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.

252379 lines
6.4MB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifdef __JUCE_JUCEHEADER__
  19. #error
  20. #endif
  21. /*** Start of inlined file: juce_TargetPlatform.h ***/
  22. #ifndef __JUCE_TARGETPLATFORM_JUCEHEADER__
  23. #define __JUCE_TARGETPLATFORM_JUCEHEADER__
  24. #if (defined (_WIN32) || defined (_WIN64))
  25. #define JUCE_WIN32 1
  26. #define JUCE_WINDOWS 1
  27. #elif defined (LINUX) || defined (__linux__)
  28. #define JUCE_LINUX 1
  29. #elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  30. #include <CoreFoundation/CoreFoundation.h> // (needed to find out what platform we're using)
  31. #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
  32. #define JUCE_IPHONE 1
  33. #else
  34. #define JUCE_MAC 1
  35. #endif
  36. #else
  37. #error "Unknown platform!"
  38. #endif
  39. #if JUCE_WINDOWS
  40. #ifdef _MSC_VER
  41. #ifdef _WIN64
  42. #define JUCE_64BIT 1
  43. #else
  44. #define JUCE_32BIT 1
  45. #endif
  46. #endif
  47. #ifdef _DEBUG
  48. #define JUCE_DEBUG 1
  49. #endif
  50. #ifdef __MINGW32__
  51. #define JUCE_MINGW 1
  52. #endif
  53. #define JUCE_LITTLE_ENDIAN 1
  54. #define JUCE_INTEL 1
  55. #endif
  56. #if JUCE_MAC
  57. #ifndef NDEBUG
  58. #define JUCE_DEBUG 1
  59. #endif
  60. #ifdef __LITTLE_ENDIAN__
  61. #define JUCE_LITTLE_ENDIAN 1
  62. #else
  63. #define JUCE_BIG_ENDIAN 1
  64. #endif
  65. #if defined (__ppc__) || defined (__ppc64__)
  66. #define JUCE_PPC 1
  67. #undef MAC_OS_X_VERSION_MAX_ALLOWED
  68. #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_4
  69. #else
  70. #define JUCE_INTEL 1
  71. #endif
  72. #ifdef __LP64__
  73. #define JUCE_64BIT 1
  74. #else
  75. #define JUCE_32BIT 1
  76. #endif
  77. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  78. #error "Building for OSX 10.3 is no longer supported!"
  79. #endif
  80. #ifndef MAC_OS_X_VERSION_10_5
  81. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  82. #endif
  83. #endif
  84. #if JUCE_IPHONE
  85. #ifndef NDEBUG
  86. #define JUCE_DEBUG 1
  87. #endif
  88. #ifdef __LITTLE_ENDIAN__
  89. #define JUCE_LITTLE_ENDIAN 1
  90. #else
  91. #define JUCE_BIG_ENDIAN 1
  92. #endif
  93. #endif
  94. #if JUCE_LINUX
  95. #ifdef _DEBUG
  96. #define JUCE_DEBUG 1
  97. #endif
  98. // Allow override for big-endian Linux platforms
  99. #ifndef JUCE_BIG_ENDIAN
  100. #define JUCE_LITTLE_ENDIAN 1
  101. #endif
  102. #if defined (__LP64__) || defined (_LP64)
  103. #define JUCE_64BIT 1
  104. #else
  105. #define JUCE_32BIT 1
  106. #endif
  107. #define JUCE_INTEL 1
  108. #endif
  109. // Compiler type macros.
  110. #ifdef __GNUC__
  111. #define JUCE_GCC 1
  112. #elif defined (_MSC_VER)
  113. #define JUCE_MSVC 1
  114. #if _MSC_VER >= 1400
  115. #define JUCE_USE_INTRINSICS 1
  116. #endif
  117. #else
  118. #error unknown compiler
  119. #endif
  120. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  121. /*** End of inlined file: juce_TargetPlatform.h ***/
  122. // FORCE_AMALGAMATOR_INCLUDE
  123. /*** Start of inlined file: juce_Config.h ***/
  124. #ifndef __JUCE_CONFIG_JUCEHEADER__
  125. #define __JUCE_CONFIG_JUCEHEADER__
  126. #ifndef JUCE_NAMESPACE
  127. #define JUCE_NAMESPACE juce
  128. #endif
  129. #ifndef JUCE_FORCE_DEBUG
  130. //#define JUCE_FORCE_DEBUG 1
  131. #endif
  132. #ifndef JUCE_LOG_ASSERTIONS
  133. // #define JUCE_LOG_ASSERTIONS 1
  134. #endif
  135. #ifndef JUCE_ASIO
  136. #define JUCE_ASIO 0
  137. #endif
  138. #ifndef JUCE_WASAPI
  139. // #define JUCE_WASAPI 1
  140. #endif
  141. #ifndef JUCE_DIRECTSOUND
  142. #define JUCE_DIRECTSOUND 1
  143. #endif
  144. #ifndef JUCE_ALSA
  145. #define JUCE_ALSA 1
  146. #endif
  147. #ifndef JUCE_JACK
  148. #define JUCE_JACK 1
  149. #endif
  150. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  151. #define JUCE_QUICKTIME 0
  152. #endif
  153. #if (JUCE_IPHONE || JUCE_LINUX) && JUCE_QUICKTIME
  154. #undef JUCE_QUICKTIME
  155. #endif
  156. #ifndef JUCE_OPENGL
  157. #define JUCE_OPENGL 1
  158. #endif
  159. #ifndef JUCE_USE_FLAC
  160. #define JUCE_USE_FLAC 1
  161. #endif
  162. #ifndef JUCE_USE_OGGVORBIS
  163. #define JUCE_USE_OGGVORBIS 1
  164. #endif
  165. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  166. #define JUCE_USE_CDBURNER 0
  167. #endif
  168. #ifndef JUCE_USE_CDREADER
  169. #define JUCE_USE_CDREADER 1
  170. #endif
  171. #if (JUCE_QUICKTIME || JUCE_WINDOWS) && ! defined (JUCE_USE_CAMERA)
  172. // #define JUCE_USE_CAMERA 1
  173. #endif
  174. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  175. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  176. #endif
  177. #ifndef JUCE_USE_XINERAMA
  178. #define JUCE_USE_XINERAMA 1
  179. #endif
  180. #ifndef JUCE_USE_XSHM
  181. #define JUCE_USE_XSHM 1
  182. #endif
  183. #ifndef JUCE_USE_XRENDER
  184. //#define JUCE_USE_XRENDER 1
  185. #endif
  186. #ifndef JUCE_USE_XCURSOR
  187. #define JUCE_USE_XCURSOR 1
  188. #endif
  189. #ifndef JUCE_PLUGINHOST_VST
  190. // #define JUCE_PLUGINHOST_VST 1
  191. #endif
  192. #ifndef JUCE_PLUGINHOST_AU
  193. // #define JUCE_PLUGINHOST_AU 1
  194. #endif
  195. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  196. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  197. #endif
  198. #ifndef JUCE_WEB_BROWSER
  199. #define JUCE_WEB_BROWSER 0
  200. #endif
  201. #ifndef JUCE_SUPPORT_CARBON
  202. #define JUCE_SUPPORT_CARBON 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_ZLIB_CODE
  205. #define JUCE_INCLUDE_ZLIB_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_FLAC_CODE
  208. #define JUCE_INCLUDE_FLAC_CODE 1
  209. #endif
  210. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  211. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  212. #endif
  213. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  214. #define JUCE_INCLUDE_PNGLIB_CODE 1
  215. #endif
  216. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  217. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  218. #endif
  219. #ifndef JUCE_CHECK_MEMORY_LEAKS
  220. #define JUCE_CHECK_MEMORY_LEAKS 1
  221. #endif
  222. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  223. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  224. #endif
  225. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  226. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  227. #undef JUCE_QUICKTIME
  228. #define JUCE_QUICKTIME 0
  229. #undef JUCE_OPENGL
  230. #define JUCE_OPENGL 0
  231. #undef JUCE_USE_CDBURNER
  232. #define JUCE_USE_CDBURNER 0
  233. #undef JUCE_USE_CDREADER
  234. #define JUCE_USE_CDREADER 0
  235. #undef JUCE_WEB_BROWSER
  236. #define JUCE_WEB_BROWSER 0
  237. #undef JUCE_PLUGINHOST_AU
  238. #define JUCE_PLUGINHOST_AU 0
  239. #undef JUCE_PLUGINHOST_VST
  240. #define JUCE_PLUGINHOST_VST 0
  241. #endif
  242. #endif
  243. /*** End of inlined file: juce_Config.h ***/
  244. // FORCE_AMALGAMATOR_INCLUDE
  245. #ifndef JUCE_BUILD_CORE
  246. #define JUCE_BUILD_CORE 1
  247. #endif
  248. #ifndef JUCE_BUILD_MISC
  249. #define JUCE_BUILD_MISC 1
  250. #endif
  251. #ifndef JUCE_BUILD_GUI
  252. #define JUCE_BUILD_GUI 1
  253. #endif
  254. #ifndef JUCE_BUILD_NATIVE
  255. #define JUCE_BUILD_NATIVE 1
  256. #endif
  257. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  258. #undef JUCE_BUILD_MISC
  259. #undef JUCE_BUILD_GUI
  260. #endif
  261. //==============================================================================
  262. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  263. #if JUCE_WINDOWS
  264. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  265. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  266. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  267. #ifndef STRICT
  268. #define STRICT 1
  269. #endif
  270. #undef WIN32_LEAN_AND_MEAN
  271. #define WIN32_LEAN_AND_MEAN 1
  272. #ifdef _MSC_VER
  273. #pragma warning (push)
  274. #pragma warning (disable : 4100 4201 4514 4312 4995)
  275. #endif
  276. #define _WIN32_WINNT 0x0500
  277. #define _UNICODE 1
  278. #define UNICODE 1
  279. #ifndef _WIN32_IE
  280. #define _WIN32_IE 0x0400
  281. #endif
  282. #include <windows.h>
  283. #include <windowsx.h>
  284. #include <commdlg.h>
  285. #include <shellapi.h>
  286. #include <mmsystem.h>
  287. #include <vfw.h>
  288. #include <tchar.h>
  289. #include <stddef.h>
  290. #include <ctime>
  291. #include <wininet.h>
  292. #include <nb30.h>
  293. #include <iphlpapi.h>
  294. #include <mapi.h>
  295. #include <float.h>
  296. #include <process.h>
  297. #include <Exdisp.h>
  298. #include <exdispid.h>
  299. #include <shlobj.h>
  300. #if ! JUCE_MINGW
  301. #include <crtdbg.h>
  302. #include <comutil.h>
  303. #endif
  304. #if JUCE_OPENGL
  305. #include <gl/gl.h>
  306. #endif
  307. #undef PACKED
  308. #if JUCE_ASIO
  309. #include "iasiodrv.h"
  310. #endif
  311. #if JUCE_USE_CDBURNER
  312. #include <imapi.h>
  313. #include <imapierror.h>
  314. #endif
  315. #if JUCE_USE_CAMERA
  316. #include <dshow.h>
  317. #include <qedit.h>
  318. #include <dshowasf.h>
  319. #endif
  320. #if JUCE_WASAPI
  321. #include <MMReg.h>
  322. #include <mmdeviceapi.h>
  323. #include <Audioclient.h>
  324. #include <Avrt.h>
  325. #include <functiondiscoverykeys.h>
  326. #endif
  327. #if JUCE_QUICKTIME
  328. #include <Movies.h>
  329. #include <QTML.h>
  330. #include <QuickTimeComponents.h>
  331. #include <MediaHandlers.h>
  332. #include <ImageCodec.h>
  333. #import <QTOLibrary.dll>
  334. #import <QTOControl.dll>
  335. #endif
  336. #ifdef _MSC_VER
  337. #pragma warning (pop)
  338. #endif
  339. template <class T>
  340. class ComSmartPtr
  341. {
  342. public:
  343. ComSmartPtr() throw() : p (0) {}
  344. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  345. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  346. ~ComSmartPtr() { if (p != 0) p->Release(); }
  347. operator T*() const throw() { return p; }
  348. T& operator*() const throw() { return *p; }
  349. T** operator&() throw() { return &p; }
  350. T* operator->() const throw() { return p; }
  351. T* operator= (T* const newP)
  352. {
  353. if (newP != 0)
  354. newP->AddRef();
  355. if (p != 0)
  356. p->Release();
  357. p = newP;
  358. return newP;
  359. }
  360. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  361. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  362. {
  363. #ifndef __MINGW32__
  364. operator= (0);
  365. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  366. #else
  367. return S_FALSE;
  368. #endif
  369. }
  370. T* p;
  371. };
  372. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  373. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  374. #elif JUCE_LINUX
  375. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  376. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  377. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  378. #include <sched.h>
  379. #include <pthread.h>
  380. #include <sys/time.h>
  381. #include <errno.h>
  382. #include <sys/stat.h>
  383. #include <sys/dir.h>
  384. #include <sys/ptrace.h>
  385. #include <sys/vfs.h>
  386. #include <sys/wait.h>
  387. #include <fnmatch.h>
  388. #include <utime.h>
  389. #include <pwd.h>
  390. #include <fcntl.h>
  391. #include <dlfcn.h>
  392. #include <netdb.h>
  393. #include <arpa/inet.h>
  394. #include <netinet/in.h>
  395. #include <sys/types.h>
  396. #include <sys/ioctl.h>
  397. #include <sys/socket.h>
  398. #include <linux/if.h>
  399. #include <sys/sysinfo.h>
  400. #include <sys/file.h>
  401. #include <signal.h>
  402. #include <ft2build.h>
  403. #include FT_FREETYPE_H
  404. #include <X11/Xlib.h>
  405. #include <X11/Xatom.h>
  406. #include <X11/Xresource.h>
  407. #include <X11/Xutil.h>
  408. #include <X11/Xmd.h>
  409. #include <X11/keysym.h>
  410. #include <X11/cursorfont.h>
  411. #if JUCE_USE_XINERAMA
  412. #include <X11/extensions/Xinerama.h>
  413. #endif
  414. #if JUCE_USE_XSHM
  415. #include <X11/extensions/XShm.h>
  416. #include <sys/shm.h>
  417. #include <sys/ipc.h>
  418. #endif
  419. #if JUCE_USE_XRENDER
  420. // If you're missing these headers, try installing the libxrender-dev and libxcomposite-dev
  421. #include <X11/extensions/Xrender.h>
  422. #include <X11/extensions/Xcomposite.h>
  423. #endif
  424. #if JUCE_USE_XCURSOR
  425. // If you're missing this header, try installing the libxcursor-dev package
  426. #include <X11/Xcursor/Xcursor.h>
  427. #endif
  428. #if JUCE_OPENGL
  429. #include <GL/glx.h>
  430. #endif
  431. #undef KeyPress
  432. #if JUCE_ALSA
  433. #include <alsa/asoundlib.h>
  434. #endif
  435. #if JUCE_JACK
  436. #include <jack/jack.h>
  437. //#include <jack/transport.h>
  438. #endif
  439. #undef SIZEOF
  440. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  441. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  442. #elif JUCE_MAC || JUCE_IPHONE
  443. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  444. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  445. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  446. #define USE_COREGRAPHICS_RENDERING 1
  447. #if JUCE_IPHONE
  448. #import <Foundation/Foundation.h>
  449. #import <UIKit/UIKit.h>
  450. #import <AudioToolbox/AudioToolbox.h>
  451. #import <AVFoundation/AVFoundation.h>
  452. #import <CoreData/CoreData.h>
  453. #import <MobileCoreServices/MobileCoreServices.h>
  454. #import <QuartzCore/QuartzCore.h>
  455. #include <sys/fcntl.h>
  456. #if JUCE_OPENGL
  457. #include <OpenGLES/ES1/gl.h>
  458. #include <OpenGLES/ES1/glext.h>
  459. #endif
  460. #else
  461. #import <Cocoa/Cocoa.h>
  462. #import <CoreAudio/HostTime.h>
  463. #import <CoreAudio/AudioHardware.h>
  464. #import <CoreMIDI/MIDIServices.h>
  465. #import <QTKit/QTKit.h>
  466. #import <WebKit/WebKit.h>
  467. #import <DiscRecording/DiscRecording.h>
  468. #import <IOKit/IOKitLib.h>
  469. #import <IOKit/IOCFPlugIn.h>
  470. #import <IOKit/hid/IOHIDLib.h>
  471. #import <IOKit/hid/IOHIDKeys.h>
  472. #import <IOKit/pwr_mgt/IOPMLib.h>
  473. #include <Carbon/Carbon.h>
  474. #include <sys/dir.h>
  475. #include <sys/socket.h>
  476. #endif
  477. #include <sys/sysctl.h>
  478. #include <sys/stat.h>
  479. #include <sys/param.h>
  480. #include <sys/mount.h>
  481. #include <fnmatch.h>
  482. #include <utime.h>
  483. #include <dlfcn.h>
  484. #include <ifaddrs.h>
  485. #include <net/if_dl.h>
  486. #include <mach/mach_time.h>
  487. #if MACOS_10_4_OR_EARLIER
  488. #include <GLUT/glut.h>
  489. #endif
  490. #if ! CGFLOAT_DEFINED
  491. #define CGFloat float
  492. #endif
  493. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  494. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  495. #else
  496. #error "Unknown platform!"
  497. #endif
  498. #endif
  499. //==============================================================================
  500. #define DONT_SET_USING_JUCE_NAMESPACE 1
  501. #undef max
  502. #undef min
  503. #define NO_DUMMY_DECL
  504. #if JUCE_BUILD_NATIVE
  505. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  506. #endif
  507. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  508. #pragma warning (disable: 4309 4305)
  509. #endif
  510. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  511. BEGIN_JUCE_NAMESPACE
  512. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  513. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  514. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  515. class CarbonViewWrapperComponent : public Component,
  516. public ComponentMovementWatcher,
  517. public Timer
  518. {
  519. public:
  520. CarbonViewWrapperComponent()
  521. : ComponentMovementWatcher (this),
  522. wrapperWindow (0),
  523. embeddedView (0),
  524. recursiveResize (false)
  525. {
  526. }
  527. virtual ~CarbonViewWrapperComponent()
  528. {
  529. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  530. }
  531. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  532. virtual void removeView (HIViewRef embeddedView) = 0;
  533. virtual void mouseDown (int x, int y) {}
  534. virtual void paint() {}
  535. virtual bool getEmbeddedViewSize (int& w, int& h)
  536. {
  537. if (embeddedView == 0)
  538. return false;
  539. HIRect bounds;
  540. HIViewGetBounds (embeddedView, &bounds);
  541. w = jmax (1, roundToInt (bounds.size.width));
  542. h = jmax (1, roundToInt (bounds.size.height));
  543. return true;
  544. }
  545. void createWindow()
  546. {
  547. if (wrapperWindow == 0)
  548. {
  549. Rect r;
  550. r.left = getScreenX();
  551. r.top = getScreenY();
  552. r.right = r.left + getWidth();
  553. r.bottom = r.top + getHeight();
  554. CreateNewWindow (kDocumentWindowClass,
  555. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  556. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  557. &r, &wrapperWindow);
  558. jassert (wrapperWindow != 0);
  559. if (wrapperWindow == 0)
  560. return;
  561. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  562. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  563. [ownerWindow addChildWindow: carbonWindow
  564. ordered: NSWindowAbove];
  565. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  566. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  567. { kEventClassWindow, kEventWindowHandleDeactivate } };
  568. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  569. InstallWindowEventHandler (wrapperWindow, upp,
  570. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  571. windowEventTypes, this, &eventHandlerRef);
  572. setOurSizeToEmbeddedViewSize();
  573. setEmbeddedWindowToOurSize();
  574. creationTime = Time::getCurrentTime();
  575. }
  576. }
  577. void deleteWindow()
  578. {
  579. removeView (embeddedView);
  580. embeddedView = 0;
  581. if (wrapperWindow != 0)
  582. {
  583. RemoveEventHandler (eventHandlerRef);
  584. DisposeWindow (wrapperWindow);
  585. wrapperWindow = 0;
  586. }
  587. }
  588. void setOurSizeToEmbeddedViewSize()
  589. {
  590. int w, h;
  591. if (getEmbeddedViewSize (w, h))
  592. {
  593. if (w != getWidth() || h != getHeight())
  594. {
  595. startTimer (50);
  596. setSize (w, h);
  597. if (getParentComponent() != 0)
  598. getParentComponent()->setSize (w, h);
  599. }
  600. else
  601. {
  602. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  603. }
  604. }
  605. else
  606. {
  607. stopTimer();
  608. }
  609. }
  610. void setEmbeddedWindowToOurSize()
  611. {
  612. if (! recursiveResize)
  613. {
  614. recursiveResize = true;
  615. if (embeddedView != 0)
  616. {
  617. HIRect r;
  618. r.origin.x = 0;
  619. r.origin.y = 0;
  620. r.size.width = (float) getWidth();
  621. r.size.height = (float) getHeight();
  622. HIViewSetFrame (embeddedView, &r);
  623. }
  624. if (wrapperWindow != 0)
  625. {
  626. Rect wr;
  627. wr.left = getScreenX();
  628. wr.top = getScreenY();
  629. wr.right = wr.left + getWidth();
  630. wr.bottom = wr.top + getHeight();
  631. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  632. ShowWindow (wrapperWindow);
  633. }
  634. recursiveResize = false;
  635. }
  636. }
  637. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  638. {
  639. setEmbeddedWindowToOurSize();
  640. }
  641. void componentPeerChanged()
  642. {
  643. deleteWindow();
  644. createWindow();
  645. }
  646. void componentVisibilityChanged (Component&)
  647. {
  648. if (isShowing())
  649. createWindow();
  650. else
  651. deleteWindow();
  652. setEmbeddedWindowToOurSize();
  653. }
  654. static void recursiveHIViewRepaint (HIViewRef view)
  655. {
  656. HIViewSetNeedsDisplay (view, true);
  657. HIViewRef child = HIViewGetFirstSubview (view);
  658. while (child != 0)
  659. {
  660. recursiveHIViewRepaint (child);
  661. child = HIViewGetNextView (child);
  662. }
  663. }
  664. void timerCallback()
  665. {
  666. setOurSizeToEmbeddedViewSize();
  667. // To avoid strange overpainting problems when the UI is first opened, we'll
  668. // repaint it a few times during the first second that it's on-screen..
  669. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  670. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  671. }
  672. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  673. EventRef event)
  674. {
  675. switch (GetEventKind (event))
  676. {
  677. case kEventWindowHandleDeactivate:
  678. ActivateWindow (wrapperWindow, TRUE);
  679. break;
  680. case kEventWindowGetClickActivation:
  681. {
  682. getTopLevelComponent()->toFront (false);
  683. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  684. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  685. sizeof (ClickActivationResult), &howToHandleClick);
  686. HIViewSetNeedsDisplay (embeddedView, true);
  687. }
  688. break;
  689. }
  690. return noErr;
  691. }
  692. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  693. EventRef event, void* userData)
  694. {
  695. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  696. }
  697. protected:
  698. WindowRef wrapperWindow;
  699. HIViewRef embeddedView;
  700. bool recursiveResize;
  701. Time creationTime;
  702. EventHandlerRef eventHandlerRef;
  703. };
  704. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  705. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  706. END_JUCE_NAMESPACE
  707. #endif
  708. #define JUCE_AMALGAMATED_TEMPLATE 1
  709. //==============================================================================
  710. #if JUCE_BUILD_CORE
  711. /*** Start of inlined file: juce_FileLogger.cpp ***/
  712. BEGIN_JUCE_NAMESPACE
  713. FileLogger::FileLogger (const File& logFile_,
  714. const String& welcomeMessage,
  715. const int maxInitialFileSizeBytes)
  716. : logFile (logFile_)
  717. {
  718. if (maxInitialFileSizeBytes >= 0)
  719. trimFileSize (maxInitialFileSizeBytes);
  720. if (! logFile_.exists())
  721. {
  722. // do this so that the parent directories get created..
  723. logFile_.create();
  724. }
  725. logStream = logFile_.createOutputStream (256);
  726. jassert (logStream != 0);
  727. String welcome;
  728. welcome << "\r\n**********************************************************\r\n"
  729. << welcomeMessage
  730. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  731. << "\r\n";
  732. logMessage (welcome);
  733. }
  734. FileLogger::~FileLogger()
  735. {
  736. }
  737. void FileLogger::logMessage (const String& message)
  738. {
  739. if (logStream != 0)
  740. {
  741. DBG (message);
  742. const ScopedLock sl (logLock);
  743. (*logStream) << message << "\r\n";
  744. logStream->flush();
  745. }
  746. }
  747. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  748. {
  749. if (maxFileSizeBytes <= 0)
  750. {
  751. logFile.deleteFile();
  752. }
  753. else
  754. {
  755. const int64 fileSize = logFile.getSize();
  756. if (fileSize > maxFileSizeBytes)
  757. {
  758. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  759. jassert (in != 0);
  760. if (in != 0)
  761. {
  762. in->setPosition (fileSize - maxFileSizeBytes);
  763. String content;
  764. {
  765. MemoryBlock contentToSave;
  766. contentToSave.setSize (maxFileSizeBytes + 4);
  767. contentToSave.fillWith (0);
  768. in->read (contentToSave.getData(), maxFileSizeBytes);
  769. in = 0;
  770. content = contentToSave.toString();
  771. }
  772. int newStart = 0;
  773. while (newStart < fileSize
  774. && content[newStart] != '\n'
  775. && content[newStart] != '\r')
  776. ++newStart;
  777. logFile.deleteFile();
  778. logFile.appendText (content.substring (newStart), false, false);
  779. }
  780. }
  781. }
  782. }
  783. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  784. const String& logFileName,
  785. const String& welcomeMessage,
  786. const int maxInitialFileSizeBytes)
  787. {
  788. #if JUCE_MAC
  789. File logFile ("~/Library/Logs");
  790. logFile = logFile.getChildFile (logFileSubDirectoryName)
  791. .getChildFile (logFileName);
  792. #else
  793. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  794. if (logFile.isDirectory())
  795. {
  796. logFile = logFile.getChildFile (logFileSubDirectoryName)
  797. .getChildFile (logFileName);
  798. }
  799. #endif
  800. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  801. }
  802. END_JUCE_NAMESPACE
  803. /*** End of inlined file: juce_FileLogger.cpp ***/
  804. /*** Start of inlined file: juce_Logger.cpp ***/
  805. BEGIN_JUCE_NAMESPACE
  806. Logger::Logger()
  807. {
  808. }
  809. Logger::~Logger()
  810. {
  811. }
  812. static Logger* currentLogger = 0;
  813. void Logger::setCurrentLogger (Logger* const newLogger,
  814. const bool deleteOldLogger)
  815. {
  816. Logger* const oldLogger = currentLogger;
  817. currentLogger = newLogger;
  818. if (deleteOldLogger)
  819. delete oldLogger;
  820. }
  821. void Logger::writeToLog (const String& message)
  822. {
  823. if (currentLogger != 0)
  824. currentLogger->logMessage (message);
  825. else
  826. outputDebugString (message);
  827. }
  828. #if JUCE_LOG_ASSERTIONS
  829. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  830. {
  831. String m ("JUCE Assertion failure in ");
  832. m << filename << ", line " << lineNum;
  833. Logger::writeToLog (m);
  834. }
  835. #endif
  836. END_JUCE_NAMESPACE
  837. /*** End of inlined file: juce_Logger.cpp ***/
  838. /*** Start of inlined file: juce_Random.cpp ***/
  839. BEGIN_JUCE_NAMESPACE
  840. Random::Random (const int64 seedValue) throw()
  841. : seed (seedValue)
  842. {
  843. }
  844. Random::~Random() throw()
  845. {
  846. }
  847. void Random::setSeed (const int64 newSeed) throw()
  848. {
  849. seed = newSeed;
  850. }
  851. void Random::combineSeed (const int64 seedValue) throw()
  852. {
  853. seed ^= nextInt64() ^ seedValue;
  854. }
  855. void Random::setSeedRandomly()
  856. {
  857. combineSeed ((int64) (pointer_sized_int) this);
  858. combineSeed (Time::getMillisecondCounter());
  859. combineSeed (Time::getHighResolutionTicks());
  860. combineSeed (Time::getHighResolutionTicksPerSecond());
  861. combineSeed (Time::currentTimeMillis());
  862. }
  863. int Random::nextInt() throw()
  864. {
  865. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  866. return (int) (seed >> 16);
  867. }
  868. int Random::nextInt (const int maxValue) throw()
  869. {
  870. jassert (maxValue > 0);
  871. return (nextInt() & 0x7fffffff) % maxValue;
  872. }
  873. int64 Random::nextInt64() throw()
  874. {
  875. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  876. }
  877. bool Random::nextBool() throw()
  878. {
  879. return (nextInt() & 0x80000000) != 0;
  880. }
  881. float Random::nextFloat() throw()
  882. {
  883. return static_cast <uint32> (nextInt()) / (float) 0xffffffff;
  884. }
  885. double Random::nextDouble() throw()
  886. {
  887. return static_cast <uint32> (nextInt()) / (double) 0xffffffff;
  888. }
  889. const BigInteger Random::nextLargeNumber (const BigInteger& maximumValue)
  890. {
  891. BigInteger n;
  892. do
  893. {
  894. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  895. }
  896. while (n >= maximumValue);
  897. return n;
  898. }
  899. void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits)
  900. {
  901. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  902. while ((startBit & 31) != 0 && numBits > 0)
  903. {
  904. arrayToChange.setBit (startBit++, nextBool());
  905. --numBits;
  906. }
  907. while (numBits >= 32)
  908. {
  909. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  910. startBit += 32;
  911. numBits -= 32;
  912. }
  913. while (--numBits >= 0)
  914. arrayToChange.setBit (startBit + numBits, nextBool());
  915. }
  916. Random& Random::getSystemRandom() throw()
  917. {
  918. static Random sysRand (1);
  919. return sysRand;
  920. }
  921. END_JUCE_NAMESPACE
  922. /*** End of inlined file: juce_Random.cpp ***/
  923. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  924. BEGIN_JUCE_NAMESPACE
  925. RelativeTime::RelativeTime (const double seconds_) throw()
  926. : seconds (seconds_)
  927. {
  928. }
  929. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  930. : seconds (other.seconds)
  931. {
  932. }
  933. RelativeTime::~RelativeTime() throw()
  934. {
  935. }
  936. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  937. {
  938. return RelativeTime (milliseconds * 0.001);
  939. }
  940. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  941. {
  942. return RelativeTime (milliseconds * 0.001);
  943. }
  944. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  945. {
  946. return RelativeTime (numberOfMinutes * 60.0);
  947. }
  948. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  949. {
  950. return RelativeTime (numberOfHours * (60.0 * 60.0));
  951. }
  952. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  953. {
  954. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  955. }
  956. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  957. {
  958. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  959. }
  960. int64 RelativeTime::inMilliseconds() const throw()
  961. {
  962. return (int64)(seconds * 1000.0);
  963. }
  964. double RelativeTime::inMinutes() const throw()
  965. {
  966. return seconds / 60.0;
  967. }
  968. double RelativeTime::inHours() const throw()
  969. {
  970. return seconds / (60.0 * 60.0);
  971. }
  972. double RelativeTime::inDays() const throw()
  973. {
  974. return seconds / (60.0 * 60.0 * 24.0);
  975. }
  976. double RelativeTime::inWeeks() const throw()
  977. {
  978. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  979. }
  980. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  981. {
  982. if (seconds < 0.001 && seconds > -0.001)
  983. return returnValueForZeroTime;
  984. String result;
  985. if (seconds < 0)
  986. result = "-";
  987. int fieldsShown = 0;
  988. int n = abs ((int) inWeeks());
  989. if (n > 0)
  990. {
  991. result << n << ((n == 1) ? TRANS(" week ")
  992. : TRANS(" weeks "));
  993. ++fieldsShown;
  994. }
  995. n = abs ((int) inDays()) % 7;
  996. if (n > 0)
  997. {
  998. result << n << ((n == 1) ? TRANS(" day ")
  999. : TRANS(" days "));
  1000. ++fieldsShown;
  1001. }
  1002. if (fieldsShown < 2)
  1003. {
  1004. n = abs ((int) inHours()) % 24;
  1005. if (n > 0)
  1006. {
  1007. result << n << ((n == 1) ? TRANS(" hr ")
  1008. : TRANS(" hrs "));
  1009. ++fieldsShown;
  1010. }
  1011. if (fieldsShown < 2)
  1012. {
  1013. n = abs ((int) inMinutes()) % 60;
  1014. if (n > 0)
  1015. {
  1016. result << n << ((n == 1) ? TRANS(" min ")
  1017. : TRANS(" mins "));
  1018. ++fieldsShown;
  1019. }
  1020. if (fieldsShown < 2)
  1021. {
  1022. n = abs ((int) inSeconds()) % 60;
  1023. if (n > 0)
  1024. {
  1025. result << n << ((n == 1) ? TRANS(" sec ")
  1026. : TRANS(" secs "));
  1027. ++fieldsShown;
  1028. }
  1029. if (fieldsShown < 1)
  1030. {
  1031. n = abs ((int) inMilliseconds()) % 1000;
  1032. if (n > 0)
  1033. {
  1034. result << n << TRANS(" ms");
  1035. ++fieldsShown;
  1036. }
  1037. }
  1038. }
  1039. }
  1040. }
  1041. return result.trimEnd();
  1042. }
  1043. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1044. {
  1045. seconds = other.seconds;
  1046. return *this;
  1047. }
  1048. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1049. {
  1050. return seconds == other.seconds;
  1051. }
  1052. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1053. {
  1054. return seconds != other.seconds;
  1055. }
  1056. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1057. {
  1058. return seconds > other.seconds;
  1059. }
  1060. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1061. {
  1062. return seconds < other.seconds;
  1063. }
  1064. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1065. {
  1066. return seconds >= other.seconds;
  1067. }
  1068. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1069. {
  1070. return seconds <= other.seconds;
  1071. }
  1072. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1073. {
  1074. return RelativeTime (seconds + timeToAdd.seconds);
  1075. }
  1076. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1077. {
  1078. return RelativeTime (seconds - timeToSubtract.seconds);
  1079. }
  1080. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1081. {
  1082. return RelativeTime (seconds + secondsToAdd);
  1083. }
  1084. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1085. {
  1086. return RelativeTime (seconds - secondsToSubtract);
  1087. }
  1088. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1089. {
  1090. seconds += timeToAdd.seconds;
  1091. return *this;
  1092. }
  1093. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1094. {
  1095. seconds -= timeToSubtract.seconds;
  1096. return *this;
  1097. }
  1098. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1099. {
  1100. seconds += secondsToAdd;
  1101. return *this;
  1102. }
  1103. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1104. {
  1105. seconds -= secondsToSubtract;
  1106. return *this;
  1107. }
  1108. END_JUCE_NAMESPACE
  1109. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1110. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1111. BEGIN_JUCE_NAMESPACE
  1112. const String SystemStats::getJUCEVersion() throw()
  1113. {
  1114. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1115. + "." + String (JUCE_MINOR_VERSION)
  1116. + "." + String (JUCE_BUILDNUMBER);
  1117. }
  1118. const StringArray SystemStats::getMACAddressStrings()
  1119. {
  1120. int64 macAddresses [16];
  1121. const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);
  1122. StringArray s;
  1123. for (int i = 0; i < numAddresses; ++i)
  1124. {
  1125. s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
  1126. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
  1127. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
  1128. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
  1129. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
  1130. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
  1131. }
  1132. return s;
  1133. }
  1134. static bool juceInitialisedNonGUI = false;
  1135. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1136. {
  1137. if (! juceInitialisedNonGUI)
  1138. {
  1139. #if JUCE_MAC || JUCE_IPHONE
  1140. const ScopedAutoReleasePool pool;
  1141. #endif
  1142. #ifdef JUCE_DEBUG
  1143. {
  1144. // Some simple test code to keep an eye on things and make sure these functions
  1145. // work ok on all platforms. Let me know if any of these assertions fail!
  1146. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1147. char a1[7];
  1148. jassert (numElementsInArray(a1) == 7);
  1149. int a2[3];
  1150. jassert (numElementsInArray(a2) == 3);
  1151. int n = 1;
  1152. Atomic::increment (n);
  1153. jassert (Atomic::incrementAndReturn (n) == 3);
  1154. Atomic::decrement (n);
  1155. jassert (Atomic::decrementAndReturn (n) == 1);
  1156. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1157. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1158. // Some quick stream tests..
  1159. int randomInt = Random::getSystemRandom().nextInt();
  1160. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1161. double randomDouble = Random::getSystemRandom().nextDouble();
  1162. String randomString;
  1163. for (int i = 50; --i >= 0;)
  1164. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1165. MemoryOutputStream mo;
  1166. mo.writeInt (randomInt);
  1167. mo.writeIntBigEndian (randomInt);
  1168. mo.writeCompressedInt (randomInt);
  1169. mo.writeString (randomString);
  1170. mo.writeInt64 (randomInt64);
  1171. mo.writeInt64BigEndian (randomInt64);
  1172. mo.writeDouble (randomDouble);
  1173. mo.writeDoubleBigEndian (randomDouble);
  1174. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1175. jassert (mi.readInt() == randomInt);
  1176. jassert (mi.readIntBigEndian() == randomInt);
  1177. jassert (mi.readCompressedInt() == randomInt);
  1178. jassert (mi.readString() == randomString);
  1179. jassert (mi.readInt64() == randomInt64);
  1180. jassert (mi.readInt64BigEndian() == randomInt64);
  1181. jassert (mi.readDouble() == randomDouble);
  1182. jassert (mi.readDoubleBigEndian() == randomDouble);
  1183. }
  1184. #endif
  1185. // Now the real initialisation..
  1186. juceInitialisedNonGUI = true;
  1187. DBG (SystemStats::getJUCEVersion());
  1188. SystemStats::initialiseStats();
  1189. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1190. }
  1191. }
  1192. #if JUCE_WINDOWS
  1193. // This is imported from the sockets code..
  1194. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1195. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1196. #endif
  1197. #if JUCE_DEBUG
  1198. extern void juce_CheckForDanglingStreams();
  1199. #endif
  1200. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1201. {
  1202. if (juceInitialisedNonGUI)
  1203. {
  1204. #if JUCE_MAC || JUCE_IPHONE
  1205. const ScopedAutoReleasePool pool;
  1206. #endif
  1207. #if JUCE_WINDOWS
  1208. // need to shut down sockets if they were used..
  1209. if (juce_CloseWin32SocketLib != 0)
  1210. (*juce_CloseWin32SocketLib)();
  1211. #endif
  1212. LocalisedStrings::setCurrentMappings (0);
  1213. Thread::stopAllThreads (3000);
  1214. #if JUCE_DEBUG
  1215. juce_CheckForDanglingStreams();
  1216. #endif
  1217. juceInitialisedNonGUI = false;
  1218. }
  1219. }
  1220. #ifdef JUCE_DLL
  1221. void* juce_Malloc (const int size)
  1222. {
  1223. return malloc (size);
  1224. }
  1225. void* juce_Calloc (const int size)
  1226. {
  1227. return calloc (1, size);
  1228. }
  1229. void* juce_Realloc (void* const block, const int size)
  1230. {
  1231. return realloc (block, size);
  1232. }
  1233. void juce_Free (void* const block)
  1234. {
  1235. free (block);
  1236. }
  1237. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1238. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1239. {
  1240. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1241. }
  1242. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1243. {
  1244. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1245. }
  1246. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1247. {
  1248. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1249. }
  1250. void juce_DebugFree (void* const block)
  1251. {
  1252. _free_dbg (block, _NORMAL_BLOCK);
  1253. }
  1254. #endif
  1255. #endif
  1256. END_JUCE_NAMESPACE
  1257. /*** End of inlined file: juce_SystemStats.cpp ***/
  1258. /*** Start of inlined file: juce_Time.cpp ***/
  1259. #ifdef _MSC_VER
  1260. #pragma warning (disable: 4514)
  1261. #pragma warning (push)
  1262. #endif
  1263. #ifndef JUCE_WINDOWS
  1264. #include <sys/time.h>
  1265. #else
  1266. #include <ctime>
  1267. #endif
  1268. #include <sys/timeb.h>
  1269. BEGIN_JUCE_NAMESPACE
  1270. #ifdef _MSC_VER
  1271. #pragma warning (pop)
  1272. #ifdef _INC_TIME_INL
  1273. #define USE_NEW_SECURE_TIME_FNS
  1274. #endif
  1275. #endif
  1276. namespace TimeHelpers
  1277. {
  1278. static struct tm millisToLocal (const int64 millis) throw()
  1279. {
  1280. struct tm result;
  1281. const int64 seconds = millis / 1000;
  1282. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1283. {
  1284. // use extended maths for dates beyond 1970 to 2037..
  1285. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1286. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1287. const int days = (int) (jdm / literal64bit (86400));
  1288. const int a = 32044 + days;
  1289. const int b = (4 * a + 3) / 146097;
  1290. const int c = a - (b * 146097) / 4;
  1291. const int d = (4 * c + 3) / 1461;
  1292. const int e = c - (d * 1461) / 4;
  1293. const int m = (5 * e + 2) / 153;
  1294. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1295. result.tm_mon = m + 2 - 12 * (m / 10);
  1296. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1297. result.tm_wday = (days + 1) % 7;
  1298. result.tm_yday = -1;
  1299. int t = (int) (jdm % literal64bit (86400));
  1300. result.tm_hour = t / 3600;
  1301. t %= 3600;
  1302. result.tm_min = t / 60;
  1303. result.tm_sec = t % 60;
  1304. result.tm_isdst = -1;
  1305. }
  1306. else
  1307. {
  1308. time_t now = static_cast <time_t> (seconds);
  1309. #if JUCE_WINDOWS
  1310. #ifdef USE_NEW_SECURE_TIME_FNS
  1311. if (now >= 0 && now <= 0x793406fff)
  1312. localtime_s (&result, &now);
  1313. else
  1314. zeromem (&result, sizeof (result));
  1315. #else
  1316. result = *localtime (&now);
  1317. #endif
  1318. #else
  1319. // more thread-safe
  1320. localtime_r (&now, &result);
  1321. #endif
  1322. }
  1323. return result;
  1324. }
  1325. static int extendedModulo (const int64 value, const int modulo) throw()
  1326. {
  1327. return (int) (value >= 0 ? (value % modulo)
  1328. : (value - ((value / modulo) + 1) * modulo));
  1329. }
  1330. static uint32 lastMSCounterValue = 0;
  1331. }
  1332. Time::Time() throw()
  1333. : millisSinceEpoch (0)
  1334. {
  1335. }
  1336. Time::Time (const Time& other) throw()
  1337. : millisSinceEpoch (other.millisSinceEpoch)
  1338. {
  1339. }
  1340. Time::Time (const int64 ms) throw()
  1341. : millisSinceEpoch (ms)
  1342. {
  1343. }
  1344. Time::Time (const int year,
  1345. const int month,
  1346. const int day,
  1347. const int hours,
  1348. const int minutes,
  1349. const int seconds,
  1350. const int milliseconds,
  1351. const bool useLocalTime) throw()
  1352. {
  1353. jassert (year > 100); // year must be a 4-digit version
  1354. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1355. {
  1356. // use extended maths for dates beyond 1970 to 2037..
  1357. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1358. : 0;
  1359. const int a = (13 - month) / 12;
  1360. const int y = year + 4800 - a;
  1361. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1362. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1363. - 32045;
  1364. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1365. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1366. + milliseconds;
  1367. }
  1368. else
  1369. {
  1370. struct tm t;
  1371. t.tm_year = year - 1900;
  1372. t.tm_mon = month;
  1373. t.tm_mday = day;
  1374. t.tm_hour = hours;
  1375. t.tm_min = minutes;
  1376. t.tm_sec = seconds;
  1377. t.tm_isdst = -1;
  1378. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1379. if (millisSinceEpoch < 0)
  1380. millisSinceEpoch = 0;
  1381. else
  1382. millisSinceEpoch += milliseconds;
  1383. }
  1384. }
  1385. Time::~Time() throw()
  1386. {
  1387. }
  1388. Time& Time::operator= (const Time& other) throw()
  1389. {
  1390. millisSinceEpoch = other.millisSinceEpoch;
  1391. return *this;
  1392. }
  1393. int64 Time::currentTimeMillis() throw()
  1394. {
  1395. static uint32 lastCounterResult = 0xffffffff;
  1396. static int64 correction = 0;
  1397. const uint32 now = getMillisecondCounter();
  1398. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1399. if (now < lastCounterResult)
  1400. {
  1401. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1402. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1403. {
  1404. // get the time once using normal library calls, and store the difference needed to
  1405. // turn the millisecond counter into a real time.
  1406. #if JUCE_WINDOWS
  1407. struct _timeb t;
  1408. #ifdef USE_NEW_SECURE_TIME_FNS
  1409. _ftime_s (&t);
  1410. #else
  1411. _ftime (&t);
  1412. #endif
  1413. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1414. #else
  1415. struct timeval tv;
  1416. struct timezone tz;
  1417. gettimeofday (&tv, &tz);
  1418. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1419. #endif
  1420. }
  1421. }
  1422. lastCounterResult = now;
  1423. return correction + now;
  1424. }
  1425. uint32 juce_millisecondsSinceStartup() throw();
  1426. uint32 Time::getMillisecondCounter() throw()
  1427. {
  1428. const uint32 now = juce_millisecondsSinceStartup();
  1429. if (now < TimeHelpers::lastMSCounterValue)
  1430. {
  1431. // in multi-threaded apps this might be called concurrently, so
  1432. // make sure that our last counter value only increases and doesn't
  1433. // go backwards..
  1434. if (now < TimeHelpers::lastMSCounterValue - 1000)
  1435. TimeHelpers::lastMSCounterValue = now;
  1436. }
  1437. else
  1438. {
  1439. TimeHelpers::lastMSCounterValue = now;
  1440. }
  1441. return now;
  1442. }
  1443. uint32 Time::getApproximateMillisecondCounter() throw()
  1444. {
  1445. jassert (TimeHelpers::lastMSCounterValue != 0);
  1446. return TimeHelpers::lastMSCounterValue;
  1447. }
  1448. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1449. {
  1450. for (;;)
  1451. {
  1452. const uint32 now = getMillisecondCounter();
  1453. if (now >= targetTime)
  1454. break;
  1455. const int toWait = targetTime - now;
  1456. if (toWait > 2)
  1457. {
  1458. Thread::sleep (jmin (20, toWait >> 1));
  1459. }
  1460. else
  1461. {
  1462. // xxx should consider using mutex_pause on the mac as it apparently
  1463. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1464. for (int i = 10; --i >= 0;)
  1465. Thread::yield();
  1466. }
  1467. }
  1468. }
  1469. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1470. {
  1471. return ticks / (double) getHighResolutionTicksPerSecond();
  1472. }
  1473. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1474. {
  1475. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1476. }
  1477. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1478. {
  1479. return Time (currentTimeMillis());
  1480. }
  1481. const String Time::toString (const bool includeDate,
  1482. const bool includeTime,
  1483. const bool includeSeconds,
  1484. const bool use24HourClock) const throw()
  1485. {
  1486. String result;
  1487. if (includeDate)
  1488. {
  1489. result << getDayOfMonth() << ' '
  1490. << getMonthName (true) << ' '
  1491. << getYear();
  1492. if (includeTime)
  1493. result << ' ';
  1494. }
  1495. if (includeTime)
  1496. {
  1497. const int mins = getMinutes();
  1498. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1499. << (mins < 10 ? ":0" : ":") << mins;
  1500. if (includeSeconds)
  1501. {
  1502. const int secs = getSeconds();
  1503. result << (secs < 10 ? ":0" : ":") << secs;
  1504. }
  1505. if (! use24HourClock)
  1506. result << (isAfternoon() ? "pm" : "am");
  1507. }
  1508. return result.trimEnd();
  1509. }
  1510. const String Time::formatted (const juce_wchar* const format) const throw()
  1511. {
  1512. String buffer;
  1513. int bufferSize = 128;
  1514. buffer.preallocateStorage (bufferSize);
  1515. struct tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  1516. while (CharacterFunctions::ftime (static_cast <juce_wchar*> (buffer), bufferSize, format, &t) <= 0)
  1517. {
  1518. bufferSize += 128;
  1519. buffer.preallocateStorage (bufferSize);
  1520. }
  1521. return buffer;
  1522. }
  1523. int Time::getYear() const throw()
  1524. {
  1525. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900;
  1526. }
  1527. int Time::getMonth() const throw()
  1528. {
  1529. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon;
  1530. }
  1531. int Time::getDayOfMonth() const throw()
  1532. {
  1533. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday;
  1534. }
  1535. int Time::getDayOfWeek() const throw()
  1536. {
  1537. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday;
  1538. }
  1539. int Time::getHours() const throw()
  1540. {
  1541. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour;
  1542. }
  1543. int Time::getHoursInAmPmFormat() const throw()
  1544. {
  1545. const int hours = getHours();
  1546. if (hours == 0)
  1547. return 12;
  1548. else if (hours <= 12)
  1549. return hours;
  1550. else
  1551. return hours - 12;
  1552. }
  1553. bool Time::isAfternoon() const throw()
  1554. {
  1555. return getHours() >= 12;
  1556. }
  1557. int Time::getMinutes() const throw()
  1558. {
  1559. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min;
  1560. }
  1561. int Time::getSeconds() const throw()
  1562. {
  1563. return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60);
  1564. }
  1565. int Time::getMilliseconds() const throw()
  1566. {
  1567. return TimeHelpers::extendedModulo (millisSinceEpoch, 1000);
  1568. }
  1569. bool Time::isDaylightSavingTime() const throw()
  1570. {
  1571. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  1572. }
  1573. const String Time::getTimeZone() const throw()
  1574. {
  1575. String zone[2];
  1576. #if JUCE_WINDOWS
  1577. _tzset();
  1578. #ifdef USE_NEW_SECURE_TIME_FNS
  1579. {
  1580. char name [128];
  1581. size_t length;
  1582. for (int i = 0; i < 2; ++i)
  1583. {
  1584. zeromem (name, sizeof (name));
  1585. _get_tzname (&length, name, 127, i);
  1586. zone[i] = name;
  1587. }
  1588. }
  1589. #else
  1590. const char** const zonePtr = (const char**) _tzname;
  1591. zone[0] = zonePtr[0];
  1592. zone[1] = zonePtr[1];
  1593. #endif
  1594. #else
  1595. tzset();
  1596. const char** const zonePtr = (const char**) tzname;
  1597. zone[0] = zonePtr[0];
  1598. zone[1] = zonePtr[1];
  1599. #endif
  1600. if (isDaylightSavingTime())
  1601. {
  1602. zone[0] = zone[1];
  1603. if (zone[0].length() > 3
  1604. && zone[0].containsIgnoreCase ("daylight")
  1605. && zone[0].contains ("GMT"))
  1606. zone[0] = "BST";
  1607. }
  1608. return zone[0].substring (0, 3);
  1609. }
  1610. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1611. {
  1612. return getMonthName (getMonth(), threeLetterVersion);
  1613. }
  1614. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1615. {
  1616. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1617. }
  1618. const String Time::getMonthName (int monthNumber, const bool threeLetterVersion) throw()
  1619. {
  1620. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1621. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1622. monthNumber %= 12;
  1623. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1624. : longMonthNames [monthNumber]);
  1625. }
  1626. const String Time::getWeekdayName (int day, const bool threeLetterVersion) throw()
  1627. {
  1628. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1629. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1630. day %= 7;
  1631. return TRANS (threeLetterVersion ? shortDayNames [day]
  1632. : longDayNames [day]);
  1633. }
  1634. END_JUCE_NAMESPACE
  1635. /*** End of inlined file: juce_Time.cpp ***/
  1636. /*** Start of inlined file: juce_BitArray.cpp ***/
  1637. BEGIN_JUCE_NAMESPACE
  1638. BigInteger::BigInteger()
  1639. : numValues (4),
  1640. highestBit (-1),
  1641. negative (false)
  1642. {
  1643. values.calloc (numValues + 1);
  1644. }
  1645. BigInteger::BigInteger (const int value)
  1646. : numValues (4),
  1647. highestBit (31),
  1648. negative (value < 0)
  1649. {
  1650. values.calloc (numValues + 1);
  1651. values[0] = abs (value);
  1652. highestBit = getHighestBit();
  1653. }
  1654. BigInteger::BigInteger (int64 value)
  1655. : numValues (4),
  1656. highestBit (63),
  1657. negative (value < 0)
  1658. {
  1659. values.calloc (numValues + 1);
  1660. if (value < 0)
  1661. value = -value;
  1662. values[0] = (unsigned int) value;
  1663. values[1] = (unsigned int) (value >> 32);
  1664. highestBit = getHighestBit();
  1665. }
  1666. BigInteger::BigInteger (const unsigned int value)
  1667. : numValues (4),
  1668. highestBit (31),
  1669. negative (false)
  1670. {
  1671. values.calloc (numValues + 1);
  1672. values[0] = value;
  1673. highestBit = getHighestBit();
  1674. }
  1675. BigInteger::BigInteger (const BigInteger& other)
  1676. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1677. highestBit (other.getHighestBit()),
  1678. negative (other.negative)
  1679. {
  1680. values.malloc (numValues + 1);
  1681. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1682. }
  1683. BigInteger::~BigInteger()
  1684. {
  1685. }
  1686. void BigInteger::swapWith (BigInteger& other) throw()
  1687. {
  1688. values.swapWith (other.values);
  1689. swapVariables (numValues, other.numValues);
  1690. swapVariables (highestBit, other.highestBit);
  1691. swapVariables (negative, other.negative);
  1692. }
  1693. BigInteger& BigInteger::operator= (const BigInteger& other)
  1694. {
  1695. if (this != &other)
  1696. {
  1697. highestBit = other.getHighestBit();
  1698. numValues = jmax (4, (highestBit >> 5) + 1);
  1699. negative = other.negative;
  1700. values.malloc (numValues + 1);
  1701. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1702. }
  1703. return *this;
  1704. }
  1705. void BigInteger::ensureSize (const int numVals)
  1706. {
  1707. if (numVals + 2 >= numValues)
  1708. {
  1709. int oldSize = numValues;
  1710. numValues = ((numVals + 2) * 3) / 2;
  1711. values.realloc (numValues + 1);
  1712. while (oldSize < numValues)
  1713. values [oldSize++] = 0;
  1714. }
  1715. }
  1716. bool BigInteger::operator[] (const int bit) const throw()
  1717. {
  1718. return bit <= highestBit && bit >= 0
  1719. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1720. }
  1721. int BigInteger::toInteger() const throw()
  1722. {
  1723. const int n = (int) (values[0] & 0x7fffffff);
  1724. return negative ? -n : n;
  1725. }
  1726. const BigInteger BigInteger::getBitRange (int startBit, int numBits) const
  1727. {
  1728. BigInteger r;
  1729. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  1730. r.ensureSize (numBits >> 5);
  1731. r.highestBit = numBits;
  1732. int i = 0;
  1733. while (numBits > 0)
  1734. {
  1735. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  1736. numBits -= 32;
  1737. startBit += 32;
  1738. }
  1739. r.highestBit = r.getHighestBit();
  1740. return r;
  1741. }
  1742. int BigInteger::getBitRangeAsInt (const int startBit, int numBits) const throw()
  1743. {
  1744. if (numBits > 32)
  1745. {
  1746. jassertfalse // use getBitRange() if you need more than 32 bits..
  1747. numBits = 32;
  1748. }
  1749. numBits = jmin (numBits, highestBit + 1 - startBit);
  1750. if (numBits <= 0)
  1751. return 0;
  1752. const int pos = startBit >> 5;
  1753. const int offset = startBit & 31;
  1754. const int endSpace = 32 - numBits;
  1755. uint32 n = ((uint32) values [pos]) >> offset;
  1756. if (offset > endSpace)
  1757. n |= ((uint32) values [pos + 1]) << (32 - offset);
  1758. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  1759. }
  1760. void BigInteger::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet)
  1761. {
  1762. if (numBits > 32)
  1763. {
  1764. jassertfalse
  1765. numBits = 32;
  1766. }
  1767. for (int i = 0; i < numBits; ++i)
  1768. {
  1769. setBit (startBit + i, (valueToSet & 1) != 0);
  1770. valueToSet >>= 1;
  1771. }
  1772. }
  1773. void BigInteger::clear()
  1774. {
  1775. if (numValues > 16)
  1776. {
  1777. numValues = 4;
  1778. values.calloc (numValues + 1);
  1779. }
  1780. else
  1781. {
  1782. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1783. }
  1784. highestBit = -1;
  1785. negative = false;
  1786. }
  1787. void BigInteger::setBit (const int bit)
  1788. {
  1789. if (bit >= 0)
  1790. {
  1791. if (bit > highestBit)
  1792. {
  1793. ensureSize (bit >> 5);
  1794. highestBit = bit;
  1795. }
  1796. values [bit >> 5] |= (1 << (bit & 31));
  1797. }
  1798. }
  1799. void BigInteger::setBit (const int bit, const bool shouldBeSet)
  1800. {
  1801. if (shouldBeSet)
  1802. setBit (bit);
  1803. else
  1804. clearBit (bit);
  1805. }
  1806. void BigInteger::clearBit (const int bit) throw()
  1807. {
  1808. if (bit >= 0 && bit <= highestBit)
  1809. values [bit >> 5] &= ~(1 << (bit & 31));
  1810. }
  1811. void BigInteger::setRange (int startBit, int numBits, const bool shouldBeSet)
  1812. {
  1813. while (--numBits >= 0)
  1814. setBit (startBit++, shouldBeSet);
  1815. }
  1816. void BigInteger::insertBit (const int bit, const bool shouldBeSet)
  1817. {
  1818. if (bit >= 0)
  1819. shiftBits (1, bit);
  1820. setBit (bit, shouldBeSet);
  1821. }
  1822. bool BigInteger::isZero() const throw()
  1823. {
  1824. return getHighestBit() < 0;
  1825. }
  1826. bool BigInteger::isOne() const throw()
  1827. {
  1828. return getHighestBit() == 0 && ! negative;
  1829. }
  1830. bool BigInteger::isNegative() const throw()
  1831. {
  1832. return negative && ! isZero();
  1833. }
  1834. void BigInteger::setNegative (const bool neg) throw()
  1835. {
  1836. negative = neg;
  1837. }
  1838. void BigInteger::negate() throw()
  1839. {
  1840. negative = (! negative) && ! isZero();
  1841. }
  1842. int BigInteger::countNumberOfSetBits() const throw()
  1843. {
  1844. int total = 0;
  1845. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  1846. {
  1847. unsigned int n = values[i];
  1848. if (n == 0xffffffff)
  1849. {
  1850. total += 32;
  1851. }
  1852. else
  1853. {
  1854. while (n != 0)
  1855. {
  1856. total += (n & 1);
  1857. n >>= 1;
  1858. }
  1859. }
  1860. }
  1861. return total;
  1862. }
  1863. int BigInteger::getHighestBit() const throw()
  1864. {
  1865. for (int i = highestBit + 1; --i >= 0;)
  1866. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1867. return i;
  1868. return -1;
  1869. }
  1870. int BigInteger::findNextSetBit (int i) const throw()
  1871. {
  1872. for (; i <= highestBit; ++i)
  1873. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1874. return i;
  1875. return -1;
  1876. }
  1877. int BigInteger::findNextClearBit (int i) const throw()
  1878. {
  1879. for (; i <= highestBit; ++i)
  1880. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  1881. break;
  1882. return i;
  1883. }
  1884. BigInteger& BigInteger::operator+= (const BigInteger& other)
  1885. {
  1886. if (other.isNegative())
  1887. return operator-= (-other);
  1888. if (isNegative())
  1889. {
  1890. if (compareAbsolute (other) < 0)
  1891. {
  1892. BigInteger temp (*this);
  1893. temp.negate();
  1894. *this = other;
  1895. operator-= (temp);
  1896. }
  1897. else
  1898. {
  1899. negate();
  1900. operator-= (other);
  1901. negate();
  1902. }
  1903. }
  1904. else
  1905. {
  1906. if (other.highestBit > highestBit)
  1907. highestBit = other.highestBit;
  1908. ++highestBit;
  1909. const int numInts = (highestBit >> 5) + 1;
  1910. ensureSize (numInts);
  1911. int64 remainder = 0;
  1912. for (int i = 0; i <= numInts; ++i)
  1913. {
  1914. if (i < numValues)
  1915. remainder += values[i];
  1916. if (i < other.numValues)
  1917. remainder += other.values[i];
  1918. values[i] = (unsigned int) remainder;
  1919. remainder >>= 32;
  1920. }
  1921. jassert (remainder == 0);
  1922. highestBit = getHighestBit();
  1923. }
  1924. return *this;
  1925. }
  1926. BigInteger& BigInteger::operator-= (const BigInteger& other)
  1927. {
  1928. if (other.isNegative())
  1929. return operator+= (-other);
  1930. if (! isNegative())
  1931. {
  1932. if (compareAbsolute (other) < 0)
  1933. {
  1934. BigInteger temp (other);
  1935. swapWith (temp);
  1936. operator-= (temp);
  1937. negate();
  1938. return *this;
  1939. }
  1940. }
  1941. else
  1942. {
  1943. negate();
  1944. operator+= (other);
  1945. negate();
  1946. return *this;
  1947. }
  1948. const int numInts = (highestBit >> 5) + 1;
  1949. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1950. int64 amountToSubtract = 0;
  1951. for (int i = 0; i <= numInts; ++i)
  1952. {
  1953. if (i <= maxOtherInts)
  1954. amountToSubtract += (int64) other.values[i];
  1955. if (values[i] >= amountToSubtract)
  1956. {
  1957. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1958. amountToSubtract = 0;
  1959. }
  1960. else
  1961. {
  1962. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1963. values[i] = (unsigned int) n;
  1964. amountToSubtract = 1;
  1965. }
  1966. }
  1967. return *this;
  1968. }
  1969. BigInteger& BigInteger::operator*= (const BigInteger& other)
  1970. {
  1971. BigInteger total;
  1972. highestBit = getHighestBit();
  1973. const bool wasNegative = isNegative();
  1974. setNegative (false);
  1975. for (int i = 0; i <= highestBit; ++i)
  1976. {
  1977. if (operator[](i))
  1978. {
  1979. BigInteger n (other);
  1980. n.setNegative (false);
  1981. n <<= i;
  1982. total += n;
  1983. }
  1984. }
  1985. total.setNegative (wasNegative ^ other.isNegative());
  1986. swapWith (total);
  1987. return *this;
  1988. }
  1989. void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
  1990. {
  1991. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1992. const int divHB = divisor.getHighestBit();
  1993. const int ourHB = getHighestBit();
  1994. if (divHB < 0 || ourHB < 0)
  1995. {
  1996. // division by zero
  1997. remainder.clear();
  1998. clear();
  1999. }
  2000. else
  2001. {
  2002. const bool wasNegative = isNegative();
  2003. swapWith (remainder);
  2004. remainder.setNegative (false);
  2005. clear();
  2006. BigInteger temp (divisor);
  2007. temp.setNegative (false);
  2008. int leftShift = ourHB - divHB;
  2009. temp <<= leftShift;
  2010. while (leftShift >= 0)
  2011. {
  2012. if (remainder.compareAbsolute (temp) >= 0)
  2013. {
  2014. remainder -= temp;
  2015. setBit (leftShift);
  2016. }
  2017. if (--leftShift >= 0)
  2018. temp >>= 1;
  2019. }
  2020. negative = wasNegative ^ divisor.isNegative();
  2021. remainder.setNegative (wasNegative);
  2022. }
  2023. }
  2024. BigInteger& BigInteger::operator/= (const BigInteger& other)
  2025. {
  2026. BigInteger remainder;
  2027. divideBy (other, remainder);
  2028. return *this;
  2029. }
  2030. BigInteger& BigInteger::operator|= (const BigInteger& other)
  2031. {
  2032. // this operation doesn't take into account negative values..
  2033. jassert (isNegative() == other.isNegative());
  2034. if (other.highestBit >= 0)
  2035. {
  2036. ensureSize (other.highestBit >> 5);
  2037. int n = (other.highestBit >> 5) + 1;
  2038. while (--n >= 0)
  2039. values[n] |= other.values[n];
  2040. if (other.highestBit > highestBit)
  2041. highestBit = other.highestBit;
  2042. highestBit = getHighestBit();
  2043. }
  2044. return *this;
  2045. }
  2046. BigInteger& BigInteger::operator&= (const BigInteger& other)
  2047. {
  2048. // this operation doesn't take into account negative values..
  2049. jassert (isNegative() == other.isNegative());
  2050. int n = numValues;
  2051. while (n > other.numValues)
  2052. values[--n] = 0;
  2053. while (--n >= 0)
  2054. values[n] &= other.values[n];
  2055. if (other.highestBit < highestBit)
  2056. highestBit = other.highestBit;
  2057. highestBit = getHighestBit();
  2058. return *this;
  2059. }
  2060. BigInteger& BigInteger::operator^= (const BigInteger& other)
  2061. {
  2062. // this operation will only work with the absolute values
  2063. jassert (isNegative() == other.isNegative());
  2064. if (other.highestBit >= 0)
  2065. {
  2066. ensureSize (other.highestBit >> 5);
  2067. int n = (other.highestBit >> 5) + 1;
  2068. while (--n >= 0)
  2069. values[n] ^= other.values[n];
  2070. if (other.highestBit > highestBit)
  2071. highestBit = other.highestBit;
  2072. highestBit = getHighestBit();
  2073. }
  2074. return *this;
  2075. }
  2076. BigInteger& BigInteger::operator%= (const BigInteger& divisor)
  2077. {
  2078. BigInteger remainder;
  2079. divideBy (divisor, remainder);
  2080. swapWith (remainder);
  2081. return *this;
  2082. }
  2083. BigInteger& BigInteger::operator<<= (int numBitsToShift)
  2084. {
  2085. shiftBits (numBitsToShift, 0);
  2086. return *this;
  2087. }
  2088. BigInteger& BigInteger::operator>>= (int numBitsToShift)
  2089. {
  2090. return operator<<= (-numBitsToShift);
  2091. }
  2092. BigInteger& BigInteger::operator++() { return operator+= (1); }
  2093. BigInteger& BigInteger::operator--() { return operator-= (1); }
  2094. const BigInteger BigInteger::operator++ (int) { const BigInteger old (*this); operator+= (1); return old; }
  2095. const BigInteger BigInteger::operator-- (int) { const BigInteger old (*this); operator-= (1); return old; }
  2096. const BigInteger BigInteger::operator+ (const BigInteger& other) const { BigInteger b (*this); return b += other; }
  2097. const BigInteger BigInteger::operator- (const BigInteger& other) const { BigInteger b (*this); return b -= other; }
  2098. const BigInteger BigInteger::operator* (const BigInteger& other) const { BigInteger b (*this); return b *= other; }
  2099. const BigInteger BigInteger::operator/ (const BigInteger& other) const { BigInteger b (*this); return b /= other; }
  2100. const BigInteger BigInteger::operator| (const BigInteger& other) const { BigInteger b (*this); return b |= other; }
  2101. const BigInteger BigInteger::operator& (const BigInteger& other) const { BigInteger b (*this); return b &= other; }
  2102. const BigInteger BigInteger::operator^ (const BigInteger& other) const { BigInteger b (*this); return b ^= other; }
  2103. const BigInteger BigInteger::operator% (const BigInteger& other) const { BigInteger b (*this); return b %= other; }
  2104. const BigInteger BigInteger::operator<< (const int numBits) const { BigInteger b (*this); return b <<= numBits; }
  2105. const BigInteger BigInteger::operator>> (const int numBits) const { BigInteger b (*this); return b >>= numBits; }
  2106. const BigInteger BigInteger::operator-() const { BigInteger b (*this); b.negate(); return b; }
  2107. int BigInteger::compare (const BigInteger& other) const throw()
  2108. {
  2109. if (isNegative() == other.isNegative())
  2110. {
  2111. const int absComp = compareAbsolute (other);
  2112. return isNegative() ? -absComp : absComp;
  2113. }
  2114. else
  2115. {
  2116. return isNegative() ? -1 : 1;
  2117. }
  2118. }
  2119. int BigInteger::compareAbsolute (const BigInteger& other) const throw()
  2120. {
  2121. const int h1 = getHighestBit();
  2122. const int h2 = other.getHighestBit();
  2123. if (h1 > h2)
  2124. return 1;
  2125. else if (h1 < h2)
  2126. return -1;
  2127. for (int i = (h1 >> 5) + 1; --i >= 0;)
  2128. if (values[i] != other.values[i])
  2129. return (values[i] > other.values[i]) ? 1 : -1;
  2130. return 0;
  2131. }
  2132. bool BigInteger::operator== (const BigInteger& other) const throw() { return compare (other) == 0; }
  2133. bool BigInteger::operator!= (const BigInteger& other) const throw() { return compare (other) != 0; }
  2134. bool BigInteger::operator< (const BigInteger& other) const throw() { return compare (other) < 0; }
  2135. bool BigInteger::operator<= (const BigInteger& other) const throw() { return compare (other) <= 0; }
  2136. bool BigInteger::operator> (const BigInteger& other) const throw() { return compare (other) > 0; }
  2137. bool BigInteger::operator>= (const BigInteger& other) const throw() { return compare (other) >= 0; }
  2138. void BigInteger::shiftBits (int bits, const int startBit)
  2139. {
  2140. if (highestBit < 0)
  2141. return;
  2142. if (startBit > 0)
  2143. {
  2144. if (bits < 0)
  2145. {
  2146. // right shift
  2147. for (int i = startBit; i <= highestBit; ++i)
  2148. setBit (i, operator[] (i - bits));
  2149. highestBit = getHighestBit();
  2150. }
  2151. else if (bits > 0)
  2152. {
  2153. // left shift
  2154. for (int i = highestBit + 1; --i >= startBit;)
  2155. setBit (i + bits, operator[] (i));
  2156. while (--bits >= 0)
  2157. clearBit (bits + startBit);
  2158. }
  2159. }
  2160. else
  2161. {
  2162. if (bits < 0)
  2163. {
  2164. // right shift
  2165. bits = -bits;
  2166. if (bits > highestBit)
  2167. {
  2168. clear();
  2169. }
  2170. else
  2171. {
  2172. const int wordsToMove = bits >> 5;
  2173. int top = 1 + (highestBit >> 5) - wordsToMove;
  2174. highestBit -= bits;
  2175. if (wordsToMove > 0)
  2176. {
  2177. int i;
  2178. for (i = 0; i < top; ++i)
  2179. values [i] = values [i + wordsToMove];
  2180. for (i = 0; i < wordsToMove; ++i)
  2181. values [top + i] = 0;
  2182. bits &= 31;
  2183. }
  2184. if (bits != 0)
  2185. {
  2186. const int invBits = 32 - bits;
  2187. --top;
  2188. for (int i = 0; i < top; ++i)
  2189. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2190. values[top] = (values[top] >> bits);
  2191. }
  2192. highestBit = getHighestBit();
  2193. }
  2194. }
  2195. else if (bits > 0)
  2196. {
  2197. // left shift
  2198. ensureSize (((highestBit + bits) >> 5) + 1);
  2199. const int wordsToMove = bits >> 5;
  2200. int top = 1 + (highestBit >> 5);
  2201. highestBit += bits;
  2202. if (wordsToMove > 0)
  2203. {
  2204. int i;
  2205. for (i = top; --i >= 0;)
  2206. values [i + wordsToMove] = values [i];
  2207. for (i = 0; i < wordsToMove; ++i)
  2208. values [i] = 0;
  2209. bits &= 31;
  2210. }
  2211. if (bits != 0)
  2212. {
  2213. const int invBits = 32 - bits;
  2214. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2215. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2216. values [wordsToMove] = values [wordsToMove] << bits;
  2217. }
  2218. highestBit = getHighestBit();
  2219. }
  2220. }
  2221. }
  2222. const BigInteger BigInteger::simpleGCD (BigInteger* m, BigInteger* n)
  2223. {
  2224. while (! m->isZero())
  2225. {
  2226. if (n->compareAbsolute (*m) > 0)
  2227. swapVariables (m, n);
  2228. *m -= *n;
  2229. }
  2230. return *n;
  2231. }
  2232. const BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
  2233. {
  2234. BigInteger m (*this);
  2235. while (! n.isZero())
  2236. {
  2237. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  2238. return simpleGCD (&m, &n);
  2239. BigInteger temp1 (m), temp2;
  2240. temp1.divideBy (n, temp2);
  2241. m = n;
  2242. n = temp2;
  2243. }
  2244. return m;
  2245. }
  2246. void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
  2247. {
  2248. BigInteger exp (exponent);
  2249. exp %= modulus;
  2250. BigInteger value (1);
  2251. swapWith (value);
  2252. value %= modulus;
  2253. while (! exp.isZero())
  2254. {
  2255. if (exp [0])
  2256. {
  2257. operator*= (value);
  2258. operator%= (modulus);
  2259. }
  2260. value *= value;
  2261. value %= modulus;
  2262. exp >>= 1;
  2263. }
  2264. }
  2265. void BigInteger::inverseModulo (const BigInteger& modulus)
  2266. {
  2267. if (modulus.isOne() || modulus.isNegative())
  2268. {
  2269. clear();
  2270. return;
  2271. }
  2272. if (isNegative() || compareAbsolute (modulus) >= 0)
  2273. operator%= (modulus);
  2274. if (isOne())
  2275. return;
  2276. if (! (*this)[0])
  2277. {
  2278. // not invertible
  2279. clear();
  2280. return;
  2281. }
  2282. BigInteger a1 (modulus);
  2283. BigInteger a2 (*this);
  2284. BigInteger b1 (modulus);
  2285. BigInteger b2 (1);
  2286. while (! a2.isOne())
  2287. {
  2288. BigInteger temp1, temp2, multiplier (a1);
  2289. multiplier.divideBy (a2, temp1);
  2290. temp1 = a2;
  2291. temp1 *= multiplier;
  2292. temp2 = a1;
  2293. temp2 -= temp1;
  2294. a1 = a2;
  2295. a2 = temp2;
  2296. temp1 = b2;
  2297. temp1 *= multiplier;
  2298. temp2 = b1;
  2299. temp2 -= temp1;
  2300. b1 = b2;
  2301. b2 = temp2;
  2302. }
  2303. while (b2.isNegative())
  2304. b2 += modulus;
  2305. b2 %= modulus;
  2306. swapWith (b2);
  2307. }
  2308. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger& value)
  2309. {
  2310. return stream << value.toString (10);
  2311. }
  2312. const String BigInteger::toString (const int base, const int minimumNumCharacters) const
  2313. {
  2314. String s;
  2315. BigInteger v (*this);
  2316. if (base == 2 || base == 8 || base == 16)
  2317. {
  2318. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2319. static const char* const hexDigits = "0123456789abcdef";
  2320. for (;;)
  2321. {
  2322. const int remainder = v.getBitRangeAsInt (0, bits);
  2323. v >>= bits;
  2324. if (remainder == 0 && v.isZero())
  2325. break;
  2326. s = String::charToString (hexDigits [remainder]) + s;
  2327. }
  2328. }
  2329. else if (base == 10)
  2330. {
  2331. const BigInteger ten (10);
  2332. BigInteger remainder;
  2333. for (;;)
  2334. {
  2335. v.divideBy (ten, remainder);
  2336. if (remainder.isZero() && v.isZero())
  2337. break;
  2338. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2339. }
  2340. }
  2341. else
  2342. {
  2343. jassertfalse // can't do the specified base!
  2344. return String::empty;
  2345. }
  2346. s = s.paddedLeft ('0', minimumNumCharacters);
  2347. return isNegative() ? "-" + s : s;
  2348. }
  2349. void BigInteger::parseString (const String& text, const int base)
  2350. {
  2351. clear();
  2352. const juce_wchar* t = (const juce_wchar*) text;
  2353. if (base == 2 || base == 8 || base == 16)
  2354. {
  2355. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2356. for (;;)
  2357. {
  2358. const juce_wchar c = *t++;
  2359. const int digit = CharacterFunctions::getHexDigitValue (c);
  2360. if (((unsigned int) digit) < (unsigned int) base)
  2361. {
  2362. operator<<= (bits);
  2363. operator+= (digit);
  2364. }
  2365. else if (c == 0)
  2366. {
  2367. break;
  2368. }
  2369. }
  2370. }
  2371. else if (base == 10)
  2372. {
  2373. const BigInteger ten ((unsigned int) 10);
  2374. for (;;)
  2375. {
  2376. const juce_wchar c = *t++;
  2377. if (c >= '0' && c <= '9')
  2378. {
  2379. operator*= (ten);
  2380. operator+= ((int) (c - '0'));
  2381. }
  2382. else if (c == 0)
  2383. {
  2384. break;
  2385. }
  2386. }
  2387. }
  2388. setNegative (text.trimStart().startsWithChar ('-'));
  2389. }
  2390. const MemoryBlock BigInteger::toMemoryBlock() const
  2391. {
  2392. const int numBytes = (getHighestBit() + 8) >> 3;
  2393. MemoryBlock mb ((size_t) numBytes);
  2394. for (int i = 0; i < numBytes; ++i)
  2395. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2396. return mb;
  2397. }
  2398. void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
  2399. {
  2400. clear();
  2401. for (int i = (int) data.getSize(); --i >= 0;)
  2402. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2403. }
  2404. END_JUCE_NAMESPACE
  2405. /*** End of inlined file: juce_BitArray.cpp ***/
  2406. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2407. BEGIN_JUCE_NAMESPACE
  2408. MemoryBlock::MemoryBlock() throw()
  2409. : size (0)
  2410. {
  2411. }
  2412. MemoryBlock::MemoryBlock (const size_t initialSize,
  2413. const bool initialiseToZero) throw()
  2414. {
  2415. if (initialSize > 0)
  2416. {
  2417. size = initialSize;
  2418. data.allocate (initialSize, initialiseToZero);
  2419. }
  2420. else
  2421. {
  2422. size = 0;
  2423. }
  2424. }
  2425. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2426. : size (other.size)
  2427. {
  2428. if (size > 0)
  2429. {
  2430. jassert (other.data != 0);
  2431. data.malloc (size);
  2432. memcpy (data, other.data, size);
  2433. }
  2434. }
  2435. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2436. const size_t sizeInBytes) throw()
  2437. : size (jmax ((size_t) 0, sizeInBytes))
  2438. {
  2439. jassert (sizeInBytes >= 0);
  2440. if (size > 0)
  2441. {
  2442. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2443. data.malloc (size);
  2444. if (dataToInitialiseFrom != 0)
  2445. memcpy (data, dataToInitialiseFrom, size);
  2446. }
  2447. }
  2448. MemoryBlock::~MemoryBlock() throw()
  2449. {
  2450. jassert (size >= 0); // should never happen
  2451. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2452. }
  2453. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2454. {
  2455. if (this != &other)
  2456. {
  2457. setSize (other.size, false);
  2458. memcpy (data, other.data, size);
  2459. }
  2460. return *this;
  2461. }
  2462. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2463. {
  2464. return matches (other.data, other.size);
  2465. }
  2466. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2467. {
  2468. return ! operator== (other);
  2469. }
  2470. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2471. {
  2472. return size == dataSize
  2473. && memcmp (data, dataToCompare, size) == 0;
  2474. }
  2475. // this will resize the block to this size
  2476. void MemoryBlock::setSize (const size_t newSize,
  2477. const bool initialiseToZero) throw()
  2478. {
  2479. if (size != newSize)
  2480. {
  2481. if (newSize <= 0)
  2482. {
  2483. data.free();
  2484. size = 0;
  2485. }
  2486. else
  2487. {
  2488. if (data != 0)
  2489. {
  2490. data.realloc (newSize);
  2491. if (initialiseToZero && (newSize > size))
  2492. zeromem (data + size, newSize - size);
  2493. }
  2494. else
  2495. {
  2496. data.allocate (newSize, initialiseToZero);
  2497. }
  2498. size = newSize;
  2499. }
  2500. }
  2501. }
  2502. void MemoryBlock::ensureSize (const size_t minimumSize,
  2503. const bool initialiseToZero) throw()
  2504. {
  2505. if (size < minimumSize)
  2506. setSize (minimumSize, initialiseToZero);
  2507. }
  2508. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2509. {
  2510. swapVariables (size, other.size);
  2511. data.swapWith (other.data);
  2512. }
  2513. void MemoryBlock::fillWith (const uint8 value) throw()
  2514. {
  2515. memset (data, (int) value, size);
  2516. }
  2517. void MemoryBlock::append (const void* const srcData,
  2518. const size_t numBytes) throw()
  2519. {
  2520. if (numBytes > 0)
  2521. {
  2522. const size_t oldSize = size;
  2523. setSize (size + numBytes);
  2524. memcpy (data + oldSize, srcData, numBytes);
  2525. }
  2526. }
  2527. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2528. {
  2529. const char* d = static_cast<const char*> (src);
  2530. if (offset < 0)
  2531. {
  2532. d -= offset;
  2533. num -= offset;
  2534. offset = 0;
  2535. }
  2536. if (offset + num > size)
  2537. num = size - offset;
  2538. if (num > 0)
  2539. memcpy (data + offset, d, num);
  2540. }
  2541. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2542. {
  2543. char* d = static_cast<char*> (dst);
  2544. if (offset < 0)
  2545. {
  2546. zeromem (d, -offset);
  2547. d -= offset;
  2548. num += offset;
  2549. offset = 0;
  2550. }
  2551. if (offset + num > size)
  2552. {
  2553. const size_t newNum = size - offset;
  2554. zeromem (d + newNum, num - newNum);
  2555. num = newNum;
  2556. }
  2557. if (num > 0)
  2558. memcpy (d, data + offset, num);
  2559. }
  2560. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2561. {
  2562. if (startByte < 0)
  2563. {
  2564. numBytesToRemove += startByte;
  2565. startByte = 0;
  2566. }
  2567. if (startByte + numBytesToRemove >= size)
  2568. {
  2569. setSize (startByte);
  2570. }
  2571. else if (numBytesToRemove > 0)
  2572. {
  2573. memmove (data + startByte,
  2574. data + startByte + numBytesToRemove,
  2575. size - (startByte + numBytesToRemove));
  2576. setSize (size - numBytesToRemove);
  2577. }
  2578. }
  2579. const String MemoryBlock::toString() const throw()
  2580. {
  2581. return String ((const char*) data, size);
  2582. }
  2583. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2584. {
  2585. int res = 0;
  2586. size_t byte = bitRangeStart >> 3;
  2587. int offsetInByte = (int) bitRangeStart & 7;
  2588. size_t bitsSoFar = 0;
  2589. while (numBits > 0 && (size_t) byte < size)
  2590. {
  2591. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2592. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2593. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2594. bitsSoFar += bitsThisTime;
  2595. numBits -= bitsThisTime;
  2596. ++byte;
  2597. offsetInByte = 0;
  2598. }
  2599. return res;
  2600. }
  2601. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2602. {
  2603. size_t byte = bitRangeStart >> 3;
  2604. int offsetInByte = (int) bitRangeStart & 7;
  2605. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2606. while (numBits > 0 && (size_t) byte < size)
  2607. {
  2608. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2609. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2610. const unsigned int tempBits = bitsToSet << offsetInByte;
  2611. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2612. ++byte;
  2613. numBits -= bitsThisTime;
  2614. bitsToSet >>= bitsThisTime;
  2615. mask >>= bitsThisTime;
  2616. offsetInByte = 0;
  2617. }
  2618. }
  2619. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2620. {
  2621. ensureSize (hex.length() >> 1);
  2622. char* dest = data;
  2623. int i = 0;
  2624. for (;;)
  2625. {
  2626. int byte = 0;
  2627. for (int loop = 2; --loop >= 0;)
  2628. {
  2629. byte <<= 4;
  2630. for (;;)
  2631. {
  2632. const juce_wchar c = hex [i++];
  2633. if (c >= '0' && c <= '9')
  2634. {
  2635. byte |= c - '0';
  2636. break;
  2637. }
  2638. else if (c >= 'a' && c <= 'z')
  2639. {
  2640. byte |= c - ('a' - 10);
  2641. break;
  2642. }
  2643. else if (c >= 'A' && c <= 'Z')
  2644. {
  2645. byte |= c - ('A' - 10);
  2646. break;
  2647. }
  2648. else if (c == 0)
  2649. {
  2650. setSize (static_cast <size_t> (dest - data));
  2651. return;
  2652. }
  2653. }
  2654. }
  2655. *dest++ = (char) byte;
  2656. }
  2657. }
  2658. static const char* const encodingTable
  2659. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2660. const String MemoryBlock::toBase64Encoding() const throw()
  2661. {
  2662. const size_t numChars = ((size << 3) + 5) / 6;
  2663. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2664. const int initialLen = destString.length();
  2665. destString.preallocateStorage (initialLen + 2 + numChars);
  2666. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2667. *d++ = '.';
  2668. for (size_t i = 0; i < numChars; ++i)
  2669. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2670. *d++ = 0;
  2671. return destString;
  2672. }
  2673. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2674. {
  2675. const int startPos = s.indexOfChar ('.') + 1;
  2676. if (startPos <= 0)
  2677. return false;
  2678. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2679. setSize (numBytesNeeded, true);
  2680. const int numChars = s.length() - startPos;
  2681. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2682. int pos = 0;
  2683. for (int i = 0; i < numChars; ++i)
  2684. {
  2685. const char c = (char) srcChars[i];
  2686. for (int j = 0; j < 64; ++j)
  2687. {
  2688. if (encodingTable[j] == c)
  2689. {
  2690. setBitRange (pos, 6, j);
  2691. pos += 6;
  2692. break;
  2693. }
  2694. }
  2695. }
  2696. return true;
  2697. }
  2698. END_JUCE_NAMESPACE
  2699. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2700. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2701. BEGIN_JUCE_NAMESPACE
  2702. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2703. : properties (ignoreCaseOfKeyNames),
  2704. fallbackProperties (0),
  2705. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2706. {
  2707. }
  2708. PropertySet::PropertySet (const PropertySet& other) throw()
  2709. : properties (other.properties),
  2710. fallbackProperties (other.fallbackProperties),
  2711. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2712. {
  2713. }
  2714. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2715. {
  2716. properties = other.properties;
  2717. fallbackProperties = other.fallbackProperties;
  2718. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2719. propertyChanged();
  2720. return *this;
  2721. }
  2722. PropertySet::~PropertySet()
  2723. {
  2724. }
  2725. void PropertySet::clear()
  2726. {
  2727. const ScopedLock sl (lock);
  2728. if (properties.size() > 0)
  2729. {
  2730. properties.clear();
  2731. propertyChanged();
  2732. }
  2733. }
  2734. const String PropertySet::getValue (const String& keyName,
  2735. const String& defaultValue) const throw()
  2736. {
  2737. const ScopedLock sl (lock);
  2738. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2739. if (index >= 0)
  2740. return properties.getAllValues() [index];
  2741. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2742. : defaultValue;
  2743. }
  2744. int PropertySet::getIntValue (const String& keyName,
  2745. const int defaultValue) const throw()
  2746. {
  2747. const ScopedLock sl (lock);
  2748. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2749. if (index >= 0)
  2750. return properties.getAllValues() [index].getIntValue();
  2751. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2752. : defaultValue;
  2753. }
  2754. double PropertySet::getDoubleValue (const String& keyName,
  2755. const double defaultValue) const throw()
  2756. {
  2757. const ScopedLock sl (lock);
  2758. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2759. if (index >= 0)
  2760. return properties.getAllValues()[index].getDoubleValue();
  2761. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2762. : defaultValue;
  2763. }
  2764. bool PropertySet::getBoolValue (const String& keyName,
  2765. const bool defaultValue) const throw()
  2766. {
  2767. const ScopedLock sl (lock);
  2768. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2769. if (index >= 0)
  2770. return properties.getAllValues() [index].getIntValue() != 0;
  2771. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2772. : defaultValue;
  2773. }
  2774. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2775. {
  2776. XmlDocument doc (getValue (keyName));
  2777. return doc.getDocumentElement();
  2778. }
  2779. void PropertySet::setValue (const String& keyName,
  2780. const String& value) throw()
  2781. {
  2782. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2783. if (keyName.isNotEmpty())
  2784. {
  2785. const ScopedLock sl (lock);
  2786. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2787. if (index < 0 || properties.getAllValues() [index] != value)
  2788. {
  2789. properties.set (keyName, value);
  2790. propertyChanged();
  2791. }
  2792. }
  2793. }
  2794. void PropertySet::removeValue (const String& keyName) throw()
  2795. {
  2796. if (keyName.isNotEmpty())
  2797. {
  2798. const ScopedLock sl (lock);
  2799. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2800. if (index >= 0)
  2801. {
  2802. properties.remove (keyName);
  2803. propertyChanged();
  2804. }
  2805. }
  2806. }
  2807. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2808. {
  2809. setValue (keyName, String (value));
  2810. }
  2811. void PropertySet::setValue (const String& keyName, const int value) throw()
  2812. {
  2813. setValue (keyName, String (value));
  2814. }
  2815. void PropertySet::setValue (const String& keyName, const double value) throw()
  2816. {
  2817. setValue (keyName, String (value));
  2818. }
  2819. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2820. {
  2821. setValue (keyName, String (value ? "1" : "0"));
  2822. }
  2823. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2824. {
  2825. setValue (keyName, (xml == 0) ? String::empty
  2826. : xml->createDocument (String::empty, true));
  2827. }
  2828. bool PropertySet::containsKey (const String& keyName) const throw()
  2829. {
  2830. const ScopedLock sl (lock);
  2831. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2832. }
  2833. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2834. {
  2835. const ScopedLock sl (lock);
  2836. fallbackProperties = fallbackProperties_;
  2837. }
  2838. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2839. {
  2840. const ScopedLock sl (lock);
  2841. XmlElement* const xml = new XmlElement (nodeName);
  2842. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2843. {
  2844. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2845. e->setAttribute ("name", properties.getAllKeys()[i]);
  2846. e->setAttribute ("val", properties.getAllValues()[i]);
  2847. }
  2848. return xml;
  2849. }
  2850. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2851. {
  2852. const ScopedLock sl (lock);
  2853. clear();
  2854. forEachXmlChildElementWithTagName (xml, e, "VALUE")
  2855. {
  2856. if (e->hasAttribute ("name")
  2857. && e->hasAttribute ("val"))
  2858. {
  2859. properties.set (e->getStringAttribute ("name"),
  2860. e->getStringAttribute ("val"));
  2861. }
  2862. }
  2863. if (properties.size() > 0)
  2864. propertyChanged();
  2865. }
  2866. void PropertySet::propertyChanged()
  2867. {
  2868. }
  2869. END_JUCE_NAMESPACE
  2870. /*** End of inlined file: juce_PropertySet.cpp ***/
  2871. /*** Start of inlined file: juce_Variant.cpp ***/
  2872. BEGIN_JUCE_NAMESPACE
  2873. var::var() throw()
  2874. : type (voidType)
  2875. {
  2876. value.doubleValue = 0;
  2877. }
  2878. var::~var() throw()
  2879. {
  2880. if (type == stringType)
  2881. delete value.stringValue;
  2882. else if (type == objectType && value.objectValue != 0)
  2883. value.objectValue->decReferenceCount();
  2884. }
  2885. const var var::null;
  2886. var::var (const var& valueToCopy)
  2887. : type (valueToCopy.type),
  2888. value (valueToCopy.value)
  2889. {
  2890. if (type == stringType)
  2891. value.stringValue = new String (*(value.stringValue));
  2892. else if (type == objectType && value.objectValue != 0)
  2893. value.objectValue->incReferenceCount();
  2894. }
  2895. var::var (const int value_) throw()
  2896. : type (intType)
  2897. {
  2898. value.intValue = value_;
  2899. }
  2900. var::var (const bool value_) throw()
  2901. : type (boolType)
  2902. {
  2903. value.boolValue = value_;
  2904. }
  2905. var::var (const double value_) throw()
  2906. : type (doubleType)
  2907. {
  2908. value.doubleValue = value_;
  2909. }
  2910. var::var (const String& value_)
  2911. : type (stringType)
  2912. {
  2913. value.stringValue = new String (value_);
  2914. }
  2915. var::var (const char* const value_)
  2916. : type (stringType)
  2917. {
  2918. value.stringValue = new String (value_);
  2919. }
  2920. var::var (const juce_wchar* const value_)
  2921. : type (stringType)
  2922. {
  2923. value.stringValue = new String (value_);
  2924. }
  2925. var::var (DynamicObject* const object)
  2926. : type (objectType)
  2927. {
  2928. value.objectValue = object;
  2929. if (object != 0)
  2930. object->incReferenceCount();
  2931. }
  2932. var::var (MethodFunction method_) throw()
  2933. : type (methodType)
  2934. {
  2935. value.methodValue = method_;
  2936. }
  2937. void var::swapWith (var& other) throw()
  2938. {
  2939. swapVariables (type, other.type);
  2940. swapVariables (value, other.value);
  2941. }
  2942. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2943. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2944. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2945. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2946. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2947. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2948. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2949. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2950. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2951. var::operator int() const
  2952. {
  2953. switch (type)
  2954. {
  2955. case voidType: break;
  2956. case intType: return value.intValue;
  2957. case boolType: return value.boolValue ? 1 : 0;
  2958. case doubleType: return static_cast <int> (value.doubleValue);
  2959. case stringType: return value.stringValue->getIntValue();
  2960. case objectType: break;
  2961. default: jassertfalse; break;
  2962. }
  2963. return 0;
  2964. }
  2965. var::operator bool() const
  2966. {
  2967. switch (type)
  2968. {
  2969. case voidType: break;
  2970. case intType: return value.intValue != 0;
  2971. case boolType: return value.boolValue;
  2972. case doubleType: return value.doubleValue != 0;
  2973. case stringType: return value.stringValue->getIntValue() != 0
  2974. || value.stringValue->trim().equalsIgnoreCase ("true")
  2975. || value.stringValue->trim().equalsIgnoreCase ("yes");
  2976. case objectType: return value.objectValue != 0;
  2977. default: jassertfalse; break;
  2978. }
  2979. return false;
  2980. }
  2981. var::operator float() const
  2982. {
  2983. return (float) operator double();
  2984. }
  2985. var::operator double() const
  2986. {
  2987. switch (type)
  2988. {
  2989. case voidType: break;
  2990. case intType: return value.intValue;
  2991. case boolType: return value.boolValue ? 1.0 : 0.0;
  2992. case doubleType: return value.doubleValue;
  2993. case stringType: return value.stringValue->getDoubleValue();
  2994. case objectType: break;
  2995. default: jassertfalse; break;
  2996. }
  2997. return 0.0;
  2998. }
  2999. const String var::toString() const
  3000. {
  3001. switch (type)
  3002. {
  3003. case voidType: return String::empty;
  3004. case intType: return String (value.intValue);
  3005. case boolType: return String::charToString (value.boolValue ? '1' : '0');
  3006. case doubleType: return String (value.doubleValue);
  3007. case stringType: return *(value.stringValue);
  3008. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  3009. case methodType: return "Method";
  3010. default: jassertfalse; break;
  3011. }
  3012. return String::empty;
  3013. }
  3014. var::operator const String() const
  3015. {
  3016. return toString();
  3017. }
  3018. DynamicObject* var::getObject() const
  3019. {
  3020. return type == objectType ? value.objectValue : 0;
  3021. }
  3022. bool var::equals (const var& other) const throw()
  3023. {
  3024. switch (type)
  3025. {
  3026. case voidType: return other.isVoid();
  3027. case intType: return value.intValue == static_cast <int> (other);
  3028. case boolType: return value.boolValue == static_cast <bool> (other);
  3029. case doubleType: return value.doubleValue == static_cast <double> (other);
  3030. case stringType: return (*(value.stringValue)) == other.toString();
  3031. case objectType: return value.objectValue == other.getObject();
  3032. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  3033. default: jassertfalse; break;
  3034. }
  3035. return false;
  3036. }
  3037. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  3038. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  3039. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  3040. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  3041. void var::writeToStream (OutputStream& output) const
  3042. {
  3043. switch (type)
  3044. {
  3045. case voidType: output.writeCompressedInt (0); break;
  3046. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  3047. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  3048. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  3049. case stringType:
  3050. {
  3051. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  3052. output.writeCompressedInt (len + 1);
  3053. output.writeByte (5);
  3054. HeapBlock<char> temp (len);
  3055. value.stringValue->copyToUTF8 (temp, len);
  3056. output.write (temp, len);
  3057. break;
  3058. }
  3059. case objectType:
  3060. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3061. default: jassertfalse; break; // Is this a corrupted object?
  3062. }
  3063. }
  3064. const var var::readFromStream (InputStream& input)
  3065. {
  3066. const int numBytes = input.readCompressedInt();
  3067. if (numBytes > 0)
  3068. {
  3069. switch (input.readByte())
  3070. {
  3071. case 1: return var (input.readInt());
  3072. case 2: return var (true);
  3073. case 3: return var (false);
  3074. case 4: return var (input.readDouble());
  3075. case 5:
  3076. {
  3077. MemoryBlock mb;
  3078. input.readIntoMemoryBlock (mb, numBytes - 1);
  3079. return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize()));
  3080. }
  3081. default: input.skipNextBytes (numBytes - 1); break;
  3082. }
  3083. }
  3084. return var::null;
  3085. }
  3086. const var var::operator[] (const var::identifier& propertyName) const
  3087. {
  3088. if (type == objectType && value.objectValue != 0)
  3089. return value.objectValue->getProperty (propertyName);
  3090. return var::null;
  3091. }
  3092. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3093. {
  3094. if (type == objectType && value.objectValue != 0)
  3095. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3096. return var::null;
  3097. }
  3098. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3099. {
  3100. if (isMethod())
  3101. {
  3102. DynamicObject* const target = targetObject.getObject();
  3103. if (target != 0)
  3104. return (target->*(value.methodValue)) (arguments, numArguments);
  3105. }
  3106. return var::null;
  3107. }
  3108. const var var::call (const var::identifier& method) const
  3109. {
  3110. return invoke (method, 0, 0);
  3111. }
  3112. const var var::call (const var::identifier& method, const var& arg1) const
  3113. {
  3114. return invoke (method, &arg1, 1);
  3115. }
  3116. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3117. {
  3118. var args[] = { arg1, arg2 };
  3119. return invoke (method, args, 2);
  3120. }
  3121. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3122. {
  3123. var args[] = { arg1, arg2, arg3 };
  3124. return invoke (method, args, 3);
  3125. }
  3126. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3127. {
  3128. var args[] = { arg1, arg2, arg3, arg4 };
  3129. return invoke (method, args, 4);
  3130. }
  3131. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3132. {
  3133. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3134. return invoke (method, args, 5);
  3135. }
  3136. var::identifier::identifier() throw()
  3137. : hashCode (0)
  3138. {
  3139. }
  3140. var::identifier::identifier (const String& name_)
  3141. : name (name_),
  3142. hashCode (name_.hashCode())
  3143. {
  3144. /* An identifier string must be suitable for use as a script variable or XML
  3145. attribute, so it can only contain this limited set of characters.. */
  3146. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3147. }
  3148. var::identifier::identifier (const char* const name_)
  3149. : name (name_),
  3150. hashCode (name.hashCode())
  3151. {
  3152. /* An identifier string must be suitable for use as a script variable or XML
  3153. attribute, so it can only contain this limited set of characters.. */
  3154. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3155. }
  3156. var::identifier::~identifier()
  3157. {
  3158. }
  3159. END_JUCE_NAMESPACE
  3160. /*** End of inlined file: juce_Variant.cpp ***/
  3161. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3162. BEGIN_JUCE_NAMESPACE
  3163. NamedValueSet::NamedValue::NamedValue() throw()
  3164. {
  3165. }
  3166. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3167. : name (name_), value (value_)
  3168. {
  3169. }
  3170. NamedValueSet::NamedValueSet() throw()
  3171. {
  3172. }
  3173. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3174. : values (other.values)
  3175. {
  3176. }
  3177. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3178. {
  3179. values = other.values;
  3180. return *this;
  3181. }
  3182. NamedValueSet::~NamedValueSet()
  3183. {
  3184. }
  3185. int NamedValueSet::size() const throw()
  3186. {
  3187. return values.size();
  3188. }
  3189. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3190. {
  3191. for (int i = values.size(); --i >= 0;)
  3192. {
  3193. const NamedValue& v = values.getReference(i);
  3194. if (v.name == name)
  3195. return v.value;
  3196. }
  3197. return var::null;
  3198. }
  3199. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3200. {
  3201. const var* v = getItem (name);
  3202. return v != 0 ? *v : defaultReturnValue;
  3203. }
  3204. var* NamedValueSet::getItem (const var::identifier& name) const
  3205. {
  3206. for (int i = values.size(); --i >= 0;)
  3207. {
  3208. NamedValue& v = values.getReference(i);
  3209. if (v.name == name)
  3210. return &(v.value);
  3211. }
  3212. return 0;
  3213. }
  3214. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3215. {
  3216. for (int i = values.size(); --i >= 0;)
  3217. {
  3218. NamedValue& v = values.getReference(i);
  3219. if (v.name == name)
  3220. {
  3221. if (v.value == newValue)
  3222. return false;
  3223. v.value = newValue;
  3224. return true;
  3225. }
  3226. }
  3227. values.add (NamedValue (name, newValue));
  3228. return true;
  3229. }
  3230. bool NamedValueSet::contains (const var::identifier& name) const
  3231. {
  3232. return getItem (name) != 0;
  3233. }
  3234. bool NamedValueSet::remove (const var::identifier& name)
  3235. {
  3236. for (int i = values.size(); --i >= 0;)
  3237. {
  3238. if (values.getReference(i).name == name)
  3239. {
  3240. values.remove (i);
  3241. return true;
  3242. }
  3243. }
  3244. return false;
  3245. }
  3246. const var::identifier NamedValueSet::getName (int index) const
  3247. {
  3248. jassert (((unsigned int) index) < (unsigned int) values.size());
  3249. return values [index].name;
  3250. }
  3251. void NamedValueSet::clear()
  3252. {
  3253. values.clear();
  3254. }
  3255. END_JUCE_NAMESPACE
  3256. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3257. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3258. BEGIN_JUCE_NAMESPACE
  3259. DynamicObject::DynamicObject()
  3260. {
  3261. }
  3262. DynamicObject::~DynamicObject()
  3263. {
  3264. }
  3265. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3266. {
  3267. var* const v = properties.getItem (propertyName);
  3268. return v != 0 && ! v->isMethod();
  3269. }
  3270. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3271. {
  3272. return properties [propertyName];
  3273. }
  3274. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3275. {
  3276. properties.set (propertyName, newValue);
  3277. }
  3278. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3279. {
  3280. properties.remove (propertyName);
  3281. }
  3282. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3283. {
  3284. return getProperty (methodName).isMethod();
  3285. }
  3286. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3287. const var* parameters,
  3288. int numParameters)
  3289. {
  3290. return properties [methodName].invoke (var (this), parameters, numParameters);
  3291. }
  3292. void DynamicObject::setMethod (const var::identifier& name,
  3293. var::MethodFunction methodFunction)
  3294. {
  3295. properties.set (name, var (methodFunction));
  3296. }
  3297. void DynamicObject::clear()
  3298. {
  3299. properties.clear();
  3300. }
  3301. END_JUCE_NAMESPACE
  3302. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3303. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3304. BEGIN_JUCE_NAMESPACE
  3305. BlowFish::BlowFish (const void* const keyData, const int keyBytes)
  3306. {
  3307. jassert (keyData != 0);
  3308. jassert (keyBytes > 0);
  3309. static const uint32 initialPValues [18] =
  3310. {
  3311. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3312. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3313. 0x9216d5d9, 0x8979fb1b
  3314. };
  3315. static const uint32 initialSValues [4 * 256] =
  3316. {
  3317. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3318. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3319. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3320. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3321. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3322. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3323. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3324. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3325. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3326. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3327. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3328. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3329. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3330. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3331. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3332. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3333. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3334. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3335. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3336. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3337. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3338. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3339. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3340. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3341. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3342. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3343. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3344. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3345. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3346. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3347. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3348. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3349. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3350. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3351. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3352. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3353. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3354. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3355. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3356. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3357. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3358. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3359. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3360. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3361. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3362. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3363. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3364. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3365. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3366. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3367. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3368. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3369. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3370. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3371. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3372. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3373. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3374. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3375. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3376. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3377. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3378. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3379. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3380. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3381. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3382. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3383. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3384. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3385. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3386. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3387. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3388. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3389. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3390. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3391. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3392. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3393. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3394. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3395. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3396. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3397. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3398. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3399. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3400. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3401. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3402. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3403. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3404. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3405. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3406. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3407. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3408. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3409. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3410. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3411. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3412. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3413. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3414. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3415. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3416. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3417. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3418. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3419. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3420. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3421. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3422. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3423. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3424. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3425. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3426. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3427. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3428. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3429. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3430. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3431. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3432. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3433. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3434. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3435. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3436. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3437. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3438. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3439. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3440. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3441. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3442. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3443. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3444. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3445. };
  3446. memcpy (p, initialPValues, sizeof (p));
  3447. int i, j = 0;
  3448. for (i = 4; --i >= 0;)
  3449. {
  3450. s[i].malloc (256);
  3451. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3452. }
  3453. for (i = 0; i < 18; ++i)
  3454. {
  3455. uint32 d = 0;
  3456. for (int k = 0; k < 4; ++k)
  3457. {
  3458. d = (d << 8) | static_cast <const uint8*> (keyData)[j];
  3459. if (++j >= keyBytes)
  3460. j = 0;
  3461. }
  3462. p[i] = initialPValues[i] ^ d;
  3463. }
  3464. uint32 l = 0, r = 0;
  3465. for (i = 0; i < 18; i += 2)
  3466. {
  3467. encrypt (l, r);
  3468. p[i] = l;
  3469. p[i + 1] = r;
  3470. }
  3471. for (i = 0; i < 4; ++i)
  3472. {
  3473. for (j = 0; j < 256; j += 2)
  3474. {
  3475. encrypt (l, r);
  3476. s[i][j] = l;
  3477. s[i][j + 1] = r;
  3478. }
  3479. }
  3480. }
  3481. BlowFish::BlowFish (const BlowFish& other)
  3482. {
  3483. for (int i = 4; --i >= 0;)
  3484. s[i].malloc (256);
  3485. operator= (other);
  3486. }
  3487. BlowFish& BlowFish::operator= (const BlowFish& other)
  3488. {
  3489. memcpy (p, other.p, sizeof (p));
  3490. for (int i = 4; --i >= 0;)
  3491. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3492. return *this;
  3493. }
  3494. BlowFish::~BlowFish()
  3495. {
  3496. }
  3497. uint32 BlowFish::F (const uint32 x) const throw()
  3498. {
  3499. return ((s[0][(x >> 24) & 0xff] + s[1][(x >> 16) & 0xff])
  3500. ^ s[2][(x >> 8) & 0xff]) + s[3][x & 0xff];
  3501. }
  3502. void BlowFish::encrypt (uint32& data1, uint32& data2) const throw()
  3503. {
  3504. uint32 l = data1;
  3505. uint32 r = data2;
  3506. for (int i = 0; i < 16; ++i)
  3507. {
  3508. l ^= p[i];
  3509. r ^= F(l);
  3510. swapVariables (l, r);
  3511. }
  3512. data1 = r ^ p[17];
  3513. data2 = l ^ p[16];
  3514. }
  3515. void BlowFish::decrypt (uint32& data1, uint32& data2) const throw()
  3516. {
  3517. uint32 l = data1;
  3518. uint32 r = data2;
  3519. for (int i = 17; i > 1; --i)
  3520. {
  3521. l ^= p[i];
  3522. r ^= F(l);
  3523. swapVariables (l, r);
  3524. }
  3525. data1 = r ^ p[0];
  3526. data2 = l ^ p[1];
  3527. }
  3528. END_JUCE_NAMESPACE
  3529. /*** End of inlined file: juce_BlowFish.cpp ***/
  3530. /*** Start of inlined file: juce_MD5.cpp ***/
  3531. BEGIN_JUCE_NAMESPACE
  3532. MD5::MD5()
  3533. {
  3534. zerostruct (result);
  3535. }
  3536. MD5::MD5 (const MD5& other)
  3537. {
  3538. memcpy (result, other.result, sizeof (result));
  3539. }
  3540. MD5& MD5::operator= (const MD5& other)
  3541. {
  3542. memcpy (result, other.result, sizeof (result));
  3543. return *this;
  3544. }
  3545. MD5::MD5 (const MemoryBlock& data)
  3546. {
  3547. ProcessContext context;
  3548. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3549. context.finish (result);
  3550. }
  3551. MD5::MD5 (const char* data, const size_t numBytes)
  3552. {
  3553. ProcessContext context;
  3554. context.processBlock ((const uint8*) data, numBytes);
  3555. context.finish (result);
  3556. }
  3557. MD5::MD5 (const String& text)
  3558. {
  3559. ProcessContext context;
  3560. const int len = text.length();
  3561. const juce_wchar* const t = text;
  3562. for (int i = 0; i < len; ++i)
  3563. {
  3564. // force the string into integer-sized unicode characters, to try to make it
  3565. // get the same results on all platforms + compilers.
  3566. uint32 unicodeChar = (uint32) t[i];
  3567. ByteOrder::swapIfBigEndian (unicodeChar);
  3568. context.processBlock ((const uint8*) &unicodeChar,
  3569. sizeof (unicodeChar));
  3570. }
  3571. context.finish (result);
  3572. }
  3573. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3574. {
  3575. ProcessContext context;
  3576. if (numBytesToRead < 0)
  3577. numBytesToRead = std::numeric_limits<int64>::max();
  3578. while (numBytesToRead > 0)
  3579. {
  3580. char tempBuffer [512];
  3581. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3582. if (bytesRead <= 0)
  3583. break;
  3584. numBytesToRead -= bytesRead;
  3585. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3586. }
  3587. context.finish (result);
  3588. }
  3589. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3590. {
  3591. processStream (input, numBytesToRead);
  3592. }
  3593. MD5::MD5 (const File& file)
  3594. {
  3595. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3596. if (fin != 0)
  3597. processStream (*fin, -1);
  3598. else
  3599. zerostruct (result);
  3600. }
  3601. MD5::~MD5()
  3602. {
  3603. }
  3604. namespace MD5Functions
  3605. {
  3606. static void encode (uint8* const output, const uint32* const input, const int numBytes) throw()
  3607. {
  3608. uint32* const o = (uint32*) output;
  3609. for (int i = 0; i < (numBytes >> 2); ++i)
  3610. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3611. }
  3612. static void decode (uint32* const output, const uint8* const input, const int numBytes) throw()
  3613. {
  3614. for (int i = 0; i < (numBytes >> 2); ++i)
  3615. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3616. }
  3617. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3618. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3619. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3620. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3621. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3622. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3623. {
  3624. a += F (b, c, d) + x + ac;
  3625. a = rotateLeft (a, s) + b;
  3626. }
  3627. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3628. {
  3629. a += G (b, c, d) + x + ac;
  3630. a = rotateLeft (a, s) + b;
  3631. }
  3632. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3633. {
  3634. a += H (b, c, d) + x + ac;
  3635. a = rotateLeft (a, s) + b;
  3636. }
  3637. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3638. {
  3639. a += I (b, c, d) + x + ac;
  3640. a = rotateLeft (a, s) + b;
  3641. }
  3642. }
  3643. MD5::ProcessContext::ProcessContext()
  3644. {
  3645. state[0] = 0x67452301;
  3646. state[1] = 0xefcdab89;
  3647. state[2] = 0x98badcfe;
  3648. state[3] = 0x10325476;
  3649. count[0] = 0;
  3650. count[1] = 0;
  3651. }
  3652. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3653. {
  3654. int bufferPos = ((count[0] >> 3) & 0x3F);
  3655. count[0] += (uint32) (dataSize << 3);
  3656. if (count[0] < ((uint32) dataSize << 3))
  3657. count[1]++;
  3658. count[1] += (uint32) (dataSize >> 29);
  3659. const size_t spaceLeft = 64 - bufferPos;
  3660. size_t i = 0;
  3661. if (dataSize >= spaceLeft)
  3662. {
  3663. memcpy (buffer + bufferPos, data, spaceLeft);
  3664. transform (buffer);
  3665. i = spaceLeft;
  3666. while (i + 64 <= dataSize)
  3667. {
  3668. transform (data + i);
  3669. i += 64;
  3670. }
  3671. bufferPos = 0;
  3672. }
  3673. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3674. }
  3675. void MD5::ProcessContext::finish (uint8* const result)
  3676. {
  3677. unsigned char encodedLength[8];
  3678. MD5Functions::encode (encodedLength, count, 8);
  3679. // Pad out to 56 mod 64.
  3680. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3681. const int paddingLength = (index < 56) ? (56 - index)
  3682. : (120 - index);
  3683. uint8 paddingBuffer [64];
  3684. zeromem (paddingBuffer, paddingLength);
  3685. paddingBuffer [0] = 0x80;
  3686. processBlock (paddingBuffer, paddingLength);
  3687. processBlock (encodedLength, 8);
  3688. MD5Functions::encode (result, state, 16);
  3689. zerostruct (buffer);
  3690. }
  3691. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3692. {
  3693. using namespace MD5Functions;
  3694. uint32 a = state[0];
  3695. uint32 b = state[1];
  3696. uint32 c = state[2];
  3697. uint32 d = state[3];
  3698. uint32 x[16];
  3699. decode (x, bufferToTransform, 64);
  3700. enum Constants
  3701. {
  3702. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3703. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3704. };
  3705. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3706. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3707. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3708. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3709. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3710. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3711. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3712. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3713. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3714. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3715. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3716. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3717. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3718. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3719. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3720. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3721. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3722. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3723. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3724. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3725. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3726. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3727. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3728. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3729. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3730. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3731. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3732. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3733. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3734. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3735. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3736. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3737. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3738. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3739. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3740. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3741. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3742. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3743. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3744. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3745. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3746. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3747. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3748. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3749. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3750. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3751. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3752. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3753. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3754. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3755. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3756. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3757. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3758. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3759. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3760. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3761. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3762. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3763. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3764. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3765. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3766. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3767. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3768. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3769. state[0] += a;
  3770. state[1] += b;
  3771. state[2] += c;
  3772. state[3] += d;
  3773. zerostruct (x);
  3774. }
  3775. const MemoryBlock MD5::getRawChecksumData() const
  3776. {
  3777. return MemoryBlock (result, sizeof (result));
  3778. }
  3779. const String MD5::toHexString() const
  3780. {
  3781. return String::toHexString (result, sizeof (result), 0);
  3782. }
  3783. bool MD5::operator== (const MD5& other) const
  3784. {
  3785. return memcmp (result, other.result, sizeof (result)) == 0;
  3786. }
  3787. bool MD5::operator!= (const MD5& other) const
  3788. {
  3789. return ! operator== (other);
  3790. }
  3791. END_JUCE_NAMESPACE
  3792. /*** End of inlined file: juce_MD5.cpp ***/
  3793. /*** Start of inlined file: juce_Primes.cpp ***/
  3794. BEGIN_JUCE_NAMESPACE
  3795. namespace PrimesHelpers
  3796. {
  3797. static void createSmallSieve (const int numBits, BigInteger& result)
  3798. {
  3799. result.setBit (numBits);
  3800. result.clearBit (numBits); // to enlarge the array
  3801. result.setBit (0);
  3802. int n = 2;
  3803. do
  3804. {
  3805. for (int i = n + n; i < numBits; i += n)
  3806. result.setBit (i);
  3807. n = result.findNextClearBit (n + 1);
  3808. }
  3809. while (n <= (numBits >> 1));
  3810. }
  3811. static void bigSieve (const BigInteger& base, const int numBits, BigInteger& result,
  3812. const BigInteger& smallSieve, const int smallSieveSize)
  3813. {
  3814. jassert (! base[0]); // must be even!
  3815. result.setBit (numBits);
  3816. result.clearBit (numBits); // to enlarge the array
  3817. int index = smallSieve.findNextClearBit (0);
  3818. do
  3819. {
  3820. const int prime = (index << 1) + 1;
  3821. BigInteger r (base), remainder;
  3822. r.divideBy (prime, remainder);
  3823. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3824. if (r.isZero())
  3825. i += prime;
  3826. if ((i & 1) == 0)
  3827. i += prime;
  3828. i = (i - 1) >> 1;
  3829. while (i < numBits)
  3830. {
  3831. result.setBit (i);
  3832. i += prime;
  3833. }
  3834. index = smallSieve.findNextClearBit (index + 1);
  3835. }
  3836. while (index < smallSieveSize);
  3837. }
  3838. static bool findCandidate (const BigInteger& base, const BigInteger& sieve,
  3839. const int numBits, BigInteger& result, const int certainty)
  3840. {
  3841. for (int i = 0; i < numBits; ++i)
  3842. {
  3843. if (! sieve[i])
  3844. {
  3845. result = base + (unsigned int) ((i << 1) + 1);
  3846. if (Primes::isProbablyPrime (result, certainty))
  3847. return true;
  3848. }
  3849. }
  3850. return false;
  3851. }
  3852. static bool passesMillerRabin (const BigInteger& n, int iterations)
  3853. {
  3854. const BigInteger one (1), two (2);
  3855. const BigInteger nMinusOne (n - one);
  3856. BigInteger d (nMinusOne);
  3857. const int s = d.findNextSetBit (0);
  3858. d >>= s;
  3859. BigInteger smallPrimes;
  3860. int numBitsInSmallPrimes = 0;
  3861. for (;;)
  3862. {
  3863. numBitsInSmallPrimes += 256;
  3864. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3865. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3866. if (numPrimesFound > iterations + 1)
  3867. break;
  3868. }
  3869. int smallPrime = 2;
  3870. while (--iterations >= 0)
  3871. {
  3872. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3873. BigInteger r (smallPrime);
  3874. r.exponentModulo (d, n);
  3875. if (r != one && r != nMinusOne)
  3876. {
  3877. for (int j = 0; j < s; ++j)
  3878. {
  3879. r.exponentModulo (two, n);
  3880. if (r == nMinusOne)
  3881. break;
  3882. }
  3883. if (r != nMinusOne)
  3884. return false;
  3885. }
  3886. }
  3887. return true;
  3888. }
  3889. }
  3890. const BigInteger Primes::createProbablePrime (const int bitLength,
  3891. const int certainty,
  3892. const int* randomSeeds,
  3893. int numRandomSeeds)
  3894. {
  3895. using namespace PrimesHelpers;
  3896. int defaultSeeds [16];
  3897. if (numRandomSeeds <= 0)
  3898. {
  3899. randomSeeds = defaultSeeds;
  3900. numRandomSeeds = numElementsInArray (defaultSeeds);
  3901. Random r (0);
  3902. for (int j = 10; --j >= 0;)
  3903. {
  3904. r.setSeedRandomly();
  3905. for (int i = numRandomSeeds; --i >= 0;)
  3906. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3907. }
  3908. }
  3909. BigInteger smallSieve;
  3910. const int smallSieveSize = 15000;
  3911. createSmallSieve (smallSieveSize, smallSieve);
  3912. BigInteger p;
  3913. for (int i = numRandomSeeds; --i >= 0;)
  3914. {
  3915. BigInteger p2;
  3916. Random r (randomSeeds[i]);
  3917. r.fillBitsRandomly (p2, 0, bitLength);
  3918. p ^= p2;
  3919. }
  3920. p.setBit (bitLength - 1);
  3921. p.clearBit (0);
  3922. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3923. while (p.getHighestBit() < bitLength)
  3924. {
  3925. p += 2 * searchLen;
  3926. BigInteger sieve;
  3927. bigSieve (p, searchLen, sieve,
  3928. smallSieve, smallSieveSize);
  3929. BigInteger candidate;
  3930. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3931. return candidate;
  3932. }
  3933. jassertfalse
  3934. return BigInteger();
  3935. }
  3936. bool Primes::isProbablyPrime (const BigInteger& number, const int certainty)
  3937. {
  3938. using namespace PrimesHelpers;
  3939. if (! number[0])
  3940. return false;
  3941. if (number.getHighestBit() <= 10)
  3942. {
  3943. const int num = number.getBitRangeAsInt (0, 10);
  3944. for (int i = num / 2; --i > 1;)
  3945. if (num % i == 0)
  3946. return false;
  3947. return true;
  3948. }
  3949. else
  3950. {
  3951. if (number.findGreatestCommonDivisor (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23) != 1)
  3952. return false;
  3953. return passesMillerRabin (number, certainty);
  3954. }
  3955. }
  3956. END_JUCE_NAMESPACE
  3957. /*** End of inlined file: juce_Primes.cpp ***/
  3958. /*** Start of inlined file: juce_RSAKey.cpp ***/
  3959. BEGIN_JUCE_NAMESPACE
  3960. RSAKey::RSAKey()
  3961. {
  3962. }
  3963. RSAKey::RSAKey (const String& s)
  3964. {
  3965. if (s.containsChar (','))
  3966. {
  3967. part1.parseString (s.upToFirstOccurrenceOf (",", false, false), 16);
  3968. part2.parseString (s.fromFirstOccurrenceOf (",", false, false), 16);
  3969. }
  3970. else
  3971. {
  3972. // the string needs to be two hex numbers, comma-separated..
  3973. jassertfalse;
  3974. }
  3975. }
  3976. RSAKey::~RSAKey()
  3977. {
  3978. }
  3979. const String RSAKey::toString() const
  3980. {
  3981. return part1.toString (16) + "," + part2.toString (16);
  3982. }
  3983. bool RSAKey::applyToValue (BigInteger& value) const
  3984. {
  3985. if (part1.isZero() || part2.isZero() || value <= 0)
  3986. {
  3987. jassertfalse // using an uninitialised key
  3988. value.clear();
  3989. return false;
  3990. }
  3991. BigInteger result;
  3992. while (! value.isZero())
  3993. {
  3994. result *= part2;
  3995. BigInteger remainder;
  3996. value.divideBy (part2, remainder);
  3997. remainder.exponentModulo (part1, part2);
  3998. result += remainder;
  3999. }
  4000. value.swapWith (result);
  4001. return true;
  4002. }
  4003. static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q)
  4004. {
  4005. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  4006. // are fast to divide + multiply
  4007. for (int i = 2; i <= 65536; i *= 2)
  4008. {
  4009. const BigInteger e (1 + i);
  4010. if (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne())
  4011. return e;
  4012. }
  4013. BigInteger e (4);
  4014. while (! (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne()))
  4015. ++e;
  4016. return e;
  4017. }
  4018. void RSAKey::createKeyPair (RSAKey& publicKey, RSAKey& privateKey,
  4019. const int numBits, const int* randomSeeds, const int numRandomSeeds)
  4020. {
  4021. jassert (numBits > 16); // not much point using less than this..
  4022. BigInteger p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4023. BigInteger q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4024. const BigInteger n (p * q);
  4025. const BigInteger m (--p * --q);
  4026. const BigInteger e (findBestCommonDivisor (p, q));
  4027. BigInteger d (e);
  4028. d.inverseModulo (m);
  4029. publicKey.part1 = e;
  4030. publicKey.part2 = n;
  4031. privateKey.part1 = d;
  4032. privateKey.part2 = n;
  4033. }
  4034. END_JUCE_NAMESPACE
  4035. /*** End of inlined file: juce_RSAKey.cpp ***/
  4036. /*** Start of inlined file: juce_InputStream.cpp ***/
  4037. BEGIN_JUCE_NAMESPACE
  4038. char InputStream::readByte()
  4039. {
  4040. char temp = 0;
  4041. read (&temp, 1);
  4042. return temp;
  4043. }
  4044. bool InputStream::readBool()
  4045. {
  4046. return readByte() != 0;
  4047. }
  4048. short InputStream::readShort()
  4049. {
  4050. char temp[2];
  4051. if (read (temp, 2) == 2)
  4052. return (short) ByteOrder::littleEndianShort (temp);
  4053. return 0;
  4054. }
  4055. short InputStream::readShortBigEndian()
  4056. {
  4057. char temp[2];
  4058. if (read (temp, 2) == 2)
  4059. return (short) ByteOrder::bigEndianShort (temp);
  4060. return 0;
  4061. }
  4062. int InputStream::readInt()
  4063. {
  4064. char temp[4];
  4065. if (read (temp, 4) == 4)
  4066. return (int) ByteOrder::littleEndianInt (temp);
  4067. return 0;
  4068. }
  4069. int InputStream::readIntBigEndian()
  4070. {
  4071. char temp[4];
  4072. if (read (temp, 4) == 4)
  4073. return (int) ByteOrder::bigEndianInt (temp);
  4074. return 0;
  4075. }
  4076. int InputStream::readCompressedInt()
  4077. {
  4078. const unsigned char sizeByte = readByte();
  4079. if (sizeByte == 0)
  4080. return 0;
  4081. const int numBytes = (sizeByte & 0x7f);
  4082. if (numBytes > 4)
  4083. {
  4084. jassertfalse // trying to read corrupt data - this method must only be used
  4085. // to read data that was written by OutputStream::writeCompressedInt()
  4086. return 0;
  4087. }
  4088. char bytes[4] = { 0, 0, 0, 0 };
  4089. if (read (bytes, numBytes) != numBytes)
  4090. return 0;
  4091. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4092. return (sizeByte >> 7) ? -num : num;
  4093. }
  4094. int64 InputStream::readInt64()
  4095. {
  4096. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4097. if (read (n.asBytes, 8) == 8)
  4098. return (int64) ByteOrder::swapIfBigEndian (n.asInt64);
  4099. return 0;
  4100. }
  4101. int64 InputStream::readInt64BigEndian()
  4102. {
  4103. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4104. if (read (n.asBytes, 8) == 8)
  4105. return (int64) ByteOrder::swapIfLittleEndian (n.asInt64);
  4106. return 0;
  4107. }
  4108. float InputStream::readFloat()
  4109. {
  4110. // the union below relies on these types being the same size...
  4111. static_jassert (sizeof (int32) == sizeof (float));
  4112. union { int32 asInt; float asFloat; } n;
  4113. n.asInt = (int32) readInt();
  4114. return n.asFloat;
  4115. }
  4116. float InputStream::readFloatBigEndian()
  4117. {
  4118. union { int32 asInt; float asFloat; } n;
  4119. n.asInt = (int32) readIntBigEndian();
  4120. return n.asFloat;
  4121. }
  4122. double InputStream::readDouble()
  4123. {
  4124. union { int64 asInt; double asDouble; } n;
  4125. n.asInt = readInt64();
  4126. return n.asDouble;
  4127. }
  4128. double InputStream::readDoubleBigEndian()
  4129. {
  4130. union { int64 asInt; double asDouble; } n;
  4131. n.asInt = readInt64BigEndian();
  4132. return n.asDouble;
  4133. }
  4134. const String InputStream::readString()
  4135. {
  4136. MemoryBlock buffer (256);
  4137. char* data = static_cast<char*> (buffer.getData());
  4138. size_t i = 0;
  4139. while ((data[i] = readByte()) != 0)
  4140. {
  4141. if (++i >= buffer.getSize())
  4142. {
  4143. buffer.setSize (buffer.getSize() + 512);
  4144. data = static_cast<char*> (buffer.getData());
  4145. }
  4146. }
  4147. return String::fromUTF8 (data, (int) i);
  4148. }
  4149. const String InputStream::readNextLine()
  4150. {
  4151. MemoryBlock buffer (256);
  4152. char* data = static_cast<char*> (buffer.getData());
  4153. size_t i = 0;
  4154. while ((data[i] = readByte()) != 0)
  4155. {
  4156. if (data[i] == '\n')
  4157. break;
  4158. if (data[i] == '\r')
  4159. {
  4160. const int64 lastPos = getPosition();
  4161. if (readByte() != '\n')
  4162. setPosition (lastPos);
  4163. break;
  4164. }
  4165. if (++i >= buffer.getSize())
  4166. {
  4167. buffer.setSize (buffer.getSize() + 512);
  4168. data = static_cast<char*> (buffer.getData());
  4169. }
  4170. }
  4171. return String::fromUTF8 (data, (int) i);
  4172. }
  4173. int InputStream::readIntoMemoryBlock (MemoryBlock& block, int numBytes)
  4174. {
  4175. const int64 totalLength = getTotalLength();
  4176. if (totalLength >= 0)
  4177. {
  4178. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4179. totalLength - getPosition());
  4180. if (numBytes < 0)
  4181. numBytes = totalBytesRemaining;
  4182. else if (numBytes > 0)
  4183. numBytes = jmin (numBytes, totalBytesRemaining);
  4184. else
  4185. return 0;
  4186. }
  4187. const size_t originalBlockSize = block.getSize();
  4188. int totalBytesRead = 0;
  4189. if (numBytes > 0)
  4190. {
  4191. // know how many bytes we want, so we can resize the block first..
  4192. block.setSize (originalBlockSize + numBytes, false);
  4193. totalBytesRead = read (static_cast<char*> (block.getData()) + originalBlockSize, numBytes);
  4194. }
  4195. else
  4196. {
  4197. // read until end of stram..
  4198. const int chunkSize = 32768;
  4199. for (;;)
  4200. {
  4201. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4202. const int bytesJustIn = read (static_cast<char*> (block.getData())
  4203. + originalBlockSize
  4204. + totalBytesRead,
  4205. chunkSize);
  4206. if (bytesJustIn == 0)
  4207. break;
  4208. totalBytesRead += bytesJustIn;
  4209. }
  4210. }
  4211. // trim off any excess left at the end
  4212. block.setSize (originalBlockSize + totalBytesRead, false);
  4213. return totalBytesRead;
  4214. }
  4215. const String InputStream::readEntireStreamAsString()
  4216. {
  4217. MemoryBlock mb;
  4218. const int size = readIntoMemoryBlock (mb);
  4219. return String::createStringFromData (static_cast<const char*> (mb.getData()), size);
  4220. }
  4221. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4222. {
  4223. if (numBytesToSkip > 0)
  4224. {
  4225. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4226. HeapBlock<char> temp (skipBufferSize);
  4227. while (numBytesToSkip > 0 && ! isExhausted())
  4228. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4229. }
  4230. }
  4231. END_JUCE_NAMESPACE
  4232. /*** End of inlined file: juce_InputStream.cpp ***/
  4233. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4234. BEGIN_JUCE_NAMESPACE
  4235. #if JUCE_DEBUG
  4236. static CriticalSection activeStreamLock;
  4237. static VoidArray activeStreams;
  4238. void juce_CheckForDanglingStreams()
  4239. {
  4240. /*
  4241. It's always a bad idea to leak any object, but if you're leaking output
  4242. streams, then there's a good chance that you're failing to flush a file
  4243. to disk properly, which could result in corrupted data and other similar
  4244. nastiness..
  4245. */
  4246. jassert (activeStreams.size() == 0);
  4247. };
  4248. #endif
  4249. OutputStream::OutputStream()
  4250. {
  4251. #if JUCE_DEBUG
  4252. const ScopedLock sl (activeStreamLock);
  4253. activeStreams.add (this);
  4254. #endif
  4255. }
  4256. OutputStream::~OutputStream()
  4257. {
  4258. #if JUCE_DEBUG
  4259. const ScopedLock sl (activeStreamLock);
  4260. activeStreams.removeValue (this);
  4261. #endif
  4262. }
  4263. void OutputStream::writeBool (const bool b)
  4264. {
  4265. writeByte (b ? (char) 1
  4266. : (char) 0);
  4267. }
  4268. void OutputStream::writeByte (char byte)
  4269. {
  4270. write (&byte, 1);
  4271. }
  4272. void OutputStream::writeShort (short value)
  4273. {
  4274. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4275. write (&v, 2);
  4276. }
  4277. void OutputStream::writeShortBigEndian (short value)
  4278. {
  4279. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4280. write (&v, 2);
  4281. }
  4282. void OutputStream::writeInt (int value)
  4283. {
  4284. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4285. write (&v, 4);
  4286. }
  4287. void OutputStream::writeIntBigEndian (int value)
  4288. {
  4289. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4290. write (&v, 4);
  4291. }
  4292. void OutputStream::writeCompressedInt (int value)
  4293. {
  4294. unsigned int un = (value < 0) ? (unsigned int) -value
  4295. : (unsigned int) value;
  4296. uint8 data[5];
  4297. int num = 0;
  4298. while (un > 0)
  4299. {
  4300. data[++num] = (uint8) un;
  4301. un >>= 8;
  4302. }
  4303. data[0] = (uint8) num;
  4304. if (value < 0)
  4305. data[0] |= 0x80;
  4306. write (data, num + 1);
  4307. }
  4308. void OutputStream::writeInt64 (int64 value)
  4309. {
  4310. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4311. write (&v, 8);
  4312. }
  4313. void OutputStream::writeInt64BigEndian (int64 value)
  4314. {
  4315. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4316. write (&v, 8);
  4317. }
  4318. void OutputStream::writeFloat (float value)
  4319. {
  4320. union { int asInt; float asFloat; } n;
  4321. n.asFloat = value;
  4322. writeInt (n.asInt);
  4323. }
  4324. void OutputStream::writeFloatBigEndian (float value)
  4325. {
  4326. union { int asInt; float asFloat; } n;
  4327. n.asFloat = value;
  4328. writeIntBigEndian (n.asInt);
  4329. }
  4330. void OutputStream::writeDouble (double value)
  4331. {
  4332. union { int64 asInt; double asDouble; } n;
  4333. n.asDouble = value;
  4334. writeInt64 (n.asInt);
  4335. }
  4336. void OutputStream::writeDoubleBigEndian (double value)
  4337. {
  4338. union { int64 asInt; double asDouble; } n;
  4339. n.asDouble = value;
  4340. writeInt64BigEndian (n.asInt);
  4341. }
  4342. void OutputStream::writeString (const String& text)
  4343. {
  4344. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4345. // if lots of large, persistent strings were to be written to streams).
  4346. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4347. HeapBlock<char> temp (numBytes);
  4348. text.copyToUTF8 (temp, numBytes);
  4349. write (temp, numBytes);
  4350. }
  4351. void OutputStream::writeText (const String& text, const bool asUnicode,
  4352. const bool writeUnicodeHeaderBytes)
  4353. {
  4354. if (asUnicode)
  4355. {
  4356. if (writeUnicodeHeaderBytes)
  4357. write ("\x0ff\x0fe", 2);
  4358. const juce_wchar* src = (const juce_wchar*) text;
  4359. bool lastCharWasReturn = false;
  4360. while (*src != 0)
  4361. {
  4362. if (*src == L'\n' && ! lastCharWasReturn)
  4363. writeShort ((short) L'\r');
  4364. lastCharWasReturn = (*src == L'\r');
  4365. writeShort ((short) *src++);
  4366. }
  4367. }
  4368. else
  4369. {
  4370. const char* src = text.toUTF8();
  4371. const char* t = src;
  4372. for (;;)
  4373. {
  4374. if (*t == '\n')
  4375. {
  4376. if (t > src)
  4377. write (src, (int) (t - src));
  4378. write ("\r\n", 2);
  4379. src = t + 1;
  4380. }
  4381. else if (*t == '\r')
  4382. {
  4383. if (t[1] == '\n')
  4384. ++t;
  4385. }
  4386. else if (*t == 0)
  4387. {
  4388. if (t > src)
  4389. write (src, (int) (t - src));
  4390. break;
  4391. }
  4392. ++t;
  4393. }
  4394. }
  4395. }
  4396. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4397. {
  4398. if (numBytesToWrite < 0)
  4399. numBytesToWrite = 0x7fffffff;
  4400. int numWritten = 0;
  4401. while (numBytesToWrite > 0 && ! source.isExhausted())
  4402. {
  4403. char buffer [8192];
  4404. const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4405. if (num == 0)
  4406. break;
  4407. write (buffer, num);
  4408. numBytesToWrite -= num;
  4409. numWritten += num;
  4410. }
  4411. return numWritten;
  4412. }
  4413. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4414. {
  4415. return stream << String (number);
  4416. }
  4417. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4418. {
  4419. return stream << String (number);
  4420. }
  4421. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4422. {
  4423. stream.writeByte (character);
  4424. return stream;
  4425. }
  4426. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4427. {
  4428. stream.write (text, (int) strlen (text));
  4429. return stream;
  4430. }
  4431. END_JUCE_NAMESPACE
  4432. /*** End of inlined file: juce_OutputStream.cpp ***/
  4433. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4434. BEGIN_JUCE_NAMESPACE
  4435. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4436. bool* isDirectory, bool* isHidden, int64* fileSize,
  4437. Time* modTime, Time* creationTime, bool* isReadOnly);
  4438. bool juce_findFileNext (void* handle, String& resultFile,
  4439. bool* isDirectory, bool* isHidden, int64* fileSize,
  4440. Time* modTime, Time* creationTime, bool* isReadOnly);
  4441. void juce_findFileClose (void* handle);
  4442. DirectoryIterator::DirectoryIterator (const File& directory,
  4443. bool isRecursive,
  4444. const String& wc,
  4445. const int whatToLookFor_)
  4446. : wildCard (wc),
  4447. index (-1),
  4448. whatToLookFor (whatToLookFor_)
  4449. {
  4450. // you have to specify the type of files you're looking for!
  4451. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4452. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4453. String path (directory.getFullPathName());
  4454. if (! path.endsWithChar (File::separator))
  4455. path += File::separator;
  4456. String filename;
  4457. bool isDirectory, isHidden;
  4458. void* const handle = juce_findFileStart (path,
  4459. isRecursive ? "*" : wc,
  4460. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4461. if (handle != 0)
  4462. {
  4463. do
  4464. {
  4465. if (! filename.containsOnly ("."))
  4466. {
  4467. bool addToList = false;
  4468. if (isDirectory)
  4469. {
  4470. if (isRecursive
  4471. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4472. || ! isHidden))
  4473. {
  4474. dirsFound.add (File (path + filename, 0));
  4475. }
  4476. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4477. }
  4478. else
  4479. {
  4480. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4481. }
  4482. // if it's recursive, we're not relying on the OS iterator
  4483. // to do the wildcard match, so do it now..
  4484. if (isRecursive && addToList)
  4485. addToList = filename.matchesWildcard (wc, true);
  4486. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4487. addToList = ! isHidden;
  4488. if (addToList)
  4489. filesFound.add (File (path + filename, 0));
  4490. }
  4491. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4492. juce_findFileClose (handle);
  4493. }
  4494. }
  4495. DirectoryIterator::~DirectoryIterator()
  4496. {
  4497. }
  4498. bool DirectoryIterator::next()
  4499. {
  4500. if (subIterator != 0)
  4501. {
  4502. if (subIterator->next())
  4503. return true;
  4504. subIterator = 0;
  4505. }
  4506. if (index >= filesFound.size() + dirsFound.size() - 1)
  4507. return false;
  4508. ++index;
  4509. if (index >= filesFound.size())
  4510. {
  4511. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4512. true, wildCard, whatToLookFor);
  4513. return next();
  4514. }
  4515. return true;
  4516. }
  4517. const File DirectoryIterator::getFile() const
  4518. {
  4519. if (subIterator != 0)
  4520. return subIterator->getFile();
  4521. return filesFound [index];
  4522. }
  4523. float DirectoryIterator::getEstimatedProgress() const
  4524. {
  4525. if (filesFound.size() + dirsFound.size() == 0)
  4526. {
  4527. return 0.0f;
  4528. }
  4529. else
  4530. {
  4531. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4532. : (float) index;
  4533. return detailedIndex / (filesFound.size() + dirsFound.size());
  4534. }
  4535. }
  4536. END_JUCE_NAMESPACE
  4537. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4538. /*** Start of inlined file: juce_File.cpp ***/
  4539. #ifdef _MSC_VER
  4540. #pragma warning (disable: 4514)
  4541. #pragma warning (push)
  4542. #endif
  4543. #if ! JUCE_WINDOWS
  4544. #include <pwd.h>
  4545. #endif
  4546. BEGIN_JUCE_NAMESPACE
  4547. #ifdef _MSC_VER
  4548. #pragma warning (pop)
  4549. #endif
  4550. void* juce_fileOpen (const String& path, bool forWriting);
  4551. void juce_fileClose (void* handle);
  4552. int juce_fileWrite (void* handle, const void* buffer, int size);
  4553. int64 juce_fileGetPosition (void* handle);
  4554. int64 juce_fileSetPosition (void* handle, int64 pos);
  4555. void juce_fileFlush (void* handle);
  4556. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4557. bool juce_isDirectory (const String& fileName);
  4558. int64 juce_getFileSize (const String& fileName);
  4559. bool juce_canWriteToFile (const String& fileName);
  4560. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4561. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4562. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4563. bool juce_deleteFile (const String& fileName);
  4564. bool juce_copyFile (const String& source, const String& dest);
  4565. bool juce_moveFile (const String& source, const String& dest);
  4566. // this must also create all paths involved in the directory.
  4567. void juce_createDirectory (const String& fileName);
  4568. bool juce_launchFile (const String& fileName, const String& parameters);
  4569. const StringArray juce_getFileSystemRoots();
  4570. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4571. // starts a directory search operation with a wildcard, returning a handle for
  4572. // use in calls to juce_findFileNext.
  4573. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4574. // the other pointers, if non-null, are set based on the properties of the file.
  4575. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4576. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4577. Time* creationTime, bool* isReadOnly);
  4578. // returns false when no more files are found
  4579. bool juce_findFileNext (void* handle, String& resultFile,
  4580. bool* isDirectory, bool* isHidden, int64* fileSize,
  4581. Time* modTime, Time* creationTime, bool* isReadOnly);
  4582. void juce_findFileClose (void* handle);
  4583. static const String juce_addTrailingSeparator (const String& path)
  4584. {
  4585. return path.endsWithChar (File::separator) ? path
  4586. : path + File::separator;
  4587. }
  4588. static const String parseAbsolutePath (String path)
  4589. {
  4590. if (path.isEmpty())
  4591. return String::empty;
  4592. #if JUCE_WINDOWS
  4593. // Windows..
  4594. path = path.replaceCharacter ('/', '\\');
  4595. if (path.startsWithChar (File::separator))
  4596. {
  4597. if (path[1] != File::separator)
  4598. {
  4599. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4600. If you're trying to parse a string that may be either a relative path or an absolute path,
  4601. you MUST provide a context against which the partial path can be evaluated - you can do
  4602. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4603. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4604. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4605. */
  4606. jassertfalse
  4607. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4608. }
  4609. }
  4610. else if (path.indexOfChar (':') < 0)
  4611. {
  4612. if (path.isEmpty())
  4613. return String::empty;
  4614. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4615. If you're trying to parse a string that may be either a relative path or an absolute path,
  4616. you MUST provide a context against which the partial path can be evaluated - you can do
  4617. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4618. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4619. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4620. */
  4621. jassertfalse
  4622. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4623. }
  4624. #else
  4625. // Mac or Linux..
  4626. path = path.replaceCharacter ('\\', '/');
  4627. if (path.startsWithChar ('~'))
  4628. {
  4629. const char* homeDir = 0;
  4630. if (path[1] == File::separator || path[1] == 0)
  4631. {
  4632. // expand a name of the form "~/abc"
  4633. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4634. + path.substring (1);
  4635. }
  4636. else
  4637. {
  4638. // expand a name of type "~dave/abc"
  4639. const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false));
  4640. struct passwd* const pw = getpwnam (userName.toUTF8());
  4641. if (pw != 0)
  4642. {
  4643. String home (homeDir);
  4644. if (home.endsWithChar (File::separator))
  4645. home [home.length() - 1] = 0;
  4646. path = String (pw->pw_dir)
  4647. + path.substring (userName.length());
  4648. }
  4649. }
  4650. }
  4651. else if (! path.startsWithChar (File::separator))
  4652. {
  4653. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4654. If you're trying to parse a string that may be either a relative path or an absolute path,
  4655. you MUST provide a context against which the partial path can be evaluated - you can do
  4656. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4657. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4658. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4659. */
  4660. jassert (path.startsWith ("./") || path.startsWith ("../")); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4661. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4662. }
  4663. #endif
  4664. int len = path.length();
  4665. while (--len > 0 && path [len] == File::separator)
  4666. path [len] = 0;
  4667. return path;
  4668. }
  4669. const File File::nonexistent;
  4670. File::File (const String& fullPathName)
  4671. : fullPath (parseAbsolutePath (fullPathName))
  4672. {
  4673. }
  4674. File::File (const String& path, int)
  4675. : fullPath (path)
  4676. {
  4677. }
  4678. const File File::createFileWithoutCheckingPath (const String& path)
  4679. {
  4680. return File (path, 0);
  4681. }
  4682. File::File (const File& other)
  4683. : fullPath (other.fullPath)
  4684. {
  4685. }
  4686. File& File::operator= (const String& newPath)
  4687. {
  4688. fullPath = parseAbsolutePath (newPath);
  4689. return *this;
  4690. }
  4691. File& File::operator= (const File& other)
  4692. {
  4693. fullPath = other.fullPath;
  4694. return *this;
  4695. }
  4696. #if JUCE_LINUX
  4697. #define NAMES_ARE_CASE_SENSITIVE 1
  4698. #endif
  4699. bool File::areFileNamesCaseSensitive()
  4700. {
  4701. #if NAMES_ARE_CASE_SENSITIVE
  4702. return true;
  4703. #else
  4704. return false;
  4705. #endif
  4706. }
  4707. bool File::operator== (const File& other) const
  4708. {
  4709. // case-insensitive on Windows, but not on linux.
  4710. #if NAMES_ARE_CASE_SENSITIVE
  4711. return fullPath == other.fullPath;
  4712. #else
  4713. return fullPath.equalsIgnoreCase (other.fullPath);
  4714. #endif
  4715. }
  4716. bool File::operator!= (const File& other) const
  4717. {
  4718. return ! operator== (other);
  4719. }
  4720. bool File::exists() const
  4721. {
  4722. return juce_fileExists (fullPath, false);
  4723. }
  4724. bool File::existsAsFile() const
  4725. {
  4726. return juce_fileExists (fullPath, true);
  4727. }
  4728. bool File::isDirectory() const
  4729. {
  4730. return juce_isDirectory (fullPath);
  4731. }
  4732. bool File::hasWriteAccess() const
  4733. {
  4734. if (exists())
  4735. return juce_canWriteToFile (fullPath);
  4736. #if ! JUCE_WINDOWS
  4737. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4738. return getParentDirectory().hasWriteAccess();
  4739. else
  4740. return false;
  4741. #else
  4742. // on windows, it seems that even read-only directories can still be written into,
  4743. // so checking the parent directory's permissions would return the wrong result..
  4744. else
  4745. return true;
  4746. #endif
  4747. }
  4748. bool File::setReadOnly (const bool shouldBeReadOnly,
  4749. const bool applyRecursively) const
  4750. {
  4751. bool worked = true;
  4752. if (applyRecursively && isDirectory())
  4753. {
  4754. Array <File> subFiles;
  4755. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4756. for (int i = subFiles.size(); --i >= 0;)
  4757. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4758. }
  4759. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4760. }
  4761. bool File::deleteFile() const
  4762. {
  4763. return (! exists())
  4764. || juce_deleteFile (fullPath);
  4765. }
  4766. bool File::deleteRecursively() const
  4767. {
  4768. bool worked = true;
  4769. if (isDirectory())
  4770. {
  4771. Array<File> subFiles;
  4772. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4773. for (int i = subFiles.size(); --i >= 0;)
  4774. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4775. }
  4776. return deleteFile() && worked;
  4777. }
  4778. bool File::moveFileTo (const File& newFile) const
  4779. {
  4780. if (newFile.fullPath == fullPath)
  4781. return true;
  4782. #if ! NAMES_ARE_CASE_SENSITIVE
  4783. if (*this != newFile)
  4784. #endif
  4785. if (! newFile.deleteFile())
  4786. return false;
  4787. return juce_moveFile (fullPath, newFile.fullPath);
  4788. }
  4789. bool File::copyFileTo (const File& newFile) const
  4790. {
  4791. if (*this == newFile)
  4792. return true;
  4793. if (! newFile.deleteFile())
  4794. return false;
  4795. return juce_copyFile (fullPath, newFile.fullPath);
  4796. }
  4797. bool File::copyDirectoryTo (const File& newDirectory) const
  4798. {
  4799. if (isDirectory() && newDirectory.createDirectory())
  4800. {
  4801. Array<File> subFiles;
  4802. findChildFiles (subFiles, File::findFiles, false);
  4803. int i;
  4804. for (i = 0; i < subFiles.size(); ++i)
  4805. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4806. return false;
  4807. subFiles.clear();
  4808. findChildFiles (subFiles, File::findDirectories, false);
  4809. for (i = 0; i < subFiles.size(); ++i)
  4810. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4811. return false;
  4812. return true;
  4813. }
  4814. return false;
  4815. }
  4816. const String File::getPathUpToLastSlash() const
  4817. {
  4818. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4819. if (lastSlash > 0)
  4820. return fullPath.substring (0, lastSlash);
  4821. else if (lastSlash == 0)
  4822. return separatorString;
  4823. else
  4824. return fullPath;
  4825. }
  4826. const File File::getParentDirectory() const
  4827. {
  4828. return File (getPathUpToLastSlash());
  4829. }
  4830. const String File::getFileName() const
  4831. {
  4832. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4833. }
  4834. int File::hashCode() const
  4835. {
  4836. return fullPath.hashCode();
  4837. }
  4838. int64 File::hashCode64() const
  4839. {
  4840. return fullPath.hashCode64();
  4841. }
  4842. const String File::getFileNameWithoutExtension() const
  4843. {
  4844. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4845. const int lastDot = fullPath.lastIndexOfChar ('.');
  4846. if (lastDot > lastSlash)
  4847. return fullPath.substring (lastSlash, lastDot);
  4848. else
  4849. return fullPath.substring (lastSlash);
  4850. }
  4851. bool File::isAChildOf (const File& potentialParent) const
  4852. {
  4853. if (potentialParent == File::nonexistent)
  4854. return false;
  4855. const String ourPath (getPathUpToLastSlash());
  4856. #if NAMES_ARE_CASE_SENSITIVE
  4857. if (potentialParent.fullPath == ourPath)
  4858. #else
  4859. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4860. #endif
  4861. {
  4862. return true;
  4863. }
  4864. else if (potentialParent.fullPath.length() >= ourPath.length())
  4865. {
  4866. return false;
  4867. }
  4868. else
  4869. {
  4870. return getParentDirectory().isAChildOf (potentialParent);
  4871. }
  4872. }
  4873. bool File::isAbsolutePath (const String& path)
  4874. {
  4875. return path.startsWithChar ('/') || path.startsWithChar ('\\')
  4876. #if JUCE_WINDOWS
  4877. || (path.isNotEmpty() && path[1] == ':');
  4878. #else
  4879. || path.startsWithChar ('~');
  4880. #endif
  4881. }
  4882. const File File::getChildFile (String relativePath) const
  4883. {
  4884. if (isAbsolutePath (relativePath))
  4885. {
  4886. // the path is really absolute..
  4887. return File (relativePath);
  4888. }
  4889. else
  4890. {
  4891. // it's relative, so remove any ../ or ./ bits at the start.
  4892. String path (fullPath);
  4893. if (relativePath[0] == '.')
  4894. {
  4895. #if JUCE_WINDOWS
  4896. relativePath = relativePath.replaceCharacter ('/', '\\').trimStart();
  4897. #else
  4898. relativePath = relativePath.replaceCharacter ('\\', '/').trimStart();
  4899. #endif
  4900. while (relativePath[0] == '.')
  4901. {
  4902. if (relativePath[1] == '.')
  4903. {
  4904. if (relativePath [2] == 0 || relativePath[2] == separator)
  4905. {
  4906. const int lastSlash = path.lastIndexOfChar (separator);
  4907. if (lastSlash >= 0)
  4908. path = path.substring (0, lastSlash);
  4909. relativePath = relativePath.substring (3);
  4910. }
  4911. else
  4912. {
  4913. break;
  4914. }
  4915. }
  4916. else if (relativePath[1] == separator)
  4917. {
  4918. relativePath = relativePath.substring (2);
  4919. }
  4920. else
  4921. {
  4922. break;
  4923. }
  4924. }
  4925. }
  4926. return File (juce_addTrailingSeparator (path) + relativePath);
  4927. }
  4928. }
  4929. const File File::getSiblingFile (const String& fileName) const
  4930. {
  4931. return getParentDirectory().getChildFile (fileName);
  4932. }
  4933. int64 File::getSize() const
  4934. {
  4935. return juce_getFileSize (fullPath);
  4936. }
  4937. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4938. {
  4939. if (bytes == 1)
  4940. {
  4941. return "1 byte";
  4942. }
  4943. else if (bytes < 1024)
  4944. {
  4945. return String ((int) bytes) + " bytes";
  4946. }
  4947. else if (bytes < 1024 * 1024)
  4948. {
  4949. return String (bytes / 1024.0, 1) + " KB";
  4950. }
  4951. else if (bytes < 1024 * 1024 * 1024)
  4952. {
  4953. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4954. }
  4955. else
  4956. {
  4957. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4958. }
  4959. }
  4960. bool File::create() const
  4961. {
  4962. if (! exists())
  4963. {
  4964. const File parentDir (getParentDirectory());
  4965. if (parentDir == *this || ! parentDir.createDirectory())
  4966. return false;
  4967. void* const fh = juce_fileOpen (fullPath, true);
  4968. if (fh == 0)
  4969. return false;
  4970. juce_fileClose (fh);
  4971. }
  4972. return true;
  4973. }
  4974. bool File::createDirectory() const
  4975. {
  4976. if (! isDirectory())
  4977. {
  4978. const File parentDir (getParentDirectory());
  4979. if (parentDir == *this || ! parentDir.createDirectory())
  4980. return false;
  4981. String dir (fullPath);
  4982. while (dir.endsWithChar (separator))
  4983. dir [dir.length() - 1] = 0;
  4984. juce_createDirectory (dir);
  4985. return isDirectory();
  4986. }
  4987. return true;
  4988. }
  4989. const Time File::getCreationTime() const
  4990. {
  4991. int64 m, a, c;
  4992. juce_getFileTimes (fullPath, m, a, c);
  4993. return Time (c);
  4994. }
  4995. bool File::setCreationTime (const Time& t) const
  4996. {
  4997. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  4998. }
  4999. const Time File::getLastModificationTime() const
  5000. {
  5001. int64 m, a, c;
  5002. juce_getFileTimes (fullPath, m, a, c);
  5003. return Time (m);
  5004. }
  5005. bool File::setLastModificationTime (const Time& t) const
  5006. {
  5007. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5008. }
  5009. const Time File::getLastAccessTime() const
  5010. {
  5011. int64 m, a, c;
  5012. juce_getFileTimes (fullPath, m, a, c);
  5013. return Time (a);
  5014. }
  5015. bool File::setLastAccessTime (const Time& t) const
  5016. {
  5017. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5018. }
  5019. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5020. {
  5021. if (! existsAsFile())
  5022. return false;
  5023. FileInputStream in (*this);
  5024. return getSize() == in.readIntoMemoryBlock (destBlock);
  5025. }
  5026. const String File::loadFileAsString() const
  5027. {
  5028. if (! existsAsFile())
  5029. return String::empty;
  5030. FileInputStream in (*this);
  5031. return in.readEntireStreamAsString();
  5032. }
  5033. static inline bool fileTypeMatches (const int whatToLookFor,
  5034. const bool isDir,
  5035. const bool isHidden)
  5036. {
  5037. return (whatToLookFor & (isDir ? File::findDirectories
  5038. : File::findFiles)) != 0
  5039. && ((! isHidden)
  5040. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5041. }
  5042. int File::findChildFiles (Array<File>& results,
  5043. const int whatToLookFor,
  5044. const bool searchRecursively,
  5045. const String& wildCardPattern) const
  5046. {
  5047. // you have to specify the type of files you're looking for!
  5048. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5049. int total = 0;
  5050. // find child files or directories in this directory first..
  5051. if (isDirectory())
  5052. {
  5053. const String path (juce_addTrailingSeparator (fullPath));
  5054. String filename;
  5055. bool itemIsDirectory, itemIsHidden;
  5056. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5057. &itemIsDirectory, &itemIsHidden,
  5058. 0, 0, 0, 0);
  5059. if (handle != 0)
  5060. {
  5061. do
  5062. {
  5063. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5064. && ! filename.containsOnly ("."))
  5065. {
  5066. results.add (File (path + filename, 0));
  5067. ++total;
  5068. }
  5069. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5070. juce_findFileClose (handle);
  5071. }
  5072. }
  5073. else
  5074. {
  5075. // trying to search for files inside a non-directory?
  5076. //jassertfalse
  5077. }
  5078. // and recurse down if required.
  5079. if (searchRecursively)
  5080. {
  5081. Array<File> subDirectories;
  5082. findChildFiles (subDirectories, File::findDirectories, false);
  5083. for (int i = 0; i < subDirectories.size(); ++i)
  5084. {
  5085. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5086. true, wildCardPattern);
  5087. }
  5088. }
  5089. return total;
  5090. }
  5091. int File::getNumberOfChildFiles (const int whatToLookFor,
  5092. const String& wildCardPattern) const
  5093. {
  5094. // you have to specify the type of files you're looking for!
  5095. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5096. int count = 0;
  5097. if (isDirectory())
  5098. {
  5099. String filename;
  5100. bool itemIsDirectory, itemIsHidden;
  5101. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5102. &itemIsDirectory, &itemIsHidden,
  5103. 0, 0, 0, 0);
  5104. if (handle != 0)
  5105. {
  5106. do
  5107. {
  5108. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5109. && ! filename.containsOnly ("."))
  5110. {
  5111. ++count;
  5112. }
  5113. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5114. juce_findFileClose (handle);
  5115. }
  5116. }
  5117. else
  5118. {
  5119. // trying to search for files inside a non-directory?
  5120. jassertfalse
  5121. }
  5122. return count;
  5123. }
  5124. bool File::containsSubDirectories() const
  5125. {
  5126. bool result = false;
  5127. if (isDirectory())
  5128. {
  5129. String filename;
  5130. bool itemIsDirectory, itemIsHidden;
  5131. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5132. "*", filename,
  5133. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5134. if (handle != 0)
  5135. {
  5136. do
  5137. {
  5138. if (itemIsDirectory)
  5139. {
  5140. result = true;
  5141. break;
  5142. }
  5143. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5144. juce_findFileClose (handle);
  5145. }
  5146. }
  5147. return result;
  5148. }
  5149. const File File::getNonexistentChildFile (const String& prefix_,
  5150. const String& suffix,
  5151. bool putNumbersInBrackets) const
  5152. {
  5153. File f (getChildFile (prefix_ + suffix));
  5154. if (f.exists())
  5155. {
  5156. int num = 2;
  5157. String prefix (prefix_);
  5158. // remove any bracketed numbers that may already be on the end..
  5159. if (prefix.trim().endsWithChar (')'))
  5160. {
  5161. putNumbersInBrackets = true;
  5162. const int openBracks = prefix.lastIndexOfChar ('(');
  5163. const int closeBracks = prefix.lastIndexOfChar (')');
  5164. if (openBracks > 0
  5165. && closeBracks > openBracks
  5166. && prefix.substring (openBracks + 1, closeBracks).containsOnly ("0123456789"))
  5167. {
  5168. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5169. prefix = prefix.substring (0, openBracks);
  5170. }
  5171. }
  5172. // also use brackets if it ends in a digit.
  5173. putNumbersInBrackets = putNumbersInBrackets
  5174. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5175. do
  5176. {
  5177. if (putNumbersInBrackets)
  5178. f = getChildFile (prefix + '(' + String (num++) + ')' + suffix);
  5179. else
  5180. f = getChildFile (prefix + String (num++) + suffix);
  5181. } while (f.exists());
  5182. }
  5183. return f;
  5184. }
  5185. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5186. {
  5187. if (exists())
  5188. {
  5189. return getParentDirectory()
  5190. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5191. getFileExtension(),
  5192. putNumbersInBrackets);
  5193. }
  5194. else
  5195. {
  5196. return *this;
  5197. }
  5198. }
  5199. const String File::getFileExtension() const
  5200. {
  5201. String ext;
  5202. if (! isDirectory())
  5203. {
  5204. const int indexOfDot = fullPath.lastIndexOfChar ('.');
  5205. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5206. ext = fullPath.substring (indexOfDot);
  5207. }
  5208. return ext;
  5209. }
  5210. bool File::hasFileExtension (const String& possibleSuffix) const
  5211. {
  5212. if (possibleSuffix.isEmpty())
  5213. return fullPath.lastIndexOfChar ('.') <= fullPath.lastIndexOfChar (separator);
  5214. const int semicolon = possibleSuffix.indexOfChar (0, ';');
  5215. if (semicolon >= 0)
  5216. {
  5217. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5218. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5219. }
  5220. else
  5221. {
  5222. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5223. {
  5224. if (possibleSuffix.startsWithChar ('.'))
  5225. return true;
  5226. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5227. if (dotPos >= 0)
  5228. return fullPath [dotPos] == '.';
  5229. }
  5230. }
  5231. return false;
  5232. }
  5233. const File File::withFileExtension (const String& newExtension) const
  5234. {
  5235. if (fullPath.isEmpty())
  5236. return File::nonexistent;
  5237. String filePart (getFileName());
  5238. int i = filePart.lastIndexOfChar ('.');
  5239. if (i >= 0)
  5240. filePart = filePart.substring (0, i);
  5241. if (newExtension.isNotEmpty() && ! newExtension.startsWithChar ('.'))
  5242. filePart << '.';
  5243. return getSiblingFile (filePart + newExtension);
  5244. }
  5245. bool File::startAsProcess (const String& parameters) const
  5246. {
  5247. return exists() && juce_launchFile (fullPath, parameters);
  5248. }
  5249. FileInputStream* File::createInputStream() const
  5250. {
  5251. if (existsAsFile())
  5252. return new FileInputStream (*this);
  5253. return 0;
  5254. }
  5255. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5256. {
  5257. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5258. if (out->failedToOpen())
  5259. return 0;
  5260. return out.release();
  5261. }
  5262. bool File::appendData (const void* const dataToAppend,
  5263. const int numberOfBytes) const
  5264. {
  5265. if (numberOfBytes > 0)
  5266. {
  5267. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5268. if (out == 0)
  5269. return false;
  5270. out->write (dataToAppend, numberOfBytes);
  5271. }
  5272. return true;
  5273. }
  5274. bool File::replaceWithData (const void* const dataToWrite,
  5275. const int numberOfBytes) const
  5276. {
  5277. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5278. if (numberOfBytes <= 0)
  5279. return deleteFile();
  5280. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5281. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5282. return tempFile.overwriteTargetFileWithTemporary();
  5283. }
  5284. bool File::appendText (const String& text,
  5285. const bool asUnicode,
  5286. const bool writeUnicodeHeaderBytes) const
  5287. {
  5288. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5289. if (out != 0)
  5290. {
  5291. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5292. return true;
  5293. }
  5294. return false;
  5295. }
  5296. bool File::replaceWithText (const String& textToWrite,
  5297. const bool asUnicode,
  5298. const bool writeUnicodeHeaderBytes) const
  5299. {
  5300. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5301. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5302. return tempFile.overwriteTargetFileWithTemporary();
  5303. }
  5304. const String File::createLegalPathName (const String& original)
  5305. {
  5306. String s (original);
  5307. String start;
  5308. if (s[1] == ':')
  5309. {
  5310. start = s.substring (0, 2);
  5311. s = s.substring (2);
  5312. }
  5313. return start + s.removeCharacters ("\"#@,;:<>*^|?")
  5314. .substring (0, 1024);
  5315. }
  5316. const String File::createLegalFileName (const String& original)
  5317. {
  5318. String s (original.removeCharacters ("\"#@,;:<>*^|?\\/"));
  5319. const int maxLength = 128; // only the length of the filename, not the whole path
  5320. const int len = s.length();
  5321. if (len > maxLength)
  5322. {
  5323. const int lastDot = s.lastIndexOfChar ('.');
  5324. if (lastDot > jmax (0, len - 12))
  5325. {
  5326. s = s.substring (0, maxLength - (len - lastDot))
  5327. + s.substring (lastDot);
  5328. }
  5329. else
  5330. {
  5331. s = s.substring (0, maxLength);
  5332. }
  5333. }
  5334. return s;
  5335. }
  5336. const String File::getRelativePathFrom (const File& dir) const
  5337. {
  5338. String thisPath (fullPath);
  5339. {
  5340. int len = thisPath.length();
  5341. while (--len >= 0 && thisPath [len] == File::separator)
  5342. thisPath [len] = 0;
  5343. }
  5344. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5345. : dir.fullPath));
  5346. const int len = jmin (thisPath.length(), dirPath.length());
  5347. int commonBitLength = 0;
  5348. for (int i = 0; i < len; ++i)
  5349. {
  5350. #if NAMES_ARE_CASE_SENSITIVE
  5351. if (thisPath[i] != dirPath[i])
  5352. #else
  5353. if (CharacterFunctions::toLowerCase (thisPath[i])
  5354. != CharacterFunctions::toLowerCase (dirPath[i]))
  5355. #endif
  5356. {
  5357. break;
  5358. }
  5359. ++commonBitLength;
  5360. }
  5361. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5362. --commonBitLength;
  5363. // if the only common bit is the root, then just return the full path..
  5364. if (commonBitLength <= 0
  5365. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5366. return fullPath;
  5367. thisPath = thisPath.substring (commonBitLength);
  5368. dirPath = dirPath.substring (commonBitLength);
  5369. while (dirPath.isNotEmpty())
  5370. {
  5371. #if JUCE_WINDOWS
  5372. thisPath = "..\\" + thisPath;
  5373. #else
  5374. thisPath = "../" + thisPath;
  5375. #endif
  5376. const int sep = dirPath.indexOfChar (separator);
  5377. if (sep >= 0)
  5378. dirPath = dirPath.substring (sep + 1);
  5379. else
  5380. dirPath = String::empty;
  5381. }
  5382. return thisPath;
  5383. }
  5384. void File::findFileSystemRoots (Array<File>& destArray)
  5385. {
  5386. const StringArray roots (juce_getFileSystemRoots());
  5387. for (int i = 0; i < roots.size(); ++i)
  5388. destArray.add (File (roots[i]));
  5389. }
  5390. const String File::getVolumeLabel() const
  5391. {
  5392. int serialNum;
  5393. return juce_getVolumeLabel (fullPath, serialNum);
  5394. }
  5395. int File::getVolumeSerialNumber() const
  5396. {
  5397. int serialNum;
  5398. juce_getVolumeLabel (fullPath, serialNum);
  5399. return serialNum;
  5400. }
  5401. const File File::createTempFile (const String& fileNameEnding)
  5402. {
  5403. const File tempFile (getSpecialLocation (tempDirectory)
  5404. .getChildFile ("temp_" + String (Random::getSystemRandom().nextInt()))
  5405. .withFileExtension (fileNameEnding));
  5406. if (tempFile.exists())
  5407. return createTempFile (fileNameEnding);
  5408. else
  5409. return tempFile;
  5410. }
  5411. END_JUCE_NAMESPACE
  5412. /*** End of inlined file: juce_File.cpp ***/
  5413. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5414. BEGIN_JUCE_NAMESPACE
  5415. void* juce_fileOpen (const String& path, bool forWriting);
  5416. void juce_fileClose (void* handle);
  5417. int juce_fileRead (void* handle, void* buffer, int size);
  5418. int64 juce_fileSetPosition (void* handle, int64 pos);
  5419. FileInputStream::FileInputStream (const File& f)
  5420. : file (f),
  5421. currentPosition (0),
  5422. needToSeek (true)
  5423. {
  5424. totalSize = f.getSize();
  5425. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5426. }
  5427. FileInputStream::~FileInputStream()
  5428. {
  5429. juce_fileClose (fileHandle);
  5430. }
  5431. int64 FileInputStream::getTotalLength()
  5432. {
  5433. return totalSize;
  5434. }
  5435. int FileInputStream::read (void* buffer, int bytesToRead)
  5436. {
  5437. int num = 0;
  5438. if (needToSeek)
  5439. {
  5440. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5441. return 0;
  5442. needToSeek = false;
  5443. }
  5444. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5445. currentPosition += num;
  5446. return num;
  5447. }
  5448. bool FileInputStream::isExhausted()
  5449. {
  5450. return currentPosition >= totalSize;
  5451. }
  5452. int64 FileInputStream::getPosition()
  5453. {
  5454. return currentPosition;
  5455. }
  5456. bool FileInputStream::setPosition (int64 pos)
  5457. {
  5458. pos = jlimit ((int64) 0, totalSize, pos);
  5459. needToSeek |= (currentPosition != pos);
  5460. currentPosition = pos;
  5461. return true;
  5462. }
  5463. END_JUCE_NAMESPACE
  5464. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5465. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5466. BEGIN_JUCE_NAMESPACE
  5467. void* juce_fileOpen (const String& path, bool forWriting);
  5468. void juce_fileClose (void* handle);
  5469. int juce_fileWrite (void* handle, const void* buffer, int size);
  5470. void juce_fileFlush (void* handle);
  5471. int64 juce_fileGetPosition (void* handle);
  5472. int64 juce_fileSetPosition (void* handle, int64 pos);
  5473. FileOutputStream::FileOutputStream (const File& f,
  5474. const int bufferSize_)
  5475. : file (f),
  5476. bufferSize (bufferSize_),
  5477. bytesInBuffer (0)
  5478. {
  5479. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5480. if (fileHandle != 0)
  5481. {
  5482. currentPosition = juce_fileGetPosition (fileHandle);
  5483. if (currentPosition < 0)
  5484. {
  5485. jassertfalse
  5486. juce_fileClose (fileHandle);
  5487. fileHandle = 0;
  5488. }
  5489. }
  5490. buffer.malloc (jmax (bufferSize_, 16));
  5491. }
  5492. FileOutputStream::~FileOutputStream()
  5493. {
  5494. flush();
  5495. juce_fileClose (fileHandle);
  5496. }
  5497. int64 FileOutputStream::getPosition()
  5498. {
  5499. return currentPosition;
  5500. }
  5501. bool FileOutputStream::setPosition (int64 newPosition)
  5502. {
  5503. if (newPosition != currentPosition)
  5504. {
  5505. flush();
  5506. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5507. }
  5508. return newPosition == currentPosition;
  5509. }
  5510. void FileOutputStream::flush()
  5511. {
  5512. if (bytesInBuffer > 0)
  5513. {
  5514. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5515. bytesInBuffer = 0;
  5516. }
  5517. juce_fileFlush (fileHandle);
  5518. }
  5519. bool FileOutputStream::write (const void* const src, const int numBytes)
  5520. {
  5521. if (bytesInBuffer + numBytes < bufferSize)
  5522. {
  5523. memcpy (buffer + bytesInBuffer, src, numBytes);
  5524. bytesInBuffer += numBytes;
  5525. currentPosition += numBytes;
  5526. }
  5527. else
  5528. {
  5529. if (bytesInBuffer > 0)
  5530. {
  5531. // flush the reservoir
  5532. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5533. bytesInBuffer = 0;
  5534. if (! wroteOk)
  5535. return false;
  5536. }
  5537. if (numBytes < bufferSize)
  5538. {
  5539. memcpy (buffer + bytesInBuffer, src, numBytes);
  5540. bytesInBuffer += numBytes;
  5541. currentPosition += numBytes;
  5542. }
  5543. else
  5544. {
  5545. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5546. currentPosition += bytesWritten;
  5547. return bytesWritten == numBytes;
  5548. }
  5549. }
  5550. return true;
  5551. }
  5552. END_JUCE_NAMESPACE
  5553. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5554. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5555. BEGIN_JUCE_NAMESPACE
  5556. FileSearchPath::FileSearchPath()
  5557. {
  5558. }
  5559. FileSearchPath::FileSearchPath (const String& path)
  5560. {
  5561. init (path);
  5562. }
  5563. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5564. : directories (other.directories)
  5565. {
  5566. }
  5567. FileSearchPath::~FileSearchPath()
  5568. {
  5569. }
  5570. FileSearchPath& FileSearchPath::operator= (const String& path)
  5571. {
  5572. init (path);
  5573. return *this;
  5574. }
  5575. void FileSearchPath::init (const String& path)
  5576. {
  5577. directories.clear();
  5578. directories.addTokens (path, ";", "\"");
  5579. directories.trim();
  5580. directories.removeEmptyStrings();
  5581. for (int i = directories.size(); --i >= 0;)
  5582. directories.set (i, directories[i].unquoted());
  5583. }
  5584. int FileSearchPath::getNumPaths() const
  5585. {
  5586. return directories.size();
  5587. }
  5588. const File FileSearchPath::operator[] (const int index) const
  5589. {
  5590. return File (directories [index]);
  5591. }
  5592. const String FileSearchPath::toString() const
  5593. {
  5594. StringArray directories2 (directories);
  5595. for (int i = directories2.size(); --i >= 0;)
  5596. if (directories2[i].containsChar (';'))
  5597. directories2.set (i, directories2[i].quoted());
  5598. return directories2.joinIntoString (";");
  5599. }
  5600. void FileSearchPath::add (const File& dir, const int insertIndex)
  5601. {
  5602. directories.insert (insertIndex, dir.getFullPathName());
  5603. }
  5604. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5605. {
  5606. for (int i = 0; i < directories.size(); ++i)
  5607. if (File (directories[i]) == dir)
  5608. return;
  5609. add (dir);
  5610. }
  5611. void FileSearchPath::remove (const int index)
  5612. {
  5613. directories.remove (index);
  5614. }
  5615. void FileSearchPath::addPath (const FileSearchPath& other)
  5616. {
  5617. for (int i = 0; i < other.getNumPaths(); ++i)
  5618. addIfNotAlreadyThere (other[i]);
  5619. }
  5620. void FileSearchPath::removeRedundantPaths()
  5621. {
  5622. for (int i = directories.size(); --i >= 0;)
  5623. {
  5624. const File d1 (directories[i]);
  5625. for (int j = directories.size(); --j >= 0;)
  5626. {
  5627. const File d2 (directories[j]);
  5628. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5629. {
  5630. directories.remove (i);
  5631. break;
  5632. }
  5633. }
  5634. }
  5635. }
  5636. void FileSearchPath::removeNonExistentPaths()
  5637. {
  5638. for (int i = directories.size(); --i >= 0;)
  5639. if (! File (directories[i]).isDirectory())
  5640. directories.remove (i);
  5641. }
  5642. int FileSearchPath::findChildFiles (Array<File>& results,
  5643. const int whatToLookFor,
  5644. const bool searchRecursively,
  5645. const String& wildCardPattern) const
  5646. {
  5647. int total = 0;
  5648. for (int i = 0; i < directories.size(); ++i)
  5649. total += operator[] (i).findChildFiles (results,
  5650. whatToLookFor,
  5651. searchRecursively,
  5652. wildCardPattern);
  5653. return total;
  5654. }
  5655. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5656. const bool checkRecursively) const
  5657. {
  5658. for (int i = directories.size(); --i >= 0;)
  5659. {
  5660. const File d (directories[i]);
  5661. if (checkRecursively)
  5662. {
  5663. if (fileToCheck.isAChildOf (d))
  5664. return true;
  5665. }
  5666. else
  5667. {
  5668. if (fileToCheck.getParentDirectory() == d)
  5669. return true;
  5670. }
  5671. }
  5672. return false;
  5673. }
  5674. END_JUCE_NAMESPACE
  5675. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5676. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5677. BEGIN_JUCE_NAMESPACE
  5678. NamedPipe::NamedPipe()
  5679. : internal (0)
  5680. {
  5681. }
  5682. NamedPipe::~NamedPipe()
  5683. {
  5684. close();
  5685. }
  5686. bool NamedPipe::openExisting (const String& pipeName)
  5687. {
  5688. currentPipeName = pipeName;
  5689. return openInternal (pipeName, false);
  5690. }
  5691. bool NamedPipe::createNewPipe (const String& pipeName)
  5692. {
  5693. currentPipeName = pipeName;
  5694. return openInternal (pipeName, true);
  5695. }
  5696. bool NamedPipe::isOpen() const
  5697. {
  5698. return internal != 0;
  5699. }
  5700. const String NamedPipe::getName() const
  5701. {
  5702. return currentPipeName;
  5703. }
  5704. // other methods for this class are implemented in the platform-specific files
  5705. END_JUCE_NAMESPACE
  5706. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5707. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5708. BEGIN_JUCE_NAMESPACE
  5709. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5710. {
  5711. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5712. "temp_" + String (Random::getSystemRandom().nextInt()),
  5713. suffix,
  5714. optionFlags);
  5715. }
  5716. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5717. : targetFile (targetFile_)
  5718. {
  5719. // If you use this constructor, you need to give it a valid target file!
  5720. jassert (targetFile != File::nonexistent);
  5721. createTempFile (targetFile.getParentDirectory(),
  5722. targetFile.getFileNameWithoutExtension() + "_temp" + String (Random::getSystemRandom().nextInt()),
  5723. targetFile.getFileExtension(),
  5724. optionFlags);
  5725. }
  5726. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5727. const String& suffix, const int optionFlags)
  5728. {
  5729. if ((optionFlags & useHiddenFile) != 0)
  5730. name = "." + name;
  5731. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5732. }
  5733. TemporaryFile::~TemporaryFile()
  5734. {
  5735. // Have a few attempts at deleting the file before giving up..
  5736. for (int i = 5; --i >= 0;)
  5737. {
  5738. if (temporaryFile.deleteFile())
  5739. return;
  5740. Thread::sleep (50);
  5741. }
  5742. // Failed to delete our temporary file! Check that you've deleted all the
  5743. // file output streams that were using it!
  5744. jassertfalse;
  5745. }
  5746. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5747. {
  5748. // This method only works if you created this object with the constructor
  5749. // that takes a target file!
  5750. jassert (targetFile != File::nonexistent);
  5751. if (temporaryFile.exists())
  5752. {
  5753. // Have a few attempts at overwriting the file before giving up..
  5754. for (int i = 5; --i >= 0;)
  5755. {
  5756. if (temporaryFile.moveFileTo (targetFile))
  5757. return true;
  5758. Thread::sleep (100);
  5759. }
  5760. }
  5761. else
  5762. {
  5763. // There's no temporary file to use. If your write failed, you should
  5764. // probably check, and not bother calling this method.
  5765. jassertfalse
  5766. }
  5767. return false;
  5768. }
  5769. END_JUCE_NAMESPACE
  5770. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5771. /*** Start of inlined file: juce_Socket.cpp ***/
  5772. #if JUCE_WINDOWS
  5773. #include <winsock2.h>
  5774. #ifdef _MSC_VER
  5775. #pragma warning (disable : 4127 4389 4018)
  5776. #endif
  5777. #else
  5778. #if JUCE_LINUX
  5779. #include <sys/types.h>
  5780. #include <sys/socket.h>
  5781. #include <sys/errno.h>
  5782. #include <unistd.h>
  5783. #include <netinet/in.h>
  5784. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5785. #include <CoreServices/CoreServices.h>
  5786. #endif
  5787. #include <fcntl.h>
  5788. #include <netdb.h>
  5789. #include <arpa/inet.h>
  5790. #include <netinet/tcp.h>
  5791. #endif
  5792. BEGIN_JUCE_NAMESPACE
  5793. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5794. typedef socklen_t juce_socklen_t;
  5795. #else
  5796. typedef int juce_socklen_t;
  5797. #endif
  5798. #if JUCE_WINDOWS
  5799. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5800. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5801. static void initWin32Sockets()
  5802. {
  5803. static CriticalSection lock;
  5804. const ScopedLock sl (lock);
  5805. if (juce_CloseWin32SocketLib == 0)
  5806. {
  5807. WSADATA wsaData;
  5808. const WORD wVersionRequested = MAKEWORD (1, 1);
  5809. WSAStartup (wVersionRequested, &wsaData);
  5810. juce_CloseWin32SocketLib = &WSACleanup;
  5811. }
  5812. }
  5813. #endif
  5814. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5815. {
  5816. const int sndBufSize = 65536;
  5817. const int rcvBufSize = 65536;
  5818. const int one = 1;
  5819. return handle > 0
  5820. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5821. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5822. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5823. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5824. }
  5825. static bool bindSocketToPort (const int handle, const int port) throw()
  5826. {
  5827. if (handle <= 0 || port <= 0)
  5828. return false;
  5829. struct sockaddr_in servTmpAddr;
  5830. zerostruct (servTmpAddr);
  5831. servTmpAddr.sin_family = PF_INET;
  5832. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5833. servTmpAddr.sin_port = htons ((uint16) port);
  5834. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5835. }
  5836. static int readSocket (const int handle,
  5837. void* const destBuffer, const int maxBytesToRead,
  5838. bool volatile& connected,
  5839. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5840. {
  5841. int bytesRead = 0;
  5842. while (bytesRead < maxBytesToRead)
  5843. {
  5844. int bytesThisTime;
  5845. #if JUCE_WINDOWS
  5846. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5847. #else
  5848. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5849. && errno == EINTR
  5850. && connected)
  5851. {
  5852. }
  5853. #endif
  5854. if (bytesThisTime <= 0 || ! connected)
  5855. {
  5856. if (bytesRead == 0)
  5857. bytesRead = -1;
  5858. break;
  5859. }
  5860. bytesRead += bytesThisTime;
  5861. if (! blockUntilSpecifiedAmountHasArrived)
  5862. break;
  5863. }
  5864. return bytesRead;
  5865. }
  5866. static int waitForReadiness (const int handle, const bool forReading,
  5867. const int timeoutMsecs) throw()
  5868. {
  5869. struct timeval timeout;
  5870. struct timeval* timeoutp;
  5871. if (timeoutMsecs >= 0)
  5872. {
  5873. timeout.tv_sec = timeoutMsecs / 1000;
  5874. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5875. timeoutp = &timeout;
  5876. }
  5877. else
  5878. {
  5879. timeoutp = 0;
  5880. }
  5881. fd_set rset, wset;
  5882. FD_ZERO (&rset);
  5883. FD_SET (handle, &rset);
  5884. FD_ZERO (&wset);
  5885. FD_SET (handle, &wset);
  5886. fd_set* const prset = forReading ? &rset : 0;
  5887. fd_set* const pwset = forReading ? 0 : &wset;
  5888. #if JUCE_WINDOWS
  5889. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5890. return -1;
  5891. #else
  5892. {
  5893. int result;
  5894. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5895. && errno == EINTR)
  5896. {
  5897. }
  5898. if (result < 0)
  5899. return -1;
  5900. }
  5901. #endif
  5902. {
  5903. int opt;
  5904. juce_socklen_t len = sizeof (opt);
  5905. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5906. || opt != 0)
  5907. return -1;
  5908. }
  5909. if ((forReading && FD_ISSET (handle, &rset))
  5910. || ((! forReading) && FD_ISSET (handle, &wset)))
  5911. return 1;
  5912. return 0;
  5913. }
  5914. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5915. {
  5916. #if JUCE_WINDOWS
  5917. u_long nonBlocking = shouldBlock ? 0 : 1;
  5918. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5919. return false;
  5920. #else
  5921. int socketFlags = fcntl (handle, F_GETFL, 0);
  5922. if (socketFlags == -1)
  5923. return false;
  5924. if (shouldBlock)
  5925. socketFlags &= ~O_NONBLOCK;
  5926. else
  5927. socketFlags |= O_NONBLOCK;
  5928. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5929. return false;
  5930. #endif
  5931. return true;
  5932. }
  5933. static bool connectSocket (int volatile& handle,
  5934. const bool isDatagram,
  5935. void** serverAddress,
  5936. const String& hostName,
  5937. const int portNumber,
  5938. const int timeOutMillisecs) throw()
  5939. {
  5940. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  5941. if (hostEnt == 0)
  5942. return false;
  5943. struct in_addr targetAddress;
  5944. memcpy (&targetAddress.s_addr,
  5945. *(hostEnt->h_addr_list),
  5946. sizeof (targetAddress.s_addr));
  5947. struct sockaddr_in servTmpAddr;
  5948. zerostruct (servTmpAddr);
  5949. servTmpAddr.sin_family = PF_INET;
  5950. servTmpAddr.sin_addr = targetAddress;
  5951. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5952. if (handle < 0)
  5953. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5954. if (handle < 0)
  5955. return false;
  5956. if (isDatagram)
  5957. {
  5958. *serverAddress = new struct sockaddr_in();
  5959. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  5960. return true;
  5961. }
  5962. setSocketBlockingState (handle, false);
  5963. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  5964. if (result < 0)
  5965. {
  5966. #if JUCE_WINDOWS
  5967. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  5968. #else
  5969. if (errno == EINPROGRESS)
  5970. #endif
  5971. {
  5972. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  5973. {
  5974. setSocketBlockingState (handle, true);
  5975. return false;
  5976. }
  5977. }
  5978. }
  5979. setSocketBlockingState (handle, true);
  5980. resetSocketOptions (handle, false, false);
  5981. return true;
  5982. }
  5983. StreamingSocket::StreamingSocket()
  5984. : portNumber (0),
  5985. handle (-1),
  5986. connected (false),
  5987. isListener (false)
  5988. {
  5989. #if JUCE_WINDOWS
  5990. initWin32Sockets();
  5991. #endif
  5992. }
  5993. StreamingSocket::StreamingSocket (const String& hostName_,
  5994. const int portNumber_,
  5995. const int handle_)
  5996. : hostName (hostName_),
  5997. portNumber (portNumber_),
  5998. handle (handle_),
  5999. connected (true),
  6000. isListener (false)
  6001. {
  6002. #if JUCE_WINDOWS
  6003. initWin32Sockets();
  6004. #endif
  6005. resetSocketOptions (handle_, false, false);
  6006. }
  6007. StreamingSocket::~StreamingSocket()
  6008. {
  6009. close();
  6010. }
  6011. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6012. {
  6013. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6014. : -1;
  6015. }
  6016. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6017. {
  6018. if (isListener || ! connected)
  6019. return -1;
  6020. #if JUCE_WINDOWS
  6021. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6022. #else
  6023. int result;
  6024. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6025. && errno == EINTR)
  6026. {
  6027. }
  6028. return result;
  6029. #endif
  6030. }
  6031. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6032. const int timeoutMsecs) const
  6033. {
  6034. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6035. : -1;
  6036. }
  6037. bool StreamingSocket::bindToPort (const int port)
  6038. {
  6039. return bindSocketToPort (handle, port);
  6040. }
  6041. bool StreamingSocket::connect (const String& remoteHostName,
  6042. const int remotePortNumber,
  6043. const int timeOutMillisecs)
  6044. {
  6045. if (isListener)
  6046. {
  6047. jassertfalse // a listener socket can't connect to another one!
  6048. return false;
  6049. }
  6050. if (connected)
  6051. close();
  6052. hostName = remoteHostName;
  6053. portNumber = remotePortNumber;
  6054. isListener = false;
  6055. connected = connectSocket (handle, false, 0, remoteHostName,
  6056. remotePortNumber, timeOutMillisecs);
  6057. if (! (connected && resetSocketOptions (handle, false, false)))
  6058. {
  6059. close();
  6060. return false;
  6061. }
  6062. return true;
  6063. }
  6064. void StreamingSocket::close()
  6065. {
  6066. #if JUCE_WINDOWS
  6067. closesocket (handle);
  6068. connected = false;
  6069. #else
  6070. if (connected)
  6071. {
  6072. connected = false;
  6073. if (isListener)
  6074. {
  6075. // need to do this to interrupt the accept() function..
  6076. StreamingSocket temp;
  6077. temp.connect ("localhost", portNumber, 1000);
  6078. }
  6079. }
  6080. ::close (handle);
  6081. #endif
  6082. hostName = String::empty;
  6083. portNumber = 0;
  6084. handle = -1;
  6085. isListener = false;
  6086. }
  6087. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6088. {
  6089. if (connected)
  6090. close();
  6091. hostName = "listener";
  6092. portNumber = newPortNumber;
  6093. isListener = true;
  6094. struct sockaddr_in servTmpAddr;
  6095. zerostruct (servTmpAddr);
  6096. servTmpAddr.sin_family = PF_INET;
  6097. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6098. if (localHostName.isNotEmpty())
  6099. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6100. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6101. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6102. if (handle < 0)
  6103. return false;
  6104. const int reuse = 1;
  6105. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6106. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6107. || listen (handle, SOMAXCONN) < 0)
  6108. {
  6109. close();
  6110. return false;
  6111. }
  6112. connected = true;
  6113. return true;
  6114. }
  6115. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6116. {
  6117. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6118. // prepare this socket as a listener.
  6119. if (connected && isListener)
  6120. {
  6121. struct sockaddr address;
  6122. juce_socklen_t len = sizeof (sockaddr);
  6123. const int newSocket = (int) accept (handle, &address, &len);
  6124. if (newSocket >= 0 && connected)
  6125. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6126. portNumber, newSocket);
  6127. }
  6128. return 0;
  6129. }
  6130. bool StreamingSocket::isLocal() const throw()
  6131. {
  6132. return hostName == "127.0.0.1";
  6133. }
  6134. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6135. : portNumber (0),
  6136. handle (-1),
  6137. connected (true),
  6138. allowBroadcast (allowBroadcast_),
  6139. serverAddress (0)
  6140. {
  6141. #if JUCE_WINDOWS
  6142. initWin32Sockets();
  6143. #endif
  6144. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6145. bindToPort (localPortNumber);
  6146. }
  6147. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6148. const int handle_, const int localPortNumber)
  6149. : hostName (hostName_),
  6150. portNumber (portNumber_),
  6151. handle (handle_),
  6152. connected (true),
  6153. allowBroadcast (false),
  6154. serverAddress (0)
  6155. {
  6156. #if JUCE_WINDOWS
  6157. initWin32Sockets();
  6158. #endif
  6159. resetSocketOptions (handle_, true, allowBroadcast);
  6160. bindToPort (localPortNumber);
  6161. }
  6162. DatagramSocket::~DatagramSocket()
  6163. {
  6164. close();
  6165. delete ((struct sockaddr_in*) serverAddress);
  6166. serverAddress = 0;
  6167. }
  6168. void DatagramSocket::close()
  6169. {
  6170. #if JUCE_WINDOWS
  6171. closesocket (handle);
  6172. connected = false;
  6173. #else
  6174. connected = false;
  6175. ::close (handle);
  6176. #endif
  6177. hostName = String::empty;
  6178. portNumber = 0;
  6179. handle = -1;
  6180. }
  6181. bool DatagramSocket::bindToPort (const int port)
  6182. {
  6183. return bindSocketToPort (handle, port);
  6184. }
  6185. bool DatagramSocket::connect (const String& remoteHostName,
  6186. const int remotePortNumber,
  6187. const int timeOutMillisecs)
  6188. {
  6189. if (connected)
  6190. close();
  6191. hostName = remoteHostName;
  6192. portNumber = remotePortNumber;
  6193. connected = connectSocket (handle, true, &serverAddress,
  6194. remoteHostName, remotePortNumber,
  6195. timeOutMillisecs);
  6196. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6197. {
  6198. close();
  6199. return false;
  6200. }
  6201. return true;
  6202. }
  6203. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6204. {
  6205. struct sockaddr address;
  6206. juce_socklen_t len = sizeof (sockaddr);
  6207. while (waitUntilReady (true, -1) == 1)
  6208. {
  6209. char buf[1];
  6210. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6211. {
  6212. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6213. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6214. -1, -1);
  6215. }
  6216. }
  6217. return 0;
  6218. }
  6219. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6220. const int timeoutMsecs) const
  6221. {
  6222. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6223. : -1;
  6224. }
  6225. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6226. {
  6227. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6228. : -1;
  6229. }
  6230. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6231. {
  6232. // You need to call connect() first to set the server address..
  6233. jassert (serverAddress != 0 && connected);
  6234. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6235. numBytesToWrite, 0,
  6236. (const struct sockaddr*) serverAddress,
  6237. sizeof (struct sockaddr_in))
  6238. : -1;
  6239. }
  6240. bool DatagramSocket::isLocal() const throw()
  6241. {
  6242. return hostName == "127.0.0.1";
  6243. }
  6244. END_JUCE_NAMESPACE
  6245. /*** End of inlined file: juce_Socket.cpp ***/
  6246. /*** Start of inlined file: juce_URL.cpp ***/
  6247. BEGIN_JUCE_NAMESPACE
  6248. URL::URL()
  6249. {
  6250. }
  6251. URL::URL (const String& url_)
  6252. : url (url_)
  6253. {
  6254. int i = url.indexOfChar ('?');
  6255. if (i >= 0)
  6256. {
  6257. do
  6258. {
  6259. const int nextAmp = url.indexOfChar (i + 1, '&');
  6260. const int equalsPos = url.indexOfChar (i + 1, '=');
  6261. if (equalsPos > i + 1)
  6262. {
  6263. if (nextAmp < 0)
  6264. {
  6265. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6266. removeEscapeChars (url.substring (equalsPos + 1)));
  6267. }
  6268. else if (nextAmp > 0 && equalsPos < nextAmp)
  6269. {
  6270. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6271. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6272. }
  6273. }
  6274. i = nextAmp;
  6275. }
  6276. while (i >= 0);
  6277. url = url.upToFirstOccurrenceOf ("?", false, false);
  6278. }
  6279. }
  6280. URL::URL (const URL& other)
  6281. : url (other.url),
  6282. postData (other.postData),
  6283. parameters (other.parameters),
  6284. filesToUpload (other.filesToUpload),
  6285. mimeTypes (other.mimeTypes)
  6286. {
  6287. }
  6288. URL& URL::operator= (const URL& other)
  6289. {
  6290. url = other.url;
  6291. postData = other.postData;
  6292. parameters = other.parameters;
  6293. filesToUpload = other.filesToUpload;
  6294. mimeTypes = other.mimeTypes;
  6295. return *this;
  6296. }
  6297. URL::~URL()
  6298. {
  6299. }
  6300. static const String getMangledParameters (const StringPairArray& parameters)
  6301. {
  6302. String p;
  6303. for (int i = 0; i < parameters.size(); ++i)
  6304. {
  6305. if (i > 0)
  6306. p += '&';
  6307. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6308. << '='
  6309. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6310. }
  6311. return p;
  6312. }
  6313. const String URL::toString (const bool includeGetParameters) const
  6314. {
  6315. if (includeGetParameters && parameters.size() > 0)
  6316. return url + "?" + getMangledParameters (parameters);
  6317. else
  6318. return url;
  6319. }
  6320. bool URL::isWellFormed() const
  6321. {
  6322. //xxx TODO
  6323. return url.isNotEmpty();
  6324. }
  6325. static int findStartOfDomain (const String& url)
  6326. {
  6327. int i = 0;
  6328. while (CharacterFunctions::isLetterOrDigit (url[i])
  6329. || CharacterFunctions::indexOfChar (L"+-.", url[i], false) >= 0)
  6330. ++i;
  6331. return url[i] == ':' ? i + 1 : 0;
  6332. }
  6333. const String URL::getDomain() const
  6334. {
  6335. int start = findStartOfDomain (url);
  6336. while (url[start] == '/')
  6337. ++start;
  6338. const int end1 = url.indexOfChar (start, '/');
  6339. const int end2 = url.indexOfChar (start, ':');
  6340. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6341. : jmin (end1, end2);
  6342. return url.substring (start, end);
  6343. }
  6344. const String URL::getSubPath() const
  6345. {
  6346. int start = findStartOfDomain (url);
  6347. while (url[start] == '/')
  6348. ++start;
  6349. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6350. return startOfPath <= 0 ? String::empty
  6351. : url.substring (startOfPath);
  6352. }
  6353. const String URL::getScheme() const
  6354. {
  6355. return url.substring (0, findStartOfDomain (url) - 1);
  6356. }
  6357. const URL URL::withNewSubPath (const String& newPath) const
  6358. {
  6359. int start = findStartOfDomain (url);
  6360. while (url[start] == '/')
  6361. ++start;
  6362. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6363. URL u (*this);
  6364. if (startOfPath > 0)
  6365. u.url = url.substring (0, startOfPath);
  6366. if (! u.url.endsWithChar ('/'))
  6367. u.url << '/';
  6368. if (newPath.startsWithChar ('/'))
  6369. u.url << newPath.substring (1);
  6370. else
  6371. u.url << newPath;
  6372. return u;
  6373. }
  6374. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6375. {
  6376. if (possibleURL.startsWithIgnoreCase ("http:")
  6377. || possibleURL.startsWithIgnoreCase ("ftp:"))
  6378. return true;
  6379. if (possibleURL.startsWithIgnoreCase ("file:")
  6380. || possibleURL.containsChar ('@')
  6381. || possibleURL.endsWithChar ('.')
  6382. || (! possibleURL.containsChar ('.')))
  6383. return false;
  6384. if (possibleURL.startsWithIgnoreCase ("www.")
  6385. && possibleURL.substring (5).containsChar ('.'))
  6386. return true;
  6387. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6388. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6389. if ((possibleURL + "/").containsIgnoreCase ("." + String (commonTLDs[i]) + "/"))
  6390. return true;
  6391. return false;
  6392. }
  6393. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6394. {
  6395. const int atSign = possibleEmailAddress.indexOfChar ('@');
  6396. return atSign > 0
  6397. && possibleEmailAddress.lastIndexOfChar ('.') > (atSign + 1)
  6398. && (! possibleEmailAddress.endsWithChar ('.'));
  6399. }
  6400. void* juce_openInternetFile (const String& url,
  6401. const String& headers,
  6402. const MemoryBlock& optionalPostData,
  6403. const bool isPost,
  6404. URL::OpenStreamProgressCallback* callback,
  6405. void* callbackContext,
  6406. int timeOutMs);
  6407. void juce_closeInternetFile (void* handle);
  6408. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6409. int juce_seekInInternetFile (void* handle, int newPosition);
  6410. int64 juce_getInternetFileContentLength (void* handle);
  6411. class WebInputStream : public InputStream
  6412. {
  6413. public:
  6414. WebInputStream (const URL& url,
  6415. const bool isPost_,
  6416. URL::OpenStreamProgressCallback* const progressCallback_,
  6417. void* const progressCallbackContext_,
  6418. const String& extraHeaders,
  6419. int timeOutMs_)
  6420. : position (0),
  6421. finished (false),
  6422. isPost (isPost_),
  6423. progressCallback (progressCallback_),
  6424. progressCallbackContext (progressCallbackContext_),
  6425. timeOutMs (timeOutMs_)
  6426. {
  6427. server = url.toString (! isPost);
  6428. if (isPost_)
  6429. createHeadersAndPostData (url);
  6430. headers += extraHeaders;
  6431. if (! headers.endsWithChar ('\n'))
  6432. headers << "\r\n";
  6433. handle = juce_openInternetFile (server, headers, postData, isPost,
  6434. progressCallback_, progressCallbackContext_,
  6435. timeOutMs);
  6436. }
  6437. ~WebInputStream()
  6438. {
  6439. juce_closeInternetFile (handle);
  6440. }
  6441. bool isError() const
  6442. {
  6443. return handle == 0;
  6444. }
  6445. int64 getTotalLength()
  6446. {
  6447. return juce_getInternetFileContentLength (handle);
  6448. }
  6449. bool isExhausted()
  6450. {
  6451. return finished;
  6452. }
  6453. int read (void* dest, int bytes)
  6454. {
  6455. if (finished || isError())
  6456. {
  6457. return 0;
  6458. }
  6459. else
  6460. {
  6461. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6462. position += bytesRead;
  6463. if (bytesRead == 0)
  6464. finished = true;
  6465. return bytesRead;
  6466. }
  6467. }
  6468. int64 getPosition()
  6469. {
  6470. return position;
  6471. }
  6472. bool setPosition (int64 wantedPos)
  6473. {
  6474. if (wantedPos != position)
  6475. {
  6476. finished = false;
  6477. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6478. if (actualPos == wantedPos)
  6479. {
  6480. position = wantedPos;
  6481. }
  6482. else
  6483. {
  6484. if (wantedPos < position)
  6485. {
  6486. juce_closeInternetFile (handle);
  6487. position = 0;
  6488. finished = false;
  6489. handle = juce_openInternetFile (server, headers, postData, isPost,
  6490. progressCallback, progressCallbackContext,
  6491. timeOutMs);
  6492. }
  6493. skipNextBytes (wantedPos - position);
  6494. }
  6495. }
  6496. return true;
  6497. }
  6498. juce_UseDebuggingNewOperator
  6499. private:
  6500. String server, headers;
  6501. MemoryBlock postData;
  6502. int64 position;
  6503. bool finished;
  6504. const bool isPost;
  6505. void* handle;
  6506. URL::OpenStreamProgressCallback* const progressCallback;
  6507. void* const progressCallbackContext;
  6508. const int timeOutMs;
  6509. void createHeadersAndPostData (const URL& url)
  6510. {
  6511. if (url.getFilesToUpload().size() > 0)
  6512. {
  6513. // need to upload some files, so do it as multi-part...
  6514. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6515. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6516. appendUTF8ToPostData ("--" + boundary);
  6517. int i;
  6518. for (i = 0; i < url.getParameters().size(); ++i)
  6519. {
  6520. String s;
  6521. s << "\r\nContent-Disposition: form-data; name=\""
  6522. << url.getParameters().getAllKeys() [i]
  6523. << "\"\r\n\r\n"
  6524. << url.getParameters().getAllValues() [i]
  6525. << "\r\n--"
  6526. << boundary;
  6527. appendUTF8ToPostData (s);
  6528. }
  6529. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6530. {
  6531. const File f (url.getFilesToUpload().getAllValues() [i]);
  6532. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6533. String s;
  6534. s << "\r\nContent-Disposition: form-data; name=\""
  6535. << paramName
  6536. << "\"; filename=\""
  6537. << f.getFileName()
  6538. << "\"\r\n";
  6539. const String mimeType (url.getMimeTypesOfUploadFiles()
  6540. .getValue (paramName, String::empty));
  6541. if (mimeType.isNotEmpty())
  6542. s << "Content-Type: " << mimeType << "\r\n";
  6543. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6544. appendUTF8ToPostData (s);
  6545. f.loadFileAsData (postData);
  6546. s = "\r\n--" + boundary;
  6547. appendUTF8ToPostData (s);
  6548. }
  6549. appendUTF8ToPostData ("--\r\n");
  6550. }
  6551. else
  6552. {
  6553. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6554. appendUTF8ToPostData (url.getPostData());
  6555. // just a short text attachment, so use simple url encoding..
  6556. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6557. + String ((unsigned int) postData.getSize())
  6558. + "\r\n";
  6559. }
  6560. }
  6561. void appendUTF8ToPostData (const String& text)
  6562. {
  6563. postData.append (text.toUTF8(),
  6564. (int) strlen (text.toUTF8()));
  6565. }
  6566. WebInputStream (const WebInputStream&);
  6567. WebInputStream& operator= (const WebInputStream&);
  6568. };
  6569. InputStream* URL::createInputStream (const bool usePostCommand,
  6570. OpenStreamProgressCallback* const progressCallback,
  6571. void* const progressCallbackContext,
  6572. const String& extraHeaders,
  6573. const int timeOutMs) const
  6574. {
  6575. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6576. progressCallback, progressCallbackContext,
  6577. extraHeaders,
  6578. timeOutMs));
  6579. return wi->isError() ? 0 : wi.release();
  6580. }
  6581. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6582. const bool usePostCommand) const
  6583. {
  6584. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6585. if (in != 0)
  6586. {
  6587. in->readIntoMemoryBlock (destData, -1);
  6588. return true;
  6589. }
  6590. return false;
  6591. }
  6592. const String URL::readEntireTextStream (const bool usePostCommand) const
  6593. {
  6594. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6595. if (in != 0)
  6596. return in->readEntireStreamAsString();
  6597. return String::empty;
  6598. }
  6599. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6600. {
  6601. XmlDocument doc (readEntireTextStream (usePostCommand));
  6602. return doc.getDocumentElement();
  6603. }
  6604. const URL URL::withParameter (const String& parameterName,
  6605. const String& parameterValue) const
  6606. {
  6607. URL u (*this);
  6608. u.parameters.set (parameterName, parameterValue);
  6609. return u;
  6610. }
  6611. const URL URL::withFileToUpload (const String& parameterName,
  6612. const File& fileToUpload,
  6613. const String& mimeType) const
  6614. {
  6615. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6616. URL u (*this);
  6617. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6618. u.mimeTypes.set (parameterName, mimeType);
  6619. return u;
  6620. }
  6621. const URL URL::withPOSTData (const String& postData_) const
  6622. {
  6623. URL u (*this);
  6624. u.postData = postData_;
  6625. return u;
  6626. }
  6627. const StringPairArray& URL::getParameters() const
  6628. {
  6629. return parameters;
  6630. }
  6631. const StringPairArray& URL::getFilesToUpload() const
  6632. {
  6633. return filesToUpload;
  6634. }
  6635. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6636. {
  6637. return mimeTypes;
  6638. }
  6639. const String URL::removeEscapeChars (const String& s)
  6640. {
  6641. String result (s.replaceCharacter ('+', ' '));
  6642. int nextPercent = 0;
  6643. for (;;)
  6644. {
  6645. nextPercent = result.indexOfChar (nextPercent, '%');
  6646. if (nextPercent < 0)
  6647. break;
  6648. juce_wchar replacementChar = result.substring (nextPercent + 1, nextPercent + 3).getHexValue32();
  6649. result = result.replaceSection (nextPercent, 3, String::charToString (replacementChar));
  6650. ++nextPercent;
  6651. }
  6652. return result;
  6653. }
  6654. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6655. {
  6656. String result;
  6657. result.preallocateStorage (s.length() + 8);
  6658. const char* utf8 = s.toUTF8();
  6659. const char* legalChars = isParameter ? "_-.*!'()"
  6660. : "_-$.*!'(),";
  6661. while (*utf8 != 0)
  6662. {
  6663. const char c = *utf8++;
  6664. if (CharacterFunctions::isLetterOrDigit (c)
  6665. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6666. {
  6667. result << c;
  6668. }
  6669. else
  6670. {
  6671. const int v = (int) (uint8) c;
  6672. result << (v < 0x10 ? "%0" : "%") << String::toHexString (v);
  6673. }
  6674. }
  6675. return result;
  6676. }
  6677. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6678. bool URL::launchInDefaultBrowser() const
  6679. {
  6680. String u (toString (true));
  6681. if (u.containsChar ('@') && ! u.containsChar (':'))
  6682. u = "mailto:" + u;
  6683. return juce_launchFile (u, String::empty);
  6684. }
  6685. END_JUCE_NAMESPACE
  6686. /*** End of inlined file: juce_URL.cpp ***/
  6687. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6688. BEGIN_JUCE_NAMESPACE
  6689. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6690. const int bufferSize_,
  6691. const bool deleteSourceWhenDestroyed)
  6692. : source (source_),
  6693. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6694. bufferSize (jmax (256, bufferSize_)),
  6695. position (source_->getPosition()),
  6696. lastReadPos (0),
  6697. bufferOverlap (128)
  6698. {
  6699. const int sourceSize = (int) source_->getTotalLength();
  6700. if (sourceSize >= 0)
  6701. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6702. bufferStart = position;
  6703. buffer.malloc (bufferSize);
  6704. }
  6705. BufferedInputStream::~BufferedInputStream()
  6706. {
  6707. }
  6708. int64 BufferedInputStream::getTotalLength()
  6709. {
  6710. return source->getTotalLength();
  6711. }
  6712. int64 BufferedInputStream::getPosition()
  6713. {
  6714. return position;
  6715. }
  6716. bool BufferedInputStream::setPosition (int64 newPosition)
  6717. {
  6718. position = jmax ((int64) 0, newPosition);
  6719. return true;
  6720. }
  6721. bool BufferedInputStream::isExhausted()
  6722. {
  6723. return (position >= lastReadPos)
  6724. && source->isExhausted();
  6725. }
  6726. void BufferedInputStream::ensureBuffered()
  6727. {
  6728. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6729. if (position < bufferStart || position >= bufferEndOverlap)
  6730. {
  6731. int bytesRead;
  6732. if (position < lastReadPos
  6733. && position >= bufferEndOverlap
  6734. && position >= bufferStart)
  6735. {
  6736. const int bytesToKeep = (int) (lastReadPos - position);
  6737. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6738. bufferStart = position;
  6739. bytesRead = source->read (buffer + bytesToKeep,
  6740. bufferSize - bytesToKeep);
  6741. lastReadPos += bytesRead;
  6742. bytesRead += bytesToKeep;
  6743. }
  6744. else
  6745. {
  6746. bufferStart = position;
  6747. source->setPosition (bufferStart);
  6748. bytesRead = source->read (buffer, bufferSize);
  6749. lastReadPos = bufferStart + bytesRead;
  6750. }
  6751. while (bytesRead < bufferSize)
  6752. buffer [bytesRead++] = 0;
  6753. }
  6754. }
  6755. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6756. {
  6757. if (position >= bufferStart
  6758. && position + maxBytesToRead <= lastReadPos)
  6759. {
  6760. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6761. position += maxBytesToRead;
  6762. return maxBytesToRead;
  6763. }
  6764. else
  6765. {
  6766. if (position < bufferStart || position >= lastReadPos)
  6767. ensureBuffered();
  6768. int bytesRead = 0;
  6769. while (maxBytesToRead > 0)
  6770. {
  6771. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6772. if (bytesAvailable > 0)
  6773. {
  6774. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6775. maxBytesToRead -= bytesAvailable;
  6776. bytesRead += bytesAvailable;
  6777. position += bytesAvailable;
  6778. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6779. }
  6780. const int64 oldLastReadPos = lastReadPos;
  6781. ensureBuffered();
  6782. if (oldLastReadPos == lastReadPos)
  6783. break; // if ensureBuffered() failed to read any more data, bail out
  6784. if (isExhausted())
  6785. break;
  6786. }
  6787. return bytesRead;
  6788. }
  6789. }
  6790. const String BufferedInputStream::readString()
  6791. {
  6792. if (position >= bufferStart
  6793. && position < lastReadPos)
  6794. {
  6795. const int maxChars = (int) (lastReadPos - position);
  6796. const char* const src = buffer + (int) (position - bufferStart);
  6797. for (int i = 0; i < maxChars; ++i)
  6798. {
  6799. if (src[i] == 0)
  6800. {
  6801. position += i + 1;
  6802. return String::fromUTF8 (src, i);
  6803. }
  6804. }
  6805. }
  6806. return InputStream::readString();
  6807. }
  6808. END_JUCE_NAMESPACE
  6809. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6810. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6811. BEGIN_JUCE_NAMESPACE
  6812. FileInputSource::FileInputSource (const File& file_)
  6813. : file (file_)
  6814. {
  6815. }
  6816. FileInputSource::~FileInputSource()
  6817. {
  6818. }
  6819. InputStream* FileInputSource::createInputStream()
  6820. {
  6821. return file.createInputStream();
  6822. }
  6823. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6824. {
  6825. return file.getSiblingFile (relatedItemPath).createInputStream();
  6826. }
  6827. int64 FileInputSource::hashCode() const
  6828. {
  6829. return file.hashCode();
  6830. }
  6831. END_JUCE_NAMESPACE
  6832. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6833. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6834. BEGIN_JUCE_NAMESPACE
  6835. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6836. const size_t sourceDataSize,
  6837. const bool keepInternalCopy)
  6838. : data (static_cast <const char*> (sourceData)),
  6839. dataSize (sourceDataSize),
  6840. position (0)
  6841. {
  6842. if (keepInternalCopy)
  6843. {
  6844. internalCopy.append (data, sourceDataSize);
  6845. data = static_cast <const char*> (internalCopy.getData());
  6846. }
  6847. }
  6848. MemoryInputStream::MemoryInputStream (const MemoryBlock& sourceData,
  6849. const bool keepInternalCopy)
  6850. : data (static_cast <const char*> (sourceData.getData())),
  6851. dataSize (sourceData.getSize()),
  6852. position (0)
  6853. {
  6854. if (keepInternalCopy)
  6855. {
  6856. internalCopy = sourceData;
  6857. data = static_cast <const char*> (internalCopy.getData());
  6858. }
  6859. }
  6860. MemoryInputStream::~MemoryInputStream()
  6861. {
  6862. }
  6863. int64 MemoryInputStream::getTotalLength()
  6864. {
  6865. return dataSize;
  6866. }
  6867. int MemoryInputStream::read (void* const buffer, const int howMany)
  6868. {
  6869. jassert (howMany >= 0);
  6870. const int num = jmin (howMany, (int) (dataSize - position));
  6871. memcpy (buffer, data + position, num);
  6872. position += num;
  6873. return (int) num;
  6874. }
  6875. bool MemoryInputStream::isExhausted()
  6876. {
  6877. return (position >= dataSize);
  6878. }
  6879. bool MemoryInputStream::setPosition (const int64 pos)
  6880. {
  6881. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6882. return true;
  6883. }
  6884. int64 MemoryInputStream::getPosition()
  6885. {
  6886. return position;
  6887. }
  6888. END_JUCE_NAMESPACE
  6889. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  6890. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  6891. BEGIN_JUCE_NAMESPACE
  6892. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6893. const size_t blockSizeToIncreaseBy,
  6894. MemoryBlock* const memoryBlockToWriteTo)
  6895. : data (memoryBlockToWriteTo),
  6896. position (0),
  6897. size (0),
  6898. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6899. {
  6900. if (data == 0)
  6901. dataToDelete = data = new MemoryBlock (initialSize);
  6902. else
  6903. data->setSize (initialSize, false);
  6904. }
  6905. MemoryOutputStream::~MemoryOutputStream()
  6906. {
  6907. flush();
  6908. }
  6909. void MemoryOutputStream::flush()
  6910. {
  6911. if (dataToDelete == 0)
  6912. data->setSize (size, false);
  6913. }
  6914. void MemoryOutputStream::reset() throw()
  6915. {
  6916. position = 0;
  6917. size = 0;
  6918. }
  6919. bool MemoryOutputStream::write (const void* const buffer, int howMany)
  6920. {
  6921. if (howMany > 0)
  6922. {
  6923. size_t storageNeeded = position + howMany;
  6924. if (storageNeeded >= data->getSize())
  6925. {
  6926. // if we need more space, increase the block by at least 10%..
  6927. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6928. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6929. data->ensureSize (storageNeeded);
  6930. }
  6931. data->copyFrom (buffer, (int) position, howMany);
  6932. position += howMany;
  6933. size = jmax (size, position);
  6934. }
  6935. return true;
  6936. }
  6937. const char* MemoryOutputStream::getData() const throw()
  6938. {
  6939. char* const d = static_cast <char*> (data->getData());
  6940. if (data->getSize() > size)
  6941. d [size] = 0;
  6942. return d;
  6943. }
  6944. bool MemoryOutputStream::setPosition (int64 newPosition)
  6945. {
  6946. if (newPosition <= (int64) size)
  6947. {
  6948. // ok to seek backwards
  6949. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  6950. return true;
  6951. }
  6952. else
  6953. {
  6954. // trying to make it bigger isn't a good thing to do..
  6955. return false;
  6956. }
  6957. }
  6958. const String MemoryOutputStream::toUTF8() const
  6959. {
  6960. return String (getData(), getDataSize());
  6961. }
  6962. END_JUCE_NAMESPACE
  6963. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  6964. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  6965. BEGIN_JUCE_NAMESPACE
  6966. SubregionStream::SubregionStream (InputStream* const sourceStream,
  6967. const int64 startPositionInSourceStream_,
  6968. const int64 lengthOfSourceStream_,
  6969. const bool deleteSourceWhenDestroyed) throw()
  6970. : source (sourceStream),
  6971. startPositionInSourceStream (startPositionInSourceStream_),
  6972. lengthOfSourceStream (lengthOfSourceStream_)
  6973. {
  6974. if (deleteSourceWhenDestroyed)
  6975. sourceToDelete = source;
  6976. setPosition (0);
  6977. }
  6978. SubregionStream::~SubregionStream() throw()
  6979. {
  6980. }
  6981. int64 SubregionStream::getTotalLength()
  6982. {
  6983. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  6984. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  6985. : srcLen;
  6986. }
  6987. int64 SubregionStream::getPosition()
  6988. {
  6989. return source->getPosition() - startPositionInSourceStream;
  6990. }
  6991. bool SubregionStream::setPosition (int64 newPosition)
  6992. {
  6993. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  6994. }
  6995. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  6996. {
  6997. if (lengthOfSourceStream < 0)
  6998. {
  6999. return source->read (destBuffer, maxBytesToRead);
  7000. }
  7001. else
  7002. {
  7003. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7004. if (maxBytesToRead <= 0)
  7005. return 0;
  7006. return source->read (destBuffer, maxBytesToRead);
  7007. }
  7008. }
  7009. bool SubregionStream::isExhausted()
  7010. {
  7011. if (lengthOfSourceStream >= 0)
  7012. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7013. else
  7014. return source->isExhausted();
  7015. }
  7016. END_JUCE_NAMESPACE
  7017. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7018. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7019. BEGIN_JUCE_NAMESPACE
  7020. PerformanceCounter::PerformanceCounter (const String& name_,
  7021. int runsPerPrintout,
  7022. const File& loggingFile)
  7023. : name (name_),
  7024. numRuns (0),
  7025. runsPerPrint (runsPerPrintout),
  7026. totalTime (0),
  7027. outputFile (loggingFile)
  7028. {
  7029. if (outputFile != File::nonexistent)
  7030. {
  7031. String s ("**** Counter for \"");
  7032. s << name_ << "\" started at: "
  7033. << Time::getCurrentTime().toString (true, true)
  7034. << "\r\n";
  7035. outputFile.appendText (s, false, false);
  7036. }
  7037. }
  7038. PerformanceCounter::~PerformanceCounter()
  7039. {
  7040. printStatistics();
  7041. }
  7042. void PerformanceCounter::start()
  7043. {
  7044. started = Time::getHighResolutionTicks();
  7045. }
  7046. void PerformanceCounter::stop()
  7047. {
  7048. const int64 now = Time::getHighResolutionTicks();
  7049. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7050. if (++numRuns == runsPerPrint)
  7051. printStatistics();
  7052. }
  7053. void PerformanceCounter::printStatistics()
  7054. {
  7055. if (numRuns > 0)
  7056. {
  7057. String s ("Performance count for \"");
  7058. s << name << "\" - average over " << numRuns << " run(s) = ";
  7059. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7060. if (micros > 10000)
  7061. s << (micros/1000) << " millisecs";
  7062. else
  7063. s << micros << " microsecs";
  7064. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7065. Logger::outputDebugString (s);
  7066. s << "\r\n";
  7067. if (outputFile != File::nonexistent)
  7068. outputFile.appendText (s, false, false);
  7069. numRuns = 0;
  7070. totalTime = 0;
  7071. }
  7072. }
  7073. END_JUCE_NAMESPACE
  7074. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7075. /*** Start of inlined file: juce_Uuid.cpp ***/
  7076. BEGIN_JUCE_NAMESPACE
  7077. Uuid::Uuid()
  7078. {
  7079. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7080. // to make it very very unlikely that two UUIDs will ever be the same..
  7081. static int64 macAddresses[2];
  7082. static bool hasCheckedMacAddresses = false;
  7083. if (! hasCheckedMacAddresses)
  7084. {
  7085. hasCheckedMacAddresses = true;
  7086. SystemStats::getMACAddresses (macAddresses, 2);
  7087. }
  7088. value.asInt64[0] = macAddresses[0];
  7089. value.asInt64[1] = macAddresses[1];
  7090. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7091. // whose seed will carry over between calls to this method.
  7092. Random r (macAddresses[0] ^ macAddresses[1]
  7093. ^ Random::getSystemRandom().nextInt64());
  7094. for (int i = 4; --i >= 0;)
  7095. {
  7096. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7097. value.asInt[i] ^= r.nextInt();
  7098. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7099. }
  7100. }
  7101. Uuid::~Uuid() throw()
  7102. {
  7103. }
  7104. Uuid::Uuid (const Uuid& other)
  7105. : value (other.value)
  7106. {
  7107. }
  7108. Uuid& Uuid::operator= (const Uuid& other)
  7109. {
  7110. value = other.value;
  7111. return *this;
  7112. }
  7113. bool Uuid::operator== (const Uuid& other) const
  7114. {
  7115. return value.asInt64[0] == other.value.asInt64[0]
  7116. && value.asInt64[1] == other.value.asInt64[1];
  7117. }
  7118. bool Uuid::operator!= (const Uuid& other) const
  7119. {
  7120. return ! operator== (other);
  7121. }
  7122. bool Uuid::isNull() const throw()
  7123. {
  7124. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7125. }
  7126. const String Uuid::toString() const
  7127. {
  7128. return String::toHexString (value.asBytes, 16, 0);
  7129. }
  7130. Uuid::Uuid (const String& uuidString)
  7131. {
  7132. operator= (uuidString);
  7133. }
  7134. Uuid& Uuid::operator= (const String& uuidString)
  7135. {
  7136. int destIndex = 0;
  7137. int i = 0;
  7138. for (;;)
  7139. {
  7140. int byte = 0;
  7141. for (int loop = 2; --loop >= 0;)
  7142. {
  7143. byte <<= 4;
  7144. for (;;)
  7145. {
  7146. const tchar c = uuidString [i++];
  7147. if (c >= '0' && c <= '9')
  7148. {
  7149. byte |= c - '0';
  7150. break;
  7151. }
  7152. else if (c >= 'a' && c <= 'z')
  7153. {
  7154. byte |= c - ('a' - 10);
  7155. break;
  7156. }
  7157. else if (c >= 'A' && c <= 'Z')
  7158. {
  7159. byte |= c - ('A' - 10);
  7160. break;
  7161. }
  7162. else if (c == 0)
  7163. {
  7164. while (destIndex < 16)
  7165. value.asBytes [destIndex++] = 0;
  7166. return *this;
  7167. }
  7168. }
  7169. }
  7170. value.asBytes [destIndex++] = (uint8) byte;
  7171. }
  7172. }
  7173. Uuid::Uuid (const uint8* const rawData)
  7174. {
  7175. operator= (rawData);
  7176. }
  7177. Uuid& Uuid::operator= (const uint8* const rawData)
  7178. {
  7179. if (rawData != 0)
  7180. memcpy (value.asBytes, rawData, 16);
  7181. else
  7182. zeromem (value.asBytes, 16);
  7183. return *this;
  7184. }
  7185. END_JUCE_NAMESPACE
  7186. /*** End of inlined file: juce_Uuid.cpp ***/
  7187. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7188. BEGIN_JUCE_NAMESPACE
  7189. class ZipFile::ZipEntryInfo
  7190. {
  7191. public:
  7192. ZipFile::ZipEntry entry;
  7193. int streamOffset;
  7194. int compressedSize;
  7195. bool compressed;
  7196. };
  7197. class ZipFile::ZipInputStream : public InputStream
  7198. {
  7199. public:
  7200. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7201. : file (file_),
  7202. zipEntryInfo (zei),
  7203. pos (0),
  7204. headerSize (0),
  7205. inputStream (0)
  7206. {
  7207. inputStream = file_.inputStream;
  7208. if (file_.inputSource != 0)
  7209. {
  7210. inputStream = file.inputSource->createInputStream();
  7211. }
  7212. else
  7213. {
  7214. #ifdef JUCE_DEBUG
  7215. file_.numOpenStreams++;
  7216. #endif
  7217. }
  7218. char buffer [30];
  7219. if (inputStream != 0
  7220. && inputStream->setPosition (zei.streamOffset)
  7221. && inputStream->read (buffer, 30) == 30
  7222. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7223. {
  7224. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7225. + ByteOrder::littleEndianShort (buffer + 28);
  7226. }
  7227. }
  7228. ~ZipInputStream() throw()
  7229. {
  7230. #ifdef JUCE_DEBUG
  7231. if (inputStream != 0 && inputStream == file.inputStream)
  7232. file.numOpenStreams--;
  7233. #endif
  7234. if (inputStream != file.inputStream)
  7235. delete inputStream;
  7236. }
  7237. int64 getTotalLength() throw()
  7238. {
  7239. return zipEntryInfo.compressedSize;
  7240. }
  7241. int read (void* buffer, int howMany) throw()
  7242. {
  7243. if (headerSize <= 0)
  7244. return 0;
  7245. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7246. if (inputStream == 0)
  7247. return 0;
  7248. int num;
  7249. if (inputStream == file.inputStream)
  7250. {
  7251. const ScopedLock sl (file.lock);
  7252. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7253. num = inputStream->read (buffer, howMany);
  7254. }
  7255. else
  7256. {
  7257. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7258. num = inputStream->read (buffer, howMany);
  7259. }
  7260. pos += num;
  7261. return num;
  7262. }
  7263. bool isExhausted() throw()
  7264. {
  7265. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7266. }
  7267. int64 getPosition() throw()
  7268. {
  7269. return pos;
  7270. }
  7271. bool setPosition (int64 newPos) throw()
  7272. {
  7273. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7274. return true;
  7275. }
  7276. private:
  7277. ZipFile& file;
  7278. ZipEntryInfo zipEntryInfo;
  7279. int64 pos;
  7280. int headerSize;
  7281. InputStream* inputStream;
  7282. ZipInputStream (const ZipInputStream&);
  7283. ZipInputStream& operator= (const ZipInputStream&);
  7284. };
  7285. ZipFile::ZipFile (InputStream* const source_,
  7286. const bool deleteStreamWhenDestroyed) throw()
  7287. : inputStream (source_)
  7288. #ifdef JUCE_DEBUG
  7289. , numOpenStreams (0)
  7290. #endif
  7291. {
  7292. if (deleteStreamWhenDestroyed)
  7293. streamToDelete = inputStream;
  7294. init();
  7295. }
  7296. ZipFile::ZipFile (const File& file)
  7297. : inputStream (0)
  7298. #ifdef JUCE_DEBUG
  7299. , numOpenStreams (0)
  7300. #endif
  7301. {
  7302. inputSource = new FileInputSource (file);
  7303. init();
  7304. }
  7305. ZipFile::ZipFile (InputSource* const inputSource_)
  7306. : inputStream (0),
  7307. inputSource (inputSource_)
  7308. #ifdef JUCE_DEBUG
  7309. , numOpenStreams (0)
  7310. #endif
  7311. {
  7312. init();
  7313. }
  7314. ZipFile::~ZipFile() throw()
  7315. {
  7316. #ifdef JUCE_DEBUG
  7317. entries.clear();
  7318. // If you hit this assertion, it means you've created a stream to read
  7319. // one of the items in the zipfile, but you've forgotten to delete that
  7320. // stream object before deleting the file.. Streams can't be kept open
  7321. // after the file is deleted because they need to share the input
  7322. // stream that the file uses to read itself.
  7323. jassert (numOpenStreams == 0);
  7324. #endif
  7325. }
  7326. int ZipFile::getNumEntries() const throw()
  7327. {
  7328. return entries.size();
  7329. }
  7330. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7331. {
  7332. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7333. return (zei != 0) ? &(zei->entry)
  7334. : 0;
  7335. }
  7336. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7337. {
  7338. for (int i = 0; i < entries.size(); ++i)
  7339. if (entries.getUnchecked (i)->entry.filename == fileName)
  7340. return i;
  7341. return -1;
  7342. }
  7343. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7344. {
  7345. return getEntry (getIndexOfFileName (fileName));
  7346. }
  7347. InputStream* ZipFile::createStreamForEntry (const int index)
  7348. {
  7349. ZipEntryInfo* const zei = entries[index];
  7350. InputStream* stream = 0;
  7351. if (zei != 0)
  7352. {
  7353. stream = new ZipInputStream (*this, *zei);
  7354. if (zei->compressed)
  7355. {
  7356. stream = new GZIPDecompressorInputStream (stream, true, true,
  7357. zei->entry.uncompressedSize);
  7358. // (much faster to unzip in big blocks using a buffer..)
  7359. stream = new BufferedInputStream (stream, 32768, true);
  7360. }
  7361. }
  7362. return stream;
  7363. }
  7364. class ZipFile::ZipFilenameComparator
  7365. {
  7366. public:
  7367. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7368. {
  7369. return first->entry.filename.compare (second->entry.filename);
  7370. }
  7371. };
  7372. void ZipFile::sortEntriesByFilename()
  7373. {
  7374. ZipFilenameComparator sorter;
  7375. entries.sort (sorter);
  7376. }
  7377. void ZipFile::init()
  7378. {
  7379. ScopedPointer <InputStream> toDelete;
  7380. InputStream* in = inputStream;
  7381. if (inputSource != 0)
  7382. {
  7383. in = inputSource->createInputStream();
  7384. toDelete = in;
  7385. }
  7386. if (in != 0)
  7387. {
  7388. int numEntries = 0;
  7389. int pos = findEndOfZipEntryTable (in, numEntries);
  7390. if (pos >= 0 && pos < in->getTotalLength())
  7391. {
  7392. const int size = (int) (in->getTotalLength() - pos);
  7393. in->setPosition (pos);
  7394. MemoryBlock headerData;
  7395. if (in->readIntoMemoryBlock (headerData, size) == size)
  7396. {
  7397. pos = 0;
  7398. for (int i = 0; i < numEntries; ++i)
  7399. {
  7400. if (pos + 46 > size)
  7401. break;
  7402. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7403. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7404. if (pos + 46 + fileNameLen > size)
  7405. break;
  7406. ZipEntryInfo* const zei = new ZipEntryInfo();
  7407. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7408. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7409. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7410. const int year = 1980 + (date >> 9);
  7411. const int month = ((date >> 5) & 15) - 1;
  7412. const int day = date & 31;
  7413. const int hours = time >> 11;
  7414. const int minutes = (time >> 5) & 63;
  7415. const int seconds = (time & 31) << 1;
  7416. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7417. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7418. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7419. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7420. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7421. entries.add (zei);
  7422. pos += 46 + fileNameLen
  7423. + ByteOrder::littleEndianShort (buffer + 30)
  7424. + ByteOrder::littleEndianShort (buffer + 32);
  7425. }
  7426. }
  7427. }
  7428. }
  7429. }
  7430. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7431. {
  7432. BufferedInputStream in (input, 8192, false);
  7433. in.setPosition (in.getTotalLength());
  7434. int64 pos = in.getPosition();
  7435. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7436. char buffer [32];
  7437. zeromem (buffer, sizeof (buffer));
  7438. while (pos > lowestPos)
  7439. {
  7440. in.setPosition (pos - 22);
  7441. pos = in.getPosition();
  7442. memcpy (buffer + 22, buffer, 4);
  7443. if (in.read (buffer, 22) != 22)
  7444. return 0;
  7445. for (int i = 0; i < 22; ++i)
  7446. {
  7447. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7448. {
  7449. in.setPosition (pos + i);
  7450. in.read (buffer, 22);
  7451. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7452. return ByteOrder::littleEndianInt (buffer + 16);
  7453. }
  7454. }
  7455. }
  7456. return 0;
  7457. }
  7458. void ZipFile::uncompressTo (const File& targetDirectory,
  7459. const bool shouldOverwriteFiles)
  7460. {
  7461. for (int i = 0; i < entries.size(); ++i)
  7462. {
  7463. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7464. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7465. if (zei.filename.endsWithChar ('/'))
  7466. {
  7467. targetFile.createDirectory(); // (entry is a directory, not a file)
  7468. }
  7469. else
  7470. {
  7471. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7472. if (in != 0)
  7473. {
  7474. if (shouldOverwriteFiles)
  7475. targetFile.deleteFile();
  7476. if ((! targetFile.exists())
  7477. && targetFile.getParentDirectory().createDirectory())
  7478. {
  7479. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7480. if (out != 0)
  7481. {
  7482. out->writeFromInputStream (*in, -1);
  7483. out = 0;
  7484. targetFile.setCreationTime (zei.fileTime);
  7485. targetFile.setLastModificationTime (zei.fileTime);
  7486. targetFile.setLastAccessTime (zei.fileTime);
  7487. }
  7488. }
  7489. }
  7490. }
  7491. }
  7492. }
  7493. END_JUCE_NAMESPACE
  7494. /*** End of inlined file: juce_ZipFile.cpp ***/
  7495. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7496. #ifdef _MSC_VER
  7497. #pragma warning (disable: 4514 4996)
  7498. #pragma warning (push)
  7499. #endif
  7500. #include <cwctype>
  7501. #include <cctype>
  7502. #include <ctime>
  7503. #ifdef _MSC_VER
  7504. #pragma warning (pop)
  7505. #endif
  7506. BEGIN_JUCE_NAMESPACE
  7507. int CharacterFunctions::length (const char* const s) throw()
  7508. {
  7509. return (int) strlen (s);
  7510. }
  7511. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7512. {
  7513. return (int) wcslen (s);
  7514. }
  7515. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7516. {
  7517. strncpy (dest, src, maxChars);
  7518. }
  7519. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7520. {
  7521. wcsncpy (dest, src, maxChars);
  7522. }
  7523. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7524. {
  7525. mbstowcs (dest, src, maxChars);
  7526. }
  7527. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7528. {
  7529. wcstombs (dest, src, maxChars);
  7530. }
  7531. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7532. {
  7533. return (int) wcstombs (0, src, 0);
  7534. }
  7535. void CharacterFunctions::append (char* dest, const char* src) throw()
  7536. {
  7537. strcat (dest, src);
  7538. }
  7539. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7540. {
  7541. wcscat (dest, src);
  7542. }
  7543. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7544. {
  7545. return strcmp (s1, s2);
  7546. }
  7547. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7548. {
  7549. jassert (s1 != 0 && s2 != 0);
  7550. return wcscmp (s1, s2);
  7551. }
  7552. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7553. {
  7554. jassert (s1 != 0 && s2 != 0);
  7555. return strncmp (s1, s2, maxChars);
  7556. }
  7557. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7558. {
  7559. jassert (s1 != 0 && s2 != 0);
  7560. return wcsncmp (s1, s2, maxChars);
  7561. }
  7562. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7563. {
  7564. jassert (s1 != 0 && s2 != 0);
  7565. for (;;)
  7566. {
  7567. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7568. if (diff != 0)
  7569. return diff;
  7570. else if (*s1 == 0)
  7571. break;
  7572. ++s1;
  7573. ++s2;
  7574. }
  7575. return 0;
  7576. }
  7577. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7578. {
  7579. return -compare (s2, s1);
  7580. }
  7581. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7582. {
  7583. jassert (s1 != 0 && s2 != 0);
  7584. #if JUCE_WIN32
  7585. return stricmp (s1, s2);
  7586. #else
  7587. return strcasecmp (s1, s2);
  7588. #endif
  7589. }
  7590. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7591. {
  7592. jassert (s1 != 0 && s2 != 0);
  7593. #if JUCE_WIN32
  7594. return _wcsicmp (s1, s2);
  7595. #else
  7596. for (;;)
  7597. {
  7598. if (*s1 != *s2)
  7599. {
  7600. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7601. if (diff != 0)
  7602. return diff < 0 ? -1 : 1;
  7603. }
  7604. else if (*s1 == 0)
  7605. break;
  7606. ++s1;
  7607. ++s2;
  7608. }
  7609. return 0;
  7610. #endif
  7611. }
  7612. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const char* s2) throw()
  7613. {
  7614. jassert (s1 != 0 && s2 != 0);
  7615. for (;;)
  7616. {
  7617. if (*s1 != *s2)
  7618. {
  7619. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7620. if (diff != 0)
  7621. return diff < 0 ? -1 : 1;
  7622. }
  7623. else if (*s1 == 0)
  7624. break;
  7625. ++s1;
  7626. ++s2;
  7627. }
  7628. return 0;
  7629. }
  7630. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7631. {
  7632. jassert (s1 != 0 && s2 != 0);
  7633. #if JUCE_WIN32
  7634. return strnicmp (s1, s2, maxChars);
  7635. #else
  7636. return strncasecmp (s1, s2, maxChars);
  7637. #endif
  7638. }
  7639. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7640. {
  7641. jassert (s1 != 0 && s2 != 0);
  7642. #if JUCE_WIN32
  7643. return _wcsnicmp (s1, s2, maxChars);
  7644. #else
  7645. while (--maxChars >= 0)
  7646. {
  7647. if (*s1 != *s2)
  7648. {
  7649. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7650. if (diff != 0)
  7651. return diff < 0 ? -1 : 1;
  7652. }
  7653. else if (*s1 == 0)
  7654. break;
  7655. ++s1;
  7656. ++s2;
  7657. }
  7658. return 0;
  7659. #endif
  7660. }
  7661. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7662. {
  7663. return strstr (haystack, needle);
  7664. }
  7665. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7666. {
  7667. return wcsstr (haystack, needle);
  7668. }
  7669. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7670. {
  7671. if (haystack != 0)
  7672. {
  7673. int i = 0;
  7674. if (ignoreCase)
  7675. {
  7676. const char n1 = toLowerCase (needle);
  7677. const char n2 = toUpperCase (needle);
  7678. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7679. {
  7680. while (haystack[i] != 0)
  7681. {
  7682. if (haystack[i] == n1 || haystack[i] == n2)
  7683. return i;
  7684. ++i;
  7685. }
  7686. return -1;
  7687. }
  7688. jassert (n1 == needle);
  7689. }
  7690. while (haystack[i] != 0)
  7691. {
  7692. if (haystack[i] == needle)
  7693. return i;
  7694. ++i;
  7695. }
  7696. }
  7697. return -1;
  7698. }
  7699. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7700. {
  7701. if (haystack != 0)
  7702. {
  7703. int i = 0;
  7704. if (ignoreCase)
  7705. {
  7706. const juce_wchar n1 = toLowerCase (needle);
  7707. const juce_wchar n2 = toUpperCase (needle);
  7708. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7709. {
  7710. while (haystack[i] != 0)
  7711. {
  7712. if (haystack[i] == n1 || haystack[i] == n2)
  7713. return i;
  7714. ++i;
  7715. }
  7716. return -1;
  7717. }
  7718. jassert (n1 == needle);
  7719. }
  7720. while (haystack[i] != 0)
  7721. {
  7722. if (haystack[i] == needle)
  7723. return i;
  7724. ++i;
  7725. }
  7726. }
  7727. return -1;
  7728. }
  7729. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char 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::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7742. {
  7743. jassert (haystack != 0);
  7744. int i = 0;
  7745. while (haystack[i] != 0)
  7746. {
  7747. if (haystack[i] == needle)
  7748. return i;
  7749. ++i;
  7750. }
  7751. return -1;
  7752. }
  7753. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7754. {
  7755. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7756. }
  7757. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7758. {
  7759. if (allowedChars == 0)
  7760. return 0;
  7761. int i = 0;
  7762. for (;;)
  7763. {
  7764. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7765. break;
  7766. ++i;
  7767. }
  7768. return i;
  7769. }
  7770. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7771. {
  7772. return (int) strftime (dest, maxChars, format, tm);
  7773. }
  7774. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7775. {
  7776. return (int) wcsftime (dest, maxChars, format, tm);
  7777. }
  7778. int CharacterFunctions::getIntValue (const char* const s) throw()
  7779. {
  7780. return atoi (s);
  7781. }
  7782. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7783. {
  7784. #if JUCE_WIN32
  7785. return _wtoi (s);
  7786. #else
  7787. int v = 0;
  7788. while (isWhitespace (*s))
  7789. ++s;
  7790. const bool isNeg = *s == '-';
  7791. if (isNeg)
  7792. ++s;
  7793. for (;;)
  7794. {
  7795. const wchar_t c = *s++;
  7796. if (c >= '0' && c <= '9')
  7797. v = v * 10 + (int) (c - '0');
  7798. else
  7799. break;
  7800. }
  7801. return isNeg ? -v : v;
  7802. #endif
  7803. }
  7804. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7805. {
  7806. #if JUCE_LINUX
  7807. return atoll (s);
  7808. #elif defined (JUCE_WIN32)
  7809. return _atoi64 (s);
  7810. #else
  7811. int64 v = 0;
  7812. while (isWhitespace (*s))
  7813. ++s;
  7814. const bool isNeg = *s == '-';
  7815. if (isNeg)
  7816. ++s;
  7817. for (;;)
  7818. {
  7819. const char c = *s++;
  7820. if (c >= '0' && c <= '9')
  7821. v = v * 10 + (int64) (c - '0');
  7822. else
  7823. break;
  7824. }
  7825. return isNeg ? -v : v;
  7826. #endif
  7827. }
  7828. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7829. {
  7830. #if JUCE_WIN32
  7831. return _wtoi64 (s);
  7832. #else
  7833. int64 v = 0;
  7834. while (isWhitespace (*s))
  7835. ++s;
  7836. const bool isNeg = *s == '-';
  7837. if (isNeg)
  7838. ++s;
  7839. for (;;)
  7840. {
  7841. const juce_wchar c = *s++;
  7842. if (c >= '0' && c <= '9')
  7843. v = v * 10 + (int64) (c - '0');
  7844. else
  7845. break;
  7846. }
  7847. return isNeg ? -v : v;
  7848. #endif
  7849. }
  7850. static double juce_mulexp10 (const double value, int exponent) throw()
  7851. {
  7852. if (exponent == 0)
  7853. return value;
  7854. if (value == 0)
  7855. return 0;
  7856. const bool negative = (exponent < 0);
  7857. if (negative)
  7858. exponent = -exponent;
  7859. double result = 1.0, power = 10.0;
  7860. for (int bit = 1; exponent != 0; bit <<= 1)
  7861. {
  7862. if ((exponent & bit) != 0)
  7863. {
  7864. exponent ^= bit;
  7865. result *= power;
  7866. if (exponent == 0)
  7867. break;
  7868. }
  7869. power *= power;
  7870. }
  7871. return negative ? (value / result) : (value * result);
  7872. }
  7873. template <class CharType>
  7874. double juce_atof (const CharType* const original) throw()
  7875. {
  7876. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7877. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7878. int exponent = 0, decPointIndex = 0, digit = 0;
  7879. int lastDigit = 0, numSignificantDigits = 0;
  7880. bool isNegative = false, digitsFound = false;
  7881. const int maxSignificantDigits = 15 + 2;
  7882. const CharType* s = original;
  7883. while (CharacterFunctions::isWhitespace (*s))
  7884. ++s;
  7885. switch (*s)
  7886. {
  7887. case '-': isNegative = true; // fall-through..
  7888. case '+': ++s;
  7889. }
  7890. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7891. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  7892. for (;;)
  7893. {
  7894. if (CharacterFunctions::isDigit (*s))
  7895. {
  7896. lastDigit = digit;
  7897. digit = *s++ - '0';
  7898. digitsFound = true;
  7899. if (decPointIndex != 0)
  7900. exponentAdjustment[1]++;
  7901. if (numSignificantDigits == 0 && digit == 0)
  7902. continue;
  7903. if (++numSignificantDigits > maxSignificantDigits)
  7904. {
  7905. if (digit > 5)
  7906. ++accumulator [decPointIndex];
  7907. else if (digit == 5 && (lastDigit & 1) != 0)
  7908. ++accumulator [decPointIndex];
  7909. if (decPointIndex > 0)
  7910. exponentAdjustment[1]--;
  7911. else
  7912. exponentAdjustment[0]++;
  7913. while (CharacterFunctions::isDigit (*s))
  7914. {
  7915. ++s;
  7916. if (decPointIndex == 0)
  7917. exponentAdjustment[0]++;
  7918. }
  7919. }
  7920. else
  7921. {
  7922. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  7923. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7924. {
  7925. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7926. + accumulator [decPointIndex];
  7927. accumulator [decPointIndex] = 0;
  7928. exponentAccumulator [decPointIndex] = 0;
  7929. }
  7930. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7931. exponentAccumulator [decPointIndex]++;
  7932. }
  7933. }
  7934. else if (decPointIndex == 0 && *s == '.')
  7935. {
  7936. ++s;
  7937. decPointIndex = 1;
  7938. if (numSignificantDigits > maxSignificantDigits)
  7939. {
  7940. while (CharacterFunctions::isDigit (*s))
  7941. ++s;
  7942. break;
  7943. }
  7944. }
  7945. else
  7946. {
  7947. break;
  7948. }
  7949. }
  7950. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7951. if (decPointIndex != 0)
  7952. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7953. if ((*s == 'e' || *s == 'E') && digitsFound)
  7954. {
  7955. bool negativeExponent = false;
  7956. switch (*++s)
  7957. {
  7958. case '-': negativeExponent = true; // fall-through..
  7959. case '+': ++s;
  7960. }
  7961. while (CharacterFunctions::isDigit (*s))
  7962. exponent = (exponent * 10) + (*s++ - '0');
  7963. if (negativeExponent)
  7964. exponent = -exponent;
  7965. }
  7966. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7967. if (decPointIndex != 0)
  7968. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7969. return isNegative ? -r : r;
  7970. }
  7971. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7972. {
  7973. return juce_atof <char> (s);
  7974. }
  7975. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7976. {
  7977. return juce_atof <juce_wchar> (s);
  7978. }
  7979. char CharacterFunctions::toUpperCase (const char character) throw()
  7980. {
  7981. return (char) toupper (character);
  7982. }
  7983. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7984. {
  7985. return towupper (character);
  7986. }
  7987. void CharacterFunctions::toUpperCase (char* s) throw()
  7988. {
  7989. #if JUCE_WIN32
  7990. strupr (s);
  7991. #else
  7992. while (*s != 0)
  7993. {
  7994. *s = toUpperCase (*s);
  7995. ++s;
  7996. }
  7997. #endif
  7998. }
  7999. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8000. {
  8001. #if JUCE_WIN32
  8002. _wcsupr (s);
  8003. #else
  8004. while (*s != 0)
  8005. {
  8006. *s = toUpperCase (*s);
  8007. ++s;
  8008. }
  8009. #endif
  8010. }
  8011. bool CharacterFunctions::isUpperCase (const char character) throw()
  8012. {
  8013. return isupper (character) != 0;
  8014. }
  8015. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8016. {
  8017. #if JUCE_WIN32
  8018. return iswupper (character) != 0;
  8019. #else
  8020. return toLowerCase (character) != character;
  8021. #endif
  8022. }
  8023. char CharacterFunctions::toLowerCase (const char character) throw()
  8024. {
  8025. return (char) tolower (character);
  8026. }
  8027. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8028. {
  8029. return towlower (character);
  8030. }
  8031. void CharacterFunctions::toLowerCase (char* s) throw()
  8032. {
  8033. #if JUCE_WIN32
  8034. strlwr (s);
  8035. #else
  8036. while (*s != 0)
  8037. {
  8038. *s = toLowerCase (*s);
  8039. ++s;
  8040. }
  8041. #endif
  8042. }
  8043. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8044. {
  8045. #if JUCE_WIN32
  8046. _wcslwr (s);
  8047. #else
  8048. while (*s != 0)
  8049. {
  8050. *s = toLowerCase (*s);
  8051. ++s;
  8052. }
  8053. #endif
  8054. }
  8055. bool CharacterFunctions::isLowerCase (const char character) throw()
  8056. {
  8057. return islower (character) != 0;
  8058. }
  8059. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8060. {
  8061. #if JUCE_WIN32
  8062. return iswlower (character) != 0;
  8063. #else
  8064. return toUpperCase (character) != character;
  8065. #endif
  8066. }
  8067. bool CharacterFunctions::isWhitespace (const char character) throw()
  8068. {
  8069. return character == ' ' || (character <= 13 && character >= 9);
  8070. }
  8071. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8072. {
  8073. return iswspace (character) != 0;
  8074. }
  8075. bool CharacterFunctions::isDigit (const char character) throw()
  8076. {
  8077. return (character >= '0' && character <= '9');
  8078. }
  8079. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8080. {
  8081. return iswdigit (character) != 0;
  8082. }
  8083. bool CharacterFunctions::isLetter (const char character) throw()
  8084. {
  8085. return (character >= 'a' && character <= 'z')
  8086. || (character >= 'A' && character <= 'Z');
  8087. }
  8088. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8089. {
  8090. return iswalpha (character) != 0;
  8091. }
  8092. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8093. {
  8094. return (character >= 'a' && character <= 'z')
  8095. || (character >= 'A' && character <= 'Z')
  8096. || (character >= '0' && character <= '9');
  8097. }
  8098. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8099. {
  8100. return iswalnum (character) != 0;
  8101. }
  8102. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8103. {
  8104. if (digit >= '0' && digit <= '9')
  8105. return digit - '0';
  8106. else if (digit >= 'a' && digit <= 'f')
  8107. return digit - ('a' - 10);
  8108. else if (digit >= 'A' && digit <= 'F')
  8109. return digit - ('A' - 10);
  8110. return -1;
  8111. }
  8112. END_JUCE_NAMESPACE
  8113. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8114. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8115. BEGIN_JUCE_NAMESPACE
  8116. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8117. {
  8118. loadFromText (fileContents);
  8119. }
  8120. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8121. {
  8122. loadFromText (fileToLoad.loadFileAsString());
  8123. }
  8124. LocalisedStrings::~LocalisedStrings()
  8125. {
  8126. }
  8127. const String LocalisedStrings::translate (const String& text) const
  8128. {
  8129. return translations.getValue (text, text);
  8130. }
  8131. static int findCloseQuote (const String& text, int startPos)
  8132. {
  8133. tchar lastChar = 0;
  8134. for (;;)
  8135. {
  8136. const tchar c = text [startPos];
  8137. if (c == 0 || (c == '"' && lastChar != '\\'))
  8138. break;
  8139. lastChar = c;
  8140. ++startPos;
  8141. }
  8142. return startPos;
  8143. }
  8144. static const String unescapeString (const String& s)
  8145. {
  8146. return s.replace ("\\\"", "\"")
  8147. .replace ("\\\'", "\'")
  8148. .replace ("\\t", "\t")
  8149. .replace ("\\r", "\r")
  8150. .replace ("\\n", "\n");
  8151. }
  8152. void LocalisedStrings::loadFromText (const String& fileContents)
  8153. {
  8154. StringArray lines;
  8155. lines.addLines (fileContents);
  8156. for (int i = 0; i < lines.size(); ++i)
  8157. {
  8158. String line (lines[i].trim());
  8159. if (line.startsWithChar ('"'))
  8160. {
  8161. int closeQuote = findCloseQuote (line, 1);
  8162. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8163. if (originalText.isNotEmpty())
  8164. {
  8165. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8166. closeQuote = findCloseQuote (line, openingQuote + 1);
  8167. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8168. if (newText.isNotEmpty())
  8169. translations.set (originalText, newText);
  8170. }
  8171. }
  8172. else if (line.startsWithIgnoreCase ("language:"))
  8173. {
  8174. languageName = line.substring (9).trim();
  8175. }
  8176. else if (line.startsWithIgnoreCase ("countries:"))
  8177. {
  8178. countryCodes.addTokens (line.substring (10).trim(), true);
  8179. countryCodes.trim();
  8180. countryCodes.removeEmptyStrings();
  8181. }
  8182. }
  8183. }
  8184. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8185. {
  8186. translations.setIgnoresCase (shouldIgnoreCase);
  8187. }
  8188. static CriticalSection currentMappingsLock;
  8189. static LocalisedStrings* currentMappings = 0;
  8190. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8191. {
  8192. const ScopedLock sl (currentMappingsLock);
  8193. delete currentMappings;
  8194. currentMappings = newTranslations;
  8195. }
  8196. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8197. {
  8198. return currentMappings;
  8199. }
  8200. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8201. {
  8202. const ScopedLock sl (currentMappingsLock);
  8203. if (currentMappings != 0)
  8204. return currentMappings->translate (text);
  8205. return text;
  8206. }
  8207. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8208. {
  8209. return translateWithCurrentMappings (String (text));
  8210. }
  8211. END_JUCE_NAMESPACE
  8212. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8213. /*** Start of inlined file: juce_String.cpp ***/
  8214. #ifdef _MSC_VER
  8215. #pragma warning (push)
  8216. #pragma warning (disable: 4514)
  8217. #endif
  8218. #include <locale>
  8219. #if JUCE_MSVC
  8220. #include <float.h>
  8221. #endif
  8222. BEGIN_JUCE_NAMESPACE
  8223. #ifdef _MSC_VER
  8224. #pragma warning (pop)
  8225. #endif
  8226. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8227. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8228. #endif
  8229. class StringHolder
  8230. {
  8231. public:
  8232. StringHolder()
  8233. : refCount (0x3fffffff), allocatedNumChars (0)
  8234. {
  8235. text[0] = 0;
  8236. }
  8237. static juce_wchar* create (const size_t numChars)
  8238. {
  8239. StringHolder* const s = reinterpret_cast <StringHolder*> (new char [sizeof (StringHolder) + numChars * sizeof (juce_wchar)]);
  8240. s->refCount = 0;
  8241. s->allocatedNumChars = numChars;
  8242. return &(s->text[0]);
  8243. }
  8244. static inline juce_wchar* getEmpty() throw()
  8245. {
  8246. return &(empty.text[0]);
  8247. }
  8248. static void retain (juce_wchar* const text) throw()
  8249. {
  8250. Atomic::increment (bufferFromText (text)->refCount);
  8251. }
  8252. static inline void release (StringHolder* const b) throw()
  8253. {
  8254. if (Atomic::decrementAndReturn (b->refCount) == -1 && b != &empty)
  8255. delete[] reinterpret_cast <char*> (b);
  8256. }
  8257. static void release (juce_wchar* const text) throw()
  8258. {
  8259. release (bufferFromText (text));
  8260. }
  8261. static juce_wchar* makeUnique (juce_wchar* const text)
  8262. {
  8263. StringHolder* const b = bufferFromText (text);
  8264. if (b->refCount <= 0)
  8265. return text;
  8266. juce_wchar* const newText = create (b->allocatedNumChars);
  8267. copyChars (newText, text, b->allocatedNumChars);
  8268. release (b);
  8269. return newText;
  8270. }
  8271. static juce_wchar* makeUniqueWithSize (juce_wchar* const text, size_t numChars)
  8272. {
  8273. StringHolder* const b = bufferFromText (text);
  8274. if (b->refCount <= 0 && b->allocatedNumChars >= numChars)
  8275. return text;
  8276. juce_wchar* const newText = create (jmax (b->allocatedNumChars, numChars));
  8277. copyChars (newText, text, b->allocatedNumChars);
  8278. release (b);
  8279. return newText;
  8280. }
  8281. static size_t getAllocatedNumChars (juce_wchar* const text) throw()
  8282. {
  8283. return bufferFromText (text)->allocatedNumChars;
  8284. }
  8285. static void copyChars (juce_wchar* const dest, const juce_wchar* const src, const size_t numChars) throw()
  8286. {
  8287. memcpy (dest, src, numChars * sizeof (juce_wchar));
  8288. dest [numChars] = 0;
  8289. }
  8290. int refCount;
  8291. size_t allocatedNumChars;
  8292. juce_wchar text[1];
  8293. static StringHolder empty;
  8294. private:
  8295. static inline StringHolder* bufferFromText (void* const text) throw()
  8296. {
  8297. // (Can't use offsetof() here because of warnings about this not being a POD)
  8298. return reinterpret_cast <StringHolder*> (static_cast <char*> (text)
  8299. - (reinterpret_cast <size_t> (reinterpret_cast <StringHolder*> (1)->text) - 1));
  8300. }
  8301. };
  8302. StringHolder StringHolder::empty;
  8303. const String String::empty;
  8304. void String::createInternal (const juce_wchar* const t, const size_t numChars)
  8305. {
  8306. jassert (t[numChars] == 0); // must have a null terminator
  8307. text = StringHolder::create (numChars);
  8308. StringHolder::copyChars (text, t, numChars);
  8309. }
  8310. void String::appendInternal (const juce_wchar* const newText, const int numExtraChars)
  8311. {
  8312. if (numExtraChars > 0)
  8313. {
  8314. const int oldLen = length();
  8315. const int newTotalLen = oldLen + numExtraChars;
  8316. text = StringHolder::makeUniqueWithSize (text, newTotalLen);
  8317. StringHolder::copyChars (text + oldLen, newText, numExtraChars);
  8318. }
  8319. }
  8320. void String::preallocateStorage (const size_t numChars)
  8321. {
  8322. text = StringHolder::makeUniqueWithSize (text, numChars);
  8323. }
  8324. String::String() throw()
  8325. : text (StringHolder::getEmpty())
  8326. {
  8327. }
  8328. String::~String() throw()
  8329. {
  8330. StringHolder::release (text);
  8331. }
  8332. String::String (const String& other) throw()
  8333. : text (other.text)
  8334. {
  8335. StringHolder::retain (text);
  8336. }
  8337. void String::swapWith (String& other) throw()
  8338. {
  8339. swapVariables (text, other.text);
  8340. }
  8341. String& String::operator= (const String& other) throw()
  8342. {
  8343. juce_wchar* const newText = other.text;
  8344. StringHolder::retain (newText);
  8345. StringHolder::release (static_cast <juce_wchar*> (Atomic::swapPointers ((void* volatile*) &text, newText)));
  8346. return *this;
  8347. }
  8348. String::String (const size_t numChars, const int /*dummyVariable*/)
  8349. : text (StringHolder::create (numChars))
  8350. {
  8351. }
  8352. String::String (const String& stringToCopy, const size_t charsToAllocate)
  8353. {
  8354. const size_t otherSize = StringHolder::getAllocatedNumChars (stringToCopy.text);
  8355. text = StringHolder::create (jmax (charsToAllocate, otherSize));
  8356. StringHolder::copyChars (text, stringToCopy.text, otherSize);
  8357. }
  8358. String::String (const char* const t)
  8359. {
  8360. if (t != 0 && *t != 0)
  8361. {
  8362. const int len = CharacterFunctions::length (t);
  8363. text = StringHolder::create (len);
  8364. CharacterFunctions::copy (text, t, len + 1);
  8365. }
  8366. else
  8367. {
  8368. text = StringHolder::getEmpty();
  8369. }
  8370. }
  8371. String::String (const juce_wchar* const t)
  8372. {
  8373. if (t != 0 && *t != 0)
  8374. {
  8375. const int len = CharacterFunctions::length (t);
  8376. text = StringHolder::create (len);
  8377. StringHolder::copyChars (text, t, len);
  8378. }
  8379. else
  8380. {
  8381. text = StringHolder::getEmpty();
  8382. }
  8383. }
  8384. String::String (const char* const t, const size_t maxChars)
  8385. {
  8386. int i;
  8387. for (i = 0; (size_t) i < maxChars; ++i)
  8388. if (t[i] == 0)
  8389. break;
  8390. if (i > 0)
  8391. {
  8392. text = StringHolder::create (i);
  8393. CharacterFunctions::copy (text, t, i);
  8394. text[i] = 0;
  8395. }
  8396. else
  8397. {
  8398. text = StringHolder::getEmpty();
  8399. }
  8400. }
  8401. String::String (const juce_wchar* const t, const size_t maxChars)
  8402. {
  8403. int i;
  8404. for (i = 0; (size_t) i < maxChars; ++i)
  8405. if (t[i] == 0)
  8406. break;
  8407. if (i > 0)
  8408. {
  8409. text = StringHolder::create (i);
  8410. StringHolder::copyChars (text, t, i);
  8411. }
  8412. else
  8413. {
  8414. text = StringHolder::getEmpty();
  8415. }
  8416. }
  8417. const String String::charToString (const juce_wchar character)
  8418. {
  8419. String result ((size_t) 1, (int) 0);
  8420. result.text[0] = character;
  8421. result.text[1] = 0;
  8422. return result;
  8423. }
  8424. namespace NumberToStringConverters
  8425. {
  8426. // pass in a pointer to the END of a buffer..
  8427. static juce_wchar* int64ToString (juce_wchar* t, const int64 n) throw()
  8428. {
  8429. *--t = 0;
  8430. int64 v = (n >= 0) ? n : -n;
  8431. do
  8432. {
  8433. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8434. v /= 10;
  8435. } while (v > 0);
  8436. if (n < 0)
  8437. *--t = '-';
  8438. return t;
  8439. }
  8440. static juce_wchar* uint64ToString (juce_wchar* t, int64 v) throw()
  8441. {
  8442. *--t = 0;
  8443. do
  8444. {
  8445. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8446. v /= 10;
  8447. } while (v > 0);
  8448. return t;
  8449. }
  8450. static juce_wchar* intToString (juce_wchar* t, const int n) throw()
  8451. {
  8452. if (n == (int) 0x80000000) // (would cause an overflow)
  8453. return int64ToString (t, n);
  8454. *--t = 0;
  8455. int v = abs (n);
  8456. do
  8457. {
  8458. *--t = (juce_wchar) ('0' + (v % 10));
  8459. v /= 10;
  8460. } while (v > 0);
  8461. if (n < 0)
  8462. *--t = '-';
  8463. return t;
  8464. }
  8465. static juce_wchar* uintToString (juce_wchar* t, unsigned int v) throw()
  8466. {
  8467. *--t = 0;
  8468. do
  8469. {
  8470. *--t = (juce_wchar) ('0' + (v % 10));
  8471. v /= 10;
  8472. } while (v > 0);
  8473. return t;
  8474. }
  8475. static juce_wchar getDecimalPoint()
  8476. {
  8477. #if JUCE_WINDOWS && _MSC_VER < 1400
  8478. static juce_wchar dp = std::_USE (std::locale(), std::numpunct <wchar_t>).decimal_point();
  8479. #else
  8480. static juce_wchar dp = std::use_facet <std::numpunct <wchar_t> > (std::locale()).decimal_point();
  8481. #endif
  8482. return dp;
  8483. }
  8484. static juce_wchar* doubleToString (juce_wchar* buffer, int numChars, double n, int numDecPlaces, size_t& len) throw()
  8485. {
  8486. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8487. {
  8488. juce_wchar* const end = buffer + numChars;
  8489. juce_wchar* t = end;
  8490. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8491. *--t = (juce_wchar) 0;
  8492. while (numDecPlaces >= 0 || v > 0)
  8493. {
  8494. if (numDecPlaces == 0)
  8495. *--t = getDecimalPoint();
  8496. *--t = (juce_wchar) ('0' + (v % 10));
  8497. v /= 10;
  8498. --numDecPlaces;
  8499. }
  8500. if (n < 0)
  8501. *--t = '-';
  8502. len = end - t - 1;
  8503. return t;
  8504. }
  8505. else
  8506. {
  8507. #if JUCE_WIN32
  8508. #if _MSC_VER <= 1200
  8509. len = _snwprintf (buffer, numChars, L"%.9g", n);
  8510. #else
  8511. len = _snwprintf_s (buffer, numChars, _TRUNCATE, L"%.9g", n);
  8512. #endif
  8513. #else
  8514. len = swprintf (buffer, numChars, L"%.9g", n);
  8515. #endif
  8516. return buffer;
  8517. }
  8518. }
  8519. }
  8520. String::String (const int number)
  8521. {
  8522. juce_wchar buffer [16];
  8523. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8524. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8525. createInternal (start, end - start - 1);
  8526. }
  8527. String::String (const unsigned int number)
  8528. {
  8529. juce_wchar buffer [16];
  8530. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8531. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8532. createInternal (start, end - start - 1);
  8533. }
  8534. String::String (const short number)
  8535. {
  8536. juce_wchar buffer [16];
  8537. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8538. juce_wchar* const start = NumberToStringConverters::intToString (end, (int) number);
  8539. createInternal (start, end - start - 1);
  8540. }
  8541. String::String (const unsigned short number)
  8542. {
  8543. juce_wchar buffer [16];
  8544. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8545. juce_wchar* const start = NumberToStringConverters::uintToString (end, (unsigned int) number);
  8546. createInternal (start, end - start - 1);
  8547. }
  8548. String::String (const int64 number)
  8549. {
  8550. juce_wchar buffer [32];
  8551. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8552. juce_wchar* const start = NumberToStringConverters::int64ToString (end, number);
  8553. createInternal (start, end - start - 1);
  8554. }
  8555. String::String (const uint64 number)
  8556. {
  8557. juce_wchar buffer [32];
  8558. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8559. juce_wchar* const start = NumberToStringConverters::uint64ToString (end, number);
  8560. createInternal (start, end - start - 1);
  8561. }
  8562. String::String (const float number, const int numberOfDecimalPlaces)
  8563. {
  8564. juce_wchar buffer [48];
  8565. size_t len;
  8566. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len);
  8567. createInternal (start, len);
  8568. }
  8569. String::String (const double number, const int numberOfDecimalPlaces)
  8570. {
  8571. juce_wchar buffer [48];
  8572. size_t len;
  8573. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), number, numberOfDecimalPlaces, len);
  8574. createInternal (start, len);
  8575. }
  8576. int String::length() const throw()
  8577. {
  8578. return CharacterFunctions::length (text);
  8579. }
  8580. int String::hashCode() const throw()
  8581. {
  8582. const juce_wchar* t = text;
  8583. int result = 0;
  8584. while (*t != (juce_wchar) 0)
  8585. result = 31 * result + *t++;
  8586. return result;
  8587. }
  8588. int64 String::hashCode64() const throw()
  8589. {
  8590. const juce_wchar* t = text;
  8591. int64 result = 0;
  8592. while (*t != (juce_wchar) 0)
  8593. result = 101 * result + *t++;
  8594. return result;
  8595. }
  8596. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8597. {
  8598. return string1.compare (string2) == 0;
  8599. }
  8600. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8601. {
  8602. return string1.compare (string2) == 0;
  8603. }
  8604. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8605. {
  8606. return string1.compare (string2) == 0;
  8607. }
  8608. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8609. {
  8610. return string1.compare (string2) != 0;
  8611. }
  8612. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8613. {
  8614. return string1.compare (string2) != 0;
  8615. }
  8616. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8617. {
  8618. return string1.compare (string2) != 0;
  8619. }
  8620. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8621. {
  8622. return string1.compare (string2) > 0;
  8623. }
  8624. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8625. {
  8626. return string1.compare (string2) < 0;
  8627. }
  8628. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8629. {
  8630. return string1.compare (string2) >= 0;
  8631. }
  8632. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8633. {
  8634. return string1.compare (string2) <= 0;
  8635. }
  8636. bool String::equalsIgnoreCase (const juce_wchar* t) const throw()
  8637. {
  8638. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8639. : isEmpty();
  8640. }
  8641. bool String::equalsIgnoreCase (const char* t) const throw()
  8642. {
  8643. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8644. : isEmpty();
  8645. }
  8646. bool String::equalsIgnoreCase (const String& other) const throw()
  8647. {
  8648. return text == other.text
  8649. || CharacterFunctions::compareIgnoreCase (text, other.text) == 0;
  8650. }
  8651. int String::compare (const String& other) const throw()
  8652. {
  8653. return (text == other.text) ? 0 : CharacterFunctions::compare (text, other.text);
  8654. }
  8655. int String::compare (const char* other) const throw()
  8656. {
  8657. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8658. }
  8659. int String::compare (const juce_wchar* other) const throw()
  8660. {
  8661. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8662. }
  8663. int String::compareIgnoreCase (const String& other) const throw()
  8664. {
  8665. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text, other.text);
  8666. }
  8667. int String::compareLexicographically (const String& other) const throw()
  8668. {
  8669. const juce_wchar* s1 = text;
  8670. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8671. ++s1;
  8672. const juce_wchar* s2 = other.text;
  8673. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8674. ++s2;
  8675. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8676. }
  8677. String& String::operator+= (const juce_wchar* const t)
  8678. {
  8679. if (t != 0)
  8680. appendInternal (t, CharacterFunctions::length (t));
  8681. return *this;
  8682. }
  8683. String& String::operator+= (const String& other)
  8684. {
  8685. if (isEmpty())
  8686. operator= (other);
  8687. else
  8688. appendInternal (other.text, other.length());
  8689. return *this;
  8690. }
  8691. String& String::operator+= (const char ch)
  8692. {
  8693. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8694. return operator+= ((const juce_wchar*) asString);
  8695. }
  8696. String& String::operator+= (const juce_wchar ch)
  8697. {
  8698. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8699. return operator+= ((const juce_wchar*) asString);
  8700. }
  8701. String& String::operator+= (const int number)
  8702. {
  8703. juce_wchar buffer [16];
  8704. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8705. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8706. appendInternal (start, (int) (end - start));
  8707. return *this;
  8708. }
  8709. String& String::operator+= (const unsigned int number)
  8710. {
  8711. juce_wchar buffer [16];
  8712. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8713. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8714. appendInternal (start, (int) (end - start));
  8715. return *this;
  8716. }
  8717. void String::append (const juce_wchar* const other, const int howMany)
  8718. {
  8719. if (howMany > 0)
  8720. {
  8721. int i;
  8722. for (i = 0; i < howMany; ++i)
  8723. if (other[i] == 0)
  8724. break;
  8725. appendInternal (other, i);
  8726. }
  8727. }
  8728. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8729. {
  8730. String s (string1);
  8731. return s += string2;
  8732. }
  8733. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8734. {
  8735. String s (string1);
  8736. return s += string2;
  8737. }
  8738. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8739. {
  8740. return String::charToString (string1) + string2;
  8741. }
  8742. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8743. {
  8744. return String::charToString (string1) + string2;
  8745. }
  8746. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8747. {
  8748. return string1 += string2;
  8749. }
  8750. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8751. {
  8752. return string1 += string2;
  8753. }
  8754. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8755. {
  8756. return string1 += string2;
  8757. }
  8758. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8759. {
  8760. return string1 += string2;
  8761. }
  8762. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8763. {
  8764. return string1 += string2;
  8765. }
  8766. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8767. {
  8768. return string1 += characterToAppend;
  8769. }
  8770. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8771. {
  8772. return string1 += characterToAppend;
  8773. }
  8774. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8775. {
  8776. return string1 += string2;
  8777. }
  8778. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8779. {
  8780. return string1 += string2;
  8781. }
  8782. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8783. {
  8784. return string1 += string2;
  8785. }
  8786. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8787. {
  8788. return string1 += (int) number;
  8789. }
  8790. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8791. {
  8792. return string1 += number;
  8793. }
  8794. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8795. {
  8796. return string1 += number;
  8797. }
  8798. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8799. {
  8800. return string1 += (int) number;
  8801. }
  8802. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8803. {
  8804. return string1 += (unsigned int) number;
  8805. }
  8806. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8807. {
  8808. return string1 += String (number);
  8809. }
  8810. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8811. {
  8812. return string1 += String (number);
  8813. }
  8814. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8815. {
  8816. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8817. // if lots of large, persistent strings were to be written to streams).
  8818. const int numBytes = text.getNumBytesAsUTF8();
  8819. HeapBlock<char> temp (numBytes + 1);
  8820. text.copyToUTF8 (temp, numBytes + 1);
  8821. stream.write (temp, numBytes);
  8822. return stream;
  8823. }
  8824. int String::indexOfChar (const juce_wchar character) const throw()
  8825. {
  8826. const juce_wchar* t = text;
  8827. for (;;)
  8828. {
  8829. if (*t == character)
  8830. return (int) (t - text);
  8831. if (*t++ == 0)
  8832. return -1;
  8833. }
  8834. }
  8835. int String::lastIndexOfChar (const juce_wchar character) const throw()
  8836. {
  8837. for (int i = length(); --i >= 0;)
  8838. if (text[i] == character)
  8839. return i;
  8840. return -1;
  8841. }
  8842. int String::indexOf (const String& t) const throw()
  8843. {
  8844. const juce_wchar* const r = CharacterFunctions::find (text, t.text);
  8845. return r == 0 ? -1 : (int) (r - text);
  8846. }
  8847. int String::indexOfChar (const int startIndex,
  8848. const juce_wchar character) const throw()
  8849. {
  8850. if (startIndex > 0 && startIndex >= length())
  8851. return -1;
  8852. const juce_wchar* t = text + jmax (0, startIndex);
  8853. for (;;)
  8854. {
  8855. if (*t == character)
  8856. return (int) (t - text);
  8857. if (*t == 0)
  8858. return -1;
  8859. ++t;
  8860. }
  8861. }
  8862. int String::indexOfAnyOf (const String& charactersToLookFor,
  8863. const int startIndex,
  8864. const bool ignoreCase) const throw()
  8865. {
  8866. if (startIndex > 0 && startIndex >= length())
  8867. return -1;
  8868. const juce_wchar* t = text + jmax (0, startIndex);
  8869. while (*t != 0)
  8870. {
  8871. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, *t, ignoreCase) >= 0)
  8872. return (int) (t - text);
  8873. ++t;
  8874. }
  8875. return -1;
  8876. }
  8877. int String::indexOf (const int startIndex, const String& other) const throw()
  8878. {
  8879. if (startIndex > 0 && startIndex >= length())
  8880. return -1;
  8881. const juce_wchar* const found = CharacterFunctions::find (text + jmax (0, startIndex), other.text);
  8882. return found == 0 ? -1 : (int) (found - text);
  8883. }
  8884. int String::indexOfIgnoreCase (const String& other) const throw()
  8885. {
  8886. if (other.isNotEmpty())
  8887. {
  8888. const int len = other.length();
  8889. const int end = length() - len;
  8890. for (int i = 0; i <= end; ++i)
  8891. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8892. return i;
  8893. }
  8894. return -1;
  8895. }
  8896. int String::indexOfIgnoreCase (const int startIndex, const String& other) const throw()
  8897. {
  8898. if (other.isNotEmpty())
  8899. {
  8900. const int len = other.length();
  8901. const int end = length() - len;
  8902. for (int i = jmax (0, startIndex); i <= end; ++i)
  8903. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8904. return i;
  8905. }
  8906. return -1;
  8907. }
  8908. int String::lastIndexOf (const String& other) const throw()
  8909. {
  8910. if (other.isNotEmpty())
  8911. {
  8912. const int len = other.length();
  8913. int i = length() - len;
  8914. if (i >= 0)
  8915. {
  8916. const juce_wchar* n = text + i;
  8917. while (i >= 0)
  8918. {
  8919. if (CharacterFunctions::compare (n--, other.text, len) == 0)
  8920. return i;
  8921. --i;
  8922. }
  8923. }
  8924. }
  8925. return -1;
  8926. }
  8927. int String::lastIndexOfIgnoreCase (const String& other) const throw()
  8928. {
  8929. if (other.isNotEmpty())
  8930. {
  8931. const int len = other.length();
  8932. int i = length() - len;
  8933. if (i >= 0)
  8934. {
  8935. const juce_wchar* n = text + i;
  8936. while (i >= 0)
  8937. {
  8938. if (CharacterFunctions::compareIgnoreCase (n--, other.text, len) == 0)
  8939. return i;
  8940. --i;
  8941. }
  8942. }
  8943. }
  8944. return -1;
  8945. }
  8946. int String::lastIndexOfAnyOf (const String& charactersToLookFor, const bool ignoreCase) const throw()
  8947. {
  8948. for (int i = length(); --i >= 0;)
  8949. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, text[i], ignoreCase) >= 0)
  8950. return i;
  8951. return -1;
  8952. }
  8953. bool String::contains (const String& other) const throw()
  8954. {
  8955. return indexOf (other) >= 0;
  8956. }
  8957. bool String::containsChar (const juce_wchar character) const throw()
  8958. {
  8959. const juce_wchar* t = text;
  8960. for (;;)
  8961. {
  8962. if (*t == 0)
  8963. return false;
  8964. if (*t == character)
  8965. return true;
  8966. ++t;
  8967. }
  8968. }
  8969. bool String::containsIgnoreCase (const String& t) const throw()
  8970. {
  8971. return indexOfIgnoreCase (t) >= 0;
  8972. }
  8973. int String::indexOfWholeWord (const String& word) const throw()
  8974. {
  8975. if (word.isNotEmpty())
  8976. {
  8977. const int wordLen = word.length();
  8978. const int end = length() - wordLen;
  8979. const juce_wchar* t = text;
  8980. for (int i = 0; i <= end; ++i)
  8981. {
  8982. if (CharacterFunctions::compare (t, word.text, wordLen) == 0
  8983. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8984. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8985. {
  8986. return i;
  8987. }
  8988. ++t;
  8989. }
  8990. }
  8991. return -1;
  8992. }
  8993. int String::indexOfWholeWordIgnoreCase (const String& word) const throw()
  8994. {
  8995. if (word.isNotEmpty())
  8996. {
  8997. const int wordLen = word.length();
  8998. const int end = length() - wordLen;
  8999. const juce_wchar* t = text;
  9000. for (int i = 0; i <= end; ++i)
  9001. {
  9002. if (CharacterFunctions::compareIgnoreCase (t, word.text, wordLen) == 0
  9003. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9004. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9005. {
  9006. return i;
  9007. }
  9008. ++t;
  9009. }
  9010. }
  9011. return -1;
  9012. }
  9013. bool String::containsWholeWord (const String& wordToLookFor) const throw()
  9014. {
  9015. return indexOfWholeWord (wordToLookFor) >= 0;
  9016. }
  9017. bool String::containsWholeWordIgnoreCase (const String& wordToLookFor) const throw()
  9018. {
  9019. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9020. }
  9021. static int indexOfMatch (const juce_wchar* const wildcard,
  9022. const juce_wchar* const test,
  9023. const bool ignoreCase) throw()
  9024. {
  9025. int start = 0;
  9026. while (test [start] != 0)
  9027. {
  9028. int i = 0;
  9029. for (;;)
  9030. {
  9031. const juce_wchar wc = wildcard [i];
  9032. const juce_wchar c = test [i + start];
  9033. if (wc == c
  9034. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9035. || (wc == '?' && c != 0))
  9036. {
  9037. if (wc == 0)
  9038. return start;
  9039. ++i;
  9040. }
  9041. else
  9042. {
  9043. if (wc == '*' && (wildcard [i + 1] == 0
  9044. || indexOfMatch (wildcard + i + 1,
  9045. test + start + i,
  9046. ignoreCase) >= 0))
  9047. {
  9048. return start;
  9049. }
  9050. break;
  9051. }
  9052. }
  9053. ++start;
  9054. }
  9055. return -1;
  9056. }
  9057. bool String::matchesWildcard (const String& wildcard, const bool ignoreCase) const throw()
  9058. {
  9059. int i = 0;
  9060. for (;;)
  9061. {
  9062. const juce_wchar wc = wildcard.text [i];
  9063. const juce_wchar c = text [i];
  9064. if (wc == c
  9065. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9066. || (wc == '?' && c != 0))
  9067. {
  9068. if (wc == 0)
  9069. return true;
  9070. ++i;
  9071. }
  9072. else
  9073. {
  9074. return wc == '*' && (wildcard [i + 1] == 0
  9075. || indexOfMatch (wildcard.text + i + 1,
  9076. text + i,
  9077. ignoreCase) >= 0);
  9078. }
  9079. }
  9080. }
  9081. const String String::repeatedString (const String& stringToRepeat, int numberOfTimesToRepeat)
  9082. {
  9083. const int len = stringToRepeat.length();
  9084. String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
  9085. juce_wchar* n = result.text;
  9086. *n = 0;
  9087. while (--numberOfTimesToRepeat >= 0)
  9088. {
  9089. StringHolder::copyChars (n, stringToRepeat.text, len);
  9090. n += len;
  9091. }
  9092. return result;
  9093. }
  9094. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  9095. {
  9096. jassert (padCharacter != 0);
  9097. const int len = length();
  9098. if (len >= minimumLength || padCharacter == 0)
  9099. return *this;
  9100. String result ((size_t) minimumLength + 1, (int) 0);
  9101. juce_wchar* n = result.text;
  9102. minimumLength -= len;
  9103. while (--minimumLength >= 0)
  9104. *n++ = padCharacter;
  9105. StringHolder::copyChars (n, text, len);
  9106. return result;
  9107. }
  9108. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  9109. {
  9110. jassert (padCharacter != 0);
  9111. const int len = length();
  9112. if (len >= minimumLength || padCharacter == 0)
  9113. return *this;
  9114. String result (*this, (size_t) minimumLength);
  9115. juce_wchar* n = result.text + len;
  9116. minimumLength -= len;
  9117. while (--minimumLength >= 0)
  9118. *n++ = padCharacter;
  9119. *n = 0;
  9120. return result;
  9121. }
  9122. const String String::replaceSection (int index, int numCharsToReplace, const String& stringToInsert) const
  9123. {
  9124. if (index < 0)
  9125. {
  9126. // a negative index to replace from?
  9127. jassertfalse
  9128. index = 0;
  9129. }
  9130. if (numCharsToReplace < 0)
  9131. {
  9132. // replacing a negative number of characters?
  9133. numCharsToReplace = 0;
  9134. jassertfalse;
  9135. }
  9136. const int len = length();
  9137. if (index + numCharsToReplace > len)
  9138. {
  9139. if (index > len)
  9140. {
  9141. // replacing beyond the end of the string?
  9142. index = len;
  9143. jassertfalse
  9144. }
  9145. numCharsToReplace = len - index;
  9146. }
  9147. const int newStringLen = stringToInsert.length();
  9148. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9149. if (newTotalLen <= 0)
  9150. return String::empty;
  9151. String result ((size_t) newTotalLen, (int) 0);
  9152. StringHolder::copyChars (result.text, text, index);
  9153. if (newStringLen > 0)
  9154. StringHolder::copyChars (result.text + index, stringToInsert.text, newStringLen);
  9155. const int endStringLen = newTotalLen - (index + newStringLen);
  9156. if (endStringLen > 0)
  9157. StringHolder::copyChars (result.text + (index + newStringLen),
  9158. text + (index + numCharsToReplace),
  9159. endStringLen);
  9160. return result;
  9161. }
  9162. const String String::replace (const String& stringToReplace, const String& stringToInsert, const bool ignoreCase) const
  9163. {
  9164. const int stringToReplaceLen = stringToReplace.length();
  9165. const int stringToInsertLen = stringToInsert.length();
  9166. int i = 0;
  9167. String result (*this);
  9168. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9169. : result.indexOf (i, stringToReplace))) >= 0)
  9170. {
  9171. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9172. i += stringToInsertLen;
  9173. }
  9174. return result;
  9175. }
  9176. const String String::replaceCharacter (const juce_wchar charToReplace, const juce_wchar charToInsert) const
  9177. {
  9178. const int index = indexOfChar (charToReplace);
  9179. if (index < 0)
  9180. return *this;
  9181. String result (*this, size_t());
  9182. juce_wchar* t = result.text + index;
  9183. while (*t != 0)
  9184. {
  9185. if (*t == charToReplace)
  9186. *t = charToInsert;
  9187. ++t;
  9188. }
  9189. return result;
  9190. }
  9191. const String String::replaceCharacters (const String& charactersToReplace,
  9192. const String& charactersToInsertInstead) const
  9193. {
  9194. String result (*this, size_t());
  9195. juce_wchar* t = result.text;
  9196. const int len2 = charactersToInsertInstead.length();
  9197. // the two strings passed in are supposed to be the same length!
  9198. jassert (len2 == charactersToReplace.length());
  9199. while (*t != 0)
  9200. {
  9201. const int index = charactersToReplace.indexOfChar (*t);
  9202. if (((unsigned int) index) < (unsigned int) len2)
  9203. *t = charactersToInsertInstead [index];
  9204. ++t;
  9205. }
  9206. return result;
  9207. }
  9208. bool String::startsWith (const String& other) const throw()
  9209. {
  9210. return CharacterFunctions::compare (text, other.text, other.length()) == 0;
  9211. }
  9212. bool String::startsWithIgnoreCase (const String& other) const throw()
  9213. {
  9214. return CharacterFunctions::compareIgnoreCase (text, other.text, other.length()) == 0;
  9215. }
  9216. bool String::startsWithChar (const juce_wchar character) const throw()
  9217. {
  9218. jassert (character != 0); // strings can't contain a null character!
  9219. return text[0] == character;
  9220. }
  9221. bool String::endsWithChar (const juce_wchar character) const throw()
  9222. {
  9223. jassert (character != 0); // strings can't contain a null character!
  9224. return text[0] != 0
  9225. && text [length() - 1] == character;
  9226. }
  9227. bool String::endsWith (const String& other) const throw()
  9228. {
  9229. const int thisLen = length();
  9230. const int otherLen = other.length();
  9231. return thisLen >= otherLen
  9232. && CharacterFunctions::compare (text + thisLen - otherLen, other.text) == 0;
  9233. }
  9234. bool String::endsWithIgnoreCase (const String& other) const throw()
  9235. {
  9236. const int thisLen = length();
  9237. const int otherLen = other.length();
  9238. return thisLen >= otherLen
  9239. && CharacterFunctions::compareIgnoreCase (text + thisLen - otherLen, other.text) == 0;
  9240. }
  9241. const String String::toUpperCase() const
  9242. {
  9243. String result (*this, size_t());
  9244. CharacterFunctions::toUpperCase (result.text);
  9245. return result;
  9246. }
  9247. const String String::toLowerCase() const
  9248. {
  9249. String result (*this, size_t());
  9250. CharacterFunctions::toLowerCase (result.text);
  9251. return result;
  9252. }
  9253. juce_wchar& String::operator[] (const int index)
  9254. {
  9255. jassert (((unsigned int) index) <= (unsigned int) length());
  9256. text = StringHolder::makeUnique (text);
  9257. return text [index];
  9258. }
  9259. juce_wchar String::getLastCharacter() const throw()
  9260. {
  9261. return isEmpty() ? juce_wchar() : text [length() - 1];
  9262. }
  9263. const String String::substring (int start, int end) const
  9264. {
  9265. if (start < 0)
  9266. start = 0;
  9267. else if (end <= start)
  9268. return empty;
  9269. int len = 0;
  9270. while (len <= end && text [len] != 0)
  9271. ++len;
  9272. if (end >= len)
  9273. {
  9274. if (start == 0)
  9275. return *this;
  9276. end = len;
  9277. }
  9278. return String (text + start, end - start);
  9279. }
  9280. const String String::substring (const int start) const
  9281. {
  9282. if (start <= 0)
  9283. return *this;
  9284. const int len = length();
  9285. if (start >= len)
  9286. return empty;
  9287. return String (text + start, len - start);
  9288. }
  9289. const String String::dropLastCharacters (const int numberToDrop) const
  9290. {
  9291. return String (text, jmax (0, length() - numberToDrop));
  9292. }
  9293. const String String::getLastCharacters (const int numCharacters) const
  9294. {
  9295. return String (text + jmax (0, length() - jmax (0, numCharacters)));
  9296. }
  9297. const String String::fromFirstOccurrenceOf (const String& sub,
  9298. const bool includeSubString,
  9299. const bool ignoreCase) const
  9300. {
  9301. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9302. : indexOf (sub);
  9303. if (i < 0)
  9304. return empty;
  9305. return substring (includeSubString ? i : i + sub.length());
  9306. }
  9307. const String String::fromLastOccurrenceOf (const String& sub,
  9308. const bool includeSubString,
  9309. const bool ignoreCase) const
  9310. {
  9311. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9312. : lastIndexOf (sub);
  9313. if (i < 0)
  9314. return *this;
  9315. return substring (includeSubString ? i : i + sub.length());
  9316. }
  9317. const String String::upToFirstOccurrenceOf (const String& 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. return substring (0, includeSubString ? i + sub.length() : i);
  9326. }
  9327. const String String::upToLastOccurrenceOf (const String& sub,
  9328. const bool includeSubString,
  9329. const bool ignoreCase) const
  9330. {
  9331. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9332. : lastIndexOf (sub);
  9333. if (i < 0)
  9334. return *this;
  9335. return substring (0, includeSubString ? i + sub.length() : i);
  9336. }
  9337. bool String::isQuotedString() const
  9338. {
  9339. const String trimmed (trimStart());
  9340. return trimmed[0] == '"'
  9341. || trimmed[0] == '\'';
  9342. }
  9343. const String String::unquoted() const
  9344. {
  9345. String s (*this);
  9346. if (s.text[0] == '"' || s.text[0] == '\'')
  9347. s = s.substring (1);
  9348. const int lastCharIndex = s.length() - 1;
  9349. if (lastCharIndex >= 0
  9350. && (s [lastCharIndex] == '"' || s[lastCharIndex] == '\''))
  9351. s [lastCharIndex] = 0;
  9352. return s;
  9353. }
  9354. const String String::quoted (const juce_wchar quoteCharacter) const
  9355. {
  9356. if (isEmpty())
  9357. return charToString (quoteCharacter) + quoteCharacter;
  9358. String t (*this);
  9359. if (! t.startsWithChar (quoteCharacter))
  9360. t = charToString (quoteCharacter) + t;
  9361. if (! t.endsWithChar (quoteCharacter))
  9362. t += quoteCharacter;
  9363. return t;
  9364. }
  9365. const String String::trim() const
  9366. {
  9367. if (isEmpty())
  9368. return empty;
  9369. int start = 0;
  9370. while (CharacterFunctions::isWhitespace (text [start]))
  9371. ++start;
  9372. const int len = length();
  9373. int end = len - 1;
  9374. while ((end >= start) && CharacterFunctions::isWhitespace (text [end]))
  9375. --end;
  9376. ++end;
  9377. if (end <= start)
  9378. return empty;
  9379. else if (start > 0 || end < len)
  9380. return String (text + start, end - start);
  9381. return *this;
  9382. }
  9383. const String String::trimStart() const
  9384. {
  9385. if (isEmpty())
  9386. return empty;
  9387. const juce_wchar* t = text;
  9388. while (CharacterFunctions::isWhitespace (*t))
  9389. ++t;
  9390. if (t == text)
  9391. return *this;
  9392. return String (t);
  9393. }
  9394. const String String::trimEnd() const
  9395. {
  9396. if (isEmpty())
  9397. return empty;
  9398. const juce_wchar* endT = text + (length() - 1);
  9399. while ((endT >= text) && CharacterFunctions::isWhitespace (*endT))
  9400. --endT;
  9401. return String (text, (int) (++endT - text));
  9402. }
  9403. const String String::trimCharactersAtStart (const String& charactersToTrim) const
  9404. {
  9405. const juce_wchar* t = text;
  9406. while (charactersToTrim.containsChar (*t))
  9407. ++t;
  9408. if (t == text)
  9409. return *this;
  9410. return String (t);
  9411. }
  9412. const String String::trimCharactersAtEnd (const String& charactersToTrim) const
  9413. {
  9414. if (isEmpty())
  9415. return empty;
  9416. const juce_wchar* endT = text + (length() - 1);
  9417. while (endT >= text && charactersToTrim.containsChar (*endT))
  9418. --endT;
  9419. return String (text, (int) (++endT - text));
  9420. }
  9421. const String String::retainCharacters (const String& charactersToRetain) const
  9422. {
  9423. if (isEmpty())
  9424. return empty;
  9425. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9426. juce_wchar* dst = result.text;
  9427. const juce_wchar* src = text;
  9428. while (*src != 0)
  9429. {
  9430. if (charactersToRetain.containsChar (*src))
  9431. *dst++ = *src;
  9432. ++src;
  9433. }
  9434. *dst = 0;
  9435. return result;
  9436. }
  9437. const String String::removeCharacters (const String& charactersToRemove) const
  9438. {
  9439. if (isEmpty())
  9440. return empty;
  9441. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9442. juce_wchar* dst = result.text;
  9443. const juce_wchar* src = text;
  9444. while (*src != 0)
  9445. {
  9446. if (! charactersToRemove.containsChar (*src))
  9447. *dst++ = *src;
  9448. ++src;
  9449. }
  9450. *dst = 0;
  9451. return result;
  9452. }
  9453. const String String::initialSectionContainingOnly (const String& permittedCharacters) const
  9454. {
  9455. int i = 0;
  9456. for (;;)
  9457. {
  9458. if (! permittedCharacters.containsChar (text[i]))
  9459. break;
  9460. ++i;
  9461. }
  9462. return substring (0, i);
  9463. }
  9464. const String String::initialSectionNotContaining (const String& charactersToStopAt) const
  9465. {
  9466. const juce_wchar* const t = text;
  9467. int i = 0;
  9468. while (t[i] != 0)
  9469. {
  9470. if (charactersToStopAt.containsChar (t[i]))
  9471. return String (text, i);
  9472. ++i;
  9473. }
  9474. return empty;
  9475. }
  9476. bool String::containsOnly (const String& chars) const throw()
  9477. {
  9478. const juce_wchar* t = text;
  9479. while (*t != 0)
  9480. if (! chars.containsChar (*t++))
  9481. return false;
  9482. return true;
  9483. }
  9484. bool String::containsAnyOf (const String& chars) const throw()
  9485. {
  9486. const juce_wchar* t = text;
  9487. while (*t != 0)
  9488. if (chars.containsChar (*t++))
  9489. return true;
  9490. return false;
  9491. }
  9492. bool String::containsNonWhitespaceChars() const throw()
  9493. {
  9494. const juce_wchar* t = text;
  9495. while (*t != 0)
  9496. if (! CharacterFunctions::isWhitespace (*t++))
  9497. return true;
  9498. return false;
  9499. }
  9500. const String String::formatted (const juce_wchar* const pf, ... )
  9501. {
  9502. jassert (pf != 0);
  9503. va_list args;
  9504. va_start (args, pf);
  9505. size_t bufferSize = 256;
  9506. String result (bufferSize, (int) 0);
  9507. result.text[0] = 0;
  9508. for (;;)
  9509. {
  9510. #if JUCE_LINUX && JUCE_64BIT
  9511. va_list tempArgs;
  9512. va_copy (tempArgs, args);
  9513. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, tempArgs);
  9514. va_end (tempArgs);
  9515. #elif JUCE_WINDOWS
  9516. #ifdef _MSC_VER
  9517. #pragma warning (push)
  9518. #pragma warning (disable: 4996)
  9519. #endif
  9520. const int num = (int) _vsnwprintf (result.text, bufferSize - 1, pf, args);
  9521. #ifdef _MSC_VER
  9522. #pragma warning (pop)
  9523. #endif
  9524. #else
  9525. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, args);
  9526. #endif
  9527. if (num > 0)
  9528. return result;
  9529. bufferSize += 256;
  9530. if (num == 0 || bufferSize > 65536) // the upper limit is a sanity check to avoid situations where vprintf repeatedly
  9531. break; // returns -1 because of an error rather than because it needs more space.
  9532. result.preallocateStorage (bufferSize);
  9533. }
  9534. return empty;
  9535. }
  9536. int String::getIntValue() const throw()
  9537. {
  9538. return CharacterFunctions::getIntValue (text);
  9539. }
  9540. int String::getTrailingIntValue() const throw()
  9541. {
  9542. int n = 0;
  9543. int mult = 1;
  9544. const juce_wchar* t = text + length();
  9545. while (--t >= text)
  9546. {
  9547. const juce_wchar c = *t;
  9548. if (! CharacterFunctions::isDigit (c))
  9549. {
  9550. if (c == '-')
  9551. n = -n;
  9552. break;
  9553. }
  9554. n += mult * (c - '0');
  9555. mult *= 10;
  9556. }
  9557. return n;
  9558. }
  9559. int64 String::getLargeIntValue() const throw()
  9560. {
  9561. return CharacterFunctions::getInt64Value (text);
  9562. }
  9563. float String::getFloatValue() const throw()
  9564. {
  9565. return (float) CharacterFunctions::getDoubleValue (text);
  9566. }
  9567. double String::getDoubleValue() const throw()
  9568. {
  9569. return CharacterFunctions::getDoubleValue (text);
  9570. }
  9571. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  9572. const String String::toHexString (const int number)
  9573. {
  9574. juce_wchar buffer[32];
  9575. juce_wchar* const end = buffer + 32;
  9576. juce_wchar* t = end;
  9577. *--t = 0;
  9578. unsigned int v = (unsigned int) number;
  9579. do
  9580. {
  9581. *--t = hexDigits [v & 15];
  9582. v >>= 4;
  9583. } while (v != 0);
  9584. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9585. }
  9586. const String String::toHexString (const int64 number)
  9587. {
  9588. juce_wchar buffer[32];
  9589. juce_wchar* const end = buffer + 32;
  9590. juce_wchar* t = end;
  9591. *--t = 0;
  9592. uint64 v = (uint64) number;
  9593. do
  9594. {
  9595. *--t = hexDigits [(int) (v & 15)];
  9596. v >>= 4;
  9597. } while (v != 0);
  9598. return String (t, (int) (((char*) end) - (char*) t));
  9599. }
  9600. const String String::toHexString (const short number)
  9601. {
  9602. return toHexString ((int) (unsigned short) number);
  9603. }
  9604. const String String::toHexString (const unsigned char* data,
  9605. const int size,
  9606. const int groupSize)
  9607. {
  9608. if (size <= 0)
  9609. return empty;
  9610. int numChars = (size * 2) + 2;
  9611. if (groupSize > 0)
  9612. numChars += size / groupSize;
  9613. String s ((size_t) numChars, (int) 0);
  9614. juce_wchar* d = s.text;
  9615. for (int i = 0; i < size; ++i)
  9616. {
  9617. *d++ = hexDigits [(*data) >> 4];
  9618. *d++ = hexDigits [(*data) & 0xf];
  9619. ++data;
  9620. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9621. *d++ = ' ';
  9622. }
  9623. *d = 0;
  9624. return s;
  9625. }
  9626. int String::getHexValue32() const throw()
  9627. {
  9628. int result = 0;
  9629. const juce_wchar* c = text;
  9630. for (;;)
  9631. {
  9632. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9633. if (hexValue >= 0)
  9634. result = (result << 4) | hexValue;
  9635. else if (*c == 0)
  9636. break;
  9637. ++c;
  9638. }
  9639. return result;
  9640. }
  9641. int64 String::getHexValue64() const throw()
  9642. {
  9643. int64 result = 0;
  9644. const juce_wchar* c = text;
  9645. for (;;)
  9646. {
  9647. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9648. if (hexValue >= 0)
  9649. result = (result << 4) | hexValue;
  9650. else if (*c == 0)
  9651. break;
  9652. ++c;
  9653. }
  9654. return result;
  9655. }
  9656. const String String::createStringFromData (const void* const data_, const int size)
  9657. {
  9658. const char* const data = (const char*) data_;
  9659. if (size <= 0 || data == 0)
  9660. {
  9661. return empty;
  9662. }
  9663. else if (size < 2)
  9664. {
  9665. return charToString (data[0]);
  9666. }
  9667. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9668. || (data[0] == (char)-1 && data[1] == (char)-2))
  9669. {
  9670. // assume it's 16-bit unicode
  9671. const bool bigEndian = (data[0] == (char)-2);
  9672. const int numChars = size / 2 - 1;
  9673. String result;
  9674. result.preallocateStorage (numChars + 2);
  9675. const uint16* const src = (const uint16*) (data + 2);
  9676. juce_wchar* const dst = const_cast <juce_wchar*> ((const juce_wchar*) result);
  9677. if (bigEndian)
  9678. {
  9679. for (int i = 0; i < numChars; ++i)
  9680. dst[i] = (juce_wchar) ByteOrder::swapIfLittleEndian (src[i]);
  9681. }
  9682. else
  9683. {
  9684. for (int i = 0; i < numChars; ++i)
  9685. dst[i] = (juce_wchar) ByteOrder::swapIfBigEndian (src[i]);
  9686. }
  9687. dst [numChars] = 0;
  9688. return result;
  9689. }
  9690. else
  9691. {
  9692. return String::fromUTF8 (data, size);
  9693. }
  9694. }
  9695. const char* String::toUTF8() const
  9696. {
  9697. if (isEmpty())
  9698. {
  9699. return reinterpret_cast <const char*> (text);
  9700. }
  9701. else
  9702. {
  9703. const int currentLen = length() + 1;
  9704. const int utf8BytesNeeded = getNumBytesAsUTF8();
  9705. String* const mutableThis = const_cast <String*> (this);
  9706. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar));
  9707. char* const otherCopy = reinterpret_cast <char*> (text + currentLen);
  9708. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9709. return otherCopy;
  9710. }
  9711. }
  9712. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9713. {
  9714. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9715. int num = 0, index = 0;
  9716. for (;;)
  9717. {
  9718. const uint32 c = (uint32) text [index++];
  9719. if (c >= 0x80)
  9720. {
  9721. int numExtraBytes = 1;
  9722. if (c >= 0x800)
  9723. {
  9724. ++numExtraBytes;
  9725. if (c >= 0x10000)
  9726. {
  9727. ++numExtraBytes;
  9728. if (c >= 0x200000)
  9729. {
  9730. ++numExtraBytes;
  9731. if (c >= 0x4000000)
  9732. ++numExtraBytes;
  9733. }
  9734. }
  9735. }
  9736. if (buffer != 0)
  9737. {
  9738. if (num + numExtraBytes >= maxBufferSizeBytes)
  9739. {
  9740. buffer [num++] = 0;
  9741. break;
  9742. }
  9743. else
  9744. {
  9745. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9746. while (--numExtraBytes >= 0)
  9747. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9748. }
  9749. }
  9750. else
  9751. {
  9752. num += numExtraBytes + 1;
  9753. }
  9754. }
  9755. else
  9756. {
  9757. if (buffer != 0)
  9758. {
  9759. if (num + 1 >= maxBufferSizeBytes)
  9760. {
  9761. buffer [num++] = 0;
  9762. break;
  9763. }
  9764. buffer [num] = (uint8) c;
  9765. }
  9766. ++num;
  9767. }
  9768. if (c == 0)
  9769. break;
  9770. }
  9771. return num;
  9772. }
  9773. int String::getNumBytesAsUTF8() const throw()
  9774. {
  9775. int num = 0;
  9776. const juce_wchar* t = text;
  9777. for (;;)
  9778. {
  9779. const uint32 c = (uint32) *t;
  9780. if (c >= 0x80)
  9781. {
  9782. ++num;
  9783. if (c >= 0x800)
  9784. {
  9785. ++num;
  9786. if (c >= 0x10000)
  9787. {
  9788. ++num;
  9789. if (c >= 0x200000)
  9790. {
  9791. ++num;
  9792. if (c >= 0x4000000)
  9793. ++num;
  9794. }
  9795. }
  9796. }
  9797. }
  9798. else if (c == 0)
  9799. break;
  9800. ++num;
  9801. ++t;
  9802. }
  9803. return num;
  9804. }
  9805. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9806. {
  9807. if (buffer == 0)
  9808. return empty;
  9809. if (bufferSizeBytes < 0)
  9810. bufferSizeBytes = std::numeric_limits<int>::max();
  9811. size_t numBytes;
  9812. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9813. if (buffer [numBytes] == 0)
  9814. break;
  9815. String result ((size_t) numBytes + 1, (int) 0);
  9816. juce_wchar* dest = result.text;
  9817. size_t i = 0;
  9818. while (i < numBytes)
  9819. {
  9820. const char c = buffer [i++];
  9821. if (c < 0)
  9822. {
  9823. unsigned int mask = 0x7f;
  9824. int bit = 0x40;
  9825. int numExtraValues = 0;
  9826. while (bit != 0 && (c & bit) != 0)
  9827. {
  9828. bit >>= 1;
  9829. mask >>= 1;
  9830. ++numExtraValues;
  9831. }
  9832. int n = (mask & (unsigned char) c);
  9833. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9834. {
  9835. const char nextByte = buffer[i];
  9836. if ((nextByte & 0xc0) != 0x80)
  9837. break;
  9838. n <<= 6;
  9839. n |= (nextByte & 0x3f);
  9840. ++i;
  9841. }
  9842. *dest++ = (juce_wchar) n;
  9843. }
  9844. else
  9845. {
  9846. *dest++ = (juce_wchar) c;
  9847. }
  9848. }
  9849. *dest = 0;
  9850. return result;
  9851. }
  9852. const char* String::toCString() const
  9853. {
  9854. if (isEmpty())
  9855. {
  9856. return reinterpret_cast <const char*> (text);
  9857. }
  9858. else
  9859. {
  9860. const int len = length();
  9861. String* const mutableThis = const_cast <String*> (this);
  9862. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2);
  9863. char* otherCopy = reinterpret_cast <char*> (text + len + 1);
  9864. CharacterFunctions::copy (otherCopy, text, len);
  9865. otherCopy [len] = 0;
  9866. return otherCopy;
  9867. }
  9868. }
  9869. #ifdef _MSC_VER
  9870. #pragma warning (disable: 4514 4996)
  9871. #pragma warning (push)
  9872. #endif
  9873. int String::getNumBytesAsCString() const throw()
  9874. {
  9875. return (int) wcstombs (0, text, 0);
  9876. }
  9877. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  9878. {
  9879. const int numBytes = (int) wcstombs (destBuffer, text, maxBufferSizeBytes);
  9880. if (destBuffer != 0 && numBytes >= 0)
  9881. destBuffer [numBytes] = 0;
  9882. return numBytes;
  9883. }
  9884. #ifdef _MSC_VER
  9885. #pragma warning (pop)
  9886. #endif
  9887. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  9888. {
  9889. StringHolder::copyChars (destBuffer, text, jmin (maxCharsToCopy, length()));
  9890. }
  9891. String::Concatenator::Concatenator (String& stringToAppendTo)
  9892. : result (stringToAppendTo),
  9893. nextIndex (stringToAppendTo.length())
  9894. {
  9895. }
  9896. String::Concatenator::~Concatenator()
  9897. {
  9898. }
  9899. void String::Concatenator::append (const String& s)
  9900. {
  9901. const int len = s.length();
  9902. if (len > 0)
  9903. {
  9904. result.preallocateStorage (nextIndex + len);
  9905. s.copyToUnicode (((juce_wchar*) result) + nextIndex, len);
  9906. nextIndex += len;
  9907. }
  9908. }
  9909. END_JUCE_NAMESPACE
  9910. /*** End of inlined file: juce_String.cpp ***/
  9911. /*** Start of inlined file: juce_StringArray.cpp ***/
  9912. BEGIN_JUCE_NAMESPACE
  9913. StringArray::StringArray() throw()
  9914. {
  9915. }
  9916. StringArray::StringArray (const StringArray& other)
  9917. : strings (other.strings)
  9918. {
  9919. }
  9920. StringArray::StringArray (const String& firstValue)
  9921. {
  9922. strings.add (firstValue);
  9923. }
  9924. StringArray::StringArray (const juce_wchar** const initialStrings,
  9925. const int numberOfStrings)
  9926. {
  9927. for (int i = 0; i < numberOfStrings; ++i)
  9928. strings.add (initialStrings [i]);
  9929. }
  9930. StringArray::StringArray (const char** const initialStrings,
  9931. const int numberOfStrings)
  9932. {
  9933. for (int i = 0; i < numberOfStrings; ++i)
  9934. strings.add (initialStrings [i]);
  9935. }
  9936. StringArray::StringArray (const juce_wchar** const initialStrings)
  9937. {
  9938. int i = 0;
  9939. while (initialStrings[i] != 0)
  9940. strings.add (initialStrings [i++]);
  9941. }
  9942. StringArray::StringArray (const char** const initialStrings)
  9943. {
  9944. int i = 0;
  9945. while (initialStrings[i] != 0)
  9946. strings.add (initialStrings [i++]);
  9947. }
  9948. StringArray& StringArray::operator= (const StringArray& other)
  9949. {
  9950. strings = other.strings;
  9951. return *this;
  9952. }
  9953. StringArray::~StringArray()
  9954. {
  9955. }
  9956. bool StringArray::operator== (const StringArray& other) const throw()
  9957. {
  9958. if (other.size() != size())
  9959. return false;
  9960. for (int i = size(); --i >= 0;)
  9961. if (other.strings.getReference(i) != strings.getReference(i))
  9962. return false;
  9963. return true;
  9964. }
  9965. bool StringArray::operator!= (const StringArray& other) const throw()
  9966. {
  9967. return ! operator== (other);
  9968. }
  9969. void StringArray::clear()
  9970. {
  9971. strings.clear();
  9972. }
  9973. const String& StringArray::operator[] (const int index) const throw()
  9974. {
  9975. if (((unsigned int) index) < (unsigned int) strings.size())
  9976. return strings.getReference (index);
  9977. return String::empty;
  9978. }
  9979. void StringArray::add (const String& newString)
  9980. {
  9981. strings.add (newString);
  9982. }
  9983. void StringArray::insert (const int index, const String& newString)
  9984. {
  9985. strings.insert (index, newString);
  9986. }
  9987. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  9988. {
  9989. if (! contains (newString, ignoreCase))
  9990. add (newString);
  9991. }
  9992. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  9993. {
  9994. if (startIndex < 0)
  9995. {
  9996. jassertfalse
  9997. startIndex = 0;
  9998. }
  9999. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10000. numElementsToAdd = otherArray.size() - startIndex;
  10001. while (--numElementsToAdd >= 0)
  10002. strings.add (otherArray.strings.getReference (startIndex++));
  10003. }
  10004. void StringArray::set (const int index, const String& newString)
  10005. {
  10006. strings.set (index, newString);
  10007. }
  10008. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10009. {
  10010. if (ignoreCase)
  10011. {
  10012. for (int i = size(); --i >= 0;)
  10013. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10014. return true;
  10015. }
  10016. else
  10017. {
  10018. for (int i = size(); --i >= 0;)
  10019. if (stringToLookFor == strings.getReference(i))
  10020. return true;
  10021. }
  10022. return false;
  10023. }
  10024. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10025. {
  10026. if (i < 0)
  10027. i = 0;
  10028. const int numElements = size();
  10029. if (ignoreCase)
  10030. {
  10031. while (i < numElements)
  10032. {
  10033. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10034. return i;
  10035. ++i;
  10036. }
  10037. }
  10038. else
  10039. {
  10040. while (i < numElements)
  10041. {
  10042. if (stringToLookFor == strings.getReference (i))
  10043. return i;
  10044. ++i;
  10045. }
  10046. }
  10047. return -1;
  10048. }
  10049. void StringArray::remove (const int index)
  10050. {
  10051. strings.remove (index);
  10052. }
  10053. void StringArray::removeString (const String& stringToRemove,
  10054. const bool ignoreCase)
  10055. {
  10056. if (ignoreCase)
  10057. {
  10058. for (int i = size(); --i >= 0;)
  10059. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10060. strings.remove (i);
  10061. }
  10062. else
  10063. {
  10064. for (int i = size(); --i >= 0;)
  10065. if (stringToRemove == strings.getReference (i))
  10066. strings.remove (i);
  10067. }
  10068. }
  10069. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10070. {
  10071. if (removeWhitespaceStrings)
  10072. {
  10073. for (int i = size(); --i >= 0;)
  10074. if (! strings.getReference(i).containsNonWhitespaceChars())
  10075. strings.remove (i);
  10076. }
  10077. else
  10078. {
  10079. for (int i = size(); --i >= 0;)
  10080. if (strings.getReference(i).isEmpty())
  10081. strings.remove (i);
  10082. }
  10083. }
  10084. void StringArray::trim()
  10085. {
  10086. for (int i = size(); --i >= 0;)
  10087. {
  10088. String& s = strings.getReference(i);
  10089. s = s.trim();
  10090. }
  10091. }
  10092. class InternalStringArrayComparator_CaseSensitive
  10093. {
  10094. public:
  10095. static int compareElements (String& first, String& second) { return first.compare (second); }
  10096. };
  10097. class InternalStringArrayComparator_CaseInsensitive
  10098. {
  10099. public:
  10100. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10101. };
  10102. void StringArray::sort (const bool ignoreCase)
  10103. {
  10104. if (ignoreCase)
  10105. {
  10106. InternalStringArrayComparator_CaseInsensitive comp;
  10107. strings.sort (comp);
  10108. }
  10109. else
  10110. {
  10111. InternalStringArrayComparator_CaseSensitive comp;
  10112. strings.sort (comp);
  10113. }
  10114. }
  10115. void StringArray::move (const int currentIndex, int newIndex) throw()
  10116. {
  10117. strings.move (currentIndex, newIndex);
  10118. }
  10119. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10120. {
  10121. const int last = (numberToJoin < 0) ? size()
  10122. : jmin (size(), start + numberToJoin);
  10123. if (start < 0)
  10124. start = 0;
  10125. if (start >= last)
  10126. return String::empty;
  10127. if (start == last - 1)
  10128. return strings.getReference (start);
  10129. const int separatorLen = separator.length();
  10130. int charsNeeded = separatorLen * (last - start - 1);
  10131. for (int i = start; i < last; ++i)
  10132. charsNeeded += strings.getReference(i).length();
  10133. String result;
  10134. result.preallocateStorage (charsNeeded);
  10135. juce_wchar* dest = (juce_wchar*) result;
  10136. while (start < last)
  10137. {
  10138. const String& s = strings.getReference (start);
  10139. const int len = s.length();
  10140. if (len > 0)
  10141. {
  10142. s.copyToUnicode (dest, len);
  10143. dest += len;
  10144. }
  10145. if (++start < last && separatorLen > 0)
  10146. {
  10147. separator.copyToUnicode (dest, separatorLen);
  10148. dest += separatorLen;
  10149. }
  10150. }
  10151. *dest = 0;
  10152. return result;
  10153. }
  10154. int StringArray::addTokens (const String& text, const bool preserveQuotedStrings)
  10155. {
  10156. return addTokens (text, " \n\r\t", preserveQuotedStrings ? "\"" : "");
  10157. }
  10158. int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters)
  10159. {
  10160. int num = 0;
  10161. if (text.isNotEmpty())
  10162. {
  10163. bool insideQuotes = false;
  10164. juce_wchar currentQuoteChar = 0;
  10165. int i = 0;
  10166. int tokenStart = 0;
  10167. for (;;)
  10168. {
  10169. const juce_wchar c = text[i];
  10170. const bool isBreak = (c == 0) || ((! insideQuotes) && breakCharacters.containsChar (c));
  10171. if (! isBreak)
  10172. {
  10173. if (quoteCharacters.containsChar (c))
  10174. {
  10175. if (insideQuotes)
  10176. {
  10177. // only break out of quotes-mode if we find a matching quote to the
  10178. // one that we opened with..
  10179. if (currentQuoteChar == c)
  10180. insideQuotes = false;
  10181. }
  10182. else
  10183. {
  10184. insideQuotes = true;
  10185. currentQuoteChar = c;
  10186. }
  10187. }
  10188. }
  10189. else
  10190. {
  10191. add (String (static_cast <const juce_wchar*> (text) + tokenStart, i - tokenStart));
  10192. ++num;
  10193. tokenStart = i + 1;
  10194. }
  10195. if (c == 0)
  10196. break;
  10197. ++i;
  10198. }
  10199. }
  10200. return num;
  10201. }
  10202. int StringArray::addLines (const String& sourceText)
  10203. {
  10204. int numLines = 0;
  10205. const juce_wchar* text = sourceText;
  10206. while (*text != 0)
  10207. {
  10208. const juce_wchar* const startOfLine = text;
  10209. while (*text != 0)
  10210. {
  10211. if (*text == '\r')
  10212. {
  10213. ++text;
  10214. if (*text == '\n')
  10215. ++text;
  10216. break;
  10217. }
  10218. if (*text == '\n')
  10219. {
  10220. ++text;
  10221. break;
  10222. }
  10223. ++text;
  10224. }
  10225. const juce_wchar* endOfLine = text;
  10226. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10227. --endOfLine;
  10228. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10229. --endOfLine;
  10230. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10231. ++numLines;
  10232. }
  10233. return numLines;
  10234. }
  10235. void StringArray::removeDuplicates (const bool ignoreCase)
  10236. {
  10237. for (int i = 0; i < size() - 1; ++i)
  10238. {
  10239. const String s (strings.getReference(i));
  10240. int nextIndex = i + 1;
  10241. for (;;)
  10242. {
  10243. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10244. if (nextIndex < 0)
  10245. break;
  10246. strings.remove (nextIndex);
  10247. }
  10248. }
  10249. }
  10250. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10251. const bool appendNumberToFirstInstance,
  10252. const juce_wchar* preNumberString,
  10253. const juce_wchar* postNumberString)
  10254. {
  10255. if (preNumberString == 0)
  10256. preNumberString = T(" (");
  10257. if (postNumberString == 0)
  10258. postNumberString = T(")");
  10259. for (int i = 0; i < size() - 1; ++i)
  10260. {
  10261. String& s = strings.getReference(i);
  10262. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10263. if (nextIndex >= 0)
  10264. {
  10265. const String original (s);
  10266. int number = 0;
  10267. if (appendNumberToFirstInstance)
  10268. s = original + preNumberString + String (++number) + postNumberString;
  10269. else
  10270. ++number;
  10271. while (nextIndex >= 0)
  10272. {
  10273. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10274. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10275. }
  10276. }
  10277. }
  10278. }
  10279. void StringArray::minimiseStorageOverheads()
  10280. {
  10281. strings.minimiseStorageOverheads();
  10282. }
  10283. END_JUCE_NAMESPACE
  10284. /*** End of inlined file: juce_StringArray.cpp ***/
  10285. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10286. BEGIN_JUCE_NAMESPACE
  10287. StringPairArray::StringPairArray (const bool ignoreCase_)
  10288. : ignoreCase (ignoreCase_)
  10289. {
  10290. }
  10291. StringPairArray::StringPairArray (const StringPairArray& other)
  10292. : keys (other.keys),
  10293. values (other.values),
  10294. ignoreCase (other.ignoreCase)
  10295. {
  10296. }
  10297. StringPairArray::~StringPairArray()
  10298. {
  10299. }
  10300. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  10301. {
  10302. keys = other.keys;
  10303. values = other.values;
  10304. return *this;
  10305. }
  10306. bool StringPairArray::operator== (const StringPairArray& other) const
  10307. {
  10308. for (int i = keys.size(); --i >= 0;)
  10309. if (other [keys[i]] != values[i])
  10310. return false;
  10311. return true;
  10312. }
  10313. bool StringPairArray::operator!= (const StringPairArray& other) const
  10314. {
  10315. return ! operator== (other);
  10316. }
  10317. const String& StringPairArray::operator[] (const String& key) const
  10318. {
  10319. return values [keys.indexOf (key, ignoreCase)];
  10320. }
  10321. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10322. {
  10323. const int i = keys.indexOf (key, ignoreCase);
  10324. if (i >= 0)
  10325. return values[i];
  10326. return defaultReturnValue;
  10327. }
  10328. void StringPairArray::set (const String& key, const String& value)
  10329. {
  10330. const int i = keys.indexOf (key, ignoreCase);
  10331. if (i >= 0)
  10332. {
  10333. values.set (i, value);
  10334. }
  10335. else
  10336. {
  10337. keys.add (key);
  10338. values.add (value);
  10339. }
  10340. }
  10341. void StringPairArray::addArray (const StringPairArray& other)
  10342. {
  10343. for (int i = 0; i < other.size(); ++i)
  10344. set (other.keys[i], other.values[i]);
  10345. }
  10346. void StringPairArray::clear()
  10347. {
  10348. keys.clear();
  10349. values.clear();
  10350. }
  10351. void StringPairArray::remove (const String& key)
  10352. {
  10353. remove (keys.indexOf (key, ignoreCase));
  10354. }
  10355. void StringPairArray::remove (const int index)
  10356. {
  10357. keys.remove (index);
  10358. values.remove (index);
  10359. }
  10360. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  10361. {
  10362. ignoreCase = shouldIgnoreCase;
  10363. }
  10364. const String StringPairArray::getDescription() const
  10365. {
  10366. String s;
  10367. for (int i = 0; i < keys.size(); ++i)
  10368. {
  10369. s << keys[i] << " = " << values[i];
  10370. if (i < keys.size())
  10371. s << ", ";
  10372. }
  10373. return s;
  10374. }
  10375. void StringPairArray::minimiseStorageOverheads()
  10376. {
  10377. keys.minimiseStorageOverheads();
  10378. values.minimiseStorageOverheads();
  10379. }
  10380. END_JUCE_NAMESPACE
  10381. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10382. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10383. BEGIN_JUCE_NAMESPACE
  10384. XmlDocument::XmlDocument (const String& documentText)
  10385. : originalText (documentText),
  10386. ignoreEmptyTextElements (true)
  10387. {
  10388. }
  10389. XmlDocument::XmlDocument (const File& file)
  10390. {
  10391. inputSource = new FileInputSource (file);
  10392. }
  10393. XmlDocument::~XmlDocument()
  10394. {
  10395. }
  10396. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10397. {
  10398. inputSource = newSource;
  10399. }
  10400. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10401. {
  10402. ignoreEmptyTextElements = shouldBeIgnored;
  10403. }
  10404. bool XmlDocument::isXmlIdentifierCharSlow (const juce_wchar c) throw()
  10405. {
  10406. return CharacterFunctions::isLetterOrDigit (c)
  10407. || c == '_' || c == '-' || c == ':' || c == '.';
  10408. }
  10409. inline bool XmlDocument::isXmlIdentifierChar (const juce_wchar c) const throw()
  10410. {
  10411. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10412. : isXmlIdentifierCharSlow (c);
  10413. }
  10414. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10415. {
  10416. String textToParse (originalText);
  10417. if (textToParse.isEmpty() && inputSource != 0)
  10418. {
  10419. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10420. if (in != 0)
  10421. {
  10422. MemoryBlock data;
  10423. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10424. if (data.getSize() >= 2
  10425. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10426. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10427. {
  10428. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10429. }
  10430. else
  10431. {
  10432. textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize());
  10433. }
  10434. if (! onlyReadOuterDocumentElement)
  10435. originalText = textToParse;
  10436. }
  10437. }
  10438. input = textToParse;
  10439. lastError = String::empty;
  10440. errorOccurred = false;
  10441. outOfData = false;
  10442. needToLoadDTD = true;
  10443. for (int i = 0; i < 128; ++i)
  10444. identifierLookupTable[i] = isXmlIdentifierCharSlow ((juce_wchar) i);
  10445. if (textToParse.isEmpty())
  10446. {
  10447. lastError = "not enough input";
  10448. }
  10449. else
  10450. {
  10451. skipHeader();
  10452. if (input != 0)
  10453. {
  10454. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10455. if (! errorOccurred)
  10456. return result.release();
  10457. }
  10458. else
  10459. {
  10460. lastError = "incorrect xml header";
  10461. }
  10462. }
  10463. return 0;
  10464. }
  10465. const String& XmlDocument::getLastParseError() const throw()
  10466. {
  10467. return lastError;
  10468. }
  10469. void XmlDocument::setLastError (const String& desc, const bool carryOn)
  10470. {
  10471. lastError = desc;
  10472. errorOccurred = ! carryOn;
  10473. }
  10474. const String XmlDocument::getFileContents (const String& filename) const
  10475. {
  10476. if (inputSource != 0)
  10477. {
  10478. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10479. if (in != 0)
  10480. return in->readEntireStreamAsString();
  10481. }
  10482. return String::empty;
  10483. }
  10484. juce_wchar XmlDocument::readNextChar() throw()
  10485. {
  10486. if (*input != 0)
  10487. {
  10488. return *input++;
  10489. }
  10490. else
  10491. {
  10492. outOfData = true;
  10493. return 0;
  10494. }
  10495. }
  10496. int XmlDocument::findNextTokenLength() throw()
  10497. {
  10498. int len = 0;
  10499. juce_wchar c = *input;
  10500. while (isXmlIdentifierChar (c))
  10501. c = input [++len];
  10502. return len;
  10503. }
  10504. void XmlDocument::skipHeader()
  10505. {
  10506. const juce_wchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10507. if (found != 0)
  10508. {
  10509. input = found;
  10510. input = CharacterFunctions::find (input, T("?>"));
  10511. if (input == 0)
  10512. return;
  10513. input += 2;
  10514. }
  10515. skipNextWhiteSpace();
  10516. const juce_wchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10517. if (docType == 0)
  10518. return;
  10519. input = docType + 9;
  10520. int n = 1;
  10521. while (n > 0)
  10522. {
  10523. const juce_wchar c = readNextChar();
  10524. if (outOfData)
  10525. return;
  10526. if (c == '<')
  10527. ++n;
  10528. else if (c == '>')
  10529. --n;
  10530. }
  10531. docType += 9;
  10532. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10533. }
  10534. void XmlDocument::skipNextWhiteSpace()
  10535. {
  10536. for (;;)
  10537. {
  10538. juce_wchar c = *input;
  10539. while (CharacterFunctions::isWhitespace (c))
  10540. c = *++input;
  10541. if (c == 0)
  10542. {
  10543. outOfData = true;
  10544. break;
  10545. }
  10546. else if (c == '<')
  10547. {
  10548. if (input[1] == '!'
  10549. && input[2] == '-'
  10550. && input[3] == '-')
  10551. {
  10552. const juce_wchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10553. if (closeComment == 0)
  10554. {
  10555. outOfData = true;
  10556. break;
  10557. }
  10558. input = closeComment + 3;
  10559. continue;
  10560. }
  10561. else if (input[1] == '?')
  10562. {
  10563. const juce_wchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10564. if (closeBracket == 0)
  10565. {
  10566. outOfData = true;
  10567. break;
  10568. }
  10569. input = closeBracket + 2;
  10570. continue;
  10571. }
  10572. }
  10573. break;
  10574. }
  10575. }
  10576. void XmlDocument::readQuotedString (String& result)
  10577. {
  10578. const juce_wchar quote = readNextChar();
  10579. while (! outOfData)
  10580. {
  10581. const juce_wchar c = readNextChar();
  10582. if (c == quote)
  10583. break;
  10584. if (c == '&')
  10585. {
  10586. --input;
  10587. readEntity (result);
  10588. }
  10589. else
  10590. {
  10591. --input;
  10592. const juce_wchar* const start = input;
  10593. for (;;)
  10594. {
  10595. const juce_wchar character = *input;
  10596. if (character == quote)
  10597. {
  10598. result.append (start, (int) (input - start));
  10599. ++input;
  10600. return;
  10601. }
  10602. else if (character == '&')
  10603. {
  10604. result.append (start, (int) (input - start));
  10605. break;
  10606. }
  10607. else if (character == 0)
  10608. {
  10609. outOfData = true;
  10610. setLastError ("unmatched quotes", false);
  10611. break;
  10612. }
  10613. ++input;
  10614. }
  10615. }
  10616. }
  10617. }
  10618. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements)
  10619. {
  10620. XmlElement* node = 0;
  10621. skipNextWhiteSpace();
  10622. if (outOfData)
  10623. return 0;
  10624. input = CharacterFunctions::find (input, T("<"));
  10625. if (input != 0)
  10626. {
  10627. ++input;
  10628. int tagLen = findNextTokenLength();
  10629. if (tagLen == 0)
  10630. {
  10631. // no tag name - but allow for a gap after the '<' before giving an error
  10632. skipNextWhiteSpace();
  10633. tagLen = findNextTokenLength();
  10634. if (tagLen == 0)
  10635. {
  10636. setLastError ("tag name missing", false);
  10637. return node;
  10638. }
  10639. }
  10640. node = new XmlElement (String (input, tagLen));
  10641. input += tagLen;
  10642. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10643. // look for attributes
  10644. for (;;)
  10645. {
  10646. skipNextWhiteSpace();
  10647. const juce_wchar c = *input;
  10648. // empty tag..
  10649. if (c == '/' && input[1] == '>')
  10650. {
  10651. input += 2;
  10652. break;
  10653. }
  10654. // parse the guts of the element..
  10655. if (c == '>')
  10656. {
  10657. ++input;
  10658. skipNextWhiteSpace();
  10659. if (alsoParseSubElements)
  10660. readChildElements (node);
  10661. break;
  10662. }
  10663. // get an attribute..
  10664. if (isXmlIdentifierChar (c))
  10665. {
  10666. const int attNameLen = findNextTokenLength();
  10667. if (attNameLen > 0)
  10668. {
  10669. const juce_wchar* attNameStart = input;
  10670. input += attNameLen;
  10671. skipNextWhiteSpace();
  10672. if (readNextChar() == '=')
  10673. {
  10674. skipNextWhiteSpace();
  10675. const juce_wchar nextChar = *input;
  10676. if (nextChar == '"' || nextChar == '\'')
  10677. {
  10678. XmlElement::XmlAttributeNode* const newAtt
  10679. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10680. String::empty);
  10681. readQuotedString (newAtt->value);
  10682. if (lastAttribute == 0)
  10683. node->attributes = newAtt;
  10684. else
  10685. lastAttribute->next = newAtt;
  10686. lastAttribute = newAtt;
  10687. continue;
  10688. }
  10689. }
  10690. }
  10691. }
  10692. else
  10693. {
  10694. if (! outOfData)
  10695. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10696. }
  10697. break;
  10698. }
  10699. }
  10700. return node;
  10701. }
  10702. void XmlDocument::readChildElements (XmlElement* parent)
  10703. {
  10704. XmlElement* lastChildNode = 0;
  10705. for (;;)
  10706. {
  10707. skipNextWhiteSpace();
  10708. if (outOfData)
  10709. {
  10710. setLastError ("unmatched tags", false);
  10711. break;
  10712. }
  10713. if (*input == '<')
  10714. {
  10715. if (input[1] == '/')
  10716. {
  10717. // our close tag..
  10718. input = CharacterFunctions::find (input, T(">"));
  10719. ++input;
  10720. break;
  10721. }
  10722. else if (input[1] == '!'
  10723. && input[2] == '['
  10724. && input[3] == 'C'
  10725. && input[4] == 'D'
  10726. && input[5] == 'A'
  10727. && input[6] == 'T'
  10728. && input[7] == 'A'
  10729. && input[8] == '[')
  10730. {
  10731. input += 9;
  10732. const juce_wchar* const inputStart = input;
  10733. int len = 0;
  10734. for (;;)
  10735. {
  10736. if (*input == 0)
  10737. {
  10738. setLastError ("unterminated CDATA section", false);
  10739. outOfData = true;
  10740. break;
  10741. }
  10742. else if (input[0] == ']'
  10743. && input[1] == ']'
  10744. && input[2] == '>')
  10745. {
  10746. input += 3;
  10747. break;
  10748. }
  10749. ++input;
  10750. ++len;
  10751. }
  10752. XmlElement* const e = new XmlElement ((int) 0);
  10753. e->setText (String (inputStart, len));
  10754. if (lastChildNode != 0)
  10755. lastChildNode->nextElement = e;
  10756. else
  10757. parent->addChildElement (e);
  10758. lastChildNode = e;
  10759. }
  10760. else
  10761. {
  10762. // this is some other element, so parse and add it..
  10763. XmlElement* const n = readNextElement (true);
  10764. if (n != 0)
  10765. {
  10766. if (lastChildNode == 0)
  10767. parent->addChildElement (n);
  10768. else
  10769. lastChildNode->nextElement = n;
  10770. lastChildNode = n;
  10771. }
  10772. else
  10773. {
  10774. return;
  10775. }
  10776. }
  10777. }
  10778. else
  10779. {
  10780. // read character block..
  10781. XmlElement* const e = new XmlElement ((int)0);
  10782. if (lastChildNode != 0)
  10783. lastChildNode->nextElement = e;
  10784. else
  10785. parent->addChildElement (e);
  10786. lastChildNode = e;
  10787. String textElementContent;
  10788. for (;;)
  10789. {
  10790. const juce_wchar c = *input;
  10791. if (c == '<')
  10792. break;
  10793. if (c == 0)
  10794. {
  10795. setLastError ("unmatched tags", false);
  10796. outOfData = true;
  10797. return;
  10798. }
  10799. if (c == '&')
  10800. {
  10801. String entity;
  10802. readEntity (entity);
  10803. if (entity.startsWithChar ('<') && entity [1] != 0)
  10804. {
  10805. const juce_wchar* const oldInput = input;
  10806. const bool oldOutOfData = outOfData;
  10807. input = entity;
  10808. outOfData = false;
  10809. for (;;)
  10810. {
  10811. XmlElement* const n = readNextElement (true);
  10812. if (n == 0)
  10813. break;
  10814. if (lastChildNode == 0)
  10815. parent->addChildElement (n);
  10816. else
  10817. lastChildNode->nextElement = n;
  10818. lastChildNode = n;
  10819. }
  10820. input = oldInput;
  10821. outOfData = oldOutOfData;
  10822. }
  10823. else
  10824. {
  10825. textElementContent += entity;
  10826. }
  10827. }
  10828. else
  10829. {
  10830. const juce_wchar* start = input;
  10831. int len = 0;
  10832. for (;;)
  10833. {
  10834. const juce_wchar nextChar = *input;
  10835. if (nextChar == '<' || nextChar == '&')
  10836. {
  10837. break;
  10838. }
  10839. else if (nextChar == 0)
  10840. {
  10841. setLastError ("unmatched tags", false);
  10842. outOfData = true;
  10843. return;
  10844. }
  10845. ++input;
  10846. ++len;
  10847. }
  10848. textElementContent.append (start, len);
  10849. }
  10850. }
  10851. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10852. : textElementContent.isNotEmpty())
  10853. e->setText (textElementContent);
  10854. }
  10855. }
  10856. }
  10857. void XmlDocument::readEntity (String& result)
  10858. {
  10859. // skip over the ampersand
  10860. ++input;
  10861. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10862. {
  10863. input += 4;
  10864. result += '&';
  10865. }
  10866. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10867. {
  10868. input += 5;
  10869. result += '"';
  10870. }
  10871. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  10872. {
  10873. input += 5;
  10874. result += '\'';
  10875. }
  10876. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  10877. {
  10878. input += 3;
  10879. result += '<';
  10880. }
  10881. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  10882. {
  10883. input += 3;
  10884. result += '>';
  10885. }
  10886. else if (*input == '#')
  10887. {
  10888. int charCode = 0;
  10889. ++input;
  10890. if (*input == 'x' || *input == 'X')
  10891. {
  10892. ++input;
  10893. int numChars = 0;
  10894. while (input[0] != ';')
  10895. {
  10896. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  10897. if (hexValue < 0 || ++numChars > 8)
  10898. {
  10899. setLastError ("illegal escape sequence", true);
  10900. break;
  10901. }
  10902. charCode = (charCode << 4) | hexValue;
  10903. ++input;
  10904. }
  10905. ++input;
  10906. }
  10907. else if (input[0] >= '0' && input[0] <= '9')
  10908. {
  10909. int numChars = 0;
  10910. while (input[0] != ';')
  10911. {
  10912. if (++numChars > 12)
  10913. {
  10914. setLastError ("illegal escape sequence", true);
  10915. break;
  10916. }
  10917. charCode = charCode * 10 + (input[0] - '0');
  10918. ++input;
  10919. }
  10920. ++input;
  10921. }
  10922. else
  10923. {
  10924. setLastError ("illegal escape sequence", true);
  10925. result += '&';
  10926. return;
  10927. }
  10928. result << (juce_wchar) charCode;
  10929. }
  10930. else
  10931. {
  10932. const juce_wchar* const entityNameStart = input;
  10933. const juce_wchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  10934. if (closingSemiColon == 0)
  10935. {
  10936. outOfData = true;
  10937. result += '&';
  10938. }
  10939. else
  10940. {
  10941. input = closingSemiColon + 1;
  10942. result += expandExternalEntity (String (entityNameStart,
  10943. (int) (closingSemiColon - entityNameStart)));
  10944. }
  10945. }
  10946. }
  10947. const String XmlDocument::expandEntity (const String& ent)
  10948. {
  10949. if (ent.equalsIgnoreCase ("amp"))
  10950. return String::charToString ('&');
  10951. if (ent.equalsIgnoreCase ("quot"))
  10952. return String::charToString ('"');
  10953. if (ent.equalsIgnoreCase ("apos"))
  10954. return String::charToString ('\'');
  10955. if (ent.equalsIgnoreCase ("lt"))
  10956. return String::charToString ('<');
  10957. if (ent.equalsIgnoreCase ("gt"))
  10958. return String::charToString ('>');
  10959. if (ent[0] == '#')
  10960. {
  10961. if (ent[1] == 'x' || ent[1] == 'X')
  10962. return String::charToString (static_cast <juce_wchar> (ent.substring (2).getHexValue32()));
  10963. if (ent[1] >= '0' && ent[1] <= '9')
  10964. return String::charToString (static_cast <juce_wchar> (ent.substring (1).getIntValue()));
  10965. setLastError ("illegal escape sequence", false);
  10966. return String::charToString ('&');
  10967. }
  10968. return expandExternalEntity (ent);
  10969. }
  10970. const String XmlDocument::expandExternalEntity (const String& entity)
  10971. {
  10972. if (needToLoadDTD)
  10973. {
  10974. if (dtdText.isNotEmpty())
  10975. {
  10976. while (dtdText.endsWithChar ('>'))
  10977. dtdText = dtdText.dropLastCharacters (1);
  10978. tokenisedDTD.addTokens (dtdText, true);
  10979. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase ("system")
  10980. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  10981. {
  10982. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  10983. tokenisedDTD.clear();
  10984. tokenisedDTD.addTokens (getFileContents (fn), true);
  10985. }
  10986. else
  10987. {
  10988. tokenisedDTD.clear();
  10989. const int openBracket = dtdText.indexOfChar ('[');
  10990. if (openBracket > 0)
  10991. {
  10992. const int closeBracket = dtdText.lastIndexOfChar (']');
  10993. if (closeBracket > openBracket)
  10994. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  10995. closeBracket), true);
  10996. }
  10997. }
  10998. for (int i = tokenisedDTD.size(); --i >= 0;)
  10999. {
  11000. if (tokenisedDTD[i].startsWithChar ('%')
  11001. && tokenisedDTD[i].endsWithChar (';'))
  11002. {
  11003. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11004. StringArray newToks;
  11005. newToks.addTokens (parsed, true);
  11006. tokenisedDTD.remove (i);
  11007. for (int j = newToks.size(); --j >= 0;)
  11008. tokenisedDTD.insert (i, newToks[j]);
  11009. }
  11010. }
  11011. }
  11012. needToLoadDTD = false;
  11013. }
  11014. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11015. {
  11016. if (tokenisedDTD[i] == entity)
  11017. {
  11018. if (tokenisedDTD[i - 1].equalsIgnoreCase ("<!entity"))
  11019. {
  11020. String ent (tokenisedDTD [i + 1]);
  11021. while (ent.endsWithChar ('>'))
  11022. ent = ent.dropLastCharacters (1);
  11023. ent = ent.trim().unquoted();
  11024. // check for sub-entities..
  11025. int ampersand = ent.indexOfChar ('&');
  11026. while (ampersand >= 0)
  11027. {
  11028. const int semiColon = ent.indexOf (i + 1, ";");
  11029. if (semiColon < 0)
  11030. {
  11031. setLastError ("entity without terminating semi-colon", false);
  11032. break;
  11033. }
  11034. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11035. ent = ent.substring (0, ampersand)
  11036. + resolved
  11037. + ent.substring (semiColon + 1);
  11038. ampersand = ent.indexOfChar (semiColon + 1, '&');
  11039. }
  11040. return ent;
  11041. }
  11042. }
  11043. }
  11044. setLastError ("unknown entity", true);
  11045. return entity;
  11046. }
  11047. const String XmlDocument::getParameterEntity (const String& entity)
  11048. {
  11049. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11050. {
  11051. if (tokenisedDTD[i] == entity)
  11052. {
  11053. if (tokenisedDTD [i - 1] == "%"
  11054. && tokenisedDTD [i - 2].equalsIgnoreCase ("<!entity"))
  11055. {
  11056. String ent (tokenisedDTD [i + 1]);
  11057. while (ent.endsWithChar ('>'))
  11058. ent = ent.dropLastCharacters (1);
  11059. if (ent.equalsIgnoreCase ("system"))
  11060. {
  11061. String filename (tokenisedDTD [i + 2]);
  11062. while (filename.endsWithChar ('>'))
  11063. filename = filename.dropLastCharacters (1);
  11064. return getFileContents (filename);
  11065. }
  11066. else
  11067. {
  11068. return ent.trim().unquoted();
  11069. }
  11070. }
  11071. }
  11072. }
  11073. return entity;
  11074. }
  11075. END_JUCE_NAMESPACE
  11076. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11077. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11078. BEGIN_JUCE_NAMESPACE
  11079. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11080. : name (other.name),
  11081. value (other.value),
  11082. next (0)
  11083. {
  11084. }
  11085. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_, const String& value_) throw()
  11086. : name (name_),
  11087. value (value_),
  11088. next (0)
  11089. {
  11090. }
  11091. XmlElement::XmlElement (const String& tagName_) throw()
  11092. : tagName (tagName_),
  11093. firstChildElement (0),
  11094. nextElement (0),
  11095. attributes (0)
  11096. {
  11097. // the tag name mustn't be empty, or it'll look like a text element!
  11098. jassert (tagName_.containsNonWhitespaceChars())
  11099. // The tag can't contain spaces or other characters that would create invalid XML!
  11100. jassert (! tagName_.containsAnyOf (" <>/&"));
  11101. }
  11102. XmlElement::XmlElement (int /*dummy*/) throw()
  11103. : firstChildElement (0),
  11104. nextElement (0),
  11105. attributes (0)
  11106. {
  11107. }
  11108. XmlElement::XmlElement (const XmlElement& other) throw()
  11109. : tagName (other.tagName),
  11110. firstChildElement (0),
  11111. nextElement (0),
  11112. attributes (0)
  11113. {
  11114. copyChildrenAndAttributesFrom (other);
  11115. }
  11116. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11117. {
  11118. if (this != &other)
  11119. {
  11120. removeAllAttributes();
  11121. deleteAllChildElements();
  11122. tagName = other.tagName;
  11123. copyChildrenAndAttributesFrom (other);
  11124. }
  11125. return *this;
  11126. }
  11127. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11128. {
  11129. XmlElement* child = other.firstChildElement;
  11130. XmlElement* lastChild = 0;
  11131. while (child != 0)
  11132. {
  11133. XmlElement* const copiedChild = new XmlElement (*child);
  11134. if (lastChild != 0)
  11135. lastChild->nextElement = copiedChild;
  11136. else
  11137. firstChildElement = copiedChild;
  11138. lastChild = copiedChild;
  11139. child = child->nextElement;
  11140. }
  11141. const XmlAttributeNode* att = other.attributes;
  11142. XmlAttributeNode* lastAtt = 0;
  11143. while (att != 0)
  11144. {
  11145. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11146. if (lastAtt != 0)
  11147. lastAtt->next = newAtt;
  11148. else
  11149. attributes = newAtt;
  11150. lastAtt = newAtt;
  11151. att = att->next;
  11152. }
  11153. }
  11154. XmlElement::~XmlElement() throw()
  11155. {
  11156. XmlElement* child = firstChildElement;
  11157. while (child != 0)
  11158. {
  11159. XmlElement* const nextChild = child->nextElement;
  11160. delete child;
  11161. child = nextChild;
  11162. }
  11163. XmlAttributeNode* att = attributes;
  11164. while (att != 0)
  11165. {
  11166. XmlAttributeNode* const nextAtt = att->next;
  11167. delete att;
  11168. att = nextAtt;
  11169. }
  11170. }
  11171. namespace XmlOutputFunctions
  11172. {
  11173. static bool isLegalXmlChar (const uint32 c) throw()
  11174. {
  11175. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11176. return c < sizeof (legalChars) * 8
  11177. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11178. }
  11179. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11180. {
  11181. const juce_wchar* t = (const juce_wchar*) text;
  11182. for (;;)
  11183. {
  11184. const juce_wchar character = *t++;
  11185. if (character == 0)
  11186. {
  11187. break;
  11188. }
  11189. else if (isLegalXmlChar ((uint32) character))
  11190. {
  11191. outputStream << (char) character;
  11192. }
  11193. else
  11194. {
  11195. switch (character)
  11196. {
  11197. case '&': outputStream << "&amp;"; break;
  11198. case '"': outputStream << "&quot;"; break;
  11199. case '>': outputStream << "&gt;"; break;
  11200. case '<': outputStream << "&lt;"; break;
  11201. case '\n':
  11202. if (changeNewLines)
  11203. outputStream << "&#10;";
  11204. else
  11205. outputStream << (char) character;
  11206. break;
  11207. case '\r':
  11208. if (changeNewLines)
  11209. outputStream << "&#13;";
  11210. else
  11211. outputStream << (char) character;
  11212. break;
  11213. default:
  11214. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11215. break;
  11216. }
  11217. }
  11218. }
  11219. }
  11220. static void writeSpaces (OutputStream& out, int numSpaces)
  11221. {
  11222. if (numSpaces > 0)
  11223. {
  11224. const char* const blanks = " ";
  11225. const int blankSize = (int) sizeof (blanks) - 1;
  11226. while (numSpaces > blankSize)
  11227. {
  11228. out.write (blanks, blankSize);
  11229. numSpaces -= blankSize;
  11230. }
  11231. out.write (blanks, numSpaces);
  11232. }
  11233. }
  11234. }
  11235. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11236. const int indentationLevel,
  11237. const int lineWrapLength) const
  11238. {
  11239. using namespace XmlOutputFunctions;
  11240. writeSpaces (outputStream, indentationLevel);
  11241. if (! isTextElement())
  11242. {
  11243. outputStream.writeByte ('<');
  11244. outputStream << tagName;
  11245. const int attIndent = indentationLevel + tagName.length() + 1;
  11246. int lineLen = 0;
  11247. const XmlAttributeNode* att = attributes;
  11248. while (att != 0)
  11249. {
  11250. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11251. {
  11252. outputStream.write ("\r\n", 2);
  11253. writeSpaces (outputStream, attIndent);
  11254. lineLen = 0;
  11255. }
  11256. const int64 startPos = outputStream.getPosition();
  11257. outputStream.writeByte (' ');
  11258. outputStream << att->name;
  11259. outputStream.write ("=\"", 2);
  11260. escapeIllegalXmlChars (outputStream, att->value, true);
  11261. outputStream.writeByte ('"');
  11262. lineLen += (int) (outputStream.getPosition() - startPos);
  11263. att = att->next;
  11264. }
  11265. if (firstChildElement != 0)
  11266. {
  11267. XmlElement* child = firstChildElement;
  11268. if (child->nextElement == 0 && child->isTextElement())
  11269. {
  11270. outputStream.writeByte ('>');
  11271. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11272. }
  11273. else
  11274. {
  11275. if (indentationLevel >= 0)
  11276. outputStream.write (">\r\n", 3);
  11277. else
  11278. outputStream.writeByte ('>');
  11279. bool lastWasTextNode = false;
  11280. while (child != 0)
  11281. {
  11282. if (child->isTextElement())
  11283. {
  11284. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11285. writeSpaces (outputStream, indentationLevel + 2);
  11286. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11287. lastWasTextNode = true;
  11288. }
  11289. else
  11290. {
  11291. if (indentationLevel >= 0)
  11292. {
  11293. if (lastWasTextNode)
  11294. outputStream.write ("\r\n", 2);
  11295. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11296. }
  11297. else
  11298. {
  11299. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11300. }
  11301. lastWasTextNode = false;
  11302. }
  11303. child = child->nextElement;
  11304. }
  11305. if (indentationLevel >= 0)
  11306. {
  11307. if (lastWasTextNode)
  11308. outputStream.write ("\r\n", 2);
  11309. writeSpaces (outputStream, indentationLevel);
  11310. }
  11311. }
  11312. outputStream.write ("</", 2);
  11313. outputStream << tagName;
  11314. if (indentationLevel >= 0)
  11315. outputStream.write (">\r\n", 3);
  11316. else
  11317. outputStream.writeByte ('>');
  11318. }
  11319. else
  11320. {
  11321. if (indentationLevel >= 0)
  11322. outputStream.write ("/>\r\n", 4);
  11323. else
  11324. outputStream.write ("/>", 2);
  11325. }
  11326. }
  11327. else
  11328. {
  11329. if (indentationLevel >= 0)
  11330. writeSpaces (outputStream, indentationLevel + 2);
  11331. escapeIllegalXmlChars (outputStream, getText(), false);
  11332. }
  11333. }
  11334. const String XmlElement::createDocument (const String& dtdToUse,
  11335. const bool allOnOneLine,
  11336. const bool includeXmlHeader,
  11337. const String& encodingType,
  11338. const int lineWrapLength) const
  11339. {
  11340. MemoryOutputStream mem (2048, 4096);
  11341. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11342. return mem.toUTF8();
  11343. }
  11344. void XmlElement::writeToStream (OutputStream& output,
  11345. const String& dtdToUse,
  11346. const bool allOnOneLine,
  11347. const bool includeXmlHeader,
  11348. const String& encodingType,
  11349. const int lineWrapLength) const
  11350. {
  11351. if (includeXmlHeader)
  11352. output << "<?xml version=\"1.0\" encoding=\"" << encodingType
  11353. << (allOnOneLine ? "\"?> " : "\"?>\r\n\r\n");
  11354. if (dtdToUse.isNotEmpty())
  11355. output << dtdToUse << (allOnOneLine ? " " : "\r\n");
  11356. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11357. }
  11358. bool XmlElement::writeToFile (const File& file,
  11359. const String& dtdToUse,
  11360. const String& encodingType,
  11361. const int lineWrapLength) const
  11362. {
  11363. if (file.hasWriteAccess())
  11364. {
  11365. TemporaryFile tempFile (file);
  11366. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11367. if (out != 0)
  11368. {
  11369. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11370. out = 0;
  11371. return tempFile.overwriteTargetFileWithTemporary();
  11372. }
  11373. }
  11374. return false;
  11375. }
  11376. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11377. {
  11378. #ifdef JUCE_DEBUG
  11379. // if debugging, check that the case is actually the same, because
  11380. // valid xml is case-sensitive, and although this lets it pass, it's
  11381. // better not to..
  11382. if (tagName.equalsIgnoreCase (tagNameWanted))
  11383. {
  11384. jassert (tagName == tagNameWanted);
  11385. return true;
  11386. }
  11387. else
  11388. {
  11389. return false;
  11390. }
  11391. #else
  11392. return tagName.equalsIgnoreCase (tagNameWanted);
  11393. #endif
  11394. }
  11395. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11396. {
  11397. XmlElement* e = nextElement;
  11398. while (e != 0 && ! e->hasTagName (requiredTagName))
  11399. e = e->nextElement;
  11400. return e;
  11401. }
  11402. int XmlElement::getNumAttributes() const throw()
  11403. {
  11404. const XmlAttributeNode* att = attributes;
  11405. int count = 0;
  11406. while (att != 0)
  11407. {
  11408. att = att->next;
  11409. ++count;
  11410. }
  11411. return count;
  11412. }
  11413. const String& XmlElement::getAttributeName (const int index) const throw()
  11414. {
  11415. const XmlAttributeNode* att = attributes;
  11416. int count = 0;
  11417. while (att != 0)
  11418. {
  11419. if (count == index)
  11420. return att->name;
  11421. att = att->next;
  11422. ++count;
  11423. }
  11424. return String::empty;
  11425. }
  11426. const String& XmlElement::getAttributeValue (const int index) const throw()
  11427. {
  11428. const XmlAttributeNode* att = attributes;
  11429. int count = 0;
  11430. while (att != 0)
  11431. {
  11432. if (count == index)
  11433. return att->value;
  11434. att = att->next;
  11435. ++count;
  11436. }
  11437. return String::empty;
  11438. }
  11439. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11440. {
  11441. const XmlAttributeNode* att = attributes;
  11442. while (att != 0)
  11443. {
  11444. if (att->name.equalsIgnoreCase (attributeName))
  11445. return true;
  11446. att = att->next;
  11447. }
  11448. return false;
  11449. }
  11450. const String& XmlElement::getStringAttribute (const String& attributeName) const throw()
  11451. {
  11452. const XmlAttributeNode* att = attributes;
  11453. while (att != 0)
  11454. {
  11455. if (att->name.equalsIgnoreCase (attributeName))
  11456. return att->value;
  11457. att = att->next;
  11458. }
  11459. return String::empty;
  11460. }
  11461. const String XmlElement::getStringAttribute (const String& attributeName, const String& defaultReturnValue) const
  11462. {
  11463. const XmlAttributeNode* att = attributes;
  11464. while (att != 0)
  11465. {
  11466. if (att->name.equalsIgnoreCase (attributeName))
  11467. return att->value;
  11468. att = att->next;
  11469. }
  11470. return defaultReturnValue;
  11471. }
  11472. int XmlElement::getIntAttribute (const String& attributeName, const int defaultReturnValue) const
  11473. {
  11474. const XmlAttributeNode* att = attributes;
  11475. while (att != 0)
  11476. {
  11477. if (att->name.equalsIgnoreCase (attributeName))
  11478. return att->value.getIntValue();
  11479. att = att->next;
  11480. }
  11481. return defaultReturnValue;
  11482. }
  11483. double XmlElement::getDoubleAttribute (const String& attributeName, const double defaultReturnValue) const
  11484. {
  11485. const XmlAttributeNode* att = attributes;
  11486. while (att != 0)
  11487. {
  11488. if (att->name.equalsIgnoreCase (attributeName))
  11489. return att->value.getDoubleValue();
  11490. att = att->next;
  11491. }
  11492. return defaultReturnValue;
  11493. }
  11494. bool XmlElement::getBoolAttribute (const String& attributeName, const bool defaultReturnValue) const
  11495. {
  11496. const XmlAttributeNode* att = attributes;
  11497. while (att != 0)
  11498. {
  11499. if (att->name.equalsIgnoreCase (attributeName))
  11500. {
  11501. juce_wchar firstChar = att->value[0];
  11502. if (CharacterFunctions::isWhitespace (firstChar))
  11503. firstChar = att->value.trimStart() [0];
  11504. return firstChar == '1'
  11505. || firstChar == 't'
  11506. || firstChar == 'y'
  11507. || firstChar == 'T'
  11508. || firstChar == 'Y';
  11509. }
  11510. att = att->next;
  11511. }
  11512. return defaultReturnValue;
  11513. }
  11514. bool XmlElement::compareAttribute (const String& attributeName,
  11515. const String& stringToCompareAgainst,
  11516. const bool ignoreCase) const throw()
  11517. {
  11518. const XmlAttributeNode* att = attributes;
  11519. while (att != 0)
  11520. {
  11521. if (att->name.equalsIgnoreCase (attributeName))
  11522. {
  11523. if (ignoreCase)
  11524. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11525. else
  11526. return att->value == stringToCompareAgainst;
  11527. }
  11528. att = att->next;
  11529. }
  11530. return false;
  11531. }
  11532. void XmlElement::setAttribute (const String& attributeName, const String& value)
  11533. {
  11534. #ifdef JUCE_DEBUG
  11535. // check the identifier being passed in is legal..
  11536. const juce_wchar* t = attributeName;
  11537. while (*t != 0)
  11538. {
  11539. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11540. || *t == '_'
  11541. || *t == '-'
  11542. || *t == ':');
  11543. ++t;
  11544. }
  11545. #endif
  11546. if (attributes == 0)
  11547. {
  11548. attributes = new XmlAttributeNode (attributeName, value);
  11549. }
  11550. else
  11551. {
  11552. XmlAttributeNode* att = attributes;
  11553. for (;;)
  11554. {
  11555. if (att->name.equalsIgnoreCase (attributeName))
  11556. {
  11557. att->value = value;
  11558. break;
  11559. }
  11560. else if (att->next == 0)
  11561. {
  11562. att->next = new XmlAttributeNode (attributeName, value);
  11563. break;
  11564. }
  11565. att = att->next;
  11566. }
  11567. }
  11568. }
  11569. void XmlElement::setAttribute (const String& attributeName, const int number)
  11570. {
  11571. setAttribute (attributeName, String (number));
  11572. }
  11573. void XmlElement::setAttribute (const String& attributeName, const double number)
  11574. {
  11575. setAttribute (attributeName, String (number));
  11576. }
  11577. void XmlElement::removeAttribute (const String& attributeName) throw()
  11578. {
  11579. XmlAttributeNode* att = attributes;
  11580. XmlAttributeNode* lastAtt = 0;
  11581. while (att != 0)
  11582. {
  11583. if (att->name.equalsIgnoreCase (attributeName))
  11584. {
  11585. if (lastAtt == 0)
  11586. attributes = att->next;
  11587. else
  11588. lastAtt->next = att->next;
  11589. delete att;
  11590. break;
  11591. }
  11592. lastAtt = att;
  11593. att = att->next;
  11594. }
  11595. }
  11596. void XmlElement::removeAllAttributes() throw()
  11597. {
  11598. while (attributes != 0)
  11599. {
  11600. XmlAttributeNode* const nextAtt = attributes->next;
  11601. delete attributes;
  11602. attributes = nextAtt;
  11603. }
  11604. }
  11605. int XmlElement::getNumChildElements() const throw()
  11606. {
  11607. int count = 0;
  11608. const XmlElement* child = firstChildElement;
  11609. while (child != 0)
  11610. {
  11611. ++count;
  11612. child = child->nextElement;
  11613. }
  11614. return count;
  11615. }
  11616. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11617. {
  11618. int count = 0;
  11619. XmlElement* child = firstChildElement;
  11620. while (child != 0 && count < index)
  11621. {
  11622. child = child->nextElement;
  11623. ++count;
  11624. }
  11625. return child;
  11626. }
  11627. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11628. {
  11629. XmlElement* child = firstChildElement;
  11630. while (child != 0)
  11631. {
  11632. if (child->hasTagName (childName))
  11633. break;
  11634. child = child->nextElement;
  11635. }
  11636. return child;
  11637. }
  11638. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11639. {
  11640. if (newNode != 0)
  11641. {
  11642. if (firstChildElement == 0)
  11643. {
  11644. firstChildElement = newNode;
  11645. }
  11646. else
  11647. {
  11648. XmlElement* child = firstChildElement;
  11649. while (child->nextElement != 0)
  11650. child = child->nextElement;
  11651. child->nextElement = newNode;
  11652. // if this is non-zero, then something's probably
  11653. // gone wrong..
  11654. jassert (newNode->nextElement == 0);
  11655. }
  11656. }
  11657. }
  11658. void XmlElement::insertChildElement (XmlElement* const newNode,
  11659. int indexToInsertAt) throw()
  11660. {
  11661. if (newNode != 0)
  11662. {
  11663. removeChildElement (newNode, false);
  11664. if (indexToInsertAt == 0)
  11665. {
  11666. newNode->nextElement = firstChildElement;
  11667. firstChildElement = newNode;
  11668. }
  11669. else
  11670. {
  11671. if (firstChildElement == 0)
  11672. {
  11673. firstChildElement = newNode;
  11674. }
  11675. else
  11676. {
  11677. if (indexToInsertAt < 0)
  11678. indexToInsertAt = std::numeric_limits<int>::max();
  11679. XmlElement* child = firstChildElement;
  11680. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11681. child = child->nextElement;
  11682. newNode->nextElement = child->nextElement;
  11683. child->nextElement = newNode;
  11684. }
  11685. }
  11686. }
  11687. }
  11688. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11689. {
  11690. XmlElement* const newElement = new XmlElement (tagName);
  11691. addChildElement (newElement);
  11692. return newElement;
  11693. }
  11694. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11695. XmlElement* const newNode) throw()
  11696. {
  11697. if (newNode != 0)
  11698. {
  11699. XmlElement* child = firstChildElement;
  11700. XmlElement* previousNode = 0;
  11701. while (child != 0)
  11702. {
  11703. if (child == currentChildElement)
  11704. {
  11705. if (child != newNode)
  11706. {
  11707. if (previousNode == 0)
  11708. firstChildElement = newNode;
  11709. else
  11710. previousNode->nextElement = newNode;
  11711. newNode->nextElement = child->nextElement;
  11712. delete child;
  11713. }
  11714. return true;
  11715. }
  11716. previousNode = child;
  11717. child = child->nextElement;
  11718. }
  11719. }
  11720. return false;
  11721. }
  11722. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11723. const bool shouldDeleteTheChild) throw()
  11724. {
  11725. if (childToRemove != 0)
  11726. {
  11727. if (firstChildElement == childToRemove)
  11728. {
  11729. firstChildElement = childToRemove->nextElement;
  11730. childToRemove->nextElement = 0;
  11731. }
  11732. else
  11733. {
  11734. XmlElement* child = firstChildElement;
  11735. XmlElement* last = 0;
  11736. while (child != 0)
  11737. {
  11738. if (child == childToRemove)
  11739. {
  11740. if (last == 0)
  11741. firstChildElement = child->nextElement;
  11742. else
  11743. last->nextElement = child->nextElement;
  11744. childToRemove->nextElement = 0;
  11745. break;
  11746. }
  11747. last = child;
  11748. child = child->nextElement;
  11749. }
  11750. }
  11751. if (shouldDeleteTheChild)
  11752. delete childToRemove;
  11753. }
  11754. }
  11755. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11756. const bool ignoreOrderOfAttributes) const throw()
  11757. {
  11758. if (this != other)
  11759. {
  11760. if (other == 0 || tagName != other->tagName)
  11761. {
  11762. return false;
  11763. }
  11764. if (ignoreOrderOfAttributes)
  11765. {
  11766. int totalAtts = 0;
  11767. const XmlAttributeNode* att = attributes;
  11768. while (att != 0)
  11769. {
  11770. if (! other->compareAttribute (att->name, att->value))
  11771. return false;
  11772. att = att->next;
  11773. ++totalAtts;
  11774. }
  11775. if (totalAtts != other->getNumAttributes())
  11776. return false;
  11777. }
  11778. else
  11779. {
  11780. const XmlAttributeNode* thisAtt = attributes;
  11781. const XmlAttributeNode* otherAtt = other->attributes;
  11782. for (;;)
  11783. {
  11784. if (thisAtt == 0 || otherAtt == 0)
  11785. {
  11786. if (thisAtt == otherAtt) // both 0, so it's a match
  11787. break;
  11788. return false;
  11789. }
  11790. if (thisAtt->name != otherAtt->name
  11791. || thisAtt->value != otherAtt->value)
  11792. {
  11793. return false;
  11794. }
  11795. thisAtt = thisAtt->next;
  11796. otherAtt = otherAtt->next;
  11797. }
  11798. }
  11799. const XmlElement* thisChild = firstChildElement;
  11800. const XmlElement* otherChild = other->firstChildElement;
  11801. for (;;)
  11802. {
  11803. if (thisChild == 0 || otherChild == 0)
  11804. {
  11805. if (thisChild == otherChild) // both 0, so it's a match
  11806. break;
  11807. return false;
  11808. }
  11809. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11810. return false;
  11811. thisChild = thisChild->nextElement;
  11812. otherChild = otherChild->nextElement;
  11813. }
  11814. }
  11815. return true;
  11816. }
  11817. void XmlElement::deleteAllChildElements() throw()
  11818. {
  11819. while (firstChildElement != 0)
  11820. {
  11821. XmlElement* const nextChild = firstChildElement->nextElement;
  11822. delete firstChildElement;
  11823. firstChildElement = nextChild;
  11824. }
  11825. }
  11826. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  11827. {
  11828. XmlElement* child = firstChildElement;
  11829. while (child != 0)
  11830. {
  11831. if (child->hasTagName (name))
  11832. {
  11833. XmlElement* const nextChild = child->nextElement;
  11834. removeChildElement (child, true);
  11835. child = nextChild;
  11836. }
  11837. else
  11838. {
  11839. child = child->nextElement;
  11840. }
  11841. }
  11842. }
  11843. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  11844. {
  11845. const XmlElement* child = firstChildElement;
  11846. while (child != 0)
  11847. {
  11848. if (child == possibleChild)
  11849. return true;
  11850. child = child->nextElement;
  11851. }
  11852. return false;
  11853. }
  11854. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  11855. {
  11856. if (this == elementToLookFor || elementToLookFor == 0)
  11857. return 0;
  11858. XmlElement* child = firstChildElement;
  11859. while (child != 0)
  11860. {
  11861. if (elementToLookFor == child)
  11862. return this;
  11863. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  11864. if (found != 0)
  11865. return found;
  11866. child = child->nextElement;
  11867. }
  11868. return 0;
  11869. }
  11870. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  11871. {
  11872. XmlElement* e = firstChildElement;
  11873. while (e != 0)
  11874. {
  11875. *elems++ = e;
  11876. e = e->nextElement;
  11877. }
  11878. }
  11879. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  11880. {
  11881. XmlElement* e = firstChildElement = elems[0];
  11882. for (int i = 1; i < num; ++i)
  11883. {
  11884. e->nextElement = elems[i];
  11885. e = e->nextElement;
  11886. }
  11887. e->nextElement = 0;
  11888. }
  11889. bool XmlElement::isTextElement() const throw()
  11890. {
  11891. return tagName.isEmpty();
  11892. }
  11893. static const juce_wchar* const juce_xmltextContentAttributeName = T("text");
  11894. const String XmlElement::getText() const throw()
  11895. {
  11896. jassert (isTextElement()); // you're trying to get the text from an element that
  11897. // isn't actually a text element.. If this contains text sub-nodes, you
  11898. // probably want to use getAllSubText instead.
  11899. return getStringAttribute (juce_xmltextContentAttributeName);
  11900. }
  11901. void XmlElement::setText (const String& newText) throw()
  11902. {
  11903. if (isTextElement())
  11904. {
  11905. setAttribute (juce_xmltextContentAttributeName, newText);
  11906. }
  11907. else
  11908. {
  11909. jassertfalse // you can only change the text in a text element, not a normal one.
  11910. }
  11911. }
  11912. const String XmlElement::getAllSubText() const throw()
  11913. {
  11914. String result;
  11915. String::Concatenator concatenator (result);
  11916. const XmlElement* child = firstChildElement;
  11917. while (child != 0)
  11918. {
  11919. if (child->isTextElement())
  11920. concatenator.append (child->getText());
  11921. child = child->nextElement;
  11922. }
  11923. return result;
  11924. }
  11925. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  11926. const String& defaultReturnValue) const throw()
  11927. {
  11928. const XmlElement* const child = getChildByName (childTagName);
  11929. if (child != 0)
  11930. return child->getAllSubText();
  11931. return defaultReturnValue;
  11932. }
  11933. XmlElement* XmlElement::createTextElement (const String& text) throw()
  11934. {
  11935. XmlElement* const e = new XmlElement ((int) 0);
  11936. e->setAttribute (juce_xmltextContentAttributeName, text);
  11937. return e;
  11938. }
  11939. void XmlElement::addTextElement (const String& text) throw()
  11940. {
  11941. addChildElement (createTextElement (text));
  11942. }
  11943. void XmlElement::deleteAllTextElements() throw()
  11944. {
  11945. XmlElement* child = firstChildElement;
  11946. while (child != 0)
  11947. {
  11948. XmlElement* const next = child->nextElement;
  11949. if (child->isTextElement())
  11950. removeChildElement (child, true);
  11951. child = next;
  11952. }
  11953. }
  11954. END_JUCE_NAMESPACE
  11955. /*** End of inlined file: juce_XmlElement.cpp ***/
  11956. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  11957. BEGIN_JUCE_NAMESPACE
  11958. ReadWriteLock::ReadWriteLock() throw()
  11959. : numWaitingWriters (0),
  11960. numWriters (0),
  11961. writerThreadId (0)
  11962. {
  11963. }
  11964. ReadWriteLock::~ReadWriteLock() throw()
  11965. {
  11966. jassert (readerThreads.size() == 0);
  11967. jassert (numWriters == 0);
  11968. }
  11969. void ReadWriteLock::enterRead() const throw()
  11970. {
  11971. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11972. const ScopedLock sl (accessLock);
  11973. for (;;)
  11974. {
  11975. jassert (readerThreads.size() % 2 == 0);
  11976. int i;
  11977. for (i = 0; i < readerThreads.size(); i += 2)
  11978. if (readerThreads.getUnchecked(i) == threadId)
  11979. break;
  11980. if (i < readerThreads.size()
  11981. || numWriters + numWaitingWriters == 0
  11982. || (threadId == writerThreadId && numWriters > 0))
  11983. {
  11984. if (i < readerThreads.size())
  11985. {
  11986. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  11987. }
  11988. else
  11989. {
  11990. readerThreads.add (threadId);
  11991. readerThreads.add ((Thread::ThreadID) 1);
  11992. }
  11993. return;
  11994. }
  11995. const ScopedUnlock ul (accessLock);
  11996. waitEvent.wait (100);
  11997. }
  11998. }
  11999. void ReadWriteLock::exitRead() const throw()
  12000. {
  12001. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12002. const ScopedLock sl (accessLock);
  12003. for (int i = 0; i < readerThreads.size(); i += 2)
  12004. {
  12005. if (readerThreads.getUnchecked(i) == threadId)
  12006. {
  12007. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12008. if (newCount == 0)
  12009. {
  12010. readerThreads.removeRange (i, 2);
  12011. waitEvent.signal();
  12012. }
  12013. else
  12014. {
  12015. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12016. }
  12017. return;
  12018. }
  12019. }
  12020. jassertfalse // unlocking a lock that wasn't locked..
  12021. }
  12022. void ReadWriteLock::enterWrite() const throw()
  12023. {
  12024. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12025. const ScopedLock sl (accessLock);
  12026. for (;;)
  12027. {
  12028. if (readerThreads.size() + numWriters == 0
  12029. || threadId == writerThreadId
  12030. || (readerThreads.size() == 2
  12031. && readerThreads.getUnchecked(0) == threadId))
  12032. {
  12033. writerThreadId = threadId;
  12034. ++numWriters;
  12035. break;
  12036. }
  12037. ++numWaitingWriters;
  12038. accessLock.exit();
  12039. waitEvent.wait (100);
  12040. accessLock.enter();
  12041. --numWaitingWriters;
  12042. }
  12043. }
  12044. bool ReadWriteLock::tryEnterWrite() const throw()
  12045. {
  12046. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12047. const ScopedLock sl (accessLock);
  12048. if (readerThreads.size() + numWriters == 0
  12049. || threadId == writerThreadId
  12050. || (readerThreads.size() == 2
  12051. && readerThreads.getUnchecked(0) == threadId))
  12052. {
  12053. writerThreadId = threadId;
  12054. ++numWriters;
  12055. return true;
  12056. }
  12057. return false;
  12058. }
  12059. void ReadWriteLock::exitWrite() const throw()
  12060. {
  12061. const ScopedLock sl (accessLock);
  12062. // check this thread actually had the lock..
  12063. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12064. if (--numWriters == 0)
  12065. {
  12066. writerThreadId = 0;
  12067. waitEvent.signal();
  12068. }
  12069. }
  12070. END_JUCE_NAMESPACE
  12071. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12072. /*** Start of inlined file: juce_Thread.cpp ***/
  12073. BEGIN_JUCE_NAMESPACE
  12074. // these functions are implemented in the platform-specific code.
  12075. void* juce_createThread (void* userData);
  12076. void juce_killThread (void* handle);
  12077. bool juce_setThreadPriority (void* handle, int priority);
  12078. void juce_setCurrentThreadName (const String& name);
  12079. #if JUCE_WIN32
  12080. void juce_CloseThreadHandle (void* handle);
  12081. #endif
  12082. void Thread::threadEntryPoint (Thread* const thread)
  12083. {
  12084. {
  12085. const ScopedLock sl (runningThreadsLock);
  12086. runningThreads.add (thread);
  12087. }
  12088. JUCE_TRY
  12089. {
  12090. thread->threadId_ = Thread::getCurrentThreadId();
  12091. if (thread->threadName_.isNotEmpty())
  12092. juce_setCurrentThreadName (thread->threadName_);
  12093. if (thread->startSuspensionEvent_.wait (10000))
  12094. {
  12095. if (thread->affinityMask_ != 0)
  12096. setCurrentThreadAffinityMask (thread->affinityMask_);
  12097. thread->run();
  12098. }
  12099. }
  12100. JUCE_CATCH_ALL_ASSERT
  12101. {
  12102. const ScopedLock sl (runningThreadsLock);
  12103. jassert (runningThreads.contains (thread));
  12104. runningThreads.removeValue (thread);
  12105. }
  12106. #if JUCE_WIN32
  12107. juce_CloseThreadHandle (thread->threadHandle_);
  12108. #endif
  12109. thread->threadHandle_ = 0;
  12110. thread->threadId_ = 0;
  12111. }
  12112. // used to wrap the incoming call from the platform-specific code
  12113. void JUCE_API juce_threadEntryPoint (void* userData)
  12114. {
  12115. Thread::threadEntryPoint ((Thread*) userData);
  12116. }
  12117. Thread::Thread (const String& threadName)
  12118. : threadName_ (threadName),
  12119. threadHandle_ (0),
  12120. threadPriority_ (5),
  12121. threadId_ (0),
  12122. affinityMask_ (0),
  12123. threadShouldExit_ (false)
  12124. {
  12125. }
  12126. Thread::~Thread()
  12127. {
  12128. stopThread (100);
  12129. }
  12130. void Thread::startThread()
  12131. {
  12132. const ScopedLock sl (startStopLock);
  12133. threadShouldExit_ = false;
  12134. if (threadHandle_ == 0)
  12135. {
  12136. threadHandle_ = juce_createThread ((void*) this);
  12137. juce_setThreadPriority (threadHandle_, threadPriority_);
  12138. startSuspensionEvent_.signal();
  12139. }
  12140. }
  12141. void Thread::startThread (const int priority)
  12142. {
  12143. const ScopedLock sl (startStopLock);
  12144. if (threadHandle_ == 0)
  12145. {
  12146. threadPriority_ = priority;
  12147. startThread();
  12148. }
  12149. else
  12150. {
  12151. setPriority (priority);
  12152. }
  12153. }
  12154. bool Thread::isThreadRunning() const
  12155. {
  12156. return threadHandle_ != 0;
  12157. }
  12158. void Thread::signalThreadShouldExit()
  12159. {
  12160. threadShouldExit_ = true;
  12161. }
  12162. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12163. {
  12164. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12165. jassert (getThreadId() != getCurrentThreadId());
  12166. const int sleepMsPerIteration = 5;
  12167. int count = timeOutMilliseconds / sleepMsPerIteration;
  12168. while (isThreadRunning())
  12169. {
  12170. if (timeOutMilliseconds > 0 && --count < 0)
  12171. return false;
  12172. sleep (sleepMsPerIteration);
  12173. }
  12174. return true;
  12175. }
  12176. void Thread::stopThread (const int timeOutMilliseconds)
  12177. {
  12178. // agh! You can't stop the thread that's calling this method! How on earth
  12179. // would that work??
  12180. jassert (getCurrentThreadId() != getThreadId());
  12181. const ScopedLock sl (startStopLock);
  12182. if (isThreadRunning())
  12183. {
  12184. signalThreadShouldExit();
  12185. notify();
  12186. if (timeOutMilliseconds != 0)
  12187. waitForThreadToExit (timeOutMilliseconds);
  12188. if (isThreadRunning())
  12189. {
  12190. // very bad karma if this point is reached, as
  12191. // there are bound to be locks and events left in
  12192. // silly states when a thread is killed by force..
  12193. jassertfalse
  12194. Logger::writeToLog ("!! killing thread by force !!");
  12195. juce_killThread (threadHandle_);
  12196. threadHandle_ = 0;
  12197. threadId_ = 0;
  12198. const ScopedLock sl2 (runningThreadsLock);
  12199. runningThreads.removeValue (this);
  12200. }
  12201. }
  12202. }
  12203. bool Thread::setPriority (const int priority)
  12204. {
  12205. const ScopedLock sl (startStopLock);
  12206. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12207. if (worked)
  12208. threadPriority_ = priority;
  12209. return worked;
  12210. }
  12211. bool Thread::setCurrentThreadPriority (const int priority)
  12212. {
  12213. return juce_setThreadPriority (0, priority);
  12214. }
  12215. void Thread::setAffinityMask (const uint32 affinityMask)
  12216. {
  12217. affinityMask_ = affinityMask;
  12218. }
  12219. bool Thread::wait (const int timeOutMilliseconds) const
  12220. {
  12221. return defaultEvent_.wait (timeOutMilliseconds);
  12222. }
  12223. void Thread::notify() const
  12224. {
  12225. defaultEvent_.signal();
  12226. }
  12227. int Thread::getNumRunningThreads()
  12228. {
  12229. return runningThreads.size();
  12230. }
  12231. Thread* Thread::getCurrentThread()
  12232. {
  12233. const ThreadID thisId = getCurrentThreadId();
  12234. const ScopedLock sl (runningThreadsLock);
  12235. for (int i = runningThreads.size(); --i >= 0;)
  12236. {
  12237. Thread* const t = runningThreads.getUnchecked(i);
  12238. if (t->threadId_ == thisId)
  12239. return t;
  12240. }
  12241. return 0;
  12242. }
  12243. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12244. {
  12245. {
  12246. const ScopedLock sl (runningThreadsLock);
  12247. for (int i = runningThreads.size(); --i >= 0;)
  12248. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12249. }
  12250. for (;;)
  12251. {
  12252. Thread* firstThread;
  12253. {
  12254. const ScopedLock sl (runningThreadsLock);
  12255. firstThread = runningThreads.getFirst();
  12256. }
  12257. if (firstThread == 0)
  12258. break;
  12259. firstThread->stopThread (timeOutMilliseconds);
  12260. }
  12261. }
  12262. Array<Thread*> Thread::runningThreads;
  12263. CriticalSection Thread::runningThreadsLock;
  12264. END_JUCE_NAMESPACE
  12265. /*** End of inlined file: juce_Thread.cpp ***/
  12266. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12267. BEGIN_JUCE_NAMESPACE
  12268. ThreadPoolJob::ThreadPoolJob (const String& name)
  12269. : jobName (name),
  12270. pool (0),
  12271. shouldStop (false),
  12272. isActive (false),
  12273. shouldBeDeleted (false)
  12274. {
  12275. }
  12276. ThreadPoolJob::~ThreadPoolJob()
  12277. {
  12278. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12279. // to remove it first!
  12280. jassert (pool == 0 || ! pool->contains (this));
  12281. }
  12282. const String ThreadPoolJob::getJobName() const
  12283. {
  12284. return jobName;
  12285. }
  12286. void ThreadPoolJob::setJobName (const String& newName)
  12287. {
  12288. jobName = newName;
  12289. }
  12290. void ThreadPoolJob::signalJobShouldExit()
  12291. {
  12292. shouldStop = true;
  12293. }
  12294. class ThreadPool::ThreadPoolThread : public Thread
  12295. {
  12296. public:
  12297. ThreadPoolThread (ThreadPool& pool_)
  12298. : Thread ("Pool"),
  12299. pool (pool_),
  12300. busy (false)
  12301. {
  12302. }
  12303. ~ThreadPoolThread()
  12304. {
  12305. }
  12306. void run()
  12307. {
  12308. while (! threadShouldExit())
  12309. {
  12310. if (! pool.runNextJob())
  12311. wait (500);
  12312. }
  12313. }
  12314. private:
  12315. ThreadPool& pool;
  12316. bool volatile busy;
  12317. ThreadPoolThread (const ThreadPoolThread&);
  12318. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12319. };
  12320. ThreadPool::ThreadPool (const int numThreads,
  12321. const bool startThreadsOnlyWhenNeeded,
  12322. const int stopThreadsWhenNotUsedTimeoutMs)
  12323. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12324. priority (5)
  12325. {
  12326. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12327. for (int i = jmax (1, numThreads); --i >= 0;)
  12328. threads.add (new ThreadPoolThread (*this));
  12329. if (! startThreadsOnlyWhenNeeded)
  12330. for (int i = threads.size(); --i >= 0;)
  12331. threads.getUnchecked(i)->startThread (priority);
  12332. }
  12333. ThreadPool::~ThreadPool()
  12334. {
  12335. removeAllJobs (true, 4000);
  12336. int i;
  12337. for (i = threads.size(); --i >= 0;)
  12338. threads.getUnchecked(i)->signalThreadShouldExit();
  12339. for (i = threads.size(); --i >= 0;)
  12340. threads.getUnchecked(i)->stopThread (500);
  12341. }
  12342. void ThreadPool::addJob (ThreadPoolJob* const job)
  12343. {
  12344. jassert (job != 0);
  12345. jassert (job->pool == 0);
  12346. if (job->pool == 0)
  12347. {
  12348. job->pool = this;
  12349. job->shouldStop = false;
  12350. job->isActive = false;
  12351. {
  12352. const ScopedLock sl (lock);
  12353. jobs.add (job);
  12354. int numRunning = 0;
  12355. for (int i = threads.size(); --i >= 0;)
  12356. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12357. ++numRunning;
  12358. if (numRunning < threads.size())
  12359. {
  12360. bool startedOne = false;
  12361. int n = 1000;
  12362. while (--n >= 0 && ! startedOne)
  12363. {
  12364. for (int i = threads.size(); --i >= 0;)
  12365. {
  12366. if (! threads.getUnchecked(i)->isThreadRunning())
  12367. {
  12368. threads.getUnchecked(i)->startThread (priority);
  12369. startedOne = true;
  12370. break;
  12371. }
  12372. }
  12373. if (! startedOne)
  12374. Thread::sleep (2);
  12375. }
  12376. }
  12377. }
  12378. for (int i = threads.size(); --i >= 0;)
  12379. threads.getUnchecked(i)->notify();
  12380. }
  12381. }
  12382. int ThreadPool::getNumJobs() const
  12383. {
  12384. return jobs.size();
  12385. }
  12386. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12387. {
  12388. const ScopedLock sl (lock);
  12389. return (ThreadPoolJob*) jobs [index];
  12390. }
  12391. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12392. {
  12393. const ScopedLock sl (lock);
  12394. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12395. }
  12396. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12397. {
  12398. const ScopedLock sl (lock);
  12399. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12400. }
  12401. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12402. const int timeOutMs) const
  12403. {
  12404. if (job != 0)
  12405. {
  12406. const uint32 start = Time::getMillisecondCounter();
  12407. while (contains (job))
  12408. {
  12409. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12410. return false;
  12411. jobFinishedSignal.wait (2);
  12412. }
  12413. }
  12414. return true;
  12415. }
  12416. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12417. const bool interruptIfRunning,
  12418. const int timeOutMs)
  12419. {
  12420. bool dontWait = true;
  12421. if (job != 0)
  12422. {
  12423. const ScopedLock sl (lock);
  12424. if (jobs.contains (job))
  12425. {
  12426. if (job->isActive)
  12427. {
  12428. if (interruptIfRunning)
  12429. job->signalJobShouldExit();
  12430. dontWait = false;
  12431. }
  12432. else
  12433. {
  12434. jobs.removeValue (job);
  12435. }
  12436. }
  12437. }
  12438. return dontWait || waitForJobToFinish (job, timeOutMs);
  12439. }
  12440. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12441. const int timeOutMs,
  12442. const bool deleteInactiveJobs,
  12443. ThreadPool::JobSelector* selectedJobsToRemove)
  12444. {
  12445. Array <ThreadPoolJob*> jobsToWaitFor;
  12446. {
  12447. const ScopedLock sl (lock);
  12448. for (int i = jobs.size(); --i >= 0;)
  12449. {
  12450. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12451. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12452. {
  12453. if (job->isActive)
  12454. {
  12455. jobsToWaitFor.add (job);
  12456. if (interruptRunningJobs)
  12457. job->signalJobShouldExit();
  12458. }
  12459. else
  12460. {
  12461. jobs.remove (i);
  12462. if (deleteInactiveJobs)
  12463. delete job;
  12464. }
  12465. }
  12466. }
  12467. }
  12468. const uint32 start = Time::getMillisecondCounter();
  12469. for (;;)
  12470. {
  12471. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12472. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12473. jobsToWaitFor.remove (i);
  12474. if (jobsToWaitFor.size() == 0)
  12475. break;
  12476. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12477. return false;
  12478. jobFinishedSignal.wait (20);
  12479. }
  12480. return true;
  12481. }
  12482. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12483. {
  12484. StringArray s;
  12485. const ScopedLock sl (lock);
  12486. for (int i = 0; i < jobs.size(); ++i)
  12487. {
  12488. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12489. if (job->isActive || ! onlyReturnActiveJobs)
  12490. s.add (job->getJobName());
  12491. }
  12492. return s;
  12493. }
  12494. bool ThreadPool::setThreadPriorities (const int newPriority)
  12495. {
  12496. bool ok = true;
  12497. if (priority != newPriority)
  12498. {
  12499. priority = newPriority;
  12500. for (int i = threads.size(); --i >= 0;)
  12501. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12502. ok = false;
  12503. }
  12504. return ok;
  12505. }
  12506. bool ThreadPool::runNextJob()
  12507. {
  12508. ThreadPoolJob* job = 0;
  12509. {
  12510. const ScopedLock sl (lock);
  12511. for (int i = 0; i < jobs.size(); ++i)
  12512. {
  12513. job = jobs[i];
  12514. if (job != 0 && ! (job->isActive || job->shouldStop))
  12515. break;
  12516. job = 0;
  12517. }
  12518. if (job != 0)
  12519. job->isActive = true;
  12520. }
  12521. if (job != 0)
  12522. {
  12523. JUCE_TRY
  12524. {
  12525. ThreadPoolJob::JobStatus result = job->runJob();
  12526. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12527. const ScopedLock sl (lock);
  12528. if (jobs.contains (job))
  12529. {
  12530. job->isActive = false;
  12531. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12532. {
  12533. job->pool = 0;
  12534. job->shouldStop = true;
  12535. jobs.removeValue (job);
  12536. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12537. delete job;
  12538. jobFinishedSignal.signal();
  12539. }
  12540. else
  12541. {
  12542. // move the job to the end of the queue if it wants another go
  12543. jobs.move (jobs.indexOf (job), -1);
  12544. }
  12545. }
  12546. }
  12547. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12548. catch (...)
  12549. {
  12550. const ScopedLock sl (lock);
  12551. jobs.removeValue (job);
  12552. }
  12553. #endif
  12554. }
  12555. else
  12556. {
  12557. if (threadStopTimeout > 0
  12558. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12559. {
  12560. const ScopedLock sl (lock);
  12561. if (jobs.size() == 0)
  12562. for (int i = threads.size(); --i >= 0;)
  12563. threads.getUnchecked(i)->signalThreadShouldExit();
  12564. }
  12565. else
  12566. {
  12567. return false;
  12568. }
  12569. }
  12570. return true;
  12571. }
  12572. END_JUCE_NAMESPACE
  12573. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12574. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12575. BEGIN_JUCE_NAMESPACE
  12576. TimeSliceThread::TimeSliceThread (const String& threadName)
  12577. : Thread (threadName),
  12578. index (0),
  12579. clientBeingCalled (0),
  12580. clientsChanged (false)
  12581. {
  12582. }
  12583. TimeSliceThread::~TimeSliceThread()
  12584. {
  12585. stopThread (2000);
  12586. }
  12587. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12588. {
  12589. const ScopedLock sl (listLock);
  12590. clients.addIfNotAlreadyThere (client);
  12591. clientsChanged = true;
  12592. notify();
  12593. }
  12594. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12595. {
  12596. const ScopedLock sl1 (listLock);
  12597. clientsChanged = true;
  12598. // if there's a chance we're in the middle of calling this client, we need to
  12599. // also lock the outer lock..
  12600. if (clientBeingCalled == client)
  12601. {
  12602. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12603. const ScopedLock sl2 (callbackLock);
  12604. const ScopedLock sl3 (listLock);
  12605. clients.removeValue (client);
  12606. }
  12607. else
  12608. {
  12609. clients.removeValue (client);
  12610. }
  12611. }
  12612. int TimeSliceThread::getNumClients() const
  12613. {
  12614. return clients.size();
  12615. }
  12616. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12617. {
  12618. const ScopedLock sl (listLock);
  12619. return clients [i];
  12620. }
  12621. void TimeSliceThread::run()
  12622. {
  12623. int numCallsSinceBusy = 0;
  12624. while (! threadShouldExit())
  12625. {
  12626. int timeToWait = 500;
  12627. {
  12628. const ScopedLock sl (callbackLock);
  12629. {
  12630. const ScopedLock sl2 (listLock);
  12631. if (clients.size() > 0)
  12632. {
  12633. index = (index + 1) % clients.size();
  12634. clientBeingCalled = clients [index];
  12635. }
  12636. else
  12637. {
  12638. index = 0;
  12639. clientBeingCalled = 0;
  12640. }
  12641. if (clientsChanged)
  12642. {
  12643. clientsChanged = false;
  12644. numCallsSinceBusy = 0;
  12645. }
  12646. }
  12647. if (clientBeingCalled != 0)
  12648. {
  12649. if (clientBeingCalled->useTimeSlice())
  12650. numCallsSinceBusy = 0;
  12651. else
  12652. ++numCallsSinceBusy;
  12653. if (numCallsSinceBusy >= clients.size())
  12654. timeToWait = 500;
  12655. else if (index == 0)
  12656. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12657. else
  12658. timeToWait = 0;
  12659. }
  12660. }
  12661. if (timeToWait > 0)
  12662. wait (timeToWait);
  12663. }
  12664. }
  12665. END_JUCE_NAMESPACE
  12666. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12667. #endif
  12668. #if JUCE_BUILD_MISC
  12669. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12670. BEGIN_JUCE_NAMESPACE
  12671. class ValueTreeSetPropertyAction : public UndoableAction
  12672. {
  12673. public:
  12674. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12675. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12676. : target (target_), name (name_), newValue (newValue_),
  12677. isAddingNewProperty (isAddingNewProperty_),
  12678. isDeletingProperty (isDeletingProperty_)
  12679. {
  12680. if (! isAddingNewProperty)
  12681. oldValue = target_->getProperty (name_);
  12682. }
  12683. ~ValueTreeSetPropertyAction() {}
  12684. bool perform()
  12685. {
  12686. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12687. if (isDeletingProperty)
  12688. target->removeProperty (name, 0);
  12689. else
  12690. target->setProperty (name, newValue, 0);
  12691. return true;
  12692. }
  12693. bool undo()
  12694. {
  12695. if (isAddingNewProperty)
  12696. target->removeProperty (name, 0);
  12697. else
  12698. target->setProperty (name, oldValue, 0);
  12699. return true;
  12700. }
  12701. int getSizeInUnits()
  12702. {
  12703. return (int) sizeof (*this); //xxx should be more accurate
  12704. }
  12705. private:
  12706. const ValueTree::SharedObjectPtr target;
  12707. const var::identifier name;
  12708. const var newValue;
  12709. var oldValue;
  12710. const bool isAddingNewProperty, isDeletingProperty;
  12711. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12712. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12713. };
  12714. class ValueTreeChildChangeAction : public UndoableAction
  12715. {
  12716. public:
  12717. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12718. const ValueTree::SharedObjectPtr& newChild_)
  12719. : target (target_),
  12720. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12721. childIndex (childIndex_),
  12722. isDeleting (newChild_ == 0)
  12723. {
  12724. jassert (child != 0);
  12725. }
  12726. ~ValueTreeChildChangeAction() {}
  12727. bool perform()
  12728. {
  12729. if (isDeleting)
  12730. target->removeChild (childIndex, 0);
  12731. else
  12732. target->addChild (child, childIndex, 0);
  12733. return true;
  12734. }
  12735. bool undo()
  12736. {
  12737. if (isDeleting)
  12738. target->addChild (child, childIndex, 0);
  12739. else
  12740. target->removeChild (childIndex, 0);
  12741. return true;
  12742. }
  12743. int getSizeInUnits()
  12744. {
  12745. return (int) sizeof (*this); //xxx should be more accurate
  12746. }
  12747. private:
  12748. const ValueTree::SharedObjectPtr target, child;
  12749. const int childIndex;
  12750. const bool isDeleting;
  12751. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12752. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12753. };
  12754. ValueTree::SharedObject::SharedObject (const String& type_)
  12755. : type (type_), parent (0)
  12756. {
  12757. }
  12758. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12759. : type (other.type), properties (other.properties), parent (0)
  12760. {
  12761. for (int i = 0; i < other.children.size(); ++i)
  12762. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12763. }
  12764. ValueTree::SharedObject::~SharedObject()
  12765. {
  12766. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12767. for (int i = children.size(); --i >= 0;)
  12768. {
  12769. const SharedObjectPtr c (children.getUnchecked(i));
  12770. c->parent = 0;
  12771. children.remove (i);
  12772. c->sendParentChangeMessage();
  12773. }
  12774. }
  12775. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12776. {
  12777. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12778. {
  12779. ValueTree* const v = valueTreesWithListeners[i];
  12780. if (v != 0)
  12781. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12782. }
  12783. }
  12784. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12785. {
  12786. ValueTree tree (this);
  12787. ValueTree::SharedObject* t = this;
  12788. while (t != 0)
  12789. {
  12790. t->sendPropertyChangeMessage (tree, property);
  12791. t = t->parent;
  12792. }
  12793. }
  12794. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12795. {
  12796. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12797. {
  12798. ValueTree* const v = valueTreesWithListeners[i];
  12799. if (v != 0)
  12800. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12801. }
  12802. }
  12803. void ValueTree::SharedObject::sendChildChangeMessage()
  12804. {
  12805. ValueTree tree (this);
  12806. ValueTree::SharedObject* t = this;
  12807. while (t != 0)
  12808. {
  12809. t->sendChildChangeMessage (tree);
  12810. t = t->parent;
  12811. }
  12812. }
  12813. void ValueTree::SharedObject::sendParentChangeMessage()
  12814. {
  12815. ValueTree tree (this);
  12816. int i;
  12817. for (i = children.size(); --i >= 0;)
  12818. {
  12819. SharedObject* const t = children[i];
  12820. if (t != 0)
  12821. t->sendParentChangeMessage();
  12822. }
  12823. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12824. {
  12825. ValueTree* const v = valueTreesWithListeners[i];
  12826. if (v != 0)
  12827. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12828. }
  12829. }
  12830. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12831. {
  12832. return properties [name];
  12833. }
  12834. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12835. {
  12836. if (undoManager == 0)
  12837. {
  12838. if (properties.set (name, newValue))
  12839. sendPropertyChangeMessage (name);
  12840. }
  12841. else
  12842. {
  12843. var* const existingValue = properties.getItem (name);
  12844. if (existingValue != 0)
  12845. {
  12846. if (*existingValue != newValue)
  12847. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  12848. }
  12849. else
  12850. {
  12851. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  12852. }
  12853. }
  12854. }
  12855. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  12856. {
  12857. return properties.contains (name);
  12858. }
  12859. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12860. {
  12861. if (undoManager == 0)
  12862. {
  12863. if (properties.remove (name))
  12864. sendPropertyChangeMessage (name);
  12865. }
  12866. else
  12867. {
  12868. if (properties.contains (name))
  12869. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  12870. }
  12871. }
  12872. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  12873. {
  12874. if (undoManager == 0)
  12875. {
  12876. while (properties.size() > 0)
  12877. {
  12878. const var::identifier name (properties.getName (properties.size() - 1));
  12879. properties.remove (name);
  12880. sendPropertyChangeMessage (name);
  12881. }
  12882. }
  12883. else
  12884. {
  12885. for (int i = properties.size(); --i >= 0;)
  12886. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  12887. }
  12888. }
  12889. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  12890. {
  12891. for (int i = 0; i < children.size(); ++i)
  12892. if (children.getUnchecked(i)->type == typeToMatch)
  12893. return (SharedObject*) children.getUnchecked(i);
  12894. return (SharedObject*) 0;
  12895. }
  12896. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12897. {
  12898. for (int i = 0; i < children.size(); ++i)
  12899. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  12900. return (SharedObject*) children.getUnchecked(i);
  12901. return (SharedObject*) 0;
  12902. }
  12903. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  12904. {
  12905. const SharedObject* p = parent;
  12906. while (p != 0)
  12907. {
  12908. if (p == possibleParent)
  12909. return true;
  12910. p = p->parent;
  12911. }
  12912. return false;
  12913. }
  12914. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  12915. {
  12916. if (child != 0 && child->parent != this)
  12917. {
  12918. if (child != this && ! isAChildOf (child))
  12919. {
  12920. // You should always make sure that a child is removed from its previous parent before
  12921. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  12922. // undomanager should be used when removing it from its current parent..
  12923. jassert (child->parent == 0);
  12924. if (child->parent != 0)
  12925. {
  12926. jassert (child->parent->children.indexOf (child) >= 0);
  12927. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  12928. }
  12929. if (undoManager == 0)
  12930. {
  12931. children.insert (index, child);
  12932. child->parent = this;
  12933. sendChildChangeMessage();
  12934. child->sendParentChangeMessage();
  12935. }
  12936. else
  12937. {
  12938. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  12939. }
  12940. }
  12941. else
  12942. {
  12943. // You're attempting to create a recursive loop! A node
  12944. // can't be a child of one of its own children!
  12945. jassertfalse
  12946. }
  12947. }
  12948. }
  12949. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  12950. {
  12951. const SharedObjectPtr child (children [childIndex]);
  12952. if (child != 0)
  12953. {
  12954. if (undoManager == 0)
  12955. {
  12956. children.remove (childIndex);
  12957. child->parent = 0;
  12958. sendChildChangeMessage();
  12959. child->sendParentChangeMessage();
  12960. }
  12961. else
  12962. {
  12963. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  12964. }
  12965. }
  12966. }
  12967. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  12968. {
  12969. while (children.size() > 0)
  12970. removeChild (children.size() - 1, undoManager);
  12971. }
  12972. ValueTree::ValueTree (const String& type_)
  12973. : object (new ValueTree::SharedObject (type_))
  12974. {
  12975. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  12976. }
  12977. ValueTree::ValueTree (SharedObject* const object_)
  12978. : object (object_)
  12979. {
  12980. }
  12981. ValueTree::ValueTree (const ValueTree& other)
  12982. : object (other.object)
  12983. {
  12984. }
  12985. ValueTree& ValueTree::operator= (const ValueTree& other)
  12986. {
  12987. if (listeners.size() > 0)
  12988. {
  12989. if (object != 0)
  12990. object->valueTreesWithListeners.removeValue (this);
  12991. if (other.object != 0)
  12992. other.object->valueTreesWithListeners.add (this);
  12993. }
  12994. object = other.object;
  12995. return *this;
  12996. }
  12997. ValueTree::~ValueTree()
  12998. {
  12999. if (listeners.size() > 0 && object != 0)
  13000. object->valueTreesWithListeners.removeValue (this);
  13001. }
  13002. bool ValueTree::operator== (const ValueTree& other) const
  13003. {
  13004. return object == other.object;
  13005. }
  13006. bool ValueTree::operator!= (const ValueTree& other) const
  13007. {
  13008. return object != other.object;
  13009. }
  13010. ValueTree ValueTree::createCopy() const
  13011. {
  13012. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13013. }
  13014. bool ValueTree::hasType (const String& typeName) const
  13015. {
  13016. return object != 0 && object->type == typeName;
  13017. }
  13018. const String ValueTree::getType() const
  13019. {
  13020. return object != 0 ? object->type : String::empty;
  13021. }
  13022. ValueTree ValueTree::getParent() const
  13023. {
  13024. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13025. }
  13026. const var& ValueTree::operator[] (const var::identifier& name) const
  13027. {
  13028. return object == 0 ? var::null : object->getProperty (name);
  13029. }
  13030. const var& ValueTree::getProperty (const var::identifier& name) const
  13031. {
  13032. return object == 0 ? var::null : object->getProperty (name);
  13033. }
  13034. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13035. {
  13036. jassert (name.name.isNotEmpty());
  13037. if (object != 0 && name.name.isNotEmpty())
  13038. object->setProperty (name, newValue, undoManager);
  13039. }
  13040. bool ValueTree::hasProperty (const var::identifier& name) const
  13041. {
  13042. return object != 0 && object->hasProperty (name);
  13043. }
  13044. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13045. {
  13046. if (object != 0)
  13047. object->removeProperty (name, undoManager);
  13048. }
  13049. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13050. {
  13051. if (object != 0)
  13052. object->removeAllProperties (undoManager);
  13053. }
  13054. int ValueTree::getNumProperties() const
  13055. {
  13056. return object == 0 ? 0 : object->properties.size();
  13057. }
  13058. const var::identifier ValueTree::getPropertyName (int index) const
  13059. {
  13060. return (object == 0) ? var::identifier()
  13061. : object->properties.getName (index);
  13062. }
  13063. class ValueTreePropertyValueSource : public Value::ValueSource,
  13064. public ValueTree::Listener
  13065. {
  13066. public:
  13067. ValueTreePropertyValueSource (const ValueTree& tree_,
  13068. const var::identifier& property_,
  13069. UndoManager* const undoManager_)
  13070. : tree (tree_),
  13071. property (property_),
  13072. undoManager (undoManager_)
  13073. {
  13074. tree.addListener (this);
  13075. }
  13076. ~ValueTreePropertyValueSource()
  13077. {
  13078. tree.removeListener (this);
  13079. }
  13080. const var getValue() const
  13081. {
  13082. return tree [property];
  13083. }
  13084. void setValue (const var& newValue)
  13085. {
  13086. tree.setProperty (property, newValue, undoManager);
  13087. }
  13088. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13089. {
  13090. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13091. sendChangeMessage (false);
  13092. }
  13093. void valueTreeChildrenChanged (ValueTree&) {}
  13094. void valueTreeParentChanged (ValueTree&) {}
  13095. private:
  13096. ValueTree tree;
  13097. const var::identifier property;
  13098. UndoManager* const undoManager;
  13099. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13100. };
  13101. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13102. {
  13103. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13104. }
  13105. int ValueTree::getNumChildren() const
  13106. {
  13107. return object == 0 ? 0 : object->children.size();
  13108. }
  13109. ValueTree ValueTree::getChild (int index) const
  13110. {
  13111. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13112. }
  13113. ValueTree ValueTree::getChildWithName (const String& type) const
  13114. {
  13115. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13116. }
  13117. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13118. {
  13119. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13120. }
  13121. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13122. {
  13123. return object != 0 && object->isAChildOf (possibleParent.object);
  13124. }
  13125. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13126. {
  13127. if (object != 0)
  13128. object->addChild (child.object, index, undoManager);
  13129. }
  13130. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13131. {
  13132. if (object != 0)
  13133. object->removeChild (childIndex, undoManager);
  13134. }
  13135. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13136. {
  13137. if (object != 0)
  13138. object->removeChild (object->children.indexOf (child.object), undoManager);
  13139. }
  13140. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13141. {
  13142. if (object != 0)
  13143. object->removeAllChildren (undoManager);
  13144. }
  13145. void ValueTree::addListener (Listener* listener)
  13146. {
  13147. if (listener != 0)
  13148. {
  13149. if (listeners.size() == 0 && object != 0)
  13150. object->valueTreesWithListeners.add (this);
  13151. listeners.add (listener);
  13152. }
  13153. }
  13154. void ValueTree::removeListener (Listener* listener)
  13155. {
  13156. listeners.remove (listener);
  13157. if (listeners.size() == 0 && object != 0)
  13158. object->valueTreesWithListeners.removeValue (this);
  13159. }
  13160. XmlElement* ValueTree::SharedObject::createXml() const
  13161. {
  13162. XmlElement* xml = new XmlElement (type);
  13163. int i;
  13164. for (i = 0; i < properties.size(); ++i)
  13165. {
  13166. var::identifier name (properties.getName(i));
  13167. const var& v = properties [name];
  13168. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13169. xml->setAttribute (name.name, v.toString());
  13170. }
  13171. for (i = 0; i < children.size(); ++i)
  13172. xml->addChildElement (children.getUnchecked(i)->createXml());
  13173. return xml;
  13174. }
  13175. XmlElement* ValueTree::createXml() const
  13176. {
  13177. return object != 0 ? object->createXml() : 0;
  13178. }
  13179. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13180. {
  13181. ValueTree v (xml.getTagName());
  13182. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13183. for (int i = 0; i < numAtts; ++i)
  13184. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13185. forEachXmlChildElement (xml, e)
  13186. {
  13187. v.addChild (fromXml (*e), -1, 0);
  13188. }
  13189. return v;
  13190. }
  13191. void ValueTree::writeToStream (OutputStream& output)
  13192. {
  13193. output.writeString (getType());
  13194. const int numProps = getNumProperties();
  13195. output.writeCompressedInt (numProps);
  13196. int i;
  13197. for (i = 0; i < numProps; ++i)
  13198. {
  13199. const var::identifier name (getPropertyName(i));
  13200. output.writeString (name.name);
  13201. getProperty(name).writeToStream (output);
  13202. }
  13203. const int numChildren = getNumChildren();
  13204. output.writeCompressedInt (numChildren);
  13205. for (i = 0; i < numChildren; ++i)
  13206. getChild (i).writeToStream (output);
  13207. }
  13208. ValueTree ValueTree::readFromStream (InputStream& input)
  13209. {
  13210. String type (input.readString());
  13211. if (type.isEmpty())
  13212. return ValueTree ((SharedObject*) 0);
  13213. ValueTree v (type);
  13214. const int numProps = input.readCompressedInt();
  13215. if (numProps < 0)
  13216. {
  13217. jassertfalse // trying to read corrupted data!
  13218. return v;
  13219. }
  13220. int i;
  13221. for (i = 0; i < numProps; ++i)
  13222. {
  13223. const String name (input.readString());
  13224. jassert (name.isNotEmpty());
  13225. const var value (var::readFromStream (input));
  13226. v.setProperty (name, value, 0);
  13227. }
  13228. const int numChildren = input.readCompressedInt();
  13229. for (i = 0; i < numChildren; ++i)
  13230. v.addChild (readFromStream (input), -1, 0);
  13231. return v;
  13232. }
  13233. END_JUCE_NAMESPACE
  13234. /*** End of inlined file: juce_ValueTree.cpp ***/
  13235. /*** Start of inlined file: juce_Value.cpp ***/
  13236. BEGIN_JUCE_NAMESPACE
  13237. Value::ValueSource::ValueSource()
  13238. {
  13239. }
  13240. Value::ValueSource::~ValueSource()
  13241. {
  13242. }
  13243. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13244. {
  13245. if (synchronous)
  13246. {
  13247. for (int i = valuesWithListeners.size(); --i >= 0;)
  13248. {
  13249. Value* const v = valuesWithListeners[i];
  13250. if (v != 0)
  13251. v->callListeners();
  13252. }
  13253. }
  13254. else
  13255. {
  13256. triggerAsyncUpdate();
  13257. }
  13258. }
  13259. void Value::ValueSource::handleAsyncUpdate()
  13260. {
  13261. sendChangeMessage (true);
  13262. }
  13263. class SimpleValueSource : public Value::ValueSource
  13264. {
  13265. public:
  13266. SimpleValueSource()
  13267. {
  13268. }
  13269. SimpleValueSource (const var& initialValue)
  13270. : value (initialValue)
  13271. {
  13272. }
  13273. ~SimpleValueSource()
  13274. {
  13275. }
  13276. const var getValue() const
  13277. {
  13278. return value;
  13279. }
  13280. void setValue (const var& newValue)
  13281. {
  13282. if (newValue != value)
  13283. {
  13284. value = newValue;
  13285. sendChangeMessage (false);
  13286. }
  13287. }
  13288. private:
  13289. var value;
  13290. SimpleValueSource (const SimpleValueSource&);
  13291. SimpleValueSource& operator= (const SimpleValueSource&);
  13292. };
  13293. Value::Value()
  13294. : value (new SimpleValueSource())
  13295. {
  13296. }
  13297. Value::Value (ValueSource* const value_)
  13298. : value (value_)
  13299. {
  13300. jassert (value_ != 0);
  13301. }
  13302. Value::Value (const var& initialValue)
  13303. : value (new SimpleValueSource (initialValue))
  13304. {
  13305. }
  13306. Value::Value (const Value& other)
  13307. : value (other.value)
  13308. {
  13309. }
  13310. Value& Value::operator= (const Value& other)
  13311. {
  13312. value = other.value;
  13313. return *this;
  13314. }
  13315. Value::~Value()
  13316. {
  13317. if (listeners.size() > 0)
  13318. value->valuesWithListeners.removeValue (this);
  13319. }
  13320. const var Value::getValue() const
  13321. {
  13322. return value->getValue();
  13323. }
  13324. Value::operator const var() const
  13325. {
  13326. return getValue();
  13327. }
  13328. void Value::setValue (const var& newValue)
  13329. {
  13330. value->setValue (newValue);
  13331. }
  13332. const String Value::toString() const
  13333. {
  13334. return value->getValue().toString();
  13335. }
  13336. Value& Value::operator= (const var& newValue)
  13337. {
  13338. value->setValue (newValue);
  13339. return *this;
  13340. }
  13341. void Value::referTo (const Value& valueToReferTo)
  13342. {
  13343. if (valueToReferTo.value != value)
  13344. {
  13345. if (listeners.size() > 0)
  13346. {
  13347. value->valuesWithListeners.removeValue (this);
  13348. valueToReferTo.value->valuesWithListeners.add (this);
  13349. }
  13350. value = valueToReferTo.value;
  13351. callListeners();
  13352. }
  13353. }
  13354. bool Value::refersToSameSourceAs (const Value& other) const
  13355. {
  13356. return value == other.value;
  13357. }
  13358. bool Value::operator== (const Value& other) const
  13359. {
  13360. return value == other.value || value->getValue() == other.getValue();
  13361. }
  13362. bool Value::operator!= (const Value& other) const
  13363. {
  13364. return value != other.value && value->getValue() != other.getValue();
  13365. }
  13366. void Value::addListener (Listener* const listener)
  13367. {
  13368. if (listener != 0)
  13369. {
  13370. if (listeners.size() == 0)
  13371. value->valuesWithListeners.add (this);
  13372. listeners.add (listener);
  13373. }
  13374. }
  13375. void Value::removeListener (Listener* const listener)
  13376. {
  13377. listeners.remove (listener);
  13378. if (listeners.size() == 0)
  13379. value->valuesWithListeners.removeValue (this);
  13380. }
  13381. void Value::callListeners()
  13382. {
  13383. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13384. listeners.call (&Listener::valueChanged, v);
  13385. }
  13386. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const Value& value)
  13387. {
  13388. return stream << value.toString();
  13389. }
  13390. END_JUCE_NAMESPACE
  13391. /*** End of inlined file: juce_Value.cpp ***/
  13392. /*** Start of inlined file: juce_Application.cpp ***/
  13393. #if JUCE_MSVC
  13394. #pragma warning (push)
  13395. #pragma warning (disable: 4245 4514 4100)
  13396. #include <crtdbg.h>
  13397. #pragma warning (pop)
  13398. #endif
  13399. BEGIN_JUCE_NAMESPACE
  13400. void juce_setCurrentThreadName (const String& name);
  13401. static JUCEApplication* appInstance = 0;
  13402. JUCEApplication::JUCEApplication()
  13403. : appReturnValue (0),
  13404. stillInitialising (true)
  13405. {
  13406. }
  13407. JUCEApplication::~JUCEApplication()
  13408. {
  13409. if (appLock != 0)
  13410. {
  13411. appLock->exit();
  13412. appLock = 0;
  13413. }
  13414. }
  13415. JUCEApplication* JUCEApplication::getInstance() throw()
  13416. {
  13417. return appInstance;
  13418. }
  13419. bool JUCEApplication::isInitialising() const throw()
  13420. {
  13421. return stillInitialising;
  13422. }
  13423. const String JUCEApplication::getApplicationVersion()
  13424. {
  13425. return String::empty;
  13426. }
  13427. bool JUCEApplication::moreThanOneInstanceAllowed()
  13428. {
  13429. return true;
  13430. }
  13431. void JUCEApplication::anotherInstanceStarted (const String&)
  13432. {
  13433. }
  13434. void JUCEApplication::systemRequestedQuit()
  13435. {
  13436. quit();
  13437. }
  13438. void JUCEApplication::quit()
  13439. {
  13440. MessageManager::getInstance()->stopDispatchLoop();
  13441. }
  13442. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13443. {
  13444. appReturnValue = newReturnValue;
  13445. }
  13446. void JUCEApplication::unhandledException (const std::exception*,
  13447. const String&,
  13448. const int)
  13449. {
  13450. jassertfalse
  13451. }
  13452. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13453. const char* const sourceFile,
  13454. const int lineNumber)
  13455. {
  13456. if (appInstance != 0)
  13457. appInstance->unhandledException (e, sourceFile, lineNumber);
  13458. }
  13459. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13460. {
  13461. return 0;
  13462. }
  13463. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13464. {
  13465. commands.add (StandardApplicationCommandIDs::quit);
  13466. }
  13467. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13468. {
  13469. if (commandID == StandardApplicationCommandIDs::quit)
  13470. {
  13471. result.setInfo (TRANS("Quit"),
  13472. TRANS("Quits the application"),
  13473. "Application",
  13474. 0);
  13475. result.defaultKeypresses.add (KeyPress ('q', ModifierKeys::commandModifier, 0));
  13476. }
  13477. }
  13478. bool JUCEApplication::perform (const InvocationInfo& info)
  13479. {
  13480. if (info.commandID == StandardApplicationCommandIDs::quit)
  13481. {
  13482. systemRequestedQuit();
  13483. return true;
  13484. }
  13485. return false;
  13486. }
  13487. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13488. {
  13489. if (! app->initialiseApp (commandLine))
  13490. return 0;
  13491. // now loop until a quit message is received..
  13492. JUCE_TRY
  13493. {
  13494. MessageManager::getInstance()->runDispatchLoop();
  13495. }
  13496. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13497. catch (const std::exception& e)
  13498. {
  13499. app->unhandledException (&e, __FILE__, __LINE__);
  13500. }
  13501. catch (...)
  13502. {
  13503. app->unhandledException (0, __FILE__, __LINE__);
  13504. }
  13505. #endif
  13506. return shutdownAppAndClearUp();
  13507. }
  13508. bool JUCEApplication::initialiseApp (String& commandLine)
  13509. {
  13510. jassert (appInstance == 0);
  13511. appInstance = this;
  13512. commandLineParameters = commandLine.trim();
  13513. commandLine = String::empty;
  13514. initialiseJuce_GUI();
  13515. #if ! JUCE_IPHONE
  13516. jassert (appLock == 0); // initialiseApp must only be called once!
  13517. if (! moreThanOneInstanceAllowed())
  13518. {
  13519. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13520. if (! appLock->enter(0))
  13521. {
  13522. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13523. delete appInstance;
  13524. appInstance = 0;
  13525. DBG ("Another instance is running - quitting...");
  13526. return false;
  13527. }
  13528. }
  13529. #endif
  13530. // let the app do its setting-up..
  13531. initialise (commandLineParameters);
  13532. // register for broadcast new app messages
  13533. MessageManager::getInstance()->registerBroadcastListener (this);
  13534. stillInitialising = false;
  13535. return true;
  13536. }
  13537. int JUCEApplication::shutdownAppAndClearUp()
  13538. {
  13539. jassert (appInstance != 0);
  13540. ScopedPointer<JUCEApplication> app (appInstance);
  13541. int returnValue = 0;
  13542. MessageManager::getInstance()->deregisterBroadcastListener ((JUCEApplication*) app);
  13543. static bool reentrancyCheck = false;
  13544. if (! reentrancyCheck)
  13545. {
  13546. reentrancyCheck = true;
  13547. JUCE_TRY
  13548. {
  13549. // give the app a chance to clean up..
  13550. app->shutdown();
  13551. }
  13552. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13553. catch (const std::exception& e)
  13554. {
  13555. app->unhandledException (&e, __FILE__, __LINE__);
  13556. }
  13557. catch (...)
  13558. {
  13559. app->unhandledException (0, __FILE__, __LINE__);
  13560. }
  13561. #endif
  13562. JUCE_TRY
  13563. {
  13564. shutdownJuce_GUI();
  13565. returnValue = app->getApplicationReturnValue();
  13566. appInstance = 0;
  13567. app = 0;
  13568. }
  13569. JUCE_CATCH_ALL_ASSERT
  13570. reentrancyCheck = false;
  13571. }
  13572. return returnValue;
  13573. }
  13574. #if JUCE_IPHONE
  13575. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13576. #endif
  13577. #if ! JUCE_WINDOWS
  13578. extern const char* juce_Argv0;
  13579. #endif
  13580. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13581. {
  13582. #if ! JUCE_WINDOWS
  13583. juce_Argv0 = argv[0];
  13584. #endif
  13585. #if JUCE_IPHONE
  13586. const ScopedAutoReleasePool pool;
  13587. return juce_IPhoneMain (argc, argv, newApp);
  13588. #else
  13589. #if JUCE_MAC
  13590. const ScopedAutoReleasePool pool;
  13591. #endif
  13592. String cmd;
  13593. for (int i = 1; i < argc; ++i)
  13594. cmd << argv[i] << ' ';
  13595. return JUCEApplication::main (cmd, newApp);
  13596. #endif
  13597. }
  13598. void JUCEApplication::actionListenerCallback (const String& message)
  13599. {
  13600. if (message.startsWith (getApplicationName() + "/"))
  13601. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13602. }
  13603. static bool juceInitialisedGUI = false;
  13604. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13605. {
  13606. if (! juceInitialisedGUI)
  13607. {
  13608. #if JUCE_MAC || JUCE_IPHONE
  13609. const ScopedAutoReleasePool pool;
  13610. #endif
  13611. juceInitialisedGUI = true;
  13612. initialiseJuce_NonGUI();
  13613. MessageManager::getInstance();
  13614. LookAndFeel::setDefaultLookAndFeel (0);
  13615. juce_setCurrentThreadName ("Juce Message Thread");
  13616. #if JUCE_WINDOWS && JUCE_DEBUG
  13617. // This section is just for catching people who mess up their project settings and
  13618. // turn RTTI off..
  13619. try
  13620. {
  13621. TextButton tb (String::empty);
  13622. Component* c = &tb;
  13623. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13624. c = dynamic_cast <Button*> (c);
  13625. }
  13626. catch (...)
  13627. {
  13628. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13629. // got as far as this catch statement, then why haven't you got exception catching
  13630. // turned on in the debugger???
  13631. jassertfalse
  13632. }
  13633. #endif
  13634. }
  13635. }
  13636. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13637. {
  13638. if (juceInitialisedGUI)
  13639. {
  13640. #if JUCE_MAC
  13641. const ScopedAutoReleasePool pool;
  13642. #endif
  13643. {
  13644. DeletedAtShutdown::deleteAll();
  13645. LookAndFeel::clearDefaultLookAndFeel();
  13646. }
  13647. delete MessageManager::getInstance();
  13648. shutdownJuce_NonGUI();
  13649. juceInitialisedGUI = false;
  13650. }
  13651. }
  13652. END_JUCE_NAMESPACE
  13653. /*** End of inlined file: juce_Application.cpp ***/
  13654. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13655. BEGIN_JUCE_NAMESPACE
  13656. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13657. : commandID (commandID_),
  13658. flags (0)
  13659. {
  13660. }
  13661. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13662. const String& description_,
  13663. const String& categoryName_,
  13664. const int flags_) throw()
  13665. {
  13666. shortName = shortName_;
  13667. description = description_;
  13668. categoryName = categoryName_;
  13669. flags = flags_;
  13670. }
  13671. void ApplicationCommandInfo::setActive (const bool b) throw()
  13672. {
  13673. if (b)
  13674. flags &= ~isDisabled;
  13675. else
  13676. flags |= isDisabled;
  13677. }
  13678. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13679. {
  13680. if (b)
  13681. flags |= isTicked;
  13682. else
  13683. flags &= ~isTicked;
  13684. }
  13685. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13686. {
  13687. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13688. }
  13689. END_JUCE_NAMESPACE
  13690. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13691. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13692. BEGIN_JUCE_NAMESPACE
  13693. ApplicationCommandManager::ApplicationCommandManager()
  13694. : firstTarget (0)
  13695. {
  13696. keyMappings = new KeyPressMappingSet (this);
  13697. Desktop::getInstance().addFocusChangeListener (this);
  13698. }
  13699. ApplicationCommandManager::~ApplicationCommandManager()
  13700. {
  13701. Desktop::getInstance().removeFocusChangeListener (this);
  13702. keyMappings = 0;
  13703. }
  13704. void ApplicationCommandManager::clearCommands()
  13705. {
  13706. commands.clear();
  13707. keyMappings->clearAllKeyPresses();
  13708. triggerAsyncUpdate();
  13709. }
  13710. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13711. {
  13712. // zero isn't a valid command ID!
  13713. jassert (newCommand.commandID != 0);
  13714. // the name isn't optional!
  13715. jassert (newCommand.shortName.isNotEmpty());
  13716. if (getCommandForID (newCommand.commandID) == 0)
  13717. {
  13718. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13719. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13720. commands.add (newInfo);
  13721. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13722. triggerAsyncUpdate();
  13723. }
  13724. else
  13725. {
  13726. // trying to re-register the same command with different parameters?
  13727. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13728. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13729. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13730. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13731. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13732. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13733. }
  13734. }
  13735. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13736. {
  13737. if (target != 0)
  13738. {
  13739. Array <CommandID> commandIDs;
  13740. target->getAllCommands (commandIDs);
  13741. for (int i = 0; i < commandIDs.size(); ++i)
  13742. {
  13743. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13744. target->getCommandInfo (info.commandID, info);
  13745. registerCommand (info);
  13746. }
  13747. }
  13748. }
  13749. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13750. {
  13751. for (int i = commands.size(); --i >= 0;)
  13752. {
  13753. if (commands.getUnchecked (i)->commandID == commandID)
  13754. {
  13755. commands.remove (i);
  13756. triggerAsyncUpdate();
  13757. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13758. for (int j = keys.size(); --j >= 0;)
  13759. keyMappings->removeKeyPress (keys.getReference (j));
  13760. }
  13761. }
  13762. }
  13763. void ApplicationCommandManager::commandStatusChanged()
  13764. {
  13765. triggerAsyncUpdate();
  13766. }
  13767. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13768. {
  13769. for (int i = commands.size(); --i >= 0;)
  13770. if (commands.getUnchecked(i)->commandID == commandID)
  13771. return commands.getUnchecked(i);
  13772. return 0;
  13773. }
  13774. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13775. {
  13776. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13777. return (ci != 0) ? ci->shortName : String::empty;
  13778. }
  13779. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13780. {
  13781. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13782. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13783. : String::empty;
  13784. }
  13785. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13786. {
  13787. StringArray s;
  13788. for (int i = 0; i < commands.size(); ++i)
  13789. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13790. return s;
  13791. }
  13792. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13793. {
  13794. Array <CommandID> results;
  13795. for (int i = 0; i < commands.size(); ++i)
  13796. if (commands.getUnchecked(i)->categoryName == categoryName)
  13797. results.add (commands.getUnchecked(i)->commandID);
  13798. return results;
  13799. }
  13800. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13801. {
  13802. ApplicationCommandTarget::InvocationInfo info (commandID);
  13803. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13804. return invoke (info, asynchronously);
  13805. }
  13806. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13807. {
  13808. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13809. // manager first..
  13810. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13811. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13812. if (target == 0)
  13813. return false;
  13814. ApplicationCommandInfo commandInfo (0);
  13815. target->getCommandInfo (info_.commandID, commandInfo);
  13816. ApplicationCommandTarget::InvocationInfo info (info_);
  13817. info.commandFlags = commandInfo.flags;
  13818. sendListenerInvokeCallback (info);
  13819. const bool ok = target->invoke (info, asynchronously);
  13820. commandStatusChanged();
  13821. return ok;
  13822. }
  13823. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13824. {
  13825. return firstTarget != 0 ? firstTarget
  13826. : findDefaultComponentTarget();
  13827. }
  13828. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13829. {
  13830. firstTarget = newTarget;
  13831. }
  13832. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13833. ApplicationCommandInfo& upToDateInfo)
  13834. {
  13835. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13836. if (target == 0)
  13837. target = JUCEApplication::getInstance();
  13838. if (target != 0)
  13839. target = target->getTargetForCommand (commandID);
  13840. if (target != 0)
  13841. target->getCommandInfo (commandID, upToDateInfo);
  13842. return target;
  13843. }
  13844. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13845. {
  13846. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13847. if (target == 0 && c != 0)
  13848. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13849. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13850. return target;
  13851. }
  13852. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  13853. {
  13854. Component* c = Component::getCurrentlyFocusedComponent();
  13855. if (c == 0)
  13856. {
  13857. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  13858. if (activeWindow != 0)
  13859. {
  13860. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  13861. if (c == 0)
  13862. c = activeWindow;
  13863. }
  13864. }
  13865. if (c == 0 && Process::isForegroundProcess())
  13866. {
  13867. // getting a bit desperate now - try all desktop comps..
  13868. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  13869. {
  13870. ApplicationCommandTarget* const target
  13871. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  13872. ->getPeer()->getLastFocusedSubcomponent());
  13873. if (target != 0)
  13874. return target;
  13875. }
  13876. }
  13877. if (c != 0)
  13878. {
  13879. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  13880. // if we're focused on a ResizableWindow, chances are that it's the content
  13881. // component that really should get the event. And if not, the event will
  13882. // still be passed up to the top level window anyway, so let's send it to the
  13883. // content comp.
  13884. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  13885. c = resizableWindow->getContentComponent();
  13886. ApplicationCommandTarget* const target = findTargetForComponent (c);
  13887. if (target != 0)
  13888. return target;
  13889. }
  13890. return JUCEApplication::getInstance();
  13891. }
  13892. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  13893. {
  13894. listeners.add (listener);
  13895. }
  13896. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  13897. {
  13898. listeners.remove (listener);
  13899. }
  13900. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  13901. {
  13902. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  13903. }
  13904. void ApplicationCommandManager::handleAsyncUpdate()
  13905. {
  13906. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  13907. }
  13908. void ApplicationCommandManager::globalFocusChanged (Component*)
  13909. {
  13910. commandStatusChanged();
  13911. }
  13912. END_JUCE_NAMESPACE
  13913. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  13914. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13915. BEGIN_JUCE_NAMESPACE
  13916. ApplicationCommandTarget::ApplicationCommandTarget()
  13917. {
  13918. }
  13919. ApplicationCommandTarget::~ApplicationCommandTarget()
  13920. {
  13921. messageInvoker = 0;
  13922. }
  13923. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  13924. {
  13925. if (isCommandActive (info.commandID))
  13926. {
  13927. if (async)
  13928. {
  13929. if (messageInvoker == 0)
  13930. messageInvoker = new CommandTargetMessageInvoker (this);
  13931. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  13932. return true;
  13933. }
  13934. else
  13935. {
  13936. const bool success = perform (info);
  13937. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  13938. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  13939. // returns the command's info.
  13940. return success;
  13941. }
  13942. }
  13943. return false;
  13944. }
  13945. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  13946. {
  13947. Component* c = dynamic_cast <Component*> (this);
  13948. if (c != 0)
  13949. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13950. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13951. return 0;
  13952. }
  13953. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  13954. {
  13955. ApplicationCommandTarget* target = this;
  13956. int depth = 0;
  13957. while (target != 0)
  13958. {
  13959. Array <CommandID> commandIDs;
  13960. target->getAllCommands (commandIDs);
  13961. if (commandIDs.contains (commandID))
  13962. return target;
  13963. target = target->getNextCommandTarget();
  13964. ++depth;
  13965. jassert (depth < 100); // could be a recursive command chain??
  13966. jassert (target != this); // definitely a recursive command chain!
  13967. if (depth > 100 || target == this)
  13968. break;
  13969. }
  13970. if (target == 0)
  13971. {
  13972. target = JUCEApplication::getInstance();
  13973. if (target != 0)
  13974. {
  13975. Array <CommandID> commandIDs;
  13976. target->getAllCommands (commandIDs);
  13977. if (commandIDs.contains (commandID))
  13978. return target;
  13979. }
  13980. }
  13981. return 0;
  13982. }
  13983. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  13984. {
  13985. ApplicationCommandInfo info (commandID);
  13986. info.flags = ApplicationCommandInfo::isDisabled;
  13987. getCommandInfo (commandID, info);
  13988. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  13989. }
  13990. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  13991. {
  13992. ApplicationCommandTarget* target = this;
  13993. int depth = 0;
  13994. while (target != 0)
  13995. {
  13996. if (target->tryToInvoke (info, async))
  13997. return true;
  13998. target = target->getNextCommandTarget();
  13999. ++depth;
  14000. jassert (depth < 100); // could be a recursive command chain??
  14001. jassert (target != this); // definitely a recursive command chain!
  14002. if (depth > 100 || target == this)
  14003. break;
  14004. }
  14005. if (target == 0)
  14006. {
  14007. target = JUCEApplication::getInstance();
  14008. if (target != 0)
  14009. return target->tryToInvoke (info, async);
  14010. }
  14011. return false;
  14012. }
  14013. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14014. {
  14015. ApplicationCommandTarget::InvocationInfo info (commandID);
  14016. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14017. return invoke (info, asynchronously);
  14018. }
  14019. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14020. : commandID (commandID_),
  14021. commandFlags (0),
  14022. invocationMethod (direct),
  14023. originatingComponent (0),
  14024. isKeyDown (false),
  14025. millisecsSinceKeyPressed (0)
  14026. {
  14027. }
  14028. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14029. : owner (owner_)
  14030. {
  14031. }
  14032. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14033. {
  14034. }
  14035. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14036. {
  14037. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14038. owner->tryToInvoke (*info, false);
  14039. }
  14040. END_JUCE_NAMESPACE
  14041. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14042. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14043. BEGIN_JUCE_NAMESPACE
  14044. juce_ImplementSingleton (ApplicationProperties)
  14045. ApplicationProperties::ApplicationProperties() throw()
  14046. : msBeforeSaving (3000),
  14047. options (PropertiesFile::storeAsBinary),
  14048. commonSettingsAreReadOnly (0)
  14049. {
  14050. }
  14051. ApplicationProperties::~ApplicationProperties()
  14052. {
  14053. closeFiles();
  14054. clearSingletonInstance();
  14055. }
  14056. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14057. const String& fileNameSuffix,
  14058. const String& folderName_,
  14059. const int millisecondsBeforeSaving,
  14060. const int propertiesFileOptions) throw()
  14061. {
  14062. appName = applicationName;
  14063. fileSuffix = fileNameSuffix;
  14064. folderName = folderName_;
  14065. msBeforeSaving = millisecondsBeforeSaving;
  14066. options = propertiesFileOptions;
  14067. }
  14068. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14069. const bool testCommonSettings,
  14070. const bool showWarningDialogOnFailure)
  14071. {
  14072. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14073. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14074. if (! (userOk && commonOk))
  14075. {
  14076. if (showWarningDialogOnFailure)
  14077. {
  14078. String filenames;
  14079. if (userProps != 0 && ! userOk)
  14080. filenames << '\n' << userProps->getFile().getFullPathName();
  14081. if (commonProps != 0 && ! commonOk)
  14082. filenames << '\n' << commonProps->getFile().getFullPathName();
  14083. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14084. appName + TRANS(" - Unable to save settings"),
  14085. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14086. + appName + TRANS(" needs to be able to write to the following files:\n")
  14087. + filenames
  14088. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14089. }
  14090. return false;
  14091. }
  14092. return true;
  14093. }
  14094. void ApplicationProperties::openFiles() throw()
  14095. {
  14096. // You need to call setStorageParameters() before trying to get hold of the
  14097. // properties!
  14098. jassert (appName.isNotEmpty());
  14099. if (appName.isNotEmpty())
  14100. {
  14101. if (userProps == 0)
  14102. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14103. false, msBeforeSaving, options);
  14104. if (commonProps == 0)
  14105. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14106. true, msBeforeSaving, options);
  14107. userProps->setFallbackPropertySet (commonProps);
  14108. }
  14109. }
  14110. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14111. {
  14112. if (userProps == 0)
  14113. openFiles();
  14114. return userProps;
  14115. }
  14116. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14117. {
  14118. if (commonProps == 0)
  14119. openFiles();
  14120. if (returnUserPropsIfReadOnly)
  14121. {
  14122. if (commonSettingsAreReadOnly == 0)
  14123. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14124. if (commonSettingsAreReadOnly > 0)
  14125. return userProps;
  14126. }
  14127. return commonProps;
  14128. }
  14129. bool ApplicationProperties::saveIfNeeded()
  14130. {
  14131. return (userProps == 0 || userProps->saveIfNeeded())
  14132. && (commonProps == 0 || commonProps->saveIfNeeded());
  14133. }
  14134. void ApplicationProperties::closeFiles()
  14135. {
  14136. userProps = 0;
  14137. commonProps = 0;
  14138. }
  14139. END_JUCE_NAMESPACE
  14140. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14141. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14142. BEGIN_JUCE_NAMESPACE
  14143. static VoidArray objectsToDelete;
  14144. static CriticalSection lock;
  14145. DeletedAtShutdown::DeletedAtShutdown()
  14146. {
  14147. const ScopedLock sl (lock);
  14148. objectsToDelete.add (this);
  14149. }
  14150. DeletedAtShutdown::~DeletedAtShutdown()
  14151. {
  14152. const ScopedLock sl (lock);
  14153. objectsToDelete.removeValue (this);
  14154. }
  14155. void DeletedAtShutdown::deleteAll()
  14156. {
  14157. // make a local copy of the array, so it can't get into a loop if something
  14158. // creates another DeletedAtShutdown object during its destructor.
  14159. VoidArray localCopy;
  14160. {
  14161. const ScopedLock sl (lock);
  14162. localCopy = objectsToDelete;
  14163. }
  14164. for (int i = localCopy.size(); --i >= 0;)
  14165. {
  14166. JUCE_TRY
  14167. {
  14168. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14169. // double-check that it's not already been deleted during another object's destructor.
  14170. {
  14171. const ScopedLock sl (lock);
  14172. if (! objectsToDelete.contains (deletee))
  14173. deletee = 0;
  14174. }
  14175. delete deletee;
  14176. }
  14177. JUCE_CATCH_EXCEPTION
  14178. }
  14179. // if no objects got re-created during shutdown, this should have been emptied by their
  14180. // destructors
  14181. jassert (objectsToDelete.size() == 0);
  14182. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14183. }
  14184. END_JUCE_NAMESPACE
  14185. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14186. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14187. BEGIN_JUCE_NAMESPACE
  14188. namespace PropertyFileConstants
  14189. {
  14190. static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP");
  14191. static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP");
  14192. static const char* const fileTag = "PROPERTIES";
  14193. static const char* const valueTag = "VALUE";
  14194. static const char* const nameAttribute = "name";
  14195. static const char* const valueAttribute = "val";
  14196. }
  14197. PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving, const int options_)
  14198. : PropertySet (ignoreCaseOfKeyNames),
  14199. file (f),
  14200. timerInterval (millisecondsBeforeSaving),
  14201. options (options_),
  14202. loadedOk (false),
  14203. needsWriting (false)
  14204. {
  14205. // You need to correctly specify just one storage format for the file
  14206. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14207. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14208. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14209. ScopedPointer<InputStream> fileStream (f.createInputStream());
  14210. if (fileStream != 0)
  14211. {
  14212. int magicNumber = fileStream->readInt();
  14213. if (magicNumber == PropertyFileConstants::magicNumberCompressed)
  14214. {
  14215. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true);
  14216. magicNumber = PropertyFileConstants::magicNumber;
  14217. }
  14218. if (magicNumber == PropertyFileConstants::magicNumber)
  14219. {
  14220. loadedOk = true;
  14221. BufferedInputStream in (fileStream.release(), 2048, true);
  14222. int numValues = in.readInt();
  14223. while (--numValues >= 0 && ! in.isExhausted())
  14224. {
  14225. const String key (in.readString());
  14226. const String value (in.readString());
  14227. jassert (key.isNotEmpty());
  14228. if (key.isNotEmpty())
  14229. getAllProperties().set (key, value);
  14230. }
  14231. }
  14232. else
  14233. {
  14234. // Not a binary props file - let's see if it's XML..
  14235. fileStream = 0;
  14236. XmlDocument parser (f);
  14237. ScopedPointer<XmlElement> doc (parser.getDocumentElement (true));
  14238. if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag))
  14239. {
  14240. doc = parser.getDocumentElement();
  14241. if (doc != 0)
  14242. {
  14243. loadedOk = true;
  14244. forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
  14245. {
  14246. const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute));
  14247. if (name.isNotEmpty())
  14248. {
  14249. getAllProperties().set (name,
  14250. e->getFirstChildElement() != 0
  14251. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14252. : e->getStringAttribute (PropertyFileConstants::valueAttribute));
  14253. }
  14254. }
  14255. }
  14256. else
  14257. {
  14258. // must be a pretty broken XML file we're trying to parse here!
  14259. jassertfalse
  14260. }
  14261. }
  14262. }
  14263. }
  14264. else
  14265. {
  14266. loadedOk = ! f.exists();
  14267. }
  14268. }
  14269. PropertiesFile::~PropertiesFile()
  14270. {
  14271. if (! saveIfNeeded())
  14272. jassertfalse;
  14273. }
  14274. bool PropertiesFile::saveIfNeeded()
  14275. {
  14276. const ScopedLock sl (getLock());
  14277. return (! needsWriting) || save();
  14278. }
  14279. bool PropertiesFile::needsToBeSaved() const
  14280. {
  14281. const ScopedLock sl (getLock());
  14282. return needsWriting;
  14283. }
  14284. void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved)
  14285. {
  14286. const ScopedLock sl (getLock());
  14287. needsWriting = needsToBeSaved;
  14288. }
  14289. bool PropertiesFile::save()
  14290. {
  14291. const ScopedLock sl (getLock());
  14292. stopTimer();
  14293. if (file == File::nonexistent
  14294. || file.isDirectory()
  14295. || ! file.getParentDirectory().createDirectory())
  14296. return false;
  14297. if ((options & storeAsXML) != 0)
  14298. {
  14299. XmlElement doc (PropertyFileConstants::fileTag);
  14300. for (int i = 0; i < getAllProperties().size(); ++i)
  14301. {
  14302. XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag);
  14303. e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]);
  14304. // if the value seems to contain xml, store it as such..
  14305. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14306. XmlElement* const childElement = xmlContent.getDocumentElement();
  14307. if (childElement != 0)
  14308. e->addChildElement (childElement);
  14309. else
  14310. e->setAttribute (PropertyFileConstants::valueAttribute,
  14311. getAllProperties().getAllValues() [i]);
  14312. }
  14313. if (doc.writeToFile (file, String::empty))
  14314. {
  14315. needsWriting = false;
  14316. return true;
  14317. }
  14318. }
  14319. else
  14320. {
  14321. TemporaryFile tempFile (file);
  14322. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14323. if (out != 0)
  14324. {
  14325. if ((options & storeAsCompressedBinary) != 0)
  14326. {
  14327. out->writeInt (PropertyFileConstants::magicNumberCompressed);
  14328. out->flush();
  14329. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14330. }
  14331. else
  14332. {
  14333. // have you set up the storage option flags correctly?
  14334. jassert ((options & storeAsBinary) != 0);
  14335. out->writeInt (PropertyFileConstants::magicNumber);
  14336. }
  14337. const int numProperties = getAllProperties().size();
  14338. out->writeInt (numProperties);
  14339. for (int i = 0; i < numProperties; ++i)
  14340. {
  14341. out->writeString (getAllProperties().getAllKeys() [i]);
  14342. out->writeString (getAllProperties().getAllValues() [i]);
  14343. }
  14344. out = 0;
  14345. if (tempFile.overwriteTargetFileWithTemporary())
  14346. {
  14347. needsWriting = false;
  14348. return true;
  14349. }
  14350. }
  14351. }
  14352. return false;
  14353. }
  14354. void PropertiesFile::timerCallback()
  14355. {
  14356. saveIfNeeded();
  14357. }
  14358. void PropertiesFile::propertyChanged()
  14359. {
  14360. sendChangeMessage (this);
  14361. needsWriting = true;
  14362. if (timerInterval > 0)
  14363. startTimer (timerInterval);
  14364. else if (timerInterval == 0)
  14365. saveIfNeeded();
  14366. }
  14367. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14368. const String& fileNameSuffix,
  14369. const String& folderName,
  14370. const bool commonToAllUsers)
  14371. {
  14372. // mustn't have illegal characters in this name..
  14373. jassert (applicationName == File::createLegalFileName (applicationName));
  14374. #if JUCE_MAC || JUCE_IPHONE
  14375. File dir (commonToAllUsers ? "/Library/Preferences"
  14376. : "~/Library/Preferences");
  14377. if (folderName.isNotEmpty())
  14378. dir = dir.getChildFile (folderName);
  14379. #endif
  14380. #ifdef JUCE_LINUX
  14381. const File dir ((commonToAllUsers ? "/var/" : "~/")
  14382. + (folderName.isNotEmpty() ? folderName
  14383. : ("." + applicationName)));
  14384. #endif
  14385. #if JUCE_WIN32
  14386. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14387. : File::userApplicationDataDirectory));
  14388. if (dir == File::nonexistent)
  14389. return File::nonexistent;
  14390. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14391. : applicationName);
  14392. #endif
  14393. return dir.getChildFile (applicationName)
  14394. .withFileExtension (fileNameSuffix);
  14395. }
  14396. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14397. const String& fileNameSuffix,
  14398. const String& folderName,
  14399. const bool commonToAllUsers,
  14400. const int millisecondsBeforeSaving,
  14401. const int propertiesFileOptions)
  14402. {
  14403. const File file (getDefaultAppSettingsFile (applicationName,
  14404. fileNameSuffix,
  14405. folderName,
  14406. commonToAllUsers));
  14407. jassert (file != File::nonexistent);
  14408. if (file == File::nonexistent)
  14409. return 0;
  14410. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14411. }
  14412. END_JUCE_NAMESPACE
  14413. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14414. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14415. BEGIN_JUCE_NAMESPACE
  14416. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14417. const String& fileWildcard_,
  14418. const String& openFileDialogTitle_,
  14419. const String& saveFileDialogTitle_)
  14420. : changedSinceSave (false),
  14421. fileExtension (fileExtension_),
  14422. fileWildcard (fileWildcard_),
  14423. openFileDialogTitle (openFileDialogTitle_),
  14424. saveFileDialogTitle (saveFileDialogTitle_)
  14425. {
  14426. }
  14427. FileBasedDocument::~FileBasedDocument()
  14428. {
  14429. }
  14430. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14431. {
  14432. changedSinceSave = hasChanged;
  14433. }
  14434. void FileBasedDocument::changed()
  14435. {
  14436. changedSinceSave = true;
  14437. sendChangeMessage (this);
  14438. }
  14439. void FileBasedDocument::setFile (const File& newFile)
  14440. {
  14441. if (documentFile != newFile)
  14442. {
  14443. documentFile = newFile;
  14444. changedSinceSave = true;
  14445. }
  14446. }
  14447. bool FileBasedDocument::loadFrom (const File& newFile,
  14448. const bool showMessageOnFailure)
  14449. {
  14450. MouseCursor::showWaitCursor();
  14451. const File oldFile (documentFile);
  14452. documentFile = newFile;
  14453. String error;
  14454. if (newFile.existsAsFile())
  14455. {
  14456. error = loadDocument (newFile);
  14457. if (error.isEmpty())
  14458. {
  14459. setChangedFlag (false);
  14460. MouseCursor::hideWaitCursor();
  14461. setLastDocumentOpened (newFile);
  14462. return true;
  14463. }
  14464. }
  14465. else
  14466. {
  14467. error = "The file doesn't exist";
  14468. }
  14469. documentFile = oldFile;
  14470. MouseCursor::hideWaitCursor();
  14471. if (showMessageOnFailure)
  14472. {
  14473. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14474. TRANS("Failed to open file..."),
  14475. TRANS("There was an error while trying to load the file:\n\n")
  14476. + newFile.getFullPathName()
  14477. + "\n\n"
  14478. + error);
  14479. }
  14480. return false;
  14481. }
  14482. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14483. {
  14484. FileChooser fc (openFileDialogTitle,
  14485. getLastDocumentOpened(),
  14486. fileWildcard);
  14487. if (fc.browseForFileToOpen())
  14488. return loadFrom (fc.getResult(), showMessageOnFailure);
  14489. return false;
  14490. }
  14491. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14492. const bool showMessageOnFailure)
  14493. {
  14494. return saveAs (documentFile,
  14495. false,
  14496. askUserForFileIfNotSpecified,
  14497. showMessageOnFailure);
  14498. }
  14499. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14500. const bool warnAboutOverwritingExistingFiles,
  14501. const bool askUserForFileIfNotSpecified,
  14502. const bool showMessageOnFailure)
  14503. {
  14504. if (newFile == File::nonexistent)
  14505. {
  14506. if (askUserForFileIfNotSpecified)
  14507. {
  14508. return saveAsInteractive (true);
  14509. }
  14510. else
  14511. {
  14512. // can't save to an unspecified file
  14513. jassertfalse
  14514. return failedToWriteToFile;
  14515. }
  14516. }
  14517. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14518. {
  14519. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14520. TRANS("File already exists"),
  14521. TRANS("There's already a file called:\n\n")
  14522. + newFile.getFullPathName()
  14523. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14524. TRANS("overwrite"),
  14525. TRANS("cancel")))
  14526. {
  14527. return userCancelledSave;
  14528. }
  14529. }
  14530. MouseCursor::showWaitCursor();
  14531. const File oldFile (documentFile);
  14532. documentFile = newFile;
  14533. String error (saveDocument (newFile));
  14534. if (error.isEmpty())
  14535. {
  14536. setChangedFlag (false);
  14537. MouseCursor::hideWaitCursor();
  14538. return savedOk;
  14539. }
  14540. documentFile = oldFile;
  14541. MouseCursor::hideWaitCursor();
  14542. if (showMessageOnFailure)
  14543. {
  14544. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14545. TRANS("Error writing to file..."),
  14546. TRANS("An error occurred while trying to save \"")
  14547. + getDocumentTitle()
  14548. + TRANS("\" to the file:\n\n")
  14549. + newFile.getFullPathName()
  14550. + "\n\n"
  14551. + error);
  14552. }
  14553. return failedToWriteToFile;
  14554. }
  14555. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14556. {
  14557. if (! hasChangedSinceSaved())
  14558. return savedOk;
  14559. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14560. TRANS("Closing document..."),
  14561. TRANS("Do you want to save the changes to \"")
  14562. + getDocumentTitle() + "\"?",
  14563. TRANS("save"),
  14564. TRANS("discard changes"),
  14565. TRANS("cancel"));
  14566. if (r == 1)
  14567. {
  14568. // save changes
  14569. return save (true, true);
  14570. }
  14571. else if (r == 2)
  14572. {
  14573. // discard changes
  14574. return savedOk;
  14575. }
  14576. return userCancelledSave;
  14577. }
  14578. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14579. {
  14580. File f;
  14581. if (documentFile.existsAsFile())
  14582. f = documentFile;
  14583. else
  14584. f = getLastDocumentOpened();
  14585. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14586. if (legalFilename.isEmpty())
  14587. legalFilename = "unnamed";
  14588. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14589. f = f.getSiblingFile (legalFilename);
  14590. else
  14591. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14592. f = f.withFileExtension (fileExtension)
  14593. .getNonexistentSibling (true);
  14594. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14595. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14596. {
  14597. setLastDocumentOpened (fc.getResult());
  14598. File chosen (fc.getResult());
  14599. if (chosen.getFileExtension().isEmpty())
  14600. {
  14601. chosen = chosen.withFileExtension (fileExtension);
  14602. if (chosen.exists())
  14603. {
  14604. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14605. TRANS("File already exists"),
  14606. TRANS("There's already a file called:")
  14607. + "\n\n" + chosen.getFullPathName()
  14608. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  14609. TRANS("overwrite"),
  14610. TRANS("cancel")))
  14611. {
  14612. return userCancelledSave;
  14613. }
  14614. }
  14615. }
  14616. return saveAs (chosen, false, false, true);
  14617. }
  14618. return userCancelledSave;
  14619. }
  14620. END_JUCE_NAMESPACE
  14621. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14622. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14623. BEGIN_JUCE_NAMESPACE
  14624. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14625. : maxNumberOfItems (10)
  14626. {
  14627. }
  14628. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14629. {
  14630. }
  14631. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14632. {
  14633. maxNumberOfItems = jmax (1, newMaxNumber);
  14634. while (getNumFiles() > maxNumberOfItems)
  14635. files.remove (getNumFiles() - 1);
  14636. }
  14637. int RecentlyOpenedFilesList::getNumFiles() const
  14638. {
  14639. return files.size();
  14640. }
  14641. const File RecentlyOpenedFilesList::getFile (const int index) const
  14642. {
  14643. return File (files [index]);
  14644. }
  14645. void RecentlyOpenedFilesList::clear()
  14646. {
  14647. files.clear();
  14648. }
  14649. void RecentlyOpenedFilesList::addFile (const File& file)
  14650. {
  14651. const String path (file.getFullPathName());
  14652. files.removeString (path, true);
  14653. files.insert (0, path);
  14654. setMaxNumberOfItems (maxNumberOfItems);
  14655. }
  14656. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14657. {
  14658. for (int i = getNumFiles(); --i >= 0;)
  14659. if (! getFile(i).exists())
  14660. files.remove (i);
  14661. }
  14662. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14663. const int baseItemId,
  14664. const bool showFullPaths,
  14665. const bool dontAddNonExistentFiles,
  14666. const File** filesToAvoid)
  14667. {
  14668. int num = 0;
  14669. for (int i = 0; i < getNumFiles(); ++i)
  14670. {
  14671. const File f (getFile(i));
  14672. if ((! dontAddNonExistentFiles) || f.exists())
  14673. {
  14674. bool needsAvoiding = false;
  14675. if (filesToAvoid != 0)
  14676. {
  14677. const File** avoid = filesToAvoid;
  14678. while (*avoid != 0)
  14679. {
  14680. if (f == **avoid)
  14681. {
  14682. needsAvoiding = true;
  14683. break;
  14684. }
  14685. ++avoid;
  14686. }
  14687. }
  14688. if (! needsAvoiding)
  14689. {
  14690. menuToAddTo.addItem (baseItemId + i,
  14691. showFullPaths ? f.getFullPathName()
  14692. : f.getFileName());
  14693. ++num;
  14694. }
  14695. }
  14696. }
  14697. return num;
  14698. }
  14699. const String RecentlyOpenedFilesList::toString() const
  14700. {
  14701. return files.joinIntoString ("\n");
  14702. }
  14703. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14704. {
  14705. clear();
  14706. files.addLines (stringifiedVersion);
  14707. setMaxNumberOfItems (maxNumberOfItems);
  14708. }
  14709. END_JUCE_NAMESPACE
  14710. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14711. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14712. BEGIN_JUCE_NAMESPACE
  14713. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14714. const int minimumTransactions)
  14715. : totalUnitsStored (0),
  14716. nextIndex (0),
  14717. newTransaction (true),
  14718. reentrancyCheck (false)
  14719. {
  14720. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14721. minimumTransactions);
  14722. }
  14723. UndoManager::~UndoManager()
  14724. {
  14725. clearUndoHistory();
  14726. }
  14727. void UndoManager::clearUndoHistory()
  14728. {
  14729. transactions.clear();
  14730. transactionNames.clear();
  14731. totalUnitsStored = 0;
  14732. nextIndex = 0;
  14733. sendChangeMessage (this);
  14734. }
  14735. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14736. {
  14737. return totalUnitsStored;
  14738. }
  14739. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14740. const int minimumTransactions)
  14741. {
  14742. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14743. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14744. }
  14745. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14746. {
  14747. if (command != 0)
  14748. {
  14749. if (actionName.isNotEmpty())
  14750. currentTransactionName = actionName;
  14751. if (reentrancyCheck)
  14752. {
  14753. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14754. // undo() methods, or else these actions won't actually get done.
  14755. return false;
  14756. }
  14757. else
  14758. {
  14759. bool success = false;
  14760. JUCE_TRY
  14761. {
  14762. success = command->perform();
  14763. }
  14764. JUCE_CATCH_EXCEPTION
  14765. jassert (success);
  14766. if (success)
  14767. {
  14768. if (nextIndex > 0 && ! newTransaction)
  14769. {
  14770. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14771. jassert (commandSet != 0);
  14772. if (commandSet == 0)
  14773. return false;
  14774. commandSet->add (command);
  14775. }
  14776. else
  14777. {
  14778. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14779. commandSet->add (command);
  14780. transactions.insert (nextIndex, commandSet);
  14781. transactionNames.insert (nextIndex, currentTransactionName);
  14782. ++nextIndex;
  14783. }
  14784. totalUnitsStored += command->getSizeInUnits();
  14785. newTransaction = false;
  14786. }
  14787. while (nextIndex < transactions.size())
  14788. {
  14789. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14790. for (int i = lastSet->size(); --i >= 0;)
  14791. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14792. transactions.removeLast();
  14793. transactionNames.remove (transactionNames.size() - 1);
  14794. }
  14795. while (nextIndex > 0
  14796. && totalUnitsStored > maxNumUnitsToKeep
  14797. && transactions.size() > minimumTransactionsToKeep)
  14798. {
  14799. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14800. for (int i = firstSet->size(); --i >= 0;)
  14801. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14802. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14803. transactions.remove (0);
  14804. transactionNames.remove (0);
  14805. --nextIndex;
  14806. }
  14807. sendChangeMessage (this);
  14808. return success;
  14809. }
  14810. }
  14811. return false;
  14812. }
  14813. void UndoManager::beginNewTransaction (const String& actionName)
  14814. {
  14815. newTransaction = true;
  14816. currentTransactionName = actionName;
  14817. }
  14818. void UndoManager::setCurrentTransactionName (const String& newName)
  14819. {
  14820. currentTransactionName = newName;
  14821. }
  14822. bool UndoManager::canUndo() const
  14823. {
  14824. return nextIndex > 0;
  14825. }
  14826. bool UndoManager::canRedo() const
  14827. {
  14828. return nextIndex < transactions.size();
  14829. }
  14830. const String UndoManager::getUndoDescription() const
  14831. {
  14832. return transactionNames [nextIndex - 1];
  14833. }
  14834. const String UndoManager::getRedoDescription() const
  14835. {
  14836. return transactionNames [nextIndex];
  14837. }
  14838. bool UndoManager::undo()
  14839. {
  14840. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14841. if (commandSet == 0)
  14842. return false;
  14843. reentrancyCheck = true;
  14844. bool failed = false;
  14845. for (int i = commandSet->size(); --i >= 0;)
  14846. {
  14847. if (! commandSet->getUnchecked(i)->undo())
  14848. {
  14849. jassertfalse
  14850. failed = true;
  14851. break;
  14852. }
  14853. }
  14854. reentrancyCheck = false;
  14855. if (failed)
  14856. {
  14857. clearUndoHistory();
  14858. }
  14859. else
  14860. {
  14861. --nextIndex;
  14862. }
  14863. beginNewTransaction();
  14864. sendChangeMessage (this);
  14865. return true;
  14866. }
  14867. bool UndoManager::redo()
  14868. {
  14869. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14870. if (commandSet == 0)
  14871. return false;
  14872. reentrancyCheck = true;
  14873. bool failed = false;
  14874. for (int i = 0; i < commandSet->size(); ++i)
  14875. {
  14876. if (! commandSet->getUnchecked(i)->perform())
  14877. {
  14878. jassertfalse
  14879. failed = true;
  14880. break;
  14881. }
  14882. }
  14883. reentrancyCheck = false;
  14884. if (failed)
  14885. {
  14886. clearUndoHistory();
  14887. }
  14888. else
  14889. {
  14890. ++nextIndex;
  14891. }
  14892. beginNewTransaction();
  14893. sendChangeMessage (this);
  14894. return true;
  14895. }
  14896. bool UndoManager::undoCurrentTransactionOnly()
  14897. {
  14898. return newTransaction ? false
  14899. : undo();
  14900. }
  14901. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  14902. {
  14903. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14904. if (commandSet != 0 && ! newTransaction)
  14905. {
  14906. for (int i = 0; i < commandSet->size(); ++i)
  14907. actionsFound.add (commandSet->getUnchecked(i));
  14908. }
  14909. }
  14910. int UndoManager::getNumActionsInCurrentTransaction() const
  14911. {
  14912. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14913. if (commandSet != 0 && ! newTransaction)
  14914. return commandSet->size();
  14915. return 0;
  14916. }
  14917. END_JUCE_NAMESPACE
  14918. /*** End of inlined file: juce_UndoManager.cpp ***/
  14919. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  14920. BEGIN_JUCE_NAMESPACE
  14921. static const char* const aiffFormatName = "AIFF file";
  14922. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  14923. class AiffAudioFormatReader : public AudioFormatReader
  14924. {
  14925. public:
  14926. int bytesPerFrame;
  14927. int64 dataChunkStart;
  14928. bool littleEndian;
  14929. AiffAudioFormatReader (InputStream* in)
  14930. : AudioFormatReader (in, TRANS (aiffFormatName))
  14931. {
  14932. if (input->readInt() == chunkName ("FORM"))
  14933. {
  14934. const int len = input->readIntBigEndian();
  14935. const int64 end = input->getPosition() + len;
  14936. const int nextType = input->readInt();
  14937. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  14938. {
  14939. bool hasGotVer = false;
  14940. bool hasGotData = false;
  14941. bool hasGotType = false;
  14942. while (input->getPosition() < end)
  14943. {
  14944. const int type = input->readInt();
  14945. const uint32 length = (uint32) input->readIntBigEndian();
  14946. const int64 chunkEnd = input->getPosition() + length;
  14947. if (type == chunkName ("FVER"))
  14948. {
  14949. hasGotVer = true;
  14950. const int ver = input->readIntBigEndian();
  14951. if (ver != 0 && ver != (int)0xa2805140)
  14952. break;
  14953. }
  14954. else if (type == chunkName ("COMM"))
  14955. {
  14956. hasGotType = true;
  14957. numChannels = (unsigned int)input->readShortBigEndian();
  14958. lengthInSamples = input->readIntBigEndian();
  14959. bitsPerSample = input->readShortBigEndian();
  14960. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  14961. unsigned char sampleRateBytes[10];
  14962. input->read (sampleRateBytes, 10);
  14963. const int byte0 = sampleRateBytes[0];
  14964. if ((byte0 & 0x80) != 0
  14965. || byte0 <= 0x3F || byte0 > 0x40
  14966. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  14967. break;
  14968. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  14969. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  14970. sampleRate = (int) sampRate;
  14971. if (length <= 18)
  14972. {
  14973. // some types don't have a chunk large enough to include a compression
  14974. // type, so assume it's just big-endian pcm
  14975. littleEndian = false;
  14976. }
  14977. else
  14978. {
  14979. const int compType = input->readInt();
  14980. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  14981. {
  14982. littleEndian = false;
  14983. }
  14984. else if (compType == chunkName ("sowt"))
  14985. {
  14986. littleEndian = true;
  14987. }
  14988. else
  14989. {
  14990. sampleRate = 0;
  14991. break;
  14992. }
  14993. }
  14994. }
  14995. else if (type == chunkName ("SSND"))
  14996. {
  14997. hasGotData = true;
  14998. const int offset = input->readIntBigEndian();
  14999. dataChunkStart = input->getPosition() + 4 + offset;
  15000. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15001. }
  15002. else if ((hasGotVer && hasGotData && hasGotType)
  15003. || chunkEnd < input->getPosition()
  15004. || input->isExhausted())
  15005. {
  15006. break;
  15007. }
  15008. input->setPosition (chunkEnd);
  15009. }
  15010. }
  15011. }
  15012. }
  15013. ~AiffAudioFormatReader()
  15014. {
  15015. }
  15016. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15017. int64 startSampleInFile, int numSamples)
  15018. {
  15019. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15020. if (samplesAvailable < numSamples)
  15021. {
  15022. for (int i = numDestChannels; --i >= 0;)
  15023. if (destSamples[i] != 0)
  15024. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15025. numSamples = (int) samplesAvailable;
  15026. }
  15027. if (numSamples <= 0)
  15028. return true;
  15029. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15030. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15031. char tempBuffer [tempBufSize];
  15032. while (numSamples > 0)
  15033. {
  15034. int* left = destSamples[0];
  15035. if (left != 0)
  15036. left += startOffsetInDestBuffer;
  15037. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15038. if (right != 0)
  15039. right += startOffsetInDestBuffer;
  15040. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15041. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15042. if (bytesRead < numThisTime * bytesPerFrame)
  15043. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15044. if (bitsPerSample == 16)
  15045. {
  15046. if (littleEndian)
  15047. {
  15048. const short* src = (const short*) tempBuffer;
  15049. if (numChannels > 1)
  15050. {
  15051. if (left == 0)
  15052. {
  15053. for (int i = numThisTime; --i >= 0;)
  15054. {
  15055. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15056. ++src;
  15057. }
  15058. }
  15059. else if (right == 0)
  15060. {
  15061. for (int i = numThisTime; --i >= 0;)
  15062. {
  15063. ++src;
  15064. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15065. }
  15066. }
  15067. else
  15068. {
  15069. for (int i = numThisTime; --i >= 0;)
  15070. {
  15071. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15072. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15073. }
  15074. }
  15075. }
  15076. else
  15077. {
  15078. for (int i = numThisTime; --i >= 0;)
  15079. {
  15080. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15081. }
  15082. }
  15083. }
  15084. else
  15085. {
  15086. const char* src = (const char*) tempBuffer;
  15087. if (numChannels > 1)
  15088. {
  15089. if (left == 0)
  15090. {
  15091. for (int i = numThisTime; --i >= 0;)
  15092. {
  15093. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15094. src += 4;
  15095. }
  15096. }
  15097. else if (right == 0)
  15098. {
  15099. for (int i = numThisTime; --i >= 0;)
  15100. {
  15101. src += 2;
  15102. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15103. src += 2;
  15104. }
  15105. }
  15106. else
  15107. {
  15108. for (int i = numThisTime; --i >= 0;)
  15109. {
  15110. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15111. src += 2;
  15112. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15113. src += 2;
  15114. }
  15115. }
  15116. }
  15117. else
  15118. {
  15119. for (int i = numThisTime; --i >= 0;)
  15120. {
  15121. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15122. src += 2;
  15123. }
  15124. }
  15125. }
  15126. }
  15127. else if (bitsPerSample == 24)
  15128. {
  15129. const char* src = (const char*)tempBuffer;
  15130. if (littleEndian)
  15131. {
  15132. if (numChannels > 1)
  15133. {
  15134. if (left == 0)
  15135. {
  15136. for (int i = numThisTime; --i >= 0;)
  15137. {
  15138. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15139. src += 6;
  15140. }
  15141. }
  15142. else if (right == 0)
  15143. {
  15144. for (int i = numThisTime; --i >= 0;)
  15145. {
  15146. src += 3;
  15147. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15148. src += 3;
  15149. }
  15150. }
  15151. else
  15152. {
  15153. for (int i = numThisTime; --i >= 0;)
  15154. {
  15155. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15156. src += 3;
  15157. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15158. src += 3;
  15159. }
  15160. }
  15161. }
  15162. else
  15163. {
  15164. for (int i = numThisTime; --i >= 0;)
  15165. {
  15166. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15167. src += 3;
  15168. }
  15169. }
  15170. }
  15171. else
  15172. {
  15173. if (numChannels > 1)
  15174. {
  15175. if (left == 0)
  15176. {
  15177. for (int i = numThisTime; --i >= 0;)
  15178. {
  15179. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15180. src += 6;
  15181. }
  15182. }
  15183. else if (right == 0)
  15184. {
  15185. for (int i = numThisTime; --i >= 0;)
  15186. {
  15187. src += 3;
  15188. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15189. src += 3;
  15190. }
  15191. }
  15192. else
  15193. {
  15194. for (int i = numThisTime; --i >= 0;)
  15195. {
  15196. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15197. src += 3;
  15198. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15199. src += 3;
  15200. }
  15201. }
  15202. }
  15203. else
  15204. {
  15205. for (int i = numThisTime; --i >= 0;)
  15206. {
  15207. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15208. src += 3;
  15209. }
  15210. }
  15211. }
  15212. }
  15213. else if (bitsPerSample == 32)
  15214. {
  15215. const unsigned int* src = (const unsigned int*) tempBuffer;
  15216. unsigned int* l = (unsigned int*) left;
  15217. unsigned int* r = (unsigned int*) right;
  15218. if (littleEndian)
  15219. {
  15220. if (numChannels > 1)
  15221. {
  15222. if (l == 0)
  15223. {
  15224. for (int i = numThisTime; --i >= 0;)
  15225. {
  15226. ++src;
  15227. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15228. }
  15229. }
  15230. else if (r == 0)
  15231. {
  15232. for (int i = numThisTime; --i >= 0;)
  15233. {
  15234. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15235. ++src;
  15236. }
  15237. }
  15238. else
  15239. {
  15240. for (int i = numThisTime; --i >= 0;)
  15241. {
  15242. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15243. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15244. }
  15245. }
  15246. }
  15247. else
  15248. {
  15249. for (int i = numThisTime; --i >= 0;)
  15250. {
  15251. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15252. }
  15253. }
  15254. }
  15255. else
  15256. {
  15257. if (numChannels > 1)
  15258. {
  15259. if (l == 0)
  15260. {
  15261. for (int i = numThisTime; --i >= 0;)
  15262. {
  15263. ++src;
  15264. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15265. }
  15266. }
  15267. else if (r == 0)
  15268. {
  15269. for (int i = numThisTime; --i >= 0;)
  15270. {
  15271. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15272. ++src;
  15273. }
  15274. }
  15275. else
  15276. {
  15277. for (int i = numThisTime; --i >= 0;)
  15278. {
  15279. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15280. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15281. }
  15282. }
  15283. }
  15284. else
  15285. {
  15286. for (int i = numThisTime; --i >= 0;)
  15287. {
  15288. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15289. }
  15290. }
  15291. }
  15292. left = (int*) l;
  15293. right = (int*) r;
  15294. }
  15295. else if (bitsPerSample == 8)
  15296. {
  15297. const char* src = (const char*) tempBuffer;
  15298. if (numChannels > 1)
  15299. {
  15300. if (left == 0)
  15301. {
  15302. for (int i = numThisTime; --i >= 0;)
  15303. {
  15304. *right++ = ((int) *src++) << 24;
  15305. ++src;
  15306. }
  15307. }
  15308. else if (right == 0)
  15309. {
  15310. for (int i = numThisTime; --i >= 0;)
  15311. {
  15312. ++src;
  15313. *left++ = ((int) *src++) << 24;
  15314. }
  15315. }
  15316. else
  15317. {
  15318. for (int i = numThisTime; --i >= 0;)
  15319. {
  15320. *left++ = ((int) *src++) << 24;
  15321. *right++ = ((int) *src++) << 24;
  15322. }
  15323. }
  15324. }
  15325. else
  15326. {
  15327. for (int i = numThisTime; --i >= 0;)
  15328. {
  15329. *left++ = ((int) *src++) << 24;
  15330. }
  15331. }
  15332. }
  15333. startOffsetInDestBuffer += numThisTime;
  15334. numSamples -= numThisTime;
  15335. }
  15336. if (numSamples > 0)
  15337. {
  15338. for (int i = numDestChannels; --i >= 0;)
  15339. if (destSamples[i] != 0)
  15340. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15341. sizeof (int) * numSamples);
  15342. }
  15343. return true;
  15344. }
  15345. juce_UseDebuggingNewOperator
  15346. private:
  15347. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15348. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15349. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15350. };
  15351. class AiffAudioFormatWriter : public AudioFormatWriter
  15352. {
  15353. MemoryBlock tempBlock;
  15354. uint32 lengthInSamples, bytesWritten;
  15355. int64 headerPosition;
  15356. bool writeFailed;
  15357. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15358. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15359. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15360. void writeHeader()
  15361. {
  15362. const bool couldSeekOk = output->setPosition (headerPosition);
  15363. (void) couldSeekOk;
  15364. // if this fails, you've given it an output stream that can't seek! It needs
  15365. // to be able to seek back to write the header
  15366. jassert (couldSeekOk);
  15367. const int headerLen = 54;
  15368. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15369. audioBytes += (audioBytes & 1);
  15370. output->writeInt (chunkName ("FORM"));
  15371. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15372. output->writeInt (chunkName ("AIFF"));
  15373. output->writeInt (chunkName ("COMM"));
  15374. output->writeIntBigEndian (18);
  15375. output->writeShortBigEndian ((short) numChannels);
  15376. output->writeIntBigEndian (lengthInSamples);
  15377. output->writeShortBigEndian ((short) bitsPerSample);
  15378. uint8 sampleRateBytes[10];
  15379. zeromem (sampleRateBytes, 10);
  15380. if (sampleRate <= 1)
  15381. {
  15382. sampleRateBytes[0] = 0x3f;
  15383. sampleRateBytes[1] = 0xff;
  15384. sampleRateBytes[2] = 0x80;
  15385. }
  15386. else
  15387. {
  15388. int mask = 0x40000000;
  15389. sampleRateBytes[0] = 0x40;
  15390. if (sampleRate >= mask)
  15391. {
  15392. jassertfalse
  15393. sampleRateBytes[1] = 0x1d;
  15394. }
  15395. else
  15396. {
  15397. int n = (int) sampleRate;
  15398. int i;
  15399. for (i = 0; i <= 32 ; ++i)
  15400. {
  15401. if ((n & mask) != 0)
  15402. break;
  15403. mask >>= 1;
  15404. }
  15405. n = n << (i + 1);
  15406. sampleRateBytes[1] = (uint8) (29 - i);
  15407. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15408. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15409. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15410. sampleRateBytes[5] = (uint8) (n & 0xff);
  15411. }
  15412. }
  15413. output->write (sampleRateBytes, 10);
  15414. output->writeInt (chunkName ("SSND"));
  15415. output->writeIntBigEndian (audioBytes + 8);
  15416. output->writeInt (0);
  15417. output->writeInt (0);
  15418. jassert (output->getPosition() == headerLen);
  15419. }
  15420. public:
  15421. AiffAudioFormatWriter (OutputStream* out,
  15422. const double sampleRate_,
  15423. const unsigned int chans,
  15424. const int bits)
  15425. : AudioFormatWriter (out,
  15426. TRANS (aiffFormatName),
  15427. sampleRate_,
  15428. chans,
  15429. bits),
  15430. lengthInSamples (0),
  15431. bytesWritten (0),
  15432. writeFailed (false)
  15433. {
  15434. headerPosition = out->getPosition();
  15435. writeHeader();
  15436. }
  15437. ~AiffAudioFormatWriter()
  15438. {
  15439. if ((bytesWritten & 1) != 0)
  15440. output->writeByte (0);
  15441. writeHeader();
  15442. }
  15443. bool write (const int** data, int numSamples)
  15444. {
  15445. if (writeFailed)
  15446. return false;
  15447. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15448. tempBlock.ensureSize (bytes, false);
  15449. char* buffer = (char*) tempBlock.getData();
  15450. const int* left = data[0];
  15451. const int* right = data[1];
  15452. if (right == 0)
  15453. right = left;
  15454. if (bitsPerSample == 16)
  15455. {
  15456. short* b = (short*) buffer;
  15457. if (numChannels > 1)
  15458. {
  15459. for (int i = numSamples; --i >= 0;)
  15460. {
  15461. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15462. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15463. }
  15464. }
  15465. else
  15466. {
  15467. for (int i = numSamples; --i >= 0;)
  15468. {
  15469. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15470. }
  15471. }
  15472. }
  15473. else if (bitsPerSample == 24)
  15474. {
  15475. char* b = (char*) buffer;
  15476. if (numChannels > 1)
  15477. {
  15478. for (int i = numSamples; --i >= 0;)
  15479. {
  15480. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15481. b += 3;
  15482. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15483. b += 3;
  15484. }
  15485. }
  15486. else
  15487. {
  15488. for (int i = numSamples; --i >= 0;)
  15489. {
  15490. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15491. b += 3;
  15492. }
  15493. }
  15494. }
  15495. else if (bitsPerSample == 32)
  15496. {
  15497. uint32* b = (uint32*) buffer;
  15498. if (numChannels > 1)
  15499. {
  15500. for (int i = numSamples; --i >= 0;)
  15501. {
  15502. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15503. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15504. }
  15505. }
  15506. else
  15507. {
  15508. for (int i = numSamples; --i >= 0;)
  15509. {
  15510. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15511. }
  15512. }
  15513. }
  15514. else if (bitsPerSample == 8)
  15515. {
  15516. char* b = (char*) buffer;
  15517. if (numChannels > 1)
  15518. {
  15519. for (int i = numSamples; --i >= 0;)
  15520. {
  15521. *b++ = (char) (*left++ >> 24);
  15522. *b++ = (char) (*right++ >> 24);
  15523. }
  15524. }
  15525. else
  15526. {
  15527. for (int i = numSamples; --i >= 0;)
  15528. {
  15529. *b++ = (char) (*left++ >> 24);
  15530. }
  15531. }
  15532. }
  15533. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15534. || ! output->write (buffer, bytes))
  15535. {
  15536. // failed to write to disk, so let's try writing the header.
  15537. // If it's just run out of disk space, then if it does manage
  15538. // to write the header, we'll still have a useable file..
  15539. writeHeader();
  15540. writeFailed = true;
  15541. return false;
  15542. }
  15543. else
  15544. {
  15545. bytesWritten += bytes;
  15546. lengthInSamples += numSamples;
  15547. return true;
  15548. }
  15549. }
  15550. juce_UseDebuggingNewOperator
  15551. };
  15552. AiffAudioFormat::AiffAudioFormat()
  15553. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15554. {
  15555. }
  15556. AiffAudioFormat::~AiffAudioFormat()
  15557. {
  15558. }
  15559. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15560. {
  15561. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15562. return Array <int> (rates);
  15563. }
  15564. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15565. {
  15566. const int depths[] = { 8, 16, 24, 0 };
  15567. return Array <int> (depths);
  15568. }
  15569. bool AiffAudioFormat::canDoStereo()
  15570. {
  15571. return true;
  15572. }
  15573. bool AiffAudioFormat::canDoMono()
  15574. {
  15575. return true;
  15576. }
  15577. #if JUCE_MAC
  15578. bool AiffAudioFormat::canHandleFile (const File& f)
  15579. {
  15580. if (AudioFormat::canHandleFile (f))
  15581. return true;
  15582. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15583. return type == 'AIFF' || type == 'AIFC'
  15584. || type == 'aiff' || type == 'aifc';
  15585. }
  15586. #endif
  15587. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15588. const bool deleteStreamIfOpeningFails)
  15589. {
  15590. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15591. if (w->sampleRate != 0)
  15592. return w.release();
  15593. if (! deleteStreamIfOpeningFails)
  15594. w->input = 0;
  15595. return 0;
  15596. }
  15597. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15598. double sampleRate,
  15599. unsigned int chans,
  15600. int bitsPerSample,
  15601. const StringPairArray& /*metadataValues*/,
  15602. int /*qualityOptionIndex*/)
  15603. {
  15604. if (getPossibleBitDepths().contains (bitsPerSample))
  15605. {
  15606. return new AiffAudioFormatWriter (out,
  15607. sampleRate,
  15608. chans,
  15609. bitsPerSample);
  15610. }
  15611. return 0;
  15612. }
  15613. END_JUCE_NAMESPACE
  15614. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15615. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15616. BEGIN_JUCE_NAMESPACE
  15617. #if JUCE_MAC && JUCE_USE_CDREADER
  15618. // Mac version doesn't need any native code because it's all done with files..
  15619. // Windows + Linux versions are in the platform-dependent code sections.
  15620. static void findCDs (Array<File>& cds)
  15621. {
  15622. File volumes ("/Volumes");
  15623. volumes.findChildFiles (cds, File::findDirectories, false);
  15624. for (int i = cds.size(); --i >= 0;)
  15625. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15626. cds.remove (i);
  15627. }
  15628. const StringArray AudioCDReader::getAvailableCDNames()
  15629. {
  15630. Array<File> cds;
  15631. findCDs (cds);
  15632. StringArray names;
  15633. for (int i = 0; i < cds.size(); ++i)
  15634. names.add (cds.getReference(i).getFileName());
  15635. return names;
  15636. }
  15637. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15638. {
  15639. Array<File> cds;
  15640. findCDs (cds);
  15641. if (cds[index] != File::nonexistent)
  15642. return new AudioCDReader (cds[index]);
  15643. else
  15644. return 0;
  15645. }
  15646. AudioCDReader::AudioCDReader (const File& volume)
  15647. : AudioFormatReader (0, "CD Audio"),
  15648. volumeDir (volume),
  15649. currentReaderTrack (-1),
  15650. reader (0)
  15651. {
  15652. sampleRate = 44100.0;
  15653. bitsPerSample = 16;
  15654. numChannels = 2;
  15655. usesFloatingPointData = false;
  15656. refreshTrackLengths();
  15657. }
  15658. AudioCDReader::~AudioCDReader()
  15659. {
  15660. }
  15661. static int getTrackNumber (const File& file)
  15662. {
  15663. return file.getFileName()
  15664. .initialSectionContainingOnly ("0123456789")
  15665. .getIntValue();
  15666. }
  15667. int AudioCDReader::compareElements (const File& first, const File& second)
  15668. {
  15669. const int firstTrack = getTrackNumber (first);
  15670. const int secondTrack = getTrackNumber (second);
  15671. jassert (firstTrack > 0 && secondTrack > 0);
  15672. return firstTrack - secondTrack;
  15673. }
  15674. void AudioCDReader::refreshTrackLengths()
  15675. {
  15676. tracks.clear();
  15677. trackStartSamples.clear();
  15678. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, "*.aiff");
  15679. tracks.sort (*this);
  15680. AiffAudioFormat format;
  15681. int sample = 0;
  15682. for (int i = 0; i < tracks.size(); ++i)
  15683. {
  15684. trackStartSamples.add (sample);
  15685. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15686. if (in != 0)
  15687. {
  15688. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15689. if (r != 0)
  15690. sample += (int) r->lengthInSamples;
  15691. }
  15692. }
  15693. trackStartSamples.add (sample);
  15694. lengthInSamples = sample;
  15695. }
  15696. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15697. int64 startSampleInFile, int numSamples)
  15698. {
  15699. while (numSamples > 0)
  15700. {
  15701. int track = -1;
  15702. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15703. {
  15704. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15705. {
  15706. track = i;
  15707. break;
  15708. }
  15709. }
  15710. if (track < 0)
  15711. return false;
  15712. if (track != currentReaderTrack)
  15713. {
  15714. reader = 0;
  15715. FileInputStream* const in = tracks [track].createInputStream();
  15716. if (in != 0)
  15717. {
  15718. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15719. AiffAudioFormat format;
  15720. reader = format.createReaderFor (bin, true);
  15721. if (reader == 0)
  15722. currentReaderTrack = -1;
  15723. else
  15724. currentReaderTrack = track;
  15725. }
  15726. }
  15727. if (reader == 0)
  15728. return false;
  15729. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15730. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15731. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15732. numSamples -= numAvailable;
  15733. startSampleInFile += numAvailable;
  15734. }
  15735. return true;
  15736. }
  15737. bool AudioCDReader::isCDStillPresent() const
  15738. {
  15739. return volumeDir.exists();
  15740. }
  15741. int AudioCDReader::getNumTracks() const
  15742. {
  15743. return tracks.size();
  15744. }
  15745. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15746. {
  15747. return trackStartSamples [trackNum];
  15748. }
  15749. bool AudioCDReader::isTrackAudio (int trackNum) const
  15750. {
  15751. return tracks [trackNum] != File::nonexistent;
  15752. }
  15753. void AudioCDReader::enableIndexScanning (bool b)
  15754. {
  15755. // any way to do this on a Mac??
  15756. }
  15757. int AudioCDReader::getLastIndex() const
  15758. {
  15759. return 0;
  15760. }
  15761. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15762. {
  15763. return Array <int>();
  15764. }
  15765. int AudioCDReader::getCDDBId()
  15766. {
  15767. return 0; //xxx
  15768. }
  15769. #endif
  15770. END_JUCE_NAMESPACE
  15771. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15772. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15773. BEGIN_JUCE_NAMESPACE
  15774. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15775. const String& formatName_)
  15776. : sampleRate (0),
  15777. bitsPerSample (0),
  15778. lengthInSamples (0),
  15779. numChannels (0),
  15780. usesFloatingPointData (false),
  15781. input (in),
  15782. formatName (formatName_)
  15783. {
  15784. }
  15785. AudioFormatReader::~AudioFormatReader()
  15786. {
  15787. delete input;
  15788. }
  15789. bool AudioFormatReader::read (int** destSamples,
  15790. int numDestChannels,
  15791. int64 startSampleInSource,
  15792. int numSamplesToRead,
  15793. const bool fillLeftoverChannelsWithCopies)
  15794. {
  15795. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15796. int startOffsetInDestBuffer = 0;
  15797. if (startSampleInSource < 0)
  15798. {
  15799. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15800. for (int i = numDestChannels; --i >= 0;)
  15801. if (destSamples[i] != 0)
  15802. zeromem (destSamples[i], sizeof (int) * silence);
  15803. startOffsetInDestBuffer += silence;
  15804. numSamplesToRead -= silence;
  15805. startSampleInSource = 0;
  15806. }
  15807. if (numSamplesToRead <= 0)
  15808. return true;
  15809. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15810. startSampleInSource, numSamplesToRead))
  15811. return false;
  15812. if (numDestChannels > (int) numChannels)
  15813. {
  15814. if (fillLeftoverChannelsWithCopies)
  15815. {
  15816. int* lastFullChannel = destSamples[0];
  15817. for (int i = numDestChannels; --i > 0;)
  15818. {
  15819. if (destSamples[i] != 0)
  15820. {
  15821. lastFullChannel = destSamples[i];
  15822. break;
  15823. }
  15824. }
  15825. if (lastFullChannel != 0)
  15826. for (int i = numChannels; i < numDestChannels; ++i)
  15827. if (destSamples[i] != 0)
  15828. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15829. }
  15830. else
  15831. {
  15832. for (int i = numChannels; i < numDestChannels; ++i)
  15833. if (destSamples[i] != 0)
  15834. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15835. }
  15836. }
  15837. return true;
  15838. }
  15839. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15840. {
  15841. float mn = buffer[0];
  15842. float mx = mn;
  15843. for (int i = 1; i < num; ++i)
  15844. {
  15845. const float s = buffer[i];
  15846. if (s > mx) mx = s;
  15847. if (s < mn) mn = s;
  15848. }
  15849. maxVal = mx;
  15850. minVal = mn;
  15851. }
  15852. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15853. int64 numSamples,
  15854. float& lowestLeft, float& highestLeft,
  15855. float& lowestRight, float& highestRight)
  15856. {
  15857. if (numSamples <= 0)
  15858. {
  15859. lowestLeft = 0;
  15860. lowestRight = 0;
  15861. highestLeft = 0;
  15862. highestRight = 0;
  15863. return;
  15864. }
  15865. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15866. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15867. int* tempBuffer[3];
  15868. tempBuffer[0] = (int*) tempSpace.getData();
  15869. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15870. tempBuffer[2] = 0;
  15871. if (usesFloatingPointData)
  15872. {
  15873. float lmin = 1.0e6f;
  15874. float lmax = -lmin;
  15875. float rmin = lmin;
  15876. float rmax = lmax;
  15877. while (numSamples > 0)
  15878. {
  15879. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15880. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15881. numSamples -= numToDo;
  15882. startSampleInFile += numToDo;
  15883. float bufmin, bufmax;
  15884. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  15885. lmin = jmin (lmin, bufmin);
  15886. lmax = jmax (lmax, bufmax);
  15887. if (numChannels > 1)
  15888. {
  15889. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  15890. rmin = jmin (rmin, bufmin);
  15891. rmax = jmax (rmax, bufmax);
  15892. }
  15893. }
  15894. if (numChannels <= 1)
  15895. {
  15896. rmax = lmax;
  15897. rmin = lmin;
  15898. }
  15899. lowestLeft = lmin;
  15900. highestLeft = lmax;
  15901. lowestRight = rmin;
  15902. highestRight = rmax;
  15903. }
  15904. else
  15905. {
  15906. int lmax = std::numeric_limits<int>::min();
  15907. int lmin = std::numeric_limits<int>::max();
  15908. int rmax = std::numeric_limits<int>::min();
  15909. int rmin = std::numeric_limits<int>::max();
  15910. while (numSamples > 0)
  15911. {
  15912. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15913. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15914. numSamples -= numToDo;
  15915. startSampleInFile += numToDo;
  15916. for (int j = numChannels; --j >= 0;)
  15917. {
  15918. int bufMax = std::numeric_limits<int>::min();
  15919. int bufMin = std::numeric_limits<int>::max();
  15920. const int* const b = tempBuffer[j];
  15921. for (int i = 0; i < numToDo; ++i)
  15922. {
  15923. const int samp = b[i];
  15924. if (samp < bufMin)
  15925. bufMin = samp;
  15926. if (samp > bufMax)
  15927. bufMax = samp;
  15928. }
  15929. if (j == 0)
  15930. {
  15931. lmax = jmax (lmax, bufMax);
  15932. lmin = jmin (lmin, bufMin);
  15933. }
  15934. else
  15935. {
  15936. rmax = jmax (rmax, bufMax);
  15937. rmin = jmin (rmin, bufMin);
  15938. }
  15939. }
  15940. }
  15941. if (numChannels <= 1)
  15942. {
  15943. rmax = lmax;
  15944. rmin = lmin;
  15945. }
  15946. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  15947. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  15948. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  15949. highestRight = rmax / (float) std::numeric_limits<int>::max();
  15950. }
  15951. }
  15952. int64 AudioFormatReader::searchForLevel (int64 startSample,
  15953. int64 numSamplesToSearch,
  15954. const double magnitudeRangeMinimum,
  15955. const double magnitudeRangeMaximum,
  15956. const int minimumConsecutiveSamples)
  15957. {
  15958. if (numSamplesToSearch == 0)
  15959. return -1;
  15960. const int bufferSize = 4096;
  15961. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15962. int* tempBuffer[3];
  15963. tempBuffer[0] = (int*) tempSpace.getData();
  15964. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15965. tempBuffer[2] = 0;
  15966. int consecutive = 0;
  15967. int64 firstMatchPos = -1;
  15968. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  15969. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  15970. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  15971. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  15972. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  15973. while (numSamplesToSearch != 0)
  15974. {
  15975. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  15976. int64 bufferStart = startSample;
  15977. if (numSamplesToSearch < 0)
  15978. bufferStart -= numThisTime;
  15979. if (bufferStart >= (int) lengthInSamples)
  15980. break;
  15981. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  15982. int num = numThisTime;
  15983. while (--num >= 0)
  15984. {
  15985. if (numSamplesToSearch < 0)
  15986. --startSample;
  15987. bool matches = false;
  15988. const int index = (int) (startSample - bufferStart);
  15989. if (usesFloatingPointData)
  15990. {
  15991. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  15992. if (sample1 >= magnitudeRangeMinimum
  15993. && sample1 <= magnitudeRangeMaximum)
  15994. {
  15995. matches = true;
  15996. }
  15997. else if (numChannels > 1)
  15998. {
  15999. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16000. matches = (sample2 >= magnitudeRangeMinimum
  16001. && sample2 <= magnitudeRangeMaximum);
  16002. }
  16003. }
  16004. else
  16005. {
  16006. const int sample1 = abs (tempBuffer[0] [index]);
  16007. if (sample1 >= intMagnitudeRangeMinimum
  16008. && sample1 <= intMagnitudeRangeMaximum)
  16009. {
  16010. matches = true;
  16011. }
  16012. else if (numChannels > 1)
  16013. {
  16014. const int sample2 = abs (tempBuffer[1][index]);
  16015. matches = (sample2 >= intMagnitudeRangeMinimum
  16016. && sample2 <= intMagnitudeRangeMaximum);
  16017. }
  16018. }
  16019. if (matches)
  16020. {
  16021. if (firstMatchPos < 0)
  16022. firstMatchPos = startSample;
  16023. if (++consecutive >= minimumConsecutiveSamples)
  16024. {
  16025. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16026. return -1;
  16027. return firstMatchPos;
  16028. }
  16029. }
  16030. else
  16031. {
  16032. consecutive = 0;
  16033. firstMatchPos = -1;
  16034. }
  16035. if (numSamplesToSearch > 0)
  16036. ++startSample;
  16037. }
  16038. if (numSamplesToSearch > 0)
  16039. numSamplesToSearch -= numThisTime;
  16040. else
  16041. numSamplesToSearch += numThisTime;
  16042. }
  16043. return -1;
  16044. }
  16045. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16046. const String& formatName_,
  16047. const double rate,
  16048. const unsigned int numChannels_,
  16049. const unsigned int bitsPerSample_)
  16050. : sampleRate (rate),
  16051. numChannels (numChannels_),
  16052. bitsPerSample (bitsPerSample_),
  16053. usesFloatingPointData (false),
  16054. output (out),
  16055. formatName (formatName_)
  16056. {
  16057. }
  16058. AudioFormatWriter::~AudioFormatWriter()
  16059. {
  16060. delete output;
  16061. }
  16062. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16063. int64 startSample,
  16064. int64 numSamplesToRead)
  16065. {
  16066. const int bufferSize = 16384;
  16067. const int maxChans = 128;
  16068. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16069. int* buffers [maxChans];
  16070. for (int i = maxChans; --i >= 0;)
  16071. buffers[i] = 0;
  16072. if (numSamplesToRead < 0)
  16073. numSamplesToRead = reader.lengthInSamples;
  16074. while (numSamplesToRead > 0)
  16075. {
  16076. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16077. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16078. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16079. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16080. return false;
  16081. if (reader.usesFloatingPointData != isFloatingPoint())
  16082. {
  16083. int** bufferChan = buffers;
  16084. while (*bufferChan != 0)
  16085. {
  16086. int* b = *bufferChan++;
  16087. if (isFloatingPoint())
  16088. {
  16089. // int -> float
  16090. const double factor = 1.0 / std::numeric_limits<int>::max();
  16091. for (int i = 0; i < numToDo; ++i)
  16092. ((float*) b)[i] = (float) (factor * b[i]);
  16093. }
  16094. else
  16095. {
  16096. // float -> int
  16097. for (int i = 0; i < numToDo; ++i)
  16098. {
  16099. const double samp = *(const float*) b;
  16100. if (samp <= -1.0)
  16101. *b++ = std::numeric_limits<int>::min();
  16102. else if (samp >= 1.0)
  16103. *b++ = std::numeric_limits<int>::max();
  16104. else
  16105. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16106. }
  16107. }
  16108. }
  16109. }
  16110. if (! write ((const int**) buffers, numToDo))
  16111. return false;
  16112. numSamplesToRead -= numToDo;
  16113. startSample += numToDo;
  16114. }
  16115. return true;
  16116. }
  16117. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16118. int numSamplesToRead,
  16119. const int samplesPerBlock)
  16120. {
  16121. const int maxChans = 128;
  16122. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16123. int* buffers [maxChans];
  16124. while (numSamplesToRead > 0)
  16125. {
  16126. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16127. AudioSourceChannelInfo info;
  16128. info.buffer = &tempBuffer;
  16129. info.startSample = 0;
  16130. info.numSamples = numToDo;
  16131. info.clearActiveBufferRegion();
  16132. source.getNextAudioBlock (info);
  16133. int i;
  16134. for (i = maxChans; --i >= 0;)
  16135. buffers[i] = 0;
  16136. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16137. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16138. if (! isFloatingPoint())
  16139. {
  16140. int** bufferChan = buffers;
  16141. while (*bufferChan != 0)
  16142. {
  16143. int* b = *bufferChan++;
  16144. // float -> int
  16145. for (int j = numToDo; --j >= 0;)
  16146. {
  16147. const double samp = *(const float*) b;
  16148. if (samp <= -1.0)
  16149. *b++ = std::numeric_limits<int>::min();
  16150. else if (samp >= 1.0)
  16151. *b++ = std::numeric_limits<int>::max();
  16152. else
  16153. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16154. }
  16155. }
  16156. }
  16157. if (! write ((const int**) buffers, numToDo))
  16158. return false;
  16159. numSamplesToRead -= numToDo;
  16160. }
  16161. return true;
  16162. }
  16163. AudioFormat::AudioFormat (const String& name,
  16164. const tchar** const extensions)
  16165. : formatName (name),
  16166. fileExtensions (extensions)
  16167. {
  16168. }
  16169. AudioFormat::~AudioFormat()
  16170. {
  16171. }
  16172. const String& AudioFormat::getFormatName() const
  16173. {
  16174. return formatName;
  16175. }
  16176. const StringArray& AudioFormat::getFileExtensions() const
  16177. {
  16178. return fileExtensions;
  16179. }
  16180. bool AudioFormat::canHandleFile (const File& f)
  16181. {
  16182. for (int i = 0; i < fileExtensions.size(); ++i)
  16183. if (f.hasFileExtension (fileExtensions[i]))
  16184. return true;
  16185. return false;
  16186. }
  16187. bool AudioFormat::isCompressed()
  16188. {
  16189. return false;
  16190. }
  16191. const StringArray AudioFormat::getQualityOptions()
  16192. {
  16193. return StringArray();
  16194. }
  16195. END_JUCE_NAMESPACE
  16196. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16197. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16198. BEGIN_JUCE_NAMESPACE
  16199. AudioFormatManager::AudioFormatManager()
  16200. : defaultFormatIndex (0)
  16201. {
  16202. }
  16203. AudioFormatManager::~AudioFormatManager()
  16204. {
  16205. clearFormats();
  16206. clearSingletonInstance();
  16207. }
  16208. juce_ImplementSingleton (AudioFormatManager);
  16209. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16210. const bool makeThisTheDefaultFormat)
  16211. {
  16212. jassert (newFormat != 0);
  16213. if (newFormat != 0)
  16214. {
  16215. #ifdef JUCE_DEBUG
  16216. for (int i = getNumKnownFormats(); --i >= 0;)
  16217. {
  16218. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16219. {
  16220. jassertfalse // trying to add the same format twice!
  16221. }
  16222. }
  16223. #endif
  16224. if (makeThisTheDefaultFormat)
  16225. defaultFormatIndex = knownFormats.size();
  16226. knownFormats.add (newFormat);
  16227. }
  16228. }
  16229. void AudioFormatManager::registerBasicFormats()
  16230. {
  16231. #if JUCE_MAC
  16232. registerFormat (new AiffAudioFormat(), true);
  16233. registerFormat (new WavAudioFormat(), false);
  16234. #else
  16235. registerFormat (new WavAudioFormat(), true);
  16236. registerFormat (new AiffAudioFormat(), false);
  16237. #endif
  16238. #if JUCE_USE_FLAC
  16239. registerFormat (new FlacAudioFormat(), false);
  16240. #endif
  16241. #if JUCE_USE_OGGVORBIS
  16242. registerFormat (new OggVorbisAudioFormat(), false);
  16243. #endif
  16244. }
  16245. void AudioFormatManager::clearFormats()
  16246. {
  16247. for (int i = getNumKnownFormats(); --i >= 0;)
  16248. delete getKnownFormat(i);
  16249. knownFormats.clear();
  16250. defaultFormatIndex = 0;
  16251. }
  16252. int AudioFormatManager::getNumKnownFormats() const
  16253. {
  16254. return knownFormats.size();
  16255. }
  16256. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16257. {
  16258. return (AudioFormat*) knownFormats [index];
  16259. }
  16260. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16261. {
  16262. return getKnownFormat (defaultFormatIndex);
  16263. }
  16264. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16265. {
  16266. String e (fileExtension);
  16267. if (! e.startsWithChar ('.'))
  16268. e = "." + e;
  16269. for (int i = 0; i < getNumKnownFormats(); ++i)
  16270. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16271. return getKnownFormat(i);
  16272. return 0;
  16273. }
  16274. const String AudioFormatManager::getWildcardForAllFormats() const
  16275. {
  16276. StringArray allExtensions;
  16277. int i;
  16278. for (i = 0; i < getNumKnownFormats(); ++i)
  16279. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16280. allExtensions.trim();
  16281. allExtensions.removeEmptyStrings();
  16282. String s;
  16283. for (i = 0; i < allExtensions.size(); ++i)
  16284. {
  16285. s << '*';
  16286. if (! allExtensions[i].startsWithChar ('.'))
  16287. s << '.';
  16288. s << allExtensions[i];
  16289. if (i < allExtensions.size() - 1)
  16290. s << ';';
  16291. }
  16292. return s;
  16293. }
  16294. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16295. {
  16296. // you need to actually register some formats before the manager can
  16297. // use them to open a file!
  16298. jassert (knownFormats.size() > 0);
  16299. for (int i = 0; i < getNumKnownFormats(); ++i)
  16300. {
  16301. AudioFormat* const af = getKnownFormat(i);
  16302. if (af->canHandleFile (file))
  16303. {
  16304. InputStream* const in = file.createInputStream();
  16305. if (in != 0)
  16306. {
  16307. AudioFormatReader* const r = af->createReaderFor (in, true);
  16308. if (r != 0)
  16309. return r;
  16310. }
  16311. }
  16312. }
  16313. return 0;
  16314. }
  16315. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16316. {
  16317. // you need to actually register some formats before the manager can
  16318. // use them to open a file!
  16319. jassert (knownFormats.size() > 0);
  16320. ScopedPointer <InputStream> in (audioFileStream);
  16321. if (in != 0)
  16322. {
  16323. const int64 originalStreamPos = in->getPosition();
  16324. for (int i = 0; i < getNumKnownFormats(); ++i)
  16325. {
  16326. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16327. if (r != 0)
  16328. {
  16329. in.release();
  16330. return r;
  16331. }
  16332. in->setPosition (originalStreamPos);
  16333. // the stream that is passed-in must be capable of being repositioned so
  16334. // that all the formats can have a go at opening it.
  16335. jassert (in->getPosition() == originalStreamPos);
  16336. }
  16337. }
  16338. return 0;
  16339. }
  16340. END_JUCE_NAMESPACE
  16341. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16342. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16343. BEGIN_JUCE_NAMESPACE
  16344. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16345. const int64 startSample_,
  16346. const int64 length_,
  16347. const bool deleteSourceWhenDeleted_)
  16348. : AudioFormatReader (0, source_->getFormatName()),
  16349. source (source_),
  16350. startSample (startSample_),
  16351. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16352. {
  16353. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16354. sampleRate = source->sampleRate;
  16355. bitsPerSample = source->bitsPerSample;
  16356. lengthInSamples = length;
  16357. numChannels = source->numChannels;
  16358. usesFloatingPointData = source->usesFloatingPointData;
  16359. }
  16360. AudioSubsectionReader::~AudioSubsectionReader()
  16361. {
  16362. if (deleteSourceWhenDeleted)
  16363. delete source;
  16364. }
  16365. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16366. int64 startSampleInFile, int numSamples)
  16367. {
  16368. if (startSampleInFile + numSamples > length)
  16369. {
  16370. for (int i = numDestChannels; --i >= 0;)
  16371. if (destSamples[i] != 0)
  16372. zeromem (destSamples[i], sizeof (int) * numSamples);
  16373. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16374. if (numSamples <= 0)
  16375. return true;
  16376. }
  16377. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16378. startSampleInFile + startSample, numSamples);
  16379. }
  16380. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16381. int64 numSamples,
  16382. float& lowestLeft,
  16383. float& highestLeft,
  16384. float& lowestRight,
  16385. float& highestRight)
  16386. {
  16387. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16388. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16389. source->readMaxLevels (startSampleInFile + startSample,
  16390. numSamples,
  16391. lowestLeft,
  16392. highestLeft,
  16393. lowestRight,
  16394. highestRight);
  16395. }
  16396. END_JUCE_NAMESPACE
  16397. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16398. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16399. BEGIN_JUCE_NAMESPACE
  16400. const int timeBeforeDeletingReader = 2000;
  16401. struct AudioThumbnailDataFormat
  16402. {
  16403. char thumbnailMagic[4];
  16404. int samplesPerThumbSample;
  16405. int64 totalSamples; // source samples
  16406. int64 numFinishedSamples; // source samples
  16407. int numThumbnailSamples;
  16408. int numChannels;
  16409. int sampleRate;
  16410. char future[16];
  16411. char data[1];
  16412. void swapEndiannessIfNeeded() throw()
  16413. {
  16414. #if JUCE_BIG_ENDIAN
  16415. flip (samplesPerThumbSample);
  16416. flip (totalSamples);
  16417. flip (numFinishedSamples);
  16418. flip (numThumbnailSamples);
  16419. flip (numChannels);
  16420. flip (sampleRate);
  16421. #endif
  16422. }
  16423. private:
  16424. #if JUCE_BIG_ENDIAN
  16425. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16426. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16427. #endif
  16428. };
  16429. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16430. AudioFormatManager& formatManagerToUse_,
  16431. AudioThumbnailCache& cacheToUse)
  16432. : formatManagerToUse (formatManagerToUse_),
  16433. cache (cacheToUse),
  16434. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16435. {
  16436. clear();
  16437. }
  16438. AudioThumbnail::~AudioThumbnail()
  16439. {
  16440. cache.removeThumbnail (this);
  16441. const ScopedLock sl (readerLock);
  16442. reader = 0;
  16443. }
  16444. void AudioThumbnail::setSource (InputSource* const newSource)
  16445. {
  16446. cache.removeThumbnail (this);
  16447. timerCallback(); // stops the timer and deletes the reader
  16448. source = newSource;
  16449. clear();
  16450. if (newSource != 0
  16451. && ! (cache.loadThumb (*this, newSource->hashCode())
  16452. && isFullyLoaded()))
  16453. {
  16454. {
  16455. const ScopedLock sl (readerLock);
  16456. reader = createReader();
  16457. }
  16458. if (reader != 0)
  16459. {
  16460. initialiseFromAudioFile (*reader);
  16461. cache.addThumbnail (this);
  16462. }
  16463. }
  16464. sendChangeMessage (this);
  16465. }
  16466. bool AudioThumbnail::useTimeSlice()
  16467. {
  16468. const ScopedLock sl (readerLock);
  16469. if (isFullyLoaded())
  16470. {
  16471. if (reader != 0)
  16472. startTimer (timeBeforeDeletingReader);
  16473. cache.removeThumbnail (this);
  16474. return false;
  16475. }
  16476. if (reader == 0)
  16477. reader = createReader();
  16478. if (reader != 0)
  16479. {
  16480. readNextBlockFromAudioFile (*reader);
  16481. stopTimer();
  16482. sendChangeMessage (this);
  16483. const bool justFinished = isFullyLoaded();
  16484. if (justFinished)
  16485. cache.storeThumb (*this, source->hashCode());
  16486. return ! justFinished;
  16487. }
  16488. return false;
  16489. }
  16490. AudioFormatReader* AudioThumbnail::createReader() const
  16491. {
  16492. if (source != 0)
  16493. {
  16494. InputStream* const audioFileStream = source->createInputStream();
  16495. if (audioFileStream != 0)
  16496. return formatManagerToUse.createReaderFor (audioFileStream);
  16497. }
  16498. return 0;
  16499. }
  16500. void AudioThumbnail::timerCallback()
  16501. {
  16502. stopTimer();
  16503. const ScopedLock sl (readerLock);
  16504. reader = 0;
  16505. }
  16506. void AudioThumbnail::clear()
  16507. {
  16508. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16509. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16510. d->thumbnailMagic[0] = 'j';
  16511. d->thumbnailMagic[1] = 'a';
  16512. d->thumbnailMagic[2] = 't';
  16513. d->thumbnailMagic[3] = 'm';
  16514. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16515. d->totalSamples = 0;
  16516. d->numFinishedSamples = 0;
  16517. d->numThumbnailSamples = 0;
  16518. d->numChannels = 0;
  16519. d->sampleRate = 0;
  16520. numSamplesCached = 0;
  16521. cacheNeedsRefilling = true;
  16522. }
  16523. void AudioThumbnail::loadFrom (InputStream& input)
  16524. {
  16525. const ScopedLock sl (readerLock);
  16526. data.setSize (0);
  16527. input.readIntoMemoryBlock (data);
  16528. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16529. d->swapEndiannessIfNeeded();
  16530. if (! (d->thumbnailMagic[0] == 'j'
  16531. && d->thumbnailMagic[1] == 'a'
  16532. && d->thumbnailMagic[2] == 't'
  16533. && d->thumbnailMagic[3] == 'm'))
  16534. {
  16535. clear();
  16536. }
  16537. numSamplesCached = 0;
  16538. cacheNeedsRefilling = true;
  16539. }
  16540. void AudioThumbnail::saveTo (OutputStream& output) const
  16541. {
  16542. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16543. d->swapEndiannessIfNeeded();
  16544. output.write (data.getData(), (int) data.getSize());
  16545. d->swapEndiannessIfNeeded();
  16546. }
  16547. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16548. {
  16549. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16550. d->totalSamples = fileReader.lengthInSamples;
  16551. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16552. d->numFinishedSamples = 0;
  16553. d->sampleRate = roundToInt (fileReader.sampleRate);
  16554. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16555. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16556. d = (AudioThumbnailDataFormat*) data.getData();
  16557. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16558. return d->totalSamples > 0;
  16559. }
  16560. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16561. {
  16562. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16563. if (d->numFinishedSamples < d->totalSamples)
  16564. {
  16565. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16566. generateSection (fileReader,
  16567. d->numFinishedSamples,
  16568. numToDo);
  16569. d->numFinishedSamples += numToDo;
  16570. }
  16571. cacheNeedsRefilling = true;
  16572. return (d->numFinishedSamples < d->totalSamples);
  16573. }
  16574. int AudioThumbnail::getNumChannels() const throw()
  16575. {
  16576. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16577. jassert (d != 0);
  16578. return d->numChannels;
  16579. }
  16580. double AudioThumbnail::getTotalLength() const throw()
  16581. {
  16582. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16583. jassert (d != 0);
  16584. if (d->sampleRate > 0)
  16585. return d->totalSamples / (double)d->sampleRate;
  16586. else
  16587. return 0.0;
  16588. }
  16589. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16590. int64 startSample,
  16591. int numSamples)
  16592. {
  16593. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16594. jassert (d != 0);
  16595. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16596. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16597. char* l = getChannelData (0);
  16598. char* r = getChannelData (1);
  16599. for (int i = firstDataPos; i < lastDataPos; ++i)
  16600. {
  16601. const int sourceStart = i * d->samplesPerThumbSample;
  16602. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16603. float lowestLeft, highestLeft, lowestRight, highestRight;
  16604. fileReader.readMaxLevels (sourceStart,
  16605. sourceEnd - sourceStart,
  16606. lowestLeft,
  16607. highestLeft,
  16608. lowestRight,
  16609. highestRight);
  16610. int n = i * 2;
  16611. if (r != 0)
  16612. {
  16613. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16614. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16615. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16616. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16617. }
  16618. else
  16619. {
  16620. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16621. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16622. }
  16623. }
  16624. }
  16625. char* AudioThumbnail::getChannelData (int channel) const
  16626. {
  16627. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16628. jassert (d != 0);
  16629. if (channel >= 0 && channel < d->numChannels)
  16630. return d->data + (channel * 2 * d->numThumbnailSamples);
  16631. return 0;
  16632. }
  16633. bool AudioThumbnail::isFullyLoaded() const throw()
  16634. {
  16635. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16636. jassert (d != 0);
  16637. return d->numFinishedSamples >= d->totalSamples;
  16638. }
  16639. void AudioThumbnail::refillCache (const int numSamples,
  16640. double startTime,
  16641. const double timePerPixel)
  16642. {
  16643. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16644. jassert (d != 0);
  16645. if (numSamples <= 0
  16646. || timePerPixel <= 0.0
  16647. || d->sampleRate <= 0)
  16648. {
  16649. numSamplesCached = 0;
  16650. cacheNeedsRefilling = true;
  16651. return;
  16652. }
  16653. if (numSamples == numSamplesCached
  16654. && numChannelsCached == d->numChannels
  16655. && startTime == cachedStart
  16656. && timePerPixel == cachedTimePerPixel
  16657. && ! cacheNeedsRefilling)
  16658. {
  16659. return;
  16660. }
  16661. numSamplesCached = numSamples;
  16662. numChannelsCached = d->numChannels;
  16663. cachedStart = startTime;
  16664. cachedTimePerPixel = timePerPixel;
  16665. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16666. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16667. const ScopedLock sl (readerLock);
  16668. cacheNeedsRefilling = false;
  16669. if (needExtraDetail && reader == 0)
  16670. reader = createReader();
  16671. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16672. {
  16673. startTimer (timeBeforeDeletingReader);
  16674. char* cacheData = (char*) cachedLevels.getData();
  16675. int sample = roundToInt (startTime * d->sampleRate);
  16676. for (int i = numSamples; --i >= 0;)
  16677. {
  16678. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16679. if (sample >= 0)
  16680. {
  16681. if (sample >= reader->lengthInSamples)
  16682. break;
  16683. float lmin, lmax, rmin, rmax;
  16684. reader->readMaxLevels (sample,
  16685. jmax (1, nextSample - sample),
  16686. lmin, lmax, rmin, rmax);
  16687. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16688. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16689. if (numChannelsCached > 1)
  16690. {
  16691. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16692. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16693. }
  16694. cacheData += 2 * numChannelsCached;
  16695. }
  16696. startTime += timePerPixel;
  16697. sample = nextSample;
  16698. }
  16699. }
  16700. else
  16701. {
  16702. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16703. {
  16704. char* const channelData = getChannelData (channelNum);
  16705. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16706. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16707. startTime = cachedStart;
  16708. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16709. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16710. for (int i = numSamples; --i >= 0;)
  16711. {
  16712. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16713. if (sample >= 0 && channelData != 0)
  16714. {
  16715. char mx = -128;
  16716. char mn = 127;
  16717. while (sample <= nextSample)
  16718. {
  16719. if (sample >= numFinished)
  16720. break;
  16721. const int n = sample << 1;
  16722. const char sampMin = channelData [n];
  16723. const char sampMax = channelData [n + 1];
  16724. if (sampMin < mn)
  16725. mn = sampMin;
  16726. if (sampMax > mx)
  16727. mx = sampMax;
  16728. ++sample;
  16729. }
  16730. if (mn <= mx)
  16731. {
  16732. cacheData[0] = mn;
  16733. cacheData[1] = mx;
  16734. }
  16735. else
  16736. {
  16737. cacheData[0] = 1;
  16738. cacheData[1] = 0;
  16739. }
  16740. }
  16741. else
  16742. {
  16743. cacheData[0] = 1;
  16744. cacheData[1] = 0;
  16745. }
  16746. cacheData += numChannelsCached * 2;
  16747. startTime += timePerPixel;
  16748. sample = nextSample;
  16749. }
  16750. }
  16751. }
  16752. }
  16753. void AudioThumbnail::drawChannel (Graphics& g,
  16754. int x, int y, int w, int h,
  16755. double startTime,
  16756. double endTime,
  16757. int channelNum,
  16758. const float verticalZoomFactor)
  16759. {
  16760. refillCache (w, startTime, (endTime - startTime) / w);
  16761. if (numSamplesCached >= w
  16762. && channelNum >= 0
  16763. && channelNum < numChannelsCached)
  16764. {
  16765. const float topY = (float) y;
  16766. const float bottomY = topY + h;
  16767. const float midY = topY + h * 0.5f;
  16768. const float vscale = verticalZoomFactor * h / 256.0f;
  16769. const Rectangle<int> clip (g.getClipBounds());
  16770. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16771. w -= skipLeft;
  16772. x += skipLeft;
  16773. const char* cacheData = ((const char*) cachedLevels.getData())
  16774. + (channelNum << 1)
  16775. + skipLeft * (numChannelsCached << 1);
  16776. while (--w >= 0)
  16777. {
  16778. const char mn = cacheData[0];
  16779. const char mx = cacheData[1];
  16780. cacheData += numChannelsCached << 1;
  16781. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16782. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16783. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16784. ++x;
  16785. if (x >= clip.getRight())
  16786. break;
  16787. }
  16788. }
  16789. }
  16790. END_JUCE_NAMESPACE
  16791. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16792. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16793. BEGIN_JUCE_NAMESPACE
  16794. struct ThumbnailCacheEntry
  16795. {
  16796. int64 hash;
  16797. uint32 lastUsed;
  16798. MemoryBlock data;
  16799. juce_UseDebuggingNewOperator
  16800. };
  16801. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16802. : TimeSliceThread ("thumb cache"),
  16803. maxNumThumbsToStore (maxNumThumbsToStore_)
  16804. {
  16805. startThread (2);
  16806. }
  16807. AudioThumbnailCache::~AudioThumbnailCache()
  16808. {
  16809. }
  16810. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16811. {
  16812. for (int i = thumbs.size(); --i >= 0;)
  16813. {
  16814. if (thumbs[i]->hash == hashCode)
  16815. {
  16816. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  16817. thumbs[i]->data.getSize(),
  16818. false);
  16819. thumb.loadFrom (in);
  16820. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16821. return true;
  16822. }
  16823. }
  16824. return false;
  16825. }
  16826. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16827. const int64 hashCode)
  16828. {
  16829. MemoryOutputStream out;
  16830. thumb.saveTo (out);
  16831. ThumbnailCacheEntry* te = 0;
  16832. for (int i = thumbs.size(); --i >= 0;)
  16833. {
  16834. if (thumbs[i]->hash == hashCode)
  16835. {
  16836. te = thumbs[i];
  16837. break;
  16838. }
  16839. }
  16840. if (te == 0)
  16841. {
  16842. te = new ThumbnailCacheEntry();
  16843. te->hash = hashCode;
  16844. if (thumbs.size() < maxNumThumbsToStore)
  16845. {
  16846. thumbs.add (te);
  16847. }
  16848. else
  16849. {
  16850. int oldest = 0;
  16851. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16852. int i;
  16853. for (i = thumbs.size(); --i >= 0;)
  16854. if (thumbs[i]->lastUsed < oldestTime)
  16855. oldest = i;
  16856. thumbs.set (i, te);
  16857. }
  16858. }
  16859. te->lastUsed = Time::getMillisecondCounter();
  16860. te->data.setSize (0);
  16861. te->data.append (out.getData(), out.getDataSize());
  16862. }
  16863. void AudioThumbnailCache::clear()
  16864. {
  16865. thumbs.clear();
  16866. }
  16867. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16868. {
  16869. addTimeSliceClient (thumb);
  16870. }
  16871. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  16872. {
  16873. removeTimeSliceClient (thumb);
  16874. }
  16875. END_JUCE_NAMESPACE
  16876. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  16877. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  16878. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  16879. #if ! JUCE_WINDOWS
  16880. #include <QuickTime/Movies.h>
  16881. #include <QuickTime/QTML.h>
  16882. #include <QuickTime/QuickTimeComponents.h>
  16883. #include <QuickTime/MediaHandlers.h>
  16884. #include <QuickTime/ImageCodec.h>
  16885. #else
  16886. #if JUCE_MSVC
  16887. #pragma warning (push)
  16888. #pragma warning (disable : 4100)
  16889. #endif
  16890. #include <Movies.h>
  16891. #include <QTML.h>
  16892. #include <QuickTimeComponents.h>
  16893. #include <MediaHandlers.h>
  16894. #include <ImageCodec.h>
  16895. #if JUCE_MSVC
  16896. #pragma warning (pop)
  16897. #endif
  16898. #endif
  16899. BEGIN_JUCE_NAMESPACE
  16900. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  16901. static const char* const quickTimeFormatName = "QuickTime file";
  16902. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  16903. class QTAudioReader : public AudioFormatReader
  16904. {
  16905. public:
  16906. QTAudioReader (InputStream* const input_, const int trackNum_)
  16907. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  16908. ok (false),
  16909. movie (0),
  16910. trackNum (trackNum_),
  16911. lastSampleRead (0),
  16912. lastThreadId (0),
  16913. extractor (0),
  16914. dataHandle (0)
  16915. {
  16916. bufferList.calloc (256, 1);
  16917. #ifdef WIN32
  16918. if (InitializeQTML (0) != noErr)
  16919. return;
  16920. #endif
  16921. if (EnterMovies() != noErr)
  16922. return;
  16923. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  16924. if (! opened)
  16925. return;
  16926. {
  16927. const int numTracks = GetMovieTrackCount (movie);
  16928. int trackCount = 0;
  16929. for (int i = 1; i <= numTracks; ++i)
  16930. {
  16931. track = GetMovieIndTrack (movie, i);
  16932. media = GetTrackMedia (track);
  16933. OSType mediaType;
  16934. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  16935. if (mediaType == SoundMediaType
  16936. && trackCount++ == trackNum_)
  16937. {
  16938. ok = true;
  16939. break;
  16940. }
  16941. }
  16942. }
  16943. if (! ok)
  16944. return;
  16945. ok = false;
  16946. lengthInSamples = GetMediaDecodeDuration (media);
  16947. usesFloatingPointData = false;
  16948. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  16949. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  16950. / GetMediaTimeScale (media);
  16951. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  16952. unsigned long output_layout_size;
  16953. err = MovieAudioExtractionGetPropertyInfo (extractor,
  16954. kQTPropertyClass_MovieAudioExtraction_Audio,
  16955. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16956. 0, &output_layout_size, 0);
  16957. if (err != noErr)
  16958. return;
  16959. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  16960. qt_audio_channel_layout.calloc (output_layout_size, 1);
  16961. err = MovieAudioExtractionGetProperty (extractor,
  16962. kQTPropertyClass_MovieAudioExtraction_Audio,
  16963. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16964. output_layout_size, qt_audio_channel_layout, 0);
  16965. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  16966. err = MovieAudioExtractionSetProperty (extractor,
  16967. kQTPropertyClass_MovieAudioExtraction_Audio,
  16968. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16969. output_layout_size,
  16970. qt_audio_channel_layout);
  16971. err = MovieAudioExtractionGetProperty (extractor,
  16972. kQTPropertyClass_MovieAudioExtraction_Audio,
  16973. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16974. sizeof (inputStreamDesc),
  16975. &inputStreamDesc, 0);
  16976. if (err != noErr)
  16977. return;
  16978. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  16979. | kAudioFormatFlagIsPacked
  16980. | kAudioFormatFlagsNativeEndian;
  16981. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  16982. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  16983. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  16984. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  16985. err = MovieAudioExtractionSetProperty (extractor,
  16986. kQTPropertyClass_MovieAudioExtraction_Audio,
  16987. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16988. sizeof (inputStreamDesc),
  16989. &inputStreamDesc);
  16990. if (err != noErr)
  16991. return;
  16992. Boolean allChannelsDiscrete = false;
  16993. err = MovieAudioExtractionSetProperty (extractor,
  16994. kQTPropertyClass_MovieAudioExtraction_Movie,
  16995. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  16996. sizeof (allChannelsDiscrete),
  16997. &allChannelsDiscrete);
  16998. if (err != noErr)
  16999. return;
  17000. bufferList->mNumberBuffers = 1;
  17001. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17002. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17003. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17004. sampleRate = inputStreamDesc.mSampleRate;
  17005. bitsPerSample = 16;
  17006. numChannels = inputStreamDesc.mChannelsPerFrame;
  17007. detachThread();
  17008. ok = true;
  17009. }
  17010. ~QTAudioReader()
  17011. {
  17012. if (dataHandle != 0)
  17013. DisposeHandle (dataHandle);
  17014. if (extractor != 0)
  17015. {
  17016. MovieAudioExtractionEnd (extractor);
  17017. extractor = 0;
  17018. }
  17019. checkThreadIsAttached();
  17020. DisposeMovie (movie);
  17021. juce_free (bufferList->mBuffers[0].mData);
  17022. #if JUCE_MAC
  17023. ExitMoviesOnThread ();
  17024. #endif
  17025. }
  17026. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17027. int64 startSampleInFile, int numSamples)
  17028. {
  17029. checkThreadIsAttached();
  17030. while (numSamples > 0)
  17031. {
  17032. if (! loadFrame ((int) startSampleInFile))
  17033. return false;
  17034. const int numToDo = jmin (numSamples, samplesPerFrame);
  17035. for (int j = numDestChannels; --j >= 0;)
  17036. {
  17037. if (destSamples[j] != 0)
  17038. {
  17039. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17040. for (int i = 0; i < numToDo; ++i)
  17041. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17042. }
  17043. }
  17044. startOffsetInDestBuffer += numToDo;
  17045. startSampleInFile += numToDo;
  17046. numSamples -= numToDo;
  17047. }
  17048. detachThread();
  17049. return true;
  17050. }
  17051. bool loadFrame (const int sampleNum)
  17052. {
  17053. if (lastSampleRead != sampleNum)
  17054. {
  17055. TimeRecord time;
  17056. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17057. time.base = 0;
  17058. time.value.hi = 0;
  17059. time.value.lo = (UInt32) sampleNum;
  17060. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17061. kQTPropertyClass_MovieAudioExtraction_Movie,
  17062. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17063. sizeof (time), &time);
  17064. if (err != noErr)
  17065. return false;
  17066. }
  17067. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17068. UInt32 outFlags = 0;
  17069. UInt32 actualNumSamples = samplesPerFrame;
  17070. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17071. bufferList, &outFlags);
  17072. lastSampleRead = sampleNum + samplesPerFrame;
  17073. return err == noErr;
  17074. }
  17075. juce_UseDebuggingNewOperator
  17076. bool ok;
  17077. private:
  17078. Movie movie;
  17079. Media media;
  17080. Track track;
  17081. const int trackNum;
  17082. double trackUnitsPerFrame;
  17083. int samplesPerFrame;
  17084. int lastSampleRead;
  17085. Thread::ThreadID lastThreadId;
  17086. MovieAudioExtractionRef extractor;
  17087. AudioStreamBasicDescription inputStreamDesc;
  17088. HeapBlock <AudioBufferList> bufferList;
  17089. Handle dataHandle;
  17090. void checkThreadIsAttached()
  17091. {
  17092. #if JUCE_MAC
  17093. if (Thread::getCurrentThreadId() != lastThreadId)
  17094. EnterMoviesOnThread (0);
  17095. AttachMovieToCurrentThread (movie);
  17096. #endif
  17097. }
  17098. void detachThread()
  17099. {
  17100. #if JUCE_MAC
  17101. DetachMovieFromCurrentThread (movie);
  17102. #endif
  17103. }
  17104. QTAudioReader (const QTAudioReader&);
  17105. QTAudioReader& operator= (const QTAudioReader&);
  17106. };
  17107. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17108. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17109. {
  17110. }
  17111. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17112. {
  17113. }
  17114. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17115. {
  17116. return Array<int>();
  17117. }
  17118. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17119. {
  17120. return Array<int>();
  17121. }
  17122. bool QuickTimeAudioFormat::canDoStereo()
  17123. {
  17124. return true;
  17125. }
  17126. bool QuickTimeAudioFormat::canDoMono()
  17127. {
  17128. return true;
  17129. }
  17130. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17131. const bool deleteStreamIfOpeningFails)
  17132. {
  17133. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17134. if (r->ok)
  17135. return r.release();
  17136. if (! deleteStreamIfOpeningFails)
  17137. r->input = 0;
  17138. return 0;
  17139. }
  17140. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17141. double /*sampleRateToUse*/,
  17142. unsigned int /*numberOfChannels*/,
  17143. int /*bitsPerSample*/,
  17144. const StringPairArray& /*metadataValues*/,
  17145. int /*qualityOptionIndex*/)
  17146. {
  17147. jassertfalse // not yet implemented!
  17148. return 0;
  17149. }
  17150. END_JUCE_NAMESPACE
  17151. #endif
  17152. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17153. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17154. BEGIN_JUCE_NAMESPACE
  17155. static const char* const wavFormatName = "WAV file";
  17156. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17157. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17158. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17159. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17160. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17161. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17162. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17163. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17164. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17165. const String& originator,
  17166. const String& originatorRef,
  17167. const Time& date,
  17168. const int64 timeReferenceSamples,
  17169. const String& codingHistory)
  17170. {
  17171. StringPairArray m;
  17172. m.set (bwavDescription, description);
  17173. m.set (bwavOriginator, originator);
  17174. m.set (bwavOriginatorRef, originatorRef);
  17175. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17176. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17177. m.set (bwavTimeReference, String (timeReferenceSamples));
  17178. m.set (bwavCodingHistory, codingHistory);
  17179. return m;
  17180. }
  17181. #if JUCE_MSVC
  17182. #pragma pack (push, 1)
  17183. #define PACKED
  17184. #elif JUCE_GCC
  17185. #define PACKED __attribute__((packed))
  17186. #else
  17187. #define PACKED
  17188. #endif
  17189. struct BWAVChunk
  17190. {
  17191. char description [256];
  17192. char originator [32];
  17193. char originatorRef [32];
  17194. char originationDate [10];
  17195. char originationTime [8];
  17196. uint32 timeRefLow;
  17197. uint32 timeRefHigh;
  17198. uint16 version;
  17199. uint8 umid[64];
  17200. uint8 reserved[190];
  17201. char codingHistory[1];
  17202. void copyTo (StringPairArray& values) const
  17203. {
  17204. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17205. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17206. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17207. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17208. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17209. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17210. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17211. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17212. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17213. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17214. }
  17215. static MemoryBlock createFrom (const StringPairArray& values)
  17216. {
  17217. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17218. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17219. data.fillWith (0);
  17220. BWAVChunk* b = (BWAVChunk*) data.getData();
  17221. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17222. // as they get called in the right order..
  17223. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17224. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17225. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17226. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17227. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17228. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17229. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17230. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17231. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17232. if (b->description[0] != 0
  17233. || b->originator[0] != 0
  17234. || b->originationDate[0] != 0
  17235. || b->originationTime[0] != 0
  17236. || b->codingHistory[0] != 0
  17237. || time != 0)
  17238. {
  17239. return data;
  17240. }
  17241. return MemoryBlock();
  17242. }
  17243. } PACKED;
  17244. struct SMPLChunk
  17245. {
  17246. struct SampleLoop
  17247. {
  17248. uint32 identifier;
  17249. uint32 type;
  17250. uint32 start;
  17251. uint32 end;
  17252. uint32 fraction;
  17253. uint32 playCount;
  17254. } PACKED;
  17255. uint32 manufacturer;
  17256. uint32 product;
  17257. uint32 samplePeriod;
  17258. uint32 midiUnityNote;
  17259. uint32 midiPitchFraction;
  17260. uint32 smpteFormat;
  17261. uint32 smpteOffset;
  17262. uint32 numSampleLoops;
  17263. uint32 samplerData;
  17264. SampleLoop loops[1];
  17265. void copyTo (StringPairArray& values, const int totalSize) const
  17266. {
  17267. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17268. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17269. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17270. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17271. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17272. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17273. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17274. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17275. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17276. for (uint32 i = 0; i < numSampleLoops; ++i)
  17277. {
  17278. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17279. break;
  17280. const String prefix ("Loop" + String(i));
  17281. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17282. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17283. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17284. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17285. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17286. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17287. }
  17288. }
  17289. static MemoryBlock createFrom (const StringPairArray& values)
  17290. {
  17291. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17292. if (numLoops <= 0)
  17293. return MemoryBlock();
  17294. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17295. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17296. data.fillWith (0);
  17297. SMPLChunk* s = (SMPLChunk*) data.getData();
  17298. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17299. // as they get called in the right order..
  17300. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17301. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17302. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17303. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17304. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17305. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17306. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17307. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17308. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17309. for (int i = 0; i < numLoops; ++i)
  17310. {
  17311. const String prefix ("Loop" + String(i));
  17312. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17313. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17314. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17315. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17316. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17317. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17318. }
  17319. return data;
  17320. }
  17321. } PACKED;
  17322. struct ExtensibleWavSubFormat
  17323. {
  17324. uint32 data1;
  17325. uint16 data2;
  17326. uint16 data3;
  17327. uint8 data4[8];
  17328. } PACKED;
  17329. #if JUCE_MSVC
  17330. #pragma pack (pop)
  17331. #endif
  17332. #undef PACKED
  17333. class WavAudioFormatReader : public AudioFormatReader
  17334. {
  17335. int bytesPerFrame;
  17336. int64 dataChunkStart, dataLength;
  17337. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17338. WavAudioFormatReader (const WavAudioFormatReader&);
  17339. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17340. public:
  17341. int64 bwavChunkStart, bwavSize;
  17342. WavAudioFormatReader (InputStream* const in)
  17343. : AudioFormatReader (in, TRANS (wavFormatName)),
  17344. dataLength (0),
  17345. bwavChunkStart (0),
  17346. bwavSize (0)
  17347. {
  17348. if (input->readInt() == chunkName ("RIFF"))
  17349. {
  17350. const uint32 len = (uint32) input->readInt();
  17351. const int64 end = input->getPosition() + len;
  17352. bool hasGotType = false;
  17353. bool hasGotData = false;
  17354. if (input->readInt() == chunkName ("WAVE"))
  17355. {
  17356. while (input->getPosition() < end
  17357. && ! input->isExhausted())
  17358. {
  17359. const int chunkType = input->readInt();
  17360. uint32 length = (uint32) input->readInt();
  17361. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17362. if (chunkType == chunkName ("fmt "))
  17363. {
  17364. // read the format chunk
  17365. const unsigned short format = input->readShort();
  17366. const short numChans = input->readShort();
  17367. sampleRate = input->readInt();
  17368. const int bytesPerSec = input->readInt();
  17369. numChannels = numChans;
  17370. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17371. bitsPerSample = 8 * bytesPerFrame / numChans;
  17372. if (format == 3)
  17373. {
  17374. usesFloatingPointData = true;
  17375. }
  17376. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17377. {
  17378. if (length < 40) // too short
  17379. {
  17380. bytesPerFrame = 0;
  17381. }
  17382. else
  17383. {
  17384. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17385. ExtensibleWavSubFormat subFormat;
  17386. subFormat.data1 = input->readInt();
  17387. subFormat.data2 = input->readShort();
  17388. subFormat.data3 = input->readShort();
  17389. input->read (subFormat.data4, sizeof (subFormat.data4));
  17390. const ExtensibleWavSubFormat pcmFormat
  17391. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17392. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17393. {
  17394. const ExtensibleWavSubFormat ambisonicFormat
  17395. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17396. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17397. bytesPerFrame = 0;
  17398. }
  17399. }
  17400. }
  17401. else if (format != 1)
  17402. {
  17403. bytesPerFrame = 0;
  17404. }
  17405. hasGotType = true;
  17406. }
  17407. else if (chunkType == chunkName ("data"))
  17408. {
  17409. // get the data chunk's position
  17410. dataLength = length;
  17411. dataChunkStart = input->getPosition();
  17412. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17413. hasGotData = true;
  17414. }
  17415. else if (chunkType == chunkName ("bext"))
  17416. {
  17417. bwavChunkStart = input->getPosition();
  17418. bwavSize = length;
  17419. // Broadcast-wav extension chunk..
  17420. HeapBlock <BWAVChunk> bwav;
  17421. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17422. input->read (bwav, length);
  17423. bwav->copyTo (metadataValues);
  17424. }
  17425. else if (chunkType == chunkName ("smpl"))
  17426. {
  17427. HeapBlock <SMPLChunk> smpl;
  17428. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17429. input->read (smpl, length);
  17430. smpl->copyTo (metadataValues, length);
  17431. }
  17432. else if (chunkEnd <= input->getPosition())
  17433. {
  17434. break;
  17435. }
  17436. input->setPosition (chunkEnd);
  17437. }
  17438. }
  17439. }
  17440. }
  17441. ~WavAudioFormatReader()
  17442. {
  17443. }
  17444. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17445. int64 startSampleInFile, int numSamples)
  17446. {
  17447. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17448. if (samplesAvailable < numSamples)
  17449. {
  17450. for (int i = numDestChannels; --i >= 0;)
  17451. if (destSamples[i] != 0)
  17452. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17453. numSamples = (int) samplesAvailable;
  17454. }
  17455. if (numSamples <= 0)
  17456. return true;
  17457. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17458. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17459. char tempBuffer [tempBufSize];
  17460. while (numSamples > 0)
  17461. {
  17462. int* left = destSamples[0];
  17463. if (left != 0)
  17464. left += startOffsetInDestBuffer;
  17465. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17466. if (right != 0)
  17467. right += startOffsetInDestBuffer;
  17468. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17469. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17470. if (bytesRead < numThisTime * bytesPerFrame)
  17471. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17472. if (bitsPerSample == 16)
  17473. {
  17474. const short* src = (const short*) tempBuffer;
  17475. if (numChannels > 1)
  17476. {
  17477. if (left == 0)
  17478. {
  17479. for (int i = numThisTime; --i >= 0;)
  17480. {
  17481. ++src;
  17482. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17483. }
  17484. }
  17485. else if (right == 0)
  17486. {
  17487. for (int i = numThisTime; --i >= 0;)
  17488. {
  17489. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17490. ++src;
  17491. }
  17492. }
  17493. else
  17494. {
  17495. for (int i = numThisTime; --i >= 0;)
  17496. {
  17497. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17498. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17499. }
  17500. }
  17501. }
  17502. else
  17503. {
  17504. for (int i = numThisTime; --i >= 0;)
  17505. {
  17506. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17507. }
  17508. }
  17509. }
  17510. else if (bitsPerSample == 24)
  17511. {
  17512. const char* src = (const char*) tempBuffer;
  17513. if (numChannels > 1)
  17514. {
  17515. if (left == 0)
  17516. {
  17517. for (int i = numThisTime; --i >= 0;)
  17518. {
  17519. src += 3;
  17520. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17521. src += 3;
  17522. }
  17523. }
  17524. else if (right == 0)
  17525. {
  17526. for (int i = numThisTime; --i >= 0;)
  17527. {
  17528. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17529. src += 6;
  17530. }
  17531. }
  17532. else
  17533. {
  17534. for (int i = 0; i < numThisTime; ++i)
  17535. {
  17536. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17537. src += 3;
  17538. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17539. src += 3;
  17540. }
  17541. }
  17542. }
  17543. else
  17544. {
  17545. for (int i = 0; i < numThisTime; ++i)
  17546. {
  17547. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17548. src += 3;
  17549. }
  17550. }
  17551. }
  17552. else if (bitsPerSample == 32)
  17553. {
  17554. const unsigned int* src = (const unsigned int*) tempBuffer;
  17555. unsigned int* l = (unsigned int*) left;
  17556. unsigned int* r = (unsigned int*) right;
  17557. if (numChannels > 1)
  17558. {
  17559. if (l == 0)
  17560. {
  17561. for (int i = numThisTime; --i >= 0;)
  17562. {
  17563. ++src;
  17564. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17565. }
  17566. }
  17567. else if (r == 0)
  17568. {
  17569. for (int i = numThisTime; --i >= 0;)
  17570. {
  17571. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17572. ++src;
  17573. }
  17574. }
  17575. else
  17576. {
  17577. for (int i = numThisTime; --i >= 0;)
  17578. {
  17579. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17580. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17581. }
  17582. }
  17583. }
  17584. else
  17585. {
  17586. for (int i = numThisTime; --i >= 0;)
  17587. {
  17588. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17589. }
  17590. }
  17591. left = (int*)l;
  17592. right = (int*)r;
  17593. }
  17594. else if (bitsPerSample == 8)
  17595. {
  17596. const unsigned char* src = (const unsigned char*) tempBuffer;
  17597. if (numChannels > 1)
  17598. {
  17599. if (left == 0)
  17600. {
  17601. for (int i = numThisTime; --i >= 0;)
  17602. {
  17603. ++src;
  17604. *right++ = ((int) *src++ - 128) << 24;
  17605. }
  17606. }
  17607. else if (right == 0)
  17608. {
  17609. for (int i = numThisTime; --i >= 0;)
  17610. {
  17611. *left++ = ((int) *src++ - 128) << 24;
  17612. ++src;
  17613. }
  17614. }
  17615. else
  17616. {
  17617. for (int i = numThisTime; --i >= 0;)
  17618. {
  17619. *left++ = ((int) *src++ - 128) << 24;
  17620. *right++ = ((int) *src++ - 128) << 24;
  17621. }
  17622. }
  17623. }
  17624. else
  17625. {
  17626. for (int i = numThisTime; --i >= 0;)
  17627. {
  17628. *left++ = ((int)*src++ - 128) << 24;
  17629. }
  17630. }
  17631. }
  17632. startOffsetInDestBuffer += numThisTime;
  17633. numSamples -= numThisTime;
  17634. }
  17635. if (numSamples > 0)
  17636. {
  17637. for (int i = numDestChannels; --i >= 0;)
  17638. if (destSamples[i] != 0)
  17639. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17640. sizeof (int) * numSamples);
  17641. }
  17642. return true;
  17643. }
  17644. juce_UseDebuggingNewOperator
  17645. };
  17646. class WavAudioFormatWriter : public AudioFormatWriter
  17647. {
  17648. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17649. uint32 lengthInSamples, bytesWritten;
  17650. int64 headerPosition;
  17651. bool writeFailed;
  17652. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17653. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17654. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17655. void writeHeader()
  17656. {
  17657. const bool seekedOk = output->setPosition (headerPosition);
  17658. (void) seekedOk;
  17659. // if this fails, you've given it an output stream that can't seek! It needs
  17660. // to be able to seek back to write the header
  17661. jassert (seekedOk);
  17662. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17663. output->writeInt (chunkName ("RIFF"));
  17664. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17665. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17666. output->writeInt (chunkName ("WAVE"));
  17667. output->writeInt (chunkName ("fmt "));
  17668. output->writeInt (16);
  17669. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17670. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17671. output->writeShort ((short) numChannels);
  17672. output->writeInt ((int) sampleRate);
  17673. output->writeInt (bytesPerFrame * (int) sampleRate);
  17674. output->writeShort ((short) bytesPerFrame);
  17675. output->writeShort ((short) bitsPerSample);
  17676. if (bwavChunk.getSize() > 0)
  17677. {
  17678. output->writeInt (chunkName ("bext"));
  17679. output->writeInt ((int) bwavChunk.getSize());
  17680. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17681. }
  17682. if (smplChunk.getSize() > 0)
  17683. {
  17684. output->writeInt (chunkName ("smpl"));
  17685. output->writeInt ((int) smplChunk.getSize());
  17686. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17687. }
  17688. output->writeInt (chunkName ("data"));
  17689. output->writeInt (lengthInSamples * bytesPerFrame);
  17690. usesFloatingPointData = (bitsPerSample == 32);
  17691. }
  17692. public:
  17693. WavAudioFormatWriter (OutputStream* const out,
  17694. const double sampleRate_,
  17695. const unsigned int numChannels_,
  17696. const int bits,
  17697. const StringPairArray& metadataValues)
  17698. : AudioFormatWriter (out,
  17699. TRANS (wavFormatName),
  17700. sampleRate_,
  17701. numChannels_,
  17702. bits),
  17703. lengthInSamples (0),
  17704. bytesWritten (0),
  17705. writeFailed (false)
  17706. {
  17707. if (metadataValues.size() > 0)
  17708. {
  17709. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17710. smplChunk = SMPLChunk::createFrom (metadataValues);
  17711. }
  17712. headerPosition = out->getPosition();
  17713. writeHeader();
  17714. }
  17715. ~WavAudioFormatWriter()
  17716. {
  17717. writeHeader();
  17718. }
  17719. bool write (const int** data, int numSamples)
  17720. {
  17721. if (writeFailed)
  17722. return false;
  17723. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17724. tempBlock.ensureSize (bytes, false);
  17725. char* buffer = (char*) tempBlock.getData();
  17726. const int* left = data[0];
  17727. const int* right = data[1];
  17728. if (right == 0)
  17729. right = left;
  17730. if (bitsPerSample == 16)
  17731. {
  17732. short* b = (short*) buffer;
  17733. if (numChannels > 1)
  17734. {
  17735. for (int i = numSamples; --i >= 0;)
  17736. {
  17737. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17738. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17739. }
  17740. }
  17741. else
  17742. {
  17743. for (int i = numSamples; --i >= 0;)
  17744. {
  17745. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17746. }
  17747. }
  17748. }
  17749. else if (bitsPerSample == 24)
  17750. {
  17751. char* b = (char*) buffer;
  17752. if (numChannels > 1)
  17753. {
  17754. for (int i = numSamples; --i >= 0;)
  17755. {
  17756. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17757. b += 3;
  17758. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17759. b += 3;
  17760. }
  17761. }
  17762. else
  17763. {
  17764. for (int i = numSamples; --i >= 0;)
  17765. {
  17766. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17767. b += 3;
  17768. }
  17769. }
  17770. }
  17771. else if (bitsPerSample == 32)
  17772. {
  17773. unsigned int* b = (unsigned int*) buffer;
  17774. if (numChannels > 1)
  17775. {
  17776. for (int i = numSamples; --i >= 0;)
  17777. {
  17778. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17779. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17780. }
  17781. }
  17782. else
  17783. {
  17784. for (int i = numSamples; --i >= 0;)
  17785. {
  17786. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17787. }
  17788. }
  17789. }
  17790. else if (bitsPerSample == 8)
  17791. {
  17792. unsigned char* b = (unsigned char*) buffer;
  17793. if (numChannels > 1)
  17794. {
  17795. for (int i = numSamples; --i >= 0;)
  17796. {
  17797. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17798. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17799. }
  17800. }
  17801. else
  17802. {
  17803. for (int i = numSamples; --i >= 0;)
  17804. {
  17805. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17806. }
  17807. }
  17808. }
  17809. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17810. || ! output->write (buffer, bytes))
  17811. {
  17812. // failed to write to disk, so let's try writing the header.
  17813. // If it's just run out of disk space, then if it does manage
  17814. // to write the header, we'll still have a useable file..
  17815. writeHeader();
  17816. writeFailed = true;
  17817. return false;
  17818. }
  17819. else
  17820. {
  17821. bytesWritten += bytes;
  17822. lengthInSamples += numSamples;
  17823. return true;
  17824. }
  17825. }
  17826. juce_UseDebuggingNewOperator
  17827. };
  17828. WavAudioFormat::WavAudioFormat()
  17829. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  17830. {
  17831. }
  17832. WavAudioFormat::~WavAudioFormat()
  17833. {
  17834. }
  17835. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17836. {
  17837. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17838. return Array <int> (rates);
  17839. }
  17840. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17841. {
  17842. const int depths[] = { 8, 16, 24, 32, 0 };
  17843. return Array <int> (depths);
  17844. }
  17845. bool WavAudioFormat::canDoStereo()
  17846. {
  17847. return true;
  17848. }
  17849. bool WavAudioFormat::canDoMono()
  17850. {
  17851. return true;
  17852. }
  17853. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17854. const bool deleteStreamIfOpeningFails)
  17855. {
  17856. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17857. if (r->sampleRate != 0)
  17858. return r.release();
  17859. if (! deleteStreamIfOpeningFails)
  17860. r->input = 0;
  17861. return 0;
  17862. }
  17863. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17864. double sampleRate,
  17865. unsigned int numChannels,
  17866. int bitsPerSample,
  17867. const StringPairArray& metadataValues,
  17868. int /*qualityOptionIndex*/)
  17869. {
  17870. if (getPossibleBitDepths().contains (bitsPerSample))
  17871. {
  17872. return new WavAudioFormatWriter (out,
  17873. sampleRate,
  17874. numChannels,
  17875. bitsPerSample,
  17876. metadataValues);
  17877. }
  17878. return 0;
  17879. }
  17880. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  17881. {
  17882. TemporaryFile tempFile (file);
  17883. WavAudioFormat wav;
  17884. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  17885. if (reader != 0)
  17886. {
  17887. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  17888. if (outStream != 0)
  17889. {
  17890. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  17891. reader->numChannels, reader->bitsPerSample,
  17892. metadata, 0));
  17893. if (writer != 0)
  17894. {
  17895. outStream.release();
  17896. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  17897. writer = 0;
  17898. reader = 0;
  17899. return ok && tempFile.overwriteTargetFileWithTemporary();
  17900. }
  17901. }
  17902. }
  17903. return false;
  17904. }
  17905. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  17906. {
  17907. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  17908. if (reader != 0)
  17909. {
  17910. const int64 bwavPos = reader->bwavChunkStart;
  17911. const int64 bwavSize = reader->bwavSize;
  17912. reader = 0;
  17913. if (bwavSize > 0)
  17914. {
  17915. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  17916. if (chunk.getSize() <= (size_t) bwavSize)
  17917. {
  17918. // the new one will fit in the space available, so write it directly..
  17919. const int64 oldSize = wavFile.getSize();
  17920. {
  17921. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  17922. out->setPosition (bwavPos);
  17923. out->write (chunk.getData(), (int) chunk.getSize());
  17924. out->setPosition (oldSize);
  17925. }
  17926. jassert (wavFile.getSize() == oldSize);
  17927. return true;
  17928. }
  17929. }
  17930. }
  17931. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  17932. }
  17933. END_JUCE_NAMESPACE
  17934. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  17935. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17936. BEGIN_JUCE_NAMESPACE
  17937. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  17938. const bool deleteReaderWhenThisIsDeleted)
  17939. : reader (reader_),
  17940. deleteReader (deleteReaderWhenThisIsDeleted),
  17941. nextPlayPos (0),
  17942. looping (false)
  17943. {
  17944. jassert (reader != 0);
  17945. }
  17946. AudioFormatReaderSource::~AudioFormatReaderSource()
  17947. {
  17948. releaseResources();
  17949. if (deleteReader)
  17950. delete reader;
  17951. }
  17952. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  17953. {
  17954. nextPlayPos = newPosition;
  17955. }
  17956. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  17957. {
  17958. looping = shouldLoop;
  17959. }
  17960. int AudioFormatReaderSource::getNextReadPosition() const
  17961. {
  17962. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  17963. : nextPlayPos;
  17964. }
  17965. int AudioFormatReaderSource::getTotalLength() const
  17966. {
  17967. return (int) reader->lengthInSamples;
  17968. }
  17969. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  17970. double /*sampleRate*/)
  17971. {
  17972. }
  17973. void AudioFormatReaderSource::releaseResources()
  17974. {
  17975. }
  17976. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  17977. {
  17978. if (info.numSamples > 0)
  17979. {
  17980. const int start = nextPlayPos;
  17981. if (looping)
  17982. {
  17983. const int newStart = start % (int) reader->lengthInSamples;
  17984. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  17985. if (newEnd > newStart)
  17986. {
  17987. info.buffer->readFromAudioReader (reader,
  17988. info.startSample,
  17989. newEnd - newStart,
  17990. newStart,
  17991. true, true);
  17992. }
  17993. else
  17994. {
  17995. const int endSamps = (int) reader->lengthInSamples - newStart;
  17996. info.buffer->readFromAudioReader (reader,
  17997. info.startSample,
  17998. endSamps,
  17999. newStart,
  18000. true, true);
  18001. info.buffer->readFromAudioReader (reader,
  18002. info.startSample + endSamps,
  18003. newEnd,
  18004. 0,
  18005. true, true);
  18006. }
  18007. nextPlayPos = newEnd;
  18008. }
  18009. else
  18010. {
  18011. info.buffer->readFromAudioReader (reader,
  18012. info.startSample,
  18013. info.numSamples,
  18014. start,
  18015. true, true);
  18016. nextPlayPos += info.numSamples;
  18017. }
  18018. }
  18019. }
  18020. END_JUCE_NAMESPACE
  18021. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18022. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18023. BEGIN_JUCE_NAMESPACE
  18024. AudioSourcePlayer::AudioSourcePlayer()
  18025. : source (0),
  18026. sampleRate (0),
  18027. bufferSize (0),
  18028. tempBuffer (2, 8),
  18029. lastGain (1.0f),
  18030. gain (1.0f)
  18031. {
  18032. }
  18033. AudioSourcePlayer::~AudioSourcePlayer()
  18034. {
  18035. setSource (0);
  18036. }
  18037. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18038. {
  18039. if (source != newSource)
  18040. {
  18041. AudioSource* const oldSource = source;
  18042. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18043. newSource->prepareToPlay (bufferSize, sampleRate);
  18044. {
  18045. const ScopedLock sl (readLock);
  18046. source = newSource;
  18047. }
  18048. if (oldSource != 0)
  18049. oldSource->releaseResources();
  18050. }
  18051. }
  18052. void AudioSourcePlayer::setGain (const float newGain) throw()
  18053. {
  18054. gain = newGain;
  18055. }
  18056. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18057. int totalNumInputChannels,
  18058. float** outputChannelData,
  18059. int totalNumOutputChannels,
  18060. int numSamples)
  18061. {
  18062. // these should have been prepared by audioDeviceAboutToStart()...
  18063. jassert (sampleRate > 0 && bufferSize > 0);
  18064. const ScopedLock sl (readLock);
  18065. if (source != 0)
  18066. {
  18067. AudioSourceChannelInfo info;
  18068. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18069. // messy stuff needed to compact the channels down into an array
  18070. // of non-zero pointers..
  18071. for (i = 0; i < totalNumInputChannels; ++i)
  18072. {
  18073. if (inputChannelData[i] != 0)
  18074. {
  18075. inputChans [numInputs++] = inputChannelData[i];
  18076. if (numInputs >= numElementsInArray (inputChans))
  18077. break;
  18078. }
  18079. }
  18080. for (i = 0; i < totalNumOutputChannels; ++i)
  18081. {
  18082. if (outputChannelData[i] != 0)
  18083. {
  18084. outputChans [numOutputs++] = outputChannelData[i];
  18085. if (numOutputs >= numElementsInArray (outputChans))
  18086. break;
  18087. }
  18088. }
  18089. if (numInputs > numOutputs)
  18090. {
  18091. // if there aren't enough output channels for the number of
  18092. // inputs, we need to create some temporary extra ones (can't
  18093. // use the input data in case it gets written to)
  18094. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18095. false, false, true);
  18096. for (i = 0; i < numOutputs; ++i)
  18097. {
  18098. channels[numActiveChans] = outputChans[i];
  18099. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18100. ++numActiveChans;
  18101. }
  18102. for (i = numOutputs; i < numInputs; ++i)
  18103. {
  18104. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18105. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18106. ++numActiveChans;
  18107. }
  18108. }
  18109. else
  18110. {
  18111. for (i = 0; i < numInputs; ++i)
  18112. {
  18113. channels[numActiveChans] = outputChans[i];
  18114. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18115. ++numActiveChans;
  18116. }
  18117. for (i = numInputs; i < numOutputs; ++i)
  18118. {
  18119. channels[numActiveChans] = outputChans[i];
  18120. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18121. ++numActiveChans;
  18122. }
  18123. }
  18124. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18125. info.buffer = &buffer;
  18126. info.startSample = 0;
  18127. info.numSamples = numSamples;
  18128. source->getNextAudioBlock (info);
  18129. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18130. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18131. lastGain = gain;
  18132. }
  18133. else
  18134. {
  18135. for (int i = 0; i < totalNumOutputChannels; ++i)
  18136. if (outputChannelData[i] != 0)
  18137. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18138. }
  18139. }
  18140. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18141. {
  18142. sampleRate = device->getCurrentSampleRate();
  18143. bufferSize = device->getCurrentBufferSizeSamples();
  18144. zeromem (channels, sizeof (channels));
  18145. if (source != 0)
  18146. source->prepareToPlay (bufferSize, sampleRate);
  18147. }
  18148. void AudioSourcePlayer::audioDeviceStopped()
  18149. {
  18150. if (source != 0)
  18151. source->releaseResources();
  18152. sampleRate = 0.0;
  18153. bufferSize = 0;
  18154. tempBuffer.setSize (2, 8);
  18155. }
  18156. END_JUCE_NAMESPACE
  18157. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18158. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18159. BEGIN_JUCE_NAMESPACE
  18160. AudioTransportSource::AudioTransportSource()
  18161. : source (0),
  18162. resamplerSource (0),
  18163. bufferingSource (0),
  18164. positionableSource (0),
  18165. masterSource (0),
  18166. gain (1.0f),
  18167. lastGain (1.0f),
  18168. playing (false),
  18169. stopped (true),
  18170. sampleRate (44100.0),
  18171. sourceSampleRate (0.0),
  18172. blockSize (128),
  18173. readAheadBufferSize (0),
  18174. isPrepared (false),
  18175. inputStreamEOF (false)
  18176. {
  18177. }
  18178. AudioTransportSource::~AudioTransportSource()
  18179. {
  18180. setSource (0);
  18181. releaseResources();
  18182. }
  18183. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18184. int readAheadBufferSize_,
  18185. double sourceSampleRateToCorrectFor)
  18186. {
  18187. if (source == newSource)
  18188. {
  18189. if (source == 0)
  18190. return;
  18191. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18192. }
  18193. readAheadBufferSize = readAheadBufferSize_;
  18194. sourceSampleRate = sourceSampleRateToCorrectFor;
  18195. ResamplingAudioSource* newResamplerSource = 0;
  18196. BufferingAudioSource* newBufferingSource = 0;
  18197. PositionableAudioSource* newPositionableSource = 0;
  18198. AudioSource* newMasterSource = 0;
  18199. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18200. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18201. AudioSource* oldMasterSource = masterSource;
  18202. if (newSource != 0)
  18203. {
  18204. newPositionableSource = newSource;
  18205. if (readAheadBufferSize_ > 0)
  18206. newPositionableSource = newBufferingSource
  18207. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18208. newPositionableSource->setNextReadPosition (0);
  18209. if (sourceSampleRateToCorrectFor != 0)
  18210. newMasterSource = newResamplerSource
  18211. = new ResamplingAudioSource (newPositionableSource, false);
  18212. else
  18213. newMasterSource = newPositionableSource;
  18214. if (isPrepared)
  18215. {
  18216. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18217. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18218. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18219. }
  18220. }
  18221. {
  18222. const ScopedLock sl (callbackLock);
  18223. source = newSource;
  18224. resamplerSource = newResamplerSource;
  18225. bufferingSource = newBufferingSource;
  18226. masterSource = newMasterSource;
  18227. positionableSource = newPositionableSource;
  18228. playing = false;
  18229. }
  18230. if (oldMasterSource != 0)
  18231. oldMasterSource->releaseResources();
  18232. }
  18233. void AudioTransportSource::start()
  18234. {
  18235. if ((! playing) && masterSource != 0)
  18236. {
  18237. {
  18238. const ScopedLock sl (callbackLock);
  18239. playing = true;
  18240. stopped = false;
  18241. inputStreamEOF = false;
  18242. }
  18243. sendChangeMessage (this);
  18244. }
  18245. }
  18246. void AudioTransportSource::stop()
  18247. {
  18248. if (playing)
  18249. {
  18250. {
  18251. const ScopedLock sl (callbackLock);
  18252. playing = false;
  18253. }
  18254. int n = 500;
  18255. while (--n >= 0 && ! stopped)
  18256. Thread::sleep (2);
  18257. sendChangeMessage (this);
  18258. }
  18259. }
  18260. void AudioTransportSource::setPosition (double newPosition)
  18261. {
  18262. if (sampleRate > 0.0)
  18263. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18264. }
  18265. double AudioTransportSource::getCurrentPosition() const
  18266. {
  18267. if (sampleRate > 0.0)
  18268. return getNextReadPosition() / sampleRate;
  18269. else
  18270. return 0.0;
  18271. }
  18272. void AudioTransportSource::setNextReadPosition (int newPosition)
  18273. {
  18274. if (positionableSource != 0)
  18275. {
  18276. if (sampleRate > 0 && sourceSampleRate > 0)
  18277. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18278. positionableSource->setNextReadPosition (newPosition);
  18279. }
  18280. }
  18281. int AudioTransportSource::getNextReadPosition() const
  18282. {
  18283. if (positionableSource != 0)
  18284. {
  18285. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18286. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18287. }
  18288. return 0;
  18289. }
  18290. int AudioTransportSource::getTotalLength() const
  18291. {
  18292. const ScopedLock sl (callbackLock);
  18293. if (positionableSource != 0)
  18294. {
  18295. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18296. return roundToInt (positionableSource->getTotalLength() * ratio);
  18297. }
  18298. return 0;
  18299. }
  18300. bool AudioTransportSource::isLooping() const
  18301. {
  18302. const ScopedLock sl (callbackLock);
  18303. return positionableSource != 0
  18304. && positionableSource->isLooping();
  18305. }
  18306. void AudioTransportSource::setGain (const float newGain) throw()
  18307. {
  18308. gain = newGain;
  18309. }
  18310. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18311. double sampleRate_)
  18312. {
  18313. const ScopedLock sl (callbackLock);
  18314. sampleRate = sampleRate_;
  18315. blockSize = samplesPerBlockExpected;
  18316. if (masterSource != 0)
  18317. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18318. if (resamplerSource != 0 && sourceSampleRate != 0)
  18319. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18320. isPrepared = true;
  18321. }
  18322. void AudioTransportSource::releaseResources()
  18323. {
  18324. const ScopedLock sl (callbackLock);
  18325. if (masterSource != 0)
  18326. masterSource->releaseResources();
  18327. isPrepared = false;
  18328. }
  18329. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18330. {
  18331. const ScopedLock sl (callbackLock);
  18332. inputStreamEOF = false;
  18333. if (masterSource != 0 && ! stopped)
  18334. {
  18335. masterSource->getNextAudioBlock (info);
  18336. if (! playing)
  18337. {
  18338. // just stopped playing, so fade out the last block..
  18339. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18340. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18341. if (info.numSamples > 256)
  18342. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18343. }
  18344. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18345. && ! positionableSource->isLooping())
  18346. {
  18347. playing = false;
  18348. inputStreamEOF = true;
  18349. sendChangeMessage (this);
  18350. }
  18351. stopped = ! playing;
  18352. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18353. {
  18354. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18355. lastGain, gain);
  18356. }
  18357. }
  18358. else
  18359. {
  18360. info.clearActiveBufferRegion();
  18361. stopped = true;
  18362. }
  18363. lastGain = gain;
  18364. }
  18365. END_JUCE_NAMESPACE
  18366. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18367. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18368. BEGIN_JUCE_NAMESPACE
  18369. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18370. public Thread,
  18371. private Timer
  18372. {
  18373. public:
  18374. SharedBufferingAudioSourceThread()
  18375. : Thread ("Audio Buffer")
  18376. {
  18377. }
  18378. ~SharedBufferingAudioSourceThread()
  18379. {
  18380. stopThread (10000);
  18381. clearSingletonInstance();
  18382. }
  18383. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18384. void addSource (BufferingAudioSource* source)
  18385. {
  18386. const ScopedLock sl (lock);
  18387. if (! sources.contains ((void*) source))
  18388. {
  18389. sources.add ((void*) source);
  18390. startThread();
  18391. stopTimer();
  18392. }
  18393. notify();
  18394. }
  18395. void removeSource (BufferingAudioSource* source)
  18396. {
  18397. const ScopedLock sl (lock);
  18398. sources.removeValue ((void*) source);
  18399. if (sources.size() == 0)
  18400. startTimer (5000);
  18401. }
  18402. private:
  18403. VoidArray sources;
  18404. CriticalSection lock;
  18405. void run()
  18406. {
  18407. while (! threadShouldExit())
  18408. {
  18409. bool busy = false;
  18410. for (int i = sources.size(); --i >= 0;)
  18411. {
  18412. if (threadShouldExit())
  18413. return;
  18414. const ScopedLock sl (lock);
  18415. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18416. if (b != 0 && b->readNextBufferChunk())
  18417. busy = true;
  18418. }
  18419. if (! busy)
  18420. wait (500);
  18421. }
  18422. }
  18423. void timerCallback()
  18424. {
  18425. stopTimer();
  18426. if (sources.size() == 0)
  18427. deleteInstance();
  18428. }
  18429. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18430. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18431. };
  18432. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18433. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18434. const bool deleteSourceWhenDeleted_,
  18435. int numberOfSamplesToBuffer_)
  18436. : source (source_),
  18437. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18438. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18439. buffer (2, 0),
  18440. bufferValidStart (0),
  18441. bufferValidEnd (0),
  18442. nextPlayPos (0),
  18443. wasSourceLooping (false)
  18444. {
  18445. jassert (source_ != 0);
  18446. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18447. // not using a larger buffer..
  18448. }
  18449. BufferingAudioSource::~BufferingAudioSource()
  18450. {
  18451. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18452. if (thread != 0)
  18453. thread->removeSource (this);
  18454. if (deleteSourceWhenDeleted)
  18455. delete source;
  18456. }
  18457. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18458. {
  18459. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18460. sampleRate = sampleRate_;
  18461. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18462. buffer.clear();
  18463. bufferValidStart = 0;
  18464. bufferValidEnd = 0;
  18465. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18466. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18467. buffer.getNumSamples() / 2))
  18468. {
  18469. SharedBufferingAudioSourceThread::getInstance()->notify();
  18470. Thread::sleep (5);
  18471. }
  18472. }
  18473. void BufferingAudioSource::releaseResources()
  18474. {
  18475. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18476. if (thread != 0)
  18477. thread->removeSource (this);
  18478. buffer.setSize (2, 0);
  18479. source->releaseResources();
  18480. }
  18481. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18482. {
  18483. const ScopedLock sl (bufferStartPosLock);
  18484. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18485. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18486. if (validStart == validEnd)
  18487. {
  18488. // total cache miss
  18489. info.clearActiveBufferRegion();
  18490. }
  18491. else
  18492. {
  18493. if (validStart > 0)
  18494. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18495. if (validEnd < info.numSamples)
  18496. info.buffer->clear (info.startSample + validEnd,
  18497. info.numSamples - validEnd); // partial cache miss at end
  18498. if (validStart < validEnd)
  18499. {
  18500. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18501. {
  18502. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18503. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18504. if (startBufferIndex < endBufferIndex)
  18505. {
  18506. info.buffer->copyFrom (chan, info.startSample + validStart,
  18507. buffer,
  18508. chan, startBufferIndex,
  18509. validEnd - validStart);
  18510. }
  18511. else
  18512. {
  18513. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18514. info.buffer->copyFrom (chan, info.startSample + validStart,
  18515. buffer,
  18516. chan, startBufferIndex,
  18517. initialSize);
  18518. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18519. buffer,
  18520. chan, 0,
  18521. (validEnd - validStart) - initialSize);
  18522. }
  18523. }
  18524. }
  18525. nextPlayPos += info.numSamples;
  18526. if (source->isLooping() && nextPlayPos > 0)
  18527. nextPlayPos %= source->getTotalLength();
  18528. }
  18529. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18530. if (thread != 0)
  18531. thread->notify();
  18532. }
  18533. int BufferingAudioSource::getNextReadPosition() const
  18534. {
  18535. return (source->isLooping() && nextPlayPos > 0)
  18536. ? nextPlayPos % source->getTotalLength()
  18537. : nextPlayPos;
  18538. }
  18539. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18540. {
  18541. const ScopedLock sl (bufferStartPosLock);
  18542. nextPlayPos = newPosition;
  18543. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18544. if (thread != 0)
  18545. thread->notify();
  18546. }
  18547. bool BufferingAudioSource::readNextBufferChunk()
  18548. {
  18549. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18550. {
  18551. const ScopedLock sl (bufferStartPosLock);
  18552. if (wasSourceLooping != isLooping())
  18553. {
  18554. wasSourceLooping = isLooping();
  18555. bufferValidStart = 0;
  18556. bufferValidEnd = 0;
  18557. }
  18558. newBVS = jmax (0, nextPlayPos);
  18559. newBVE = newBVS + buffer.getNumSamples() - 4;
  18560. sectionToReadStart = 0;
  18561. sectionToReadEnd = 0;
  18562. const int maxChunkSize = 2048;
  18563. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18564. {
  18565. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18566. sectionToReadStart = newBVS;
  18567. sectionToReadEnd = newBVE;
  18568. bufferValidStart = 0;
  18569. bufferValidEnd = 0;
  18570. }
  18571. else if (abs (newBVS - bufferValidStart) > 512
  18572. || abs (newBVE - bufferValidEnd) > 512)
  18573. {
  18574. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18575. sectionToReadStart = bufferValidEnd;
  18576. sectionToReadEnd = newBVE;
  18577. bufferValidStart = newBVS;
  18578. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18579. }
  18580. }
  18581. if (sectionToReadStart != sectionToReadEnd)
  18582. {
  18583. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18584. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18585. if (bufferIndexStart < bufferIndexEnd)
  18586. {
  18587. readBufferSection (sectionToReadStart,
  18588. sectionToReadEnd - sectionToReadStart,
  18589. bufferIndexStart);
  18590. }
  18591. else
  18592. {
  18593. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18594. readBufferSection (sectionToReadStart,
  18595. initialSize,
  18596. bufferIndexStart);
  18597. readBufferSection (sectionToReadStart + initialSize,
  18598. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18599. 0);
  18600. }
  18601. const ScopedLock sl2 (bufferStartPosLock);
  18602. bufferValidStart = newBVS;
  18603. bufferValidEnd = newBVE;
  18604. return true;
  18605. }
  18606. else
  18607. {
  18608. return false;
  18609. }
  18610. }
  18611. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18612. {
  18613. if (source->getNextReadPosition() != start)
  18614. source->setNextReadPosition (start);
  18615. AudioSourceChannelInfo info;
  18616. info.buffer = &buffer;
  18617. info.startSample = bufferOffset;
  18618. info.numSamples = length;
  18619. source->getNextAudioBlock (info);
  18620. }
  18621. END_JUCE_NAMESPACE
  18622. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18623. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18624. BEGIN_JUCE_NAMESPACE
  18625. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18626. const bool deleteSourceWhenDeleted_)
  18627. : requiredNumberOfChannels (2),
  18628. source (source_),
  18629. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18630. buffer (2, 16)
  18631. {
  18632. remappedInfo.buffer = &buffer;
  18633. remappedInfo.startSample = 0;
  18634. }
  18635. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18636. {
  18637. if (deleteSourceWhenDeleted)
  18638. delete source;
  18639. }
  18640. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18641. {
  18642. const ScopedLock sl (lock);
  18643. requiredNumberOfChannels = requiredNumberOfChannels_;
  18644. }
  18645. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18646. {
  18647. const ScopedLock sl (lock);
  18648. remappedInputs.clear();
  18649. remappedOutputs.clear();
  18650. }
  18651. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18652. {
  18653. const ScopedLock sl (lock);
  18654. while (remappedInputs.size() < destIndex)
  18655. remappedInputs.add (-1);
  18656. remappedInputs.set (destIndex, sourceIndex);
  18657. }
  18658. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18659. {
  18660. const ScopedLock sl (lock);
  18661. while (remappedOutputs.size() < sourceIndex)
  18662. remappedOutputs.add (-1);
  18663. remappedOutputs.set (sourceIndex, destIndex);
  18664. }
  18665. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18666. {
  18667. const ScopedLock sl (lock);
  18668. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18669. return remappedInputs.getUnchecked (inputChannelIndex);
  18670. return -1;
  18671. }
  18672. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18673. {
  18674. const ScopedLock sl (lock);
  18675. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18676. return remappedOutputs .getUnchecked (outputChannelIndex);
  18677. return -1;
  18678. }
  18679. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18680. {
  18681. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18682. }
  18683. void ChannelRemappingAudioSource::releaseResources()
  18684. {
  18685. source->releaseResources();
  18686. }
  18687. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18688. {
  18689. const ScopedLock sl (lock);
  18690. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18691. const int numChans = bufferToFill.buffer->getNumChannels();
  18692. int i;
  18693. for (i = 0; i < buffer.getNumChannels(); ++i)
  18694. {
  18695. const int remappedChan = getRemappedInputChannel (i);
  18696. if (remappedChan >= 0 && remappedChan < numChans)
  18697. {
  18698. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18699. remappedChan,
  18700. bufferToFill.startSample,
  18701. bufferToFill.numSamples);
  18702. }
  18703. else
  18704. {
  18705. buffer.clear (i, 0, bufferToFill.numSamples);
  18706. }
  18707. }
  18708. remappedInfo.numSamples = bufferToFill.numSamples;
  18709. source->getNextAudioBlock (remappedInfo);
  18710. bufferToFill.clearActiveBufferRegion();
  18711. for (i = 0; i < requiredNumberOfChannels; ++i)
  18712. {
  18713. const int remappedChan = getRemappedOutputChannel (i);
  18714. if (remappedChan >= 0 && remappedChan < numChans)
  18715. {
  18716. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18717. buffer, i, 0, bufferToFill.numSamples);
  18718. }
  18719. }
  18720. }
  18721. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18722. {
  18723. XmlElement* e = new XmlElement ("MAPPINGS");
  18724. String ins, outs;
  18725. int i;
  18726. const ScopedLock sl (lock);
  18727. for (i = 0; i < remappedInputs.size(); ++i)
  18728. ins << remappedInputs.getUnchecked(i) << ' ';
  18729. for (i = 0; i < remappedOutputs.size(); ++i)
  18730. outs << remappedOutputs.getUnchecked(i) << ' ';
  18731. e->setAttribute ("inputs", ins.trimEnd());
  18732. e->setAttribute ("outputs", outs.trimEnd());
  18733. return e;
  18734. }
  18735. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18736. {
  18737. if (e.hasTagName ("MAPPINGS"))
  18738. {
  18739. const ScopedLock sl (lock);
  18740. clearAllMappings();
  18741. StringArray ins, outs;
  18742. ins.addTokens (e.getStringAttribute ("inputs"), false);
  18743. outs.addTokens (e.getStringAttribute ("outputs"), false);
  18744. int i;
  18745. for (i = 0; i < ins.size(); ++i)
  18746. remappedInputs.add (ins[i].getIntValue());
  18747. for (i = 0; i < outs.size(); ++i)
  18748. remappedOutputs.add (outs[i].getIntValue());
  18749. }
  18750. }
  18751. END_JUCE_NAMESPACE
  18752. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18753. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18754. BEGIN_JUCE_NAMESPACE
  18755. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18756. const bool deleteInputWhenDeleted_)
  18757. : input (inputSource),
  18758. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18759. {
  18760. jassert (inputSource != 0);
  18761. for (int i = 2; --i >= 0;)
  18762. iirFilters.add (new IIRFilter());
  18763. }
  18764. IIRFilterAudioSource::~IIRFilterAudioSource()
  18765. {
  18766. if (deleteInputWhenDeleted)
  18767. delete input;
  18768. }
  18769. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18770. {
  18771. for (int i = iirFilters.size(); --i >= 0;)
  18772. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18773. }
  18774. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18775. {
  18776. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18777. for (int i = iirFilters.size(); --i >= 0;)
  18778. iirFilters.getUnchecked(i)->reset();
  18779. }
  18780. void IIRFilterAudioSource::releaseResources()
  18781. {
  18782. input->releaseResources();
  18783. }
  18784. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18785. {
  18786. input->getNextAudioBlock (bufferToFill);
  18787. const int numChannels = bufferToFill.buffer->getNumChannels();
  18788. while (numChannels > iirFilters.size())
  18789. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18790. for (int i = 0; i < numChannels; ++i)
  18791. iirFilters.getUnchecked(i)
  18792. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18793. bufferToFill.numSamples);
  18794. }
  18795. END_JUCE_NAMESPACE
  18796. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18797. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18798. BEGIN_JUCE_NAMESPACE
  18799. MixerAudioSource::MixerAudioSource()
  18800. : tempBuffer (2, 0),
  18801. currentSampleRate (0.0),
  18802. bufferSizeExpected (0)
  18803. {
  18804. }
  18805. MixerAudioSource::~MixerAudioSource()
  18806. {
  18807. removeAllInputs();
  18808. }
  18809. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18810. {
  18811. if (input != 0 && ! inputs.contains (input))
  18812. {
  18813. double localRate;
  18814. int localBufferSize;
  18815. {
  18816. const ScopedLock sl (lock);
  18817. localRate = currentSampleRate;
  18818. localBufferSize = bufferSizeExpected;
  18819. }
  18820. if (localRate != 0.0)
  18821. input->prepareToPlay (localBufferSize, localRate);
  18822. const ScopedLock sl (lock);
  18823. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18824. inputs.add (input);
  18825. }
  18826. }
  18827. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18828. {
  18829. if (input != 0)
  18830. {
  18831. int index;
  18832. {
  18833. const ScopedLock sl (lock);
  18834. index = inputs.indexOf ((void*) input);
  18835. if (index >= 0)
  18836. {
  18837. inputsToDelete.shiftBits (index, 1);
  18838. inputs.remove (index);
  18839. }
  18840. }
  18841. if (index >= 0)
  18842. {
  18843. input->releaseResources();
  18844. if (deleteInput)
  18845. delete input;
  18846. }
  18847. }
  18848. }
  18849. void MixerAudioSource::removeAllInputs()
  18850. {
  18851. VoidArray inputsCopy;
  18852. BigInteger inputsToDeleteCopy;
  18853. {
  18854. const ScopedLock sl (lock);
  18855. inputsCopy = inputs;
  18856. inputsToDeleteCopy = inputsToDelete;
  18857. }
  18858. for (int i = inputsCopy.size(); --i >= 0;)
  18859. if (inputsToDeleteCopy[i])
  18860. delete (AudioSource*) inputsCopy[i];
  18861. }
  18862. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18863. {
  18864. tempBuffer.setSize (2, samplesPerBlockExpected);
  18865. const ScopedLock sl (lock);
  18866. currentSampleRate = sampleRate;
  18867. bufferSizeExpected = samplesPerBlockExpected;
  18868. for (int i = inputs.size(); --i >= 0;)
  18869. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18870. sampleRate);
  18871. }
  18872. void MixerAudioSource::releaseResources()
  18873. {
  18874. const ScopedLock sl (lock);
  18875. for (int i = inputs.size(); --i >= 0;)
  18876. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  18877. tempBuffer.setSize (2, 0);
  18878. currentSampleRate = 0;
  18879. bufferSizeExpected = 0;
  18880. }
  18881. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18882. {
  18883. const ScopedLock sl (lock);
  18884. if (inputs.size() > 0)
  18885. {
  18886. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  18887. if (inputs.size() > 1)
  18888. {
  18889. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  18890. info.buffer->getNumSamples());
  18891. AudioSourceChannelInfo info2;
  18892. info2.buffer = &tempBuffer;
  18893. info2.numSamples = info.numSamples;
  18894. info2.startSample = 0;
  18895. for (int i = 1; i < inputs.size(); ++i)
  18896. {
  18897. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  18898. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  18899. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  18900. }
  18901. }
  18902. }
  18903. else
  18904. {
  18905. info.clearActiveBufferRegion();
  18906. }
  18907. }
  18908. END_JUCE_NAMESPACE
  18909. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  18910. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  18911. BEGIN_JUCE_NAMESPACE
  18912. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  18913. const bool deleteInputWhenDeleted_)
  18914. : input (inputSource),
  18915. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  18916. ratio (1.0),
  18917. lastRatio (1.0),
  18918. buffer (2, 0),
  18919. sampsInBuffer (0)
  18920. {
  18921. jassert (input != 0);
  18922. }
  18923. ResamplingAudioSource::~ResamplingAudioSource()
  18924. {
  18925. if (deleteInputWhenDeleted)
  18926. delete input;
  18927. }
  18928. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  18929. {
  18930. jassert (samplesInPerOutputSample > 0);
  18931. const ScopedLock sl (ratioLock);
  18932. ratio = jmax (0.0, samplesInPerOutputSample);
  18933. }
  18934. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  18935. double sampleRate)
  18936. {
  18937. const ScopedLock sl (ratioLock);
  18938. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18939. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  18940. buffer.clear();
  18941. sampsInBuffer = 0;
  18942. bufferPos = 0;
  18943. subSampleOffset = 0.0;
  18944. createLowPass (ratio);
  18945. resetFilters();
  18946. }
  18947. void ResamplingAudioSource::releaseResources()
  18948. {
  18949. input->releaseResources();
  18950. buffer.setSize (2, 0);
  18951. }
  18952. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18953. {
  18954. const ScopedLock sl (ratioLock);
  18955. if (lastRatio != ratio)
  18956. {
  18957. createLowPass (ratio);
  18958. lastRatio = ratio;
  18959. }
  18960. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  18961. int bufferSize = buffer.getNumSamples();
  18962. if (bufferSize < sampsNeeded + 8)
  18963. {
  18964. bufferPos %= bufferSize;
  18965. bufferSize = sampsNeeded + 32;
  18966. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  18967. }
  18968. bufferPos %= bufferSize;
  18969. int endOfBufferPos = bufferPos + sampsInBuffer;
  18970. while (sampsNeeded > sampsInBuffer)
  18971. {
  18972. endOfBufferPos %= bufferSize;
  18973. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  18974. bufferSize - endOfBufferPos);
  18975. AudioSourceChannelInfo readInfo;
  18976. readInfo.buffer = &buffer;
  18977. readInfo.numSamples = numToDo;
  18978. readInfo.startSample = endOfBufferPos;
  18979. input->getNextAudioBlock (readInfo);
  18980. if (ratio > 1.0001)
  18981. {
  18982. // for down-sampling, pre-apply the filter..
  18983. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18984. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  18985. }
  18986. sampsInBuffer += numToDo;
  18987. endOfBufferPos += numToDo;
  18988. }
  18989. float* dl = info.buffer->getSampleData (0, info.startSample);
  18990. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  18991. const float* const bl = buffer.getSampleData (0, 0);
  18992. const float* const br = buffer.getSampleData (1, 0);
  18993. int nextPos = (bufferPos + 1) % bufferSize;
  18994. for (int m = info.numSamples; --m >= 0;)
  18995. {
  18996. const float alpha = (float) subSampleOffset;
  18997. const float invAlpha = 1.0f - alpha;
  18998. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  18999. if (dr != 0)
  19000. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19001. subSampleOffset += ratio;
  19002. jassert (sampsInBuffer > 0);
  19003. while (subSampleOffset >= 1.0)
  19004. {
  19005. if (++bufferPos >= bufferSize)
  19006. bufferPos = 0;
  19007. --sampsInBuffer;
  19008. nextPos = (bufferPos + 1) % bufferSize;
  19009. subSampleOffset -= 1.0;
  19010. }
  19011. }
  19012. if (ratio < 0.9999)
  19013. {
  19014. // for up-sampling, apply the filter after transposing..
  19015. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19016. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19017. }
  19018. else if (ratio <= 1.0001)
  19019. {
  19020. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19021. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19022. {
  19023. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19024. FilterState& fs = filterStates[i];
  19025. if (info.numSamples > 1)
  19026. {
  19027. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19028. }
  19029. else
  19030. {
  19031. fs.y2 = fs.y1;
  19032. fs.x2 = fs.x1;
  19033. }
  19034. fs.y1 = fs.x1 = *endOfBuffer;
  19035. }
  19036. }
  19037. jassert (sampsInBuffer >= 0);
  19038. }
  19039. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19040. {
  19041. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19042. : 0.5 * frequencyRatio;
  19043. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19044. const double nSquared = n * n;
  19045. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19046. setFilterCoefficients (c1,
  19047. c1 * 2.0f,
  19048. c1,
  19049. 1.0,
  19050. c1 * 2.0 * (1.0 - nSquared),
  19051. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19052. }
  19053. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19054. {
  19055. const double a = 1.0 / c4;
  19056. c1 *= a;
  19057. c2 *= a;
  19058. c3 *= a;
  19059. c5 *= a;
  19060. c6 *= a;
  19061. coefficients[0] = c1;
  19062. coefficients[1] = c2;
  19063. coefficients[2] = c3;
  19064. coefficients[3] = c4;
  19065. coefficients[4] = c5;
  19066. coefficients[5] = c6;
  19067. }
  19068. void ResamplingAudioSource::resetFilters()
  19069. {
  19070. zeromem (filterStates, sizeof (filterStates));
  19071. }
  19072. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19073. {
  19074. while (--num >= 0)
  19075. {
  19076. const double in = *samples;
  19077. double out = coefficients[0] * in
  19078. + coefficients[1] * fs.x1
  19079. + coefficients[2] * fs.x2
  19080. - coefficients[4] * fs.y1
  19081. - coefficients[5] * fs.y2;
  19082. #if JUCE_INTEL
  19083. if (! (out < -1.0e-8 || out > 1.0e-8))
  19084. out = 0;
  19085. #endif
  19086. fs.x2 = fs.x1;
  19087. fs.x1 = in;
  19088. fs.y2 = fs.y1;
  19089. fs.y1 = out;
  19090. *samples++ = (float) out;
  19091. }
  19092. }
  19093. END_JUCE_NAMESPACE
  19094. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19095. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19096. BEGIN_JUCE_NAMESPACE
  19097. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19098. : frequency (1000.0),
  19099. sampleRate (44100.0),
  19100. currentPhase (0.0),
  19101. phasePerSample (0.0),
  19102. amplitude (0.5f)
  19103. {
  19104. }
  19105. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19106. {
  19107. }
  19108. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19109. {
  19110. amplitude = newAmplitude;
  19111. }
  19112. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19113. {
  19114. frequency = newFrequencyHz;
  19115. phasePerSample = 0.0;
  19116. }
  19117. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19118. double sampleRate_)
  19119. {
  19120. currentPhase = 0.0;
  19121. phasePerSample = 0.0;
  19122. sampleRate = sampleRate_;
  19123. }
  19124. void ToneGeneratorAudioSource::releaseResources()
  19125. {
  19126. }
  19127. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19128. {
  19129. if (phasePerSample == 0.0)
  19130. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19131. for (int i = 0; i < info.numSamples; ++i)
  19132. {
  19133. const float sample = amplitude * (float) sin (currentPhase);
  19134. currentPhase += phasePerSample;
  19135. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19136. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19137. }
  19138. }
  19139. END_JUCE_NAMESPACE
  19140. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19141. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19142. BEGIN_JUCE_NAMESPACE
  19143. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19144. : sampleRate (0),
  19145. bufferSize (0),
  19146. useDefaultInputChannels (true),
  19147. useDefaultOutputChannels (true)
  19148. {
  19149. }
  19150. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19151. {
  19152. return outputDeviceName == other.outputDeviceName
  19153. && inputDeviceName == other.inputDeviceName
  19154. && sampleRate == other.sampleRate
  19155. && bufferSize == other.bufferSize
  19156. && inputChannels == other.inputChannels
  19157. && useDefaultInputChannels == other.useDefaultInputChannels
  19158. && outputChannels == other.outputChannels
  19159. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19160. }
  19161. AudioDeviceManager::AudioDeviceManager()
  19162. : currentAudioDevice (0),
  19163. numInputChansNeeded (0),
  19164. numOutputChansNeeded (2),
  19165. listNeedsScanning (true),
  19166. useInputNames (false),
  19167. inputLevelMeasurementEnabledCount (0),
  19168. inputLevel (0),
  19169. tempBuffer (2, 2),
  19170. defaultMidiOutput (0),
  19171. cpuUsageMs (0),
  19172. timeToCpuScale (0)
  19173. {
  19174. callbackHandler.owner = this;
  19175. }
  19176. AudioDeviceManager::~AudioDeviceManager()
  19177. {
  19178. currentAudioDevice = 0;
  19179. defaultMidiOutput = 0;
  19180. }
  19181. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19182. {
  19183. if (availableDeviceTypes.size() == 0)
  19184. {
  19185. createAudioDeviceTypes (availableDeviceTypes);
  19186. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19187. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19188. if (availableDeviceTypes.size() > 0)
  19189. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19190. }
  19191. }
  19192. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19193. {
  19194. scanDevicesIfNeeded();
  19195. return availableDeviceTypes;
  19196. }
  19197. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19198. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19199. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19200. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19201. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19202. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19203. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19204. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19205. {
  19206. #if JUCE_WINDOWS
  19207. #if JUCE_WASAPI
  19208. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19209. list.add (juce_createAudioIODeviceType_WASAPI());
  19210. #endif
  19211. #if JUCE_DIRECTSOUND
  19212. list.add (juce_createAudioIODeviceType_DirectSound());
  19213. #endif
  19214. #if JUCE_ASIO
  19215. list.add (juce_createAudioIODeviceType_ASIO());
  19216. #endif
  19217. #endif
  19218. #if JUCE_MAC
  19219. list.add (juce_createAudioIODeviceType_CoreAudio());
  19220. #endif
  19221. #if JUCE_IPHONE
  19222. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19223. #endif
  19224. #if JUCE_LINUX && JUCE_ALSA
  19225. list.add (juce_createAudioIODeviceType_ALSA());
  19226. #endif
  19227. #if JUCE_LINUX && JUCE_JACK
  19228. list.add (juce_createAudioIODeviceType_JACK());
  19229. #endif
  19230. }
  19231. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19232. const int numOutputChannelsNeeded,
  19233. const XmlElement* const e,
  19234. const bool selectDefaultDeviceOnFailure,
  19235. const String& preferredDefaultDeviceName,
  19236. const AudioDeviceSetup* preferredSetupOptions)
  19237. {
  19238. scanDevicesIfNeeded();
  19239. numInputChansNeeded = numInputChannelsNeeded;
  19240. numOutputChansNeeded = numOutputChannelsNeeded;
  19241. if (e != 0 && e->hasTagName ("DEVICESETUP"))
  19242. {
  19243. lastExplicitSettings = new XmlElement (*e);
  19244. String error;
  19245. AudioDeviceSetup setup;
  19246. if (preferredSetupOptions != 0)
  19247. setup = *preferredSetupOptions;
  19248. if (e->getStringAttribute ("audioDeviceName").isNotEmpty())
  19249. {
  19250. setup.inputDeviceName = setup.outputDeviceName
  19251. = e->getStringAttribute ("audioDeviceName");
  19252. }
  19253. else
  19254. {
  19255. setup.inputDeviceName = e->getStringAttribute ("audioInputDeviceName");
  19256. setup.outputDeviceName = e->getStringAttribute ("audioOutputDeviceName");
  19257. }
  19258. currentDeviceType = e->getStringAttribute ("deviceType");
  19259. if (currentDeviceType.isEmpty())
  19260. {
  19261. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19262. if (type != 0)
  19263. currentDeviceType = type->getTypeName();
  19264. else if (availableDeviceTypes.size() > 0)
  19265. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19266. }
  19267. setup.bufferSize = e->getIntAttribute ("audioDeviceBufferSize");
  19268. setup.sampleRate = e->getDoubleAttribute ("audioDeviceRate");
  19269. setup.inputChannels.parseString (e->getStringAttribute ("audioDeviceInChans", "11"), 2);
  19270. setup.outputChannels.parseString (e->getStringAttribute ("audioDeviceOutChans", "11"), 2);
  19271. setup.useDefaultInputChannels = ! e->hasAttribute ("audioDeviceInChans");
  19272. setup.useDefaultOutputChannels = ! e->hasAttribute ("audioDeviceOutChans");
  19273. error = setAudioDeviceSetup (setup, true);
  19274. midiInsFromXml.clear();
  19275. forEachXmlChildElementWithTagName (*e, c, "MIDIINPUT")
  19276. midiInsFromXml.add (c->getStringAttribute ("name"));
  19277. const StringArray allMidiIns (MidiInput::getDevices());
  19278. for (int i = allMidiIns.size(); --i >= 0;)
  19279. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19280. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19281. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19282. false, preferredDefaultDeviceName);
  19283. setDefaultMidiOutput (e->getStringAttribute ("defaultMidiOutput"));
  19284. return error;
  19285. }
  19286. else
  19287. {
  19288. AudioDeviceSetup setup;
  19289. if (preferredSetupOptions != 0)
  19290. {
  19291. setup = *preferredSetupOptions;
  19292. }
  19293. else if (preferredDefaultDeviceName.isNotEmpty())
  19294. {
  19295. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19296. {
  19297. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19298. StringArray outs (type->getDeviceNames (false));
  19299. int i;
  19300. for (i = 0; i < outs.size(); ++i)
  19301. {
  19302. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19303. {
  19304. setup.outputDeviceName = outs[i];
  19305. break;
  19306. }
  19307. }
  19308. StringArray ins (type->getDeviceNames (true));
  19309. for (i = 0; i < ins.size(); ++i)
  19310. {
  19311. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19312. {
  19313. setup.inputDeviceName = ins[i];
  19314. break;
  19315. }
  19316. }
  19317. }
  19318. }
  19319. insertDefaultDeviceNames (setup);
  19320. return setAudioDeviceSetup (setup, false);
  19321. }
  19322. }
  19323. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19324. {
  19325. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19326. if (type != 0)
  19327. {
  19328. if (setup.outputDeviceName.isEmpty())
  19329. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19330. if (setup.inputDeviceName.isEmpty())
  19331. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19332. }
  19333. }
  19334. XmlElement* AudioDeviceManager::createStateXml() const
  19335. {
  19336. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19337. }
  19338. void AudioDeviceManager::scanDevicesIfNeeded()
  19339. {
  19340. if (listNeedsScanning)
  19341. {
  19342. listNeedsScanning = false;
  19343. createDeviceTypesIfNeeded();
  19344. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19345. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19346. }
  19347. }
  19348. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19349. {
  19350. scanDevicesIfNeeded();
  19351. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19352. {
  19353. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19354. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19355. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19356. {
  19357. return type;
  19358. }
  19359. }
  19360. return 0;
  19361. }
  19362. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19363. {
  19364. setup = currentSetup;
  19365. }
  19366. void AudioDeviceManager::deleteCurrentDevice()
  19367. {
  19368. currentAudioDevice = 0;
  19369. currentSetup.inputDeviceName = String::empty;
  19370. currentSetup.outputDeviceName = String::empty;
  19371. }
  19372. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19373. const bool treatAsChosenDevice)
  19374. {
  19375. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19376. {
  19377. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19378. && currentDeviceType != type)
  19379. {
  19380. currentDeviceType = type;
  19381. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19382. insertDefaultDeviceNames (s);
  19383. setAudioDeviceSetup (s, treatAsChosenDevice);
  19384. sendChangeMessage (this);
  19385. break;
  19386. }
  19387. }
  19388. }
  19389. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19390. {
  19391. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19392. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19393. return availableDeviceTypes[i];
  19394. return availableDeviceTypes[0];
  19395. }
  19396. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19397. const bool treatAsChosenDevice)
  19398. {
  19399. jassert (&newSetup != &currentSetup); // this will have no effect
  19400. if (newSetup == currentSetup && currentAudioDevice != 0)
  19401. return String::empty;
  19402. if (! (newSetup == currentSetup))
  19403. sendChangeMessage (this);
  19404. stopDevice();
  19405. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19406. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19407. String error;
  19408. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19409. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19410. {
  19411. deleteCurrentDevice();
  19412. if (treatAsChosenDevice)
  19413. updateXml();
  19414. return String::empty;
  19415. }
  19416. if (currentSetup.inputDeviceName != newInputDeviceName
  19417. || currentSetup.outputDeviceName != newOutputDeviceName
  19418. || currentAudioDevice == 0)
  19419. {
  19420. deleteCurrentDevice();
  19421. scanDevicesIfNeeded();
  19422. if (newOutputDeviceName.isNotEmpty()
  19423. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19424. {
  19425. return "No such device: " + newOutputDeviceName;
  19426. }
  19427. if (newInputDeviceName.isNotEmpty()
  19428. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19429. {
  19430. return "No such device: " + newInputDeviceName;
  19431. }
  19432. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19433. if (currentAudioDevice == 0)
  19434. 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!";
  19435. else
  19436. error = currentAudioDevice->getLastError();
  19437. if (error.isNotEmpty())
  19438. {
  19439. deleteCurrentDevice();
  19440. return error;
  19441. }
  19442. if (newSetup.useDefaultInputChannels)
  19443. {
  19444. inputChannels.clear();
  19445. inputChannels.setRange (0, numInputChansNeeded, true);
  19446. }
  19447. if (newSetup.useDefaultOutputChannels)
  19448. {
  19449. outputChannels.clear();
  19450. outputChannels.setRange (0, numOutputChansNeeded, true);
  19451. }
  19452. if (newInputDeviceName.isEmpty())
  19453. inputChannels.clear();
  19454. if (newOutputDeviceName.isEmpty())
  19455. outputChannels.clear();
  19456. }
  19457. if (! newSetup.useDefaultInputChannels)
  19458. inputChannels = newSetup.inputChannels;
  19459. if (! newSetup.useDefaultOutputChannels)
  19460. outputChannels = newSetup.outputChannels;
  19461. currentSetup = newSetup;
  19462. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19463. error = currentAudioDevice->open (inputChannels,
  19464. outputChannels,
  19465. currentSetup.sampleRate,
  19466. currentSetup.bufferSize);
  19467. if (error.isEmpty())
  19468. {
  19469. currentDeviceType = currentAudioDevice->getTypeName();
  19470. currentAudioDevice->start (&callbackHandler);
  19471. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19472. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19473. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19474. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19475. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19476. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19477. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19478. if (treatAsChosenDevice)
  19479. updateXml();
  19480. }
  19481. else
  19482. {
  19483. deleteCurrentDevice();
  19484. }
  19485. return error;
  19486. }
  19487. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19488. {
  19489. jassert (currentAudioDevice != 0);
  19490. if (rate > 0)
  19491. {
  19492. bool ok = false;
  19493. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19494. {
  19495. const double sr = currentAudioDevice->getSampleRate (i);
  19496. if (sr == rate)
  19497. ok = true;
  19498. }
  19499. if (! ok)
  19500. rate = 0;
  19501. }
  19502. if (rate == 0)
  19503. {
  19504. double lowestAbove44 = 0.0;
  19505. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19506. {
  19507. const double sr = currentAudioDevice->getSampleRate (i);
  19508. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19509. lowestAbove44 = sr;
  19510. }
  19511. if (lowestAbove44 == 0.0)
  19512. rate = currentAudioDevice->getSampleRate (0);
  19513. else
  19514. rate = lowestAbove44;
  19515. }
  19516. return rate;
  19517. }
  19518. void AudioDeviceManager::stopDevice()
  19519. {
  19520. if (currentAudioDevice != 0)
  19521. currentAudioDevice->stop();
  19522. testSound = 0;
  19523. }
  19524. void AudioDeviceManager::closeAudioDevice()
  19525. {
  19526. stopDevice();
  19527. currentAudioDevice = 0;
  19528. }
  19529. void AudioDeviceManager::restartLastAudioDevice()
  19530. {
  19531. if (currentAudioDevice == 0)
  19532. {
  19533. if (currentSetup.inputDeviceName.isEmpty()
  19534. && currentSetup.outputDeviceName.isEmpty())
  19535. {
  19536. // This method will only reload the last device that was running
  19537. // before closeAudioDevice() was called - you need to actually open
  19538. // one first, with setAudioDevice().
  19539. jassertfalse
  19540. return;
  19541. }
  19542. AudioDeviceSetup s (currentSetup);
  19543. setAudioDeviceSetup (s, false);
  19544. }
  19545. }
  19546. void AudioDeviceManager::updateXml()
  19547. {
  19548. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19549. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19550. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19551. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19552. if (currentAudioDevice != 0)
  19553. {
  19554. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19555. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19556. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19557. if (! currentSetup.useDefaultInputChannels)
  19558. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19559. if (! currentSetup.useDefaultOutputChannels)
  19560. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19561. }
  19562. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19563. {
  19564. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19565. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19566. }
  19567. if (midiInsFromXml.size() > 0)
  19568. {
  19569. // Add any midi devices that have been enabled before, but which aren't currently
  19570. // open because the device has been disconnected.
  19571. const StringArray availableMidiDevices (MidiInput::getDevices());
  19572. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19573. {
  19574. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19575. {
  19576. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19577. m->setAttribute ("name", midiInsFromXml[i]);
  19578. }
  19579. }
  19580. }
  19581. if (defaultMidiOutputName.isNotEmpty())
  19582. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19583. }
  19584. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19585. {
  19586. {
  19587. const ScopedLock sl (audioCallbackLock);
  19588. if (callbacks.contains (newCallback))
  19589. return;
  19590. }
  19591. if (currentAudioDevice != 0 && newCallback != 0)
  19592. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19593. const ScopedLock sl (audioCallbackLock);
  19594. callbacks.add (newCallback);
  19595. }
  19596. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19597. {
  19598. if (callback != 0)
  19599. {
  19600. bool needsDeinitialising = currentAudioDevice != 0;
  19601. {
  19602. const ScopedLock sl (audioCallbackLock);
  19603. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19604. callbacks.removeValue (callback);
  19605. }
  19606. if (needsDeinitialising)
  19607. callback->audioDeviceStopped();
  19608. }
  19609. }
  19610. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19611. int numInputChannels,
  19612. float** outputChannelData,
  19613. int numOutputChannels,
  19614. int numSamples)
  19615. {
  19616. const ScopedLock sl (audioCallbackLock);
  19617. if (inputLevelMeasurementEnabledCount > 0)
  19618. {
  19619. for (int j = 0; j < numSamples; ++j)
  19620. {
  19621. float s = 0;
  19622. for (int i = 0; i < numInputChannels; ++i)
  19623. s += fabsf (inputChannelData[i][j]);
  19624. s /= numInputChannels;
  19625. const double decayFactor = 0.99992;
  19626. if (s > inputLevel)
  19627. inputLevel = s;
  19628. else if (inputLevel > 0.001f)
  19629. inputLevel *= decayFactor;
  19630. else
  19631. inputLevel = 0;
  19632. }
  19633. }
  19634. if (callbacks.size() > 0)
  19635. {
  19636. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19637. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19638. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19639. outputChannelData, numOutputChannels, numSamples);
  19640. float** const tempChans = tempBuffer.getArrayOfChannels();
  19641. for (int i = callbacks.size(); --i > 0;)
  19642. {
  19643. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19644. tempChans, numOutputChannels, numSamples);
  19645. for (int chan = 0; chan < numOutputChannels; ++chan)
  19646. {
  19647. const float* const src = tempChans [chan];
  19648. float* const dst = outputChannelData [chan];
  19649. if (src != 0 && dst != 0)
  19650. for (int j = 0; j < numSamples; ++j)
  19651. dst[j] += src[j];
  19652. }
  19653. }
  19654. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19655. const double filterAmount = 0.2;
  19656. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19657. }
  19658. else
  19659. {
  19660. for (int i = 0; i < numOutputChannels; ++i)
  19661. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19662. }
  19663. if (testSound != 0)
  19664. {
  19665. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19666. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19667. for (int i = 0; i < numOutputChannels; ++i)
  19668. for (int j = 0; j < numSamps; ++j)
  19669. outputChannelData [i][j] += src[j];
  19670. testSoundPosition += numSamps;
  19671. if (testSoundPosition >= testSound->getNumSamples())
  19672. testSound = 0;
  19673. }
  19674. }
  19675. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19676. {
  19677. cpuUsageMs = 0;
  19678. const double sampleRate = device->getCurrentSampleRate();
  19679. const int blockSize = device->getCurrentBufferSizeSamples();
  19680. if (sampleRate > 0.0 && blockSize > 0)
  19681. {
  19682. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19683. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19684. }
  19685. {
  19686. const ScopedLock sl (audioCallbackLock);
  19687. for (int i = callbacks.size(); --i >= 0;)
  19688. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19689. }
  19690. sendChangeMessage (this);
  19691. }
  19692. void AudioDeviceManager::audioDeviceStoppedInt()
  19693. {
  19694. cpuUsageMs = 0;
  19695. timeToCpuScale = 0;
  19696. sendChangeMessage (this);
  19697. const ScopedLock sl (audioCallbackLock);
  19698. for (int i = callbacks.size(); --i >= 0;)
  19699. callbacks.getUnchecked(i)->audioDeviceStopped();
  19700. }
  19701. double AudioDeviceManager::getCpuUsage() const
  19702. {
  19703. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19704. }
  19705. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19706. const bool enabled)
  19707. {
  19708. if (enabled != isMidiInputEnabled (name))
  19709. {
  19710. if (enabled)
  19711. {
  19712. const int index = MidiInput::getDevices().indexOf (name);
  19713. if (index >= 0)
  19714. {
  19715. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19716. if (min != 0)
  19717. {
  19718. enabledMidiInputs.add (min);
  19719. min->start();
  19720. }
  19721. }
  19722. }
  19723. else
  19724. {
  19725. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19726. if (enabledMidiInputs[i]->getName() == name)
  19727. enabledMidiInputs.remove (i);
  19728. }
  19729. updateXml();
  19730. sendChangeMessage (this);
  19731. }
  19732. }
  19733. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19734. {
  19735. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19736. if (enabledMidiInputs[i]->getName() == name)
  19737. return true;
  19738. return false;
  19739. }
  19740. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19741. MidiInputCallback* callback)
  19742. {
  19743. removeMidiInputCallback (name, callback);
  19744. if (name.isEmpty())
  19745. {
  19746. midiCallbacks.add (callback);
  19747. midiCallbackDevices.add (0);
  19748. }
  19749. else
  19750. {
  19751. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19752. {
  19753. if (enabledMidiInputs[i]->getName() == name)
  19754. {
  19755. const ScopedLock sl (midiCallbackLock);
  19756. midiCallbacks.add (callback);
  19757. midiCallbackDevices.add (enabledMidiInputs[i]);
  19758. break;
  19759. }
  19760. }
  19761. }
  19762. }
  19763. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19764. MidiInputCallback* /*callback*/)
  19765. {
  19766. const ScopedLock sl (midiCallbackLock);
  19767. for (int i = midiCallbacks.size(); --i >= 0;)
  19768. {
  19769. String devName;
  19770. if (midiCallbackDevices.getUnchecked(i) != 0)
  19771. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19772. if (devName == name)
  19773. {
  19774. midiCallbacks.remove (i);
  19775. midiCallbackDevices.remove (i);
  19776. }
  19777. }
  19778. }
  19779. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19780. const MidiMessage& message)
  19781. {
  19782. if (! message.isActiveSense())
  19783. {
  19784. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19785. const ScopedLock sl (midiCallbackLock);
  19786. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19787. {
  19788. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19789. if (md == source || (md == 0 && isDefaultSource))
  19790. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19791. }
  19792. }
  19793. }
  19794. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19795. {
  19796. if (defaultMidiOutputName != deviceName)
  19797. {
  19798. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19799. {
  19800. const ScopedLock sl (audioCallbackLock);
  19801. oldCallbacks = callbacks;
  19802. callbacks.clear();
  19803. }
  19804. if (currentAudioDevice != 0)
  19805. for (int i = oldCallbacks.size(); --i >= 0;)
  19806. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19807. defaultMidiOutput = 0;
  19808. defaultMidiOutputName = deviceName;
  19809. if (deviceName.isNotEmpty())
  19810. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19811. if (currentAudioDevice != 0)
  19812. for (int i = oldCallbacks.size(); --i >= 0;)
  19813. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19814. {
  19815. const ScopedLock sl (audioCallbackLock);
  19816. callbacks = oldCallbacks;
  19817. }
  19818. updateXml();
  19819. sendChangeMessage (this);
  19820. }
  19821. }
  19822. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19823. int numInputChannels,
  19824. float** outputChannelData,
  19825. int numOutputChannels,
  19826. int numSamples)
  19827. {
  19828. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19829. }
  19830. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19831. {
  19832. owner->audioDeviceAboutToStartInt (device);
  19833. }
  19834. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19835. {
  19836. owner->audioDeviceStoppedInt();
  19837. }
  19838. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19839. {
  19840. owner->handleIncomingMidiMessageInt (source, message);
  19841. }
  19842. void AudioDeviceManager::playTestSound()
  19843. {
  19844. { // cunningly nested to swap, unlock and delete in that order.
  19845. ScopedPointer <AudioSampleBuffer> oldSound;
  19846. {
  19847. const ScopedLock sl (audioCallbackLock);
  19848. oldSound = testSound;
  19849. }
  19850. }
  19851. testSoundPosition = 0;
  19852. if (currentAudioDevice != 0)
  19853. {
  19854. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19855. const int soundLength = (int) sampleRate;
  19856. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19857. float* samples = newSound->getSampleData (0);
  19858. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19859. const float amplitude = 0.5f;
  19860. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19861. for (int i = 0; i < soundLength; ++i)
  19862. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19863. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19864. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19865. const ScopedLock sl (audioCallbackLock);
  19866. testSound = newSound;
  19867. }
  19868. }
  19869. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19870. {
  19871. const ScopedLock sl (audioCallbackLock);
  19872. if (enableMeasurement)
  19873. ++inputLevelMeasurementEnabledCount;
  19874. else
  19875. --inputLevelMeasurementEnabledCount;
  19876. inputLevel = 0;
  19877. }
  19878. double AudioDeviceManager::getCurrentInputLevel() const
  19879. {
  19880. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  19881. return inputLevel;
  19882. }
  19883. END_JUCE_NAMESPACE
  19884. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  19885. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  19886. BEGIN_JUCE_NAMESPACE
  19887. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  19888. : name (deviceName),
  19889. typeName (typeName_)
  19890. {
  19891. }
  19892. AudioIODevice::~AudioIODevice()
  19893. {
  19894. }
  19895. bool AudioIODevice::hasControlPanel() const
  19896. {
  19897. return false;
  19898. }
  19899. bool AudioIODevice::showControlPanel()
  19900. {
  19901. jassertfalse // this should only be called for devices which return true from
  19902. // their hasControlPanel() method.
  19903. return false;
  19904. }
  19905. END_JUCE_NAMESPACE
  19906. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  19907. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  19908. BEGIN_JUCE_NAMESPACE
  19909. AudioIODeviceType::AudioIODeviceType (const String& name)
  19910. : typeName (name)
  19911. {
  19912. }
  19913. AudioIODeviceType::~AudioIODeviceType()
  19914. {
  19915. }
  19916. END_JUCE_NAMESPACE
  19917. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  19918. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  19919. BEGIN_JUCE_NAMESPACE
  19920. MidiOutput::MidiOutput()
  19921. : Thread ("midi out"),
  19922. internal (0),
  19923. firstMessage (0)
  19924. {
  19925. }
  19926. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  19927. const double sampleNumber)
  19928. : message (data, len, sampleNumber)
  19929. {
  19930. }
  19931. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  19932. const double millisecondCounterToStartAt,
  19933. double samplesPerSecondForBuffer)
  19934. {
  19935. // You've got to call startBackgroundThread() for this to actually work..
  19936. jassert (isThreadRunning());
  19937. // this needs to be a value in the future - RTFM for this method!
  19938. jassert (millisecondCounterToStartAt > 0);
  19939. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  19940. MidiBuffer::Iterator i (buffer);
  19941. const uint8* data;
  19942. int len, time;
  19943. while (i.getNextEvent (data, len, time))
  19944. {
  19945. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  19946. PendingMessage* const m
  19947. = new PendingMessage (data, len, eventTime);
  19948. const ScopedLock sl (lock);
  19949. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  19950. {
  19951. m->next = firstMessage;
  19952. firstMessage = m;
  19953. }
  19954. else
  19955. {
  19956. PendingMessage* mm = firstMessage;
  19957. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  19958. mm = mm->next;
  19959. m->next = mm->next;
  19960. mm->next = m;
  19961. }
  19962. }
  19963. notify();
  19964. }
  19965. void MidiOutput::clearAllPendingMessages()
  19966. {
  19967. const ScopedLock sl (lock);
  19968. while (firstMessage != 0)
  19969. {
  19970. PendingMessage* const m = firstMessage;
  19971. firstMessage = firstMessage->next;
  19972. delete m;
  19973. }
  19974. }
  19975. void MidiOutput::startBackgroundThread()
  19976. {
  19977. startThread (9);
  19978. }
  19979. void MidiOutput::stopBackgroundThread()
  19980. {
  19981. stopThread (5000);
  19982. }
  19983. void MidiOutput::run()
  19984. {
  19985. while (! threadShouldExit())
  19986. {
  19987. uint32 now = Time::getMillisecondCounter();
  19988. uint32 eventTime = 0;
  19989. uint32 timeToWait = 500;
  19990. PendingMessage* message;
  19991. {
  19992. const ScopedLock sl (lock);
  19993. message = firstMessage;
  19994. if (message != 0)
  19995. {
  19996. eventTime = roundToInt (message->message.getTimeStamp());
  19997. if (eventTime > now + 20)
  19998. {
  19999. timeToWait = eventTime - (now + 20);
  20000. message = 0;
  20001. }
  20002. else
  20003. {
  20004. firstMessage = message->next;
  20005. }
  20006. }
  20007. }
  20008. if (message != 0)
  20009. {
  20010. if (eventTime > now)
  20011. {
  20012. Time::waitForMillisecondCounter (eventTime);
  20013. if (threadShouldExit())
  20014. break;
  20015. }
  20016. if (eventTime > now - 200)
  20017. sendMessageNow (message->message);
  20018. delete message;
  20019. }
  20020. else
  20021. {
  20022. jassert (timeToWait < 1000 * 30);
  20023. wait (timeToWait);
  20024. }
  20025. }
  20026. clearAllPendingMessages();
  20027. }
  20028. END_JUCE_NAMESPACE
  20029. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20030. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20031. BEGIN_JUCE_NAMESPACE
  20032. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20033. {
  20034. const double maxVal = (double) 0x7fff;
  20035. char* intData = (char*) dest;
  20036. if (dest != (void*) source || destBytesPerSample <= 4)
  20037. {
  20038. for (int i = 0; i < numSamples; ++i)
  20039. {
  20040. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20041. intData += destBytesPerSample;
  20042. }
  20043. }
  20044. else
  20045. {
  20046. intData += destBytesPerSample * numSamples;
  20047. for (int i = numSamples; --i >= 0;)
  20048. {
  20049. intData -= destBytesPerSample;
  20050. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20051. }
  20052. }
  20053. }
  20054. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20055. {
  20056. const double maxVal = (double) 0x7fff;
  20057. char* intData = (char*) dest;
  20058. if (dest != (void*) source || destBytesPerSample <= 4)
  20059. {
  20060. for (int i = 0; i < numSamples; ++i)
  20061. {
  20062. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20063. intData += destBytesPerSample;
  20064. }
  20065. }
  20066. else
  20067. {
  20068. intData += destBytesPerSample * numSamples;
  20069. for (int i = numSamples; --i >= 0;)
  20070. {
  20071. intData -= destBytesPerSample;
  20072. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20073. }
  20074. }
  20075. }
  20076. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20077. {
  20078. const double maxVal = (double) 0x7fffff;
  20079. char* intData = (char*) dest;
  20080. if (dest != (void*) source || destBytesPerSample <= 4)
  20081. {
  20082. for (int i = 0; i < numSamples; ++i)
  20083. {
  20084. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20085. intData += destBytesPerSample;
  20086. }
  20087. }
  20088. else
  20089. {
  20090. intData += destBytesPerSample * numSamples;
  20091. for (int i = numSamples; --i >= 0;)
  20092. {
  20093. intData -= destBytesPerSample;
  20094. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20095. }
  20096. }
  20097. }
  20098. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20099. {
  20100. const double maxVal = (double) 0x7fffff;
  20101. char* intData = (char*) dest;
  20102. if (dest != (void*) source || destBytesPerSample <= 4)
  20103. {
  20104. for (int i = 0; i < numSamples; ++i)
  20105. {
  20106. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20107. intData += destBytesPerSample;
  20108. }
  20109. }
  20110. else
  20111. {
  20112. intData += destBytesPerSample * numSamples;
  20113. for (int i = numSamples; --i >= 0;)
  20114. {
  20115. intData -= destBytesPerSample;
  20116. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20117. }
  20118. }
  20119. }
  20120. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20121. {
  20122. const double maxVal = (double) 0x7fffffff;
  20123. char* intData = (char*) dest;
  20124. if (dest != (void*) source || destBytesPerSample <= 4)
  20125. {
  20126. for (int i = 0; i < numSamples; ++i)
  20127. {
  20128. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20129. intData += destBytesPerSample;
  20130. }
  20131. }
  20132. else
  20133. {
  20134. intData += destBytesPerSample * numSamples;
  20135. for (int i = numSamples; --i >= 0;)
  20136. {
  20137. intData -= destBytesPerSample;
  20138. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20139. }
  20140. }
  20141. }
  20142. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20143. {
  20144. const double maxVal = (double) 0x7fffffff;
  20145. char* intData = (char*) dest;
  20146. if (dest != (void*) source || destBytesPerSample <= 4)
  20147. {
  20148. for (int i = 0; i < numSamples; ++i)
  20149. {
  20150. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20151. intData += destBytesPerSample;
  20152. }
  20153. }
  20154. else
  20155. {
  20156. intData += destBytesPerSample * numSamples;
  20157. for (int i = numSamples; --i >= 0;)
  20158. {
  20159. intData -= destBytesPerSample;
  20160. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20161. }
  20162. }
  20163. }
  20164. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20165. {
  20166. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20167. char* d = (char*) dest;
  20168. for (int i = 0; i < numSamples; ++i)
  20169. {
  20170. *(float*) d = source[i];
  20171. #if JUCE_BIG_ENDIAN
  20172. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20173. #endif
  20174. d += destBytesPerSample;
  20175. }
  20176. }
  20177. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20178. {
  20179. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20180. char* d = (char*) dest;
  20181. for (int i = 0; i < numSamples; ++i)
  20182. {
  20183. *(float*) d = source[i];
  20184. #if JUCE_LITTLE_ENDIAN
  20185. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20186. #endif
  20187. d += destBytesPerSample;
  20188. }
  20189. }
  20190. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20191. {
  20192. const float scale = 1.0f / 0x7fff;
  20193. const char* intData = (const char*) source;
  20194. if (source != (void*) dest || srcBytesPerSample >= 4)
  20195. {
  20196. for (int i = 0; i < numSamples; ++i)
  20197. {
  20198. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20199. intData += srcBytesPerSample;
  20200. }
  20201. }
  20202. else
  20203. {
  20204. intData += srcBytesPerSample * numSamples;
  20205. for (int i = numSamples; --i >= 0;)
  20206. {
  20207. intData -= srcBytesPerSample;
  20208. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20209. }
  20210. }
  20211. }
  20212. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20213. {
  20214. const float scale = 1.0f / 0x7fff;
  20215. const char* intData = (const char*) source;
  20216. if (source != (void*) dest || srcBytesPerSample >= 4)
  20217. {
  20218. for (int i = 0; i < numSamples; ++i)
  20219. {
  20220. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20221. intData += srcBytesPerSample;
  20222. }
  20223. }
  20224. else
  20225. {
  20226. intData += srcBytesPerSample * numSamples;
  20227. for (int i = numSamples; --i >= 0;)
  20228. {
  20229. intData -= srcBytesPerSample;
  20230. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20231. }
  20232. }
  20233. }
  20234. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20235. {
  20236. const float scale = 1.0f / 0x7fffff;
  20237. const char* intData = (const char*) source;
  20238. if (source != (void*) dest || srcBytesPerSample >= 4)
  20239. {
  20240. for (int i = 0; i < numSamples; ++i)
  20241. {
  20242. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20243. intData += srcBytesPerSample;
  20244. }
  20245. }
  20246. else
  20247. {
  20248. intData += srcBytesPerSample * numSamples;
  20249. for (int i = numSamples; --i >= 0;)
  20250. {
  20251. intData -= srcBytesPerSample;
  20252. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20253. }
  20254. }
  20255. }
  20256. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20257. {
  20258. const float scale = 1.0f / 0x7fffff;
  20259. const char* intData = (const char*) source;
  20260. if (source != (void*) dest || srcBytesPerSample >= 4)
  20261. {
  20262. for (int i = 0; i < numSamples; ++i)
  20263. {
  20264. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20265. intData += srcBytesPerSample;
  20266. }
  20267. }
  20268. else
  20269. {
  20270. intData += srcBytesPerSample * numSamples;
  20271. for (int i = numSamples; --i >= 0;)
  20272. {
  20273. intData -= srcBytesPerSample;
  20274. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20275. }
  20276. }
  20277. }
  20278. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20279. {
  20280. const float scale = 1.0f / 0x7fffffff;
  20281. const char* intData = (const char*) source;
  20282. if (source != (void*) dest || srcBytesPerSample >= 4)
  20283. {
  20284. for (int i = 0; i < numSamples; ++i)
  20285. {
  20286. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20287. intData += srcBytesPerSample;
  20288. }
  20289. }
  20290. else
  20291. {
  20292. intData += srcBytesPerSample * numSamples;
  20293. for (int i = numSamples; --i >= 0;)
  20294. {
  20295. intData -= srcBytesPerSample;
  20296. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20297. }
  20298. }
  20299. }
  20300. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20301. {
  20302. const float scale = 1.0f / 0x7fffffff;
  20303. const char* intData = (const char*) source;
  20304. if (source != (void*) dest || srcBytesPerSample >= 4)
  20305. {
  20306. for (int i = 0; i < numSamples; ++i)
  20307. {
  20308. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20309. intData += srcBytesPerSample;
  20310. }
  20311. }
  20312. else
  20313. {
  20314. intData += srcBytesPerSample * numSamples;
  20315. for (int i = numSamples; --i >= 0;)
  20316. {
  20317. intData -= srcBytesPerSample;
  20318. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20319. }
  20320. }
  20321. }
  20322. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20323. {
  20324. const char* s = (const char*) source;
  20325. for (int i = 0; i < numSamples; ++i)
  20326. {
  20327. dest[i] = *(float*)s;
  20328. #if JUCE_BIG_ENDIAN
  20329. uint32* const d = (uint32*) (dest + i);
  20330. *d = ByteOrder::swap (*d);
  20331. #endif
  20332. s += srcBytesPerSample;
  20333. }
  20334. }
  20335. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20336. {
  20337. const char* s = (const char*) source;
  20338. for (int i = 0; i < numSamples; ++i)
  20339. {
  20340. dest[i] = *(float*)s;
  20341. #if JUCE_LITTLE_ENDIAN
  20342. uint32* const d = (uint32*) (dest + i);
  20343. *d = ByteOrder::swap (*d);
  20344. #endif
  20345. s += srcBytesPerSample;
  20346. }
  20347. }
  20348. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20349. const float* const source,
  20350. void* const dest,
  20351. const int numSamples)
  20352. {
  20353. switch (destFormat)
  20354. {
  20355. case int16LE:
  20356. convertFloatToInt16LE (source, dest, numSamples);
  20357. break;
  20358. case int16BE:
  20359. convertFloatToInt16BE (source, dest, numSamples);
  20360. break;
  20361. case int24LE:
  20362. convertFloatToInt24LE (source, dest, numSamples);
  20363. break;
  20364. case int24BE:
  20365. convertFloatToInt24BE (source, dest, numSamples);
  20366. break;
  20367. case int32LE:
  20368. convertFloatToInt32LE (source, dest, numSamples);
  20369. break;
  20370. case int32BE:
  20371. convertFloatToInt32BE (source, dest, numSamples);
  20372. break;
  20373. case float32LE:
  20374. convertFloatToFloat32LE (source, dest, numSamples);
  20375. break;
  20376. case float32BE:
  20377. convertFloatToFloat32BE (source, dest, numSamples);
  20378. break;
  20379. default:
  20380. jassertfalse
  20381. break;
  20382. }
  20383. }
  20384. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20385. const void* const source,
  20386. float* const dest,
  20387. const int numSamples)
  20388. {
  20389. switch (sourceFormat)
  20390. {
  20391. case int16LE:
  20392. convertInt16LEToFloat (source, dest, numSamples);
  20393. break;
  20394. case int16BE:
  20395. convertInt16BEToFloat (source, dest, numSamples);
  20396. break;
  20397. case int24LE:
  20398. convertInt24LEToFloat (source, dest, numSamples);
  20399. break;
  20400. case int24BE:
  20401. convertInt24BEToFloat (source, dest, numSamples);
  20402. break;
  20403. case int32LE:
  20404. convertInt32LEToFloat (source, dest, numSamples);
  20405. break;
  20406. case int32BE:
  20407. convertInt32BEToFloat (source, dest, numSamples);
  20408. break;
  20409. case float32LE:
  20410. convertFloat32LEToFloat (source, dest, numSamples);
  20411. break;
  20412. case float32BE:
  20413. convertFloat32BEToFloat (source, dest, numSamples);
  20414. break;
  20415. default:
  20416. jassertfalse
  20417. break;
  20418. }
  20419. }
  20420. void AudioDataConverters::interleaveSamples (const float** const source,
  20421. float* const dest,
  20422. const int numSamples,
  20423. const int numChannels)
  20424. {
  20425. for (int chan = 0; chan < numChannels; ++chan)
  20426. {
  20427. int i = chan;
  20428. const float* src = source [chan];
  20429. for (int j = 0; j < numSamples; ++j)
  20430. {
  20431. dest [i] = src [j];
  20432. i += numChannels;
  20433. }
  20434. }
  20435. }
  20436. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20437. float** const dest,
  20438. const int numSamples,
  20439. const int numChannels)
  20440. {
  20441. for (int chan = 0; chan < numChannels; ++chan)
  20442. {
  20443. int i = chan;
  20444. float* dst = dest [chan];
  20445. for (int j = 0; j < numSamples; ++j)
  20446. {
  20447. dst [j] = source [i];
  20448. i += numChannels;
  20449. }
  20450. }
  20451. }
  20452. END_JUCE_NAMESPACE
  20453. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20454. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20455. BEGIN_JUCE_NAMESPACE
  20456. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20457. const int numSamples) throw()
  20458. : numChannels (numChannels_),
  20459. size (numSamples)
  20460. {
  20461. jassert (numSamples >= 0);
  20462. jassert (numChannels_ > 0);
  20463. allocateData();
  20464. }
  20465. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20466. : numChannels (other.numChannels),
  20467. size (other.size)
  20468. {
  20469. allocateData();
  20470. const size_t numBytes = size * sizeof (float);
  20471. for (int i = 0; i < numChannels; ++i)
  20472. memcpy (channels[i], other.channels[i], numBytes);
  20473. }
  20474. void AudioSampleBuffer::allocateData()
  20475. {
  20476. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20477. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20478. allocatedData.malloc (allocatedBytes);
  20479. channels = reinterpret_cast <float**> (allocatedData.getData());
  20480. float* chan = (float*) (allocatedData + channelListSize);
  20481. for (int i = 0; i < numChannels; ++i)
  20482. {
  20483. channels[i] = chan;
  20484. chan += size;
  20485. }
  20486. channels [numChannels] = 0;
  20487. }
  20488. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20489. const int numChannels_,
  20490. const int numSamples) throw()
  20491. : numChannels (numChannels_),
  20492. size (numSamples),
  20493. allocatedBytes (0)
  20494. {
  20495. jassert (numChannels_ > 0);
  20496. allocateChannels (dataToReferTo);
  20497. }
  20498. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20499. const int newNumChannels,
  20500. const int newNumSamples) throw()
  20501. {
  20502. jassert (newNumChannels > 0);
  20503. allocatedBytes = 0;
  20504. allocatedData.free();
  20505. numChannels = newNumChannels;
  20506. size = newNumSamples;
  20507. allocateChannels (dataToReferTo);
  20508. }
  20509. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20510. {
  20511. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20512. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20513. {
  20514. channels = static_cast <float**> (preallocatedChannelSpace);
  20515. }
  20516. else
  20517. {
  20518. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20519. channels = reinterpret_cast <float**> (allocatedData.getData());
  20520. }
  20521. for (int i = 0; i < numChannels; ++i)
  20522. {
  20523. // you have to pass in the same number of valid pointers as numChannels
  20524. jassert (dataToReferTo[i] != 0);
  20525. channels[i] = dataToReferTo[i];
  20526. }
  20527. channels [numChannels] = 0;
  20528. }
  20529. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20530. {
  20531. if (this != &other)
  20532. {
  20533. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20534. const size_t numBytes = size * sizeof (float);
  20535. for (int i = 0; i < numChannels; ++i)
  20536. memcpy (channels[i], other.channels[i], numBytes);
  20537. }
  20538. return *this;
  20539. }
  20540. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20541. {
  20542. }
  20543. void AudioSampleBuffer::setSize (const int newNumChannels,
  20544. const int newNumSamples,
  20545. const bool keepExistingContent,
  20546. const bool clearExtraSpace,
  20547. const bool avoidReallocating) throw()
  20548. {
  20549. jassert (newNumChannels > 0);
  20550. if (newNumSamples != size || newNumChannels != numChannels)
  20551. {
  20552. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20553. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20554. if (keepExistingContent)
  20555. {
  20556. HeapBlock <char> newData;
  20557. newData.allocate (newTotalBytes, clearExtraSpace);
  20558. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20559. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20560. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20561. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20562. for (int i = 0; i < numChansToCopy; ++i)
  20563. {
  20564. memcpy (newChan, channels[i], numBytesToCopy);
  20565. newChannels[i] = newChan;
  20566. newChan += newNumSamples;
  20567. }
  20568. allocatedData.swapWith (newData);
  20569. allocatedBytes = (int) newTotalBytes;
  20570. channels = newChannels;
  20571. }
  20572. else
  20573. {
  20574. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20575. {
  20576. if (clearExtraSpace)
  20577. zeromem (allocatedData, newTotalBytes);
  20578. }
  20579. else
  20580. {
  20581. allocatedBytes = newTotalBytes;
  20582. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20583. channels = reinterpret_cast <float**> (allocatedData.getData());
  20584. }
  20585. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20586. for (int i = 0; i < newNumChannels; ++i)
  20587. {
  20588. channels[i] = chan;
  20589. chan += newNumSamples;
  20590. }
  20591. }
  20592. channels [newNumChannels] = 0;
  20593. size = newNumSamples;
  20594. numChannels = newNumChannels;
  20595. }
  20596. }
  20597. void AudioSampleBuffer::clear() throw()
  20598. {
  20599. for (int i = 0; i < numChannels; ++i)
  20600. zeromem (channels[i], size * sizeof (float));
  20601. }
  20602. void AudioSampleBuffer::clear (const int startSample,
  20603. const int numSamples) throw()
  20604. {
  20605. jassert (startSample >= 0 && startSample + numSamples <= size);
  20606. for (int i = 0; i < numChannels; ++i)
  20607. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20608. }
  20609. void AudioSampleBuffer::clear (const int channel,
  20610. const int startSample,
  20611. const int numSamples) throw()
  20612. {
  20613. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20614. jassert (startSample >= 0 && startSample + numSamples <= size);
  20615. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20616. }
  20617. void AudioSampleBuffer::applyGain (const int channel,
  20618. const int startSample,
  20619. int numSamples,
  20620. const float gain) throw()
  20621. {
  20622. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20623. jassert (startSample >= 0 && startSample + numSamples <= size);
  20624. if (gain != 1.0f)
  20625. {
  20626. float* d = channels [channel] + startSample;
  20627. if (gain == 0.0f)
  20628. {
  20629. zeromem (d, sizeof (float) * numSamples);
  20630. }
  20631. else
  20632. {
  20633. while (--numSamples >= 0)
  20634. *d++ *= gain;
  20635. }
  20636. }
  20637. }
  20638. void AudioSampleBuffer::applyGainRamp (const int channel,
  20639. const int startSample,
  20640. int numSamples,
  20641. float startGain,
  20642. float endGain) throw()
  20643. {
  20644. if (startGain == endGain)
  20645. {
  20646. applyGain (channel, startSample, numSamples, startGain);
  20647. }
  20648. else
  20649. {
  20650. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20651. jassert (startSample >= 0 && startSample + numSamples <= size);
  20652. const float increment = (endGain - startGain) / numSamples;
  20653. float* d = channels [channel] + startSample;
  20654. while (--numSamples >= 0)
  20655. {
  20656. *d++ *= startGain;
  20657. startGain += increment;
  20658. }
  20659. }
  20660. }
  20661. void AudioSampleBuffer::applyGain (const int startSample,
  20662. const int numSamples,
  20663. const float gain) throw()
  20664. {
  20665. for (int i = 0; i < numChannels; ++i)
  20666. applyGain (i, startSample, numSamples, gain);
  20667. }
  20668. void AudioSampleBuffer::addFrom (const int destChannel,
  20669. const int destStartSample,
  20670. const AudioSampleBuffer& source,
  20671. const int sourceChannel,
  20672. const int sourceStartSample,
  20673. int numSamples,
  20674. const float gain) throw()
  20675. {
  20676. jassert (&source != this || sourceChannel != destChannel);
  20677. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20678. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20679. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20680. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20681. if (gain != 0.0f && numSamples > 0)
  20682. {
  20683. float* d = channels [destChannel] + destStartSample;
  20684. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20685. if (gain != 1.0f)
  20686. {
  20687. while (--numSamples >= 0)
  20688. *d++ += gain * *s++;
  20689. }
  20690. else
  20691. {
  20692. while (--numSamples >= 0)
  20693. *d++ += *s++;
  20694. }
  20695. }
  20696. }
  20697. void AudioSampleBuffer::addFrom (const int destChannel,
  20698. const int destStartSample,
  20699. const float* source,
  20700. int numSamples,
  20701. const float gain) throw()
  20702. {
  20703. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20704. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20705. jassert (source != 0);
  20706. if (gain != 0.0f && numSamples > 0)
  20707. {
  20708. float* d = channels [destChannel] + destStartSample;
  20709. if (gain != 1.0f)
  20710. {
  20711. while (--numSamples >= 0)
  20712. *d++ += gain * *source++;
  20713. }
  20714. else
  20715. {
  20716. while (--numSamples >= 0)
  20717. *d++ += *source++;
  20718. }
  20719. }
  20720. }
  20721. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20722. const int destStartSample,
  20723. const float* source,
  20724. int numSamples,
  20725. float startGain,
  20726. const float endGain) throw()
  20727. {
  20728. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20729. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20730. jassert (source != 0);
  20731. if (startGain == endGain)
  20732. {
  20733. addFrom (destChannel,
  20734. destStartSample,
  20735. source,
  20736. numSamples,
  20737. startGain);
  20738. }
  20739. else
  20740. {
  20741. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20742. {
  20743. const float increment = (endGain - startGain) / numSamples;
  20744. float* d = channels [destChannel] + destStartSample;
  20745. while (--numSamples >= 0)
  20746. {
  20747. *d++ += startGain * *source++;
  20748. startGain += increment;
  20749. }
  20750. }
  20751. }
  20752. }
  20753. void AudioSampleBuffer::copyFrom (const int destChannel,
  20754. const int destStartSample,
  20755. const AudioSampleBuffer& source,
  20756. const int sourceChannel,
  20757. const int sourceStartSample,
  20758. int numSamples) throw()
  20759. {
  20760. jassert (&source != this || sourceChannel != destChannel);
  20761. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20762. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20763. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20764. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20765. if (numSamples > 0)
  20766. {
  20767. memcpy (channels [destChannel] + destStartSample,
  20768. source.channels [sourceChannel] + sourceStartSample,
  20769. sizeof (float) * numSamples);
  20770. }
  20771. }
  20772. void AudioSampleBuffer::copyFrom (const int destChannel,
  20773. const int destStartSample,
  20774. const float* source,
  20775. int numSamples) throw()
  20776. {
  20777. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20778. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20779. jassert (source != 0);
  20780. if (numSamples > 0)
  20781. {
  20782. memcpy (channels [destChannel] + destStartSample,
  20783. source,
  20784. sizeof (float) * numSamples);
  20785. }
  20786. }
  20787. void AudioSampleBuffer::copyFrom (const int destChannel,
  20788. const int destStartSample,
  20789. const float* source,
  20790. int numSamples,
  20791. const float gain) throw()
  20792. {
  20793. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20794. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20795. jassert (source != 0);
  20796. if (numSamples > 0)
  20797. {
  20798. float* d = channels [destChannel] + destStartSample;
  20799. if (gain != 1.0f)
  20800. {
  20801. if (gain == 0)
  20802. {
  20803. zeromem (d, sizeof (float) * numSamples);
  20804. }
  20805. else
  20806. {
  20807. while (--numSamples >= 0)
  20808. *d++ = gain * *source++;
  20809. }
  20810. }
  20811. else
  20812. {
  20813. memcpy (d, source, sizeof (float) * numSamples);
  20814. }
  20815. }
  20816. }
  20817. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20818. const int destStartSample,
  20819. const float* source,
  20820. int numSamples,
  20821. float startGain,
  20822. float endGain) throw()
  20823. {
  20824. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20825. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20826. jassert (source != 0);
  20827. if (startGain == endGain)
  20828. {
  20829. copyFrom (destChannel,
  20830. destStartSample,
  20831. source,
  20832. numSamples,
  20833. startGain);
  20834. }
  20835. else
  20836. {
  20837. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20838. {
  20839. const float increment = (endGain - startGain) / numSamples;
  20840. float* d = channels [destChannel] + destStartSample;
  20841. while (--numSamples >= 0)
  20842. {
  20843. *d++ = startGain * *source++;
  20844. startGain += increment;
  20845. }
  20846. }
  20847. }
  20848. }
  20849. void AudioSampleBuffer::findMinMax (const int channel,
  20850. const int startSample,
  20851. int numSamples,
  20852. float& minVal,
  20853. float& maxVal) const throw()
  20854. {
  20855. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20856. jassert (startSample >= 0 && startSample + numSamples <= size);
  20857. if (numSamples <= 0)
  20858. {
  20859. minVal = 0.0f;
  20860. maxVal = 0.0f;
  20861. }
  20862. else
  20863. {
  20864. const float* d = channels [channel] + startSample;
  20865. float mn = *d++;
  20866. float mx = mn;
  20867. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20868. {
  20869. const float samp = *d++;
  20870. if (samp > mx)
  20871. mx = samp;
  20872. if (samp < mn)
  20873. mn = samp;
  20874. }
  20875. maxVal = mx;
  20876. minVal = mn;
  20877. }
  20878. }
  20879. float AudioSampleBuffer::getMagnitude (const int channel,
  20880. const int startSample,
  20881. const int numSamples) const throw()
  20882. {
  20883. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20884. jassert (startSample >= 0 && startSample + numSamples <= size);
  20885. float mn, mx;
  20886. findMinMax (channel, startSample, numSamples, mn, mx);
  20887. return jmax (mn, -mn, mx, -mx);
  20888. }
  20889. float AudioSampleBuffer::getMagnitude (const int startSample,
  20890. const int numSamples) const throw()
  20891. {
  20892. float mag = 0.0f;
  20893. for (int i = 0; i < numChannels; ++i)
  20894. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  20895. return mag;
  20896. }
  20897. float AudioSampleBuffer::getRMSLevel (const int channel,
  20898. const int startSample,
  20899. const int numSamples) const throw()
  20900. {
  20901. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20902. jassert (startSample >= 0 && startSample + numSamples <= size);
  20903. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  20904. return 0.0f;
  20905. const float* const data = channels [channel] + startSample;
  20906. double sum = 0.0;
  20907. for (int i = 0; i < numSamples; ++i)
  20908. {
  20909. const float sample = data [i];
  20910. sum += sample * sample;
  20911. }
  20912. return (float) sqrt (sum / numSamples);
  20913. }
  20914. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  20915. const int startSample,
  20916. const int numSamples,
  20917. const int readerStartSample,
  20918. const bool useLeftChan,
  20919. const bool useRightChan) throw()
  20920. {
  20921. jassert (reader != 0);
  20922. jassert (startSample >= 0 && startSample + numSamples <= size);
  20923. if (numSamples > 0)
  20924. {
  20925. int* chans[3];
  20926. if (useLeftChan == useRightChan)
  20927. {
  20928. chans[0] = (int*) getSampleData (0, startSample);
  20929. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  20930. }
  20931. else if (useLeftChan || (reader->numChannels == 1))
  20932. {
  20933. chans[0] = (int*) getSampleData (0, startSample);
  20934. chans[1] = 0;
  20935. }
  20936. else if (useRightChan)
  20937. {
  20938. chans[0] = 0;
  20939. chans[1] = (int*) getSampleData (0, startSample);
  20940. }
  20941. chans[2] = 0;
  20942. reader->read (chans, 2, readerStartSample, numSamples, true);
  20943. if (! reader->usesFloatingPointData)
  20944. {
  20945. for (int j = 0; j < 2; ++j)
  20946. {
  20947. float* const d = (float*) (chans[j]);
  20948. if (d != 0)
  20949. {
  20950. const float multiplier = 1.0f / 0x7fffffff;
  20951. for (int i = 0; i < numSamples; ++i)
  20952. d[i] = *(int*)(d + i) * multiplier;
  20953. }
  20954. }
  20955. }
  20956. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  20957. {
  20958. // if this is a stereo buffer and the source was mono, dupe the first channel..
  20959. memcpy (getSampleData (1, startSample),
  20960. getSampleData (0, startSample),
  20961. sizeof (float) * numSamples);
  20962. }
  20963. }
  20964. }
  20965. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  20966. const int startSample,
  20967. const int numSamples) const throw()
  20968. {
  20969. jassert (startSample >= 0 && startSample + numSamples <= size);
  20970. if (numSamples > 0)
  20971. {
  20972. int* chans [3];
  20973. if (writer->isFloatingPoint())
  20974. {
  20975. chans[0] = (int*) getSampleData (0, startSample);
  20976. if (numChannels > 1)
  20977. chans[1] = (int*) getSampleData (1, startSample);
  20978. else
  20979. chans[1] = 0;
  20980. chans[2] = 0;
  20981. writer->write ((const int**) chans, numSamples);
  20982. }
  20983. else
  20984. {
  20985. HeapBlock <int> tempBuffer (numSamples * 2);
  20986. chans[0] = tempBuffer;
  20987. if (numChannels > 1)
  20988. chans[1] = chans[0] + numSamples;
  20989. else
  20990. chans[1] = 0;
  20991. chans[2] = 0;
  20992. for (int j = 0; j < 2; ++j)
  20993. {
  20994. int* const dest = chans[j];
  20995. if (dest != 0)
  20996. {
  20997. const float* const src = channels [j] + startSample;
  20998. for (int i = 0; i < numSamples; ++i)
  20999. {
  21000. const double samp = src[i];
  21001. if (samp <= -1.0)
  21002. dest[i] = std::numeric_limits<int>::min();
  21003. else if (samp >= 1.0)
  21004. dest[i] = std::numeric_limits<int>::max();
  21005. else
  21006. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21007. }
  21008. }
  21009. }
  21010. writer->write ((const int**) chans, numSamples);
  21011. }
  21012. }
  21013. }
  21014. END_JUCE_NAMESPACE
  21015. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21016. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21017. BEGIN_JUCE_NAMESPACE
  21018. IIRFilter::IIRFilter()
  21019. : active (false)
  21020. {
  21021. reset();
  21022. }
  21023. IIRFilter::IIRFilter (const IIRFilter& other)
  21024. : active (other.active)
  21025. {
  21026. const ScopedLock sl (other.processLock);
  21027. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21028. reset();
  21029. }
  21030. IIRFilter::~IIRFilter()
  21031. {
  21032. }
  21033. void IIRFilter::reset() throw()
  21034. {
  21035. const ScopedLock sl (processLock);
  21036. x1 = 0;
  21037. x2 = 0;
  21038. y1 = 0;
  21039. y2 = 0;
  21040. }
  21041. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21042. {
  21043. float out = coefficients[0] * in
  21044. + coefficients[1] * x1
  21045. + coefficients[2] * x2
  21046. - coefficients[4] * y1
  21047. - coefficients[5] * y2;
  21048. #if JUCE_INTEL
  21049. if (! (out < -1.0e-8 || out > 1.0e-8))
  21050. out = 0;
  21051. #endif
  21052. x2 = x1;
  21053. x1 = in;
  21054. y2 = y1;
  21055. y1 = out;
  21056. return out;
  21057. }
  21058. void IIRFilter::processSamples (float* const samples,
  21059. const int numSamples) throw()
  21060. {
  21061. const ScopedLock sl (processLock);
  21062. if (active)
  21063. {
  21064. for (int i = 0; i < numSamples; ++i)
  21065. {
  21066. const float in = samples[i];
  21067. float out = coefficients[0] * in
  21068. + coefficients[1] * x1
  21069. + coefficients[2] * x2
  21070. - coefficients[4] * y1
  21071. - coefficients[5] * y2;
  21072. #if JUCE_INTEL
  21073. if (! (out < -1.0e-8 || out > 1.0e-8))
  21074. out = 0;
  21075. #endif
  21076. x2 = x1;
  21077. x1 = in;
  21078. y2 = y1;
  21079. y1 = out;
  21080. samples[i] = out;
  21081. }
  21082. }
  21083. }
  21084. void IIRFilter::makeLowPass (const double sampleRate,
  21085. const double frequency) throw()
  21086. {
  21087. jassert (sampleRate > 0);
  21088. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21089. const double nSquared = n * n;
  21090. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21091. setCoefficients (c1,
  21092. c1 * 2.0f,
  21093. c1,
  21094. 1.0,
  21095. c1 * 2.0 * (1.0 - nSquared),
  21096. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21097. }
  21098. void IIRFilter::makeHighPass (const double sampleRate,
  21099. const double frequency) throw()
  21100. {
  21101. const double n = tan (double_Pi * frequency / sampleRate);
  21102. const double nSquared = n * n;
  21103. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21104. setCoefficients (c1,
  21105. c1 * -2.0f,
  21106. c1,
  21107. 1.0,
  21108. c1 * 2.0 * (nSquared - 1.0),
  21109. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21110. }
  21111. void IIRFilter::makeLowShelf (const double sampleRate,
  21112. const double cutOffFrequency,
  21113. const double Q,
  21114. const float gainFactor) throw()
  21115. {
  21116. jassert (sampleRate > 0);
  21117. jassert (Q > 0);
  21118. const double A = jmax (0.0f, gainFactor);
  21119. const double aminus1 = A - 1.0;
  21120. const double aplus1 = A + 1.0;
  21121. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21122. const double coso = cos (omega);
  21123. const double beta = sin (omega) * sqrt (A) / Q;
  21124. const double aminus1TimesCoso = aminus1 * coso;
  21125. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21126. A * 2.0 * (aminus1 - aplus1 * coso),
  21127. A * (aplus1 - aminus1TimesCoso - beta),
  21128. aplus1 + aminus1TimesCoso + beta,
  21129. -2.0 * (aminus1 + aplus1 * coso),
  21130. aplus1 + aminus1TimesCoso - beta);
  21131. }
  21132. void IIRFilter::makeHighShelf (const double sampleRate,
  21133. const double cutOffFrequency,
  21134. const double Q,
  21135. const float gainFactor) throw()
  21136. {
  21137. jassert (sampleRate > 0);
  21138. jassert (Q > 0);
  21139. const double A = jmax (0.0f, gainFactor);
  21140. const double aminus1 = A - 1.0;
  21141. const double aplus1 = A + 1.0;
  21142. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21143. const double coso = cos (omega);
  21144. const double beta = sin (omega) * sqrt (A) / Q;
  21145. const double aminus1TimesCoso = aminus1 * coso;
  21146. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21147. A * -2.0 * (aminus1 + aplus1 * coso),
  21148. A * (aplus1 + aminus1TimesCoso - beta),
  21149. aplus1 - aminus1TimesCoso + beta,
  21150. 2.0 * (aminus1 - aplus1 * coso),
  21151. aplus1 - aminus1TimesCoso - beta);
  21152. }
  21153. void IIRFilter::makeBandPass (const double sampleRate,
  21154. const double centreFrequency,
  21155. const double Q,
  21156. const float gainFactor) throw()
  21157. {
  21158. jassert (sampleRate > 0);
  21159. jassert (Q > 0);
  21160. const double A = jmax (0.0f, gainFactor);
  21161. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21162. const double alpha = 0.5 * sin (omega) / Q;
  21163. const double c2 = -2.0 * cos (omega);
  21164. const double alphaTimesA = alpha * A;
  21165. const double alphaOverA = alpha / A;
  21166. setCoefficients (1.0 + alphaTimesA,
  21167. c2,
  21168. 1.0 - alphaTimesA,
  21169. 1.0 + alphaOverA,
  21170. c2,
  21171. 1.0 - alphaOverA);
  21172. }
  21173. void IIRFilter::makeInactive() throw()
  21174. {
  21175. const ScopedLock sl (processLock);
  21176. active = false;
  21177. }
  21178. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21179. {
  21180. const ScopedLock sl (processLock);
  21181. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21182. active = other.active;
  21183. }
  21184. void IIRFilter::setCoefficients (double c1,
  21185. double c2,
  21186. double c3,
  21187. double c4,
  21188. double c5,
  21189. double c6) throw()
  21190. {
  21191. const double a = 1.0 / c4;
  21192. c1 *= a;
  21193. c2 *= a;
  21194. c3 *= a;
  21195. c5 *= a;
  21196. c6 *= a;
  21197. const ScopedLock sl (processLock);
  21198. coefficients[0] = (float) c1;
  21199. coefficients[1] = (float) c2;
  21200. coefficients[2] = (float) c3;
  21201. coefficients[3] = (float) c4;
  21202. coefficients[4] = (float) c5;
  21203. coefficients[5] = (float) c6;
  21204. active = true;
  21205. }
  21206. END_JUCE_NAMESPACE
  21207. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21208. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21209. BEGIN_JUCE_NAMESPACE
  21210. MidiBuffer::MidiBuffer() throw()
  21211. : bytesUsed (0)
  21212. {
  21213. }
  21214. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21215. : bytesUsed (0)
  21216. {
  21217. addEvent (message, 0);
  21218. }
  21219. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21220. : data (other.data),
  21221. bytesUsed (other.bytesUsed)
  21222. {
  21223. }
  21224. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21225. {
  21226. bytesUsed = other.bytesUsed;
  21227. data = other.data;
  21228. return *this;
  21229. }
  21230. void MidiBuffer::swapWith (MidiBuffer& other)
  21231. {
  21232. data.swapWith (other.data);
  21233. swapVariables <int> (bytesUsed, other.bytesUsed);
  21234. }
  21235. MidiBuffer::~MidiBuffer() throw()
  21236. {
  21237. }
  21238. inline uint8* MidiBuffer::getData() const throw()
  21239. {
  21240. return static_cast <uint8*> (data.getData());
  21241. }
  21242. inline int MidiBuffer::getEventTime (const void* const d) throw()
  21243. {
  21244. return *static_cast <const int*> (d);
  21245. }
  21246. inline uint16 MidiBuffer::getEventDataSize (const void* const d) throw()
  21247. {
  21248. return *reinterpret_cast <const uint16*> (static_cast <const char*> (d) + sizeof (int));
  21249. }
  21250. inline uint16 MidiBuffer::getEventTotalSize (const void* const d) throw()
  21251. {
  21252. return getEventDataSize (d) + sizeof (int) + sizeof (uint16);
  21253. }
  21254. void MidiBuffer::clear() throw()
  21255. {
  21256. bytesUsed = 0;
  21257. }
  21258. void MidiBuffer::clear (const int startSample,
  21259. const int numSamples) throw()
  21260. {
  21261. uint8* const start = findEventAfter (getData(), startSample - 1);
  21262. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21263. if (end > start)
  21264. {
  21265. const int bytesToMove = bytesUsed - (int) (end - getData());
  21266. if (bytesToMove > 0)
  21267. memmove (start, end, bytesToMove);
  21268. bytesUsed -= (int) (end - start);
  21269. }
  21270. }
  21271. void MidiBuffer::addEvent (const MidiMessage& m,
  21272. const int sampleNumber) throw()
  21273. {
  21274. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21275. }
  21276. static int findActualEventLength (const uint8* const data,
  21277. const int maxBytes) throw()
  21278. {
  21279. unsigned int byte = (unsigned int) *data;
  21280. int size = 0;
  21281. if (byte == 0xf0 || byte == 0xf7)
  21282. {
  21283. const uint8* d = data + 1;
  21284. while (d < data + maxBytes)
  21285. if (*d++ == 0xf7)
  21286. break;
  21287. size = (int) (d - data);
  21288. }
  21289. else if (byte == 0xff)
  21290. {
  21291. int n;
  21292. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21293. size = jmin (maxBytes, n + 2 + bytesLeft);
  21294. }
  21295. else if (byte >= 0x80)
  21296. {
  21297. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21298. }
  21299. return size;
  21300. }
  21301. void MidiBuffer::addEvent (const uint8* const newData,
  21302. const int maxBytes,
  21303. const int sampleNumber) throw()
  21304. {
  21305. const int numBytes = findActualEventLength (newData, maxBytes);
  21306. if (numBytes > 0)
  21307. {
  21308. int spaceNeeded = bytesUsed + numBytes + sizeof (int) + sizeof (uint16);
  21309. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21310. uint8* d = findEventAfter (getData(), sampleNumber);
  21311. const int bytesToMove = bytesUsed - (int) (d - getData());
  21312. if (bytesToMove > 0)
  21313. memmove (d + numBytes + sizeof (int) + sizeof (uint16), d, bytesToMove);
  21314. *reinterpret_cast <int*> (d) = sampleNumber;
  21315. d += sizeof (int);
  21316. *reinterpret_cast <uint16*> (d) = (uint16) numBytes;
  21317. d += sizeof (uint16);
  21318. memcpy (d, newData, numBytes);
  21319. bytesUsed += numBytes + sizeof (int) + sizeof (uint16);
  21320. }
  21321. }
  21322. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21323. const int startSample,
  21324. const int numSamples,
  21325. const int sampleDeltaToAdd) throw()
  21326. {
  21327. Iterator i (otherBuffer);
  21328. i.setNextSamplePosition (startSample);
  21329. const uint8* eventData;
  21330. int eventSize, position;
  21331. while (i.getNextEvent (eventData, eventSize, position)
  21332. && (position < startSample + numSamples || numSamples < 0))
  21333. {
  21334. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21335. }
  21336. }
  21337. bool MidiBuffer::isEmpty() const throw()
  21338. {
  21339. return bytesUsed == 0;
  21340. }
  21341. int MidiBuffer::getNumEvents() const throw()
  21342. {
  21343. int n = 0;
  21344. const uint8* d = getData();
  21345. const uint8* const end = d + bytesUsed;
  21346. while (d < end)
  21347. {
  21348. d += getEventTotalSize (d);
  21349. ++n;
  21350. }
  21351. return n;
  21352. }
  21353. int MidiBuffer::getFirstEventTime() const throw()
  21354. {
  21355. return bytesUsed > 0 ? getEventTime (data.getData()) : 0;
  21356. }
  21357. int MidiBuffer::getLastEventTime() const throw()
  21358. {
  21359. if (bytesUsed == 0)
  21360. return 0;
  21361. const uint8* d = getData();
  21362. const uint8* const endData = d + bytesUsed;
  21363. for (;;)
  21364. {
  21365. const uint8* const nextOne = d + getEventTotalSize (d);
  21366. if (nextOne >= endData)
  21367. return getEventTime (d);
  21368. d = nextOne;
  21369. }
  21370. }
  21371. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21372. {
  21373. const uint8* const endData = getData() + bytesUsed;
  21374. while (d < endData && getEventTime (d) <= samplePosition)
  21375. d += getEventTotalSize (d);
  21376. return d;
  21377. }
  21378. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21379. : buffer (buffer_),
  21380. data (buffer_.getData())
  21381. {
  21382. }
  21383. MidiBuffer::Iterator::~Iterator() throw()
  21384. {
  21385. }
  21386. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21387. {
  21388. data = buffer.getData();
  21389. const uint8* dataEnd = data + buffer.bytesUsed;
  21390. while (data < dataEnd && getEventTime (data) < samplePosition)
  21391. data += getEventTotalSize (data);
  21392. }
  21393. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, int& samplePosition) throw()
  21394. {
  21395. if (data >= buffer.getData() + buffer.bytesUsed)
  21396. return false;
  21397. samplePosition = getEventTime (data);
  21398. numBytes = getEventDataSize (data);
  21399. data += sizeof (int) + sizeof (uint16);
  21400. midiData = data;
  21401. data += numBytes;
  21402. return true;
  21403. }
  21404. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePosition) throw()
  21405. {
  21406. if (data >= buffer.getData() + buffer.bytesUsed)
  21407. return false;
  21408. samplePosition = getEventTime (data);
  21409. const int numBytes = getEventDataSize (data);
  21410. data += sizeof (int) + sizeof (uint16);
  21411. result = MidiMessage (data, numBytes, samplePosition);
  21412. data += numBytes;
  21413. return true;
  21414. }
  21415. END_JUCE_NAMESPACE
  21416. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21417. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21418. BEGIN_JUCE_NAMESPACE
  21419. namespace MidiFileHelpers
  21420. {
  21421. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21422. {
  21423. unsigned int buffer = v & 0x7F;
  21424. while ((v >>= 7) != 0)
  21425. {
  21426. buffer <<= 8;
  21427. buffer |= ((v & 0x7F) | 0x80);
  21428. }
  21429. for (;;)
  21430. {
  21431. out.writeByte ((char) buffer);
  21432. if (buffer & 0x80)
  21433. buffer >>= 8;
  21434. else
  21435. break;
  21436. }
  21437. }
  21438. static bool parseMidiHeader (const char* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21439. {
  21440. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21441. data += 4;
  21442. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21443. {
  21444. bool ok = false;
  21445. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21446. {
  21447. for (int i = 0; i < 8; ++i)
  21448. {
  21449. ch = ByteOrder::bigEndianInt (data);
  21450. data += 4;
  21451. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21452. {
  21453. ok = true;
  21454. break;
  21455. }
  21456. }
  21457. }
  21458. if (! ok)
  21459. return false;
  21460. }
  21461. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21462. data += 4;
  21463. fileType = (short) ByteOrder::bigEndianShort (data);
  21464. data += 2;
  21465. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21466. data += 2;
  21467. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21468. data += 2;
  21469. bytesRemaining -= 6;
  21470. data += bytesRemaining;
  21471. return true;
  21472. }
  21473. static double convertTicksToSeconds (const double time,
  21474. const MidiMessageSequence& tempoEvents,
  21475. const int timeFormat)
  21476. {
  21477. if (timeFormat > 0)
  21478. {
  21479. int numer = 4, denom = 4;
  21480. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21481. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21482. double secsPerTick = 0.5 * tickLen;
  21483. const int numEvents = tempoEvents.getNumEvents();
  21484. for (int i = 0; i < numEvents; ++i)
  21485. {
  21486. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21487. if (time <= m.getTimeStamp())
  21488. break;
  21489. if (timeFormat > 0)
  21490. {
  21491. correctedTempoTime = correctedTempoTime
  21492. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21493. }
  21494. else
  21495. {
  21496. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21497. }
  21498. tempoTime = m.getTimeStamp();
  21499. if (m.isTempoMetaEvent())
  21500. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21501. else if (m.isTimeSignatureMetaEvent())
  21502. m.getTimeSignatureInfo (numer, denom);
  21503. while (i + 1 < numEvents)
  21504. {
  21505. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21506. if (m2.getTimeStamp() == tempoTime)
  21507. {
  21508. ++i;
  21509. if (m2.isTempoMetaEvent())
  21510. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21511. else if (m2.isTimeSignatureMetaEvent())
  21512. m2.getTimeSignatureInfo (numer, denom);
  21513. }
  21514. else
  21515. {
  21516. break;
  21517. }
  21518. }
  21519. }
  21520. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21521. }
  21522. else
  21523. {
  21524. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21525. }
  21526. }
  21527. }
  21528. MidiFile::MidiFile()
  21529. : timeFormat ((short) (unsigned short) 0xe728)
  21530. {
  21531. }
  21532. MidiFile::~MidiFile()
  21533. {
  21534. clear();
  21535. }
  21536. void MidiFile::clear()
  21537. {
  21538. tracks.clear();
  21539. }
  21540. int MidiFile::getNumTracks() const throw()
  21541. {
  21542. return tracks.size();
  21543. }
  21544. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21545. {
  21546. return tracks [index];
  21547. }
  21548. void MidiFile::addTrack (const MidiMessageSequence& trackSequence)
  21549. {
  21550. tracks.add (new MidiMessageSequence (trackSequence));
  21551. }
  21552. short MidiFile::getTimeFormat() const throw()
  21553. {
  21554. return timeFormat;
  21555. }
  21556. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21557. {
  21558. timeFormat = (short) ticks;
  21559. }
  21560. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21561. const int subframeResolution) throw()
  21562. {
  21563. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21564. }
  21565. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21566. {
  21567. for (int i = tracks.size(); --i >= 0;)
  21568. {
  21569. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21570. for (int j = 0; j < numEvents; ++j)
  21571. {
  21572. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21573. if (m.isTempoMetaEvent())
  21574. tempoChangeEvents.addEvent (m);
  21575. }
  21576. }
  21577. }
  21578. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21579. {
  21580. for (int i = tracks.size(); --i >= 0;)
  21581. {
  21582. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21583. for (int j = 0; j < numEvents; ++j)
  21584. {
  21585. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21586. if (m.isTimeSignatureMetaEvent())
  21587. timeSigEvents.addEvent (m);
  21588. }
  21589. }
  21590. }
  21591. double MidiFile::getLastTimestamp() const
  21592. {
  21593. double t = 0.0;
  21594. for (int i = tracks.size(); --i >= 0;)
  21595. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21596. return t;
  21597. }
  21598. bool MidiFile::readFrom (InputStream& sourceStream)
  21599. {
  21600. clear();
  21601. MemoryBlock data;
  21602. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21603. // (put a sanity-check on the file size, as midi files are generally small)
  21604. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21605. {
  21606. size_t size = data.getSize();
  21607. const char* d = (char*) data.getData();
  21608. short fileType, expectedTracks;
  21609. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21610. {
  21611. size -= (int) (d - (char*) data.getData());
  21612. int track = 0;
  21613. while (size > 0 && track < expectedTracks)
  21614. {
  21615. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21616. d += 4;
  21617. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21618. d += 4;
  21619. if (chunkSize <= 0)
  21620. break;
  21621. if (size < 0)
  21622. return false;
  21623. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21624. {
  21625. readNextTrack (d, chunkSize);
  21626. }
  21627. size -= chunkSize + 8;
  21628. d += chunkSize;
  21629. ++track;
  21630. }
  21631. return true;
  21632. }
  21633. }
  21634. return false;
  21635. }
  21636. // a comparator that puts all the note-offs before note-ons that have the same time
  21637. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21638. const MidiMessageSequence::MidiEventHolder* const second)
  21639. {
  21640. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21641. if (diff == 0)
  21642. {
  21643. if (first->message.isNoteOff() && second->message.isNoteOn())
  21644. return -1;
  21645. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21646. return 1;
  21647. else
  21648. return 0;
  21649. }
  21650. else
  21651. {
  21652. return (diff > 0) ? 1 : -1;
  21653. }
  21654. }
  21655. void MidiFile::readNextTrack (const char* data, int size)
  21656. {
  21657. double time = 0;
  21658. char lastStatusByte = 0;
  21659. MidiMessageSequence result;
  21660. while (size > 0)
  21661. {
  21662. int bytesUsed;
  21663. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21664. data += bytesUsed;
  21665. size -= bytesUsed;
  21666. time += delay;
  21667. int messSize = 0;
  21668. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21669. if (messSize <= 0)
  21670. break;
  21671. size -= messSize;
  21672. data += messSize;
  21673. result.addEvent (mm);
  21674. const char firstByte = *(mm.getRawData());
  21675. if ((firstByte & 0xf0) != 0xf0)
  21676. lastStatusByte = firstByte;
  21677. }
  21678. // use a sort that puts all the note-offs before note-ons that have the same time
  21679. result.list.sort (*this, true);
  21680. result.updateMatchedPairs();
  21681. addTrack (result);
  21682. }
  21683. void MidiFile::convertTimestampTicksToSeconds()
  21684. {
  21685. MidiMessageSequence tempoEvents;
  21686. findAllTempoEvents (tempoEvents);
  21687. findAllTimeSigEvents (tempoEvents);
  21688. for (int i = 0; i < tracks.size(); ++i)
  21689. {
  21690. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21691. for (int j = ms.getNumEvents(); --j >= 0;)
  21692. {
  21693. MidiMessage& m = ms.getEventPointer(j)->message;
  21694. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21695. tempoEvents,
  21696. timeFormat));
  21697. }
  21698. }
  21699. }
  21700. bool MidiFile::writeTo (OutputStream& out)
  21701. {
  21702. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21703. out.writeIntBigEndian (6);
  21704. out.writeShortBigEndian (1); // type
  21705. out.writeShortBigEndian ((short) tracks.size());
  21706. out.writeShortBigEndian (timeFormat);
  21707. for (int i = 0; i < tracks.size(); ++i)
  21708. writeTrack (out, i);
  21709. out.flush();
  21710. return true;
  21711. }
  21712. void MidiFile::writeTrack (OutputStream& mainOut,
  21713. const int trackNum)
  21714. {
  21715. MemoryOutputStream out;
  21716. const MidiMessageSequence& ms = *tracks[trackNum];
  21717. int lastTick = 0;
  21718. char lastStatusByte = 0;
  21719. for (int i = 0; i < ms.getNumEvents(); ++i)
  21720. {
  21721. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21722. const int tick = roundToInt (mm.getTimeStamp());
  21723. const int delta = jmax (0, tick - lastTick);
  21724. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21725. lastTick = tick;
  21726. const char statusByte = *(mm.getRawData());
  21727. if ((statusByte == lastStatusByte)
  21728. && ((statusByte & 0xf0) != 0xf0)
  21729. && i > 0
  21730. && mm.getRawDataSize() > 1)
  21731. {
  21732. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21733. }
  21734. else
  21735. {
  21736. out.write (mm.getRawData(), mm.getRawDataSize());
  21737. }
  21738. lastStatusByte = statusByte;
  21739. }
  21740. out.writeByte (0);
  21741. const MidiMessage m (MidiMessage::endOfTrack());
  21742. out.write (m.getRawData(),
  21743. m.getRawDataSize());
  21744. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21745. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21746. mainOut.write (out.getData(), (int) out.getDataSize());
  21747. }
  21748. END_JUCE_NAMESPACE
  21749. /*** End of inlined file: juce_MidiFile.cpp ***/
  21750. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21751. BEGIN_JUCE_NAMESPACE
  21752. MidiKeyboardState::MidiKeyboardState()
  21753. {
  21754. zerostruct (noteStates);
  21755. }
  21756. MidiKeyboardState::~MidiKeyboardState()
  21757. {
  21758. }
  21759. void MidiKeyboardState::reset()
  21760. {
  21761. const ScopedLock sl (lock);
  21762. zerostruct (noteStates);
  21763. eventsToAdd.clear();
  21764. }
  21765. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21766. {
  21767. jassert (midiChannel >= 0 && midiChannel <= 16);
  21768. return ((unsigned int) n) < 128
  21769. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21770. }
  21771. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21772. {
  21773. return ((unsigned int) n) < 128
  21774. && (noteStates[n] & midiChannelMask) != 0;
  21775. }
  21776. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21777. {
  21778. jassert (midiChannel >= 0 && midiChannel <= 16);
  21779. jassert (((unsigned int) midiNoteNumber) < 128);
  21780. const ScopedLock sl (lock);
  21781. if (((unsigned int) midiNoteNumber) < 128)
  21782. {
  21783. const int timeNow = (int) Time::getMillisecondCounter();
  21784. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21785. eventsToAdd.clear (0, timeNow - 500);
  21786. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21787. }
  21788. }
  21789. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21790. {
  21791. if (((unsigned int) midiNoteNumber) < 128)
  21792. {
  21793. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21794. for (int i = listeners.size(); --i >= 0;)
  21795. listeners.getUnchecked(i)->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21796. }
  21797. }
  21798. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21799. {
  21800. const ScopedLock sl (lock);
  21801. if (isNoteOn (midiChannel, midiNoteNumber))
  21802. {
  21803. const int timeNow = (int) Time::getMillisecondCounter();
  21804. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21805. eventsToAdd.clear (0, timeNow - 500);
  21806. noteOffInternal (midiChannel, midiNoteNumber);
  21807. }
  21808. }
  21809. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21810. {
  21811. if (isNoteOn (midiChannel, midiNoteNumber))
  21812. {
  21813. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21814. for (int i = listeners.size(); --i >= 0;)
  21815. listeners.getUnchecked(i)->handleNoteOff (this, midiChannel, midiNoteNumber);
  21816. }
  21817. }
  21818. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21819. {
  21820. const ScopedLock sl (lock);
  21821. if (midiChannel <= 0)
  21822. {
  21823. for (int i = 1; i <= 16; ++i)
  21824. allNotesOff (i);
  21825. }
  21826. else
  21827. {
  21828. for (int i = 0; i < 128; ++i)
  21829. noteOff (midiChannel, i);
  21830. }
  21831. }
  21832. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21833. {
  21834. if (message.isNoteOn())
  21835. {
  21836. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21837. }
  21838. else if (message.isNoteOff())
  21839. {
  21840. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21841. }
  21842. else if (message.isAllNotesOff())
  21843. {
  21844. for (int i = 0; i < 128; ++i)
  21845. noteOffInternal (message.getChannel(), i);
  21846. }
  21847. }
  21848. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21849. const int startSample,
  21850. const int numSamples,
  21851. const bool injectIndirectEvents)
  21852. {
  21853. MidiBuffer::Iterator i (buffer);
  21854. MidiMessage message (0xf4, 0.0);
  21855. int time;
  21856. const ScopedLock sl (lock);
  21857. while (i.getNextEvent (message, time))
  21858. processNextMidiEvent (message);
  21859. if (injectIndirectEvents)
  21860. {
  21861. MidiBuffer::Iterator i2 (eventsToAdd);
  21862. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21863. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21864. while (i2.getNextEvent (message, time))
  21865. {
  21866. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21867. buffer.addEvent (message, startSample + pos);
  21868. }
  21869. }
  21870. eventsToAdd.clear();
  21871. }
  21872. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  21873. {
  21874. const ScopedLock sl (lock);
  21875. listeners.addIfNotAlreadyThere (listener);
  21876. }
  21877. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  21878. {
  21879. const ScopedLock sl (lock);
  21880. listeners.removeValue (listener);
  21881. }
  21882. END_JUCE_NAMESPACE
  21883. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  21884. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  21885. BEGIN_JUCE_NAMESPACE
  21886. int MidiMessage::readVariableLengthVal (const uint8* data,
  21887. int& numBytesUsed) throw()
  21888. {
  21889. numBytesUsed = 0;
  21890. int v = 0;
  21891. int i;
  21892. do
  21893. {
  21894. i = (int) *data++;
  21895. if (++numBytesUsed > 6)
  21896. break;
  21897. v = (v << 7) + (i & 0x7f);
  21898. } while (i & 0x80);
  21899. return v;
  21900. }
  21901. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  21902. {
  21903. // this method only works for valid starting bytes of a short midi message
  21904. jassert (firstByte >= 0x80
  21905. && firstByte != 0xf0
  21906. && firstByte != 0xf7);
  21907. static const char messageLengths[] =
  21908. {
  21909. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21910. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21911. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21912. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21913. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21914. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21915. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21916. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  21917. };
  21918. return messageLengths [firstByte & 0x7f];
  21919. }
  21920. MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t)
  21921. : timeStamp (t),
  21922. size (dataSize)
  21923. {
  21924. jassert (dataSize > 0);
  21925. if (dataSize <= 4)
  21926. data = static_cast<uint8*> (preallocatedData.asBytes);
  21927. else
  21928. data = static_cast<uint8*> (juce_malloc (dataSize));
  21929. memcpy (data, d, dataSize);
  21930. // check that the length matches the data..
  21931. jassert (size > 3 || data[0] >= 0xf0 || getMessageLengthFromFirstByte (data[0]) == size);
  21932. }
  21933. MidiMessage::MidiMessage (const int byte1, const double t) throw()
  21934. : timeStamp (t),
  21935. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21936. size (1)
  21937. {
  21938. data[0] = (uint8) byte1;
  21939. // check that the length matches the data..
  21940. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  21941. }
  21942. MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) throw()
  21943. : timeStamp (t),
  21944. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21945. size (2)
  21946. {
  21947. data[0] = (uint8) byte1;
  21948. data[1] = (uint8) byte2;
  21949. // check that the length matches the data..
  21950. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  21951. }
  21952. MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, const double t) throw()
  21953. : timeStamp (t),
  21954. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21955. size (3)
  21956. {
  21957. data[0] = (uint8) byte1;
  21958. data[1] = (uint8) byte2;
  21959. data[2] = (uint8) byte3;
  21960. // check that the length matches the data..
  21961. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  21962. }
  21963. MidiMessage::MidiMessage (const MidiMessage& other)
  21964. : timeStamp (other.timeStamp),
  21965. size (other.size)
  21966. {
  21967. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21968. {
  21969. data = static_cast<uint8*> (juce_malloc (size));
  21970. memcpy (data, other.data, size);
  21971. }
  21972. else
  21973. {
  21974. data = static_cast<uint8*> (preallocatedData.asBytes);
  21975. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21976. }
  21977. }
  21978. MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp)
  21979. : timeStamp (newTimeStamp),
  21980. size (other.size)
  21981. {
  21982. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21983. {
  21984. data = static_cast<uint8*> (juce_malloc (size));
  21985. memcpy (data, other.data, size);
  21986. }
  21987. else
  21988. {
  21989. data = static_cast<uint8*> (preallocatedData.asBytes);
  21990. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21991. }
  21992. }
  21993. MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uint8 lastStatusByte, double t)
  21994. : timeStamp (t),
  21995. data (static_cast<uint8*> (preallocatedData.asBytes))
  21996. {
  21997. const uint8* src = static_cast <const uint8*> (src_);
  21998. unsigned int byte = (unsigned int) *src;
  21999. if (byte < 0x80)
  22000. {
  22001. byte = (unsigned int) (uint8) lastStatusByte;
  22002. numBytesUsed = -1;
  22003. }
  22004. else
  22005. {
  22006. numBytesUsed = 0;
  22007. --sz;
  22008. ++src;
  22009. }
  22010. if (byte >= 0x80)
  22011. {
  22012. if (byte == 0xf0)
  22013. {
  22014. const uint8* d = src;
  22015. while (d < src + sz)
  22016. {
  22017. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22018. {
  22019. if (*d == 0xf7) // include an 0xf7 if we hit one
  22020. ++d;
  22021. break;
  22022. }
  22023. ++d;
  22024. }
  22025. size = 1 + (int) (d - src);
  22026. data = static_cast<uint8*> (juce_malloc (size));
  22027. *data = (uint8) byte;
  22028. memcpy (data + 1, src, size - 1);
  22029. }
  22030. else if (byte == 0xff)
  22031. {
  22032. int n;
  22033. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22034. size = jmin (sz + 1, n + 2 + bytesLeft);
  22035. data = static_cast<uint8*> (juce_malloc (size));
  22036. *data = (uint8) byte;
  22037. memcpy (data + 1, src, size - 1);
  22038. }
  22039. else
  22040. {
  22041. preallocatedData.asInt32 = 0;
  22042. size = getMessageLengthFromFirstByte ((uint8) byte);
  22043. data[0] = (uint8) byte;
  22044. if (size > 1)
  22045. {
  22046. data[1] = src[0];
  22047. if (size > 2)
  22048. data[2] = src[1];
  22049. }
  22050. }
  22051. numBytesUsed += size;
  22052. }
  22053. else
  22054. {
  22055. preallocatedData.asInt32 = 0;
  22056. size = 0;
  22057. }
  22058. }
  22059. MidiMessage& MidiMessage::operator= (const MidiMessage& other)
  22060. {
  22061. if (this != &other)
  22062. {
  22063. timeStamp = other.timeStamp;
  22064. size = other.size;
  22065. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22066. juce_free (data);
  22067. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  22068. {
  22069. data = static_cast<uint8*> (juce_malloc (size));
  22070. memcpy (data, other.data, size);
  22071. }
  22072. else
  22073. {
  22074. data = static_cast<uint8*> (preallocatedData.asBytes);
  22075. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  22076. }
  22077. }
  22078. return *this;
  22079. }
  22080. MidiMessage::~MidiMessage()
  22081. {
  22082. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22083. juce_free (data);
  22084. }
  22085. int MidiMessage::getChannel() const throw()
  22086. {
  22087. if ((data[0] & 0xf0) != 0xf0)
  22088. return (data[0] & 0xf) + 1;
  22089. else
  22090. return 0;
  22091. }
  22092. bool MidiMessage::isForChannel (const int channel) const throw()
  22093. {
  22094. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22095. return ((data[0] & 0xf) == channel - 1)
  22096. && ((data[0] & 0xf0) != 0xf0);
  22097. }
  22098. void MidiMessage::setChannel (const int channel) throw()
  22099. {
  22100. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22101. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22102. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22103. | (uint8)(channel - 1));
  22104. }
  22105. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22106. {
  22107. return ((data[0] & 0xf0) == 0x90)
  22108. && (returnTrueForVelocity0 || data[2] != 0);
  22109. }
  22110. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22111. {
  22112. return ((data[0] & 0xf0) == 0x80)
  22113. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22114. }
  22115. bool MidiMessage::isNoteOnOrOff() const throw()
  22116. {
  22117. const int d = data[0] & 0xf0;
  22118. return (d == 0x90) || (d == 0x80);
  22119. }
  22120. int MidiMessage::getNoteNumber() const throw()
  22121. {
  22122. return data[1];
  22123. }
  22124. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22125. {
  22126. if (isNoteOnOrOff())
  22127. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22128. }
  22129. uint8 MidiMessage::getVelocity() const throw()
  22130. {
  22131. if (isNoteOnOrOff())
  22132. return data[2];
  22133. else
  22134. return 0;
  22135. }
  22136. float MidiMessage::getFloatVelocity() const throw()
  22137. {
  22138. return getVelocity() * (1.0f / 127.0f);
  22139. }
  22140. void MidiMessage::setVelocity (const float newVelocity) throw()
  22141. {
  22142. if (isNoteOnOrOff())
  22143. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22144. }
  22145. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22146. {
  22147. if (isNoteOnOrOff())
  22148. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22149. }
  22150. bool MidiMessage::isAftertouch() const throw()
  22151. {
  22152. return (data[0] & 0xf0) == 0xa0;
  22153. }
  22154. int MidiMessage::getAfterTouchValue() const throw()
  22155. {
  22156. return data[2];
  22157. }
  22158. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22159. const int noteNum,
  22160. const int aftertouchValue) throw()
  22161. {
  22162. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22163. jassert (((unsigned int) noteNum) <= 127);
  22164. jassert (((unsigned int) aftertouchValue) <= 127);
  22165. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22166. noteNum & 0x7f,
  22167. aftertouchValue & 0x7f);
  22168. }
  22169. bool MidiMessage::isChannelPressure() const throw()
  22170. {
  22171. return (data[0] & 0xf0) == 0xd0;
  22172. }
  22173. int MidiMessage::getChannelPressureValue() const throw()
  22174. {
  22175. jassert (isChannelPressure());
  22176. return data[1];
  22177. }
  22178. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22179. const int pressure) throw()
  22180. {
  22181. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22182. jassert (((unsigned int) pressure) <= 127);
  22183. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22184. pressure & 0x7f);
  22185. }
  22186. bool MidiMessage::isProgramChange() const throw()
  22187. {
  22188. return (data[0] & 0xf0) == 0xc0;
  22189. }
  22190. int MidiMessage::getProgramChangeNumber() const throw()
  22191. {
  22192. return data[1];
  22193. }
  22194. const MidiMessage MidiMessage::programChange (const int channel,
  22195. const int programNumber) throw()
  22196. {
  22197. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22198. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22199. programNumber & 0x7f);
  22200. }
  22201. bool MidiMessage::isPitchWheel() const throw()
  22202. {
  22203. return (data[0] & 0xf0) == 0xe0;
  22204. }
  22205. int MidiMessage::getPitchWheelValue() const throw()
  22206. {
  22207. return data[1] | (data[2] << 7);
  22208. }
  22209. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22210. const int position) throw()
  22211. {
  22212. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22213. jassert (((unsigned int) position) <= 0x3fff);
  22214. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22215. position & 127,
  22216. (position >> 7) & 127);
  22217. }
  22218. bool MidiMessage::isController() const throw()
  22219. {
  22220. return (data[0] & 0xf0) == 0xb0;
  22221. }
  22222. int MidiMessage::getControllerNumber() const throw()
  22223. {
  22224. jassert (isController());
  22225. return data[1];
  22226. }
  22227. int MidiMessage::getControllerValue() const throw()
  22228. {
  22229. jassert (isController());
  22230. return data[2];
  22231. }
  22232. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22233. const int controllerType,
  22234. const int value) throw()
  22235. {
  22236. // the channel must be between 1 and 16 inclusive
  22237. jassert (channel > 0 && channel <= 16);
  22238. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22239. controllerType & 127,
  22240. value & 127);
  22241. }
  22242. const MidiMessage MidiMessage::noteOn (const int channel,
  22243. const int noteNumber,
  22244. const float velocity) throw()
  22245. {
  22246. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22247. }
  22248. const MidiMessage MidiMessage::noteOn (const int channel,
  22249. const int noteNumber,
  22250. const uint8 velocity) throw()
  22251. {
  22252. jassert (channel > 0 && channel <= 16);
  22253. jassert (((unsigned int) noteNumber) <= 127);
  22254. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22255. noteNumber & 127,
  22256. jlimit (0, 127, roundToInt (velocity)));
  22257. }
  22258. const MidiMessage MidiMessage::noteOff (const int channel,
  22259. const int noteNumber) throw()
  22260. {
  22261. jassert (channel > 0 && channel <= 16);
  22262. jassert (((unsigned int) noteNumber) <= 127);
  22263. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22264. }
  22265. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22266. {
  22267. jassert (channel > 0 && channel <= 16);
  22268. return controllerEvent (channel, 123, 0);
  22269. }
  22270. bool MidiMessage::isAllNotesOff() const throw()
  22271. {
  22272. return (data[0] & 0xf0) == 0xb0
  22273. && data[1] == 123;
  22274. }
  22275. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22276. {
  22277. return controllerEvent (channel, 120, 0);
  22278. }
  22279. bool MidiMessage::isAllSoundOff() const throw()
  22280. {
  22281. return (data[0] & 0xf0) == 0xb0
  22282. && data[1] == 120;
  22283. }
  22284. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22285. {
  22286. return controllerEvent (channel, 121, 0);
  22287. }
  22288. const MidiMessage MidiMessage::masterVolume (const float volume)
  22289. {
  22290. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22291. uint8 buf[8];
  22292. buf[0] = 0xf0;
  22293. buf[1] = 0x7f;
  22294. buf[2] = 0x7f;
  22295. buf[3] = 0x04;
  22296. buf[4] = 0x01;
  22297. buf[5] = (uint8) (vol & 0x7f);
  22298. buf[6] = (uint8) (vol >> 7);
  22299. buf[7] = 0xf7;
  22300. return MidiMessage (buf, 8);
  22301. }
  22302. bool MidiMessage::isSysEx() const throw()
  22303. {
  22304. return *data == 0xf0;
  22305. }
  22306. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData, const int dataSize)
  22307. {
  22308. MemoryBlock mm (dataSize + 2);
  22309. uint8* const m = (uint8*) mm.getData();
  22310. m[0] = 0xf0;
  22311. memcpy (m + 1, sysexData, dataSize);
  22312. m[dataSize + 1] = 0xf7;
  22313. return MidiMessage (m, dataSize + 2);
  22314. }
  22315. const uint8* MidiMessage::getSysExData() const throw()
  22316. {
  22317. return (isSysEx()) ? getRawData() + 1 : 0;
  22318. }
  22319. int MidiMessage::getSysExDataSize() const throw()
  22320. {
  22321. return (isSysEx()) ? size - 2 : 0;
  22322. }
  22323. bool MidiMessage::isMetaEvent() const throw()
  22324. {
  22325. return *data == 0xff;
  22326. }
  22327. bool MidiMessage::isActiveSense() const throw()
  22328. {
  22329. return *data == 0xfe;
  22330. }
  22331. int MidiMessage::getMetaEventType() const throw()
  22332. {
  22333. if (*data != 0xff)
  22334. return -1;
  22335. else
  22336. return data[1];
  22337. }
  22338. int MidiMessage::getMetaEventLength() const throw()
  22339. {
  22340. if (*data == 0xff)
  22341. {
  22342. int n;
  22343. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22344. }
  22345. return 0;
  22346. }
  22347. const uint8* MidiMessage::getMetaEventData() const throw()
  22348. {
  22349. int n;
  22350. const uint8* d = data + 2;
  22351. readVariableLengthVal (d, n);
  22352. return d + n;
  22353. }
  22354. bool MidiMessage::isTrackMetaEvent() const throw()
  22355. {
  22356. return getMetaEventType() == 0;
  22357. }
  22358. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22359. {
  22360. return getMetaEventType() == 47;
  22361. }
  22362. bool MidiMessage::isTextMetaEvent() const throw()
  22363. {
  22364. const int t = getMetaEventType();
  22365. return t > 0 && t < 16;
  22366. }
  22367. const String MidiMessage::getTextFromTextMetaEvent() const
  22368. {
  22369. return String ((const char*) getMetaEventData(), getMetaEventLength());
  22370. }
  22371. bool MidiMessage::isTrackNameEvent() const throw()
  22372. {
  22373. return (data[1] == 3)
  22374. && (*data == 0xff);
  22375. }
  22376. bool MidiMessage::isTempoMetaEvent() const throw()
  22377. {
  22378. return (data[1] == 81)
  22379. && (*data == 0xff);
  22380. }
  22381. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22382. {
  22383. return (data[1] == 0x20)
  22384. && (*data == 0xff)
  22385. && (data[2] == 1);
  22386. }
  22387. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22388. {
  22389. return data[3] + 1;
  22390. }
  22391. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22392. {
  22393. if (! isTempoMetaEvent())
  22394. return 0.0;
  22395. const uint8* const d = getMetaEventData();
  22396. return (((unsigned int) d[0] << 16)
  22397. | ((unsigned int) d[1] << 8)
  22398. | d[2])
  22399. / 1000000.0;
  22400. }
  22401. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22402. {
  22403. if (timeFormat > 0)
  22404. {
  22405. if (! isTempoMetaEvent())
  22406. return 0.5 / timeFormat;
  22407. return getTempoSecondsPerQuarterNote() / timeFormat;
  22408. }
  22409. else
  22410. {
  22411. const int frameCode = (-timeFormat) >> 8;
  22412. double framesPerSecond;
  22413. switch (frameCode)
  22414. {
  22415. case 24: framesPerSecond = 24.0; break;
  22416. case 25: framesPerSecond = 25.0; break;
  22417. case 29: framesPerSecond = 29.97; break;
  22418. case 30: framesPerSecond = 30.0; break;
  22419. default: framesPerSecond = 30.0; break;
  22420. }
  22421. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22422. }
  22423. }
  22424. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22425. {
  22426. uint8 d[8];
  22427. d[0] = 0xff;
  22428. d[1] = 81;
  22429. d[2] = 3;
  22430. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22431. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22432. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22433. return MidiMessage (d, 6, 0.0);
  22434. }
  22435. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22436. {
  22437. return (data[1] == 0x58)
  22438. && (*data == (uint8) 0xff);
  22439. }
  22440. void MidiMessage::getTimeSignatureInfo (int& numerator, int& denominator) const throw()
  22441. {
  22442. if (isTimeSignatureMetaEvent())
  22443. {
  22444. const uint8* const d = getMetaEventData();
  22445. numerator = d[0];
  22446. denominator = 1 << d[1];
  22447. }
  22448. else
  22449. {
  22450. numerator = 4;
  22451. denominator = 4;
  22452. }
  22453. }
  22454. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator, const int denominator)
  22455. {
  22456. uint8 d[8];
  22457. d[0] = 0xff;
  22458. d[1] = 0x58;
  22459. d[2] = 0x04;
  22460. d[3] = (uint8) numerator;
  22461. int n = 1;
  22462. int powerOfTwo = 0;
  22463. while (n < denominator)
  22464. {
  22465. n <<= 1;
  22466. ++powerOfTwo;
  22467. }
  22468. d[4] = (uint8) powerOfTwo;
  22469. d[5] = 0x01;
  22470. d[6] = 96;
  22471. return MidiMessage (d, 7, 0.0);
  22472. }
  22473. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22474. {
  22475. uint8 d[8];
  22476. d[0] = 0xff;
  22477. d[1] = 0x20;
  22478. d[2] = 0x01;
  22479. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22480. return MidiMessage (d, 4, 0.0);
  22481. }
  22482. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22483. {
  22484. return getMetaEventType() == 89;
  22485. }
  22486. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22487. {
  22488. return (int) *getMetaEventData();
  22489. }
  22490. const MidiMessage MidiMessage::endOfTrack() throw()
  22491. {
  22492. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22493. }
  22494. bool MidiMessage::isSongPositionPointer() const throw()
  22495. {
  22496. return *data == 0xf2;
  22497. }
  22498. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22499. {
  22500. return data[1] | (data[2] << 7);
  22501. }
  22502. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22503. {
  22504. return MidiMessage (0xf2,
  22505. positionInMidiBeats & 127,
  22506. (positionInMidiBeats >> 7) & 127);
  22507. }
  22508. bool MidiMessage::isMidiStart() const throw()
  22509. {
  22510. return *data == 0xfa;
  22511. }
  22512. const MidiMessage MidiMessage::midiStart() throw()
  22513. {
  22514. return MidiMessage (0xfa);
  22515. }
  22516. bool MidiMessage::isMidiContinue() const throw()
  22517. {
  22518. return *data == 0xfb;
  22519. }
  22520. const MidiMessage MidiMessage::midiContinue() throw()
  22521. {
  22522. return MidiMessage (0xfb);
  22523. }
  22524. bool MidiMessage::isMidiStop() const throw()
  22525. {
  22526. return *data == 0xfc;
  22527. }
  22528. const MidiMessage MidiMessage::midiStop() throw()
  22529. {
  22530. return MidiMessage (0xfc);
  22531. }
  22532. bool MidiMessage::isMidiClock() const throw()
  22533. {
  22534. return *data == 0xf8;
  22535. }
  22536. const MidiMessage MidiMessage::midiClock() throw()
  22537. {
  22538. return MidiMessage (0xf8);
  22539. }
  22540. bool MidiMessage::isQuarterFrame() const throw()
  22541. {
  22542. return *data == 0xf1;
  22543. }
  22544. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22545. {
  22546. return ((int) data[1]) >> 4;
  22547. }
  22548. int MidiMessage::getQuarterFrameValue() const throw()
  22549. {
  22550. return ((int) data[1]) & 0x0f;
  22551. }
  22552. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22553. const int value) throw()
  22554. {
  22555. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22556. }
  22557. bool MidiMessage::isFullFrame() const throw()
  22558. {
  22559. return data[0] == 0xf0
  22560. && data[1] == 0x7f
  22561. && size >= 10
  22562. && data[3] == 0x01
  22563. && data[4] == 0x01;
  22564. }
  22565. void MidiMessage::getFullFrameParameters (int& hours,
  22566. int& minutes,
  22567. int& seconds,
  22568. int& frames,
  22569. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22570. {
  22571. jassert (isFullFrame());
  22572. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22573. hours = data[5] & 0x1f;
  22574. minutes = data[6];
  22575. seconds = data[7];
  22576. frames = data[8];
  22577. }
  22578. const MidiMessage MidiMessage::fullFrame (const int hours,
  22579. const int minutes,
  22580. const int seconds,
  22581. const int frames,
  22582. MidiMessage::SmpteTimecodeType timecodeType)
  22583. {
  22584. uint8 d[10];
  22585. d[0] = 0xf0;
  22586. d[1] = 0x7f;
  22587. d[2] = 0x7f;
  22588. d[3] = 0x01;
  22589. d[4] = 0x01;
  22590. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22591. d[6] = (uint8) minutes;
  22592. d[7] = (uint8) seconds;
  22593. d[8] = (uint8) frames;
  22594. d[9] = 0xf7;
  22595. return MidiMessage (d, 10, 0.0);
  22596. }
  22597. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22598. {
  22599. return data[0] == 0xf0
  22600. && data[1] == 0x7f
  22601. && data[3] == 0x06
  22602. && size > 5;
  22603. }
  22604. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22605. {
  22606. jassert (isMidiMachineControlMessage());
  22607. return (MidiMachineControlCommand) data[4];
  22608. }
  22609. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22610. {
  22611. uint8 d[6];
  22612. d[0] = 0xf0;
  22613. d[1] = 0x7f;
  22614. d[2] = 0x00;
  22615. d[3] = 0x06;
  22616. d[4] = (uint8) command;
  22617. d[5] = 0xf7;
  22618. return MidiMessage (d, 6, 0.0);
  22619. }
  22620. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22621. int& minutes,
  22622. int& seconds,
  22623. int& frames) const throw()
  22624. {
  22625. if (size >= 12
  22626. && data[0] == 0xf0
  22627. && data[1] == 0x7f
  22628. && data[3] == 0x06
  22629. && data[4] == 0x44
  22630. && data[5] == 0x06
  22631. && data[6] == 0x01)
  22632. {
  22633. hours = data[7] % 24; // (that some machines send out hours > 24)
  22634. minutes = data[8];
  22635. seconds = data[9];
  22636. frames = data[10];
  22637. return true;
  22638. }
  22639. return false;
  22640. }
  22641. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22642. int minutes,
  22643. int seconds,
  22644. int frames)
  22645. {
  22646. uint8 d[12];
  22647. d[0] = 0xf0;
  22648. d[1] = 0x7f;
  22649. d[2] = 0x00;
  22650. d[3] = 0x06;
  22651. d[4] = 0x44;
  22652. d[5] = 0x06;
  22653. d[6] = 0x01;
  22654. d[7] = (uint8) hours;
  22655. d[8] = (uint8) minutes;
  22656. d[9] = (uint8) seconds;
  22657. d[10] = (uint8) frames;
  22658. d[11] = 0xf7;
  22659. return MidiMessage (d, 12, 0.0);
  22660. }
  22661. const String MidiMessage::getMidiNoteName (int note,
  22662. bool useSharps,
  22663. bool includeOctaveNumber,
  22664. int octaveNumForMiddleC) throw()
  22665. {
  22666. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22667. "F", "F#", "G", "G#", "A",
  22668. "A#", "B" };
  22669. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22670. "F", "Gb", "G", "Ab", "A",
  22671. "Bb", "B" };
  22672. if (((unsigned int) note) < 128)
  22673. {
  22674. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22675. : flatNoteNames [note % 12]);
  22676. if (includeOctaveNumber)
  22677. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22678. else
  22679. return s;
  22680. }
  22681. return String::empty;
  22682. }
  22683. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22684. {
  22685. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22686. return 440.0 * pow (2.0, noteNumber / 12.0);
  22687. }
  22688. const String MidiMessage::getGMInstrumentName (int n) throw()
  22689. {
  22690. const char *names[] =
  22691. {
  22692. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22693. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22694. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22695. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22696. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22697. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22698. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22699. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22700. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22701. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22702. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22703. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22704. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22705. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22706. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22707. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22708. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22709. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22710. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22711. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22712. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22713. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22714. "Applause", "Gunshot"
  22715. };
  22716. return (((unsigned int) n) < 128) ? names[n]
  22717. : (const char*)0;
  22718. }
  22719. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22720. {
  22721. const char* names[] =
  22722. {
  22723. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22724. "Bass", "Strings", "Ensemble", "Brass",
  22725. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22726. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22727. };
  22728. return (((unsigned int) n) <= 15) ? names[n]
  22729. : (const char*)0;
  22730. }
  22731. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22732. {
  22733. const char* names[] =
  22734. {
  22735. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22736. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22737. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22738. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22739. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22740. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22741. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22742. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22743. "Mute Triangle", "Open Triangle"
  22744. };
  22745. return (n >= 35 && n <= 81) ? names [n - 35]
  22746. : (const char*)0;
  22747. }
  22748. const String MidiMessage::getControllerName (int n) throw()
  22749. {
  22750. const char* names[] =
  22751. {
  22752. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22753. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22754. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22755. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22756. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22757. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22758. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22759. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22760. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22761. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22762. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22763. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22764. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22765. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22766. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22767. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22768. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22769. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22770. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22772. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22773. "Poly Operation"
  22774. };
  22775. return (((unsigned int) n) < 128) ? names[n]
  22776. : (const char*)0;
  22777. }
  22778. END_JUCE_NAMESPACE
  22779. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22780. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22781. BEGIN_JUCE_NAMESPACE
  22782. MidiMessageCollector::MidiMessageCollector()
  22783. : lastCallbackTime (0),
  22784. sampleRate (44100.0001)
  22785. {
  22786. }
  22787. MidiMessageCollector::~MidiMessageCollector()
  22788. {
  22789. }
  22790. void MidiMessageCollector::reset (const double sampleRate_)
  22791. {
  22792. jassert (sampleRate_ > 0);
  22793. const ScopedLock sl (midiCallbackLock);
  22794. sampleRate = sampleRate_;
  22795. incomingMessages.clear();
  22796. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22797. }
  22798. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22799. {
  22800. // you need to call reset() to set the correct sample rate before using this object
  22801. jassert (sampleRate != 44100.0001);
  22802. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22803. // for details of what the number should be.
  22804. jassert (message.getTimeStamp() != 0);
  22805. const ScopedLock sl (midiCallbackLock);
  22806. const int sampleNumber
  22807. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22808. incomingMessages.addEvent (message, sampleNumber);
  22809. // if the messages don't get used for over a second, we'd better
  22810. // get rid of any old ones to avoid the queue getting too big
  22811. if (sampleNumber > sampleRate)
  22812. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22813. }
  22814. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22815. const int numSamples)
  22816. {
  22817. // you need to call reset() to set the correct sample rate before using this object
  22818. jassert (sampleRate != 44100.0001);
  22819. const double timeNow = Time::getMillisecondCounterHiRes();
  22820. const double msElapsed = timeNow - lastCallbackTime;
  22821. const ScopedLock sl (midiCallbackLock);
  22822. lastCallbackTime = timeNow;
  22823. if (! incomingMessages.isEmpty())
  22824. {
  22825. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22826. int startSample = 0;
  22827. int scale = 1 << 16;
  22828. const uint8* midiData;
  22829. int numBytes, samplePosition;
  22830. MidiBuffer::Iterator iter (incomingMessages);
  22831. if (numSourceSamples > numSamples)
  22832. {
  22833. // if our list of events is longer than the buffer we're being
  22834. // asked for, scale them down to squeeze them all in..
  22835. const int maxBlockLengthToUse = numSamples << 5;
  22836. if (numSourceSamples > maxBlockLengthToUse)
  22837. {
  22838. startSample = numSourceSamples - maxBlockLengthToUse;
  22839. numSourceSamples = maxBlockLengthToUse;
  22840. iter.setNextSamplePosition (startSample);
  22841. }
  22842. scale = (numSamples << 10) / numSourceSamples;
  22843. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22844. {
  22845. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22846. destBuffer.addEvent (midiData, numBytes,
  22847. jlimit (0, numSamples - 1, samplePosition));
  22848. }
  22849. }
  22850. else
  22851. {
  22852. // if our event list is shorter than the number we need, put them
  22853. // towards the end of the buffer
  22854. startSample = numSamples - numSourceSamples;
  22855. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22856. {
  22857. destBuffer.addEvent (midiData, numBytes,
  22858. jlimit (0, numSamples - 1, samplePosition + startSample));
  22859. }
  22860. }
  22861. incomingMessages.clear();
  22862. }
  22863. }
  22864. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  22865. {
  22866. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  22867. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22868. addMessageToQueue (m);
  22869. }
  22870. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  22871. {
  22872. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  22873. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22874. addMessageToQueue (m);
  22875. }
  22876. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  22877. {
  22878. addMessageToQueue (message);
  22879. }
  22880. END_JUCE_NAMESPACE
  22881. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  22882. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  22883. BEGIN_JUCE_NAMESPACE
  22884. MidiMessageSequence::MidiMessageSequence()
  22885. {
  22886. }
  22887. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  22888. {
  22889. list.ensureStorageAllocated (other.list.size());
  22890. for (int i = 0; i < other.list.size(); ++i)
  22891. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  22892. }
  22893. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  22894. {
  22895. MidiMessageSequence otherCopy (other);
  22896. swapWith (otherCopy);
  22897. return *this;
  22898. }
  22899. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  22900. {
  22901. list.swapWithArray (other.list);
  22902. }
  22903. MidiMessageSequence::~MidiMessageSequence()
  22904. {
  22905. }
  22906. void MidiMessageSequence::clear()
  22907. {
  22908. list.clear();
  22909. }
  22910. int MidiMessageSequence::getNumEvents() const
  22911. {
  22912. return list.size();
  22913. }
  22914. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  22915. {
  22916. return list [index];
  22917. }
  22918. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  22919. {
  22920. const MidiEventHolder* const meh = list [index];
  22921. if (meh != 0 && meh->noteOffObject != 0)
  22922. return meh->noteOffObject->message.getTimeStamp();
  22923. else
  22924. return 0.0;
  22925. }
  22926. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  22927. {
  22928. const MidiEventHolder* const meh = list [index];
  22929. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  22930. }
  22931. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  22932. {
  22933. return list.indexOf (event);
  22934. }
  22935. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  22936. {
  22937. const int numEvents = list.size();
  22938. int i;
  22939. for (i = 0; i < numEvents; ++i)
  22940. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  22941. break;
  22942. return i;
  22943. }
  22944. double MidiMessageSequence::getStartTime() const
  22945. {
  22946. if (list.size() > 0)
  22947. return list.getUnchecked(0)->message.getTimeStamp();
  22948. else
  22949. return 0;
  22950. }
  22951. double MidiMessageSequence::getEndTime() const
  22952. {
  22953. if (list.size() > 0)
  22954. return list.getLast()->message.getTimeStamp();
  22955. else
  22956. return 0;
  22957. }
  22958. double MidiMessageSequence::getEventTime (const int index) const
  22959. {
  22960. if (((unsigned int) index) < (unsigned int) list.size())
  22961. return list.getUnchecked (index)->message.getTimeStamp();
  22962. return 0.0;
  22963. }
  22964. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  22965. double timeAdjustment)
  22966. {
  22967. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  22968. timeAdjustment += newMessage.getTimeStamp();
  22969. newOne->message.setTimeStamp (timeAdjustment);
  22970. int i;
  22971. for (i = list.size(); --i >= 0;)
  22972. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  22973. break;
  22974. list.insert (i + 1, newOne);
  22975. }
  22976. void MidiMessageSequence::deleteEvent (const int index,
  22977. const bool deleteMatchingNoteUp)
  22978. {
  22979. if (((unsigned int) index) < (unsigned int) list.size())
  22980. {
  22981. if (deleteMatchingNoteUp)
  22982. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  22983. list.remove (index);
  22984. }
  22985. }
  22986. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  22987. double timeAdjustment,
  22988. double firstAllowableTime,
  22989. double endOfAllowableDestTimes)
  22990. {
  22991. firstAllowableTime -= timeAdjustment;
  22992. endOfAllowableDestTimes -= timeAdjustment;
  22993. for (int i = 0; i < other.list.size(); ++i)
  22994. {
  22995. const MidiMessage& m = other.list.getUnchecked(i)->message;
  22996. const double t = m.getTimeStamp();
  22997. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  22998. {
  22999. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23000. newOne->message.setTimeStamp (timeAdjustment + t);
  23001. list.add (newOne);
  23002. }
  23003. }
  23004. sort();
  23005. }
  23006. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23007. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23008. {
  23009. const double diff = first->message.getTimeStamp()
  23010. - second->message.getTimeStamp();
  23011. return (diff > 0) - (diff < 0);
  23012. }
  23013. void MidiMessageSequence::sort()
  23014. {
  23015. list.sort (*this, true);
  23016. }
  23017. void MidiMessageSequence::updateMatchedPairs()
  23018. {
  23019. for (int i = 0; i < list.size(); ++i)
  23020. {
  23021. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23022. if (m1.isNoteOn())
  23023. {
  23024. list.getUnchecked(i)->noteOffObject = 0;
  23025. const int note = m1.getNoteNumber();
  23026. const int chan = m1.getChannel();
  23027. const int len = list.size();
  23028. for (int j = i + 1; j < len; ++j)
  23029. {
  23030. const MidiMessage& m = list.getUnchecked(j)->message;
  23031. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23032. {
  23033. if (m.isNoteOff())
  23034. {
  23035. list.getUnchecked(i)->noteOffObject = list[j];
  23036. break;
  23037. }
  23038. else if (m.isNoteOn())
  23039. {
  23040. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23041. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23042. list.getUnchecked(i)->noteOffObject = list[j];
  23043. break;
  23044. }
  23045. }
  23046. }
  23047. }
  23048. }
  23049. }
  23050. void MidiMessageSequence::addTimeToMessages (const double delta)
  23051. {
  23052. for (int i = list.size(); --i >= 0;)
  23053. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23054. + delta);
  23055. }
  23056. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23057. MidiMessageSequence& destSequence,
  23058. const bool alsoIncludeMetaEvents) const
  23059. {
  23060. for (int i = 0; i < list.size(); ++i)
  23061. {
  23062. const MidiMessage& mm = list.getUnchecked(i)->message;
  23063. if (mm.isForChannel (channelNumberToExtract)
  23064. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23065. {
  23066. destSequence.addEvent (mm);
  23067. }
  23068. }
  23069. }
  23070. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23071. {
  23072. for (int i = 0; i < list.size(); ++i)
  23073. {
  23074. const MidiMessage& mm = list.getUnchecked(i)->message;
  23075. if (mm.isSysEx())
  23076. destSequence.addEvent (mm);
  23077. }
  23078. }
  23079. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23080. {
  23081. for (int i = list.size(); --i >= 0;)
  23082. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23083. list.remove(i);
  23084. }
  23085. void MidiMessageSequence::deleteSysExMessages()
  23086. {
  23087. for (int i = list.size(); --i >= 0;)
  23088. if (list.getUnchecked(i)->message.isSysEx())
  23089. list.remove(i);
  23090. }
  23091. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23092. const double time,
  23093. OwnedArray<MidiMessage>& dest)
  23094. {
  23095. bool doneProg = false;
  23096. bool donePitchWheel = false;
  23097. Array <int> doneControllers;
  23098. doneControllers.ensureStorageAllocated (32);
  23099. for (int i = list.size(); --i >= 0;)
  23100. {
  23101. const MidiMessage& mm = list.getUnchecked(i)->message;
  23102. if (mm.isForChannel (channelNumber)
  23103. && mm.getTimeStamp() <= time)
  23104. {
  23105. if (mm.isProgramChange())
  23106. {
  23107. if (! doneProg)
  23108. {
  23109. dest.add (new MidiMessage (mm, 0.0));
  23110. doneProg = true;
  23111. }
  23112. }
  23113. else if (mm.isController())
  23114. {
  23115. if (! doneControllers.contains (mm.getControllerNumber()))
  23116. {
  23117. dest.add (new MidiMessage (mm, 0.0));
  23118. doneControllers.add (mm.getControllerNumber());
  23119. }
  23120. }
  23121. else if (mm.isPitchWheel())
  23122. {
  23123. if (! donePitchWheel)
  23124. {
  23125. dest.add (new MidiMessage (mm, 0.0));
  23126. donePitchWheel = true;
  23127. }
  23128. }
  23129. }
  23130. }
  23131. }
  23132. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23133. : message (message_),
  23134. noteOffObject (0)
  23135. {
  23136. }
  23137. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23138. {
  23139. }
  23140. END_JUCE_NAMESPACE
  23141. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23142. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23143. BEGIN_JUCE_NAMESPACE
  23144. AudioPluginFormat::AudioPluginFormat() throw()
  23145. {
  23146. }
  23147. AudioPluginFormat::~AudioPluginFormat()
  23148. {
  23149. }
  23150. END_JUCE_NAMESPACE
  23151. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23152. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23153. BEGIN_JUCE_NAMESPACE
  23154. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23155. {
  23156. }
  23157. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23158. {
  23159. clearSingletonInstance();
  23160. }
  23161. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23162. void AudioPluginFormatManager::addDefaultFormats()
  23163. {
  23164. #ifdef JUCE_DEBUG
  23165. // you should only call this method once!
  23166. for (int i = formats.size(); --i >= 0;)
  23167. {
  23168. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23169. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23170. #endif
  23171. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23172. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23173. #endif
  23174. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23175. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23176. #endif
  23177. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23178. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23179. #endif
  23180. }
  23181. #endif
  23182. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23183. formats.add (new AudioUnitPluginFormat());
  23184. #endif
  23185. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23186. formats.add (new VSTPluginFormat());
  23187. #endif
  23188. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23189. formats.add (new DirectXPluginFormat());
  23190. #endif
  23191. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23192. formats.add (new LADSPAPluginFormat());
  23193. #endif
  23194. }
  23195. int AudioPluginFormatManager::getNumFormats() throw()
  23196. {
  23197. return formats.size();
  23198. }
  23199. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23200. {
  23201. return formats [index];
  23202. }
  23203. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23204. {
  23205. formats.add (format);
  23206. }
  23207. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23208. String& errorMessage) const
  23209. {
  23210. AudioPluginInstance* result = 0;
  23211. for (int i = 0; i < formats.size(); ++i)
  23212. {
  23213. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23214. if (result != 0)
  23215. break;
  23216. }
  23217. if (result == 0)
  23218. {
  23219. if (! doesPluginStillExist (description))
  23220. errorMessage = TRANS ("This plug-in file no longer exists");
  23221. else
  23222. errorMessage = TRANS ("This plug-in failed to load correctly");
  23223. }
  23224. return result;
  23225. }
  23226. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23227. {
  23228. for (int i = 0; i < formats.size(); ++i)
  23229. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23230. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23231. return false;
  23232. }
  23233. END_JUCE_NAMESPACE
  23234. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23235. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23236. #define JUCE_PLUGIN_HOST 1
  23237. BEGIN_JUCE_NAMESPACE
  23238. AudioPluginInstance::AudioPluginInstance()
  23239. {
  23240. }
  23241. AudioPluginInstance::~AudioPluginInstance()
  23242. {
  23243. }
  23244. END_JUCE_NAMESPACE
  23245. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23246. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23247. BEGIN_JUCE_NAMESPACE
  23248. KnownPluginList::KnownPluginList()
  23249. {
  23250. }
  23251. KnownPluginList::~KnownPluginList()
  23252. {
  23253. }
  23254. void KnownPluginList::clear()
  23255. {
  23256. if (types.size() > 0)
  23257. {
  23258. types.clear();
  23259. sendChangeMessage (this);
  23260. }
  23261. }
  23262. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23263. {
  23264. for (int i = 0; i < types.size(); ++i)
  23265. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23266. return types.getUnchecked(i);
  23267. return 0;
  23268. }
  23269. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23270. {
  23271. for (int i = 0; i < types.size(); ++i)
  23272. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23273. return types.getUnchecked(i);
  23274. return 0;
  23275. }
  23276. bool KnownPluginList::addType (const PluginDescription& type)
  23277. {
  23278. for (int i = types.size(); --i >= 0;)
  23279. {
  23280. if (types.getUnchecked(i)->isDuplicateOf (type))
  23281. {
  23282. // strange - found a duplicate plugin with different info..
  23283. jassert (types.getUnchecked(i)->name == type.name);
  23284. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23285. *types.getUnchecked(i) = type;
  23286. return false;
  23287. }
  23288. }
  23289. types.add (new PluginDescription (type));
  23290. sendChangeMessage (this);
  23291. return true;
  23292. }
  23293. void KnownPluginList::removeType (const int index) throw()
  23294. {
  23295. types.remove (index);
  23296. sendChangeMessage (this);
  23297. }
  23298. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23299. {
  23300. if (fileOrIdentifier.startsWithChar ('/')
  23301. || fileOrIdentifier[1] == ':')
  23302. {
  23303. return File (fileOrIdentifier).getLastModificationTime();
  23304. }
  23305. return Time (0);
  23306. }
  23307. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23308. {
  23309. return t1 != t2 || t1 == Time (0);
  23310. }
  23311. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23312. {
  23313. if (getTypeForFile (fileOrIdentifier) == 0)
  23314. return false;
  23315. for (int i = types.size(); --i >= 0;)
  23316. {
  23317. const PluginDescription* const d = types.getUnchecked(i);
  23318. if (d->fileOrIdentifier == fileOrIdentifier
  23319. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23320. {
  23321. return false;
  23322. }
  23323. }
  23324. return true;
  23325. }
  23326. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23327. const bool dontRescanIfAlreadyInList,
  23328. OwnedArray <PluginDescription>& typesFound,
  23329. AudioPluginFormat& format)
  23330. {
  23331. bool addedOne = false;
  23332. if (dontRescanIfAlreadyInList
  23333. && getTypeForFile (fileOrIdentifier) != 0)
  23334. {
  23335. bool needsRescanning = false;
  23336. for (int i = types.size(); --i >= 0;)
  23337. {
  23338. const PluginDescription* const d = types.getUnchecked(i);
  23339. if (d->fileOrIdentifier == fileOrIdentifier)
  23340. {
  23341. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23342. needsRescanning = true;
  23343. else
  23344. typesFound.add (new PluginDescription (*d));
  23345. }
  23346. }
  23347. if (! needsRescanning)
  23348. return false;
  23349. }
  23350. OwnedArray <PluginDescription> found;
  23351. format.findAllTypesForFile (found, fileOrIdentifier);
  23352. for (int i = 0; i < found.size(); ++i)
  23353. {
  23354. PluginDescription* const desc = found.getUnchecked(i);
  23355. jassert (desc != 0);
  23356. if (addType (*desc))
  23357. addedOne = true;
  23358. typesFound.add (new PluginDescription (*desc));
  23359. }
  23360. return addedOne;
  23361. }
  23362. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23363. OwnedArray <PluginDescription>& typesFound)
  23364. {
  23365. for (int i = 0; i < files.size(); ++i)
  23366. {
  23367. bool loaded = false;
  23368. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23369. {
  23370. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23371. if (scanAndAddFile (files[i], true, typesFound, *format))
  23372. loaded = true;
  23373. }
  23374. if (! loaded)
  23375. {
  23376. const File f (files[i]);
  23377. if (f.isDirectory())
  23378. {
  23379. StringArray s;
  23380. {
  23381. Array<File> subFiles;
  23382. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23383. for (int j = 0; j < subFiles.size(); ++j)
  23384. s.add (subFiles.getReference(j).getFullPathName());
  23385. }
  23386. scanAndAddDragAndDroppedFiles (s, typesFound);
  23387. }
  23388. }
  23389. }
  23390. }
  23391. class PluginSorter
  23392. {
  23393. public:
  23394. KnownPluginList::SortMethod method;
  23395. PluginSorter() throw() {}
  23396. int compareElements (const PluginDescription* const first,
  23397. const PluginDescription* const second) const throw()
  23398. {
  23399. int diff = 0;
  23400. if (method == KnownPluginList::sortByCategory)
  23401. diff = first->category.compareLexicographically (second->category);
  23402. else if (method == KnownPluginList::sortByManufacturer)
  23403. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23404. else if (method == KnownPluginList::sortByFileSystemLocation)
  23405. diff = first->fileOrIdentifier.replaceCharacter ('\\', '/')
  23406. .upToLastOccurrenceOf ("/", false, false)
  23407. .compare (second->fileOrIdentifier.replaceCharacter ('\\', '/')
  23408. .upToLastOccurrenceOf ("/", false, false));
  23409. if (diff == 0)
  23410. diff = first->name.compareLexicographically (second->name);
  23411. return diff;
  23412. }
  23413. };
  23414. void KnownPluginList::sort (const SortMethod method)
  23415. {
  23416. if (method != defaultOrder)
  23417. {
  23418. PluginSorter sorter;
  23419. sorter.method = method;
  23420. types.sort (sorter, true);
  23421. sendChangeMessage (this);
  23422. }
  23423. }
  23424. XmlElement* KnownPluginList::createXml() const
  23425. {
  23426. XmlElement* const e = new XmlElement ("KNOWNPLUGINS");
  23427. for (int i = 0; i < types.size(); ++i)
  23428. e->addChildElement (types.getUnchecked(i)->createXml());
  23429. return e;
  23430. }
  23431. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23432. {
  23433. clear();
  23434. if (xml.hasTagName ("KNOWNPLUGINS"))
  23435. {
  23436. forEachXmlChildElement (xml, e)
  23437. {
  23438. PluginDescription info;
  23439. if (info.loadFromXml (*e))
  23440. addType (info);
  23441. }
  23442. }
  23443. }
  23444. const int menuIdBase = 0x324503f4;
  23445. // This is used to turn a bunch of paths into a nested menu structure.
  23446. struct PluginFilesystemTree
  23447. {
  23448. private:
  23449. String folder;
  23450. OwnedArray <PluginFilesystemTree> subFolders;
  23451. Array <PluginDescription*> plugins;
  23452. void addPlugin (PluginDescription* const pd, const String& path)
  23453. {
  23454. if (path.isEmpty())
  23455. {
  23456. plugins.add (pd);
  23457. }
  23458. else
  23459. {
  23460. const String firstSubFolder (path.upToFirstOccurrenceOf ("/", false, false));
  23461. const String remainingPath (path.fromFirstOccurrenceOf ("/", false, false));
  23462. for (int i = subFolders.size(); --i >= 0;)
  23463. {
  23464. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23465. {
  23466. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23467. return;
  23468. }
  23469. }
  23470. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23471. newFolder->folder = firstSubFolder;
  23472. subFolders.add (newFolder);
  23473. newFolder->addPlugin (pd, remainingPath);
  23474. }
  23475. }
  23476. // removes any deeply nested folders that don't contain any actual plugins
  23477. void optimise()
  23478. {
  23479. for (int i = subFolders.size(); --i >= 0;)
  23480. {
  23481. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23482. sub->optimise();
  23483. if (sub->plugins.size() == 0)
  23484. {
  23485. for (int j = 0; j < sub->subFolders.size(); ++j)
  23486. subFolders.add (sub->subFolders.getUnchecked(j));
  23487. sub->subFolders.clear (false);
  23488. subFolders.remove (i);
  23489. }
  23490. }
  23491. }
  23492. public:
  23493. void buildTree (const Array <PluginDescription*>& allPlugins)
  23494. {
  23495. for (int i = 0; i < allPlugins.size(); ++i)
  23496. {
  23497. String path (allPlugins.getUnchecked(i)
  23498. ->fileOrIdentifier.replaceCharacter ('\\', '/')
  23499. .upToLastOccurrenceOf ("/", false, false));
  23500. if (path.substring (1, 2) == ":")
  23501. path = path.substring (2);
  23502. addPlugin (allPlugins.getUnchecked(i), path);
  23503. }
  23504. optimise();
  23505. }
  23506. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23507. {
  23508. int i;
  23509. for (i = 0; i < subFolders.size(); ++i)
  23510. {
  23511. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23512. PopupMenu subMenu;
  23513. sub->addToMenu (subMenu, allPlugins);
  23514. #if JUCE_MAC
  23515. // avoid the special AU formatting nonsense on Mac..
  23516. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (":", false, false), subMenu);
  23517. #else
  23518. m.addSubMenu (sub->folder, subMenu);
  23519. #endif
  23520. }
  23521. for (i = 0; i < plugins.size(); ++i)
  23522. {
  23523. PluginDescription* const plugin = plugins.getUnchecked(i);
  23524. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23525. plugin->name, true, false);
  23526. }
  23527. }
  23528. };
  23529. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23530. {
  23531. Array <PluginDescription*> sorted;
  23532. {
  23533. PluginSorter sorter;
  23534. sorter.method = sortMethod;
  23535. for (int i = 0; i < types.size(); ++i)
  23536. sorted.addSorted (sorter, types.getUnchecked(i));
  23537. }
  23538. if (sortMethod == sortByCategory
  23539. || sortMethod == sortByManufacturer)
  23540. {
  23541. String lastSubMenuName;
  23542. PopupMenu sub;
  23543. for (int i = 0; i < sorted.size(); ++i)
  23544. {
  23545. const PluginDescription* const pd = sorted.getUnchecked(i);
  23546. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23547. : pd->manufacturerName);
  23548. if (! thisSubMenuName.containsNonWhitespaceChars())
  23549. thisSubMenuName = "Other";
  23550. if (thisSubMenuName != lastSubMenuName)
  23551. {
  23552. if (sub.getNumItems() > 0)
  23553. {
  23554. menu.addSubMenu (lastSubMenuName, sub);
  23555. sub.clear();
  23556. }
  23557. lastSubMenuName = thisSubMenuName;
  23558. }
  23559. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23560. }
  23561. if (sub.getNumItems() > 0)
  23562. menu.addSubMenu (lastSubMenuName, sub);
  23563. }
  23564. else if (sortMethod == sortByFileSystemLocation)
  23565. {
  23566. PluginFilesystemTree root;
  23567. root.buildTree (sorted);
  23568. root.addToMenu (menu, types);
  23569. }
  23570. else
  23571. {
  23572. for (int i = 0; i < sorted.size(); ++i)
  23573. {
  23574. const PluginDescription* const pd = sorted.getUnchecked(i);
  23575. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23576. }
  23577. }
  23578. }
  23579. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23580. {
  23581. const int i = menuResultCode - menuIdBase;
  23582. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23583. }
  23584. END_JUCE_NAMESPACE
  23585. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23586. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23587. BEGIN_JUCE_NAMESPACE
  23588. PluginDescription::PluginDescription() throw()
  23589. : uid (0),
  23590. isInstrument (false),
  23591. numInputChannels (0),
  23592. numOutputChannels (0)
  23593. {
  23594. }
  23595. PluginDescription::~PluginDescription() throw()
  23596. {
  23597. }
  23598. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23599. : name (other.name),
  23600. pluginFormatName (other.pluginFormatName),
  23601. category (other.category),
  23602. manufacturerName (other.manufacturerName),
  23603. version (other.version),
  23604. fileOrIdentifier (other.fileOrIdentifier),
  23605. lastFileModTime (other.lastFileModTime),
  23606. uid (other.uid),
  23607. isInstrument (other.isInstrument),
  23608. numInputChannels (other.numInputChannels),
  23609. numOutputChannels (other.numOutputChannels)
  23610. {
  23611. }
  23612. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23613. {
  23614. name = other.name;
  23615. pluginFormatName = other.pluginFormatName;
  23616. category = other.category;
  23617. manufacturerName = other.manufacturerName;
  23618. version = other.version;
  23619. fileOrIdentifier = other.fileOrIdentifier;
  23620. uid = other.uid;
  23621. isInstrument = other.isInstrument;
  23622. lastFileModTime = other.lastFileModTime;
  23623. numInputChannels = other.numInputChannels;
  23624. numOutputChannels = other.numOutputChannels;
  23625. return *this;
  23626. }
  23627. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23628. {
  23629. return fileOrIdentifier == other.fileOrIdentifier
  23630. && uid == other.uid;
  23631. }
  23632. const String PluginDescription::createIdentifierString() const throw()
  23633. {
  23634. return pluginFormatName
  23635. + "-" + name
  23636. + "-" + String::toHexString (fileOrIdentifier.hashCode())
  23637. + "-" + String::toHexString (uid);
  23638. }
  23639. XmlElement* PluginDescription::createXml() const
  23640. {
  23641. XmlElement* const e = new XmlElement ("PLUGIN");
  23642. e->setAttribute ("name", name);
  23643. e->setAttribute ("format", pluginFormatName);
  23644. e->setAttribute ("category", category);
  23645. e->setAttribute ("manufacturer", manufacturerName);
  23646. e->setAttribute ("version", version);
  23647. e->setAttribute ("file", fileOrIdentifier);
  23648. e->setAttribute ("uid", String::toHexString (uid));
  23649. e->setAttribute ("isInstrument", isInstrument);
  23650. e->setAttribute ("fileTime", String::toHexString (lastFileModTime.toMilliseconds()));
  23651. e->setAttribute ("numInputs", numInputChannels);
  23652. e->setAttribute ("numOutputs", numOutputChannels);
  23653. return e;
  23654. }
  23655. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23656. {
  23657. if (xml.hasTagName ("PLUGIN"))
  23658. {
  23659. name = xml.getStringAttribute ("name");
  23660. pluginFormatName = xml.getStringAttribute ("format");
  23661. category = xml.getStringAttribute ("category");
  23662. manufacturerName = xml.getStringAttribute ("manufacturer");
  23663. version = xml.getStringAttribute ("version");
  23664. fileOrIdentifier = xml.getStringAttribute ("file");
  23665. uid = xml.getStringAttribute ("uid").getHexValue32();
  23666. isInstrument = xml.getBoolAttribute ("isInstrument", false);
  23667. lastFileModTime = Time (xml.getStringAttribute ("fileTime").getHexValue64());
  23668. numInputChannels = xml.getIntAttribute ("numInputs");
  23669. numOutputChannels = xml.getIntAttribute ("numOutputs");
  23670. return true;
  23671. }
  23672. return false;
  23673. }
  23674. END_JUCE_NAMESPACE
  23675. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23676. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23677. BEGIN_JUCE_NAMESPACE
  23678. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23679. AudioPluginFormat& formatToLookFor,
  23680. FileSearchPath directoriesToSearch,
  23681. const bool recursive,
  23682. const File& deadMansPedalFile_)
  23683. : list (listToAddTo),
  23684. format (formatToLookFor),
  23685. deadMansPedalFile (deadMansPedalFile_),
  23686. nextIndex (0),
  23687. progress (0)
  23688. {
  23689. directoriesToSearch.removeRedundantPaths();
  23690. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23691. // If any plugins have crashed recently when being loaded, move them to the
  23692. // end of the list to give the others a chance to load correctly..
  23693. const StringArray crashedPlugins (getDeadMansPedalFile());
  23694. for (int i = 0; i < crashedPlugins.size(); ++i)
  23695. {
  23696. const String f = crashedPlugins[i];
  23697. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23698. if (f == filesOrIdentifiersToScan[j])
  23699. filesOrIdentifiersToScan.move (j, -1);
  23700. }
  23701. }
  23702. PluginDirectoryScanner::~PluginDirectoryScanner()
  23703. {
  23704. }
  23705. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23706. {
  23707. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23708. }
  23709. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23710. {
  23711. String file (filesOrIdentifiersToScan [nextIndex]);
  23712. if (file.isNotEmpty())
  23713. {
  23714. if (! list.isListingUpToDate (file))
  23715. {
  23716. OwnedArray <PluginDescription> typesFound;
  23717. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23718. StringArray crashedPlugins (getDeadMansPedalFile());
  23719. crashedPlugins.removeString (file);
  23720. crashedPlugins.add (file);
  23721. setDeadMansPedalFile (crashedPlugins);
  23722. list.scanAndAddFile (file,
  23723. dontRescanIfAlreadyInList,
  23724. typesFound,
  23725. format);
  23726. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23727. crashedPlugins.removeString (file);
  23728. setDeadMansPedalFile (crashedPlugins);
  23729. if (typesFound.size() == 0)
  23730. failedFiles.add (file);
  23731. }
  23732. ++nextIndex;
  23733. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23734. }
  23735. return nextIndex < filesOrIdentifiersToScan.size();
  23736. }
  23737. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23738. {
  23739. StringArray lines;
  23740. if (deadMansPedalFile != File::nonexistent)
  23741. {
  23742. lines.addLines (deadMansPedalFile.loadFileAsString());
  23743. lines.removeEmptyStrings();
  23744. }
  23745. return lines;
  23746. }
  23747. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23748. {
  23749. if (deadMansPedalFile != File::nonexistent)
  23750. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23751. }
  23752. END_JUCE_NAMESPACE
  23753. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23754. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23755. BEGIN_JUCE_NAMESPACE
  23756. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23757. const File& deadMansPedalFile_,
  23758. PropertiesFile* const propertiesToUse_)
  23759. : list (listToEdit),
  23760. deadMansPedalFile (deadMansPedalFile_),
  23761. propertiesToUse (propertiesToUse_)
  23762. {
  23763. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23764. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23765. optionsButton->addButtonListener (this);
  23766. optionsButton->setTriggeredOnMouseDown (true);
  23767. setSize (400, 600);
  23768. list.addChangeListener (this);
  23769. }
  23770. PluginListComponent::~PluginListComponent()
  23771. {
  23772. list.removeChangeListener (this);
  23773. deleteAllChildren();
  23774. }
  23775. void PluginListComponent::resized()
  23776. {
  23777. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23778. optionsButton->changeWidthToFitText (24);
  23779. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23780. }
  23781. void PluginListComponent::changeListenerCallback (void*)
  23782. {
  23783. listBox->updateContent();
  23784. listBox->repaint();
  23785. }
  23786. int PluginListComponent::getNumRows()
  23787. {
  23788. return list.getNumTypes();
  23789. }
  23790. void PluginListComponent::paintListBoxItem (int row,
  23791. Graphics& g,
  23792. int width, int height,
  23793. bool rowIsSelected)
  23794. {
  23795. if (rowIsSelected)
  23796. g.fillAll (findColour (TextEditor::highlightColourId));
  23797. const PluginDescription* const pd = list.getType (row);
  23798. if (pd != 0)
  23799. {
  23800. GlyphArrangement ga;
  23801. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23802. g.setColour (Colours::black);
  23803. ga.draw (g);
  23804. float x, y, r, b;
  23805. ga.getBoundingBox (0, -1, x, y, r, b, false);
  23806. String desc;
  23807. desc << pd->pluginFormatName
  23808. << (pd->isInstrument ? " instrument" : " effect")
  23809. << " - "
  23810. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23811. << " / "
  23812. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23813. if (pd->manufacturerName.isNotEmpty())
  23814. desc << " - " << pd->manufacturerName;
  23815. if (pd->version.isNotEmpty())
  23816. desc << " - " << pd->version;
  23817. if (pd->category.isNotEmpty())
  23818. desc << " - category: '" << pd->category << '\'';
  23819. g.setColour (Colours::grey);
  23820. ga.clear();
  23821. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  23822. ga.draw (g);
  23823. }
  23824. }
  23825. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23826. {
  23827. list.removeType (lastRowSelected);
  23828. }
  23829. void PluginListComponent::buttonClicked (Button* b)
  23830. {
  23831. if (optionsButton == b)
  23832. {
  23833. PopupMenu menu;
  23834. menu.addItem (1, TRANS("Clear list"));
  23835. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23836. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23837. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23838. menu.addSeparator();
  23839. menu.addItem (2, TRANS("Sort alphabetically"));
  23840. menu.addItem (3, TRANS("Sort by category"));
  23841. menu.addItem (4, TRANS("Sort by manufacturer"));
  23842. menu.addSeparator();
  23843. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23844. {
  23845. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23846. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23847. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23848. }
  23849. const int r = menu.showAt (optionsButton);
  23850. if (r == 1)
  23851. {
  23852. list.clear();
  23853. }
  23854. else if (r == 2)
  23855. {
  23856. list.sort (KnownPluginList::sortAlphabetically);
  23857. }
  23858. else if (r == 3)
  23859. {
  23860. list.sort (KnownPluginList::sortByCategory);
  23861. }
  23862. else if (r == 4)
  23863. {
  23864. list.sort (KnownPluginList::sortByManufacturer);
  23865. }
  23866. else if (r == 5)
  23867. {
  23868. const SparseSet <int> selected (listBox->getSelectedRows());
  23869. for (int i = list.getNumTypes(); --i >= 0;)
  23870. if (selected.contains (i))
  23871. list.removeType (i);
  23872. }
  23873. else if (r == 6)
  23874. {
  23875. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  23876. if (desc != 0)
  23877. {
  23878. if (File (desc->fileOrIdentifier).existsAsFile())
  23879. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  23880. }
  23881. }
  23882. else if (r == 7)
  23883. {
  23884. for (int i = list.getNumTypes(); --i >= 0;)
  23885. {
  23886. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  23887. {
  23888. list.removeType (i);
  23889. }
  23890. }
  23891. }
  23892. else if (r != 0)
  23893. {
  23894. typeToScan = r - 10;
  23895. startTimer (1);
  23896. }
  23897. }
  23898. }
  23899. void PluginListComponent::timerCallback()
  23900. {
  23901. stopTimer();
  23902. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  23903. }
  23904. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  23905. {
  23906. return true;
  23907. }
  23908. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  23909. {
  23910. OwnedArray <PluginDescription> typesFound;
  23911. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  23912. }
  23913. void PluginListComponent::scanFor (AudioPluginFormat* format)
  23914. {
  23915. if (format == 0)
  23916. return;
  23917. FileSearchPath path (format->getDefaultLocationsToSearch());
  23918. if (propertiesToUse != 0)
  23919. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23920. {
  23921. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  23922. FileSearchPathListComponent pathList;
  23923. pathList.setSize (500, 300);
  23924. pathList.setPath (path);
  23925. aw.addCustomComponent (&pathList);
  23926. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  23927. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23928. if (aw.runModalLoop() == 0)
  23929. return;
  23930. path = pathList.getPath();
  23931. }
  23932. if (propertiesToUse != 0)
  23933. {
  23934. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23935. propertiesToUse->saveIfNeeded();
  23936. }
  23937. double progress = 0.0;
  23938. AlertWindow aw (TRANS("Scanning for plugins..."),
  23939. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  23940. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23941. aw.addProgressBarComponent (progress);
  23942. aw.enterModalState();
  23943. MessageManager::getInstance()->runDispatchLoopUntil (300);
  23944. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  23945. for (;;)
  23946. {
  23947. aw.setMessage (TRANS("Testing:\n\n")
  23948. + scanner.getNextPluginFileThatWillBeScanned());
  23949. MessageManager::getInstance()->runDispatchLoopUntil (20);
  23950. if (! scanner.scanNextFile (true))
  23951. break;
  23952. if (! aw.isCurrentlyModal())
  23953. break;
  23954. progress = scanner.getProgress();
  23955. }
  23956. if (scanner.getFailedFiles().size() > 0)
  23957. {
  23958. StringArray shortNames;
  23959. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  23960. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  23961. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  23962. TRANS("Scan complete"),
  23963. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  23964. + shortNames.joinIntoString (", "));
  23965. }
  23966. }
  23967. END_JUCE_NAMESPACE
  23968. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  23969. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  23970. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  23971. #include <AudioUnit/AudioUnit.h>
  23972. #include <AudioUnit/AUCocoaUIView.h>
  23973. #include <CoreAudioKit/AUGenericView.h>
  23974. #if JUCE_SUPPORT_CARBON
  23975. #include <AudioToolbox/AudioUnitUtilities.h>
  23976. #include <AudioUnit/AudioUnitCarbonView.h>
  23977. #endif
  23978. BEGIN_JUCE_NAMESPACE
  23979. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  23980. #endif
  23981. #if JUCE_MAC
  23982. // Change this to disable logging of various activities
  23983. #ifndef AU_LOGGING
  23984. #define AU_LOGGING 1
  23985. #endif
  23986. #if AU_LOGGING
  23987. #define log(a) Logger::writeToLog(a);
  23988. #else
  23989. #define log(a)
  23990. #endif
  23991. static int insideCallback = 0;
  23992. static const String osTypeToString (OSType type)
  23993. {
  23994. char s[4];
  23995. s[0] = (char) (((uint32) type) >> 24);
  23996. s[1] = (char) (((uint32) type) >> 16);
  23997. s[2] = (char) (((uint32) type) >> 8);
  23998. s[3] = (char) ((uint32) type);
  23999. return String (s, 4);
  24000. }
  24001. static OSType stringToOSType (const String& s1)
  24002. {
  24003. const String s (s1 + " ");
  24004. return (((OSType) (unsigned char) s[0]) << 24)
  24005. | (((OSType) (unsigned char) s[1]) << 16)
  24006. | (((OSType) (unsigned char) s[2]) << 8)
  24007. | ((OSType) (unsigned char) s[3]);
  24008. }
  24009. static const char* auIdentifierPrefix = "AudioUnit:";
  24010. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24011. {
  24012. jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong..
  24013. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24014. String s (auIdentifierPrefix);
  24015. if (desc.componentType == kAudioUnitType_MusicDevice)
  24016. s << "Synths/";
  24017. else if (desc.componentType == kAudioUnitType_MusicEffect
  24018. || desc.componentType == kAudioUnitType_Effect)
  24019. s << "Effects/";
  24020. else if (desc.componentType == kAudioUnitType_Generator)
  24021. s << "Generators/";
  24022. else if (desc.componentType == kAudioUnitType_Panner)
  24023. s << "Panners/";
  24024. s << osTypeToString (desc.componentType) << ","
  24025. << osTypeToString (desc.componentSubType) << ","
  24026. << osTypeToString (desc.componentManufacturer);
  24027. return s;
  24028. }
  24029. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24030. {
  24031. Handle componentNameHandle = NewHandle (sizeof (void*));
  24032. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24033. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24034. {
  24035. ComponentDescription desc;
  24036. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24037. {
  24038. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24039. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24040. if (nameString != 0 && nameString[0] != 0)
  24041. {
  24042. const String all ((const char*) nameString + 1, nameString[0]);
  24043. DBG ("name: "+ all);
  24044. manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim();
  24045. name = all.fromFirstOccurrenceOf (":", false, false).trim();
  24046. }
  24047. if (infoString != 0 && infoString[0] != 0)
  24048. {
  24049. DBG ("info: " + String ((const char*) infoString + 1, infoString[0]));
  24050. }
  24051. if (name.isEmpty())
  24052. name = "<Unknown>";
  24053. }
  24054. DisposeHandle (componentNameHandle);
  24055. DisposeHandle (componentInfoHandle);
  24056. }
  24057. }
  24058. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24059. String& name, String& version, String& manufacturer)
  24060. {
  24061. zerostruct (desc);
  24062. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24063. {
  24064. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'),
  24065. fileOrIdentifier.lastIndexOfChar ('/')) + 1));
  24066. StringArray tokens;
  24067. tokens.addTokens (s, ",", String::empty);
  24068. tokens.trim();
  24069. tokens.removeEmptyStrings();
  24070. if (tokens.size() == 3)
  24071. {
  24072. desc.componentType = stringToOSType (tokens[0]);
  24073. desc.componentSubType = stringToOSType (tokens[1]);
  24074. desc.componentManufacturer = stringToOSType (tokens[2]);
  24075. ComponentRecord* comp = FindNextComponent (0, &desc);
  24076. if (comp != 0)
  24077. {
  24078. getAUDetails (comp, name, manufacturer);
  24079. return true;
  24080. }
  24081. }
  24082. }
  24083. return false;
  24084. }
  24085. class AudioUnitPluginWindowCarbon;
  24086. class AudioUnitPluginWindowCocoa;
  24087. class AudioUnitPluginInstance : public AudioPluginInstance
  24088. {
  24089. public:
  24090. ~AudioUnitPluginInstance();
  24091. // AudioPluginInstance methods:
  24092. void fillInPluginDescription (PluginDescription& desc) const
  24093. {
  24094. desc.name = pluginName;
  24095. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24096. desc.uid = ((int) componentDesc.componentType)
  24097. ^ ((int) componentDesc.componentSubType)
  24098. ^ ((int) componentDesc.componentManufacturer);
  24099. desc.lastFileModTime = 0;
  24100. desc.pluginFormatName = "AudioUnit";
  24101. desc.category = getCategory();
  24102. desc.manufacturerName = manufacturer;
  24103. desc.version = version;
  24104. desc.numInputChannels = getNumInputChannels();
  24105. desc.numOutputChannels = getNumOutputChannels();
  24106. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24107. }
  24108. const String getName() const { return pluginName; }
  24109. bool acceptsMidi() const { return wantsMidiMessages; }
  24110. bool producesMidi() const { return false; }
  24111. // AudioProcessor methods:
  24112. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24113. void releaseResources();
  24114. void processBlock (AudioSampleBuffer& buffer,
  24115. MidiBuffer& midiMessages);
  24116. AudioProcessorEditor* createEditor();
  24117. const String getInputChannelName (const int index) const;
  24118. bool isInputChannelStereoPair (int index) const;
  24119. const String getOutputChannelName (const int index) const;
  24120. bool isOutputChannelStereoPair (int index) const;
  24121. int getNumParameters();
  24122. float getParameter (int index);
  24123. void setParameter (int index, float newValue);
  24124. const String getParameterName (int index);
  24125. const String getParameterText (int index);
  24126. bool isParameterAutomatable (int index) const;
  24127. int getNumPrograms();
  24128. int getCurrentProgram();
  24129. void setCurrentProgram (int index);
  24130. const String getProgramName (int index);
  24131. void changeProgramName (int index, const String& newName);
  24132. void getStateInformation (MemoryBlock& destData);
  24133. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24134. void setStateInformation (const void* data, int sizeInBytes);
  24135. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24136. juce_UseDebuggingNewOperator
  24137. private:
  24138. friend class AudioUnitPluginWindowCarbon;
  24139. friend class AudioUnitPluginWindowCocoa;
  24140. friend class AudioUnitPluginFormat;
  24141. ComponentDescription componentDesc;
  24142. String pluginName, manufacturer, version;
  24143. String fileOrIdentifier;
  24144. CriticalSection lock;
  24145. bool initialised, wantsMidiMessages, wasPlaying;
  24146. HeapBlock <AudioBufferList> outputBufferList;
  24147. AudioTimeStamp timeStamp;
  24148. AudioSampleBuffer* currentBuffer;
  24149. AudioUnit audioUnit;
  24150. Array <int> parameterIds;
  24151. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24152. void initialise();
  24153. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24154. const AudioTimeStamp* inTimeStamp,
  24155. UInt32 inBusNumber,
  24156. UInt32 inNumberFrames,
  24157. AudioBufferList* ioData) const;
  24158. static OSStatus renderGetInputCallback (void* inRefCon,
  24159. AudioUnitRenderActionFlags* ioActionFlags,
  24160. const AudioTimeStamp* inTimeStamp,
  24161. UInt32 inBusNumber,
  24162. UInt32 inNumberFrames,
  24163. AudioBufferList* ioData)
  24164. {
  24165. return ((AudioUnitPluginInstance*) inRefCon)
  24166. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24167. }
  24168. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24169. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24170. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24171. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24172. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24173. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24174. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24175. {
  24176. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24177. }
  24178. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24179. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24180. Float64* outCurrentMeasureDownBeat)
  24181. {
  24182. return ((AudioUnitPluginInstance*) inHostUserData)
  24183. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24184. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24185. }
  24186. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24187. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24188. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24189. {
  24190. return ((AudioUnitPluginInstance*) inHostUserData)
  24191. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24192. outCurrentSampleInTimeLine, outIsCycling,
  24193. outCycleStartBeat, outCycleEndBeat);
  24194. }
  24195. void getNumChannels (int& numIns, int& numOuts)
  24196. {
  24197. numIns = 0;
  24198. numOuts = 0;
  24199. AUChannelInfo supportedChannels [128];
  24200. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24201. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24202. 0, supportedChannels, &supportedChannelsSize) == noErr
  24203. && supportedChannelsSize > 0)
  24204. {
  24205. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24206. {
  24207. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24208. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24209. }
  24210. }
  24211. else
  24212. {
  24213. // (this really means the plugin will take any number of ins/outs as long
  24214. // as they are the same)
  24215. numIns = numOuts = 2;
  24216. }
  24217. }
  24218. const String getCategory() const;
  24219. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24220. };
  24221. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24222. : fileOrIdentifier (fileOrIdentifier),
  24223. initialised (false),
  24224. wantsMidiMessages (false),
  24225. audioUnit (0),
  24226. currentBuffer (0)
  24227. {
  24228. try
  24229. {
  24230. ++insideCallback;
  24231. log ("Opening AU: " + fileOrIdentifier);
  24232. if (getComponentDescFromFile (fileOrIdentifier))
  24233. {
  24234. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24235. if (comp != 0)
  24236. {
  24237. audioUnit = (AudioUnit) OpenComponent (comp);
  24238. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24239. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24240. }
  24241. }
  24242. --insideCallback;
  24243. }
  24244. catch (...)
  24245. {
  24246. --insideCallback;
  24247. }
  24248. }
  24249. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24250. {
  24251. const ScopedLock sl (lock);
  24252. jassert (insideCallback == 0);
  24253. if (audioUnit != 0)
  24254. {
  24255. AudioUnitUninitialize (audioUnit);
  24256. CloseComponent (audioUnit);
  24257. audioUnit = 0;
  24258. }
  24259. }
  24260. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24261. {
  24262. zerostruct (componentDesc);
  24263. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24264. return true;
  24265. const File file (fileOrIdentifier);
  24266. if (! file.hasFileExtension (".component"))
  24267. return false;
  24268. const char* const utf8 = fileOrIdentifier.toUTF8();
  24269. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24270. strlen (utf8), file.isDirectory());
  24271. if (url != 0)
  24272. {
  24273. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24274. CFRelease (url);
  24275. if (bundleRef != 0)
  24276. {
  24277. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24278. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24279. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24280. if (pluginName.isEmpty())
  24281. pluginName = file.getFileNameWithoutExtension();
  24282. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24283. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24284. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24285. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24286. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24287. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24288. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24289. UseResFile (resFileId);
  24290. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24291. {
  24292. Handle h = Get1IndResource ('thng', i);
  24293. if (h != 0)
  24294. {
  24295. HLock (h);
  24296. const uint32* const types = (const uint32*) *h;
  24297. if (types[0] == kAudioUnitType_MusicDevice
  24298. || types[0] == kAudioUnitType_MusicEffect
  24299. || types[0] == kAudioUnitType_Effect
  24300. || types[0] == kAudioUnitType_Generator
  24301. || types[0] == kAudioUnitType_Panner)
  24302. {
  24303. componentDesc.componentType = types[0];
  24304. componentDesc.componentSubType = types[1];
  24305. componentDesc.componentManufacturer = types[2];
  24306. break;
  24307. }
  24308. HUnlock (h);
  24309. ReleaseResource (h);
  24310. }
  24311. }
  24312. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24313. CFRelease (bundleRef);
  24314. }
  24315. }
  24316. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24317. }
  24318. void AudioUnitPluginInstance::initialise()
  24319. {
  24320. if (initialised || audioUnit == 0)
  24321. return;
  24322. log ("Initialising AU: " + pluginName);
  24323. parameterIds.clear();
  24324. {
  24325. UInt32 paramListSize = 0;
  24326. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24327. 0, 0, &paramListSize);
  24328. if (paramListSize > 0)
  24329. {
  24330. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24331. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24332. 0, &parameterIds.getReference(0), &paramListSize);
  24333. }
  24334. }
  24335. {
  24336. AURenderCallbackStruct info;
  24337. zerostruct (info);
  24338. info.inputProcRefCon = this;
  24339. info.inputProc = renderGetInputCallback;
  24340. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24341. 0, &info, sizeof (info));
  24342. }
  24343. {
  24344. HostCallbackInfo info;
  24345. zerostruct (info);
  24346. info.hostUserData = this;
  24347. info.beatAndTempoProc = getBeatAndTempoCallback;
  24348. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24349. info.transportStateProc = getTransportStateCallback;
  24350. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24351. 0, &info, sizeof (info));
  24352. }
  24353. int numIns, numOuts;
  24354. getNumChannels (numIns, numOuts);
  24355. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24356. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24357. setLatencySamples (0);
  24358. }
  24359. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24360. int samplesPerBlockExpected)
  24361. {
  24362. initialise();
  24363. if (initialised)
  24364. {
  24365. int numIns, numOuts;
  24366. getNumChannels (numIns, numOuts);
  24367. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24368. Float64 latencySecs = 0.0;
  24369. UInt32 latencySize = sizeof (latencySecs);
  24370. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24371. 0, &latencySecs, &latencySize);
  24372. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24373. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24374. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24375. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24376. AudioStreamBasicDescription stream;
  24377. zerostruct (stream);
  24378. stream.mSampleRate = sampleRate_;
  24379. stream.mFormatID = kAudioFormatLinearPCM;
  24380. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24381. stream.mFramesPerPacket = 1;
  24382. stream.mBytesPerPacket = 4;
  24383. stream.mBytesPerFrame = 4;
  24384. stream.mBitsPerChannel = 32;
  24385. stream.mChannelsPerFrame = numIns;
  24386. OSStatus err = AudioUnitSetProperty (audioUnit,
  24387. kAudioUnitProperty_StreamFormat,
  24388. kAudioUnitScope_Input,
  24389. 0, &stream, sizeof (stream));
  24390. stream.mChannelsPerFrame = numOuts;
  24391. err = AudioUnitSetProperty (audioUnit,
  24392. kAudioUnitProperty_StreamFormat,
  24393. kAudioUnitScope_Output,
  24394. 0, &stream, sizeof (stream));
  24395. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24396. outputBufferList->mNumberBuffers = numOuts;
  24397. for (int i = numOuts; --i >= 0;)
  24398. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24399. zerostruct (timeStamp);
  24400. timeStamp.mSampleTime = 0;
  24401. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24402. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24403. currentBuffer = 0;
  24404. wasPlaying = false;
  24405. }
  24406. }
  24407. void AudioUnitPluginInstance::releaseResources()
  24408. {
  24409. if (initialised)
  24410. {
  24411. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24412. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24413. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24414. outputBufferList.free();
  24415. currentBuffer = 0;
  24416. }
  24417. }
  24418. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24419. const AudioTimeStamp* inTimeStamp,
  24420. UInt32 inBusNumber,
  24421. UInt32 inNumberFrames,
  24422. AudioBufferList* ioData) const
  24423. {
  24424. if (inBusNumber == 0
  24425. && currentBuffer != 0)
  24426. {
  24427. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24428. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24429. {
  24430. if (i < currentBuffer->getNumChannels())
  24431. {
  24432. memcpy (ioData->mBuffers[i].mData,
  24433. currentBuffer->getSampleData (i, 0),
  24434. sizeof (float) * inNumberFrames);
  24435. }
  24436. else
  24437. {
  24438. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24439. }
  24440. }
  24441. }
  24442. return noErr;
  24443. }
  24444. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24445. MidiBuffer& midiMessages)
  24446. {
  24447. const int numSamples = buffer.getNumSamples();
  24448. if (initialised)
  24449. {
  24450. AudioUnitRenderActionFlags flags = 0;
  24451. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24452. for (int i = getNumOutputChannels(); --i >= 0;)
  24453. {
  24454. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24455. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24456. }
  24457. currentBuffer = &buffer;
  24458. if (wantsMidiMessages)
  24459. {
  24460. const uint8* midiEventData;
  24461. int midiEventSize, midiEventPosition;
  24462. MidiBuffer::Iterator i (midiMessages);
  24463. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24464. {
  24465. if (midiEventSize <= 3)
  24466. MusicDeviceMIDIEvent (audioUnit,
  24467. midiEventData[0], midiEventData[1], midiEventData[2],
  24468. midiEventPosition);
  24469. else
  24470. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24471. }
  24472. midiMessages.clear();
  24473. }
  24474. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24475. 0, numSamples, outputBufferList);
  24476. timeStamp.mSampleTime += numSamples;
  24477. }
  24478. else
  24479. {
  24480. // Not initialised, so just bypass..
  24481. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24482. buffer.clear (i, 0, buffer.getNumSamples());
  24483. }
  24484. }
  24485. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24486. {
  24487. AudioPlayHead* const ph = getPlayHead();
  24488. AudioPlayHead::CurrentPositionInfo result;
  24489. if (ph != 0 && ph->getCurrentPosition (result))
  24490. {
  24491. if (outCurrentBeat != 0)
  24492. *outCurrentBeat = result.ppqPosition;
  24493. if (outCurrentTempo != 0)
  24494. *outCurrentTempo = result.bpm;
  24495. }
  24496. else
  24497. {
  24498. if (outCurrentBeat != 0)
  24499. *outCurrentBeat = 0;
  24500. if (outCurrentTempo != 0)
  24501. *outCurrentTempo = 120.0;
  24502. }
  24503. return noErr;
  24504. }
  24505. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24506. Float32* outTimeSig_Numerator,
  24507. UInt32* outTimeSig_Denominator,
  24508. Float64* outCurrentMeasureDownBeat) const
  24509. {
  24510. AudioPlayHead* const ph = getPlayHead();
  24511. AudioPlayHead::CurrentPositionInfo result;
  24512. if (ph != 0 && ph->getCurrentPosition (result))
  24513. {
  24514. if (outTimeSig_Numerator != 0)
  24515. *outTimeSig_Numerator = result.timeSigNumerator;
  24516. if (outTimeSig_Denominator != 0)
  24517. *outTimeSig_Denominator = result.timeSigDenominator;
  24518. if (outDeltaSampleOffsetToNextBeat != 0)
  24519. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24520. if (outCurrentMeasureDownBeat != 0)
  24521. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24522. }
  24523. else
  24524. {
  24525. if (outDeltaSampleOffsetToNextBeat != 0)
  24526. *outDeltaSampleOffsetToNextBeat = 0;
  24527. if (outTimeSig_Numerator != 0)
  24528. *outTimeSig_Numerator = 4;
  24529. if (outTimeSig_Denominator != 0)
  24530. *outTimeSig_Denominator = 4;
  24531. if (outCurrentMeasureDownBeat != 0)
  24532. *outCurrentMeasureDownBeat = 0;
  24533. }
  24534. return noErr;
  24535. }
  24536. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24537. Boolean* outTransportStateChanged,
  24538. Float64* outCurrentSampleInTimeLine,
  24539. Boolean* outIsCycling,
  24540. Float64* outCycleStartBeat,
  24541. Float64* outCycleEndBeat)
  24542. {
  24543. AudioPlayHead* const ph = getPlayHead();
  24544. AudioPlayHead::CurrentPositionInfo result;
  24545. if (ph != 0 && ph->getCurrentPosition (result))
  24546. {
  24547. if (outIsPlaying != 0)
  24548. *outIsPlaying = result.isPlaying;
  24549. if (outTransportStateChanged != 0)
  24550. {
  24551. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24552. wasPlaying = result.isPlaying;
  24553. }
  24554. if (outCurrentSampleInTimeLine != 0)
  24555. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24556. if (outIsCycling != 0)
  24557. *outIsCycling = false;
  24558. if (outCycleStartBeat != 0)
  24559. *outCycleStartBeat = 0;
  24560. if (outCycleEndBeat != 0)
  24561. *outCycleEndBeat = 0;
  24562. }
  24563. else
  24564. {
  24565. if (outIsPlaying != 0)
  24566. *outIsPlaying = false;
  24567. if (outTransportStateChanged != 0)
  24568. *outTransportStateChanged = false;
  24569. if (outCurrentSampleInTimeLine != 0)
  24570. *outCurrentSampleInTimeLine = 0;
  24571. if (outIsCycling != 0)
  24572. *outIsCycling = false;
  24573. if (outCycleStartBeat != 0)
  24574. *outCycleStartBeat = 0;
  24575. if (outCycleEndBeat != 0)
  24576. *outCycleEndBeat = 0;
  24577. }
  24578. return noErr;
  24579. }
  24580. static VoidArray activeWindows;
  24581. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24582. {
  24583. public:
  24584. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24585. : AudioProcessorEditor (&plugin_),
  24586. plugin (plugin_),
  24587. wrapper (0)
  24588. {
  24589. addAndMakeVisible (wrapper = new NSViewComponent());
  24590. activeWindows.add (this);
  24591. setOpaque (true);
  24592. setVisible (true);
  24593. setSize (100, 100);
  24594. createView (createGenericViewIfNeeded);
  24595. }
  24596. ~AudioUnitPluginWindowCocoa()
  24597. {
  24598. const bool wasValid = isValid();
  24599. wrapper->setView (0);
  24600. activeWindows.removeValue (this);
  24601. if (wasValid)
  24602. plugin.editorBeingDeleted (this);
  24603. delete wrapper;
  24604. }
  24605. bool isValid() const { return wrapper->getView() != 0; }
  24606. void paint (Graphics& g)
  24607. {
  24608. g.fillAll (Colours::white);
  24609. }
  24610. void resized()
  24611. {
  24612. wrapper->setSize (getWidth(), getHeight());
  24613. }
  24614. private:
  24615. AudioUnitPluginInstance& plugin;
  24616. NSViewComponent* wrapper;
  24617. bool createView (const bool createGenericViewIfNeeded)
  24618. {
  24619. NSView* pluginView = 0;
  24620. UInt32 dataSize = 0;
  24621. Boolean isWritable = false;
  24622. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24623. 0, &dataSize, &isWritable) == noErr
  24624. && dataSize != 0
  24625. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24626. 0, &dataSize, &isWritable) == noErr)
  24627. {
  24628. HeapBlock <AudioUnitCocoaViewInfo> info;
  24629. info.calloc (dataSize, 1);
  24630. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24631. 0, info, &dataSize) == noErr)
  24632. {
  24633. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24634. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24635. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24636. Class viewClass = [viewBundle classNamed: viewClassName];
  24637. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24638. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24639. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24640. {
  24641. id factory = [[[viewClass alloc] init] autorelease];
  24642. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24643. withSize: NSMakeSize (getWidth(), getHeight())];
  24644. }
  24645. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24646. {
  24647. CFRelease (info->mCocoaAUViewClass[i]);
  24648. CFRelease (info->mCocoaAUViewBundleLocation);
  24649. }
  24650. }
  24651. }
  24652. if (createGenericViewIfNeeded && (pluginView == 0))
  24653. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24654. wrapper->setView (pluginView);
  24655. if (pluginView != 0)
  24656. setSize ([pluginView frame].size.width,
  24657. [pluginView frame].size.height);
  24658. return pluginView != 0;
  24659. }
  24660. };
  24661. #if JUCE_SUPPORT_CARBON
  24662. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24663. {
  24664. public:
  24665. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24666. : AudioProcessorEditor (&plugin_),
  24667. plugin (plugin_),
  24668. viewComponent (0)
  24669. {
  24670. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24671. activeWindows.add (this);
  24672. setOpaque (true);
  24673. setVisible (true);
  24674. setSize (400, 300);
  24675. ComponentDescription viewList [16];
  24676. UInt32 viewListSize = sizeof (viewList);
  24677. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24678. 0, &viewList, &viewListSize);
  24679. componentRecord = FindNextComponent (0, &viewList[0]);
  24680. }
  24681. ~AudioUnitPluginWindowCarbon()
  24682. {
  24683. innerWrapper = 0;
  24684. activeWindows.removeValue (this);
  24685. if (isValid())
  24686. plugin.editorBeingDeleted (this);
  24687. }
  24688. bool isValid() const throw() { return componentRecord != 0; }
  24689. void paint (Graphics& g)
  24690. {
  24691. g.fillAll (Colours::black);
  24692. }
  24693. void resized()
  24694. {
  24695. innerWrapper->setSize (getWidth(), getHeight());
  24696. }
  24697. bool keyStateChanged (bool)
  24698. {
  24699. return false;
  24700. }
  24701. bool keyPressed (const KeyPress&)
  24702. {
  24703. return false;
  24704. }
  24705. void broughtToFront()
  24706. {
  24707. activeWindows.removeValue (this);
  24708. activeWindows.add (this);
  24709. }
  24710. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24711. AudioUnitCarbonView getViewComponent()
  24712. {
  24713. if (viewComponent == 0 && componentRecord != 0)
  24714. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24715. return viewComponent;
  24716. }
  24717. void closeViewComponent()
  24718. {
  24719. if (viewComponent != 0)
  24720. {
  24721. CloseComponent (viewComponent);
  24722. viewComponent = 0;
  24723. }
  24724. }
  24725. juce_UseDebuggingNewOperator
  24726. private:
  24727. AudioUnitPluginInstance& plugin;
  24728. ComponentRecord* componentRecord;
  24729. AudioUnitCarbonView viewComponent;
  24730. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24731. {
  24732. public:
  24733. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24734. : owner (owner_)
  24735. {
  24736. }
  24737. ~InnerWrapperComponent()
  24738. {
  24739. deleteWindow();
  24740. }
  24741. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24742. {
  24743. log ("Opening AU GUI: " + owner->plugin.getName());
  24744. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24745. if (viewComponent == 0)
  24746. return 0;
  24747. Float32Point pos = { 0, 0 };
  24748. Float32Point size = { 250, 200 };
  24749. HIViewRef pluginView = 0;
  24750. AudioUnitCarbonViewCreate (viewComponent,
  24751. owner->getAudioUnit(),
  24752. windowRef,
  24753. rootView,
  24754. &pos,
  24755. &size,
  24756. (ControlRef*) &pluginView);
  24757. return pluginView;
  24758. }
  24759. void removeView (HIViewRef)
  24760. {
  24761. log ("Closing AU GUI: " + owner->plugin.getName());
  24762. owner->closeViewComponent();
  24763. }
  24764. private:
  24765. AudioUnitPluginWindowCarbon* const owner;
  24766. };
  24767. friend class InnerWrapperComponent;
  24768. ScopedPointer<InnerWrapperComponent> innerWrapper;
  24769. };
  24770. #endif
  24771. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24772. {
  24773. ScopedPointer<AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24774. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24775. w = 0;
  24776. #if JUCE_SUPPORT_CARBON
  24777. if (w == 0)
  24778. {
  24779. w = new AudioUnitPluginWindowCarbon (*this);
  24780. if (! static_cast <AudioUnitPluginWindowCarbon*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24781. w = 0;
  24782. }
  24783. #endif
  24784. if (w == 0)
  24785. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24786. return w.release();
  24787. }
  24788. const String AudioUnitPluginInstance::getCategory() const
  24789. {
  24790. const char* result = 0;
  24791. switch (componentDesc.componentType)
  24792. {
  24793. case kAudioUnitType_Effect:
  24794. case kAudioUnitType_MusicEffect:
  24795. result = "Effect";
  24796. break;
  24797. case kAudioUnitType_MusicDevice:
  24798. result = "Synth";
  24799. break;
  24800. case kAudioUnitType_Generator:
  24801. result = "Generator";
  24802. break;
  24803. case kAudioUnitType_Panner:
  24804. result = "Panner";
  24805. break;
  24806. default:
  24807. break;
  24808. }
  24809. return result;
  24810. }
  24811. int AudioUnitPluginInstance::getNumParameters()
  24812. {
  24813. return parameterIds.size();
  24814. }
  24815. float AudioUnitPluginInstance::getParameter (int index)
  24816. {
  24817. const ScopedLock sl (lock);
  24818. Float32 value = 0.0f;
  24819. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24820. {
  24821. AudioUnitGetParameter (audioUnit,
  24822. (UInt32) parameterIds.getUnchecked (index),
  24823. kAudioUnitScope_Global, 0,
  24824. &value);
  24825. }
  24826. return value;
  24827. }
  24828. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24829. {
  24830. const ScopedLock sl (lock);
  24831. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24832. {
  24833. AudioUnitSetParameter (audioUnit,
  24834. (UInt32) parameterIds.getUnchecked (index),
  24835. kAudioUnitScope_Global, 0,
  24836. newValue, 0);
  24837. }
  24838. }
  24839. const String AudioUnitPluginInstance::getParameterName (int index)
  24840. {
  24841. AudioUnitParameterInfo info;
  24842. zerostruct (info);
  24843. UInt32 sz = sizeof (info);
  24844. String name;
  24845. if (AudioUnitGetProperty (audioUnit,
  24846. kAudioUnitProperty_ParameterInfo,
  24847. kAudioUnitScope_Global,
  24848. parameterIds [index], &info, &sz) == noErr)
  24849. {
  24850. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  24851. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  24852. else
  24853. name = String (info.name, sizeof (info.name));
  24854. }
  24855. return name;
  24856. }
  24857. const String AudioUnitPluginInstance::getParameterText (int index)
  24858. {
  24859. return String (getParameter (index));
  24860. }
  24861. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  24862. {
  24863. AudioUnitParameterInfo info;
  24864. UInt32 sz = sizeof (info);
  24865. if (AudioUnitGetProperty (audioUnit,
  24866. kAudioUnitProperty_ParameterInfo,
  24867. kAudioUnitScope_Global,
  24868. parameterIds [index], &info, &sz) == noErr)
  24869. {
  24870. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  24871. }
  24872. return true;
  24873. }
  24874. int AudioUnitPluginInstance::getNumPrograms()
  24875. {
  24876. CFArrayRef presets;
  24877. UInt32 sz = sizeof (CFArrayRef);
  24878. int num = 0;
  24879. if (AudioUnitGetProperty (audioUnit,
  24880. kAudioUnitProperty_FactoryPresets,
  24881. kAudioUnitScope_Global,
  24882. 0, &presets, &sz) == noErr)
  24883. {
  24884. num = (int) CFArrayGetCount (presets);
  24885. CFRelease (presets);
  24886. }
  24887. return num;
  24888. }
  24889. int AudioUnitPluginInstance::getCurrentProgram()
  24890. {
  24891. AUPreset current;
  24892. current.presetNumber = 0;
  24893. UInt32 sz = sizeof (AUPreset);
  24894. AudioUnitGetProperty (audioUnit,
  24895. kAudioUnitProperty_FactoryPresets,
  24896. kAudioUnitScope_Global,
  24897. 0, &current, &sz);
  24898. return current.presetNumber;
  24899. }
  24900. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  24901. {
  24902. AUPreset current;
  24903. current.presetNumber = newIndex;
  24904. current.presetName = 0;
  24905. AudioUnitSetProperty (audioUnit,
  24906. kAudioUnitProperty_FactoryPresets,
  24907. kAudioUnitScope_Global,
  24908. 0, &current, sizeof (AUPreset));
  24909. }
  24910. const String AudioUnitPluginInstance::getProgramName (int index)
  24911. {
  24912. String s;
  24913. CFArrayRef presets;
  24914. UInt32 sz = sizeof (CFArrayRef);
  24915. if (AudioUnitGetProperty (audioUnit,
  24916. kAudioUnitProperty_FactoryPresets,
  24917. kAudioUnitScope_Global,
  24918. 0, &presets, &sz) == noErr)
  24919. {
  24920. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  24921. {
  24922. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  24923. if (p != 0 && p->presetNumber == index)
  24924. {
  24925. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  24926. break;
  24927. }
  24928. }
  24929. CFRelease (presets);
  24930. }
  24931. return s;
  24932. }
  24933. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  24934. {
  24935. jassertfalse // xxx not implemented!
  24936. }
  24937. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  24938. {
  24939. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  24940. return "Input " + String (index + 1);
  24941. return String::empty;
  24942. }
  24943. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  24944. {
  24945. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  24946. return false;
  24947. return true;
  24948. }
  24949. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  24950. {
  24951. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  24952. return "Output " + String (index + 1);
  24953. return String::empty;
  24954. }
  24955. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  24956. {
  24957. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  24958. return false;
  24959. return true;
  24960. }
  24961. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  24962. {
  24963. getCurrentProgramStateInformation (destData);
  24964. }
  24965. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  24966. {
  24967. CFPropertyListRef propertyList = 0;
  24968. UInt32 sz = sizeof (CFPropertyListRef);
  24969. if (AudioUnitGetProperty (audioUnit,
  24970. kAudioUnitProperty_ClassInfo,
  24971. kAudioUnitScope_Global,
  24972. 0, &propertyList, &sz) == noErr)
  24973. {
  24974. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  24975. CFWriteStreamOpen (stream);
  24976. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  24977. CFWriteStreamClose (stream);
  24978. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  24979. destData.setSize (bytesWritten);
  24980. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  24981. CFRelease (data);
  24982. CFRelease (stream);
  24983. CFRelease (propertyList);
  24984. }
  24985. }
  24986. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  24987. {
  24988. setCurrentProgramStateInformation (data, sizeInBytes);
  24989. }
  24990. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  24991. {
  24992. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  24993. (const UInt8*) data,
  24994. sizeInBytes,
  24995. kCFAllocatorNull);
  24996. CFReadStreamOpen (stream);
  24997. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  24998. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  24999. stream,
  25000. 0,
  25001. kCFPropertyListImmutable,
  25002. &format,
  25003. 0);
  25004. CFRelease (stream);
  25005. if (propertyList != 0)
  25006. AudioUnitSetProperty (audioUnit,
  25007. kAudioUnitProperty_ClassInfo,
  25008. kAudioUnitScope_Global,
  25009. 0, &propertyList, sizeof (propertyList));
  25010. }
  25011. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25012. {
  25013. }
  25014. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25015. {
  25016. }
  25017. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25018. const String& fileOrIdentifier)
  25019. {
  25020. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25021. return;
  25022. PluginDescription desc;
  25023. desc.fileOrIdentifier = fileOrIdentifier;
  25024. desc.uid = 0;
  25025. try
  25026. {
  25027. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25028. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25029. if (auInstance != 0)
  25030. {
  25031. auInstance->fillInPluginDescription (desc);
  25032. results.add (new PluginDescription (desc));
  25033. }
  25034. }
  25035. catch (...)
  25036. {
  25037. // crashed while loading...
  25038. }
  25039. }
  25040. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25041. {
  25042. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25043. {
  25044. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25045. if (result->audioUnit != 0)
  25046. {
  25047. result->initialise();
  25048. return result.release();
  25049. }
  25050. }
  25051. return 0;
  25052. }
  25053. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25054. const bool /*recursive*/)
  25055. {
  25056. StringArray result;
  25057. ComponentRecord* comp = 0;
  25058. ComponentDescription desc;
  25059. zerostruct (desc);
  25060. for (;;)
  25061. {
  25062. zerostruct (desc);
  25063. comp = FindNextComponent (comp, &desc);
  25064. if (comp == 0)
  25065. break;
  25066. GetComponentInfo (comp, &desc, 0, 0, 0);
  25067. if (desc.componentType == kAudioUnitType_MusicDevice
  25068. || desc.componentType == kAudioUnitType_MusicEffect
  25069. || desc.componentType == kAudioUnitType_Effect
  25070. || desc.componentType == kAudioUnitType_Generator
  25071. || desc.componentType == kAudioUnitType_Panner)
  25072. {
  25073. const String s (createAUPluginIdentifier (desc));
  25074. DBG (s);
  25075. result.add (s);
  25076. }
  25077. }
  25078. return result;
  25079. }
  25080. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25081. {
  25082. ComponentDescription desc;
  25083. String name, version, manufacturer;
  25084. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25085. return FindNextComponent (0, &desc) != 0;
  25086. const File f (fileOrIdentifier);
  25087. return f.hasFileExtension (".component")
  25088. && f.isDirectory();
  25089. }
  25090. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25091. {
  25092. ComponentDescription desc;
  25093. String name, version, manufacturer;
  25094. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25095. if (name.isEmpty())
  25096. name = fileOrIdentifier;
  25097. return name;
  25098. }
  25099. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25100. {
  25101. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25102. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25103. else
  25104. return File (desc.fileOrIdentifier).exists();
  25105. }
  25106. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25107. {
  25108. return FileSearchPath ("/(Default AudioUnit locations)");
  25109. }
  25110. #endif
  25111. END_JUCE_NAMESPACE
  25112. #undef log
  25113. #endif
  25114. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25115. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25116. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25117. #define JUCE_MAC_VST_INCLUDED 1
  25118. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25119. #if JUCE_PLUGINHOST_VST
  25120. #if (defined (_WIN32) || defined (_WIN64))
  25121. #undef _WIN32_WINNT
  25122. #define _WIN32_WINNT 0x500
  25123. #undef STRICT
  25124. #define STRICT
  25125. #include <windows.h>
  25126. #include <float.h>
  25127. #pragma warning (disable : 4312 4355)
  25128. #elif defined (LINUX) || defined (__linux__)
  25129. #include <float.h>
  25130. #include <sys/time.h>
  25131. #include <X11/Xlib.h>
  25132. #include <X11/Xutil.h>
  25133. #include <X11/Xatom.h>
  25134. #undef Font
  25135. #undef KeyPress
  25136. #undef Drawable
  25137. #undef Time
  25138. #else
  25139. #ifndef JUCE_MAC_VST_INCLUDED
  25140. // On the mac, this file needs to be compiled indirectly, by using
  25141. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25142. #error
  25143. #endif
  25144. #include <Cocoa/Cocoa.h>
  25145. #include <Carbon/Carbon.h>
  25146. #endif
  25147. #if ! (JUCE_MAC && JUCE_64BIT)
  25148. BEGIN_JUCE_NAMESPACE
  25149. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25150. #endif
  25151. #undef PRAGMA_ALIGN_SUPPORTED
  25152. #define VST_FORCE_DEPRECATED 0
  25153. #ifdef _MSC_VER
  25154. #pragma warning (push)
  25155. #pragma warning (disable: 4996)
  25156. #endif
  25157. #include "pluginterfaces/vst2.x/aeffectx.h"
  25158. #ifdef _MSC_VER
  25159. #pragma warning (pop)
  25160. #endif
  25161. #if JUCE_LINUX
  25162. #define Font JUCE_NAMESPACE::Font
  25163. #define KeyPress JUCE_NAMESPACE::KeyPress
  25164. #define Drawable JUCE_NAMESPACE::Drawable
  25165. #define Time JUCE_NAMESPACE::Time
  25166. #endif
  25167. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25168. #ifdef __aeffect__
  25169. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25170. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25171. class VSTMidiEventList
  25172. {
  25173. public:
  25174. VSTMidiEventList()
  25175. : numEventsUsed (0), numEventsAllocated (0)
  25176. {
  25177. }
  25178. ~VSTMidiEventList()
  25179. {
  25180. freeEvents();
  25181. }
  25182. void clear()
  25183. {
  25184. numEventsUsed = 0;
  25185. if (events != 0)
  25186. events->numEvents = 0;
  25187. }
  25188. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25189. {
  25190. ensureSize (numEventsUsed + 1);
  25191. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25192. events->numEvents = ++numEventsUsed;
  25193. if (numBytes <= 4)
  25194. {
  25195. if (e->type == kVstSysExType)
  25196. {
  25197. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25198. e->type = kVstMidiType;
  25199. e->byteSize = sizeof (VstMidiEvent);
  25200. e->noteLength = 0;
  25201. e->noteOffset = 0;
  25202. e->detune = 0;
  25203. e->noteOffVelocity = 0;
  25204. }
  25205. e->deltaFrames = frameOffset;
  25206. memcpy (e->midiData, midiData, numBytes);
  25207. }
  25208. else
  25209. {
  25210. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25211. if (se->type == kVstSysExType)
  25212. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25213. else
  25214. se->sysexDump = (char*) juce_malloc (numBytes);
  25215. memcpy (se->sysexDump, midiData, numBytes);
  25216. se->type = kVstSysExType;
  25217. se->byteSize = sizeof (VstMidiSysexEvent);
  25218. se->deltaFrames = frameOffset;
  25219. se->flags = 0;
  25220. se->dumpBytes = numBytes;
  25221. se->resvd1 = 0;
  25222. se->resvd2 = 0;
  25223. }
  25224. }
  25225. // Handy method to pull the events out of an event buffer supplied by the host
  25226. // or plugin.
  25227. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25228. {
  25229. for (int i = 0; i < events->numEvents; ++i)
  25230. {
  25231. const VstEvent* const e = events->events[i];
  25232. if (e != 0)
  25233. {
  25234. if (e->type == kVstMidiType)
  25235. {
  25236. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25237. 4, e->deltaFrames);
  25238. }
  25239. else if (e->type == kVstSysExType)
  25240. {
  25241. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25242. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25243. e->deltaFrames);
  25244. }
  25245. }
  25246. }
  25247. }
  25248. void ensureSize (int numEventsNeeded)
  25249. {
  25250. if (numEventsNeeded > numEventsAllocated)
  25251. {
  25252. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25253. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25254. if (events == 0)
  25255. events.calloc (size, 1);
  25256. else
  25257. events.realloc (size, 1);
  25258. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25259. {
  25260. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25261. (int) sizeof (VstMidiSysexEvent)));
  25262. e->type = kVstMidiType;
  25263. e->byteSize = sizeof (VstMidiEvent);
  25264. events->events[i] = (VstEvent*) e;
  25265. }
  25266. numEventsAllocated = numEventsNeeded;
  25267. }
  25268. }
  25269. void freeEvents()
  25270. {
  25271. if (events != 0)
  25272. {
  25273. for (int i = numEventsAllocated; --i >= 0;)
  25274. {
  25275. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25276. if (e->type == kVstSysExType)
  25277. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25278. juce_free (e);
  25279. }
  25280. events.free();
  25281. numEventsUsed = 0;
  25282. numEventsAllocated = 0;
  25283. }
  25284. }
  25285. HeapBlock <VstEvents> events;
  25286. private:
  25287. int numEventsUsed, numEventsAllocated;
  25288. };
  25289. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25290. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25291. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25292. #if ! JUCE_WIN32
  25293. static void _fpreset() {}
  25294. static void _clearfp() {}
  25295. #endif
  25296. extern void juce_callAnyTimersSynchronously();
  25297. const int fxbVersionNum = 1;
  25298. struct fxProgram
  25299. {
  25300. long chunkMagic; // 'CcnK'
  25301. long byteSize; // of this chunk, excl. magic + byteSize
  25302. long fxMagic; // 'FxCk'
  25303. long version;
  25304. long fxID; // fx unique id
  25305. long fxVersion;
  25306. long numParams;
  25307. char prgName[28];
  25308. float params[1]; // variable no. of parameters
  25309. };
  25310. struct fxSet
  25311. {
  25312. long chunkMagic; // 'CcnK'
  25313. long byteSize; // of this chunk, excl. magic + byteSize
  25314. long fxMagic; // 'FxBk'
  25315. long version;
  25316. long fxID; // fx unique id
  25317. long fxVersion;
  25318. long numPrograms;
  25319. char future[128];
  25320. fxProgram programs[1]; // variable no. of programs
  25321. };
  25322. struct fxChunkSet
  25323. {
  25324. long chunkMagic; // 'CcnK'
  25325. long byteSize; // of this chunk, excl. magic + byteSize
  25326. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25327. long version;
  25328. long fxID; // fx unique id
  25329. long fxVersion;
  25330. long numPrograms;
  25331. char future[128];
  25332. long chunkSize;
  25333. char chunk[8]; // variable
  25334. };
  25335. struct fxProgramSet
  25336. {
  25337. long chunkMagic; // 'CcnK'
  25338. long byteSize; // of this chunk, excl. magic + byteSize
  25339. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25340. long version;
  25341. long fxID; // fx unique id
  25342. long fxVersion;
  25343. long numPrograms;
  25344. char name[28];
  25345. long chunkSize;
  25346. char chunk[8]; // variable
  25347. };
  25348. static long vst_swap (const long x) throw()
  25349. {
  25350. #ifdef JUCE_LITTLE_ENDIAN
  25351. return (long) ByteOrder::swap ((uint32) x);
  25352. #else
  25353. return x;
  25354. #endif
  25355. }
  25356. static float vst_swapFloat (const float x) throw()
  25357. {
  25358. #ifdef JUCE_LITTLE_ENDIAN
  25359. union { uint32 asInt; float asFloat; } n;
  25360. n.asFloat = x;
  25361. n.asInt = ByteOrder::swap (n.asInt);
  25362. return n.asFloat;
  25363. #else
  25364. return x;
  25365. #endif
  25366. }
  25367. typedef AEffect* (*MainCall) (audioMasterCallback);
  25368. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25369. static int shellUIDToCreate = 0;
  25370. static int insideVSTCallback = 0;
  25371. class VSTPluginWindow;
  25372. // Change this to disable logging of various VST activities
  25373. #ifndef VST_LOGGING
  25374. #define VST_LOGGING 1
  25375. #endif
  25376. #if VST_LOGGING
  25377. #define log(a) Logger::writeToLog(a);
  25378. #else
  25379. #define log(a)
  25380. #endif
  25381. #if JUCE_MAC && JUCE_PPC
  25382. static void* NewCFMFromMachO (void* const machofp) throw()
  25383. {
  25384. void* result = juce_malloc (8);
  25385. ((void**) result)[0] = machofp;
  25386. ((void**) result)[1] = result;
  25387. return result;
  25388. }
  25389. #endif
  25390. #if JUCE_LINUX
  25391. extern Display* display;
  25392. extern XContext improbableNumber;
  25393. typedef void (*EventProcPtr) (XEvent* ev);
  25394. static bool xErrorTriggered;
  25395. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25396. {
  25397. xErrorTriggered = true;
  25398. return 0;
  25399. }
  25400. static int getPropertyFromXWindow (Window handle, Atom atom)
  25401. {
  25402. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25403. xErrorTriggered = false;
  25404. int userSize;
  25405. unsigned long bytes, userCount;
  25406. unsigned char* data;
  25407. Atom userType;
  25408. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25409. &userType, &userSize, &userCount, &bytes, &data);
  25410. XSetErrorHandler (oldErrorHandler);
  25411. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25412. : 0;
  25413. }
  25414. static Window getChildWindow (Window windowToCheck)
  25415. {
  25416. Window rootWindow, parentWindow;
  25417. Window* childWindows;
  25418. unsigned int numChildren;
  25419. XQueryTree (display,
  25420. windowToCheck,
  25421. &rootWindow,
  25422. &parentWindow,
  25423. &childWindows,
  25424. &numChildren);
  25425. if (numChildren > 0)
  25426. return childWindows [0];
  25427. return 0;
  25428. }
  25429. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25430. {
  25431. if (e.mods.isLeftButtonDown())
  25432. {
  25433. ev.xbutton.button = Button1;
  25434. ev.xbutton.state |= Button1Mask;
  25435. }
  25436. else if (e.mods.isRightButtonDown())
  25437. {
  25438. ev.xbutton.button = Button3;
  25439. ev.xbutton.state |= Button3Mask;
  25440. }
  25441. else if (e.mods.isMiddleButtonDown())
  25442. {
  25443. ev.xbutton.button = Button2;
  25444. ev.xbutton.state |= Button2Mask;
  25445. }
  25446. }
  25447. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25448. {
  25449. if (e.mods.isLeftButtonDown())
  25450. ev.xmotion.state |= Button1Mask;
  25451. else if (e.mods.isRightButtonDown())
  25452. ev.xmotion.state |= Button3Mask;
  25453. else if (e.mods.isMiddleButtonDown())
  25454. ev.xmotion.state |= Button2Mask;
  25455. }
  25456. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25457. {
  25458. if (e.mods.isLeftButtonDown())
  25459. ev.xcrossing.state |= Button1Mask;
  25460. else if (e.mods.isRightButtonDown())
  25461. ev.xcrossing.state |= Button3Mask;
  25462. else if (e.mods.isMiddleButtonDown())
  25463. ev.xcrossing.state |= Button2Mask;
  25464. }
  25465. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25466. {
  25467. if (increment < 0)
  25468. {
  25469. ev.xbutton.button = Button5;
  25470. ev.xbutton.state |= Button5Mask;
  25471. }
  25472. else if (increment > 0)
  25473. {
  25474. ev.xbutton.button = Button4;
  25475. ev.xbutton.state |= Button4Mask;
  25476. }
  25477. }
  25478. #endif
  25479. static VoidArray activeModules;
  25480. class ModuleHandle : public ReferenceCountedObject
  25481. {
  25482. public:
  25483. File file;
  25484. MainCall moduleMain;
  25485. String pluginName;
  25486. static ModuleHandle* findOrCreateModule (const File& file)
  25487. {
  25488. for (int i = activeModules.size(); --i >= 0;)
  25489. {
  25490. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25491. if (module->file == file)
  25492. return module;
  25493. }
  25494. _fpreset(); // (doesn't do any harm)
  25495. ++insideVSTCallback;
  25496. shellUIDToCreate = 0;
  25497. log ("Attempting to load VST: " + file.getFullPathName());
  25498. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25499. if (! m->open())
  25500. m = 0;
  25501. --insideVSTCallback;
  25502. _fpreset(); // (doesn't do any harm)
  25503. return m.release();
  25504. }
  25505. ModuleHandle (const File& file_)
  25506. : file (file_),
  25507. moduleMain (0),
  25508. #if JUCE_WIN32 || JUCE_LINUX
  25509. hModule (0)
  25510. #elif JUCE_MAC
  25511. fragId (0),
  25512. resHandle (0),
  25513. bundleRef (0),
  25514. resFileId (0)
  25515. #endif
  25516. {
  25517. activeModules.add (this);
  25518. #if JUCE_WIN32 || JUCE_LINUX
  25519. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25520. #elif JUCE_MAC
  25521. FSRef ref;
  25522. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25523. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25524. #endif
  25525. }
  25526. ~ModuleHandle()
  25527. {
  25528. activeModules.removeValue (this);
  25529. close();
  25530. }
  25531. juce_UseDebuggingNewOperator
  25532. #if JUCE_WIN32 || JUCE_LINUX
  25533. void* hModule;
  25534. String fullParentDirectoryPathName;
  25535. bool open()
  25536. {
  25537. #if JUCE_WIN32
  25538. static bool timePeriodSet = false;
  25539. if (! timePeriodSet)
  25540. {
  25541. timePeriodSet = true;
  25542. timeBeginPeriod (2);
  25543. }
  25544. #endif
  25545. pluginName = file.getFileNameWithoutExtension();
  25546. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25547. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25548. if (moduleMain == 0)
  25549. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25550. return moduleMain != 0;
  25551. }
  25552. void close()
  25553. {
  25554. _fpreset(); // (doesn't do any harm)
  25555. PlatformUtilities::freeDynamicLibrary (hModule);
  25556. }
  25557. void closeEffect (AEffect* eff)
  25558. {
  25559. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25560. }
  25561. #else
  25562. CFragConnectionID fragId;
  25563. Handle resHandle;
  25564. CFBundleRef bundleRef;
  25565. FSSpec parentDirFSSpec;
  25566. short resFileId;
  25567. bool open()
  25568. {
  25569. bool ok = false;
  25570. const String filename (file.getFullPathName());
  25571. if (file.hasFileExtension (".vst"))
  25572. {
  25573. const char* const utf8 = filename.toUTF8();
  25574. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25575. strlen (utf8), file.isDirectory());
  25576. if (url != 0)
  25577. {
  25578. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25579. CFRelease (url);
  25580. if (bundleRef != 0)
  25581. {
  25582. if (CFBundleLoadExecutable (bundleRef))
  25583. {
  25584. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25585. if (moduleMain == 0)
  25586. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25587. if (moduleMain != 0)
  25588. {
  25589. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25590. if (name != 0)
  25591. {
  25592. if (CFGetTypeID (name) == CFStringGetTypeID())
  25593. {
  25594. char buffer[1024];
  25595. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25596. pluginName = buffer;
  25597. }
  25598. }
  25599. if (pluginName.isEmpty())
  25600. pluginName = file.getFileNameWithoutExtension();
  25601. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25602. ok = true;
  25603. }
  25604. }
  25605. if (! ok)
  25606. {
  25607. CFBundleUnloadExecutable (bundleRef);
  25608. CFRelease (bundleRef);
  25609. bundleRef = 0;
  25610. }
  25611. }
  25612. }
  25613. }
  25614. #if JUCE_PPC
  25615. else
  25616. {
  25617. FSRef fn;
  25618. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25619. {
  25620. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25621. if (resFileId != -1)
  25622. {
  25623. const int numEffs = Count1Resources ('aEff');
  25624. for (int i = 0; i < numEffs; ++i)
  25625. {
  25626. resHandle = Get1IndResource ('aEff', i + 1);
  25627. if (resHandle != 0)
  25628. {
  25629. OSType type;
  25630. Str255 name;
  25631. SInt16 id;
  25632. GetResInfo (resHandle, &id, &type, name);
  25633. pluginName = String ((const char*) name + 1, name[0]);
  25634. DetachResource (resHandle);
  25635. HLock (resHandle);
  25636. Ptr ptr;
  25637. Str255 errorText;
  25638. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25639. name, kPrivateCFragCopy,
  25640. &fragId, &ptr, errorText);
  25641. if (err == noErr)
  25642. {
  25643. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25644. ok = true;
  25645. }
  25646. else
  25647. {
  25648. HUnlock (resHandle);
  25649. }
  25650. break;
  25651. }
  25652. }
  25653. if (! ok)
  25654. CloseResFile (resFileId);
  25655. }
  25656. }
  25657. }
  25658. #endif
  25659. return ok;
  25660. }
  25661. void close()
  25662. {
  25663. #if JUCE_PPC
  25664. if (fragId != 0)
  25665. {
  25666. if (moduleMain != 0)
  25667. disposeMachOFromCFM ((void*) moduleMain);
  25668. CloseConnection (&fragId);
  25669. HUnlock (resHandle);
  25670. if (resFileId != 0)
  25671. CloseResFile (resFileId);
  25672. }
  25673. else
  25674. #endif
  25675. if (bundleRef != 0)
  25676. {
  25677. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25678. if (CFGetRetainCount (bundleRef) == 1)
  25679. CFBundleUnloadExecutable (bundleRef);
  25680. if (CFGetRetainCount (bundleRef) > 0)
  25681. CFRelease (bundleRef);
  25682. }
  25683. }
  25684. void closeEffect (AEffect* eff)
  25685. {
  25686. #if JUCE_PPC
  25687. if (fragId != 0)
  25688. {
  25689. VoidArray thingsToDelete;
  25690. thingsToDelete.add ((void*) eff->dispatcher);
  25691. thingsToDelete.add ((void*) eff->process);
  25692. thingsToDelete.add ((void*) eff->setParameter);
  25693. thingsToDelete.add ((void*) eff->getParameter);
  25694. thingsToDelete.add ((void*) eff->processReplacing);
  25695. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25696. for (int i = thingsToDelete.size(); --i >= 0;)
  25697. disposeMachOFromCFM (thingsToDelete[i]);
  25698. }
  25699. else
  25700. #endif
  25701. {
  25702. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25703. }
  25704. }
  25705. #if JUCE_PPC
  25706. static void* newMachOFromCFM (void* cfmfp)
  25707. {
  25708. if (cfmfp == 0)
  25709. return 0;
  25710. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25711. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25712. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25713. mfp[2] = 0x800c0000;
  25714. mfp[3] = 0x804c0004;
  25715. mfp[4] = 0x7c0903a6;
  25716. mfp[5] = 0x4e800420;
  25717. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25718. return mfp;
  25719. }
  25720. static void disposeMachOFromCFM (void* ptr)
  25721. {
  25722. juce_free (ptr);
  25723. }
  25724. void coerceAEffectFunctionCalls (AEffect* eff)
  25725. {
  25726. if (fragId != 0)
  25727. {
  25728. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25729. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25730. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25731. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25732. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25733. }
  25734. }
  25735. #endif
  25736. #endif
  25737. };
  25738. class VSTPluginInstance : public AudioPluginInstance,
  25739. private Timer,
  25740. private AsyncUpdater
  25741. {
  25742. public:
  25743. ~VSTPluginInstance();
  25744. // AudioPluginInstance methods:
  25745. void fillInPluginDescription (PluginDescription& desc) const
  25746. {
  25747. desc.name = name;
  25748. desc.fileOrIdentifier = module->file.getFullPathName();
  25749. desc.uid = getUID();
  25750. desc.lastFileModTime = module->file.getLastModificationTime();
  25751. desc.pluginFormatName = "VST";
  25752. desc.category = getCategory();
  25753. {
  25754. char buffer [kVstMaxVendorStrLen + 8];
  25755. zerostruct (buffer);
  25756. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25757. desc.manufacturerName = buffer;
  25758. }
  25759. desc.version = getVersion();
  25760. desc.numInputChannels = getNumInputChannels();
  25761. desc.numOutputChannels = getNumOutputChannels();
  25762. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25763. }
  25764. const String getName() const { return name; }
  25765. int getUID() const throw();
  25766. bool acceptsMidi() const { return wantsMidiMessages; }
  25767. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25768. // AudioProcessor methods:
  25769. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25770. void releaseResources();
  25771. void processBlock (AudioSampleBuffer& buffer,
  25772. MidiBuffer& midiMessages);
  25773. AudioProcessorEditor* createEditor();
  25774. const String getInputChannelName (const int index) const;
  25775. bool isInputChannelStereoPair (int index) const;
  25776. const String getOutputChannelName (const int index) const;
  25777. bool isOutputChannelStereoPair (int index) const;
  25778. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25779. float getParameter (int index);
  25780. void setParameter (int index, float newValue);
  25781. const String getParameterName (int index);
  25782. const String getParameterText (int index);
  25783. bool isParameterAutomatable (int index) const;
  25784. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25785. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25786. void setCurrentProgram (int index);
  25787. const String getProgramName (int index);
  25788. void changeProgramName (int index, const String& newName);
  25789. void getStateInformation (MemoryBlock& destData);
  25790. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25791. void setStateInformation (const void* data, int sizeInBytes);
  25792. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25793. void timerCallback();
  25794. void handleAsyncUpdate();
  25795. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25796. juce_UseDebuggingNewOperator
  25797. private:
  25798. friend class VSTPluginWindow;
  25799. friend class VSTPluginFormat;
  25800. AEffect* effect;
  25801. String name;
  25802. CriticalSection lock;
  25803. bool wantsMidiMessages, initialised, isPowerOn;
  25804. mutable StringArray programNames;
  25805. AudioSampleBuffer tempBuffer;
  25806. CriticalSection midiInLock;
  25807. MidiBuffer incomingMidi;
  25808. VSTMidiEventList midiEventsToSend;
  25809. VstTimeInfo vstHostTime;
  25810. HeapBlock <float*> channels;
  25811. ReferenceCountedObjectPtr <ModuleHandle> module;
  25812. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25813. bool restoreProgramSettings (const fxProgram* const prog);
  25814. const String getCurrentProgramName();
  25815. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25816. void updateStoredProgramNames();
  25817. void initialise();
  25818. void handleMidiFromPlugin (const VstEvents* const events);
  25819. void createTempParameterStore (MemoryBlock& dest);
  25820. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25821. const String getParameterLabel (int index) const;
  25822. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25823. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25824. void setChunkData (const char* data, int size, bool isPreset);
  25825. bool loadFromFXBFile (const void* data, int numBytes);
  25826. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25827. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25828. const String getVersion() const throw();
  25829. const String getCategory() const throw();
  25830. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25831. void setPower (const bool on);
  25832. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25833. };
  25834. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25835. : effect (0),
  25836. wantsMidiMessages (false),
  25837. initialised (false),
  25838. isPowerOn (false),
  25839. tempBuffer (1, 1),
  25840. module (module_)
  25841. {
  25842. try
  25843. {
  25844. _fpreset();
  25845. ++insideVSTCallback;
  25846. name = module->pluginName;
  25847. log ("Creating VST instance: " + name);
  25848. #if JUCE_MAC
  25849. if (module->resFileId != 0)
  25850. UseResFile (module->resFileId);
  25851. #if JUCE_PPC
  25852. if (module->fragId != 0)
  25853. {
  25854. static void* audioMasterCoerced = 0;
  25855. if (audioMasterCoerced == 0)
  25856. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  25857. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  25858. }
  25859. else
  25860. #endif
  25861. #endif
  25862. {
  25863. effect = module->moduleMain (&audioMaster);
  25864. }
  25865. --insideVSTCallback;
  25866. if (effect != 0 && effect->magic == kEffectMagic)
  25867. {
  25868. #if JUCE_PPC
  25869. module->coerceAEffectFunctionCalls (effect);
  25870. #endif
  25871. jassert (effect->resvd2 == 0);
  25872. jassert (effect->object != 0);
  25873. _fpreset(); // some dodgy plugs fuck around with this
  25874. }
  25875. else
  25876. {
  25877. effect = 0;
  25878. }
  25879. }
  25880. catch (...)
  25881. {
  25882. --insideVSTCallback;
  25883. }
  25884. }
  25885. VSTPluginInstance::~VSTPluginInstance()
  25886. {
  25887. {
  25888. const ScopedLock sl (lock);
  25889. jassert (insideVSTCallback == 0);
  25890. if (effect != 0 && effect->magic == kEffectMagic)
  25891. {
  25892. try
  25893. {
  25894. #if JUCE_MAC
  25895. if (module->resFileId != 0)
  25896. UseResFile (module->resFileId);
  25897. #endif
  25898. // Must delete any editors before deleting the plugin instance!
  25899. jassert (getActiveEditor() == 0);
  25900. _fpreset(); // some dodgy plugs fuck around with this
  25901. module->closeEffect (effect);
  25902. }
  25903. catch (...)
  25904. {}
  25905. }
  25906. module = 0;
  25907. effect = 0;
  25908. }
  25909. }
  25910. void VSTPluginInstance::initialise()
  25911. {
  25912. if (initialised || effect == 0)
  25913. return;
  25914. log ("Initialising VST: " + module->pluginName);
  25915. initialised = true;
  25916. dispatch (effIdentify, 0, 0, 0, 0);
  25917. // this code would ask the plugin for its name, but so few plugins
  25918. // actually bother implementing this correctly, that it's better to
  25919. // just ignore it and use the file name instead.
  25920. if (getSampleRate() > 0)
  25921. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  25922. if (getBlockSize() > 0)
  25923. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  25924. dispatch (effOpen, 0, 0, 0, 0);
  25925. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25926. getSampleRate(), getBlockSize());
  25927. if (getNumPrograms() > 1)
  25928. setCurrentProgram (0);
  25929. else
  25930. dispatch (effSetProgram, 0, 0, 0, 0);
  25931. int i;
  25932. for (i = effect->numInputs; --i >= 0;)
  25933. dispatch (effConnectInput, i, 1, 0, 0);
  25934. for (i = effect->numOutputs; --i >= 0;)
  25935. dispatch (effConnectOutput, i, 1, 0, 0);
  25936. updateStoredProgramNames();
  25937. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  25938. setLatencySamples (effect->initialDelay);
  25939. }
  25940. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  25941. int samplesPerBlockExpected)
  25942. {
  25943. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25944. sampleRate_, samplesPerBlockExpected);
  25945. setLatencySamples (effect->initialDelay);
  25946. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  25947. vstHostTime.tempo = 120.0;
  25948. vstHostTime.timeSigNumerator = 4;
  25949. vstHostTime.timeSigDenominator = 4;
  25950. vstHostTime.sampleRate = sampleRate_;
  25951. vstHostTime.samplePos = 0;
  25952. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  25953. initialise();
  25954. if (initialised)
  25955. {
  25956. wantsMidiMessages = wantsMidiMessages
  25957. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  25958. if (wantsMidiMessages)
  25959. midiEventsToSend.ensureSize (256);
  25960. else
  25961. midiEventsToSend.freeEvents();
  25962. incomingMidi.clear();
  25963. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  25964. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  25965. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  25966. if (! isPowerOn)
  25967. setPower (true);
  25968. // dodgy hack to force some plugins to initialise the sample rate..
  25969. if ((! hasEditor()) && getNumParameters() > 0)
  25970. {
  25971. const float old = getParameter (0);
  25972. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  25973. setParameter (0, old);
  25974. }
  25975. dispatch (effStartProcess, 0, 0, 0, 0);
  25976. }
  25977. }
  25978. void VSTPluginInstance::releaseResources()
  25979. {
  25980. if (initialised)
  25981. {
  25982. dispatch (effStopProcess, 0, 0, 0, 0);
  25983. setPower (false);
  25984. }
  25985. tempBuffer.setSize (1, 1);
  25986. incomingMidi.clear();
  25987. midiEventsToSend.freeEvents();
  25988. channels.free();
  25989. }
  25990. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  25991. MidiBuffer& midiMessages)
  25992. {
  25993. const int numSamples = buffer.getNumSamples();
  25994. if (initialised)
  25995. {
  25996. AudioPlayHead* playHead = getPlayHead();
  25997. if (playHead != 0)
  25998. {
  25999. AudioPlayHead::CurrentPositionInfo position;
  26000. playHead->getCurrentPosition (position);
  26001. vstHostTime.tempo = position.bpm;
  26002. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26003. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26004. vstHostTime.ppqPos = position.ppqPosition;
  26005. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26006. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26007. if (position.isPlaying)
  26008. vstHostTime.flags |= kVstTransportPlaying;
  26009. else
  26010. vstHostTime.flags &= ~kVstTransportPlaying;
  26011. }
  26012. #if JUCE_WIN32
  26013. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26014. #elif JUCE_LINUX
  26015. timeval micro;
  26016. gettimeofday (&micro, 0);
  26017. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26018. #elif JUCE_MAC
  26019. UnsignedWide micro;
  26020. Microseconds (&micro);
  26021. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26022. #endif
  26023. if (wantsMidiMessages)
  26024. {
  26025. midiEventsToSend.clear();
  26026. midiEventsToSend.ensureSize (1);
  26027. MidiBuffer::Iterator iter (midiMessages);
  26028. const uint8* midiData;
  26029. int numBytesOfMidiData, samplePosition;
  26030. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26031. {
  26032. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26033. jlimit (0, numSamples - 1, samplePosition));
  26034. }
  26035. try
  26036. {
  26037. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26038. }
  26039. catch (...)
  26040. {}
  26041. }
  26042. int i;
  26043. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26044. for (i = 0; i < maxChans; ++i)
  26045. channels[i] = buffer.getSampleData (i);
  26046. channels [maxChans] = 0;
  26047. _clearfp();
  26048. if ((effect->flags & effFlagsCanReplacing) != 0)
  26049. {
  26050. try
  26051. {
  26052. effect->processReplacing (effect, channels, channels, numSamples);
  26053. }
  26054. catch (...)
  26055. {}
  26056. }
  26057. else
  26058. {
  26059. tempBuffer.setSize (effect->numOutputs, numSamples);
  26060. tempBuffer.clear();
  26061. float* outs [64];
  26062. for (i = effect->numOutputs; --i >= 0;)
  26063. outs[i] = tempBuffer.getSampleData (i);
  26064. outs [effect->numOutputs] = 0;
  26065. try
  26066. {
  26067. effect->process (effect, channels, outs, numSamples);
  26068. }
  26069. catch (...)
  26070. {}
  26071. for (i = effect->numOutputs; --i >= 0;)
  26072. buffer.copyFrom (i, 0, outs[i], numSamples);
  26073. }
  26074. }
  26075. else
  26076. {
  26077. // Not initialised, so just bypass..
  26078. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26079. buffer.clear (i, 0, buffer.getNumSamples());
  26080. }
  26081. {
  26082. // copy any incoming midi..
  26083. const ScopedLock sl (midiInLock);
  26084. midiMessages = incomingMidi;
  26085. incomingMidi.clear();
  26086. }
  26087. }
  26088. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26089. {
  26090. if (events != 0)
  26091. {
  26092. const ScopedLock sl (midiInLock);
  26093. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26094. }
  26095. }
  26096. static Array <VSTPluginWindow*> activeVSTWindows;
  26097. class VSTPluginWindow : public AudioProcessorEditor,
  26098. #if ! JUCE_MAC
  26099. public ComponentMovementWatcher,
  26100. #endif
  26101. public Timer
  26102. {
  26103. public:
  26104. VSTPluginWindow (VSTPluginInstance& plugin_)
  26105. : AudioProcessorEditor (&plugin_),
  26106. #if ! JUCE_MAC
  26107. ComponentMovementWatcher (this),
  26108. #endif
  26109. plugin (plugin_),
  26110. isOpen (false),
  26111. wasShowing (false),
  26112. pluginRefusesToResize (false),
  26113. pluginWantsKeys (false),
  26114. alreadyInside (false),
  26115. recursiveResize (false)
  26116. {
  26117. #if JUCE_WIN32
  26118. sizeCheckCount = 0;
  26119. pluginHWND = 0;
  26120. #elif JUCE_LINUX
  26121. pluginWindow = None;
  26122. pluginProc = None;
  26123. #else
  26124. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26125. #endif
  26126. activeVSTWindows.add (this);
  26127. setSize (1, 1);
  26128. setOpaque (true);
  26129. setVisible (true);
  26130. }
  26131. ~VSTPluginWindow()
  26132. {
  26133. #if JUCE_MAC
  26134. innerWrapper = 0;
  26135. #else
  26136. closePluginWindow();
  26137. #endif
  26138. activeVSTWindows.removeValue (this);
  26139. plugin.editorBeingDeleted (this);
  26140. }
  26141. #if ! JUCE_MAC
  26142. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26143. {
  26144. if (recursiveResize)
  26145. return;
  26146. Component* const topComp = getTopLevelComponent();
  26147. if (topComp->getPeer() != 0)
  26148. {
  26149. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26150. recursiveResize = true;
  26151. #if JUCE_WIN32
  26152. if (pluginHWND != 0)
  26153. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26154. #elif JUCE_LINUX
  26155. if (pluginWindow != 0)
  26156. {
  26157. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26158. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26159. XMapRaised (display, pluginWindow);
  26160. }
  26161. #endif
  26162. recursiveResize = false;
  26163. }
  26164. }
  26165. void componentVisibilityChanged (Component&)
  26166. {
  26167. const bool isShowingNow = isShowing();
  26168. if (wasShowing != isShowingNow)
  26169. {
  26170. wasShowing = isShowingNow;
  26171. if (isShowingNow)
  26172. openPluginWindow();
  26173. else
  26174. closePluginWindow();
  26175. }
  26176. componentMovedOrResized (true, true);
  26177. }
  26178. void componentPeerChanged()
  26179. {
  26180. closePluginWindow();
  26181. openPluginWindow();
  26182. }
  26183. #endif
  26184. bool keyStateChanged (bool)
  26185. {
  26186. return pluginWantsKeys;
  26187. }
  26188. bool keyPressed (const KeyPress&)
  26189. {
  26190. return pluginWantsKeys;
  26191. }
  26192. #if JUCE_MAC
  26193. void paint (Graphics& g)
  26194. {
  26195. g.fillAll (Colours::black);
  26196. }
  26197. #else
  26198. void paint (Graphics& g)
  26199. {
  26200. if (isOpen)
  26201. {
  26202. ComponentPeer* const peer = getPeer();
  26203. if (peer != 0)
  26204. {
  26205. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26206. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26207. #if JUCE_LINUX
  26208. if (pluginWindow != 0)
  26209. {
  26210. const Rectangle<int> clip (g.getClipBounds());
  26211. XEvent ev;
  26212. zerostruct (ev);
  26213. ev.xexpose.type = Expose;
  26214. ev.xexpose.display = display;
  26215. ev.xexpose.window = pluginWindow;
  26216. ev.xexpose.x = clip.getX();
  26217. ev.xexpose.y = clip.getY();
  26218. ev.xexpose.width = clip.getWidth();
  26219. ev.xexpose.height = clip.getHeight();
  26220. sendEventToChild (&ev);
  26221. }
  26222. #endif
  26223. }
  26224. }
  26225. else
  26226. {
  26227. g.fillAll (Colours::black);
  26228. }
  26229. }
  26230. #endif
  26231. void timerCallback()
  26232. {
  26233. #if JUCE_WIN32
  26234. if (--sizeCheckCount <= 0)
  26235. {
  26236. sizeCheckCount = 10;
  26237. checkPluginWindowSize();
  26238. }
  26239. #endif
  26240. try
  26241. {
  26242. static bool reentrant = false;
  26243. if (! reentrant)
  26244. {
  26245. reentrant = true;
  26246. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26247. reentrant = false;
  26248. }
  26249. }
  26250. catch (...)
  26251. {}
  26252. }
  26253. void mouseDown (const MouseEvent& e)
  26254. {
  26255. #if JUCE_LINUX
  26256. if (pluginWindow == 0)
  26257. return;
  26258. toFront (true);
  26259. XEvent ev;
  26260. zerostruct (ev);
  26261. ev.xbutton.display = display;
  26262. ev.xbutton.type = ButtonPress;
  26263. ev.xbutton.window = pluginWindow;
  26264. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26265. ev.xbutton.time = CurrentTime;
  26266. ev.xbutton.x = e.x;
  26267. ev.xbutton.y = e.y;
  26268. ev.xbutton.x_root = e.getScreenX();
  26269. ev.xbutton.y_root = e.getScreenY();
  26270. translateJuceToXButtonModifiers (e, ev);
  26271. sendEventToChild (&ev);
  26272. #elif JUCE_WIN32
  26273. (void) e;
  26274. toFront (true);
  26275. #endif
  26276. }
  26277. void broughtToFront()
  26278. {
  26279. activeVSTWindows.removeValue (this);
  26280. activeVSTWindows.add (this);
  26281. #if JUCE_MAC
  26282. dispatch (effEditTop, 0, 0, 0, 0);
  26283. #endif
  26284. }
  26285. juce_UseDebuggingNewOperator
  26286. private:
  26287. VSTPluginInstance& plugin;
  26288. bool isOpen, wasShowing, recursiveResize;
  26289. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26290. #if JUCE_WIN32
  26291. HWND pluginHWND;
  26292. void* originalWndProc;
  26293. int sizeCheckCount;
  26294. #elif JUCE_LINUX
  26295. Window pluginWindow;
  26296. EventProcPtr pluginProc;
  26297. #endif
  26298. #if JUCE_MAC
  26299. void openPluginWindow (WindowRef parentWindow)
  26300. {
  26301. if (isOpen || parentWindow == 0)
  26302. return;
  26303. isOpen = true;
  26304. ERect* rect = 0;
  26305. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26306. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26307. // do this before and after like in the steinberg example
  26308. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26309. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26310. // Install keyboard hooks
  26311. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26312. // double-check it's not too tiny
  26313. int w = 250, h = 150;
  26314. if (rect != 0)
  26315. {
  26316. w = rect->right - rect->left;
  26317. h = rect->bottom - rect->top;
  26318. if (w == 0 || h == 0)
  26319. {
  26320. w = 250;
  26321. h = 150;
  26322. }
  26323. }
  26324. w = jmax (w, 32);
  26325. h = jmax (h, 32);
  26326. setSize (w, h);
  26327. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26328. repaint();
  26329. }
  26330. #else
  26331. void openPluginWindow()
  26332. {
  26333. if (isOpen || getWindowHandle() == 0)
  26334. return;
  26335. log ("Opening VST UI: " + plugin.name);
  26336. isOpen = true;
  26337. ERect* rect = 0;
  26338. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26339. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26340. // do this before and after like in the steinberg example
  26341. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26342. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26343. // Install keyboard hooks
  26344. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26345. #if JUCE_WIN32
  26346. originalWndProc = 0;
  26347. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26348. if (pluginHWND == 0)
  26349. {
  26350. isOpen = false;
  26351. setSize (300, 150);
  26352. return;
  26353. }
  26354. #pragma warning (push)
  26355. #pragma warning (disable: 4244)
  26356. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26357. if (! pluginWantsKeys)
  26358. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26359. #pragma warning (pop)
  26360. int w, h;
  26361. RECT r;
  26362. GetWindowRect (pluginHWND, &r);
  26363. w = r.right - r.left;
  26364. h = r.bottom - r.top;
  26365. if (rect != 0)
  26366. {
  26367. const int rw = rect->right - rect->left;
  26368. const int rh = rect->bottom - rect->top;
  26369. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26370. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26371. {
  26372. // very dodgy logic to decide which size is right.
  26373. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26374. {
  26375. SetWindowPos (pluginHWND, 0,
  26376. 0, 0, rw, rh,
  26377. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26378. GetWindowRect (pluginHWND, &r);
  26379. w = r.right - r.left;
  26380. h = r.bottom - r.top;
  26381. pluginRefusesToResize = (w != rw) || (h != rh);
  26382. w = rw;
  26383. h = rh;
  26384. }
  26385. }
  26386. }
  26387. #elif JUCE_LINUX
  26388. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26389. if (pluginWindow != 0)
  26390. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26391. XInternAtom (display, "_XEventProc", False));
  26392. int w = 250, h = 150;
  26393. if (rect != 0)
  26394. {
  26395. w = rect->right - rect->left;
  26396. h = rect->bottom - rect->top;
  26397. if (w == 0 || h == 0)
  26398. {
  26399. w = 250;
  26400. h = 150;
  26401. }
  26402. }
  26403. if (pluginWindow != 0)
  26404. XMapRaised (display, pluginWindow);
  26405. #endif
  26406. // double-check it's not too tiny
  26407. w = jmax (w, 32);
  26408. h = jmax (h, 32);
  26409. setSize (w, h);
  26410. #if JUCE_WIN32
  26411. checkPluginWindowSize();
  26412. #endif
  26413. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26414. repaint();
  26415. }
  26416. #endif
  26417. #if ! JUCE_MAC
  26418. void closePluginWindow()
  26419. {
  26420. if (isOpen)
  26421. {
  26422. log ("Closing VST UI: " + plugin.getName());
  26423. isOpen = false;
  26424. dispatch (effEditClose, 0, 0, 0, 0);
  26425. #if JUCE_WIN32
  26426. #pragma warning (push)
  26427. #pragma warning (disable: 4244)
  26428. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26429. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26430. #pragma warning (pop)
  26431. stopTimer();
  26432. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26433. DestroyWindow (pluginHWND);
  26434. pluginHWND = 0;
  26435. #elif JUCE_LINUX
  26436. stopTimer();
  26437. pluginWindow = 0;
  26438. pluginProc = 0;
  26439. #endif
  26440. }
  26441. }
  26442. #endif
  26443. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26444. {
  26445. return plugin.dispatch (opcode, index, value, ptr, opt);
  26446. }
  26447. #if JUCE_WIN32
  26448. void checkPluginWindowSize() throw()
  26449. {
  26450. RECT r;
  26451. GetWindowRect (pluginHWND, &r);
  26452. const int w = r.right - r.left;
  26453. const int h = r.bottom - r.top;
  26454. if (isShowing() && w > 0 && h > 0
  26455. && (w != getWidth() || h != getHeight())
  26456. && ! pluginRefusesToResize)
  26457. {
  26458. setSize (w, h);
  26459. sizeCheckCount = 0;
  26460. }
  26461. }
  26462. // hooks to get keyboard events from VST windows..
  26463. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26464. {
  26465. for (int i = activeVSTWindows.size(); --i >= 0;)
  26466. {
  26467. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26468. if (w->pluginHWND == hW)
  26469. {
  26470. if (message == WM_CHAR
  26471. || message == WM_KEYDOWN
  26472. || message == WM_SYSKEYDOWN
  26473. || message == WM_KEYUP
  26474. || message == WM_SYSKEYUP
  26475. || message == WM_APPCOMMAND)
  26476. {
  26477. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26478. message, wParam, lParam);
  26479. }
  26480. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26481. (HWND) w->pluginHWND,
  26482. message,
  26483. wParam,
  26484. lParam);
  26485. }
  26486. }
  26487. return DefWindowProc (hW, message, wParam, lParam);
  26488. }
  26489. #endif
  26490. #if JUCE_LINUX
  26491. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26492. void sendEventToChild (XEvent* event)
  26493. {
  26494. if (pluginProc != 0)
  26495. {
  26496. // if the plugin publishes an event procedure, pass the event directly..
  26497. pluginProc (event);
  26498. }
  26499. else if (pluginWindow != 0)
  26500. {
  26501. // if the plugin has a window, then send the event to the window so that
  26502. // its message thread will pick it up..
  26503. XSendEvent (display, pluginWindow, False, 0L, event);
  26504. XFlush (display);
  26505. }
  26506. }
  26507. void mouseEnter (const MouseEvent& e)
  26508. {
  26509. if (pluginWindow != 0)
  26510. {
  26511. XEvent ev;
  26512. zerostruct (ev);
  26513. ev.xcrossing.display = display;
  26514. ev.xcrossing.type = EnterNotify;
  26515. ev.xcrossing.window = pluginWindow;
  26516. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26517. ev.xcrossing.time = CurrentTime;
  26518. ev.xcrossing.x = e.x;
  26519. ev.xcrossing.y = e.y;
  26520. ev.xcrossing.x_root = e.getScreenX();
  26521. ev.xcrossing.y_root = e.getScreenY();
  26522. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26523. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26524. translateJuceToXCrossingModifiers (e, ev);
  26525. sendEventToChild (&ev);
  26526. }
  26527. }
  26528. void mouseExit (const MouseEvent& e)
  26529. {
  26530. if (pluginWindow != 0)
  26531. {
  26532. XEvent ev;
  26533. zerostruct (ev);
  26534. ev.xcrossing.display = display;
  26535. ev.xcrossing.type = LeaveNotify;
  26536. ev.xcrossing.window = pluginWindow;
  26537. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26538. ev.xcrossing.time = CurrentTime;
  26539. ev.xcrossing.x = e.x;
  26540. ev.xcrossing.y = e.y;
  26541. ev.xcrossing.x_root = e.getScreenX();
  26542. ev.xcrossing.y_root = e.getScreenY();
  26543. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26544. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26545. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26546. translateJuceToXCrossingModifiers (e, ev);
  26547. sendEventToChild (&ev);
  26548. }
  26549. }
  26550. void mouseMove (const MouseEvent& e)
  26551. {
  26552. if (pluginWindow != 0)
  26553. {
  26554. XEvent ev;
  26555. zerostruct (ev);
  26556. ev.xmotion.display = display;
  26557. ev.xmotion.type = MotionNotify;
  26558. ev.xmotion.window = pluginWindow;
  26559. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26560. ev.xmotion.time = CurrentTime;
  26561. ev.xmotion.is_hint = NotifyNormal;
  26562. ev.xmotion.x = e.x;
  26563. ev.xmotion.y = e.y;
  26564. ev.xmotion.x_root = e.getScreenX();
  26565. ev.xmotion.y_root = e.getScreenY();
  26566. sendEventToChild (&ev);
  26567. }
  26568. }
  26569. void mouseDrag (const MouseEvent& e)
  26570. {
  26571. if (pluginWindow != 0)
  26572. {
  26573. XEvent ev;
  26574. zerostruct (ev);
  26575. ev.xmotion.display = display;
  26576. ev.xmotion.type = MotionNotify;
  26577. ev.xmotion.window = pluginWindow;
  26578. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26579. ev.xmotion.time = CurrentTime;
  26580. ev.xmotion.x = e.x ;
  26581. ev.xmotion.y = e.y;
  26582. ev.xmotion.x_root = e.getScreenX();
  26583. ev.xmotion.y_root = e.getScreenY();
  26584. ev.xmotion.is_hint = NotifyNormal;
  26585. translateJuceToXMotionModifiers (e, ev);
  26586. sendEventToChild (&ev);
  26587. }
  26588. }
  26589. void mouseUp (const MouseEvent& e)
  26590. {
  26591. if (pluginWindow != 0)
  26592. {
  26593. XEvent ev;
  26594. zerostruct (ev);
  26595. ev.xbutton.display = display;
  26596. ev.xbutton.type = ButtonRelease;
  26597. ev.xbutton.window = pluginWindow;
  26598. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26599. ev.xbutton.time = CurrentTime;
  26600. ev.xbutton.x = e.x;
  26601. ev.xbutton.y = e.y;
  26602. ev.xbutton.x_root = e.getScreenX();
  26603. ev.xbutton.y_root = e.getScreenY();
  26604. translateJuceToXButtonModifiers (e, ev);
  26605. sendEventToChild (&ev);
  26606. }
  26607. }
  26608. void mouseWheelMove (const MouseEvent& e,
  26609. float incrementX,
  26610. float incrementY)
  26611. {
  26612. if (pluginWindow != 0)
  26613. {
  26614. XEvent ev;
  26615. zerostruct (ev);
  26616. ev.xbutton.display = display;
  26617. ev.xbutton.type = ButtonPress;
  26618. ev.xbutton.window = pluginWindow;
  26619. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26620. ev.xbutton.time = CurrentTime;
  26621. ev.xbutton.x = e.x;
  26622. ev.xbutton.y = e.y;
  26623. ev.xbutton.x_root = e.getScreenX();
  26624. ev.xbutton.y_root = e.getScreenY();
  26625. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26626. sendEventToChild (&ev);
  26627. // TODO - put a usleep here ?
  26628. ev.xbutton.type = ButtonRelease;
  26629. sendEventToChild (&ev);
  26630. }
  26631. }
  26632. #endif
  26633. #if JUCE_MAC
  26634. #if ! JUCE_SUPPORT_CARBON
  26635. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26636. #endif
  26637. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26638. {
  26639. public:
  26640. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26641. : owner (owner_),
  26642. alreadyInside (false)
  26643. {
  26644. }
  26645. ~InnerWrapperComponent()
  26646. {
  26647. deleteWindow();
  26648. }
  26649. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26650. {
  26651. owner->openPluginWindow (windowRef);
  26652. return 0;
  26653. }
  26654. void removeView (HIViewRef)
  26655. {
  26656. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26657. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26658. }
  26659. bool getEmbeddedViewSize (int& w, int& h)
  26660. {
  26661. ERect* rect = 0;
  26662. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26663. w = rect->right - rect->left;
  26664. h = rect->bottom - rect->top;
  26665. return true;
  26666. }
  26667. void mouseDown (int x, int y)
  26668. {
  26669. if (! alreadyInside)
  26670. {
  26671. alreadyInside = true;
  26672. getTopLevelComponent()->toFront (true);
  26673. owner->dispatch (effEditMouse, x, y, 0, 0);
  26674. alreadyInside = false;
  26675. }
  26676. else
  26677. {
  26678. PostEvent (::mouseDown, 0);
  26679. }
  26680. }
  26681. void paint()
  26682. {
  26683. ComponentPeer* const peer = getPeer();
  26684. if (peer != 0)
  26685. {
  26686. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26687. ERect r;
  26688. r.left = pos.getX();
  26689. r.right = r.left + getWidth();
  26690. r.top = pos.getY();
  26691. r.bottom = r.top + getHeight();
  26692. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26693. }
  26694. }
  26695. private:
  26696. VSTPluginWindow* const owner;
  26697. bool alreadyInside;
  26698. };
  26699. friend class InnerWrapperComponent;
  26700. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26701. void resized()
  26702. {
  26703. innerWrapper->setSize (getWidth(), getHeight());
  26704. }
  26705. #endif
  26706. };
  26707. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26708. {
  26709. if (hasEditor())
  26710. return new VSTPluginWindow (*this);
  26711. return 0;
  26712. }
  26713. void VSTPluginInstance::handleAsyncUpdate()
  26714. {
  26715. // indicates that something about the plugin has changed..
  26716. updateHostDisplay();
  26717. }
  26718. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26719. {
  26720. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26721. {
  26722. changeProgramName (getCurrentProgram(), prog->prgName);
  26723. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26724. setParameter (i, vst_swapFloat (prog->params[i]));
  26725. return true;
  26726. }
  26727. return false;
  26728. }
  26729. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26730. const int dataSize)
  26731. {
  26732. if (dataSize < 28)
  26733. return false;
  26734. const fxSet* const set = (const fxSet*) data;
  26735. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26736. || vst_swap (set->version) > fxbVersionNum)
  26737. return false;
  26738. if (vst_swap (set->fxMagic) == 'FxBk')
  26739. {
  26740. // bank of programs
  26741. if (vst_swap (set->numPrograms) >= 0)
  26742. {
  26743. const int oldProg = getCurrentProgram();
  26744. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26745. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26746. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26747. {
  26748. if (i != oldProg)
  26749. {
  26750. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26751. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26752. return false;
  26753. if (vst_swap (set->numPrograms) > 0)
  26754. setCurrentProgram (i);
  26755. if (! restoreProgramSettings (prog))
  26756. return false;
  26757. }
  26758. }
  26759. if (vst_swap (set->numPrograms) > 0)
  26760. setCurrentProgram (oldProg);
  26761. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26762. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26763. return false;
  26764. if (! restoreProgramSettings (prog))
  26765. return false;
  26766. }
  26767. }
  26768. else if (vst_swap (set->fxMagic) == 'FxCk')
  26769. {
  26770. // single program
  26771. const fxProgram* const prog = (const fxProgram*) data;
  26772. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26773. return false;
  26774. changeProgramName (getCurrentProgram(), prog->prgName);
  26775. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26776. setParameter (i, vst_swapFloat (prog->params[i]));
  26777. }
  26778. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26779. {
  26780. // non-preset chunk
  26781. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26782. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26783. return false;
  26784. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26785. }
  26786. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26787. {
  26788. // preset chunk
  26789. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26790. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26791. return false;
  26792. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26793. changeProgramName (getCurrentProgram(), cset->name);
  26794. }
  26795. else
  26796. {
  26797. return false;
  26798. }
  26799. return true;
  26800. }
  26801. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26802. {
  26803. const int numParams = getNumParameters();
  26804. prog->chunkMagic = vst_swap ('CcnK');
  26805. prog->byteSize = 0;
  26806. prog->fxMagic = vst_swap ('FxCk');
  26807. prog->version = vst_swap (fxbVersionNum);
  26808. prog->fxID = vst_swap (getUID());
  26809. prog->fxVersion = vst_swap (getVersionNumber());
  26810. prog->numParams = vst_swap (numParams);
  26811. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26812. for (int i = 0; i < numParams; ++i)
  26813. prog->params[i] = vst_swapFloat (getParameter (i));
  26814. }
  26815. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26816. {
  26817. const int numPrograms = getNumPrograms();
  26818. const int numParams = getNumParameters();
  26819. if (usesChunks())
  26820. {
  26821. if (isFXB)
  26822. {
  26823. MemoryBlock chunk;
  26824. getChunkData (chunk, false, maxSizeMB);
  26825. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26826. dest.setSize (totalLen, true);
  26827. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26828. set->chunkMagic = vst_swap ('CcnK');
  26829. set->byteSize = 0;
  26830. set->fxMagic = vst_swap ('FBCh');
  26831. set->version = vst_swap (fxbVersionNum);
  26832. set->fxID = vst_swap (getUID());
  26833. set->fxVersion = vst_swap (getVersionNumber());
  26834. set->numPrograms = vst_swap (numPrograms);
  26835. set->chunkSize = vst_swap ((long) chunk.getSize());
  26836. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26837. }
  26838. else
  26839. {
  26840. MemoryBlock chunk;
  26841. getChunkData (chunk, true, maxSizeMB);
  26842. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26843. dest.setSize (totalLen, true);
  26844. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26845. set->chunkMagic = vst_swap ('CcnK');
  26846. set->byteSize = 0;
  26847. set->fxMagic = vst_swap ('FPCh');
  26848. set->version = vst_swap (fxbVersionNum);
  26849. set->fxID = vst_swap (getUID());
  26850. set->fxVersion = vst_swap (getVersionNumber());
  26851. set->numPrograms = vst_swap (numPrograms);
  26852. set->chunkSize = vst_swap ((long) chunk.getSize());
  26853. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  26854. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26855. }
  26856. }
  26857. else
  26858. {
  26859. if (isFXB)
  26860. {
  26861. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26862. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  26863. dest.setSize (len, true);
  26864. fxSet* const set = (fxSet*) dest.getData();
  26865. set->chunkMagic = vst_swap ('CcnK');
  26866. set->byteSize = 0;
  26867. set->fxMagic = vst_swap ('FxBk');
  26868. set->version = vst_swap (fxbVersionNum);
  26869. set->fxID = vst_swap (getUID());
  26870. set->fxVersion = vst_swap (getVersionNumber());
  26871. set->numPrograms = vst_swap (numPrograms);
  26872. const int oldProgram = getCurrentProgram();
  26873. MemoryBlock oldSettings;
  26874. createTempParameterStore (oldSettings);
  26875. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  26876. for (int i = 0; i < numPrograms; ++i)
  26877. {
  26878. if (i != oldProgram)
  26879. {
  26880. setCurrentProgram (i);
  26881. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  26882. }
  26883. }
  26884. setCurrentProgram (oldProgram);
  26885. restoreFromTempParameterStore (oldSettings);
  26886. }
  26887. else
  26888. {
  26889. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26890. dest.setSize (totalLen, true);
  26891. setParamsInProgramBlock ((fxProgram*) dest.getData());
  26892. }
  26893. }
  26894. return true;
  26895. }
  26896. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  26897. {
  26898. if (usesChunks())
  26899. {
  26900. void* data = 0;
  26901. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  26902. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  26903. {
  26904. mb.setSize (bytes);
  26905. mb.copyFrom (data, 0, bytes);
  26906. }
  26907. }
  26908. }
  26909. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  26910. {
  26911. if (size > 0 && usesChunks())
  26912. {
  26913. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  26914. if (! isPreset)
  26915. updateStoredProgramNames();
  26916. }
  26917. }
  26918. void VSTPluginInstance::timerCallback()
  26919. {
  26920. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  26921. stopTimer();
  26922. }
  26923. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  26924. {
  26925. const ScopedLock sl (lock);
  26926. ++insideVSTCallback;
  26927. int result = 0;
  26928. try
  26929. {
  26930. if (effect != 0)
  26931. {
  26932. #if JUCE_MAC
  26933. if (module->resFileId != 0)
  26934. UseResFile (module->resFileId);
  26935. CGrafPtr oldPort;
  26936. if (getActiveEditor() != 0)
  26937. {
  26938. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  26939. GetPort (&oldPort);
  26940. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  26941. SetOrigin (-pos.getX(), -pos.getY());
  26942. }
  26943. #endif
  26944. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  26945. #if JUCE_MAC
  26946. if (getActiveEditor() != 0)
  26947. SetPort (oldPort);
  26948. module->resFileId = CurResFile();
  26949. #endif
  26950. --insideVSTCallback;
  26951. return result;
  26952. }
  26953. }
  26954. catch (...)
  26955. {
  26956. }
  26957. --insideVSTCallback;
  26958. return result;
  26959. }
  26960. // handles non plugin-specific callbacks..
  26961. static const int defaultVSTSampleRateValue = 16384;
  26962. static const int defaultVSTBlockSizeValue = 512;
  26963. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26964. {
  26965. (void) index;
  26966. (void) value;
  26967. (void) opt;
  26968. switch (opcode)
  26969. {
  26970. case audioMasterCanDo:
  26971. {
  26972. static const char* canDos[] = { "supplyIdle",
  26973. "sendVstEvents",
  26974. "sendVstMidiEvent",
  26975. "sendVstTimeInfo",
  26976. "receiveVstEvents",
  26977. "receiveVstMidiEvent",
  26978. "supportShell",
  26979. "shellCategory" };
  26980. for (int i = 0; i < numElementsInArray (canDos); ++i)
  26981. if (strcmp (canDos[i], (const char*) ptr) == 0)
  26982. return 1;
  26983. return 0;
  26984. }
  26985. case audioMasterVersion:
  26986. return 0x2400;
  26987. case audioMasterCurrentId:
  26988. return shellUIDToCreate;
  26989. case audioMasterGetNumAutomatableParameters:
  26990. return 0;
  26991. case audioMasterGetAutomationState:
  26992. return 1;
  26993. case audioMasterGetVendorVersion:
  26994. return 0x0101;
  26995. case audioMasterGetVendorString:
  26996. case audioMasterGetProductString:
  26997. {
  26998. String hostName ("Juce VST Host");
  26999. if (JUCEApplication::getInstance() != 0)
  27000. hostName = JUCEApplication::getInstance()->getApplicationName();
  27001. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27002. }
  27003. break;
  27004. case audioMasterGetSampleRate:
  27005. return (VstIntPtr) defaultVSTSampleRateValue;
  27006. case audioMasterGetBlockSize:
  27007. return (VstIntPtr) defaultVSTBlockSizeValue;
  27008. case audioMasterSetOutputSampleRate:
  27009. return 0;
  27010. default:
  27011. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27012. break;
  27013. }
  27014. return 0;
  27015. }
  27016. // handles callbacks for a specific plugin
  27017. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27018. {
  27019. switch (opcode)
  27020. {
  27021. case audioMasterAutomate:
  27022. sendParamChangeMessageToListeners (index, opt);
  27023. break;
  27024. case audioMasterProcessEvents:
  27025. handleMidiFromPlugin ((const VstEvents*) ptr);
  27026. break;
  27027. case audioMasterGetTime:
  27028. #ifdef _MSC_VER
  27029. #pragma warning (push)
  27030. #pragma warning (disable: 4311)
  27031. #endif
  27032. return (VstIntPtr) &vstHostTime;
  27033. #ifdef _MSC_VER
  27034. #pragma warning (pop)
  27035. #endif
  27036. break;
  27037. case audioMasterIdle:
  27038. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27039. {
  27040. ++insideVSTCallback;
  27041. #if JUCE_MAC
  27042. if (getActiveEditor() != 0)
  27043. dispatch (effEditIdle, 0, 0, 0, 0);
  27044. #endif
  27045. juce_callAnyTimersSynchronously();
  27046. handleUpdateNowIfNeeded();
  27047. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27048. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27049. --insideVSTCallback;
  27050. }
  27051. break;
  27052. case audioMasterUpdateDisplay:
  27053. triggerAsyncUpdate();
  27054. break;
  27055. case audioMasterTempoAt:
  27056. // returns (10000 * bpm)
  27057. break;
  27058. case audioMasterNeedIdle:
  27059. startTimer (50);
  27060. break;
  27061. case audioMasterSizeWindow:
  27062. if (getActiveEditor() != 0)
  27063. getActiveEditor()->setSize (index, value);
  27064. return 1;
  27065. case audioMasterGetSampleRate:
  27066. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27067. case audioMasterGetBlockSize:
  27068. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27069. case audioMasterWantMidi:
  27070. wantsMidiMessages = true;
  27071. break;
  27072. case audioMasterGetDirectory:
  27073. #if JUCE_MAC
  27074. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27075. #else
  27076. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27077. #endif
  27078. case audioMasterGetAutomationState:
  27079. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27080. break;
  27081. // none of these are handled (yet)..
  27082. case audioMasterBeginEdit:
  27083. case audioMasterEndEdit:
  27084. case audioMasterSetTime:
  27085. case audioMasterPinConnected:
  27086. case audioMasterGetParameterQuantization:
  27087. case audioMasterIOChanged:
  27088. case audioMasterGetInputLatency:
  27089. case audioMasterGetOutputLatency:
  27090. case audioMasterGetPreviousPlug:
  27091. case audioMasterGetNextPlug:
  27092. case audioMasterWillReplaceOrAccumulate:
  27093. case audioMasterGetCurrentProcessLevel:
  27094. case audioMasterOfflineStart:
  27095. case audioMasterOfflineRead:
  27096. case audioMasterOfflineWrite:
  27097. case audioMasterOfflineGetCurrentPass:
  27098. case audioMasterOfflineGetCurrentMetaPass:
  27099. case audioMasterVendorSpecific:
  27100. case audioMasterSetIcon:
  27101. case audioMasterGetLanguage:
  27102. case audioMasterOpenWindow:
  27103. case audioMasterCloseWindow:
  27104. break;
  27105. default:
  27106. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27107. }
  27108. return 0;
  27109. }
  27110. // entry point for all callbacks from the plugin
  27111. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27112. {
  27113. try
  27114. {
  27115. if (effect != 0 && effect->resvd2 != 0)
  27116. {
  27117. return ((VSTPluginInstance*)(effect->resvd2))
  27118. ->handleCallback (opcode, index, value, ptr, opt);
  27119. }
  27120. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27121. }
  27122. catch (...)
  27123. {
  27124. return 0;
  27125. }
  27126. }
  27127. const String VSTPluginInstance::getVersion() const throw()
  27128. {
  27129. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27130. String s;
  27131. if (v == 0 || v == -1)
  27132. v = getVersionNumber();
  27133. if (v != 0)
  27134. {
  27135. int versionBits[4];
  27136. int n = 0;
  27137. while (v != 0)
  27138. {
  27139. versionBits [n++] = (v & 0xff);
  27140. v >>= 8;
  27141. }
  27142. s << 'V';
  27143. while (n > 0)
  27144. {
  27145. s << versionBits [--n];
  27146. if (n > 0)
  27147. s << '.';
  27148. }
  27149. }
  27150. return s;
  27151. }
  27152. int VSTPluginInstance::getUID() const throw()
  27153. {
  27154. int uid = effect != 0 ? effect->uniqueID : 0;
  27155. if (uid == 0)
  27156. uid = module->file.hashCode();
  27157. return uid;
  27158. }
  27159. const String VSTPluginInstance::getCategory() const throw()
  27160. {
  27161. const char* result = 0;
  27162. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27163. {
  27164. case kPlugCategEffect:
  27165. result = "Effect";
  27166. break;
  27167. case kPlugCategSynth:
  27168. result = "Synth";
  27169. break;
  27170. case kPlugCategAnalysis:
  27171. result = "Anaylsis";
  27172. break;
  27173. case kPlugCategMastering:
  27174. result = "Mastering";
  27175. break;
  27176. case kPlugCategSpacializer:
  27177. result = "Spacial";
  27178. break;
  27179. case kPlugCategRoomFx:
  27180. result = "Reverb";
  27181. break;
  27182. case kPlugSurroundFx:
  27183. result = "Surround";
  27184. break;
  27185. case kPlugCategRestoration:
  27186. result = "Restoration";
  27187. break;
  27188. case kPlugCategGenerator:
  27189. result = "Tone generation";
  27190. break;
  27191. default:
  27192. break;
  27193. }
  27194. return result;
  27195. }
  27196. float VSTPluginInstance::getParameter (int index)
  27197. {
  27198. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27199. {
  27200. try
  27201. {
  27202. const ScopedLock sl (lock);
  27203. return effect->getParameter (effect, index);
  27204. }
  27205. catch (...)
  27206. {
  27207. }
  27208. }
  27209. return 0.0f;
  27210. }
  27211. void VSTPluginInstance::setParameter (int index, float newValue)
  27212. {
  27213. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27214. {
  27215. try
  27216. {
  27217. const ScopedLock sl (lock);
  27218. if (effect->getParameter (effect, index) != newValue)
  27219. effect->setParameter (effect, index, newValue);
  27220. }
  27221. catch (...)
  27222. {
  27223. }
  27224. }
  27225. }
  27226. const String VSTPluginInstance::getParameterName (int index)
  27227. {
  27228. if (effect != 0)
  27229. {
  27230. jassert (index >= 0 && index < effect->numParams);
  27231. char nm [256];
  27232. zerostruct (nm);
  27233. dispatch (effGetParamName, index, 0, nm, 0);
  27234. return String (nm).trim();
  27235. }
  27236. return String::empty;
  27237. }
  27238. const String VSTPluginInstance::getParameterLabel (int index) const
  27239. {
  27240. if (effect != 0)
  27241. {
  27242. jassert (index >= 0 && index < effect->numParams);
  27243. char nm [256];
  27244. zerostruct (nm);
  27245. dispatch (effGetParamLabel, index, 0, nm, 0);
  27246. return String (nm).trim();
  27247. }
  27248. return String::empty;
  27249. }
  27250. const String VSTPluginInstance::getParameterText (int index)
  27251. {
  27252. if (effect != 0)
  27253. {
  27254. jassert (index >= 0 && index < effect->numParams);
  27255. char nm [256];
  27256. zerostruct (nm);
  27257. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27258. return String (nm).trim();
  27259. }
  27260. return String::empty;
  27261. }
  27262. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27263. {
  27264. if (effect != 0)
  27265. {
  27266. jassert (index >= 0 && index < effect->numParams);
  27267. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27268. }
  27269. return false;
  27270. }
  27271. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27272. {
  27273. dest.setSize (64 + 4 * getNumParameters());
  27274. dest.fillWith (0);
  27275. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27276. float* const p = (float*) (((char*) dest.getData()) + 64);
  27277. for (int i = 0; i < getNumParameters(); ++i)
  27278. p[i] = getParameter(i);
  27279. }
  27280. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27281. {
  27282. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27283. float* p = (float*) (((char*) m.getData()) + 64);
  27284. for (int i = 0; i < getNumParameters(); ++i)
  27285. setParameter (i, p[i]);
  27286. }
  27287. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27288. {
  27289. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27290. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27291. }
  27292. const String VSTPluginInstance::getProgramName (int index)
  27293. {
  27294. if (index == getCurrentProgram())
  27295. {
  27296. return getCurrentProgramName();
  27297. }
  27298. else if (effect != 0)
  27299. {
  27300. char nm [256];
  27301. zerostruct (nm);
  27302. if (dispatch (effGetProgramNameIndexed,
  27303. jlimit (0, getNumPrograms(), index),
  27304. -1, nm, 0) != 0)
  27305. {
  27306. return String (nm).trim();
  27307. }
  27308. }
  27309. return programNames [index];
  27310. }
  27311. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27312. {
  27313. if (index == getCurrentProgram())
  27314. {
  27315. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27316. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27317. }
  27318. else
  27319. {
  27320. jassertfalse // xxx not implemented!
  27321. }
  27322. }
  27323. void VSTPluginInstance::updateStoredProgramNames()
  27324. {
  27325. if (effect != 0 && getNumPrograms() > 0)
  27326. {
  27327. char nm [256];
  27328. zerostruct (nm);
  27329. // only do this if the plugin can't use indexed names..
  27330. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27331. {
  27332. const int oldProgram = getCurrentProgram();
  27333. MemoryBlock oldSettings;
  27334. createTempParameterStore (oldSettings);
  27335. for (int i = 0; i < getNumPrograms(); ++i)
  27336. {
  27337. setCurrentProgram (i);
  27338. getCurrentProgramName(); // (this updates the list)
  27339. }
  27340. setCurrentProgram (oldProgram);
  27341. restoreFromTempParameterStore (oldSettings);
  27342. }
  27343. }
  27344. }
  27345. const String VSTPluginInstance::getCurrentProgramName()
  27346. {
  27347. if (effect != 0)
  27348. {
  27349. char nm [256];
  27350. zerostruct (nm);
  27351. dispatch (effGetProgramName, 0, 0, nm, 0);
  27352. const int index = getCurrentProgram();
  27353. if (programNames[index].isEmpty())
  27354. {
  27355. while (programNames.size() < index)
  27356. programNames.add (String::empty);
  27357. programNames.set (index, String (nm).trim());
  27358. }
  27359. return String (nm).trim();
  27360. }
  27361. return String::empty;
  27362. }
  27363. const String VSTPluginInstance::getInputChannelName (const int index) const
  27364. {
  27365. if (index >= 0 && index < getNumInputChannels())
  27366. {
  27367. VstPinProperties pinProps;
  27368. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27369. return String (pinProps.label, sizeof (pinProps.label));
  27370. }
  27371. return String::empty;
  27372. }
  27373. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27374. {
  27375. if (index < 0 || index >= getNumInputChannels())
  27376. return false;
  27377. VstPinProperties pinProps;
  27378. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27379. return (pinProps.flags & kVstPinIsStereo) != 0;
  27380. return true;
  27381. }
  27382. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27383. {
  27384. if (index >= 0 && index < getNumOutputChannels())
  27385. {
  27386. VstPinProperties pinProps;
  27387. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27388. return String (pinProps.label, sizeof (pinProps.label));
  27389. }
  27390. return String::empty;
  27391. }
  27392. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27393. {
  27394. if (index < 0 || index >= getNumOutputChannels())
  27395. return false;
  27396. VstPinProperties pinProps;
  27397. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27398. return (pinProps.flags & kVstPinIsStereo) != 0;
  27399. return true;
  27400. }
  27401. void VSTPluginInstance::setPower (const bool on)
  27402. {
  27403. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27404. isPowerOn = on;
  27405. }
  27406. const int defaultMaxSizeMB = 64;
  27407. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27408. {
  27409. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27410. }
  27411. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27412. {
  27413. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27414. }
  27415. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27416. {
  27417. loadFromFXBFile (data, sizeInBytes);
  27418. }
  27419. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27420. {
  27421. loadFromFXBFile (data, sizeInBytes);
  27422. }
  27423. VSTPluginFormat::VSTPluginFormat()
  27424. {
  27425. }
  27426. VSTPluginFormat::~VSTPluginFormat()
  27427. {
  27428. }
  27429. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27430. const String& fileOrIdentifier)
  27431. {
  27432. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27433. return;
  27434. PluginDescription desc;
  27435. desc.fileOrIdentifier = fileOrIdentifier;
  27436. desc.uid = 0;
  27437. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27438. if (instance == 0)
  27439. return;
  27440. try
  27441. {
  27442. #if JUCE_MAC
  27443. if (instance->module->resFileId != 0)
  27444. UseResFile (instance->module->resFileId);
  27445. #endif
  27446. instance->fillInPluginDescription (desc);
  27447. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27448. if (category != kPlugCategShell)
  27449. {
  27450. // Normal plugin...
  27451. results.add (new PluginDescription (desc));
  27452. ++insideVSTCallback;
  27453. instance->dispatch (effOpen, 0, 0, 0, 0);
  27454. --insideVSTCallback;
  27455. }
  27456. else
  27457. {
  27458. // It's a shell plugin, so iterate all the subtypes...
  27459. char shellEffectName [64];
  27460. for (;;)
  27461. {
  27462. zerostruct (shellEffectName);
  27463. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27464. if (uid == 0)
  27465. {
  27466. break;
  27467. }
  27468. else
  27469. {
  27470. desc.uid = uid;
  27471. desc.name = shellEffectName;
  27472. bool alreadyThere = false;
  27473. for (int i = results.size(); --i >= 0;)
  27474. {
  27475. PluginDescription* const d = results.getUnchecked(i);
  27476. if (d->isDuplicateOf (desc))
  27477. {
  27478. alreadyThere = true;
  27479. break;
  27480. }
  27481. }
  27482. if (! alreadyThere)
  27483. results.add (new PluginDescription (desc));
  27484. }
  27485. }
  27486. }
  27487. }
  27488. catch (...)
  27489. {
  27490. // crashed while loading...
  27491. }
  27492. }
  27493. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27494. {
  27495. ScopedPointer <VSTPluginInstance> result;
  27496. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27497. {
  27498. File file (desc.fileOrIdentifier);
  27499. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27500. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27501. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27502. if (module != 0)
  27503. {
  27504. shellUIDToCreate = desc.uid;
  27505. result = new VSTPluginInstance (module);
  27506. if (result->effect != 0)
  27507. {
  27508. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27509. result->initialise();
  27510. }
  27511. else
  27512. {
  27513. result = 0;
  27514. }
  27515. }
  27516. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27517. }
  27518. return result.release();
  27519. }
  27520. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27521. {
  27522. const File f (fileOrIdentifier);
  27523. #if JUCE_MAC
  27524. if (f.isDirectory() && f.hasFileExtension (".vst"))
  27525. return true;
  27526. #if JUCE_PPC
  27527. FSRef fileRef;
  27528. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27529. {
  27530. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27531. if (resFileId != -1)
  27532. {
  27533. const int numEffects = Count1Resources ('aEff');
  27534. CloseResFile (resFileId);
  27535. if (numEffects > 0)
  27536. return true;
  27537. }
  27538. }
  27539. #endif
  27540. return false;
  27541. #elif JUCE_WIN32
  27542. return f.existsAsFile()
  27543. && f.hasFileExtension (".dll");
  27544. #elif JUCE_LINUX
  27545. return f.existsAsFile()
  27546. && f.hasFileExtension (".so");
  27547. #endif
  27548. }
  27549. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27550. {
  27551. return fileOrIdentifier;
  27552. }
  27553. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27554. {
  27555. return File (desc.fileOrIdentifier).exists();
  27556. }
  27557. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27558. {
  27559. StringArray results;
  27560. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27561. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27562. return results;
  27563. }
  27564. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27565. {
  27566. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27567. // .component or .vst directories.
  27568. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27569. while (iter.next())
  27570. {
  27571. const File f (iter.getFile());
  27572. bool isPlugin = false;
  27573. if (fileMightContainThisPluginType (f.getFullPathName()))
  27574. {
  27575. isPlugin = true;
  27576. results.add (f.getFullPathName());
  27577. }
  27578. if (recursive && (! isPlugin) && f.isDirectory())
  27579. recursiveFileSearch (results, f, true);
  27580. }
  27581. }
  27582. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27583. {
  27584. #if JUCE_MAC
  27585. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27586. #elif JUCE_WIN32
  27587. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27588. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27589. #elif JUCE_LINUX
  27590. return FileSearchPath ("/usr/lib/vst");
  27591. #endif
  27592. }
  27593. END_JUCE_NAMESPACE
  27594. #endif
  27595. #undef log
  27596. #endif
  27597. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27598. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27599. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27600. BEGIN_JUCE_NAMESPACE
  27601. AudioProcessor::AudioProcessor()
  27602. : playHead (0),
  27603. activeEditor (0),
  27604. sampleRate (0),
  27605. blockSize (0),
  27606. numInputChannels (0),
  27607. numOutputChannels (0),
  27608. latencySamples (0),
  27609. suspended (false),
  27610. nonRealtime (false)
  27611. {
  27612. }
  27613. AudioProcessor::~AudioProcessor()
  27614. {
  27615. // ooh, nasty - the editor should have been deleted before the filter
  27616. // that it refers to is deleted..
  27617. jassert (activeEditor == 0);
  27618. #ifdef JUCE_DEBUG
  27619. // This will fail if you've called beginParameterChangeGesture() for one
  27620. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27621. jassert (changingParams.countNumberOfSetBits() == 0);
  27622. #endif
  27623. }
  27624. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27625. {
  27626. playHead = newPlayHead;
  27627. }
  27628. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27629. {
  27630. const ScopedLock sl (listenerLock);
  27631. listeners.addIfNotAlreadyThere (newListener);
  27632. }
  27633. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27634. {
  27635. const ScopedLock sl (listenerLock);
  27636. listeners.removeValue (listenerToRemove);
  27637. }
  27638. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27639. const int numOuts,
  27640. const double sampleRate_,
  27641. const int blockSize_) throw()
  27642. {
  27643. numInputChannels = numIns;
  27644. numOutputChannels = numOuts;
  27645. sampleRate = sampleRate_;
  27646. blockSize = blockSize_;
  27647. }
  27648. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27649. {
  27650. nonRealtime = nonRealtime_;
  27651. }
  27652. void AudioProcessor::setLatencySamples (const int newLatency)
  27653. {
  27654. if (latencySamples != newLatency)
  27655. {
  27656. latencySamples = newLatency;
  27657. updateHostDisplay();
  27658. }
  27659. }
  27660. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27661. const float newValue)
  27662. {
  27663. setParameter (parameterIndex, newValue);
  27664. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27665. }
  27666. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27667. {
  27668. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27669. for (int i = listeners.size(); --i >= 0;)
  27670. {
  27671. AudioProcessorListener* l;
  27672. {
  27673. const ScopedLock sl (listenerLock);
  27674. l = (AudioProcessorListener*) listeners [i];
  27675. }
  27676. if (l != 0)
  27677. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27678. }
  27679. }
  27680. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27681. {
  27682. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27683. #ifdef JUCE_DEBUG
  27684. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27685. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27686. jassert (! changingParams [parameterIndex]);
  27687. changingParams.setBit (parameterIndex);
  27688. #endif
  27689. for (int i = listeners.size(); --i >= 0;)
  27690. {
  27691. AudioProcessorListener* l;
  27692. {
  27693. const ScopedLock sl (listenerLock);
  27694. l = (AudioProcessorListener*) listeners [i];
  27695. }
  27696. if (l != 0)
  27697. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27698. }
  27699. }
  27700. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27701. {
  27702. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27703. #ifdef JUCE_DEBUG
  27704. // This means you've called endParameterChangeGesture without having previously called
  27705. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27706. // calls matched correctly.
  27707. jassert (changingParams [parameterIndex]);
  27708. changingParams.clearBit (parameterIndex);
  27709. #endif
  27710. for (int i = listeners.size(); --i >= 0;)
  27711. {
  27712. AudioProcessorListener* l;
  27713. {
  27714. const ScopedLock sl (listenerLock);
  27715. l = (AudioProcessorListener*) listeners [i];
  27716. }
  27717. if (l != 0)
  27718. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27719. }
  27720. }
  27721. void AudioProcessor::updateHostDisplay()
  27722. {
  27723. for (int i = listeners.size(); --i >= 0;)
  27724. {
  27725. AudioProcessorListener* l;
  27726. {
  27727. const ScopedLock sl (listenerLock);
  27728. l = (AudioProcessorListener*) listeners [i];
  27729. }
  27730. if (l != 0)
  27731. l->audioProcessorChanged (this);
  27732. }
  27733. }
  27734. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27735. {
  27736. return true;
  27737. }
  27738. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27739. {
  27740. return false;
  27741. }
  27742. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27743. {
  27744. const ScopedLock sl (callbackLock);
  27745. suspended = shouldBeSuspended;
  27746. }
  27747. void AudioProcessor::reset()
  27748. {
  27749. }
  27750. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27751. {
  27752. const ScopedLock sl (callbackLock);
  27753. jassert (activeEditor == editor);
  27754. if (activeEditor == editor)
  27755. activeEditor = 0;
  27756. }
  27757. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27758. {
  27759. if (activeEditor != 0)
  27760. return activeEditor;
  27761. AudioProcessorEditor* const ed = createEditor();
  27762. if (ed != 0)
  27763. {
  27764. // you must give your editor comp a size before returning it..
  27765. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27766. const ScopedLock sl (callbackLock);
  27767. activeEditor = ed;
  27768. }
  27769. return ed;
  27770. }
  27771. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27772. {
  27773. getStateInformation (destData);
  27774. }
  27775. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27776. {
  27777. setStateInformation (data, sizeInBytes);
  27778. }
  27779. // magic number to identify memory blocks that we've stored as XML
  27780. const uint32 magicXmlNumber = 0x21324356;
  27781. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27782. JUCE_NAMESPACE::MemoryBlock& destData)
  27783. {
  27784. const String xmlString (xml.createDocument (String::empty, true, false));
  27785. const int stringLength = xmlString.getNumBytesAsUTF8();
  27786. destData.setSize (stringLength + 10);
  27787. char* const d = (char*) destData.getData();
  27788. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27789. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27790. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27791. }
  27792. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27793. const int sizeInBytes)
  27794. {
  27795. if (sizeInBytes > 8
  27796. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27797. {
  27798. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27799. if (stringLength > 0)
  27800. {
  27801. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27802. jmin ((sizeInBytes - 8), stringLength)));
  27803. return doc.getDocumentElement();
  27804. }
  27805. }
  27806. return 0;
  27807. }
  27808. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27809. {
  27810. }
  27811. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27812. {
  27813. }
  27814. bool AudioPlayHead::CurrentPositionInfo::operator== (const CurrentPositionInfo& other) const throw()
  27815. {
  27816. return timeInSeconds == other.timeInSeconds
  27817. && ppqPosition == other.ppqPosition
  27818. && editOriginTime == other.editOriginTime
  27819. && ppqPositionOfLastBarStart == other.ppqPositionOfLastBarStart
  27820. && frameRate == other.frameRate
  27821. && isPlaying == other.isPlaying
  27822. && isRecording == other.isRecording
  27823. && bpm == other.bpm
  27824. && timeSigNumerator == other.timeSigNumerator
  27825. && timeSigDenominator == other.timeSigDenominator;
  27826. }
  27827. bool AudioPlayHead::CurrentPositionInfo::operator!= (const CurrentPositionInfo& other) const throw()
  27828. {
  27829. return ! operator== (other);
  27830. }
  27831. void AudioPlayHead::CurrentPositionInfo::resetToDefault()
  27832. {
  27833. zerostruct (*this);
  27834. timeSigNumerator = 4;
  27835. timeSigDenominator = 4;
  27836. bpm = 120;
  27837. }
  27838. END_JUCE_NAMESPACE
  27839. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27840. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27841. BEGIN_JUCE_NAMESPACE
  27842. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27843. : owner (owner_)
  27844. {
  27845. // the filter must be valid..
  27846. jassert (owner != 0);
  27847. }
  27848. AudioProcessorEditor::~AudioProcessorEditor()
  27849. {
  27850. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27851. // filter for some reason..
  27852. jassert (owner->getActiveEditor() != this);
  27853. }
  27854. END_JUCE_NAMESPACE
  27855. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27856. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27857. BEGIN_JUCE_NAMESPACE
  27858. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27859. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27860. : id (id_),
  27861. processor (processor_),
  27862. isPrepared (false)
  27863. {
  27864. jassert (processor_ != 0);
  27865. }
  27866. AudioProcessorGraph::Node::~Node()
  27867. {
  27868. delete processor;
  27869. }
  27870. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27871. AudioProcessorGraph* const graph)
  27872. {
  27873. if (! isPrepared)
  27874. {
  27875. isPrepared = true;
  27876. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27877. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  27878. if (ioProc != 0)
  27879. ioProc->setParentGraph (graph);
  27880. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  27881. processor->getNumOutputChannels(),
  27882. sampleRate, blockSize);
  27883. processor->prepareToPlay (sampleRate, blockSize);
  27884. }
  27885. }
  27886. void AudioProcessorGraph::Node::unprepare()
  27887. {
  27888. if (isPrepared)
  27889. {
  27890. isPrepared = false;
  27891. processor->releaseResources();
  27892. }
  27893. }
  27894. AudioProcessorGraph::AudioProcessorGraph()
  27895. : lastNodeId (0),
  27896. renderingBuffers (1, 1),
  27897. currentAudioOutputBuffer (1, 1)
  27898. {
  27899. }
  27900. AudioProcessorGraph::~AudioProcessorGraph()
  27901. {
  27902. clearRenderingSequence();
  27903. clear();
  27904. }
  27905. const String AudioProcessorGraph::getName() const
  27906. {
  27907. return "Audio Graph";
  27908. }
  27909. void AudioProcessorGraph::clear()
  27910. {
  27911. nodes.clear();
  27912. connections.clear();
  27913. triggerAsyncUpdate();
  27914. }
  27915. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  27916. {
  27917. for (int i = nodes.size(); --i >= 0;)
  27918. if (nodes.getUnchecked(i)->id == nodeId)
  27919. return nodes.getUnchecked(i);
  27920. return 0;
  27921. }
  27922. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  27923. uint32 nodeId)
  27924. {
  27925. if (newProcessor == 0)
  27926. {
  27927. jassertfalse
  27928. return 0;
  27929. }
  27930. if (nodeId == 0)
  27931. {
  27932. nodeId = ++lastNodeId;
  27933. }
  27934. else
  27935. {
  27936. // you can't add a node with an id that already exists in the graph..
  27937. jassert (getNodeForId (nodeId) == 0);
  27938. removeNode (nodeId);
  27939. }
  27940. lastNodeId = nodeId;
  27941. Node* const n = new Node (nodeId, newProcessor);
  27942. nodes.add (n);
  27943. triggerAsyncUpdate();
  27944. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27945. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  27946. if (ioProc != 0)
  27947. ioProc->setParentGraph (this);
  27948. return n;
  27949. }
  27950. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  27951. {
  27952. disconnectNode (nodeId);
  27953. for (int i = nodes.size(); --i >= 0;)
  27954. {
  27955. if (nodes.getUnchecked(i)->id == nodeId)
  27956. {
  27957. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27958. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  27959. if (ioProc != 0)
  27960. ioProc->setParentGraph (0);
  27961. nodes.remove (i);
  27962. triggerAsyncUpdate();
  27963. return true;
  27964. }
  27965. }
  27966. return false;
  27967. }
  27968. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  27969. const int sourceChannelIndex,
  27970. const uint32 destNodeId,
  27971. const int destChannelIndex) const
  27972. {
  27973. for (int i = connections.size(); --i >= 0;)
  27974. {
  27975. const Connection* const c = connections.getUnchecked(i);
  27976. if (c->sourceNodeId == sourceNodeId
  27977. && c->destNodeId == destNodeId
  27978. && c->sourceChannelIndex == sourceChannelIndex
  27979. && c->destChannelIndex == destChannelIndex)
  27980. {
  27981. return c;
  27982. }
  27983. }
  27984. return 0;
  27985. }
  27986. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  27987. const uint32 possibleDestNodeId) const
  27988. {
  27989. for (int i = connections.size(); --i >= 0;)
  27990. {
  27991. const Connection* const c = connections.getUnchecked(i);
  27992. if (c->sourceNodeId == possibleSourceNodeId
  27993. && c->destNodeId == possibleDestNodeId)
  27994. {
  27995. return true;
  27996. }
  27997. }
  27998. return false;
  27999. }
  28000. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28001. const int sourceChannelIndex,
  28002. const uint32 destNodeId,
  28003. const int destChannelIndex) const
  28004. {
  28005. if (sourceChannelIndex < 0
  28006. || destChannelIndex < 0
  28007. || sourceNodeId == destNodeId
  28008. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28009. return false;
  28010. const Node* const source = getNodeForId (sourceNodeId);
  28011. if (source == 0
  28012. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28013. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28014. return false;
  28015. const Node* const dest = getNodeForId (destNodeId);
  28016. if (dest == 0
  28017. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28018. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28019. return false;
  28020. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28021. destNodeId, destChannelIndex) == 0;
  28022. }
  28023. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28024. const int sourceChannelIndex,
  28025. const uint32 destNodeId,
  28026. const int destChannelIndex)
  28027. {
  28028. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28029. return false;
  28030. Connection* const c = new Connection();
  28031. c->sourceNodeId = sourceNodeId;
  28032. c->sourceChannelIndex = sourceChannelIndex;
  28033. c->destNodeId = destNodeId;
  28034. c->destChannelIndex = destChannelIndex;
  28035. connections.add (c);
  28036. triggerAsyncUpdate();
  28037. return true;
  28038. }
  28039. void AudioProcessorGraph::removeConnection (const int index)
  28040. {
  28041. connections.remove (index);
  28042. triggerAsyncUpdate();
  28043. }
  28044. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28045. const uint32 destNodeId, const int destChannelIndex)
  28046. {
  28047. bool doneAnything = false;
  28048. for (int i = connections.size(); --i >= 0;)
  28049. {
  28050. const Connection* const c = connections.getUnchecked(i);
  28051. if (c->sourceNodeId == sourceNodeId
  28052. && c->destNodeId == destNodeId
  28053. && c->sourceChannelIndex == sourceChannelIndex
  28054. && c->destChannelIndex == destChannelIndex)
  28055. {
  28056. removeConnection (i);
  28057. doneAnything = true;
  28058. triggerAsyncUpdate();
  28059. }
  28060. }
  28061. return doneAnything;
  28062. }
  28063. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28064. {
  28065. bool doneAnything = false;
  28066. for (int i = connections.size(); --i >= 0;)
  28067. {
  28068. const Connection* const c = connections.getUnchecked(i);
  28069. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28070. {
  28071. removeConnection (i);
  28072. doneAnything = true;
  28073. triggerAsyncUpdate();
  28074. }
  28075. }
  28076. return doneAnything;
  28077. }
  28078. bool AudioProcessorGraph::removeIllegalConnections()
  28079. {
  28080. bool doneAnything = false;
  28081. for (int i = connections.size(); --i >= 0;)
  28082. {
  28083. const Connection* const c = connections.getUnchecked(i);
  28084. const Node* const source = getNodeForId (c->sourceNodeId);
  28085. const Node* const dest = getNodeForId (c->destNodeId);
  28086. if (source == 0 || dest == 0
  28087. || (c->sourceChannelIndex != midiChannelIndex
  28088. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28089. || (c->sourceChannelIndex == midiChannelIndex
  28090. && ! source->processor->producesMidi())
  28091. || (c->destChannelIndex != midiChannelIndex
  28092. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28093. || (c->destChannelIndex == midiChannelIndex
  28094. && ! dest->processor->acceptsMidi()))
  28095. {
  28096. removeConnection (i);
  28097. doneAnything = true;
  28098. triggerAsyncUpdate();
  28099. }
  28100. }
  28101. return doneAnything;
  28102. }
  28103. namespace GraphRenderingOps
  28104. {
  28105. class AudioGraphRenderingOp
  28106. {
  28107. public:
  28108. AudioGraphRenderingOp() {}
  28109. virtual ~AudioGraphRenderingOp() {}
  28110. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28111. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28112. const int numSamples) = 0;
  28113. juce_UseDebuggingNewOperator
  28114. };
  28115. class ClearChannelOp : public AudioGraphRenderingOp
  28116. {
  28117. public:
  28118. ClearChannelOp (const int channelNum_)
  28119. : channelNum (channelNum_)
  28120. {}
  28121. ~ClearChannelOp() {}
  28122. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28123. {
  28124. sharedBufferChans.clear (channelNum, 0, numSamples);
  28125. }
  28126. private:
  28127. const int channelNum;
  28128. ClearChannelOp (const ClearChannelOp&);
  28129. ClearChannelOp& operator= (const ClearChannelOp&);
  28130. };
  28131. class CopyChannelOp : public AudioGraphRenderingOp
  28132. {
  28133. public:
  28134. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28135. : srcChannelNum (srcChannelNum_),
  28136. dstChannelNum (dstChannelNum_)
  28137. {}
  28138. ~CopyChannelOp() {}
  28139. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28140. {
  28141. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28142. }
  28143. private:
  28144. const int srcChannelNum, dstChannelNum;
  28145. CopyChannelOp (const CopyChannelOp&);
  28146. CopyChannelOp& operator= (const CopyChannelOp&);
  28147. };
  28148. class AddChannelOp : public AudioGraphRenderingOp
  28149. {
  28150. public:
  28151. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28152. : srcChannelNum (srcChannelNum_),
  28153. dstChannelNum (dstChannelNum_)
  28154. {}
  28155. ~AddChannelOp() {}
  28156. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28157. {
  28158. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28159. }
  28160. private:
  28161. const int srcChannelNum, dstChannelNum;
  28162. AddChannelOp (const AddChannelOp&);
  28163. AddChannelOp& operator= (const AddChannelOp&);
  28164. };
  28165. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28166. {
  28167. public:
  28168. ClearMidiBufferOp (const int bufferNum_)
  28169. : bufferNum (bufferNum_)
  28170. {}
  28171. ~ClearMidiBufferOp() {}
  28172. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28173. {
  28174. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28175. }
  28176. private:
  28177. const int bufferNum;
  28178. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28179. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28180. };
  28181. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28182. {
  28183. public:
  28184. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28185. : srcBufferNum (srcBufferNum_),
  28186. dstBufferNum (dstBufferNum_)
  28187. {}
  28188. ~CopyMidiBufferOp() {}
  28189. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28190. {
  28191. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28192. }
  28193. private:
  28194. const int srcBufferNum, dstBufferNum;
  28195. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28196. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28197. };
  28198. class AddMidiBufferOp : public AudioGraphRenderingOp
  28199. {
  28200. public:
  28201. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28202. : srcBufferNum (srcBufferNum_),
  28203. dstBufferNum (dstBufferNum_)
  28204. {}
  28205. ~AddMidiBufferOp() {}
  28206. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28207. {
  28208. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28209. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28210. }
  28211. private:
  28212. const int srcBufferNum, dstBufferNum;
  28213. AddMidiBufferOp (const AddMidiBufferOp&);
  28214. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28215. };
  28216. class ProcessBufferOp : public AudioGraphRenderingOp
  28217. {
  28218. public:
  28219. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28220. const Array <int>& audioChannelsToUse_,
  28221. const int totalChans_,
  28222. const int midiBufferToUse_)
  28223. : node (node_),
  28224. processor (node_->processor),
  28225. audioChannelsToUse (audioChannelsToUse_),
  28226. totalChans (jmax (1, totalChans_)),
  28227. midiBufferToUse (midiBufferToUse_)
  28228. {
  28229. channels.calloc (totalChans);
  28230. while (audioChannelsToUse.size() < totalChans)
  28231. audioChannelsToUse.add (0);
  28232. }
  28233. ~ProcessBufferOp()
  28234. {
  28235. }
  28236. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28237. {
  28238. for (int i = totalChans; --i >= 0;)
  28239. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28240. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28241. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28242. }
  28243. const AudioProcessorGraph::Node::Ptr node;
  28244. AudioProcessor* const processor;
  28245. private:
  28246. Array <int> audioChannelsToUse;
  28247. HeapBlock <float*> channels;
  28248. int totalChans;
  28249. int midiBufferToUse;
  28250. ProcessBufferOp (const ProcessBufferOp&);
  28251. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28252. };
  28253. class RenderingOpSequenceCalculator
  28254. {
  28255. public:
  28256. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28257. const VoidArray& orderedNodes_,
  28258. VoidArray& renderingOps)
  28259. : graph (graph_),
  28260. orderedNodes (orderedNodes_)
  28261. {
  28262. nodeIds.add (-2); // first buffer is read-only zeros
  28263. channels.add (0);
  28264. midiNodeIds.add (-2);
  28265. for (int i = 0; i < orderedNodes.size(); ++i)
  28266. {
  28267. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28268. renderingOps, i);
  28269. markAnyUnusedBuffersAsFree (i);
  28270. }
  28271. }
  28272. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28273. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28274. juce_UseDebuggingNewOperator
  28275. private:
  28276. AudioProcessorGraph& graph;
  28277. const VoidArray& orderedNodes;
  28278. Array <int> nodeIds, channels, midiNodeIds;
  28279. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28280. VoidArray& renderingOps,
  28281. const int ourRenderingIndex)
  28282. {
  28283. const int numIns = node->processor->getNumInputChannels();
  28284. const int numOuts = node->processor->getNumOutputChannels();
  28285. const int totalChans = jmax (numIns, numOuts);
  28286. Array <int> audioChannelsToUse;
  28287. int midiBufferToUse = -1;
  28288. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28289. {
  28290. // get a list of all the inputs to this node
  28291. Array <int> sourceNodes, sourceOutputChans;
  28292. for (int i = graph.getNumConnections(); --i >= 0;)
  28293. {
  28294. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28295. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28296. {
  28297. sourceNodes.add (c->sourceNodeId);
  28298. sourceOutputChans.add (c->sourceChannelIndex);
  28299. }
  28300. }
  28301. int bufIndex = -1;
  28302. if (sourceNodes.size() == 0)
  28303. {
  28304. // unconnected input channel
  28305. if (inputChan >= numOuts)
  28306. {
  28307. bufIndex = getReadOnlyEmptyBuffer();
  28308. jassert (bufIndex >= 0);
  28309. }
  28310. else
  28311. {
  28312. bufIndex = getFreeBuffer (false);
  28313. renderingOps.add (new ClearChannelOp (bufIndex));
  28314. }
  28315. }
  28316. else if (sourceNodes.size() == 1)
  28317. {
  28318. // channel with a straightforward single input..
  28319. const int srcNode = sourceNodes.getUnchecked(0);
  28320. const int srcChan = sourceOutputChans.getUnchecked(0);
  28321. bufIndex = getBufferContaining (srcNode, srcChan);
  28322. if (bufIndex < 0)
  28323. {
  28324. // if not found, this is probably a feedback loop
  28325. bufIndex = getReadOnlyEmptyBuffer();
  28326. jassert (bufIndex >= 0);
  28327. }
  28328. if (inputChan < numOuts
  28329. && isBufferNeededLater (ourRenderingIndex,
  28330. inputChan,
  28331. srcNode, srcChan))
  28332. {
  28333. // can't mess up this channel because it's needed later by another node, so we
  28334. // need to use a copy of it..
  28335. const int newFreeBuffer = getFreeBuffer (false);
  28336. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28337. bufIndex = newFreeBuffer;
  28338. }
  28339. }
  28340. else
  28341. {
  28342. // channel with a mix of several inputs..
  28343. // try to find a re-usable channel from our inputs..
  28344. int reusableInputIndex = -1;
  28345. for (int i = 0; i < sourceNodes.size(); ++i)
  28346. {
  28347. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28348. sourceOutputChans.getUnchecked(i));
  28349. if (sourceBufIndex >= 0
  28350. && ! isBufferNeededLater (ourRenderingIndex,
  28351. inputChan,
  28352. sourceNodes.getUnchecked(i),
  28353. sourceOutputChans.getUnchecked(i)))
  28354. {
  28355. // we've found one of our input chans that can be re-used..
  28356. reusableInputIndex = i;
  28357. bufIndex = sourceBufIndex;
  28358. break;
  28359. }
  28360. }
  28361. if (reusableInputIndex < 0)
  28362. {
  28363. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28364. bufIndex = getFreeBuffer (false);
  28365. jassert (bufIndex != 0);
  28366. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28367. sourceOutputChans.getUnchecked (0));
  28368. if (srcIndex < 0)
  28369. {
  28370. // if not found, this is probably a feedback loop
  28371. renderingOps.add (new ClearChannelOp (bufIndex));
  28372. }
  28373. else
  28374. {
  28375. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28376. }
  28377. reusableInputIndex = 0;
  28378. }
  28379. for (int j = 0; j < sourceNodes.size(); ++j)
  28380. {
  28381. if (j != reusableInputIndex)
  28382. {
  28383. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28384. sourceOutputChans.getUnchecked(j));
  28385. if (srcIndex >= 0)
  28386. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28387. }
  28388. }
  28389. }
  28390. jassert (bufIndex >= 0);
  28391. audioChannelsToUse.add (bufIndex);
  28392. if (inputChan < numOuts)
  28393. markBufferAsContaining (bufIndex, node->id, inputChan);
  28394. }
  28395. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28396. {
  28397. const int bufIndex = getFreeBuffer (false);
  28398. jassert (bufIndex != 0);
  28399. audioChannelsToUse.add (bufIndex);
  28400. markBufferAsContaining (bufIndex, node->id, outputChan);
  28401. }
  28402. // Now the same thing for midi..
  28403. Array <int> midiSourceNodes;
  28404. for (int i = graph.getNumConnections(); --i >= 0;)
  28405. {
  28406. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28407. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28408. midiSourceNodes.add (c->sourceNodeId);
  28409. }
  28410. if (midiSourceNodes.size() == 0)
  28411. {
  28412. // No midi inputs..
  28413. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28414. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28415. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28416. }
  28417. else if (midiSourceNodes.size() == 1)
  28418. {
  28419. // One midi input..
  28420. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28421. AudioProcessorGraph::midiChannelIndex);
  28422. if (midiBufferToUse >= 0)
  28423. {
  28424. if (isBufferNeededLater (ourRenderingIndex,
  28425. AudioProcessorGraph::midiChannelIndex,
  28426. midiSourceNodes.getUnchecked(0),
  28427. AudioProcessorGraph::midiChannelIndex))
  28428. {
  28429. // can't mess up this channel because it's needed later by another node, so we
  28430. // need to use a copy of it..
  28431. const int newFreeBuffer = getFreeBuffer (true);
  28432. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28433. midiBufferToUse = newFreeBuffer;
  28434. }
  28435. }
  28436. else
  28437. {
  28438. // probably a feedback loop, so just use an empty one..
  28439. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28440. }
  28441. }
  28442. else
  28443. {
  28444. // More than one midi input being mixed..
  28445. int reusableInputIndex = -1;
  28446. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28447. {
  28448. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28449. AudioProcessorGraph::midiChannelIndex);
  28450. if (sourceBufIndex >= 0
  28451. && ! isBufferNeededLater (ourRenderingIndex,
  28452. AudioProcessorGraph::midiChannelIndex,
  28453. midiSourceNodes.getUnchecked(i),
  28454. AudioProcessorGraph::midiChannelIndex))
  28455. {
  28456. // we've found one of our input buffers that can be re-used..
  28457. reusableInputIndex = i;
  28458. midiBufferToUse = sourceBufIndex;
  28459. break;
  28460. }
  28461. }
  28462. if (reusableInputIndex < 0)
  28463. {
  28464. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28465. midiBufferToUse = getFreeBuffer (true);
  28466. jassert (midiBufferToUse >= 0);
  28467. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28468. AudioProcessorGraph::midiChannelIndex);
  28469. if (srcIndex >= 0)
  28470. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28471. else
  28472. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28473. reusableInputIndex = 0;
  28474. }
  28475. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28476. {
  28477. if (j != reusableInputIndex)
  28478. {
  28479. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28480. AudioProcessorGraph::midiChannelIndex);
  28481. if (srcIndex >= 0)
  28482. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28483. }
  28484. }
  28485. }
  28486. if (node->processor->producesMidi())
  28487. markBufferAsContaining (midiBufferToUse, node->id,
  28488. AudioProcessorGraph::midiChannelIndex);
  28489. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28490. totalChans, midiBufferToUse));
  28491. }
  28492. int getFreeBuffer (const bool forMidi)
  28493. {
  28494. if (forMidi)
  28495. {
  28496. for (int i = 1; i < midiNodeIds.size(); ++i)
  28497. if (midiNodeIds.getUnchecked(i) < 0)
  28498. return i;
  28499. midiNodeIds.add (-1);
  28500. return midiNodeIds.size() - 1;
  28501. }
  28502. else
  28503. {
  28504. for (int i = 1; i < nodeIds.size(); ++i)
  28505. if (nodeIds.getUnchecked(i) < 0)
  28506. return i;
  28507. nodeIds.add (-1);
  28508. channels.add (0);
  28509. return nodeIds.size() - 1;
  28510. }
  28511. }
  28512. int getReadOnlyEmptyBuffer() const
  28513. {
  28514. return 0;
  28515. }
  28516. int getBufferContaining (const int nodeId, const int outputChannel) const
  28517. {
  28518. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28519. {
  28520. for (int i = midiNodeIds.size(); --i >= 0;)
  28521. if (midiNodeIds.getUnchecked(i) == nodeId)
  28522. return i;
  28523. }
  28524. else
  28525. {
  28526. for (int i = nodeIds.size(); --i >= 0;)
  28527. if (nodeIds.getUnchecked(i) == nodeId
  28528. && channels.getUnchecked(i) == outputChannel)
  28529. return i;
  28530. }
  28531. return -1;
  28532. }
  28533. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28534. {
  28535. int i;
  28536. for (i = 0; i < nodeIds.size(); ++i)
  28537. {
  28538. if (nodeIds.getUnchecked(i) >= 0
  28539. && ! isBufferNeededLater (stepIndex, -1,
  28540. nodeIds.getUnchecked(i),
  28541. channels.getUnchecked(i)))
  28542. {
  28543. nodeIds.set (i, -1);
  28544. }
  28545. }
  28546. for (i = 0; i < midiNodeIds.size(); ++i)
  28547. {
  28548. if (midiNodeIds.getUnchecked(i) >= 0
  28549. && ! isBufferNeededLater (stepIndex, -1,
  28550. midiNodeIds.getUnchecked(i),
  28551. AudioProcessorGraph::midiChannelIndex))
  28552. {
  28553. midiNodeIds.set (i, -1);
  28554. }
  28555. }
  28556. }
  28557. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28558. int inputChannelOfIndexToIgnore,
  28559. const int nodeId,
  28560. const int outputChanIndex) const
  28561. {
  28562. while (stepIndexToSearchFrom < orderedNodes.size())
  28563. {
  28564. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28565. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28566. {
  28567. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28568. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28569. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28570. return true;
  28571. }
  28572. else
  28573. {
  28574. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28575. if (i != inputChannelOfIndexToIgnore
  28576. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28577. node->id, i) != 0)
  28578. return true;
  28579. }
  28580. inputChannelOfIndexToIgnore = -1;
  28581. ++stepIndexToSearchFrom;
  28582. }
  28583. return false;
  28584. }
  28585. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28586. {
  28587. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28588. {
  28589. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28590. midiNodeIds.set (bufferNum, nodeId);
  28591. }
  28592. else
  28593. {
  28594. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28595. nodeIds.set (bufferNum, nodeId);
  28596. channels.set (bufferNum, outputIndex);
  28597. }
  28598. }
  28599. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28600. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28601. };
  28602. }
  28603. void AudioProcessorGraph::clearRenderingSequence()
  28604. {
  28605. const ScopedLock sl (renderLock);
  28606. for (int i = renderingOps.size(); --i >= 0;)
  28607. {
  28608. GraphRenderingOps::AudioGraphRenderingOp* const r
  28609. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28610. renderingOps.remove (i);
  28611. delete r;
  28612. }
  28613. }
  28614. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28615. const uint32 possibleDestinationId,
  28616. const int recursionCheck) const
  28617. {
  28618. if (recursionCheck > 0)
  28619. {
  28620. for (int i = connections.size(); --i >= 0;)
  28621. {
  28622. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28623. if (c->destNodeId == possibleDestinationId
  28624. && (c->sourceNodeId == possibleInputId
  28625. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28626. return true;
  28627. }
  28628. }
  28629. return false;
  28630. }
  28631. void AudioProcessorGraph::buildRenderingSequence()
  28632. {
  28633. VoidArray newRenderingOps;
  28634. int numRenderingBuffersNeeded = 2;
  28635. int numMidiBuffersNeeded = 1;
  28636. {
  28637. MessageManagerLock mml;
  28638. VoidArray orderedNodes;
  28639. int i;
  28640. for (i = 0; i < nodes.size(); ++i)
  28641. {
  28642. Node* const node = nodes.getUnchecked(i);
  28643. node->prepare (getSampleRate(), getBlockSize(), this);
  28644. int j = 0;
  28645. for (; j < orderedNodes.size(); ++j)
  28646. if (isAnInputTo (node->id,
  28647. ((Node*) orderedNodes.getUnchecked (j))->id,
  28648. nodes.size() + 1))
  28649. break;
  28650. orderedNodes.insert (j, node);
  28651. }
  28652. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28653. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28654. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28655. }
  28656. VoidArray oldRenderingOps (renderingOps);
  28657. {
  28658. // swap over to the new rendering sequence..
  28659. const ScopedLock sl (renderLock);
  28660. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28661. renderingBuffers.clear();
  28662. for (int i = midiBuffers.size(); --i >= 0;)
  28663. midiBuffers.getUnchecked(i)->clear();
  28664. while (midiBuffers.size() < numMidiBuffersNeeded)
  28665. midiBuffers.add (new MidiBuffer());
  28666. renderingOps = newRenderingOps;
  28667. }
  28668. for (int i = oldRenderingOps.size(); --i >= 0;)
  28669. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28670. }
  28671. void AudioProcessorGraph::handleAsyncUpdate()
  28672. {
  28673. buildRenderingSequence();
  28674. }
  28675. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28676. {
  28677. currentAudioInputBuffer = 0;
  28678. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28679. currentMidiInputBuffer = 0;
  28680. currentMidiOutputBuffer.clear();
  28681. clearRenderingSequence();
  28682. buildRenderingSequence();
  28683. }
  28684. void AudioProcessorGraph::releaseResources()
  28685. {
  28686. for (int i = 0; i < nodes.size(); ++i)
  28687. nodes.getUnchecked(i)->unprepare();
  28688. renderingBuffers.setSize (1, 1);
  28689. midiBuffers.clear();
  28690. currentAudioInputBuffer = 0;
  28691. currentAudioOutputBuffer.setSize (1, 1);
  28692. currentMidiInputBuffer = 0;
  28693. currentMidiOutputBuffer.clear();
  28694. }
  28695. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28696. {
  28697. const int numSamples = buffer.getNumSamples();
  28698. const ScopedLock sl (renderLock);
  28699. currentAudioInputBuffer = &buffer;
  28700. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28701. currentAudioOutputBuffer.clear();
  28702. currentMidiInputBuffer = &midiMessages;
  28703. currentMidiOutputBuffer.clear();
  28704. int i;
  28705. for (i = 0; i < renderingOps.size(); ++i)
  28706. {
  28707. GraphRenderingOps::AudioGraphRenderingOp* const op
  28708. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28709. op->perform (renderingBuffers, midiBuffers, numSamples);
  28710. }
  28711. for (i = 0; i < buffer.getNumChannels(); ++i)
  28712. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28713. midiMessages.clear();
  28714. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28715. }
  28716. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28717. {
  28718. return "Input " + String (channelIndex + 1);
  28719. }
  28720. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28721. {
  28722. return "Output " + String (channelIndex + 1);
  28723. }
  28724. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28725. {
  28726. return true;
  28727. }
  28728. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28729. {
  28730. return true;
  28731. }
  28732. bool AudioProcessorGraph::acceptsMidi() const
  28733. {
  28734. return true;
  28735. }
  28736. bool AudioProcessorGraph::producesMidi() const
  28737. {
  28738. return true;
  28739. }
  28740. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28741. {
  28742. }
  28743. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28744. {
  28745. }
  28746. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28747. : type (type_),
  28748. graph (0)
  28749. {
  28750. }
  28751. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28752. {
  28753. }
  28754. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28755. {
  28756. switch (type)
  28757. {
  28758. case audioOutputNode:
  28759. return "Audio Output";
  28760. case audioInputNode:
  28761. return "Audio Input";
  28762. case midiOutputNode:
  28763. return "Midi Output";
  28764. case midiInputNode:
  28765. return "Midi Input";
  28766. default:
  28767. break;
  28768. }
  28769. return String::empty;
  28770. }
  28771. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28772. {
  28773. d.name = getName();
  28774. d.uid = d.name.hashCode();
  28775. d.category = "I/O devices";
  28776. d.pluginFormatName = "Internal";
  28777. d.manufacturerName = "Raw Material Software";
  28778. d.version = "1.0";
  28779. d.isInstrument = false;
  28780. d.numInputChannels = getNumInputChannels();
  28781. if (type == audioOutputNode && graph != 0)
  28782. d.numInputChannels = graph->getNumInputChannels();
  28783. d.numOutputChannels = getNumOutputChannels();
  28784. if (type == audioInputNode && graph != 0)
  28785. d.numOutputChannels = graph->getNumOutputChannels();
  28786. }
  28787. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28788. {
  28789. jassert (graph != 0);
  28790. }
  28791. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28792. {
  28793. }
  28794. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28795. MidiBuffer& midiMessages)
  28796. {
  28797. jassert (graph != 0);
  28798. switch (type)
  28799. {
  28800. case audioOutputNode:
  28801. {
  28802. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28803. buffer.getNumChannels()); --i >= 0;)
  28804. {
  28805. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28806. }
  28807. break;
  28808. }
  28809. case audioInputNode:
  28810. {
  28811. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28812. buffer.getNumChannels()); --i >= 0;)
  28813. {
  28814. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28815. }
  28816. break;
  28817. }
  28818. case midiOutputNode:
  28819. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28820. break;
  28821. case midiInputNode:
  28822. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28823. break;
  28824. default:
  28825. break;
  28826. }
  28827. }
  28828. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28829. {
  28830. return type == midiOutputNode;
  28831. }
  28832. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28833. {
  28834. return type == midiInputNode;
  28835. }
  28836. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28837. {
  28838. switch (type)
  28839. {
  28840. case audioOutputNode:
  28841. return "Output " + String (channelIndex + 1);
  28842. case midiOutputNode:
  28843. return "Midi Output";
  28844. default:
  28845. break;
  28846. }
  28847. return String::empty;
  28848. }
  28849. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28850. {
  28851. switch (type)
  28852. {
  28853. case audioInputNode:
  28854. return "Input " + String (channelIndex + 1);
  28855. case midiInputNode:
  28856. return "Midi Input";
  28857. default:
  28858. break;
  28859. }
  28860. return String::empty;
  28861. }
  28862. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28863. {
  28864. return type == audioInputNode || type == audioOutputNode;
  28865. }
  28866. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28867. {
  28868. return isInputChannelStereoPair (index);
  28869. }
  28870. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28871. {
  28872. return type == audioInputNode || type == midiInputNode;
  28873. }
  28874. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  28875. {
  28876. return type == audioOutputNode || type == midiOutputNode;
  28877. }
  28878. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  28879. {
  28880. return 0;
  28881. }
  28882. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  28883. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  28884. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  28885. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  28886. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  28887. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  28888. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  28889. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  28890. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  28891. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  28892. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  28893. {
  28894. }
  28895. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  28896. {
  28897. }
  28898. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  28899. {
  28900. graph = newGraph;
  28901. if (graph != 0)
  28902. {
  28903. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  28904. type == audioInputNode ? graph->getNumInputChannels() : 0,
  28905. getSampleRate(),
  28906. getBlockSize());
  28907. updateHostDisplay();
  28908. }
  28909. }
  28910. END_JUCE_NAMESPACE
  28911. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  28912. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28913. BEGIN_JUCE_NAMESPACE
  28914. AudioProcessorPlayer::AudioProcessorPlayer()
  28915. : processor (0),
  28916. sampleRate (0),
  28917. blockSize (0),
  28918. isPrepared (false),
  28919. numInputChans (0),
  28920. numOutputChans (0),
  28921. tempBuffer (1, 1)
  28922. {
  28923. }
  28924. AudioProcessorPlayer::~AudioProcessorPlayer()
  28925. {
  28926. setProcessor (0);
  28927. }
  28928. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  28929. {
  28930. if (processor != processorToPlay)
  28931. {
  28932. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  28933. {
  28934. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  28935. sampleRate, blockSize);
  28936. processorToPlay->prepareToPlay (sampleRate, blockSize);
  28937. }
  28938. AudioProcessor* oldOne;
  28939. {
  28940. const ScopedLock sl (lock);
  28941. oldOne = isPrepared ? processor : 0;
  28942. processor = processorToPlay;
  28943. isPrepared = true;
  28944. }
  28945. if (oldOne != 0)
  28946. oldOne->releaseResources();
  28947. }
  28948. }
  28949. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  28950. int numInputChannels,
  28951. float** outputChannelData,
  28952. int numOutputChannels,
  28953. int numSamples)
  28954. {
  28955. // these should have been prepared by audioDeviceAboutToStart()...
  28956. jassert (sampleRate > 0 && blockSize > 0);
  28957. incomingMidi.clear();
  28958. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  28959. int i, totalNumChans = 0;
  28960. if (numInputChannels > numOutputChannels)
  28961. {
  28962. // if there aren't enough output channels for the number of
  28963. // inputs, we need to create some temporary extra ones (can't
  28964. // use the input data in case it gets written to)
  28965. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  28966. false, false, true);
  28967. for (i = 0; i < numOutputChannels; ++i)
  28968. {
  28969. channels[totalNumChans] = outputChannelData[i];
  28970. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28971. ++totalNumChans;
  28972. }
  28973. for (i = numOutputChannels; i < numInputChannels; ++i)
  28974. {
  28975. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  28976. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28977. ++totalNumChans;
  28978. }
  28979. }
  28980. else
  28981. {
  28982. for (i = 0; i < numInputChannels; ++i)
  28983. {
  28984. channels[totalNumChans] = outputChannelData[i];
  28985. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28986. ++totalNumChans;
  28987. }
  28988. for (i = numInputChannels; i < numOutputChannels; ++i)
  28989. {
  28990. channels[totalNumChans] = outputChannelData[i];
  28991. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  28992. ++totalNumChans;
  28993. }
  28994. }
  28995. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  28996. const ScopedLock sl (lock);
  28997. if (processor != 0)
  28998. processor->processBlock (buffer, incomingMidi);
  28999. }
  29000. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29001. {
  29002. const ScopedLock sl (lock);
  29003. sampleRate = device->getCurrentSampleRate();
  29004. blockSize = device->getCurrentBufferSizeSamples();
  29005. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29006. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29007. messageCollector.reset (sampleRate);
  29008. zeromem (channels, sizeof (channels));
  29009. if (processor != 0)
  29010. {
  29011. if (isPrepared)
  29012. processor->releaseResources();
  29013. AudioProcessor* const oldProcessor = processor;
  29014. setProcessor (0);
  29015. setProcessor (oldProcessor);
  29016. }
  29017. }
  29018. void AudioProcessorPlayer::audioDeviceStopped()
  29019. {
  29020. const ScopedLock sl (lock);
  29021. if (processor != 0 && isPrepared)
  29022. processor->releaseResources();
  29023. sampleRate = 0.0;
  29024. blockSize = 0;
  29025. isPrepared = false;
  29026. tempBuffer.setSize (1, 1);
  29027. }
  29028. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29029. {
  29030. messageCollector.addMessageToQueue (message);
  29031. }
  29032. END_JUCE_NAMESPACE
  29033. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29034. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29035. BEGIN_JUCE_NAMESPACE
  29036. class ProcessorParameterPropertyComp : public PropertyComponent,
  29037. public AudioProcessorListener,
  29038. public AsyncUpdater
  29039. {
  29040. public:
  29041. ProcessorParameterPropertyComp (const String& name,
  29042. AudioProcessor* const owner_,
  29043. const int index_)
  29044. : PropertyComponent (name),
  29045. owner (owner_),
  29046. index (index_)
  29047. {
  29048. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29049. owner_->addListener (this);
  29050. }
  29051. ~ProcessorParameterPropertyComp()
  29052. {
  29053. owner->removeListener (this);
  29054. deleteAllChildren();
  29055. }
  29056. void refresh()
  29057. {
  29058. slider->setValue (owner->getParameter (index), false);
  29059. }
  29060. void audioProcessorChanged (AudioProcessor*) {}
  29061. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29062. {
  29063. if (parameterIndex == index)
  29064. triggerAsyncUpdate();
  29065. }
  29066. void handleAsyncUpdate()
  29067. {
  29068. refresh();
  29069. }
  29070. juce_UseDebuggingNewOperator
  29071. private:
  29072. AudioProcessor* const owner;
  29073. const int index;
  29074. Slider* slider;
  29075. class ParamSlider : public Slider
  29076. {
  29077. public:
  29078. ParamSlider (AudioProcessor* const owner_, const int index_)
  29079. : Slider (String::empty),
  29080. owner (owner_),
  29081. index (index_)
  29082. {
  29083. setRange (0.0, 1.0, 0.0);
  29084. setSliderStyle (Slider::LinearBar);
  29085. setTextBoxIsEditable (false);
  29086. setScrollWheelEnabled (false);
  29087. }
  29088. ~ParamSlider()
  29089. {
  29090. }
  29091. void valueChanged()
  29092. {
  29093. const float newVal = (float) getValue();
  29094. if (owner->getParameter (index) != newVal)
  29095. owner->setParameter (index, newVal);
  29096. }
  29097. const String getTextFromValue (double /*value*/)
  29098. {
  29099. return owner->getParameterText (index);
  29100. }
  29101. juce_UseDebuggingNewOperator
  29102. private:
  29103. AudioProcessor* const owner;
  29104. const int index;
  29105. ParamSlider (const ParamSlider&);
  29106. ParamSlider& operator= (const ParamSlider&);
  29107. };
  29108. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29109. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29110. };
  29111. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29112. : AudioProcessorEditor (owner_)
  29113. {
  29114. setOpaque (true);
  29115. addAndMakeVisible (panel = new PropertyPanel());
  29116. Array <PropertyComponent*> params;
  29117. const int numParams = owner_->getNumParameters();
  29118. int totalHeight = 0;
  29119. for (int i = 0; i < numParams; ++i)
  29120. {
  29121. String name (owner_->getParameterName (i));
  29122. if (name.trim().isEmpty())
  29123. name = "Unnamed";
  29124. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29125. params.add (pc);
  29126. totalHeight += pc->getPreferredHeight();
  29127. }
  29128. panel->addProperties (params);
  29129. setSize (400, jlimit (25, 400, totalHeight));
  29130. }
  29131. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29132. {
  29133. deleteAllChildren();
  29134. }
  29135. void GenericAudioProcessorEditor::paint (Graphics& g)
  29136. {
  29137. g.fillAll (Colours::white);
  29138. }
  29139. void GenericAudioProcessorEditor::resized()
  29140. {
  29141. panel->setSize (getWidth(), getHeight());
  29142. }
  29143. END_JUCE_NAMESPACE
  29144. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29145. /*** Start of inlined file: juce_Sampler.cpp ***/
  29146. BEGIN_JUCE_NAMESPACE
  29147. SamplerSound::SamplerSound (const String& name_,
  29148. AudioFormatReader& source,
  29149. const BigInteger& midiNotes_,
  29150. const int midiNoteForNormalPitch,
  29151. const double attackTimeSecs,
  29152. const double releaseTimeSecs,
  29153. const double maxSampleLengthSeconds)
  29154. : name (name_),
  29155. midiNotes (midiNotes_),
  29156. midiRootNote (midiNoteForNormalPitch)
  29157. {
  29158. sourceSampleRate = source.sampleRate;
  29159. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29160. {
  29161. length = 0;
  29162. attackSamples = 0;
  29163. releaseSamples = 0;
  29164. }
  29165. else
  29166. {
  29167. length = jmin ((int) source.lengthInSamples,
  29168. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29169. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29170. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29171. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29172. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29173. }
  29174. }
  29175. SamplerSound::~SamplerSound()
  29176. {
  29177. }
  29178. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29179. {
  29180. return midiNotes [midiNoteNumber];
  29181. }
  29182. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29183. {
  29184. return true;
  29185. }
  29186. SamplerVoice::SamplerVoice()
  29187. : pitchRatio (0.0),
  29188. sourceSamplePosition (0.0),
  29189. lgain (0.0f),
  29190. rgain (0.0f),
  29191. isInAttack (false),
  29192. isInRelease (false)
  29193. {
  29194. }
  29195. SamplerVoice::~SamplerVoice()
  29196. {
  29197. }
  29198. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29199. {
  29200. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29201. }
  29202. void SamplerVoice::startNote (const int midiNoteNumber,
  29203. const float velocity,
  29204. SynthesiserSound* s,
  29205. const int /*currentPitchWheelPosition*/)
  29206. {
  29207. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29208. jassert (sound != 0); // this object can only play SamplerSounds!
  29209. if (sound != 0)
  29210. {
  29211. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29212. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29213. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29214. sourceSamplePosition = 0.0;
  29215. lgain = velocity;
  29216. rgain = velocity;
  29217. isInAttack = (sound->attackSamples > 0);
  29218. isInRelease = false;
  29219. if (isInAttack)
  29220. {
  29221. attackReleaseLevel = 0.0f;
  29222. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29223. }
  29224. else
  29225. {
  29226. attackReleaseLevel = 1.0f;
  29227. attackDelta = 0.0f;
  29228. }
  29229. if (sound->releaseSamples > 0)
  29230. {
  29231. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29232. }
  29233. else
  29234. {
  29235. releaseDelta = 0.0f;
  29236. }
  29237. }
  29238. }
  29239. void SamplerVoice::stopNote (const bool allowTailOff)
  29240. {
  29241. if (allowTailOff)
  29242. {
  29243. isInAttack = false;
  29244. isInRelease = true;
  29245. }
  29246. else
  29247. {
  29248. clearCurrentNote();
  29249. }
  29250. }
  29251. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29252. {
  29253. }
  29254. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29255. const int /*newValue*/)
  29256. {
  29257. }
  29258. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29259. {
  29260. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29261. if (playingSound != 0)
  29262. {
  29263. const float* const inL = playingSound->data->getSampleData (0, 0);
  29264. const float* const inR = playingSound->data->getNumChannels() > 1
  29265. ? playingSound->data->getSampleData (1, 0) : 0;
  29266. float* outL = outputBuffer.getSampleData (0, startSample);
  29267. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29268. while (--numSamples >= 0)
  29269. {
  29270. const int pos = (int) sourceSamplePosition;
  29271. const float alpha = (float) (sourceSamplePosition - pos);
  29272. const float invAlpha = 1.0f - alpha;
  29273. // just using a very simple linear interpolation here..
  29274. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29275. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29276. : l;
  29277. l *= lgain;
  29278. r *= rgain;
  29279. if (isInAttack)
  29280. {
  29281. l *= attackReleaseLevel;
  29282. r *= attackReleaseLevel;
  29283. attackReleaseLevel += attackDelta;
  29284. if (attackReleaseLevel >= 1.0f)
  29285. {
  29286. attackReleaseLevel = 1.0f;
  29287. isInAttack = false;
  29288. }
  29289. }
  29290. else if (isInRelease)
  29291. {
  29292. l *= attackReleaseLevel;
  29293. r *= attackReleaseLevel;
  29294. attackReleaseLevel += releaseDelta;
  29295. if (attackReleaseLevel <= 0.0f)
  29296. {
  29297. stopNote (false);
  29298. break;
  29299. }
  29300. }
  29301. if (outR != 0)
  29302. {
  29303. *outL++ += l;
  29304. *outR++ += r;
  29305. }
  29306. else
  29307. {
  29308. *outL++ += (l + r) * 0.5f;
  29309. }
  29310. sourceSamplePosition += pitchRatio;
  29311. if (sourceSamplePosition > playingSound->length)
  29312. {
  29313. stopNote (false);
  29314. break;
  29315. }
  29316. }
  29317. }
  29318. }
  29319. END_JUCE_NAMESPACE
  29320. /*** End of inlined file: juce_Sampler.cpp ***/
  29321. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29322. BEGIN_JUCE_NAMESPACE
  29323. SynthesiserSound::SynthesiserSound()
  29324. {
  29325. }
  29326. SynthesiserSound::~SynthesiserSound()
  29327. {
  29328. }
  29329. SynthesiserVoice::SynthesiserVoice()
  29330. : currentSampleRate (44100.0),
  29331. currentlyPlayingNote (-1),
  29332. noteOnTime (0),
  29333. currentlyPlayingSound (0)
  29334. {
  29335. }
  29336. SynthesiserVoice::~SynthesiserVoice()
  29337. {
  29338. }
  29339. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29340. {
  29341. return currentlyPlayingSound != 0
  29342. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29343. }
  29344. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29345. {
  29346. currentSampleRate = newRate;
  29347. }
  29348. void SynthesiserVoice::clearCurrentNote()
  29349. {
  29350. currentlyPlayingNote = -1;
  29351. currentlyPlayingSound = 0;
  29352. }
  29353. Synthesiser::Synthesiser()
  29354. : sampleRate (0),
  29355. lastNoteOnCounter (0),
  29356. shouldStealNotes (true)
  29357. {
  29358. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29359. lastPitchWheelValues[i] = 0x2000;
  29360. }
  29361. Synthesiser::~Synthesiser()
  29362. {
  29363. }
  29364. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29365. {
  29366. const ScopedLock sl (lock);
  29367. return voices [index];
  29368. }
  29369. void Synthesiser::clearVoices()
  29370. {
  29371. const ScopedLock sl (lock);
  29372. voices.clear();
  29373. }
  29374. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29375. {
  29376. const ScopedLock sl (lock);
  29377. voices.add (newVoice);
  29378. }
  29379. void Synthesiser::removeVoice (const int index)
  29380. {
  29381. const ScopedLock sl (lock);
  29382. voices.remove (index);
  29383. }
  29384. void Synthesiser::clearSounds()
  29385. {
  29386. const ScopedLock sl (lock);
  29387. sounds.clear();
  29388. }
  29389. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29390. {
  29391. const ScopedLock sl (lock);
  29392. sounds.add (newSound);
  29393. }
  29394. void Synthesiser::removeSound (const int index)
  29395. {
  29396. const ScopedLock sl (lock);
  29397. sounds.remove (index);
  29398. }
  29399. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29400. {
  29401. shouldStealNotes = shouldStealNotes_;
  29402. }
  29403. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29404. {
  29405. if (sampleRate != newRate)
  29406. {
  29407. const ScopedLock sl (lock);
  29408. allNotesOff (0, false);
  29409. sampleRate = newRate;
  29410. for (int i = voices.size(); --i >= 0;)
  29411. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29412. }
  29413. }
  29414. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29415. const MidiBuffer& midiData,
  29416. int startSample,
  29417. int numSamples)
  29418. {
  29419. // must set the sample rate before using this!
  29420. jassert (sampleRate != 0);
  29421. const ScopedLock sl (lock);
  29422. MidiBuffer::Iterator midiIterator (midiData);
  29423. midiIterator.setNextSamplePosition (startSample);
  29424. MidiMessage m (0xf4, 0.0);
  29425. while (numSamples > 0)
  29426. {
  29427. int midiEventPos;
  29428. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29429. && midiEventPos < startSample + numSamples;
  29430. const int numThisTime = useEvent ? midiEventPos - startSample
  29431. : numSamples;
  29432. if (numThisTime > 0)
  29433. {
  29434. for (int i = voices.size(); --i >= 0;)
  29435. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29436. }
  29437. if (useEvent)
  29438. {
  29439. if (m.isNoteOn())
  29440. {
  29441. const int channel = m.getChannel();
  29442. noteOn (channel,
  29443. m.getNoteNumber(),
  29444. m.getFloatVelocity());
  29445. }
  29446. else if (m.isNoteOff())
  29447. {
  29448. noteOff (m.getChannel(),
  29449. m.getNoteNumber(),
  29450. true);
  29451. }
  29452. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29453. {
  29454. allNotesOff (m.getChannel(), true);
  29455. }
  29456. else if (m.isPitchWheel())
  29457. {
  29458. const int channel = m.getChannel();
  29459. const int wheelPos = m.getPitchWheelValue();
  29460. lastPitchWheelValues [channel - 1] = wheelPos;
  29461. handlePitchWheel (channel, wheelPos);
  29462. }
  29463. else if (m.isController())
  29464. {
  29465. handleController (m.getChannel(),
  29466. m.getControllerNumber(),
  29467. m.getControllerValue());
  29468. }
  29469. }
  29470. startSample += numThisTime;
  29471. numSamples -= numThisTime;
  29472. }
  29473. }
  29474. void Synthesiser::noteOn (const int midiChannel,
  29475. const int midiNoteNumber,
  29476. const float velocity)
  29477. {
  29478. const ScopedLock sl (lock);
  29479. for (int i = sounds.size(); --i >= 0;)
  29480. {
  29481. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29482. if (sound->appliesToNote (midiNoteNumber)
  29483. && sound->appliesToChannel (midiChannel))
  29484. {
  29485. startVoice (findFreeVoice (sound, shouldStealNotes),
  29486. sound, midiChannel, midiNoteNumber, velocity);
  29487. }
  29488. }
  29489. }
  29490. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29491. SynthesiserSound* const sound,
  29492. const int midiChannel,
  29493. const int midiNoteNumber,
  29494. const float velocity)
  29495. {
  29496. if (voice != 0 && sound != 0)
  29497. {
  29498. if (voice->currentlyPlayingSound != 0)
  29499. voice->stopNote (false);
  29500. voice->startNote (midiNoteNumber,
  29501. velocity,
  29502. sound,
  29503. lastPitchWheelValues [midiChannel - 1]);
  29504. voice->currentlyPlayingNote = midiNoteNumber;
  29505. voice->noteOnTime = ++lastNoteOnCounter;
  29506. voice->currentlyPlayingSound = sound;
  29507. }
  29508. }
  29509. void Synthesiser::noteOff (const int midiChannel,
  29510. const int midiNoteNumber,
  29511. const bool allowTailOff)
  29512. {
  29513. const ScopedLock sl (lock);
  29514. for (int i = voices.size(); --i >= 0;)
  29515. {
  29516. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29517. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29518. {
  29519. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29520. if (sound != 0
  29521. && sound->appliesToNote (midiNoteNumber)
  29522. && sound->appliesToChannel (midiChannel))
  29523. {
  29524. voice->stopNote (allowTailOff);
  29525. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29526. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29527. }
  29528. }
  29529. }
  29530. }
  29531. void Synthesiser::allNotesOff (const int midiChannel,
  29532. const bool allowTailOff)
  29533. {
  29534. const ScopedLock sl (lock);
  29535. for (int i = voices.size(); --i >= 0;)
  29536. {
  29537. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29538. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29539. voice->stopNote (allowTailOff);
  29540. }
  29541. }
  29542. void Synthesiser::handlePitchWheel (const int midiChannel,
  29543. const int wheelValue)
  29544. {
  29545. const ScopedLock sl (lock);
  29546. for (int i = voices.size(); --i >= 0;)
  29547. {
  29548. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29549. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29550. {
  29551. voice->pitchWheelMoved (wheelValue);
  29552. }
  29553. }
  29554. }
  29555. void Synthesiser::handleController (const int midiChannel,
  29556. const int controllerNumber,
  29557. const int controllerValue)
  29558. {
  29559. const ScopedLock sl (lock);
  29560. for (int i = voices.size(); --i >= 0;)
  29561. {
  29562. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29563. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29564. voice->controllerMoved (controllerNumber, controllerValue);
  29565. }
  29566. }
  29567. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29568. const bool stealIfNoneAvailable) const
  29569. {
  29570. const ScopedLock sl (lock);
  29571. for (int i = voices.size(); --i >= 0;)
  29572. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29573. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29574. return voices.getUnchecked (i);
  29575. if (stealIfNoneAvailable)
  29576. {
  29577. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29578. SynthesiserVoice* oldest = 0;
  29579. for (int i = voices.size(); --i >= 0;)
  29580. {
  29581. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29582. if (voice->canPlaySound (soundToPlay)
  29583. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29584. oldest = voice;
  29585. }
  29586. jassert (oldest != 0);
  29587. return oldest;
  29588. }
  29589. return 0;
  29590. }
  29591. END_JUCE_NAMESPACE
  29592. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29593. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29594. BEGIN_JUCE_NAMESPACE
  29595. ActionBroadcaster::ActionBroadcaster() throw()
  29596. {
  29597. // are you trying to create this object before or after juce has been intialised??
  29598. jassert (MessageManager::instance != 0);
  29599. }
  29600. ActionBroadcaster::~ActionBroadcaster()
  29601. {
  29602. // all event-based objects must be deleted BEFORE juce is shut down!
  29603. jassert (MessageManager::instance != 0);
  29604. }
  29605. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29606. {
  29607. actionListenerList.addActionListener (listener);
  29608. }
  29609. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29610. {
  29611. jassert (actionListenerList.isValidMessageListener());
  29612. if (actionListenerList.isValidMessageListener())
  29613. actionListenerList.removeActionListener (listener);
  29614. }
  29615. void ActionBroadcaster::removeAllActionListeners()
  29616. {
  29617. actionListenerList.removeAllActionListeners();
  29618. }
  29619. void ActionBroadcaster::sendActionMessage (const String& message) const
  29620. {
  29621. actionListenerList.sendActionMessage (message);
  29622. }
  29623. END_JUCE_NAMESPACE
  29624. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29625. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29626. BEGIN_JUCE_NAMESPACE
  29627. // special message of our own with a string in it
  29628. class ActionMessage : public Message
  29629. {
  29630. public:
  29631. const String message;
  29632. ActionMessage (const String& messageText,
  29633. void* const listener_) throw()
  29634. : message (messageText)
  29635. {
  29636. pointerParameter = listener_;
  29637. }
  29638. ~ActionMessage() throw()
  29639. {
  29640. }
  29641. private:
  29642. ActionMessage (const ActionMessage&);
  29643. ActionMessage& operator= (const ActionMessage&);
  29644. };
  29645. ActionListenerList::ActionListenerList() throw()
  29646. {
  29647. }
  29648. ActionListenerList::~ActionListenerList() throw()
  29649. {
  29650. }
  29651. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29652. {
  29653. const ScopedLock sl (actionListenerLock_);
  29654. jassert (listener != 0);
  29655. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29656. if (listener != 0)
  29657. actionListeners_.add (listener);
  29658. }
  29659. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29660. {
  29661. const ScopedLock sl (actionListenerLock_);
  29662. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29663. actionListeners_.removeValue (listener);
  29664. }
  29665. void ActionListenerList::removeAllActionListeners() throw()
  29666. {
  29667. const ScopedLock sl (actionListenerLock_);
  29668. actionListeners_.clear();
  29669. }
  29670. void ActionListenerList::sendActionMessage (const String& message) const
  29671. {
  29672. const ScopedLock sl (actionListenerLock_);
  29673. for (int i = actionListeners_.size(); --i >= 0;)
  29674. {
  29675. postMessage (new ActionMessage (message,
  29676. (ActionListener*) actionListeners_.getUnchecked(i)));
  29677. }
  29678. }
  29679. void ActionListenerList::handleMessage (const Message& message)
  29680. {
  29681. const ActionMessage& am = (const ActionMessage&) message;
  29682. if (actionListeners_.contains (am.pointerParameter))
  29683. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29684. }
  29685. END_JUCE_NAMESPACE
  29686. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29687. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29688. BEGIN_JUCE_NAMESPACE
  29689. AsyncUpdater::AsyncUpdater() throw()
  29690. : asyncMessagePending (false)
  29691. {
  29692. internalAsyncHandler.owner = this;
  29693. }
  29694. AsyncUpdater::~AsyncUpdater()
  29695. {
  29696. }
  29697. void AsyncUpdater::triggerAsyncUpdate() throw()
  29698. {
  29699. if (! asyncMessagePending)
  29700. {
  29701. asyncMessagePending = true;
  29702. internalAsyncHandler.postMessage (new Message());
  29703. }
  29704. }
  29705. void AsyncUpdater::cancelPendingUpdate() throw()
  29706. {
  29707. asyncMessagePending = false;
  29708. }
  29709. void AsyncUpdater::handleUpdateNowIfNeeded()
  29710. {
  29711. if (asyncMessagePending)
  29712. {
  29713. asyncMessagePending = false;
  29714. handleAsyncUpdate();
  29715. }
  29716. }
  29717. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29718. {
  29719. owner->handleUpdateNowIfNeeded();
  29720. }
  29721. END_JUCE_NAMESPACE
  29722. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29723. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29724. BEGIN_JUCE_NAMESPACE
  29725. ChangeBroadcaster::ChangeBroadcaster() throw()
  29726. {
  29727. // are you trying to create this object before or after juce has been intialised??
  29728. jassert (MessageManager::instance != 0);
  29729. }
  29730. ChangeBroadcaster::~ChangeBroadcaster()
  29731. {
  29732. // all event-based objects must be deleted BEFORE juce is shut down!
  29733. jassert (MessageManager::instance != 0);
  29734. }
  29735. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29736. {
  29737. changeListenerList.addChangeListener (listener);
  29738. }
  29739. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29740. {
  29741. jassert (changeListenerList.isValidMessageListener());
  29742. if (changeListenerList.isValidMessageListener())
  29743. changeListenerList.removeChangeListener (listener);
  29744. }
  29745. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29746. {
  29747. changeListenerList.removeAllChangeListeners();
  29748. }
  29749. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29750. {
  29751. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29752. }
  29753. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29754. {
  29755. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29756. }
  29757. void ChangeBroadcaster::dispatchPendingMessages()
  29758. {
  29759. changeListenerList.dispatchPendingMessages();
  29760. }
  29761. END_JUCE_NAMESPACE
  29762. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29763. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29764. BEGIN_JUCE_NAMESPACE
  29765. ChangeListenerList::ChangeListenerList() throw()
  29766. : lastChangedObject (0),
  29767. messagePending (false)
  29768. {
  29769. }
  29770. ChangeListenerList::~ChangeListenerList() throw()
  29771. {
  29772. }
  29773. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29774. {
  29775. const ScopedLock sl (lock);
  29776. jassert (listener != 0);
  29777. if (listener != 0)
  29778. listeners.add (listener);
  29779. }
  29780. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29781. {
  29782. const ScopedLock sl (lock);
  29783. listeners.removeValue (listener);
  29784. }
  29785. void ChangeListenerList::removeAllChangeListeners() throw()
  29786. {
  29787. const ScopedLock sl (lock);
  29788. listeners.clear();
  29789. }
  29790. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29791. {
  29792. const ScopedLock sl (lock);
  29793. if ((! messagePending) && (listeners.size() > 0))
  29794. {
  29795. lastChangedObject = objectThatHasChanged;
  29796. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29797. messagePending = true;
  29798. }
  29799. }
  29800. void ChangeListenerList::handleMessage (const Message& message)
  29801. {
  29802. sendSynchronousChangeMessage (message.pointerParameter);
  29803. }
  29804. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29805. {
  29806. const ScopedLock sl (lock);
  29807. messagePending = false;
  29808. for (int i = listeners.size(); --i >= 0;)
  29809. {
  29810. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  29811. {
  29812. const ScopedUnlock tempUnlocker (lock);
  29813. l->changeListenerCallback (objectThatHasChanged);
  29814. }
  29815. i = jmin (i, listeners.size());
  29816. }
  29817. }
  29818. void ChangeListenerList::dispatchPendingMessages()
  29819. {
  29820. if (messagePending)
  29821. sendSynchronousChangeMessage (lastChangedObject);
  29822. }
  29823. END_JUCE_NAMESPACE
  29824. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29825. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29826. BEGIN_JUCE_NAMESPACE
  29827. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29828. const uint32 magicMessageHeaderNumber)
  29829. : Thread ("Juce IPC connection"),
  29830. callbackConnectionState (false),
  29831. useMessageThread (callbacksOnMessageThread),
  29832. magicMessageHeader (magicMessageHeaderNumber),
  29833. pipeReceiveMessageTimeout (-1)
  29834. {
  29835. }
  29836. InterprocessConnection::~InterprocessConnection()
  29837. {
  29838. callbackConnectionState = false;
  29839. disconnect();
  29840. }
  29841. bool InterprocessConnection::connectToSocket (const String& hostName,
  29842. const int portNumber,
  29843. const int timeOutMillisecs)
  29844. {
  29845. disconnect();
  29846. const ScopedLock sl (pipeAndSocketLock);
  29847. socket = new StreamingSocket();
  29848. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29849. {
  29850. connectionMadeInt();
  29851. startThread();
  29852. return true;
  29853. }
  29854. else
  29855. {
  29856. socket = 0;
  29857. return false;
  29858. }
  29859. }
  29860. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29861. const int pipeReceiveMessageTimeoutMs)
  29862. {
  29863. disconnect();
  29864. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29865. if (newPipe->openExisting (pipeName))
  29866. {
  29867. const ScopedLock sl (pipeAndSocketLock);
  29868. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29869. initialiseWithPipe (newPipe.release());
  29870. return true;
  29871. }
  29872. return false;
  29873. }
  29874. bool InterprocessConnection::createPipe (const String& pipeName,
  29875. const int pipeReceiveMessageTimeoutMs)
  29876. {
  29877. disconnect();
  29878. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29879. if (newPipe->createNewPipe (pipeName))
  29880. {
  29881. const ScopedLock sl (pipeAndSocketLock);
  29882. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29883. initialiseWithPipe (newPipe.release());
  29884. return true;
  29885. }
  29886. return false;
  29887. }
  29888. void InterprocessConnection::disconnect()
  29889. {
  29890. if (socket != 0)
  29891. socket->close();
  29892. if (pipe != 0)
  29893. {
  29894. pipe->cancelPendingReads();
  29895. pipe->close();
  29896. }
  29897. stopThread (4000);
  29898. {
  29899. const ScopedLock sl (pipeAndSocketLock);
  29900. socket = 0;
  29901. pipe = 0;
  29902. }
  29903. connectionLostInt();
  29904. }
  29905. bool InterprocessConnection::isConnected() const
  29906. {
  29907. const ScopedLock sl (pipeAndSocketLock);
  29908. return ((socket != 0 && socket->isConnected())
  29909. || (pipe != 0 && pipe->isOpen()))
  29910. && isThreadRunning();
  29911. }
  29912. const String InterprocessConnection::getConnectedHostName() const
  29913. {
  29914. if (pipe != 0)
  29915. {
  29916. return "localhost";
  29917. }
  29918. else if (socket != 0)
  29919. {
  29920. if (! socket->isLocal())
  29921. return socket->getHostName();
  29922. return "localhost";
  29923. }
  29924. return String::empty;
  29925. }
  29926. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  29927. {
  29928. uint32 messageHeader[2];
  29929. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  29930. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  29931. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  29932. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  29933. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  29934. size_t bytesWritten = 0;
  29935. const ScopedLock sl (pipeAndSocketLock);
  29936. if (socket != 0)
  29937. {
  29938. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  29939. }
  29940. else if (pipe != 0)
  29941. {
  29942. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  29943. }
  29944. if (bytesWritten < 0)
  29945. {
  29946. // error..
  29947. return false;
  29948. }
  29949. return (bytesWritten == messageData.getSize());
  29950. }
  29951. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  29952. {
  29953. jassert (socket == 0);
  29954. socket = socket_;
  29955. connectionMadeInt();
  29956. startThread();
  29957. }
  29958. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  29959. {
  29960. jassert (pipe == 0);
  29961. pipe = pipe_;
  29962. connectionMadeInt();
  29963. startThread();
  29964. }
  29965. const int messageMagicNumber = 0xb734128b;
  29966. void InterprocessConnection::handleMessage (const Message& message)
  29967. {
  29968. if (message.intParameter1 == messageMagicNumber)
  29969. {
  29970. switch (message.intParameter2)
  29971. {
  29972. case 0:
  29973. {
  29974. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  29975. messageReceived (*data);
  29976. break;
  29977. }
  29978. case 1:
  29979. connectionMade();
  29980. break;
  29981. case 2:
  29982. connectionLost();
  29983. break;
  29984. }
  29985. }
  29986. }
  29987. void InterprocessConnection::connectionMadeInt()
  29988. {
  29989. if (! callbackConnectionState)
  29990. {
  29991. callbackConnectionState = true;
  29992. if (useMessageThread)
  29993. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  29994. else
  29995. connectionMade();
  29996. }
  29997. }
  29998. void InterprocessConnection::connectionLostInt()
  29999. {
  30000. if (callbackConnectionState)
  30001. {
  30002. callbackConnectionState = false;
  30003. if (useMessageThread)
  30004. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30005. else
  30006. connectionLost();
  30007. }
  30008. }
  30009. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30010. {
  30011. jassert (callbackConnectionState);
  30012. if (useMessageThread)
  30013. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30014. else
  30015. messageReceived (data);
  30016. }
  30017. bool InterprocessConnection::readNextMessageInt()
  30018. {
  30019. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30020. uint32 messageHeader[2];
  30021. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30022. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30023. if (bytes == sizeof (messageHeader)
  30024. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30025. {
  30026. int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30027. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30028. {
  30029. MemoryBlock messageData (bytesInMessage, true);
  30030. int bytesRead = 0;
  30031. while (bytesInMessage > 0)
  30032. {
  30033. if (threadShouldExit())
  30034. return false;
  30035. const int numThisTime = jmin (bytesInMessage, 65536);
  30036. const int bytesIn = (socket != 0) ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
  30037. : pipe->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
  30038. if (bytesIn <= 0)
  30039. break;
  30040. bytesRead += bytesIn;
  30041. bytesInMessage -= bytesIn;
  30042. }
  30043. if (bytesRead >= 0)
  30044. deliverDataInt (messageData);
  30045. }
  30046. }
  30047. else if (bytes < 0)
  30048. {
  30049. {
  30050. const ScopedLock sl (pipeAndSocketLock);
  30051. socket = 0;
  30052. }
  30053. connectionLostInt();
  30054. return false;
  30055. }
  30056. return true;
  30057. }
  30058. void InterprocessConnection::run()
  30059. {
  30060. while (! threadShouldExit())
  30061. {
  30062. if (socket != 0)
  30063. {
  30064. const int ready = socket->waitUntilReady (true, 0);
  30065. if (ready < 0)
  30066. {
  30067. {
  30068. const ScopedLock sl (pipeAndSocketLock);
  30069. socket = 0;
  30070. }
  30071. connectionLostInt();
  30072. break;
  30073. }
  30074. else if (ready > 0)
  30075. {
  30076. if (! readNextMessageInt())
  30077. break;
  30078. }
  30079. else
  30080. {
  30081. Thread::sleep (2);
  30082. }
  30083. }
  30084. else if (pipe != 0)
  30085. {
  30086. if (! pipe->isOpen())
  30087. {
  30088. {
  30089. const ScopedLock sl (pipeAndSocketLock);
  30090. pipe = 0;
  30091. }
  30092. connectionLostInt();
  30093. break;
  30094. }
  30095. else
  30096. {
  30097. if (! readNextMessageInt())
  30098. break;
  30099. }
  30100. }
  30101. else
  30102. {
  30103. break;
  30104. }
  30105. }
  30106. }
  30107. END_JUCE_NAMESPACE
  30108. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30109. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30110. BEGIN_JUCE_NAMESPACE
  30111. InterprocessConnectionServer::InterprocessConnectionServer()
  30112. : Thread ("Juce IPC server")
  30113. {
  30114. }
  30115. InterprocessConnectionServer::~InterprocessConnectionServer()
  30116. {
  30117. stop();
  30118. }
  30119. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30120. {
  30121. stop();
  30122. socket = new StreamingSocket();
  30123. if (socket->createListener (portNumber))
  30124. {
  30125. startThread();
  30126. return true;
  30127. }
  30128. socket = 0;
  30129. return false;
  30130. }
  30131. void InterprocessConnectionServer::stop()
  30132. {
  30133. signalThreadShouldExit();
  30134. if (socket != 0)
  30135. socket->close();
  30136. stopThread (4000);
  30137. socket = 0;
  30138. }
  30139. void InterprocessConnectionServer::run()
  30140. {
  30141. while ((! threadShouldExit()) && socket != 0)
  30142. {
  30143. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30144. if (clientSocket != 0)
  30145. {
  30146. InterprocessConnection* newConnection = createConnectionObject();
  30147. if (newConnection != 0)
  30148. newConnection->initialiseWithSocket (clientSocket.release());
  30149. }
  30150. }
  30151. }
  30152. END_JUCE_NAMESPACE
  30153. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30154. /*** Start of inlined file: juce_Message.cpp ***/
  30155. BEGIN_JUCE_NAMESPACE
  30156. Message::Message() throw()
  30157. {
  30158. }
  30159. Message::~Message() throw()
  30160. {
  30161. }
  30162. Message::Message (const int intParameter1_,
  30163. const int intParameter2_,
  30164. const int intParameter3_,
  30165. void* const pointerParameter_) throw()
  30166. : intParameter1 (intParameter1_),
  30167. intParameter2 (intParameter2_),
  30168. intParameter3 (intParameter3_),
  30169. pointerParameter (pointerParameter_)
  30170. {
  30171. }
  30172. END_JUCE_NAMESPACE
  30173. /*** End of inlined file: juce_Message.cpp ***/
  30174. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30175. BEGIN_JUCE_NAMESPACE
  30176. MessageListener::MessageListener() throw()
  30177. {
  30178. // are you trying to create a messagelistener before or after juce has been intialised??
  30179. jassert (MessageManager::instance != 0);
  30180. if (MessageManager::instance != 0)
  30181. MessageManager::instance->messageListeners.add (this);
  30182. }
  30183. MessageListener::~MessageListener()
  30184. {
  30185. if (MessageManager::instance != 0)
  30186. MessageManager::instance->messageListeners.removeValue (this);
  30187. }
  30188. void MessageListener::postMessage (Message* const message) const throw()
  30189. {
  30190. message->messageRecipient = const_cast <MessageListener*> (this);
  30191. if (MessageManager::instance == 0)
  30192. MessageManager::getInstance();
  30193. MessageManager::instance->postMessageToQueue (message);
  30194. }
  30195. bool MessageListener::isValidMessageListener() const throw()
  30196. {
  30197. return (MessageManager::instance != 0)
  30198. && MessageManager::instance->messageListeners.contains (this);
  30199. }
  30200. END_JUCE_NAMESPACE
  30201. /*** End of inlined file: juce_MessageListener.cpp ***/
  30202. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30203. BEGIN_JUCE_NAMESPACE
  30204. // platform-specific functions..
  30205. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30206. bool juce_postMessageToSystemQueue (void* message);
  30207. MessageManager* MessageManager::instance = 0;
  30208. static const int quitMessageId = 0xfffff321;
  30209. MessageManager::MessageManager() throw()
  30210. : quitMessagePosted (false),
  30211. quitMessageReceived (false),
  30212. threadWithLock (0)
  30213. {
  30214. messageThreadId = Thread::getCurrentThreadId();
  30215. }
  30216. MessageManager::~MessageManager() throw()
  30217. {
  30218. broadcastListeners = 0;
  30219. doPlatformSpecificShutdown();
  30220. jassert (instance == this);
  30221. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30222. }
  30223. MessageManager* MessageManager::getInstance() throw()
  30224. {
  30225. if (instance == 0)
  30226. {
  30227. instance = new MessageManager();
  30228. doPlatformSpecificInitialisation();
  30229. }
  30230. return instance;
  30231. }
  30232. void MessageManager::postMessageToQueue (Message* const message)
  30233. {
  30234. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30235. delete message;
  30236. }
  30237. CallbackMessage::CallbackMessage() throw() {}
  30238. CallbackMessage::~CallbackMessage() throw() {}
  30239. void CallbackMessage::post()
  30240. {
  30241. if (MessageManager::instance != 0)
  30242. MessageManager::instance->postCallbackMessage (this);
  30243. }
  30244. void MessageManager::postCallbackMessage (Message* const message)
  30245. {
  30246. message->messageRecipient = 0;
  30247. postMessageToQueue (message);
  30248. }
  30249. // not for public use..
  30250. void MessageManager::deliverMessage (void* message)
  30251. {
  30252. const ScopedPointer <Message> m ((Message*) message);
  30253. MessageListener* const recipient = m->messageRecipient;
  30254. JUCE_TRY
  30255. {
  30256. if (messageListeners.contains (recipient))
  30257. {
  30258. recipient->handleMessage (*m);
  30259. }
  30260. else if (recipient == 0)
  30261. {
  30262. if (m->intParameter1 == quitMessageId)
  30263. {
  30264. quitMessageReceived = true;
  30265. }
  30266. else
  30267. {
  30268. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30269. if (cm != 0)
  30270. cm->messageCallback();
  30271. }
  30272. }
  30273. }
  30274. JUCE_CATCH_EXCEPTION
  30275. }
  30276. #if ! (JUCE_MAC || JUCE_IPHONE)
  30277. void MessageManager::runDispatchLoop()
  30278. {
  30279. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30280. runDispatchLoopUntil (-1);
  30281. }
  30282. void MessageManager::stopDispatchLoop()
  30283. {
  30284. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30285. m->messageRecipient = 0;
  30286. postMessageToQueue (m);
  30287. quitMessagePosted = true;
  30288. }
  30289. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30290. {
  30291. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30292. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30293. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30294. && ! quitMessageReceived)
  30295. {
  30296. JUCE_TRY
  30297. {
  30298. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30299. {
  30300. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30301. if (msToWait > 0)
  30302. Thread::sleep (jmin (5, msToWait));
  30303. }
  30304. }
  30305. JUCE_CATCH_EXCEPTION
  30306. }
  30307. return ! quitMessageReceived;
  30308. }
  30309. #endif
  30310. void MessageManager::deliverBroadcastMessage (const String& value)
  30311. {
  30312. if (broadcastListeners != 0)
  30313. broadcastListeners->sendActionMessage (value);
  30314. }
  30315. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30316. {
  30317. if (broadcastListeners == 0)
  30318. broadcastListeners = new ActionListenerList();
  30319. broadcastListeners->addActionListener (listener);
  30320. }
  30321. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30322. {
  30323. if (broadcastListeners != 0)
  30324. broadcastListeners->removeActionListener (listener);
  30325. }
  30326. bool MessageManager::isThisTheMessageThread() const throw()
  30327. {
  30328. return Thread::getCurrentThreadId() == messageThreadId;
  30329. }
  30330. void MessageManager::setCurrentThreadAsMessageThread()
  30331. {
  30332. if (messageThreadId != Thread::getCurrentThreadId())
  30333. {
  30334. messageThreadId = Thread::getCurrentThreadId();
  30335. // This is needed on windows to make sure the message window is created by this thread
  30336. doPlatformSpecificShutdown();
  30337. doPlatformSpecificInitialisation();
  30338. }
  30339. }
  30340. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30341. {
  30342. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30343. return thisThread == messageThreadId || thisThread == threadWithLock;
  30344. }
  30345. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30346. {
  30347. public:
  30348. SharedEvents() {}
  30349. ~SharedEvents() {}
  30350. WaitableEvent lockedEvent, releaseEvent;
  30351. private:
  30352. SharedEvents (const SharedEvents&);
  30353. SharedEvents& operator= (const SharedEvents&);
  30354. };
  30355. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30356. {
  30357. public:
  30358. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30359. ~BlockingMessage() throw() {}
  30360. void messageCallback()
  30361. {
  30362. events->lockedEvent.signal();
  30363. events->releaseEvent.wait();
  30364. }
  30365. juce_UseDebuggingNewOperator
  30366. private:
  30367. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30368. BlockingMessage (const BlockingMessage&);
  30369. BlockingMessage& operator= (const BlockingMessage&);
  30370. };
  30371. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30372. : sharedEvents (0),
  30373. locked (false)
  30374. {
  30375. init (threadToCheck, 0);
  30376. }
  30377. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30378. : sharedEvents (0),
  30379. locked (false)
  30380. {
  30381. init (0, jobToCheckForExitSignal);
  30382. }
  30383. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30384. {
  30385. if (MessageManager::instance != 0)
  30386. {
  30387. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30388. {
  30389. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30390. }
  30391. else
  30392. {
  30393. if (threadToCheck == 0 && job == 0)
  30394. {
  30395. MessageManager::instance->lockingLock.enter();
  30396. }
  30397. else
  30398. {
  30399. while (! MessageManager::instance->lockingLock.tryEnter())
  30400. {
  30401. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30402. || (job != 0 && job->shouldExit()))
  30403. return;
  30404. Thread::sleep (1);
  30405. }
  30406. }
  30407. sharedEvents = new SharedEvents();
  30408. sharedEvents->incReferenceCount();
  30409. (new BlockingMessage (sharedEvents))->post();
  30410. while (! sharedEvents->lockedEvent.wait (50))
  30411. {
  30412. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30413. || (job != 0 && job->shouldExit()))
  30414. {
  30415. sharedEvents->releaseEvent.signal();
  30416. sharedEvents->decReferenceCount();
  30417. sharedEvents = 0;
  30418. MessageManager::instance->lockingLock.exit();
  30419. return;
  30420. }
  30421. }
  30422. jassert (MessageManager::instance->threadWithLock == 0);
  30423. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30424. locked = true;
  30425. }
  30426. }
  30427. }
  30428. MessageManagerLock::~MessageManagerLock() throw()
  30429. {
  30430. if (sharedEvents != 0)
  30431. {
  30432. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30433. sharedEvents->releaseEvent.signal();
  30434. sharedEvents->decReferenceCount();
  30435. if (MessageManager::instance != 0)
  30436. {
  30437. MessageManager::instance->threadWithLock = 0;
  30438. MessageManager::instance->lockingLock.exit();
  30439. }
  30440. }
  30441. }
  30442. END_JUCE_NAMESPACE
  30443. /*** End of inlined file: juce_MessageManager.cpp ***/
  30444. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30445. BEGIN_JUCE_NAMESPACE
  30446. class MultiTimer::MultiTimerCallback : public Timer
  30447. {
  30448. public:
  30449. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30450. : timerId (timerId_),
  30451. owner (owner_)
  30452. {
  30453. }
  30454. ~MultiTimerCallback()
  30455. {
  30456. }
  30457. void timerCallback()
  30458. {
  30459. owner.timerCallback (timerId);
  30460. }
  30461. const int timerId;
  30462. private:
  30463. MultiTimer& owner;
  30464. };
  30465. MultiTimer::MultiTimer() throw()
  30466. {
  30467. }
  30468. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30469. {
  30470. }
  30471. MultiTimer::~MultiTimer()
  30472. {
  30473. const ScopedLock sl (timerListLock);
  30474. timers.clear();
  30475. }
  30476. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30477. {
  30478. const ScopedLock sl (timerListLock);
  30479. for (int i = timers.size(); --i >= 0;)
  30480. {
  30481. MultiTimerCallback* const t = timers.getUnchecked(i);
  30482. if (t->timerId == timerId)
  30483. {
  30484. t->startTimer (intervalInMilliseconds);
  30485. return;
  30486. }
  30487. }
  30488. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30489. timers.add (newTimer);
  30490. newTimer->startTimer (intervalInMilliseconds);
  30491. }
  30492. void MultiTimer::stopTimer (const int timerId) throw()
  30493. {
  30494. const ScopedLock sl (timerListLock);
  30495. for (int i = timers.size(); --i >= 0;)
  30496. {
  30497. MultiTimerCallback* const t = timers.getUnchecked(i);
  30498. if (t->timerId == timerId)
  30499. t->stopTimer();
  30500. }
  30501. }
  30502. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30503. {
  30504. const ScopedLock sl (timerListLock);
  30505. for (int i = timers.size(); --i >= 0;)
  30506. {
  30507. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30508. if (t->timerId == timerId)
  30509. return t->isTimerRunning();
  30510. }
  30511. return false;
  30512. }
  30513. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30514. {
  30515. const ScopedLock sl (timerListLock);
  30516. for (int i = timers.size(); --i >= 0;)
  30517. {
  30518. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30519. if (t->timerId == timerId)
  30520. return t->getTimerInterval();
  30521. }
  30522. return 0;
  30523. }
  30524. END_JUCE_NAMESPACE
  30525. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30526. /*** Start of inlined file: juce_Timer.cpp ***/
  30527. BEGIN_JUCE_NAMESPACE
  30528. class InternalTimerThread : private Thread,
  30529. private MessageListener,
  30530. private DeletedAtShutdown,
  30531. private AsyncUpdater
  30532. {
  30533. public:
  30534. InternalTimerThread()
  30535. : Thread ("Juce Timer"),
  30536. firstTimer (0),
  30537. callbackNeeded (false)
  30538. {
  30539. triggerAsyncUpdate();
  30540. }
  30541. ~InternalTimerThread() throw()
  30542. {
  30543. stopThread (4000);
  30544. jassert (instance == this || instance == 0);
  30545. if (instance == this)
  30546. instance = 0;
  30547. }
  30548. void run()
  30549. {
  30550. uint32 lastTime = Time::getMillisecondCounter();
  30551. while (! threadShouldExit())
  30552. {
  30553. const uint32 now = Time::getMillisecondCounter();
  30554. if (now <= lastTime)
  30555. {
  30556. wait (2);
  30557. continue;
  30558. }
  30559. const int elapsed = now - lastTime;
  30560. lastTime = now;
  30561. int timeUntilFirstTimer = 1000;
  30562. {
  30563. const ScopedLock sl (lock);
  30564. decrementAllCounters (elapsed);
  30565. if (firstTimer != 0)
  30566. timeUntilFirstTimer = firstTimer->countdownMs;
  30567. }
  30568. if (timeUntilFirstTimer <= 0)
  30569. {
  30570. if (callbackNeeded.set (true))
  30571. {
  30572. postMessage (new Message());
  30573. const uint32 messageDeliveryTimeout = now + 2000;
  30574. while (callbackNeeded.get())
  30575. {
  30576. wait (4);
  30577. if (threadShouldExit())
  30578. return;
  30579. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30580. break;
  30581. }
  30582. }
  30583. }
  30584. else
  30585. {
  30586. // don't wait for too long because running this loop also helps keep the
  30587. // Time::getApproximateMillisecondTimer value stay up-to-date
  30588. wait (jlimit (1, 50, timeUntilFirstTimer));
  30589. }
  30590. }
  30591. }
  30592. void callTimers()
  30593. {
  30594. const ScopedLock sl (lock);
  30595. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30596. {
  30597. Timer* const t = firstTimer;
  30598. t->countdownMs = t->periodMs;
  30599. removeTimer (t);
  30600. addTimer (t);
  30601. const ScopedUnlock ul (lock);
  30602. JUCE_TRY
  30603. {
  30604. t->timerCallback();
  30605. }
  30606. JUCE_CATCH_EXCEPTION
  30607. }
  30608. callbackNeeded.set (false);
  30609. }
  30610. void handleMessage (const Message&)
  30611. {
  30612. callTimers();
  30613. }
  30614. void callTimersSynchronously()
  30615. {
  30616. if (! isThreadRunning())
  30617. {
  30618. // (This is relied on by some plugins in cases where the MM has
  30619. // had to restart and the async callback never started)
  30620. cancelPendingUpdate();
  30621. triggerAsyncUpdate();
  30622. }
  30623. callTimers();
  30624. }
  30625. static void callAnyTimersSynchronously()
  30626. {
  30627. if (InternalTimerThread::instance != 0)
  30628. InternalTimerThread::instance->callTimersSynchronously();
  30629. }
  30630. static inline void add (Timer* const tim) throw()
  30631. {
  30632. if (instance == 0)
  30633. instance = new InternalTimerThread();
  30634. const ScopedLock sl (instance->lock);
  30635. instance->addTimer (tim);
  30636. }
  30637. static inline void remove (Timer* const tim) throw()
  30638. {
  30639. if (instance != 0)
  30640. {
  30641. const ScopedLock sl (instance->lock);
  30642. instance->removeTimer (tim);
  30643. }
  30644. }
  30645. static inline void resetCounter (Timer* const tim,
  30646. const int newCounter) throw()
  30647. {
  30648. if (instance != 0)
  30649. {
  30650. tim->countdownMs = newCounter;
  30651. tim->periodMs = newCounter;
  30652. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30653. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30654. {
  30655. const ScopedLock sl (instance->lock);
  30656. instance->removeTimer (tim);
  30657. instance->addTimer (tim);
  30658. }
  30659. }
  30660. }
  30661. private:
  30662. friend class Timer;
  30663. static InternalTimerThread* instance;
  30664. static CriticalSection lock;
  30665. Timer* volatile firstTimer;
  30666. class AtomicBool
  30667. {
  30668. public:
  30669. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30670. ~AtomicBool() throw() {}
  30671. bool get() const throw() { return value != 0; }
  30672. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30673. private:
  30674. int32 value;
  30675. AtomicBool (const AtomicBool&);
  30676. AtomicBool& operator= (const AtomicBool&);
  30677. };
  30678. AtomicBool callbackNeeded;
  30679. void addTimer (Timer* const t) throw()
  30680. {
  30681. #ifdef JUCE_DEBUG
  30682. Timer* tt = firstTimer;
  30683. while (tt != 0)
  30684. {
  30685. // trying to add a timer that's already here - shouldn't get to this point,
  30686. // so if you get this assertion, let me know!
  30687. jassert (tt != t);
  30688. tt = tt->next;
  30689. }
  30690. jassert (t->previous == 0 && t->next == 0);
  30691. #endif
  30692. Timer* i = firstTimer;
  30693. if (i == 0 || i->countdownMs > t->countdownMs)
  30694. {
  30695. t->next = firstTimer;
  30696. firstTimer = t;
  30697. }
  30698. else
  30699. {
  30700. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30701. i = i->next;
  30702. jassert (i != 0);
  30703. t->next = i->next;
  30704. t->previous = i;
  30705. i->next = t;
  30706. }
  30707. if (t->next != 0)
  30708. t->next->previous = t;
  30709. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30710. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30711. notify();
  30712. }
  30713. void removeTimer (Timer* const t) throw()
  30714. {
  30715. #ifdef JUCE_DEBUG
  30716. Timer* tt = firstTimer;
  30717. bool found = false;
  30718. while (tt != 0)
  30719. {
  30720. if (tt == t)
  30721. {
  30722. found = true;
  30723. break;
  30724. }
  30725. tt = tt->next;
  30726. }
  30727. // trying to remove a timer that's not here - shouldn't get to this point,
  30728. // so if you get this assertion, let me know!
  30729. jassert (found);
  30730. #endif
  30731. if (t->previous != 0)
  30732. {
  30733. jassert (firstTimer != t);
  30734. t->previous->next = t->next;
  30735. }
  30736. else
  30737. {
  30738. jassert (firstTimer == t);
  30739. firstTimer = t->next;
  30740. }
  30741. if (t->next != 0)
  30742. t->next->previous = t->previous;
  30743. t->next = 0;
  30744. t->previous = 0;
  30745. }
  30746. void decrementAllCounters (const int numMillisecs) const
  30747. {
  30748. Timer* t = firstTimer;
  30749. while (t != 0)
  30750. {
  30751. t->countdownMs -= numMillisecs;
  30752. t = t->next;
  30753. }
  30754. }
  30755. void handleAsyncUpdate()
  30756. {
  30757. startThread (7);
  30758. }
  30759. InternalTimerThread (const InternalTimerThread&);
  30760. InternalTimerThread& operator= (const InternalTimerThread&);
  30761. };
  30762. InternalTimerThread* InternalTimerThread::instance = 0;
  30763. CriticalSection InternalTimerThread::lock;
  30764. void juce_callAnyTimersSynchronously()
  30765. {
  30766. InternalTimerThread::callAnyTimersSynchronously();
  30767. }
  30768. #ifdef JUCE_DEBUG
  30769. static SortedSet <Timer*> activeTimers;
  30770. #endif
  30771. Timer::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 (const Timer&) throw()
  30782. : countdownMs (0),
  30783. periodMs (0),
  30784. previous (0),
  30785. next (0)
  30786. {
  30787. #ifdef JUCE_DEBUG
  30788. activeTimers.add (this);
  30789. #endif
  30790. }
  30791. Timer::~Timer()
  30792. {
  30793. stopTimer();
  30794. #ifdef JUCE_DEBUG
  30795. activeTimers.removeValue (this);
  30796. #endif
  30797. }
  30798. void Timer::startTimer (const int interval) throw()
  30799. {
  30800. const ScopedLock sl (InternalTimerThread::lock);
  30801. #ifdef JUCE_DEBUG
  30802. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30803. jassert (activeTimers.contains (this));
  30804. #endif
  30805. if (periodMs == 0)
  30806. {
  30807. countdownMs = interval;
  30808. periodMs = jmax (1, interval);
  30809. InternalTimerThread::add (this);
  30810. }
  30811. else
  30812. {
  30813. InternalTimerThread::resetCounter (this, interval);
  30814. }
  30815. }
  30816. void Timer::stopTimer() throw()
  30817. {
  30818. const ScopedLock sl (InternalTimerThread::lock);
  30819. #ifdef JUCE_DEBUG
  30820. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30821. jassert (activeTimers.contains (this));
  30822. #endif
  30823. if (periodMs > 0)
  30824. {
  30825. InternalTimerThread::remove (this);
  30826. periodMs = 0;
  30827. }
  30828. }
  30829. END_JUCE_NAMESPACE
  30830. /*** End of inlined file: juce_Timer.cpp ***/
  30831. #endif
  30832. #if JUCE_BUILD_GUI
  30833. /*** Start of inlined file: juce_Component.cpp ***/
  30834. BEGIN_JUCE_NAMESPACE
  30835. Component* Component::currentlyFocusedComponent = 0;
  30836. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30837. static Array <int> modalReturnValues;
  30838. enum ComponentMessageNumbers
  30839. {
  30840. customCommandMessage = 0x7fff0001,
  30841. exitModalStateMessage = 0x7fff0002
  30842. };
  30843. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30844. static uint32 nextComponentUID = 0;
  30845. Component::Component()
  30846. : parentComponent_ (0),
  30847. componentUID (++nextComponentUID),
  30848. numDeepMouseListeners (0),
  30849. lookAndFeel_ (0),
  30850. effect_ (0),
  30851. bufferedImage_ (0),
  30852. mouseListeners_ (0),
  30853. keyListeners_ (0),
  30854. componentFlags_ (0)
  30855. {
  30856. }
  30857. Component::Component (const String& name)
  30858. : componentName_ (name),
  30859. parentComponent_ (0),
  30860. componentUID (++nextComponentUID),
  30861. numDeepMouseListeners (0),
  30862. lookAndFeel_ (0),
  30863. effect_ (0),
  30864. bufferedImage_ (0),
  30865. mouseListeners_ (0),
  30866. keyListeners_ (0),
  30867. componentFlags_ (0)
  30868. {
  30869. }
  30870. Component::~Component()
  30871. {
  30872. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  30873. if (parentComponent_ != 0)
  30874. {
  30875. parentComponent_->removeChildComponent (this);
  30876. }
  30877. else if ((currentlyFocusedComponent == this)
  30878. || isParentOf (currentlyFocusedComponent))
  30879. {
  30880. giveAwayFocus();
  30881. }
  30882. if (flags.hasHeavyweightPeerFlag)
  30883. removeFromDesktop();
  30884. modalComponentStack.removeValue (this);
  30885. for (int i = childComponentList_.size(); --i >= 0;)
  30886. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  30887. delete bufferedImage_;
  30888. delete mouseListeners_;
  30889. delete keyListeners_;
  30890. }
  30891. void Component::setName (const String& name)
  30892. {
  30893. // if component methods are being called from threads other than the message
  30894. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30895. checkMessageManagerIsLocked
  30896. if (componentName_ != name)
  30897. {
  30898. componentName_ = name;
  30899. if (flags.hasHeavyweightPeerFlag)
  30900. {
  30901. ComponentPeer* const peer = getPeer();
  30902. jassert (peer != 0);
  30903. if (peer != 0)
  30904. peer->setTitle (name);
  30905. }
  30906. BailOutChecker checker (this);
  30907. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  30908. }
  30909. }
  30910. void Component::setVisible (bool shouldBeVisible)
  30911. {
  30912. if (flags.visibleFlag != shouldBeVisible)
  30913. {
  30914. // if component methods are being called from threads other than the message
  30915. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30916. checkMessageManagerIsLocked
  30917. SafePointer<Component> safePointer (this);
  30918. flags.visibleFlag = shouldBeVisible;
  30919. internalRepaint (0, 0, getWidth(), getHeight());
  30920. sendFakeMouseMove();
  30921. if (! shouldBeVisible)
  30922. {
  30923. if (currentlyFocusedComponent == this
  30924. || isParentOf (currentlyFocusedComponent))
  30925. {
  30926. if (parentComponent_ != 0)
  30927. parentComponent_->grabKeyboardFocus();
  30928. else
  30929. giveAwayFocus();
  30930. }
  30931. }
  30932. if (safePointer != 0)
  30933. {
  30934. sendVisibilityChangeMessage();
  30935. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  30936. {
  30937. ComponentPeer* const peer = getPeer();
  30938. jassert (peer != 0);
  30939. if (peer != 0)
  30940. {
  30941. peer->setVisible (shouldBeVisible);
  30942. internalHierarchyChanged();
  30943. }
  30944. }
  30945. }
  30946. }
  30947. }
  30948. void Component::visibilityChanged()
  30949. {
  30950. }
  30951. void Component::sendVisibilityChangeMessage()
  30952. {
  30953. BailOutChecker checker (this);
  30954. visibilityChanged();
  30955. if (! checker.shouldBailOut())
  30956. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  30957. }
  30958. bool Component::isShowing() const
  30959. {
  30960. if (flags.visibleFlag)
  30961. {
  30962. if (parentComponent_ != 0)
  30963. {
  30964. return parentComponent_->isShowing();
  30965. }
  30966. else
  30967. {
  30968. const ComponentPeer* const peer = getPeer();
  30969. return peer != 0 && ! peer->isMinimised();
  30970. }
  30971. }
  30972. return false;
  30973. }
  30974. class FadeOutProxyComponent : public Component,
  30975. public Timer
  30976. {
  30977. public:
  30978. FadeOutProxyComponent (Component* comp,
  30979. const int fadeLengthMs,
  30980. const int deltaXToMove,
  30981. const int deltaYToMove,
  30982. const float scaleFactorAtEnd)
  30983. : lastTime (0),
  30984. alpha (1.0f),
  30985. scale (1.0f)
  30986. {
  30987. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  30988. setBounds (comp->getBounds());
  30989. comp->getParentComponent()->addAndMakeVisible (this);
  30990. toBehind (comp);
  30991. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  30992. centreX = comp->getX() + comp->getWidth() * 0.5f;
  30993. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  30994. centreY = comp->getY() + comp->getHeight() * 0.5f;
  30995. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  30996. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  30997. setInterceptsMouseClicks (false, false);
  30998. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  30999. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31000. }
  31001. ~FadeOutProxyComponent()
  31002. {
  31003. delete image;
  31004. }
  31005. void paint (Graphics& g)
  31006. {
  31007. g.setOpacity (alpha);
  31008. g.drawImage (image,
  31009. 0, 0, getWidth(), getHeight(),
  31010. 0, 0, image->getWidth(), image->getHeight());
  31011. }
  31012. void timerCallback()
  31013. {
  31014. const uint32 now = Time::getMillisecondCounter();
  31015. if (lastTime == 0)
  31016. lastTime = now;
  31017. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31018. lastTime = now;
  31019. alpha += alphaChangePerMs * msPassed;
  31020. if (alpha > 0)
  31021. {
  31022. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31023. {
  31024. centreX += xChangePerMs * msPassed;
  31025. centreY += yChangePerMs * msPassed;
  31026. scale += scaleChangePerMs * msPassed;
  31027. const int w = roundToInt (image->getWidth() * scale);
  31028. const int h = roundToInt (image->getHeight() * scale);
  31029. setBounds (roundToInt (centreX) - w / 2,
  31030. roundToInt (centreY) - h / 2,
  31031. w, h);
  31032. }
  31033. repaint();
  31034. }
  31035. else
  31036. {
  31037. delete this;
  31038. }
  31039. }
  31040. juce_UseDebuggingNewOperator
  31041. private:
  31042. Image* image;
  31043. uint32 lastTime;
  31044. float alpha, alphaChangePerMs;
  31045. float centreX, xChangePerMs;
  31046. float centreY, yChangePerMs;
  31047. float scale, scaleChangePerMs;
  31048. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31049. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31050. };
  31051. void Component::fadeOutComponent (const int millisecondsToFade,
  31052. const int deltaXToMove,
  31053. const int deltaYToMove,
  31054. const float scaleFactorAtEnd)
  31055. {
  31056. //xxx won't work for comps without parents
  31057. if (isShowing() && millisecondsToFade > 0)
  31058. new FadeOutProxyComponent (this, millisecondsToFade,
  31059. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31060. setVisible (false);
  31061. }
  31062. bool Component::isValidComponent() const
  31063. {
  31064. return (this != 0) && isValidMessageListener();
  31065. }
  31066. void* Component::getWindowHandle() const
  31067. {
  31068. const ComponentPeer* const peer = getPeer();
  31069. if (peer != 0)
  31070. return peer->getNativeHandle();
  31071. return 0;
  31072. }
  31073. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31074. {
  31075. // if component methods are being called from threads other than the message
  31076. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31077. checkMessageManagerIsLocked
  31078. if (isOpaque())
  31079. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31080. else
  31081. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31082. int currentStyleFlags = 0;
  31083. // don't use getPeer(), so that we only get the peer that's specifically
  31084. // for this comp, and not for one of its parents.
  31085. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31086. if (peer != 0)
  31087. currentStyleFlags = peer->getStyleFlags();
  31088. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31089. {
  31090. SafePointer<Component> safePointer (this);
  31091. #if JUCE_LINUX
  31092. // it's wise to give the component a non-zero size before
  31093. // putting it on the desktop, as X windows get confused by this, and
  31094. // a (1, 1) minimum size is enforced here.
  31095. setSize (jmax (1, getWidth()),
  31096. jmax (1, getHeight()));
  31097. #endif
  31098. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31099. bool wasFullscreen = false;
  31100. bool wasMinimised = false;
  31101. ComponentBoundsConstrainer* currentConstainer = 0;
  31102. Rectangle<int> oldNonFullScreenBounds;
  31103. if (peer != 0)
  31104. {
  31105. wasFullscreen = peer->isFullScreen();
  31106. wasMinimised = peer->isMinimised();
  31107. currentConstainer = peer->getConstrainer();
  31108. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31109. removeFromDesktop();
  31110. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31111. }
  31112. if (parentComponent_ != 0)
  31113. parentComponent_->removeChildComponent (this);
  31114. if (safePointer != 0)
  31115. {
  31116. flags.hasHeavyweightPeerFlag = true;
  31117. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31118. Desktop::getInstance().addDesktopComponent (this);
  31119. bounds_.setPosition (topLeft);
  31120. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31121. peer->setVisible (isVisible());
  31122. if (wasFullscreen)
  31123. {
  31124. peer->setFullScreen (true);
  31125. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31126. }
  31127. if (wasMinimised)
  31128. peer->setMinimised (true);
  31129. if (isAlwaysOnTop())
  31130. peer->setAlwaysOnTop (true);
  31131. peer->setConstrainer (currentConstainer);
  31132. repaint();
  31133. }
  31134. internalHierarchyChanged();
  31135. }
  31136. }
  31137. void Component::removeFromDesktop()
  31138. {
  31139. // if component methods are being called from threads other than the message
  31140. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31141. checkMessageManagerIsLocked
  31142. if (flags.hasHeavyweightPeerFlag)
  31143. {
  31144. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31145. flags.hasHeavyweightPeerFlag = false;
  31146. jassert (peer != 0);
  31147. delete peer;
  31148. Desktop::getInstance().removeDesktopComponent (this);
  31149. }
  31150. }
  31151. bool Component::isOnDesktop() const throw()
  31152. {
  31153. return flags.hasHeavyweightPeerFlag;
  31154. }
  31155. void Component::userTriedToCloseWindow()
  31156. {
  31157. /* This means that the user's trying to get rid of your window with the 'close window' system
  31158. menu option (on windows) or possibly the task manager - you should really handle this
  31159. and delete or hide your component in an appropriate way.
  31160. If you want to ignore the event and don't want to trigger this assertion, just override
  31161. this method and do nothing.
  31162. */
  31163. jassertfalse
  31164. }
  31165. void Component::minimisationStateChanged (bool)
  31166. {
  31167. }
  31168. void Component::setOpaque (const bool shouldBeOpaque)
  31169. {
  31170. if (shouldBeOpaque != flags.opaqueFlag)
  31171. {
  31172. flags.opaqueFlag = shouldBeOpaque;
  31173. if (flags.hasHeavyweightPeerFlag)
  31174. {
  31175. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31176. if (peer != 0)
  31177. {
  31178. // to make it recreate the heavyweight window
  31179. addToDesktop (peer->getStyleFlags());
  31180. }
  31181. }
  31182. repaint();
  31183. }
  31184. }
  31185. bool Component::isOpaque() const throw()
  31186. {
  31187. return flags.opaqueFlag;
  31188. }
  31189. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31190. {
  31191. if (shouldBeBuffered != flags.bufferToImageFlag)
  31192. {
  31193. deleteAndZero (bufferedImage_);
  31194. flags.bufferToImageFlag = shouldBeBuffered;
  31195. }
  31196. }
  31197. void Component::toFront (const bool setAsForeground)
  31198. {
  31199. // if component methods are being called from threads other than the message
  31200. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31201. checkMessageManagerIsLocked
  31202. if (flags.hasHeavyweightPeerFlag)
  31203. {
  31204. ComponentPeer* const peer = getPeer();
  31205. if (peer != 0)
  31206. {
  31207. peer->toFront (setAsForeground);
  31208. if (setAsForeground && ! hasKeyboardFocus (true))
  31209. grabKeyboardFocus();
  31210. }
  31211. }
  31212. else if (parentComponent_ != 0)
  31213. {
  31214. if (parentComponent_->childComponentList_.getLast() != this)
  31215. {
  31216. const int index = parentComponent_->childComponentList_.indexOf (this);
  31217. if (index >= 0)
  31218. {
  31219. int insertIndex = -1;
  31220. if (! flags.alwaysOnTopFlag)
  31221. {
  31222. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31223. while (insertIndex > 0
  31224. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31225. {
  31226. --insertIndex;
  31227. }
  31228. }
  31229. if (index != insertIndex)
  31230. {
  31231. parentComponent_->childComponentList_.move (index, insertIndex);
  31232. sendFakeMouseMove();
  31233. repaintParent();
  31234. }
  31235. }
  31236. }
  31237. if (setAsForeground)
  31238. {
  31239. internalBroughtToFront();
  31240. grabKeyboardFocus();
  31241. }
  31242. }
  31243. }
  31244. void Component::toBehind (Component* const other)
  31245. {
  31246. if (other != 0)
  31247. {
  31248. // the two components must belong to the same parent..
  31249. jassert (parentComponent_ == other->parentComponent_);
  31250. if (parentComponent_ != 0)
  31251. {
  31252. const int index = parentComponent_->childComponentList_.indexOf (this);
  31253. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31254. if (index >= 0
  31255. && otherIndex >= 0
  31256. && index != otherIndex - 1
  31257. && other != this)
  31258. {
  31259. if (index < otherIndex)
  31260. --otherIndex;
  31261. parentComponent_->childComponentList_.move (index, otherIndex);
  31262. sendFakeMouseMove();
  31263. repaintParent();
  31264. }
  31265. }
  31266. else if (isOnDesktop())
  31267. {
  31268. jassert (other->isOnDesktop());
  31269. if (other->isOnDesktop())
  31270. {
  31271. ComponentPeer* const us = getPeer();
  31272. ComponentPeer* const them = other->getPeer();
  31273. jassert (us != 0 && them != 0);
  31274. if (us != 0 && them != 0)
  31275. us->toBehind (them);
  31276. }
  31277. }
  31278. }
  31279. }
  31280. void Component::toBack()
  31281. {
  31282. if (isOnDesktop())
  31283. {
  31284. jassertfalse //xxx need to add this to native window
  31285. }
  31286. else if (parentComponent_ != 0
  31287. && parentComponent_->childComponentList_.getFirst() != this)
  31288. {
  31289. const int index = parentComponent_->childComponentList_.indexOf (this);
  31290. if (index > 0)
  31291. {
  31292. int insertIndex = 0;
  31293. if (flags.alwaysOnTopFlag)
  31294. {
  31295. while (insertIndex < parentComponent_->childComponentList_.size()
  31296. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31297. {
  31298. ++insertIndex;
  31299. }
  31300. }
  31301. if (index != insertIndex)
  31302. {
  31303. parentComponent_->childComponentList_.move (index, insertIndex);
  31304. sendFakeMouseMove();
  31305. repaintParent();
  31306. }
  31307. }
  31308. }
  31309. }
  31310. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31311. {
  31312. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31313. {
  31314. flags.alwaysOnTopFlag = shouldStayOnTop;
  31315. if (isOnDesktop())
  31316. {
  31317. ComponentPeer* const peer = getPeer();
  31318. jassert (peer != 0);
  31319. if (peer != 0)
  31320. {
  31321. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31322. {
  31323. // some kinds of peer can't change their always-on-top status, so
  31324. // for these, we'll need to create a new window
  31325. const int oldFlags = peer->getStyleFlags();
  31326. removeFromDesktop();
  31327. addToDesktop (oldFlags);
  31328. }
  31329. }
  31330. }
  31331. if (shouldStayOnTop)
  31332. toFront (false);
  31333. internalHierarchyChanged();
  31334. }
  31335. }
  31336. bool Component::isAlwaysOnTop() const throw()
  31337. {
  31338. return flags.alwaysOnTopFlag;
  31339. }
  31340. int Component::proportionOfWidth (const float proportion) const throw()
  31341. {
  31342. return roundToInt (proportion * bounds_.getWidth());
  31343. }
  31344. int Component::proportionOfHeight (const float proportion) const throw()
  31345. {
  31346. return roundToInt (proportion * bounds_.getHeight());
  31347. }
  31348. int Component::getParentWidth() const throw()
  31349. {
  31350. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31351. : getParentMonitorArea().getWidth();
  31352. }
  31353. int Component::getParentHeight() const throw()
  31354. {
  31355. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31356. : getParentMonitorArea().getHeight();
  31357. }
  31358. int Component::getScreenX() const
  31359. {
  31360. return getScreenPosition().getX();
  31361. }
  31362. int Component::getScreenY() const
  31363. {
  31364. return getScreenPosition().getY();
  31365. }
  31366. const Point<int> Component::getScreenPosition() const
  31367. {
  31368. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31369. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31370. : getPosition());
  31371. }
  31372. const Rectangle<int> Component::getScreenBounds() const
  31373. {
  31374. return bounds_.withPosition (getScreenPosition());
  31375. }
  31376. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31377. {
  31378. const Component* c = this;
  31379. Point<int> p (relativePosition);
  31380. do
  31381. {
  31382. if (c->flags.hasHeavyweightPeerFlag)
  31383. return c->getPeer()->relativePositionToGlobal (p);
  31384. p += c->getPosition();
  31385. c = c->parentComponent_;
  31386. }
  31387. while (c != 0);
  31388. return p;
  31389. }
  31390. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31391. {
  31392. if (flags.hasHeavyweightPeerFlag)
  31393. {
  31394. return getPeer()->globalPositionToRelative (screenPosition);
  31395. }
  31396. else
  31397. {
  31398. if (parentComponent_ != 0)
  31399. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31400. return screenPosition - getPosition();
  31401. }
  31402. }
  31403. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31404. {
  31405. Point<int> p (positionRelativeToThis);
  31406. if (targetComponent != 0)
  31407. {
  31408. const Component* c = this;
  31409. do
  31410. {
  31411. if (c == targetComponent)
  31412. return p;
  31413. if (c->flags.hasHeavyweightPeerFlag)
  31414. {
  31415. p = c->getPeer()->relativePositionToGlobal (p);
  31416. break;
  31417. }
  31418. p += c->getPosition();
  31419. c = c->parentComponent_;
  31420. }
  31421. while (c != 0);
  31422. p = targetComponent->globalPositionToRelative (p);
  31423. }
  31424. return p;
  31425. }
  31426. void Component::setBounds (int x, int y, int w, int h)
  31427. {
  31428. // if component methods are being called from threads other than the message
  31429. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31430. checkMessageManagerIsLocked
  31431. if (w < 0) w = 0;
  31432. if (h < 0) h = 0;
  31433. const bool wasResized = (getWidth() != w || getHeight() != h);
  31434. const bool wasMoved = (getX() != x || getY() != y);
  31435. #ifdef JUCE_DEBUG
  31436. // It's a very bad idea to try to resize a window during its paint() method!
  31437. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31438. #endif
  31439. if (wasMoved || wasResized)
  31440. {
  31441. if (flags.visibleFlag)
  31442. {
  31443. // send a fake mouse move to trigger enter/exit messages if needed..
  31444. sendFakeMouseMove();
  31445. if (! flags.hasHeavyweightPeerFlag)
  31446. repaintParent();
  31447. }
  31448. bounds_.setBounds (x, y, w, h);
  31449. if (wasResized)
  31450. repaint();
  31451. else if (! flags.hasHeavyweightPeerFlag)
  31452. repaintParent();
  31453. if (flags.hasHeavyweightPeerFlag)
  31454. {
  31455. ComponentPeer* const peer = getPeer();
  31456. if (peer != 0)
  31457. {
  31458. if (wasMoved && wasResized)
  31459. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31460. else if (wasMoved)
  31461. peer->setPosition (getX(), getY());
  31462. else if (wasResized)
  31463. peer->setSize (getWidth(), getHeight());
  31464. }
  31465. }
  31466. sendMovedResizedMessages (wasMoved, wasResized);
  31467. }
  31468. }
  31469. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31470. {
  31471. JUCE_TRY
  31472. {
  31473. if (wasMoved)
  31474. moved();
  31475. if (wasResized)
  31476. {
  31477. resized();
  31478. for (int i = childComponentList_.size(); --i >= 0;)
  31479. {
  31480. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31481. i = jmin (i, childComponentList_.size());
  31482. }
  31483. }
  31484. BailOutChecker checker (this);
  31485. if (parentComponent_ != 0)
  31486. parentComponent_->childBoundsChanged (this);
  31487. if (! checker.shouldBailOut())
  31488. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31489. *this, wasMoved, wasResized);
  31490. }
  31491. JUCE_CATCH_EXCEPTION
  31492. }
  31493. void Component::setSize (const int w, const int h)
  31494. {
  31495. setBounds (getX(), getY(), w, h);
  31496. }
  31497. void Component::setTopLeftPosition (const int x, const int y)
  31498. {
  31499. setBounds (x, y, getWidth(), getHeight());
  31500. }
  31501. void Component::setTopRightPosition (const int x, const int y)
  31502. {
  31503. setTopLeftPosition (x - getWidth(), y);
  31504. }
  31505. void Component::setBounds (const Rectangle<int>& r)
  31506. {
  31507. setBounds (r.getX(),
  31508. r.getY(),
  31509. r.getWidth(),
  31510. r.getHeight());
  31511. }
  31512. void Component::setBoundsRelative (const float x, const float y,
  31513. const float w, const float h)
  31514. {
  31515. const int pw = getParentWidth();
  31516. const int ph = getParentHeight();
  31517. setBounds (roundToInt (x * pw),
  31518. roundToInt (y * ph),
  31519. roundToInt (w * pw),
  31520. roundToInt (h * ph));
  31521. }
  31522. void Component::setCentrePosition (const int x, const int y)
  31523. {
  31524. setTopLeftPosition (x - getWidth() / 2,
  31525. y - getHeight() / 2);
  31526. }
  31527. void Component::setCentreRelative (const float x, const float y)
  31528. {
  31529. setCentrePosition (roundToInt (getParentWidth() * x),
  31530. roundToInt (getParentHeight() * y));
  31531. }
  31532. void Component::centreWithSize (const int width, const int height)
  31533. {
  31534. setBounds ((getParentWidth() - width) / 2,
  31535. (getParentHeight() - height) / 2,
  31536. width,
  31537. height);
  31538. }
  31539. void Component::setBoundsInset (const BorderSize& borders)
  31540. {
  31541. setBounds (borders.getLeft(),
  31542. borders.getTop(),
  31543. getParentWidth() - (borders.getLeftAndRight()),
  31544. getParentHeight() - (borders.getTopAndBottom()));
  31545. }
  31546. void Component::setBoundsToFit (int x, int y, int width, int height,
  31547. const Justification& justification,
  31548. const bool onlyReduceInSize)
  31549. {
  31550. // it's no good calling this method unless both the component and
  31551. // target rectangle have a finite size.
  31552. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31553. if (getWidth() > 0 && getHeight() > 0
  31554. && width > 0 && height > 0)
  31555. {
  31556. int newW, newH;
  31557. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31558. {
  31559. newW = getWidth();
  31560. newH = getHeight();
  31561. }
  31562. else
  31563. {
  31564. const double imageRatio = getHeight() / (double) getWidth();
  31565. const double targetRatio = height / (double) width;
  31566. if (imageRatio <= targetRatio)
  31567. {
  31568. newW = width;
  31569. newH = jmin (height, roundToInt (newW * imageRatio));
  31570. }
  31571. else
  31572. {
  31573. newH = height;
  31574. newW = jmin (width, roundToInt (newH / imageRatio));
  31575. }
  31576. }
  31577. if (newW > 0 && newH > 0)
  31578. {
  31579. int newX, newY;
  31580. justification.applyToRectangle (newX, newY, newW, newH,
  31581. x, y, width, height);
  31582. setBounds (newX, newY, newW, newH);
  31583. }
  31584. }
  31585. }
  31586. bool Component::hitTest (int x, int y)
  31587. {
  31588. if (! flags.ignoresMouseClicksFlag)
  31589. return true;
  31590. if (flags.allowChildMouseClicksFlag)
  31591. {
  31592. for (int i = getNumChildComponents(); --i >= 0;)
  31593. {
  31594. Component* const c = getChildComponent (i);
  31595. if (c->isVisible()
  31596. && c->bounds_.contains (x, y)
  31597. && c->hitTest (x - c->getX(),
  31598. y - c->getY()))
  31599. {
  31600. return true;
  31601. }
  31602. }
  31603. }
  31604. return false;
  31605. }
  31606. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31607. const bool allowClicksOnChildComponents) throw()
  31608. {
  31609. flags.ignoresMouseClicksFlag = ! allowClicks;
  31610. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31611. }
  31612. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31613. bool& allowsClicksOnChildComponents) const throw()
  31614. {
  31615. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31616. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31617. }
  31618. bool Component::contains (const int x, const int y)
  31619. {
  31620. if (((unsigned int) x) < (unsigned int) getWidth()
  31621. && ((unsigned int) y) < (unsigned int) getHeight()
  31622. && hitTest (x, y))
  31623. {
  31624. if (parentComponent_ != 0)
  31625. {
  31626. return parentComponent_->contains (x + getX(),
  31627. y + getY());
  31628. }
  31629. else if (flags.hasHeavyweightPeerFlag)
  31630. {
  31631. const ComponentPeer* const peer = getPeer();
  31632. if (peer != 0)
  31633. return peer->contains (Point<int> (x, y), true);
  31634. }
  31635. }
  31636. return false;
  31637. }
  31638. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31639. {
  31640. if (! contains (x, y))
  31641. return false;
  31642. Component* p = this;
  31643. while (p->parentComponent_ != 0)
  31644. {
  31645. x += p->getX();
  31646. y += p->getY();
  31647. p = p->parentComponent_;
  31648. }
  31649. const Component* const c = p->getComponentAt (x, y);
  31650. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31651. }
  31652. Component* Component::getComponentAt (const Point<int>& position)
  31653. {
  31654. return getComponentAt (position.getX(), position.getY());
  31655. }
  31656. Component* Component::getComponentAt (const int x, const int y)
  31657. {
  31658. if (flags.visibleFlag
  31659. && ((unsigned int) x) < (unsigned int) getWidth()
  31660. && ((unsigned int) y) < (unsigned int) getHeight()
  31661. && hitTest (x, y))
  31662. {
  31663. for (int i = childComponentList_.size(); --i >= 0;)
  31664. {
  31665. Component* const child = childComponentList_.getUnchecked(i);
  31666. Component* const c = child->getComponentAt (x - child->getX(),
  31667. y - child->getY());
  31668. if (c != 0)
  31669. return c;
  31670. }
  31671. return this;
  31672. }
  31673. return 0;
  31674. }
  31675. void Component::addChildComponent (Component* const child, int zOrder)
  31676. {
  31677. // if component methods are being called from threads other than the message
  31678. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31679. checkMessageManagerIsLocked
  31680. if (child != 0 && child->parentComponent_ != this)
  31681. {
  31682. if (child->parentComponent_ != 0)
  31683. child->parentComponent_->removeChildComponent (child);
  31684. else
  31685. child->removeFromDesktop();
  31686. child->parentComponent_ = this;
  31687. if (child->isVisible())
  31688. child->repaintParent();
  31689. if (! child->isAlwaysOnTop())
  31690. {
  31691. if (zOrder < 0 || zOrder > childComponentList_.size())
  31692. zOrder = childComponentList_.size();
  31693. while (zOrder > 0)
  31694. {
  31695. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31696. break;
  31697. --zOrder;
  31698. }
  31699. }
  31700. childComponentList_.insert (zOrder, child);
  31701. child->internalHierarchyChanged();
  31702. internalChildrenChanged();
  31703. }
  31704. }
  31705. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31706. {
  31707. if (child != 0)
  31708. {
  31709. child->setVisible (true);
  31710. addChildComponent (child, zOrder);
  31711. }
  31712. }
  31713. void Component::removeChildComponent (Component* const child)
  31714. {
  31715. removeChildComponent (childComponentList_.indexOf (child));
  31716. }
  31717. Component* Component::removeChildComponent (const int index)
  31718. {
  31719. // if component methods are being called from threads other than the message
  31720. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31721. checkMessageManagerIsLocked
  31722. Component* const child = childComponentList_ [index];
  31723. if (child != 0)
  31724. {
  31725. sendFakeMouseMove();
  31726. child->repaintParent();
  31727. childComponentList_.remove (index);
  31728. child->parentComponent_ = 0;
  31729. JUCE_TRY
  31730. {
  31731. if ((currentlyFocusedComponent == child)
  31732. || child->isParentOf (currentlyFocusedComponent))
  31733. {
  31734. // get rid first to force the grabKeyboardFocus to change to us.
  31735. giveAwayFocus();
  31736. grabKeyboardFocus();
  31737. }
  31738. }
  31739. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31740. catch (const std::exception& e)
  31741. {
  31742. currentlyFocusedComponent = 0;
  31743. Desktop::getInstance().triggerFocusCallback();
  31744. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31745. }
  31746. catch (...)
  31747. {
  31748. currentlyFocusedComponent = 0;
  31749. Desktop::getInstance().triggerFocusCallback();
  31750. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31751. }
  31752. #endif
  31753. child->internalHierarchyChanged();
  31754. internalChildrenChanged();
  31755. }
  31756. return child;
  31757. }
  31758. void Component::removeAllChildren()
  31759. {
  31760. for (int i = childComponentList_.size(); --i >= 0;)
  31761. removeChildComponent (i);
  31762. }
  31763. void Component::deleteAllChildren()
  31764. {
  31765. for (int i = childComponentList_.size(); --i >= 0;)
  31766. delete (removeChildComponent (i));
  31767. }
  31768. int Component::getNumChildComponents() const throw()
  31769. {
  31770. return childComponentList_.size();
  31771. }
  31772. Component* Component::getChildComponent (const int index) const throw()
  31773. {
  31774. return childComponentList_ [index];
  31775. }
  31776. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31777. {
  31778. return childComponentList_.indexOf (const_cast <Component*> (child));
  31779. }
  31780. Component* Component::getTopLevelComponent() const throw()
  31781. {
  31782. const Component* comp = this;
  31783. while (comp->parentComponent_ != 0)
  31784. comp = comp->parentComponent_;
  31785. return const_cast <Component*> (comp);
  31786. }
  31787. bool Component::isParentOf (const Component* possibleChild) const throw()
  31788. {
  31789. if (! possibleChild->isValidComponent())
  31790. {
  31791. jassert (possibleChild == 0);
  31792. return false;
  31793. }
  31794. while (possibleChild != 0)
  31795. {
  31796. possibleChild = possibleChild->parentComponent_;
  31797. if (possibleChild == this)
  31798. return true;
  31799. }
  31800. return false;
  31801. }
  31802. void Component::parentHierarchyChanged()
  31803. {
  31804. }
  31805. void Component::childrenChanged()
  31806. {
  31807. }
  31808. void Component::internalChildrenChanged()
  31809. {
  31810. if (componentListeners.isEmpty())
  31811. {
  31812. childrenChanged();
  31813. }
  31814. else
  31815. {
  31816. BailOutChecker checker (this);
  31817. childrenChanged();
  31818. if (! checker.shouldBailOut())
  31819. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31820. }
  31821. }
  31822. void Component::internalHierarchyChanged()
  31823. {
  31824. BailOutChecker checker (this);
  31825. parentHierarchyChanged();
  31826. if (checker.shouldBailOut())
  31827. return;
  31828. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31829. if (checker.shouldBailOut())
  31830. return;
  31831. for (int i = childComponentList_.size(); --i >= 0;)
  31832. {
  31833. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31834. if (checker.shouldBailOut())
  31835. {
  31836. // you really shouldn't delete the parent component during a callback telling you
  31837. // that it's changed..
  31838. jassertfalse;
  31839. return;
  31840. }
  31841. i = jmin (i, childComponentList_.size());
  31842. }
  31843. }
  31844. void* Component::runModalLoopCallback (void* userData)
  31845. {
  31846. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  31847. }
  31848. int Component::runModalLoop()
  31849. {
  31850. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31851. {
  31852. // use a callback so this can be called from non-gui threads
  31853. return (int) (pointer_sized_int)
  31854. MessageManager::getInstance()
  31855. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  31856. }
  31857. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31858. if (! isCurrentlyModal())
  31859. enterModalState();
  31860. JUCE_TRY
  31861. {
  31862. while (flags.currentlyModalFlag && flags.visibleFlag)
  31863. {
  31864. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31865. break;
  31866. // check whether this component was deleted during the last message
  31867. if (! isValidMessageListener())
  31868. break;
  31869. }
  31870. }
  31871. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31872. catch (const std::exception& e)
  31873. {
  31874. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31875. return 0;
  31876. }
  31877. catch (...)
  31878. {
  31879. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31880. return 0;
  31881. }
  31882. #endif
  31883. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31884. int returnValue = 0;
  31885. if (modalIndex >= 0)
  31886. {
  31887. modalComponentReturnValueKeys.remove (modalIndex);
  31888. returnValue = modalReturnValues.remove (modalIndex);
  31889. }
  31890. modalComponentStack.removeValue (this);
  31891. if (prevFocused != 0)
  31892. prevFocused->grabKeyboardFocus();
  31893. return returnValue;
  31894. }
  31895. void Component::enterModalState (const bool takeKeyboardFocus_)
  31896. {
  31897. // if component methods are being called from threads other than the message
  31898. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31899. checkMessageManagerIsLocked
  31900. // Check for an attempt to make a component modal when it already is!
  31901. // This can cause nasty problems..
  31902. jassert (! flags.currentlyModalFlag);
  31903. if (! isCurrentlyModal())
  31904. {
  31905. modalComponentStack.add (this);
  31906. modalComponentReturnValueKeys.add (this);
  31907. modalReturnValues.add (0);
  31908. flags.currentlyModalFlag = true;
  31909. setVisible (true);
  31910. if (takeKeyboardFocus_)
  31911. grabKeyboardFocus();
  31912. }
  31913. }
  31914. void Component::exitModalState (const int returnValue)
  31915. {
  31916. if (isCurrentlyModal())
  31917. {
  31918. if (MessageManager::getInstance()->isThisTheMessageThread())
  31919. {
  31920. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31921. if (modalIndex >= 0)
  31922. {
  31923. modalReturnValues.set (modalIndex, returnValue);
  31924. }
  31925. else
  31926. {
  31927. modalComponentReturnValueKeys.add (this);
  31928. modalReturnValues.add (returnValue);
  31929. }
  31930. modalComponentStack.removeValue (this);
  31931. flags.currentlyModalFlag = false;
  31932. bringModalComponentToFront();
  31933. }
  31934. else
  31935. {
  31936. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  31937. }
  31938. }
  31939. }
  31940. bool Component::isCurrentlyModal() const throw()
  31941. {
  31942. return flags.currentlyModalFlag
  31943. && getCurrentlyModalComponent() == this;
  31944. }
  31945. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  31946. {
  31947. Component* const mc = getCurrentlyModalComponent();
  31948. return mc != 0
  31949. && mc != this
  31950. && (! mc->isParentOf (this))
  31951. && ! mc->canModalEventBeSentToComponent (this);
  31952. }
  31953. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  31954. {
  31955. return modalComponentStack.size();
  31956. }
  31957. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  31958. {
  31959. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  31960. return c->isValidComponent() ? c : 0;
  31961. }
  31962. void Component::bringModalComponentToFront()
  31963. {
  31964. ComponentPeer* lastOne = 0;
  31965. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  31966. {
  31967. Component* const c = getCurrentlyModalComponent (i);
  31968. if (c == 0)
  31969. break;
  31970. ComponentPeer* peer = c->getPeer();
  31971. if (peer != 0 && peer != lastOne)
  31972. {
  31973. if (lastOne == 0)
  31974. {
  31975. peer->toFront (true);
  31976. peer->grabFocus();
  31977. }
  31978. else
  31979. peer->toBehind (lastOne);
  31980. lastOne = peer;
  31981. }
  31982. }
  31983. }
  31984. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  31985. {
  31986. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  31987. }
  31988. bool Component::isBroughtToFrontOnMouseClick() const throw()
  31989. {
  31990. return flags.bringToFrontOnClickFlag;
  31991. }
  31992. void Component::setMouseCursor (const MouseCursor& cursor)
  31993. {
  31994. if (cursor_ != cursor)
  31995. {
  31996. cursor_ = cursor;
  31997. if (flags.visibleFlag)
  31998. updateMouseCursor();
  31999. }
  32000. }
  32001. const MouseCursor Component::getMouseCursor()
  32002. {
  32003. return cursor_;
  32004. }
  32005. void Component::updateMouseCursor() const
  32006. {
  32007. sendFakeMouseMove();
  32008. }
  32009. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32010. {
  32011. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32012. }
  32013. void Component::repaintParent()
  32014. {
  32015. if (flags.visibleFlag)
  32016. internalRepaint (0, 0, getWidth(), getHeight());
  32017. }
  32018. void Component::repaint()
  32019. {
  32020. repaint (0, 0, getWidth(), getHeight());
  32021. }
  32022. void Component::repaint (const int x, const int y,
  32023. const int w, const int h)
  32024. {
  32025. deleteAndZero (bufferedImage_);
  32026. if (flags.visibleFlag)
  32027. internalRepaint (x, y, w, h);
  32028. }
  32029. void Component::internalRepaint (int x, int y, int w, int h)
  32030. {
  32031. // if component methods are being called from threads other than the message
  32032. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32033. checkMessageManagerIsLocked
  32034. if (x < 0)
  32035. {
  32036. w += x;
  32037. x = 0;
  32038. }
  32039. if (x + w > getWidth())
  32040. w = getWidth() - x;
  32041. if (w > 0)
  32042. {
  32043. if (y < 0)
  32044. {
  32045. h += y;
  32046. y = 0;
  32047. }
  32048. if (y + h > getHeight())
  32049. h = getHeight() - y;
  32050. if (h > 0)
  32051. {
  32052. if (parentComponent_ != 0)
  32053. {
  32054. x += getX();
  32055. y += getY();
  32056. if (parentComponent_->flags.visibleFlag)
  32057. parentComponent_->internalRepaint (x, y, w, h);
  32058. }
  32059. else if (flags.hasHeavyweightPeerFlag)
  32060. {
  32061. ComponentPeer* const peer = getPeer();
  32062. if (peer != 0)
  32063. peer->repaint (x, y, w, h);
  32064. }
  32065. }
  32066. }
  32067. }
  32068. void Component::renderComponent (Graphics& g)
  32069. {
  32070. const Rectangle<int> clipBounds (g.getClipBounds());
  32071. g.saveState();
  32072. clipObscuredRegions (g, clipBounds, 0, 0);
  32073. if (! g.isClipEmpty())
  32074. {
  32075. if (flags.bufferToImageFlag)
  32076. {
  32077. if (bufferedImage_ == 0)
  32078. {
  32079. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32080. getWidth(), getHeight(), ! flags.opaqueFlag);
  32081. Graphics imG (*bufferedImage_);
  32082. paint (imG);
  32083. }
  32084. g.setColour (Colours::black);
  32085. g.drawImageAt (bufferedImage_, 0, 0);
  32086. }
  32087. else
  32088. {
  32089. paint (g);
  32090. }
  32091. }
  32092. g.restoreState();
  32093. for (int i = 0; i < childComponentList_.size(); ++i)
  32094. {
  32095. Component* const child = childComponentList_.getUnchecked (i);
  32096. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32097. {
  32098. g.saveState();
  32099. if (g.reduceClipRegion (child->getX(), child->getY(),
  32100. child->getWidth(), child->getHeight()))
  32101. {
  32102. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32103. {
  32104. const Component* const sibling = childComponentList_.getUnchecked (j);
  32105. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32106. g.excludeClipRegion (sibling->getBounds());
  32107. }
  32108. if (! g.isClipEmpty())
  32109. {
  32110. g.setOrigin (child->getX(), child->getY());
  32111. child->paintEntireComponent (g);
  32112. }
  32113. }
  32114. g.restoreState();
  32115. }
  32116. }
  32117. g.saveState();
  32118. paintOverChildren (g);
  32119. g.restoreState();
  32120. }
  32121. void Component::paintEntireComponent (Graphics& g)
  32122. {
  32123. jassert (! g.isClipEmpty());
  32124. #ifdef JUCE_DEBUG
  32125. flags.isInsidePaintCall = true;
  32126. #endif
  32127. if (effect_ != 0)
  32128. {
  32129. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32130. getWidth(), getHeight(),
  32131. ! flags.opaqueFlag));
  32132. {
  32133. Graphics g2 (*effectImage);
  32134. renderComponent (g2);
  32135. }
  32136. effect_->applyEffect (*effectImage, g);
  32137. }
  32138. else
  32139. {
  32140. renderComponent (g);
  32141. }
  32142. #ifdef JUCE_DEBUG
  32143. flags.isInsidePaintCall = false;
  32144. #endif
  32145. }
  32146. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32147. const bool clipImageToComponentBounds)
  32148. {
  32149. Rectangle<int> r (areaToGrab);
  32150. if (clipImageToComponentBounds)
  32151. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32152. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32153. jmax (1, r.getWidth()),
  32154. jmax (1, r.getHeight()),
  32155. true));
  32156. Graphics imageContext (*componentImage);
  32157. imageContext.setOrigin (-r.getX(), -r.getY());
  32158. paintEntireComponent (imageContext);
  32159. return componentImage.release();
  32160. }
  32161. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32162. {
  32163. if (effect_ != effect)
  32164. {
  32165. effect_ = effect;
  32166. repaint();
  32167. }
  32168. }
  32169. LookAndFeel& Component::getLookAndFeel() const throw()
  32170. {
  32171. const Component* c = this;
  32172. do
  32173. {
  32174. if (c->lookAndFeel_ != 0)
  32175. return *(c->lookAndFeel_);
  32176. c = c->parentComponent_;
  32177. }
  32178. while (c != 0);
  32179. return LookAndFeel::getDefaultLookAndFeel();
  32180. }
  32181. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32182. {
  32183. if (lookAndFeel_ != newLookAndFeel)
  32184. {
  32185. lookAndFeel_ = newLookAndFeel;
  32186. sendLookAndFeelChange();
  32187. }
  32188. }
  32189. void Component::lookAndFeelChanged()
  32190. {
  32191. }
  32192. void Component::sendLookAndFeelChange()
  32193. {
  32194. repaint();
  32195. lookAndFeelChanged();
  32196. // (it's not a great idea to do anything that would delete this component
  32197. // during the lookAndFeelChanged() callback)
  32198. jassert (isValidComponent());
  32199. SafePointer<Component> safePointer (this);
  32200. for (int i = childComponentList_.size(); --i >= 0;)
  32201. {
  32202. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32203. if (safePointer == 0)
  32204. return;
  32205. i = jmin (i, childComponentList_.size());
  32206. }
  32207. }
  32208. static const var::identifier getColourPropertyId (const int colourId)
  32209. {
  32210. String s;
  32211. s.preallocateStorage (18);
  32212. s << "jcclr_" << String::toHexString (colourId);
  32213. return s;
  32214. }
  32215. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32216. {
  32217. var* v = properties.getItem (getColourPropertyId (colourId));
  32218. if (v != 0)
  32219. return Colour ((int) *v);
  32220. if (inheritFromParent && parentComponent_ != 0)
  32221. return parentComponent_->findColour (colourId, true);
  32222. return getLookAndFeel().findColour (colourId);
  32223. }
  32224. bool Component::isColourSpecified (const int colourId) const
  32225. {
  32226. return properties.contains (getColourPropertyId (colourId));
  32227. }
  32228. void Component::removeColour (const int colourId)
  32229. {
  32230. if (properties.remove (getColourPropertyId (colourId)))
  32231. colourChanged();
  32232. }
  32233. void Component::setColour (const int colourId, const Colour& colour)
  32234. {
  32235. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32236. colourChanged();
  32237. }
  32238. void Component::copyAllExplicitColoursTo (Component& target) const
  32239. {
  32240. bool changed = false;
  32241. for (int i = properties.size(); --i >= 0;)
  32242. {
  32243. const var::identifier name (properties.getName(i));
  32244. if (name.name.startsWith ("jcclr_"))
  32245. if (target.properties.set (name, properties [name]))
  32246. changed = true;
  32247. }
  32248. if (changed)
  32249. target.colourChanged();
  32250. }
  32251. void Component::colourChanged()
  32252. {
  32253. }
  32254. const Rectangle<int> Component::getUnclippedArea() const
  32255. {
  32256. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32257. Component* p = parentComponent_;
  32258. int px = getX();
  32259. int py = getY();
  32260. while (p != 0)
  32261. {
  32262. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32263. return Rectangle<int>();
  32264. px += p->getX();
  32265. py += p->getY();
  32266. p = p->parentComponent_;
  32267. }
  32268. return Rectangle<int> (x, y, w, h);
  32269. }
  32270. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32271. const int deltaX, const int deltaY) const
  32272. {
  32273. for (int i = childComponentList_.size(); --i >= 0;)
  32274. {
  32275. const Component* const c = childComponentList_.getUnchecked(i);
  32276. if (c->isVisible())
  32277. {
  32278. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32279. if (! newClip.isEmpty())
  32280. {
  32281. if (c->isOpaque())
  32282. {
  32283. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32284. }
  32285. else
  32286. {
  32287. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32288. c->getX() + deltaX,
  32289. c->getY() + deltaY);
  32290. }
  32291. }
  32292. }
  32293. }
  32294. }
  32295. void Component::getVisibleArea (RectangleList& result,
  32296. const bool includeSiblings) const
  32297. {
  32298. result.clear();
  32299. const Rectangle<int> unclipped (getUnclippedArea());
  32300. if (! unclipped.isEmpty())
  32301. {
  32302. result.add (unclipped);
  32303. if (includeSiblings)
  32304. {
  32305. const Component* const c = getTopLevelComponent();
  32306. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32307. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32308. this);
  32309. }
  32310. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32311. result.consolidate();
  32312. }
  32313. }
  32314. void Component::subtractObscuredRegions (RectangleList& result,
  32315. const Point<int>& delta,
  32316. const Rectangle<int>& clipRect,
  32317. const Component* const compToAvoid) const
  32318. {
  32319. for (int i = childComponentList_.size(); --i >= 0;)
  32320. {
  32321. const Component* const c = childComponentList_.getUnchecked(i);
  32322. if (c != compToAvoid && c->isVisible())
  32323. {
  32324. if (c->isOpaque())
  32325. {
  32326. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32327. childBounds.translate (delta.getX(), delta.getY());
  32328. result.subtract (childBounds);
  32329. }
  32330. else
  32331. {
  32332. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32333. newClip.translate (-c->getX(), -c->getY());
  32334. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32335. newClip, compToAvoid);
  32336. }
  32337. }
  32338. }
  32339. }
  32340. void Component::mouseEnter (const MouseEvent&)
  32341. {
  32342. // base class does nothing
  32343. }
  32344. void Component::mouseExit (const MouseEvent&)
  32345. {
  32346. // base class does nothing
  32347. }
  32348. void Component::mouseDown (const MouseEvent&)
  32349. {
  32350. // base class does nothing
  32351. }
  32352. void Component::mouseUp (const MouseEvent&)
  32353. {
  32354. // base class does nothing
  32355. }
  32356. void Component::mouseDrag (const MouseEvent&)
  32357. {
  32358. // base class does nothing
  32359. }
  32360. void Component::mouseMove (const MouseEvent&)
  32361. {
  32362. // base class does nothing
  32363. }
  32364. void Component::mouseDoubleClick (const MouseEvent&)
  32365. {
  32366. // base class does nothing
  32367. }
  32368. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32369. {
  32370. // the base class just passes this event up to its parent..
  32371. if (parentComponent_ != 0)
  32372. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32373. wheelIncrementX, wheelIncrementY);
  32374. }
  32375. void Component::resized()
  32376. {
  32377. // base class does nothing
  32378. }
  32379. void Component::moved()
  32380. {
  32381. // base class does nothing
  32382. }
  32383. void Component::childBoundsChanged (Component*)
  32384. {
  32385. // base class does nothing
  32386. }
  32387. void Component::parentSizeChanged()
  32388. {
  32389. // base class does nothing
  32390. }
  32391. void Component::addComponentListener (ComponentListener* const newListener)
  32392. {
  32393. jassert (isValidComponent());
  32394. componentListeners.add (newListener);
  32395. }
  32396. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32397. {
  32398. jassert (isValidComponent());
  32399. componentListeners.remove (listenerToRemove);
  32400. }
  32401. void Component::inputAttemptWhenModal()
  32402. {
  32403. bringModalComponentToFront();
  32404. getLookAndFeel().playAlertSound();
  32405. }
  32406. bool Component::canModalEventBeSentToComponent (const Component*)
  32407. {
  32408. return false;
  32409. }
  32410. void Component::internalModalInputAttempt()
  32411. {
  32412. Component* const current = getCurrentlyModalComponent();
  32413. if (current != 0)
  32414. current->inputAttemptWhenModal();
  32415. }
  32416. void Component::paint (Graphics&)
  32417. {
  32418. // all painting is done in the subclasses
  32419. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32420. }
  32421. void Component::paintOverChildren (Graphics&)
  32422. {
  32423. // all painting is done in the subclasses
  32424. }
  32425. void Component::handleMessage (const Message& message)
  32426. {
  32427. if (message.intParameter1 == exitModalStateMessage)
  32428. {
  32429. exitModalState (message.intParameter2);
  32430. }
  32431. else if (message.intParameter1 == customCommandMessage)
  32432. {
  32433. handleCommandMessage (message.intParameter2);
  32434. }
  32435. }
  32436. void Component::postCommandMessage (const int commandId)
  32437. {
  32438. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32439. }
  32440. void Component::handleCommandMessage (int)
  32441. {
  32442. // used by subclasses
  32443. }
  32444. void Component::addMouseListener (MouseListener* const newListener,
  32445. const bool wantsEventsForAllNestedChildComponents)
  32446. {
  32447. // if component methods are being called from threads other than the message
  32448. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32449. checkMessageManagerIsLocked
  32450. if (mouseListeners_ == 0)
  32451. mouseListeners_ = new VoidArray();
  32452. if (! mouseListeners_->contains (newListener))
  32453. {
  32454. if (wantsEventsForAllNestedChildComponents)
  32455. {
  32456. mouseListeners_->insert (0, newListener);
  32457. ++numDeepMouseListeners;
  32458. }
  32459. else
  32460. {
  32461. mouseListeners_->add (newListener);
  32462. }
  32463. }
  32464. }
  32465. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32466. {
  32467. // if component methods are being called from threads other than the message
  32468. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32469. checkMessageManagerIsLocked
  32470. if (mouseListeners_ != 0)
  32471. {
  32472. const int index = mouseListeners_->indexOf (listenerToRemove);
  32473. if (index >= 0)
  32474. {
  32475. if (index < numDeepMouseListeners)
  32476. --numDeepMouseListeners;
  32477. mouseListeners_->remove (index);
  32478. }
  32479. }
  32480. }
  32481. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32482. {
  32483. if (isCurrentlyBlockedByAnotherModalComponent())
  32484. {
  32485. // if something else is modal, always just show a normal mouse cursor
  32486. source.showMouseCursor (MouseCursor::NormalCursor);
  32487. return;
  32488. }
  32489. if (! flags.mouseInsideFlag)
  32490. {
  32491. flags.mouseInsideFlag = true;
  32492. flags.mouseOverFlag = true;
  32493. flags.draggingFlag = false;
  32494. BailOutChecker checker (this);
  32495. if (flags.repaintOnMouseActivityFlag)
  32496. repaint();
  32497. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32498. this, time, relativePos,
  32499. time, 0, false);
  32500. mouseEnter (me);
  32501. if (checker.shouldBailOut())
  32502. return;
  32503. Desktop::getInstance().resetTimer();
  32504. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32505. if (checker.shouldBailOut())
  32506. return;
  32507. if (mouseListeners_ != 0)
  32508. {
  32509. for (int i = mouseListeners_->size(); --i >= 0;)
  32510. {
  32511. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32512. if (checker.shouldBailOut())
  32513. return;
  32514. i = jmin (i, mouseListeners_->size());
  32515. }
  32516. }
  32517. Component* p = parentComponent_;
  32518. while (p != 0)
  32519. {
  32520. if (p->numDeepMouseListeners > 0)
  32521. {
  32522. BailOutChecker checker (this, p);
  32523. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32524. {
  32525. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32526. if (checker.shouldBailOut())
  32527. return;
  32528. i = jmin (i, p->numDeepMouseListeners);
  32529. }
  32530. }
  32531. p = p->parentComponent_;
  32532. }
  32533. }
  32534. }
  32535. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32536. {
  32537. BailOutChecker checker (this);
  32538. if (flags.draggingFlag)
  32539. {
  32540. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32541. if (checker.shouldBailOut())
  32542. return;
  32543. }
  32544. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32545. {
  32546. flags.mouseInsideFlag = false;
  32547. flags.mouseOverFlag = false;
  32548. flags.draggingFlag = false;
  32549. if (flags.repaintOnMouseActivityFlag)
  32550. repaint();
  32551. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32552. this, time, relativePos,
  32553. time, 0, false);
  32554. mouseExit (me);
  32555. if (checker.shouldBailOut())
  32556. return;
  32557. Desktop::getInstance().resetTimer();
  32558. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32559. if (checker.shouldBailOut())
  32560. return;
  32561. if (mouseListeners_ != 0)
  32562. {
  32563. for (int i = mouseListeners_->size(); --i >= 0;)
  32564. {
  32565. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32566. if (checker.shouldBailOut())
  32567. return;
  32568. i = jmin (i, mouseListeners_->size());
  32569. }
  32570. }
  32571. Component* p = parentComponent_;
  32572. while (p != 0)
  32573. {
  32574. if (p->numDeepMouseListeners > 0)
  32575. {
  32576. BailOutChecker checker (this, p);
  32577. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32578. {
  32579. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32580. if (checker.shouldBailOut())
  32581. return;
  32582. i = jmin (i, p->numDeepMouseListeners);
  32583. }
  32584. }
  32585. p = p->parentComponent_;
  32586. }
  32587. }
  32588. }
  32589. class InternalDragRepeater : public Timer
  32590. {
  32591. public:
  32592. InternalDragRepeater()
  32593. {}
  32594. ~InternalDragRepeater()
  32595. {
  32596. clearSingletonInstance();
  32597. }
  32598. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32599. void timerCallback()
  32600. {
  32601. Desktop& desktop = Desktop::getInstance();
  32602. int numMiceDown = 0;
  32603. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32604. {
  32605. MouseInputSource* const source = desktop.getMouseSource(i);
  32606. if (source->isDragging())
  32607. {
  32608. source->triggerFakeMove();
  32609. ++numMiceDown;
  32610. }
  32611. }
  32612. if (numMiceDown == 0)
  32613. deleteInstance();
  32614. }
  32615. juce_UseDebuggingNewOperator
  32616. private:
  32617. InternalDragRepeater (const InternalDragRepeater&);
  32618. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32619. };
  32620. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32621. void Component::beginDragAutoRepeat (const int interval)
  32622. {
  32623. if (interval > 0)
  32624. {
  32625. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32626. InternalDragRepeater::getInstance()->startTimer (interval);
  32627. }
  32628. else
  32629. {
  32630. InternalDragRepeater::deleteInstance();
  32631. }
  32632. }
  32633. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32634. {
  32635. Desktop& desktop = Desktop::getInstance();
  32636. BailOutChecker checker (this);
  32637. if (isCurrentlyBlockedByAnotherModalComponent())
  32638. {
  32639. internalModalInputAttempt();
  32640. if (checker.shouldBailOut())
  32641. return;
  32642. // If processing the input attempt has exited the modal loop, we'll allow the event
  32643. // to be delivered..
  32644. if (isCurrentlyBlockedByAnotherModalComponent())
  32645. {
  32646. // allow blocked mouse-events to go to global listeners..
  32647. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32648. this, time, relativePos, time,
  32649. source.getNumberOfMultipleClicks(), false);
  32650. desktop.resetTimer();
  32651. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32652. return;
  32653. }
  32654. }
  32655. {
  32656. Component* c = this;
  32657. while (c != 0)
  32658. {
  32659. if (c->isBroughtToFrontOnMouseClick())
  32660. {
  32661. c->toFront (true);
  32662. if (checker.shouldBailOut())
  32663. return;
  32664. }
  32665. c = c->parentComponent_;
  32666. }
  32667. }
  32668. if (! flags.dontFocusOnMouseClickFlag)
  32669. {
  32670. grabFocusInternal (focusChangedByMouseClick);
  32671. if (checker.shouldBailOut())
  32672. return;
  32673. }
  32674. flags.draggingFlag = true;
  32675. flags.mouseOverFlag = true;
  32676. if (flags.repaintOnMouseActivityFlag)
  32677. repaint();
  32678. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32679. this, time, relativePos, time,
  32680. source.getNumberOfMultipleClicks(), false);
  32681. mouseDown (me);
  32682. if (checker.shouldBailOut())
  32683. return;
  32684. desktop.resetTimer();
  32685. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32686. if (checker.shouldBailOut())
  32687. return;
  32688. if (mouseListeners_ != 0)
  32689. {
  32690. for (int i = mouseListeners_->size(); --i >= 0;)
  32691. {
  32692. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32693. if (checker.shouldBailOut())
  32694. return;
  32695. i = jmin (i, mouseListeners_->size());
  32696. }
  32697. }
  32698. Component* p = parentComponent_;
  32699. while (p != 0)
  32700. {
  32701. if (p->numDeepMouseListeners > 0)
  32702. {
  32703. BailOutChecker checker (this, p);
  32704. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32705. {
  32706. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32707. if (checker.shouldBailOut())
  32708. return;
  32709. i = jmin (i, p->numDeepMouseListeners);
  32710. }
  32711. }
  32712. p = p->parentComponent_;
  32713. }
  32714. }
  32715. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32716. {
  32717. if (flags.draggingFlag)
  32718. {
  32719. Desktop& desktop = Desktop::getInstance();
  32720. flags.draggingFlag = false;
  32721. BailOutChecker checker (this);
  32722. if (flags.repaintOnMouseActivityFlag)
  32723. repaint();
  32724. const MouseEvent me (source, relativePos,
  32725. oldModifiers, this, time,
  32726. globalPositionToRelative (source.getLastMouseDownPosition()),
  32727. source.getLastMouseDownTime(),
  32728. source.getNumberOfMultipleClicks(),
  32729. source.hasMouseMovedSignificantlySincePressed());
  32730. mouseUp (me);
  32731. if (checker.shouldBailOut())
  32732. return;
  32733. desktop.resetTimer();
  32734. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32735. if (checker.shouldBailOut())
  32736. return;
  32737. if (mouseListeners_ != 0)
  32738. {
  32739. for (int i = mouseListeners_->size(); --i >= 0;)
  32740. {
  32741. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32742. if (checker.shouldBailOut())
  32743. return;
  32744. i = jmin (i, mouseListeners_->size());
  32745. }
  32746. }
  32747. {
  32748. Component* p = parentComponent_;
  32749. while (p != 0)
  32750. {
  32751. if (p->numDeepMouseListeners > 0)
  32752. {
  32753. BailOutChecker checker (this, p);
  32754. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32755. {
  32756. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  32757. if (checker.shouldBailOut())
  32758. return;
  32759. i = jmin (i, p->numDeepMouseListeners);
  32760. }
  32761. }
  32762. p = p->parentComponent_;
  32763. }
  32764. }
  32765. // check for double-click
  32766. if (me.getNumberOfClicks() >= 2)
  32767. {
  32768. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32769. mouseDoubleClick (me);
  32770. if (checker.shouldBailOut())
  32771. return;
  32772. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32773. if (checker.shouldBailOut())
  32774. return;
  32775. for (int i = numListeners; --i >= 0;)
  32776. {
  32777. if (checker.shouldBailOut())
  32778. return;
  32779. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32780. if (ml != 0)
  32781. ml->mouseDoubleClick (me);
  32782. }
  32783. if (checker.shouldBailOut())
  32784. return;
  32785. Component* p = parentComponent_;
  32786. while (p != 0)
  32787. {
  32788. if (p->numDeepMouseListeners > 0)
  32789. {
  32790. BailOutChecker checker (this, p);
  32791. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32792. {
  32793. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  32794. if (checker.shouldBailOut())
  32795. return;
  32796. i = jmin (i, p->numDeepMouseListeners);
  32797. }
  32798. }
  32799. p = p->parentComponent_;
  32800. }
  32801. }
  32802. }
  32803. }
  32804. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32805. {
  32806. if (flags.draggingFlag)
  32807. {
  32808. Desktop& desktop = Desktop::getInstance();
  32809. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32810. BailOutChecker checker (this);
  32811. const MouseEvent me (source, relativePos,
  32812. source.getCurrentModifiers(), this, time,
  32813. globalPositionToRelative (source.getLastMouseDownPosition()),
  32814. source.getLastMouseDownTime(),
  32815. source.getNumberOfMultipleClicks(),
  32816. source.hasMouseMovedSignificantlySincePressed());
  32817. mouseDrag (me);
  32818. if (checker.shouldBailOut())
  32819. return;
  32820. desktop.resetTimer();
  32821. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32822. if (checker.shouldBailOut())
  32823. return;
  32824. if (mouseListeners_ != 0)
  32825. {
  32826. for (int i = mouseListeners_->size(); --i >= 0;)
  32827. {
  32828. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32829. if (checker.shouldBailOut())
  32830. return;
  32831. i = jmin (i, mouseListeners_->size());
  32832. }
  32833. }
  32834. Component* p = parentComponent_;
  32835. while (p != 0)
  32836. {
  32837. if (p->numDeepMouseListeners > 0)
  32838. {
  32839. BailOutChecker checker (this, p);
  32840. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32841. {
  32842. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  32843. if (checker.shouldBailOut())
  32844. return;
  32845. i = jmin (i, p->numDeepMouseListeners);
  32846. }
  32847. }
  32848. p = p->parentComponent_;
  32849. }
  32850. }
  32851. }
  32852. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32853. {
  32854. Desktop& desktop = Desktop::getInstance();
  32855. BailOutChecker checker (this);
  32856. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32857. this, time, relativePos,
  32858. time, 0, false);
  32859. if (isCurrentlyBlockedByAnotherModalComponent())
  32860. {
  32861. // allow blocked mouse-events to go to global listeners..
  32862. desktop.sendMouseMove();
  32863. }
  32864. else
  32865. {
  32866. flags.mouseOverFlag = true;
  32867. mouseMove (me);
  32868. if (checker.shouldBailOut())
  32869. return;
  32870. desktop.resetTimer();
  32871. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32872. if (checker.shouldBailOut())
  32873. return;
  32874. if (mouseListeners_ != 0)
  32875. {
  32876. for (int i = mouseListeners_->size(); --i >= 0;)
  32877. {
  32878. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  32879. if (checker.shouldBailOut())
  32880. return;
  32881. i = jmin (i, mouseListeners_->size());
  32882. }
  32883. }
  32884. Component* p = parentComponent_;
  32885. while (p != 0)
  32886. {
  32887. if (p->numDeepMouseListeners > 0)
  32888. {
  32889. BailOutChecker checker (this, p);
  32890. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32891. {
  32892. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  32893. if (checker.shouldBailOut())
  32894. return;
  32895. i = jmin (i, p->numDeepMouseListeners);
  32896. }
  32897. }
  32898. p = p->parentComponent_;
  32899. }
  32900. }
  32901. }
  32902. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  32903. const Time& time, const float amountX, const float amountY)
  32904. {
  32905. Desktop& desktop = Desktop::getInstance();
  32906. BailOutChecker checker (this);
  32907. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  32908. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  32909. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32910. this, time, relativePos, time, 0, false);
  32911. if (isCurrentlyBlockedByAnotherModalComponent())
  32912. {
  32913. // allow blocked mouse-events to go to global listeners..
  32914. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32915. }
  32916. else
  32917. {
  32918. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32919. if (checker.shouldBailOut())
  32920. return;
  32921. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32922. if (checker.shouldBailOut())
  32923. return;
  32924. if (mouseListeners_ != 0)
  32925. {
  32926. for (int i = mouseListeners_->size(); --i >= 0;)
  32927. {
  32928. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32929. if (checker.shouldBailOut())
  32930. return;
  32931. i = jmin (i, mouseListeners_->size());
  32932. }
  32933. }
  32934. Component* p = parentComponent_;
  32935. while (p != 0)
  32936. {
  32937. if (p->numDeepMouseListeners > 0)
  32938. {
  32939. BailOutChecker checker (this, p);
  32940. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32941. {
  32942. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32943. if (checker.shouldBailOut())
  32944. return;
  32945. i = jmin (i, p->numDeepMouseListeners);
  32946. }
  32947. }
  32948. p = p->parentComponent_;
  32949. }
  32950. }
  32951. }
  32952. void Component::sendFakeMouseMove() const
  32953. {
  32954. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  32955. }
  32956. void Component::broughtToFront()
  32957. {
  32958. }
  32959. void Component::internalBroughtToFront()
  32960. {
  32961. if (! isValidComponent())
  32962. return;
  32963. if (flags.hasHeavyweightPeerFlag)
  32964. Desktop::getInstance().componentBroughtToFront (this);
  32965. BailOutChecker checker (this);
  32966. broughtToFront();
  32967. if (checker.shouldBailOut())
  32968. return;
  32969. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  32970. if (checker.shouldBailOut())
  32971. return;
  32972. // When brought to the front and there's a modal component blocking this one,
  32973. // we need to bring the modal one to the front instead..
  32974. Component* const cm = getCurrentlyModalComponent();
  32975. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  32976. bringModalComponentToFront();
  32977. }
  32978. void Component::focusGained (FocusChangeType)
  32979. {
  32980. // base class does nothing
  32981. }
  32982. void Component::internalFocusGain (const FocusChangeType cause)
  32983. {
  32984. SafePointer<Component> safePointer (this);
  32985. focusGained (cause);
  32986. if (safePointer != 0)
  32987. internalChildFocusChange (cause);
  32988. }
  32989. void Component::focusLost (FocusChangeType)
  32990. {
  32991. // base class does nothing
  32992. }
  32993. void Component::internalFocusLoss (const FocusChangeType cause)
  32994. {
  32995. SafePointer<Component> safePointer (this);
  32996. focusLost (focusChangedDirectly);
  32997. if (safePointer != 0)
  32998. internalChildFocusChange (cause);
  32999. }
  33000. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33001. {
  33002. // base class does nothing
  33003. }
  33004. void Component::internalChildFocusChange (FocusChangeType cause)
  33005. {
  33006. const bool childIsNowFocused = hasKeyboardFocus (true);
  33007. if (flags.childCompFocusedFlag != childIsNowFocused)
  33008. {
  33009. flags.childCompFocusedFlag = childIsNowFocused;
  33010. SafePointer<Component> safePointer (this);
  33011. focusOfChildComponentChanged (cause);
  33012. if (safePointer == 0)
  33013. return;
  33014. }
  33015. if (parentComponent_ != 0)
  33016. parentComponent_->internalChildFocusChange (cause);
  33017. }
  33018. bool Component::isEnabled() const throw()
  33019. {
  33020. return (! flags.isDisabledFlag)
  33021. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33022. }
  33023. void Component::setEnabled (const bool shouldBeEnabled)
  33024. {
  33025. if (flags.isDisabledFlag == shouldBeEnabled)
  33026. {
  33027. flags.isDisabledFlag = ! shouldBeEnabled;
  33028. // if any parent components are disabled, setting our flag won't make a difference,
  33029. // so no need to send a change message
  33030. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33031. sendEnablementChangeMessage();
  33032. }
  33033. }
  33034. void Component::sendEnablementChangeMessage()
  33035. {
  33036. SafePointer<Component> safePointer (this);
  33037. enablementChanged();
  33038. if (safePointer == 0)
  33039. return;
  33040. for (int i = getNumChildComponents(); --i >= 0;)
  33041. {
  33042. Component* const c = getChildComponent (i);
  33043. if (c != 0)
  33044. {
  33045. c->sendEnablementChangeMessage();
  33046. if (safePointer == 0)
  33047. return;
  33048. }
  33049. }
  33050. }
  33051. void Component::enablementChanged()
  33052. {
  33053. }
  33054. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33055. {
  33056. flags.wantsFocusFlag = wantsFocus;
  33057. }
  33058. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33059. {
  33060. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33061. }
  33062. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33063. {
  33064. return ! flags.dontFocusOnMouseClickFlag;
  33065. }
  33066. bool Component::getWantsKeyboardFocus() const throw()
  33067. {
  33068. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33069. }
  33070. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33071. {
  33072. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33073. }
  33074. bool Component::isFocusContainer() const throw()
  33075. {
  33076. return flags.isFocusContainerFlag;
  33077. }
  33078. int Component::getExplicitFocusOrder() const
  33079. {
  33080. return properties ["_jexfo"];
  33081. }
  33082. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33083. {
  33084. properties.set ("_jexfo", newFocusOrderIndex);
  33085. }
  33086. KeyboardFocusTraverser* Component::createFocusTraverser()
  33087. {
  33088. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33089. return new KeyboardFocusTraverser();
  33090. return parentComponent_->createFocusTraverser();
  33091. }
  33092. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33093. {
  33094. // give the focus to this component
  33095. if (currentlyFocusedComponent != this)
  33096. {
  33097. JUCE_TRY
  33098. {
  33099. // get the focus onto our desktop window
  33100. ComponentPeer* const peer = getPeer();
  33101. if (peer != 0)
  33102. {
  33103. SafePointer<Component> safePointer (this);
  33104. peer->grabFocus();
  33105. if (peer->isFocused() && currentlyFocusedComponent != this)
  33106. {
  33107. Component* const componentLosingFocus = currentlyFocusedComponent;
  33108. currentlyFocusedComponent = this;
  33109. Desktop::getInstance().triggerFocusCallback();
  33110. // call this after setting currentlyFocusedComponent so that the one that's
  33111. // losing it has a chance to see where focus is going
  33112. if (componentLosingFocus->isValidComponent())
  33113. componentLosingFocus->internalFocusLoss (cause);
  33114. if (currentlyFocusedComponent == this)
  33115. {
  33116. focusGained (cause);
  33117. if (safePointer != 0)
  33118. internalChildFocusChange (cause);
  33119. }
  33120. }
  33121. }
  33122. }
  33123. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33124. catch (const std::exception& e)
  33125. {
  33126. currentlyFocusedComponent = 0;
  33127. Desktop::getInstance().triggerFocusCallback();
  33128. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33129. }
  33130. catch (...)
  33131. {
  33132. currentlyFocusedComponent = 0;
  33133. Desktop::getInstance().triggerFocusCallback();
  33134. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33135. }
  33136. #endif
  33137. }
  33138. }
  33139. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33140. {
  33141. if (isShowing())
  33142. {
  33143. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33144. {
  33145. takeKeyboardFocus (cause);
  33146. }
  33147. else
  33148. {
  33149. if (isParentOf (currentlyFocusedComponent)
  33150. && currentlyFocusedComponent->isShowing())
  33151. {
  33152. // do nothing if the focused component is actually a child of ours..
  33153. }
  33154. else
  33155. {
  33156. // find the default child component..
  33157. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33158. if (traverser != 0)
  33159. {
  33160. Component* const defaultComp = traverser->getDefaultComponent (this);
  33161. traverser = 0;
  33162. if (defaultComp != 0)
  33163. {
  33164. defaultComp->grabFocusInternal (cause, false);
  33165. return;
  33166. }
  33167. }
  33168. if (canTryParent && parentComponent_ != 0)
  33169. {
  33170. // if no children want it and we're allowed to try our parent comp,
  33171. // then pass up to parent, which will try our siblings.
  33172. parentComponent_->grabFocusInternal (cause, true);
  33173. }
  33174. }
  33175. }
  33176. }
  33177. }
  33178. void Component::grabKeyboardFocus()
  33179. {
  33180. // if component methods are being called from threads other than the message
  33181. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33182. checkMessageManagerIsLocked
  33183. grabFocusInternal (focusChangedDirectly);
  33184. }
  33185. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33186. {
  33187. // if component methods are being called from threads other than the message
  33188. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33189. checkMessageManagerIsLocked
  33190. if (parentComponent_ != 0)
  33191. {
  33192. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33193. if (traverser != 0)
  33194. {
  33195. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33196. : traverser->getPreviousComponent (this);
  33197. traverser = 0;
  33198. if (nextComp != 0)
  33199. {
  33200. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33201. {
  33202. SafePointer<Component> safePointer (this);
  33203. internalModalInputAttempt();
  33204. if (safePointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33205. return;
  33206. }
  33207. nextComp->grabFocusInternal (focusChangedByTabKey);
  33208. return;
  33209. }
  33210. }
  33211. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33212. }
  33213. }
  33214. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33215. {
  33216. return (currentlyFocusedComponent == this)
  33217. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33218. }
  33219. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33220. {
  33221. return currentlyFocusedComponent;
  33222. }
  33223. void Component::giveAwayFocus()
  33224. {
  33225. // use a copy so we can clear the value before the call
  33226. Component* const componentLosingFocus = currentlyFocusedComponent;
  33227. currentlyFocusedComponent = 0;
  33228. Desktop::getInstance().triggerFocusCallback();
  33229. if (componentLosingFocus->isValidComponent())
  33230. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33231. }
  33232. bool Component::isMouseOver() const throw()
  33233. {
  33234. return flags.mouseOverFlag;
  33235. }
  33236. bool Component::isMouseButtonDown() const throw()
  33237. {
  33238. return flags.draggingFlag;
  33239. }
  33240. bool Component::isMouseOverOrDragging() const throw()
  33241. {
  33242. return flags.mouseOverFlag || flags.draggingFlag;
  33243. }
  33244. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33245. {
  33246. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33247. }
  33248. const Point<int> Component::getMouseXYRelative() const
  33249. {
  33250. return globalPositionToRelative (Desktop::getMousePosition());
  33251. }
  33252. const Rectangle<int> Component::getParentMonitorArea() const
  33253. {
  33254. return Desktop::getInstance()
  33255. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33256. getHeight() / 2)));
  33257. }
  33258. void Component::addKeyListener (KeyListener* const newListener)
  33259. {
  33260. if (keyListeners_ == 0)
  33261. keyListeners_ = new VoidArray();
  33262. keyListeners_->addIfNotAlreadyThere (newListener);
  33263. }
  33264. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33265. {
  33266. if (keyListeners_ != 0)
  33267. keyListeners_->removeValue (listenerToRemove);
  33268. }
  33269. bool Component::keyPressed (const KeyPress&)
  33270. {
  33271. return false;
  33272. }
  33273. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33274. {
  33275. return false;
  33276. }
  33277. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33278. {
  33279. if (parentComponent_ != 0)
  33280. parentComponent_->modifierKeysChanged (modifiers);
  33281. }
  33282. void Component::internalModifierKeysChanged()
  33283. {
  33284. sendFakeMouseMove();
  33285. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33286. }
  33287. ComponentPeer* Component::getPeer() const
  33288. {
  33289. if (flags.hasHeavyweightPeerFlag)
  33290. return ComponentPeer::getPeerFor (this);
  33291. else if (parentComponent_ != 0)
  33292. return parentComponent_->getPeer();
  33293. else
  33294. return 0;
  33295. }
  33296. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33297. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33298. {
  33299. jassert (component1 != 0);
  33300. }
  33301. bool Component::BailOutChecker::shouldBailOut() const throw()
  33302. {
  33303. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33304. }
  33305. END_JUCE_NAMESPACE
  33306. /*** End of inlined file: juce_Component.cpp ***/
  33307. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33308. BEGIN_JUCE_NAMESPACE
  33309. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33310. void ComponentListener::componentBroughtToFront (Component&) {}
  33311. void ComponentListener::componentVisibilityChanged (Component&) {}
  33312. void ComponentListener::componentChildrenChanged (Component&) {}
  33313. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33314. void ComponentListener::componentNameChanged (Component&) {}
  33315. void ComponentListener::componentBeingDeleted (Component&) {}
  33316. END_JUCE_NAMESPACE
  33317. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33318. /*** Start of inlined file: juce_Desktop.cpp ***/
  33319. BEGIN_JUCE_NAMESPACE
  33320. Desktop::Desktop()
  33321. : mouseClickCounter (0),
  33322. kioskModeComponent (0)
  33323. {
  33324. createMouseInputSources();
  33325. refreshMonitorSizes();
  33326. }
  33327. Desktop::~Desktop()
  33328. {
  33329. jassert (instance == this);
  33330. instance = 0;
  33331. // doh! If you don't delete all your windows before exiting, you're going to
  33332. // be leaking memory!
  33333. jassert (desktopComponents.size() == 0);
  33334. }
  33335. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33336. {
  33337. if (instance == 0)
  33338. instance = new Desktop();
  33339. return *instance;
  33340. }
  33341. Desktop* Desktop::instance = 0;
  33342. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33343. const bool clipToWorkArea);
  33344. void Desktop::refreshMonitorSizes()
  33345. {
  33346. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33347. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33348. monitorCoordsClipped.clear();
  33349. monitorCoordsUnclipped.clear();
  33350. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33351. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33352. jassert (monitorCoordsClipped.size() > 0
  33353. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33354. if (oldClipped != monitorCoordsClipped
  33355. || oldUnclipped != monitorCoordsUnclipped)
  33356. {
  33357. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33358. {
  33359. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33360. if (p != 0)
  33361. p->handleScreenSizeChange();
  33362. }
  33363. }
  33364. }
  33365. int Desktop::getNumDisplayMonitors() const throw()
  33366. {
  33367. return monitorCoordsClipped.size();
  33368. }
  33369. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33370. {
  33371. return clippedToWorkArea ? monitorCoordsClipped [index]
  33372. : monitorCoordsUnclipped [index];
  33373. }
  33374. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33375. {
  33376. RectangleList rl;
  33377. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33378. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33379. return rl;
  33380. }
  33381. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33382. {
  33383. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33384. }
  33385. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33386. {
  33387. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33388. double bestDistance = 1.0e10;
  33389. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33390. {
  33391. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33392. if (rect.contains (position))
  33393. return rect;
  33394. const double distance = rect.getCentre().getDistanceFrom (position);
  33395. if (distance < bestDistance)
  33396. {
  33397. bestDistance = distance;
  33398. best = rect;
  33399. }
  33400. }
  33401. return best;
  33402. }
  33403. int Desktop::getNumComponents() const throw()
  33404. {
  33405. return desktopComponents.size();
  33406. }
  33407. Component* Desktop::getComponent (const int index) const throw()
  33408. {
  33409. return desktopComponents [index];
  33410. }
  33411. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33412. {
  33413. for (int i = desktopComponents.size(); --i >= 0;)
  33414. {
  33415. Component* const c = desktopComponents.getUnchecked(i);
  33416. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33417. if (c->contains (relative.getX(), relative.getY()))
  33418. return c->getComponentAt (relative.getX(), relative.getY());
  33419. }
  33420. return 0;
  33421. }
  33422. void Desktop::addDesktopComponent (Component* const c)
  33423. {
  33424. jassert (c != 0);
  33425. jassert (! desktopComponents.contains (c));
  33426. desktopComponents.addIfNotAlreadyThere (c);
  33427. }
  33428. void Desktop::removeDesktopComponent (Component* const c)
  33429. {
  33430. desktopComponents.removeValue (c);
  33431. }
  33432. void Desktop::componentBroughtToFront (Component* const c)
  33433. {
  33434. const int index = desktopComponents.indexOf (c);
  33435. jassert (index >= 0);
  33436. if (index >= 0)
  33437. {
  33438. int newIndex = -1;
  33439. if (! c->isAlwaysOnTop())
  33440. {
  33441. newIndex = desktopComponents.size();
  33442. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33443. --newIndex;
  33444. --newIndex;
  33445. }
  33446. desktopComponents.move (index, newIndex);
  33447. }
  33448. }
  33449. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33450. {
  33451. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33452. }
  33453. int Desktop::getMouseButtonClickCounter() throw()
  33454. {
  33455. return getInstance().mouseClickCounter;
  33456. }
  33457. void Desktop::incrementMouseClickCounter() throw()
  33458. {
  33459. ++mouseClickCounter;
  33460. }
  33461. int Desktop::getNumDraggingMouseSources() const throw()
  33462. {
  33463. int num = 0;
  33464. for (int i = mouseSources.size(); --i >= 0;)
  33465. if (mouseSources.getUnchecked(i)->isDragging())
  33466. ++num;
  33467. return num;
  33468. }
  33469. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33470. {
  33471. int num = 0;
  33472. for (int i = mouseSources.size(); --i >= 0;)
  33473. {
  33474. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33475. if (mi->isDragging())
  33476. {
  33477. if (index == num)
  33478. return mi;
  33479. ++num;
  33480. }
  33481. }
  33482. return 0;
  33483. }
  33484. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33485. {
  33486. focusListeners.add (listener);
  33487. }
  33488. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33489. {
  33490. focusListeners.remove (listener);
  33491. }
  33492. void Desktop::triggerFocusCallback()
  33493. {
  33494. triggerAsyncUpdate();
  33495. }
  33496. void Desktop::handleAsyncUpdate()
  33497. {
  33498. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33499. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33500. }
  33501. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33502. {
  33503. mouseListeners.add (listener);
  33504. resetTimer();
  33505. }
  33506. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33507. {
  33508. mouseListeners.remove (listener);
  33509. resetTimer();
  33510. }
  33511. void Desktop::timerCallback()
  33512. {
  33513. if (lastFakeMouseMove != getMousePosition())
  33514. sendMouseMove();
  33515. }
  33516. void Desktop::sendMouseMove()
  33517. {
  33518. if (! mouseListeners.isEmpty())
  33519. {
  33520. startTimer (20);
  33521. lastFakeMouseMove = getMousePosition();
  33522. Component* const target = findComponentAt (lastFakeMouseMove);
  33523. if (target != 0)
  33524. {
  33525. Component::BailOutChecker checker (target);
  33526. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33527. const Time now (Time::getCurrentTime());
  33528. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33529. target, now, pos, now, 0, false);
  33530. if (me.mods.isAnyMouseButtonDown())
  33531. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33532. else
  33533. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33534. }
  33535. }
  33536. }
  33537. void Desktop::resetTimer()
  33538. {
  33539. if (mouseListeners.size() == 0)
  33540. stopTimer();
  33541. else
  33542. startTimer (100);
  33543. lastFakeMouseMove = getMousePosition();
  33544. }
  33545. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33546. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33547. {
  33548. if (kioskModeComponent != componentToUse)
  33549. {
  33550. // agh! Don't delete a component without first stopping it being the kiosk comp
  33551. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33552. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33553. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33554. if (kioskModeComponent->isValidComponent())
  33555. {
  33556. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33557. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33558. }
  33559. kioskModeComponent = componentToUse;
  33560. if (kioskModeComponent != 0)
  33561. {
  33562. jassert (kioskModeComponent->isValidComponent());
  33563. // Only components that are already on the desktop can be put into kiosk mode!
  33564. jassert (kioskModeComponent->isOnDesktop());
  33565. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33566. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33567. }
  33568. }
  33569. }
  33570. END_JUCE_NAMESPACE
  33571. /*** End of inlined file: juce_Desktop.cpp ***/
  33572. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33573. BEGIN_JUCE_NAMESPACE
  33574. ArrowButton::ArrowButton (const String& name,
  33575. float arrowDirectionInRadians,
  33576. const Colour& arrowColour)
  33577. : Button (name),
  33578. colour (arrowColour)
  33579. {
  33580. path.lineTo (0.0f, 1.0f);
  33581. path.lineTo (1.0f, 0.5f);
  33582. path.closeSubPath();
  33583. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33584. 0.5f, 0.5f));
  33585. setComponentEffect (&shadow);
  33586. buttonStateChanged();
  33587. }
  33588. ArrowButton::~ArrowButton()
  33589. {
  33590. }
  33591. void ArrowButton::paintButton (Graphics& g,
  33592. bool /*isMouseOverButton*/,
  33593. bool /*isButtonDown*/)
  33594. {
  33595. g.setColour (colour);
  33596. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33597. (float) offset,
  33598. (float) (getWidth() - 3),
  33599. (float) (getHeight() - 3),
  33600. false));
  33601. }
  33602. void ArrowButton::buttonStateChanged()
  33603. {
  33604. offset = (isDown()) ? 1 : 0;
  33605. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33606. 0.3f, -1, 0);
  33607. }
  33608. END_JUCE_NAMESPACE
  33609. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33610. /*** Start of inlined file: juce_Button.cpp ***/
  33611. BEGIN_JUCE_NAMESPACE
  33612. class Button::RepeatTimer : public Timer
  33613. {
  33614. public:
  33615. RepeatTimer (Button& owner_) : owner (owner_) {}
  33616. void timerCallback() { owner.repeatTimerCallback(); }
  33617. juce_UseDebuggingNewOperator
  33618. private:
  33619. Button& owner;
  33620. RepeatTimer (const RepeatTimer&);
  33621. RepeatTimer& operator= (const RepeatTimer&);
  33622. };
  33623. Button::Button (const String& name)
  33624. : Component (name),
  33625. text (name),
  33626. buttonPressTime (0),
  33627. lastTimeCallbackTime (0),
  33628. commandManagerToUse (0),
  33629. autoRepeatDelay (-1),
  33630. autoRepeatSpeed (0),
  33631. autoRepeatMinimumDelay (-1),
  33632. radioGroupId (0),
  33633. commandID (0),
  33634. connectedEdgeFlags (0),
  33635. buttonState (buttonNormal),
  33636. lastToggleState (false),
  33637. clickTogglesState (false),
  33638. needsToRelease (false),
  33639. needsRepainting (false),
  33640. isKeyDown (false),
  33641. triggerOnMouseDown (false),
  33642. generateTooltip (false)
  33643. {
  33644. setWantsKeyboardFocus (true);
  33645. isOn.addListener (this);
  33646. }
  33647. Button::~Button()
  33648. {
  33649. isOn.removeListener (this);
  33650. if (commandManagerToUse != 0)
  33651. commandManagerToUse->removeListener (this);
  33652. repeatTimer = 0;
  33653. clearShortcuts();
  33654. }
  33655. void Button::setButtonText (const String& newText)
  33656. {
  33657. if (text != newText)
  33658. {
  33659. text = newText;
  33660. repaint();
  33661. }
  33662. }
  33663. void Button::setTooltip (const String& newTooltip)
  33664. {
  33665. SettableTooltipClient::setTooltip (newTooltip);
  33666. generateTooltip = false;
  33667. }
  33668. const String Button::getTooltip()
  33669. {
  33670. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33671. {
  33672. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33673. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33674. for (int i = 0; i < keyPresses.size(); ++i)
  33675. {
  33676. const String key (keyPresses.getReference(i).getTextDescription());
  33677. tt << " [";
  33678. if (key.length() == 1)
  33679. tt << TRANS("shortcut") << ": '" << key << "']";
  33680. else
  33681. tt << key << ']';
  33682. }
  33683. return tt;
  33684. }
  33685. return SettableTooltipClient::getTooltip();
  33686. }
  33687. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33688. {
  33689. if (connectedEdgeFlags != connectedEdgeFlags_)
  33690. {
  33691. connectedEdgeFlags = connectedEdgeFlags_;
  33692. repaint();
  33693. }
  33694. }
  33695. void Button::setToggleState (const bool shouldBeOn,
  33696. const bool sendChangeNotification)
  33697. {
  33698. if (shouldBeOn != lastToggleState)
  33699. {
  33700. isOn = shouldBeOn;
  33701. lastToggleState = shouldBeOn;
  33702. repaint();
  33703. if (sendChangeNotification)
  33704. {
  33705. Component::SafePointer<Component> deletionWatcher (this);
  33706. sendClickMessage (ModifierKeys());
  33707. if (deletionWatcher == 0)
  33708. return;
  33709. }
  33710. if (lastToggleState)
  33711. turnOffOtherButtonsInGroup (sendChangeNotification);
  33712. }
  33713. }
  33714. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33715. {
  33716. clickTogglesState = shouldToggle;
  33717. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33718. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33719. // it is that this button represents, and the button will update its state to reflect this
  33720. // in the applicationCommandListChanged() method.
  33721. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33722. }
  33723. bool Button::getClickingTogglesState() const throw()
  33724. {
  33725. return clickTogglesState;
  33726. }
  33727. void Button::valueChanged (Value& value)
  33728. {
  33729. if (value.refersToSameSourceAs (isOn))
  33730. setToggleState (isOn.getValue(), true);
  33731. }
  33732. void Button::setRadioGroupId (const int newGroupId)
  33733. {
  33734. if (radioGroupId != newGroupId)
  33735. {
  33736. radioGroupId = newGroupId;
  33737. if (lastToggleState)
  33738. turnOffOtherButtonsInGroup (true);
  33739. }
  33740. }
  33741. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33742. {
  33743. Component* const p = getParentComponent();
  33744. if (p != 0 && radioGroupId != 0)
  33745. {
  33746. Component::SafePointer<Component> deletionWatcher (this);
  33747. for (int i = p->getNumChildComponents(); --i >= 0;)
  33748. {
  33749. Component* const c = p->getChildComponent (i);
  33750. if (c != this)
  33751. {
  33752. Button* const b = dynamic_cast <Button*> (c);
  33753. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33754. {
  33755. b->setToggleState (false, sendChangeNotification);
  33756. if (deletionWatcher == 0)
  33757. return;
  33758. }
  33759. }
  33760. }
  33761. }
  33762. }
  33763. void Button::enablementChanged()
  33764. {
  33765. updateState (0);
  33766. repaint();
  33767. }
  33768. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33769. {
  33770. ButtonState state = buttonNormal;
  33771. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33772. {
  33773. Point<int> mousePos;
  33774. if (e == 0)
  33775. mousePos = getMouseXYRelative();
  33776. else
  33777. mousePos = e->getEventRelativeTo (this).getPosition();
  33778. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33779. const bool down = isMouseButtonDown();
  33780. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33781. state = buttonDown;
  33782. else if (over)
  33783. state = buttonOver;
  33784. }
  33785. setState (state);
  33786. return state;
  33787. }
  33788. void Button::setState (const ButtonState newState)
  33789. {
  33790. if (buttonState != newState)
  33791. {
  33792. buttonState = newState;
  33793. repaint();
  33794. if (buttonState == buttonDown)
  33795. {
  33796. buttonPressTime = Time::getApproximateMillisecondCounter();
  33797. lastTimeCallbackTime = buttonPressTime;
  33798. }
  33799. sendStateMessage();
  33800. }
  33801. }
  33802. bool Button::isDown() const throw()
  33803. {
  33804. return buttonState == buttonDown;
  33805. }
  33806. bool Button::isOver() const throw()
  33807. {
  33808. return buttonState != buttonNormal;
  33809. }
  33810. void Button::buttonStateChanged()
  33811. {
  33812. }
  33813. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33814. {
  33815. const uint32 now = Time::getApproximateMillisecondCounter();
  33816. return now > buttonPressTime ? now - buttonPressTime : 0;
  33817. }
  33818. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33819. {
  33820. triggerOnMouseDown = isTriggeredOnMouseDown;
  33821. }
  33822. void Button::clicked()
  33823. {
  33824. }
  33825. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33826. {
  33827. clicked();
  33828. }
  33829. static const int clickMessageId = 0x2f3f4f99;
  33830. void Button::triggerClick()
  33831. {
  33832. postCommandMessage (clickMessageId);
  33833. }
  33834. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33835. {
  33836. if (clickTogglesState)
  33837. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33838. sendClickMessage (modifiers);
  33839. }
  33840. void Button::flashButtonState()
  33841. {
  33842. if (isEnabled())
  33843. {
  33844. needsToRelease = true;
  33845. setState (buttonDown);
  33846. getRepeatTimer().startTimer (100);
  33847. }
  33848. }
  33849. void Button::handleCommandMessage (int commandId)
  33850. {
  33851. if (commandId == clickMessageId)
  33852. {
  33853. if (isEnabled())
  33854. {
  33855. flashButtonState();
  33856. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33857. }
  33858. }
  33859. else
  33860. {
  33861. Component::handleCommandMessage (commandId);
  33862. }
  33863. }
  33864. void Button::addButtonListener (ButtonListener* const newListener)
  33865. {
  33866. buttonListeners.add (newListener);
  33867. }
  33868. void Button::removeButtonListener (ButtonListener* const listener)
  33869. {
  33870. buttonListeners.remove (listener);
  33871. }
  33872. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33873. {
  33874. Component::BailOutChecker checker (this);
  33875. if (commandManagerToUse != 0 && commandID != 0)
  33876. {
  33877. ApplicationCommandTarget::InvocationInfo info (commandID);
  33878. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  33879. info.originatingComponent = this;
  33880. commandManagerToUse->invoke (info, true);
  33881. }
  33882. clicked (modifiers);
  33883. if (! checker.shouldBailOut())
  33884. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  33885. }
  33886. void Button::sendStateMessage()
  33887. {
  33888. Component::BailOutChecker checker (this);
  33889. buttonStateChanged();
  33890. if (! checker.shouldBailOut())
  33891. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  33892. }
  33893. void Button::paint (Graphics& g)
  33894. {
  33895. if (needsToRelease && isEnabled())
  33896. {
  33897. needsToRelease = false;
  33898. needsRepainting = true;
  33899. }
  33900. paintButton (g, isOver(), isDown());
  33901. }
  33902. void Button::mouseEnter (const MouseEvent& e)
  33903. {
  33904. updateState (&e);
  33905. }
  33906. void Button::mouseExit (const MouseEvent& e)
  33907. {
  33908. updateState (&e);
  33909. }
  33910. void Button::mouseDown (const MouseEvent& e)
  33911. {
  33912. updateState (&e);
  33913. if (isDown())
  33914. {
  33915. if (autoRepeatDelay >= 0)
  33916. getRepeatTimer().startTimer (autoRepeatDelay);
  33917. if (triggerOnMouseDown)
  33918. internalClickCallback (e.mods);
  33919. }
  33920. }
  33921. void Button::mouseUp (const MouseEvent& e)
  33922. {
  33923. const bool wasDown = isDown();
  33924. updateState (&e);
  33925. if (wasDown && isOver() && ! triggerOnMouseDown)
  33926. internalClickCallback (e.mods);
  33927. }
  33928. void Button::mouseDrag (const MouseEvent& e)
  33929. {
  33930. const ButtonState oldState = buttonState;
  33931. updateState (&e);
  33932. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  33933. getRepeatTimer().startTimer (autoRepeatSpeed);
  33934. }
  33935. void Button::focusGained (FocusChangeType)
  33936. {
  33937. updateState (0);
  33938. repaint();
  33939. }
  33940. void Button::focusLost (FocusChangeType)
  33941. {
  33942. updateState (0);
  33943. repaint();
  33944. }
  33945. void Button::setVisible (bool shouldBeVisible)
  33946. {
  33947. if (shouldBeVisible != isVisible())
  33948. {
  33949. Component::setVisible (shouldBeVisible);
  33950. if (! shouldBeVisible)
  33951. needsToRelease = false;
  33952. updateState (0);
  33953. }
  33954. else
  33955. {
  33956. Component::setVisible (shouldBeVisible);
  33957. }
  33958. }
  33959. void Button::parentHierarchyChanged()
  33960. {
  33961. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  33962. if (newKeySource != keySource.getComponent())
  33963. {
  33964. if (keySource != 0)
  33965. keySource->removeKeyListener (this);
  33966. keySource = newKeySource;
  33967. if (keySource != 0)
  33968. keySource->addKeyListener (this);
  33969. }
  33970. }
  33971. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  33972. const int commandID_,
  33973. const bool generateTooltip_)
  33974. {
  33975. commandID = commandID_;
  33976. generateTooltip = generateTooltip_;
  33977. if (commandManagerToUse != commandManagerToUse_)
  33978. {
  33979. if (commandManagerToUse != 0)
  33980. commandManagerToUse->removeListener (this);
  33981. commandManagerToUse = commandManagerToUse_;
  33982. if (commandManagerToUse != 0)
  33983. commandManagerToUse->addListener (this);
  33984. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33985. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33986. // it is that this button represents, and the button will update its state to reflect this
  33987. // in the applicationCommandListChanged() method.
  33988. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33989. }
  33990. if (commandManagerToUse != 0)
  33991. applicationCommandListChanged();
  33992. else
  33993. setEnabled (true);
  33994. }
  33995. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  33996. {
  33997. if (info.commandID == commandID
  33998. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  33999. {
  34000. flashButtonState();
  34001. }
  34002. }
  34003. void Button::applicationCommandListChanged()
  34004. {
  34005. if (commandManagerToUse != 0)
  34006. {
  34007. ApplicationCommandInfo info (0);
  34008. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34009. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34010. if (target != 0)
  34011. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34012. }
  34013. }
  34014. void Button::addShortcut (const KeyPress& key)
  34015. {
  34016. if (key.isValid())
  34017. {
  34018. jassert (! isRegisteredForShortcut (key)); // already registered!
  34019. shortcuts.add (key);
  34020. parentHierarchyChanged();
  34021. }
  34022. }
  34023. void Button::clearShortcuts()
  34024. {
  34025. shortcuts.clear();
  34026. parentHierarchyChanged();
  34027. }
  34028. bool Button::isShortcutPressed() const
  34029. {
  34030. if (! isCurrentlyBlockedByAnotherModalComponent())
  34031. {
  34032. for (int i = shortcuts.size(); --i >= 0;)
  34033. if (shortcuts.getReference(i).isCurrentlyDown())
  34034. return true;
  34035. }
  34036. return false;
  34037. }
  34038. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34039. {
  34040. for (int i = shortcuts.size(); --i >= 0;)
  34041. if (key == shortcuts.getReference(i))
  34042. return true;
  34043. return false;
  34044. }
  34045. bool Button::keyStateChanged (const bool, Component*)
  34046. {
  34047. if (! isEnabled())
  34048. return false;
  34049. const bool wasDown = isKeyDown;
  34050. isKeyDown = isShortcutPressed();
  34051. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34052. getRepeatTimer().startTimer (autoRepeatDelay);
  34053. updateState (0);
  34054. if (isEnabled() && wasDown && ! isKeyDown)
  34055. {
  34056. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34057. // (return immediately - this button may now have been deleted)
  34058. return true;
  34059. }
  34060. return wasDown || isKeyDown;
  34061. }
  34062. bool Button::keyPressed (const KeyPress&, Component*)
  34063. {
  34064. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34065. return isShortcutPressed();
  34066. }
  34067. bool Button::keyPressed (const KeyPress& key)
  34068. {
  34069. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34070. {
  34071. triggerClick();
  34072. return true;
  34073. }
  34074. return false;
  34075. }
  34076. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34077. const int repeatMillisecs,
  34078. const int minimumDelayInMillisecs) throw()
  34079. {
  34080. autoRepeatDelay = initialDelayMillisecs;
  34081. autoRepeatSpeed = repeatMillisecs;
  34082. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34083. }
  34084. void Button::repeatTimerCallback()
  34085. {
  34086. if (needsRepainting)
  34087. {
  34088. getRepeatTimer().stopTimer();
  34089. updateState (0);
  34090. needsRepainting = false;
  34091. }
  34092. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34093. {
  34094. int repeatSpeed = autoRepeatSpeed;
  34095. if (autoRepeatMinimumDelay >= 0)
  34096. {
  34097. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34098. timeHeldDown *= timeHeldDown;
  34099. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34100. }
  34101. repeatSpeed = jmax (1, repeatSpeed);
  34102. getRepeatTimer().startTimer (repeatSpeed);
  34103. const uint32 now = Time::getApproximateMillisecondCounter();
  34104. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34105. lastTimeCallbackTime = now;
  34106. Component::SafePointer<Component> deletionWatcher (this);
  34107. for (int i = numTimesToCallback; --i >= 0;)
  34108. {
  34109. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34110. if (deletionWatcher == 0 || ! isDown())
  34111. return;
  34112. }
  34113. }
  34114. else if (! needsToRelease)
  34115. {
  34116. getRepeatTimer().stopTimer();
  34117. }
  34118. }
  34119. Button::RepeatTimer& Button::getRepeatTimer()
  34120. {
  34121. if (repeatTimer == 0)
  34122. repeatTimer = new RepeatTimer (*this);
  34123. return *repeatTimer;
  34124. }
  34125. END_JUCE_NAMESPACE
  34126. /*** End of inlined file: juce_Button.cpp ***/
  34127. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34128. BEGIN_JUCE_NAMESPACE
  34129. DrawableButton::DrawableButton (const String& name,
  34130. const DrawableButton::ButtonStyle buttonStyle)
  34131. : Button (name),
  34132. style (buttonStyle),
  34133. edgeIndent (3)
  34134. {
  34135. if (buttonStyle == ImageOnButtonBackground)
  34136. {
  34137. backgroundOff = Colour (0xffbbbbff);
  34138. backgroundOn = Colour (0xff3333ff);
  34139. }
  34140. else
  34141. {
  34142. backgroundOff = Colours::transparentBlack;
  34143. backgroundOn = Colour (0xaabbbbff);
  34144. }
  34145. }
  34146. DrawableButton::~DrawableButton()
  34147. {
  34148. deleteImages();
  34149. }
  34150. void DrawableButton::deleteImages()
  34151. {
  34152. }
  34153. void DrawableButton::setImages (const Drawable* normal,
  34154. const Drawable* over,
  34155. const Drawable* down,
  34156. const Drawable* disabled,
  34157. const Drawable* normalOn,
  34158. const Drawable* overOn,
  34159. const Drawable* downOn,
  34160. const Drawable* disabledOn)
  34161. {
  34162. deleteImages();
  34163. jassert (normal != 0); // you really need to give it at least a normal image..
  34164. if (normal != 0)
  34165. normalImage = normal->createCopy();
  34166. if (over != 0)
  34167. overImage = over->createCopy();
  34168. if (down != 0)
  34169. downImage = down->createCopy();
  34170. if (disabled != 0)
  34171. disabledImage = disabled->createCopy();
  34172. if (normalOn != 0)
  34173. normalImageOn = normalOn->createCopy();
  34174. if (overOn != 0)
  34175. overImageOn = overOn->createCopy();
  34176. if (downOn != 0)
  34177. downImageOn = downOn->createCopy();
  34178. if (disabledOn != 0)
  34179. disabledImageOn = disabledOn->createCopy();
  34180. repaint();
  34181. }
  34182. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34183. {
  34184. if (style != newStyle)
  34185. {
  34186. style = newStyle;
  34187. repaint();
  34188. }
  34189. }
  34190. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34191. const Colour& toggledOnColour)
  34192. {
  34193. if (backgroundOff != toggledOffColour
  34194. || backgroundOn != toggledOnColour)
  34195. {
  34196. backgroundOff = toggledOffColour;
  34197. backgroundOn = toggledOnColour;
  34198. repaint();
  34199. }
  34200. }
  34201. const Colour& DrawableButton::getBackgroundColour() const throw()
  34202. {
  34203. return getToggleState() ? backgroundOn
  34204. : backgroundOff;
  34205. }
  34206. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34207. {
  34208. edgeIndent = numPixelsIndent;
  34209. repaint();
  34210. }
  34211. void DrawableButton::paintButton (Graphics& g,
  34212. bool isMouseOverButton,
  34213. bool isButtonDown)
  34214. {
  34215. Rectangle<int> imageSpace;
  34216. if (style == ImageOnButtonBackground)
  34217. {
  34218. const int insetX = getWidth() / 4;
  34219. const int insetY = getHeight() / 4;
  34220. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34221. getLookAndFeel().drawButtonBackground (g, *this,
  34222. getBackgroundColour(),
  34223. isMouseOverButton,
  34224. isButtonDown);
  34225. }
  34226. else
  34227. {
  34228. g.fillAll (getBackgroundColour());
  34229. const int textH = (style == ImageAboveTextLabel)
  34230. ? jmin (16, proportionOfHeight (0.25f))
  34231. : 0;
  34232. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34233. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34234. imageSpace.setBounds (indentX, indentY,
  34235. getWidth() - indentX * 2,
  34236. getHeight() - indentY * 2 - textH);
  34237. if (textH > 0)
  34238. {
  34239. g.setFont ((float) textH);
  34240. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34241. g.drawFittedText (getButtonText(),
  34242. 2, getHeight() - textH - 1,
  34243. getWidth() - 4, textH,
  34244. Justification::centred, 1);
  34245. }
  34246. }
  34247. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34248. g.setOpacity (1.0f);
  34249. const Drawable* imageToDraw = 0;
  34250. if (isEnabled())
  34251. {
  34252. imageToDraw = getCurrentImage();
  34253. }
  34254. else
  34255. {
  34256. imageToDraw = getToggleState() ? disabledImageOn
  34257. : disabledImage;
  34258. if (imageToDraw == 0)
  34259. {
  34260. g.setOpacity (0.4f);
  34261. imageToDraw = getNormalImage();
  34262. }
  34263. }
  34264. if (imageToDraw != 0)
  34265. {
  34266. if (style == ImageRaw)
  34267. {
  34268. imageToDraw->draw (g, 1.0f);
  34269. }
  34270. else
  34271. {
  34272. imageToDraw->drawWithin (g,
  34273. imageSpace.getX(),
  34274. imageSpace.getY(),
  34275. imageSpace.getWidth(),
  34276. imageSpace.getHeight(),
  34277. RectanglePlacement::centred,
  34278. 1.0f);
  34279. }
  34280. }
  34281. }
  34282. const Drawable* DrawableButton::getCurrentImage() const throw()
  34283. {
  34284. if (isDown())
  34285. return getDownImage();
  34286. if (isOver())
  34287. return getOverImage();
  34288. return getNormalImage();
  34289. }
  34290. const Drawable* DrawableButton::getNormalImage() const throw()
  34291. {
  34292. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34293. : normalImage;
  34294. }
  34295. const Drawable* DrawableButton::getOverImage() const throw()
  34296. {
  34297. const Drawable* d = normalImage;
  34298. if (getToggleState())
  34299. {
  34300. if (overImageOn != 0)
  34301. d = overImageOn;
  34302. else if (normalImageOn != 0)
  34303. d = normalImageOn;
  34304. else if (overImage != 0)
  34305. d = overImage;
  34306. }
  34307. else
  34308. {
  34309. if (overImage != 0)
  34310. d = overImage;
  34311. }
  34312. return d;
  34313. }
  34314. const Drawable* DrawableButton::getDownImage() const throw()
  34315. {
  34316. const Drawable* d = normalImage;
  34317. if (getToggleState())
  34318. {
  34319. if (downImageOn != 0)
  34320. d = downImageOn;
  34321. else if (overImageOn != 0)
  34322. d = overImageOn;
  34323. else if (normalImageOn != 0)
  34324. d = normalImageOn;
  34325. else if (downImage != 0)
  34326. d = downImage;
  34327. else
  34328. d = getOverImage();
  34329. }
  34330. else
  34331. {
  34332. if (downImage != 0)
  34333. d = downImage;
  34334. else
  34335. d = getOverImage();
  34336. }
  34337. return d;
  34338. }
  34339. END_JUCE_NAMESPACE
  34340. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34341. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34342. BEGIN_JUCE_NAMESPACE
  34343. HyperlinkButton::HyperlinkButton (const String& linkText,
  34344. const URL& linkURL)
  34345. : Button (linkText),
  34346. url (linkURL),
  34347. font (14.0f, Font::underlined),
  34348. resizeFont (true),
  34349. justification (Justification::centred)
  34350. {
  34351. setMouseCursor (MouseCursor::PointingHandCursor);
  34352. setTooltip (linkURL.toString (false));
  34353. }
  34354. HyperlinkButton::~HyperlinkButton()
  34355. {
  34356. }
  34357. void HyperlinkButton::setFont (const Font& newFont,
  34358. const bool resizeToMatchComponentHeight,
  34359. const Justification& justificationType)
  34360. {
  34361. font = newFont;
  34362. resizeFont = resizeToMatchComponentHeight;
  34363. justification = justificationType;
  34364. repaint();
  34365. }
  34366. void HyperlinkButton::setURL (const URL& newURL) throw()
  34367. {
  34368. url = newURL;
  34369. setTooltip (newURL.toString (false));
  34370. }
  34371. const Font HyperlinkButton::getFontToUse() const
  34372. {
  34373. Font f (font);
  34374. if (resizeFont)
  34375. f.setHeight (getHeight() * 0.7f);
  34376. return f;
  34377. }
  34378. void HyperlinkButton::changeWidthToFitText()
  34379. {
  34380. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34381. }
  34382. void HyperlinkButton::colourChanged()
  34383. {
  34384. repaint();
  34385. }
  34386. void HyperlinkButton::clicked()
  34387. {
  34388. if (url.isWellFormed())
  34389. url.launchInDefaultBrowser();
  34390. }
  34391. void HyperlinkButton::paintButton (Graphics& g,
  34392. bool isMouseOverButton,
  34393. bool isButtonDown)
  34394. {
  34395. const Colour textColour (findColour (textColourId));
  34396. if (isEnabled())
  34397. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34398. : textColour);
  34399. else
  34400. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34401. g.setFont (getFontToUse());
  34402. g.drawText (getButtonText(),
  34403. 2, 0, getWidth() - 2, getHeight(),
  34404. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34405. true);
  34406. }
  34407. END_JUCE_NAMESPACE
  34408. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34409. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34410. BEGIN_JUCE_NAMESPACE
  34411. ImageButton::ImageButton (const String& text_)
  34412. : Button (text_),
  34413. scaleImageToFit (true),
  34414. preserveProportions (true),
  34415. alphaThreshold (0),
  34416. imageX (0),
  34417. imageY (0),
  34418. imageW (0),
  34419. imageH (0),
  34420. normalImage (0),
  34421. overImage (0),
  34422. downImage (0)
  34423. {
  34424. }
  34425. ImageButton::~ImageButton()
  34426. {
  34427. deleteImages();
  34428. }
  34429. void ImageButton::deleteImages()
  34430. {
  34431. ImageCache::releaseOrDelete (normalImage);
  34432. ImageCache::releaseOrDelete (overImage);
  34433. ImageCache::releaseOrDelete (downImage);
  34434. }
  34435. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34436. const bool rescaleImagesWhenButtonSizeChanges,
  34437. const bool preserveImageProportions,
  34438. Image* const normalImage_,
  34439. const float imageOpacityWhenNormal,
  34440. const Colour& overlayColourWhenNormal,
  34441. Image* const overImage_,
  34442. const float imageOpacityWhenOver,
  34443. const Colour& overlayColourWhenOver,
  34444. Image* const downImage_,
  34445. const float imageOpacityWhenDown,
  34446. const Colour& overlayColourWhenDown,
  34447. const float hitTestAlphaThreshold)
  34448. {
  34449. deleteImages();
  34450. normalImage = normalImage_;
  34451. overImage = overImage_;
  34452. downImage = downImage_;
  34453. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34454. {
  34455. imageW = normalImage->getWidth();
  34456. imageH = normalImage->getHeight();
  34457. setSize (imageW, imageH);
  34458. }
  34459. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34460. preserveProportions = preserveImageProportions;
  34461. normalOpacity = imageOpacityWhenNormal;
  34462. normalOverlay = overlayColourWhenNormal;
  34463. overOpacity = imageOpacityWhenOver;
  34464. overOverlay = overlayColourWhenOver;
  34465. downOpacity = imageOpacityWhenDown;
  34466. downOverlay = overlayColourWhenDown;
  34467. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34468. repaint();
  34469. }
  34470. Image* ImageButton::getCurrentImage() const
  34471. {
  34472. if (isDown() || getToggleState())
  34473. return getDownImage();
  34474. if (isOver())
  34475. return getOverImage();
  34476. return getNormalImage();
  34477. }
  34478. Image* ImageButton::getNormalImage() const throw()
  34479. {
  34480. return normalImage;
  34481. }
  34482. Image* ImageButton::getOverImage() const throw()
  34483. {
  34484. return (overImage != 0) ? overImage
  34485. : normalImage;
  34486. }
  34487. Image* ImageButton::getDownImage() const throw()
  34488. {
  34489. return (downImage != 0) ? downImage
  34490. : getOverImage();
  34491. }
  34492. void ImageButton::paintButton (Graphics& g,
  34493. bool isMouseOverButton,
  34494. bool isButtonDown)
  34495. {
  34496. if (! isEnabled())
  34497. {
  34498. isMouseOverButton = false;
  34499. isButtonDown = false;
  34500. }
  34501. Image* const im = getCurrentImage();
  34502. if (im != 0)
  34503. {
  34504. const int iw = im->getWidth();
  34505. const int ih = im->getHeight();
  34506. imageW = getWidth();
  34507. imageH = getHeight();
  34508. imageX = (imageW - iw) >> 1;
  34509. imageY = (imageH - ih) >> 1;
  34510. if (scaleImageToFit)
  34511. {
  34512. if (preserveProportions)
  34513. {
  34514. int newW, newH;
  34515. const float imRatio = ih / (float)iw;
  34516. const float destRatio = imageH / (float)imageW;
  34517. if (imRatio > destRatio)
  34518. {
  34519. newW = roundToInt (imageH / imRatio);
  34520. newH = imageH;
  34521. }
  34522. else
  34523. {
  34524. newW = imageW;
  34525. newH = roundToInt (imageW * imRatio);
  34526. }
  34527. imageX = (imageW - newW) / 2;
  34528. imageY = (imageH - newH) / 2;
  34529. imageW = newW;
  34530. imageH = newH;
  34531. }
  34532. else
  34533. {
  34534. imageX = 0;
  34535. imageY = 0;
  34536. }
  34537. }
  34538. if (! scaleImageToFit)
  34539. {
  34540. imageW = iw;
  34541. imageH = ih;
  34542. }
  34543. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34544. isButtonDown ? downOverlay
  34545. : (isMouseOverButton ? overOverlay
  34546. : normalOverlay),
  34547. isButtonDown ? downOpacity
  34548. : (isMouseOverButton ? overOpacity
  34549. : normalOpacity),
  34550. *this);
  34551. }
  34552. }
  34553. bool ImageButton::hitTest (int x, int y)
  34554. {
  34555. if (alphaThreshold == 0)
  34556. return true;
  34557. Image* const im = getCurrentImage();
  34558. return im == 0
  34559. || (imageW > 0 && imageH > 0
  34560. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34561. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34562. }
  34563. END_JUCE_NAMESPACE
  34564. /*** End of inlined file: juce_ImageButton.cpp ***/
  34565. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34566. BEGIN_JUCE_NAMESPACE
  34567. ShapeButton::ShapeButton (const String& text_,
  34568. const Colour& normalColour_,
  34569. const Colour& overColour_,
  34570. const Colour& downColour_)
  34571. : Button (text_),
  34572. normalColour (normalColour_),
  34573. overColour (overColour_),
  34574. downColour (downColour_),
  34575. maintainShapeProportions (false),
  34576. outlineWidth (0.0f)
  34577. {
  34578. }
  34579. ShapeButton::~ShapeButton()
  34580. {
  34581. }
  34582. void ShapeButton::setColours (const Colour& newNormalColour,
  34583. const Colour& newOverColour,
  34584. const Colour& newDownColour)
  34585. {
  34586. normalColour = newNormalColour;
  34587. overColour = newOverColour;
  34588. downColour = newDownColour;
  34589. }
  34590. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34591. const float newOutlineWidth)
  34592. {
  34593. outlineColour = newOutlineColour;
  34594. outlineWidth = newOutlineWidth;
  34595. }
  34596. void ShapeButton::setShape (const Path& newShape,
  34597. const bool resizeNowToFitThisShape,
  34598. const bool maintainShapeProportions_,
  34599. const bool hasShadow)
  34600. {
  34601. shape = newShape;
  34602. maintainShapeProportions = maintainShapeProportions_;
  34603. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34604. setComponentEffect ((hasShadow) ? &shadow : 0);
  34605. if (resizeNowToFitThisShape)
  34606. {
  34607. Rectangle<float> bounds (shape.getBounds());
  34608. if (hasShadow)
  34609. bounds.expand (4.0f, 4.0f);
  34610. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34611. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34612. 1 + (int) (bounds.getHeight() + outlineWidth));
  34613. }
  34614. }
  34615. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34616. {
  34617. if (! isEnabled())
  34618. {
  34619. isMouseOverButton = false;
  34620. isButtonDown = false;
  34621. }
  34622. g.setColour ((isButtonDown) ? downColour
  34623. : (isMouseOverButton) ? overColour
  34624. : normalColour);
  34625. int w = getWidth();
  34626. int h = getHeight();
  34627. if (getComponentEffect() != 0)
  34628. {
  34629. w -= 4;
  34630. h -= 4;
  34631. }
  34632. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34633. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34634. w - offset - outlineWidth,
  34635. h - offset - outlineWidth,
  34636. maintainShapeProportions));
  34637. g.fillPath (shape, trans);
  34638. if (outlineWidth > 0.0f)
  34639. {
  34640. g.setColour (outlineColour);
  34641. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34642. }
  34643. }
  34644. END_JUCE_NAMESPACE
  34645. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34646. /*** Start of inlined file: juce_TextButton.cpp ***/
  34647. BEGIN_JUCE_NAMESPACE
  34648. TextButton::TextButton (const String& name,
  34649. const String& toolTip)
  34650. : Button (name)
  34651. {
  34652. setTooltip (toolTip);
  34653. }
  34654. TextButton::~TextButton()
  34655. {
  34656. }
  34657. void TextButton::paintButton (Graphics& g,
  34658. bool isMouseOverButton,
  34659. bool isButtonDown)
  34660. {
  34661. getLookAndFeel().drawButtonBackground (g, *this,
  34662. findColour (getToggleState() ? buttonOnColourId
  34663. : buttonColourId),
  34664. isMouseOverButton,
  34665. isButtonDown);
  34666. getLookAndFeel().drawButtonText (g, *this,
  34667. isMouseOverButton,
  34668. isButtonDown);
  34669. }
  34670. void TextButton::colourChanged()
  34671. {
  34672. repaint();
  34673. }
  34674. const Font TextButton::getFont()
  34675. {
  34676. return Font (jmin (15.0f, getHeight() * 0.6f));
  34677. }
  34678. void TextButton::changeWidthToFitText (const int newHeight)
  34679. {
  34680. if (newHeight >= 0)
  34681. setSize (jmax (1, getWidth()), newHeight);
  34682. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34683. getHeight());
  34684. }
  34685. END_JUCE_NAMESPACE
  34686. /*** End of inlined file: juce_TextButton.cpp ***/
  34687. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34688. BEGIN_JUCE_NAMESPACE
  34689. ToggleButton::ToggleButton (const String& buttonText)
  34690. : Button (buttonText)
  34691. {
  34692. setClickingTogglesState (true);
  34693. }
  34694. ToggleButton::~ToggleButton()
  34695. {
  34696. }
  34697. void ToggleButton::paintButton (Graphics& g,
  34698. bool isMouseOverButton,
  34699. bool isButtonDown)
  34700. {
  34701. getLookAndFeel().drawToggleButton (g, *this,
  34702. isMouseOverButton,
  34703. isButtonDown);
  34704. }
  34705. void ToggleButton::changeWidthToFitText()
  34706. {
  34707. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34708. }
  34709. void ToggleButton::colourChanged()
  34710. {
  34711. repaint();
  34712. }
  34713. END_JUCE_NAMESPACE
  34714. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34715. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34716. BEGIN_JUCE_NAMESPACE
  34717. ToolbarButton::ToolbarButton (const int itemId_,
  34718. const String& buttonText,
  34719. Drawable* const normalImage_,
  34720. Drawable* const toggledOnImage_)
  34721. : ToolbarItemComponent (itemId_, buttonText, true),
  34722. normalImage (normalImage_),
  34723. toggledOnImage (toggledOnImage_)
  34724. {
  34725. }
  34726. ToolbarButton::~ToolbarButton()
  34727. {
  34728. }
  34729. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34730. bool /*isToolbarVertical*/,
  34731. int& preferredSize,
  34732. int& minSize, int& maxSize)
  34733. {
  34734. preferredSize = minSize = maxSize = toolbarDepth;
  34735. return true;
  34736. }
  34737. void ToolbarButton::paintButtonArea (Graphics& g,
  34738. int width, int height,
  34739. bool /*isMouseOver*/,
  34740. bool /*isMouseDown*/)
  34741. {
  34742. Drawable* d = normalImage;
  34743. if (getToggleState() && toggledOnImage != 0)
  34744. d = toggledOnImage;
  34745. if (! isEnabled())
  34746. {
  34747. Image im (Image::ARGB, width, height, true);
  34748. Graphics g2 (im);
  34749. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34750. im.desaturate();
  34751. g.drawImageAt (&im, 0, 0);
  34752. }
  34753. else
  34754. {
  34755. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34756. }
  34757. }
  34758. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34759. {
  34760. }
  34761. END_JUCE_NAMESPACE
  34762. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34763. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34764. BEGIN_JUCE_NAMESPACE
  34765. class CodeDocumentLine
  34766. {
  34767. public:
  34768. CodeDocumentLine (const tchar* const line_,
  34769. const int lineLength_,
  34770. const int numNewLineChars,
  34771. const int lineStartInFile_)
  34772. : line (line_, lineLength_),
  34773. lineStartInFile (lineStartInFile_),
  34774. lineLength (lineLength_),
  34775. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34776. {
  34777. }
  34778. ~CodeDocumentLine()
  34779. {
  34780. }
  34781. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34782. {
  34783. const tchar* const t = (const tchar*) text;
  34784. int pos = 0;
  34785. while (t [pos] != 0)
  34786. {
  34787. const int startOfLine = pos;
  34788. int numNewLineChars = 0;
  34789. while (t[pos] != 0)
  34790. {
  34791. if (t[pos] == '\r')
  34792. {
  34793. ++numNewLineChars;
  34794. ++pos;
  34795. if (t[pos] == '\n')
  34796. {
  34797. ++numNewLineChars;
  34798. ++pos;
  34799. }
  34800. break;
  34801. }
  34802. if (t[pos] == '\n')
  34803. {
  34804. ++numNewLineChars;
  34805. ++pos;
  34806. break;
  34807. }
  34808. ++pos;
  34809. }
  34810. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34811. numNewLineChars, startOfLine));
  34812. }
  34813. jassert (pos == text.length());
  34814. }
  34815. bool endsWithLineBreak() const throw()
  34816. {
  34817. return lineLengthWithoutNewLines != lineLength;
  34818. }
  34819. void updateLength() throw()
  34820. {
  34821. lineLengthWithoutNewLines = lineLength = line.length();
  34822. while (lineLengthWithoutNewLines > 0
  34823. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34824. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34825. {
  34826. --lineLengthWithoutNewLines;
  34827. }
  34828. }
  34829. String line;
  34830. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34831. };
  34832. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34833. : document (document_),
  34834. currentLine (document_->lines[0]),
  34835. line (0),
  34836. position (0)
  34837. {
  34838. }
  34839. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34840. : document (other.document),
  34841. currentLine (other.currentLine),
  34842. line (other.line),
  34843. position (other.position)
  34844. {
  34845. }
  34846. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34847. {
  34848. document = other.document;
  34849. currentLine = other.currentLine;
  34850. line = other.line;
  34851. position = other.position;
  34852. return *this;
  34853. }
  34854. CodeDocument::Iterator::~Iterator() throw()
  34855. {
  34856. }
  34857. juce_wchar CodeDocument::Iterator::nextChar()
  34858. {
  34859. if (currentLine == 0)
  34860. return 0;
  34861. jassert (currentLine == document->lines.getUnchecked (line));
  34862. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34863. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34864. {
  34865. ++line;
  34866. currentLine = document->lines [line];
  34867. }
  34868. return result;
  34869. }
  34870. void CodeDocument::Iterator::skip()
  34871. {
  34872. if (currentLine != 0)
  34873. {
  34874. jassert (currentLine == document->lines.getUnchecked (line));
  34875. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34876. {
  34877. ++line;
  34878. currentLine = document->lines [line];
  34879. }
  34880. }
  34881. }
  34882. void CodeDocument::Iterator::skipToEndOfLine()
  34883. {
  34884. if (currentLine != 0)
  34885. {
  34886. jassert (currentLine == document->lines.getUnchecked (line));
  34887. ++line;
  34888. currentLine = document->lines [line];
  34889. if (currentLine != 0)
  34890. position = currentLine->lineStartInFile;
  34891. else
  34892. position = document->getNumCharacters();
  34893. }
  34894. }
  34895. juce_wchar CodeDocument::Iterator::peekNextChar() const
  34896. {
  34897. if (currentLine == 0)
  34898. return 0;
  34899. jassert (currentLine == document->lines.getUnchecked (line));
  34900. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  34901. }
  34902. void CodeDocument::Iterator::skipWhitespace()
  34903. {
  34904. while (CharacterFunctions::isWhitespace (peekNextChar()))
  34905. skip();
  34906. }
  34907. bool CodeDocument::Iterator::isEOF() const throw()
  34908. {
  34909. return currentLine == 0;
  34910. }
  34911. CodeDocument::Position::Position() throw()
  34912. : owner (0), characterPos (0), line (0),
  34913. indexInLine (0), positionMaintained (false)
  34914. {
  34915. }
  34916. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34917. const int line_, const int indexInLine_) throw()
  34918. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34919. characterPos (0), line (line_),
  34920. indexInLine (indexInLine_), positionMaintained (false)
  34921. {
  34922. setLineAndIndex (line_, indexInLine_);
  34923. }
  34924. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34925. const int characterPos_) throw()
  34926. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34927. positionMaintained (false)
  34928. {
  34929. setPosition (characterPos_);
  34930. }
  34931. CodeDocument::Position::Position (const Position& other) throw()
  34932. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  34933. indexInLine (other.indexInLine), positionMaintained (false)
  34934. {
  34935. jassert (*this == other);
  34936. }
  34937. CodeDocument::Position::~Position() throw()
  34938. {
  34939. setPositionMaintained (false);
  34940. }
  34941. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  34942. {
  34943. if (this != &other)
  34944. {
  34945. const bool wasPositionMaintained = positionMaintained;
  34946. if (owner != other.owner)
  34947. setPositionMaintained (false);
  34948. owner = other.owner;
  34949. line = other.line;
  34950. indexInLine = other.indexInLine;
  34951. characterPos = other.characterPos;
  34952. setPositionMaintained (wasPositionMaintained);
  34953. jassert (*this == other);
  34954. }
  34955. return *this;
  34956. }
  34957. bool CodeDocument::Position::operator== (const Position& other) const throw()
  34958. {
  34959. jassert ((characterPos == other.characterPos)
  34960. == (line == other.line && indexInLine == other.indexInLine));
  34961. return characterPos == other.characterPos
  34962. && line == other.line
  34963. && indexInLine == other.indexInLine
  34964. && owner == other.owner;
  34965. }
  34966. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  34967. {
  34968. return ! operator== (other);
  34969. }
  34970. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  34971. {
  34972. jassert (owner != 0);
  34973. if (owner->lines.size() == 0)
  34974. {
  34975. line = 0;
  34976. indexInLine = 0;
  34977. characterPos = 0;
  34978. }
  34979. else
  34980. {
  34981. if (newLine >= owner->lines.size())
  34982. {
  34983. line = owner->lines.size() - 1;
  34984. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34985. jassert (l != 0);
  34986. indexInLine = l->lineLengthWithoutNewLines;
  34987. characterPos = l->lineStartInFile + indexInLine;
  34988. }
  34989. else
  34990. {
  34991. line = jmax (0, newLine);
  34992. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34993. jassert (l != 0);
  34994. if (l->lineLengthWithoutNewLines > 0)
  34995. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  34996. else
  34997. indexInLine = 0;
  34998. characterPos = l->lineStartInFile + indexInLine;
  34999. }
  35000. }
  35001. }
  35002. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35003. {
  35004. jassert (owner != 0);
  35005. line = 0;
  35006. indexInLine = 0;
  35007. characterPos = 0;
  35008. if (newPosition > 0)
  35009. {
  35010. int lineStart = 0;
  35011. int lineEnd = owner->lines.size();
  35012. for (;;)
  35013. {
  35014. if (lineEnd - lineStart < 4)
  35015. {
  35016. for (int i = lineStart; i < lineEnd; ++i)
  35017. {
  35018. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35019. int index = newPosition - l->lineStartInFile;
  35020. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35021. {
  35022. line = i;
  35023. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35024. characterPos = l->lineStartInFile + indexInLine;
  35025. }
  35026. }
  35027. break;
  35028. }
  35029. else
  35030. {
  35031. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35032. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35033. if (newPosition >= mid->lineStartInFile)
  35034. lineStart = midIndex;
  35035. else
  35036. lineEnd = midIndex;
  35037. }
  35038. }
  35039. }
  35040. }
  35041. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35042. {
  35043. jassert (owner != 0);
  35044. if (characterDelta == 1)
  35045. {
  35046. setPosition (getPosition());
  35047. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35048. if (line < owner->lines.size())
  35049. {
  35050. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35051. if (indexInLine + characterDelta < l->lineLength
  35052. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35053. ++characterDelta;
  35054. }
  35055. }
  35056. setPosition (characterPos + characterDelta);
  35057. }
  35058. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35059. {
  35060. CodeDocument::Position p (*this);
  35061. p.moveBy (characterDelta);
  35062. return p;
  35063. }
  35064. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35065. {
  35066. CodeDocument::Position p (*this);
  35067. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35068. return p;
  35069. }
  35070. const tchar CodeDocument::Position::getCharacter() const throw()
  35071. {
  35072. const CodeDocumentLine* const l = owner->lines [line];
  35073. return l == 0 ? 0 : l->line [getIndexInLine()];
  35074. }
  35075. const String CodeDocument::Position::getLineText() const throw()
  35076. {
  35077. const CodeDocumentLine* const l = owner->lines [line];
  35078. return l == 0 ? String::empty : l->line;
  35079. }
  35080. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35081. {
  35082. if (isMaintained != positionMaintained)
  35083. {
  35084. positionMaintained = isMaintained;
  35085. if (owner != 0)
  35086. {
  35087. if (isMaintained)
  35088. {
  35089. jassert (! owner->positionsToMaintain.contains (this));
  35090. owner->positionsToMaintain.add (this);
  35091. }
  35092. else
  35093. {
  35094. jassert (owner->positionsToMaintain.contains (this));
  35095. owner->positionsToMaintain.removeValue (this);
  35096. }
  35097. }
  35098. }
  35099. }
  35100. CodeDocument::CodeDocument()
  35101. : undoManager (std::numeric_limits<int>::max(), 10000),
  35102. currentActionIndex (0),
  35103. indexOfSavedState (-1),
  35104. maximumLineLength (-1),
  35105. newLineChars ("\r\n")
  35106. {
  35107. }
  35108. CodeDocument::~CodeDocument()
  35109. {
  35110. }
  35111. const String CodeDocument::getAllContent() const throw()
  35112. {
  35113. return getTextBetween (Position (this, 0),
  35114. Position (this, lines.size(), 0));
  35115. }
  35116. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35117. {
  35118. if (end.getPosition() <= start.getPosition())
  35119. return String::empty;
  35120. const int startLine = start.getLineNumber();
  35121. const int endLine = end.getLineNumber();
  35122. if (startLine == endLine)
  35123. {
  35124. CodeDocumentLine* const line = lines [startLine];
  35125. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35126. }
  35127. String result;
  35128. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35129. String::Concatenator concatenator (result);
  35130. const int maxLine = jmin (lines.size() - 1, endLine);
  35131. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35132. {
  35133. const CodeDocumentLine* line = lines.getUnchecked(i);
  35134. int len = line->lineLength;
  35135. if (i == startLine)
  35136. {
  35137. const int index = start.getIndexInLine();
  35138. concatenator.append (line->line.substring (index, len));
  35139. }
  35140. else if (i == endLine)
  35141. {
  35142. len = end.getIndexInLine();
  35143. concatenator.append (line->line.substring (0, len));
  35144. }
  35145. else
  35146. {
  35147. concatenator.append (line->line);
  35148. }
  35149. }
  35150. return result;
  35151. }
  35152. int CodeDocument::getNumCharacters() const throw()
  35153. {
  35154. const CodeDocumentLine* const lastLine = lines.getLast();
  35155. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35156. }
  35157. const String CodeDocument::getLine (const int lineIndex) const throw()
  35158. {
  35159. const CodeDocumentLine* const line = lines [lineIndex];
  35160. return (line == 0) ? String::empty : line->line;
  35161. }
  35162. int CodeDocument::getMaximumLineLength() throw()
  35163. {
  35164. if (maximumLineLength < 0)
  35165. {
  35166. maximumLineLength = 0;
  35167. for (int i = lines.size(); --i >= 0;)
  35168. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35169. }
  35170. return maximumLineLength;
  35171. }
  35172. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35173. {
  35174. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35175. }
  35176. void CodeDocument::insertText (const Position& position, const String& text)
  35177. {
  35178. insert (text, position.getPosition(), true);
  35179. }
  35180. void CodeDocument::replaceAllContent (const String& newContent)
  35181. {
  35182. remove (0, getNumCharacters(), true);
  35183. insert (newContent, 0, true);
  35184. }
  35185. bool CodeDocument::loadFromStream (InputStream& stream)
  35186. {
  35187. replaceAllContent (stream.readEntireStreamAsString());
  35188. setSavePoint();
  35189. clearUndoHistory();
  35190. return true;
  35191. }
  35192. bool CodeDocument::writeToStream (OutputStream& stream)
  35193. {
  35194. for (int i = 0; i < lines.size(); ++i)
  35195. {
  35196. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35197. const char* utf8 = temp.toUTF8();
  35198. if (! stream.write (utf8, (int) strlen (utf8)))
  35199. return false;
  35200. }
  35201. return true;
  35202. }
  35203. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35204. {
  35205. jassert (newLine == "\r\n" || newLine == "\n" || newLine == "\r");
  35206. newLineChars = newLine;
  35207. }
  35208. void CodeDocument::newTransaction()
  35209. {
  35210. undoManager.beginNewTransaction (String::empty);
  35211. }
  35212. void CodeDocument::undo()
  35213. {
  35214. newTransaction();
  35215. undoManager.undo();
  35216. }
  35217. void CodeDocument::redo()
  35218. {
  35219. undoManager.redo();
  35220. }
  35221. void CodeDocument::clearUndoHistory()
  35222. {
  35223. undoManager.clearUndoHistory();
  35224. }
  35225. void CodeDocument::setSavePoint() throw()
  35226. {
  35227. indexOfSavedState = currentActionIndex;
  35228. }
  35229. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35230. {
  35231. return currentActionIndex != indexOfSavedState;
  35232. }
  35233. static int getCodeCharacterCategory (const tchar character) throw()
  35234. {
  35235. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35236. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35237. }
  35238. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35239. {
  35240. Position p (position);
  35241. const int maxDistance = 256;
  35242. int i = 0;
  35243. while (i < maxDistance
  35244. && CharacterFunctions::isWhitespace (p.getCharacter())
  35245. && (i == 0 || (p.getCharacter() != '\n'
  35246. && p.getCharacter() != '\r')))
  35247. {
  35248. ++i;
  35249. p.moveBy (1);
  35250. }
  35251. if (i == 0)
  35252. {
  35253. const int type = getCodeCharacterCategory (p.getCharacter());
  35254. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35255. {
  35256. ++i;
  35257. p.moveBy (1);
  35258. }
  35259. while (i < maxDistance
  35260. && CharacterFunctions::isWhitespace (p.getCharacter())
  35261. && (i == 0 || (p.getCharacter() != '\n'
  35262. && p.getCharacter() != '\r')))
  35263. {
  35264. ++i;
  35265. p.moveBy (1);
  35266. }
  35267. }
  35268. return p;
  35269. }
  35270. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35271. {
  35272. Position p (position);
  35273. const int maxDistance = 256;
  35274. int i = 0;
  35275. bool stoppedAtLineStart = false;
  35276. while (i < maxDistance)
  35277. {
  35278. const tchar c = p.movedBy (-1).getCharacter();
  35279. if (c == '\r' || c == '\n')
  35280. {
  35281. stoppedAtLineStart = true;
  35282. if (i > 0)
  35283. break;
  35284. }
  35285. if (! CharacterFunctions::isWhitespace (c))
  35286. break;
  35287. p.moveBy (-1);
  35288. ++i;
  35289. }
  35290. if (i < maxDistance && ! stoppedAtLineStart)
  35291. {
  35292. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35293. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35294. {
  35295. p.moveBy (-1);
  35296. ++i;
  35297. }
  35298. }
  35299. return p;
  35300. }
  35301. void CodeDocument::checkLastLineStatus()
  35302. {
  35303. while (lines.size() > 0
  35304. && lines.getLast()->lineLength == 0
  35305. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35306. {
  35307. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35308. lines.removeLast();
  35309. }
  35310. const CodeDocumentLine* const lastLine = lines.getLast();
  35311. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35312. {
  35313. // check that there's an empty line at the end if the preceding one ends in a newline..
  35314. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35315. }
  35316. }
  35317. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35318. {
  35319. listeners.addIfNotAlreadyThere (listener);
  35320. }
  35321. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35322. {
  35323. listeners.removeValue (listener);
  35324. }
  35325. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35326. {
  35327. const Position startPos (this, startLine, 0);
  35328. const Position endPos (this, endLine, 0);
  35329. for (int i = listeners.size(); --i >= 0;)
  35330. {
  35331. Listener* const l = (Listener*) listeners[i];
  35332. if (l != 0)
  35333. l->codeDocumentChanged (startPos, endPos);
  35334. }
  35335. }
  35336. class CodeDocumentInsertAction : public UndoableAction
  35337. {
  35338. CodeDocument& owner;
  35339. const String text;
  35340. int insertPos;
  35341. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35342. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35343. public:
  35344. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35345. : owner (owner_),
  35346. text (text_),
  35347. insertPos (insertPos_)
  35348. {
  35349. }
  35350. ~CodeDocumentInsertAction() {}
  35351. bool perform()
  35352. {
  35353. owner.currentActionIndex++;
  35354. owner.insert (text, insertPos, false);
  35355. return true;
  35356. }
  35357. bool undo()
  35358. {
  35359. owner.currentActionIndex--;
  35360. owner.remove (insertPos, insertPos + text.length(), false);
  35361. return true;
  35362. }
  35363. int getSizeInUnits() { return text.length() + 32; }
  35364. };
  35365. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35366. {
  35367. if (text.isEmpty())
  35368. return;
  35369. if (undoable)
  35370. {
  35371. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35372. }
  35373. else
  35374. {
  35375. Position pos (this, insertPos);
  35376. const int firstAffectedLine = pos.getLineNumber();
  35377. int lastAffectedLine = firstAffectedLine + 1;
  35378. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35379. String textInsideOriginalLine (text);
  35380. if (firstLine != 0)
  35381. {
  35382. const int index = pos.getIndexInLine();
  35383. textInsideOriginalLine = firstLine->line.substring (0, index)
  35384. + textInsideOriginalLine
  35385. + firstLine->line.substring (index);
  35386. }
  35387. maximumLineLength = -1;
  35388. Array <CodeDocumentLine*> newLines;
  35389. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35390. jassert (newLines.size() > 0);
  35391. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35392. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35393. lines.set (firstAffectedLine, newFirstLine);
  35394. if (newLines.size() > 1)
  35395. {
  35396. for (int i = 1; i < newLines.size(); ++i)
  35397. {
  35398. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35399. lines.insert (firstAffectedLine + i, l);
  35400. }
  35401. lastAffectedLine = lines.size();
  35402. }
  35403. int i, lineStart = newFirstLine->lineStartInFile;
  35404. for (i = firstAffectedLine; i < lines.size(); ++i)
  35405. {
  35406. CodeDocumentLine* const l = lines.getUnchecked (i);
  35407. l->lineStartInFile = lineStart;
  35408. lineStart += l->lineLength;
  35409. }
  35410. checkLastLineStatus();
  35411. const int newTextLength = text.length();
  35412. for (i = 0; i < positionsToMaintain.size(); ++i)
  35413. {
  35414. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35415. if (p->getPosition() >= insertPos)
  35416. p->setPosition (p->getPosition() + newTextLength);
  35417. }
  35418. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35419. }
  35420. }
  35421. class CodeDocumentDeleteAction : public UndoableAction
  35422. {
  35423. CodeDocument& owner;
  35424. int startPos, endPos;
  35425. String removedText;
  35426. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35427. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35428. public:
  35429. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35430. : owner (owner_),
  35431. startPos (startPos_),
  35432. endPos (endPos_)
  35433. {
  35434. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35435. CodeDocument::Position (&owner, endPos));
  35436. }
  35437. ~CodeDocumentDeleteAction() {}
  35438. bool perform()
  35439. {
  35440. owner.currentActionIndex++;
  35441. owner.remove (startPos, endPos, false);
  35442. return true;
  35443. }
  35444. bool undo()
  35445. {
  35446. owner.currentActionIndex--;
  35447. owner.insert (removedText, startPos, false);
  35448. return true;
  35449. }
  35450. int getSizeInUnits() { return removedText.length() + 32; }
  35451. };
  35452. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35453. {
  35454. if (endPos <= startPos)
  35455. return;
  35456. if (undoable)
  35457. {
  35458. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35459. }
  35460. else
  35461. {
  35462. Position startPosition (this, startPos);
  35463. Position endPosition (this, endPos);
  35464. maximumLineLength = -1;
  35465. const int firstAffectedLine = startPosition.getLineNumber();
  35466. const int endLine = endPosition.getLineNumber();
  35467. int lastAffectedLine = firstAffectedLine + 1;
  35468. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35469. if (firstAffectedLine == endLine)
  35470. {
  35471. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35472. + firstLine->line.substring (endPosition.getIndexInLine());
  35473. firstLine->updateLength();
  35474. }
  35475. else
  35476. {
  35477. lastAffectedLine = lines.size();
  35478. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35479. jassert (lastLine != 0);
  35480. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35481. + lastLine->line.substring (endPosition.getIndexInLine());
  35482. firstLine->updateLength();
  35483. int numLinesToRemove = endLine - firstAffectedLine;
  35484. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35485. }
  35486. int i;
  35487. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35488. {
  35489. CodeDocumentLine* const l = lines.getUnchecked (i);
  35490. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35491. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35492. }
  35493. checkLastLineStatus();
  35494. const int totalChars = getNumCharacters();
  35495. for (i = 0; i < positionsToMaintain.size(); ++i)
  35496. {
  35497. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35498. if (p->getPosition() > startPosition.getPosition())
  35499. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35500. if (p->getPosition() > totalChars)
  35501. p->setPosition (totalChars);
  35502. }
  35503. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35504. }
  35505. }
  35506. END_JUCE_NAMESPACE
  35507. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35508. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35509. BEGIN_JUCE_NAMESPACE
  35510. class CaretComponent : public Component,
  35511. public Timer
  35512. {
  35513. public:
  35514. CaretComponent()
  35515. {
  35516. setAlwaysOnTop (true);
  35517. setInterceptsMouseClicks (false, false);
  35518. }
  35519. ~CaretComponent()
  35520. {
  35521. }
  35522. void paint (Graphics& g)
  35523. {
  35524. if (getParentComponent()->hasKeyboardFocus (true))
  35525. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35526. }
  35527. void timerCallback()
  35528. {
  35529. setVisible (! isVisible());
  35530. }
  35531. void updatePosition (CodeEditorComponent& owner)
  35532. {
  35533. startTimer (400);
  35534. setVisible (true);
  35535. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35536. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35537. }
  35538. };
  35539. class CodeEditorComponent::CodeEditorLine
  35540. {
  35541. public:
  35542. CodeEditorLine() throw()
  35543. {
  35544. }
  35545. ~CodeEditorLine() throw()
  35546. {
  35547. }
  35548. bool update (CodeDocument& document, int lineNum,
  35549. CodeDocument::Iterator& source,
  35550. CodeTokeniser* analyser, const int spacesPerTab,
  35551. const CodeDocument::Position& selectionStart,
  35552. const CodeDocument::Position& selectionEnd)
  35553. {
  35554. Array <SyntaxToken> newTokens;
  35555. newTokens.ensureStorageAllocated (8);
  35556. if (analyser == 0)
  35557. {
  35558. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35559. }
  35560. else if (lineNum < document.getNumLines())
  35561. {
  35562. const CodeDocument::Position pos (&document, lineNum, 0);
  35563. createTokens (pos.getPosition(), pos.getLineText(),
  35564. source, analyser, newTokens);
  35565. }
  35566. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35567. int newHighlightStart = 0;
  35568. int newHighlightEnd = 0;
  35569. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35570. {
  35571. const String line (document.getLine (lineNum));
  35572. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35573. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35574. line, spacesPerTab);
  35575. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35576. line, spacesPerTab);
  35577. }
  35578. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35579. {
  35580. highlightColumnStart = newHighlightStart;
  35581. highlightColumnEnd = newHighlightEnd;
  35582. }
  35583. else
  35584. {
  35585. if (tokens.size() == newTokens.size())
  35586. {
  35587. bool allTheSame = true;
  35588. for (int i = newTokens.size(); --i >= 0;)
  35589. {
  35590. if (tokens.getReference(i) != newTokens.getReference(i))
  35591. {
  35592. allTheSame = false;
  35593. break;
  35594. }
  35595. }
  35596. if (allTheSame)
  35597. return false;
  35598. }
  35599. }
  35600. tokens.swapWithArray (newTokens);
  35601. return true;
  35602. }
  35603. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35604. float x, const int y, const int baselineOffset, const int lineHeight,
  35605. const Colour& highlightColour) const throw()
  35606. {
  35607. if (highlightColumnStart < highlightColumnEnd)
  35608. {
  35609. g.setColour (highlightColour);
  35610. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35611. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35612. }
  35613. int lastType = std::numeric_limits<int>::min();
  35614. for (int i = 0; i < tokens.size(); ++i)
  35615. {
  35616. SyntaxToken& token = tokens.getReference(i);
  35617. if (lastType != token.tokenType)
  35618. {
  35619. lastType = token.tokenType;
  35620. g.setColour (owner.getColourForTokenType (lastType));
  35621. }
  35622. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35623. if (i < tokens.size() - 1)
  35624. {
  35625. if (token.width < 0)
  35626. token.width = font.getStringWidthFloat (token.text);
  35627. x += token.width;
  35628. }
  35629. }
  35630. }
  35631. private:
  35632. struct SyntaxToken
  35633. {
  35634. String text;
  35635. int tokenType;
  35636. float width;
  35637. SyntaxToken (const String& text_, const int type) throw()
  35638. : text (text_), tokenType (type), width (-1.0f)
  35639. {
  35640. }
  35641. bool operator!= (const SyntaxToken& other) const throw()
  35642. {
  35643. return text != other.text || tokenType != other.tokenType;
  35644. }
  35645. };
  35646. Array <SyntaxToken> tokens;
  35647. int highlightColumnStart, highlightColumnEnd;
  35648. static void createTokens (int startPosition, const String& lineText,
  35649. CodeDocument::Iterator& source,
  35650. CodeTokeniser* analyser,
  35651. Array <SyntaxToken>& newTokens)
  35652. {
  35653. CodeDocument::Iterator lastIterator (source);
  35654. const int lineLength = lineText.length();
  35655. for (;;)
  35656. {
  35657. int tokenType = analyser->readNextToken (source);
  35658. int tokenStart = lastIterator.getPosition();
  35659. int tokenEnd = source.getPosition();
  35660. if (tokenEnd <= tokenStart)
  35661. break;
  35662. tokenEnd -= startPosition;
  35663. if (tokenEnd > 0)
  35664. {
  35665. tokenStart -= startPosition;
  35666. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35667. tokenType));
  35668. if (tokenEnd >= lineLength)
  35669. break;
  35670. }
  35671. lastIterator = source;
  35672. }
  35673. source = lastIterator;
  35674. }
  35675. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35676. {
  35677. int x = 0;
  35678. for (int i = 0; i < tokens.size(); ++i)
  35679. {
  35680. SyntaxToken& t = tokens.getReference(i);
  35681. for (;;)
  35682. {
  35683. int tabPos = t.text.indexOfChar ('\t');
  35684. if (tabPos < 0)
  35685. break;
  35686. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35687. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (" ", spacesNeeded));
  35688. }
  35689. x += t.text.length();
  35690. }
  35691. }
  35692. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35693. {
  35694. jassert (index <= line.length());
  35695. int col = 0;
  35696. for (int i = 0; i < index; ++i)
  35697. {
  35698. if (line[i] != '\t')
  35699. ++col;
  35700. else
  35701. col += spacesPerTab - (col % spacesPerTab);
  35702. }
  35703. return col;
  35704. }
  35705. };
  35706. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35707. CodeTokeniser* const codeTokeniser_)
  35708. : document (document_),
  35709. firstLineOnScreen (0),
  35710. gutter (5),
  35711. spacesPerTab (4),
  35712. lineHeight (0),
  35713. linesOnScreen (0),
  35714. columnsOnScreen (0),
  35715. scrollbarThickness (16),
  35716. columnToTryToMaintain (-1),
  35717. useSpacesForTabs (false),
  35718. xOffset (0),
  35719. codeTokeniser (codeTokeniser_)
  35720. {
  35721. caretPos = CodeDocument::Position (&document_, 0, 0);
  35722. caretPos.setPositionMaintained (true);
  35723. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35724. selectionStart.setPositionMaintained (true);
  35725. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35726. selectionEnd.setPositionMaintained (true);
  35727. setOpaque (true);
  35728. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35729. setWantsKeyboardFocus (true);
  35730. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35731. verticalScrollBar->setSingleStepSize (1.0);
  35732. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35733. horizontalScrollBar->setSingleStepSize (1.0);
  35734. addAndMakeVisible (caret = new CaretComponent());
  35735. Font f (12.0f);
  35736. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35737. setFont (f);
  35738. resetToDefaultColours();
  35739. verticalScrollBar->addListener (this);
  35740. horizontalScrollBar->addListener (this);
  35741. document.addListener (this);
  35742. }
  35743. CodeEditorComponent::~CodeEditorComponent()
  35744. {
  35745. document.removeListener (this);
  35746. deleteAllChildren();
  35747. }
  35748. void CodeEditorComponent::loadContent (const String& newContent)
  35749. {
  35750. clearCachedIterators (0);
  35751. document.replaceAllContent (newContent);
  35752. document.clearUndoHistory();
  35753. document.setSavePoint();
  35754. caretPos.setPosition (0);
  35755. selectionStart.setPosition (0);
  35756. selectionEnd.setPosition (0);
  35757. scrollToLine (0);
  35758. }
  35759. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35760. const CodeDocument::Position& affectedTextEnd)
  35761. {
  35762. clearCachedIterators (affectedTextStart.getLineNumber());
  35763. triggerAsyncUpdate();
  35764. ((CaretComponent*) caret)->updatePosition (*this);
  35765. columnToTryToMaintain = -1;
  35766. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35767. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35768. deselectAll();
  35769. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35770. || caretPos.getPosition() < affectedTextStart.getPosition())
  35771. moveCaretTo (affectedTextStart, false);
  35772. updateScrollBars();
  35773. }
  35774. void CodeEditorComponent::resized()
  35775. {
  35776. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35777. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35778. lines.clear();
  35779. rebuildLineTokens();
  35780. ((CaretComponent*) caret)->updatePosition (*this);
  35781. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35782. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35783. updateScrollBars();
  35784. }
  35785. void CodeEditorComponent::paint (Graphics& g)
  35786. {
  35787. handleUpdateNowIfNeeded();
  35788. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35789. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35790. g.setFont (font);
  35791. const int baselineOffset = (int) font.getAscent();
  35792. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35793. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35794. const Rectangle<int> clip (g.getClipBounds());
  35795. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35796. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35797. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35798. {
  35799. lines.getUnchecked(j)->draw (*this, g, font,
  35800. (float) (gutter - xOffset * charWidth),
  35801. lineHeight * j, baselineOffset, lineHeight,
  35802. highlightColour);
  35803. }
  35804. }
  35805. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35806. {
  35807. if (scrollbarThickness != thickness)
  35808. {
  35809. scrollbarThickness = thickness;
  35810. resized();
  35811. }
  35812. }
  35813. void CodeEditorComponent::handleAsyncUpdate()
  35814. {
  35815. rebuildLineTokens();
  35816. }
  35817. void CodeEditorComponent::rebuildLineTokens()
  35818. {
  35819. cancelPendingUpdate();
  35820. const int numNeeded = linesOnScreen + 1;
  35821. int minLineToRepaint = numNeeded;
  35822. int maxLineToRepaint = 0;
  35823. if (numNeeded != lines.size())
  35824. {
  35825. lines.clear();
  35826. for (int i = numNeeded; --i >= 0;)
  35827. lines.add (new CodeEditorLine());
  35828. minLineToRepaint = 0;
  35829. maxLineToRepaint = numNeeded;
  35830. }
  35831. jassert (numNeeded == lines.size());
  35832. CodeDocument::Iterator source (&document);
  35833. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35834. for (int i = 0; i < numNeeded; ++i)
  35835. {
  35836. CodeEditorLine* const line = lines.getUnchecked(i);
  35837. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35838. selectionStart, selectionEnd))
  35839. {
  35840. minLineToRepaint = jmin (minLineToRepaint, i);
  35841. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35842. }
  35843. }
  35844. if (minLineToRepaint <= maxLineToRepaint)
  35845. {
  35846. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35847. verticalScrollBar->getX() - gutter,
  35848. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35849. }
  35850. }
  35851. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35852. {
  35853. caretPos = newPos;
  35854. columnToTryToMaintain = -1;
  35855. if (highlighting)
  35856. {
  35857. if (dragType == notDragging)
  35858. {
  35859. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35860. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35861. dragType = draggingSelectionStart;
  35862. else
  35863. dragType = draggingSelectionEnd;
  35864. }
  35865. if (dragType == draggingSelectionStart)
  35866. {
  35867. selectionStart = caretPos;
  35868. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35869. {
  35870. const CodeDocument::Position temp (selectionStart);
  35871. selectionStart = selectionEnd;
  35872. selectionEnd = temp;
  35873. dragType = draggingSelectionEnd;
  35874. }
  35875. }
  35876. else
  35877. {
  35878. selectionEnd = caretPos;
  35879. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35880. {
  35881. const CodeDocument::Position temp (selectionStart);
  35882. selectionStart = selectionEnd;
  35883. selectionEnd = temp;
  35884. dragType = draggingSelectionStart;
  35885. }
  35886. }
  35887. triggerAsyncUpdate();
  35888. }
  35889. else
  35890. {
  35891. deselectAll();
  35892. }
  35893. ((CaretComponent*) caret)->updatePosition (*this);
  35894. scrollToKeepCaretOnScreen();
  35895. updateScrollBars();
  35896. }
  35897. void CodeEditorComponent::deselectAll()
  35898. {
  35899. if (selectionStart != selectionEnd)
  35900. triggerAsyncUpdate();
  35901. selectionStart = caretPos;
  35902. selectionEnd = caretPos;
  35903. }
  35904. void CodeEditorComponent::updateScrollBars()
  35905. {
  35906. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  35907. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  35908. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  35909. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  35910. }
  35911. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  35912. {
  35913. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  35914. newFirstLineOnScreen);
  35915. if (newFirstLineOnScreen != firstLineOnScreen)
  35916. {
  35917. firstLineOnScreen = newFirstLineOnScreen;
  35918. ((CaretComponent*) caret)->updatePosition (*this);
  35919. updateCachedIterators (firstLineOnScreen);
  35920. triggerAsyncUpdate();
  35921. }
  35922. }
  35923. void CodeEditorComponent::scrollToColumnInternal (double column)
  35924. {
  35925. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  35926. if (xOffset != newOffset)
  35927. {
  35928. xOffset = newOffset;
  35929. ((CaretComponent*) caret)->updatePosition (*this);
  35930. repaint();
  35931. }
  35932. }
  35933. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  35934. {
  35935. scrollToLineInternal (newFirstLineOnScreen);
  35936. updateScrollBars();
  35937. }
  35938. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  35939. {
  35940. scrollToColumnInternal (newFirstColumnOnScreen);
  35941. updateScrollBars();
  35942. }
  35943. void CodeEditorComponent::scrollBy (int deltaLines)
  35944. {
  35945. scrollToLine (firstLineOnScreen + deltaLines);
  35946. }
  35947. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  35948. {
  35949. if (caretPos.getLineNumber() < firstLineOnScreen)
  35950. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  35951. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35952. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  35953. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35954. if (column >= xOffset + columnsOnScreen - 1)
  35955. scrollToColumn (column + 1 - columnsOnScreen);
  35956. else if (column < xOffset)
  35957. scrollToColumn (column);
  35958. }
  35959. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  35960. {
  35961. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  35962. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  35963. roundToInt (charWidth),
  35964. lineHeight);
  35965. }
  35966. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  35967. {
  35968. const int line = y / lineHeight + firstLineOnScreen;
  35969. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  35970. const int index = columnToIndex (line, column);
  35971. return CodeDocument::Position (&document, line, index);
  35972. }
  35973. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  35974. {
  35975. document.deleteSection (selectionStart, selectionEnd);
  35976. if (newText.isNotEmpty())
  35977. document.insertText (caretPos, newText);
  35978. scrollToKeepCaretOnScreen();
  35979. }
  35980. void CodeEditorComponent::insertTabAtCaret()
  35981. {
  35982. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  35983. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  35984. {
  35985. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  35986. }
  35987. if (useSpacesForTabs)
  35988. {
  35989. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35990. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  35991. insertTextAtCaret (String::repeatedString (" ", spacesNeeded));
  35992. }
  35993. else
  35994. {
  35995. insertTextAtCaret ("\t");
  35996. }
  35997. }
  35998. void CodeEditorComponent::cut()
  35999. {
  36000. insertTextAtCaret (String::empty);
  36001. }
  36002. void CodeEditorComponent::copy()
  36003. {
  36004. newTransaction();
  36005. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36006. if (selection.isNotEmpty())
  36007. SystemClipboard::copyTextToClipboard (selection);
  36008. }
  36009. void CodeEditorComponent::copyThenCut()
  36010. {
  36011. copy();
  36012. cut();
  36013. newTransaction();
  36014. }
  36015. void CodeEditorComponent::paste()
  36016. {
  36017. newTransaction();
  36018. const String clip (SystemClipboard::getTextFromClipboard());
  36019. if (clip.isNotEmpty())
  36020. insertTextAtCaret (clip);
  36021. newTransaction();
  36022. }
  36023. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36024. {
  36025. newTransaction();
  36026. if (moveInWholeWordSteps)
  36027. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36028. else
  36029. moveCaretTo (caretPos.movedBy (-1), selecting);
  36030. }
  36031. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36032. {
  36033. newTransaction();
  36034. if (moveInWholeWordSteps)
  36035. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36036. else
  36037. moveCaretTo (caretPos.movedBy (1), selecting);
  36038. }
  36039. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36040. {
  36041. CodeDocument::Position pos (caretPos);
  36042. const int newLineNum = pos.getLineNumber() + delta;
  36043. if (columnToTryToMaintain < 0)
  36044. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36045. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36046. const int colToMaintain = columnToTryToMaintain;
  36047. moveCaretTo (pos, selecting);
  36048. columnToTryToMaintain = colToMaintain;
  36049. }
  36050. void CodeEditorComponent::cursorDown (const bool selecting)
  36051. {
  36052. newTransaction();
  36053. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36054. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36055. else
  36056. moveLineDelta (1, selecting);
  36057. }
  36058. void CodeEditorComponent::cursorUp (const bool selecting)
  36059. {
  36060. newTransaction();
  36061. if (caretPos.getLineNumber() == 0)
  36062. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36063. else
  36064. moveLineDelta (-1, selecting);
  36065. }
  36066. void CodeEditorComponent::pageDown (const bool selecting)
  36067. {
  36068. newTransaction();
  36069. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36070. moveLineDelta (linesOnScreen, selecting);
  36071. }
  36072. void CodeEditorComponent::pageUp (const bool selecting)
  36073. {
  36074. newTransaction();
  36075. scrollBy (-linesOnScreen);
  36076. moveLineDelta (-linesOnScreen, selecting);
  36077. }
  36078. void CodeEditorComponent::scrollUp()
  36079. {
  36080. newTransaction();
  36081. scrollBy (1);
  36082. if (caretPos.getLineNumber() < firstLineOnScreen)
  36083. moveLineDelta (1, false);
  36084. }
  36085. void CodeEditorComponent::scrollDown()
  36086. {
  36087. newTransaction();
  36088. scrollBy (-1);
  36089. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36090. moveLineDelta (-1, false);
  36091. }
  36092. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36093. {
  36094. newTransaction();
  36095. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36096. }
  36097. static int findFirstNonWhitespaceChar (const String& line) throw()
  36098. {
  36099. const int len = line.length();
  36100. for (int i = 0; i < len; ++i)
  36101. if (! CharacterFunctions::isWhitespace (line [i]))
  36102. return i;
  36103. return 0;
  36104. }
  36105. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36106. {
  36107. newTransaction();
  36108. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36109. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36110. index = 0;
  36111. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36112. }
  36113. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36114. {
  36115. newTransaction();
  36116. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36117. }
  36118. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36119. {
  36120. newTransaction();
  36121. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36122. }
  36123. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36124. {
  36125. if (moveInWholeWordSteps)
  36126. {
  36127. cut(); // in case something is already highlighted
  36128. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36129. }
  36130. else
  36131. {
  36132. if (selectionStart == selectionEnd)
  36133. selectionStart.moveBy (-1);
  36134. }
  36135. cut();
  36136. }
  36137. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36138. {
  36139. if (moveInWholeWordSteps)
  36140. {
  36141. cut(); // in case something is already highlighted
  36142. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36143. }
  36144. else
  36145. {
  36146. if (selectionStart == selectionEnd)
  36147. selectionEnd.moveBy (1);
  36148. else
  36149. newTransaction();
  36150. }
  36151. cut();
  36152. }
  36153. void CodeEditorComponent::selectAll()
  36154. {
  36155. newTransaction();
  36156. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36157. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36158. }
  36159. void CodeEditorComponent::undo()
  36160. {
  36161. document.undo();
  36162. scrollToKeepCaretOnScreen();
  36163. }
  36164. void CodeEditorComponent::redo()
  36165. {
  36166. document.redo();
  36167. scrollToKeepCaretOnScreen();
  36168. }
  36169. void CodeEditorComponent::newTransaction()
  36170. {
  36171. document.newTransaction();
  36172. startTimer (600);
  36173. }
  36174. void CodeEditorComponent::timerCallback()
  36175. {
  36176. newTransaction();
  36177. }
  36178. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36179. {
  36180. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36181. }
  36182. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36183. {
  36184. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36185. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36186. }
  36187. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36188. {
  36189. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36190. CodeDocument::Position (&document, range.getEnd()));
  36191. }
  36192. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36193. {
  36194. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36195. const bool shiftDown = key.getModifiers().isShiftDown();
  36196. if (key.isKeyCode (KeyPress::leftKey))
  36197. {
  36198. cursorLeft (moveInWholeWordSteps, shiftDown);
  36199. }
  36200. else if (key.isKeyCode (KeyPress::rightKey))
  36201. {
  36202. cursorRight (moveInWholeWordSteps, shiftDown);
  36203. }
  36204. else if (key.isKeyCode (KeyPress::upKey))
  36205. {
  36206. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36207. scrollDown();
  36208. #if JUCE_MAC
  36209. else if (key.getModifiers().isCommandDown())
  36210. goToStartOfDocument (shiftDown);
  36211. #endif
  36212. else
  36213. cursorUp (shiftDown);
  36214. }
  36215. else if (key.isKeyCode (KeyPress::downKey))
  36216. {
  36217. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36218. scrollUp();
  36219. #if JUCE_MAC
  36220. else if (key.getModifiers().isCommandDown())
  36221. goToEndOfDocument (shiftDown);
  36222. #endif
  36223. else
  36224. cursorDown (shiftDown);
  36225. }
  36226. else if (key.isKeyCode (KeyPress::pageDownKey))
  36227. {
  36228. pageDown (shiftDown);
  36229. }
  36230. else if (key.isKeyCode (KeyPress::pageUpKey))
  36231. {
  36232. pageUp (shiftDown);
  36233. }
  36234. else if (key.isKeyCode (KeyPress::homeKey))
  36235. {
  36236. if (moveInWholeWordSteps)
  36237. goToStartOfDocument (shiftDown);
  36238. else
  36239. goToStartOfLine (shiftDown);
  36240. }
  36241. else if (key.isKeyCode (KeyPress::endKey))
  36242. {
  36243. if (moveInWholeWordSteps)
  36244. goToEndOfDocument (shiftDown);
  36245. else
  36246. goToEndOfLine (shiftDown);
  36247. }
  36248. else if (key.isKeyCode (KeyPress::backspaceKey))
  36249. {
  36250. backspace (moveInWholeWordSteps);
  36251. }
  36252. else if (key.isKeyCode (KeyPress::deleteKey))
  36253. {
  36254. deleteForward (moveInWholeWordSteps);
  36255. }
  36256. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0))
  36257. {
  36258. copy();
  36259. }
  36260. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  36261. {
  36262. copyThenCut();
  36263. }
  36264. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0))
  36265. {
  36266. paste();
  36267. }
  36268. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  36269. {
  36270. undo();
  36271. }
  36272. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0)
  36273. || key == KeyPress ('z', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36274. {
  36275. redo();
  36276. }
  36277. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  36278. {
  36279. selectAll();
  36280. }
  36281. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36282. {
  36283. insertTabAtCaret();
  36284. }
  36285. else if (key == KeyPress::returnKey)
  36286. {
  36287. newTransaction();
  36288. insertTextAtCaret (document.getNewLineCharacters());
  36289. }
  36290. else if (key.isKeyCode (KeyPress::escapeKey))
  36291. {
  36292. newTransaction();
  36293. }
  36294. else if (key.getTextCharacter() >= ' ')
  36295. {
  36296. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36297. }
  36298. else
  36299. {
  36300. return false;
  36301. }
  36302. return true;
  36303. }
  36304. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36305. {
  36306. newTransaction();
  36307. dragType = notDragging;
  36308. if (! e.mods.isPopupMenu())
  36309. {
  36310. beginDragAutoRepeat (100);
  36311. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36312. }
  36313. else
  36314. {
  36315. }
  36316. }
  36317. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36318. {
  36319. if (! e.mods.isPopupMenu())
  36320. moveCaretTo (getPositionAt (e.x, e.y), true);
  36321. }
  36322. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36323. {
  36324. newTransaction();
  36325. beginDragAutoRepeat (0);
  36326. dragType = notDragging;
  36327. }
  36328. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36329. {
  36330. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36331. CodeDocument::Position tokenEnd (tokenStart);
  36332. if (e.getNumberOfClicks() > 2)
  36333. {
  36334. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36335. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36336. }
  36337. else
  36338. {
  36339. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36340. tokenEnd.moveBy (1);
  36341. tokenStart = tokenEnd;
  36342. while (tokenStart.getIndexInLine() > 0
  36343. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36344. tokenStart.moveBy (-1);
  36345. }
  36346. moveCaretTo (tokenEnd, false);
  36347. moveCaretTo (tokenStart, true);
  36348. }
  36349. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36350. {
  36351. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36352. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36353. }
  36354. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36355. {
  36356. if (scrollBarThatHasMoved == verticalScrollBar)
  36357. scrollToLineInternal ((int) newRangeStart);
  36358. else
  36359. scrollToColumnInternal (newRangeStart);
  36360. }
  36361. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36362. {
  36363. useSpacesForTabs = insertSpaces;
  36364. if (spacesPerTab != numSpaces)
  36365. {
  36366. spacesPerTab = numSpaces;
  36367. triggerAsyncUpdate();
  36368. }
  36369. }
  36370. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36371. {
  36372. const String line (document.getLine (lineNum));
  36373. jassert (index <= line.length());
  36374. int col = 0;
  36375. for (int i = 0; i < index; ++i)
  36376. {
  36377. if (line[i] != '\t')
  36378. ++col;
  36379. else
  36380. col += getTabSize() - (col % getTabSize());
  36381. }
  36382. return col;
  36383. }
  36384. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36385. {
  36386. const String line (document.getLine (lineNum));
  36387. const int lineLength = line.length();
  36388. int i, col = 0;
  36389. for (i = 0; i < lineLength; ++i)
  36390. {
  36391. if (line[i] != '\t')
  36392. ++col;
  36393. else
  36394. col += getTabSize() - (col % getTabSize());
  36395. if (col > column)
  36396. break;
  36397. }
  36398. return i;
  36399. }
  36400. void CodeEditorComponent::setFont (const Font& newFont)
  36401. {
  36402. font = newFont;
  36403. charWidth = font.getStringWidthFloat ("0");
  36404. lineHeight = roundToInt (font.getHeight());
  36405. resized();
  36406. }
  36407. void CodeEditorComponent::resetToDefaultColours()
  36408. {
  36409. coloursForTokenCategories.clear();
  36410. if (codeTokeniser != 0)
  36411. {
  36412. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36413. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36414. }
  36415. }
  36416. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36417. {
  36418. jassert (tokenType < 256);
  36419. while (coloursForTokenCategories.size() < tokenType)
  36420. coloursForTokenCategories.add (Colours::black);
  36421. coloursForTokenCategories.set (tokenType, colour);
  36422. repaint();
  36423. }
  36424. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36425. {
  36426. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36427. return findColour (CodeEditorComponent::defaultTextColourId);
  36428. return coloursForTokenCategories.getReference (tokenType);
  36429. }
  36430. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36431. {
  36432. int i;
  36433. for (i = cachedIterators.size(); --i >= 0;)
  36434. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36435. break;
  36436. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36437. }
  36438. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36439. {
  36440. const int maxNumCachedPositions = 5000;
  36441. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36442. if (cachedIterators.size() == 0)
  36443. cachedIterators.add (new CodeDocument::Iterator (&document));
  36444. if (codeTokeniser == 0)
  36445. return;
  36446. for (;;)
  36447. {
  36448. CodeDocument::Iterator* last = cachedIterators.getLast();
  36449. if (last->getLine() >= maxLineNum)
  36450. break;
  36451. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36452. cachedIterators.add (t);
  36453. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36454. for (;;)
  36455. {
  36456. codeTokeniser->readNextToken (*t);
  36457. if (t->getLine() >= targetLine)
  36458. break;
  36459. if (t->isEOF())
  36460. return;
  36461. }
  36462. }
  36463. }
  36464. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36465. {
  36466. if (codeTokeniser == 0)
  36467. return;
  36468. for (int i = cachedIterators.size(); --i >= 0;)
  36469. {
  36470. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36471. if (t->getPosition() <= position)
  36472. {
  36473. source = *t;
  36474. break;
  36475. }
  36476. }
  36477. while (source.getPosition() < position)
  36478. {
  36479. const CodeDocument::Iterator original (source);
  36480. codeTokeniser->readNextToken (source);
  36481. if (source.getPosition() > position || source.isEOF())
  36482. {
  36483. source = original;
  36484. break;
  36485. }
  36486. }
  36487. }
  36488. END_JUCE_NAMESPACE
  36489. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36490. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36491. BEGIN_JUCE_NAMESPACE
  36492. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36493. {
  36494. }
  36495. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36496. {
  36497. }
  36498. namespace CppTokeniser
  36499. {
  36500. static bool isIdentifierStart (const tchar c) throw()
  36501. {
  36502. return CharacterFunctions::isLetter (c)
  36503. || c == '_' || c == '@';
  36504. }
  36505. static bool isIdentifierBody (const tchar c) throw()
  36506. {
  36507. return CharacterFunctions::isLetter (c)
  36508. || CharacterFunctions::isDigit (c)
  36509. || c == '_' || c == '@';
  36510. }
  36511. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36512. {
  36513. static const tchar* keywords2Char[] =
  36514. { T("if"), T("do"), T("or"), 0 };
  36515. static const tchar* keywords3Char[] =
  36516. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36517. static const tchar* keywords4Char[] =
  36518. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36519. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36520. static const tchar* keywords5Char[] =
  36521. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36522. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36523. static const tchar* keywords6Char[] =
  36524. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36525. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36526. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36527. static const tchar* keywordsOther[] =
  36528. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36529. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36530. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36531. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36532. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36533. int tokenLength = 0;
  36534. tchar possibleIdentifier [19];
  36535. while (isIdentifierBody (source.peekNextChar()))
  36536. {
  36537. const tchar c = source.nextChar();
  36538. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36539. possibleIdentifier [tokenLength] = c;
  36540. ++tokenLength;
  36541. }
  36542. if (tokenLength > 1 && tokenLength <= 16)
  36543. {
  36544. possibleIdentifier [tokenLength] = 0;
  36545. const tchar** k;
  36546. switch (tokenLength)
  36547. {
  36548. case 2: k = keywords2Char; break;
  36549. case 3: k = keywords3Char; break;
  36550. case 4: k = keywords4Char; break;
  36551. case 5: k = keywords5Char; break;
  36552. case 6: k = keywords6Char; break;
  36553. default: k = keywordsOther; break;
  36554. }
  36555. int i = 0;
  36556. while (k[i] != 0)
  36557. {
  36558. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36559. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36560. ++i;
  36561. }
  36562. }
  36563. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36564. }
  36565. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36566. {
  36567. const juce_wchar c = source.peekNextChar();
  36568. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36569. source.skip();
  36570. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36571. return false;
  36572. return true;
  36573. }
  36574. static bool isHexDigit (const juce_wchar c) throw()
  36575. {
  36576. return (c >= '0' && c <= '9')
  36577. || (c >= 'a' && c <= 'f')
  36578. || (c >= 'A' && c <= 'F');
  36579. }
  36580. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36581. {
  36582. if (source.nextChar() != '0')
  36583. return false;
  36584. juce_wchar c = source.nextChar();
  36585. if (c != 'x' && c != 'X')
  36586. return false;
  36587. int numDigits = 0;
  36588. while (isHexDigit (source.peekNextChar()))
  36589. {
  36590. ++numDigits;
  36591. source.skip();
  36592. }
  36593. if (numDigits == 0)
  36594. return false;
  36595. return skipNumberSuffix (source);
  36596. }
  36597. static bool isOctalDigit (const juce_wchar c) throw()
  36598. {
  36599. return c >= '0' && c <= '7';
  36600. }
  36601. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36602. {
  36603. if (source.nextChar() != '0')
  36604. return false;
  36605. if (! isOctalDigit (source.nextChar()))
  36606. return false;
  36607. while (isOctalDigit (source.peekNextChar()))
  36608. source.skip();
  36609. return skipNumberSuffix (source);
  36610. }
  36611. static bool isDecimalDigit (const juce_wchar c) throw()
  36612. {
  36613. return c >= '0' && c <= '9';
  36614. }
  36615. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36616. {
  36617. int numChars = 0;
  36618. while (isDecimalDigit (source.peekNextChar()))
  36619. {
  36620. ++numChars;
  36621. source.skip();
  36622. }
  36623. if (numChars == 0)
  36624. return false;
  36625. return skipNumberSuffix (source);
  36626. }
  36627. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36628. {
  36629. int numDigits = 0;
  36630. while (isDecimalDigit (source.peekNextChar()))
  36631. {
  36632. source.skip();
  36633. ++numDigits;
  36634. }
  36635. const bool hasPoint = (source.peekNextChar() == '.');
  36636. if (hasPoint)
  36637. {
  36638. source.skip();
  36639. while (isDecimalDigit (source.peekNextChar()))
  36640. {
  36641. source.skip();
  36642. ++numDigits;
  36643. }
  36644. }
  36645. if (numDigits == 0)
  36646. return false;
  36647. juce_wchar c = source.peekNextChar();
  36648. const bool hasExponent = (c == 'e' || c == 'E');
  36649. if (hasExponent)
  36650. {
  36651. source.skip();
  36652. c = source.peekNextChar();
  36653. if (c == '+' || c == '-')
  36654. source.skip();
  36655. int numExpDigits = 0;
  36656. while (isDecimalDigit (source.peekNextChar()))
  36657. {
  36658. source.skip();
  36659. ++numExpDigits;
  36660. }
  36661. if (numExpDigits == 0)
  36662. return false;
  36663. }
  36664. c = source.peekNextChar();
  36665. if (c == 'f' || c == 'F')
  36666. source.skip();
  36667. else if (! (hasExponent || hasPoint))
  36668. return false;
  36669. return true;
  36670. }
  36671. static int parseNumber (CodeDocument::Iterator& source)
  36672. {
  36673. const CodeDocument::Iterator original (source);
  36674. if (parseFloatLiteral (source))
  36675. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36676. source = original;
  36677. if (parseHexLiteral (source))
  36678. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36679. source = original;
  36680. if (parseOctalLiteral (source))
  36681. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36682. source = original;
  36683. if (parseDecimalLiteral (source))
  36684. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36685. source = original;
  36686. source.skip();
  36687. return CPlusPlusCodeTokeniser::tokenType_error;
  36688. }
  36689. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36690. {
  36691. const juce_wchar quote = source.nextChar();
  36692. for (;;)
  36693. {
  36694. const juce_wchar c = source.nextChar();
  36695. if (c == quote || c == 0)
  36696. break;
  36697. if (c == '\\')
  36698. source.skip();
  36699. }
  36700. }
  36701. static void skipComment (CodeDocument::Iterator& source) throw()
  36702. {
  36703. bool lastWasStar = false;
  36704. for (;;)
  36705. {
  36706. const juce_wchar c = source.nextChar();
  36707. if (c == 0 || (c == '/' && lastWasStar))
  36708. break;
  36709. lastWasStar = (c == '*');
  36710. }
  36711. }
  36712. }
  36713. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36714. {
  36715. int result = tokenType_error;
  36716. source.skipWhitespace();
  36717. tchar firstChar = source.peekNextChar();
  36718. switch (firstChar)
  36719. {
  36720. case 0:
  36721. source.skip();
  36722. break;
  36723. case '0':
  36724. case '1':
  36725. case '2':
  36726. case '3':
  36727. case '4':
  36728. case '5':
  36729. case '6':
  36730. case '7':
  36731. case '8':
  36732. case '9':
  36733. result = CppTokeniser::parseNumber (source);
  36734. break;
  36735. case '.':
  36736. result = CppTokeniser::parseNumber (source);
  36737. if (result == tokenType_error)
  36738. result = tokenType_punctuation;
  36739. break;
  36740. case ',':
  36741. case ';':
  36742. case ':':
  36743. source.skip();
  36744. result = tokenType_punctuation;
  36745. break;
  36746. case '(':
  36747. case ')':
  36748. case '{':
  36749. case '}':
  36750. case '[':
  36751. case ']':
  36752. source.skip();
  36753. result = tokenType_bracket;
  36754. break;
  36755. case '"':
  36756. case '\'':
  36757. CppTokeniser::skipQuotedString (source);
  36758. result = tokenType_stringLiteral;
  36759. break;
  36760. case '+':
  36761. result = tokenType_operator;
  36762. source.skip();
  36763. if (source.peekNextChar() == '+')
  36764. source.skip();
  36765. else if (source.peekNextChar() == '=')
  36766. source.skip();
  36767. break;
  36768. case '-':
  36769. source.skip();
  36770. result = CppTokeniser::parseNumber (source);
  36771. if (result == tokenType_error)
  36772. {
  36773. result = tokenType_operator;
  36774. if (source.peekNextChar() == '-')
  36775. source.skip();
  36776. else if (source.peekNextChar() == '=')
  36777. source.skip();
  36778. }
  36779. break;
  36780. case '*':
  36781. case '%':
  36782. case '=':
  36783. case '!':
  36784. result = tokenType_operator;
  36785. source.skip();
  36786. if (source.peekNextChar() == '=')
  36787. source.skip();
  36788. break;
  36789. case '/':
  36790. result = tokenType_operator;
  36791. source.skip();
  36792. if (source.peekNextChar() == '=')
  36793. {
  36794. source.skip();
  36795. }
  36796. else if (source.peekNextChar() == '/')
  36797. {
  36798. result = tokenType_comment;
  36799. source.skipToEndOfLine();
  36800. }
  36801. else if (source.peekNextChar() == '*')
  36802. {
  36803. source.skip();
  36804. result = tokenType_comment;
  36805. CppTokeniser::skipComment (source);
  36806. }
  36807. break;
  36808. case '?':
  36809. case '~':
  36810. source.skip();
  36811. result = tokenType_operator;
  36812. break;
  36813. case '<':
  36814. source.skip();
  36815. result = tokenType_operator;
  36816. if (source.peekNextChar() == '=')
  36817. {
  36818. source.skip();
  36819. }
  36820. else if (source.peekNextChar() == '<')
  36821. {
  36822. source.skip();
  36823. if (source.peekNextChar() == '=')
  36824. source.skip();
  36825. }
  36826. break;
  36827. case '>':
  36828. source.skip();
  36829. result = tokenType_operator;
  36830. if (source.peekNextChar() == '=')
  36831. {
  36832. source.skip();
  36833. }
  36834. else if (source.peekNextChar() == '<')
  36835. {
  36836. source.skip();
  36837. if (source.peekNextChar() == '=')
  36838. source.skip();
  36839. }
  36840. break;
  36841. case '|':
  36842. source.skip();
  36843. result = tokenType_operator;
  36844. if (source.peekNextChar() == '=')
  36845. {
  36846. source.skip();
  36847. }
  36848. else if (source.peekNextChar() == '|')
  36849. {
  36850. source.skip();
  36851. if (source.peekNextChar() == '=')
  36852. source.skip();
  36853. }
  36854. break;
  36855. case '&':
  36856. source.skip();
  36857. result = tokenType_operator;
  36858. if (source.peekNextChar() == '=')
  36859. {
  36860. source.skip();
  36861. }
  36862. else if (source.peekNextChar() == '&')
  36863. {
  36864. source.skip();
  36865. if (source.peekNextChar() == '=')
  36866. source.skip();
  36867. }
  36868. break;
  36869. case '^':
  36870. source.skip();
  36871. result = tokenType_operator;
  36872. if (source.peekNextChar() == '=')
  36873. {
  36874. source.skip();
  36875. }
  36876. else if (source.peekNextChar() == '^')
  36877. {
  36878. source.skip();
  36879. if (source.peekNextChar() == '=')
  36880. source.skip();
  36881. }
  36882. break;
  36883. case '#':
  36884. result = tokenType_preprocessor;
  36885. source.skipToEndOfLine();
  36886. break;
  36887. default:
  36888. if (CppTokeniser::isIdentifierStart (firstChar))
  36889. result = CppTokeniser::parseIdentifier (source);
  36890. else
  36891. source.skip();
  36892. break;
  36893. }
  36894. //jassert (result != tokenType_unknown);
  36895. return result;
  36896. }
  36897. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  36898. {
  36899. StringArray s;
  36900. s.add ("Error");
  36901. s.add ("Comment");
  36902. s.add ("C++ keyword");
  36903. s.add ("Identifier");
  36904. s.add ("Integer literal");
  36905. s.add ("Float literal");
  36906. s.add ("String literal");
  36907. s.add ("Operator");
  36908. s.add ("Bracket");
  36909. s.add ("Punctuation");
  36910. s.add ("Preprocessor line");
  36911. return s;
  36912. }
  36913. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  36914. {
  36915. const uint32 colours[] =
  36916. {
  36917. 0xffcc0000, // error
  36918. 0xff00aa00, // comment
  36919. 0xff0000cc, // keyword
  36920. 0xff000000, // identifier
  36921. 0xff880000, // int literal
  36922. 0xff885500, // float literal
  36923. 0xff990099, // string literal
  36924. 0xff225500, // operator
  36925. 0xff000055, // bracket
  36926. 0xff004400, // punctuation
  36927. 0xff660000 // preprocessor
  36928. };
  36929. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  36930. return Colour (colours [tokenType]);
  36931. return Colours::black;
  36932. }
  36933. END_JUCE_NAMESPACE
  36934. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36935. /*** Start of inlined file: juce_ComboBox.cpp ***/
  36936. BEGIN_JUCE_NAMESPACE
  36937. ComboBox::ComboBox (const String& name)
  36938. : Component (name),
  36939. lastCurrentId (0),
  36940. isButtonDown (false),
  36941. separatorPending (false),
  36942. menuActive (false),
  36943. label (0)
  36944. {
  36945. noChoicesMessage = TRANS("(no choices)");
  36946. setRepaintsOnMouseActivity (true);
  36947. lookAndFeelChanged();
  36948. currentId.addListener (this);
  36949. }
  36950. ComboBox::~ComboBox()
  36951. {
  36952. currentId.removeListener (this);
  36953. if (menuActive)
  36954. PopupMenu::dismissAllActiveMenus();
  36955. label = 0;
  36956. deleteAllChildren();
  36957. }
  36958. void ComboBox::setEditableText (const bool isEditable)
  36959. {
  36960. label->setEditable (isEditable, isEditable, false);
  36961. setWantsKeyboardFocus (! isEditable);
  36962. resized();
  36963. }
  36964. bool ComboBox::isTextEditable() const throw()
  36965. {
  36966. return label->isEditable();
  36967. }
  36968. void ComboBox::setJustificationType (const Justification& justification) throw()
  36969. {
  36970. label->setJustificationType (justification);
  36971. }
  36972. const Justification ComboBox::getJustificationType() const throw()
  36973. {
  36974. return label->getJustificationType();
  36975. }
  36976. void ComboBox::setTooltip (const String& newTooltip)
  36977. {
  36978. SettableTooltipClient::setTooltip (newTooltip);
  36979. label->setTooltip (newTooltip);
  36980. }
  36981. void ComboBox::addItem (const String& newItemText,
  36982. const int newItemId) throw()
  36983. {
  36984. // you can't add empty strings to the list..
  36985. jassert (newItemText.isNotEmpty());
  36986. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  36987. jassert (newItemId != 0);
  36988. // you shouldn't use duplicate item IDs!
  36989. jassert (getItemForId (newItemId) == 0);
  36990. if (newItemText.isNotEmpty() && newItemId != 0)
  36991. {
  36992. if (separatorPending)
  36993. {
  36994. separatorPending = false;
  36995. ItemInfo* const item = new ItemInfo();
  36996. item->itemId = 0;
  36997. item->isEnabled = false;
  36998. item->isHeading = false;
  36999. items.add (item);
  37000. }
  37001. ItemInfo* const item = new ItemInfo();
  37002. item->name = newItemText;
  37003. item->itemId = newItemId;
  37004. item->isEnabled = true;
  37005. item->isHeading = false;
  37006. items.add (item);
  37007. }
  37008. }
  37009. void ComboBox::addSeparator() throw()
  37010. {
  37011. separatorPending = (items.size() > 0);
  37012. }
  37013. void ComboBox::addSectionHeading (const String& headingName) throw()
  37014. {
  37015. // you can't add empty strings to the list..
  37016. jassert (headingName.isNotEmpty());
  37017. if (headingName.isNotEmpty())
  37018. {
  37019. if (separatorPending)
  37020. {
  37021. separatorPending = false;
  37022. ItemInfo* const item = new ItemInfo();
  37023. item->itemId = 0;
  37024. item->isEnabled = false;
  37025. item->isHeading = false;
  37026. items.add (item);
  37027. }
  37028. ItemInfo* const item = new ItemInfo();
  37029. item->name = headingName;
  37030. item->itemId = 0;
  37031. item->isEnabled = true;
  37032. item->isHeading = true;
  37033. items.add (item);
  37034. }
  37035. }
  37036. void ComboBox::setItemEnabled (const int itemId,
  37037. const bool shouldBeEnabled) throw()
  37038. {
  37039. ItemInfo* const item = getItemForId (itemId);
  37040. if (item != 0)
  37041. item->isEnabled = shouldBeEnabled;
  37042. }
  37043. void ComboBox::changeItemText (const int itemId,
  37044. const String& newText) throw()
  37045. {
  37046. ItemInfo* const item = getItemForId (itemId);
  37047. jassert (item != 0);
  37048. if (item != 0)
  37049. item->name = newText;
  37050. }
  37051. void ComboBox::clear (const bool dontSendChangeMessage)
  37052. {
  37053. items.clear();
  37054. separatorPending = false;
  37055. if (! label->isEditable())
  37056. setSelectedItemIndex (-1, dontSendChangeMessage);
  37057. }
  37058. bool ComboBox::ItemInfo::isSeparator() const throw()
  37059. {
  37060. return name.isEmpty();
  37061. }
  37062. bool ComboBox::ItemInfo::isRealItem() const throw()
  37063. {
  37064. return ! (isHeading || name.isEmpty());
  37065. }
  37066. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37067. {
  37068. if (itemId != 0)
  37069. {
  37070. for (int i = items.size(); --i >= 0;)
  37071. if (items.getUnchecked(i)->itemId == itemId)
  37072. return items.getUnchecked(i);
  37073. }
  37074. return 0;
  37075. }
  37076. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37077. {
  37078. int n = 0;
  37079. for (int i = 0; i < items.size(); ++i)
  37080. {
  37081. ItemInfo* const item = items.getUnchecked(i);
  37082. if (item->isRealItem())
  37083. if (n++ == index)
  37084. return item;
  37085. }
  37086. return 0;
  37087. }
  37088. int ComboBox::getNumItems() const throw()
  37089. {
  37090. int n = 0;
  37091. for (int i = items.size(); --i >= 0;)
  37092. if (items.getUnchecked(i)->isRealItem())
  37093. ++n;
  37094. return n;
  37095. }
  37096. const String ComboBox::getItemText (const int index) const throw()
  37097. {
  37098. const ItemInfo* const item = getItemForIndex (index);
  37099. if (item != 0)
  37100. return item->name;
  37101. return String::empty;
  37102. }
  37103. int ComboBox::getItemId (const int index) const throw()
  37104. {
  37105. const ItemInfo* const item = getItemForIndex (index);
  37106. return (item != 0) ? item->itemId : 0;
  37107. }
  37108. int ComboBox::indexOfItemId (const int itemId) const throw()
  37109. {
  37110. int n = 0;
  37111. for (int i = 0; i < items.size(); ++i)
  37112. {
  37113. const ItemInfo* const item = items.getUnchecked(i);
  37114. if (item->isRealItem())
  37115. {
  37116. if (item->itemId == itemId)
  37117. return n;
  37118. ++n;
  37119. }
  37120. }
  37121. return -1;
  37122. }
  37123. int ComboBox::getSelectedItemIndex() const throw()
  37124. {
  37125. int index = indexOfItemId (currentId.getValue());
  37126. if (getText() != getItemText (index))
  37127. index = -1;
  37128. return index;
  37129. }
  37130. void ComboBox::setSelectedItemIndex (const int index,
  37131. const bool dontSendChangeMessage) throw()
  37132. {
  37133. setSelectedId (getItemId (index), dontSendChangeMessage);
  37134. }
  37135. int ComboBox::getSelectedId() const throw()
  37136. {
  37137. const ItemInfo* const item = getItemForId (currentId.getValue());
  37138. return (item != 0 && getText() == item->name)
  37139. ? item->itemId
  37140. : 0;
  37141. }
  37142. void ComboBox::setSelectedId (const int newItemId,
  37143. const bool dontSendChangeMessage) throw()
  37144. {
  37145. const ItemInfo* const item = getItemForId (newItemId);
  37146. const String newItemText (item != 0 ? item->name : String::empty);
  37147. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37148. {
  37149. if (! dontSendChangeMessage)
  37150. triggerAsyncUpdate();
  37151. label->setText (newItemText, false);
  37152. lastCurrentId = newItemId;
  37153. currentId = newItemId;
  37154. repaint(); // for the benefit of the 'none selected' text
  37155. }
  37156. }
  37157. void ComboBox::valueChanged (Value&)
  37158. {
  37159. if (lastCurrentId != (int) currentId.getValue())
  37160. setSelectedId (currentId.getValue(), false);
  37161. }
  37162. const String ComboBox::getText() const throw()
  37163. {
  37164. return label->getText();
  37165. }
  37166. void ComboBox::setText (const String& newText,
  37167. const bool dontSendChangeMessage) throw()
  37168. {
  37169. for (int i = items.size(); --i >= 0;)
  37170. {
  37171. const ItemInfo* const item = items.getUnchecked(i);
  37172. if (item->isRealItem()
  37173. && item->name == newText)
  37174. {
  37175. setSelectedId (item->itemId, dontSendChangeMessage);
  37176. return;
  37177. }
  37178. }
  37179. lastCurrentId = 0;
  37180. currentId = 0;
  37181. if (label->getText() != newText)
  37182. {
  37183. label->setText (newText, false);
  37184. if (! dontSendChangeMessage)
  37185. triggerAsyncUpdate();
  37186. }
  37187. repaint();
  37188. }
  37189. void ComboBox::showEditor()
  37190. {
  37191. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37192. label->showEditor();
  37193. }
  37194. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37195. {
  37196. textWhenNothingSelected = newMessage;
  37197. repaint();
  37198. }
  37199. const String ComboBox::getTextWhenNothingSelected() const throw()
  37200. {
  37201. return textWhenNothingSelected;
  37202. }
  37203. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37204. {
  37205. noChoicesMessage = newMessage;
  37206. }
  37207. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37208. {
  37209. return noChoicesMessage;
  37210. }
  37211. void ComboBox::paint (Graphics& g)
  37212. {
  37213. getLookAndFeel().drawComboBox (g,
  37214. getWidth(),
  37215. getHeight(),
  37216. isButtonDown,
  37217. label->getRight(),
  37218. 0,
  37219. getWidth() - label->getRight(),
  37220. getHeight(),
  37221. *this);
  37222. if (textWhenNothingSelected.isNotEmpty()
  37223. && label->getText().isEmpty()
  37224. && ! label->isBeingEdited())
  37225. {
  37226. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37227. g.setFont (label->getFont());
  37228. g.drawFittedText (textWhenNothingSelected,
  37229. label->getX() + 2, label->getY() + 1,
  37230. label->getWidth() - 4, label->getHeight() - 2,
  37231. label->getJustificationType(),
  37232. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37233. }
  37234. }
  37235. void ComboBox::resized()
  37236. {
  37237. if (getHeight() > 0 && getWidth() > 0)
  37238. getLookAndFeel().positionComboBoxText (*this, *label);
  37239. }
  37240. void ComboBox::enablementChanged()
  37241. {
  37242. repaint();
  37243. }
  37244. void ComboBox::lookAndFeelChanged()
  37245. {
  37246. repaint();
  37247. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37248. if (label != 0)
  37249. {
  37250. newLabel->setEditable (label->isEditable());
  37251. newLabel->setJustificationType (label->getJustificationType());
  37252. newLabel->setTooltip (label->getTooltip());
  37253. newLabel->setText (label->getText(), false);
  37254. }
  37255. label = newLabel;
  37256. addAndMakeVisible (newLabel);
  37257. newLabel->addListener (this);
  37258. newLabel->addMouseListener (this, false);
  37259. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37260. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37261. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37262. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37263. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37264. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37265. resized();
  37266. }
  37267. void ComboBox::colourChanged()
  37268. {
  37269. lookAndFeelChanged();
  37270. }
  37271. bool ComboBox::keyPressed (const KeyPress& key)
  37272. {
  37273. bool used = false;
  37274. if (key.isKeyCode (KeyPress::upKey)
  37275. || key.isKeyCode (KeyPress::leftKey))
  37276. {
  37277. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37278. used = true;
  37279. }
  37280. else if (key.isKeyCode (KeyPress::downKey)
  37281. || key.isKeyCode (KeyPress::rightKey))
  37282. {
  37283. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37284. used = true;
  37285. }
  37286. else if (key.isKeyCode (KeyPress::returnKey))
  37287. {
  37288. showPopup();
  37289. used = true;
  37290. }
  37291. return used;
  37292. }
  37293. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37294. {
  37295. // only forward key events that aren't used by this component
  37296. return isKeyDown
  37297. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37298. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37299. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37300. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37301. }
  37302. void ComboBox::focusGained (FocusChangeType)
  37303. {
  37304. repaint();
  37305. }
  37306. void ComboBox::focusLost (FocusChangeType)
  37307. {
  37308. repaint();
  37309. }
  37310. void ComboBox::labelTextChanged (Label*)
  37311. {
  37312. triggerAsyncUpdate();
  37313. }
  37314. void ComboBox::showPopup()
  37315. {
  37316. if (! menuActive)
  37317. {
  37318. const int selectedId = getSelectedId();
  37319. Component::SafePointer<Component> deletionWatcher (this);
  37320. PopupMenu menu;
  37321. menu.setLookAndFeel (&getLookAndFeel());
  37322. for (int i = 0; i < items.size(); ++i)
  37323. {
  37324. const ItemInfo* const item = items.getUnchecked(i);
  37325. if (item->isSeparator())
  37326. menu.addSeparator();
  37327. else if (item->isHeading)
  37328. menu.addSectionHeader (item->name);
  37329. else
  37330. menu.addItem (item->itemId, item->name,
  37331. item->isEnabled, item->itemId == selectedId);
  37332. }
  37333. if (items.size() == 0)
  37334. menu.addItem (1, noChoicesMessage, false);
  37335. const int itemHeight = jlimit (12, 24, getHeight());
  37336. menuActive = true;
  37337. const int resultId = menu.showAt (this, selectedId,
  37338. getWidth(), 1, itemHeight);
  37339. if (deletionWatcher == 0)
  37340. return;
  37341. menuActive = false;
  37342. if (resultId != 0)
  37343. setSelectedId (resultId);
  37344. }
  37345. }
  37346. void ComboBox::mouseDown (const MouseEvent& e)
  37347. {
  37348. beginDragAutoRepeat (300);
  37349. isButtonDown = isEnabled();
  37350. if (isButtonDown
  37351. && (e.eventComponent == this || ! label->isEditable()))
  37352. {
  37353. showPopup();
  37354. }
  37355. }
  37356. void ComboBox::mouseDrag (const MouseEvent& e)
  37357. {
  37358. beginDragAutoRepeat (50);
  37359. if (isButtonDown && ! e.mouseWasClicked())
  37360. showPopup();
  37361. }
  37362. void ComboBox::mouseUp (const MouseEvent& e2)
  37363. {
  37364. if (isButtonDown)
  37365. {
  37366. isButtonDown = false;
  37367. repaint();
  37368. const MouseEvent e (e2.getEventRelativeTo (this));
  37369. if (reallyContains (e.x, e.y, true)
  37370. && (e2.eventComponent == this || ! label->isEditable()))
  37371. {
  37372. showPopup();
  37373. }
  37374. }
  37375. }
  37376. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37377. {
  37378. listeners.add (listener);
  37379. }
  37380. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37381. {
  37382. listeners.remove (listener);
  37383. }
  37384. void ComboBox::handleAsyncUpdate()
  37385. {
  37386. Component::BailOutChecker checker (this);
  37387. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37388. }
  37389. END_JUCE_NAMESPACE
  37390. /*** End of inlined file: juce_ComboBox.cpp ***/
  37391. /*** Start of inlined file: juce_Label.cpp ***/
  37392. BEGIN_JUCE_NAMESPACE
  37393. Label::Label (const String& componentName,
  37394. const String& labelText)
  37395. : Component (componentName),
  37396. textValue (labelText),
  37397. lastTextValue (labelText),
  37398. font (15.0f),
  37399. justification (Justification::centredLeft),
  37400. ownerComponent (0),
  37401. horizontalBorderSize (5),
  37402. verticalBorderSize (1),
  37403. minimumHorizontalScale (0.7f),
  37404. editSingleClick (false),
  37405. editDoubleClick (false),
  37406. lossOfFocusDiscardsChanges (false)
  37407. {
  37408. setColour (TextEditor::textColourId, Colours::black);
  37409. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37410. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37411. textValue.addListener (this);
  37412. }
  37413. Label::~Label()
  37414. {
  37415. textValue.removeListener (this);
  37416. if (ownerComponent != 0)
  37417. ownerComponent->removeComponentListener (this);
  37418. editor = 0;
  37419. }
  37420. void Label::setText (const String& newText,
  37421. const bool broadcastChangeMessage)
  37422. {
  37423. hideEditor (true);
  37424. if (lastTextValue != newText)
  37425. {
  37426. lastTextValue = newText;
  37427. textValue = newText;
  37428. repaint();
  37429. textWasChanged();
  37430. if (ownerComponent != 0)
  37431. componentMovedOrResized (*ownerComponent, true, true);
  37432. if (broadcastChangeMessage)
  37433. callChangeListeners();
  37434. }
  37435. }
  37436. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37437. {
  37438. return (returnActiveEditorContents && isBeingEdited())
  37439. ? editor->getText()
  37440. : textValue.toString();
  37441. }
  37442. void Label::valueChanged (Value&)
  37443. {
  37444. if (lastTextValue != textValue.toString())
  37445. setText (textValue.toString(), true);
  37446. }
  37447. void Label::setFont (const Font& newFont) throw()
  37448. {
  37449. font = newFont;
  37450. repaint();
  37451. }
  37452. const Font& Label::getFont() const throw()
  37453. {
  37454. return font;
  37455. }
  37456. void Label::setEditable (const bool editOnSingleClick,
  37457. const bool editOnDoubleClick,
  37458. const bool lossOfFocusDiscardsChanges_) throw()
  37459. {
  37460. editSingleClick = editOnSingleClick;
  37461. editDoubleClick = editOnDoubleClick;
  37462. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37463. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37464. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37465. }
  37466. void Label::setJustificationType (const Justification& justification_) throw()
  37467. {
  37468. justification = justification_;
  37469. repaint();
  37470. }
  37471. void Label::setBorderSize (int h, int v)
  37472. {
  37473. horizontalBorderSize = h;
  37474. verticalBorderSize = v;
  37475. repaint();
  37476. }
  37477. Component* Label::getAttachedComponent() const
  37478. {
  37479. return static_cast<Component*> (ownerComponent);
  37480. }
  37481. void Label::attachToComponent (Component* owner,
  37482. const bool onLeft)
  37483. {
  37484. if (ownerComponent != 0)
  37485. ownerComponent->removeComponentListener (this);
  37486. ownerComponent = owner;
  37487. leftOfOwnerComp = onLeft;
  37488. if (ownerComponent != 0)
  37489. {
  37490. setVisible (owner->isVisible());
  37491. ownerComponent->addComponentListener (this);
  37492. componentParentHierarchyChanged (*ownerComponent);
  37493. componentMovedOrResized (*ownerComponent, true, true);
  37494. }
  37495. }
  37496. void Label::componentMovedOrResized (Component& component,
  37497. bool /*wasMoved*/,
  37498. bool /*wasResized*/)
  37499. {
  37500. if (leftOfOwnerComp)
  37501. {
  37502. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37503. component.getHeight());
  37504. setTopRightPosition (component.getX(), component.getY());
  37505. }
  37506. else
  37507. {
  37508. setSize (component.getWidth(),
  37509. 8 + roundToInt (getFont().getHeight()));
  37510. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37511. }
  37512. }
  37513. void Label::componentParentHierarchyChanged (Component& component)
  37514. {
  37515. if (component.getParentComponent() != 0)
  37516. component.getParentComponent()->addChildComponent (this);
  37517. }
  37518. void Label::componentVisibilityChanged (Component& component)
  37519. {
  37520. setVisible (component.isVisible());
  37521. }
  37522. void Label::textWasEdited()
  37523. {
  37524. }
  37525. void Label::textWasChanged()
  37526. {
  37527. }
  37528. void Label::showEditor()
  37529. {
  37530. if (editor == 0)
  37531. {
  37532. addAndMakeVisible (editor = createEditorComponent());
  37533. editor->setText (getText(), false);
  37534. editor->addListener (this);
  37535. editor->grabKeyboardFocus();
  37536. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37537. editor->addListener (this);
  37538. resized();
  37539. repaint();
  37540. editorShown (editor);
  37541. enterModalState();
  37542. editor->grabKeyboardFocus();
  37543. }
  37544. }
  37545. void Label::editorShown (TextEditor* /*editorComponent*/)
  37546. {
  37547. }
  37548. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37549. {
  37550. }
  37551. bool Label::updateFromTextEditorContents()
  37552. {
  37553. jassert (editor != 0);
  37554. const String newText (editor->getText());
  37555. if (textValue.toString() != newText)
  37556. {
  37557. lastTextValue = newText;
  37558. textValue = newText;
  37559. repaint();
  37560. textWasChanged();
  37561. if (ownerComponent != 0)
  37562. componentMovedOrResized (*ownerComponent, true, true);
  37563. return true;
  37564. }
  37565. return false;
  37566. }
  37567. void Label::hideEditor (const bool discardCurrentEditorContents)
  37568. {
  37569. if (editor != 0)
  37570. {
  37571. Component::SafePointer<Component> deletionChecker (this);
  37572. editorAboutToBeHidden (editor);
  37573. const bool changed = (! discardCurrentEditorContents)
  37574. && updateFromTextEditorContents();
  37575. editor = 0;
  37576. repaint();
  37577. if (changed)
  37578. textWasEdited();
  37579. if (deletionChecker != 0)
  37580. exitModalState (0);
  37581. if (changed && deletionChecker != 0)
  37582. callChangeListeners();
  37583. }
  37584. }
  37585. void Label::inputAttemptWhenModal()
  37586. {
  37587. if (editor != 0)
  37588. {
  37589. if (lossOfFocusDiscardsChanges)
  37590. textEditorEscapeKeyPressed (*editor);
  37591. else
  37592. textEditorReturnKeyPressed (*editor);
  37593. }
  37594. }
  37595. bool Label::isBeingEdited() const throw()
  37596. {
  37597. return editor != 0;
  37598. }
  37599. TextEditor* Label::createEditorComponent()
  37600. {
  37601. TextEditor* const ed = new TextEditor (getName());
  37602. ed->setFont (font);
  37603. // copy these colours from our own settings..
  37604. const int cols[] = { TextEditor::backgroundColourId,
  37605. TextEditor::textColourId,
  37606. TextEditor::highlightColourId,
  37607. TextEditor::highlightedTextColourId,
  37608. TextEditor::caretColourId,
  37609. TextEditor::outlineColourId,
  37610. TextEditor::focusedOutlineColourId,
  37611. TextEditor::shadowColourId };
  37612. for (int i = 0; i < numElementsInArray (cols); ++i)
  37613. ed->setColour (cols[i], findColour (cols[i]));
  37614. return ed;
  37615. }
  37616. void Label::paint (Graphics& g)
  37617. {
  37618. getLookAndFeel().drawLabel (g, *this);
  37619. }
  37620. void Label::mouseUp (const MouseEvent& e)
  37621. {
  37622. if (editSingleClick
  37623. && e.mouseWasClicked()
  37624. && contains (e.x, e.y)
  37625. && ! e.mods.isPopupMenu())
  37626. {
  37627. showEditor();
  37628. }
  37629. }
  37630. void Label::mouseDoubleClick (const MouseEvent& e)
  37631. {
  37632. if (editDoubleClick && ! e.mods.isPopupMenu())
  37633. showEditor();
  37634. }
  37635. void Label::resized()
  37636. {
  37637. if (editor != 0)
  37638. editor->setBoundsInset (BorderSize (0));
  37639. }
  37640. void Label::focusGained (FocusChangeType cause)
  37641. {
  37642. if (editSingleClick && cause == focusChangedByTabKey)
  37643. showEditor();
  37644. }
  37645. void Label::enablementChanged()
  37646. {
  37647. repaint();
  37648. }
  37649. void Label::colourChanged()
  37650. {
  37651. repaint();
  37652. }
  37653. void Label::setMinimumHorizontalScale (const float newScale)
  37654. {
  37655. if (minimumHorizontalScale != newScale)
  37656. {
  37657. minimumHorizontalScale = newScale;
  37658. repaint();
  37659. }
  37660. }
  37661. // We'll use a custom focus traverser here to make sure focus goes from the
  37662. // text editor to another component rather than back to the label itself.
  37663. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37664. {
  37665. public:
  37666. LabelKeyboardFocusTraverser() {}
  37667. Component* getNextComponent (Component* current)
  37668. {
  37669. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37670. ? current->getParentComponent() : current);
  37671. }
  37672. Component* getPreviousComponent (Component* current)
  37673. {
  37674. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37675. ? current->getParentComponent() : current);
  37676. }
  37677. };
  37678. KeyboardFocusTraverser* Label::createFocusTraverser()
  37679. {
  37680. return new LabelKeyboardFocusTraverser();
  37681. }
  37682. void Label::addListener (LabelListener* const listener) throw()
  37683. {
  37684. listeners.add (listener);
  37685. }
  37686. void Label::removeListener (LabelListener* const listener) throw()
  37687. {
  37688. listeners.remove (listener);
  37689. }
  37690. void Label::callChangeListeners()
  37691. {
  37692. Component::BailOutChecker checker (this);
  37693. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37694. }
  37695. void Label::textEditorTextChanged (TextEditor& ed)
  37696. {
  37697. if (editor != 0)
  37698. {
  37699. jassert (&ed == editor);
  37700. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37701. {
  37702. if (lossOfFocusDiscardsChanges)
  37703. textEditorEscapeKeyPressed (ed);
  37704. else
  37705. textEditorReturnKeyPressed (ed);
  37706. }
  37707. }
  37708. }
  37709. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37710. {
  37711. if (editor != 0)
  37712. {
  37713. jassert (&ed == editor);
  37714. (void) ed;
  37715. const bool changed = updateFromTextEditorContents();
  37716. hideEditor (true);
  37717. if (changed)
  37718. {
  37719. Component::SafePointer<Component> deletionChecker (this);
  37720. textWasEdited();
  37721. if (deletionChecker != 0)
  37722. callChangeListeners();
  37723. }
  37724. }
  37725. }
  37726. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37727. {
  37728. if (editor != 0)
  37729. {
  37730. jassert (&ed == editor);
  37731. (void) ed;
  37732. editor->setText (textValue.toString(), false);
  37733. hideEditor (true);
  37734. }
  37735. }
  37736. void Label::textEditorFocusLost (TextEditor& ed)
  37737. {
  37738. textEditorTextChanged (ed);
  37739. }
  37740. END_JUCE_NAMESPACE
  37741. /*** End of inlined file: juce_Label.cpp ***/
  37742. /*** Start of inlined file: juce_ListBox.cpp ***/
  37743. BEGIN_JUCE_NAMESPACE
  37744. class ListBoxRowComponent : public Component,
  37745. public TooltipClient
  37746. {
  37747. public:
  37748. ListBoxRowComponent (ListBox& owner_)
  37749. : owner (owner_),
  37750. row (-1),
  37751. selected (false),
  37752. isDragging (false)
  37753. {
  37754. }
  37755. ~ListBoxRowComponent()
  37756. {
  37757. deleteAllChildren();
  37758. }
  37759. void paint (Graphics& g)
  37760. {
  37761. if (owner.getModel() != 0)
  37762. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37763. }
  37764. void update (const int row_, const bool selected_)
  37765. {
  37766. if (row != row_ || selected != selected_)
  37767. {
  37768. repaint();
  37769. row = row_;
  37770. selected = selected_;
  37771. }
  37772. if (owner.getModel() != 0)
  37773. {
  37774. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37775. if (customComp != 0)
  37776. {
  37777. addAndMakeVisible (customComp);
  37778. customComp->setBounds (0, 0, getWidth(), getHeight());
  37779. for (int i = getNumChildComponents(); --i >= 0;)
  37780. if (getChildComponent (i) != customComp)
  37781. delete getChildComponent (i);
  37782. }
  37783. else
  37784. {
  37785. deleteAllChildren();
  37786. }
  37787. }
  37788. }
  37789. void mouseDown (const MouseEvent& e)
  37790. {
  37791. isDragging = false;
  37792. selectRowOnMouseUp = false;
  37793. if (isEnabled())
  37794. {
  37795. if (! selected)
  37796. {
  37797. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37798. if (owner.getModel() != 0)
  37799. owner.getModel()->listBoxItemClicked (row, e);
  37800. }
  37801. else
  37802. {
  37803. selectRowOnMouseUp = true;
  37804. }
  37805. }
  37806. }
  37807. void mouseUp (const MouseEvent& e)
  37808. {
  37809. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37810. {
  37811. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37812. if (owner.getModel() != 0)
  37813. owner.getModel()->listBoxItemClicked (row, e);
  37814. }
  37815. }
  37816. void mouseDoubleClick (const MouseEvent& e)
  37817. {
  37818. if (owner.getModel() != 0 && isEnabled())
  37819. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37820. }
  37821. void mouseDrag (const MouseEvent& e)
  37822. {
  37823. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37824. {
  37825. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37826. if (selectedRows.size() > 0)
  37827. {
  37828. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37829. if (dragDescription.isNotEmpty())
  37830. {
  37831. isDragging = true;
  37832. owner.startDragAndDrop (e, dragDescription);
  37833. }
  37834. }
  37835. }
  37836. }
  37837. void resized()
  37838. {
  37839. if (getNumChildComponents() > 0)
  37840. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37841. }
  37842. const String getTooltip()
  37843. {
  37844. if (owner.getModel() != 0)
  37845. return owner.getModel()->getTooltipForRow (row);
  37846. return String::empty;
  37847. }
  37848. juce_UseDebuggingNewOperator
  37849. bool neededFlag;
  37850. private:
  37851. ListBox& owner;
  37852. int row;
  37853. bool selected, isDragging, selectRowOnMouseUp;
  37854. ListBoxRowComponent (const ListBoxRowComponent&);
  37855. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37856. };
  37857. class ListViewport : public Viewport
  37858. {
  37859. public:
  37860. int firstIndex, firstWholeIndex, lastWholeIndex;
  37861. bool hasUpdated;
  37862. ListViewport (ListBox& owner_)
  37863. : owner (owner_)
  37864. {
  37865. setWantsKeyboardFocus (false);
  37866. setViewedComponent (new Component());
  37867. getViewedComponent()->addMouseListener (this, false);
  37868. getViewedComponent()->setWantsKeyboardFocus (false);
  37869. }
  37870. ~ListViewport()
  37871. {
  37872. getViewedComponent()->removeMouseListener (this);
  37873. getViewedComponent()->deleteAllChildren();
  37874. }
  37875. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37876. {
  37877. return (ListBoxRowComponent*) getViewedComponent()
  37878. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  37879. }
  37880. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  37881. {
  37882. const int index = getIndexOfChildComponent (rowComponent);
  37883. const int num = getViewedComponent()->getNumChildComponents();
  37884. for (int i = num; --i >= 0;)
  37885. if (((firstIndex + i) % jmax (1, num)) == index)
  37886. return firstIndex + i;
  37887. return -1;
  37888. }
  37889. Component* getComponentForRowIfOnscreen (const int row) const throw()
  37890. {
  37891. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  37892. ? getComponentForRow (row) : 0;
  37893. }
  37894. void visibleAreaChanged (int, int, int, int)
  37895. {
  37896. updateVisibleArea (true);
  37897. if (owner.getModel() != 0)
  37898. owner.getModel()->listWasScrolled();
  37899. }
  37900. void updateVisibleArea (const bool makeSureItUpdatesContent)
  37901. {
  37902. hasUpdated = false;
  37903. const int newX = getViewedComponent()->getX();
  37904. int newY = getViewedComponent()->getY();
  37905. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  37906. const int newH = owner.totalItems * owner.getRowHeight();
  37907. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  37908. newY = getMaximumVisibleHeight() - newH;
  37909. getViewedComponent()->setBounds (newX, newY, newW, newH);
  37910. if (makeSureItUpdatesContent && ! hasUpdated)
  37911. updateContents();
  37912. }
  37913. void updateContents()
  37914. {
  37915. hasUpdated = true;
  37916. const int rowHeight = owner.getRowHeight();
  37917. if (rowHeight > 0)
  37918. {
  37919. const int y = getViewPositionY();
  37920. const int w = getViewedComponent()->getWidth();
  37921. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  37922. while (numNeeded > getViewedComponent()->getNumChildComponents())
  37923. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  37924. jassert (numNeeded >= 0);
  37925. while (numNeeded < getViewedComponent()->getNumChildComponents())
  37926. {
  37927. Component* const rowToRemove
  37928. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  37929. delete rowToRemove;
  37930. }
  37931. firstIndex = y / rowHeight;
  37932. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  37933. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  37934. for (int i = 0; i < numNeeded; ++i)
  37935. {
  37936. const int row = i + firstIndex;
  37937. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  37938. if (rowComp != 0)
  37939. {
  37940. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  37941. rowComp->update (row, owner.isRowSelected (row));
  37942. }
  37943. }
  37944. }
  37945. if (owner.headerComponent != 0)
  37946. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  37947. owner.outlineThickness,
  37948. jmax (owner.getWidth() - owner.outlineThickness * 2,
  37949. getViewedComponent()->getWidth()),
  37950. owner.headerComponent->getHeight());
  37951. }
  37952. void paint (Graphics& g)
  37953. {
  37954. if (isOpaque())
  37955. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  37956. }
  37957. bool keyPressed (const KeyPress& key)
  37958. {
  37959. if (key.isKeyCode (KeyPress::upKey)
  37960. || key.isKeyCode (KeyPress::downKey)
  37961. || key.isKeyCode (KeyPress::pageUpKey)
  37962. || key.isKeyCode (KeyPress::pageDownKey)
  37963. || key.isKeyCode (KeyPress::homeKey)
  37964. || key.isKeyCode (KeyPress::endKey))
  37965. {
  37966. // we want to avoid these keypresses going to the viewport, and instead allow
  37967. // them to pass up to our listbox..
  37968. return false;
  37969. }
  37970. return Viewport::keyPressed (key);
  37971. }
  37972. juce_UseDebuggingNewOperator
  37973. private:
  37974. ListBox& owner;
  37975. ListViewport (const ListViewport&);
  37976. ListViewport& operator= (const ListViewport&);
  37977. };
  37978. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  37979. : Component (name),
  37980. model (model_),
  37981. headerComponent (0),
  37982. totalItems (0),
  37983. rowHeight (22),
  37984. minimumRowWidth (0),
  37985. outlineThickness (0),
  37986. lastRowSelected (-1),
  37987. mouseMoveSelects (false),
  37988. multipleSelection (false),
  37989. hasDoneInitialUpdate (false)
  37990. {
  37991. addAndMakeVisible (viewport = new ListViewport (*this));
  37992. setWantsKeyboardFocus (true);
  37993. colourChanged();
  37994. }
  37995. ListBox::~ListBox()
  37996. {
  37997. deleteAllChildren();
  37998. }
  37999. void ListBox::setModel (ListBoxModel* const newModel)
  38000. {
  38001. if (model != newModel)
  38002. {
  38003. model = newModel;
  38004. updateContent();
  38005. }
  38006. }
  38007. void ListBox::setMultipleSelectionEnabled (bool b)
  38008. {
  38009. multipleSelection = b;
  38010. }
  38011. void ListBox::setMouseMoveSelectsRows (bool b)
  38012. {
  38013. mouseMoveSelects = b;
  38014. if (b)
  38015. addMouseListener (this, true);
  38016. }
  38017. void ListBox::paint (Graphics& g)
  38018. {
  38019. if (! hasDoneInitialUpdate)
  38020. updateContent();
  38021. g.fillAll (findColour (backgroundColourId));
  38022. }
  38023. void ListBox::paintOverChildren (Graphics& g)
  38024. {
  38025. if (outlineThickness > 0)
  38026. {
  38027. g.setColour (findColour (outlineColourId));
  38028. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38029. }
  38030. }
  38031. void ListBox::resized()
  38032. {
  38033. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38034. outlineThickness,
  38035. outlineThickness,
  38036. outlineThickness));
  38037. viewport->setSingleStepSizes (20, getRowHeight());
  38038. viewport->updateVisibleArea (false);
  38039. }
  38040. void ListBox::visibilityChanged()
  38041. {
  38042. viewport->updateVisibleArea (true);
  38043. }
  38044. Viewport* ListBox::getViewport() const throw()
  38045. {
  38046. return viewport;
  38047. }
  38048. void ListBox::updateContent()
  38049. {
  38050. hasDoneInitialUpdate = true;
  38051. totalItems = (model != 0) ? model->getNumRows() : 0;
  38052. bool selectionChanged = false;
  38053. if (selected [selected.size() - 1] >= totalItems)
  38054. {
  38055. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38056. lastRowSelected = getSelectedRow (0);
  38057. selectionChanged = true;
  38058. }
  38059. viewport->updateVisibleArea (isVisible());
  38060. viewport->resized();
  38061. if (selectionChanged && model != 0)
  38062. model->selectedRowsChanged (lastRowSelected);
  38063. }
  38064. void ListBox::selectRow (const int row,
  38065. bool dontScroll,
  38066. bool deselectOthersFirst)
  38067. {
  38068. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38069. }
  38070. void ListBox::selectRowInternal (const int row,
  38071. bool dontScroll,
  38072. bool deselectOthersFirst,
  38073. bool isMouseClick)
  38074. {
  38075. if (! multipleSelection)
  38076. deselectOthersFirst = true;
  38077. if ((! isRowSelected (row))
  38078. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38079. {
  38080. if (((unsigned int) row) < (unsigned int) totalItems)
  38081. {
  38082. if (deselectOthersFirst)
  38083. selected.clear();
  38084. selected.addRange (row, 1);
  38085. if (getHeight() == 0 || getWidth() == 0)
  38086. dontScroll = true;
  38087. viewport->hasUpdated = false;
  38088. if (row < viewport->firstWholeIndex && ! dontScroll)
  38089. {
  38090. viewport->setViewPosition (viewport->getViewPositionX(),
  38091. row * getRowHeight());
  38092. }
  38093. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38094. {
  38095. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38096. if (row >= lastRowSelected + rowsOnScreen
  38097. && rowsOnScreen < totalItems - 1
  38098. && ! isMouseClick)
  38099. {
  38100. viewport->setViewPosition (viewport->getViewPositionX(),
  38101. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38102. * getRowHeight());
  38103. }
  38104. else
  38105. {
  38106. viewport->setViewPosition (viewport->getViewPositionX(),
  38107. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38108. }
  38109. }
  38110. if (! viewport->hasUpdated)
  38111. viewport->updateContents();
  38112. lastRowSelected = row;
  38113. model->selectedRowsChanged (row);
  38114. }
  38115. else
  38116. {
  38117. if (deselectOthersFirst)
  38118. deselectAllRows();
  38119. }
  38120. }
  38121. }
  38122. void ListBox::deselectRow (const int row)
  38123. {
  38124. if (selected.contains (row))
  38125. {
  38126. selected.removeRange (row, 1);
  38127. if (row == lastRowSelected)
  38128. lastRowSelected = getSelectedRow (0);
  38129. viewport->updateContents();
  38130. model->selectedRowsChanged (lastRowSelected);
  38131. }
  38132. }
  38133. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38134. const bool sendNotificationEventToModel)
  38135. {
  38136. selected = setOfRowsToBeSelected;
  38137. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38138. if (! isRowSelected (lastRowSelected))
  38139. lastRowSelected = getSelectedRow (0);
  38140. viewport->updateContents();
  38141. if ((model != 0) && sendNotificationEventToModel)
  38142. model->selectedRowsChanged (lastRowSelected);
  38143. }
  38144. const SparseSet<int> ListBox::getSelectedRows() const
  38145. {
  38146. return selected;
  38147. }
  38148. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38149. {
  38150. if (multipleSelection && (firstRow != lastRow))
  38151. {
  38152. const int numRows = totalItems - 1;
  38153. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38154. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38155. selected.addRange (jmin (firstRow, lastRow),
  38156. abs (firstRow - lastRow) + 1);
  38157. selected.removeRange (lastRow, 1);
  38158. }
  38159. selectRowInternal (lastRow, false, false, true);
  38160. }
  38161. void ListBox::flipRowSelection (const int row)
  38162. {
  38163. if (isRowSelected (row))
  38164. deselectRow (row);
  38165. else
  38166. selectRowInternal (row, false, false, true);
  38167. }
  38168. void ListBox::deselectAllRows()
  38169. {
  38170. if (! selected.isEmpty())
  38171. {
  38172. selected.clear();
  38173. lastRowSelected = -1;
  38174. viewport->updateContents();
  38175. if (model != 0)
  38176. model->selectedRowsChanged (lastRowSelected);
  38177. }
  38178. }
  38179. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38180. const ModifierKeys& mods)
  38181. {
  38182. if (multipleSelection && mods.isCommandDown())
  38183. {
  38184. flipRowSelection (row);
  38185. }
  38186. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38187. {
  38188. selectRangeOfRows (lastRowSelected, row);
  38189. }
  38190. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38191. {
  38192. selectRowInternal (row, false, true, true);
  38193. }
  38194. }
  38195. int ListBox::getNumSelectedRows() const
  38196. {
  38197. return selected.size();
  38198. }
  38199. int ListBox::getSelectedRow (const int index) const
  38200. {
  38201. return (((unsigned int) index) < (unsigned int) selected.size())
  38202. ? selected [index] : -1;
  38203. }
  38204. bool ListBox::isRowSelected (const int row) const
  38205. {
  38206. return selected.contains (row);
  38207. }
  38208. int ListBox::getLastRowSelected() const
  38209. {
  38210. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38211. }
  38212. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38213. {
  38214. if (((unsigned int) x) < (unsigned int) getWidth())
  38215. {
  38216. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38217. if (((unsigned int) row) < (unsigned int) totalItems)
  38218. return row;
  38219. }
  38220. return -1;
  38221. }
  38222. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38223. {
  38224. if (((unsigned int) x) < (unsigned int) getWidth())
  38225. {
  38226. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38227. return jlimit (0, totalItems, row);
  38228. }
  38229. return -1;
  38230. }
  38231. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38232. {
  38233. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38234. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38235. }
  38236. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38237. {
  38238. return viewport->getRowNumberOfComponent (rowComponent);
  38239. }
  38240. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38241. const bool relativeToComponentTopLeft) const throw()
  38242. {
  38243. const int rowHeight = getRowHeight();
  38244. int y = viewport->getY() + rowHeight * rowNumber;
  38245. if (relativeToComponentTopLeft)
  38246. y -= viewport->getViewPositionY();
  38247. return Rectangle<int> (viewport->getX(), y,
  38248. viewport->getViewedComponent()->getWidth(), rowHeight);
  38249. }
  38250. void ListBox::setVerticalPosition (const double proportion)
  38251. {
  38252. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38253. viewport->setViewPosition (viewport->getViewPositionX(),
  38254. jmax (0, roundToInt (proportion * offscreen)));
  38255. }
  38256. double ListBox::getVerticalPosition() const
  38257. {
  38258. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38259. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38260. : 0;
  38261. }
  38262. int ListBox::getVisibleRowWidth() const throw()
  38263. {
  38264. return viewport->getViewWidth();
  38265. }
  38266. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38267. {
  38268. if (row < viewport->firstWholeIndex)
  38269. {
  38270. viewport->setViewPosition (viewport->getViewPositionX(),
  38271. row * getRowHeight());
  38272. }
  38273. else if (row >= viewport->lastWholeIndex)
  38274. {
  38275. viewport->setViewPosition (viewport->getViewPositionX(),
  38276. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38277. }
  38278. }
  38279. bool ListBox::keyPressed (const KeyPress& key)
  38280. {
  38281. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38282. const bool multiple = multipleSelection
  38283. && (lastRowSelected >= 0)
  38284. && (key.getModifiers().isShiftDown()
  38285. || key.getModifiers().isCtrlDown()
  38286. || key.getModifiers().isCommandDown());
  38287. if (key.isKeyCode (KeyPress::upKey))
  38288. {
  38289. if (multiple)
  38290. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38291. else
  38292. selectRow (jmax (0, lastRowSelected - 1));
  38293. }
  38294. else if (key.isKeyCode (KeyPress::returnKey)
  38295. && isRowSelected (lastRowSelected))
  38296. {
  38297. if (model != 0)
  38298. model->returnKeyPressed (lastRowSelected);
  38299. }
  38300. else if (key.isKeyCode (KeyPress::pageUpKey))
  38301. {
  38302. if (multiple)
  38303. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38304. else
  38305. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38306. }
  38307. else if (key.isKeyCode (KeyPress::pageDownKey))
  38308. {
  38309. if (multiple)
  38310. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38311. else
  38312. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38313. }
  38314. else if (key.isKeyCode (KeyPress::homeKey))
  38315. {
  38316. if (multiple && key.getModifiers().isShiftDown())
  38317. selectRangeOfRows (lastRowSelected, 0);
  38318. else
  38319. selectRow (0);
  38320. }
  38321. else if (key.isKeyCode (KeyPress::endKey))
  38322. {
  38323. if (multiple && key.getModifiers().isShiftDown())
  38324. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38325. else
  38326. selectRow (totalItems - 1);
  38327. }
  38328. else if (key.isKeyCode (KeyPress::downKey))
  38329. {
  38330. if (multiple)
  38331. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38332. else
  38333. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38334. }
  38335. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38336. && isRowSelected (lastRowSelected))
  38337. {
  38338. if (model != 0)
  38339. model->deleteKeyPressed (lastRowSelected);
  38340. }
  38341. else if (multiple && key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  38342. {
  38343. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38344. }
  38345. else
  38346. {
  38347. return false;
  38348. }
  38349. return true;
  38350. }
  38351. bool ListBox::keyStateChanged (const bool isKeyDown)
  38352. {
  38353. return isKeyDown
  38354. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38355. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38356. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38357. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38358. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38359. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38360. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38361. }
  38362. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38363. {
  38364. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38365. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38366. }
  38367. void ListBox::mouseMove (const MouseEvent& e)
  38368. {
  38369. if (mouseMoveSelects)
  38370. {
  38371. const MouseEvent e2 (e.getEventRelativeTo (this));
  38372. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38373. }
  38374. }
  38375. void ListBox::mouseExit (const MouseEvent& e)
  38376. {
  38377. mouseMove (e);
  38378. }
  38379. void ListBox::mouseUp (const MouseEvent& e)
  38380. {
  38381. if (e.mouseWasClicked() && model != 0)
  38382. model->backgroundClicked();
  38383. }
  38384. void ListBox::setRowHeight (const int newHeight)
  38385. {
  38386. rowHeight = jmax (1, newHeight);
  38387. viewport->setSingleStepSizes (20, rowHeight);
  38388. updateContent();
  38389. }
  38390. int ListBox::getNumRowsOnScreen() const throw()
  38391. {
  38392. return viewport->getMaximumVisibleHeight() / rowHeight;
  38393. }
  38394. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38395. {
  38396. minimumRowWidth = newMinimumWidth;
  38397. updateContent();
  38398. }
  38399. int ListBox::getVisibleContentWidth() const throw()
  38400. {
  38401. return viewport->getMaximumVisibleWidth();
  38402. }
  38403. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38404. {
  38405. return viewport->getVerticalScrollBar();
  38406. }
  38407. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38408. {
  38409. return viewport->getHorizontalScrollBar();
  38410. }
  38411. void ListBox::colourChanged()
  38412. {
  38413. setOpaque (findColour (backgroundColourId).isOpaque());
  38414. viewport->setOpaque (isOpaque());
  38415. repaint();
  38416. }
  38417. void ListBox::setOutlineThickness (const int outlineThickness_)
  38418. {
  38419. outlineThickness = outlineThickness_;
  38420. resized();
  38421. }
  38422. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38423. {
  38424. if (headerComponent != newHeaderComponent)
  38425. {
  38426. delete headerComponent;
  38427. headerComponent = newHeaderComponent;
  38428. addAndMakeVisible (newHeaderComponent);
  38429. ListBox::resized();
  38430. }
  38431. }
  38432. void ListBox::repaintRow (const int rowNumber) throw()
  38433. {
  38434. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38435. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38436. }
  38437. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38438. {
  38439. Rectangle<int> imageArea;
  38440. const int firstRow = getRowContainingPosition (0, 0);
  38441. int i;
  38442. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38443. {
  38444. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38445. if (rowComp != 0 && isRowSelected (firstRow + i))
  38446. {
  38447. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38448. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38449. if (imageArea.isEmpty())
  38450. imageArea = rowRect;
  38451. else
  38452. imageArea = imageArea.getUnion (rowRect);
  38453. }
  38454. }
  38455. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38456. imageX = imageArea.getX();
  38457. imageY = imageArea.getY();
  38458. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38459. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38460. {
  38461. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38462. if (rowComp != 0 && isRowSelected (firstRow + i))
  38463. {
  38464. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38465. Graphics g (*snapshot);
  38466. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38467. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38468. rowComp->paintEntireComponent (g);
  38469. }
  38470. }
  38471. return snapshot;
  38472. }
  38473. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38474. {
  38475. DragAndDropContainer* const dragContainer
  38476. = DragAndDropContainer::findParentDragContainerFor (this);
  38477. if (dragContainer != 0)
  38478. {
  38479. int x, y;
  38480. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38481. dragImage->multiplyAllAlphas (0.6f);
  38482. MouseEvent e2 (e.getEventRelativeTo (this));
  38483. const Point<int> p (x - e2.x, y - e2.y);
  38484. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38485. }
  38486. else
  38487. {
  38488. // to be able to do a drag-and-drop operation, the listbox needs to
  38489. // be inside a component which is also a DragAndDropContainer.
  38490. jassertfalse
  38491. }
  38492. }
  38493. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38494. {
  38495. (void) existingComponentToUpdate;
  38496. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38497. return 0;
  38498. }
  38499. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38500. {
  38501. }
  38502. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38503. {
  38504. }
  38505. void ListBoxModel::backgroundClicked()
  38506. {
  38507. }
  38508. void ListBoxModel::selectedRowsChanged (int)
  38509. {
  38510. }
  38511. void ListBoxModel::deleteKeyPressed (int)
  38512. {
  38513. }
  38514. void ListBoxModel::returnKeyPressed (int)
  38515. {
  38516. }
  38517. void ListBoxModel::listWasScrolled()
  38518. {
  38519. }
  38520. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38521. {
  38522. return String::empty;
  38523. }
  38524. const String ListBoxModel::getTooltipForRow (int)
  38525. {
  38526. return String::empty;
  38527. }
  38528. END_JUCE_NAMESPACE
  38529. /*** End of inlined file: juce_ListBox.cpp ***/
  38530. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38531. BEGIN_JUCE_NAMESPACE
  38532. ProgressBar::ProgressBar (double& progress_)
  38533. : progress (progress_),
  38534. displayPercentage (true),
  38535. lastCallbackTime (0)
  38536. {
  38537. currentValue = jlimit (0.0, 1.0, progress);
  38538. }
  38539. ProgressBar::~ProgressBar()
  38540. {
  38541. }
  38542. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38543. {
  38544. displayPercentage = shouldDisplayPercentage;
  38545. repaint();
  38546. }
  38547. void ProgressBar::setTextToDisplay (const String& text)
  38548. {
  38549. displayPercentage = false;
  38550. displayedMessage = text;
  38551. }
  38552. void ProgressBar::lookAndFeelChanged()
  38553. {
  38554. setOpaque (findColour (backgroundColourId).isOpaque());
  38555. }
  38556. void ProgressBar::colourChanged()
  38557. {
  38558. lookAndFeelChanged();
  38559. }
  38560. void ProgressBar::paint (Graphics& g)
  38561. {
  38562. String text;
  38563. if (displayPercentage)
  38564. {
  38565. if (currentValue >= 0 && currentValue <= 1.0)
  38566. text << roundToInt (currentValue * 100.0) << '%';
  38567. }
  38568. else
  38569. {
  38570. text = displayedMessage;
  38571. }
  38572. getLookAndFeel().drawProgressBar (g, *this,
  38573. getWidth(), getHeight(),
  38574. currentValue, text);
  38575. }
  38576. void ProgressBar::visibilityChanged()
  38577. {
  38578. if (isVisible())
  38579. startTimer (30);
  38580. else
  38581. stopTimer();
  38582. }
  38583. void ProgressBar::timerCallback()
  38584. {
  38585. double newProgress = progress;
  38586. const uint32 now = Time::getMillisecondCounter();
  38587. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38588. lastCallbackTime = now;
  38589. if (currentValue != newProgress
  38590. || newProgress < 0 || newProgress >= 1.0
  38591. || currentMessage != displayedMessage)
  38592. {
  38593. if (currentValue < newProgress
  38594. && newProgress >= 0 && newProgress < 1.0
  38595. && currentValue >= 0 && currentValue < 1.0)
  38596. {
  38597. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38598. newProgress);
  38599. }
  38600. currentValue = newProgress;
  38601. currentMessage = displayedMessage;
  38602. repaint();
  38603. }
  38604. }
  38605. END_JUCE_NAMESPACE
  38606. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38607. /*** Start of inlined file: juce_Slider.cpp ***/
  38608. BEGIN_JUCE_NAMESPACE
  38609. class SliderPopupDisplayComponent : public BubbleComponent
  38610. {
  38611. public:
  38612. SliderPopupDisplayComponent (Slider* const owner_)
  38613. : owner (owner_),
  38614. font (15.0f, Font::bold)
  38615. {
  38616. setAlwaysOnTop (true);
  38617. }
  38618. ~SliderPopupDisplayComponent()
  38619. {
  38620. }
  38621. void paintContent (Graphics& g, int w, int h)
  38622. {
  38623. g.setFont (font);
  38624. g.setColour (Colours::black);
  38625. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38626. }
  38627. void getContentSize (int& w, int& h)
  38628. {
  38629. w = font.getStringWidth (text) + 18;
  38630. h = (int) (font.getHeight() * 1.6f);
  38631. }
  38632. void updatePosition (const String& newText)
  38633. {
  38634. if (text != newText)
  38635. {
  38636. text = newText;
  38637. repaint();
  38638. }
  38639. BubbleComponent::setPosition (owner);
  38640. }
  38641. juce_UseDebuggingNewOperator
  38642. private:
  38643. Slider* owner;
  38644. Font font;
  38645. String text;
  38646. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38647. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38648. };
  38649. Slider::Slider (const String& name)
  38650. : Component (name),
  38651. lastCurrentValue (0),
  38652. lastValueMin (0),
  38653. lastValueMax (0),
  38654. minimum (0),
  38655. maximum (10),
  38656. interval (0),
  38657. skewFactor (1.0),
  38658. velocityModeSensitivity (1.0),
  38659. velocityModeOffset (0.0),
  38660. velocityModeThreshold (1),
  38661. rotaryStart (float_Pi * 1.2f),
  38662. rotaryEnd (float_Pi * 2.8f),
  38663. numDecimalPlaces (7),
  38664. sliderRegionStart (0),
  38665. sliderRegionSize (1),
  38666. sliderBeingDragged (-1),
  38667. pixelsForFullDragExtent (250),
  38668. style (LinearHorizontal),
  38669. textBoxPos (TextBoxLeft),
  38670. textBoxWidth (80),
  38671. textBoxHeight (20),
  38672. incDecButtonMode (incDecButtonsNotDraggable),
  38673. editableText (true),
  38674. doubleClickToValue (false),
  38675. isVelocityBased (false),
  38676. userKeyOverridesVelocity (true),
  38677. rotaryStop (true),
  38678. incDecButtonsSideBySide (false),
  38679. sendChangeOnlyOnRelease (false),
  38680. popupDisplayEnabled (false),
  38681. menuEnabled (false),
  38682. menuShown (false),
  38683. scrollWheelEnabled (true),
  38684. snapsToMousePos (true),
  38685. valueBox (0),
  38686. incButton (0),
  38687. decButton (0),
  38688. popupDisplay (0),
  38689. parentForPopupDisplay (0)
  38690. {
  38691. setWantsKeyboardFocus (false);
  38692. setRepaintsOnMouseActivity (true);
  38693. lookAndFeelChanged();
  38694. updateText();
  38695. currentValue.addListener (this);
  38696. valueMin.addListener (this);
  38697. valueMax.addListener (this);
  38698. }
  38699. Slider::~Slider()
  38700. {
  38701. currentValue.removeListener (this);
  38702. valueMin.removeListener (this);
  38703. valueMax.removeListener (this);
  38704. popupDisplay = 0;
  38705. deleteAllChildren();
  38706. }
  38707. void Slider::handleAsyncUpdate()
  38708. {
  38709. cancelPendingUpdate();
  38710. Component::BailOutChecker checker (this);
  38711. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38712. }
  38713. void Slider::sendDragStart()
  38714. {
  38715. startedDragging();
  38716. Component::BailOutChecker checker (this);
  38717. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38718. }
  38719. void Slider::sendDragEnd()
  38720. {
  38721. stoppedDragging();
  38722. sliderBeingDragged = -1;
  38723. Component::BailOutChecker checker (this);
  38724. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38725. }
  38726. void Slider::addListener (SliderListener* const listener)
  38727. {
  38728. listeners.add (listener);
  38729. }
  38730. void Slider::removeListener (SliderListener* const listener)
  38731. {
  38732. listeners.remove (listener);
  38733. }
  38734. void Slider::setSliderStyle (const SliderStyle newStyle)
  38735. {
  38736. if (style != newStyle)
  38737. {
  38738. style = newStyle;
  38739. repaint();
  38740. lookAndFeelChanged();
  38741. }
  38742. }
  38743. void Slider::setRotaryParameters (const float startAngleRadians,
  38744. const float endAngleRadians,
  38745. const bool stopAtEnd)
  38746. {
  38747. // make sure the values are sensible..
  38748. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38749. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38750. jassert (rotaryStart < rotaryEnd);
  38751. rotaryStart = startAngleRadians;
  38752. rotaryEnd = endAngleRadians;
  38753. rotaryStop = stopAtEnd;
  38754. }
  38755. void Slider::setVelocityBasedMode (const bool velBased)
  38756. {
  38757. isVelocityBased = velBased;
  38758. }
  38759. void Slider::setVelocityModeParameters (const double sensitivity,
  38760. const int threshold,
  38761. const double offset,
  38762. const bool userCanPressKeyToSwapMode)
  38763. {
  38764. jassert (threshold >= 0);
  38765. jassert (sensitivity > 0);
  38766. jassert (offset >= 0);
  38767. velocityModeSensitivity = sensitivity;
  38768. velocityModeOffset = offset;
  38769. velocityModeThreshold = threshold;
  38770. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38771. }
  38772. void Slider::setSkewFactor (const double factor)
  38773. {
  38774. skewFactor = factor;
  38775. }
  38776. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38777. {
  38778. if (maximum > minimum)
  38779. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38780. / (maximum - minimum));
  38781. }
  38782. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38783. {
  38784. jassert (distanceForFullScaleDrag > 0);
  38785. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38786. }
  38787. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38788. {
  38789. if (incDecButtonMode != mode)
  38790. {
  38791. incDecButtonMode = mode;
  38792. lookAndFeelChanged();
  38793. }
  38794. }
  38795. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38796. const bool isReadOnly,
  38797. const int textEntryBoxWidth,
  38798. const int textEntryBoxHeight)
  38799. {
  38800. textBoxPos = newPosition;
  38801. editableText = ! isReadOnly;
  38802. textBoxWidth = textEntryBoxWidth;
  38803. textBoxHeight = textEntryBoxHeight;
  38804. repaint();
  38805. lookAndFeelChanged();
  38806. }
  38807. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38808. {
  38809. editableText = shouldBeEditable;
  38810. if (valueBox != 0)
  38811. valueBox->setEditable (shouldBeEditable && isEnabled());
  38812. }
  38813. void Slider::showTextBox()
  38814. {
  38815. jassert (editableText); // this should probably be avoided in read-only sliders.
  38816. if (valueBox != 0)
  38817. valueBox->showEditor();
  38818. }
  38819. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38820. {
  38821. if (valueBox != 0)
  38822. {
  38823. valueBox->hideEditor (discardCurrentEditorContents);
  38824. if (discardCurrentEditorContents)
  38825. updateText();
  38826. }
  38827. }
  38828. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38829. {
  38830. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38831. }
  38832. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38833. {
  38834. snapsToMousePos = shouldSnapToMouse;
  38835. }
  38836. void Slider::setPopupDisplayEnabled (const bool enabled,
  38837. Component* const parentComponentToUse)
  38838. {
  38839. popupDisplayEnabled = enabled;
  38840. parentForPopupDisplay = parentComponentToUse;
  38841. }
  38842. void Slider::colourChanged()
  38843. {
  38844. lookAndFeelChanged();
  38845. }
  38846. void Slider::lookAndFeelChanged()
  38847. {
  38848. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38849. : getTextFromValue (currentValue.getValue()));
  38850. deleteAllChildren();
  38851. valueBox = 0;
  38852. LookAndFeel& lf = getLookAndFeel();
  38853. if (textBoxPos != NoTextBox)
  38854. {
  38855. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38856. valueBox->setWantsKeyboardFocus (false);
  38857. valueBox->setText (previousTextBoxContent, false);
  38858. valueBox->setEditable (editableText && isEnabled());
  38859. valueBox->addListener (this);
  38860. if (style == LinearBar)
  38861. valueBox->addMouseListener (this, false);
  38862. valueBox->setTooltip (getTooltip());
  38863. }
  38864. if (style == IncDecButtons)
  38865. {
  38866. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38867. incButton->addButtonListener (this);
  38868. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38869. decButton->addButtonListener (this);
  38870. if (incDecButtonMode != incDecButtonsNotDraggable)
  38871. {
  38872. incButton->addMouseListener (this, false);
  38873. decButton->addMouseListener (this, false);
  38874. }
  38875. else
  38876. {
  38877. incButton->setRepeatSpeed (300, 100, 20);
  38878. incButton->addMouseListener (decButton, false);
  38879. decButton->setRepeatSpeed (300, 100, 20);
  38880. decButton->addMouseListener (incButton, false);
  38881. }
  38882. incButton->setTooltip (getTooltip());
  38883. decButton->setTooltip (getTooltip());
  38884. }
  38885. setComponentEffect (lf.getSliderEffect());
  38886. resized();
  38887. repaint();
  38888. }
  38889. void Slider::setRange (const double newMin,
  38890. const double newMax,
  38891. const double newInt)
  38892. {
  38893. if (minimum != newMin
  38894. || maximum != newMax
  38895. || interval != newInt)
  38896. {
  38897. minimum = newMin;
  38898. maximum = newMax;
  38899. interval = newInt;
  38900. // figure out the number of DPs needed to display all values at this
  38901. // interval setting.
  38902. numDecimalPlaces = 7;
  38903. if (newInt != 0)
  38904. {
  38905. int v = abs ((int) (newInt * 10000000));
  38906. while ((v % 10) == 0)
  38907. {
  38908. --numDecimalPlaces;
  38909. v /= 10;
  38910. }
  38911. }
  38912. // keep the current values inside the new range..
  38913. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38914. {
  38915. setValue (getValue(), false, false);
  38916. }
  38917. else
  38918. {
  38919. setMinValue (getMinValue(), false, false);
  38920. setMaxValue (getMaxValue(), false, false);
  38921. }
  38922. updateText();
  38923. }
  38924. }
  38925. void Slider::triggerChangeMessage (const bool synchronous)
  38926. {
  38927. if (synchronous)
  38928. handleAsyncUpdate();
  38929. else
  38930. triggerAsyncUpdate();
  38931. valueChanged();
  38932. }
  38933. void Slider::valueChanged (Value& value)
  38934. {
  38935. if (value.refersToSameSourceAs (currentValue))
  38936. {
  38937. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38938. setValue (currentValue.getValue(), false, false);
  38939. }
  38940. else if (value.refersToSameSourceAs (valueMin))
  38941. setMinValue (valueMin.getValue(), false, false, true);
  38942. else if (value.refersToSameSourceAs (valueMax))
  38943. setMaxValue (valueMax.getValue(), false, false, true);
  38944. }
  38945. double Slider::getValue() const
  38946. {
  38947. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  38948. // methods to get the two values.
  38949. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38950. return currentValue.getValue();
  38951. }
  38952. void Slider::setValue (double newValue,
  38953. const bool sendUpdateMessage,
  38954. const bool sendMessageSynchronously)
  38955. {
  38956. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  38957. // methods to set the two values.
  38958. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38959. newValue = constrainedValue (newValue);
  38960. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  38961. {
  38962. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  38963. newValue = jlimit ((double) valueMin.getValue(),
  38964. (double) valueMax.getValue(),
  38965. newValue);
  38966. }
  38967. if (newValue != lastCurrentValue)
  38968. {
  38969. if (valueBox != 0)
  38970. valueBox->hideEditor (true);
  38971. lastCurrentValue = newValue;
  38972. currentValue = newValue;
  38973. updateText();
  38974. repaint();
  38975. if (popupDisplay != 0)
  38976. {
  38977. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38978. ->updatePosition (getTextFromValue (newValue));
  38979. popupDisplay->repaint();
  38980. }
  38981. if (sendUpdateMessage)
  38982. triggerChangeMessage (sendMessageSynchronously);
  38983. }
  38984. }
  38985. double Slider::getMinValue() const
  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. return valueMin.getValue();
  38991. }
  38992. double Slider::getMaxValue() const
  38993. {
  38994. // The maximum value only applies to sliders that are in two- or three-value mode.
  38995. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38996. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38997. return valueMax.getValue();
  38998. }
  38999. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39000. {
  39001. // The minimum value only applies to sliders that are in two- or three-value mode.
  39002. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39003. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39004. newValue = constrainedValue (newValue);
  39005. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39006. {
  39007. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39008. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39009. newValue = jmin ((double) valueMax.getValue(), newValue);
  39010. }
  39011. else
  39012. {
  39013. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39014. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39015. newValue = jmin (lastCurrentValue, newValue);
  39016. }
  39017. if (lastValueMin != newValue)
  39018. {
  39019. lastValueMin = newValue;
  39020. valueMin = newValue;
  39021. repaint();
  39022. if (popupDisplay != 0)
  39023. {
  39024. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39025. ->updatePosition (getTextFromValue (newValue));
  39026. popupDisplay->repaint();
  39027. }
  39028. if (sendUpdateMessage)
  39029. triggerChangeMessage (sendMessageSynchronously);
  39030. }
  39031. }
  39032. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39033. {
  39034. // The maximum value only applies to sliders that are in two- or three-value mode.
  39035. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39036. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39037. newValue = constrainedValue (newValue);
  39038. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39039. {
  39040. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39041. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39042. newValue = jmax ((double) valueMin.getValue(), newValue);
  39043. }
  39044. else
  39045. {
  39046. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39047. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39048. newValue = jmax (lastCurrentValue, newValue);
  39049. }
  39050. if (lastValueMax != newValue)
  39051. {
  39052. lastValueMax = newValue;
  39053. valueMax = newValue;
  39054. repaint();
  39055. if (popupDisplay != 0)
  39056. {
  39057. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39058. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39059. popupDisplay->repaint();
  39060. }
  39061. if (sendUpdateMessage)
  39062. triggerChangeMessage (sendMessageSynchronously);
  39063. }
  39064. }
  39065. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39066. const double valueToSetOnDoubleClick)
  39067. {
  39068. doubleClickToValue = isDoubleClickEnabled;
  39069. doubleClickReturnValue = valueToSetOnDoubleClick;
  39070. }
  39071. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39072. {
  39073. isEnabled_ = doubleClickToValue;
  39074. return doubleClickReturnValue;
  39075. }
  39076. void Slider::updateText()
  39077. {
  39078. if (valueBox != 0)
  39079. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39080. }
  39081. void Slider::setTextValueSuffix (const String& suffix)
  39082. {
  39083. if (textSuffix != suffix)
  39084. {
  39085. textSuffix = suffix;
  39086. updateText();
  39087. }
  39088. }
  39089. const String Slider::getTextFromValue (double v)
  39090. {
  39091. if (numDecimalPlaces > 0)
  39092. return String (v, numDecimalPlaces) + textSuffix;
  39093. else
  39094. return String (roundToInt (v)) + textSuffix;
  39095. }
  39096. double Slider::getValueFromText (const String& text)
  39097. {
  39098. String t (text.trimStart());
  39099. if (t.endsWith (textSuffix))
  39100. t = t.substring (0, t.length() - textSuffix.length());
  39101. while (t.startsWithChar ('+'))
  39102. t = t.substring (1).trimStart();
  39103. return t.initialSectionContainingOnly ("0123456789.,-")
  39104. .getDoubleValue();
  39105. }
  39106. double Slider::proportionOfLengthToValue (double proportion)
  39107. {
  39108. if (skewFactor != 1.0 && proportion > 0.0)
  39109. proportion = exp (log (proportion) / skewFactor);
  39110. return minimum + (maximum - minimum) * proportion;
  39111. }
  39112. double Slider::valueToProportionOfLength (double value)
  39113. {
  39114. const double n = (value - minimum) / (maximum - minimum);
  39115. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39116. }
  39117. double Slider::snapValue (double attemptedValue, const bool)
  39118. {
  39119. return attemptedValue;
  39120. }
  39121. void Slider::startedDragging()
  39122. {
  39123. }
  39124. void Slider::stoppedDragging()
  39125. {
  39126. }
  39127. void Slider::valueChanged()
  39128. {
  39129. }
  39130. void Slider::enablementChanged()
  39131. {
  39132. repaint();
  39133. }
  39134. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39135. {
  39136. menuEnabled = menuEnabled_;
  39137. }
  39138. void Slider::setScrollWheelEnabled (const bool enabled)
  39139. {
  39140. scrollWheelEnabled = enabled;
  39141. }
  39142. void Slider::labelTextChanged (Label* label)
  39143. {
  39144. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39145. if (newValue != (double) currentValue.getValue())
  39146. {
  39147. sendDragStart();
  39148. setValue (newValue, true, true);
  39149. sendDragEnd();
  39150. }
  39151. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39152. }
  39153. void Slider::buttonClicked (Button* button)
  39154. {
  39155. if (style == IncDecButtons)
  39156. {
  39157. sendDragStart();
  39158. if (button == incButton)
  39159. setValue (snapValue (getValue() + interval, false), true, true);
  39160. else if (button == decButton)
  39161. setValue (snapValue (getValue() - interval, false), true, true);
  39162. sendDragEnd();
  39163. }
  39164. }
  39165. double Slider::constrainedValue (double value) const
  39166. {
  39167. if (interval > 0)
  39168. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39169. if (value <= minimum || maximum <= minimum)
  39170. value = minimum;
  39171. else if (value >= maximum)
  39172. value = maximum;
  39173. return value;
  39174. }
  39175. float Slider::getLinearSliderPos (const double value)
  39176. {
  39177. double sliderPosProportional;
  39178. if (maximum > minimum)
  39179. {
  39180. if (value < minimum)
  39181. {
  39182. sliderPosProportional = 0.0;
  39183. }
  39184. else if (value > maximum)
  39185. {
  39186. sliderPosProportional = 1.0;
  39187. }
  39188. else
  39189. {
  39190. sliderPosProportional = valueToProportionOfLength (value);
  39191. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39192. }
  39193. }
  39194. else
  39195. {
  39196. sliderPosProportional = 0.5;
  39197. }
  39198. if (isVertical() || style == IncDecButtons)
  39199. sliderPosProportional = 1.0 - sliderPosProportional;
  39200. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39201. }
  39202. bool Slider::isHorizontal() const
  39203. {
  39204. return style == LinearHorizontal
  39205. || style == LinearBar
  39206. || style == TwoValueHorizontal
  39207. || style == ThreeValueHorizontal;
  39208. }
  39209. bool Slider::isVertical() const
  39210. {
  39211. return style == LinearVertical
  39212. || style == TwoValueVertical
  39213. || style == ThreeValueVertical;
  39214. }
  39215. bool Slider::incDecDragDirectionIsHorizontal() const
  39216. {
  39217. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39218. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39219. }
  39220. float Slider::getPositionOfValue (const double value)
  39221. {
  39222. if (isHorizontal() || isVertical())
  39223. {
  39224. return getLinearSliderPos (value);
  39225. }
  39226. else
  39227. {
  39228. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39229. return 0.0f;
  39230. }
  39231. }
  39232. void Slider::paint (Graphics& g)
  39233. {
  39234. if (style != IncDecButtons)
  39235. {
  39236. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39237. {
  39238. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39239. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39240. getLookAndFeel().drawRotarySlider (g,
  39241. sliderRect.getX(),
  39242. sliderRect.getY(),
  39243. sliderRect.getWidth(),
  39244. sliderRect.getHeight(),
  39245. sliderPos,
  39246. rotaryStart, rotaryEnd,
  39247. *this);
  39248. }
  39249. else
  39250. {
  39251. getLookAndFeel().drawLinearSlider (g,
  39252. sliderRect.getX(),
  39253. sliderRect.getY(),
  39254. sliderRect.getWidth(),
  39255. sliderRect.getHeight(),
  39256. getLinearSliderPos (lastCurrentValue),
  39257. getLinearSliderPos (lastValueMin),
  39258. getLinearSliderPos (lastValueMax),
  39259. style,
  39260. *this);
  39261. }
  39262. if (style == LinearBar && valueBox == 0)
  39263. {
  39264. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39265. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39266. }
  39267. }
  39268. }
  39269. void Slider::resized()
  39270. {
  39271. int minXSpace = 0;
  39272. int minYSpace = 0;
  39273. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39274. minXSpace = 30;
  39275. else
  39276. minYSpace = 15;
  39277. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39278. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39279. if (style == LinearBar)
  39280. {
  39281. if (valueBox != 0)
  39282. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39283. }
  39284. else
  39285. {
  39286. if (textBoxPos == NoTextBox)
  39287. {
  39288. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39289. }
  39290. else if (textBoxPos == TextBoxLeft)
  39291. {
  39292. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39293. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39294. }
  39295. else if (textBoxPos == TextBoxRight)
  39296. {
  39297. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39298. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39299. }
  39300. else if (textBoxPos == TextBoxAbove)
  39301. {
  39302. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39303. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39304. }
  39305. else if (textBoxPos == TextBoxBelow)
  39306. {
  39307. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39308. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39309. }
  39310. }
  39311. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39312. if (style == LinearBar)
  39313. {
  39314. const int barIndent = 1;
  39315. sliderRegionStart = barIndent;
  39316. sliderRegionSize = getWidth() - barIndent * 2;
  39317. sliderRect.setBounds (sliderRegionStart, barIndent,
  39318. sliderRegionSize, getHeight() - barIndent * 2);
  39319. }
  39320. else if (isHorizontal())
  39321. {
  39322. sliderRegionStart = sliderRect.getX() + indent;
  39323. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39324. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39325. sliderRegionSize, sliderRect.getHeight());
  39326. }
  39327. else if (isVertical())
  39328. {
  39329. sliderRegionStart = sliderRect.getY() + indent;
  39330. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39331. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39332. sliderRect.getWidth(), sliderRegionSize);
  39333. }
  39334. else
  39335. {
  39336. sliderRegionStart = 0;
  39337. sliderRegionSize = 100;
  39338. }
  39339. if (style == IncDecButtons)
  39340. {
  39341. Rectangle<int> buttonRect (sliderRect);
  39342. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39343. buttonRect.expand (-2, 0);
  39344. else
  39345. buttonRect.expand (0, -2);
  39346. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39347. if (incDecButtonsSideBySide)
  39348. {
  39349. decButton->setBounds (buttonRect.getX(),
  39350. buttonRect.getY(),
  39351. buttonRect.getWidth() / 2,
  39352. buttonRect.getHeight());
  39353. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39354. incButton->setBounds (buttonRect.getCentreX(),
  39355. buttonRect.getY(),
  39356. buttonRect.getWidth() / 2,
  39357. buttonRect.getHeight());
  39358. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39359. }
  39360. else
  39361. {
  39362. incButton->setBounds (buttonRect.getX(),
  39363. buttonRect.getY(),
  39364. buttonRect.getWidth(),
  39365. buttonRect.getHeight() / 2);
  39366. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39367. decButton->setBounds (buttonRect.getX(),
  39368. buttonRect.getCentreY(),
  39369. buttonRect.getWidth(),
  39370. buttonRect.getHeight() / 2);
  39371. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39372. }
  39373. }
  39374. }
  39375. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39376. {
  39377. repaint();
  39378. }
  39379. void Slider::mouseDown (const MouseEvent& e)
  39380. {
  39381. mouseWasHidden = false;
  39382. incDecDragged = false;
  39383. mouseXWhenLastDragged = e.x;
  39384. mouseYWhenLastDragged = e.y;
  39385. mouseDragStartX = e.getMouseDownX();
  39386. mouseDragStartY = e.getMouseDownY();
  39387. if (isEnabled())
  39388. {
  39389. if (e.mods.isPopupMenu() && menuEnabled)
  39390. {
  39391. menuShown = true;
  39392. PopupMenu m;
  39393. m.setLookAndFeel (&getLookAndFeel());
  39394. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39395. m.addSeparator();
  39396. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39397. {
  39398. PopupMenu rotaryMenu;
  39399. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39400. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39401. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39402. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39403. }
  39404. const int r = m.show();
  39405. if (r == 1)
  39406. {
  39407. setVelocityBasedMode (! isVelocityBased);
  39408. }
  39409. else if (r == 2)
  39410. {
  39411. setSliderStyle (Rotary);
  39412. }
  39413. else if (r == 3)
  39414. {
  39415. setSliderStyle (RotaryHorizontalDrag);
  39416. }
  39417. else if (r == 4)
  39418. {
  39419. setSliderStyle (RotaryVerticalDrag);
  39420. }
  39421. }
  39422. else if (maximum > minimum)
  39423. {
  39424. menuShown = false;
  39425. if (valueBox != 0)
  39426. valueBox->hideEditor (true);
  39427. sliderBeingDragged = 0;
  39428. if (style == TwoValueHorizontal
  39429. || style == TwoValueVertical
  39430. || style == ThreeValueHorizontal
  39431. || style == ThreeValueVertical)
  39432. {
  39433. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39434. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39435. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39436. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39437. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39438. {
  39439. if (maxPosDistance <= minPosDistance)
  39440. sliderBeingDragged = 2;
  39441. else
  39442. sliderBeingDragged = 1;
  39443. }
  39444. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39445. {
  39446. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39447. sliderBeingDragged = 1;
  39448. else if (normalPosDistance >= maxPosDistance)
  39449. sliderBeingDragged = 2;
  39450. }
  39451. }
  39452. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39453. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39454. * valueToProportionOfLength (currentValue.getValue());
  39455. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39456. : ((sliderBeingDragged == 1) ? valueMin
  39457. : currentValue)).getValue();
  39458. valueOnMouseDown = valueWhenLastDragged;
  39459. if (popupDisplayEnabled)
  39460. {
  39461. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39462. popupDisplay = popup;
  39463. if (parentForPopupDisplay != 0)
  39464. {
  39465. parentForPopupDisplay->addChildComponent (popup);
  39466. }
  39467. else
  39468. {
  39469. popup->addToDesktop (0);
  39470. }
  39471. popup->setVisible (true);
  39472. }
  39473. sendDragStart();
  39474. mouseDrag (e);
  39475. }
  39476. }
  39477. }
  39478. void Slider::mouseUp (const MouseEvent&)
  39479. {
  39480. if (isEnabled()
  39481. && (! menuShown)
  39482. && (maximum > minimum)
  39483. && (style != IncDecButtons || incDecDragged))
  39484. {
  39485. restoreMouseIfHidden();
  39486. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39487. triggerChangeMessage (false);
  39488. sendDragEnd();
  39489. popupDisplay = 0;
  39490. if (style == IncDecButtons)
  39491. {
  39492. incButton->setState (Button::buttonNormal);
  39493. decButton->setState (Button::buttonNormal);
  39494. }
  39495. }
  39496. }
  39497. void Slider::restoreMouseIfHidden()
  39498. {
  39499. if (mouseWasHidden)
  39500. {
  39501. mouseWasHidden = false;
  39502. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39503. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39504. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39505. : ((sliderBeingDragged == 1) ? getMinValue()
  39506. : (double) currentValue.getValue());
  39507. Point<int> mousePos;
  39508. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39509. {
  39510. mousePos = Desktop::getLastMouseDownPosition();
  39511. if (style == RotaryHorizontalDrag)
  39512. {
  39513. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39514. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39515. }
  39516. else
  39517. {
  39518. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39519. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39520. }
  39521. }
  39522. else
  39523. {
  39524. const int pixelPos = (int) getLinearSliderPos (pos);
  39525. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39526. isVertical() ? pixelPos : (getHeight() / 2)));
  39527. }
  39528. Desktop::setMousePosition (mousePos);
  39529. }
  39530. }
  39531. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39532. {
  39533. if (isEnabled()
  39534. && style != IncDecButtons
  39535. && style != Rotary
  39536. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39537. {
  39538. restoreMouseIfHidden();
  39539. }
  39540. }
  39541. static double smallestAngleBetween (double a1, double a2)
  39542. {
  39543. return jmin (fabs (a1 - a2),
  39544. fabs (a1 + double_Pi * 2.0 - a2),
  39545. fabs (a2 + double_Pi * 2.0 - a1));
  39546. }
  39547. void Slider::mouseDrag (const MouseEvent& e)
  39548. {
  39549. if (isEnabled()
  39550. && (! menuShown)
  39551. && (maximum > minimum))
  39552. {
  39553. if (style == Rotary)
  39554. {
  39555. int dx = e.x - sliderRect.getCentreX();
  39556. int dy = e.y - sliderRect.getCentreY();
  39557. if (dx * dx + dy * dy > 25)
  39558. {
  39559. double angle = atan2 ((double) dx, (double) -dy);
  39560. while (angle < 0.0)
  39561. angle += double_Pi * 2.0;
  39562. if (rotaryStop && ! e.mouseWasClicked())
  39563. {
  39564. if (fabs (angle - lastAngle) > double_Pi)
  39565. {
  39566. if (angle >= lastAngle)
  39567. angle -= double_Pi * 2.0;
  39568. else
  39569. angle += double_Pi * 2.0;
  39570. }
  39571. if (angle >= lastAngle)
  39572. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39573. else
  39574. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39575. }
  39576. else
  39577. {
  39578. while (angle < rotaryStart)
  39579. angle += double_Pi * 2.0;
  39580. if (angle > rotaryEnd)
  39581. {
  39582. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39583. angle = rotaryStart;
  39584. else
  39585. angle = rotaryEnd;
  39586. }
  39587. }
  39588. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39589. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39590. lastAngle = angle;
  39591. }
  39592. }
  39593. else
  39594. {
  39595. if (style == LinearBar && e.mouseWasClicked()
  39596. && valueBox != 0 && valueBox->isEditable())
  39597. return;
  39598. if (style == IncDecButtons && ! incDecDragged)
  39599. {
  39600. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39601. return;
  39602. incDecDragged = true;
  39603. mouseDragStartX = e.x;
  39604. mouseDragStartY = e.y;
  39605. }
  39606. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39607. : false))
  39608. || ((maximum - minimum) / sliderRegionSize < interval))
  39609. {
  39610. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39611. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39612. if (style == RotaryHorizontalDrag
  39613. || style == RotaryVerticalDrag
  39614. || style == IncDecButtons
  39615. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39616. && ! snapsToMousePos))
  39617. {
  39618. const int mouseDiff = (style == RotaryHorizontalDrag
  39619. || style == LinearHorizontal
  39620. || style == LinearBar
  39621. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39622. ? e.x - mouseDragStartX
  39623. : mouseDragStartY - e.y;
  39624. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39625. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39626. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39627. if (style == IncDecButtons)
  39628. {
  39629. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39630. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39631. }
  39632. }
  39633. else
  39634. {
  39635. if (isVertical())
  39636. scaledMousePos = 1.0 - scaledMousePos;
  39637. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39638. }
  39639. }
  39640. else
  39641. {
  39642. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39643. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39644. ? e.x - mouseXWhenLastDragged
  39645. : e.y - mouseYWhenLastDragged;
  39646. const double maxSpeed = jmax (200, sliderRegionSize);
  39647. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39648. if (speed != 0)
  39649. {
  39650. speed = 0.2 * velocityModeSensitivity
  39651. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39652. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39653. / maxSpeed))));
  39654. if (mouseDiff < 0)
  39655. speed = -speed;
  39656. if (isVertical() || style == RotaryVerticalDrag
  39657. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39658. speed = -speed;
  39659. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39660. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39661. e.source.enableUnboundedMouseMovement (true, false);
  39662. mouseWasHidden = true;
  39663. }
  39664. }
  39665. }
  39666. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39667. if (sliderBeingDragged == 0)
  39668. {
  39669. setValue (snapValue (valueWhenLastDragged, true),
  39670. ! sendChangeOnlyOnRelease, true);
  39671. }
  39672. else if (sliderBeingDragged == 1)
  39673. {
  39674. setMinValue (snapValue (valueWhenLastDragged, true),
  39675. ! sendChangeOnlyOnRelease, false, true);
  39676. if (e.mods.isShiftDown())
  39677. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39678. else
  39679. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39680. }
  39681. else
  39682. {
  39683. jassert (sliderBeingDragged == 2);
  39684. setMaxValue (snapValue (valueWhenLastDragged, true),
  39685. ! sendChangeOnlyOnRelease, false, true);
  39686. if (e.mods.isShiftDown())
  39687. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39688. else
  39689. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39690. }
  39691. mouseXWhenLastDragged = e.x;
  39692. mouseYWhenLastDragged = e.y;
  39693. }
  39694. }
  39695. void Slider::mouseDoubleClick (const MouseEvent&)
  39696. {
  39697. if (doubleClickToValue
  39698. && isEnabled()
  39699. && style != IncDecButtons
  39700. && minimum <= doubleClickReturnValue
  39701. && maximum >= doubleClickReturnValue)
  39702. {
  39703. sendDragStart();
  39704. setValue (doubleClickReturnValue, true, true);
  39705. sendDragEnd();
  39706. }
  39707. }
  39708. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39709. {
  39710. if (scrollWheelEnabled && isEnabled()
  39711. && style != TwoValueHorizontal
  39712. && style != TwoValueVertical)
  39713. {
  39714. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39715. {
  39716. if (valueBox != 0)
  39717. valueBox->hideEditor (false);
  39718. const double value = (double) currentValue.getValue();
  39719. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39720. const double currentPos = valueToProportionOfLength (value);
  39721. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39722. double delta = (newValue != value)
  39723. ? jmax (fabs (newValue - value), interval) : 0;
  39724. if (value > newValue)
  39725. delta = -delta;
  39726. sendDragStart();
  39727. setValue (snapValue (value + delta, false), true, true);
  39728. sendDragEnd();
  39729. }
  39730. }
  39731. else
  39732. {
  39733. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39734. }
  39735. }
  39736. void SliderListener::sliderDragStarted (Slider*)
  39737. {
  39738. }
  39739. void SliderListener::sliderDragEnded (Slider*)
  39740. {
  39741. }
  39742. END_JUCE_NAMESPACE
  39743. /*** End of inlined file: juce_Slider.cpp ***/
  39744. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39745. BEGIN_JUCE_NAMESPACE
  39746. class DragOverlayComp : public Component
  39747. {
  39748. public:
  39749. DragOverlayComp (Image* const image_)
  39750. : image (image_)
  39751. {
  39752. image->multiplyAllAlphas (0.8f);
  39753. setAlwaysOnTop (true);
  39754. }
  39755. ~DragOverlayComp()
  39756. {
  39757. }
  39758. void paint (Graphics& g)
  39759. {
  39760. g.drawImageAt (image, 0, 0);
  39761. }
  39762. private:
  39763. ScopedPointer <Image> image;
  39764. DragOverlayComp (const DragOverlayComp&);
  39765. DragOverlayComp& operator= (const DragOverlayComp&);
  39766. };
  39767. TableHeaderComponent::TableHeaderComponent()
  39768. : columnsChanged (false),
  39769. columnsResized (false),
  39770. sortChanged (false),
  39771. menuActive (true),
  39772. stretchToFit (false),
  39773. columnIdBeingResized (0),
  39774. columnIdBeingDragged (0),
  39775. columnIdUnderMouse (0),
  39776. lastDeliberateWidth (0)
  39777. {
  39778. }
  39779. TableHeaderComponent::~TableHeaderComponent()
  39780. {
  39781. dragOverlayComp = 0;
  39782. }
  39783. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39784. {
  39785. menuActive = hasMenu;
  39786. }
  39787. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39788. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39789. {
  39790. if (onlyCountVisibleColumns)
  39791. {
  39792. int num = 0;
  39793. for (int i = columns.size(); --i >= 0;)
  39794. if (columns.getUnchecked(i)->isVisible())
  39795. ++num;
  39796. return num;
  39797. }
  39798. else
  39799. {
  39800. return columns.size();
  39801. }
  39802. }
  39803. const String TableHeaderComponent::getColumnName (const int columnId) const
  39804. {
  39805. const ColumnInfo* const ci = getInfoForId (columnId);
  39806. return ci != 0 ? ci->name : String::empty;
  39807. }
  39808. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39809. {
  39810. ColumnInfo* const ci = getInfoForId (columnId);
  39811. if (ci != 0 && ci->name != newName)
  39812. {
  39813. ci->name = newName;
  39814. sendColumnsChanged();
  39815. }
  39816. }
  39817. void TableHeaderComponent::addColumn (const String& columnName,
  39818. const int columnId,
  39819. const int width,
  39820. const int minimumWidth,
  39821. const int maximumWidth,
  39822. const int propertyFlags,
  39823. const int insertIndex)
  39824. {
  39825. // can't have a duplicate or null ID!
  39826. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39827. jassert (width > 0);
  39828. ColumnInfo* const ci = new ColumnInfo();
  39829. ci->name = columnName;
  39830. ci->id = columnId;
  39831. ci->width = width;
  39832. ci->lastDeliberateWidth = width;
  39833. ci->minimumWidth = minimumWidth;
  39834. ci->maximumWidth = maximumWidth;
  39835. if (ci->maximumWidth < 0)
  39836. ci->maximumWidth = std::numeric_limits<int>::max();
  39837. jassert (ci->maximumWidth >= ci->minimumWidth);
  39838. ci->propertyFlags = propertyFlags;
  39839. columns.insert (insertIndex, ci);
  39840. sendColumnsChanged();
  39841. }
  39842. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39843. {
  39844. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39845. if (index >= 0)
  39846. {
  39847. columns.remove (index);
  39848. sortChanged = true;
  39849. sendColumnsChanged();
  39850. }
  39851. }
  39852. void TableHeaderComponent::removeAllColumns()
  39853. {
  39854. if (columns.size() > 0)
  39855. {
  39856. columns.clear();
  39857. sendColumnsChanged();
  39858. }
  39859. }
  39860. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39861. {
  39862. const int currentIndex = getIndexOfColumnId (columnId, false);
  39863. newIndex = visibleIndexToTotalIndex (newIndex);
  39864. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39865. {
  39866. columns.move (currentIndex, newIndex);
  39867. sendColumnsChanged();
  39868. }
  39869. }
  39870. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39871. {
  39872. const ColumnInfo* const ci = getInfoForId (columnId);
  39873. return ci != 0 ? ci->width : 0;
  39874. }
  39875. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39876. {
  39877. ColumnInfo* const ci = getInfoForId (columnId);
  39878. if (ci != 0 && ci->width != newWidth)
  39879. {
  39880. const int numColumns = getNumColumns (true);
  39881. ci->lastDeliberateWidth = ci->width
  39882. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  39883. if (stretchToFit)
  39884. {
  39885. const int index = getIndexOfColumnId (columnId, true) + 1;
  39886. if (((unsigned int) index) < (unsigned int) numColumns)
  39887. {
  39888. const int x = getColumnPosition (index).getX();
  39889. if (lastDeliberateWidth == 0)
  39890. lastDeliberateWidth = getTotalWidth();
  39891. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  39892. }
  39893. }
  39894. repaint();
  39895. columnsResized = true;
  39896. triggerAsyncUpdate();
  39897. }
  39898. }
  39899. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  39900. {
  39901. int n = 0;
  39902. for (int i = 0; i < columns.size(); ++i)
  39903. {
  39904. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  39905. {
  39906. if (columns.getUnchecked(i)->id == columnId)
  39907. return n;
  39908. ++n;
  39909. }
  39910. }
  39911. return -1;
  39912. }
  39913. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  39914. {
  39915. if (onlyCountVisibleColumns)
  39916. index = visibleIndexToTotalIndex (index);
  39917. const ColumnInfo* const ci = columns [index];
  39918. return (ci != 0) ? ci->id : 0;
  39919. }
  39920. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  39921. {
  39922. int x = 0, width = 0, n = 0;
  39923. for (int i = 0; i < columns.size(); ++i)
  39924. {
  39925. x += width;
  39926. if (columns.getUnchecked(i)->isVisible())
  39927. {
  39928. width = columns.getUnchecked(i)->width;
  39929. if (n++ == index)
  39930. break;
  39931. }
  39932. else
  39933. {
  39934. width = 0;
  39935. }
  39936. }
  39937. return Rectangle<int> (x, 0, width, getHeight());
  39938. }
  39939. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  39940. {
  39941. if (xToFind >= 0)
  39942. {
  39943. int x = 0;
  39944. for (int i = 0; i < columns.size(); ++i)
  39945. {
  39946. const ColumnInfo* const ci = columns.getUnchecked(i);
  39947. if (ci->isVisible())
  39948. {
  39949. x += ci->width;
  39950. if (xToFind < x)
  39951. return ci->id;
  39952. }
  39953. }
  39954. }
  39955. return 0;
  39956. }
  39957. int TableHeaderComponent::getTotalWidth() const
  39958. {
  39959. int w = 0;
  39960. for (int i = columns.size(); --i >= 0;)
  39961. if (columns.getUnchecked(i)->isVisible())
  39962. w += columns.getUnchecked(i)->width;
  39963. return w;
  39964. }
  39965. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  39966. {
  39967. stretchToFit = shouldStretchToFit;
  39968. lastDeliberateWidth = getTotalWidth();
  39969. resized();
  39970. }
  39971. bool TableHeaderComponent::isStretchToFitActive() const
  39972. {
  39973. return stretchToFit;
  39974. }
  39975. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  39976. {
  39977. if (stretchToFit && getWidth() > 0
  39978. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  39979. {
  39980. lastDeliberateWidth = targetTotalWidth;
  39981. resizeColumnsToFit (0, targetTotalWidth);
  39982. }
  39983. }
  39984. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  39985. {
  39986. targetTotalWidth = jmax (targetTotalWidth, 0);
  39987. StretchableObjectResizer sor;
  39988. int i;
  39989. for (i = firstColumnIndex; i < columns.size(); ++i)
  39990. {
  39991. ColumnInfo* const ci = columns.getUnchecked(i);
  39992. if (ci->isVisible())
  39993. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  39994. }
  39995. sor.resizeToFit (targetTotalWidth);
  39996. int visIndex = 0;
  39997. for (i = firstColumnIndex; i < columns.size(); ++i)
  39998. {
  39999. ColumnInfo* const ci = columns.getUnchecked(i);
  40000. if (ci->isVisible())
  40001. {
  40002. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40003. (int) floor (sor.getItemSize (visIndex++)));
  40004. if (newWidth != ci->width)
  40005. {
  40006. ci->width = newWidth;
  40007. repaint();
  40008. columnsResized = true;
  40009. triggerAsyncUpdate();
  40010. }
  40011. }
  40012. }
  40013. }
  40014. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40015. {
  40016. ColumnInfo* const ci = getInfoForId (columnId);
  40017. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40018. {
  40019. if (shouldBeVisible)
  40020. ci->propertyFlags |= visible;
  40021. else
  40022. ci->propertyFlags &= ~visible;
  40023. sendColumnsChanged();
  40024. resized();
  40025. }
  40026. }
  40027. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40028. {
  40029. const ColumnInfo* const ci = getInfoForId (columnId);
  40030. return ci != 0 && ci->isVisible();
  40031. }
  40032. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40033. {
  40034. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40035. {
  40036. for (int i = columns.size(); --i >= 0;)
  40037. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40038. ColumnInfo* const ci = getInfoForId (columnId);
  40039. if (ci != 0)
  40040. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40041. reSortTable();
  40042. }
  40043. }
  40044. int TableHeaderComponent::getSortColumnId() const
  40045. {
  40046. for (int i = columns.size(); --i >= 0;)
  40047. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40048. return columns.getUnchecked(i)->id;
  40049. return 0;
  40050. }
  40051. bool TableHeaderComponent::isSortedForwards() const
  40052. {
  40053. for (int i = columns.size(); --i >= 0;)
  40054. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40055. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40056. return true;
  40057. }
  40058. void TableHeaderComponent::reSortTable()
  40059. {
  40060. sortChanged = true;
  40061. repaint();
  40062. triggerAsyncUpdate();
  40063. }
  40064. const String TableHeaderComponent::toString() const
  40065. {
  40066. String s;
  40067. XmlElement doc ("TABLELAYOUT");
  40068. doc.setAttribute ("sortedCol", getSortColumnId());
  40069. doc.setAttribute ("sortForwards", isSortedForwards());
  40070. for (int i = 0; i < columns.size(); ++i)
  40071. {
  40072. const ColumnInfo* const ci = columns.getUnchecked (i);
  40073. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40074. e->setAttribute ("id", ci->id);
  40075. e->setAttribute ("visible", ci->isVisible());
  40076. e->setAttribute ("width", ci->width);
  40077. }
  40078. return doc.createDocument (String::empty, true, false);
  40079. }
  40080. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40081. {
  40082. XmlDocument doc (storedVersion);
  40083. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40084. int index = 0;
  40085. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40086. {
  40087. forEachXmlChildElement (*storedXml, col)
  40088. {
  40089. const int tabId = col->getIntAttribute ("id");
  40090. ColumnInfo* const ci = getInfoForId (tabId);
  40091. if (ci != 0)
  40092. {
  40093. columns.move (columns.indexOf (ci), index);
  40094. ci->width = col->getIntAttribute ("width");
  40095. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40096. }
  40097. ++index;
  40098. }
  40099. columnsResized = true;
  40100. sendColumnsChanged();
  40101. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40102. storedXml->getBoolAttribute ("sortForwards", true));
  40103. }
  40104. }
  40105. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40106. {
  40107. listeners.addIfNotAlreadyThere (newListener);
  40108. }
  40109. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40110. {
  40111. listeners.removeValue (listenerToRemove);
  40112. }
  40113. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40114. {
  40115. const ColumnInfo* const ci = getInfoForId (columnId);
  40116. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40117. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40118. }
  40119. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40120. {
  40121. for (int i = 0; i < columns.size(); ++i)
  40122. {
  40123. const ColumnInfo* const ci = columns.getUnchecked(i);
  40124. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40125. menu.addItem (ci->id, ci->name,
  40126. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40127. isColumnVisible (ci->id));
  40128. }
  40129. }
  40130. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40131. {
  40132. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40133. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40134. }
  40135. void TableHeaderComponent::paint (Graphics& g)
  40136. {
  40137. LookAndFeel& lf = getLookAndFeel();
  40138. lf.drawTableHeaderBackground (g, *this);
  40139. const Rectangle<int> clip (g.getClipBounds());
  40140. int x = 0;
  40141. for (int i = 0; i < columns.size(); ++i)
  40142. {
  40143. const ColumnInfo* const ci = columns.getUnchecked(i);
  40144. if (ci->isVisible())
  40145. {
  40146. if (x + ci->width > clip.getX()
  40147. && (ci->id != columnIdBeingDragged
  40148. || dragOverlayComp == 0
  40149. || ! dragOverlayComp->isVisible()))
  40150. {
  40151. g.saveState();
  40152. g.setOrigin (x, 0);
  40153. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40154. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40155. ci->id == columnIdUnderMouse,
  40156. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40157. ci->propertyFlags);
  40158. g.restoreState();
  40159. }
  40160. x += ci->width;
  40161. if (x >= clip.getRight())
  40162. break;
  40163. }
  40164. }
  40165. }
  40166. void TableHeaderComponent::resized()
  40167. {
  40168. }
  40169. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40170. {
  40171. updateColumnUnderMouse (e.x, e.y);
  40172. }
  40173. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40174. {
  40175. updateColumnUnderMouse (e.x, e.y);
  40176. }
  40177. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40178. {
  40179. updateColumnUnderMouse (e.x, e.y);
  40180. }
  40181. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40182. {
  40183. repaint();
  40184. columnIdBeingResized = 0;
  40185. columnIdBeingDragged = 0;
  40186. if (columnIdUnderMouse != 0)
  40187. {
  40188. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40189. if (e.mods.isPopupMenu())
  40190. columnClicked (columnIdUnderMouse, e.mods);
  40191. }
  40192. if (menuActive && e.mods.isPopupMenu())
  40193. showColumnChooserMenu (columnIdUnderMouse);
  40194. }
  40195. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40196. {
  40197. if (columnIdBeingResized == 0
  40198. && columnIdBeingDragged == 0
  40199. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40200. {
  40201. dragOverlayComp = 0;
  40202. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40203. if (columnIdBeingResized != 0)
  40204. {
  40205. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40206. initialColumnWidth = ci->width;
  40207. }
  40208. else
  40209. {
  40210. beginDrag (e);
  40211. }
  40212. }
  40213. if (columnIdBeingResized != 0)
  40214. {
  40215. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40216. if (ci != 0)
  40217. {
  40218. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40219. initialColumnWidth + e.getDistanceFromDragStartX());
  40220. if (stretchToFit)
  40221. {
  40222. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40223. int minWidthOnRight = 0;
  40224. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40225. if (columns.getUnchecked (i)->isVisible())
  40226. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40227. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40228. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40229. }
  40230. setColumnWidth (columnIdBeingResized, w);
  40231. }
  40232. }
  40233. else if (columnIdBeingDragged != 0)
  40234. {
  40235. if (e.y >= -50 && e.y < getHeight() + 50)
  40236. {
  40237. if (dragOverlayComp != 0)
  40238. {
  40239. dragOverlayComp->setVisible (true);
  40240. dragOverlayComp->setBounds (jlimit (0,
  40241. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40242. e.x - draggingColumnOffset),
  40243. 0,
  40244. dragOverlayComp->getWidth(),
  40245. getHeight());
  40246. for (int i = columns.size(); --i >= 0;)
  40247. {
  40248. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40249. int newIndex = currentIndex;
  40250. if (newIndex > 0)
  40251. {
  40252. // if the previous column isn't draggable, we can't move our column
  40253. // past it, because that'd change the undraggable column's position..
  40254. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40255. if ((previous->propertyFlags & draggable) != 0)
  40256. {
  40257. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40258. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40259. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40260. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40261. {
  40262. --newIndex;
  40263. }
  40264. }
  40265. }
  40266. if (newIndex < columns.size() - 1)
  40267. {
  40268. // if the next column isn't draggable, we can't move our column
  40269. // past it, because that'd change the undraggable column's position..
  40270. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40271. if ((nextCol->propertyFlags & draggable) != 0)
  40272. {
  40273. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40274. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40275. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40276. > abs (dragOverlayComp->getRight() - rightOfNext))
  40277. {
  40278. ++newIndex;
  40279. }
  40280. }
  40281. }
  40282. if (newIndex != currentIndex)
  40283. moveColumn (columnIdBeingDragged, newIndex);
  40284. else
  40285. break;
  40286. }
  40287. }
  40288. }
  40289. else
  40290. {
  40291. endDrag (draggingColumnOriginalIndex);
  40292. }
  40293. }
  40294. }
  40295. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40296. {
  40297. if (columnIdBeingDragged == 0)
  40298. {
  40299. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40300. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40301. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40302. {
  40303. columnIdBeingDragged = 0;
  40304. }
  40305. else
  40306. {
  40307. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40308. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40309. const int temp = columnIdBeingDragged;
  40310. columnIdBeingDragged = 0;
  40311. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40312. columnIdBeingDragged = temp;
  40313. dragOverlayComp->setBounds (columnRect);
  40314. for (int i = listeners.size(); --i >= 0;)
  40315. {
  40316. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40317. i = jmin (i, listeners.size() - 1);
  40318. }
  40319. }
  40320. }
  40321. }
  40322. void TableHeaderComponent::endDrag (const int finalIndex)
  40323. {
  40324. if (columnIdBeingDragged != 0)
  40325. {
  40326. moveColumn (columnIdBeingDragged, finalIndex);
  40327. columnIdBeingDragged = 0;
  40328. repaint();
  40329. for (int i = listeners.size(); --i >= 0;)
  40330. {
  40331. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40332. i = jmin (i, listeners.size() - 1);
  40333. }
  40334. }
  40335. }
  40336. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40337. {
  40338. mouseDrag (e);
  40339. for (int i = columns.size(); --i >= 0;)
  40340. if (columns.getUnchecked (i)->isVisible())
  40341. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40342. columnIdBeingResized = 0;
  40343. repaint();
  40344. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40345. updateColumnUnderMouse (e.x, e.y);
  40346. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40347. columnClicked (columnIdUnderMouse, e.mods);
  40348. dragOverlayComp = 0;
  40349. }
  40350. const MouseCursor TableHeaderComponent::getMouseCursor()
  40351. {
  40352. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40353. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40354. return Component::getMouseCursor();
  40355. }
  40356. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40357. {
  40358. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40359. }
  40360. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40361. {
  40362. for (int i = columns.size(); --i >= 0;)
  40363. if (columns.getUnchecked(i)->id == id)
  40364. return columns.getUnchecked(i);
  40365. return 0;
  40366. }
  40367. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40368. {
  40369. int n = 0;
  40370. for (int i = 0; i < columns.size(); ++i)
  40371. {
  40372. if (columns.getUnchecked(i)->isVisible())
  40373. {
  40374. if (n == visibleIndex)
  40375. return i;
  40376. ++n;
  40377. }
  40378. }
  40379. return -1;
  40380. }
  40381. void TableHeaderComponent::sendColumnsChanged()
  40382. {
  40383. if (stretchToFit && lastDeliberateWidth > 0)
  40384. resizeAllColumnsToFit (lastDeliberateWidth);
  40385. repaint();
  40386. columnsChanged = true;
  40387. triggerAsyncUpdate();
  40388. }
  40389. void TableHeaderComponent::handleAsyncUpdate()
  40390. {
  40391. const bool changed = columnsChanged || sortChanged;
  40392. const bool sized = columnsResized || changed;
  40393. const bool sorted = sortChanged;
  40394. columnsChanged = false;
  40395. columnsResized = false;
  40396. sortChanged = false;
  40397. if (sorted)
  40398. {
  40399. for (int i = listeners.size(); --i >= 0;)
  40400. {
  40401. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40402. i = jmin (i, listeners.size() - 1);
  40403. }
  40404. }
  40405. if (changed)
  40406. {
  40407. for (int i = listeners.size(); --i >= 0;)
  40408. {
  40409. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40410. i = jmin (i, listeners.size() - 1);
  40411. }
  40412. }
  40413. if (sized)
  40414. {
  40415. for (int i = listeners.size(); --i >= 0;)
  40416. {
  40417. listeners.getUnchecked(i)->tableColumnsResized (this);
  40418. i = jmin (i, listeners.size() - 1);
  40419. }
  40420. }
  40421. }
  40422. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40423. {
  40424. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40425. {
  40426. const int draggableDistance = 3;
  40427. int x = 0;
  40428. for (int i = 0; i < columns.size(); ++i)
  40429. {
  40430. const ColumnInfo* const ci = columns.getUnchecked(i);
  40431. if (ci->isVisible())
  40432. {
  40433. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40434. && (ci->propertyFlags & resizable) != 0)
  40435. return ci->id;
  40436. x += ci->width;
  40437. }
  40438. }
  40439. }
  40440. return 0;
  40441. }
  40442. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40443. {
  40444. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40445. ? getColumnIdAtX (x) : 0;
  40446. if (newCol != columnIdUnderMouse)
  40447. {
  40448. columnIdUnderMouse = newCol;
  40449. repaint();
  40450. }
  40451. }
  40452. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40453. {
  40454. PopupMenu m;
  40455. addMenuItems (m, columnIdClicked);
  40456. if (m.getNumItems() > 0)
  40457. {
  40458. m.setLookAndFeel (&getLookAndFeel());
  40459. const int result = m.show();
  40460. if (result != 0)
  40461. reactToMenuItem (result, columnIdClicked);
  40462. }
  40463. }
  40464. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40465. {
  40466. }
  40467. END_JUCE_NAMESPACE
  40468. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40469. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40470. BEGIN_JUCE_NAMESPACE
  40471. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40472. class TableListRowComp : public Component,
  40473. public TooltipClient
  40474. {
  40475. public:
  40476. TableListRowComp (TableListBox& owner_)
  40477. : owner (owner_),
  40478. row (-1),
  40479. isSelected (false)
  40480. {
  40481. }
  40482. ~TableListRowComp()
  40483. {
  40484. deleteAllChildren();
  40485. }
  40486. void paint (Graphics& g)
  40487. {
  40488. TableListBoxModel* const model = owner.getModel();
  40489. if (model != 0)
  40490. {
  40491. const TableHeaderComponent* const header = owner.getHeader();
  40492. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40493. const int numColumns = header->getNumColumns (true);
  40494. for (int i = 0; i < numColumns; ++i)
  40495. {
  40496. if (! columnsWithComponents [i])
  40497. {
  40498. const int columnId = header->getColumnIdOfIndex (i, true);
  40499. Rectangle<int> columnRect (header->getColumnPosition (i));
  40500. columnRect.setSize (columnRect.getWidth(), getHeight());
  40501. g.saveState();
  40502. g.reduceClipRegion (columnRect);
  40503. g.setOrigin (columnRect.getX(), 0);
  40504. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40505. g.restoreState();
  40506. }
  40507. }
  40508. }
  40509. }
  40510. void update (const int newRow, const bool isNowSelected)
  40511. {
  40512. if (newRow != row || isNowSelected != isSelected)
  40513. {
  40514. row = newRow;
  40515. isSelected = isNowSelected;
  40516. repaint();
  40517. }
  40518. if (row < owner.getNumRows())
  40519. {
  40520. jassert (row >= 0);
  40521. const var::identifier tagPropertyName ("_tableLastUseNum");
  40522. const int newTag = Random::getSystemRandom().nextInt();
  40523. const TableHeaderComponent* const header = owner.getHeader();
  40524. const int numColumns = header->getNumColumns (true);
  40525. int i;
  40526. columnsWithComponents.clear();
  40527. if (owner.getModel() != 0)
  40528. {
  40529. for (i = 0; i < numColumns; ++i)
  40530. {
  40531. const int columnId = header->getColumnIdOfIndex (i, true);
  40532. Component* const newComp
  40533. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40534. findChildComponentForColumn (columnId));
  40535. if (newComp != 0)
  40536. {
  40537. addAndMakeVisible (newComp);
  40538. newComp->getProperties().set (tagPropertyName, newTag);
  40539. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40540. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40541. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40542. columnsWithComponents.setBit (i);
  40543. }
  40544. }
  40545. }
  40546. for (i = getNumChildComponents(); --i >= 0;)
  40547. {
  40548. Component* const c = getChildComponent (i);
  40549. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40550. delete c;
  40551. }
  40552. }
  40553. else
  40554. {
  40555. columnsWithComponents.clear();
  40556. deleteAllChildren();
  40557. }
  40558. }
  40559. void resized()
  40560. {
  40561. for (int i = getNumChildComponents(); --i >= 0;)
  40562. {
  40563. Component* const c = getChildComponent (i);
  40564. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40565. if (columnId != 0)
  40566. {
  40567. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40568. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40569. }
  40570. }
  40571. }
  40572. void mouseDown (const MouseEvent& e)
  40573. {
  40574. isDragging = false;
  40575. selectRowOnMouseUp = false;
  40576. if (isEnabled())
  40577. {
  40578. if (! isSelected)
  40579. {
  40580. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40581. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40582. if (columnId != 0 && owner.getModel() != 0)
  40583. owner.getModel()->cellClicked (row, columnId, e);
  40584. }
  40585. else
  40586. {
  40587. selectRowOnMouseUp = true;
  40588. }
  40589. }
  40590. }
  40591. void mouseDrag (const MouseEvent& e)
  40592. {
  40593. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40594. {
  40595. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40596. if (selectedRows.size() > 0)
  40597. {
  40598. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40599. if (dragDescription.isNotEmpty())
  40600. {
  40601. isDragging = true;
  40602. owner.startDragAndDrop (e, dragDescription);
  40603. }
  40604. }
  40605. }
  40606. }
  40607. void mouseUp (const MouseEvent& e)
  40608. {
  40609. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40610. {
  40611. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40612. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40613. if (columnId != 0 && owner.getModel() != 0)
  40614. owner.getModel()->cellClicked (row, columnId, e);
  40615. }
  40616. }
  40617. void mouseDoubleClick (const MouseEvent& e)
  40618. {
  40619. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40620. if (columnId != 0 && owner.getModel() != 0)
  40621. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40622. }
  40623. const String getTooltip()
  40624. {
  40625. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40626. if (columnId != 0 && owner.getModel() != 0)
  40627. return owner.getModel()->getCellTooltip (row, columnId);
  40628. return String::empty;
  40629. }
  40630. juce_UseDebuggingNewOperator
  40631. private:
  40632. TableListBox& owner;
  40633. int row;
  40634. bool isSelected, isDragging, selectRowOnMouseUp;
  40635. BigInteger columnsWithComponents;
  40636. Component* findChildComponentForColumn (const int columnId) const
  40637. {
  40638. for (int i = getNumChildComponents(); --i >= 0;)
  40639. {
  40640. Component* const c = getChildComponent (i);
  40641. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40642. return c;
  40643. }
  40644. return 0;
  40645. }
  40646. TableListRowComp (const TableListRowComp&);
  40647. TableListRowComp& operator= (const TableListRowComp&);
  40648. };
  40649. class TableListBoxHeader : public TableHeaderComponent
  40650. {
  40651. public:
  40652. TableListBoxHeader (TableListBox& owner_)
  40653. : owner (owner_)
  40654. {
  40655. }
  40656. ~TableListBoxHeader()
  40657. {
  40658. }
  40659. void addMenuItems (PopupMenu& menu, int columnIdClicked)
  40660. {
  40661. if (owner.isAutoSizeMenuOptionShown())
  40662. {
  40663. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40664. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40665. menu.addSeparator();
  40666. }
  40667. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40668. }
  40669. void reactToMenuItem (int menuReturnId, int columnIdClicked)
  40670. {
  40671. if (menuReturnId == 0xf836743)
  40672. {
  40673. owner.autoSizeColumn (columnIdClicked);
  40674. }
  40675. else if (menuReturnId == 0xf836744)
  40676. {
  40677. owner.autoSizeAllColumns();
  40678. }
  40679. else
  40680. {
  40681. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40682. }
  40683. }
  40684. juce_UseDebuggingNewOperator
  40685. private:
  40686. TableListBox& owner;
  40687. TableListBoxHeader (const TableListBoxHeader&);
  40688. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40689. };
  40690. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40691. : ListBox (name, 0),
  40692. model (model_),
  40693. autoSizeOptionsShown (true)
  40694. {
  40695. ListBox::model = this;
  40696. header = new TableListBoxHeader (*this);
  40697. header->setSize (100, 28);
  40698. header->addListener (this);
  40699. setHeaderComponent (header);
  40700. }
  40701. TableListBox::~TableListBox()
  40702. {
  40703. deleteAllChildren();
  40704. }
  40705. void TableListBox::setModel (TableListBoxModel* const newModel)
  40706. {
  40707. if (model != newModel)
  40708. {
  40709. model = newModel;
  40710. updateContent();
  40711. }
  40712. }
  40713. int TableListBox::getHeaderHeight() const
  40714. {
  40715. return header->getHeight();
  40716. }
  40717. void TableListBox::setHeaderHeight (const int newHeight)
  40718. {
  40719. header->setSize (header->getWidth(), newHeight);
  40720. resized();
  40721. }
  40722. void TableListBox::autoSizeColumn (const int columnId)
  40723. {
  40724. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40725. if (width > 0)
  40726. header->setColumnWidth (columnId, width);
  40727. }
  40728. void TableListBox::autoSizeAllColumns()
  40729. {
  40730. for (int i = 0; i < header->getNumColumns (true); ++i)
  40731. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40732. }
  40733. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40734. {
  40735. autoSizeOptionsShown = shouldBeShown;
  40736. }
  40737. bool TableListBox::isAutoSizeMenuOptionShown() const
  40738. {
  40739. return autoSizeOptionsShown;
  40740. }
  40741. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40742. const int rowNumber,
  40743. const bool relativeToComponentTopLeft) const
  40744. {
  40745. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40746. if (relativeToComponentTopLeft)
  40747. headerCell.translate (header->getX(), 0);
  40748. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40749. return Rectangle<int> (headerCell.getX(), row.getY(),
  40750. headerCell.getWidth(), row.getHeight());
  40751. }
  40752. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40753. {
  40754. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40755. if (scrollbar != 0)
  40756. {
  40757. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40758. double x = scrollbar->getCurrentRangeStart();
  40759. const double w = scrollbar->getCurrentRangeSize();
  40760. if (pos.getX() < x)
  40761. x = pos.getX();
  40762. else if (pos.getRight() > x + w)
  40763. x += jmax (0.0, pos.getRight() - (x + w));
  40764. scrollbar->setCurrentRangeStart (x);
  40765. }
  40766. }
  40767. int TableListBox::getNumRows()
  40768. {
  40769. return model != 0 ? model->getNumRows() : 0;
  40770. }
  40771. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40772. {
  40773. }
  40774. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40775. {
  40776. if (existingComponentToUpdate == 0)
  40777. existingComponentToUpdate = new TableListRowComp (*this);
  40778. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40779. return existingComponentToUpdate;
  40780. }
  40781. void TableListBox::selectedRowsChanged (int row)
  40782. {
  40783. if (model != 0)
  40784. model->selectedRowsChanged (row);
  40785. }
  40786. void TableListBox::deleteKeyPressed (int row)
  40787. {
  40788. if (model != 0)
  40789. model->deleteKeyPressed (row);
  40790. }
  40791. void TableListBox::returnKeyPressed (int row)
  40792. {
  40793. if (model != 0)
  40794. model->returnKeyPressed (row);
  40795. }
  40796. void TableListBox::backgroundClicked()
  40797. {
  40798. if (model != 0)
  40799. model->backgroundClicked();
  40800. }
  40801. void TableListBox::listWasScrolled()
  40802. {
  40803. if (model != 0)
  40804. model->listWasScrolled();
  40805. }
  40806. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40807. {
  40808. setMinimumContentWidth (header->getTotalWidth());
  40809. repaint();
  40810. updateColumnComponents();
  40811. }
  40812. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40813. {
  40814. setMinimumContentWidth (header->getTotalWidth());
  40815. repaint();
  40816. updateColumnComponents();
  40817. }
  40818. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40819. {
  40820. if (model != 0)
  40821. model->sortOrderChanged (header->getSortColumnId(),
  40822. header->isSortedForwards());
  40823. }
  40824. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40825. {
  40826. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40827. repaint();
  40828. }
  40829. void TableListBox::resized()
  40830. {
  40831. ListBox::resized();
  40832. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40833. setMinimumContentWidth (header->getTotalWidth());
  40834. }
  40835. void TableListBox::updateColumnComponents() const
  40836. {
  40837. const int firstRow = getRowContainingPosition (0, 0);
  40838. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40839. {
  40840. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40841. if (rowComp != 0)
  40842. rowComp->resized();
  40843. }
  40844. }
  40845. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40846. {
  40847. }
  40848. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40849. {
  40850. }
  40851. void TableListBoxModel::backgroundClicked()
  40852. {
  40853. }
  40854. void TableListBoxModel::sortOrderChanged (int, const bool)
  40855. {
  40856. }
  40857. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40858. {
  40859. return 0;
  40860. }
  40861. void TableListBoxModel::selectedRowsChanged (int)
  40862. {
  40863. }
  40864. void TableListBoxModel::deleteKeyPressed (int)
  40865. {
  40866. }
  40867. void TableListBoxModel::returnKeyPressed (int)
  40868. {
  40869. }
  40870. void TableListBoxModel::listWasScrolled()
  40871. {
  40872. }
  40873. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40874. {
  40875. return String::empty;
  40876. }
  40877. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40878. {
  40879. return String::empty;
  40880. }
  40881. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  40882. {
  40883. (void) existingComponentToUpdate;
  40884. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  40885. return 0;
  40886. }
  40887. END_JUCE_NAMESPACE
  40888. /*** End of inlined file: juce_TableListBox.cpp ***/
  40889. /*** Start of inlined file: juce_TextEditor.cpp ***/
  40890. BEGIN_JUCE_NAMESPACE
  40891. // a word or space that can't be broken down any further
  40892. struct TextAtom
  40893. {
  40894. String atomText;
  40895. float width;
  40896. uint16 numChars;
  40897. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  40898. bool isNewLine() const { return atomText[0] == '\r' || atomText[0] == '\n'; }
  40899. const String getText (const tchar passwordCharacter) const
  40900. {
  40901. if (passwordCharacter == 0)
  40902. return atomText;
  40903. else
  40904. return String::repeatedString (String::charToString (passwordCharacter),
  40905. atomText.length());
  40906. }
  40907. const String getTrimmedText (const tchar passwordCharacter) const
  40908. {
  40909. if (passwordCharacter == 0)
  40910. return atomText.substring (0, numChars);
  40911. else if (isNewLine())
  40912. return String::empty;
  40913. else
  40914. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  40915. }
  40916. };
  40917. // a run of text with a single font and colour
  40918. class UniformTextSection
  40919. {
  40920. public:
  40921. UniformTextSection (const String& text,
  40922. const Font& font_,
  40923. const Colour& colour_,
  40924. const tchar passwordCharacter)
  40925. : font (font_),
  40926. colour (colour_)
  40927. {
  40928. initialiseAtoms (text, passwordCharacter);
  40929. }
  40930. UniformTextSection (const UniformTextSection& other)
  40931. : font (other.font),
  40932. colour (other.colour)
  40933. {
  40934. atoms.ensureStorageAllocated (other.atoms.size());
  40935. for (int i = 0; i < other.atoms.size(); ++i)
  40936. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  40937. }
  40938. ~UniformTextSection()
  40939. {
  40940. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  40941. }
  40942. void clear()
  40943. {
  40944. for (int i = atoms.size(); --i >= 0;)
  40945. delete getAtom(i);
  40946. atoms.clear();
  40947. }
  40948. int getNumAtoms() const
  40949. {
  40950. return atoms.size();
  40951. }
  40952. TextAtom* getAtom (const int index) const
  40953. {
  40954. return (TextAtom*) atoms.getUnchecked (index);
  40955. }
  40956. void append (const UniformTextSection& other, const tchar passwordCharacter)
  40957. {
  40958. if (other.atoms.size() > 0)
  40959. {
  40960. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  40961. int i = 0;
  40962. if (lastAtom != 0)
  40963. {
  40964. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  40965. {
  40966. TextAtom* const first = other.getAtom(0);
  40967. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  40968. {
  40969. lastAtom->atomText += first->atomText;
  40970. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  40971. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  40972. delete first;
  40973. ++i;
  40974. }
  40975. }
  40976. }
  40977. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  40978. while (i < other.atoms.size())
  40979. {
  40980. atoms.add (other.getAtom(i));
  40981. ++i;
  40982. }
  40983. }
  40984. }
  40985. UniformTextSection* split (const int indexToBreakAt,
  40986. const tchar passwordCharacter)
  40987. {
  40988. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  40989. font, colour,
  40990. passwordCharacter);
  40991. int index = 0;
  40992. for (int i = 0; i < atoms.size(); ++i)
  40993. {
  40994. TextAtom* const atom = getAtom(i);
  40995. const int nextIndex = index + atom->numChars;
  40996. if (index == indexToBreakAt)
  40997. {
  40998. int j;
  40999. for (j = i; j < atoms.size(); ++j)
  41000. section2->atoms.add (getAtom (j));
  41001. for (j = atoms.size(); --j >= i;)
  41002. atoms.remove (j);
  41003. break;
  41004. }
  41005. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41006. {
  41007. TextAtom* const secondAtom = new TextAtom();
  41008. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41009. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41010. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41011. section2->atoms.add (secondAtom);
  41012. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41013. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41014. atom->numChars = (uint16) (indexToBreakAt - index);
  41015. int j;
  41016. for (j = i + 1; j < atoms.size(); ++j)
  41017. section2->atoms.add (getAtom (j));
  41018. for (j = atoms.size(); --j > i;)
  41019. atoms.remove (j);
  41020. break;
  41021. }
  41022. index = nextIndex;
  41023. }
  41024. return section2;
  41025. }
  41026. void appendAllText (String::Concatenator& concatenator) const
  41027. {
  41028. for (int i = 0; i < atoms.size(); ++i)
  41029. concatenator.append (getAtom(i)->atomText);
  41030. }
  41031. void appendSubstring (String::Concatenator& concatenator,
  41032. const Range<int>& range) const
  41033. {
  41034. int index = 0;
  41035. for (int i = 0; i < atoms.size(); ++i)
  41036. {
  41037. const TextAtom* const atom = getAtom (i);
  41038. const int nextIndex = index + atom->numChars;
  41039. if (range.getStart() < nextIndex)
  41040. {
  41041. if (range.getEnd() <= index)
  41042. break;
  41043. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41044. if (! r.isEmpty())
  41045. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41046. }
  41047. index = nextIndex;
  41048. }
  41049. }
  41050. int getTotalLength() const
  41051. {
  41052. int total = 0;
  41053. for (int i = atoms.size(); --i >= 0;)
  41054. total += getAtom(i)->numChars;
  41055. return total;
  41056. }
  41057. void setFont (const Font& newFont,
  41058. const tchar passwordCharacter)
  41059. {
  41060. if (font != newFont)
  41061. {
  41062. font = newFont;
  41063. for (int i = atoms.size(); --i >= 0;)
  41064. {
  41065. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41066. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41067. }
  41068. }
  41069. }
  41070. juce_UseDebuggingNewOperator
  41071. Font font;
  41072. Colour colour;
  41073. private:
  41074. VoidArray atoms;
  41075. void initialiseAtoms (const String& textToParse,
  41076. const tchar passwordCharacter)
  41077. {
  41078. int i = 0;
  41079. const int len = textToParse.length();
  41080. const tchar* const text = (const tchar*) textToParse;
  41081. while (i < len)
  41082. {
  41083. int start = i;
  41084. // create a whitespace atom unless it starts with non-ws
  41085. if (CharacterFunctions::isWhitespace (text[i])
  41086. && text[i] != '\r'
  41087. && text[i] != '\n')
  41088. {
  41089. while (i < len
  41090. && CharacterFunctions::isWhitespace (text[i])
  41091. && text[i] != '\r'
  41092. && text[i] != '\n')
  41093. {
  41094. ++i;
  41095. }
  41096. }
  41097. else
  41098. {
  41099. if (text[i] == '\r')
  41100. {
  41101. ++i;
  41102. if ((i < len) && (text[i] == '\n'))
  41103. {
  41104. ++start;
  41105. ++i;
  41106. }
  41107. }
  41108. else if (text[i] == '\n')
  41109. {
  41110. ++i;
  41111. }
  41112. else
  41113. {
  41114. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41115. ++i;
  41116. }
  41117. }
  41118. TextAtom* const atom = new TextAtom();
  41119. atom->atomText = String (text + start, i - start);
  41120. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41121. atom->numChars = (uint16) (i - start);
  41122. atoms.add (atom);
  41123. }
  41124. }
  41125. UniformTextSection& operator= (const UniformTextSection& other);
  41126. };
  41127. class TextEditorIterator
  41128. {
  41129. public:
  41130. TextEditorIterator (const VoidArray& sections_,
  41131. const float wordWrapWidth_,
  41132. const tchar passwordCharacter_)
  41133. : indexInText (0),
  41134. lineY (0),
  41135. lineHeight (0),
  41136. maxDescent (0),
  41137. atomX (0),
  41138. atomRight (0),
  41139. atom (0),
  41140. currentSection (0),
  41141. sections (sections_),
  41142. sectionIndex (0),
  41143. atomIndex (0),
  41144. wordWrapWidth (wordWrapWidth_),
  41145. passwordCharacter (passwordCharacter_)
  41146. {
  41147. jassert (wordWrapWidth_ > 0);
  41148. if (sections.size() > 0)
  41149. {
  41150. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41151. if (currentSection != 0)
  41152. beginNewLine();
  41153. }
  41154. }
  41155. TextEditorIterator (const TextEditorIterator& other)
  41156. : indexInText (other.indexInText),
  41157. lineY (other.lineY),
  41158. lineHeight (other.lineHeight),
  41159. maxDescent (other.maxDescent),
  41160. atomX (other.atomX),
  41161. atomRight (other.atomRight),
  41162. atom (other.atom),
  41163. currentSection (other.currentSection),
  41164. sections (other.sections),
  41165. sectionIndex (other.sectionIndex),
  41166. atomIndex (other.atomIndex),
  41167. wordWrapWidth (other.wordWrapWidth),
  41168. passwordCharacter (other.passwordCharacter),
  41169. tempAtom (other.tempAtom)
  41170. {
  41171. }
  41172. ~TextEditorIterator()
  41173. {
  41174. }
  41175. bool next()
  41176. {
  41177. if (atom == &tempAtom)
  41178. {
  41179. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41180. if (numRemaining > 0)
  41181. {
  41182. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41183. atomX = 0;
  41184. if (tempAtom.numChars > 0)
  41185. lineY += lineHeight;
  41186. indexInText += tempAtom.numChars;
  41187. GlyphArrangement g;
  41188. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41189. int split;
  41190. for (split = 0; split < g.getNumGlyphs(); ++split)
  41191. if (shouldWrap (g.getGlyph (split).getRight()))
  41192. break;
  41193. if (split > 0 && split <= numRemaining)
  41194. {
  41195. tempAtom.numChars = (uint16) split;
  41196. tempAtom.width = g.getGlyph (split - 1).getRight();
  41197. atomRight = atomX + tempAtom.width;
  41198. return true;
  41199. }
  41200. }
  41201. }
  41202. bool forceNewLine = false;
  41203. if (sectionIndex >= sections.size())
  41204. {
  41205. moveToEndOfLastAtom();
  41206. return false;
  41207. }
  41208. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41209. {
  41210. if (atomIndex >= currentSection->getNumAtoms())
  41211. {
  41212. if (++sectionIndex >= sections.size())
  41213. {
  41214. moveToEndOfLastAtom();
  41215. return false;
  41216. }
  41217. atomIndex = 0;
  41218. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41219. }
  41220. else
  41221. {
  41222. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41223. if (! lastAtom->isWhitespace())
  41224. {
  41225. // handle the case where the last atom in a section is actually part of the same
  41226. // word as the first atom of the next section...
  41227. float right = atomRight + lastAtom->width;
  41228. float lineHeight2 = lineHeight;
  41229. float maxDescent2 = maxDescent;
  41230. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41231. {
  41232. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41233. if (s->getNumAtoms() == 0)
  41234. break;
  41235. const TextAtom* const nextAtom = s->getAtom (0);
  41236. if (nextAtom->isWhitespace())
  41237. break;
  41238. right += nextAtom->width;
  41239. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41240. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41241. if (shouldWrap (right))
  41242. {
  41243. lineHeight = lineHeight2;
  41244. maxDescent = maxDescent2;
  41245. forceNewLine = true;
  41246. break;
  41247. }
  41248. if (s->getNumAtoms() > 1)
  41249. break;
  41250. }
  41251. }
  41252. }
  41253. }
  41254. if (atom != 0)
  41255. {
  41256. atomX = atomRight;
  41257. indexInText += atom->numChars;
  41258. if (atom->isNewLine())
  41259. beginNewLine();
  41260. }
  41261. atom = currentSection->getAtom (atomIndex);
  41262. atomRight = atomX + atom->width;
  41263. ++atomIndex;
  41264. if (shouldWrap (atomRight) || forceNewLine)
  41265. {
  41266. if (atom->isWhitespace())
  41267. {
  41268. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41269. atomRight = jmin (atomRight, wordWrapWidth);
  41270. }
  41271. else
  41272. {
  41273. atomRight = atom->width;
  41274. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41275. {
  41276. tempAtom = *atom;
  41277. tempAtom.width = 0;
  41278. tempAtom.numChars = 0;
  41279. atom = &tempAtom;
  41280. if (atomX > 0)
  41281. beginNewLine();
  41282. return next();
  41283. }
  41284. beginNewLine();
  41285. return true;
  41286. }
  41287. }
  41288. return true;
  41289. }
  41290. void beginNewLine()
  41291. {
  41292. atomX = 0;
  41293. lineY += lineHeight;
  41294. int tempSectionIndex = sectionIndex;
  41295. int tempAtomIndex = atomIndex;
  41296. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41297. lineHeight = section->font.getHeight();
  41298. maxDescent = section->font.getDescent();
  41299. float x = (atom != 0) ? atom->width : 0;
  41300. while (! shouldWrap (x))
  41301. {
  41302. if (tempSectionIndex >= sections.size())
  41303. break;
  41304. bool checkSize = false;
  41305. if (tempAtomIndex >= section->getNumAtoms())
  41306. {
  41307. if (++tempSectionIndex >= sections.size())
  41308. break;
  41309. tempAtomIndex = 0;
  41310. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41311. checkSize = true;
  41312. }
  41313. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41314. if (nextAtom == 0)
  41315. break;
  41316. x += nextAtom->width;
  41317. if (shouldWrap (x) || nextAtom->isNewLine())
  41318. break;
  41319. if (checkSize)
  41320. {
  41321. lineHeight = jmax (lineHeight, section->font.getHeight());
  41322. maxDescent = jmax (maxDescent, section->font.getDescent());
  41323. }
  41324. ++tempAtomIndex;
  41325. }
  41326. }
  41327. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41328. {
  41329. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41330. {
  41331. if (lastSection != currentSection)
  41332. {
  41333. lastSection = currentSection;
  41334. g.setColour (currentSection->colour);
  41335. g.setFont (currentSection->font);
  41336. }
  41337. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41338. GlyphArrangement ga;
  41339. ga.addLineOfText (currentSection->font,
  41340. atom->getTrimmedText (passwordCharacter),
  41341. atomX,
  41342. (float) roundToInt (lineY + lineHeight - maxDescent));
  41343. ga.draw (g);
  41344. }
  41345. }
  41346. void drawSelection (Graphics& g,
  41347. const Range<int>& selection) const
  41348. {
  41349. const int startX = roundToInt (indexToX (selection.getStart()));
  41350. const int endX = roundToInt (indexToX (selection.getEnd()));
  41351. const int y = roundToInt (lineY);
  41352. const int nextY = roundToInt (lineY + lineHeight);
  41353. g.fillRect (startX, y, endX - startX, nextY - y);
  41354. }
  41355. void drawSelectedText (Graphics& g,
  41356. const Range<int>& selection,
  41357. const Colour& selectedTextColour) const
  41358. {
  41359. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41360. {
  41361. GlyphArrangement ga;
  41362. ga.addLineOfText (currentSection->font,
  41363. atom->getTrimmedText (passwordCharacter),
  41364. atomX,
  41365. (float) roundToInt (lineY + lineHeight - maxDescent));
  41366. if (selection.getEnd() < indexInText + atom->numChars)
  41367. {
  41368. GlyphArrangement ga2 (ga);
  41369. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41370. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41371. g.setColour (currentSection->colour);
  41372. ga2.draw (g);
  41373. }
  41374. if (selection.getStart() > indexInText)
  41375. {
  41376. GlyphArrangement ga2 (ga);
  41377. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41378. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41379. g.setColour (currentSection->colour);
  41380. ga2.draw (g);
  41381. }
  41382. g.setColour (selectedTextColour);
  41383. ga.draw (g);
  41384. }
  41385. }
  41386. float indexToX (const int indexToFind) const
  41387. {
  41388. if (indexToFind <= indexInText)
  41389. return atomX;
  41390. if (indexToFind >= indexInText + atom->numChars)
  41391. return atomRight;
  41392. GlyphArrangement g;
  41393. g.addLineOfText (currentSection->font,
  41394. atom->getText (passwordCharacter),
  41395. atomX, 0.0f);
  41396. if (indexToFind - indexInText >= g.getNumGlyphs())
  41397. return atomRight;
  41398. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41399. }
  41400. int xToIndex (const float xToFind) const
  41401. {
  41402. if (xToFind <= atomX || atom->isNewLine())
  41403. return indexInText;
  41404. if (xToFind >= atomRight)
  41405. return indexInText + atom->numChars;
  41406. GlyphArrangement g;
  41407. g.addLineOfText (currentSection->font,
  41408. atom->getText (passwordCharacter),
  41409. atomX, 0.0f);
  41410. int j;
  41411. for (j = 0; j < g.getNumGlyphs(); ++j)
  41412. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41413. break;
  41414. return indexInText + j;
  41415. }
  41416. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41417. {
  41418. while (next())
  41419. {
  41420. if (indexInText + atom->numChars > index)
  41421. {
  41422. cx = indexToX (index);
  41423. cy = lineY;
  41424. lineHeight_ = lineHeight;
  41425. return true;
  41426. }
  41427. }
  41428. cx = atomX;
  41429. cy = lineY;
  41430. lineHeight_ = lineHeight;
  41431. return false;
  41432. }
  41433. juce_UseDebuggingNewOperator
  41434. int indexInText;
  41435. float lineY, lineHeight, maxDescent;
  41436. float atomX, atomRight;
  41437. const TextAtom* atom;
  41438. const UniformTextSection* currentSection;
  41439. private:
  41440. const VoidArray& sections;
  41441. int sectionIndex, atomIndex;
  41442. const float wordWrapWidth;
  41443. const tchar passwordCharacter;
  41444. TextAtom tempAtom;
  41445. TextEditorIterator& operator= (const TextEditorIterator&);
  41446. void moveToEndOfLastAtom()
  41447. {
  41448. if (atom != 0)
  41449. {
  41450. atomX = atomRight;
  41451. if (atom->isNewLine())
  41452. {
  41453. atomX = 0.0f;
  41454. lineY += lineHeight;
  41455. }
  41456. }
  41457. }
  41458. bool shouldWrap (const float x) const
  41459. {
  41460. return (x - 0.0001f) >= wordWrapWidth;
  41461. }
  41462. };
  41463. class TextEditorInsertAction : public UndoableAction
  41464. {
  41465. TextEditor& owner;
  41466. const String text;
  41467. const int insertIndex, oldCaretPos, newCaretPos;
  41468. const Font font;
  41469. const Colour colour;
  41470. TextEditorInsertAction (const TextEditorInsertAction&);
  41471. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41472. public:
  41473. TextEditorInsertAction (TextEditor& owner_,
  41474. const String& text_,
  41475. const int insertIndex_,
  41476. const Font& font_,
  41477. const Colour& colour_,
  41478. const int oldCaretPos_,
  41479. const int newCaretPos_)
  41480. : owner (owner_),
  41481. text (text_),
  41482. insertIndex (insertIndex_),
  41483. oldCaretPos (oldCaretPos_),
  41484. newCaretPos (newCaretPos_),
  41485. font (font_),
  41486. colour (colour_)
  41487. {
  41488. }
  41489. ~TextEditorInsertAction()
  41490. {
  41491. }
  41492. bool perform()
  41493. {
  41494. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41495. return true;
  41496. }
  41497. bool undo()
  41498. {
  41499. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41500. return true;
  41501. }
  41502. int getSizeInUnits()
  41503. {
  41504. return text.length() + 16;
  41505. }
  41506. };
  41507. class TextEditorRemoveAction : public UndoableAction
  41508. {
  41509. TextEditor& owner;
  41510. const Range<int> range;
  41511. const int oldCaretPos, newCaretPos;
  41512. VoidArray removedSections;
  41513. TextEditorRemoveAction (const TextEditorRemoveAction&);
  41514. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  41515. public:
  41516. TextEditorRemoveAction (TextEditor& owner_,
  41517. const Range<int> range_,
  41518. const int oldCaretPos_,
  41519. const int newCaretPos_,
  41520. const VoidArray& removedSections_)
  41521. : owner (owner_),
  41522. range (range_),
  41523. oldCaretPos (oldCaretPos_),
  41524. newCaretPos (newCaretPos_),
  41525. removedSections (removedSections_)
  41526. {
  41527. }
  41528. ~TextEditorRemoveAction()
  41529. {
  41530. for (int i = removedSections.size(); --i >= 0;)
  41531. {
  41532. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41533. section->clear();
  41534. delete section;
  41535. }
  41536. }
  41537. bool perform()
  41538. {
  41539. owner.remove (range, 0, newCaretPos);
  41540. return true;
  41541. }
  41542. bool undo()
  41543. {
  41544. owner.reinsert (range.getStart(), removedSections);
  41545. owner.moveCursorTo (oldCaretPos, false);
  41546. return true;
  41547. }
  41548. int getSizeInUnits()
  41549. {
  41550. int n = 0;
  41551. for (int i = removedSections.size(); --i >= 0;)
  41552. {
  41553. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41554. n += section->getTotalLength();
  41555. }
  41556. return n + 16;
  41557. }
  41558. };
  41559. class TextHolderComponent : public Component,
  41560. public Timer,
  41561. public Value::Listener
  41562. {
  41563. TextEditor& owner;
  41564. TextHolderComponent (const TextHolderComponent&);
  41565. TextHolderComponent& operator= (const TextHolderComponent&);
  41566. public:
  41567. TextHolderComponent (TextEditor& owner_)
  41568. : owner (owner_)
  41569. {
  41570. setWantsKeyboardFocus (false);
  41571. setInterceptsMouseClicks (false, true);
  41572. owner.getTextValue().addListener (this);
  41573. }
  41574. ~TextHolderComponent()
  41575. {
  41576. owner.getTextValue().removeListener (this);
  41577. }
  41578. void paint (Graphics& g)
  41579. {
  41580. owner.drawContent (g);
  41581. }
  41582. void timerCallback()
  41583. {
  41584. owner.timerCallbackInt();
  41585. }
  41586. const MouseCursor getMouseCursor()
  41587. {
  41588. return owner.getMouseCursor();
  41589. }
  41590. void valueChanged (Value&)
  41591. {
  41592. owner.textWasChangedByValue();
  41593. }
  41594. };
  41595. class TextEditorViewport : public Viewport
  41596. {
  41597. TextEditor* const owner;
  41598. float lastWordWrapWidth;
  41599. TextEditorViewport (const TextEditorViewport&);
  41600. TextEditorViewport& operator= (const TextEditorViewport&);
  41601. public:
  41602. TextEditorViewport (TextEditor* const owner_)
  41603. : owner (owner_),
  41604. lastWordWrapWidth (0)
  41605. {
  41606. }
  41607. ~TextEditorViewport()
  41608. {
  41609. }
  41610. void visibleAreaChanged (int, int, int, int)
  41611. {
  41612. const float wordWrapWidth = owner->getWordWrapWidth();
  41613. if (wordWrapWidth != lastWordWrapWidth)
  41614. {
  41615. lastWordWrapWidth = wordWrapWidth;
  41616. owner->updateTextHolderSize();
  41617. }
  41618. }
  41619. };
  41620. namespace TextEditorDefs
  41621. {
  41622. const int flashSpeedIntervalMs = 380;
  41623. const int textChangeMessageId = 0x10003001;
  41624. const int returnKeyMessageId = 0x10003002;
  41625. const int escapeKeyMessageId = 0x10003003;
  41626. const int focusLossMessageId = 0x10003004;
  41627. const int maxActionsPerTransaction = 100;
  41628. }
  41629. TextEditor::TextEditor (const String& name,
  41630. const tchar passwordCharacter_)
  41631. : Component (name),
  41632. borderSize (1, 1, 1, 3),
  41633. readOnly (false),
  41634. multiline (false),
  41635. wordWrap (false),
  41636. returnKeyStartsNewLine (false),
  41637. caretVisible (true),
  41638. popupMenuEnabled (true),
  41639. selectAllTextWhenFocused (false),
  41640. scrollbarVisible (true),
  41641. wasFocused (false),
  41642. caretFlashState (true),
  41643. keepCursorOnScreen (true),
  41644. tabKeyUsed (false),
  41645. menuActive (false),
  41646. valueTextNeedsUpdating (false),
  41647. cursorX (0),
  41648. cursorY (0),
  41649. cursorHeight (0),
  41650. maxTextLength (0),
  41651. leftIndent (4),
  41652. topIndent (4),
  41653. lastTransactionTime (0),
  41654. currentFont (14.0f),
  41655. totalNumChars (0),
  41656. caretPosition (0),
  41657. passwordCharacter (passwordCharacter_),
  41658. dragType (notDragging)
  41659. {
  41660. setOpaque (true);
  41661. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41662. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41663. viewport->setWantsKeyboardFocus (false);
  41664. viewport->setScrollBarsShown (false, false);
  41665. setMouseCursor (MouseCursor::IBeamCursor);
  41666. setWantsKeyboardFocus (true);
  41667. }
  41668. TextEditor::~TextEditor()
  41669. {
  41670. textValue.referTo (Value());
  41671. clearInternal (0);
  41672. viewport = 0;
  41673. textHolder = 0;
  41674. }
  41675. void TextEditor::newTransaction()
  41676. {
  41677. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41678. undoManager.beginNewTransaction();
  41679. }
  41680. void TextEditor::doUndoRedo (const bool isRedo)
  41681. {
  41682. if (! isReadOnly())
  41683. {
  41684. if (isRedo ? undoManager.redo()
  41685. : undoManager.undo())
  41686. {
  41687. scrollToMakeSureCursorIsVisible();
  41688. repaint();
  41689. textChanged();
  41690. }
  41691. }
  41692. }
  41693. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41694. const bool shouldWordWrap)
  41695. {
  41696. multiline = shouldBeMultiLine;
  41697. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41698. setScrollbarsShown (scrollbarVisible);
  41699. viewport->setViewPosition (0, 0);
  41700. resized();
  41701. scrollToMakeSureCursorIsVisible();
  41702. }
  41703. bool TextEditor::isMultiLine() const
  41704. {
  41705. return multiline;
  41706. }
  41707. void TextEditor::setScrollbarsShown (bool enabled)
  41708. {
  41709. scrollbarVisible = enabled;
  41710. enabled = enabled && isMultiLine();
  41711. viewport->setScrollBarsShown (enabled, enabled);
  41712. }
  41713. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41714. {
  41715. readOnly = shouldBeReadOnly;
  41716. enablementChanged();
  41717. }
  41718. bool TextEditor::isReadOnly() const
  41719. {
  41720. return readOnly || ! isEnabled();
  41721. }
  41722. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41723. {
  41724. returnKeyStartsNewLine = shouldStartNewLine;
  41725. }
  41726. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41727. {
  41728. tabKeyUsed = shouldTabKeyBeUsed;
  41729. }
  41730. void TextEditor::setPopupMenuEnabled (const bool b)
  41731. {
  41732. popupMenuEnabled = b;
  41733. }
  41734. void TextEditor::setSelectAllWhenFocused (const bool b)
  41735. {
  41736. selectAllTextWhenFocused = b;
  41737. }
  41738. const Font TextEditor::getFont() const
  41739. {
  41740. return currentFont;
  41741. }
  41742. void TextEditor::setFont (const Font& newFont)
  41743. {
  41744. currentFont = newFont;
  41745. scrollToMakeSureCursorIsVisible();
  41746. }
  41747. void TextEditor::applyFontToAllText (const Font& newFont)
  41748. {
  41749. currentFont = newFont;
  41750. const Colour overallColour (findColour (textColourId));
  41751. for (int i = sections.size(); --i >= 0;)
  41752. {
  41753. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  41754. uts->setFont (newFont, passwordCharacter);
  41755. uts->colour = overallColour;
  41756. }
  41757. coalesceSimilarSections();
  41758. updateTextHolderSize();
  41759. scrollToMakeSureCursorIsVisible();
  41760. repaint();
  41761. }
  41762. void TextEditor::colourChanged()
  41763. {
  41764. setOpaque (findColour (backgroundColourId).isOpaque());
  41765. repaint();
  41766. }
  41767. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41768. {
  41769. caretVisible = shouldCaretBeVisible;
  41770. if (shouldCaretBeVisible)
  41771. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41772. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41773. : MouseCursor::NormalCursor);
  41774. }
  41775. void TextEditor::setInputRestrictions (const int maxLen,
  41776. const String& chars)
  41777. {
  41778. maxTextLength = jmax (0, maxLen);
  41779. allowedCharacters = chars;
  41780. }
  41781. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41782. {
  41783. textToShowWhenEmpty = text;
  41784. colourForTextWhenEmpty = colourToUse;
  41785. }
  41786. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  41787. {
  41788. if (passwordCharacter != newPasswordCharacter)
  41789. {
  41790. passwordCharacter = newPasswordCharacter;
  41791. resized();
  41792. repaint();
  41793. }
  41794. }
  41795. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41796. {
  41797. viewport->setScrollBarThickness (newThicknessPixels);
  41798. }
  41799. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41800. {
  41801. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41802. }
  41803. void TextEditor::clear()
  41804. {
  41805. clearInternal (0);
  41806. updateTextHolderSize();
  41807. undoManager.clearUndoHistory();
  41808. }
  41809. void TextEditor::setText (const String& newText,
  41810. const bool sendTextChangeMessage)
  41811. {
  41812. const int newLength = newText.length();
  41813. if (newLength != getTotalNumChars() || getText() != newText)
  41814. {
  41815. const int oldCursorPos = caretPosition;
  41816. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41817. clearInternal (0);
  41818. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41819. // if you're adding text with line-feeds to a single-line text editor, it
  41820. // ain't gonna look right!
  41821. jassert (multiline || ! newText.containsAnyOf ("\r\n"));
  41822. if (cursorWasAtEnd && ! isMultiLine())
  41823. moveCursorTo (getTotalNumChars(), false);
  41824. else
  41825. moveCursorTo (oldCursorPos, false);
  41826. if (sendTextChangeMessage)
  41827. textChanged();
  41828. repaint();
  41829. }
  41830. updateTextHolderSize();
  41831. scrollToMakeSureCursorIsVisible();
  41832. undoManager.clearUndoHistory();
  41833. }
  41834. Value& TextEditor::getTextValue()
  41835. {
  41836. if (valueTextNeedsUpdating)
  41837. {
  41838. valueTextNeedsUpdating = false;
  41839. textValue = getText();
  41840. }
  41841. return textValue;
  41842. }
  41843. void TextEditor::textWasChangedByValue()
  41844. {
  41845. if (textValue.getValueSource().getReferenceCount() > 1)
  41846. setText (textValue.getValue());
  41847. }
  41848. void TextEditor::textChanged()
  41849. {
  41850. updateTextHolderSize();
  41851. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41852. if (textValue.getValueSource().getReferenceCount() > 1)
  41853. {
  41854. valueTextNeedsUpdating = false;
  41855. textValue = getText();
  41856. }
  41857. }
  41858. void TextEditor::returnPressed()
  41859. {
  41860. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41861. }
  41862. void TextEditor::escapePressed()
  41863. {
  41864. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41865. }
  41866. void TextEditor::addListener (TextEditorListener* const newListener)
  41867. {
  41868. listeners.add (newListener);
  41869. }
  41870. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41871. {
  41872. listeners.remove (listenerToRemove);
  41873. }
  41874. void TextEditor::timerCallbackInt()
  41875. {
  41876. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41877. if (caretFlashState != newState)
  41878. {
  41879. caretFlashState = newState;
  41880. if (caretFlashState)
  41881. wasFocused = true;
  41882. if (caretVisible
  41883. && hasKeyboardFocus (false)
  41884. && ! isReadOnly())
  41885. {
  41886. repaintCaret();
  41887. }
  41888. }
  41889. const unsigned int now = Time::getApproximateMillisecondCounter();
  41890. if (now > lastTransactionTime + 200)
  41891. newTransaction();
  41892. }
  41893. void TextEditor::repaintCaret()
  41894. {
  41895. if (! findColour (caretColourId).isTransparent())
  41896. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  41897. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  41898. 4,
  41899. roundToInt (cursorHeight) + 2);
  41900. }
  41901. void TextEditor::repaintText (const Range<int>& range)
  41902. {
  41903. if (! range.isEmpty())
  41904. {
  41905. float x = 0, y = 0, lh = currentFont.getHeight();
  41906. const float wordWrapWidth = getWordWrapWidth();
  41907. if (wordWrapWidth > 0)
  41908. {
  41909. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  41910. i.getCharPosition (range.getStart(), x, y, lh);
  41911. const int y1 = (int) y;
  41912. int y2;
  41913. if (range.getEnd() >= getTotalNumChars())
  41914. {
  41915. y2 = textHolder->getHeight();
  41916. }
  41917. else
  41918. {
  41919. i.getCharPosition (range.getEnd(), x, y, lh);
  41920. y2 = (int) (y + lh * 2.0f);
  41921. }
  41922. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  41923. }
  41924. }
  41925. }
  41926. void TextEditor::moveCaret (int newCaretPos)
  41927. {
  41928. if (newCaretPos < 0)
  41929. newCaretPos = 0;
  41930. else if (newCaretPos > getTotalNumChars())
  41931. newCaretPos = getTotalNumChars();
  41932. if (newCaretPos != getCaretPosition())
  41933. {
  41934. repaintCaret();
  41935. caretFlashState = true;
  41936. caretPosition = newCaretPos;
  41937. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41938. scrollToMakeSureCursorIsVisible();
  41939. repaintCaret();
  41940. }
  41941. }
  41942. void TextEditor::setCaretPosition (const int newIndex)
  41943. {
  41944. moveCursorTo (newIndex, false);
  41945. }
  41946. int TextEditor::getCaretPosition() const
  41947. {
  41948. return caretPosition;
  41949. }
  41950. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  41951. const int desiredCaretY)
  41952. {
  41953. updateCaretPosition();
  41954. int vx = roundToInt (cursorX) - desiredCaretX;
  41955. int vy = roundToInt (cursorY) - desiredCaretY;
  41956. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  41957. {
  41958. vx += desiredCaretX - proportionOfWidth (0.2f);
  41959. }
  41960. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41961. {
  41962. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41963. }
  41964. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  41965. if (! isMultiLine())
  41966. {
  41967. vy = viewport->getViewPositionY();
  41968. }
  41969. else
  41970. {
  41971. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  41972. const int curH = roundToInt (cursorHeight);
  41973. if (desiredCaretY < 0)
  41974. {
  41975. vy = jmax (0, desiredCaretY + vy);
  41976. }
  41977. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  41978. {
  41979. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  41980. }
  41981. }
  41982. viewport->setViewPosition (vx, vy);
  41983. }
  41984. const Rectangle<int> TextEditor::getCaretRectangle()
  41985. {
  41986. updateCaretPosition();
  41987. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  41988. roundToInt (cursorY) - viewport->getY(),
  41989. 1, roundToInt (cursorHeight));
  41990. }
  41991. float TextEditor::getWordWrapWidth() const
  41992. {
  41993. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  41994. : 1.0e10f;
  41995. }
  41996. void TextEditor::updateTextHolderSize()
  41997. {
  41998. const float wordWrapWidth = getWordWrapWidth();
  41999. if (wordWrapWidth > 0)
  42000. {
  42001. float maxWidth = 0.0f;
  42002. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42003. while (i.next())
  42004. maxWidth = jmax (maxWidth, i.atomRight);
  42005. const int w = leftIndent + roundToInt (maxWidth);
  42006. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42007. currentFont.getHeight()));
  42008. textHolder->setSize (w + 1, h + 1);
  42009. }
  42010. }
  42011. int TextEditor::getTextWidth() const
  42012. {
  42013. return textHolder->getWidth();
  42014. }
  42015. int TextEditor::getTextHeight() const
  42016. {
  42017. return textHolder->getHeight();
  42018. }
  42019. void TextEditor::setIndents (const int newLeftIndent,
  42020. const int newTopIndent)
  42021. {
  42022. leftIndent = newLeftIndent;
  42023. topIndent = newTopIndent;
  42024. }
  42025. void TextEditor::setBorder (const BorderSize& border)
  42026. {
  42027. borderSize = border;
  42028. resized();
  42029. }
  42030. const BorderSize TextEditor::getBorder() const
  42031. {
  42032. return borderSize;
  42033. }
  42034. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42035. {
  42036. keepCursorOnScreen = shouldScrollToShowCursor;
  42037. }
  42038. void TextEditor::updateCaretPosition()
  42039. {
  42040. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42041. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42042. }
  42043. void TextEditor::scrollToMakeSureCursorIsVisible()
  42044. {
  42045. updateCaretPosition();
  42046. if (keepCursorOnScreen)
  42047. {
  42048. int x = viewport->getViewPositionX();
  42049. int y = viewport->getViewPositionY();
  42050. const int relativeCursorX = roundToInt (cursorX) - x;
  42051. const int relativeCursorY = roundToInt (cursorY) - y;
  42052. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42053. {
  42054. x += relativeCursorX - proportionOfWidth (0.2f);
  42055. }
  42056. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42057. {
  42058. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42059. }
  42060. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42061. if (! isMultiLine())
  42062. {
  42063. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42064. }
  42065. else
  42066. {
  42067. const int curH = roundToInt (cursorHeight);
  42068. if (relativeCursorY < 0)
  42069. {
  42070. y = jmax (0, relativeCursorY + y);
  42071. }
  42072. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42073. {
  42074. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42075. }
  42076. }
  42077. viewport->setViewPosition (x, y);
  42078. }
  42079. }
  42080. void TextEditor::moveCursorTo (const int newPosition,
  42081. const bool isSelecting)
  42082. {
  42083. if (isSelecting)
  42084. {
  42085. moveCaret (newPosition);
  42086. const Range<int> oldSelection (selection);
  42087. if (dragType == notDragging)
  42088. {
  42089. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42090. dragType = draggingSelectionStart;
  42091. else
  42092. dragType = draggingSelectionEnd;
  42093. }
  42094. if (dragType == draggingSelectionStart)
  42095. {
  42096. if (getCaretPosition() >= selection.getEnd())
  42097. dragType = draggingSelectionEnd;
  42098. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42099. }
  42100. else
  42101. {
  42102. if (getCaretPosition() < selection.getStart())
  42103. dragType = draggingSelectionStart;
  42104. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42105. }
  42106. repaintText (selection.getUnionWith (oldSelection));
  42107. }
  42108. else
  42109. {
  42110. dragType = notDragging;
  42111. repaintText (selection);
  42112. moveCaret (newPosition);
  42113. selection = Range<int>::emptyRange (getCaretPosition());
  42114. }
  42115. }
  42116. int TextEditor::getTextIndexAt (const int x,
  42117. const int y)
  42118. {
  42119. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42120. (float) (y + viewport->getViewPositionY() - topIndent));
  42121. }
  42122. void TextEditor::insertTextAtCaret (const String& newText_)
  42123. {
  42124. String newText (newText_);
  42125. if (allowedCharacters.isNotEmpty())
  42126. newText = newText.retainCharacters (allowedCharacters);
  42127. if ((! returnKeyStartsNewLine) && newText == "\n")
  42128. {
  42129. returnPressed();
  42130. return;
  42131. }
  42132. if (! isMultiLine())
  42133. newText = newText.replaceCharacters ("\r\n", " ");
  42134. else
  42135. newText = newText.replace ("\r\n", "\n");
  42136. const int newCaretPos = selection.getStart() + newText.length();
  42137. const int insertIndex = selection.getStart();
  42138. remove (selection, getUndoManager(),
  42139. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42140. if (maxTextLength > 0)
  42141. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42142. if (newText.isNotEmpty())
  42143. insert (newText,
  42144. insertIndex,
  42145. currentFont,
  42146. findColour (textColourId),
  42147. getUndoManager(),
  42148. newCaretPos);
  42149. textChanged();
  42150. }
  42151. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42152. {
  42153. moveCursorTo (newSelection.getStart(), false);
  42154. moveCursorTo (newSelection.getEnd(), true);
  42155. }
  42156. void TextEditor::copy()
  42157. {
  42158. if (passwordCharacter == 0)
  42159. {
  42160. const String selection (getHighlightedText());
  42161. if (selection.isNotEmpty())
  42162. SystemClipboard::copyTextToClipboard (selection);
  42163. }
  42164. }
  42165. void TextEditor::paste()
  42166. {
  42167. if (! isReadOnly())
  42168. {
  42169. const String clip (SystemClipboard::getTextFromClipboard());
  42170. if (clip.isNotEmpty())
  42171. insertTextAtCaret (clip);
  42172. }
  42173. }
  42174. void TextEditor::cut()
  42175. {
  42176. if (! isReadOnly())
  42177. {
  42178. moveCaret (selection.getEnd());
  42179. insertTextAtCaret (String::empty);
  42180. }
  42181. }
  42182. void TextEditor::drawContent (Graphics& g)
  42183. {
  42184. const float wordWrapWidth = getWordWrapWidth();
  42185. if (wordWrapWidth > 0)
  42186. {
  42187. g.setOrigin (leftIndent, topIndent);
  42188. const Rectangle<int> clip (g.getClipBounds());
  42189. Colour selectedTextColour;
  42190. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42191. while (i.lineY + 200.0 < clip.getY() && i.next())
  42192. {}
  42193. if (! selection.isEmpty())
  42194. {
  42195. g.setColour (findColour (highlightColourId)
  42196. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42197. selectedTextColour = findColour (highlightedTextColourId);
  42198. TextEditorIterator i2 (i);
  42199. while (i2.next() && i2.lineY < clip.getBottom())
  42200. {
  42201. if (i2.lineY + i2.lineHeight >= clip.getY()
  42202. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42203. {
  42204. i2.drawSelection (g, selection);
  42205. }
  42206. }
  42207. }
  42208. const UniformTextSection* lastSection = 0;
  42209. while (i.next() && i.lineY < clip.getBottom())
  42210. {
  42211. if (i.lineY + i.lineHeight >= clip.getY())
  42212. {
  42213. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42214. {
  42215. i.drawSelectedText (g, selection, selectedTextColour);
  42216. lastSection = 0;
  42217. }
  42218. else
  42219. {
  42220. i.draw (g, lastSection);
  42221. }
  42222. }
  42223. }
  42224. }
  42225. }
  42226. void TextEditor::paint (Graphics& g)
  42227. {
  42228. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42229. }
  42230. void TextEditor::paintOverChildren (Graphics& g)
  42231. {
  42232. if (caretFlashState
  42233. && hasKeyboardFocus (false)
  42234. && caretVisible
  42235. && ! isReadOnly())
  42236. {
  42237. g.setColour (findColour (caretColourId));
  42238. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42239. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42240. 2.0f, cursorHeight);
  42241. }
  42242. if (textToShowWhenEmpty.isNotEmpty()
  42243. && (! hasKeyboardFocus (false))
  42244. && getTotalNumChars() == 0)
  42245. {
  42246. g.setColour (colourForTextWhenEmpty);
  42247. g.setFont (getFont());
  42248. if (isMultiLine())
  42249. {
  42250. g.drawText (textToShowWhenEmpty,
  42251. 0, 0, getWidth(), getHeight(),
  42252. Justification::centred, true);
  42253. }
  42254. else
  42255. {
  42256. g.drawText (textToShowWhenEmpty,
  42257. leftIndent, topIndent,
  42258. viewport->getWidth() - leftIndent,
  42259. viewport->getHeight() - topIndent,
  42260. Justification::centredLeft, true);
  42261. }
  42262. }
  42263. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42264. }
  42265. void TextEditor::mouseDown (const MouseEvent& e)
  42266. {
  42267. beginDragAutoRepeat (100);
  42268. newTransaction();
  42269. if (wasFocused || ! selectAllTextWhenFocused)
  42270. {
  42271. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42272. {
  42273. moveCursorTo (getTextIndexAt (e.x, e.y),
  42274. e.mods.isShiftDown());
  42275. }
  42276. else
  42277. {
  42278. PopupMenu m;
  42279. m.setLookAndFeel (&getLookAndFeel());
  42280. addPopupMenuItems (m, &e);
  42281. menuActive = true;
  42282. const int result = m.show();
  42283. menuActive = false;
  42284. if (result != 0)
  42285. performPopupMenuAction (result);
  42286. }
  42287. }
  42288. }
  42289. void TextEditor::mouseDrag (const MouseEvent& e)
  42290. {
  42291. if (wasFocused || ! selectAllTextWhenFocused)
  42292. {
  42293. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42294. {
  42295. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42296. }
  42297. }
  42298. }
  42299. void TextEditor::mouseUp (const MouseEvent& e)
  42300. {
  42301. newTransaction();
  42302. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42303. if (wasFocused || ! selectAllTextWhenFocused)
  42304. {
  42305. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42306. {
  42307. moveCaret (getTextIndexAt (e.x, e.y));
  42308. }
  42309. }
  42310. wasFocused = true;
  42311. }
  42312. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42313. {
  42314. int tokenEnd = getTextIndexAt (e.x, e.y);
  42315. int tokenStart = tokenEnd;
  42316. if (e.getNumberOfClicks() > 3)
  42317. {
  42318. tokenStart = 0;
  42319. tokenEnd = getTotalNumChars();
  42320. }
  42321. else
  42322. {
  42323. const String t (getText());
  42324. const int totalLength = getTotalNumChars();
  42325. while (tokenEnd < totalLength)
  42326. {
  42327. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42328. ++tokenEnd;
  42329. else
  42330. break;
  42331. }
  42332. tokenStart = tokenEnd;
  42333. while (tokenStart > 0)
  42334. {
  42335. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42336. --tokenStart;
  42337. else
  42338. break;
  42339. }
  42340. if (e.getNumberOfClicks() > 2)
  42341. {
  42342. while (tokenEnd < totalLength)
  42343. {
  42344. if (t [tokenEnd] != '\r' && t [tokenEnd] != '\n')
  42345. ++tokenEnd;
  42346. else
  42347. break;
  42348. }
  42349. while (tokenStart > 0)
  42350. {
  42351. if (t [tokenStart - 1] != '\r' && t [tokenStart - 1] != '\n')
  42352. --tokenStart;
  42353. else
  42354. break;
  42355. }
  42356. }
  42357. }
  42358. moveCursorTo (tokenEnd, false);
  42359. moveCursorTo (tokenStart, true);
  42360. }
  42361. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42362. {
  42363. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42364. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42365. }
  42366. bool TextEditor::keyPressed (const KeyPress& key)
  42367. {
  42368. if (isReadOnly() && key != KeyPress ('c', ModifierKeys::commandModifier, 0))
  42369. return false;
  42370. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42371. if (key.isKeyCode (KeyPress::leftKey)
  42372. || key.isKeyCode (KeyPress::upKey))
  42373. {
  42374. newTransaction();
  42375. int newPos;
  42376. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42377. newPos = indexAtPosition (cursorX, cursorY - 1);
  42378. else if (moveInWholeWordSteps)
  42379. newPos = findWordBreakBefore (getCaretPosition());
  42380. else
  42381. newPos = getCaretPosition() - 1;
  42382. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42383. }
  42384. else if (key.isKeyCode (KeyPress::rightKey)
  42385. || key.isKeyCode (KeyPress::downKey))
  42386. {
  42387. newTransaction();
  42388. int newPos;
  42389. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42390. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42391. else if (moveInWholeWordSteps)
  42392. newPos = findWordBreakAfter (getCaretPosition());
  42393. else
  42394. newPos = getCaretPosition() + 1;
  42395. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42396. }
  42397. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42398. {
  42399. newTransaction();
  42400. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42401. key.getModifiers().isShiftDown());
  42402. }
  42403. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42404. {
  42405. newTransaction();
  42406. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42407. key.getModifiers().isShiftDown());
  42408. }
  42409. else if (key.isKeyCode (KeyPress::homeKey))
  42410. {
  42411. newTransaction();
  42412. if (isMultiLine() && ! moveInWholeWordSteps)
  42413. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42414. key.getModifiers().isShiftDown());
  42415. else
  42416. moveCursorTo (0, key.getModifiers().isShiftDown());
  42417. }
  42418. else if (key.isKeyCode (KeyPress::endKey))
  42419. {
  42420. newTransaction();
  42421. if (isMultiLine() && ! moveInWholeWordSteps)
  42422. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42423. key.getModifiers().isShiftDown());
  42424. else
  42425. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42426. }
  42427. else if (key.isKeyCode (KeyPress::backspaceKey))
  42428. {
  42429. if (moveInWholeWordSteps)
  42430. {
  42431. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42432. }
  42433. else
  42434. {
  42435. if (selection.isEmpty() && selection.getStart() > 0)
  42436. selection.setStart (selection.getEnd() - 1);
  42437. }
  42438. cut();
  42439. }
  42440. else if (key.isKeyCode (KeyPress::deleteKey))
  42441. {
  42442. if (key.getModifiers().isShiftDown())
  42443. copy();
  42444. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42445. selection.setEnd (selection.getStart() + 1);
  42446. cut();
  42447. }
  42448. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0)
  42449. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42450. {
  42451. newTransaction();
  42452. copy();
  42453. }
  42454. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  42455. {
  42456. newTransaction();
  42457. copy();
  42458. cut();
  42459. }
  42460. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0)
  42461. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42462. {
  42463. newTransaction();
  42464. paste();
  42465. }
  42466. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  42467. {
  42468. newTransaction();
  42469. doUndoRedo (false);
  42470. }
  42471. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0))
  42472. {
  42473. newTransaction();
  42474. doUndoRedo (true);
  42475. }
  42476. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  42477. {
  42478. newTransaction();
  42479. moveCursorTo (getTotalNumChars(), false);
  42480. moveCursorTo (0, true);
  42481. }
  42482. else if (key == KeyPress::returnKey)
  42483. {
  42484. newTransaction();
  42485. insertTextAtCaret ("\n");
  42486. }
  42487. else if (key.isKeyCode (KeyPress::escapeKey))
  42488. {
  42489. newTransaction();
  42490. moveCursorTo (getCaretPosition(), false);
  42491. escapePressed();
  42492. }
  42493. else if (key.getTextCharacter() >= ' '
  42494. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42495. {
  42496. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42497. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42498. }
  42499. else
  42500. {
  42501. return false;
  42502. }
  42503. return true;
  42504. }
  42505. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42506. {
  42507. if (! isKeyDown)
  42508. return false;
  42509. #if JUCE_WIN32
  42510. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42511. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42512. #endif
  42513. // (overridden to avoid forwarding key events to the parent)
  42514. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42515. }
  42516. const int baseMenuItemID = 0x7fff0000;
  42517. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42518. {
  42519. const bool writable = ! isReadOnly();
  42520. if (passwordCharacter == 0)
  42521. {
  42522. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42523. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42524. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42525. }
  42526. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42527. m.addSeparator();
  42528. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42529. m.addSeparator();
  42530. if (getUndoManager() != 0)
  42531. {
  42532. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42533. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42534. }
  42535. }
  42536. void TextEditor::performPopupMenuAction (const int menuItemID)
  42537. {
  42538. switch (menuItemID)
  42539. {
  42540. case baseMenuItemID + 1:
  42541. copy();
  42542. cut();
  42543. break;
  42544. case baseMenuItemID + 2:
  42545. copy();
  42546. break;
  42547. case baseMenuItemID + 3:
  42548. paste();
  42549. break;
  42550. case baseMenuItemID + 4:
  42551. cut();
  42552. break;
  42553. case baseMenuItemID + 5:
  42554. moveCursorTo (getTotalNumChars(), false);
  42555. moveCursorTo (0, true);
  42556. break;
  42557. case baseMenuItemID + 6:
  42558. doUndoRedo (false);
  42559. break;
  42560. case baseMenuItemID + 7:
  42561. doUndoRedo (true);
  42562. break;
  42563. default:
  42564. break;
  42565. }
  42566. }
  42567. void TextEditor::focusGained (FocusChangeType)
  42568. {
  42569. newTransaction();
  42570. caretFlashState = true;
  42571. if (selectAllTextWhenFocused)
  42572. {
  42573. moveCursorTo (0, false);
  42574. moveCursorTo (getTotalNumChars(), true);
  42575. }
  42576. repaint();
  42577. if (caretVisible)
  42578. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42579. ComponentPeer* const peer = getPeer();
  42580. if (peer != 0 && ! isReadOnly())
  42581. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42582. }
  42583. void TextEditor::focusLost (FocusChangeType)
  42584. {
  42585. newTransaction();
  42586. wasFocused = false;
  42587. textHolder->stopTimer();
  42588. caretFlashState = false;
  42589. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42590. repaint();
  42591. }
  42592. void TextEditor::resized()
  42593. {
  42594. viewport->setBoundsInset (borderSize);
  42595. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42596. updateTextHolderSize();
  42597. if (! isMultiLine())
  42598. {
  42599. scrollToMakeSureCursorIsVisible();
  42600. }
  42601. else
  42602. {
  42603. updateCaretPosition();
  42604. }
  42605. }
  42606. void TextEditor::handleCommandMessage (const int commandId)
  42607. {
  42608. Component::BailOutChecker checker (this);
  42609. switch (commandId)
  42610. {
  42611. case TextEditorDefs::textChangeMessageId:
  42612. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42613. break;
  42614. case TextEditorDefs::returnKeyMessageId:
  42615. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42616. break;
  42617. case TextEditorDefs::escapeKeyMessageId:
  42618. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42619. break;
  42620. case TextEditorDefs::focusLossMessageId:
  42621. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42622. break;
  42623. default:
  42624. jassertfalse
  42625. break;
  42626. }
  42627. }
  42628. void TextEditor::enablementChanged()
  42629. {
  42630. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42631. : MouseCursor::IBeamCursor);
  42632. repaint();
  42633. }
  42634. UndoManager* TextEditor::getUndoManager() throw()
  42635. {
  42636. return isReadOnly() ? &undoManager : 0;
  42637. }
  42638. void TextEditor::clearInternal (UndoManager* const um)
  42639. {
  42640. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42641. }
  42642. void TextEditor::insert (const String& text,
  42643. const int insertIndex,
  42644. const Font& font,
  42645. const Colour& colour,
  42646. UndoManager* const um,
  42647. const int caretPositionToMoveTo)
  42648. {
  42649. if (text.isNotEmpty())
  42650. {
  42651. if (um != 0)
  42652. {
  42653. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42654. newTransaction();
  42655. um->perform (new TextEditorInsertAction (*this,
  42656. text,
  42657. insertIndex,
  42658. font,
  42659. colour,
  42660. caretPosition,
  42661. caretPositionToMoveTo));
  42662. }
  42663. else
  42664. {
  42665. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42666. // a line gets moved due to word wrap
  42667. int index = 0;
  42668. int nextIndex = 0;
  42669. for (int i = 0; i < sections.size(); ++i)
  42670. {
  42671. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42672. if (insertIndex == index)
  42673. {
  42674. sections.insert (i, new UniformTextSection (text,
  42675. font, colour,
  42676. passwordCharacter));
  42677. break;
  42678. }
  42679. else if (insertIndex > index && insertIndex < nextIndex)
  42680. {
  42681. splitSection (i, insertIndex - index);
  42682. sections.insert (i + 1, new UniformTextSection (text,
  42683. font, colour,
  42684. passwordCharacter));
  42685. break;
  42686. }
  42687. index = nextIndex;
  42688. }
  42689. if (nextIndex == insertIndex)
  42690. sections.add (new UniformTextSection (text,
  42691. font, colour,
  42692. passwordCharacter));
  42693. coalesceSimilarSections();
  42694. totalNumChars = -1;
  42695. valueTextNeedsUpdating = true;
  42696. moveCursorTo (caretPositionToMoveTo, false);
  42697. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42698. }
  42699. }
  42700. }
  42701. void TextEditor::reinsert (const int insertIndex,
  42702. const VoidArray& sectionsToInsert)
  42703. {
  42704. int index = 0;
  42705. int nextIndex = 0;
  42706. for (int i = 0; i < sections.size(); ++i)
  42707. {
  42708. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42709. if (insertIndex == index)
  42710. {
  42711. for (int j = sectionsToInsert.size(); --j >= 0;)
  42712. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42713. break;
  42714. }
  42715. else if (insertIndex > index && insertIndex < nextIndex)
  42716. {
  42717. splitSection (i, insertIndex - index);
  42718. for (int j = sectionsToInsert.size(); --j >= 0;)
  42719. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42720. break;
  42721. }
  42722. index = nextIndex;
  42723. }
  42724. if (nextIndex == insertIndex)
  42725. {
  42726. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42727. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42728. }
  42729. coalesceSimilarSections();
  42730. totalNumChars = -1;
  42731. valueTextNeedsUpdating = true;
  42732. }
  42733. void TextEditor::remove (const Range<int>& range,
  42734. UndoManager* const um,
  42735. const int caretPositionToMoveTo)
  42736. {
  42737. if (! range.isEmpty())
  42738. {
  42739. int index = 0;
  42740. for (int i = 0; i < sections.size(); ++i)
  42741. {
  42742. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  42743. if (range.getStart() > index && range.getStart() < nextIndex)
  42744. {
  42745. splitSection (i, range.getStart() - index);
  42746. --i;
  42747. }
  42748. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42749. {
  42750. splitSection (i, range.getEnd() - index);
  42751. --i;
  42752. }
  42753. else
  42754. {
  42755. index = nextIndex;
  42756. if (index > range.getEnd())
  42757. break;
  42758. }
  42759. }
  42760. index = 0;
  42761. if (um != 0)
  42762. {
  42763. VoidArray removedSections;
  42764. for (int i = 0; i < sections.size(); ++i)
  42765. {
  42766. if (range.getEnd() <= range.getStart())
  42767. break;
  42768. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42769. const int nextIndex = index + section->getTotalLength();
  42770. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42771. removedSections.add (new UniformTextSection (*section));
  42772. index = nextIndex;
  42773. }
  42774. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42775. newTransaction();
  42776. um->perform (new TextEditorRemoveAction (*this,
  42777. range,
  42778. caretPosition,
  42779. caretPositionToMoveTo,
  42780. removedSections));
  42781. }
  42782. else
  42783. {
  42784. Range<int> remainingRange (range);
  42785. for (int i = 0; i < sections.size(); ++i)
  42786. {
  42787. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42788. const int nextIndex = index + section->getTotalLength();
  42789. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42790. {
  42791. sections.remove(i);
  42792. section->clear();
  42793. delete section;
  42794. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42795. if (remainingRange.isEmpty())
  42796. break;
  42797. --i;
  42798. }
  42799. else
  42800. {
  42801. index = nextIndex;
  42802. }
  42803. }
  42804. coalesceSimilarSections();
  42805. totalNumChars = -1;
  42806. valueTextNeedsUpdating = true;
  42807. moveCursorTo (caretPositionToMoveTo, false);
  42808. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42809. }
  42810. }
  42811. }
  42812. const String TextEditor::getText() const
  42813. {
  42814. String t;
  42815. t.preallocateStorage (getTotalNumChars());
  42816. String::Concatenator concatenator (t);
  42817. for (int i = 0; i < sections.size(); ++i)
  42818. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  42819. return t;
  42820. }
  42821. const String TextEditor::getTextInRange (const Range<int>& range) const
  42822. {
  42823. String t;
  42824. if (! range.isEmpty())
  42825. {
  42826. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42827. String::Concatenator concatenator (t);
  42828. int index = 0;
  42829. for (int i = 0; i < sections.size(); ++i)
  42830. {
  42831. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  42832. const int nextIndex = index + s->getTotalLength();
  42833. if (range.getStart() < nextIndex)
  42834. {
  42835. if (range.getEnd() <= index)
  42836. break;
  42837. s->appendSubstring (concatenator, range - index);
  42838. }
  42839. index = nextIndex;
  42840. }
  42841. }
  42842. return t;
  42843. }
  42844. const String TextEditor::getHighlightedText() const
  42845. {
  42846. return getTextInRange (selection);
  42847. }
  42848. int TextEditor::getTotalNumChars() const
  42849. {
  42850. if (totalNumChars < 0)
  42851. {
  42852. totalNumChars = 0;
  42853. for (int i = sections.size(); --i >= 0;)
  42854. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42855. }
  42856. return totalNumChars;
  42857. }
  42858. bool TextEditor::isEmpty() const
  42859. {
  42860. return getTotalNumChars() == 0;
  42861. }
  42862. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42863. {
  42864. const float wordWrapWidth = getWordWrapWidth();
  42865. if (wordWrapWidth > 0 && sections.size() > 0)
  42866. {
  42867. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42868. i.getCharPosition (index, cx, cy, lineHeight);
  42869. }
  42870. else
  42871. {
  42872. cx = cy = 0;
  42873. lineHeight = currentFont.getHeight();
  42874. }
  42875. }
  42876. int TextEditor::indexAtPosition (const float x, const float y)
  42877. {
  42878. const float wordWrapWidth = getWordWrapWidth();
  42879. if (wordWrapWidth > 0)
  42880. {
  42881. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42882. while (i.next())
  42883. {
  42884. if (i.lineY + i.lineHeight > y)
  42885. {
  42886. if (i.lineY > y)
  42887. return jmax (0, i.indexInText - 1);
  42888. if (i.atomX >= x)
  42889. return i.indexInText;
  42890. if (x < i.atomRight)
  42891. return i.xToIndex (x);
  42892. }
  42893. }
  42894. }
  42895. return getTotalNumChars();
  42896. }
  42897. static int getCharacterCategory (const tchar character)
  42898. {
  42899. return CharacterFunctions::isLetterOrDigit (character)
  42900. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  42901. }
  42902. int TextEditor::findWordBreakAfter (const int position) const
  42903. {
  42904. const String t (getTextInRange (Range<int> (position, position + 512)));
  42905. const int totalLength = t.length();
  42906. int i = 0;
  42907. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42908. ++i;
  42909. const int type = getCharacterCategory (t[i]);
  42910. while (i < totalLength && type == getCharacterCategory (t[i]))
  42911. ++i;
  42912. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42913. ++i;
  42914. return position + i;
  42915. }
  42916. int TextEditor::findWordBreakBefore (const int position) const
  42917. {
  42918. if (position <= 0)
  42919. return 0;
  42920. const int startOfBuffer = jmax (0, position - 512);
  42921. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  42922. int i = position - startOfBuffer;
  42923. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  42924. --i;
  42925. if (i > 0)
  42926. {
  42927. const int type = getCharacterCategory (t [i - 1]);
  42928. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  42929. --i;
  42930. }
  42931. jassert (startOfBuffer + i >= 0);
  42932. return startOfBuffer + i;
  42933. }
  42934. void TextEditor::splitSection (const int sectionIndex,
  42935. const int charToSplitAt)
  42936. {
  42937. jassert (sections[sectionIndex] != 0);
  42938. sections.insert (sectionIndex + 1,
  42939. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  42940. ->split (charToSplitAt, passwordCharacter));
  42941. }
  42942. void TextEditor::coalesceSimilarSections()
  42943. {
  42944. for (int i = 0; i < sections.size() - 1; ++i)
  42945. {
  42946. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  42947. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  42948. if (s1->font == s2->font
  42949. && s1->colour == s2->colour)
  42950. {
  42951. s1->append (*s2, passwordCharacter);
  42952. sections.remove (i + 1);
  42953. delete s2;
  42954. --i;
  42955. }
  42956. }
  42957. }
  42958. END_JUCE_NAMESPACE
  42959. /*** End of inlined file: juce_TextEditor.cpp ***/
  42960. /*** Start of inlined file: juce_Toolbar.cpp ***/
  42961. BEGIN_JUCE_NAMESPACE
  42962. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  42963. class ToolbarSpacerComp : public ToolbarItemComponent
  42964. {
  42965. public:
  42966. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  42967. : ToolbarItemComponent (itemId_, String::empty, false),
  42968. fixedSize (fixedSize_),
  42969. drawBar (drawBar_)
  42970. {
  42971. }
  42972. ~ToolbarSpacerComp()
  42973. {
  42974. }
  42975. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  42976. int& preferredSize, int& minSize, int& maxSize)
  42977. {
  42978. if (fixedSize <= 0)
  42979. {
  42980. preferredSize = toolbarThickness * 2;
  42981. minSize = 4;
  42982. maxSize = 32768;
  42983. }
  42984. else
  42985. {
  42986. maxSize = roundToInt (toolbarThickness * fixedSize);
  42987. minSize = drawBar ? maxSize : jmin (4, maxSize);
  42988. preferredSize = maxSize;
  42989. if (getEditingMode() == editableOnPalette)
  42990. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  42991. }
  42992. return true;
  42993. }
  42994. void paintButtonArea (Graphics&, int, int, bool, bool)
  42995. {
  42996. }
  42997. void contentAreaChanged (const Rectangle<int>&)
  42998. {
  42999. }
  43000. int getResizeOrder() const throw()
  43001. {
  43002. return fixedSize <= 0 ? 0 : 1;
  43003. }
  43004. void paint (Graphics& g)
  43005. {
  43006. const int w = getWidth();
  43007. const int h = getHeight();
  43008. if (drawBar)
  43009. {
  43010. g.setColour (findColour (Toolbar::separatorColourId, true));
  43011. const float thickness = 0.2f;
  43012. if (isToolbarVertical())
  43013. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43014. else
  43015. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43016. }
  43017. if (getEditingMode() != normalMode && ! drawBar)
  43018. {
  43019. g.setColour (findColour (Toolbar::separatorColourId, true));
  43020. const int indentX = jmin (2, (w - 3) / 2);
  43021. const int indentY = jmin (2, (h - 3) / 2);
  43022. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43023. if (fixedSize <= 0)
  43024. {
  43025. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43026. if (isToolbarVertical())
  43027. {
  43028. x1 = w * 0.5f;
  43029. y1 = h * 0.4f;
  43030. x2 = x1;
  43031. y2 = indentX * 2.0f;
  43032. x3 = x1;
  43033. y3 = h * 0.6f;
  43034. x4 = x1;
  43035. y4 = h - y2;
  43036. hw = w * 0.15f;
  43037. hl = w * 0.2f;
  43038. }
  43039. else
  43040. {
  43041. x1 = w * 0.4f;
  43042. y1 = h * 0.5f;
  43043. x2 = indentX * 2.0f;
  43044. y2 = y1;
  43045. x3 = w * 0.6f;
  43046. y3 = y1;
  43047. x4 = w - x2;
  43048. y4 = y1;
  43049. hw = h * 0.15f;
  43050. hl = h * 0.2f;
  43051. }
  43052. Path p;
  43053. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43054. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43055. g.fillPath (p);
  43056. }
  43057. }
  43058. }
  43059. juce_UseDebuggingNewOperator
  43060. private:
  43061. const float fixedSize;
  43062. const bool drawBar;
  43063. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43064. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43065. };
  43066. class MissingItemsComponent : public PopupMenuCustomComponent
  43067. {
  43068. public:
  43069. MissingItemsComponent (Toolbar& owner_, const int height_)
  43070. : PopupMenuCustomComponent (true),
  43071. owner (owner_),
  43072. height (height_)
  43073. {
  43074. for (int i = owner_.items.size(); --i >= 0;)
  43075. {
  43076. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43077. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43078. {
  43079. oldIndexes.insert (0, i);
  43080. addAndMakeVisible (tc, 0);
  43081. }
  43082. }
  43083. layout (400);
  43084. }
  43085. ~MissingItemsComponent()
  43086. {
  43087. // deleting the toolbar while its menu it open??
  43088. jassert (owner.isValidComponent());
  43089. for (int i = 0; i < getNumChildComponents(); ++i)
  43090. {
  43091. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43092. if (tc != 0)
  43093. {
  43094. tc->setVisible (false);
  43095. const int index = oldIndexes.remove (i);
  43096. owner.addChildComponent (tc, index);
  43097. --i;
  43098. }
  43099. }
  43100. owner.resized();
  43101. }
  43102. void layout (const int preferredWidth)
  43103. {
  43104. const int indent = 8;
  43105. int x = indent;
  43106. int y = indent;
  43107. int maxX = 0;
  43108. for (int i = 0; i < getNumChildComponents(); ++i)
  43109. {
  43110. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43111. if (tc != 0)
  43112. {
  43113. int preferredSize = 1, minSize = 1, maxSize = 1;
  43114. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43115. {
  43116. if (x + preferredSize > preferredWidth && x > indent)
  43117. {
  43118. x = indent;
  43119. y += height;
  43120. }
  43121. tc->setBounds (x, y, preferredSize, height);
  43122. x += preferredSize;
  43123. maxX = jmax (maxX, x);
  43124. }
  43125. }
  43126. }
  43127. setSize (maxX + 8, y + height + 8);
  43128. }
  43129. void getIdealSize (int& idealWidth, int& idealHeight)
  43130. {
  43131. idealWidth = getWidth();
  43132. idealHeight = getHeight();
  43133. }
  43134. juce_UseDebuggingNewOperator
  43135. private:
  43136. Toolbar& owner;
  43137. const int height;
  43138. Array <int> oldIndexes;
  43139. MissingItemsComponent (const MissingItemsComponent&);
  43140. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43141. };
  43142. Toolbar::Toolbar()
  43143. : vertical (false),
  43144. isEditingActive (false),
  43145. toolbarStyle (Toolbar::iconsOnly)
  43146. {
  43147. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43148. missingItemsButton->setAlwaysOnTop (true);
  43149. missingItemsButton->addButtonListener (this);
  43150. }
  43151. Toolbar::~Toolbar()
  43152. {
  43153. animator.cancelAllAnimations (true);
  43154. deleteAllChildren();
  43155. }
  43156. void Toolbar::setVertical (const bool shouldBeVertical)
  43157. {
  43158. if (vertical != shouldBeVertical)
  43159. {
  43160. vertical = shouldBeVertical;
  43161. resized();
  43162. }
  43163. }
  43164. void Toolbar::clear()
  43165. {
  43166. for (int i = items.size(); --i >= 0;)
  43167. {
  43168. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43169. items.remove (i);
  43170. delete tc;
  43171. }
  43172. resized();
  43173. }
  43174. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43175. {
  43176. if (itemId == ToolbarItemFactory::separatorBarId)
  43177. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43178. else if (itemId == ToolbarItemFactory::spacerId)
  43179. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43180. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43181. return new ToolbarSpacerComp (itemId, 0, false);
  43182. return factory.createItem (itemId);
  43183. }
  43184. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43185. const int itemId,
  43186. const int insertIndex)
  43187. {
  43188. // An ID can't be zero - this might indicate a mistake somewhere?
  43189. jassert (itemId != 0);
  43190. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43191. if (tc != 0)
  43192. {
  43193. #ifdef JUCE_DEBUG
  43194. Array <int> allowedIds;
  43195. factory.getAllToolbarItemIds (allowedIds);
  43196. // If your factory can create an item for a given ID, it must also return
  43197. // that ID from its getAllToolbarItemIds() method!
  43198. jassert (allowedIds.contains (itemId));
  43199. #endif
  43200. items.insert (insertIndex, tc);
  43201. addAndMakeVisible (tc, insertIndex);
  43202. }
  43203. }
  43204. void Toolbar::addItem (ToolbarItemFactory& factory,
  43205. const int itemId,
  43206. const int insertIndex)
  43207. {
  43208. addItemInternal (factory, itemId, insertIndex);
  43209. resized();
  43210. }
  43211. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43212. {
  43213. Array <int> ids;
  43214. factoryToUse.getDefaultItemSet (ids);
  43215. clear();
  43216. for (int i = 0; i < ids.size(); ++i)
  43217. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43218. resized();
  43219. }
  43220. void Toolbar::removeToolbarItem (const int itemIndex)
  43221. {
  43222. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43223. if (tc != 0)
  43224. {
  43225. items.removeValue (tc);
  43226. delete tc;
  43227. resized();
  43228. }
  43229. }
  43230. int Toolbar::getNumItems() const throw()
  43231. {
  43232. return items.size();
  43233. }
  43234. int Toolbar::getItemId (const int itemIndex) const throw()
  43235. {
  43236. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43237. return tc != 0 ? tc->getItemId() : 0;
  43238. }
  43239. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43240. {
  43241. return items [itemIndex];
  43242. }
  43243. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43244. {
  43245. for (;;)
  43246. {
  43247. index += delta;
  43248. ToolbarItemComponent* const tc = getItemComponent (index);
  43249. if (tc == 0)
  43250. break;
  43251. if (tc->isActive)
  43252. return tc;
  43253. }
  43254. return 0;
  43255. }
  43256. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43257. {
  43258. if (toolbarStyle != newStyle)
  43259. {
  43260. toolbarStyle = newStyle;
  43261. updateAllItemPositions (false);
  43262. }
  43263. }
  43264. const String Toolbar::toString() const
  43265. {
  43266. String s ("TB:");
  43267. for (int i = 0; i < getNumItems(); ++i)
  43268. s << getItemId(i) << ' ';
  43269. return s.trimEnd();
  43270. }
  43271. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43272. const String& savedVersion)
  43273. {
  43274. if (! savedVersion.startsWith ("TB:"))
  43275. return false;
  43276. StringArray tokens;
  43277. tokens.addTokens (savedVersion.substring (3), false);
  43278. clear();
  43279. for (int i = 0; i < tokens.size(); ++i)
  43280. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43281. resized();
  43282. return true;
  43283. }
  43284. void Toolbar::paint (Graphics& g)
  43285. {
  43286. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43287. }
  43288. int Toolbar::getThickness() const throw()
  43289. {
  43290. return vertical ? getWidth() : getHeight();
  43291. }
  43292. int Toolbar::getLength() const throw()
  43293. {
  43294. return vertical ? getHeight() : getWidth();
  43295. }
  43296. void Toolbar::setEditingActive (const bool active)
  43297. {
  43298. if (isEditingActive != active)
  43299. {
  43300. isEditingActive = active;
  43301. updateAllItemPositions (false);
  43302. }
  43303. }
  43304. void Toolbar::resized()
  43305. {
  43306. updateAllItemPositions (false);
  43307. }
  43308. void Toolbar::updateAllItemPositions (const bool animate)
  43309. {
  43310. if (getWidth() > 0 && getHeight() > 0)
  43311. {
  43312. StretchableObjectResizer resizer;
  43313. int i;
  43314. for (i = 0; i < items.size(); ++i)
  43315. {
  43316. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43317. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43318. : ToolbarItemComponent::normalMode);
  43319. tc->setStyle (toolbarStyle);
  43320. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43321. int preferredSize = 1, minSize = 1, maxSize = 1;
  43322. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43323. preferredSize, minSize, maxSize))
  43324. {
  43325. tc->isActive = true;
  43326. resizer.addItem (preferredSize, minSize, maxSize,
  43327. spacer != 0 ? spacer->getResizeOrder() : 2);
  43328. }
  43329. else
  43330. {
  43331. tc->isActive = false;
  43332. tc->setVisible (false);
  43333. }
  43334. }
  43335. resizer.resizeToFit (getLength());
  43336. int totalLength = 0;
  43337. for (i = 0; i < resizer.getNumItems(); ++i)
  43338. totalLength += (int) resizer.getItemSize (i);
  43339. const bool itemsOffTheEnd = totalLength > getLength();
  43340. const int extrasButtonSize = getThickness() / 2;
  43341. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43342. missingItemsButton->setVisible (itemsOffTheEnd);
  43343. missingItemsButton->setEnabled (! isEditingActive);
  43344. if (vertical)
  43345. missingItemsButton->setCentrePosition (getWidth() / 2,
  43346. getHeight() - 4 - extrasButtonSize / 2);
  43347. else
  43348. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43349. getHeight() / 2);
  43350. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43351. : missingItemsButton->getX()) - 4
  43352. : getLength();
  43353. int pos = 0, activeIndex = 0;
  43354. for (i = 0; i < items.size(); ++i)
  43355. {
  43356. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43357. if (tc->isActive)
  43358. {
  43359. const int size = (int) resizer.getItemSize (activeIndex++);
  43360. Rectangle<int> newBounds;
  43361. if (vertical)
  43362. newBounds.setBounds (0, pos, getWidth(), size);
  43363. else
  43364. newBounds.setBounds (pos, 0, size, getHeight());
  43365. if (animate)
  43366. {
  43367. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43368. }
  43369. else
  43370. {
  43371. animator.cancelAnimation (tc, false);
  43372. tc->setBounds (newBounds);
  43373. }
  43374. pos += size;
  43375. tc->setVisible (pos <= maxLength
  43376. && ((! tc->isBeingDragged)
  43377. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43378. }
  43379. }
  43380. }
  43381. }
  43382. void Toolbar::buttonClicked (Button*)
  43383. {
  43384. jassert (missingItemsButton->isShowing());
  43385. if (missingItemsButton->isShowing())
  43386. {
  43387. PopupMenu m;
  43388. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43389. m.showAt (missingItemsButton);
  43390. }
  43391. }
  43392. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43393. Component* /*sourceComponent*/)
  43394. {
  43395. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43396. }
  43397. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43398. {
  43399. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43400. if (tc != 0)
  43401. {
  43402. if (getNumItems() == 0)
  43403. {
  43404. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43405. {
  43406. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43407. if (palette != 0)
  43408. palette->replaceComponent (tc);
  43409. }
  43410. else
  43411. {
  43412. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43413. }
  43414. items.add (tc);
  43415. addChildComponent (tc);
  43416. updateAllItemPositions (false);
  43417. }
  43418. else
  43419. {
  43420. for (int i = getNumItems(); --i >= 0;)
  43421. {
  43422. int currentIndex = getIndexOfChildComponent (tc);
  43423. if (currentIndex < 0)
  43424. {
  43425. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43426. {
  43427. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43428. if (palette != 0)
  43429. palette->replaceComponent (tc);
  43430. }
  43431. else
  43432. {
  43433. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43434. }
  43435. items.add (tc);
  43436. addChildComponent (tc);
  43437. currentIndex = getIndexOfChildComponent (tc);
  43438. updateAllItemPositions (true);
  43439. }
  43440. int newIndex = currentIndex;
  43441. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43442. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43443. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43444. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43445. if (prev != 0)
  43446. {
  43447. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43448. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43449. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43450. {
  43451. newIndex = getIndexOfChildComponent (prev);
  43452. }
  43453. }
  43454. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43455. if (next != 0)
  43456. {
  43457. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43458. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43459. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43460. {
  43461. newIndex = getIndexOfChildComponent (next) + 1;
  43462. }
  43463. }
  43464. if (newIndex != currentIndex)
  43465. {
  43466. items.removeValue (tc);
  43467. removeChildComponent (tc);
  43468. addChildComponent (tc, newIndex);
  43469. items.insert (newIndex, tc);
  43470. updateAllItemPositions (true);
  43471. }
  43472. else
  43473. {
  43474. break;
  43475. }
  43476. }
  43477. }
  43478. }
  43479. }
  43480. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43481. {
  43482. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43483. if (tc != 0)
  43484. {
  43485. if (isParentOf (tc))
  43486. {
  43487. items.removeValue (tc);
  43488. removeChildComponent (tc);
  43489. updateAllItemPositions (true);
  43490. }
  43491. }
  43492. }
  43493. void Toolbar::itemDropped (const String&, Component*, int, int)
  43494. {
  43495. }
  43496. void Toolbar::mouseDown (const MouseEvent& e)
  43497. {
  43498. if (e.mods.isPopupMenu())
  43499. {
  43500. }
  43501. }
  43502. class ToolbarCustomisationDialog : public DialogWindow
  43503. {
  43504. public:
  43505. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43506. Toolbar* const toolbar_,
  43507. const int optionFlags)
  43508. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43509. toolbar (toolbar_)
  43510. {
  43511. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43512. setResizable (true, true);
  43513. setResizeLimits (400, 300, 1500, 1000);
  43514. positionNearBar();
  43515. }
  43516. ~ToolbarCustomisationDialog()
  43517. {
  43518. setContentComponent (0, true);
  43519. }
  43520. void closeButtonPressed()
  43521. {
  43522. setVisible (false);
  43523. }
  43524. bool canModalEventBeSentToComponent (const Component* comp)
  43525. {
  43526. return toolbar->isParentOf (comp);
  43527. }
  43528. void positionNearBar()
  43529. {
  43530. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43531. const int tbx = toolbar->getScreenX();
  43532. const int tby = toolbar->getScreenY();
  43533. const int gap = 8;
  43534. int x, y;
  43535. if (toolbar->isVertical())
  43536. {
  43537. y = tby;
  43538. if (tbx > screenSize.getCentreX())
  43539. x = tbx - getWidth() - gap;
  43540. else
  43541. x = tbx + toolbar->getWidth() + gap;
  43542. }
  43543. else
  43544. {
  43545. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43546. if (tby > screenSize.getCentreY())
  43547. y = tby - getHeight() - gap;
  43548. else
  43549. y = tby + toolbar->getHeight() + gap;
  43550. }
  43551. setTopLeftPosition (x, y);
  43552. }
  43553. private:
  43554. Toolbar* const toolbar;
  43555. class CustomiserPanel : public Component,
  43556. private ComboBoxListener,
  43557. private ButtonListener
  43558. {
  43559. public:
  43560. CustomiserPanel (ToolbarItemFactory& factory_,
  43561. Toolbar* const toolbar_,
  43562. const int optionFlags)
  43563. : factory (factory_),
  43564. toolbar (toolbar_),
  43565. styleBox (0),
  43566. defaultButton (0)
  43567. {
  43568. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43569. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43570. | Toolbar::allowIconsWithTextChoice
  43571. | Toolbar::allowTextOnlyChoice)) != 0)
  43572. {
  43573. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43574. styleBox->setEditableText (false);
  43575. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43576. styleBox->addItem (TRANS("Show icons only"), 1);
  43577. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43578. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43579. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43580. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43581. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43582. styleBox->setSelectedId (1);
  43583. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43584. styleBox->setSelectedId (2);
  43585. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43586. styleBox->setSelectedId (3);
  43587. styleBox->addListener (this);
  43588. }
  43589. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43590. {
  43591. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43592. defaultButton->addButtonListener (this);
  43593. }
  43594. addAndMakeVisible (instructions = new Label (String::empty,
  43595. 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.")));
  43596. instructions->setFont (Font (13.0f));
  43597. setSize (500, 300);
  43598. }
  43599. ~CustomiserPanel()
  43600. {
  43601. deleteAllChildren();
  43602. }
  43603. void comboBoxChanged (ComboBox*)
  43604. {
  43605. if (styleBox->getSelectedId() == 1)
  43606. toolbar->setStyle (Toolbar::iconsOnly);
  43607. else if (styleBox->getSelectedId() == 2)
  43608. toolbar->setStyle (Toolbar::iconsWithText);
  43609. else if (styleBox->getSelectedId() == 3)
  43610. toolbar->setStyle (Toolbar::textOnly);
  43611. palette->resized(); // to make it update the styles
  43612. }
  43613. void buttonClicked (Button*)
  43614. {
  43615. toolbar->addDefaultItems (factory);
  43616. }
  43617. void paint (Graphics& g)
  43618. {
  43619. Colour background;
  43620. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43621. if (dw != 0)
  43622. background = dw->getBackgroundColour();
  43623. g.setColour (background.contrasting().withAlpha (0.3f));
  43624. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43625. }
  43626. void resized()
  43627. {
  43628. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43629. if (styleBox != 0)
  43630. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43631. if (defaultButton != 0)
  43632. {
  43633. defaultButton->changeWidthToFitText (22);
  43634. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43635. }
  43636. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43637. }
  43638. private:
  43639. ToolbarItemFactory& factory;
  43640. Toolbar* const toolbar;
  43641. Label* instructions;
  43642. ToolbarItemPalette* palette;
  43643. ComboBox* styleBox;
  43644. TextButton* defaultButton;
  43645. };
  43646. };
  43647. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43648. {
  43649. setEditingActive (true);
  43650. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43651. dw.runModalLoop();
  43652. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43653. setEditingActive (false);
  43654. }
  43655. END_JUCE_NAMESPACE
  43656. /*** End of inlined file: juce_Toolbar.cpp ***/
  43657. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43658. BEGIN_JUCE_NAMESPACE
  43659. ToolbarItemFactory::ToolbarItemFactory()
  43660. {
  43661. }
  43662. ToolbarItemFactory::~ToolbarItemFactory()
  43663. {
  43664. }
  43665. class ItemDragAndDropOverlayComponent : public Component
  43666. {
  43667. public:
  43668. ItemDragAndDropOverlayComponent()
  43669. : isDragging (false)
  43670. {
  43671. setAlwaysOnTop (true);
  43672. setRepaintsOnMouseActivity (true);
  43673. setMouseCursor (MouseCursor::DraggingHandCursor);
  43674. }
  43675. ~ItemDragAndDropOverlayComponent()
  43676. {
  43677. }
  43678. void paint (Graphics& g)
  43679. {
  43680. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43681. if (isMouseOverOrDragging()
  43682. && tc != 0
  43683. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43684. {
  43685. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43686. g.drawRect (0, 0, getWidth(), getHeight(),
  43687. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43688. }
  43689. }
  43690. void mouseDown (const MouseEvent& e)
  43691. {
  43692. isDragging = false;
  43693. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43694. if (tc != 0)
  43695. {
  43696. tc->dragOffsetX = e.x;
  43697. tc->dragOffsetY = e.y;
  43698. }
  43699. }
  43700. void mouseDrag (const MouseEvent& e)
  43701. {
  43702. if (! (isDragging || e.mouseWasClicked()))
  43703. {
  43704. isDragging = true;
  43705. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43706. if (dnd != 0)
  43707. {
  43708. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43709. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43710. if (tc != 0)
  43711. {
  43712. tc->isBeingDragged = true;
  43713. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43714. tc->setVisible (false);
  43715. }
  43716. }
  43717. }
  43718. }
  43719. void mouseUp (const MouseEvent&)
  43720. {
  43721. isDragging = false;
  43722. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43723. if (tc != 0)
  43724. {
  43725. tc->isBeingDragged = false;
  43726. Toolbar* const tb = tc->getToolbar();
  43727. if (tb != 0)
  43728. tb->updateAllItemPositions (true);
  43729. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43730. delete tc;
  43731. }
  43732. }
  43733. void parentSizeChanged()
  43734. {
  43735. setBounds (0, 0, getParentWidth(), getParentHeight());
  43736. }
  43737. juce_UseDebuggingNewOperator
  43738. private:
  43739. bool isDragging;
  43740. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43741. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43742. };
  43743. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43744. const String& labelText,
  43745. const bool isBeingUsedAsAButton_)
  43746. : Button (labelText),
  43747. itemId (itemId_),
  43748. mode (normalMode),
  43749. toolbarStyle (Toolbar::iconsOnly),
  43750. dragOffsetX (0),
  43751. dragOffsetY (0),
  43752. isActive (true),
  43753. isBeingDragged (false),
  43754. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43755. {
  43756. // Your item ID can't be 0!
  43757. jassert (itemId_ != 0);
  43758. }
  43759. ToolbarItemComponent::~ToolbarItemComponent()
  43760. {
  43761. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43762. overlayComp = 0;
  43763. }
  43764. Toolbar* ToolbarItemComponent::getToolbar() const
  43765. {
  43766. return dynamic_cast <Toolbar*> (getParentComponent());
  43767. }
  43768. bool ToolbarItemComponent::isToolbarVertical() const
  43769. {
  43770. const Toolbar* const t = getToolbar();
  43771. return t != 0 && t->isVertical();
  43772. }
  43773. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43774. {
  43775. if (toolbarStyle != newStyle)
  43776. {
  43777. toolbarStyle = newStyle;
  43778. repaint();
  43779. resized();
  43780. }
  43781. }
  43782. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43783. {
  43784. if (isBeingUsedAsAButton)
  43785. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43786. isMouseOver, isMouseDown, *this);
  43787. if (toolbarStyle != Toolbar::iconsOnly)
  43788. {
  43789. const int indent = contentArea.getX();
  43790. int y = indent;
  43791. int h = getHeight() - indent * 2;
  43792. if (toolbarStyle == Toolbar::iconsWithText)
  43793. {
  43794. y = contentArea.getBottom() + indent / 2;
  43795. h -= contentArea.getHeight();
  43796. }
  43797. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43798. getButtonText(), *this);
  43799. }
  43800. if (! contentArea.isEmpty())
  43801. {
  43802. g.saveState();
  43803. g.setOrigin (contentArea.getX(), contentArea.getY());
  43804. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43805. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43806. g.restoreState();
  43807. }
  43808. }
  43809. void ToolbarItemComponent::resized()
  43810. {
  43811. if (toolbarStyle != Toolbar::textOnly)
  43812. {
  43813. const int indent = jmin (proportionOfWidth (0.08f),
  43814. proportionOfHeight (0.08f));
  43815. contentArea = Rectangle<int> (indent, indent,
  43816. getWidth() - indent * 2,
  43817. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43818. : (getHeight() - indent * 2));
  43819. }
  43820. else
  43821. {
  43822. contentArea = Rectangle<int>();
  43823. }
  43824. contentAreaChanged (contentArea);
  43825. }
  43826. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43827. {
  43828. if (mode != newMode)
  43829. {
  43830. mode = newMode;
  43831. repaint();
  43832. if (mode == normalMode)
  43833. {
  43834. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43835. overlayComp = 0;
  43836. }
  43837. else if (overlayComp == 0)
  43838. {
  43839. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43840. overlayComp->parentSizeChanged();
  43841. }
  43842. resized();
  43843. }
  43844. }
  43845. END_JUCE_NAMESPACE
  43846. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43847. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43848. BEGIN_JUCE_NAMESPACE
  43849. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43850. Toolbar* const toolbar_)
  43851. : factory (factory_),
  43852. toolbar (toolbar_)
  43853. {
  43854. Component* const itemHolder = new Component();
  43855. Array <int> allIds;
  43856. factory_.getAllToolbarItemIds (allIds);
  43857. for (int i = 0; i < allIds.size(); ++i)
  43858. {
  43859. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43860. jassert (tc != 0);
  43861. if (tc != 0)
  43862. {
  43863. itemHolder->addAndMakeVisible (tc);
  43864. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43865. }
  43866. }
  43867. viewport = new Viewport();
  43868. viewport->setViewedComponent (itemHolder);
  43869. addAndMakeVisible (viewport);
  43870. }
  43871. ToolbarItemPalette::~ToolbarItemPalette()
  43872. {
  43873. viewport->getViewedComponent()->deleteAllChildren();
  43874. deleteAllChildren();
  43875. }
  43876. void ToolbarItemPalette::resized()
  43877. {
  43878. viewport->setBoundsInset (BorderSize (1));
  43879. Component* const itemHolder = viewport->getViewedComponent();
  43880. const int indent = 8;
  43881. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  43882. const int height = toolbar->getThickness();
  43883. int x = indent;
  43884. int y = indent;
  43885. int maxX = 0;
  43886. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  43887. {
  43888. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  43889. if (tc != 0)
  43890. {
  43891. tc->setStyle (toolbar->getStyle());
  43892. int preferredSize = 1, minSize = 1, maxSize = 1;
  43893. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43894. {
  43895. if (x + preferredSize > preferredWidth && x > indent)
  43896. {
  43897. x = indent;
  43898. y += height;
  43899. }
  43900. tc->setBounds (x, y, preferredSize, height);
  43901. x += preferredSize + 8;
  43902. maxX = jmax (maxX, x);
  43903. }
  43904. }
  43905. }
  43906. itemHolder->setSize (maxX, y + height + 8);
  43907. }
  43908. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  43909. {
  43910. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  43911. jassert (tc != 0);
  43912. if (tc != 0)
  43913. {
  43914. tc->setBounds (comp->getBounds());
  43915. tc->setStyle (toolbar->getStyle());
  43916. tc->setEditingMode (comp->getEditingMode());
  43917. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  43918. }
  43919. }
  43920. END_JUCE_NAMESPACE
  43921. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  43922. /*** Start of inlined file: juce_TreeView.cpp ***/
  43923. BEGIN_JUCE_NAMESPACE
  43924. class TreeViewContentComponent : public Component,
  43925. public TooltipClient
  43926. {
  43927. public:
  43928. TreeViewContentComponent (TreeView* const owner_)
  43929. : owner (owner_),
  43930. buttonUnderMouse (0),
  43931. isDragging (false)
  43932. {
  43933. }
  43934. ~TreeViewContentComponent()
  43935. {
  43936. deleteAllChildren();
  43937. }
  43938. void mouseDown (const MouseEvent& e)
  43939. {
  43940. updateButtonUnderMouse (e);
  43941. isDragging = false;
  43942. needSelectionOnMouseUp = false;
  43943. Rectangle<int> pos;
  43944. TreeViewItem* const item = findItemAt (e.y, pos);
  43945. if (item == 0)
  43946. return;
  43947. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  43948. // as selection clicks)
  43949. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  43950. {
  43951. if (e.x >= pos.getX() - owner->getIndentSize())
  43952. item->setOpen (! item->isOpen());
  43953. // (clicks to the left of an open/close button are ignored)
  43954. }
  43955. else
  43956. {
  43957. // mouse-down inside the body of the item..
  43958. if (! owner->isMultiSelectEnabled())
  43959. item->setSelected (true, true);
  43960. else if (item->isSelected())
  43961. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  43962. else
  43963. selectBasedOnModifiers (item, e.mods);
  43964. if (e.x >= pos.getX())
  43965. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43966. }
  43967. }
  43968. void mouseUp (const MouseEvent& e)
  43969. {
  43970. updateButtonUnderMouse (e);
  43971. if (needSelectionOnMouseUp && e.mouseWasClicked())
  43972. {
  43973. Rectangle<int> pos;
  43974. TreeViewItem* const item = findItemAt (e.y, pos);
  43975. if (item != 0)
  43976. selectBasedOnModifiers (item, e.mods);
  43977. }
  43978. }
  43979. void mouseDoubleClick (const MouseEvent& e)
  43980. {
  43981. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  43982. {
  43983. Rectangle<int> pos;
  43984. TreeViewItem* const item = findItemAt (e.y, pos);
  43985. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  43986. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43987. }
  43988. }
  43989. void mouseDrag (const MouseEvent& e)
  43990. {
  43991. if (isEnabled()
  43992. && ! (isDragging || e.mouseWasClicked()
  43993. || e.getDistanceFromDragStart() < 5
  43994. || e.mods.isPopupMenu()))
  43995. {
  43996. isDragging = true;
  43997. Rectangle<int> pos;
  43998. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  43999. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44000. {
  44001. const String dragDescription (item->getDragSourceDescription());
  44002. if (dragDescription.isNotEmpty())
  44003. {
  44004. DragAndDropContainer* const dragContainer
  44005. = DragAndDropContainer::findParentDragContainerFor (this);
  44006. if (dragContainer != 0)
  44007. {
  44008. pos.setSize (pos.getWidth(), item->itemHeight);
  44009. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44010. dragImage->multiplyAllAlphas (0.6f);
  44011. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44012. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44013. }
  44014. else
  44015. {
  44016. // to be able to do a drag-and-drop operation, the treeview needs to
  44017. // be inside a component which is also a DragAndDropContainer.
  44018. jassertfalse
  44019. }
  44020. }
  44021. }
  44022. }
  44023. }
  44024. void mouseMove (const MouseEvent& e)
  44025. {
  44026. updateButtonUnderMouse (e);
  44027. }
  44028. void mouseExit (const MouseEvent& e)
  44029. {
  44030. updateButtonUnderMouse (e);
  44031. }
  44032. void paint (Graphics& g);
  44033. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44034. static bool isMouseDraggingInChildCompOf (Component* const comp)
  44035. {
  44036. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  44037. {
  44038. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  44039. if (source->isDragging())
  44040. {
  44041. Component* const underMouse = source->getComponentUnderMouse();
  44042. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  44043. return true;
  44044. }
  44045. }
  44046. return false;
  44047. }
  44048. void updateComponents()
  44049. {
  44050. const int visibleTop = -getY();
  44051. const int visibleBottom = visibleTop + getParentHeight();
  44052. BigInteger itemsToKeep;
  44053. TreeViewItem* item = owner->rootItem;
  44054. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44055. while (item != 0 && y < visibleBottom)
  44056. {
  44057. y += item->itemHeight;
  44058. if (y >= visibleTop)
  44059. {
  44060. const int index = rowComponentIds.indexOf (item->uid);
  44061. if (index < 0)
  44062. {
  44063. Component* const comp = item->createItemComponent();
  44064. if (comp != 0)
  44065. {
  44066. addAndMakeVisible (comp);
  44067. itemsToKeep.setBit (rowComponentItems.size());
  44068. rowComponentItems.add (item);
  44069. rowComponentIds.add (item->uid);
  44070. rowComponents.add (comp);
  44071. }
  44072. }
  44073. else
  44074. {
  44075. itemsToKeep.setBit (index);
  44076. }
  44077. }
  44078. item = item->getNextVisibleItem (true);
  44079. }
  44080. for (int i = rowComponentItems.size(); --i >= 0;)
  44081. {
  44082. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44083. bool keep = false;
  44084. if (isParentOf (comp))
  44085. {
  44086. if (itemsToKeep[i])
  44087. {
  44088. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44089. Rectangle<int> pos (item->getItemPosition (false));
  44090. pos.setSize (pos.getWidth(), item->itemHeight);
  44091. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44092. {
  44093. keep = true;
  44094. comp->setBounds (pos);
  44095. }
  44096. }
  44097. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44098. {
  44099. keep = true;
  44100. comp->setSize (0, 0);
  44101. }
  44102. }
  44103. if (! keep)
  44104. {
  44105. delete comp;
  44106. rowComponents.remove (i);
  44107. rowComponentIds.remove (i);
  44108. rowComponentItems.remove (i);
  44109. }
  44110. }
  44111. }
  44112. void updateButtonUnderMouse (const MouseEvent& e)
  44113. {
  44114. TreeViewItem* newItem = 0;
  44115. if (owner->openCloseButtonsVisible)
  44116. {
  44117. Rectangle<int> pos;
  44118. TreeViewItem* item = findItemAt (e.y, pos);
  44119. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44120. {
  44121. newItem = item;
  44122. if (! newItem->mightContainSubItems())
  44123. newItem = 0;
  44124. }
  44125. }
  44126. if (buttonUnderMouse != newItem)
  44127. {
  44128. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44129. {
  44130. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44131. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44132. }
  44133. buttonUnderMouse = newItem;
  44134. if (buttonUnderMouse != 0)
  44135. {
  44136. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44137. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44138. }
  44139. }
  44140. }
  44141. bool isMouseOverButton (TreeViewItem* item) const throw()
  44142. {
  44143. return item == buttonUnderMouse;
  44144. }
  44145. void resized()
  44146. {
  44147. owner->itemsChanged();
  44148. }
  44149. const String getTooltip()
  44150. {
  44151. Rectangle<int> pos;
  44152. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44153. if (item != 0)
  44154. return item->getTooltip();
  44155. return owner->getTooltip();
  44156. }
  44157. juce_UseDebuggingNewOperator
  44158. private:
  44159. TreeView* const owner;
  44160. VoidArray rowComponentItems;
  44161. Array <int> rowComponentIds;
  44162. VoidArray rowComponents;
  44163. TreeViewItem* buttonUnderMouse;
  44164. bool isDragging, needSelectionOnMouseUp;
  44165. TreeViewContentComponent (const TreeViewContentComponent&);
  44166. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44167. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44168. {
  44169. TreeViewItem* firstSelected = 0;
  44170. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44171. {
  44172. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44173. jassert (lastSelected != 0);
  44174. int rowStart = firstSelected->getRowNumberInTree();
  44175. int rowEnd = lastSelected->getRowNumberInTree();
  44176. if (rowStart > rowEnd)
  44177. swapVariables (rowStart, rowEnd);
  44178. int ourRow = item->getRowNumberInTree();
  44179. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44180. if (ourRow > otherEnd)
  44181. swapVariables (ourRow, otherEnd);
  44182. for (int i = ourRow; i <= otherEnd; ++i)
  44183. owner->getItemOnRow (i)->setSelected (true, false);
  44184. }
  44185. else
  44186. {
  44187. const bool cmd = modifiers.isCommandDown();
  44188. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44189. }
  44190. }
  44191. bool containsItem (TreeViewItem* const item) const
  44192. {
  44193. for (int i = rowComponentItems.size(); --i >= 0;)
  44194. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44195. return true;
  44196. return false;
  44197. }
  44198. };
  44199. class TreeViewport : public Viewport
  44200. {
  44201. public:
  44202. TreeViewport() throw() {}
  44203. ~TreeViewport() throw() {}
  44204. void updateComponents()
  44205. {
  44206. if (getViewedComponent() != 0)
  44207. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44208. repaint();
  44209. }
  44210. void visibleAreaChanged (int, int, int, int)
  44211. {
  44212. updateComponents();
  44213. }
  44214. juce_UseDebuggingNewOperator
  44215. private:
  44216. TreeViewport (const TreeViewport&);
  44217. TreeViewport& operator= (const TreeViewport&);
  44218. };
  44219. TreeView::TreeView (const String& componentName)
  44220. : Component (componentName),
  44221. rootItem (0),
  44222. dragInsertPointHighlight (0),
  44223. dragTargetGroupHighlight (0),
  44224. indentSize (24),
  44225. defaultOpenness (false),
  44226. needsRecalculating (true),
  44227. rootItemVisible (true),
  44228. multiSelectEnabled (false),
  44229. openCloseButtonsVisible (true)
  44230. {
  44231. addAndMakeVisible (viewport = new TreeViewport());
  44232. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44233. viewport->setWantsKeyboardFocus (false);
  44234. setWantsKeyboardFocus (true);
  44235. }
  44236. TreeView::~TreeView()
  44237. {
  44238. if (rootItem != 0)
  44239. rootItem->setOwnerView (0);
  44240. deleteAllChildren();
  44241. }
  44242. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44243. {
  44244. if (rootItem != newRootItem)
  44245. {
  44246. if (newRootItem != 0)
  44247. {
  44248. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44249. if (newRootItem->ownerView != 0)
  44250. newRootItem->ownerView->setRootItem (0);
  44251. }
  44252. if (rootItem != 0)
  44253. rootItem->setOwnerView (0);
  44254. rootItem = newRootItem;
  44255. if (newRootItem != 0)
  44256. newRootItem->setOwnerView (this);
  44257. needsRecalculating = true;
  44258. handleAsyncUpdate();
  44259. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44260. {
  44261. rootItem->setOpen (false); // force a re-open
  44262. rootItem->setOpen (true);
  44263. }
  44264. }
  44265. }
  44266. void TreeView::deleteRootItem()
  44267. {
  44268. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44269. setRootItem (0);
  44270. }
  44271. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44272. {
  44273. rootItemVisible = shouldBeVisible;
  44274. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44275. {
  44276. rootItem->setOpen (false); // force a re-open
  44277. rootItem->setOpen (true);
  44278. }
  44279. itemsChanged();
  44280. }
  44281. void TreeView::colourChanged()
  44282. {
  44283. setOpaque (findColour (backgroundColourId).isOpaque());
  44284. repaint();
  44285. }
  44286. void TreeView::setIndentSize (const int newIndentSize)
  44287. {
  44288. if (indentSize != newIndentSize)
  44289. {
  44290. indentSize = newIndentSize;
  44291. resized();
  44292. }
  44293. }
  44294. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44295. {
  44296. if (defaultOpenness != isOpenByDefault)
  44297. {
  44298. defaultOpenness = isOpenByDefault;
  44299. itemsChanged();
  44300. }
  44301. }
  44302. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44303. {
  44304. multiSelectEnabled = canMultiSelect;
  44305. }
  44306. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44307. {
  44308. if (openCloseButtonsVisible != shouldBeVisible)
  44309. {
  44310. openCloseButtonsVisible = shouldBeVisible;
  44311. itemsChanged();
  44312. }
  44313. }
  44314. void TreeView::clearSelectedItems()
  44315. {
  44316. if (rootItem != 0)
  44317. rootItem->deselectAllRecursively();
  44318. }
  44319. int TreeView::getNumSelectedItems() const throw()
  44320. {
  44321. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44322. }
  44323. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44324. {
  44325. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44326. }
  44327. int TreeView::getNumRowsInTree() const
  44328. {
  44329. if (rootItem != 0)
  44330. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44331. return 0;
  44332. }
  44333. TreeViewItem* TreeView::getItemOnRow (int index) const
  44334. {
  44335. if (! rootItemVisible)
  44336. ++index;
  44337. if (rootItem != 0 && index >= 0)
  44338. return rootItem->getItemOnRow (index);
  44339. return 0;
  44340. }
  44341. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44342. {
  44343. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44344. Rectangle<int> pos;
  44345. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44346. }
  44347. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44348. {
  44349. if (rootItem == 0)
  44350. return 0;
  44351. return rootItem->findItemFromIdentifierString (identifierString);
  44352. }
  44353. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44354. {
  44355. XmlElement* e = 0;
  44356. if (rootItem != 0)
  44357. {
  44358. e = rootItem->getOpennessState();
  44359. if (e != 0 && alsoIncludeScrollPosition)
  44360. e->setAttribute ("scrollPos", viewport->getViewPositionY());
  44361. }
  44362. return e;
  44363. }
  44364. void TreeView::restoreOpennessState (const XmlElement& newState)
  44365. {
  44366. if (rootItem != 0)
  44367. {
  44368. rootItem->restoreOpennessState (newState);
  44369. if (newState.hasAttribute ("scrollPos"))
  44370. viewport->setViewPosition (viewport->getViewPositionX(),
  44371. newState.getIntAttribute ("scrollPos"));
  44372. }
  44373. }
  44374. void TreeView::paint (Graphics& g)
  44375. {
  44376. g.fillAll (findColour (backgroundColourId));
  44377. }
  44378. void TreeView::resized()
  44379. {
  44380. viewport->setBounds (0, 0, getWidth(), getHeight());
  44381. itemsChanged();
  44382. handleAsyncUpdate();
  44383. }
  44384. void TreeView::enablementChanged()
  44385. {
  44386. repaint();
  44387. }
  44388. void TreeView::moveSelectedRow (int delta)
  44389. {
  44390. if (delta == 0)
  44391. return;
  44392. int rowSelected = 0;
  44393. TreeViewItem* const firstSelected = getSelectedItem (0);
  44394. if (firstSelected != 0)
  44395. rowSelected = firstSelected->getRowNumberInTree();
  44396. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44397. for (;;)
  44398. {
  44399. TreeViewItem* item = getItemOnRow (rowSelected);
  44400. if (item != 0)
  44401. {
  44402. if (! item->canBeSelected())
  44403. {
  44404. // if the row we want to highlight doesn't allow it, try skipping
  44405. // to the next item..
  44406. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44407. rowSelected + (delta < 0 ? -1 : 1));
  44408. if (rowSelected != nextRowToTry)
  44409. {
  44410. rowSelected = nextRowToTry;
  44411. continue;
  44412. }
  44413. else
  44414. {
  44415. break;
  44416. }
  44417. }
  44418. item->setSelected (true, true);
  44419. scrollToKeepItemVisible (item);
  44420. }
  44421. break;
  44422. }
  44423. }
  44424. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44425. {
  44426. if (item != 0 && item->ownerView == this)
  44427. {
  44428. handleAsyncUpdate();
  44429. item = item->getDeepestOpenParentItem();
  44430. int y = item->y;
  44431. int viewTop = viewport->getViewPositionY();
  44432. if (y < viewTop)
  44433. {
  44434. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44435. }
  44436. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44437. {
  44438. viewport->setViewPosition (viewport->getViewPositionX(),
  44439. (y + item->itemHeight) - viewport->getViewHeight());
  44440. }
  44441. }
  44442. }
  44443. bool TreeView::keyPressed (const KeyPress& key)
  44444. {
  44445. if (key.isKeyCode (KeyPress::upKey))
  44446. {
  44447. moveSelectedRow (-1);
  44448. }
  44449. else if (key.isKeyCode (KeyPress::downKey))
  44450. {
  44451. moveSelectedRow (1);
  44452. }
  44453. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44454. {
  44455. if (rootItem != 0)
  44456. {
  44457. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44458. if (key.isKeyCode (KeyPress::pageUpKey))
  44459. rowsOnScreen = -rowsOnScreen;
  44460. moveSelectedRow (rowsOnScreen);
  44461. }
  44462. }
  44463. else if (key.isKeyCode (KeyPress::homeKey))
  44464. {
  44465. moveSelectedRow (-0x3fffffff);
  44466. }
  44467. else if (key.isKeyCode (KeyPress::endKey))
  44468. {
  44469. moveSelectedRow (0x3fffffff);
  44470. }
  44471. else if (key.isKeyCode (KeyPress::returnKey))
  44472. {
  44473. TreeViewItem* const firstSelected = getSelectedItem (0);
  44474. if (firstSelected != 0)
  44475. firstSelected->setOpen (! firstSelected->isOpen());
  44476. }
  44477. else if (key.isKeyCode (KeyPress::leftKey))
  44478. {
  44479. TreeViewItem* const firstSelected = getSelectedItem (0);
  44480. if (firstSelected != 0)
  44481. {
  44482. if (firstSelected->isOpen())
  44483. {
  44484. firstSelected->setOpen (false);
  44485. }
  44486. else
  44487. {
  44488. TreeViewItem* parent = firstSelected->parentItem;
  44489. if ((! rootItemVisible) && parent == rootItem)
  44490. parent = 0;
  44491. if (parent != 0)
  44492. {
  44493. parent->setSelected (true, true);
  44494. scrollToKeepItemVisible (parent);
  44495. }
  44496. }
  44497. }
  44498. }
  44499. else if (key.isKeyCode (KeyPress::rightKey))
  44500. {
  44501. TreeViewItem* const firstSelected = getSelectedItem (0);
  44502. if (firstSelected != 0)
  44503. {
  44504. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44505. moveSelectedRow (1);
  44506. else
  44507. firstSelected->setOpen (true);
  44508. }
  44509. }
  44510. else
  44511. {
  44512. return false;
  44513. }
  44514. return true;
  44515. }
  44516. void TreeView::itemsChanged() throw()
  44517. {
  44518. needsRecalculating = true;
  44519. repaint();
  44520. triggerAsyncUpdate();
  44521. }
  44522. void TreeView::handleAsyncUpdate()
  44523. {
  44524. if (needsRecalculating)
  44525. {
  44526. needsRecalculating = false;
  44527. const ScopedLock sl (nodeAlterationLock);
  44528. if (rootItem != 0)
  44529. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44530. ((TreeViewport*) viewport)->updateComponents();
  44531. if (rootItem != 0)
  44532. {
  44533. viewport->getViewedComponent()
  44534. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44535. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44536. }
  44537. else
  44538. {
  44539. viewport->getViewedComponent()->setSize (0, 0);
  44540. }
  44541. }
  44542. }
  44543. class TreeViewDragInsertPointHighlight : public Component
  44544. {
  44545. public:
  44546. TreeViewDragInsertPointHighlight()
  44547. : lastItem (0)
  44548. {
  44549. setSize (100, 12);
  44550. setAlwaysOnTop (true);
  44551. setInterceptsMouseClicks (false, false);
  44552. }
  44553. ~TreeViewDragInsertPointHighlight() {}
  44554. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44555. {
  44556. lastItem = item;
  44557. lastIndex = insertIndex;
  44558. const int offset = getHeight() / 2;
  44559. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44560. }
  44561. void paint (Graphics& g)
  44562. {
  44563. Path p;
  44564. const float h = (float) getHeight();
  44565. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44566. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44567. p.lineTo ((float) getWidth(), h / 2.0f);
  44568. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44569. g.strokePath (p, PathStrokeType (2.0f));
  44570. }
  44571. TreeViewItem* lastItem;
  44572. int lastIndex;
  44573. };
  44574. class TreeViewDragTargetGroupHighlight : public Component
  44575. {
  44576. public:
  44577. TreeViewDragTargetGroupHighlight()
  44578. {
  44579. setAlwaysOnTop (true);
  44580. setInterceptsMouseClicks (false, false);
  44581. }
  44582. ~TreeViewDragTargetGroupHighlight() {}
  44583. void setTargetPosition (TreeViewItem* const item) throw()
  44584. {
  44585. Rectangle<int> r (item->getItemPosition (true));
  44586. r.setHeight (item->getItemHeight());
  44587. setBounds (r);
  44588. }
  44589. void paint (Graphics& g)
  44590. {
  44591. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44592. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44593. }
  44594. };
  44595. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44596. {
  44597. beginDragAutoRepeat (1000 / 30);
  44598. if (dragInsertPointHighlight == 0)
  44599. {
  44600. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  44601. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  44602. }
  44603. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  44604. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44605. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  44606. ->setTargetPosition (item);
  44607. }
  44608. void TreeView::hideDragHighlight() throw()
  44609. {
  44610. deleteAndZero (dragInsertPointHighlight);
  44611. deleteAndZero (dragTargetGroupHighlight);
  44612. }
  44613. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44614. const StringArray& files, const String& sourceDescription,
  44615. Component* sourceComponent) const throw()
  44616. {
  44617. insertIndex = 0;
  44618. TreeViewItem* item = getItemAt (y);
  44619. if (item == 0)
  44620. return 0;
  44621. Rectangle<int> itemPos (item->getItemPosition (true));
  44622. insertIndex = item->getIndexInParent();
  44623. const int oldY = y;
  44624. y = itemPos.getY();
  44625. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44626. {
  44627. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44628. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44629. {
  44630. // Check if we're trying to drag into an empty group item..
  44631. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44632. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44633. {
  44634. insertIndex = 0;
  44635. x = itemPos.getX() + getIndentSize();
  44636. y = itemPos.getBottom();
  44637. return item;
  44638. }
  44639. }
  44640. }
  44641. if (oldY > itemPos.getCentreY())
  44642. {
  44643. y += item->getItemHeight();
  44644. while (item->isLastOfSiblings() && item->parentItem != 0
  44645. && item->parentItem->parentItem != 0)
  44646. {
  44647. if (x > itemPos.getX())
  44648. break;
  44649. item = item->parentItem;
  44650. itemPos = item->getItemPosition (true);
  44651. insertIndex = item->getIndexInParent();
  44652. }
  44653. ++insertIndex;
  44654. }
  44655. x = itemPos.getX();
  44656. return item->parentItem;
  44657. }
  44658. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44659. {
  44660. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44661. int insertIndex;
  44662. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44663. if (item != 0)
  44664. {
  44665. if (scrolled || dragInsertPointHighlight == 0
  44666. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  44667. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  44668. {
  44669. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44670. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44671. showDragHighlight (item, insertIndex, x, y);
  44672. else
  44673. hideDragHighlight();
  44674. }
  44675. }
  44676. else
  44677. {
  44678. hideDragHighlight();
  44679. }
  44680. }
  44681. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44682. {
  44683. hideDragHighlight();
  44684. int insertIndex;
  44685. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44686. if (item != 0)
  44687. {
  44688. if (files.size() > 0)
  44689. {
  44690. if (item->isInterestedInFileDrag (files))
  44691. item->filesDropped (files, insertIndex);
  44692. }
  44693. else
  44694. {
  44695. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44696. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44697. }
  44698. }
  44699. }
  44700. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44701. {
  44702. return true;
  44703. }
  44704. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44705. {
  44706. fileDragMove (files, x, y);
  44707. }
  44708. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44709. {
  44710. handleDrag (files, String::empty, 0, x, y);
  44711. }
  44712. void TreeView::fileDragExit (const StringArray&)
  44713. {
  44714. hideDragHighlight();
  44715. }
  44716. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44717. {
  44718. handleDrop (files, String::empty, 0, x, y);
  44719. }
  44720. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44721. {
  44722. return true;
  44723. }
  44724. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44725. {
  44726. itemDragMove (sourceDescription, sourceComponent, x, y);
  44727. }
  44728. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44729. {
  44730. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44731. }
  44732. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44733. {
  44734. hideDragHighlight();
  44735. }
  44736. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44737. {
  44738. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44739. }
  44740. void TreeViewContentComponent::paint (Graphics& g)
  44741. {
  44742. if (owner->rootItem != 0)
  44743. {
  44744. owner->handleAsyncUpdate();
  44745. if (! owner->rootItemVisible)
  44746. g.setOrigin (0, -owner->rootItem->itemHeight);
  44747. owner->rootItem->paintRecursively (g, getWidth());
  44748. }
  44749. }
  44750. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44751. {
  44752. if (owner->rootItem != 0)
  44753. {
  44754. owner->handleAsyncUpdate();
  44755. if (! owner->rootItemVisible)
  44756. y += owner->rootItem->itemHeight;
  44757. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44758. if (ti != 0)
  44759. itemPosition = ti->getItemPosition (false);
  44760. return ti;
  44761. }
  44762. return 0;
  44763. }
  44764. enum TreeViewOpenness
  44765. {
  44766. opennessDefault = 0,
  44767. opennessClosed = 1,
  44768. opennessOpen = 2
  44769. };
  44770. TreeViewItem::TreeViewItem()
  44771. : ownerView (0),
  44772. parentItem (0),
  44773. y (0),
  44774. itemHeight (0),
  44775. totalHeight (0),
  44776. selected (false),
  44777. redrawNeeded (true),
  44778. drawLinesInside (true),
  44779. drawsInLeftMargin (false),
  44780. openness (opennessDefault)
  44781. {
  44782. static int nextUID = 0;
  44783. uid = nextUID++;
  44784. }
  44785. TreeViewItem::~TreeViewItem()
  44786. {
  44787. }
  44788. const String TreeViewItem::getUniqueName() const
  44789. {
  44790. return String::empty;
  44791. }
  44792. void TreeViewItem::itemOpennessChanged (bool)
  44793. {
  44794. }
  44795. int TreeViewItem::getNumSubItems() const throw()
  44796. {
  44797. return subItems.size();
  44798. }
  44799. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44800. {
  44801. return subItems [index];
  44802. }
  44803. void TreeViewItem::clearSubItems()
  44804. {
  44805. if (subItems.size() > 0)
  44806. {
  44807. if (ownerView != 0)
  44808. {
  44809. const ScopedLock sl (ownerView->nodeAlterationLock);
  44810. subItems.clear();
  44811. treeHasChanged();
  44812. }
  44813. else
  44814. {
  44815. subItems.clear();
  44816. }
  44817. }
  44818. }
  44819. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44820. {
  44821. if (newItem != 0)
  44822. {
  44823. newItem->parentItem = this;
  44824. newItem->setOwnerView (ownerView);
  44825. newItem->y = 0;
  44826. newItem->itemHeight = newItem->getItemHeight();
  44827. newItem->totalHeight = 0;
  44828. newItem->itemWidth = newItem->getItemWidth();
  44829. newItem->totalWidth = 0;
  44830. if (ownerView != 0)
  44831. {
  44832. const ScopedLock sl (ownerView->nodeAlterationLock);
  44833. subItems.insert (insertPosition, newItem);
  44834. treeHasChanged();
  44835. if (newItem->isOpen())
  44836. newItem->itemOpennessChanged (true);
  44837. }
  44838. else
  44839. {
  44840. subItems.insert (insertPosition, newItem);
  44841. if (newItem->isOpen())
  44842. newItem->itemOpennessChanged (true);
  44843. }
  44844. }
  44845. }
  44846. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44847. {
  44848. if (ownerView != 0)
  44849. {
  44850. const ScopedLock sl (ownerView->nodeAlterationLock);
  44851. if (((unsigned int) index) < (unsigned int) subItems.size())
  44852. {
  44853. subItems.remove (index, deleteItem);
  44854. treeHasChanged();
  44855. }
  44856. }
  44857. else
  44858. {
  44859. subItems.remove (index, deleteItem);
  44860. }
  44861. }
  44862. bool TreeViewItem::isOpen() const throw()
  44863. {
  44864. if (openness == opennessDefault)
  44865. return ownerView != 0 && ownerView->defaultOpenness;
  44866. else
  44867. return openness == opennessOpen;
  44868. }
  44869. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44870. {
  44871. if (isOpen() != shouldBeOpen)
  44872. {
  44873. openness = shouldBeOpen ? opennessOpen
  44874. : opennessClosed;
  44875. treeHasChanged();
  44876. itemOpennessChanged (isOpen());
  44877. }
  44878. }
  44879. bool TreeViewItem::isSelected() const throw()
  44880. {
  44881. return selected;
  44882. }
  44883. void TreeViewItem::deselectAllRecursively()
  44884. {
  44885. setSelected (false, false);
  44886. for (int i = 0; i < subItems.size(); ++i)
  44887. subItems.getUnchecked(i)->deselectAllRecursively();
  44888. }
  44889. void TreeViewItem::setSelected (const bool shouldBeSelected,
  44890. const bool deselectOtherItemsFirst)
  44891. {
  44892. if (shouldBeSelected && ! canBeSelected())
  44893. return;
  44894. if (deselectOtherItemsFirst)
  44895. getTopLevelItem()->deselectAllRecursively();
  44896. if (shouldBeSelected != selected)
  44897. {
  44898. selected = shouldBeSelected;
  44899. if (ownerView != 0)
  44900. ownerView->repaint();
  44901. itemSelectionChanged (shouldBeSelected);
  44902. }
  44903. }
  44904. void TreeViewItem::paintItem (Graphics&, int, int)
  44905. {
  44906. }
  44907. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  44908. {
  44909. ownerView->getLookAndFeel()
  44910. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  44911. }
  44912. void TreeViewItem::itemClicked (const MouseEvent&)
  44913. {
  44914. }
  44915. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  44916. {
  44917. if (mightContainSubItems())
  44918. setOpen (! isOpen());
  44919. }
  44920. void TreeViewItem::itemSelectionChanged (bool)
  44921. {
  44922. }
  44923. const String TreeViewItem::getTooltip()
  44924. {
  44925. return String::empty;
  44926. }
  44927. const String TreeViewItem::getDragSourceDescription()
  44928. {
  44929. return String::empty;
  44930. }
  44931. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  44932. {
  44933. return false;
  44934. }
  44935. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  44936. {
  44937. }
  44938. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44939. {
  44940. return false;
  44941. }
  44942. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  44943. {
  44944. }
  44945. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  44946. {
  44947. const int indentX = getIndentX();
  44948. int width = itemWidth;
  44949. if (ownerView != 0 && width < 0)
  44950. width = ownerView->viewport->getViewWidth() - indentX;
  44951. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  44952. if (relativeToTreeViewTopLeft)
  44953. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  44954. r.getY() - ownerView->viewport->getViewPositionY());
  44955. return r;
  44956. }
  44957. void TreeViewItem::treeHasChanged() const throw()
  44958. {
  44959. if (ownerView != 0)
  44960. ownerView->itemsChanged();
  44961. }
  44962. void TreeViewItem::repaintItem() const
  44963. {
  44964. if (ownerView != 0 && areAllParentsOpen())
  44965. {
  44966. const Rectangle<int> r (getItemPosition (true));
  44967. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  44968. }
  44969. }
  44970. bool TreeViewItem::areAllParentsOpen() const throw()
  44971. {
  44972. return parentItem == 0
  44973. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  44974. }
  44975. void TreeViewItem::updatePositions (int newY)
  44976. {
  44977. y = newY;
  44978. itemHeight = getItemHeight();
  44979. totalHeight = itemHeight;
  44980. itemWidth = getItemWidth();
  44981. totalWidth = jmax (itemWidth, 0) + getIndentX();
  44982. if (isOpen())
  44983. {
  44984. newY += totalHeight;
  44985. for (int i = 0; i < subItems.size(); ++i)
  44986. {
  44987. TreeViewItem* const ti = subItems.getUnchecked(i);
  44988. ti->updatePositions (newY);
  44989. newY += ti->totalHeight;
  44990. totalHeight += ti->totalHeight;
  44991. totalWidth = jmax (totalWidth, ti->totalWidth);
  44992. }
  44993. }
  44994. }
  44995. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  44996. {
  44997. TreeViewItem* result = this;
  44998. TreeViewItem* item = this;
  44999. while (item->parentItem != 0)
  45000. {
  45001. item = item->parentItem;
  45002. if (! item->isOpen())
  45003. result = item;
  45004. }
  45005. return result;
  45006. }
  45007. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45008. {
  45009. ownerView = newOwner;
  45010. for (int i = subItems.size(); --i >= 0;)
  45011. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45012. }
  45013. int TreeViewItem::getIndentX() const throw()
  45014. {
  45015. const int indentWidth = ownerView->getIndentSize();
  45016. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45017. if (! ownerView->openCloseButtonsVisible)
  45018. x -= indentWidth;
  45019. TreeViewItem* p = parentItem;
  45020. while (p != 0)
  45021. {
  45022. x += indentWidth;
  45023. p = p->parentItem;
  45024. }
  45025. return x;
  45026. }
  45027. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45028. {
  45029. drawsInLeftMargin = canDrawInLeftMargin;
  45030. }
  45031. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45032. {
  45033. jassert (ownerView != 0);
  45034. if (ownerView == 0)
  45035. return;
  45036. const int indent = getIndentX();
  45037. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45038. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45039. const float halfH = itemHeight * 0.5f;
  45040. int depth = 0;
  45041. TreeViewItem* p = parentItem;
  45042. while (p != 0)
  45043. {
  45044. ++depth;
  45045. p = p->parentItem;
  45046. }
  45047. if (! ownerView->rootItemVisible)
  45048. --depth;
  45049. const int indentWidth = ownerView->getIndentSize();
  45050. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45051. {
  45052. float x = (depth + 0.5f) * indentWidth;
  45053. if (depth >= 0)
  45054. {
  45055. if (parentItem != 0 && parentItem->drawLinesInside)
  45056. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45057. if ((parentItem != 0 && parentItem->drawLinesInside)
  45058. || (parentItem == 0 && drawLinesInside))
  45059. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45060. }
  45061. p = parentItem;
  45062. int d = depth;
  45063. while (p != 0 && --d >= 0)
  45064. {
  45065. x -= (float) indentWidth;
  45066. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45067. && ! p->isLastOfSiblings())
  45068. {
  45069. g.drawLine (x, 0, x, (float) itemHeight);
  45070. }
  45071. p = p->parentItem;
  45072. }
  45073. if (mightContainSubItems())
  45074. {
  45075. g.saveState();
  45076. g.setOrigin (depth * indentWidth, 0);
  45077. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45078. paintOpenCloseButton (g, indentWidth, itemHeight,
  45079. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45080. ->isMouseOverButton (this));
  45081. g.restoreState();
  45082. }
  45083. }
  45084. {
  45085. g.saveState();
  45086. g.setOrigin (indent, 0);
  45087. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45088. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45089. paintItem (g, itemW, itemHeight);
  45090. g.restoreState();
  45091. }
  45092. if (isOpen())
  45093. {
  45094. const Rectangle<int> clip (g.getClipBounds());
  45095. for (int i = 0; i < subItems.size(); ++i)
  45096. {
  45097. TreeViewItem* const ti = subItems.getUnchecked(i);
  45098. const int relY = ti->y - y;
  45099. if (relY >= clip.getBottom())
  45100. break;
  45101. if (relY + ti->totalHeight >= clip.getY())
  45102. {
  45103. g.saveState();
  45104. g.setOrigin (0, relY);
  45105. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45106. ti->paintRecursively (g, width);
  45107. g.restoreState();
  45108. }
  45109. }
  45110. }
  45111. }
  45112. bool TreeViewItem::isLastOfSiblings() const throw()
  45113. {
  45114. return parentItem == 0
  45115. || parentItem->subItems.getLast() == this;
  45116. }
  45117. int TreeViewItem::getIndexInParent() const throw()
  45118. {
  45119. if (parentItem == 0)
  45120. return 0;
  45121. return parentItem->subItems.indexOf (this);
  45122. }
  45123. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45124. {
  45125. return (parentItem == 0) ? this
  45126. : parentItem->getTopLevelItem();
  45127. }
  45128. int TreeViewItem::getNumRows() const throw()
  45129. {
  45130. int num = 1;
  45131. if (isOpen())
  45132. {
  45133. for (int i = subItems.size(); --i >= 0;)
  45134. num += subItems.getUnchecked(i)->getNumRows();
  45135. }
  45136. return num;
  45137. }
  45138. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45139. {
  45140. if (index == 0)
  45141. return this;
  45142. if (index > 0 && isOpen())
  45143. {
  45144. --index;
  45145. for (int i = 0; i < subItems.size(); ++i)
  45146. {
  45147. TreeViewItem* const item = subItems.getUnchecked(i);
  45148. if (index == 0)
  45149. return item;
  45150. const int numRows = item->getNumRows();
  45151. if (numRows > index)
  45152. return item->getItemOnRow (index);
  45153. index -= numRows;
  45154. }
  45155. }
  45156. return 0;
  45157. }
  45158. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45159. {
  45160. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45161. {
  45162. const int h = itemHeight;
  45163. if (targetY < h)
  45164. return this;
  45165. if (isOpen())
  45166. {
  45167. targetY -= h;
  45168. for (int i = 0; i < subItems.size(); ++i)
  45169. {
  45170. TreeViewItem* const ti = subItems.getUnchecked(i);
  45171. if (targetY < ti->totalHeight)
  45172. return ti->findItemRecursively (targetY);
  45173. targetY -= ti->totalHeight;
  45174. }
  45175. }
  45176. }
  45177. return 0;
  45178. }
  45179. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45180. {
  45181. int total = 0;
  45182. if (isSelected())
  45183. ++total;
  45184. for (int i = subItems.size(); --i >= 0;)
  45185. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45186. return total;
  45187. }
  45188. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45189. {
  45190. if (isSelected())
  45191. {
  45192. if (index == 0)
  45193. return this;
  45194. --index;
  45195. }
  45196. if (index >= 0)
  45197. {
  45198. for (int i = 0; i < subItems.size(); ++i)
  45199. {
  45200. TreeViewItem* const item = subItems.getUnchecked(i);
  45201. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45202. if (found != 0)
  45203. return found;
  45204. index -= item->countSelectedItemsRecursively();
  45205. }
  45206. }
  45207. return 0;
  45208. }
  45209. int TreeViewItem::getRowNumberInTree() const throw()
  45210. {
  45211. if (parentItem != 0 && ownerView != 0)
  45212. {
  45213. int n = 1 + parentItem->getRowNumberInTree();
  45214. int ourIndex = parentItem->subItems.indexOf (this);
  45215. jassert (ourIndex >= 0);
  45216. while (--ourIndex >= 0)
  45217. n += parentItem->subItems [ourIndex]->getNumRows();
  45218. if (parentItem->parentItem == 0
  45219. && ! ownerView->rootItemVisible)
  45220. --n;
  45221. return n;
  45222. }
  45223. else
  45224. {
  45225. return 0;
  45226. }
  45227. }
  45228. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45229. {
  45230. drawLinesInside = drawLines;
  45231. }
  45232. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45233. {
  45234. if (recurse && isOpen() && subItems.size() > 0)
  45235. return subItems [0];
  45236. if (parentItem != 0)
  45237. {
  45238. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45239. if (nextIndex >= parentItem->subItems.size())
  45240. return parentItem->getNextVisibleItem (false);
  45241. return parentItem->subItems [nextIndex];
  45242. }
  45243. return 0;
  45244. }
  45245. const String TreeViewItem::getItemIdentifierString() const
  45246. {
  45247. String s;
  45248. if (parentItem != 0)
  45249. s = parentItem->getItemIdentifierString();
  45250. return s + "/" + getUniqueName().replaceCharacter ('/', '\\');
  45251. }
  45252. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45253. {
  45254. const String uid (getUniqueName());
  45255. if (uid == identifierString)
  45256. return this;
  45257. if (identifierString.startsWith (uid + "/"))
  45258. {
  45259. const String remainingPath (identifierString.substring (uid.length() + 1));
  45260. bool wasOpen = isOpen();
  45261. setOpen (true);
  45262. for (int i = subItems.size(); --i >= 0;)
  45263. {
  45264. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45265. if (item != 0)
  45266. return item;
  45267. }
  45268. setOpen (wasOpen);
  45269. }
  45270. return 0;
  45271. }
  45272. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45273. {
  45274. if (e.hasTagName ("CLOSED"))
  45275. {
  45276. setOpen (false);
  45277. }
  45278. else if (e.hasTagName ("OPEN"))
  45279. {
  45280. setOpen (true);
  45281. forEachXmlChildElement (e, n)
  45282. {
  45283. const String id (n->getStringAttribute ("id"));
  45284. for (int i = 0; i < subItems.size(); ++i)
  45285. {
  45286. TreeViewItem* const ti = subItems.getUnchecked(i);
  45287. if (ti->getUniqueName() == id)
  45288. {
  45289. ti->restoreOpennessState (*n);
  45290. break;
  45291. }
  45292. }
  45293. }
  45294. }
  45295. }
  45296. XmlElement* TreeViewItem::getOpennessState() const throw()
  45297. {
  45298. const String name (getUniqueName());
  45299. if (name.isNotEmpty())
  45300. {
  45301. XmlElement* e;
  45302. if (isOpen())
  45303. {
  45304. e = new XmlElement ("OPEN");
  45305. for (int i = 0; i < subItems.size(); ++i)
  45306. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45307. }
  45308. else
  45309. {
  45310. e = new XmlElement ("CLOSED");
  45311. }
  45312. e->setAttribute ("id", name);
  45313. return e;
  45314. }
  45315. else
  45316. {
  45317. // trying to save the openness for an element that has no name - this won't
  45318. // work because it needs the names to identify what to open.
  45319. jassertfalse
  45320. }
  45321. return 0;
  45322. }
  45323. END_JUCE_NAMESPACE
  45324. /*** End of inlined file: juce_TreeView.cpp ***/
  45325. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45326. BEGIN_JUCE_NAMESPACE
  45327. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45328. : fileList (listToShow)
  45329. {
  45330. }
  45331. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45332. {
  45333. }
  45334. FileBrowserListener::~FileBrowserListener()
  45335. {
  45336. }
  45337. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45338. {
  45339. listeners.add (listener);
  45340. }
  45341. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45342. {
  45343. listeners.remove (listener);
  45344. }
  45345. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45346. {
  45347. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45348. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45349. }
  45350. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45351. {
  45352. if (fileList.getDirectory().exists())
  45353. {
  45354. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45355. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45356. }
  45357. }
  45358. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45359. {
  45360. if (fileList.getDirectory().exists())
  45361. {
  45362. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45363. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45364. }
  45365. }
  45366. END_JUCE_NAMESPACE
  45367. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45368. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45369. BEGIN_JUCE_NAMESPACE
  45370. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45371. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45372. Time* creationTime, bool* isReadOnly);
  45373. bool juce_findFileNext (void* handle, String& resultFile,
  45374. bool* isDirectory, bool* isHidden, int64* fileSize,
  45375. Time* modTime, Time* creationTime, bool* isReadOnly);
  45376. void juce_findFileClose (void* handle);
  45377. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45378. TimeSliceThread& thread_)
  45379. : fileFilter (fileFilter_),
  45380. thread (thread_),
  45381. includeDirectories (false),
  45382. includeFiles (false),
  45383. ignoreHiddenFiles (true),
  45384. fileFindHandle (0),
  45385. shouldStop (true)
  45386. {
  45387. }
  45388. DirectoryContentsList::~DirectoryContentsList()
  45389. {
  45390. clear();
  45391. }
  45392. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45393. {
  45394. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45395. }
  45396. const File& DirectoryContentsList::getDirectory() const
  45397. {
  45398. return root;
  45399. }
  45400. void DirectoryContentsList::setDirectory (const File& directory,
  45401. const bool includeDirectories_,
  45402. const bool includeFiles_)
  45403. {
  45404. if (directory != root
  45405. || includeDirectories != includeDirectories_
  45406. || includeFiles != includeFiles_)
  45407. {
  45408. clear();
  45409. root = directory;
  45410. includeDirectories = includeDirectories_;
  45411. includeFiles = includeFiles_;
  45412. refresh();
  45413. }
  45414. }
  45415. void DirectoryContentsList::clear()
  45416. {
  45417. shouldStop = true;
  45418. thread.removeTimeSliceClient (this);
  45419. if (fileFindHandle != 0)
  45420. {
  45421. juce_findFileClose (fileFindHandle);
  45422. fileFindHandle = 0;
  45423. }
  45424. if (files.size() > 0)
  45425. {
  45426. files.clear();
  45427. changed();
  45428. }
  45429. }
  45430. void DirectoryContentsList::refresh()
  45431. {
  45432. clear();
  45433. if (root.isDirectory())
  45434. {
  45435. String fileFound;
  45436. bool fileFoundIsDir, isHidden, isReadOnly;
  45437. int64 fileSize;
  45438. Time modTime, creationTime;
  45439. String path (root.getFullPathName());
  45440. if (! path.endsWithChar (File::separator))
  45441. path += File::separator;
  45442. jassert (fileFindHandle == 0);
  45443. fileFindHandle = juce_findFileStart (path, "*", fileFound,
  45444. &fileFoundIsDir,
  45445. &isHidden,
  45446. &fileSize,
  45447. &modTime,
  45448. &creationTime,
  45449. &isReadOnly);
  45450. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45451. {
  45452. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45453. fileSize, modTime, creationTime, isReadOnly))
  45454. {
  45455. changed();
  45456. }
  45457. }
  45458. shouldStop = false;
  45459. thread.addTimeSliceClient (this);
  45460. }
  45461. }
  45462. int DirectoryContentsList::getNumFiles() const
  45463. {
  45464. return files.size();
  45465. }
  45466. bool DirectoryContentsList::getFileInfo (const int index,
  45467. FileInfo& result) const
  45468. {
  45469. const ScopedLock sl (fileListLock);
  45470. const FileInfo* const info = files [index];
  45471. if (info != 0)
  45472. {
  45473. result = *info;
  45474. return true;
  45475. }
  45476. return false;
  45477. }
  45478. const File DirectoryContentsList::getFile (const int index) const
  45479. {
  45480. const ScopedLock sl (fileListLock);
  45481. const FileInfo* const info = files [index];
  45482. if (info != 0)
  45483. return root.getChildFile (info->filename);
  45484. return File::nonexistent;
  45485. }
  45486. bool DirectoryContentsList::isStillLoading() const
  45487. {
  45488. return fileFindHandle != 0;
  45489. }
  45490. void DirectoryContentsList::changed()
  45491. {
  45492. sendChangeMessage (this);
  45493. }
  45494. bool DirectoryContentsList::useTimeSlice()
  45495. {
  45496. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45497. bool hasChanged = false;
  45498. for (int i = 100; --i >= 0;)
  45499. {
  45500. if (! checkNextFile (hasChanged))
  45501. {
  45502. if (hasChanged)
  45503. changed();
  45504. return false;
  45505. }
  45506. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45507. break;
  45508. }
  45509. if (hasChanged)
  45510. changed();
  45511. return true;
  45512. }
  45513. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45514. {
  45515. if (fileFindHandle != 0)
  45516. {
  45517. String fileFound;
  45518. bool fileFoundIsDir, isHidden, isReadOnly;
  45519. int64 fileSize;
  45520. Time modTime, creationTime;
  45521. if (juce_findFileNext (fileFindHandle, fileFound,
  45522. &fileFoundIsDir, &isHidden,
  45523. &fileSize,
  45524. &modTime,
  45525. &creationTime,
  45526. &isReadOnly))
  45527. {
  45528. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45529. modTime, creationTime, isReadOnly))
  45530. {
  45531. hasChanged = true;
  45532. }
  45533. return true;
  45534. }
  45535. else
  45536. {
  45537. juce_findFileClose (fileFindHandle);
  45538. fileFindHandle = 0;
  45539. }
  45540. }
  45541. return false;
  45542. }
  45543. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45544. const DirectoryContentsList::FileInfo* const second)
  45545. {
  45546. #if JUCE_WINDOWS
  45547. if (first->isDirectory != second->isDirectory)
  45548. return first->isDirectory ? -1 : 1;
  45549. #endif
  45550. return first->filename.compareIgnoreCase (second->filename);
  45551. }
  45552. bool DirectoryContentsList::addFile (const String& filename,
  45553. const bool isDir,
  45554. const bool isHidden,
  45555. const int64 fileSize,
  45556. const Time& modTime,
  45557. const Time& creationTime,
  45558. const bool isReadOnly)
  45559. {
  45560. if (filename == ".."
  45561. || filename == "."
  45562. || (ignoreHiddenFiles && isHidden))
  45563. return false;
  45564. const File file (root.getChildFile (filename));
  45565. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45566. && (fileFilter == 0
  45567. || ((! isDir) && fileFilter->isFileSuitable (file))
  45568. || (isDir && fileFilter->isDirectorySuitable (file))))
  45569. {
  45570. ScopedPointer <FileInfo> info (new FileInfo());
  45571. info->filename = filename;
  45572. info->fileSize = fileSize;
  45573. info->modificationTime = modTime;
  45574. info->creationTime = creationTime;
  45575. info->isDirectory = isDir;
  45576. info->isReadOnly = isReadOnly;
  45577. const ScopedLock sl (fileListLock);
  45578. for (int i = files.size(); --i >= 0;)
  45579. if (files.getUnchecked(i)->filename == info->filename)
  45580. return false;
  45581. files.addSorted (*this, info.release());
  45582. return true;
  45583. }
  45584. return false;
  45585. }
  45586. END_JUCE_NAMESPACE
  45587. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45588. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45589. BEGIN_JUCE_NAMESPACE
  45590. FileBrowserComponent::FileBrowserComponent (int flags_,
  45591. const File& initialFileOrDirectory,
  45592. const FileFilter* fileFilter_,
  45593. FilePreviewComponent* previewComp_)
  45594. : FileFilter (String::empty),
  45595. fileFilter (fileFilter_),
  45596. flags (flags_),
  45597. previewComp (previewComp_),
  45598. thread ("Juce FileBrowser")
  45599. {
  45600. // You need to specify one or other of the open/save flags..
  45601. jassert ((flags & (saveMode | openMode)) != 0);
  45602. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45603. // You need to specify at least one of these flags..
  45604. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45605. String filename;
  45606. if (initialFileOrDirectory == File::nonexistent)
  45607. {
  45608. currentRoot = File::getCurrentWorkingDirectory();
  45609. }
  45610. else if (initialFileOrDirectory.isDirectory())
  45611. {
  45612. currentRoot = initialFileOrDirectory;
  45613. }
  45614. else
  45615. {
  45616. chosenFiles.add (initialFileOrDirectory);
  45617. currentRoot = initialFileOrDirectory.getParentDirectory();
  45618. filename = initialFileOrDirectory.getFileName();
  45619. }
  45620. fileList = new DirectoryContentsList (this, thread);
  45621. if ((flags & useTreeView) != 0)
  45622. {
  45623. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45624. if ((flags & canSelectMultipleItems) != 0)
  45625. tree->setMultiSelectEnabled (true);
  45626. addAndMakeVisible (tree);
  45627. fileListComponent = tree;
  45628. }
  45629. else
  45630. {
  45631. FileListComponent* const list = new FileListComponent (*fileList);
  45632. list->setOutlineThickness (1);
  45633. if ((flags & canSelectMultipleItems) != 0)
  45634. list->setMultipleSelectionEnabled (true);
  45635. addAndMakeVisible (list);
  45636. fileListComponent = list;
  45637. }
  45638. fileListComponent->addListener (this);
  45639. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45640. currentPathBox->setEditableText (true);
  45641. StringArray rootNames, rootPaths;
  45642. const BigInteger separators (getRoots (rootNames, rootPaths));
  45643. for (int i = 0; i < rootNames.size(); ++i)
  45644. {
  45645. if (separators [i])
  45646. currentPathBox->addSeparator();
  45647. currentPathBox->addItem (rootNames[i], i + 1);
  45648. }
  45649. currentPathBox->addSeparator();
  45650. currentPathBox->addListener (this);
  45651. addAndMakeVisible (filenameBox = new TextEditor());
  45652. filenameBox->setMultiLine (false);
  45653. filenameBox->setSelectAllWhenFocused (true);
  45654. filenameBox->setText (filename, false);
  45655. filenameBox->addListener (this);
  45656. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45657. Label* label = new Label ("f", TRANS("file:"));
  45658. addAndMakeVisible (label);
  45659. label->attachToComponent (filenameBox, true);
  45660. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45661. goUpButton->addButtonListener (this);
  45662. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45663. if (previewComp != 0)
  45664. addAndMakeVisible (previewComp);
  45665. setRoot (currentRoot);
  45666. thread.startThread (4);
  45667. }
  45668. FileBrowserComponent::~FileBrowserComponent()
  45669. {
  45670. if (previewComp != 0)
  45671. removeChildComponent (previewComp);
  45672. deleteAllChildren();
  45673. fileList = 0;
  45674. thread.stopThread (10000);
  45675. }
  45676. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  45677. {
  45678. listeners.add (newListener);
  45679. }
  45680. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  45681. {
  45682. listeners.remove (listener);
  45683. }
  45684. bool FileBrowserComponent::isSaveMode() const throw()
  45685. {
  45686. return (flags & saveMode) != 0;
  45687. }
  45688. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45689. {
  45690. if (chosenFiles.size() == 0 && currentFileIsValid())
  45691. return 1;
  45692. return chosenFiles.size();
  45693. }
  45694. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45695. {
  45696. if (! filenameBox->isReadOnly())
  45697. return currentRoot.getChildFile (filenameBox->getText());
  45698. else
  45699. return chosenFiles[index];
  45700. }
  45701. bool FileBrowserComponent::currentFileIsValid() const
  45702. {
  45703. if (isSaveMode())
  45704. return ! getSelectedFile (0).isDirectory();
  45705. else
  45706. return getSelectedFile (0).exists();
  45707. }
  45708. const File FileBrowserComponent::getHighlightedFile() const throw()
  45709. {
  45710. return fileListComponent->getSelectedFile (0);
  45711. }
  45712. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45713. {
  45714. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45715. : false;
  45716. }
  45717. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45718. {
  45719. return true;
  45720. }
  45721. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45722. {
  45723. if (f.isDirectory())
  45724. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45725. return (flags & canSelectFiles) != 0 && f.exists()
  45726. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45727. }
  45728. const File FileBrowserComponent::getRoot() const
  45729. {
  45730. return currentRoot;
  45731. }
  45732. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45733. {
  45734. if (currentRoot != newRootDirectory)
  45735. {
  45736. fileListComponent->scrollToTop();
  45737. String path (newRootDirectory.getFullPathName());
  45738. if (path.isEmpty())
  45739. path += File::separator;
  45740. StringArray rootNames, rootPaths;
  45741. getRoots (rootNames, rootPaths);
  45742. if (! rootPaths.contains (path, true))
  45743. {
  45744. bool alreadyListed = false;
  45745. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45746. {
  45747. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45748. {
  45749. alreadyListed = true;
  45750. break;
  45751. }
  45752. }
  45753. if (! alreadyListed)
  45754. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45755. }
  45756. }
  45757. currentRoot = newRootDirectory;
  45758. fileList->setDirectory (currentRoot, true, true);
  45759. String currentRootName (currentRoot.getFullPathName());
  45760. if (currentRootName.isEmpty())
  45761. currentRootName += File::separator;
  45762. currentPathBox->setText (currentRootName, true);
  45763. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45764. && currentRoot.getParentDirectory() != currentRoot);
  45765. }
  45766. void FileBrowserComponent::goUp()
  45767. {
  45768. setRoot (getRoot().getParentDirectory());
  45769. }
  45770. void FileBrowserComponent::refresh()
  45771. {
  45772. fileList->refresh();
  45773. }
  45774. const String FileBrowserComponent::getActionVerb() const
  45775. {
  45776. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45777. }
  45778. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45779. {
  45780. return previewComp;
  45781. }
  45782. void FileBrowserComponent::resized()
  45783. {
  45784. getLookAndFeel()
  45785. .layoutFileBrowserComponent (*this, fileListComponent,
  45786. previewComp, currentPathBox,
  45787. filenameBox, goUpButton);
  45788. }
  45789. void FileBrowserComponent::sendListenerChangeMessage()
  45790. {
  45791. Component::BailOutChecker checker (this);
  45792. if (previewComp != 0)
  45793. previewComp->selectedFileChanged (getSelectedFile (0));
  45794. // You shouldn't delete the browser when the file gets changed!
  45795. jassert (! checker.shouldBailOut());
  45796. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45797. }
  45798. void FileBrowserComponent::selectionChanged()
  45799. {
  45800. StringArray newFilenames;
  45801. bool resetChosenFiles = true;
  45802. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45803. {
  45804. const File f (fileListComponent->getSelectedFile (i));
  45805. if (isFileOrDirSuitable (f))
  45806. {
  45807. if (resetChosenFiles)
  45808. {
  45809. chosenFiles.clear();
  45810. resetChosenFiles = false;
  45811. }
  45812. chosenFiles.add (f);
  45813. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45814. }
  45815. }
  45816. if (newFilenames.size() > 0)
  45817. filenameBox->setText (newFilenames.joinIntoString (", "), false);
  45818. sendListenerChangeMessage();
  45819. }
  45820. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45821. {
  45822. Component::BailOutChecker checker (this);
  45823. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45824. }
  45825. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45826. {
  45827. if (f.isDirectory())
  45828. {
  45829. setRoot (f);
  45830. }
  45831. else
  45832. {
  45833. Component::BailOutChecker checker (this);
  45834. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45835. }
  45836. }
  45837. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45838. {
  45839. #if JUCE_LINUX || JUCE_WINDOWS
  45840. if (key.getModifiers().isCommandDown()
  45841. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45842. {
  45843. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45844. fileList->refresh();
  45845. return true;
  45846. }
  45847. #endif
  45848. return false;
  45849. }
  45850. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45851. {
  45852. sendListenerChangeMessage();
  45853. }
  45854. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45855. {
  45856. if (filenameBox->getText().containsChar (File::separator))
  45857. {
  45858. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45859. if (f.isDirectory())
  45860. {
  45861. setRoot (f);
  45862. chosenFiles.clear();
  45863. filenameBox->setText (String::empty);
  45864. }
  45865. else
  45866. {
  45867. setRoot (f.getParentDirectory());
  45868. chosenFiles.clear();
  45869. chosenFiles.add (f);
  45870. filenameBox->setText (f.getFileName());
  45871. }
  45872. }
  45873. else
  45874. {
  45875. fileDoubleClicked (getSelectedFile (0));
  45876. }
  45877. }
  45878. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45879. {
  45880. }
  45881. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  45882. {
  45883. if (! isSaveMode())
  45884. selectionChanged();
  45885. }
  45886. void FileBrowserComponent::buttonClicked (Button*)
  45887. {
  45888. goUp();
  45889. }
  45890. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  45891. {
  45892. const String newText (currentPathBox->getText().trim().unquoted());
  45893. if (newText.isNotEmpty())
  45894. {
  45895. const int index = currentPathBox->getSelectedId() - 1;
  45896. StringArray rootNames, rootPaths;
  45897. getRoots (rootNames, rootPaths);
  45898. if (rootPaths [index].isNotEmpty())
  45899. {
  45900. setRoot (File (rootPaths [index]));
  45901. }
  45902. else
  45903. {
  45904. File f (newText);
  45905. for (;;)
  45906. {
  45907. if (f.isDirectory())
  45908. {
  45909. setRoot (f);
  45910. break;
  45911. }
  45912. if (f.getParentDirectory() == f)
  45913. break;
  45914. f = f.getParentDirectory();
  45915. }
  45916. }
  45917. }
  45918. }
  45919. const BigInteger FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  45920. {
  45921. BigInteger separators;
  45922. #if JUCE_WINDOWS
  45923. Array<File> roots;
  45924. File::findFileSystemRoots (roots);
  45925. rootPaths.clear();
  45926. for (int i = 0; i < roots.size(); ++i)
  45927. {
  45928. const File& drive = roots.getReference(i);
  45929. String name (drive.getFullPathName());
  45930. rootPaths.add (name);
  45931. if (drive.isOnHardDisk())
  45932. {
  45933. String volume (drive.getVolumeLabel());
  45934. if (volume.isEmpty())
  45935. volume = TRANS("Hard Drive");
  45936. name << " [" << drive.getVolumeLabel() << ']';
  45937. }
  45938. else if (drive.isOnCDRomDrive())
  45939. {
  45940. name << TRANS(" [CD/DVD drive]");
  45941. }
  45942. rootNames.add (name);
  45943. }
  45944. separators.setBit (rootPaths.size());
  45945. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45946. rootNames.add ("Documents");
  45947. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45948. rootNames.add ("Desktop");
  45949. #endif
  45950. #if JUCE_MAC
  45951. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45952. rootNames.add ("Home folder");
  45953. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45954. rootNames.add ("Documents");
  45955. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45956. rootNames.add ("Desktop");
  45957. separators.setBit (rootPaths.size());
  45958. Array <File> volumes;
  45959. File vol ("/Volumes");
  45960. vol.findChildFiles (volumes, File::findDirectories, false);
  45961. for (int i = 0; i < volumes.size(); ++i)
  45962. {
  45963. const File& volume = volumes.getReference(i);
  45964. if (volume.isDirectory() && ! volume.getFileName().startsWithChar ('.'))
  45965. {
  45966. rootPaths.add (volume.getFullPathName());
  45967. rootNames.add (volume.getFileName());
  45968. }
  45969. }
  45970. #endif
  45971. #if JUCE_LINUX
  45972. rootPaths.add ("/");
  45973. rootNames.add ("/");
  45974. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45975. rootNames.add ("Home folder");
  45976. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45977. rootNames.add ("Desktop");
  45978. #endif
  45979. return separators;
  45980. }
  45981. END_JUCE_NAMESPACE
  45982. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  45983. /*** Start of inlined file: juce_FileChooser.cpp ***/
  45984. BEGIN_JUCE_NAMESPACE
  45985. FileChooser::FileChooser (const String& chooserBoxTitle,
  45986. const File& currentFileOrDirectory,
  45987. const String& fileFilters,
  45988. const bool useNativeDialogBox_)
  45989. : title (chooserBoxTitle),
  45990. filters (fileFilters),
  45991. startingFile (currentFileOrDirectory),
  45992. useNativeDialogBox (useNativeDialogBox_)
  45993. {
  45994. #if JUCE_LINUX
  45995. useNativeDialogBox = false;
  45996. #endif
  45997. if (! fileFilters.containsNonWhitespaceChars())
  45998. filters = "*";
  45999. }
  46000. FileChooser::~FileChooser()
  46001. {
  46002. }
  46003. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46004. {
  46005. return showDialog (false, true, false, false, false, previewComponent);
  46006. }
  46007. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46008. {
  46009. return showDialog (false, true, false, false, true, previewComponent);
  46010. }
  46011. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46012. {
  46013. return showDialog (true, true, false, false, true, previewComponent);
  46014. }
  46015. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46016. {
  46017. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46018. }
  46019. bool FileChooser::browseForDirectory()
  46020. {
  46021. return showDialog (true, false, false, false, false, 0);
  46022. }
  46023. const File FileChooser::getResult() const
  46024. {
  46025. // if you've used a multiple-file select, you should use the getResults() method
  46026. // to retrieve all the files that were chosen.
  46027. jassert (results.size() <= 1);
  46028. return results.getFirst();
  46029. }
  46030. const Array<File>& FileChooser::getResults() const
  46031. {
  46032. return results;
  46033. }
  46034. bool FileChooser::showDialog (const bool selectsDirectories,
  46035. const bool selectsFiles,
  46036. const bool isSave,
  46037. const bool warnAboutOverwritingExistingFiles,
  46038. const bool selectMultipleFiles,
  46039. FilePreviewComponent* const previewComponent)
  46040. {
  46041. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  46042. results.clear();
  46043. // the preview component needs to be the right size before you pass it in here..
  46044. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46045. && previewComponent->getHeight() > 10));
  46046. #if JUCE_WINDOWS
  46047. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46048. #elif JUCE_MAC
  46049. if (useNativeDialogBox && (previewComponent == 0))
  46050. #else
  46051. if (false)
  46052. #endif
  46053. {
  46054. showPlatformDialog (results, title, startingFile, filters,
  46055. selectsDirectories, selectsFiles, isSave,
  46056. warnAboutOverwritingExistingFiles,
  46057. selectMultipleFiles,
  46058. previewComponent);
  46059. }
  46060. else
  46061. {
  46062. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46063. selectsDirectories ? "*" : String::empty,
  46064. String::empty);
  46065. int flags = isSave ? FileBrowserComponent::saveMode
  46066. : FileBrowserComponent::openMode;
  46067. if (selectsFiles)
  46068. flags |= FileBrowserComponent::canSelectFiles;
  46069. if (selectsDirectories)
  46070. flags |= FileBrowserComponent::canSelectDirectories;
  46071. if (selectMultipleFiles)
  46072. flags |= FileBrowserComponent::canSelectMultipleItems;
  46073. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46074. FileChooserDialogBox box (title, String::empty,
  46075. browserComponent,
  46076. warnAboutOverwritingExistingFiles,
  46077. browserComponent.findColour (AlertWindow::backgroundColourId));
  46078. if (box.show())
  46079. {
  46080. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46081. results.add (browserComponent.getSelectedFile (i));
  46082. }
  46083. }
  46084. if (previouslyFocused != 0)
  46085. previouslyFocused->grabKeyboardFocus();
  46086. return results.size() > 0;
  46087. }
  46088. FilePreviewComponent::FilePreviewComponent()
  46089. {
  46090. }
  46091. FilePreviewComponent::~FilePreviewComponent()
  46092. {
  46093. }
  46094. END_JUCE_NAMESPACE
  46095. /*** End of inlined file: juce_FileChooser.cpp ***/
  46096. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46097. BEGIN_JUCE_NAMESPACE
  46098. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46099. const String& instructions,
  46100. FileBrowserComponent& chooserComponent,
  46101. const bool warnAboutOverwritingExistingFiles_,
  46102. const Colour& backgroundColour)
  46103. : ResizableWindow (name, backgroundColour, true),
  46104. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46105. {
  46106. content = new ContentComponent();
  46107. content->setName (name);
  46108. content->instructions = instructions;
  46109. content->chooserComponent = &chooserComponent;
  46110. content->addAndMakeVisible (&chooserComponent);
  46111. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46112. content->addAndMakeVisible (content->okButton);
  46113. content->okButton->addButtonListener (this);
  46114. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46115. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46116. content->cancelButton = new TextButton (TRANS("Cancel"));
  46117. content->addAndMakeVisible (content->cancelButton);
  46118. content->cancelButton->addButtonListener (this);
  46119. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46120. setContentComponent (content);
  46121. setResizable (true, true);
  46122. setResizeLimits (300, 300, 1200, 1000);
  46123. content->chooserComponent->addListener (this);
  46124. }
  46125. FileChooserDialogBox::~FileChooserDialogBox()
  46126. {
  46127. content->chooserComponent->removeListener (this);
  46128. }
  46129. bool FileChooserDialogBox::show (int w, int h)
  46130. {
  46131. if (w <= 0)
  46132. {
  46133. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46134. if (previewComp != 0)
  46135. w = 400 + previewComp->getWidth();
  46136. else
  46137. w = 600;
  46138. }
  46139. if (h <= 0)
  46140. h = 500;
  46141. centreWithSize (w, h);
  46142. const bool ok = (runModalLoop() != 0);
  46143. setVisible (false);
  46144. return ok;
  46145. }
  46146. void FileChooserDialogBox::buttonClicked (Button* button)
  46147. {
  46148. if (button == content->okButton)
  46149. {
  46150. if (warnAboutOverwritingExistingFiles
  46151. && content->chooserComponent->isSaveMode()
  46152. && content->chooserComponent->getSelectedFile(0).exists())
  46153. {
  46154. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46155. TRANS("File already exists"),
  46156. TRANS("There's already a file called:")
  46157. + "\n\n" + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46158. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  46159. TRANS("overwrite"),
  46160. TRANS("cancel")))
  46161. {
  46162. return;
  46163. }
  46164. }
  46165. exitModalState (1);
  46166. }
  46167. else if (button == content->cancelButton)
  46168. closeButtonPressed();
  46169. }
  46170. void FileChooserDialogBox::closeButtonPressed()
  46171. {
  46172. setVisible (false);
  46173. }
  46174. void FileChooserDialogBox::selectionChanged()
  46175. {
  46176. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46177. }
  46178. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46179. {
  46180. }
  46181. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46182. {
  46183. selectionChanged();
  46184. content->okButton->triggerClick();
  46185. }
  46186. FileChooserDialogBox::ContentComponent::ContentComponent()
  46187. {
  46188. setInterceptsMouseClicks (false, true);
  46189. }
  46190. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46191. {
  46192. delete okButton;
  46193. delete cancelButton;
  46194. }
  46195. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46196. {
  46197. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46198. text.draw (g);
  46199. }
  46200. void FileChooserDialogBox::ContentComponent::resized()
  46201. {
  46202. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46203. float left, top, right, bottom;
  46204. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46205. const int y = roundToInt (bottom) + 10;
  46206. const int buttonHeight = 26;
  46207. const int buttonY = getHeight() - buttonHeight - 8;
  46208. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46209. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46210. proportionOfWidth (0.2f), buttonHeight);
  46211. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46212. proportionOfWidth (0.2f), buttonHeight);
  46213. }
  46214. END_JUCE_NAMESPACE
  46215. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46216. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46217. BEGIN_JUCE_NAMESPACE
  46218. FileFilter::FileFilter (const String& filterDescription)
  46219. : description (filterDescription)
  46220. {
  46221. }
  46222. FileFilter::~FileFilter()
  46223. {
  46224. }
  46225. const String& FileFilter::getDescription() const throw()
  46226. {
  46227. return description;
  46228. }
  46229. END_JUCE_NAMESPACE
  46230. /*** End of inlined file: juce_FileFilter.cpp ***/
  46231. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46232. BEGIN_JUCE_NAMESPACE
  46233. Image* juce_createIconForFile (const File& file);
  46234. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46235. : ListBox (String::empty, 0),
  46236. DirectoryContentsDisplayComponent (listToShow)
  46237. {
  46238. setModel (this);
  46239. fileList.addChangeListener (this);
  46240. }
  46241. FileListComponent::~FileListComponent()
  46242. {
  46243. fileList.removeChangeListener (this);
  46244. deleteAllChildren();
  46245. }
  46246. int FileListComponent::getNumSelectedFiles() const
  46247. {
  46248. return getNumSelectedRows();
  46249. }
  46250. const File FileListComponent::getSelectedFile (int index) const
  46251. {
  46252. return fileList.getFile (getSelectedRow (index));
  46253. }
  46254. void FileListComponent::scrollToTop()
  46255. {
  46256. getVerticalScrollBar()->setCurrentRangeStart (0);
  46257. }
  46258. void FileListComponent::changeListenerCallback (void*)
  46259. {
  46260. updateContent();
  46261. if (lastDirectory != fileList.getDirectory())
  46262. {
  46263. lastDirectory = fileList.getDirectory();
  46264. deselectAllRows();
  46265. }
  46266. }
  46267. class FileListItemComponent : public Component,
  46268. public TimeSliceClient,
  46269. public AsyncUpdater
  46270. {
  46271. public:
  46272. FileListItemComponent (FileListComponent& owner_,
  46273. TimeSliceThread& thread_) throw()
  46274. : owner (owner_),
  46275. thread (thread_),
  46276. icon (0)
  46277. {
  46278. }
  46279. ~FileListItemComponent() throw()
  46280. {
  46281. thread.removeTimeSliceClient (this);
  46282. clearIcon();
  46283. }
  46284. void paint (Graphics& g)
  46285. {
  46286. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46287. file.getFileName(),
  46288. icon,
  46289. fileSize, modTime,
  46290. isDirectory, highlighted,
  46291. index);
  46292. }
  46293. void mouseDown (const MouseEvent& e)
  46294. {
  46295. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46296. owner.sendMouseClickMessage (file, e);
  46297. }
  46298. void mouseDoubleClick (const MouseEvent&)
  46299. {
  46300. owner.sendDoubleClickMessage (file);
  46301. }
  46302. void update (const File& root,
  46303. const DirectoryContentsList::FileInfo* const fileInfo,
  46304. const int index_,
  46305. const bool highlighted_) throw()
  46306. {
  46307. thread.removeTimeSliceClient (this);
  46308. if (highlighted_ != highlighted
  46309. || index_ != index)
  46310. {
  46311. index = index_;
  46312. highlighted = highlighted_;
  46313. repaint();
  46314. }
  46315. File newFile;
  46316. String newFileSize;
  46317. String newModTime;
  46318. if (fileInfo != 0)
  46319. {
  46320. newFile = root.getChildFile (fileInfo->filename);
  46321. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46322. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46323. }
  46324. if (newFile != file
  46325. || fileSize != newFileSize
  46326. || modTime != newModTime)
  46327. {
  46328. file = newFile;
  46329. fileSize = newFileSize;
  46330. modTime = newModTime;
  46331. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46332. repaint();
  46333. clearIcon();
  46334. }
  46335. if (file != File::nonexistent
  46336. && icon == 0 && ! isDirectory)
  46337. {
  46338. updateIcon (true);
  46339. if (icon == 0)
  46340. thread.addTimeSliceClient (this);
  46341. }
  46342. }
  46343. bool useTimeSlice()
  46344. {
  46345. updateIcon (false);
  46346. return false;
  46347. }
  46348. void handleAsyncUpdate()
  46349. {
  46350. repaint();
  46351. }
  46352. juce_UseDebuggingNewOperator
  46353. private:
  46354. FileListComponent& owner;
  46355. TimeSliceThread& thread;
  46356. bool highlighted;
  46357. int index;
  46358. File file;
  46359. String fileSize;
  46360. String modTime;
  46361. Image* icon;
  46362. bool isDirectory;
  46363. void clearIcon() throw()
  46364. {
  46365. ImageCache::release (icon);
  46366. icon = 0;
  46367. }
  46368. void updateIcon (const bool onlyUpdateIfCached) throw()
  46369. {
  46370. if (icon == 0)
  46371. {
  46372. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46373. Image* im = ImageCache::getFromHashCode (hashCode);
  46374. if (im == 0 && ! onlyUpdateIfCached)
  46375. {
  46376. im = juce_createIconForFile (file);
  46377. if (im != 0)
  46378. ImageCache::addImageToCache (im, hashCode);
  46379. }
  46380. if (im != 0)
  46381. {
  46382. icon = im;
  46383. triggerAsyncUpdate();
  46384. }
  46385. }
  46386. }
  46387. };
  46388. int FileListComponent::getNumRows()
  46389. {
  46390. return fileList.getNumFiles();
  46391. }
  46392. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46393. {
  46394. }
  46395. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46396. {
  46397. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46398. if (comp == 0)
  46399. {
  46400. delete existingComponentToUpdate;
  46401. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46402. }
  46403. DirectoryContentsList::FileInfo fileInfo;
  46404. if (fileList.getFileInfo (row, fileInfo))
  46405. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46406. else
  46407. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46408. return comp;
  46409. }
  46410. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46411. {
  46412. sendSelectionChangeMessage();
  46413. }
  46414. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46415. {
  46416. }
  46417. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46418. {
  46419. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46420. }
  46421. END_JUCE_NAMESPACE
  46422. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46423. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46424. BEGIN_JUCE_NAMESPACE
  46425. FilenameComponent::FilenameComponent (const String& name,
  46426. const File& currentFile,
  46427. const bool canEditFilename,
  46428. const bool isDirectory,
  46429. const bool isForSaving,
  46430. const String& fileBrowserWildcard,
  46431. const String& enforcedSuffix_,
  46432. const String& textWhenNothingSelected)
  46433. : Component (name),
  46434. maxRecentFiles (30),
  46435. isDir (isDirectory),
  46436. isSaving (isForSaving),
  46437. isFileDragOver (false),
  46438. wildcard (fileBrowserWildcard),
  46439. enforcedSuffix (enforcedSuffix_)
  46440. {
  46441. addAndMakeVisible (filenameBox = new ComboBox ("fn"));
  46442. filenameBox->setEditableText (canEditFilename);
  46443. filenameBox->addListener (this);
  46444. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46445. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46446. browseButton = 0;
  46447. setBrowseButtonText ("...");
  46448. setCurrentFile (currentFile, true);
  46449. }
  46450. FilenameComponent::~FilenameComponent()
  46451. {
  46452. deleteAllChildren();
  46453. }
  46454. void FilenameComponent::paintOverChildren (Graphics& g)
  46455. {
  46456. if (isFileDragOver)
  46457. {
  46458. g.setColour (Colours::red.withAlpha (0.2f));
  46459. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46460. }
  46461. }
  46462. void FilenameComponent::resized()
  46463. {
  46464. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46465. }
  46466. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46467. {
  46468. browseButtonText = newBrowseButtonText;
  46469. lookAndFeelChanged();
  46470. }
  46471. void FilenameComponent::lookAndFeelChanged()
  46472. {
  46473. deleteAndZero (browseButton);
  46474. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46475. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46476. resized();
  46477. browseButton->addButtonListener (this);
  46478. }
  46479. void FilenameComponent::setTooltip (const String& newTooltip)
  46480. {
  46481. SettableTooltipClient::setTooltip (newTooltip);
  46482. filenameBox->setTooltip (newTooltip);
  46483. }
  46484. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46485. {
  46486. defaultBrowseFile = newDefaultDirectory;
  46487. }
  46488. void FilenameComponent::buttonClicked (Button*)
  46489. {
  46490. FileChooser fc (TRANS("Choose a new file"),
  46491. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46492. : getCurrentFile(),
  46493. wildcard);
  46494. if (isDir ? fc.browseForDirectory()
  46495. : (isSaving ? fc.browseForFileToSave (false)
  46496. : fc.browseForFileToOpen()))
  46497. {
  46498. setCurrentFile (fc.getResult(), true);
  46499. }
  46500. }
  46501. void FilenameComponent::comboBoxChanged (ComboBox*)
  46502. {
  46503. setCurrentFile (getCurrentFile(), true);
  46504. }
  46505. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46506. {
  46507. return true;
  46508. }
  46509. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46510. {
  46511. isFileDragOver = false;
  46512. repaint();
  46513. const File f (filenames[0]);
  46514. if (f.exists() && (f.isDirectory() == isDir))
  46515. setCurrentFile (f, true);
  46516. }
  46517. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46518. {
  46519. isFileDragOver = true;
  46520. repaint();
  46521. }
  46522. void FilenameComponent::fileDragExit (const StringArray&)
  46523. {
  46524. isFileDragOver = false;
  46525. repaint();
  46526. }
  46527. const File FilenameComponent::getCurrentFile() const
  46528. {
  46529. File f (filenameBox->getText());
  46530. if (enforcedSuffix.isNotEmpty())
  46531. f = f.withFileExtension (enforcedSuffix);
  46532. return f;
  46533. }
  46534. void FilenameComponent::setCurrentFile (File newFile,
  46535. const bool addToRecentlyUsedList,
  46536. const bool sendChangeNotification)
  46537. {
  46538. if (enforcedSuffix.isNotEmpty())
  46539. newFile = newFile.withFileExtension (enforcedSuffix);
  46540. if (newFile.getFullPathName() != lastFilename)
  46541. {
  46542. lastFilename = newFile.getFullPathName();
  46543. if (addToRecentlyUsedList)
  46544. addRecentlyUsedFile (newFile);
  46545. filenameBox->setText (lastFilename, true);
  46546. if (sendChangeNotification)
  46547. triggerAsyncUpdate();
  46548. }
  46549. }
  46550. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46551. {
  46552. filenameBox->setEditableText (shouldBeEditable);
  46553. }
  46554. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46555. {
  46556. StringArray names;
  46557. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46558. names.add (filenameBox->getItemText (i));
  46559. return names;
  46560. }
  46561. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46562. {
  46563. if (filenames != getRecentlyUsedFilenames())
  46564. {
  46565. filenameBox->clear();
  46566. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46567. filenameBox->addItem (filenames[i], i + 1);
  46568. }
  46569. }
  46570. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46571. {
  46572. maxRecentFiles = jmax (1, newMaximum);
  46573. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46574. }
  46575. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46576. {
  46577. StringArray files (getRecentlyUsedFilenames());
  46578. if (file.getFullPathName().isNotEmpty())
  46579. {
  46580. files.removeString (file.getFullPathName(), true);
  46581. files.insert (0, file.getFullPathName());
  46582. setRecentlyUsedFilenames (files);
  46583. }
  46584. }
  46585. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  46586. {
  46587. listeners.add (listener);
  46588. }
  46589. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  46590. {
  46591. listeners.remove (listener);
  46592. }
  46593. void FilenameComponent::handleAsyncUpdate()
  46594. {
  46595. Component::BailOutChecker checker (this);
  46596. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46597. }
  46598. END_JUCE_NAMESPACE
  46599. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46600. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46601. BEGIN_JUCE_NAMESPACE
  46602. FileSearchPathListComponent::FileSearchPathListComponent()
  46603. {
  46604. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46605. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46606. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46607. listBox->setOutlineThickness (1);
  46608. addAndMakeVisible (addButton = new TextButton ("+"));
  46609. addButton->addButtonListener (this);
  46610. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46611. addAndMakeVisible (removeButton = new TextButton ("-"));
  46612. removeButton->addButtonListener (this);
  46613. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46614. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46615. changeButton->addButtonListener (this);
  46616. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46617. upButton->addButtonListener (this);
  46618. {
  46619. Path arrowPath;
  46620. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46621. DrawablePath arrowImage;
  46622. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46623. arrowImage.setPath (arrowPath);
  46624. ((DrawableButton*) upButton)->setImages (&arrowImage);
  46625. }
  46626. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46627. downButton->addButtonListener (this);
  46628. {
  46629. Path arrowPath;
  46630. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46631. DrawablePath arrowImage;
  46632. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46633. arrowImage.setPath (arrowPath);
  46634. ((DrawableButton*) downButton)->setImages (&arrowImage);
  46635. }
  46636. updateButtons();
  46637. }
  46638. FileSearchPathListComponent::~FileSearchPathListComponent()
  46639. {
  46640. deleteAllChildren();
  46641. }
  46642. void FileSearchPathListComponent::updateButtons() throw()
  46643. {
  46644. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46645. removeButton->setEnabled (anythingSelected);
  46646. changeButton->setEnabled (anythingSelected);
  46647. upButton->setEnabled (anythingSelected);
  46648. downButton->setEnabled (anythingSelected);
  46649. }
  46650. void FileSearchPathListComponent::changed() throw()
  46651. {
  46652. listBox->updateContent();
  46653. listBox->repaint();
  46654. updateButtons();
  46655. }
  46656. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46657. {
  46658. if (newPath.toString() != path.toString())
  46659. {
  46660. path = newPath;
  46661. changed();
  46662. }
  46663. }
  46664. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46665. {
  46666. defaultBrowseTarget = newDefaultDirectory;
  46667. }
  46668. int FileSearchPathListComponent::getNumRows()
  46669. {
  46670. return path.getNumPaths();
  46671. }
  46672. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46673. {
  46674. if (rowIsSelected)
  46675. g.fillAll (findColour (TextEditor::highlightColourId));
  46676. g.setColour (findColour (ListBox::textColourId));
  46677. Font f (height * 0.7f);
  46678. f.setHorizontalScale (0.9f);
  46679. g.setFont (f);
  46680. g.drawText (path [rowNumber].getFullPathName(),
  46681. 4, 0, width - 6, height,
  46682. Justification::centredLeft, true);
  46683. }
  46684. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46685. {
  46686. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46687. {
  46688. path.remove (row);
  46689. changed();
  46690. }
  46691. }
  46692. void FileSearchPathListComponent::returnKeyPressed (int row)
  46693. {
  46694. FileChooser chooser (TRANS("Change folder..."), path [row], "*");
  46695. if (chooser.browseForDirectory())
  46696. {
  46697. path.remove (row);
  46698. path.add (chooser.getResult(), row);
  46699. changed();
  46700. }
  46701. }
  46702. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46703. {
  46704. returnKeyPressed (row);
  46705. }
  46706. void FileSearchPathListComponent::selectedRowsChanged (int)
  46707. {
  46708. updateButtons();
  46709. }
  46710. void FileSearchPathListComponent::paint (Graphics& g)
  46711. {
  46712. g.fillAll (findColour (backgroundColourId));
  46713. }
  46714. void FileSearchPathListComponent::resized()
  46715. {
  46716. const int buttonH = 22;
  46717. const int buttonY = getHeight() - buttonH - 4;
  46718. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46719. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46720. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46721. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  46722. downButton->setSize (buttonH * 2, buttonH);
  46723. upButton->setSize (buttonH * 2, buttonH);
  46724. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46725. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46726. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46727. }
  46728. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46729. {
  46730. return true;
  46731. }
  46732. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46733. {
  46734. for (int i = filenames.size(); --i >= 0;)
  46735. {
  46736. const File f (filenames[i]);
  46737. if (f.isDirectory())
  46738. {
  46739. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46740. path.add (f, row);
  46741. changed();
  46742. }
  46743. }
  46744. }
  46745. void FileSearchPathListComponent::buttonClicked (Button* button)
  46746. {
  46747. const int currentRow = listBox->getSelectedRow();
  46748. if (button == removeButton)
  46749. {
  46750. deleteKeyPressed (currentRow);
  46751. }
  46752. else if (button == addButton)
  46753. {
  46754. File start (defaultBrowseTarget);
  46755. if (start == File::nonexistent)
  46756. start = path [0];
  46757. if (start == File::nonexistent)
  46758. start = File::getCurrentWorkingDirectory();
  46759. FileChooser chooser (TRANS("Add a folder..."), start, "*");
  46760. if (chooser.browseForDirectory())
  46761. {
  46762. path.add (chooser.getResult(), currentRow);
  46763. }
  46764. }
  46765. else if (button == changeButton)
  46766. {
  46767. returnKeyPressed (currentRow);
  46768. }
  46769. else if (button == upButton)
  46770. {
  46771. if (currentRow > 0 && currentRow < path.getNumPaths())
  46772. {
  46773. const File f (path[currentRow]);
  46774. path.remove (currentRow);
  46775. path.add (f, currentRow - 1);
  46776. listBox->selectRow (currentRow - 1);
  46777. }
  46778. }
  46779. else if (button == downButton)
  46780. {
  46781. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46782. {
  46783. const File f (path[currentRow]);
  46784. path.remove (currentRow);
  46785. path.add (f, currentRow + 1);
  46786. listBox->selectRow (currentRow + 1);
  46787. }
  46788. }
  46789. changed();
  46790. }
  46791. END_JUCE_NAMESPACE
  46792. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46793. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46794. BEGIN_JUCE_NAMESPACE
  46795. Image* juce_createIconForFile (const File& file);
  46796. class FileListTreeItem : public TreeViewItem,
  46797. public TimeSliceClient,
  46798. public AsyncUpdater,
  46799. public ChangeListener
  46800. {
  46801. public:
  46802. FileListTreeItem (FileTreeComponent& owner_,
  46803. DirectoryContentsList* const parentContentsList_,
  46804. const int indexInContentsList_,
  46805. const File& file_,
  46806. TimeSliceThread& thread_) throw()
  46807. : file (file_),
  46808. owner (owner_),
  46809. parentContentsList (parentContentsList_),
  46810. indexInContentsList (indexInContentsList_),
  46811. subContentsList (0),
  46812. canDeleteSubContentsList (false),
  46813. thread (thread_),
  46814. icon (0)
  46815. {
  46816. DirectoryContentsList::FileInfo fileInfo;
  46817. if (parentContentsList_ != 0
  46818. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46819. {
  46820. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46821. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46822. isDirectory = fileInfo.isDirectory;
  46823. }
  46824. else
  46825. {
  46826. isDirectory = true;
  46827. }
  46828. }
  46829. ~FileListTreeItem() throw()
  46830. {
  46831. thread.removeTimeSliceClient (this);
  46832. clearSubItems();
  46833. ImageCache::release (icon);
  46834. if (canDeleteSubContentsList)
  46835. delete subContentsList;
  46836. }
  46837. bool mightContainSubItems() { return isDirectory; }
  46838. const String getUniqueName() const { return file.getFullPathName(); }
  46839. int getItemHeight() const { return 22; }
  46840. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46841. void itemOpennessChanged (bool isNowOpen)
  46842. {
  46843. if (isNowOpen)
  46844. {
  46845. clearSubItems();
  46846. isDirectory = file.isDirectory();
  46847. if (isDirectory)
  46848. {
  46849. if (subContentsList == 0)
  46850. {
  46851. jassert (parentContentsList != 0);
  46852. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46853. l->setDirectory (file, true, true);
  46854. setSubContentsList (l);
  46855. canDeleteSubContentsList = true;
  46856. }
  46857. changeListenerCallback (0);
  46858. }
  46859. }
  46860. }
  46861. void setSubContentsList (DirectoryContentsList* newList) throw()
  46862. {
  46863. jassert (subContentsList == 0);
  46864. subContentsList = newList;
  46865. newList->addChangeListener (this);
  46866. }
  46867. void changeListenerCallback (void*)
  46868. {
  46869. clearSubItems();
  46870. if (isOpen() && subContentsList != 0)
  46871. {
  46872. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46873. {
  46874. FileListTreeItem* const item
  46875. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46876. addSubItem (item);
  46877. }
  46878. }
  46879. }
  46880. void paintItem (Graphics& g, int width, int height)
  46881. {
  46882. if (file != File::nonexistent)
  46883. {
  46884. updateIcon (true);
  46885. if (icon == 0)
  46886. thread.addTimeSliceClient (this);
  46887. }
  46888. owner.getLookAndFeel()
  46889. .drawFileBrowserRow (g, width, height,
  46890. file.getFileName(),
  46891. icon,
  46892. fileSize, modTime,
  46893. isDirectory, isSelected(),
  46894. indexInContentsList);
  46895. }
  46896. void itemClicked (const MouseEvent& e)
  46897. {
  46898. owner.sendMouseClickMessage (file, e);
  46899. }
  46900. void itemDoubleClicked (const MouseEvent& e)
  46901. {
  46902. TreeViewItem::itemDoubleClicked (e);
  46903. owner.sendDoubleClickMessage (file);
  46904. }
  46905. void itemSelectionChanged (bool)
  46906. {
  46907. owner.sendSelectionChangeMessage();
  46908. }
  46909. bool useTimeSlice()
  46910. {
  46911. updateIcon (false);
  46912. thread.removeTimeSliceClient (this);
  46913. return false;
  46914. }
  46915. void handleAsyncUpdate()
  46916. {
  46917. owner.repaint();
  46918. }
  46919. const File file;
  46920. juce_UseDebuggingNewOperator
  46921. private:
  46922. FileTreeComponent& owner;
  46923. DirectoryContentsList* parentContentsList;
  46924. int indexInContentsList;
  46925. DirectoryContentsList* subContentsList;
  46926. bool isDirectory, canDeleteSubContentsList;
  46927. TimeSliceThread& thread;
  46928. Image* icon;
  46929. String fileSize;
  46930. String modTime;
  46931. void updateIcon (const bool onlyUpdateIfCached) throw()
  46932. {
  46933. if (icon == 0)
  46934. {
  46935. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46936. Image* im = ImageCache::getFromHashCode (hashCode);
  46937. if (im == 0 && ! onlyUpdateIfCached)
  46938. {
  46939. im = juce_createIconForFile (file);
  46940. if (im != 0)
  46941. ImageCache::addImageToCache (im, hashCode);
  46942. }
  46943. if (im != 0)
  46944. {
  46945. icon = im;
  46946. triggerAsyncUpdate();
  46947. }
  46948. }
  46949. }
  46950. };
  46951. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  46952. : DirectoryContentsDisplayComponent (listToShow)
  46953. {
  46954. FileListTreeItem* const root
  46955. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  46956. listToShow.getTimeSliceThread());
  46957. root->setSubContentsList (&listToShow);
  46958. setRootItemVisible (false);
  46959. setRootItem (root);
  46960. }
  46961. FileTreeComponent::~FileTreeComponent()
  46962. {
  46963. deleteRootItem();
  46964. }
  46965. const File FileTreeComponent::getSelectedFile (const int index) const
  46966. {
  46967. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  46968. if (item != 0)
  46969. return item->file;
  46970. return File::nonexistent;
  46971. }
  46972. void FileTreeComponent::scrollToTop()
  46973. {
  46974. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  46975. }
  46976. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  46977. {
  46978. dragAndDropDescription = description;
  46979. }
  46980. END_JUCE_NAMESPACE
  46981. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  46982. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  46983. BEGIN_JUCE_NAMESPACE
  46984. ImagePreviewComponent::ImagePreviewComponent()
  46985. {
  46986. }
  46987. ImagePreviewComponent::~ImagePreviewComponent()
  46988. {
  46989. }
  46990. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  46991. {
  46992. const int availableW = proportionOfWidth (0.97f);
  46993. const int availableH = getHeight() - 13 * 4;
  46994. const double scale = jmin (1.0,
  46995. availableW / (double) w,
  46996. availableH / (double) h);
  46997. w = roundToInt (scale * w);
  46998. h = roundToInt (scale * h);
  46999. }
  47000. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47001. {
  47002. if (fileToLoad != file)
  47003. {
  47004. fileToLoad = file;
  47005. startTimer (100);
  47006. }
  47007. }
  47008. void ImagePreviewComponent::timerCallback()
  47009. {
  47010. stopTimer();
  47011. currentThumbnail = 0;
  47012. currentDetails = String::empty;
  47013. repaint();
  47014. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47015. if (in != 0)
  47016. {
  47017. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47018. if (format != 0)
  47019. {
  47020. currentThumbnail = format->decodeImage (*in);
  47021. if (currentThumbnail != 0)
  47022. {
  47023. int w = currentThumbnail->getWidth();
  47024. int h = currentThumbnail->getHeight();
  47025. currentDetails
  47026. << fileToLoad.getFileName() << "\n"
  47027. << format->getFormatName() << "\n"
  47028. << w << " x " << h << " pixels\n"
  47029. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47030. getThumbSize (w, h);
  47031. currentThumbnail = currentThumbnail->createCopy (w, h);
  47032. }
  47033. }
  47034. }
  47035. }
  47036. void ImagePreviewComponent::paint (Graphics& g)
  47037. {
  47038. if (currentThumbnail != 0)
  47039. {
  47040. g.setFont (13.0f);
  47041. int w = currentThumbnail->getWidth();
  47042. int h = currentThumbnail->getHeight();
  47043. getThumbSize (w, h);
  47044. const int numLines = 4;
  47045. const int totalH = 13 * numLines + h + 4;
  47046. const int y = (getHeight() - totalH) / 2;
  47047. g.drawImageWithin (currentThumbnail,
  47048. (getWidth() - w) / 2, y, w, h,
  47049. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47050. false);
  47051. g.drawFittedText (currentDetails,
  47052. 0, y + h + 4, getWidth(), 100,
  47053. Justification::centredTop, numLines);
  47054. }
  47055. }
  47056. END_JUCE_NAMESPACE
  47057. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47058. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47059. BEGIN_JUCE_NAMESPACE
  47060. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47061. const String& directoryWildcardPatterns,
  47062. const String& description_)
  47063. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47064. : (description_ + " (" + fileWildcardPatterns + ")"))
  47065. {
  47066. parse (fileWildcardPatterns, fileWildcards);
  47067. parse (directoryWildcardPatterns, directoryWildcards);
  47068. }
  47069. WildcardFileFilter::~WildcardFileFilter()
  47070. {
  47071. }
  47072. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47073. {
  47074. return match (file, fileWildcards);
  47075. }
  47076. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47077. {
  47078. return match (file, directoryWildcards);
  47079. }
  47080. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47081. {
  47082. result.addTokens (pattern.toLowerCase(), ";,", "\"'");
  47083. result.trim();
  47084. result.removeEmptyStrings();
  47085. // special case for *.*, because people use it to mean "any file", but it
  47086. // would actually ignore files with no extension.
  47087. for (int i = result.size(); --i >= 0;)
  47088. if (result[i] == "*.*")
  47089. result.set (i, "*");
  47090. }
  47091. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47092. {
  47093. const String filename (file.getFileName());
  47094. for (int i = wildcards.size(); --i >= 0;)
  47095. if (filename.matchesWildcard (wildcards[i], true))
  47096. return true;
  47097. return false;
  47098. }
  47099. END_JUCE_NAMESPACE
  47100. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47101. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47102. BEGIN_JUCE_NAMESPACE
  47103. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47104. {
  47105. }
  47106. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47107. {
  47108. }
  47109. namespace KeyboardFocusHelpers
  47110. {
  47111. // This will sort a set of components, so that they are ordered in terms of
  47112. // left-to-right and then top-to-bottom.
  47113. class ScreenPositionComparator
  47114. {
  47115. public:
  47116. ScreenPositionComparator() {}
  47117. static int compareElements (const Component* const first, const Component* const second) throw()
  47118. {
  47119. int explicitOrder1 = first->getExplicitFocusOrder();
  47120. if (explicitOrder1 <= 0)
  47121. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47122. int explicitOrder2 = second->getExplicitFocusOrder();
  47123. if (explicitOrder2 <= 0)
  47124. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47125. if (explicitOrder1 != explicitOrder2)
  47126. return explicitOrder1 - explicitOrder2;
  47127. const int diff = first->getY() - second->getY();
  47128. return (diff == 0) ? first->getX() - second->getX()
  47129. : diff;
  47130. }
  47131. };
  47132. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47133. {
  47134. if (parent->getNumChildComponents() > 0)
  47135. {
  47136. Array <Component*> localComps;
  47137. ScreenPositionComparator comparator;
  47138. int i;
  47139. for (i = parent->getNumChildComponents(); --i >= 0;)
  47140. {
  47141. Component* const c = parent->getChildComponent (i);
  47142. if (c->isVisible() && c->isEnabled())
  47143. localComps.addSorted (comparator, c);
  47144. }
  47145. for (i = 0; i < localComps.size(); ++i)
  47146. {
  47147. Component* const c = localComps.getUnchecked (i);
  47148. if (c->getWantsKeyboardFocus())
  47149. comps.add (c);
  47150. if (! c->isFocusContainer())
  47151. findAllFocusableComponents (c, comps);
  47152. }
  47153. }
  47154. }
  47155. }
  47156. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47157. {
  47158. Component* focusContainer = current->getParentComponent();
  47159. if (focusContainer != 0)
  47160. {
  47161. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47162. focusContainer = focusContainer->getParentComponent();
  47163. if (focusContainer != 0)
  47164. {
  47165. Array <Component*> comps;
  47166. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47167. if (comps.size() > 0)
  47168. {
  47169. const int index = comps.indexOf (current);
  47170. return comps [(index + comps.size() + delta) % comps.size()];
  47171. }
  47172. }
  47173. }
  47174. return 0;
  47175. }
  47176. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47177. {
  47178. return getIncrementedComponent (current, 1);
  47179. }
  47180. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47181. {
  47182. return getIncrementedComponent (current, -1);
  47183. }
  47184. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47185. {
  47186. Array <Component*> comps;
  47187. if (parentComponent != 0)
  47188. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47189. return comps.getFirst();
  47190. }
  47191. END_JUCE_NAMESPACE
  47192. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47193. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47194. BEGIN_JUCE_NAMESPACE
  47195. bool KeyListener::keyStateChanged (const bool, Component*)
  47196. {
  47197. return false;
  47198. }
  47199. END_JUCE_NAMESPACE
  47200. /*** End of inlined file: juce_KeyListener.cpp ***/
  47201. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47202. BEGIN_JUCE_NAMESPACE
  47203. // N.B. these two includes are put here deliberately to avoid problems with
  47204. // old GCCs failing on long include paths
  47205. const int maxKeys = 3;
  47206. class KeyMappingChangeButton : public Button
  47207. {
  47208. public:
  47209. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47210. const CommandID commandID_,
  47211. const String& keyName,
  47212. const int keyNum_)
  47213. : Button (keyName),
  47214. owner (owner_),
  47215. commandID (commandID_),
  47216. keyNum (keyNum_)
  47217. {
  47218. setWantsKeyboardFocus (false);
  47219. setTriggeredOnMouseDown (keyNum >= 0);
  47220. if (keyNum_ < 0)
  47221. setTooltip (TRANS("adds a new key-mapping"));
  47222. else
  47223. setTooltip (TRANS("click to change this key-mapping"));
  47224. }
  47225. ~KeyMappingChangeButton()
  47226. {
  47227. }
  47228. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47229. {
  47230. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47231. keyNum >= 0 ? getName() : String::empty);
  47232. }
  47233. void clicked()
  47234. {
  47235. if (keyNum >= 0)
  47236. {
  47237. // existing key clicked..
  47238. PopupMenu m;
  47239. m.addItem (1, TRANS("change this key-mapping"));
  47240. m.addSeparator();
  47241. m.addItem (2, TRANS("remove this key-mapping"));
  47242. const int res = m.show();
  47243. if (res == 1)
  47244. {
  47245. owner->assignNewKey (commandID, keyNum);
  47246. }
  47247. else if (res == 2)
  47248. {
  47249. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47250. }
  47251. }
  47252. else
  47253. {
  47254. // + button pressed..
  47255. owner->assignNewKey (commandID, -1);
  47256. }
  47257. }
  47258. void fitToContent (const int h) throw()
  47259. {
  47260. if (keyNum < 0)
  47261. {
  47262. setSize (h, h);
  47263. }
  47264. else
  47265. {
  47266. Font f (h * 0.6f);
  47267. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47268. }
  47269. }
  47270. juce_UseDebuggingNewOperator
  47271. private:
  47272. KeyMappingEditorComponent* const owner;
  47273. const CommandID commandID;
  47274. const int keyNum;
  47275. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47276. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47277. };
  47278. class KeyMappingItemComponent : public Component
  47279. {
  47280. public:
  47281. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47282. const CommandID commandID_)
  47283. : owner (owner_),
  47284. commandID (commandID_)
  47285. {
  47286. setInterceptsMouseClicks (false, true);
  47287. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47288. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47289. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47290. {
  47291. KeyMappingChangeButton* const kb
  47292. = new KeyMappingChangeButton (owner_, commandID,
  47293. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47294. kb->setEnabled (! isReadOnly);
  47295. addAndMakeVisible (kb);
  47296. }
  47297. KeyMappingChangeButton* const kb
  47298. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47299. addChildComponent (kb);
  47300. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47301. }
  47302. ~KeyMappingItemComponent()
  47303. {
  47304. deleteAllChildren();
  47305. }
  47306. void paint (Graphics& g)
  47307. {
  47308. g.setFont (getHeight() * 0.7f);
  47309. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47310. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47311. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47312. Justification::centredLeft, true);
  47313. }
  47314. void resized()
  47315. {
  47316. int x = getWidth() - 4;
  47317. for (int i = getNumChildComponents(); --i >= 0;)
  47318. {
  47319. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47320. kb->fitToContent (getHeight() - 2);
  47321. kb->setTopRightPosition (x, 1);
  47322. x -= kb->getWidth() + 5;
  47323. }
  47324. }
  47325. juce_UseDebuggingNewOperator
  47326. private:
  47327. KeyMappingEditorComponent* const owner;
  47328. const CommandID commandID;
  47329. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47330. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47331. };
  47332. class KeyMappingTreeViewItem : public TreeViewItem
  47333. {
  47334. public:
  47335. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47336. const CommandID commandID_)
  47337. : owner (owner_),
  47338. commandID (commandID_)
  47339. {
  47340. }
  47341. ~KeyMappingTreeViewItem()
  47342. {
  47343. }
  47344. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47345. bool mightContainSubItems() { return false; }
  47346. int getItemHeight() const { return 20; }
  47347. Component* createItemComponent()
  47348. {
  47349. return new KeyMappingItemComponent (owner, commandID);
  47350. }
  47351. juce_UseDebuggingNewOperator
  47352. private:
  47353. KeyMappingEditorComponent* const owner;
  47354. const CommandID commandID;
  47355. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47356. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47357. };
  47358. class KeyCategoryTreeViewItem : public TreeViewItem
  47359. {
  47360. public:
  47361. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47362. const String& name)
  47363. : owner (owner_),
  47364. categoryName (name)
  47365. {
  47366. }
  47367. ~KeyCategoryTreeViewItem()
  47368. {
  47369. }
  47370. const String getUniqueName() const { return categoryName + "_cat"; }
  47371. bool mightContainSubItems() { return true; }
  47372. int getItemHeight() const { return 28; }
  47373. void paintItem (Graphics& g, int width, int height)
  47374. {
  47375. g.setFont (height * 0.6f, Font::bold);
  47376. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47377. g.drawText (categoryName,
  47378. 2, 0, width - 2, height,
  47379. Justification::centredLeft, true);
  47380. }
  47381. void itemOpennessChanged (bool isNowOpen)
  47382. {
  47383. if (isNowOpen)
  47384. {
  47385. if (getNumSubItems() == 0)
  47386. {
  47387. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47388. for (int i = 0; i < commands.size(); ++i)
  47389. {
  47390. if (owner->shouldCommandBeIncluded (commands[i]))
  47391. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47392. }
  47393. }
  47394. }
  47395. else
  47396. {
  47397. clearSubItems();
  47398. }
  47399. }
  47400. juce_UseDebuggingNewOperator
  47401. private:
  47402. KeyMappingEditorComponent* owner;
  47403. String categoryName;
  47404. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47405. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47406. };
  47407. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47408. const bool showResetToDefaultButton)
  47409. : mappings (mappingManager)
  47410. {
  47411. jassert (mappingManager != 0); // can't be null!
  47412. mappingManager->addChangeListener (this);
  47413. setLinesDrawnForSubItems (false);
  47414. resetButton = 0;
  47415. if (showResetToDefaultButton)
  47416. {
  47417. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47418. resetButton->addButtonListener (this);
  47419. }
  47420. addAndMakeVisible (tree = new TreeView());
  47421. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47422. tree->setRootItemVisible (false);
  47423. tree->setDefaultOpenness (true);
  47424. tree->setRootItem (this);
  47425. }
  47426. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47427. {
  47428. mappings->removeChangeListener (this);
  47429. deleteAllChildren();
  47430. }
  47431. bool KeyMappingEditorComponent::mightContainSubItems()
  47432. {
  47433. return true;
  47434. }
  47435. const String KeyMappingEditorComponent::getUniqueName() const
  47436. {
  47437. return "keys";
  47438. }
  47439. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47440. const Colour& textColour)
  47441. {
  47442. setColour (backgroundColourId, mainBackground);
  47443. setColour (textColourId, textColour);
  47444. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47445. }
  47446. void KeyMappingEditorComponent::parentHierarchyChanged()
  47447. {
  47448. changeListenerCallback (0);
  47449. }
  47450. void KeyMappingEditorComponent::resized()
  47451. {
  47452. int h = getHeight();
  47453. if (resetButton != 0)
  47454. {
  47455. const int buttonHeight = 20;
  47456. h -= buttonHeight + 8;
  47457. int x = getWidth() - 8;
  47458. const int y = h + 6;
  47459. resetButton->changeWidthToFitText (buttonHeight);
  47460. resetButton->setTopRightPosition (x, y);
  47461. }
  47462. tree->setBounds (0, 0, getWidth(), h);
  47463. }
  47464. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47465. {
  47466. if (button == resetButton)
  47467. {
  47468. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47469. TRANS("Reset to defaults"),
  47470. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47471. TRANS("Reset")))
  47472. {
  47473. mappings->resetToDefaultMappings();
  47474. }
  47475. }
  47476. }
  47477. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47478. {
  47479. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47480. clearSubItems();
  47481. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47482. for (int i = 0; i < categories.size(); ++i)
  47483. {
  47484. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47485. int count = 0;
  47486. for (int j = 0; j < commands.size(); ++j)
  47487. if (shouldCommandBeIncluded (commands[j]))
  47488. ++count;
  47489. if (count > 0)
  47490. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47491. }
  47492. if (openness != 0)
  47493. tree->restoreOpennessState (*openness);
  47494. }
  47495. class KeyEntryWindow : public AlertWindow
  47496. {
  47497. public:
  47498. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47499. : AlertWindow (TRANS("New key-mapping"),
  47500. TRANS("Please press a key combination now..."),
  47501. AlertWindow::NoIcon),
  47502. owner (owner_)
  47503. {
  47504. addButton (TRANS("ok"), 1);
  47505. addButton (TRANS("cancel"), 0);
  47506. // (avoid return + escape keys getting processed by the buttons..)
  47507. for (int i = getNumChildComponents(); --i >= 0;)
  47508. getChildComponent (i)->setWantsKeyboardFocus (false);
  47509. setWantsKeyboardFocus (true);
  47510. grabKeyboardFocus();
  47511. }
  47512. ~KeyEntryWindow()
  47513. {
  47514. }
  47515. bool keyPressed (const KeyPress& key)
  47516. {
  47517. lastPress = key;
  47518. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47519. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47520. if (previousCommand != 0)
  47521. {
  47522. message << "\n\n"
  47523. << TRANS("(Currently assigned to \"")
  47524. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47525. << "\")";
  47526. }
  47527. setMessage (message);
  47528. return true;
  47529. }
  47530. bool keyStateChanged (bool)
  47531. {
  47532. return true;
  47533. }
  47534. KeyPress lastPress;
  47535. juce_UseDebuggingNewOperator
  47536. private:
  47537. KeyMappingEditorComponent* owner;
  47538. KeyEntryWindow (const KeyEntryWindow&);
  47539. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47540. };
  47541. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47542. {
  47543. KeyEntryWindow entryWindow (this);
  47544. if (entryWindow.runModalLoop() != 0)
  47545. {
  47546. entryWindow.setVisible (false);
  47547. if (entryWindow.lastPress.isValid())
  47548. {
  47549. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47550. if (previousCommand != 0)
  47551. {
  47552. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47553. TRANS("Change key-mapping"),
  47554. TRANS("This key is already assigned to the command \"")
  47555. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47556. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47557. TRANS("re-assign"),
  47558. TRANS("cancel")))
  47559. {
  47560. return;
  47561. }
  47562. }
  47563. mappings->removeKeyPress (entryWindow.lastPress);
  47564. if (index >= 0)
  47565. mappings->removeKeyPress (commandID, index);
  47566. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47567. }
  47568. }
  47569. }
  47570. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47571. {
  47572. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47573. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47574. }
  47575. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47576. {
  47577. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47578. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47579. }
  47580. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47581. {
  47582. return key.getTextDescription();
  47583. }
  47584. END_JUCE_NAMESPACE
  47585. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47586. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47587. BEGIN_JUCE_NAMESPACE
  47588. KeyPress::KeyPress() throw()
  47589. : keyCode (0),
  47590. mods (0),
  47591. textCharacter (0)
  47592. {
  47593. }
  47594. KeyPress::KeyPress (const int keyCode_,
  47595. const ModifierKeys& mods_,
  47596. const juce_wchar textCharacter_) throw()
  47597. : keyCode (keyCode_),
  47598. mods (mods_),
  47599. textCharacter (textCharacter_)
  47600. {
  47601. }
  47602. KeyPress::KeyPress (const int keyCode_) throw()
  47603. : keyCode (keyCode_),
  47604. textCharacter (0)
  47605. {
  47606. }
  47607. KeyPress::KeyPress (const KeyPress& other) throw()
  47608. : keyCode (other.keyCode),
  47609. mods (other.mods),
  47610. textCharacter (other.textCharacter)
  47611. {
  47612. }
  47613. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47614. {
  47615. keyCode = other.keyCode;
  47616. mods = other.mods;
  47617. textCharacter = other.textCharacter;
  47618. return *this;
  47619. }
  47620. bool KeyPress::operator== (const KeyPress& other) const throw()
  47621. {
  47622. return mods.getRawFlags() == other.mods.getRawFlags()
  47623. && (textCharacter == other.textCharacter
  47624. || textCharacter == 0
  47625. || other.textCharacter == 0)
  47626. && (keyCode == other.keyCode
  47627. || (keyCode < 256
  47628. && other.keyCode < 256
  47629. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  47630. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  47631. }
  47632. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47633. {
  47634. return ! operator== (other);
  47635. }
  47636. bool KeyPress::isCurrentlyDown() const throw()
  47637. {
  47638. return isKeyCurrentlyDown (keyCode)
  47639. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47640. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47641. }
  47642. namespace KeyPressHelpers
  47643. {
  47644. struct KeyNameAndCode
  47645. {
  47646. const char* name;
  47647. int code;
  47648. };
  47649. static const KeyNameAndCode translations[] =
  47650. {
  47651. { "spacebar", KeyPress::spaceKey },
  47652. { "return", KeyPress::returnKey },
  47653. { "escape", KeyPress::escapeKey },
  47654. { "backspace", KeyPress::backspaceKey },
  47655. { "cursor left", KeyPress::leftKey },
  47656. { "cursor right", KeyPress::rightKey },
  47657. { "cursor up", KeyPress::upKey },
  47658. { "cursor down", KeyPress::downKey },
  47659. { "page up", KeyPress::pageUpKey },
  47660. { "page down", KeyPress::pageDownKey },
  47661. { "home", KeyPress::homeKey },
  47662. { "end", KeyPress::endKey },
  47663. { "delete", KeyPress::deleteKey },
  47664. { "insert", KeyPress::insertKey },
  47665. { "tab", KeyPress::tabKey },
  47666. { "play", KeyPress::playKey },
  47667. { "stop", KeyPress::stopKey },
  47668. { "fast forward", KeyPress::fastForwardKey },
  47669. { "rewind", KeyPress::rewindKey }
  47670. };
  47671. static const String numberPadPrefix() { return "numpad "; }
  47672. }
  47673. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  47674. {
  47675. int modifiers = 0;
  47676. if (desc.containsWholeWordIgnoreCase ("ctrl")
  47677. || desc.containsWholeWordIgnoreCase ("control")
  47678. || desc.containsWholeWordIgnoreCase ("ctl"))
  47679. modifiers |= ModifierKeys::ctrlModifier;
  47680. if (desc.containsWholeWordIgnoreCase ("shift")
  47681. || desc.containsWholeWordIgnoreCase ("shft"))
  47682. modifiers |= ModifierKeys::shiftModifier;
  47683. if (desc.containsWholeWordIgnoreCase ("alt")
  47684. || desc.containsWholeWordIgnoreCase ("option"))
  47685. modifiers |= ModifierKeys::altModifier;
  47686. if (desc.containsWholeWordIgnoreCase ("command")
  47687. || desc.containsWholeWordIgnoreCase ("cmd"))
  47688. modifiers |= ModifierKeys::commandModifier;
  47689. int key = 0;
  47690. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47691. {
  47692. if (desc.containsWholeWordIgnoreCase (String (KeyPressHelpers::translations[i].name)))
  47693. {
  47694. key = KeyPressHelpers::translations[i].code;
  47695. break;
  47696. }
  47697. }
  47698. if (key == 0)
  47699. {
  47700. // see if it's a numpad key..
  47701. if (desc.containsIgnoreCase (KeyPressHelpers::numberPadPrefix()))
  47702. {
  47703. const tchar lastChar = desc.trimEnd().getLastCharacter();
  47704. if (lastChar >= '0' && lastChar <= '9')
  47705. key = numberPad0 + lastChar - '0';
  47706. else if (lastChar == '+')
  47707. key = numberPadAdd;
  47708. else if (lastChar == '-')
  47709. key = numberPadSubtract;
  47710. else if (lastChar == '*')
  47711. key = numberPadMultiply;
  47712. else if (lastChar == '/')
  47713. key = numberPadDivide;
  47714. else if (lastChar == '.')
  47715. key = numberPadDecimalPoint;
  47716. else if (lastChar == '=')
  47717. key = numberPadEquals;
  47718. else if (desc.endsWith ("separator"))
  47719. key = numberPadSeparator;
  47720. else if (desc.endsWith ("delete"))
  47721. key = numberPadDelete;
  47722. }
  47723. if (key == 0)
  47724. {
  47725. // see if it's a function key..
  47726. for (int i = 1; i <= 12; ++i)
  47727. if (desc.containsWholeWordIgnoreCase ("f" + String (i)))
  47728. key = F1Key + i - 1;
  47729. if (key == 0)
  47730. {
  47731. // give up and use the hex code..
  47732. const int hexCode = desc.fromFirstOccurrenceOf ("#", false, false)
  47733. .toLowerCase()
  47734. .retainCharacters ("0123456789abcdef")
  47735. .getHexValue32();
  47736. if (hexCode > 0)
  47737. key = hexCode;
  47738. else
  47739. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47740. }
  47741. }
  47742. }
  47743. return KeyPress (key, ModifierKeys (modifiers), 0);
  47744. }
  47745. const String KeyPress::getTextDescription() const throw()
  47746. {
  47747. String desc;
  47748. if (keyCode > 0)
  47749. {
  47750. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47751. // want to store it as being a slash, not shift+whatever.
  47752. if (textCharacter == '/')
  47753. return "/";
  47754. if (mods.isCtrlDown())
  47755. desc << "ctrl + ";
  47756. if (mods.isShiftDown())
  47757. desc << "shift + ";
  47758. #if JUCE_MAC
  47759. // only do this on the mac, because on Windows ctrl and command are the same,
  47760. // and this would get confusing
  47761. if (mods.isCommandDown())
  47762. desc << "command + ";
  47763. if (mods.isAltDown())
  47764. desc << "option + ";
  47765. #else
  47766. if (mods.isAltDown())
  47767. desc << "alt + ";
  47768. #endif
  47769. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47770. if (keyCode == KeyPressHelpers::translations[i].code)
  47771. return desc + KeyPressHelpers::translations[i].name;
  47772. if (keyCode >= F1Key && keyCode <= F16Key)
  47773. desc << 'F' << (1 + keyCode - F1Key);
  47774. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47775. desc << KeyPressHelpers::numberPadPrefix() << (keyCode - numberPad0);
  47776. else if (keyCode >= 33 && keyCode < 176)
  47777. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  47778. else if (keyCode == numberPadAdd)
  47779. desc << KeyPressHelpers::numberPadPrefix() << '+';
  47780. else if (keyCode == numberPadSubtract)
  47781. desc << KeyPressHelpers::numberPadPrefix() << '-';
  47782. else if (keyCode == numberPadMultiply)
  47783. desc << KeyPressHelpers::numberPadPrefix() << '*';
  47784. else if (keyCode == numberPadDivide)
  47785. desc << KeyPressHelpers::numberPadPrefix() << '/';
  47786. else if (keyCode == numberPadSeparator)
  47787. desc << KeyPressHelpers::numberPadPrefix() << "separator";
  47788. else if (keyCode == numberPadDecimalPoint)
  47789. desc << KeyPressHelpers::numberPadPrefix() << '.';
  47790. else if (keyCode == numberPadDelete)
  47791. desc << KeyPressHelpers::numberPadPrefix() << "delete";
  47792. else
  47793. desc << '#' << String::toHexString (keyCode);
  47794. }
  47795. return desc;
  47796. }
  47797. END_JUCE_NAMESPACE
  47798. /*** End of inlined file: juce_KeyPress.cpp ***/
  47799. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47800. BEGIN_JUCE_NAMESPACE
  47801. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  47802. : commandManager (commandManager_)
  47803. {
  47804. // A manager is needed to get the descriptions of commands, and will be called when
  47805. // a command is invoked. So you can't leave this null..
  47806. jassert (commandManager_ != 0);
  47807. Desktop::getInstance().addFocusChangeListener (this);
  47808. }
  47809. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  47810. : commandManager (other.commandManager)
  47811. {
  47812. Desktop::getInstance().addFocusChangeListener (this);
  47813. }
  47814. KeyPressMappingSet::~KeyPressMappingSet()
  47815. {
  47816. Desktop::getInstance().removeFocusChangeListener (this);
  47817. }
  47818. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  47819. {
  47820. for (int i = 0; i < mappings.size(); ++i)
  47821. if (mappings.getUnchecked(i)->commandID == commandID)
  47822. return mappings.getUnchecked (i)->keypresses;
  47823. return Array <KeyPress> ();
  47824. }
  47825. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47826. const KeyPress& newKeyPress,
  47827. int insertIndex) throw()
  47828. {
  47829. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47830. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47831. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47832. && ! newKeyPress.getModifiers().isShiftDown()));
  47833. if (findCommandForKeyPress (newKeyPress) != commandID)
  47834. {
  47835. removeKeyPress (newKeyPress);
  47836. if (newKeyPress.isValid())
  47837. {
  47838. for (int i = mappings.size(); --i >= 0;)
  47839. {
  47840. if (mappings.getUnchecked(i)->commandID == commandID)
  47841. {
  47842. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47843. sendChangeMessage (this);
  47844. return;
  47845. }
  47846. }
  47847. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47848. if (ci != 0)
  47849. {
  47850. CommandMapping* const cm = new CommandMapping();
  47851. cm->commandID = commandID;
  47852. cm->keypresses.add (newKeyPress);
  47853. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47854. mappings.add (cm);
  47855. sendChangeMessage (this);
  47856. }
  47857. }
  47858. }
  47859. }
  47860. void KeyPressMappingSet::resetToDefaultMappings() throw()
  47861. {
  47862. mappings.clear();
  47863. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47864. {
  47865. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47866. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47867. {
  47868. addKeyPress (ci->commandID,
  47869. ci->defaultKeypresses.getReference (j));
  47870. }
  47871. }
  47872. sendChangeMessage (this);
  47873. }
  47874. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  47875. {
  47876. clearAllKeyPresses (commandID);
  47877. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47878. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47879. {
  47880. addKeyPress (ci->commandID,
  47881. ci->defaultKeypresses.getReference (j));
  47882. }
  47883. }
  47884. void KeyPressMappingSet::clearAllKeyPresses() throw()
  47885. {
  47886. if (mappings.size() > 0)
  47887. {
  47888. sendChangeMessage (this);
  47889. mappings.clear();
  47890. }
  47891. }
  47892. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  47893. {
  47894. for (int i = mappings.size(); --i >= 0;)
  47895. {
  47896. if (mappings.getUnchecked(i)->commandID == commandID)
  47897. {
  47898. mappings.remove (i);
  47899. sendChangeMessage (this);
  47900. }
  47901. }
  47902. }
  47903. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  47904. {
  47905. if (keypress.isValid())
  47906. {
  47907. for (int i = mappings.size(); --i >= 0;)
  47908. {
  47909. CommandMapping* const cm = mappings.getUnchecked(i);
  47910. for (int j = cm->keypresses.size(); --j >= 0;)
  47911. {
  47912. if (keypress == cm->keypresses [j])
  47913. {
  47914. cm->keypresses.remove (j);
  47915. sendChangeMessage (this);
  47916. }
  47917. }
  47918. }
  47919. }
  47920. }
  47921. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  47922. const int keyPressIndex) throw()
  47923. {
  47924. for (int i = mappings.size(); --i >= 0;)
  47925. {
  47926. if (mappings.getUnchecked(i)->commandID == commandID)
  47927. {
  47928. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  47929. sendChangeMessage (this);
  47930. break;
  47931. }
  47932. }
  47933. }
  47934. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  47935. {
  47936. for (int i = 0; i < mappings.size(); ++i)
  47937. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  47938. return mappings.getUnchecked(i)->commandID;
  47939. return 0;
  47940. }
  47941. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  47942. const KeyPress& keyPress) const throw()
  47943. {
  47944. for (int i = mappings.size(); --i >= 0;)
  47945. if (mappings.getUnchecked(i)->commandID == commandID)
  47946. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  47947. return false;
  47948. }
  47949. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  47950. const KeyPress& key,
  47951. const bool isKeyDown,
  47952. const int millisecsSinceKeyPressed,
  47953. Component* const originatingComponent) const
  47954. {
  47955. ApplicationCommandTarget::InvocationInfo info (commandID);
  47956. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  47957. info.isKeyDown = isKeyDown;
  47958. info.keyPress = key;
  47959. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  47960. info.originatingComponent = originatingComponent;
  47961. commandManager->invoke (info, false);
  47962. }
  47963. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  47964. {
  47965. if (xmlVersion.hasTagName ("KEYMAPPINGS"))
  47966. {
  47967. if (xmlVersion.getBoolAttribute ("basedOnDefaults", true))
  47968. {
  47969. // if the XML was created as a set of differences from the default mappings,
  47970. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  47971. resetToDefaultMappings();
  47972. }
  47973. else
  47974. {
  47975. // if the XML was created calling createXml (false), then we need to clear all
  47976. // the keys and treat the xml as describing the entire set of mappings.
  47977. clearAllKeyPresses();
  47978. }
  47979. forEachXmlChildElement (xmlVersion, map)
  47980. {
  47981. const CommandID commandId = map->getStringAttribute ("commandId").getHexValue32();
  47982. if (commandId != 0)
  47983. {
  47984. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute ("key")));
  47985. if (map->hasTagName ("MAPPING"))
  47986. {
  47987. addKeyPress (commandId, key);
  47988. }
  47989. else if (map->hasTagName ("UNMAPPING"))
  47990. {
  47991. if (containsMapping (commandId, key))
  47992. removeKeyPress (key);
  47993. }
  47994. }
  47995. }
  47996. return true;
  47997. }
  47998. return false;
  47999. }
  48000. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48001. {
  48002. ScopedPointer <KeyPressMappingSet> defaultSet;
  48003. if (saveDifferencesFromDefaultSet)
  48004. {
  48005. defaultSet = new KeyPressMappingSet (commandManager);
  48006. defaultSet->resetToDefaultMappings();
  48007. }
  48008. XmlElement* const doc = new XmlElement ("KEYMAPPINGS");
  48009. doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet);
  48010. int i;
  48011. for (i = 0; i < mappings.size(); ++i)
  48012. {
  48013. const CommandMapping* const cm = mappings.getUnchecked(i);
  48014. for (int j = 0; j < cm->keypresses.size(); ++j)
  48015. {
  48016. if (defaultSet == 0
  48017. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48018. {
  48019. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48020. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  48021. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  48022. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  48023. }
  48024. }
  48025. }
  48026. if (defaultSet != 0)
  48027. {
  48028. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48029. {
  48030. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48031. for (int j = 0; j < cm->keypresses.size(); ++j)
  48032. {
  48033. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48034. {
  48035. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48036. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  48037. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  48038. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  48039. }
  48040. }
  48041. }
  48042. }
  48043. return doc;
  48044. }
  48045. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48046. Component* originatingComponent)
  48047. {
  48048. bool used = false;
  48049. const CommandID commandID = findCommandForKeyPress (key);
  48050. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48051. if (ci != 0
  48052. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48053. {
  48054. ApplicationCommandInfo info (0);
  48055. if (commandManager->getTargetForCommand (commandID, info) != 0
  48056. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48057. {
  48058. invokeCommand (commandID, key, true, 0, originatingComponent);
  48059. used = true;
  48060. }
  48061. else
  48062. {
  48063. if (originatingComponent != 0)
  48064. originatingComponent->getLookAndFeel().playAlertSound();
  48065. }
  48066. }
  48067. return used;
  48068. }
  48069. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48070. {
  48071. bool used = false;
  48072. const uint32 now = Time::getMillisecondCounter();
  48073. for (int i = mappings.size(); --i >= 0;)
  48074. {
  48075. CommandMapping* const cm = mappings.getUnchecked(i);
  48076. if (cm->wantsKeyUpDownCallbacks)
  48077. {
  48078. for (int j = cm->keypresses.size(); --j >= 0;)
  48079. {
  48080. const KeyPress key (cm->keypresses.getReference (j));
  48081. const bool isDown = key.isCurrentlyDown();
  48082. int keyPressEntryIndex = 0;
  48083. bool wasDown = false;
  48084. for (int k = keysDown.size(); --k >= 0;)
  48085. {
  48086. if (key == keysDown.getUnchecked(k)->key)
  48087. {
  48088. keyPressEntryIndex = k;
  48089. wasDown = true;
  48090. used = true;
  48091. break;
  48092. }
  48093. }
  48094. if (isDown != wasDown)
  48095. {
  48096. int millisecs = 0;
  48097. if (isDown)
  48098. {
  48099. KeyPressTime* const k = new KeyPressTime();
  48100. k->key = key;
  48101. k->timeWhenPressed = now;
  48102. keysDown.add (k);
  48103. }
  48104. else
  48105. {
  48106. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48107. if (now > pressTime)
  48108. millisecs = now - pressTime;
  48109. keysDown.remove (keyPressEntryIndex);
  48110. }
  48111. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48112. used = true;
  48113. }
  48114. }
  48115. }
  48116. }
  48117. return used;
  48118. }
  48119. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48120. {
  48121. if (focusedComponent != 0)
  48122. focusedComponent->keyStateChanged (false);
  48123. }
  48124. END_JUCE_NAMESPACE
  48125. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48126. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48127. BEGIN_JUCE_NAMESPACE
  48128. ModifierKeys::ModifierKeys (const int flags_) throw()
  48129. : flags (flags_)
  48130. {
  48131. }
  48132. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48133. : flags (other.flags)
  48134. {
  48135. }
  48136. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48137. {
  48138. flags = other.flags;
  48139. return *this;
  48140. }
  48141. ModifierKeys ModifierKeys::currentModifiers;
  48142. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48143. {
  48144. return currentModifiers;
  48145. }
  48146. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48147. {
  48148. int num = 0;
  48149. if (isLeftButtonDown()) ++num;
  48150. if (isRightButtonDown()) ++num;
  48151. if (isMiddleButtonDown()) ++num;
  48152. return num;
  48153. }
  48154. END_JUCE_NAMESPACE
  48155. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48156. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48157. BEGIN_JUCE_NAMESPACE
  48158. struct AnimationTask
  48159. {
  48160. AnimationTask (Component* const comp)
  48161. : component (comp)
  48162. {
  48163. }
  48164. Component::SafePointer<Component> component;
  48165. Rectangle<int> destination;
  48166. int msElapsed, msTotal;
  48167. double startSpeed, midSpeed, endSpeed, lastProgress;
  48168. double left, top, right, bottom;
  48169. bool useTimeslice (const int elapsed)
  48170. {
  48171. if (component == 0)
  48172. return false;
  48173. msElapsed += elapsed;
  48174. double newProgress = msElapsed / (double) msTotal;
  48175. if (newProgress >= 0 && newProgress < 1.0)
  48176. {
  48177. newProgress = timeToDistance (newProgress);
  48178. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48179. jassert (newProgress >= lastProgress);
  48180. lastProgress = newProgress;
  48181. left += (destination.getX() - left) * delta;
  48182. top += (destination.getY() - top) * delta;
  48183. right += (destination.getRight() - right) * delta;
  48184. bottom += (destination.getBottom() - bottom) * delta;
  48185. if (delta < 1.0)
  48186. {
  48187. const Rectangle<int> newBounds (roundToInt (left),
  48188. roundToInt (top),
  48189. roundToInt (right - left),
  48190. roundToInt (bottom - top));
  48191. if (newBounds != destination)
  48192. {
  48193. component->setBounds (newBounds);
  48194. return true;
  48195. }
  48196. }
  48197. }
  48198. component->setBounds (destination);
  48199. return false;
  48200. }
  48201. void moveToFinalDestination()
  48202. {
  48203. if (component != 0)
  48204. component->setBounds (destination);
  48205. }
  48206. private:
  48207. inline double timeToDistance (const double time) const
  48208. {
  48209. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48210. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48211. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48212. }
  48213. };
  48214. ComponentAnimator::ComponentAnimator()
  48215. : lastTime (0)
  48216. {
  48217. }
  48218. ComponentAnimator::~ComponentAnimator()
  48219. {
  48220. cancelAllAnimations (false);
  48221. jassert (tasks.size() == 0);
  48222. }
  48223. void* ComponentAnimator::findTaskFor (Component* const component) const
  48224. {
  48225. for (int i = tasks.size(); --i >= 0;)
  48226. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component.getComponent())
  48227. return tasks.getUnchecked(i);
  48228. return 0;
  48229. }
  48230. void ComponentAnimator::animateComponent (Component* const component,
  48231. const Rectangle<int>& finalPosition,
  48232. const int millisecondsToSpendMoving,
  48233. const double startSpeed,
  48234. const double endSpeed)
  48235. {
  48236. if (component != 0)
  48237. {
  48238. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48239. if (at == 0)
  48240. {
  48241. at = new AnimationTask (component);
  48242. tasks.add (at);
  48243. sendChangeMessage (this);
  48244. }
  48245. at->msElapsed = 0;
  48246. at->lastProgress = 0;
  48247. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48248. at->destination = finalPosition;
  48249. // the speeds must be 0 or greater!
  48250. jassert (startSpeed >= 0 && endSpeed >= 0)
  48251. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48252. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48253. at->midSpeed = invTotalDistance;
  48254. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48255. at->left = component->getX();
  48256. at->top = component->getY();
  48257. at->right = component->getRight();
  48258. at->bottom = component->getBottom();
  48259. if (! isTimerRunning())
  48260. {
  48261. lastTime = Time::getMillisecondCounter();
  48262. startTimer (1000 / 50);
  48263. }
  48264. }
  48265. }
  48266. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48267. {
  48268. for (int i = tasks.size(); --i >= 0;)
  48269. {
  48270. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48271. if (moveComponentsToTheirFinalPositions)
  48272. at->moveToFinalDestination();
  48273. delete at;
  48274. tasks.remove (i);
  48275. sendChangeMessage (this);
  48276. }
  48277. }
  48278. void ComponentAnimator::cancelAnimation (Component* const component,
  48279. const bool moveComponentToItsFinalPosition)
  48280. {
  48281. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48282. if (at != 0)
  48283. {
  48284. if (moveComponentToItsFinalPosition)
  48285. at->moveToFinalDestination();
  48286. tasks.removeValue (at);
  48287. delete at;
  48288. sendChangeMessage (this);
  48289. }
  48290. }
  48291. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48292. {
  48293. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48294. if (at != 0)
  48295. return at->destination;
  48296. else if (component != 0)
  48297. return component->getBounds();
  48298. return Rectangle<int>();
  48299. }
  48300. bool ComponentAnimator::isAnimating (Component* component) const
  48301. {
  48302. return findTaskFor (component) != 0;
  48303. }
  48304. void ComponentAnimator::timerCallback()
  48305. {
  48306. const uint32 timeNow = Time::getMillisecondCounter();
  48307. if (lastTime == 0 || lastTime == timeNow)
  48308. lastTime = timeNow;
  48309. const int elapsed = timeNow - lastTime;
  48310. for (int i = tasks.size(); --i >= 0;)
  48311. {
  48312. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48313. if (! at->useTimeslice (elapsed))
  48314. {
  48315. tasks.remove (i);
  48316. delete at;
  48317. sendChangeMessage (this);
  48318. }
  48319. }
  48320. lastTime = timeNow;
  48321. if (tasks.size() == 0)
  48322. stopTimer();
  48323. }
  48324. END_JUCE_NAMESPACE
  48325. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48326. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48327. BEGIN_JUCE_NAMESPACE
  48328. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48329. : minW (0),
  48330. maxW (0x3fffffff),
  48331. minH (0),
  48332. maxH (0x3fffffff),
  48333. minOffTop (0),
  48334. minOffLeft (0),
  48335. minOffBottom (0),
  48336. minOffRight (0),
  48337. aspectRatio (0.0)
  48338. {
  48339. }
  48340. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48341. {
  48342. }
  48343. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48344. {
  48345. minW = minimumWidth;
  48346. }
  48347. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48348. {
  48349. maxW = maximumWidth;
  48350. }
  48351. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48352. {
  48353. minH = minimumHeight;
  48354. }
  48355. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48356. {
  48357. maxH = maximumHeight;
  48358. }
  48359. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48360. {
  48361. jassert (maxW >= minimumWidth);
  48362. jassert (maxH >= minimumHeight);
  48363. jassert (minimumWidth > 0 && minimumHeight > 0);
  48364. minW = minimumWidth;
  48365. minH = minimumHeight;
  48366. if (minW > maxW)
  48367. maxW = minW;
  48368. if (minH > maxH)
  48369. maxH = minH;
  48370. }
  48371. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48372. {
  48373. jassert (maximumWidth >= minW);
  48374. jassert (maximumHeight >= minH);
  48375. jassert (maximumWidth > 0 && maximumHeight > 0);
  48376. maxW = jmax (minW, maximumWidth);
  48377. maxH = jmax (minH, maximumHeight);
  48378. }
  48379. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48380. const int minimumHeight,
  48381. const int maximumWidth,
  48382. const int maximumHeight) throw()
  48383. {
  48384. jassert (maximumWidth >= minimumWidth);
  48385. jassert (maximumHeight >= minimumHeight);
  48386. jassert (maximumWidth > 0 && maximumHeight > 0);
  48387. jassert (minimumWidth > 0 && minimumHeight > 0);
  48388. minW = jmax (0, minimumWidth);
  48389. minH = jmax (0, minimumHeight);
  48390. maxW = jmax (minW, maximumWidth);
  48391. maxH = jmax (minH, maximumHeight);
  48392. }
  48393. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48394. const int minimumWhenOffTheLeft,
  48395. const int minimumWhenOffTheBottom,
  48396. const int minimumWhenOffTheRight) throw()
  48397. {
  48398. minOffTop = minimumWhenOffTheTop;
  48399. minOffLeft = minimumWhenOffTheLeft;
  48400. minOffBottom = minimumWhenOffTheBottom;
  48401. minOffRight = minimumWhenOffTheRight;
  48402. }
  48403. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48404. {
  48405. aspectRatio = jmax (0.0, widthOverHeight);
  48406. }
  48407. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48408. {
  48409. return aspectRatio;
  48410. }
  48411. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48412. const Rectangle<int>& targetBounds,
  48413. const bool isStretchingTop,
  48414. const bool isStretchingLeft,
  48415. const bool isStretchingBottom,
  48416. const bool isStretchingRight)
  48417. {
  48418. jassert (component != 0);
  48419. Rectangle<int> limits, bounds (targetBounds);
  48420. BorderSize border;
  48421. Component* const parent = component->getParentComponent();
  48422. if (parent == 0)
  48423. {
  48424. ComponentPeer* peer = component->getPeer();
  48425. if (peer != 0)
  48426. border = peer->getFrameSize();
  48427. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48428. }
  48429. else
  48430. {
  48431. limits.setSize (parent->getWidth(), parent->getHeight());
  48432. }
  48433. border.addTo (bounds);
  48434. checkBounds (bounds,
  48435. border.addedTo (component->getBounds()), limits,
  48436. isStretchingTop, isStretchingLeft,
  48437. isStretchingBottom, isStretchingRight);
  48438. border.subtractFrom (bounds);
  48439. applyBoundsToComponent (component, bounds);
  48440. }
  48441. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48442. {
  48443. setBoundsForComponent (component, component->getBounds(),
  48444. false, false, false, false);
  48445. }
  48446. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48447. const Rectangle<int>& bounds)
  48448. {
  48449. component->setBounds (bounds);
  48450. }
  48451. void ComponentBoundsConstrainer::resizeStart()
  48452. {
  48453. }
  48454. void ComponentBoundsConstrainer::resizeEnd()
  48455. {
  48456. }
  48457. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48458. const Rectangle<int>& old,
  48459. const Rectangle<int>& limits,
  48460. const bool isStretchingTop,
  48461. const bool isStretchingLeft,
  48462. const bool isStretchingBottom,
  48463. const bool isStretchingRight)
  48464. {
  48465. int x = bounds.getX();
  48466. int y = bounds.getY();
  48467. int w = bounds.getWidth();
  48468. int h = bounds.getHeight();
  48469. // constrain the size if it's being stretched..
  48470. if (isStretchingLeft)
  48471. {
  48472. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48473. w = old.getRight() - x;
  48474. }
  48475. if (isStretchingRight)
  48476. {
  48477. w = jlimit (minW, maxW, w);
  48478. }
  48479. if (isStretchingTop)
  48480. {
  48481. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48482. h = old.getBottom() - y;
  48483. }
  48484. if (isStretchingBottom)
  48485. {
  48486. h = jlimit (minH, maxH, h);
  48487. }
  48488. // constrain the aspect ratio if one has been specified..
  48489. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48490. {
  48491. bool adjustWidth;
  48492. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48493. {
  48494. adjustWidth = true;
  48495. }
  48496. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48497. {
  48498. adjustWidth = false;
  48499. }
  48500. else
  48501. {
  48502. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48503. const double newRatio = fabs (w / (double) h);
  48504. adjustWidth = (oldRatio > newRatio);
  48505. }
  48506. if (adjustWidth)
  48507. {
  48508. w = roundToInt (h * aspectRatio);
  48509. if (w > maxW || w < minW)
  48510. {
  48511. w = jlimit (minW, maxW, w);
  48512. h = roundToInt (w / aspectRatio);
  48513. }
  48514. }
  48515. else
  48516. {
  48517. h = roundToInt (w / aspectRatio);
  48518. if (h > maxH || h < minH)
  48519. {
  48520. h = jlimit (minH, maxH, h);
  48521. w = roundToInt (h * aspectRatio);
  48522. }
  48523. }
  48524. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48525. {
  48526. x = old.getX() + (old.getWidth() - w) / 2;
  48527. }
  48528. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48529. {
  48530. y = old.getY() + (old.getHeight() - h) / 2;
  48531. }
  48532. else
  48533. {
  48534. if (isStretchingLeft)
  48535. x = old.getRight() - w;
  48536. if (isStretchingTop)
  48537. y = old.getBottom() - h;
  48538. }
  48539. }
  48540. // ...and constrain the position if limits have been set for that.
  48541. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48542. {
  48543. if (minOffTop > 0)
  48544. {
  48545. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48546. if (y < limit)
  48547. {
  48548. if (isStretchingTop)
  48549. h -= (limit - y);
  48550. y = limit;
  48551. }
  48552. }
  48553. if (minOffLeft > 0)
  48554. {
  48555. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48556. if (x < limit)
  48557. {
  48558. if (isStretchingLeft)
  48559. w -= (limit - x);
  48560. x = limit;
  48561. }
  48562. }
  48563. if (minOffBottom > 0)
  48564. {
  48565. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48566. if (y > limit)
  48567. {
  48568. if (isStretchingBottom)
  48569. h += (limit - y);
  48570. else
  48571. y = limit;
  48572. }
  48573. }
  48574. if (minOffRight > 0)
  48575. {
  48576. const int limit = limits.getRight() - jmin (minOffRight, w);
  48577. if (x > limit)
  48578. {
  48579. if (isStretchingRight)
  48580. w += (limit - x);
  48581. else
  48582. x = limit;
  48583. }
  48584. }
  48585. }
  48586. jassert (w >= 0 && h >= 0);
  48587. bounds = Rectangle<int> (x, y, w, h);
  48588. }
  48589. END_JUCE_NAMESPACE
  48590. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48591. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48592. BEGIN_JUCE_NAMESPACE
  48593. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48594. : component (component_),
  48595. lastPeer (0),
  48596. reentrant (false)
  48597. {
  48598. jassert (component != 0); // can't use this with a null pointer..
  48599. component->addComponentListener (this);
  48600. registerWithParentComps();
  48601. }
  48602. ComponentMovementWatcher::~ComponentMovementWatcher()
  48603. {
  48604. component->removeComponentListener (this);
  48605. unregister();
  48606. }
  48607. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48608. {
  48609. // agh! don't delete the target component without deleting this object first!
  48610. jassert (component != 0);
  48611. if (! reentrant)
  48612. {
  48613. reentrant = true;
  48614. ComponentPeer* const peer = component->getPeer();
  48615. if (peer != lastPeer)
  48616. {
  48617. componentPeerChanged();
  48618. if (component == 0)
  48619. return;
  48620. lastPeer = peer;
  48621. }
  48622. unregister();
  48623. registerWithParentComps();
  48624. reentrant = false;
  48625. componentMovedOrResized (*component, true, true);
  48626. }
  48627. }
  48628. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48629. {
  48630. // agh! don't delete the target component without deleting this object first!
  48631. jassert (component != 0);
  48632. if (wasMoved)
  48633. {
  48634. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48635. wasMoved = lastBounds.getPosition() != pos;
  48636. lastBounds.setPosition (pos);
  48637. }
  48638. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48639. lastBounds.setSize (component->getWidth(), component->getHeight());
  48640. if (wasMoved || wasResized)
  48641. componentMovedOrResized (wasMoved, wasResized);
  48642. }
  48643. void ComponentMovementWatcher::registerWithParentComps() throw()
  48644. {
  48645. Component* p = component->getParentComponent();
  48646. while (p != 0)
  48647. {
  48648. p->addComponentListener (this);
  48649. registeredParentComps.add (p);
  48650. p = p->getParentComponent();
  48651. }
  48652. }
  48653. void ComponentMovementWatcher::unregister() throw()
  48654. {
  48655. for (int i = registeredParentComps.size(); --i >= 0;)
  48656. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48657. registeredParentComps.clear();
  48658. }
  48659. END_JUCE_NAMESPACE
  48660. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48661. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48662. BEGIN_JUCE_NAMESPACE
  48663. GroupComponent::GroupComponent (const String& componentName,
  48664. const String& labelText)
  48665. : Component (componentName),
  48666. text (labelText),
  48667. justification (Justification::left)
  48668. {
  48669. setInterceptsMouseClicks (false, true);
  48670. }
  48671. GroupComponent::~GroupComponent()
  48672. {
  48673. }
  48674. void GroupComponent::setText (const String& newText) throw()
  48675. {
  48676. if (text != newText)
  48677. {
  48678. text = newText;
  48679. repaint();
  48680. }
  48681. }
  48682. const String GroupComponent::getText() const throw()
  48683. {
  48684. return text;
  48685. }
  48686. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48687. {
  48688. if (justification.getFlags() != newJustification.getFlags())
  48689. {
  48690. justification = newJustification;
  48691. repaint();
  48692. }
  48693. }
  48694. void GroupComponent::paint (Graphics& g)
  48695. {
  48696. getLookAndFeel()
  48697. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48698. text, justification,
  48699. *this);
  48700. }
  48701. void GroupComponent::enablementChanged()
  48702. {
  48703. repaint();
  48704. }
  48705. void GroupComponent::colourChanged()
  48706. {
  48707. repaint();
  48708. }
  48709. END_JUCE_NAMESPACE
  48710. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48711. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48712. BEGIN_JUCE_NAMESPACE
  48713. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48714. : DocumentWindow (String::empty, backgroundColour,
  48715. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48716. {
  48717. }
  48718. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48719. {
  48720. }
  48721. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48722. {
  48723. MultiDocumentPanel* const owner = getOwner();
  48724. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48725. if (owner != 0)
  48726. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48727. }
  48728. void MultiDocumentPanelWindow::closeButtonPressed()
  48729. {
  48730. MultiDocumentPanel* const owner = getOwner();
  48731. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48732. if (owner != 0)
  48733. owner->closeDocument (getContentComponent(), true);
  48734. }
  48735. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48736. {
  48737. DocumentWindow::activeWindowStatusChanged();
  48738. updateOrder();
  48739. }
  48740. void MultiDocumentPanelWindow::broughtToFront()
  48741. {
  48742. DocumentWindow::broughtToFront();
  48743. updateOrder();
  48744. }
  48745. void MultiDocumentPanelWindow::updateOrder()
  48746. {
  48747. MultiDocumentPanel* const owner = getOwner();
  48748. if (owner != 0)
  48749. owner->updateOrder();
  48750. }
  48751. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48752. {
  48753. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48754. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48755. }
  48756. class MDITabbedComponentInternal : public TabbedComponent
  48757. {
  48758. public:
  48759. MDITabbedComponentInternal()
  48760. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48761. {
  48762. }
  48763. ~MDITabbedComponentInternal()
  48764. {
  48765. }
  48766. void currentTabChanged (const int, const String&)
  48767. {
  48768. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48769. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48770. if (owner != 0)
  48771. owner->updateOrder();
  48772. }
  48773. };
  48774. MultiDocumentPanel::MultiDocumentPanel()
  48775. : mode (MaximisedWindowsWithTabs),
  48776. tabComponent (0),
  48777. backgroundColour (Colours::lightblue),
  48778. maximumNumDocuments (0),
  48779. numDocsBeforeTabsUsed (0)
  48780. {
  48781. setOpaque (true);
  48782. }
  48783. MultiDocumentPanel::~MultiDocumentPanel()
  48784. {
  48785. closeAllDocuments (false);
  48786. }
  48787. static bool shouldDeleteComp (Component* const c)
  48788. {
  48789. return c->getProperties() ["mdiDocumentDelete_"];
  48790. }
  48791. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48792. {
  48793. while (components.size() > 0)
  48794. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48795. return false;
  48796. return true;
  48797. }
  48798. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48799. {
  48800. return new MultiDocumentPanelWindow (backgroundColour);
  48801. }
  48802. void MultiDocumentPanel::addWindow (Component* component)
  48803. {
  48804. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48805. dw->setResizable (true, false);
  48806. dw->setContentComponent (component, false, true);
  48807. dw->setName (component->getName());
  48808. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48809. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48810. int x = 4;
  48811. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48812. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48813. x += 16;
  48814. dw->setTopLeftPosition (x, x);
  48815. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48816. if (pos.toString().isNotEmpty())
  48817. dw->restoreWindowStateFromString (pos.toString());
  48818. addAndMakeVisible (dw);
  48819. dw->toFront (true);
  48820. }
  48821. bool MultiDocumentPanel::addDocument (Component* const component,
  48822. const Colour& docColour,
  48823. const bool deleteWhenRemoved)
  48824. {
  48825. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48826. // with a frame-within-a-frame! Just pass in the bare content component.
  48827. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48828. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48829. return false;
  48830. components.add (component);
  48831. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48832. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48833. component->addComponentListener (this);
  48834. if (mode == FloatingWindows)
  48835. {
  48836. if (isFullscreenWhenOneDocument())
  48837. {
  48838. if (components.size() == 1)
  48839. {
  48840. addAndMakeVisible (component);
  48841. }
  48842. else
  48843. {
  48844. if (components.size() == 2)
  48845. addWindow (components.getFirst());
  48846. addWindow (component);
  48847. }
  48848. }
  48849. else
  48850. {
  48851. addWindow (component);
  48852. }
  48853. }
  48854. else
  48855. {
  48856. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48857. {
  48858. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48859. Array <Component*> temp (components);
  48860. for (int i = 0; i < temp.size(); ++i)
  48861. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48862. resized();
  48863. }
  48864. else
  48865. {
  48866. if (tabComponent != 0)
  48867. tabComponent->addTab (component->getName(), docColour, component, false);
  48868. else
  48869. addAndMakeVisible (component);
  48870. }
  48871. setActiveDocument (component);
  48872. }
  48873. resized();
  48874. activeDocumentChanged();
  48875. return true;
  48876. }
  48877. bool MultiDocumentPanel::closeDocument (Component* component,
  48878. const bool checkItsOkToCloseFirst)
  48879. {
  48880. if (components.contains (component))
  48881. {
  48882. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48883. return false;
  48884. component->removeComponentListener (this);
  48885. const bool shouldDelete = shouldDeleteComp (component);
  48886. component->getProperties().remove ("mdiDocumentDelete_");
  48887. component->getProperties().remove ("mdiDocumentBkg_");
  48888. if (mode == FloatingWindows)
  48889. {
  48890. for (int i = getNumChildComponents(); --i >= 0;)
  48891. {
  48892. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48893. if (dw != 0 && dw->getContentComponent() == component)
  48894. {
  48895. dw->setContentComponent (0, false);
  48896. delete dw;
  48897. break;
  48898. }
  48899. }
  48900. if (shouldDelete)
  48901. delete component;
  48902. components.removeValue (component);
  48903. if (isFullscreenWhenOneDocument() && components.size() == 1)
  48904. {
  48905. for (int i = getNumChildComponents(); --i >= 0;)
  48906. {
  48907. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48908. if (dw != 0)
  48909. {
  48910. dw->setContentComponent (0, false);
  48911. delete dw;
  48912. }
  48913. }
  48914. addAndMakeVisible (components.getFirst());
  48915. }
  48916. }
  48917. else
  48918. {
  48919. jassert (components.indexOf (component) >= 0);
  48920. if (tabComponent != 0)
  48921. {
  48922. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48923. if (tabComponent->getTabContentComponent (i) == component)
  48924. tabComponent->removeTab (i);
  48925. }
  48926. else
  48927. {
  48928. removeChildComponent (component);
  48929. }
  48930. if (shouldDelete)
  48931. delete component;
  48932. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  48933. deleteAndZero (tabComponent);
  48934. components.removeValue (component);
  48935. if (components.size() > 0 && tabComponent == 0)
  48936. addAndMakeVisible (components.getFirst());
  48937. }
  48938. resized();
  48939. activeDocumentChanged();
  48940. }
  48941. else
  48942. {
  48943. jassertfalse
  48944. }
  48945. return true;
  48946. }
  48947. int MultiDocumentPanel::getNumDocuments() const throw()
  48948. {
  48949. return components.size();
  48950. }
  48951. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  48952. {
  48953. return components [index];
  48954. }
  48955. Component* MultiDocumentPanel::getActiveDocument() const throw()
  48956. {
  48957. if (mode == FloatingWindows)
  48958. {
  48959. for (int i = getNumChildComponents(); --i >= 0;)
  48960. {
  48961. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48962. if (dw != 0 && dw->isActiveWindow())
  48963. return dw->getContentComponent();
  48964. }
  48965. }
  48966. return components.getLast();
  48967. }
  48968. void MultiDocumentPanel::setActiveDocument (Component* component)
  48969. {
  48970. if (mode == FloatingWindows)
  48971. {
  48972. component = getContainerComp (component);
  48973. if (component != 0)
  48974. component->toFront (true);
  48975. }
  48976. else if (tabComponent != 0)
  48977. {
  48978. jassert (components.indexOf (component) >= 0);
  48979. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48980. {
  48981. if (tabComponent->getTabContentComponent (i) == component)
  48982. {
  48983. tabComponent->setCurrentTabIndex (i);
  48984. break;
  48985. }
  48986. }
  48987. }
  48988. else
  48989. {
  48990. component->grabKeyboardFocus();
  48991. }
  48992. }
  48993. void MultiDocumentPanel::activeDocumentChanged()
  48994. {
  48995. }
  48996. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  48997. {
  48998. maximumNumDocuments = newNumber;
  48999. }
  49000. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49001. {
  49002. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49003. }
  49004. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49005. {
  49006. return numDocsBeforeTabsUsed != 0;
  49007. }
  49008. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49009. {
  49010. if (mode != newLayoutMode)
  49011. {
  49012. mode = newLayoutMode;
  49013. if (mode == FloatingWindows)
  49014. {
  49015. deleteAndZero (tabComponent);
  49016. }
  49017. else
  49018. {
  49019. for (int i = getNumChildComponents(); --i >= 0;)
  49020. {
  49021. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49022. if (dw != 0)
  49023. {
  49024. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49025. dw->setContentComponent (0, false);
  49026. delete dw;
  49027. }
  49028. }
  49029. }
  49030. resized();
  49031. const Array <Component*> tempComps (components);
  49032. components.clear();
  49033. for (int i = 0; i < tempComps.size(); ++i)
  49034. {
  49035. Component* const c = tempComps.getUnchecked(i);
  49036. addDocument (c,
  49037. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49038. shouldDeleteComp (c));
  49039. }
  49040. }
  49041. }
  49042. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49043. {
  49044. if (backgroundColour != newBackgroundColour)
  49045. {
  49046. backgroundColour = newBackgroundColour;
  49047. setOpaque (newBackgroundColour.isOpaque());
  49048. repaint();
  49049. }
  49050. }
  49051. void MultiDocumentPanel::paint (Graphics& g)
  49052. {
  49053. g.fillAll (backgroundColour);
  49054. }
  49055. void MultiDocumentPanel::resized()
  49056. {
  49057. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49058. {
  49059. for (int i = getNumChildComponents(); --i >= 0;)
  49060. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49061. }
  49062. setWantsKeyboardFocus (components.size() == 0);
  49063. }
  49064. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49065. {
  49066. if (mode == FloatingWindows)
  49067. {
  49068. for (int i = 0; i < getNumChildComponents(); ++i)
  49069. {
  49070. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49071. if (dw != 0 && dw->getContentComponent() == c)
  49072. {
  49073. c = dw;
  49074. break;
  49075. }
  49076. }
  49077. }
  49078. return c;
  49079. }
  49080. void MultiDocumentPanel::componentNameChanged (Component&)
  49081. {
  49082. if (mode == FloatingWindows)
  49083. {
  49084. for (int i = 0; i < getNumChildComponents(); ++i)
  49085. {
  49086. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49087. if (dw != 0)
  49088. dw->setName (dw->getContentComponent()->getName());
  49089. }
  49090. }
  49091. else if (tabComponent != 0)
  49092. {
  49093. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49094. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49095. }
  49096. }
  49097. void MultiDocumentPanel::updateOrder()
  49098. {
  49099. const Array <Component*> oldList (components);
  49100. if (mode == FloatingWindows)
  49101. {
  49102. components.clear();
  49103. for (int i = 0; i < getNumChildComponents(); ++i)
  49104. {
  49105. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49106. if (dw != 0)
  49107. components.add (dw->getContentComponent());
  49108. }
  49109. }
  49110. else
  49111. {
  49112. if (tabComponent != 0)
  49113. {
  49114. Component* const current = tabComponent->getCurrentContentComponent();
  49115. if (current != 0)
  49116. {
  49117. components.removeValue (current);
  49118. components.add (current);
  49119. }
  49120. }
  49121. }
  49122. if (components != oldList)
  49123. activeDocumentChanged();
  49124. }
  49125. END_JUCE_NAMESPACE
  49126. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49127. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49128. BEGIN_JUCE_NAMESPACE
  49129. enum ResizableBorderComponentZones
  49130. {
  49131. zoneL = 1,
  49132. zoneR = 2,
  49133. zoneT = 4,
  49134. zoneB = 8
  49135. };
  49136. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49137. ComponentBoundsConstrainer* const constrainer_)
  49138. : component (componentToResize),
  49139. constrainer (constrainer_),
  49140. borderSize (5),
  49141. mouseZone (0)
  49142. {
  49143. }
  49144. ResizableBorderComponent::~ResizableBorderComponent()
  49145. {
  49146. }
  49147. void ResizableBorderComponent::paint (Graphics& g)
  49148. {
  49149. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49150. }
  49151. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49152. {
  49153. updateMouseZone (e);
  49154. }
  49155. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49156. {
  49157. updateMouseZone (e);
  49158. }
  49159. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49160. {
  49161. if (component == 0)
  49162. {
  49163. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49164. return;
  49165. }
  49166. updateMouseZone (e);
  49167. originalBounds = component->getBounds();
  49168. if (constrainer != 0)
  49169. constrainer->resizeStart();
  49170. }
  49171. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49172. {
  49173. if (component == 0)
  49174. {
  49175. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49176. return;
  49177. }
  49178. Rectangle<int> bounds (originalBounds);
  49179. if ((mouseZone & zoneL) != 0)
  49180. bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX());
  49181. if ((mouseZone & zoneT) != 0)
  49182. bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY());
  49183. if ((mouseZone & zoneR) != 0)
  49184. bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX());
  49185. if ((mouseZone & zoneB) != 0)
  49186. bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY());
  49187. if (constrainer != 0)
  49188. constrainer->setBoundsForComponent (component, bounds,
  49189. (mouseZone & zoneT) != 0,
  49190. (mouseZone & zoneL) != 0,
  49191. (mouseZone & zoneB) != 0,
  49192. (mouseZone & zoneR) != 0);
  49193. else
  49194. component->setBounds (bounds);
  49195. }
  49196. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49197. {
  49198. if (constrainer != 0)
  49199. constrainer->resizeEnd();
  49200. }
  49201. bool ResizableBorderComponent::hitTest (int x, int y)
  49202. {
  49203. return x < borderSize.getLeft()
  49204. || x >= getWidth() - borderSize.getRight()
  49205. || y < borderSize.getTop()
  49206. || y >= getHeight() - borderSize.getBottom();
  49207. }
  49208. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49209. {
  49210. if (borderSize != newBorderSize)
  49211. {
  49212. borderSize = newBorderSize;
  49213. repaint();
  49214. }
  49215. }
  49216. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49217. {
  49218. return borderSize;
  49219. }
  49220. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49221. {
  49222. int newZone = 0;
  49223. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49224. {
  49225. if (e.x < jmax (borderSize.getLeft(),
  49226. proportionOfWidth (0.1f),
  49227. jmin (10, proportionOfWidth (0.33f))))
  49228. newZone |= zoneL;
  49229. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49230. proportionOfWidth (0.9f),
  49231. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49232. newZone |= zoneR;
  49233. if (e.y < jmax (borderSize.getTop(),
  49234. proportionOfHeight (0.1f),
  49235. jmin (10, proportionOfHeight (0.33f))))
  49236. newZone |= zoneT;
  49237. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49238. proportionOfHeight (0.9f),
  49239. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49240. newZone |= zoneB;
  49241. }
  49242. if (mouseZone != newZone)
  49243. {
  49244. mouseZone = newZone;
  49245. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49246. switch (newZone)
  49247. {
  49248. case (zoneL | zoneT): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49249. case zoneT: mc = MouseCursor::TopEdgeResizeCursor; break;
  49250. case (zoneR | zoneT): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49251. case zoneL: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49252. case zoneR: mc = MouseCursor::RightEdgeResizeCursor; break;
  49253. case (zoneL | zoneB): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49254. case zoneB: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49255. case (zoneR | zoneB): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49256. default: break;
  49257. }
  49258. setMouseCursor (mc);
  49259. }
  49260. }
  49261. END_JUCE_NAMESPACE
  49262. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49263. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49264. BEGIN_JUCE_NAMESPACE
  49265. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49266. ComponentBoundsConstrainer* const constrainer_)
  49267. : component (componentToResize),
  49268. constrainer (constrainer_)
  49269. {
  49270. setRepaintsOnMouseActivity (true);
  49271. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49272. }
  49273. ResizableCornerComponent::~ResizableCornerComponent()
  49274. {
  49275. }
  49276. void ResizableCornerComponent::paint (Graphics& g)
  49277. {
  49278. getLookAndFeel()
  49279. .drawCornerResizer (g, getWidth(), getHeight(),
  49280. isMouseOverOrDragging(),
  49281. isMouseButtonDown());
  49282. }
  49283. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49284. {
  49285. if (component == 0)
  49286. {
  49287. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49288. return;
  49289. }
  49290. originalBounds = component->getBounds();
  49291. if (constrainer != 0)
  49292. constrainer->resizeStart();
  49293. }
  49294. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49295. {
  49296. if (component == 0)
  49297. {
  49298. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49299. return;
  49300. }
  49301. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49302. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49303. if (constrainer != 0)
  49304. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49305. else
  49306. component->setBounds (r);
  49307. }
  49308. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49309. {
  49310. if (constrainer != 0)
  49311. constrainer->resizeStart();
  49312. }
  49313. bool ResizableCornerComponent::hitTest (int x, int y)
  49314. {
  49315. if (getWidth() <= 0)
  49316. return false;
  49317. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49318. return y >= yAtX - getHeight() / 4;
  49319. }
  49320. END_JUCE_NAMESPACE
  49321. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49322. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49323. BEGIN_JUCE_NAMESPACE
  49324. class ScrollbarButton : public Button
  49325. {
  49326. public:
  49327. int direction;
  49328. ScrollbarButton (const int direction_,
  49329. ScrollBar& owner_) throw()
  49330. : Button (String::empty),
  49331. direction (direction_),
  49332. owner (owner_)
  49333. {
  49334. setWantsKeyboardFocus (false);
  49335. }
  49336. ~ScrollbarButton()
  49337. {
  49338. }
  49339. void paintButton (Graphics& g,
  49340. bool isMouseOver,
  49341. bool isMouseDown)
  49342. {
  49343. getLookAndFeel()
  49344. .drawScrollbarButton (g, owner,
  49345. getWidth(), getHeight(),
  49346. direction,
  49347. owner.isVertical(),
  49348. isMouseOver, isMouseDown);
  49349. }
  49350. void clicked()
  49351. {
  49352. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49353. }
  49354. juce_UseDebuggingNewOperator
  49355. private:
  49356. ScrollBar& owner;
  49357. ScrollbarButton (const ScrollbarButton&);
  49358. ScrollbarButton& operator= (const ScrollbarButton&);
  49359. };
  49360. ScrollBar::ScrollBar (const bool vertical_,
  49361. const bool buttonsAreVisible)
  49362. : minimum (0.0),
  49363. maximum (1.0),
  49364. rangeStart (0.0),
  49365. rangeSize (0.1),
  49366. singleStepSize (0.1),
  49367. thumbAreaStart (0),
  49368. thumbAreaSize (0),
  49369. thumbStart (0),
  49370. thumbSize (0),
  49371. initialDelayInMillisecs (100),
  49372. repeatDelayInMillisecs (50),
  49373. minimumDelayInMillisecs (10),
  49374. vertical (vertical_),
  49375. isDraggingThumb (false),
  49376. alwaysVisible (false),
  49377. upButton (0),
  49378. downButton (0)
  49379. {
  49380. setButtonVisibility (buttonsAreVisible);
  49381. setRepaintsOnMouseActivity (true);
  49382. setFocusContainer (true);
  49383. }
  49384. ScrollBar::~ScrollBar()
  49385. {
  49386. deleteAllChildren();
  49387. }
  49388. void ScrollBar::setRangeLimits (const double newMinimum,
  49389. const double newMaximum) throw()
  49390. {
  49391. minimum = newMinimum;
  49392. maximum = newMaximum;
  49393. jassert (maximum >= minimum); // these can't be the wrong way round!
  49394. setCurrentRangeStart (rangeStart);
  49395. updateThumbPosition();
  49396. }
  49397. void ScrollBar::setCurrentRange (double newStart,
  49398. double newSize) throw()
  49399. {
  49400. newSize = jlimit (0.0, maximum - minimum, newSize);
  49401. newStart = jlimit (minimum, maximum - newSize, newStart);
  49402. if (rangeStart != newStart
  49403. || rangeSize != newSize)
  49404. {
  49405. rangeStart = newStart;
  49406. rangeSize = newSize;
  49407. updateThumbPosition();
  49408. triggerAsyncUpdate();
  49409. }
  49410. }
  49411. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  49412. {
  49413. setCurrentRange (newStart, rangeSize);
  49414. }
  49415. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  49416. {
  49417. singleStepSize = newSingleStepSize;
  49418. }
  49419. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  49420. {
  49421. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  49422. }
  49423. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  49424. {
  49425. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  49426. }
  49427. void ScrollBar::scrollToTop() throw()
  49428. {
  49429. setCurrentRangeStart (minimum);
  49430. }
  49431. void ScrollBar::scrollToBottom() throw()
  49432. {
  49433. setCurrentRangeStart (maximum - rangeSize);
  49434. }
  49435. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49436. const int repeatDelayInMillisecs_,
  49437. const int minimumDelayInMillisecs_) throw()
  49438. {
  49439. initialDelayInMillisecs = initialDelayInMillisecs_;
  49440. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49441. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49442. if (upButton != 0)
  49443. {
  49444. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49445. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49446. }
  49447. }
  49448. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  49449. {
  49450. listeners.add (listener);
  49451. }
  49452. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  49453. {
  49454. listeners.remove (listener);
  49455. }
  49456. void ScrollBar::handleAsyncUpdate()
  49457. {
  49458. listeners.call (&ScrollBarListener::scrollBarMoved, this, rangeStart);
  49459. }
  49460. void ScrollBar::updateThumbPosition() throw()
  49461. {
  49462. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  49463. : thumbAreaSize);
  49464. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49465. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49466. if (newThumbSize > thumbAreaSize)
  49467. newThumbSize = thumbAreaSize;
  49468. int newThumbStart = thumbAreaStart;
  49469. if (maximum - minimum > rangeSize)
  49470. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  49471. / ((maximum - minimum) - rangeSize));
  49472. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  49473. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49474. {
  49475. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49476. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49477. if (vertical)
  49478. repaint (0, repaintStart, getWidth(), repaintSize);
  49479. else
  49480. repaint (repaintStart, 0, repaintSize, getHeight());
  49481. thumbStart = newThumbStart;
  49482. thumbSize = newThumbSize;
  49483. }
  49484. }
  49485. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  49486. {
  49487. if (vertical != shouldBeVertical)
  49488. {
  49489. vertical = shouldBeVertical;
  49490. if (upButton != 0)
  49491. {
  49492. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  49493. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  49494. }
  49495. updateThumbPosition();
  49496. }
  49497. }
  49498. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49499. {
  49500. deleteAndZero (upButton);
  49501. deleteAndZero (downButton);
  49502. if (buttonsAreVisible)
  49503. {
  49504. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  49505. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  49506. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49507. }
  49508. updateThumbPosition();
  49509. }
  49510. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49511. {
  49512. alwaysVisible = ! shouldHideWhenFullRange;
  49513. updateThumbPosition();
  49514. }
  49515. void ScrollBar::paint (Graphics& g)
  49516. {
  49517. if (thumbAreaSize > 0)
  49518. {
  49519. LookAndFeel& lf = getLookAndFeel();
  49520. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49521. ? thumbSize : 0;
  49522. if (vertical)
  49523. {
  49524. lf.drawScrollbar (g, *this,
  49525. 0, thumbAreaStart,
  49526. getWidth(), thumbAreaSize,
  49527. vertical,
  49528. thumbStart, thumb,
  49529. isMouseOver(), isMouseButtonDown());
  49530. }
  49531. else
  49532. {
  49533. lf.drawScrollbar (g, *this,
  49534. thumbAreaStart, 0,
  49535. thumbAreaSize, getHeight(),
  49536. vertical,
  49537. thumbStart, thumb,
  49538. isMouseOver(), isMouseButtonDown());
  49539. }
  49540. }
  49541. }
  49542. void ScrollBar::lookAndFeelChanged()
  49543. {
  49544. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49545. }
  49546. void ScrollBar::resized()
  49547. {
  49548. const int length = ((vertical) ? getHeight() : getWidth());
  49549. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49550. : 0;
  49551. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49552. {
  49553. thumbAreaStart = length >> 1;
  49554. thumbAreaSize = 0;
  49555. }
  49556. else
  49557. {
  49558. thumbAreaStart = buttonSize;
  49559. thumbAreaSize = length - (buttonSize << 1);
  49560. }
  49561. if (upButton != 0)
  49562. {
  49563. if (vertical)
  49564. {
  49565. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49566. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49567. }
  49568. else
  49569. {
  49570. upButton->setBounds (0, 0, buttonSize, getHeight());
  49571. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49572. }
  49573. }
  49574. updateThumbPosition();
  49575. }
  49576. void ScrollBar::mouseDown (const MouseEvent& e)
  49577. {
  49578. isDraggingThumb = false;
  49579. lastMousePos = vertical ? e.y : e.x;
  49580. dragStartMousePos = lastMousePos;
  49581. dragStartRange = rangeStart;
  49582. if (dragStartMousePos < thumbStart)
  49583. {
  49584. moveScrollbarInPages (-1);
  49585. startTimer (400);
  49586. }
  49587. else if (dragStartMousePos >= thumbStart + thumbSize)
  49588. {
  49589. moveScrollbarInPages (1);
  49590. startTimer (400);
  49591. }
  49592. else
  49593. {
  49594. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49595. && (thumbAreaSize > thumbSize);
  49596. }
  49597. }
  49598. void ScrollBar::mouseDrag (const MouseEvent& e)
  49599. {
  49600. if (isDraggingThumb)
  49601. {
  49602. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49603. setCurrentRangeStart (dragStartRange
  49604. + deltaPixels * ((maximum - minimum) - rangeSize)
  49605. / (thumbAreaSize - thumbSize));
  49606. }
  49607. else
  49608. {
  49609. lastMousePos = (vertical) ? e.y : e.x;
  49610. }
  49611. }
  49612. void ScrollBar::mouseUp (const MouseEvent&)
  49613. {
  49614. isDraggingThumb = false;
  49615. stopTimer();
  49616. repaint();
  49617. }
  49618. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49619. float wheelIncrementX,
  49620. float wheelIncrementY)
  49621. {
  49622. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49623. if (increment < 0)
  49624. increment = jmin (increment * 10.0f, -1.0f);
  49625. else if (increment > 0)
  49626. increment = jmax (increment * 10.0f, 1.0f);
  49627. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  49628. }
  49629. void ScrollBar::timerCallback()
  49630. {
  49631. if (isMouseButtonDown())
  49632. {
  49633. startTimer (40);
  49634. if (lastMousePos < thumbStart)
  49635. setCurrentRangeStart (rangeStart - rangeSize);
  49636. else if (lastMousePos > thumbStart + thumbSize)
  49637. setCurrentRangeStart (rangeStart + rangeSize);
  49638. }
  49639. else
  49640. {
  49641. stopTimer();
  49642. }
  49643. }
  49644. bool ScrollBar::keyPressed (const KeyPress& key)
  49645. {
  49646. if (! isVisible())
  49647. return false;
  49648. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49649. moveScrollbarInSteps (-1);
  49650. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49651. moveScrollbarInSteps (1);
  49652. else if (key.isKeyCode (KeyPress::pageUpKey))
  49653. moveScrollbarInPages (-1);
  49654. else if (key.isKeyCode (KeyPress::pageDownKey))
  49655. moveScrollbarInPages (1);
  49656. else if (key.isKeyCode (KeyPress::homeKey))
  49657. scrollToTop();
  49658. else if (key.isKeyCode (KeyPress::endKey))
  49659. scrollToBottom();
  49660. else
  49661. return false;
  49662. return true;
  49663. }
  49664. END_JUCE_NAMESPACE
  49665. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49666. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49667. BEGIN_JUCE_NAMESPACE
  49668. StretchableLayoutManager::StretchableLayoutManager()
  49669. : totalSize (0)
  49670. {
  49671. }
  49672. StretchableLayoutManager::~StretchableLayoutManager()
  49673. {
  49674. }
  49675. void StretchableLayoutManager::clearAllItems()
  49676. {
  49677. items.clear();
  49678. totalSize = 0;
  49679. }
  49680. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49681. const double minimumSize,
  49682. const double maximumSize,
  49683. const double preferredSize)
  49684. {
  49685. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49686. if (layout == 0)
  49687. {
  49688. layout = new ItemLayoutProperties();
  49689. layout->itemIndex = itemIndex;
  49690. int i;
  49691. for (i = 0; i < items.size(); ++i)
  49692. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49693. break;
  49694. items.insert (i, layout);
  49695. }
  49696. layout->minSize = minimumSize;
  49697. layout->maxSize = maximumSize;
  49698. layout->preferredSize = preferredSize;
  49699. layout->currentSize = 0;
  49700. }
  49701. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49702. double& minimumSize,
  49703. double& maximumSize,
  49704. double& preferredSize) const
  49705. {
  49706. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49707. if (layout != 0)
  49708. {
  49709. minimumSize = layout->minSize;
  49710. maximumSize = layout->maxSize;
  49711. preferredSize = layout->preferredSize;
  49712. return true;
  49713. }
  49714. return false;
  49715. }
  49716. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49717. {
  49718. totalSize = newTotalSize;
  49719. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49720. }
  49721. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49722. {
  49723. int pos = 0;
  49724. for (int i = 0; i < itemIndex; ++i)
  49725. {
  49726. const ItemLayoutProperties* const layout = getInfoFor (i);
  49727. if (layout != 0)
  49728. pos += layout->currentSize;
  49729. }
  49730. return pos;
  49731. }
  49732. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49733. {
  49734. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49735. if (layout != 0)
  49736. return layout->currentSize;
  49737. return 0;
  49738. }
  49739. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49740. {
  49741. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49742. if (layout != 0)
  49743. return -layout->currentSize / (double) totalSize;
  49744. return 0;
  49745. }
  49746. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49747. int newPosition)
  49748. {
  49749. for (int i = items.size(); --i >= 0;)
  49750. {
  49751. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49752. if (layout->itemIndex == itemIndex)
  49753. {
  49754. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49755. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49756. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49757. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49758. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49759. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49760. endPos += layout->currentSize;
  49761. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49762. updatePrefSizesToMatchCurrentPositions();
  49763. break;
  49764. }
  49765. }
  49766. }
  49767. void StretchableLayoutManager::layOutComponents (Component** const components,
  49768. int numComponents,
  49769. int x, int y, int w, int h,
  49770. const bool vertically,
  49771. const bool resizeOtherDimension)
  49772. {
  49773. setTotalSize (vertically ? h : w);
  49774. int pos = vertically ? y : x;
  49775. for (int i = 0; i < numComponents; ++i)
  49776. {
  49777. const ItemLayoutProperties* const layout = getInfoFor (i);
  49778. if (layout != 0)
  49779. {
  49780. Component* const c = components[i];
  49781. if (c != 0)
  49782. {
  49783. if (i == numComponents - 1)
  49784. {
  49785. // if it's the last item, crop it to exactly fit the available space..
  49786. if (resizeOtherDimension)
  49787. {
  49788. if (vertically)
  49789. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49790. else
  49791. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49792. }
  49793. else
  49794. {
  49795. if (vertically)
  49796. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49797. else
  49798. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49799. }
  49800. }
  49801. else
  49802. {
  49803. if (resizeOtherDimension)
  49804. {
  49805. if (vertically)
  49806. c->setBounds (x, pos, w, layout->currentSize);
  49807. else
  49808. c->setBounds (pos, y, layout->currentSize, h);
  49809. }
  49810. else
  49811. {
  49812. if (vertically)
  49813. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49814. else
  49815. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49816. }
  49817. }
  49818. }
  49819. pos += layout->currentSize;
  49820. }
  49821. }
  49822. }
  49823. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49824. {
  49825. for (int i = items.size(); --i >= 0;)
  49826. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49827. return items.getUnchecked(i);
  49828. return 0;
  49829. }
  49830. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49831. const int endIndex,
  49832. const int availableSpace,
  49833. int startPos)
  49834. {
  49835. // calculate the total sizes
  49836. int i;
  49837. double totalIdealSize = 0.0;
  49838. int totalMinimums = 0;
  49839. for (i = startIndex; i < endIndex; ++i)
  49840. {
  49841. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49842. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49843. totalMinimums += layout->currentSize;
  49844. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49845. }
  49846. if (totalIdealSize <= 0)
  49847. totalIdealSize = 1.0;
  49848. // now calc the best sizes..
  49849. int extraSpace = availableSpace - totalMinimums;
  49850. while (extraSpace > 0)
  49851. {
  49852. int numWantingMoreSpace = 0;
  49853. int numHavingTakenExtraSpace = 0;
  49854. // first figure out how many comps want a slice of the extra space..
  49855. for (i = startIndex; i < endIndex; ++i)
  49856. {
  49857. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49858. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49859. const int bestSize = jlimit (layout->currentSize,
  49860. jmax (layout->currentSize,
  49861. sizeToRealSize (layout->maxSize, totalSize)),
  49862. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49863. if (bestSize > layout->currentSize)
  49864. ++numWantingMoreSpace;
  49865. }
  49866. // ..share out the extra space..
  49867. for (i = startIndex; i < endIndex; ++i)
  49868. {
  49869. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49870. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49871. int bestSize = jlimit (layout->currentSize,
  49872. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49873. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49874. const int extraWanted = bestSize - layout->currentSize;
  49875. if (extraWanted > 0)
  49876. {
  49877. const int extraAllowed = jmin (extraWanted,
  49878. extraSpace / jmax (1, numWantingMoreSpace));
  49879. if (extraAllowed > 0)
  49880. {
  49881. ++numHavingTakenExtraSpace;
  49882. --numWantingMoreSpace;
  49883. layout->currentSize += extraAllowed;
  49884. extraSpace -= extraAllowed;
  49885. }
  49886. }
  49887. }
  49888. if (numHavingTakenExtraSpace <= 0)
  49889. break;
  49890. }
  49891. // ..and calculate the end position
  49892. for (i = startIndex; i < endIndex; ++i)
  49893. {
  49894. ItemLayoutProperties* const layout = items.getUnchecked(i);
  49895. startPos += layout->currentSize;
  49896. }
  49897. return startPos;
  49898. }
  49899. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  49900. const int endIndex) const
  49901. {
  49902. int totalMinimums = 0;
  49903. for (int i = startIndex; i < endIndex; ++i)
  49904. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  49905. return totalMinimums;
  49906. }
  49907. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  49908. {
  49909. int totalMaximums = 0;
  49910. for (int i = startIndex; i < endIndex; ++i)
  49911. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  49912. return totalMaximums;
  49913. }
  49914. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  49915. {
  49916. for (int i = 0; i < items.size(); ++i)
  49917. {
  49918. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49919. layout->preferredSize
  49920. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  49921. : getItemCurrentAbsoluteSize (i);
  49922. }
  49923. }
  49924. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  49925. {
  49926. if (size < 0)
  49927. size *= -totalSpace;
  49928. return roundToInt (size);
  49929. }
  49930. END_JUCE_NAMESPACE
  49931. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  49932. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49933. BEGIN_JUCE_NAMESPACE
  49934. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  49935. const int itemIndex_,
  49936. const bool isVertical_)
  49937. : layout (layout_),
  49938. itemIndex (itemIndex_),
  49939. isVertical (isVertical_)
  49940. {
  49941. setRepaintsOnMouseActivity (true);
  49942. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  49943. : MouseCursor::UpDownResizeCursor));
  49944. }
  49945. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  49946. {
  49947. }
  49948. void StretchableLayoutResizerBar::paint (Graphics& g)
  49949. {
  49950. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  49951. getWidth(), getHeight(),
  49952. isVertical,
  49953. isMouseOver(),
  49954. isMouseButtonDown());
  49955. }
  49956. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  49957. {
  49958. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  49959. }
  49960. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  49961. {
  49962. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  49963. : e.getDistanceFromDragStartY());
  49964. layout->setItemPosition (itemIndex, desiredPos);
  49965. hasBeenMoved();
  49966. }
  49967. void StretchableLayoutResizerBar::hasBeenMoved()
  49968. {
  49969. if (getParentComponent() != 0)
  49970. getParentComponent()->resized();
  49971. }
  49972. END_JUCE_NAMESPACE
  49973. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49974. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  49975. BEGIN_JUCE_NAMESPACE
  49976. StretchableObjectResizer::StretchableObjectResizer()
  49977. {
  49978. }
  49979. StretchableObjectResizer::~StretchableObjectResizer()
  49980. {
  49981. }
  49982. void StretchableObjectResizer::addItem (const double size,
  49983. const double minSize, const double maxSize,
  49984. const int order)
  49985. {
  49986. // the order must be >= 0 but less than the maximum integer value.
  49987. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  49988. Item* const item = new Item();
  49989. item->size = size;
  49990. item->minSize = minSize;
  49991. item->maxSize = maxSize;
  49992. item->order = order;
  49993. items.add (item);
  49994. }
  49995. double StretchableObjectResizer::getItemSize (const int index) const throw()
  49996. {
  49997. const Item* const it = items [index];
  49998. return it != 0 ? it->size : 0;
  49999. }
  50000. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50001. {
  50002. int order = 0;
  50003. for (;;)
  50004. {
  50005. double currentSize = 0;
  50006. double minSize = 0;
  50007. double maxSize = 0;
  50008. int nextHighestOrder = std::numeric_limits<int>::max();
  50009. for (int i = 0; i < items.size(); ++i)
  50010. {
  50011. const Item* const it = items.getUnchecked(i);
  50012. currentSize += it->size;
  50013. if (it->order <= order)
  50014. {
  50015. minSize += it->minSize;
  50016. maxSize += it->maxSize;
  50017. }
  50018. else
  50019. {
  50020. minSize += it->size;
  50021. maxSize += it->size;
  50022. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50023. }
  50024. }
  50025. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50026. if (thisIterationTarget >= currentSize)
  50027. {
  50028. const double availableExtraSpace = maxSize - currentSize;
  50029. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50030. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50031. for (int i = 0; i < items.size(); ++i)
  50032. {
  50033. Item* const it = items.getUnchecked(i);
  50034. if (it->order <= order)
  50035. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50036. }
  50037. }
  50038. else
  50039. {
  50040. const double amountOfSlack = currentSize - minSize;
  50041. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50042. const double scale = targetAmountOfSlack / amountOfSlack;
  50043. for (int i = 0; i < items.size(); ++i)
  50044. {
  50045. Item* const it = items.getUnchecked(i);
  50046. if (it->order <= order)
  50047. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50048. }
  50049. }
  50050. if (nextHighestOrder < std::numeric_limits<int>::max())
  50051. order = nextHighestOrder;
  50052. else
  50053. break;
  50054. }
  50055. }
  50056. END_JUCE_NAMESPACE
  50057. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50058. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50059. BEGIN_JUCE_NAMESPACE
  50060. TabBarButton::TabBarButton (const String& name,
  50061. TabbedButtonBar* const owner_,
  50062. const int index)
  50063. : Button (name),
  50064. owner (owner_),
  50065. tabIndex (index),
  50066. overlapPixels (0)
  50067. {
  50068. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50069. setComponentEffect (&shadow);
  50070. setWantsKeyboardFocus (false);
  50071. }
  50072. TabBarButton::~TabBarButton()
  50073. {
  50074. }
  50075. void TabBarButton::paintButton (Graphics& g,
  50076. bool isMouseOverButton,
  50077. bool isButtonDown)
  50078. {
  50079. int x, y, w, h;
  50080. getActiveArea (x, y, w, h);
  50081. g.setOrigin (x, y);
  50082. getLookAndFeel()
  50083. .drawTabButton (g, w, h,
  50084. owner->getTabBackgroundColour (tabIndex),
  50085. tabIndex, getButtonText(), *this,
  50086. owner->getOrientation(),
  50087. isMouseOverButton, isButtonDown,
  50088. getToggleState());
  50089. }
  50090. void TabBarButton::clicked (const ModifierKeys& mods)
  50091. {
  50092. if (mods.isPopupMenu())
  50093. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50094. else
  50095. owner->setCurrentTabIndex (tabIndex);
  50096. }
  50097. bool TabBarButton::hitTest (int mx, int my)
  50098. {
  50099. int x, y, w, h;
  50100. getActiveArea (x, y, w, h);
  50101. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50102. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50103. {
  50104. if (((unsigned int) mx) < (unsigned int) getWidth()
  50105. && my >= y + overlapPixels
  50106. && my < y + h - overlapPixels)
  50107. return true;
  50108. }
  50109. else
  50110. {
  50111. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50112. && ((unsigned int) my) < (unsigned int) getHeight())
  50113. return true;
  50114. }
  50115. Path p;
  50116. getLookAndFeel()
  50117. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50118. owner->getOrientation(),
  50119. false, false, getToggleState());
  50120. return p.contains ((float) (mx - x),
  50121. (float) (my - y));
  50122. }
  50123. int TabBarButton::getBestTabLength (const int depth)
  50124. {
  50125. return jlimit (depth * 2,
  50126. depth * 7,
  50127. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50128. }
  50129. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50130. {
  50131. x = 0;
  50132. y = 0;
  50133. int r = getWidth();
  50134. int b = getHeight();
  50135. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50136. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50137. r -= spaceAroundImage;
  50138. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50139. x += spaceAroundImage;
  50140. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50141. y += spaceAroundImage;
  50142. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50143. b -= spaceAroundImage;
  50144. w = r - x;
  50145. h = b - y;
  50146. }
  50147. class TabAreaBehindFrontButtonComponent : public Component
  50148. {
  50149. public:
  50150. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50151. : owner (owner_)
  50152. {
  50153. setInterceptsMouseClicks (false, false);
  50154. }
  50155. ~TabAreaBehindFrontButtonComponent()
  50156. {
  50157. }
  50158. void paint (Graphics& g)
  50159. {
  50160. getLookAndFeel()
  50161. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50162. *owner, owner->getOrientation());
  50163. }
  50164. void enablementChanged()
  50165. {
  50166. repaint();
  50167. }
  50168. private:
  50169. TabbedButtonBar* const owner;
  50170. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50171. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50172. };
  50173. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50174. : orientation (orientation_),
  50175. currentTabIndex (-1),
  50176. extraTabsButton (0)
  50177. {
  50178. setInterceptsMouseClicks (false, true);
  50179. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50180. setFocusContainer (true);
  50181. }
  50182. TabbedButtonBar::~TabbedButtonBar()
  50183. {
  50184. deleteAllChildren();
  50185. }
  50186. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50187. {
  50188. orientation = newOrientation;
  50189. for (int i = getNumChildComponents(); --i >= 0;)
  50190. getChildComponent (i)->resized();
  50191. resized();
  50192. }
  50193. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50194. {
  50195. return new TabBarButton (name, this, index);
  50196. }
  50197. void TabbedButtonBar::clearTabs()
  50198. {
  50199. tabs.clear();
  50200. tabColours.clear();
  50201. currentTabIndex = -1;
  50202. deleteAndZero (extraTabsButton);
  50203. removeChildComponent (behindFrontTab);
  50204. deleteAllChildren();
  50205. addChildComponent (behindFrontTab);
  50206. setCurrentTabIndex (-1);
  50207. }
  50208. void TabbedButtonBar::addTab (const String& tabName,
  50209. const Colour& tabBackgroundColour,
  50210. int insertIndex)
  50211. {
  50212. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50213. if (tabName.isNotEmpty())
  50214. {
  50215. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50216. insertIndex = tabs.size();
  50217. for (int i = tabs.size(); --i >= insertIndex;)
  50218. {
  50219. TabBarButton* const tb = getTabButton (i);
  50220. if (tb != 0)
  50221. tb->tabIndex++;
  50222. }
  50223. tabs.insert (insertIndex, tabName);
  50224. tabColours.insert (insertIndex, tabBackgroundColour);
  50225. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50226. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50227. addAndMakeVisible (tb, insertIndex);
  50228. resized();
  50229. if (currentTabIndex < 0)
  50230. setCurrentTabIndex (0);
  50231. }
  50232. }
  50233. void TabbedButtonBar::setTabName (const int tabIndex,
  50234. const String& newName)
  50235. {
  50236. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50237. && tabs[tabIndex] != newName)
  50238. {
  50239. tabs.set (tabIndex, newName);
  50240. TabBarButton* const tb = getTabButton (tabIndex);
  50241. if (tb != 0)
  50242. tb->setButtonText (newName);
  50243. resized();
  50244. }
  50245. }
  50246. void TabbedButtonBar::removeTab (const int tabIndex)
  50247. {
  50248. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50249. {
  50250. const int oldTabIndex = currentTabIndex;
  50251. if (currentTabIndex == tabIndex)
  50252. currentTabIndex = -1;
  50253. tabs.remove (tabIndex);
  50254. tabColours.remove (tabIndex);
  50255. delete getTabButton (tabIndex);
  50256. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50257. {
  50258. TabBarButton* const tb = getTabButton (i);
  50259. if (tb != 0)
  50260. tb->tabIndex--;
  50261. }
  50262. resized();
  50263. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50264. }
  50265. }
  50266. void TabbedButtonBar::moveTab (const int currentIndex,
  50267. const int newIndex)
  50268. {
  50269. tabs.move (currentIndex, newIndex);
  50270. tabColours.move (currentIndex, newIndex);
  50271. resized();
  50272. }
  50273. int TabbedButtonBar::getNumTabs() const
  50274. {
  50275. return tabs.size();
  50276. }
  50277. const StringArray TabbedButtonBar::getTabNames() const
  50278. {
  50279. return tabs;
  50280. }
  50281. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50282. {
  50283. if (currentTabIndex != newIndex)
  50284. {
  50285. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50286. newIndex = -1;
  50287. currentTabIndex = newIndex;
  50288. for (int i = 0; i < getNumChildComponents(); ++i)
  50289. {
  50290. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50291. if (tb != 0)
  50292. tb->setToggleState (tb->tabIndex == newIndex, false);
  50293. }
  50294. resized();
  50295. if (sendChangeMessage_)
  50296. sendChangeMessage (this);
  50297. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50298. }
  50299. }
  50300. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50301. {
  50302. for (int i = getNumChildComponents(); --i >= 0;)
  50303. {
  50304. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50305. if (tb != 0 && tb->tabIndex == index)
  50306. return tb;
  50307. }
  50308. return 0;
  50309. }
  50310. void TabbedButtonBar::lookAndFeelChanged()
  50311. {
  50312. deleteAndZero (extraTabsButton);
  50313. resized();
  50314. }
  50315. void TabbedButtonBar::resized()
  50316. {
  50317. const double minimumScale = 0.7;
  50318. int depth = getWidth();
  50319. int length = getHeight();
  50320. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50321. swapVariables (depth, length);
  50322. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50323. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50324. int i, totalLength = overlap;
  50325. int numVisibleButtons = tabs.size();
  50326. for (i = 0; i < getNumChildComponents(); ++i)
  50327. {
  50328. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50329. if (tb != 0)
  50330. {
  50331. totalLength += tb->getBestTabLength (depth) - overlap;
  50332. tb->overlapPixels = overlap / 2;
  50333. }
  50334. }
  50335. double scale = 1.0;
  50336. if (totalLength > length)
  50337. scale = jmax (minimumScale, length / (double) totalLength);
  50338. const bool isTooBig = totalLength * scale > length;
  50339. int tabsButtonPos = 0;
  50340. if (isTooBig)
  50341. {
  50342. if (extraTabsButton == 0)
  50343. {
  50344. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50345. extraTabsButton->addButtonListener (this);
  50346. extraTabsButton->setAlwaysOnTop (true);
  50347. extraTabsButton->setTriggeredOnMouseDown (true);
  50348. }
  50349. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50350. extraTabsButton->setSize (buttonSize, buttonSize);
  50351. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50352. {
  50353. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50354. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50355. }
  50356. else
  50357. {
  50358. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50359. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50360. }
  50361. totalLength = 0;
  50362. for (i = 0; i < tabs.size(); ++i)
  50363. {
  50364. TabBarButton* const tb = getTabButton (i);
  50365. if (tb != 0)
  50366. {
  50367. const int newLength = totalLength + tb->getBestTabLength (depth);
  50368. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50369. {
  50370. totalLength += overlap;
  50371. break;
  50372. }
  50373. numVisibleButtons = i + 1;
  50374. totalLength = newLength - overlap;
  50375. }
  50376. }
  50377. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50378. }
  50379. else
  50380. {
  50381. deleteAndZero (extraTabsButton);
  50382. }
  50383. int pos = 0;
  50384. TabBarButton* frontTab = 0;
  50385. for (i = 0; i < tabs.size(); ++i)
  50386. {
  50387. TabBarButton* const tb = getTabButton (i);
  50388. if (tb != 0)
  50389. {
  50390. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50391. if (i < numVisibleButtons)
  50392. {
  50393. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50394. tb->setBounds (pos, 0, bestLength, getHeight());
  50395. else
  50396. tb->setBounds (0, pos, getWidth(), bestLength);
  50397. tb->toBack();
  50398. if (tb->tabIndex == currentTabIndex)
  50399. frontTab = tb;
  50400. tb->setVisible (true);
  50401. }
  50402. else
  50403. {
  50404. tb->setVisible (false);
  50405. }
  50406. pos += bestLength - overlap;
  50407. }
  50408. }
  50409. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50410. if (frontTab != 0)
  50411. {
  50412. frontTab->toFront (false);
  50413. behindFrontTab->toBehind (frontTab);
  50414. }
  50415. }
  50416. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50417. {
  50418. return tabColours [tabIndex];
  50419. }
  50420. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50421. {
  50422. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50423. && tabColours [tabIndex] != newColour)
  50424. {
  50425. tabColours.set (tabIndex, newColour);
  50426. repaint();
  50427. }
  50428. }
  50429. void TabbedButtonBar::buttonClicked (Button* button)
  50430. {
  50431. if (extraTabsButton == button)
  50432. {
  50433. PopupMenu m;
  50434. for (int i = 0; i < tabs.size(); ++i)
  50435. {
  50436. TabBarButton* const tb = getTabButton (i);
  50437. if (tb != 0 && ! tb->isVisible())
  50438. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50439. }
  50440. const int res = m.showAt (extraTabsButton);
  50441. if (res != 0)
  50442. setCurrentTabIndex (res - 1);
  50443. }
  50444. }
  50445. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50446. {
  50447. }
  50448. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50449. {
  50450. }
  50451. END_JUCE_NAMESPACE
  50452. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50453. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50454. BEGIN_JUCE_NAMESPACE
  50455. class TabCompButtonBar : public TabbedButtonBar
  50456. {
  50457. public:
  50458. TabCompButtonBar (TabbedComponent* const owner_,
  50459. const TabbedButtonBar::Orientation orientation)
  50460. : TabbedButtonBar (orientation),
  50461. owner (owner_)
  50462. {
  50463. }
  50464. ~TabCompButtonBar()
  50465. {
  50466. }
  50467. void currentTabChanged (const int newCurrentTabIndex,
  50468. const String& newTabName)
  50469. {
  50470. owner->changeCallback (newCurrentTabIndex, newTabName);
  50471. }
  50472. void popupMenuClickOnTab (const int tabIndex,
  50473. const String& tabName)
  50474. {
  50475. owner->popupMenuClickOnTab (tabIndex, tabName);
  50476. }
  50477. const Colour getTabBackgroundColour (const int tabIndex)
  50478. {
  50479. return owner->tabs->getTabBackgroundColour (tabIndex);
  50480. }
  50481. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  50482. {
  50483. return owner->createTabButton (tabName, tabIndex);
  50484. }
  50485. juce_UseDebuggingNewOperator
  50486. private:
  50487. TabbedComponent* const owner;
  50488. TabCompButtonBar (const TabCompButtonBar&);
  50489. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50490. };
  50491. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50492. : panelComponent (0),
  50493. tabDepth (30),
  50494. outlineThickness (1),
  50495. edgeIndent (0)
  50496. {
  50497. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50498. }
  50499. TabbedComponent::~TabbedComponent()
  50500. {
  50501. clearTabs();
  50502. delete tabs;
  50503. }
  50504. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50505. {
  50506. tabs->setOrientation (orientation);
  50507. resized();
  50508. }
  50509. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50510. {
  50511. return tabs->getOrientation();
  50512. }
  50513. void TabbedComponent::setTabBarDepth (const int newDepth)
  50514. {
  50515. if (tabDepth != newDepth)
  50516. {
  50517. tabDepth = newDepth;
  50518. resized();
  50519. }
  50520. }
  50521. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50522. {
  50523. return new TabBarButton (tabName, tabs, tabIndex);
  50524. }
  50525. void TabbedComponent::clearTabs()
  50526. {
  50527. if (panelComponent != 0)
  50528. {
  50529. panelComponent->setVisible (false);
  50530. removeChildComponent (panelComponent);
  50531. panelComponent = 0;
  50532. }
  50533. tabs->clearTabs();
  50534. for (int i = contentComponents.size(); --i >= 0;)
  50535. {
  50536. Component* const c = contentComponents.getUnchecked(i);
  50537. // be careful not to delete these components until they've been removed from the tab component
  50538. jassert (c == 0 || c->isValidComponent());
  50539. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50540. delete c;
  50541. }
  50542. contentComponents.clear();
  50543. }
  50544. void TabbedComponent::addTab (const String& tabName,
  50545. const Colour& tabBackgroundColour,
  50546. Component* const contentComponent,
  50547. const bool deleteComponentWhenNotNeeded,
  50548. const int insertIndex)
  50549. {
  50550. contentComponents.insert (insertIndex, contentComponent);
  50551. if (contentComponent != 0)
  50552. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50553. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50554. }
  50555. void TabbedComponent::setTabName (const int tabIndex,
  50556. const String& newName)
  50557. {
  50558. tabs->setTabName (tabIndex, newName);
  50559. }
  50560. void TabbedComponent::removeTab (const int tabIndex)
  50561. {
  50562. Component* const c = contentComponents [tabIndex];
  50563. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50564. {
  50565. if (c == panelComponent)
  50566. panelComponent = 0;
  50567. delete c;
  50568. }
  50569. contentComponents.remove (tabIndex);
  50570. tabs->removeTab (tabIndex);
  50571. }
  50572. int TabbedComponent::getNumTabs() const
  50573. {
  50574. return tabs->getNumTabs();
  50575. }
  50576. const StringArray TabbedComponent::getTabNames() const
  50577. {
  50578. return tabs->getTabNames();
  50579. }
  50580. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50581. {
  50582. return contentComponents [tabIndex];
  50583. }
  50584. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50585. {
  50586. return tabs->getTabBackgroundColour (tabIndex);
  50587. }
  50588. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50589. {
  50590. tabs->setTabBackgroundColour (tabIndex, newColour);
  50591. if (getCurrentTabIndex() == tabIndex)
  50592. repaint();
  50593. }
  50594. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50595. {
  50596. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50597. }
  50598. int TabbedComponent::getCurrentTabIndex() const
  50599. {
  50600. return tabs->getCurrentTabIndex();
  50601. }
  50602. const String& TabbedComponent::getCurrentTabName() const
  50603. {
  50604. return tabs->getCurrentTabName();
  50605. }
  50606. void TabbedComponent::setOutline (int thickness)
  50607. {
  50608. outlineThickness = thickness;
  50609. repaint();
  50610. }
  50611. void TabbedComponent::setIndent (const int indentThickness)
  50612. {
  50613. edgeIndent = indentThickness;
  50614. }
  50615. void TabbedComponent::paint (Graphics& g)
  50616. {
  50617. g.fillAll (findColour (backgroundColourId));
  50618. const TabbedButtonBar::Orientation o = getOrientation();
  50619. int x = 0;
  50620. int y = 0;
  50621. int r = getWidth();
  50622. int b = getHeight();
  50623. if (o == TabbedButtonBar::TabsAtTop)
  50624. y += tabDepth;
  50625. else if (o == TabbedButtonBar::TabsAtBottom)
  50626. b -= tabDepth;
  50627. else if (o == TabbedButtonBar::TabsAtLeft)
  50628. x += tabDepth;
  50629. else if (o == TabbedButtonBar::TabsAtRight)
  50630. r -= tabDepth;
  50631. g.reduceClipRegion (x, y, r - x, b - y);
  50632. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50633. if (outlineThickness > 0)
  50634. {
  50635. if (o == TabbedButtonBar::TabsAtTop)
  50636. --y;
  50637. else if (o == TabbedButtonBar::TabsAtBottom)
  50638. ++b;
  50639. else if (o == TabbedButtonBar::TabsAtLeft)
  50640. --x;
  50641. else if (o == TabbedButtonBar::TabsAtRight)
  50642. ++r;
  50643. g.setColour (findColour (outlineColourId));
  50644. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50645. }
  50646. }
  50647. void TabbedComponent::resized()
  50648. {
  50649. const TabbedButtonBar::Orientation o = getOrientation();
  50650. const int indent = edgeIndent + outlineThickness;
  50651. BorderSize indents (indent);
  50652. if (o == TabbedButtonBar::TabsAtTop)
  50653. {
  50654. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50655. indents.setTop (tabDepth + edgeIndent);
  50656. }
  50657. else if (o == TabbedButtonBar::TabsAtBottom)
  50658. {
  50659. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50660. indents.setBottom (tabDepth + edgeIndent);
  50661. }
  50662. else if (o == TabbedButtonBar::TabsAtLeft)
  50663. {
  50664. tabs->setBounds (0, 0, tabDepth, getHeight());
  50665. indents.setLeft (tabDepth + edgeIndent);
  50666. }
  50667. else if (o == TabbedButtonBar::TabsAtRight)
  50668. {
  50669. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50670. indents.setRight (tabDepth + edgeIndent);
  50671. }
  50672. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  50673. for (int i = contentComponents.size(); --i >= 0;)
  50674. if (contentComponents.getUnchecked (i) != 0)
  50675. contentComponents.getUnchecked (i)->setBounds (bounds);
  50676. }
  50677. void TabbedComponent::lookAndFeelChanged()
  50678. {
  50679. for (int i = contentComponents.size(); --i >= 0;)
  50680. if (contentComponents.getUnchecked (i) != 0)
  50681. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50682. }
  50683. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50684. const String& newTabName)
  50685. {
  50686. if (panelComponent != 0)
  50687. {
  50688. panelComponent->setVisible (false);
  50689. removeChildComponent (panelComponent);
  50690. panelComponent = 0;
  50691. }
  50692. if (getCurrentTabIndex() >= 0)
  50693. {
  50694. panelComponent = contentComponents [getCurrentTabIndex()];
  50695. if (panelComponent != 0)
  50696. {
  50697. // do these ops as two stages instead of addAndMakeVisible() so that the
  50698. // component has always got a parent when it gets the visibilityChanged() callback
  50699. addChildComponent (panelComponent);
  50700. panelComponent->setVisible (true);
  50701. panelComponent->toFront (true);
  50702. }
  50703. repaint();
  50704. }
  50705. resized();
  50706. currentTabChanged (newCurrentTabIndex, newTabName);
  50707. }
  50708. void TabbedComponent::currentTabChanged (const int, const String&)
  50709. {
  50710. }
  50711. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50712. {
  50713. }
  50714. END_JUCE_NAMESPACE
  50715. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50716. /*** Start of inlined file: juce_Viewport.cpp ***/
  50717. BEGIN_JUCE_NAMESPACE
  50718. Viewport::Viewport (const String& componentName)
  50719. : Component (componentName),
  50720. contentComp (0),
  50721. lastVX (0),
  50722. lastVY (0),
  50723. lastVW (0),
  50724. lastVH (0),
  50725. scrollBarThickness (0),
  50726. singleStepX (16),
  50727. singleStepY (16),
  50728. showHScrollbar (true),
  50729. showVScrollbar (true)
  50730. {
  50731. // content holder is used to clip the contents so they don't overlap the scrollbars
  50732. addAndMakeVisible (contentHolder = new Component());
  50733. contentHolder->setInterceptsMouseClicks (false, true);
  50734. verticalScrollBar = new ScrollBar (true);
  50735. horizontalScrollBar = new ScrollBar (false);
  50736. addChildComponent (verticalScrollBar);
  50737. addChildComponent (horizontalScrollBar);
  50738. verticalScrollBar->addListener (this);
  50739. horizontalScrollBar->addListener (this);
  50740. setInterceptsMouseClicks (false, true);
  50741. setWantsKeyboardFocus (true);
  50742. }
  50743. Viewport::~Viewport()
  50744. {
  50745. contentHolder->deleteAllChildren();
  50746. deleteAllChildren();
  50747. }
  50748. void Viewport::visibleAreaChanged (int, int, int, int)
  50749. {
  50750. }
  50751. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50752. {
  50753. if (contentComp.getComponent() != newViewedComponent)
  50754. {
  50755. {
  50756. ScopedPointer<Component> oldCompDeleter (contentComp);
  50757. contentComp = 0;
  50758. }
  50759. contentComp = newViewedComponent;
  50760. if (contentComp != 0)
  50761. {
  50762. contentComp->setTopLeftPosition (0, 0);
  50763. contentHolder->addAndMakeVisible (contentComp);
  50764. contentComp->addComponentListener (this);
  50765. }
  50766. updateVisibleRegion();
  50767. }
  50768. }
  50769. int Viewport::getMaximumVisibleWidth() const throw()
  50770. {
  50771. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50772. }
  50773. int Viewport::getMaximumVisibleHeight() const throw()
  50774. {
  50775. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50776. }
  50777. void Viewport::setViewPosition (const int xPixelsOffset,
  50778. const int yPixelsOffset)
  50779. {
  50780. if (contentComp != 0)
  50781. contentComp->setTopLeftPosition (-xPixelsOffset,
  50782. -yPixelsOffset);
  50783. }
  50784. void Viewport::setViewPositionProportionately (const double x,
  50785. const double y)
  50786. {
  50787. if (contentComp != 0)
  50788. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50789. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50790. }
  50791. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50792. {
  50793. if (contentComp != 0)
  50794. {
  50795. int dx = 0, dy = 0;
  50796. if (mouseX < activeBorderThickness)
  50797. dx = activeBorderThickness - mouseX;
  50798. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50799. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50800. if (dx < 0)
  50801. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50802. else
  50803. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50804. if (mouseY < activeBorderThickness)
  50805. dy = activeBorderThickness - mouseY;
  50806. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50807. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50808. if (dy < 0)
  50809. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50810. else
  50811. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50812. if (dx != 0 || dy != 0)
  50813. {
  50814. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50815. contentComp->getY() + dy);
  50816. return true;
  50817. }
  50818. }
  50819. return false;
  50820. }
  50821. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50822. {
  50823. updateVisibleRegion();
  50824. }
  50825. void Viewport::resized()
  50826. {
  50827. updateVisibleRegion();
  50828. }
  50829. void Viewport::updateVisibleRegion()
  50830. {
  50831. if (contentComp != 0)
  50832. {
  50833. const int newVX = -contentComp->getX();
  50834. const int newVY = -contentComp->getY();
  50835. if (newVX == 0 && newVY == 0
  50836. && contentComp->getWidth() <= getWidth()
  50837. && contentComp->getHeight() <= getHeight())
  50838. {
  50839. horizontalScrollBar->setVisible (false);
  50840. verticalScrollBar->setVisible (false);
  50841. }
  50842. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50843. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50844. horizontalScrollBar->setSingleStepSize (singleStepX);
  50845. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50846. horizontalScrollBar->setVisible (false);
  50847. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50848. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50849. verticalScrollBar->setSingleStepSize (singleStepY);
  50850. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50851. verticalScrollBar->setVisible (false);
  50852. if (verticalScrollBar->isVisible())
  50853. {
  50854. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50855. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50856. verticalScrollBar
  50857. ->setBounds (getMaximumVisibleWidth(), 0,
  50858. getScrollBarThickness(), getMaximumVisibleHeight());
  50859. }
  50860. if (horizontalScrollBar->isVisible())
  50861. {
  50862. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50863. horizontalScrollBar
  50864. ->setBounds (0, getMaximumVisibleHeight(),
  50865. getMaximumVisibleWidth(), getScrollBarThickness());
  50866. }
  50867. contentHolder->setSize (getMaximumVisibleWidth(),
  50868. getMaximumVisibleHeight());
  50869. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50870. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50871. if (newVX != lastVX
  50872. || newVY != lastVY
  50873. || newVW != lastVW
  50874. || newVH != lastVH)
  50875. {
  50876. lastVX = newVX;
  50877. lastVY = newVY;
  50878. lastVW = newVW;
  50879. lastVH = newVH;
  50880. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50881. }
  50882. horizontalScrollBar->handleUpdateNowIfNeeded();
  50883. verticalScrollBar->handleUpdateNowIfNeeded();
  50884. }
  50885. else
  50886. {
  50887. horizontalScrollBar->setVisible (false);
  50888. verticalScrollBar->setVisible (false);
  50889. }
  50890. }
  50891. void Viewport::setSingleStepSizes (const int stepX,
  50892. const int stepY)
  50893. {
  50894. singleStepX = stepX;
  50895. singleStepY = stepY;
  50896. updateVisibleRegion();
  50897. }
  50898. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  50899. const bool showHorizontalScrollbarIfNeeded)
  50900. {
  50901. showVScrollbar = showVerticalScrollbarIfNeeded;
  50902. showHScrollbar = showHorizontalScrollbarIfNeeded;
  50903. updateVisibleRegion();
  50904. }
  50905. void Viewport::setScrollBarThickness (const int thickness)
  50906. {
  50907. scrollBarThickness = thickness;
  50908. updateVisibleRegion();
  50909. }
  50910. int Viewport::getScrollBarThickness() const throw()
  50911. {
  50912. return (scrollBarThickness > 0) ? scrollBarThickness
  50913. : getLookAndFeel().getDefaultScrollbarWidth();
  50914. }
  50915. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  50916. {
  50917. verticalScrollBar->setButtonVisibility (buttonsVisible);
  50918. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  50919. }
  50920. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  50921. {
  50922. if (scrollBarThatHasMoved == horizontalScrollBar)
  50923. {
  50924. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  50925. }
  50926. else if (scrollBarThatHasMoved == verticalScrollBar)
  50927. {
  50928. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  50929. }
  50930. }
  50931. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50932. {
  50933. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  50934. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  50935. }
  50936. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50937. {
  50938. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  50939. {
  50940. const bool hasVertBar = verticalScrollBar->isVisible();
  50941. const bool hasHorzBar = horizontalScrollBar->isVisible();
  50942. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  50943. {
  50944. if (wheelIncrementX == 0 && ! hasVertBar)
  50945. wheelIncrementX = wheelIncrementY;
  50946. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  50947. wheelIncrementX, wheelIncrementY);
  50948. return true;
  50949. }
  50950. else if (hasVertBar && wheelIncrementY != 0)
  50951. {
  50952. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  50953. wheelIncrementX, wheelIncrementY);
  50954. return true;
  50955. }
  50956. }
  50957. return false;
  50958. }
  50959. bool Viewport::keyPressed (const KeyPress& key)
  50960. {
  50961. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  50962. || key.isKeyCode (KeyPress::downKey)
  50963. || key.isKeyCode (KeyPress::pageUpKey)
  50964. || key.isKeyCode (KeyPress::pageDownKey)
  50965. || key.isKeyCode (KeyPress::homeKey)
  50966. || key.isKeyCode (KeyPress::endKey);
  50967. if (verticalScrollBar->isVisible() && isUpDownKey)
  50968. return verticalScrollBar->keyPressed (key);
  50969. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  50970. || key.isKeyCode (KeyPress::rightKey);
  50971. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  50972. return horizontalScrollBar->keyPressed (key);
  50973. return false;
  50974. }
  50975. END_JUCE_NAMESPACE
  50976. /*** End of inlined file: juce_Viewport.cpp ***/
  50977. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  50978. BEGIN_JUCE_NAMESPACE
  50979. static const Colour createBaseColour (const Colour& buttonColour,
  50980. const bool hasKeyboardFocus,
  50981. const bool isMouseOverButton,
  50982. const bool isButtonDown) throw()
  50983. {
  50984. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  50985. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  50986. if (isButtonDown)
  50987. return baseColour.contrasting (0.2f);
  50988. else if (isMouseOverButton)
  50989. return baseColour.contrasting (0.1f);
  50990. return baseColour;
  50991. }
  50992. LookAndFeel::LookAndFeel()
  50993. {
  50994. /* if this fails it means you're trying to create a LookAndFeel object before
  50995. the static Colours have been initialised. That ain't gonna work. It probably
  50996. means that you're using a static LookAndFeel object and that your compiler has
  50997. decided to intialise it before the Colours class.
  50998. */
  50999. jassert (Colours::white == Colour (0xffffffff));
  51000. // set up the standard set of colours..
  51001. const int textButtonColour = 0xffbbbbff;
  51002. const int textHighlightColour = 0x401111ee;
  51003. const int standardOutlineColour = 0xb2808080;
  51004. static const int standardColours[] =
  51005. {
  51006. TextButton::buttonColourId, textButtonColour,
  51007. TextButton::buttonOnColourId, 0xff4444ff,
  51008. TextButton::textColourOnId, 0xff000000,
  51009. TextButton::textColourOffId, 0xff000000,
  51010. ComboBox::buttonColourId, 0xffbbbbff,
  51011. ComboBox::outlineColourId, standardOutlineColour,
  51012. ToggleButton::textColourId, 0xff000000,
  51013. TextEditor::backgroundColourId, 0xffffffff,
  51014. TextEditor::textColourId, 0xff000000,
  51015. TextEditor::highlightColourId, textHighlightColour,
  51016. TextEditor::highlightedTextColourId, 0xff000000,
  51017. TextEditor::caretColourId, 0xff000000,
  51018. TextEditor::outlineColourId, 0x00000000,
  51019. TextEditor::focusedOutlineColourId, textButtonColour,
  51020. TextEditor::shadowColourId, 0x38000000,
  51021. Label::backgroundColourId, 0x00000000,
  51022. Label::textColourId, 0xff000000,
  51023. Label::outlineColourId, 0x00000000,
  51024. ScrollBar::backgroundColourId, 0x00000000,
  51025. ScrollBar::thumbColourId, 0xffffffff,
  51026. ScrollBar::trackColourId, 0xffffffff,
  51027. TreeView::linesColourId, 0x4c000000,
  51028. TreeView::backgroundColourId, 0x00000000,
  51029. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51030. PopupMenu::backgroundColourId, 0xffffffff,
  51031. PopupMenu::textColourId, 0xff000000,
  51032. PopupMenu::headerTextColourId, 0xff000000,
  51033. PopupMenu::highlightedTextColourId, 0xffffffff,
  51034. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51035. ComboBox::textColourId, 0xff000000,
  51036. ComboBox::backgroundColourId, 0xffffffff,
  51037. ComboBox::arrowColourId, 0x99000000,
  51038. ListBox::backgroundColourId, 0xffffffff,
  51039. ListBox::outlineColourId, standardOutlineColour,
  51040. ListBox::textColourId, 0xff000000,
  51041. Slider::backgroundColourId, 0x00000000,
  51042. Slider::thumbColourId, textButtonColour,
  51043. Slider::trackColourId, 0x7fffffff,
  51044. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51045. Slider::rotarySliderOutlineColourId, 0x66000000,
  51046. Slider::textBoxTextColourId, 0xff000000,
  51047. Slider::textBoxBackgroundColourId, 0xffffffff,
  51048. Slider::textBoxHighlightColourId, textHighlightColour,
  51049. Slider::textBoxOutlineColourId, standardOutlineColour,
  51050. ResizableWindow::backgroundColourId, 0xff777777,
  51051. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51052. AlertWindow::backgroundColourId, 0xffededed,
  51053. AlertWindow::textColourId, 0xff000000,
  51054. AlertWindow::outlineColourId, 0xff666666,
  51055. ProgressBar::backgroundColourId, 0xffeeeeee,
  51056. ProgressBar::foregroundColourId, 0xffaaaaee,
  51057. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51058. TooltipWindow::textColourId, 0xff000000,
  51059. TooltipWindow::outlineColourId, 0x4c000000,
  51060. TabbedComponent::backgroundColourId, 0x00000000,
  51061. TabbedComponent::outlineColourId, 0xff777777,
  51062. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51063. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51064. Toolbar::backgroundColourId, 0xfff6f8f9,
  51065. Toolbar::separatorColourId, 0x4c000000,
  51066. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51067. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51068. Toolbar::labelTextColourId, 0xff000000,
  51069. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51070. HyperlinkButton::textColourId, 0xcc1111ee,
  51071. GroupComponent::outlineColourId, 0x66000000,
  51072. GroupComponent::textColourId, 0xff000000,
  51073. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51074. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51075. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51076. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51077. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51078. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51079. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51080. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51081. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51082. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51083. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51084. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51085. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51086. CodeEditorComponent::caretColourId, 0xff000000,
  51087. CodeEditorComponent::highlightColourId, textHighlightColour,
  51088. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51089. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51090. ColourSelector::labelTextColourId, 0xff000000,
  51091. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51092. KeyMappingEditorComponent::textColourId, 0xff000000,
  51093. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51094. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51095. };
  51096. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51097. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51098. static String defaultSansName, defaultSerifName, defaultFixedName;
  51099. if (defaultSansName.isEmpty())
  51100. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51101. defaultSans = defaultSansName;
  51102. defaultSerif = defaultSerifName;
  51103. defaultFixed = defaultFixedName;
  51104. }
  51105. LookAndFeel::~LookAndFeel()
  51106. {
  51107. }
  51108. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51109. {
  51110. const int index = colourIds.indexOf (colourId);
  51111. if (index >= 0)
  51112. return colours [index];
  51113. jassertfalse
  51114. return Colours::black;
  51115. }
  51116. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51117. {
  51118. const int index = colourIds.indexOf (colourId);
  51119. if (index >= 0)
  51120. colours.set (index, colour);
  51121. colourIds.add (colourId);
  51122. colours.add (colour);
  51123. }
  51124. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51125. {
  51126. return colourIds.contains (colourId);
  51127. }
  51128. static LookAndFeel* defaultLF = 0;
  51129. static LookAndFeel* currentDefaultLF = 0;
  51130. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51131. {
  51132. // if this happens, your app hasn't initialised itself properly.. if you're
  51133. // trying to hack your own main() function, have a look at
  51134. // JUCEApplication::initialiseForGUI()
  51135. jassert (currentDefaultLF != 0);
  51136. return *currentDefaultLF;
  51137. }
  51138. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51139. {
  51140. if (newDefaultLookAndFeel == 0)
  51141. {
  51142. if (defaultLF == 0)
  51143. defaultLF = new LookAndFeel();
  51144. newDefaultLookAndFeel = defaultLF;
  51145. }
  51146. currentDefaultLF = newDefaultLookAndFeel;
  51147. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51148. {
  51149. Component* const c = Desktop::getInstance().getComponent (i);
  51150. if (c != 0)
  51151. c->sendLookAndFeelChange();
  51152. }
  51153. }
  51154. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51155. {
  51156. if (currentDefaultLF == defaultLF)
  51157. currentDefaultLF = 0;
  51158. deleteAndZero (defaultLF);
  51159. }
  51160. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51161. {
  51162. String faceName (font.getTypefaceName());
  51163. if (faceName == Font::getDefaultSansSerifFontName())
  51164. faceName = defaultSans;
  51165. else if (faceName == Font::getDefaultSerifFontName())
  51166. faceName = defaultSerif;
  51167. else if (faceName == Font::getDefaultMonospacedFontName())
  51168. faceName = defaultFixed;
  51169. Font f (font);
  51170. f.setTypefaceName (faceName);
  51171. return Typeface::createSystemTypefaceFor (f);
  51172. }
  51173. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51174. {
  51175. defaultSans = newName;
  51176. }
  51177. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51178. {
  51179. return component.getMouseCursor();
  51180. }
  51181. void LookAndFeel::drawButtonBackground (Graphics& g,
  51182. Button& button,
  51183. const Colour& backgroundColour,
  51184. bool isMouseOverButton,
  51185. bool isButtonDown)
  51186. {
  51187. const int width = button.getWidth();
  51188. const int height = button.getHeight();
  51189. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51190. const float halfThickness = outlineThickness * 0.5f;
  51191. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51192. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51193. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51194. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51195. const Colour baseColour (createBaseColour (backgroundColour,
  51196. button.hasKeyboardFocus (true),
  51197. isMouseOverButton, isButtonDown)
  51198. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51199. drawGlassLozenge (g,
  51200. indentL,
  51201. indentT,
  51202. width - indentL - indentR,
  51203. height - indentT - indentB,
  51204. baseColour, outlineThickness, -1.0f,
  51205. button.isConnectedOnLeft(),
  51206. button.isConnectedOnRight(),
  51207. button.isConnectedOnTop(),
  51208. button.isConnectedOnBottom());
  51209. }
  51210. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51211. {
  51212. return button.getFont();
  51213. }
  51214. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51215. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51216. {
  51217. Font font (getFontForTextButton (button));
  51218. g.setFont (font);
  51219. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51220. : TextButton::textColourOffId)
  51221. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51222. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51223. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51224. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51225. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51226. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51227. g.drawFittedText (button.getButtonText(),
  51228. leftIndent,
  51229. yIndent,
  51230. button.getWidth() - leftIndent - rightIndent,
  51231. button.getHeight() - yIndent * 2,
  51232. Justification::centred, 2);
  51233. }
  51234. void LookAndFeel::drawTickBox (Graphics& g,
  51235. Component& component,
  51236. float x, float y, float w, float h,
  51237. const bool ticked,
  51238. const bool isEnabled,
  51239. const bool isMouseOverButton,
  51240. const bool isButtonDown)
  51241. {
  51242. const float boxSize = w * 0.7f;
  51243. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51244. createBaseColour (component.findColour (TextButton::buttonColourId)
  51245. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51246. true,
  51247. isMouseOverButton,
  51248. isButtonDown),
  51249. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51250. if (ticked)
  51251. {
  51252. Path tick;
  51253. tick.startNewSubPath (1.5f, 3.0f);
  51254. tick.lineTo (3.0f, 6.0f);
  51255. tick.lineTo (6.0f, 0.0f);
  51256. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51257. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51258. .translated (x, y));
  51259. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51260. }
  51261. }
  51262. void LookAndFeel::drawToggleButton (Graphics& g,
  51263. ToggleButton& button,
  51264. bool isMouseOverButton,
  51265. bool isButtonDown)
  51266. {
  51267. if (button.hasKeyboardFocus (true))
  51268. {
  51269. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51270. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51271. }
  51272. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51273. const float tickWidth = fontSize * 1.1f;
  51274. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51275. tickWidth, tickWidth,
  51276. button.getToggleState(),
  51277. button.isEnabled(),
  51278. isMouseOverButton,
  51279. isButtonDown);
  51280. g.setColour (button.findColour (ToggleButton::textColourId));
  51281. g.setFont (fontSize);
  51282. if (! button.isEnabled())
  51283. g.setOpacity (0.5f);
  51284. const int textX = (int) tickWidth + 5;
  51285. g.drawFittedText (button.getButtonText(),
  51286. textX, 0,
  51287. button.getWidth() - textX - 2, button.getHeight(),
  51288. Justification::centredLeft, 10);
  51289. }
  51290. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51291. {
  51292. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51293. const int tickWidth = jmin (24, button.getHeight());
  51294. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51295. button.getHeight());
  51296. }
  51297. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51298. const String& message,
  51299. const String& button1,
  51300. const String& button2,
  51301. const String& button3,
  51302. AlertWindow::AlertIconType iconType,
  51303. int numButtons,
  51304. Component* associatedComponent)
  51305. {
  51306. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51307. if (numButtons == 1)
  51308. {
  51309. aw->addButton (button1, 0,
  51310. KeyPress (KeyPress::escapeKey, 0, 0),
  51311. KeyPress (KeyPress::returnKey, 0, 0));
  51312. }
  51313. else
  51314. {
  51315. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51316. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51317. if (button1ShortCut == button2ShortCut)
  51318. button2ShortCut = KeyPress();
  51319. if (numButtons == 2)
  51320. {
  51321. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51322. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51323. }
  51324. else if (numButtons == 3)
  51325. {
  51326. aw->addButton (button1, 1, button1ShortCut);
  51327. aw->addButton (button2, 2, button2ShortCut);
  51328. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51329. }
  51330. }
  51331. return aw;
  51332. }
  51333. void LookAndFeel::drawAlertBox (Graphics& g,
  51334. AlertWindow& alert,
  51335. const Rectangle<int>& textArea,
  51336. TextLayout& textLayout)
  51337. {
  51338. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51339. int iconSpaceUsed = 0;
  51340. Justification alignment (Justification::horizontallyCentred);
  51341. const int iconWidth = 80;
  51342. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51343. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51344. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51345. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51346. iconSize, iconSize);
  51347. if (alert.getAlertType() != AlertWindow::NoIcon)
  51348. {
  51349. Path icon;
  51350. uint32 colour;
  51351. char character;
  51352. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51353. {
  51354. colour = 0x55ff5555;
  51355. character = '!';
  51356. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51357. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51358. (float) iconRect.getX(), (float) iconRect.getBottom());
  51359. icon = icon.createPathWithRoundedCorners (5.0f);
  51360. }
  51361. else
  51362. {
  51363. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51364. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51365. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51366. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51367. }
  51368. GlyphArrangement ga;
  51369. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51370. String::charToString (character),
  51371. (float) iconRect.getX(), (float) iconRect.getY(),
  51372. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51373. Justification::centred, false);
  51374. ga.createPath (icon);
  51375. icon.setUsingNonZeroWinding (false);
  51376. g.setColour (Colour (colour));
  51377. g.fillPath (icon);
  51378. iconSpaceUsed = iconWidth;
  51379. alignment = Justification::left;
  51380. }
  51381. g.setColour (alert.findColour (AlertWindow::textColourId));
  51382. textLayout.drawWithin (g,
  51383. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51384. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51385. alignment.getFlags() | Justification::top);
  51386. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51387. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51388. }
  51389. int LookAndFeel::getAlertBoxWindowFlags()
  51390. {
  51391. return ComponentPeer::windowAppearsOnTaskbar
  51392. | ComponentPeer::windowHasDropShadow;
  51393. }
  51394. int LookAndFeel::getAlertWindowButtonHeight()
  51395. {
  51396. return 28;
  51397. }
  51398. const Font LookAndFeel::getAlertWindowFont()
  51399. {
  51400. return Font (12.0f);
  51401. }
  51402. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51403. int width, int height,
  51404. double progress, const String& textToShow)
  51405. {
  51406. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51407. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51408. g.fillAll (background);
  51409. if (progress >= 0.0f && progress < 1.0f)
  51410. {
  51411. drawGlassLozenge (g, 1.0f, 1.0f,
  51412. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51413. (float) (height - 2),
  51414. foreground,
  51415. 0.5f, 0.0f,
  51416. true, true, true, true);
  51417. }
  51418. else
  51419. {
  51420. // spinning bar..
  51421. g.setColour (foreground);
  51422. const int stripeWidth = height * 2;
  51423. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51424. Path p;
  51425. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51426. p.addQuadrilateral (x, 0.0f,
  51427. x + stripeWidth * 0.5f, 0.0f,
  51428. x, (float) height,
  51429. x - stripeWidth * 0.5f, (float) height);
  51430. Image im (Image::ARGB, width, height, true);
  51431. {
  51432. Graphics g2 (im);
  51433. drawGlassLozenge (g2, 1.0f, 1.0f,
  51434. (float) (width - 2),
  51435. (float) (height - 2),
  51436. foreground,
  51437. 0.5f, 0.0f,
  51438. true, true, true, true);
  51439. }
  51440. g.setTiledImageFill (im, 0, 0, 0.85f);
  51441. g.fillPath (p);
  51442. }
  51443. if (textToShow.isNotEmpty())
  51444. {
  51445. g.setColour (Colour::contrasting (background, foreground));
  51446. g.setFont (height * 0.6f);
  51447. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51448. }
  51449. }
  51450. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51451. {
  51452. const float radius = jmin (w, h) * 0.4f;
  51453. const float thickness = radius * 0.15f;
  51454. Path p;
  51455. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51456. radius * 0.6f, thickness,
  51457. thickness * 0.5f);
  51458. const float cx = x + w * 0.5f;
  51459. const float cy = y + h * 0.5f;
  51460. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51461. for (int i = 0; i < 12; ++i)
  51462. {
  51463. const int n = (i + 12 - animationIndex) % 12;
  51464. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51465. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51466. .translated (cx, cy));
  51467. }
  51468. }
  51469. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51470. ScrollBar& scrollbar,
  51471. int width, int height,
  51472. int buttonDirection,
  51473. bool /*isScrollbarVertical*/,
  51474. bool /*isMouseOverButton*/,
  51475. bool isButtonDown)
  51476. {
  51477. Path p;
  51478. if (buttonDirection == 0)
  51479. p.addTriangle (width * 0.5f, height * 0.2f,
  51480. width * 0.1f, height * 0.7f,
  51481. width * 0.9f, height * 0.7f);
  51482. else if (buttonDirection == 1)
  51483. p.addTriangle (width * 0.8f, height * 0.5f,
  51484. width * 0.3f, height * 0.1f,
  51485. width * 0.3f, height * 0.9f);
  51486. else if (buttonDirection == 2)
  51487. p.addTriangle (width * 0.5f, height * 0.8f,
  51488. width * 0.1f, height * 0.3f,
  51489. width * 0.9f, height * 0.3f);
  51490. else if (buttonDirection == 3)
  51491. p.addTriangle (width * 0.2f, height * 0.5f,
  51492. width * 0.7f, height * 0.1f,
  51493. width * 0.7f, height * 0.9f);
  51494. if (isButtonDown)
  51495. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51496. else
  51497. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51498. g.fillPath (p);
  51499. g.setColour (Colour (0x80000000));
  51500. g.strokePath (p, PathStrokeType (0.5f));
  51501. }
  51502. void LookAndFeel::drawScrollbar (Graphics& g,
  51503. ScrollBar& scrollbar,
  51504. int x, int y,
  51505. int width, int height,
  51506. bool isScrollbarVertical,
  51507. int thumbStartPosition,
  51508. int thumbSize,
  51509. bool /*isMouseOver*/,
  51510. bool /*isMouseDown*/)
  51511. {
  51512. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51513. Path slotPath, thumbPath;
  51514. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51515. const float slotIndentx2 = slotIndent * 2.0f;
  51516. const float thumbIndent = slotIndent + 1.0f;
  51517. const float thumbIndentx2 = thumbIndent * 2.0f;
  51518. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51519. if (isScrollbarVertical)
  51520. {
  51521. slotPath.addRoundedRectangle (x + slotIndent,
  51522. y + slotIndent,
  51523. width - slotIndentx2,
  51524. height - slotIndentx2,
  51525. (width - slotIndentx2) * 0.5f);
  51526. if (thumbSize > 0)
  51527. thumbPath.addRoundedRectangle (x + thumbIndent,
  51528. thumbStartPosition + thumbIndent,
  51529. width - thumbIndentx2,
  51530. thumbSize - thumbIndentx2,
  51531. (width - thumbIndentx2) * 0.5f);
  51532. gx1 = (float) x;
  51533. gx2 = x + width * 0.7f;
  51534. }
  51535. else
  51536. {
  51537. slotPath.addRoundedRectangle (x + slotIndent,
  51538. y + slotIndent,
  51539. width - slotIndentx2,
  51540. height - slotIndentx2,
  51541. (height - slotIndentx2) * 0.5f);
  51542. if (thumbSize > 0)
  51543. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51544. y + thumbIndent,
  51545. thumbSize - thumbIndentx2,
  51546. height - thumbIndentx2,
  51547. (height - thumbIndentx2) * 0.5f);
  51548. gy1 = (float) y;
  51549. gy2 = y + height * 0.7f;
  51550. }
  51551. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51552. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51553. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51554. g.fillPath (slotPath);
  51555. if (isScrollbarVertical)
  51556. {
  51557. gx1 = x + width * 0.6f;
  51558. gx2 = (float) x + width;
  51559. }
  51560. else
  51561. {
  51562. gy1 = y + height * 0.6f;
  51563. gy2 = (float) y + height;
  51564. }
  51565. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51566. Colour (0x19000000), gx2, gy2, false));
  51567. g.fillPath (slotPath);
  51568. g.setColour (thumbColour);
  51569. g.fillPath (thumbPath);
  51570. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51571. Colours::transparentBlack, gx2, gy2, false));
  51572. g.saveState();
  51573. if (isScrollbarVertical)
  51574. g.reduceClipRegion (x + width / 2, y, width, height);
  51575. else
  51576. g.reduceClipRegion (x, y + height / 2, width, height);
  51577. g.fillPath (thumbPath);
  51578. g.restoreState();
  51579. g.setColour (Colour (0x4c000000));
  51580. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51581. }
  51582. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51583. {
  51584. return 0;
  51585. }
  51586. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51587. {
  51588. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51589. }
  51590. int LookAndFeel::getDefaultScrollbarWidth()
  51591. {
  51592. return 18;
  51593. }
  51594. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51595. {
  51596. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51597. : scrollbar.getHeight());
  51598. }
  51599. const Path LookAndFeel::getTickShape (const float height)
  51600. {
  51601. static const unsigned char tickShapeData[] =
  51602. {
  51603. 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,
  51604. 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,
  51605. 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,
  51606. 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,
  51607. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51608. };
  51609. Path p;
  51610. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51611. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51612. return p;
  51613. }
  51614. const Path LookAndFeel::getCrossShape (const float height)
  51615. {
  51616. static const unsigned char crossShapeData[] =
  51617. {
  51618. 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,
  51619. 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,
  51620. 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,
  51621. 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,
  51622. 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,
  51623. 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,
  51624. 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
  51625. };
  51626. Path p;
  51627. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51628. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51629. return p;
  51630. }
  51631. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51632. {
  51633. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51634. x += (w - boxSize) >> 1;
  51635. y += (h - boxSize) >> 1;
  51636. w = boxSize;
  51637. h = boxSize;
  51638. g.setColour (Colour (0xe5ffffff));
  51639. g.fillRect (x, y, w, h);
  51640. g.setColour (Colour (0x80000000));
  51641. g.drawRect (x, y, w, h);
  51642. const float size = boxSize / 2 + 1.0f;
  51643. const float centre = (float) (boxSize / 2);
  51644. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51645. if (isPlus)
  51646. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51647. }
  51648. void LookAndFeel::drawBubble (Graphics& g,
  51649. float tipX, float tipY,
  51650. float boxX, float boxY,
  51651. float boxW, float boxH)
  51652. {
  51653. int side = 0;
  51654. if (tipX < boxX)
  51655. side = 1;
  51656. else if (tipX > boxX + boxW)
  51657. side = 3;
  51658. else if (tipY > boxY + boxH)
  51659. side = 2;
  51660. const float indent = 2.0f;
  51661. Path p;
  51662. p.addBubble (boxX + indent,
  51663. boxY + indent,
  51664. boxW - indent * 2.0f,
  51665. boxH - indent * 2.0f,
  51666. 5.0f,
  51667. tipX, tipY,
  51668. side,
  51669. 0.5f,
  51670. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51671. //xxx need to take comp as param for colour
  51672. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51673. g.fillPath (p);
  51674. //xxx as above
  51675. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51676. g.strokePath (p, PathStrokeType (1.33f));
  51677. }
  51678. const Font LookAndFeel::getPopupMenuFont()
  51679. {
  51680. return Font (17.0f);
  51681. }
  51682. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51683. const bool isSeparator,
  51684. int standardMenuItemHeight,
  51685. int& idealWidth,
  51686. int& idealHeight)
  51687. {
  51688. if (isSeparator)
  51689. {
  51690. idealWidth = 50;
  51691. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51692. }
  51693. else
  51694. {
  51695. Font font (getPopupMenuFont());
  51696. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51697. font.setHeight (standardMenuItemHeight / 1.3f);
  51698. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51699. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51700. }
  51701. }
  51702. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51703. {
  51704. const Colour background (findColour (PopupMenu::backgroundColourId));
  51705. g.fillAll (background);
  51706. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51707. for (int i = 0; i < height; i += 3)
  51708. g.fillRect (0, i, width, 1);
  51709. #if ! JUCE_MAC
  51710. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51711. g.drawRect (0, 0, width, height);
  51712. #endif
  51713. }
  51714. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51715. int width, int height,
  51716. bool isScrollUpArrow)
  51717. {
  51718. const Colour background (findColour (PopupMenu::backgroundColourId));
  51719. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51720. background.withAlpha (0.0f),
  51721. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51722. false));
  51723. g.fillRect (1, 1, width - 2, height - 2);
  51724. const float hw = width * 0.5f;
  51725. const float arrowW = height * 0.3f;
  51726. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51727. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51728. Path p;
  51729. p.addTriangle (hw - arrowW, y1,
  51730. hw + arrowW, y1,
  51731. hw, y2);
  51732. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51733. g.fillPath (p);
  51734. }
  51735. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51736. int width, int height,
  51737. const bool isSeparator,
  51738. const bool isActive,
  51739. const bool isHighlighted,
  51740. const bool isTicked,
  51741. const bool hasSubMenu,
  51742. const String& text,
  51743. const String& shortcutKeyText,
  51744. Image* image,
  51745. const Colour* const textColourToUse)
  51746. {
  51747. const float halfH = height * 0.5f;
  51748. if (isSeparator)
  51749. {
  51750. const float separatorIndent = 5.5f;
  51751. g.setColour (Colour (0x33000000));
  51752. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51753. g.setColour (Colour (0x66ffffff));
  51754. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51755. }
  51756. else
  51757. {
  51758. Colour textColour (findColour (PopupMenu::textColourId));
  51759. if (textColourToUse != 0)
  51760. textColour = *textColourToUse;
  51761. if (isHighlighted)
  51762. {
  51763. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51764. g.fillRect (1, 1, width - 2, height - 2);
  51765. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51766. }
  51767. else
  51768. {
  51769. g.setColour (textColour);
  51770. }
  51771. if (! isActive)
  51772. g.setOpacity (0.3f);
  51773. Font font (getPopupMenuFont());
  51774. if (font.getHeight() > height / 1.3f)
  51775. font.setHeight (height / 1.3f);
  51776. g.setFont (font);
  51777. const int leftBorder = (height * 5) / 4;
  51778. const int rightBorder = 4;
  51779. if (image != 0)
  51780. {
  51781. g.drawImageWithin (image,
  51782. 2, 1, leftBorder - 4, height - 2,
  51783. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51784. }
  51785. else if (isTicked)
  51786. {
  51787. const Path tick (getTickShape (1.0f));
  51788. const float th = font.getAscent();
  51789. const float ty = halfH - th * 0.5f;
  51790. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51791. th, true));
  51792. }
  51793. g.drawFittedText (text,
  51794. leftBorder, 0,
  51795. width - (leftBorder + rightBorder), height,
  51796. Justification::centredLeft, 1);
  51797. if (shortcutKeyText.isNotEmpty())
  51798. {
  51799. Font f2 (font);
  51800. f2.setHeight (f2.getHeight() * 0.75f);
  51801. f2.setHorizontalScale (0.95f);
  51802. g.setFont (f2);
  51803. g.drawText (shortcutKeyText,
  51804. leftBorder,
  51805. 0,
  51806. width - (leftBorder + rightBorder + 4),
  51807. height,
  51808. Justification::centredRight,
  51809. true);
  51810. }
  51811. if (hasSubMenu)
  51812. {
  51813. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51814. const float x = width - height * 0.6f;
  51815. Path p;
  51816. p.addTriangle (x, halfH - arrowH * 0.5f,
  51817. x, halfH + arrowH * 0.5f,
  51818. x + arrowH * 0.6f, halfH);
  51819. g.fillPath (p);
  51820. }
  51821. }
  51822. }
  51823. int LookAndFeel::getMenuWindowFlags()
  51824. {
  51825. return ComponentPeer::windowHasDropShadow;
  51826. }
  51827. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51828. bool, MenuBarComponent& menuBar)
  51829. {
  51830. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51831. if (menuBar.isEnabled())
  51832. {
  51833. drawShinyButtonShape (g,
  51834. -4.0f, 0.0f,
  51835. width + 8.0f, (float) height,
  51836. 0.0f,
  51837. baseColour,
  51838. 0.4f,
  51839. true, true, true, true);
  51840. }
  51841. else
  51842. {
  51843. g.fillAll (baseColour);
  51844. }
  51845. }
  51846. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51847. {
  51848. return Font (menuBar.getHeight() * 0.7f);
  51849. }
  51850. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51851. {
  51852. return getMenuBarFont (menuBar, itemIndex, itemText)
  51853. .getStringWidth (itemText) + menuBar.getHeight();
  51854. }
  51855. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51856. int width, int height,
  51857. int itemIndex,
  51858. const String& itemText,
  51859. bool isMouseOverItem,
  51860. bool isMenuOpen,
  51861. bool /*isMouseOverBar*/,
  51862. MenuBarComponent& menuBar)
  51863. {
  51864. if (! menuBar.isEnabled())
  51865. {
  51866. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51867. .withMultipliedAlpha (0.5f));
  51868. }
  51869. else if (isMenuOpen || isMouseOverItem)
  51870. {
  51871. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51872. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51873. }
  51874. else
  51875. {
  51876. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51877. }
  51878. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  51879. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  51880. }
  51881. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  51882. TextEditor& textEditor)
  51883. {
  51884. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  51885. }
  51886. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  51887. {
  51888. if (textEditor.isEnabled())
  51889. {
  51890. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  51891. {
  51892. const int border = 2;
  51893. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  51894. g.drawRect (0, 0, width, height, border);
  51895. g.setOpacity (1.0f);
  51896. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  51897. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  51898. }
  51899. else
  51900. {
  51901. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  51902. g.drawRect (0, 0, width, height);
  51903. g.setOpacity (1.0f);
  51904. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  51905. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  51906. }
  51907. }
  51908. }
  51909. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  51910. const bool isButtonDown,
  51911. int buttonX, int buttonY,
  51912. int buttonW, int buttonH,
  51913. ComboBox& box)
  51914. {
  51915. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  51916. if (box.isEnabled() && box.hasKeyboardFocus (false))
  51917. {
  51918. g.setColour (box.findColour (TextButton::buttonColourId));
  51919. g.drawRect (0, 0, width, height, 2);
  51920. }
  51921. else
  51922. {
  51923. g.setColour (box.findColour (ComboBox::outlineColourId));
  51924. g.drawRect (0, 0, width, height);
  51925. }
  51926. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  51927. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  51928. box.hasKeyboardFocus (true),
  51929. false, isButtonDown)
  51930. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  51931. drawGlassLozenge (g,
  51932. buttonX + outlineThickness, buttonY + outlineThickness,
  51933. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  51934. baseColour, outlineThickness, -1.0f,
  51935. true, true, true, true);
  51936. if (box.isEnabled())
  51937. {
  51938. const float arrowX = 0.3f;
  51939. const float arrowH = 0.2f;
  51940. Path p;
  51941. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  51942. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  51943. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  51944. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  51945. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  51946. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  51947. g.setColour (box.findColour (ComboBox::arrowColourId));
  51948. g.fillPath (p);
  51949. }
  51950. }
  51951. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  51952. {
  51953. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  51954. }
  51955. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  51956. {
  51957. return new Label (String::empty, String::empty);
  51958. }
  51959. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  51960. {
  51961. label.setBounds (1, 1,
  51962. box.getWidth() + 3 - box.getHeight(),
  51963. box.getHeight() - 2);
  51964. label.setFont (getComboBoxFont (box));
  51965. }
  51966. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  51967. {
  51968. g.fillAll (label.findColour (Label::backgroundColourId));
  51969. if (! label.isBeingEdited())
  51970. {
  51971. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  51972. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  51973. g.setFont (label.getFont());
  51974. g.drawFittedText (label.getText(),
  51975. label.getHorizontalBorderSize(),
  51976. label.getVerticalBorderSize(),
  51977. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  51978. label.getHeight() - 2 * label.getVerticalBorderSize(),
  51979. label.getJustificationType(),
  51980. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  51981. label.getMinimumHorizontalScale());
  51982. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  51983. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51984. }
  51985. else if (label.isEnabled())
  51986. {
  51987. g.setColour (label.findColour (Label::outlineColourId));
  51988. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51989. }
  51990. }
  51991. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  51992. int x, int y,
  51993. int width, int height,
  51994. float /*sliderPos*/,
  51995. float /*minSliderPos*/,
  51996. float /*maxSliderPos*/,
  51997. const Slider::SliderStyle /*style*/,
  51998. Slider& slider)
  51999. {
  52000. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52001. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52002. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52003. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52004. Path indent;
  52005. if (slider.isHorizontal())
  52006. {
  52007. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52008. const float ih = sliderRadius;
  52009. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52010. gradCol2, 0.0f, iy + ih, false));
  52011. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52012. width + sliderRadius, ih,
  52013. 5.0f);
  52014. g.fillPath (indent);
  52015. }
  52016. else
  52017. {
  52018. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52019. const float iw = sliderRadius;
  52020. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52021. gradCol2, ix + iw, 0.0f, false));
  52022. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52023. iw, height + sliderRadius,
  52024. 5.0f);
  52025. g.fillPath (indent);
  52026. }
  52027. g.setColour (Colour (0x4c000000));
  52028. g.strokePath (indent, PathStrokeType (0.5f));
  52029. }
  52030. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52031. int x, int y,
  52032. int width, int height,
  52033. float sliderPos,
  52034. float minSliderPos,
  52035. float maxSliderPos,
  52036. const Slider::SliderStyle style,
  52037. Slider& slider)
  52038. {
  52039. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52040. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52041. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52042. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52043. slider.isMouseButtonDown() && slider.isEnabled()));
  52044. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52045. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52046. {
  52047. float kx, ky;
  52048. if (style == Slider::LinearVertical)
  52049. {
  52050. kx = x + width * 0.5f;
  52051. ky = sliderPos;
  52052. }
  52053. else
  52054. {
  52055. kx = sliderPos;
  52056. ky = y + height * 0.5f;
  52057. }
  52058. drawGlassSphere (g,
  52059. kx - sliderRadius,
  52060. ky - sliderRadius,
  52061. sliderRadius * 2.0f,
  52062. knobColour, outlineThickness);
  52063. }
  52064. else
  52065. {
  52066. if (style == Slider::ThreeValueVertical)
  52067. {
  52068. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52069. sliderPos - sliderRadius,
  52070. sliderRadius * 2.0f,
  52071. knobColour, outlineThickness);
  52072. }
  52073. else if (style == Slider::ThreeValueHorizontal)
  52074. {
  52075. drawGlassSphere (g,sliderPos - sliderRadius,
  52076. y + height * 0.5f - sliderRadius,
  52077. sliderRadius * 2.0f,
  52078. knobColour, outlineThickness);
  52079. }
  52080. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52081. {
  52082. const float sr = jmin (sliderRadius, width * 0.4f);
  52083. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52084. minSliderPos - sliderRadius,
  52085. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52086. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52087. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52088. }
  52089. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52090. {
  52091. const float sr = jmin (sliderRadius, height * 0.4f);
  52092. drawGlassPointer (g, minSliderPos - sr,
  52093. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52094. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52095. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52096. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52097. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52098. }
  52099. }
  52100. }
  52101. void LookAndFeel::drawLinearSlider (Graphics& g,
  52102. int x, int y,
  52103. int width, int height,
  52104. float sliderPos,
  52105. float minSliderPos,
  52106. float maxSliderPos,
  52107. const Slider::SliderStyle style,
  52108. Slider& slider)
  52109. {
  52110. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52111. if (style == Slider::LinearBar)
  52112. {
  52113. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52114. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52115. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52116. false,
  52117. isMouseOver,
  52118. isMouseOver || slider.isMouseButtonDown()));
  52119. drawShinyButtonShape (g,
  52120. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52121. baseColour,
  52122. slider.isEnabled() ? 0.9f : 0.3f,
  52123. true, true, true, true);
  52124. }
  52125. else
  52126. {
  52127. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52128. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52129. }
  52130. }
  52131. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52132. {
  52133. return jmin (7,
  52134. slider.getHeight() / 2,
  52135. slider.getWidth() / 2) + 2;
  52136. }
  52137. void LookAndFeel::drawRotarySlider (Graphics& g,
  52138. int x, int y,
  52139. int width, int height,
  52140. float sliderPos,
  52141. const float rotaryStartAngle,
  52142. const float rotaryEndAngle,
  52143. Slider& slider)
  52144. {
  52145. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52146. const float centreX = x + width * 0.5f;
  52147. const float centreY = y + height * 0.5f;
  52148. const float rx = centreX - radius;
  52149. const float ry = centreY - radius;
  52150. const float rw = radius * 2.0f;
  52151. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52152. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52153. if (radius > 12.0f)
  52154. {
  52155. if (slider.isEnabled())
  52156. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52157. else
  52158. g.setColour (Colour (0x80808080));
  52159. const float thickness = 0.7f;
  52160. {
  52161. Path filledArc;
  52162. filledArc.addPieSegment (rx, ry, rw, rw,
  52163. rotaryStartAngle,
  52164. angle,
  52165. thickness);
  52166. g.fillPath (filledArc);
  52167. }
  52168. if (thickness > 0)
  52169. {
  52170. const float innerRadius = radius * 0.2f;
  52171. Path p;
  52172. p.addTriangle (-innerRadius, 0.0f,
  52173. 0.0f, -radius * thickness * 1.1f,
  52174. innerRadius, 0.0f);
  52175. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52176. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52177. }
  52178. if (slider.isEnabled())
  52179. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52180. else
  52181. g.setColour (Colour (0x80808080));
  52182. Path outlineArc;
  52183. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52184. outlineArc.closeSubPath();
  52185. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52186. }
  52187. else
  52188. {
  52189. if (slider.isEnabled())
  52190. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52191. else
  52192. g.setColour (Colour (0x80808080));
  52193. Path p;
  52194. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52195. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52196. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52197. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52198. }
  52199. }
  52200. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52201. {
  52202. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52203. }
  52204. class SliderLabelComp : public Label
  52205. {
  52206. public:
  52207. SliderLabelComp() : Label (String::empty, String::empty) {}
  52208. ~SliderLabelComp() {}
  52209. void mouseWheelMove (const MouseEvent&, float, float) {}
  52210. };
  52211. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52212. {
  52213. Label* const l = new SliderLabelComp();
  52214. l->setJustificationType (Justification::centred);
  52215. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52216. l->setColour (Label::backgroundColourId,
  52217. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52218. : slider.findColour (Slider::textBoxBackgroundColourId));
  52219. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52220. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52221. l->setColour (TextEditor::backgroundColourId,
  52222. slider.findColour (Slider::textBoxBackgroundColourId)
  52223. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52224. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52225. return l;
  52226. }
  52227. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52228. {
  52229. return 0;
  52230. }
  52231. static const TextLayout layoutTooltipText (const String& text) throw()
  52232. {
  52233. const float tooltipFontSize = 12.0f;
  52234. const int maxToolTipWidth = 400;
  52235. const Font f (tooltipFontSize, Font::bold);
  52236. TextLayout tl (text, f);
  52237. tl.layout (maxToolTipWidth, Justification::left, true);
  52238. return tl;
  52239. }
  52240. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52241. {
  52242. const TextLayout tl (layoutTooltipText (tipText));
  52243. width = tl.getWidth() + 14;
  52244. height = tl.getHeight() + 6;
  52245. }
  52246. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52247. {
  52248. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52249. const Colour textCol (findColour (TooltipWindow::textColourId));
  52250. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52251. g.setColour (findColour (TooltipWindow::outlineColourId));
  52252. g.drawRect (0, 0, width, height, 1);
  52253. #endif
  52254. const TextLayout tl (layoutTooltipText (text));
  52255. g.setColour (findColour (TooltipWindow::textColourId));
  52256. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52257. }
  52258. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52259. {
  52260. return new TextButton (text, TRANS("click to browse for a different file"));
  52261. }
  52262. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52263. ComboBox* filenameBox,
  52264. Button* browseButton)
  52265. {
  52266. browseButton->setSize (80, filenameComp.getHeight());
  52267. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52268. if (tb != 0)
  52269. tb->changeWidthToFitText();
  52270. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52271. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52272. }
  52273. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52274. int imageX, int imageY, int imageW, int imageH,
  52275. const Colour& overlayColour,
  52276. float imageOpacity,
  52277. ImageButton& button)
  52278. {
  52279. if (! button.isEnabled())
  52280. imageOpacity *= 0.3f;
  52281. if (! overlayColour.isOpaque())
  52282. {
  52283. g.setOpacity (imageOpacity);
  52284. g.drawImage (image, imageX, imageY, imageW, imageH,
  52285. 0, 0, image->getWidth(), image->getHeight(), false);
  52286. }
  52287. if (! overlayColour.isTransparent())
  52288. {
  52289. g.setColour (overlayColour);
  52290. g.drawImage (image, imageX, imageY, imageW, imageH,
  52291. 0, 0, image->getWidth(), image->getHeight(), true);
  52292. }
  52293. }
  52294. void LookAndFeel::drawCornerResizer (Graphics& g,
  52295. int w, int h,
  52296. bool /*isMouseOver*/,
  52297. bool /*isMouseDragging*/)
  52298. {
  52299. const float lineThickness = jmin (w, h) * 0.075f;
  52300. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52301. {
  52302. g.setColour (Colours::lightgrey);
  52303. g.drawLine (w * i,
  52304. h + 1.0f,
  52305. w + 1.0f,
  52306. h * i,
  52307. lineThickness);
  52308. g.setColour (Colours::darkgrey);
  52309. g.drawLine (w * i + lineThickness,
  52310. h + 1.0f,
  52311. w + 1.0f,
  52312. h * i + lineThickness,
  52313. lineThickness);
  52314. }
  52315. }
  52316. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52317. const BorderSize& /*borders*/)
  52318. {
  52319. }
  52320. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52321. const BorderSize& /*border*/, ResizableWindow& window)
  52322. {
  52323. g.fillAll (window.getBackgroundColour());
  52324. }
  52325. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52326. const BorderSize& border, ResizableWindow&)
  52327. {
  52328. g.setColour (Colour (0x80000000));
  52329. g.drawRect (0, 0, w, h);
  52330. g.setColour (Colour (0x19000000));
  52331. g.drawRect (border.getLeft() - 1,
  52332. border.getTop() - 1,
  52333. w + 2 - border.getLeftAndRight(),
  52334. h + 2 - border.getTopAndBottom());
  52335. }
  52336. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52337. Graphics& g, int w, int h,
  52338. int titleSpaceX, int titleSpaceW,
  52339. const Image* icon,
  52340. bool drawTitleTextOnLeft)
  52341. {
  52342. const bool isActive = window.isActiveWindow();
  52343. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52344. 0.0f, 0.0f,
  52345. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52346. 0.0f, (float) h, false));
  52347. g.fillAll();
  52348. Font font (h * 0.65f, Font::bold);
  52349. g.setFont (font);
  52350. int textW = font.getStringWidth (window.getName());
  52351. int iconW = 0;
  52352. int iconH = 0;
  52353. if (icon != 0)
  52354. {
  52355. iconH = (int) font.getHeight();
  52356. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52357. }
  52358. textW = jmin (titleSpaceW, textW + iconW);
  52359. int textX = drawTitleTextOnLeft ? titleSpaceX
  52360. : jmax (titleSpaceX, (w - textW) / 2);
  52361. if (textX + textW > titleSpaceX + titleSpaceW)
  52362. textX = titleSpaceX + titleSpaceW - textW;
  52363. if (icon != 0)
  52364. {
  52365. g.setOpacity (isActive ? 1.0f : 0.6f);
  52366. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52367. RectanglePlacement::centred, false);
  52368. textX += iconW;
  52369. textW -= iconW;
  52370. }
  52371. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52372. g.setColour (findColour (DocumentWindow::textColourId));
  52373. else
  52374. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52375. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52376. }
  52377. class GlassWindowButton : public Button
  52378. {
  52379. public:
  52380. GlassWindowButton (const String& name, const Colour& col,
  52381. const Path& normalShape_,
  52382. const Path& toggledShape_) throw()
  52383. : Button (name),
  52384. colour (col),
  52385. normalShape (normalShape_),
  52386. toggledShape (toggledShape_)
  52387. {
  52388. }
  52389. ~GlassWindowButton()
  52390. {
  52391. }
  52392. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52393. {
  52394. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52395. if (! isEnabled())
  52396. alpha *= 0.5f;
  52397. float x = 0, y = 0, diam;
  52398. if (getWidth() < getHeight())
  52399. {
  52400. diam = (float) getWidth();
  52401. y = (getHeight() - getWidth()) * 0.5f;
  52402. }
  52403. else
  52404. {
  52405. diam = (float) getHeight();
  52406. y = (getWidth() - getHeight()) * 0.5f;
  52407. }
  52408. x += diam * 0.05f;
  52409. y += diam * 0.05f;
  52410. diam *= 0.9f;
  52411. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52412. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52413. g.fillEllipse (x, y, diam, diam);
  52414. x += 2.0f;
  52415. y += 2.0f;
  52416. diam -= 4.0f;
  52417. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52418. Path& p = getToggleState() ? toggledShape : normalShape;
  52419. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52420. diam * 0.4f, diam * 0.4f, true));
  52421. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52422. g.fillPath (p, t);
  52423. }
  52424. juce_UseDebuggingNewOperator
  52425. private:
  52426. Colour colour;
  52427. Path normalShape, toggledShape;
  52428. GlassWindowButton (const GlassWindowButton&);
  52429. GlassWindowButton& operator= (const GlassWindowButton&);
  52430. };
  52431. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52432. {
  52433. Path shape;
  52434. const float crossThickness = 0.25f;
  52435. if (buttonType == DocumentWindow::closeButton)
  52436. {
  52437. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52438. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52439. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52440. }
  52441. else if (buttonType == DocumentWindow::minimiseButton)
  52442. {
  52443. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52444. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52445. }
  52446. else if (buttonType == DocumentWindow::maximiseButton)
  52447. {
  52448. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52449. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52450. Path fullscreenShape;
  52451. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52452. fullscreenShape.lineTo (0.0f, 100.0f);
  52453. fullscreenShape.lineTo (0.0f, 0.0f);
  52454. fullscreenShape.lineTo (100.0f, 0.0f);
  52455. fullscreenShape.lineTo (100.0f, 45.0f);
  52456. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52457. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52458. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52459. }
  52460. jassertfalse
  52461. return 0;
  52462. }
  52463. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52464. int titleBarX,
  52465. int titleBarY,
  52466. int titleBarW,
  52467. int titleBarH,
  52468. Button* minimiseButton,
  52469. Button* maximiseButton,
  52470. Button* closeButton,
  52471. bool positionTitleBarButtonsOnLeft)
  52472. {
  52473. const int buttonW = titleBarH - titleBarH / 8;
  52474. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52475. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52476. if (closeButton != 0)
  52477. {
  52478. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52479. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52480. }
  52481. if (positionTitleBarButtonsOnLeft)
  52482. swapVariables (minimiseButton, maximiseButton);
  52483. if (maximiseButton != 0)
  52484. {
  52485. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52486. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52487. }
  52488. if (minimiseButton != 0)
  52489. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52490. }
  52491. int LookAndFeel::getDefaultMenuBarHeight()
  52492. {
  52493. return 24;
  52494. }
  52495. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52496. {
  52497. return new DropShadower (0.4f, 1, 5, 10);
  52498. }
  52499. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52500. int w, int h,
  52501. bool /*isVerticalBar*/,
  52502. bool isMouseOver,
  52503. bool isMouseDragging)
  52504. {
  52505. float alpha = 0.5f;
  52506. if (isMouseOver || isMouseDragging)
  52507. {
  52508. g.fillAll (Colour (0x190000ff));
  52509. alpha = 1.0f;
  52510. }
  52511. const float cx = w * 0.5f;
  52512. const float cy = h * 0.5f;
  52513. const float cr = jmin (w, h) * 0.4f;
  52514. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52515. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52516. true));
  52517. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52518. }
  52519. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52520. const String& text,
  52521. const Justification& position,
  52522. GroupComponent& group)
  52523. {
  52524. const float textH = 15.0f;
  52525. const float indent = 3.0f;
  52526. const float textEdgeGap = 4.0f;
  52527. float cs = 5.0f;
  52528. Font f (textH);
  52529. Path p;
  52530. float x = indent;
  52531. float y = f.getAscent() - 3.0f;
  52532. float w = jmax (0.0f, width - x * 2.0f);
  52533. float h = jmax (0.0f, height - y - indent);
  52534. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52535. const float cs2 = 2.0f * cs;
  52536. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52537. float textX = cs + textEdgeGap;
  52538. if (position.testFlags (Justification::horizontallyCentred))
  52539. textX = cs + (w - cs2 - textW) * 0.5f;
  52540. else if (position.testFlags (Justification::right))
  52541. textX = w - cs - textW - textEdgeGap;
  52542. p.startNewSubPath (x + textX + textW, y);
  52543. p.lineTo (x + w - cs, y);
  52544. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52545. p.lineTo (x + w, y + h - cs);
  52546. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52547. p.lineTo (x + cs, y + h);
  52548. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52549. p.lineTo (x, y + cs);
  52550. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52551. p.lineTo (x + textX, y);
  52552. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52553. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52554. .withMultipliedAlpha (alpha));
  52555. g.strokePath (p, PathStrokeType (2.0f));
  52556. g.setColour (group.findColour (GroupComponent::textColourId)
  52557. .withMultipliedAlpha (alpha));
  52558. g.setFont (f);
  52559. g.drawText (text,
  52560. roundToInt (x + textX), 0,
  52561. roundToInt (textW),
  52562. roundToInt (textH),
  52563. Justification::centred, true);
  52564. }
  52565. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52566. {
  52567. return 1 + tabDepth / 3;
  52568. }
  52569. int LookAndFeel::getTabButtonSpaceAroundImage()
  52570. {
  52571. return 4;
  52572. }
  52573. void LookAndFeel::createTabButtonShape (Path& p,
  52574. int width, int height,
  52575. int /*tabIndex*/,
  52576. const String& /*text*/,
  52577. Button& /*button*/,
  52578. TabbedButtonBar::Orientation orientation,
  52579. const bool /*isMouseOver*/,
  52580. const bool /*isMouseDown*/,
  52581. const bool /*isFrontTab*/)
  52582. {
  52583. const float w = (float) width;
  52584. const float h = (float) height;
  52585. float length = w;
  52586. float depth = h;
  52587. if (orientation == TabbedButtonBar::TabsAtLeft
  52588. || orientation == TabbedButtonBar::TabsAtRight)
  52589. {
  52590. swapVariables (length, depth);
  52591. }
  52592. const float indent = (float) getTabButtonOverlap ((int) depth);
  52593. const float overhang = 4.0f;
  52594. if (orientation == TabbedButtonBar::TabsAtLeft)
  52595. {
  52596. p.startNewSubPath (w, 0.0f);
  52597. p.lineTo (0.0f, indent);
  52598. p.lineTo (0.0f, h - indent);
  52599. p.lineTo (w, h);
  52600. p.lineTo (w + overhang, h + overhang);
  52601. p.lineTo (w + overhang, -overhang);
  52602. }
  52603. else if (orientation == TabbedButtonBar::TabsAtRight)
  52604. {
  52605. p.startNewSubPath (0.0f, 0.0f);
  52606. p.lineTo (w, indent);
  52607. p.lineTo (w, h - indent);
  52608. p.lineTo (0.0f, h);
  52609. p.lineTo (-overhang, h + overhang);
  52610. p.lineTo (-overhang, -overhang);
  52611. }
  52612. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52613. {
  52614. p.startNewSubPath (0.0f, 0.0f);
  52615. p.lineTo (indent, h);
  52616. p.lineTo (w - indent, h);
  52617. p.lineTo (w, 0.0f);
  52618. p.lineTo (w + overhang, -overhang);
  52619. p.lineTo (-overhang, -overhang);
  52620. }
  52621. else
  52622. {
  52623. p.startNewSubPath (0.0f, h);
  52624. p.lineTo (indent, 0.0f);
  52625. p.lineTo (w - indent, 0.0f);
  52626. p.lineTo (w, h);
  52627. p.lineTo (w + overhang, h + overhang);
  52628. p.lineTo (-overhang, h + overhang);
  52629. }
  52630. p.closeSubPath();
  52631. p = p.createPathWithRoundedCorners (3.0f);
  52632. }
  52633. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52634. const Path& path,
  52635. const Colour& preferredColour,
  52636. int /*tabIndex*/,
  52637. const String& /*text*/,
  52638. Button& button,
  52639. TabbedButtonBar::Orientation /*orientation*/,
  52640. const bool /*isMouseOver*/,
  52641. const bool /*isMouseDown*/,
  52642. const bool isFrontTab)
  52643. {
  52644. g.setColour (isFrontTab ? preferredColour
  52645. : preferredColour.withMultipliedAlpha (0.9f));
  52646. g.fillPath (path);
  52647. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52648. : TabbedButtonBar::tabOutlineColourId, false)
  52649. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52650. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52651. }
  52652. void LookAndFeel::drawTabButtonText (Graphics& g,
  52653. int x, int y, int w, int h,
  52654. const Colour& preferredBackgroundColour,
  52655. int /*tabIndex*/,
  52656. const String& text,
  52657. Button& button,
  52658. TabbedButtonBar::Orientation orientation,
  52659. const bool isMouseOver,
  52660. const bool isMouseDown,
  52661. const bool isFrontTab)
  52662. {
  52663. int length = w;
  52664. int depth = h;
  52665. if (orientation == TabbedButtonBar::TabsAtLeft
  52666. || orientation == TabbedButtonBar::TabsAtRight)
  52667. {
  52668. swapVariables (length, depth);
  52669. }
  52670. Font font (depth * 0.6f);
  52671. font.setUnderline (button.hasKeyboardFocus (false));
  52672. GlyphArrangement textLayout;
  52673. textLayout.addFittedText (font, text.trim(),
  52674. 0.0f, 0.0f, (float) length, (float) depth,
  52675. Justification::centred,
  52676. jmax (1, depth / 12));
  52677. AffineTransform transform;
  52678. if (orientation == TabbedButtonBar::TabsAtLeft)
  52679. {
  52680. transform = transform.rotated (float_Pi * -0.5f)
  52681. .translated ((float) x, (float) (y + h));
  52682. }
  52683. else if (orientation == TabbedButtonBar::TabsAtRight)
  52684. {
  52685. transform = transform.rotated (float_Pi * 0.5f)
  52686. .translated ((float) (x + w), (float) y);
  52687. }
  52688. else
  52689. {
  52690. transform = transform.translated ((float) x, (float) y);
  52691. }
  52692. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52693. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52694. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52695. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52696. else
  52697. g.setColour (preferredBackgroundColour.contrasting());
  52698. if (! (isMouseOver || isMouseDown))
  52699. g.setOpacity (0.8f);
  52700. if (! button.isEnabled())
  52701. g.setOpacity (0.3f);
  52702. textLayout.draw (g, transform);
  52703. }
  52704. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52705. const String& text,
  52706. int tabDepth,
  52707. Button&)
  52708. {
  52709. Font f (tabDepth * 0.6f);
  52710. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52711. }
  52712. void LookAndFeel::drawTabButton (Graphics& g,
  52713. int w, int h,
  52714. const Colour& preferredColour,
  52715. int tabIndex,
  52716. const String& text,
  52717. Button& button,
  52718. TabbedButtonBar::Orientation orientation,
  52719. const bool isMouseOver,
  52720. const bool isMouseDown,
  52721. const bool isFrontTab)
  52722. {
  52723. int length = w;
  52724. int depth = h;
  52725. if (orientation == TabbedButtonBar::TabsAtLeft
  52726. || orientation == TabbedButtonBar::TabsAtRight)
  52727. {
  52728. swapVariables (length, depth);
  52729. }
  52730. Path tabShape;
  52731. createTabButtonShape (tabShape, w, h,
  52732. tabIndex, text, button, orientation,
  52733. isMouseOver, isMouseDown, isFrontTab);
  52734. fillTabButtonShape (g, tabShape, preferredColour,
  52735. tabIndex, text, button, orientation,
  52736. isMouseOver, isMouseDown, isFrontTab);
  52737. const int indent = getTabButtonOverlap (depth);
  52738. int x = 0, y = 0;
  52739. if (orientation == TabbedButtonBar::TabsAtLeft
  52740. || orientation == TabbedButtonBar::TabsAtRight)
  52741. {
  52742. y += indent;
  52743. h -= indent * 2;
  52744. }
  52745. else
  52746. {
  52747. x += indent;
  52748. w -= indent * 2;
  52749. }
  52750. drawTabButtonText (g, x, y, w, h, preferredColour,
  52751. tabIndex, text, button, orientation,
  52752. isMouseOver, isMouseDown, isFrontTab);
  52753. }
  52754. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52755. int w, int h,
  52756. TabbedButtonBar& tabBar,
  52757. TabbedButtonBar::Orientation orientation)
  52758. {
  52759. const float shadowSize = 0.2f;
  52760. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52761. Rectangle<int> shadowRect;
  52762. if (orientation == TabbedButtonBar::TabsAtLeft)
  52763. {
  52764. x1 = (float) w;
  52765. x2 = w * (1.0f - shadowSize);
  52766. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52767. }
  52768. else if (orientation == TabbedButtonBar::TabsAtRight)
  52769. {
  52770. x2 = w * shadowSize;
  52771. shadowRect.setBounds (0, 0, (int) x2, h);
  52772. }
  52773. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52774. {
  52775. y2 = h * shadowSize;
  52776. shadowRect.setBounds (0, 0, w, (int) y2);
  52777. }
  52778. else
  52779. {
  52780. y1 = (float) h;
  52781. y2 = h * (1.0f - shadowSize);
  52782. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52783. }
  52784. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52785. Colours::transparentBlack, x2, y2, false));
  52786. shadowRect.expand (2, 2);
  52787. g.fillRect (shadowRect);
  52788. g.setColour (Colour (0x80000000));
  52789. if (orientation == TabbedButtonBar::TabsAtLeft)
  52790. {
  52791. g.fillRect (w - 1, 0, 1, h);
  52792. }
  52793. else if (orientation == TabbedButtonBar::TabsAtRight)
  52794. {
  52795. g.fillRect (0, 0, 1, h);
  52796. }
  52797. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52798. {
  52799. g.fillRect (0, 0, w, 1);
  52800. }
  52801. else
  52802. {
  52803. g.fillRect (0, h - 1, w, 1);
  52804. }
  52805. }
  52806. Button* LookAndFeel::createTabBarExtrasButton()
  52807. {
  52808. const float thickness = 7.0f;
  52809. const float indent = 22.0f;
  52810. Path p;
  52811. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52812. DrawablePath ellipse;
  52813. ellipse.setPath (p);
  52814. ellipse.setFill (Colour (0x99ffffff));
  52815. p.clear();
  52816. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52817. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52818. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52819. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52820. p.setUsingNonZeroWinding (false);
  52821. DrawablePath dp;
  52822. dp.setPath (p);
  52823. dp.setFill (Colour (0x59000000));
  52824. DrawableComposite normalImage;
  52825. normalImage.insertDrawable (ellipse);
  52826. normalImage.insertDrawable (dp);
  52827. dp.setFill (Colour (0xcc000000));
  52828. DrawableComposite overImage;
  52829. overImage.insertDrawable (ellipse);
  52830. overImage.insertDrawable (dp);
  52831. DrawableButton* db = new DrawableButton ("tabs", DrawableButton::ImageFitted);
  52832. db->setImages (&normalImage, &overImage, 0);
  52833. return db;
  52834. }
  52835. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52836. {
  52837. g.fillAll (Colours::white);
  52838. const int w = header.getWidth();
  52839. const int h = header.getHeight();
  52840. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52841. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52842. false));
  52843. g.fillRect (0, h / 2, w, h);
  52844. g.setColour (Colour (0x33000000));
  52845. g.fillRect (0, h - 1, w, 1);
  52846. for (int i = header.getNumColumns (true); --i >= 0;)
  52847. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52848. }
  52849. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52850. int width, int height,
  52851. bool isMouseOver, bool isMouseDown,
  52852. int columnFlags)
  52853. {
  52854. if (isMouseDown)
  52855. g.fillAll (Colour (0x8899aadd));
  52856. else if (isMouseOver)
  52857. g.fillAll (Colour (0x5599aadd));
  52858. int rightOfText = width - 4;
  52859. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52860. {
  52861. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52862. const float bottom = height - top;
  52863. const float w = height * 0.5f;
  52864. const float x = rightOfText - (w * 1.25f);
  52865. rightOfText = (int) x;
  52866. Path sortArrow;
  52867. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52868. g.setColour (Colour (0x99000000));
  52869. g.fillPath (sortArrow);
  52870. }
  52871. g.setColour (Colours::black);
  52872. g.setFont (height * 0.5f, Font::bold);
  52873. const int textX = 4;
  52874. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52875. }
  52876. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52877. {
  52878. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  52879. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  52880. background.darker (0.1f),
  52881. toolbar.isVertical() ? w - 1.0f : 0.0f,
  52882. toolbar.isVertical() ? 0.0f : h - 1.0f,
  52883. false));
  52884. g.fillAll();
  52885. }
  52886. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  52887. {
  52888. return createTabBarExtrasButton();
  52889. }
  52890. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  52891. bool isMouseOver, bool isMouseDown,
  52892. ToolbarItemComponent& component)
  52893. {
  52894. if (isMouseDown)
  52895. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  52896. else if (isMouseOver)
  52897. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  52898. }
  52899. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  52900. const String& text, ToolbarItemComponent& component)
  52901. {
  52902. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  52903. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  52904. const float fontHeight = jmin (14.0f, height * 0.85f);
  52905. g.setFont (fontHeight);
  52906. g.drawFittedText (text,
  52907. x, y, width, height,
  52908. Justification::centred,
  52909. jmax (1, height / (int) fontHeight));
  52910. }
  52911. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  52912. bool isOpen, int width, int height)
  52913. {
  52914. const int buttonSize = (height * 3) / 4;
  52915. const int buttonIndent = (height - buttonSize) / 2;
  52916. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  52917. const int textX = buttonIndent * 2 + buttonSize + 2;
  52918. g.setColour (Colours::black);
  52919. g.setFont (height * 0.7f, Font::bold);
  52920. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  52921. }
  52922. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  52923. PropertyComponent&)
  52924. {
  52925. g.setColour (Colour (0x66ffffff));
  52926. g.fillRect (0, 0, width, height - 1);
  52927. }
  52928. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  52929. PropertyComponent& component)
  52930. {
  52931. g.setColour (Colours::black);
  52932. if (! component.isEnabled())
  52933. g.setOpacity (0.6f);
  52934. g.setFont (jmin (height, 24) * 0.65f);
  52935. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  52936. g.drawFittedText (component.getName(),
  52937. 3, r.getY(), r.getX() - 5, r.getHeight(),
  52938. Justification::centredLeft, 2);
  52939. }
  52940. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  52941. {
  52942. return Rectangle<int> (component.getWidth() / 3, 1,
  52943. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  52944. }
  52945. void LookAndFeel::createFileChooserHeaderText (const String& title,
  52946. const String& instructions,
  52947. GlyphArrangement& text,
  52948. int width)
  52949. {
  52950. text.clear();
  52951. text.addJustifiedText (Font (17.0f, Font::bold), title,
  52952. 8.0f, 22.0f, width - 16.0f,
  52953. Justification::centred);
  52954. text.addJustifiedText (Font (14.0f), instructions,
  52955. 8.0f, 24.0f + 16.0f, width - 16.0f,
  52956. Justification::centred);
  52957. }
  52958. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  52959. const String& filename, Image* icon,
  52960. const String& fileSizeDescription,
  52961. const String& fileTimeDescription,
  52962. const bool isDirectory,
  52963. const bool isItemSelected,
  52964. const int /*itemIndex*/)
  52965. {
  52966. if (isItemSelected)
  52967. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  52968. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  52969. g.setFont (height * 0.7f);
  52970. Image* im = icon;
  52971. Image* toRelease = 0;
  52972. if (im == 0)
  52973. {
  52974. toRelease = im = (isDirectory ? getDefaultFolderImage()
  52975. : getDefaultDocumentFileImage());
  52976. }
  52977. const int x = 32;
  52978. if (im != 0)
  52979. {
  52980. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  52981. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  52982. false);
  52983. ImageCache::release (toRelease);
  52984. }
  52985. if (width > 450 && ! isDirectory)
  52986. {
  52987. const int sizeX = roundToInt (width * 0.7f);
  52988. const int dateX = roundToInt (width * 0.8f);
  52989. g.drawFittedText (filename,
  52990. x, 0, sizeX - x, height,
  52991. Justification::centredLeft, 1);
  52992. g.setFont (height * 0.5f);
  52993. g.setColour (Colours::darkgrey);
  52994. if (! isDirectory)
  52995. {
  52996. g.drawFittedText (fileSizeDescription,
  52997. sizeX, 0, dateX - sizeX - 8, height,
  52998. Justification::centredRight, 1);
  52999. g.drawFittedText (fileTimeDescription,
  53000. dateX, 0, width - 8 - dateX, height,
  53001. Justification::centredRight, 1);
  53002. }
  53003. }
  53004. else
  53005. {
  53006. g.drawFittedText (filename,
  53007. x, 0, width - x, height,
  53008. Justification::centredLeft, 1);
  53009. }
  53010. }
  53011. Button* LookAndFeel::createFileBrowserGoUpButton()
  53012. {
  53013. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53014. Path arrowPath;
  53015. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53016. DrawablePath arrowImage;
  53017. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53018. arrowImage.setPath (arrowPath);
  53019. goUpButton->setImages (&arrowImage);
  53020. return goUpButton;
  53021. }
  53022. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53023. DirectoryContentsDisplayComponent* fileListComponent,
  53024. FilePreviewComponent* previewComp,
  53025. ComboBox* currentPathBox,
  53026. TextEditor* filenameBox,
  53027. Button* goUpButton)
  53028. {
  53029. const int x = 8;
  53030. int w = browserComp.getWidth() - x - x;
  53031. if (previewComp != 0)
  53032. {
  53033. const int previewWidth = w / 3;
  53034. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53035. w -= previewWidth + 4;
  53036. }
  53037. int y = 4;
  53038. const int controlsHeight = 22;
  53039. const int bottomSectionHeight = controlsHeight + 8;
  53040. const int upButtonWidth = 50;
  53041. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53042. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53043. y += controlsHeight + 4;
  53044. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53045. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53046. y = listAsComp->getBottom() + 4;
  53047. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53048. }
  53049. Image* LookAndFeel::getDefaultFolderImage()
  53050. {
  53051. 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,
  53052. 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,
  53053. 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,
  53054. 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,
  53055. 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,
  53056. 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,
  53057. 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,
  53058. 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,
  53059. 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,
  53060. 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,
  53061. 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,
  53062. 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,
  53063. 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,
  53064. 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,
  53065. 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,
  53066. 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,
  53067. 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,
  53068. 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,
  53069. 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,
  53070. 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,
  53071. 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,
  53072. 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,
  53073. 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,
  53074. 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,
  53075. 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,
  53076. 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,
  53077. 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,
  53078. 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,
  53079. 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,
  53080. 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,
  53081. 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,
  53082. 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,
  53083. 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,
  53084. 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,
  53085. 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,
  53086. 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,
  53087. 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,
  53088. 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,
  53089. 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,
  53090. 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,
  53091. 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,
  53092. 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,
  53093. 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,
  53094. 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};
  53095. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53096. }
  53097. Image* LookAndFeel::getDefaultDocumentFileImage()
  53098. {
  53099. 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,
  53100. 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,
  53101. 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,
  53102. 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,
  53103. 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,
  53104. 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,
  53105. 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,
  53106. 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,
  53107. 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,
  53108. 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,
  53109. 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,
  53110. 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,
  53111. 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,
  53112. 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,
  53113. 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,
  53114. 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,
  53115. 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,
  53116. 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,
  53117. 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,
  53118. 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,
  53119. 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,
  53120. 174,66,96,130,0,0};
  53121. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53122. }
  53123. void LookAndFeel::playAlertSound()
  53124. {
  53125. PlatformUtilities::beep();
  53126. }
  53127. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53128. {
  53129. g.setColour (Colours::white.withAlpha (0.7f));
  53130. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53131. g.setColour (Colours::black.withAlpha (0.2f));
  53132. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53133. const int totalBlocks = 7;
  53134. const int numBlocks = roundToInt (totalBlocks * level);
  53135. const float w = (width - 6.0f) / (float) totalBlocks;
  53136. for (int i = 0; i < totalBlocks; ++i)
  53137. {
  53138. if (i >= numBlocks)
  53139. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53140. else
  53141. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53142. : Colours::red);
  53143. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53144. }
  53145. }
  53146. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53147. {
  53148. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53149. if (keyDescription.isNotEmpty())
  53150. {
  53151. if (button.isEnabled())
  53152. {
  53153. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53154. g.fillAll (textColour.withAlpha (alpha));
  53155. g.setOpacity (0.3f);
  53156. g.drawBevel (0, 0, width, height, 2);
  53157. }
  53158. g.setColour (textColour);
  53159. g.setFont (height * 0.6f);
  53160. g.drawFittedText (keyDescription,
  53161. 3, 0, width - 6, height,
  53162. Justification::centred, 1);
  53163. }
  53164. else
  53165. {
  53166. const float thickness = 7.0f;
  53167. const float indent = 22.0f;
  53168. Path p;
  53169. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53170. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53171. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53172. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53173. p.setUsingNonZeroWinding (false);
  53174. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53175. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53176. }
  53177. if (button.hasKeyboardFocus (false))
  53178. {
  53179. g.setColour (textColour.withAlpha (0.4f));
  53180. g.drawRect (0, 0, width, height);
  53181. }
  53182. }
  53183. static void createRoundedPath (Path& p,
  53184. const float x, const float y,
  53185. const float w, const float h,
  53186. const float cs,
  53187. const bool curveTopLeft, const bool curveTopRight,
  53188. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53189. {
  53190. const float cs2 = 2.0f * cs;
  53191. if (curveTopLeft)
  53192. {
  53193. p.startNewSubPath (x, y + cs);
  53194. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53195. }
  53196. else
  53197. {
  53198. p.startNewSubPath (x, y);
  53199. }
  53200. if (curveTopRight)
  53201. {
  53202. p.lineTo (x + w - cs, y);
  53203. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53204. }
  53205. else
  53206. {
  53207. p.lineTo (x + w, y);
  53208. }
  53209. if (curveBottomRight)
  53210. {
  53211. p.lineTo (x + w, y + h - cs);
  53212. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53213. }
  53214. else
  53215. {
  53216. p.lineTo (x + w, y + h);
  53217. }
  53218. if (curveBottomLeft)
  53219. {
  53220. p.lineTo (x + cs, y + h);
  53221. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53222. }
  53223. else
  53224. {
  53225. p.lineTo (x, y + h);
  53226. }
  53227. p.closeSubPath();
  53228. }
  53229. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53230. float x, float y, float w, float h,
  53231. float maxCornerSize,
  53232. const Colour& baseColour,
  53233. const float strokeWidth,
  53234. const bool flatOnLeft,
  53235. const bool flatOnRight,
  53236. const bool flatOnTop,
  53237. const bool flatOnBottom) throw()
  53238. {
  53239. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53240. return;
  53241. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53242. Path outline;
  53243. createRoundedPath (outline, x, y, w, h, cs,
  53244. ! (flatOnLeft || flatOnTop),
  53245. ! (flatOnRight || flatOnTop),
  53246. ! (flatOnLeft || flatOnBottom),
  53247. ! (flatOnRight || flatOnBottom));
  53248. ColourGradient cg (baseColour, 0.0f, y,
  53249. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53250. false);
  53251. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53252. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53253. g.setGradientFill (cg);
  53254. g.fillPath (outline);
  53255. g.setColour (Colour (0x80000000));
  53256. g.strokePath (outline, PathStrokeType (strokeWidth));
  53257. }
  53258. void LookAndFeel::drawGlassSphere (Graphics& g,
  53259. const float x, const float y,
  53260. const float diameter,
  53261. const Colour& colour,
  53262. const float outlineThickness) throw()
  53263. {
  53264. if (diameter <= outlineThickness)
  53265. return;
  53266. Path p;
  53267. p.addEllipse (x, y, diameter, diameter);
  53268. {
  53269. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53270. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53271. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53272. g.setGradientFill (cg);
  53273. g.fillPath (p);
  53274. }
  53275. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53276. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53277. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53278. ColourGradient cg (Colours::transparentBlack,
  53279. x + diameter * 0.5f, y + diameter * 0.5f,
  53280. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53281. x, y + diameter * 0.5f, true);
  53282. cg.addColour (0.7, Colours::transparentBlack);
  53283. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53284. g.setGradientFill (cg);
  53285. g.fillPath (p);
  53286. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53287. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53288. }
  53289. void LookAndFeel::drawGlassPointer (Graphics& g,
  53290. const float x, const float y,
  53291. const float diameter,
  53292. const Colour& colour, const float outlineThickness,
  53293. const int direction) throw()
  53294. {
  53295. if (diameter <= outlineThickness)
  53296. return;
  53297. Path p;
  53298. p.startNewSubPath (x + diameter * 0.5f, y);
  53299. p.lineTo (x + diameter, y + diameter * 0.6f);
  53300. p.lineTo (x + diameter, y + diameter);
  53301. p.lineTo (x, y + diameter);
  53302. p.lineTo (x, y + diameter * 0.6f);
  53303. p.closeSubPath();
  53304. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53305. {
  53306. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53307. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53308. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53309. g.setGradientFill (cg);
  53310. g.fillPath (p);
  53311. }
  53312. ColourGradient cg (Colours::transparentBlack,
  53313. x + diameter * 0.5f, y + diameter * 0.5f,
  53314. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53315. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53316. cg.addColour (0.5, Colours::transparentBlack);
  53317. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53318. g.setGradientFill (cg);
  53319. g.fillPath (p);
  53320. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53321. g.strokePath (p, PathStrokeType (outlineThickness));
  53322. }
  53323. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53324. const float x, const float y,
  53325. const float width, const float height,
  53326. const Colour& colour,
  53327. const float outlineThickness,
  53328. const float cornerSize,
  53329. const bool flatOnLeft,
  53330. const bool flatOnRight,
  53331. const bool flatOnTop,
  53332. const bool flatOnBottom) throw()
  53333. {
  53334. if (width <= outlineThickness || height <= outlineThickness)
  53335. return;
  53336. const int intX = (int) x;
  53337. const int intY = (int) y;
  53338. const int intW = (int) width;
  53339. const int intH = (int) height;
  53340. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53341. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53342. const int intEdge = (int) edgeBlurRadius;
  53343. Path outline;
  53344. createRoundedPath (outline, x, y, width, height, cs,
  53345. ! (flatOnLeft || flatOnTop),
  53346. ! (flatOnRight || flatOnTop),
  53347. ! (flatOnLeft || flatOnBottom),
  53348. ! (flatOnRight || flatOnBottom));
  53349. {
  53350. ColourGradient cg (colour.darker (0.2f), 0, y,
  53351. colour.darker (0.2f), 0, y + height, false);
  53352. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53353. cg.addColour (0.4, colour);
  53354. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53355. g.setGradientFill (cg);
  53356. g.fillPath (outline);
  53357. }
  53358. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53359. colour.darker (0.2f), x, y + height * 0.5f, true);
  53360. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53361. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53362. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53363. {
  53364. g.saveState();
  53365. g.setGradientFill (cg);
  53366. g.reduceClipRegion (intX, intY, intEdge, intH);
  53367. g.fillPath (outline);
  53368. g.restoreState();
  53369. }
  53370. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53371. {
  53372. cg.x1 = x + width - edgeBlurRadius;
  53373. cg.x2 = x + width;
  53374. g.saveState();
  53375. g.setGradientFill (cg);
  53376. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53377. g.fillPath (outline);
  53378. g.restoreState();
  53379. }
  53380. {
  53381. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53382. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53383. Path highlight;
  53384. createRoundedPath (highlight,
  53385. x + leftIndent,
  53386. y + cs * 0.1f,
  53387. width - (leftIndent + rightIndent),
  53388. height * 0.4f, cs * 0.4f,
  53389. ! (flatOnLeft || flatOnTop),
  53390. ! (flatOnRight || flatOnTop),
  53391. ! (flatOnLeft || flatOnBottom),
  53392. ! (flatOnRight || flatOnBottom));
  53393. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53394. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53395. g.fillPath (highlight);
  53396. }
  53397. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53398. g.strokePath (outline, PathStrokeType (outlineThickness));
  53399. }
  53400. END_JUCE_NAMESPACE
  53401. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53402. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53403. BEGIN_JUCE_NAMESPACE
  53404. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53405. {
  53406. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53407. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53408. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53409. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53410. setColour (Slider::thumbColourId, Colours::white);
  53411. setColour (Slider::trackColourId, Colour (0x7f000000));
  53412. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53413. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53414. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53415. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53416. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53417. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53418. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53419. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53420. }
  53421. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53422. {
  53423. }
  53424. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53425. Button& button,
  53426. const Colour& backgroundColour,
  53427. bool isMouseOverButton,
  53428. bool isButtonDown)
  53429. {
  53430. const int width = button.getWidth();
  53431. const int height = button.getHeight();
  53432. const float indent = 2.0f;
  53433. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53434. roundToInt (height * 0.4f));
  53435. Path p;
  53436. p.addRoundedRectangle (indent, indent,
  53437. width - indent * 2.0f,
  53438. height - indent * 2.0f,
  53439. (float) cornerSize);
  53440. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53441. if (isMouseOverButton)
  53442. {
  53443. if (isButtonDown)
  53444. bc = bc.brighter();
  53445. else if (bc.getBrightness() > 0.5f)
  53446. bc = bc.darker (0.1f);
  53447. else
  53448. bc = bc.brighter (0.1f);
  53449. }
  53450. g.setColour (bc);
  53451. g.fillPath (p);
  53452. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53453. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53454. }
  53455. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53456. Component& /*component*/,
  53457. float x, float y, float w, float h,
  53458. const bool ticked,
  53459. const bool isEnabled,
  53460. const bool /*isMouseOverButton*/,
  53461. const bool isButtonDown)
  53462. {
  53463. Path box;
  53464. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53465. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53466. : Colours::lightgrey.withAlpha (0.1f));
  53467. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53468. g.fillPath (box, trans);
  53469. g.setColour (Colours::black.withAlpha (0.6f));
  53470. g.strokePath (box, PathStrokeType (0.9f), trans);
  53471. if (ticked)
  53472. {
  53473. Path tick;
  53474. tick.startNewSubPath (1.5f, 3.0f);
  53475. tick.lineTo (3.0f, 6.0f);
  53476. tick.lineTo (6.0f, 0.0f);
  53477. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53478. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53479. }
  53480. }
  53481. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53482. ToggleButton& button,
  53483. bool isMouseOverButton,
  53484. bool isButtonDown)
  53485. {
  53486. if (button.hasKeyboardFocus (true))
  53487. {
  53488. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53489. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53490. }
  53491. const int tickWidth = jmin (20, button.getHeight() - 4);
  53492. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53493. (float) tickWidth, (float) tickWidth,
  53494. button.getToggleState(),
  53495. button.isEnabled(),
  53496. isMouseOverButton,
  53497. isButtonDown);
  53498. g.setColour (button.findColour (ToggleButton::textColourId));
  53499. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53500. if (! button.isEnabled())
  53501. g.setOpacity (0.5f);
  53502. const int textX = tickWidth + 5;
  53503. g.drawFittedText (button.getButtonText(),
  53504. textX, 4,
  53505. button.getWidth() - textX - 2, button.getHeight() - 8,
  53506. Justification::centredLeft, 10);
  53507. }
  53508. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53509. int width, int height,
  53510. double progress, const String& textToShow)
  53511. {
  53512. if (progress < 0 || progress >= 1.0)
  53513. {
  53514. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53515. }
  53516. else
  53517. {
  53518. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53519. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53520. g.fillAll (background);
  53521. g.setColour (foreground);
  53522. g.fillRect (1, 1,
  53523. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53524. height - 2);
  53525. if (textToShow.isNotEmpty())
  53526. {
  53527. g.setColour (Colour::contrasting (background, foreground));
  53528. g.setFont (height * 0.6f);
  53529. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53530. }
  53531. }
  53532. }
  53533. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53534. ScrollBar& bar,
  53535. int width, int height,
  53536. int buttonDirection,
  53537. bool isScrollbarVertical,
  53538. bool isMouseOverButton,
  53539. bool isButtonDown)
  53540. {
  53541. if (isScrollbarVertical)
  53542. width -= 2;
  53543. else
  53544. height -= 2;
  53545. Path p;
  53546. if (buttonDirection == 0)
  53547. p.addTriangle (width * 0.5f, height * 0.2f,
  53548. width * 0.1f, height * 0.7f,
  53549. width * 0.9f, height * 0.7f);
  53550. else if (buttonDirection == 1)
  53551. p.addTriangle (width * 0.8f, height * 0.5f,
  53552. width * 0.3f, height * 0.1f,
  53553. width * 0.3f, height * 0.9f);
  53554. else if (buttonDirection == 2)
  53555. p.addTriangle (width * 0.5f, height * 0.8f,
  53556. width * 0.1f, height * 0.3f,
  53557. width * 0.9f, height * 0.3f);
  53558. else if (buttonDirection == 3)
  53559. p.addTriangle (width * 0.2f, height * 0.5f,
  53560. width * 0.7f, height * 0.1f,
  53561. width * 0.7f, height * 0.9f);
  53562. if (isButtonDown)
  53563. g.setColour (Colours::white);
  53564. else if (isMouseOverButton)
  53565. g.setColour (Colours::white.withAlpha (0.7f));
  53566. else
  53567. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53568. g.fillPath (p);
  53569. g.setColour (Colours::black.withAlpha (0.5f));
  53570. g.strokePath (p, PathStrokeType (0.5f));
  53571. }
  53572. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53573. ScrollBar& bar,
  53574. int x, int y,
  53575. int width, int height,
  53576. bool isScrollbarVertical,
  53577. int thumbStartPosition,
  53578. int thumbSize,
  53579. bool isMouseOver,
  53580. bool isMouseDown)
  53581. {
  53582. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53583. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53584. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53585. if (thumbSize > 0.0f)
  53586. {
  53587. Rectangle<int> thumb;
  53588. if (isScrollbarVertical)
  53589. {
  53590. width -= 2;
  53591. g.fillRect (x + roundToInt (width * 0.35f), y,
  53592. roundToInt (width * 0.3f), height);
  53593. thumb.setBounds (x + 1, thumbStartPosition,
  53594. width - 2, thumbSize);
  53595. }
  53596. else
  53597. {
  53598. height -= 2;
  53599. g.fillRect (x, y + roundToInt (height * 0.35f),
  53600. width, roundToInt (height * 0.3f));
  53601. thumb.setBounds (thumbStartPosition, y + 1,
  53602. thumbSize, height - 2);
  53603. }
  53604. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53605. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53606. g.fillRect (thumb);
  53607. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53608. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53609. if (thumbSize > 16)
  53610. {
  53611. for (int i = 3; --i >= 0;)
  53612. {
  53613. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53614. g.setColour (Colours::black.withAlpha (0.15f));
  53615. if (isScrollbarVertical)
  53616. {
  53617. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53618. g.setColour (Colours::white.withAlpha (0.15f));
  53619. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53620. }
  53621. else
  53622. {
  53623. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53624. g.setColour (Colours::white.withAlpha (0.15f));
  53625. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53626. }
  53627. }
  53628. }
  53629. }
  53630. }
  53631. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53632. {
  53633. return &scrollbarShadow;
  53634. }
  53635. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53636. {
  53637. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53638. g.setColour (Colours::black.withAlpha (0.6f));
  53639. g.drawRect (0, 0, width, height);
  53640. }
  53641. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53642. bool, MenuBarComponent& menuBar)
  53643. {
  53644. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53645. }
  53646. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53647. {
  53648. if (textEditor.isEnabled())
  53649. {
  53650. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53651. g.drawRect (0, 0, width, height);
  53652. }
  53653. }
  53654. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53655. const bool isButtonDown,
  53656. int buttonX, int buttonY,
  53657. int buttonW, int buttonH,
  53658. ComboBox& box)
  53659. {
  53660. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53661. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53662. : ComboBox::backgroundColourId));
  53663. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53664. g.setColour (box.findColour (ComboBox::outlineColourId));
  53665. g.drawRect (0, 0, width, height);
  53666. const float arrowX = 0.2f;
  53667. const float arrowH = 0.3f;
  53668. if (box.isEnabled())
  53669. {
  53670. Path p;
  53671. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53672. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53673. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53674. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53675. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53676. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53677. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53678. : ComboBox::buttonColourId));
  53679. g.fillPath (p);
  53680. }
  53681. }
  53682. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53683. {
  53684. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53685. f.setHorizontalScale (0.9f);
  53686. return f;
  53687. }
  53688. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53689. {
  53690. Path p;
  53691. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53692. g.setColour (fill);
  53693. g.fillPath (p);
  53694. g.setColour (outline);
  53695. g.strokePath (p, PathStrokeType (0.3f));
  53696. }
  53697. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53698. int x, int y,
  53699. int w, int h,
  53700. float sliderPos,
  53701. float minSliderPos,
  53702. float maxSliderPos,
  53703. const Slider::SliderStyle style,
  53704. Slider& slider)
  53705. {
  53706. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53707. if (style == Slider::LinearBar)
  53708. {
  53709. g.setColour (slider.findColour (Slider::thumbColourId));
  53710. g.fillRect (x, y, (int) sliderPos - x, h);
  53711. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53712. g.drawRect (x, y, (int) sliderPos - x, h);
  53713. }
  53714. else
  53715. {
  53716. g.setColour (slider.findColour (Slider::trackColourId)
  53717. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53718. if (slider.isHorizontal())
  53719. {
  53720. g.fillRect (x, y + roundToInt (h * 0.6f),
  53721. w, roundToInt (h * 0.2f));
  53722. }
  53723. else
  53724. {
  53725. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53726. jmin (4, roundToInt (w * 0.2f)), h);
  53727. }
  53728. float alpha = 0.35f;
  53729. if (slider.isEnabled())
  53730. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53731. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53732. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53733. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53734. {
  53735. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53736. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53737. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53738. fill, outline);
  53739. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53740. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53741. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53742. fill, outline);
  53743. }
  53744. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53745. {
  53746. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53747. minSliderPos - 7.0f, y + h * 0.9f ,
  53748. minSliderPos, y + h * 0.9f,
  53749. fill, outline);
  53750. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53751. maxSliderPos, y + h * 0.9f,
  53752. maxSliderPos + 7.0f, y + h * 0.9f,
  53753. fill, outline);
  53754. }
  53755. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53756. {
  53757. drawTriangle (g, sliderPos, y + h * 0.9f,
  53758. sliderPos - 7.0f, y + h * 0.2f,
  53759. sliderPos + 7.0f, y + h * 0.2f,
  53760. fill, outline);
  53761. }
  53762. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53763. {
  53764. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53765. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53766. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53767. fill, outline);
  53768. }
  53769. }
  53770. }
  53771. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53772. {
  53773. if (isIncrement)
  53774. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53775. else
  53776. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53777. }
  53778. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53779. {
  53780. return &scrollbarShadow;
  53781. }
  53782. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53783. {
  53784. return 8;
  53785. }
  53786. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53787. int w, int h,
  53788. bool isMouseOver,
  53789. bool isMouseDragging)
  53790. {
  53791. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53792. : Colours::darkgrey);
  53793. const float lineThickness = jmin (w, h) * 0.1f;
  53794. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53795. {
  53796. g.drawLine (w * i,
  53797. h + 1.0f,
  53798. w + 1.0f,
  53799. h * i,
  53800. lineThickness);
  53801. }
  53802. }
  53803. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53804. {
  53805. Path shape;
  53806. if (buttonType == DocumentWindow::closeButton)
  53807. {
  53808. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53809. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53810. ShapeButton* const b = new ShapeButton ("close",
  53811. Colour (0x7fff3333),
  53812. Colour (0xd7ff3333),
  53813. Colour (0xf7ff3333));
  53814. b->setShape (shape, true, true, true);
  53815. return b;
  53816. }
  53817. else if (buttonType == DocumentWindow::minimiseButton)
  53818. {
  53819. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53820. DrawableButton* b = new DrawableButton ("minimise", 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. else if (buttonType == DocumentWindow::maximiseButton)
  53828. {
  53829. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53830. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53831. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53832. DrawablePath dp;
  53833. dp.setPath (shape);
  53834. dp.setFill (Colours::black.withAlpha (0.3f));
  53835. b->setImages (&dp);
  53836. return b;
  53837. }
  53838. jassertfalse
  53839. return 0;
  53840. }
  53841. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53842. int titleBarX,
  53843. int titleBarY,
  53844. int titleBarW,
  53845. int titleBarH,
  53846. Button* minimiseButton,
  53847. Button* maximiseButton,
  53848. Button* closeButton,
  53849. bool positionTitleBarButtonsOnLeft)
  53850. {
  53851. titleBarY += titleBarH / 8;
  53852. titleBarH -= titleBarH / 4;
  53853. const int buttonW = titleBarH;
  53854. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53855. : titleBarX + titleBarW - buttonW - 4;
  53856. if (closeButton != 0)
  53857. {
  53858. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53859. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53860. : -(buttonW + buttonW / 5);
  53861. }
  53862. if (positionTitleBarButtonsOnLeft)
  53863. swapVariables (minimiseButton, maximiseButton);
  53864. if (maximiseButton != 0)
  53865. {
  53866. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53867. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53868. }
  53869. if (minimiseButton != 0)
  53870. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53871. }
  53872. END_JUCE_NAMESPACE
  53873. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53874. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53875. BEGIN_JUCE_NAMESPACE
  53876. class DummyMenuComponent : public Component
  53877. {
  53878. DummyMenuComponent (const DummyMenuComponent&);
  53879. DummyMenuComponent& operator= (const DummyMenuComponent&);
  53880. public:
  53881. DummyMenuComponent() {}
  53882. ~DummyMenuComponent() {}
  53883. void inputAttemptWhenModal()
  53884. {
  53885. exitModalState (0);
  53886. }
  53887. };
  53888. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  53889. : model (0),
  53890. itemUnderMouse (-1),
  53891. currentPopupIndex (-1),
  53892. indexToShowAgain (-1),
  53893. lastMouseX (0),
  53894. lastMouseY (0),
  53895. inModalState (false)
  53896. {
  53897. setRepaintsOnMouseActivity (true);
  53898. setWantsKeyboardFocus (false);
  53899. setMouseClickGrabsKeyboardFocus (false);
  53900. setModel (model_);
  53901. }
  53902. MenuBarComponent::~MenuBarComponent()
  53903. {
  53904. setModel (0);
  53905. Desktop::getInstance().removeGlobalMouseListener (this);
  53906. currentPopup = 0;
  53907. }
  53908. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  53909. {
  53910. if (model != newModel)
  53911. {
  53912. if (model != 0)
  53913. model->removeListener (this);
  53914. model = newModel;
  53915. if (model != 0)
  53916. model->addListener (this);
  53917. repaint();
  53918. menuBarItemsChanged (0);
  53919. }
  53920. }
  53921. void MenuBarComponent::paint (Graphics& g)
  53922. {
  53923. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  53924. getLookAndFeel().drawMenuBarBackground (g,
  53925. getWidth(),
  53926. getHeight(),
  53927. isMouseOverBar,
  53928. *this);
  53929. if (model != 0)
  53930. {
  53931. for (int i = 0; i < menuNames.size(); ++i)
  53932. {
  53933. g.saveState();
  53934. g.setOrigin (xPositions [i], 0);
  53935. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  53936. getLookAndFeel().drawMenuBarItem (g,
  53937. xPositions[i + 1] - xPositions[i],
  53938. getHeight(),
  53939. i,
  53940. menuNames[i],
  53941. i == itemUnderMouse,
  53942. i == currentPopupIndex,
  53943. isMouseOverBar,
  53944. *this);
  53945. g.restoreState();
  53946. }
  53947. }
  53948. }
  53949. void MenuBarComponent::resized()
  53950. {
  53951. xPositions.clear();
  53952. int x = 2;
  53953. xPositions.add (x);
  53954. for (int i = 0; i < menuNames.size(); ++i)
  53955. {
  53956. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  53957. xPositions.add (x);
  53958. }
  53959. }
  53960. int MenuBarComponent::getItemAt (const int x, const int y)
  53961. {
  53962. for (int i = 0; i < xPositions.size(); ++i)
  53963. if (x >= xPositions[i] && x < xPositions[i + 1])
  53964. return reallyContains (x, y, true) ? i : -1;
  53965. return -1;
  53966. }
  53967. void MenuBarComponent::repaintMenuItem (int index)
  53968. {
  53969. if (((unsigned int) index) < (unsigned int) xPositions.size())
  53970. {
  53971. const int x1 = xPositions [index];
  53972. const int x2 = xPositions [index + 1];
  53973. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  53974. }
  53975. }
  53976. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  53977. {
  53978. const int newItem = getItemAt (x, y);
  53979. if (itemUnderMouse != newItem)
  53980. {
  53981. repaintMenuItem (itemUnderMouse);
  53982. itemUnderMouse = newItem;
  53983. repaintMenuItem (itemUnderMouse);
  53984. }
  53985. }
  53986. void MenuBarComponent::hideCurrentMenu()
  53987. {
  53988. currentPopup = 0;
  53989. repaint();
  53990. }
  53991. void MenuBarComponent::showMenu (int index)
  53992. {
  53993. if (index != currentPopupIndex)
  53994. {
  53995. if (inModalState)
  53996. {
  53997. hideCurrentMenu();
  53998. indexToShowAgain = index;
  53999. return;
  54000. }
  54001. indexToShowAgain = -1;
  54002. currentPopupIndex = -1;
  54003. itemUnderMouse = index;
  54004. currentPopup = 0;
  54005. menuBarItemsChanged (0);
  54006. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  54007. Component::SafePointer<Component> deletionChecker (this);
  54008. enterModalState (false);
  54009. inModalState = true;
  54010. int result = 0;
  54011. ApplicationCommandManager* managerOfChosenCommand = 0;
  54012. Desktop::getInstance().addGlobalMouseListener (this);
  54013. for (;;)
  54014. {
  54015. const int x = getScreenX() + xPositions [itemUnderMouse];
  54016. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54017. currentPopupIndex = itemUnderMouse;
  54018. indexToShowAgain = -1;
  54019. repaint();
  54020. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54021. {
  54022. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54023. menuNames [itemUnderMouse]));
  54024. if (m.lookAndFeel == 0)
  54025. m.setLookAndFeel (&getLookAndFeel());
  54026. currentPopup = m.createMenuComponent (x, getScreenY(),
  54027. w, getHeight(),
  54028. 0, w, 0, 0,
  54029. true, this,
  54030. &managerOfChosenCommand,
  54031. this);
  54032. }
  54033. if (currentPopup == 0)
  54034. {
  54035. currentPopup = new DummyMenuComponent();
  54036. addAndMakeVisible (currentPopup);
  54037. }
  54038. currentPopup->enterModalState (false);
  54039. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54040. // be stuck behind other comps that are already modal..
  54041. result = currentPopup->runModalLoop();
  54042. if (deletionChecker == 0)
  54043. return;
  54044. const int lastPopupIndex = currentPopupIndex;
  54045. currentPopup = 0;
  54046. currentPopupIndex = -1;
  54047. if (result != 0)
  54048. {
  54049. topLevelIndexClicked = lastPopupIndex;
  54050. break;
  54051. }
  54052. else if (indexToShowAgain >= 0)
  54053. {
  54054. menuBarItemsChanged (0);
  54055. repaint();
  54056. itemUnderMouse = indexToShowAgain;
  54057. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54058. break;
  54059. }
  54060. else
  54061. {
  54062. break;
  54063. }
  54064. }
  54065. Desktop::getInstance().removeGlobalMouseListener (this);
  54066. inModalState = false;
  54067. exitModalState (0);
  54068. if (prevFocused != 0)
  54069. prevFocused->grabKeyboardFocus();
  54070. const Point<int> mousePos (getMouseXYRelative());
  54071. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54072. repaint();
  54073. if (result != 0)
  54074. {
  54075. if (managerOfChosenCommand != 0)
  54076. {
  54077. ApplicationCommandTarget::InvocationInfo info (result);
  54078. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54079. managerOfChosenCommand->invoke (info, true);
  54080. }
  54081. postCommandMessage (result);
  54082. }
  54083. }
  54084. }
  54085. void MenuBarComponent::handleCommandMessage (int commandId)
  54086. {
  54087. if (model != 0)
  54088. model->menuItemSelected (commandId, topLevelIndexClicked);
  54089. }
  54090. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54091. {
  54092. if (e.eventComponent == this)
  54093. updateItemUnderMouse (e.x, e.y);
  54094. }
  54095. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54096. {
  54097. if (e.eventComponent == this)
  54098. updateItemUnderMouse (e.x, e.y);
  54099. }
  54100. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54101. {
  54102. if (currentPopupIndex < 0)
  54103. {
  54104. const MouseEvent e2 (e.getEventRelativeTo (this));
  54105. updateItemUnderMouse (e2.x, e2.y);
  54106. currentPopupIndex = -2;
  54107. showMenu (itemUnderMouse);
  54108. }
  54109. }
  54110. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54111. {
  54112. const MouseEvent e2 (e.getEventRelativeTo (this));
  54113. const int item = getItemAt (e2.x, e2.y);
  54114. if (item >= 0)
  54115. showMenu (item);
  54116. }
  54117. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54118. {
  54119. const MouseEvent e2 (e.getEventRelativeTo (this));
  54120. updateItemUnderMouse (e2.x, e2.y);
  54121. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54122. hideCurrentMenu();
  54123. }
  54124. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54125. {
  54126. const MouseEvent e2 (e.getEventRelativeTo (this));
  54127. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54128. {
  54129. if (currentPopupIndex >= 0)
  54130. {
  54131. const int item = getItemAt (e2.x, e2.y);
  54132. if (item >= 0)
  54133. showMenu (item);
  54134. }
  54135. else
  54136. {
  54137. updateItemUnderMouse (e2.x, e2.y);
  54138. }
  54139. lastMouseX = e2.x;
  54140. lastMouseY = e2.y;
  54141. }
  54142. }
  54143. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54144. {
  54145. bool used = false;
  54146. const int numMenus = menuNames.size();
  54147. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54148. if (key.isKeyCode (KeyPress::leftKey))
  54149. {
  54150. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54151. used = true;
  54152. }
  54153. else if (key.isKeyCode (KeyPress::rightKey))
  54154. {
  54155. showMenu ((currentIndex + 1) % numMenus);
  54156. used = true;
  54157. }
  54158. return used;
  54159. }
  54160. void MenuBarComponent::inputAttemptWhenModal()
  54161. {
  54162. hideCurrentMenu();
  54163. }
  54164. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54165. {
  54166. StringArray newNames;
  54167. if (model != 0)
  54168. newNames = model->getMenuBarNames();
  54169. if (newNames != menuNames)
  54170. {
  54171. menuNames = newNames;
  54172. repaint();
  54173. resized();
  54174. }
  54175. }
  54176. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54177. const ApplicationCommandTarget::InvocationInfo& info)
  54178. {
  54179. if (model == 0
  54180. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54181. return;
  54182. for (int i = 0; i < menuNames.size(); ++i)
  54183. {
  54184. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54185. if (menu.containsCommandItem (info.commandID))
  54186. {
  54187. itemUnderMouse = i;
  54188. repaintMenuItem (i);
  54189. startTimer (200);
  54190. break;
  54191. }
  54192. }
  54193. }
  54194. void MenuBarComponent::timerCallback()
  54195. {
  54196. stopTimer();
  54197. const Point<int> mousePos (getMouseXYRelative());
  54198. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54199. }
  54200. END_JUCE_NAMESPACE
  54201. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54202. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54203. BEGIN_JUCE_NAMESPACE
  54204. MenuBarModel::MenuBarModel() throw()
  54205. : manager (0)
  54206. {
  54207. }
  54208. MenuBarModel::~MenuBarModel()
  54209. {
  54210. setApplicationCommandManagerToWatch (0);
  54211. }
  54212. void MenuBarModel::menuItemsChanged()
  54213. {
  54214. triggerAsyncUpdate();
  54215. }
  54216. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54217. {
  54218. if (manager != newManager)
  54219. {
  54220. if (manager != 0)
  54221. manager->removeListener (this);
  54222. manager = newManager;
  54223. if (manager != 0)
  54224. manager->addListener (this);
  54225. }
  54226. }
  54227. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54228. {
  54229. listeners.add (newListener);
  54230. }
  54231. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54232. {
  54233. // Trying to remove a listener that isn't on the list!
  54234. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54235. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54236. jassert (listeners.contains (listenerToRemove));
  54237. listeners.remove (listenerToRemove);
  54238. }
  54239. void MenuBarModel::handleAsyncUpdate()
  54240. {
  54241. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54242. }
  54243. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54244. {
  54245. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54246. }
  54247. void MenuBarModel::applicationCommandListChanged()
  54248. {
  54249. menuItemsChanged();
  54250. }
  54251. END_JUCE_NAMESPACE
  54252. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54253. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54254. BEGIN_JUCE_NAMESPACE
  54255. class PopupMenu::Item
  54256. {
  54257. public:
  54258. Item()
  54259. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54260. usesColour (false), customComp (0), commandManager (0)
  54261. {
  54262. }
  54263. Item (const int itemId_,
  54264. const String& text_,
  54265. const bool active_,
  54266. const bool isTicked_,
  54267. const Image* im,
  54268. const Colour& textColour_,
  54269. const bool usesColour_,
  54270. PopupMenuCustomComponent* const customComp_,
  54271. const PopupMenu* const subMenu_,
  54272. ApplicationCommandManager* const commandManager_)
  54273. : itemId (itemId_), text (text_), textColour (textColour_),
  54274. active (active_), isSeparator (false), isTicked (isTicked_),
  54275. usesColour (usesColour_), customComp (customComp_),
  54276. commandManager (commandManager_)
  54277. {
  54278. if (subMenu_ != 0)
  54279. subMenu = new PopupMenu (*subMenu_);
  54280. if (im != 0)
  54281. image = im->createCopy();
  54282. if (commandManager_ != 0 && itemId_ != 0)
  54283. {
  54284. String shortcutKey;
  54285. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54286. ->getKeyPressesAssignedToCommand (itemId_));
  54287. for (int i = 0; i < keyPresses.size(); ++i)
  54288. {
  54289. const String key (keyPresses.getReference(i).getTextDescription());
  54290. if (shortcutKey.isNotEmpty())
  54291. shortcutKey << ", ";
  54292. if (key.length() == 1)
  54293. shortcutKey << "shortcut: '" << key << '\'';
  54294. else
  54295. shortcutKey << key;
  54296. }
  54297. shortcutKey = shortcutKey.trim();
  54298. if (shortcutKey.isNotEmpty())
  54299. text << "<end>" << shortcutKey;
  54300. }
  54301. }
  54302. Item (const Item& other)
  54303. : itemId (other.itemId),
  54304. text (other.text),
  54305. textColour (other.textColour),
  54306. active (other.active),
  54307. isSeparator (other.isSeparator),
  54308. isTicked (other.isTicked),
  54309. usesColour (other.usesColour),
  54310. customComp (other.customComp),
  54311. commandManager (other.commandManager)
  54312. {
  54313. if (other.subMenu != 0)
  54314. subMenu = new PopupMenu (*(other.subMenu));
  54315. if (other.image != 0)
  54316. image = other.image->createCopy();
  54317. }
  54318. ~Item()
  54319. {
  54320. customComp = 0;
  54321. }
  54322. bool canBeTriggered() const throw()
  54323. {
  54324. return active && ! (isSeparator || (subMenu != 0));
  54325. }
  54326. bool hasActiveSubMenu() const throw()
  54327. {
  54328. return active && (subMenu != 0);
  54329. }
  54330. const int itemId;
  54331. String text;
  54332. const Colour textColour;
  54333. const bool active, isSeparator, isTicked, usesColour;
  54334. ScopedPointer <Image> image;
  54335. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54336. ScopedPointer <PopupMenu> subMenu;
  54337. ApplicationCommandManager* const commandManager;
  54338. juce_UseDebuggingNewOperator
  54339. private:
  54340. Item& operator= (const Item&);
  54341. };
  54342. class PopupMenu::ItemComponent : public Component
  54343. {
  54344. public:
  54345. ItemComponent (const PopupMenu::Item& itemInfo_)
  54346. : itemInfo (itemInfo_),
  54347. isHighlighted (false)
  54348. {
  54349. if (itemInfo.customComp != 0)
  54350. addAndMakeVisible (itemInfo.customComp);
  54351. }
  54352. ~ItemComponent()
  54353. {
  54354. if (itemInfo.customComp != 0)
  54355. removeChildComponent (itemInfo.customComp);
  54356. }
  54357. void getIdealSize (int& idealWidth,
  54358. int& idealHeight,
  54359. const int standardItemHeight)
  54360. {
  54361. if (itemInfo.customComp != 0)
  54362. {
  54363. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54364. }
  54365. else
  54366. {
  54367. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54368. itemInfo.isSeparator,
  54369. standardItemHeight,
  54370. idealWidth,
  54371. idealHeight);
  54372. }
  54373. }
  54374. void paint (Graphics& g)
  54375. {
  54376. if (itemInfo.customComp == 0)
  54377. {
  54378. String mainText (itemInfo.text);
  54379. String endText;
  54380. const int endIndex = mainText.indexOf ("<end>");
  54381. if (endIndex >= 0)
  54382. {
  54383. endText = mainText.substring (endIndex + 5).trim();
  54384. mainText = mainText.substring (0, endIndex);
  54385. }
  54386. getLookAndFeel()
  54387. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54388. itemInfo.isSeparator,
  54389. itemInfo.active,
  54390. isHighlighted,
  54391. itemInfo.isTicked,
  54392. itemInfo.subMenu != 0,
  54393. mainText, endText,
  54394. itemInfo.image,
  54395. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54396. }
  54397. }
  54398. void resized()
  54399. {
  54400. if (getNumChildComponents() > 0)
  54401. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54402. }
  54403. void setHighlighted (bool shouldBeHighlighted)
  54404. {
  54405. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54406. if (isHighlighted != shouldBeHighlighted)
  54407. {
  54408. isHighlighted = shouldBeHighlighted;
  54409. if (itemInfo.customComp != 0)
  54410. {
  54411. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54412. itemInfo.customComp->repaint();
  54413. }
  54414. repaint();
  54415. }
  54416. }
  54417. PopupMenu::Item itemInfo;
  54418. juce_UseDebuggingNewOperator
  54419. private:
  54420. bool isHighlighted;
  54421. ItemComponent (const ItemComponent&);
  54422. ItemComponent& operator= (const ItemComponent&);
  54423. };
  54424. namespace PopupMenuSettings
  54425. {
  54426. static const int scrollZone = 24;
  54427. static const int borderSize = 2;
  54428. static const int timerInterval = 50;
  54429. static const int dismissCommandId = 0x6287345f;
  54430. }
  54431. class PopupMenu::Window : public Component,
  54432. private Timer
  54433. {
  54434. public:
  54435. Window()
  54436. : Component ("menu"),
  54437. owner (0),
  54438. currentChild (0),
  54439. activeSubMenu (0),
  54440. menuBarComponent (0),
  54441. managerOfChosenCommand (0),
  54442. minimumWidth (0),
  54443. maximumNumColumns (7),
  54444. standardItemHeight (0),
  54445. isOver (false),
  54446. hasBeenOver (false),
  54447. isDown (false),
  54448. needsToScroll (false),
  54449. hideOnExit (false),
  54450. disableMouseMoves (false),
  54451. hasAnyJuceCompHadFocus (false),
  54452. numColumns (0),
  54453. contentHeight (0),
  54454. childYOffset (0),
  54455. timeEnteredCurrentChildComp (0),
  54456. scrollAcceleration (1.0)
  54457. {
  54458. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54459. setWantsKeyboardFocus (true);
  54460. setMouseClickGrabsKeyboardFocus (false);
  54461. setOpaque (true);
  54462. setAlwaysOnTop (true);
  54463. Desktop::getInstance().addGlobalMouseListener (this);
  54464. getActiveWindows().add (this);
  54465. }
  54466. ~Window()
  54467. {
  54468. getActiveWindows().removeValue (this);
  54469. Desktop::getInstance().removeGlobalMouseListener (this);
  54470. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54471. activeSubMenu = 0;
  54472. deleteAllChildren();
  54473. }
  54474. static Window* create (const PopupMenu& menu,
  54475. const bool dismissOnMouseUp,
  54476. Window* const owner_,
  54477. const int minX, const int maxX,
  54478. const int minY, const int maxY,
  54479. const int minimumWidth,
  54480. const int maximumNumColumns,
  54481. const int standardItemHeight,
  54482. const bool alignToRectangle,
  54483. const int itemIdThatMustBeVisible,
  54484. Component* const menuBarComponent,
  54485. ApplicationCommandManager** managerOfChosenCommand,
  54486. Component* const componentAttachedTo)
  54487. {
  54488. if (menu.items.size() > 0)
  54489. {
  54490. int totalItems = 0;
  54491. ScopedPointer <Window> mw (new Window());
  54492. mw->setLookAndFeel (menu.lookAndFeel);
  54493. mw->setWantsKeyboardFocus (false);
  54494. mw->minimumWidth = minimumWidth;
  54495. mw->maximumNumColumns = maximumNumColumns;
  54496. mw->standardItemHeight = standardItemHeight;
  54497. mw->dismissOnMouseUp = dismissOnMouseUp;
  54498. for (int i = 0; i < menu.items.size(); ++i)
  54499. {
  54500. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54501. mw->addItem (*item);
  54502. ++totalItems;
  54503. }
  54504. if (totalItems > 0)
  54505. {
  54506. mw->owner = owner_;
  54507. mw->menuBarComponent = menuBarComponent;
  54508. mw->managerOfChosenCommand = managerOfChosenCommand;
  54509. mw->componentAttachedTo = componentAttachedTo;
  54510. mw->componentAttachedToOriginal = componentAttachedTo;
  54511. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54512. mw->setTopLeftPosition (mw->windowPos.getX(),
  54513. mw->windowPos.getY());
  54514. mw->updateYPositions();
  54515. if (itemIdThatMustBeVisible != 0)
  54516. {
  54517. const int y = minY - mw->windowPos.getY();
  54518. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54519. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54520. }
  54521. mw->resizeToBestWindowPos();
  54522. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54523. | mw->getLookAndFeel().getMenuWindowFlags());
  54524. return mw.release();
  54525. }
  54526. }
  54527. return 0;
  54528. }
  54529. void paint (Graphics& g)
  54530. {
  54531. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54532. }
  54533. void paintOverChildren (Graphics& g)
  54534. {
  54535. if (isScrolling())
  54536. {
  54537. LookAndFeel& lf = getLookAndFeel();
  54538. if (isScrollZoneActive (false))
  54539. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54540. if (isScrollZoneActive (true))
  54541. {
  54542. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54543. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54544. }
  54545. }
  54546. }
  54547. bool isScrollZoneActive (bool bottomOne) const
  54548. {
  54549. return isScrolling()
  54550. && (bottomOne
  54551. ? childYOffset < contentHeight - windowPos.getHeight()
  54552. : childYOffset > 0);
  54553. }
  54554. void addItem (const PopupMenu::Item& item)
  54555. {
  54556. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54557. addAndMakeVisible (mic);
  54558. int itemW = 80;
  54559. int itemH = 16;
  54560. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54561. mic->setSize (itemW, jlimit (2, 600, itemH));
  54562. mic->addMouseListener (this, false);
  54563. }
  54564. // hide this and all sub-comps
  54565. void hide (const PopupMenu::Item* const item)
  54566. {
  54567. if (isVisible())
  54568. {
  54569. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54570. activeSubMenu = 0;
  54571. currentChild = 0;
  54572. exitModalState (item != 0 ? item->itemId : 0);
  54573. setVisible (false);
  54574. if (item != 0
  54575. && item->commandManager != 0
  54576. && item->itemId != 0)
  54577. {
  54578. *managerOfChosenCommand = item->commandManager;
  54579. }
  54580. }
  54581. }
  54582. void dismissMenu (const PopupMenu::Item* const item)
  54583. {
  54584. if (owner != 0)
  54585. {
  54586. owner->dismissMenu (item);
  54587. }
  54588. else
  54589. {
  54590. if (item != 0)
  54591. {
  54592. // need a copy of this on the stack as the one passed in will get deleted during this call
  54593. const PopupMenu::Item mi (*item);
  54594. hide (&mi);
  54595. }
  54596. else
  54597. {
  54598. hide (0);
  54599. }
  54600. }
  54601. }
  54602. void mouseMove (const MouseEvent&)
  54603. {
  54604. timerCallback();
  54605. }
  54606. void mouseDown (const MouseEvent&)
  54607. {
  54608. timerCallback();
  54609. }
  54610. void mouseDrag (const MouseEvent&)
  54611. {
  54612. timerCallback();
  54613. }
  54614. void mouseUp (const MouseEvent&)
  54615. {
  54616. timerCallback();
  54617. }
  54618. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54619. {
  54620. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54621. lastMouse = Point<int> (-1, -1);
  54622. }
  54623. bool keyPressed (const KeyPress& key)
  54624. {
  54625. if (key.isKeyCode (KeyPress::downKey))
  54626. {
  54627. selectNextItem (1);
  54628. }
  54629. else if (key.isKeyCode (KeyPress::upKey))
  54630. {
  54631. selectNextItem (-1);
  54632. }
  54633. else if (key.isKeyCode (KeyPress::leftKey))
  54634. {
  54635. if (owner != 0)
  54636. {
  54637. Component::SafePointer<Window> parentWindow (owner);
  54638. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54639. hide (0);
  54640. if (parentWindow != 0)
  54641. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54642. disableTimerUntilMouseMoves();
  54643. }
  54644. else if (menuBarComponent != 0)
  54645. {
  54646. menuBarComponent->keyPressed (key);
  54647. }
  54648. }
  54649. else if (key.isKeyCode (KeyPress::rightKey))
  54650. {
  54651. disableTimerUntilMouseMoves();
  54652. if (showSubMenuFor (currentChild))
  54653. {
  54654. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54655. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54656. activeSubMenu->selectNextItem (1);
  54657. }
  54658. else if (menuBarComponent != 0)
  54659. {
  54660. menuBarComponent->keyPressed (key);
  54661. }
  54662. }
  54663. else if (key.isKeyCode (KeyPress::returnKey))
  54664. {
  54665. triggerCurrentlyHighlightedItem();
  54666. }
  54667. else if (key.isKeyCode (KeyPress::escapeKey))
  54668. {
  54669. dismissMenu (0);
  54670. }
  54671. else
  54672. {
  54673. return false;
  54674. }
  54675. return true;
  54676. }
  54677. void inputAttemptWhenModal()
  54678. {
  54679. timerCallback();
  54680. if (! isOverAnyMenu())
  54681. {
  54682. if (componentAttachedTo != 0)
  54683. {
  54684. // we want to dismiss the menu, but if we do it synchronously, then
  54685. // the mouse-click will be allowed to pass through. That's good, except
  54686. // when the user clicks on the button that orginally popped the menu up,
  54687. // as they'll expect the menu to go away, and in fact it'll just
  54688. // come back. So only dismiss synchronously if they're not on the original
  54689. // comp that we're attached to.
  54690. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54691. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54692. {
  54693. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54694. return;
  54695. }
  54696. }
  54697. dismissMenu (0);
  54698. }
  54699. }
  54700. void handleCommandMessage (int commandId)
  54701. {
  54702. Component::handleCommandMessage (commandId);
  54703. if (commandId == PopupMenuSettings::dismissCommandId)
  54704. dismissMenu (0);
  54705. }
  54706. void timerCallback()
  54707. {
  54708. if (! isVisible())
  54709. return;
  54710. if (componentAttachedTo != componentAttachedToOriginal)
  54711. {
  54712. dismissMenu (0);
  54713. return;
  54714. }
  54715. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54716. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54717. return;
  54718. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54719. // move rather than a real timer callback
  54720. const Point<int> globalMousePos (Desktop::getMousePosition());
  54721. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54722. const uint32 now = Time::getMillisecondCounter();
  54723. if (now > timeEnteredCurrentChildComp + 100
  54724. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54725. && currentChild->isValidComponent()
  54726. && (! disableMouseMoves)
  54727. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54728. {
  54729. showSubMenuFor (currentChild);
  54730. }
  54731. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54732. {
  54733. highlightItemUnderMouse (globalMousePos, localMousePos);
  54734. }
  54735. bool overScrollArea = false;
  54736. if (isScrolling()
  54737. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54738. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54739. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54740. {
  54741. if (now > lastScroll + 20)
  54742. {
  54743. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54744. int amount = 0;
  54745. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54746. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54747. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54748. lastScroll = now;
  54749. }
  54750. overScrollArea = true;
  54751. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54752. }
  54753. else
  54754. {
  54755. scrollAcceleration = 1.0;
  54756. }
  54757. const bool wasDown = isDown;
  54758. bool isOverAny = isOverAnyMenu();
  54759. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54760. {
  54761. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54762. isOverAny = isOverAnyMenu();
  54763. }
  54764. if (hideOnExit && hasBeenOver && ! isOverAny)
  54765. {
  54766. hide (0);
  54767. }
  54768. else
  54769. {
  54770. isDown = hasBeenOver
  54771. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54772. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54773. bool anyFocused = Process::isForegroundProcess();
  54774. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54775. {
  54776. // because no component at all may have focus, our test here will
  54777. // only be triggered when something has focus and then loses it.
  54778. anyFocused = ! hasAnyJuceCompHadFocus;
  54779. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54780. {
  54781. if (ComponentPeer::getPeer (i)->isFocused())
  54782. {
  54783. anyFocused = true;
  54784. hasAnyJuceCompHadFocus = true;
  54785. break;
  54786. }
  54787. }
  54788. }
  54789. if (! anyFocused)
  54790. {
  54791. if (now > lastFocused + 10)
  54792. {
  54793. wasHiddenBecauseOfAppChange() = true;
  54794. dismissMenu (0);
  54795. return; // may have been deleted by the previous call..
  54796. }
  54797. }
  54798. else if (wasDown && now > menuCreationTime + 250
  54799. && ! (isDown || overScrollArea))
  54800. {
  54801. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54802. if (isOver)
  54803. {
  54804. triggerCurrentlyHighlightedItem();
  54805. }
  54806. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54807. {
  54808. dismissMenu (0);
  54809. }
  54810. return; // may have been deleted by the previous calls..
  54811. }
  54812. else
  54813. {
  54814. lastFocused = now;
  54815. }
  54816. }
  54817. }
  54818. static Array<Window*>& getActiveWindows()
  54819. {
  54820. static Array<Window*> activeMenuWindows;
  54821. return activeMenuWindows;
  54822. }
  54823. static bool& wasHiddenBecauseOfAppChange() throw()
  54824. {
  54825. static bool b = false;
  54826. return b;
  54827. }
  54828. juce_UseDebuggingNewOperator
  54829. private:
  54830. Window* owner;
  54831. PopupMenu::ItemComponent* currentChild;
  54832. ScopedPointer <Window> activeSubMenu;
  54833. Component* menuBarComponent;
  54834. ApplicationCommandManager** managerOfChosenCommand;
  54835. Component::SafePointer<Component> componentAttachedTo;
  54836. Component* componentAttachedToOriginal;
  54837. Rectangle<int> windowPos;
  54838. Point<int> lastMouse;
  54839. int minimumWidth, maximumNumColumns, standardItemHeight;
  54840. bool isOver, hasBeenOver, isDown, needsToScroll;
  54841. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54842. int numColumns, contentHeight, childYOffset;
  54843. Array <int> columnWidths;
  54844. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54845. double scrollAcceleration;
  54846. bool overlaps (const Rectangle<int>& r) const
  54847. {
  54848. return r.intersects (getBounds())
  54849. || (owner != 0 && owner->overlaps (r));
  54850. }
  54851. bool isOverAnyMenu() const
  54852. {
  54853. return (owner != 0) ? owner->isOverAnyMenu()
  54854. : isOverChildren();
  54855. }
  54856. bool isOverChildren() const
  54857. {
  54858. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54859. return isVisible()
  54860. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54861. }
  54862. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54863. {
  54864. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54865. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54866. if (activeSubMenu != 0)
  54867. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54868. }
  54869. bool treeContains (const Window* const window) const throw()
  54870. {
  54871. const Window* mw = this;
  54872. while (mw->owner != 0)
  54873. mw = mw->owner;
  54874. while (mw != 0)
  54875. {
  54876. if (mw == window)
  54877. return true;
  54878. mw = mw->activeSubMenu;
  54879. }
  54880. return false;
  54881. }
  54882. void calculateWindowPos (const int minX, const int maxX,
  54883. const int minY, const int maxY,
  54884. const bool alignToRectangle)
  54885. {
  54886. const Rectangle<int> mon (Desktop::getInstance()
  54887. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  54888. (minY + maxY) / 2),
  54889. #if JUCE_MAC
  54890. true));
  54891. #else
  54892. false)); // on windows, don't stop the menu overlapping the taskbar
  54893. #endif
  54894. int x, y, widthToUse, heightToUse;
  54895. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  54896. if (alignToRectangle)
  54897. {
  54898. x = minX;
  54899. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  54900. const int spaceOver = minY - mon.getY();
  54901. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  54902. y = maxY;
  54903. else
  54904. y = minY - heightToUse;
  54905. }
  54906. else
  54907. {
  54908. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  54909. if (owner != 0)
  54910. {
  54911. if (owner->owner != 0)
  54912. {
  54913. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  54914. > owner->owner->getX() + owner->owner->getWidth() / 2);
  54915. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  54916. tendTowardsRight = true;
  54917. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  54918. tendTowardsRight = false;
  54919. }
  54920. else if (maxX + widthToUse < mon.getRight() - 32)
  54921. {
  54922. tendTowardsRight = true;
  54923. }
  54924. }
  54925. const int biggestSpace = jmax (mon.getRight() - maxX,
  54926. minX - mon.getX()) - 32;
  54927. if (biggestSpace < widthToUse)
  54928. {
  54929. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  54930. if (numColumns > 1)
  54931. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  54932. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  54933. }
  54934. if (tendTowardsRight)
  54935. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  54936. else
  54937. x = jmax (mon.getX() + 4, minX - widthToUse);
  54938. y = minY;
  54939. if ((minY + maxY) / 2 > mon.getCentreY())
  54940. y = jmax (mon.getY(), maxY - heightToUse);
  54941. }
  54942. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  54943. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  54944. windowPos.setBounds (x, y, widthToUse, heightToUse);
  54945. // sets this flag if it's big enough to obscure any of its parent menus
  54946. hideOnExit = (owner != 0)
  54947. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  54948. }
  54949. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  54950. {
  54951. numColumns = 0;
  54952. contentHeight = 0;
  54953. const int maxMenuH = getParentHeight() - 24;
  54954. int totalW;
  54955. do
  54956. {
  54957. ++numColumns;
  54958. totalW = workOutBestSize (maxMenuW);
  54959. if (totalW > maxMenuW)
  54960. {
  54961. numColumns = jmax (1, numColumns - 1);
  54962. totalW = workOutBestSize (maxMenuW); // to update col widths
  54963. break;
  54964. }
  54965. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  54966. {
  54967. break;
  54968. }
  54969. } while (numColumns < maximumNumColumns);
  54970. const int actualH = jmin (contentHeight, maxMenuH);
  54971. needsToScroll = contentHeight > actualH;
  54972. width = updateYPositions();
  54973. height = actualH + PopupMenuSettings::borderSize * 2;
  54974. }
  54975. int workOutBestSize (const int maxMenuW)
  54976. {
  54977. int totalW = 0;
  54978. contentHeight = 0;
  54979. int childNum = 0;
  54980. for (int col = 0; col < numColumns; ++col)
  54981. {
  54982. int i, colW = 50, colH = 0;
  54983. const int numChildren = jmin (getNumChildComponents() - childNum,
  54984. (getNumChildComponents() + numColumns - 1) / numColumns);
  54985. for (i = numChildren; --i >= 0;)
  54986. {
  54987. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  54988. colH += getChildComponent (childNum + i)->getHeight();
  54989. }
  54990. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  54991. columnWidths.set (col, colW);
  54992. totalW += colW;
  54993. contentHeight = jmax (contentHeight, colH);
  54994. childNum += numChildren;
  54995. }
  54996. if (totalW < minimumWidth)
  54997. {
  54998. totalW = minimumWidth;
  54999. for (int col = 0; col < numColumns; ++col)
  55000. columnWidths.set (0, totalW / numColumns);
  55001. }
  55002. return totalW;
  55003. }
  55004. void ensureItemIsVisible (const int itemId, int wantedY)
  55005. {
  55006. jassert (itemId != 0)
  55007. for (int i = getNumChildComponents(); --i >= 0;)
  55008. {
  55009. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55010. if (m != 0
  55011. && m->itemInfo.itemId == itemId
  55012. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55013. {
  55014. const int currentY = m->getY();
  55015. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55016. {
  55017. if (wantedY < 0)
  55018. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55019. jmax (PopupMenuSettings::scrollZone,
  55020. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55021. currentY);
  55022. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55023. int deltaY = wantedY - currentY;
  55024. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55025. jmin (windowPos.getHeight(), mon.getHeight()));
  55026. const int newY = jlimit (mon.getY(),
  55027. mon.getBottom() - windowPos.getHeight(),
  55028. windowPos.getY() + deltaY);
  55029. deltaY -= newY - windowPos.getY();
  55030. childYOffset -= deltaY;
  55031. windowPos.setPosition (windowPos.getX(), newY);
  55032. updateYPositions();
  55033. }
  55034. break;
  55035. }
  55036. }
  55037. }
  55038. void resizeToBestWindowPos()
  55039. {
  55040. Rectangle<int> r (windowPos);
  55041. if (childYOffset < 0)
  55042. {
  55043. r.setBounds (r.getX(), r.getY() - childYOffset,
  55044. r.getWidth(), r.getHeight() + childYOffset);
  55045. }
  55046. else if (childYOffset > 0)
  55047. {
  55048. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55049. if (spaceAtBottom > 0)
  55050. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55051. }
  55052. setBounds (r);
  55053. updateYPositions();
  55054. }
  55055. void alterChildYPos (const int delta)
  55056. {
  55057. if (isScrolling())
  55058. {
  55059. childYOffset += delta;
  55060. if (delta < 0)
  55061. {
  55062. childYOffset = jmax (childYOffset, 0);
  55063. }
  55064. else if (delta > 0)
  55065. {
  55066. childYOffset = jmin (childYOffset,
  55067. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55068. }
  55069. updateYPositions();
  55070. }
  55071. else
  55072. {
  55073. childYOffset = 0;
  55074. }
  55075. resizeToBestWindowPos();
  55076. repaint();
  55077. }
  55078. int updateYPositions()
  55079. {
  55080. int x = 0;
  55081. int childNum = 0;
  55082. for (int col = 0; col < numColumns; ++col)
  55083. {
  55084. const int numChildren = jmin (getNumChildComponents() - childNum,
  55085. (getNumChildComponents() + numColumns - 1) / numColumns);
  55086. const int colW = columnWidths [col];
  55087. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55088. for (int i = 0; i < numChildren; ++i)
  55089. {
  55090. Component* const c = getChildComponent (childNum + i);
  55091. c->setBounds (x, y, colW, c->getHeight());
  55092. y += c->getHeight();
  55093. }
  55094. x += colW;
  55095. childNum += numChildren;
  55096. }
  55097. return x;
  55098. }
  55099. bool isScrolling() const throw()
  55100. {
  55101. return childYOffset != 0 || needsToScroll;
  55102. }
  55103. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55104. {
  55105. if (currentChild->isValidComponent())
  55106. currentChild->setHighlighted (false);
  55107. currentChild = child;
  55108. if (currentChild != 0)
  55109. {
  55110. currentChild->setHighlighted (true);
  55111. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55112. }
  55113. }
  55114. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55115. {
  55116. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55117. activeSubMenu = 0;
  55118. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55119. {
  55120. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55121. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55122. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55123. dismissOnMouseUp,
  55124. this,
  55125. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55126. 0, maximumNumColumns,
  55127. standardItemHeight,
  55128. false, 0, menuBarComponent,
  55129. managerOfChosenCommand,
  55130. componentAttachedTo);
  55131. if (activeSubMenu != 0)
  55132. {
  55133. activeSubMenu->setVisible (true);
  55134. activeSubMenu->enterModalState (false);
  55135. activeSubMenu->toFront (false);
  55136. return true;
  55137. }
  55138. }
  55139. return false;
  55140. }
  55141. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55142. {
  55143. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55144. if (isOver)
  55145. hasBeenOver = true;
  55146. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55147. {
  55148. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55149. if (disableMouseMoves && isOver)
  55150. disableMouseMoves = false;
  55151. }
  55152. if (disableMouseMoves)
  55153. return;
  55154. bool isMovingTowardsMenu = false;
  55155. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55156. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55157. {
  55158. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55159. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55160. // extends from the last mouse pos to the submenu's rectangle..
  55161. float subX = (float) activeSubMenu->getScreenX();
  55162. if (activeSubMenu->getX() > getX())
  55163. {
  55164. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55165. }
  55166. else
  55167. {
  55168. lastMouse += Point<int> (2, 0);
  55169. subX += activeSubMenu->getWidth();
  55170. }
  55171. Path areaTowardsSubMenu;
  55172. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55173. (float) lastMouse.getY(),
  55174. subX,
  55175. (float) activeSubMenu->getScreenY(),
  55176. subX,
  55177. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55178. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55179. }
  55180. lastMouse = globalMousePos;
  55181. if (! isMovingTowardsMenu)
  55182. {
  55183. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55184. if (c == this)
  55185. c = 0;
  55186. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55187. if (mic == 0 && c != 0)
  55188. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55189. if (mic != currentChild
  55190. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55191. {
  55192. if (isOver && (c != 0) && (activeSubMenu != 0))
  55193. {
  55194. activeSubMenu->hide (0);
  55195. }
  55196. if (! isOver)
  55197. mic = 0;
  55198. setCurrentlyHighlightedChild (mic);
  55199. }
  55200. }
  55201. }
  55202. void triggerCurrentlyHighlightedItem()
  55203. {
  55204. if (currentChild->isValidComponent()
  55205. && currentChild->itemInfo.canBeTriggered()
  55206. && (currentChild->itemInfo.customComp == 0
  55207. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55208. {
  55209. dismissMenu (&currentChild->itemInfo);
  55210. }
  55211. }
  55212. void selectNextItem (const int delta)
  55213. {
  55214. disableTimerUntilMouseMoves();
  55215. PopupMenu::ItemComponent* mic = 0;
  55216. bool wasLastOne = (currentChild == 0);
  55217. const int numItems = getNumChildComponents();
  55218. for (int i = 0; i < numItems + 1; ++i)
  55219. {
  55220. int index = (delta > 0) ? i : (numItems - 1 - i);
  55221. index = (index + numItems) % numItems;
  55222. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55223. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55224. && wasLastOne)
  55225. break;
  55226. if (mic == currentChild)
  55227. wasLastOne = true;
  55228. }
  55229. setCurrentlyHighlightedChild (mic);
  55230. }
  55231. void disableTimerUntilMouseMoves()
  55232. {
  55233. disableMouseMoves = true;
  55234. if (owner != 0)
  55235. owner->disableTimerUntilMouseMoves();
  55236. }
  55237. Window (const Window&);
  55238. Window& operator= (const Window&);
  55239. };
  55240. PopupMenu::PopupMenu()
  55241. : lookAndFeel (0),
  55242. separatorPending (false)
  55243. {
  55244. }
  55245. PopupMenu::PopupMenu (const PopupMenu& other)
  55246. : lookAndFeel (other.lookAndFeel),
  55247. separatorPending (false)
  55248. {
  55249. items.ensureStorageAllocated (other.items.size());
  55250. for (int i = 0; i < other.items.size(); ++i)
  55251. items.add (new Item (*other.items.getUnchecked(i)));
  55252. }
  55253. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55254. {
  55255. if (this != &other)
  55256. {
  55257. lookAndFeel = other.lookAndFeel;
  55258. clear();
  55259. items.ensureStorageAllocated (other.items.size());
  55260. for (int i = 0; i < other.items.size(); ++i)
  55261. items.add (new Item (*other.items.getUnchecked(i)));
  55262. }
  55263. return *this;
  55264. }
  55265. PopupMenu::~PopupMenu()
  55266. {
  55267. clear();
  55268. }
  55269. void PopupMenu::clear()
  55270. {
  55271. items.clear();
  55272. separatorPending = false;
  55273. }
  55274. void PopupMenu::addSeparatorIfPending()
  55275. {
  55276. if (separatorPending)
  55277. {
  55278. separatorPending = false;
  55279. if (items.size() > 0)
  55280. items.add (new Item());
  55281. }
  55282. }
  55283. void PopupMenu::addItem (const int itemResultId,
  55284. const String& itemText,
  55285. const bool isActive,
  55286. const bool isTicked,
  55287. const Image* const iconToUse)
  55288. {
  55289. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55290. // didn't pick anything, so you shouldn't use it as the id
  55291. // for an item..
  55292. addSeparatorIfPending();
  55293. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55294. iconToUse, Colours::black, false, 0, 0, 0));
  55295. }
  55296. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55297. const int commandID,
  55298. const String& displayName)
  55299. {
  55300. jassert (commandManager != 0 && commandID != 0);
  55301. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55302. if (registeredInfo != 0)
  55303. {
  55304. ApplicationCommandInfo info (*registeredInfo);
  55305. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55306. addSeparatorIfPending();
  55307. items.add (new Item (commandID,
  55308. displayName.isNotEmpty() ? displayName
  55309. : info.shortName,
  55310. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55311. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55312. 0,
  55313. Colours::black,
  55314. false,
  55315. 0, 0,
  55316. commandManager));
  55317. }
  55318. }
  55319. void PopupMenu::addColouredItem (const int itemResultId,
  55320. const String& itemText,
  55321. const Colour& itemTextColour,
  55322. const bool isActive,
  55323. const bool isTicked,
  55324. const Image* const iconToUse)
  55325. {
  55326. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55327. // didn't pick anything, so you shouldn't use it as the id
  55328. // for an item..
  55329. addSeparatorIfPending();
  55330. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55331. iconToUse, itemTextColour, true, 0, 0, 0));
  55332. }
  55333. void PopupMenu::addCustomItem (const int itemResultId,
  55334. PopupMenuCustomComponent* const customComponent)
  55335. {
  55336. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55337. // didn't pick anything, so you shouldn't use it as the id
  55338. // for an item..
  55339. addSeparatorIfPending();
  55340. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55341. Colours::black, false, customComponent, 0, 0));
  55342. }
  55343. class NormalComponentWrapper : public PopupMenuCustomComponent
  55344. {
  55345. public:
  55346. NormalComponentWrapper (Component* const comp,
  55347. const int w, const int h,
  55348. const bool triggerMenuItemAutomaticallyWhenClicked)
  55349. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55350. width (w),
  55351. height (h)
  55352. {
  55353. addAndMakeVisible (comp);
  55354. }
  55355. ~NormalComponentWrapper() {}
  55356. void getIdealSize (int& idealWidth, int& idealHeight)
  55357. {
  55358. idealWidth = width;
  55359. idealHeight = height;
  55360. }
  55361. void resized()
  55362. {
  55363. if (getChildComponent(0) != 0)
  55364. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55365. }
  55366. juce_UseDebuggingNewOperator
  55367. private:
  55368. const int width, height;
  55369. NormalComponentWrapper (const NormalComponentWrapper&);
  55370. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55371. };
  55372. void PopupMenu::addCustomItem (const int itemResultId,
  55373. Component* customComponent,
  55374. int idealWidth, int idealHeight,
  55375. const bool triggerMenuItemAutomaticallyWhenClicked)
  55376. {
  55377. addCustomItem (itemResultId,
  55378. new NormalComponentWrapper (customComponent,
  55379. idealWidth, idealHeight,
  55380. triggerMenuItemAutomaticallyWhenClicked));
  55381. }
  55382. void PopupMenu::addSubMenu (const String& subMenuName,
  55383. const PopupMenu& subMenu,
  55384. const bool isActive,
  55385. Image* const iconToUse,
  55386. const bool isTicked)
  55387. {
  55388. addSeparatorIfPending();
  55389. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55390. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55391. }
  55392. void PopupMenu::addSeparator()
  55393. {
  55394. separatorPending = true;
  55395. }
  55396. class HeaderItemComponent : public PopupMenuCustomComponent
  55397. {
  55398. public:
  55399. HeaderItemComponent (const String& name)
  55400. : PopupMenuCustomComponent (false)
  55401. {
  55402. setName (name);
  55403. }
  55404. ~HeaderItemComponent()
  55405. {
  55406. }
  55407. void paint (Graphics& g)
  55408. {
  55409. Font f (getLookAndFeel().getPopupMenuFont());
  55410. f.setBold (true);
  55411. g.setFont (f);
  55412. g.setColour (findColour (PopupMenu::headerTextColourId));
  55413. g.drawFittedText (getName(),
  55414. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55415. Justification::bottomLeft, 1);
  55416. }
  55417. void getIdealSize (int& idealWidth,
  55418. int& idealHeight)
  55419. {
  55420. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55421. idealHeight += idealHeight / 2;
  55422. idealWidth += idealWidth / 4;
  55423. }
  55424. juce_UseDebuggingNewOperator
  55425. };
  55426. void PopupMenu::addSectionHeader (const String& title)
  55427. {
  55428. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55429. }
  55430. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55431. const int itemIdThatMustBeVisible,
  55432. const int minimumWidth,
  55433. const int maximumNumColumns,
  55434. const int standardItemHeight,
  55435. const bool alignToRectangle,
  55436. Component* menuBarComponent,
  55437. ApplicationCommandManager** managerOfChosenCommand,
  55438. Component* const componentAttachedTo)
  55439. {
  55440. Window* const pw
  55441. = Window::create (*this,
  55442. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55443. 0,
  55444. x, x + w,
  55445. y, y + h,
  55446. minimumWidth,
  55447. maximumNumColumns,
  55448. standardItemHeight,
  55449. alignToRectangle,
  55450. itemIdThatMustBeVisible,
  55451. menuBarComponent,
  55452. managerOfChosenCommand,
  55453. componentAttachedTo);
  55454. if (pw != 0)
  55455. pw->setVisible (true);
  55456. return pw;
  55457. }
  55458. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55459. const int itemIdThatMustBeVisible,
  55460. const int minimumWidth,
  55461. const int maximumNumColumns,
  55462. const int standardItemHeight,
  55463. const bool alignToRectangle,
  55464. Component* const componentAttachedTo)
  55465. {
  55466. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55467. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55468. Window::wasHiddenBecauseOfAppChange() = false;
  55469. int result = 0;
  55470. ApplicationCommandManager* managerOfChosenCommand = 0;
  55471. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55472. itemIdThatMustBeVisible,
  55473. minimumWidth,
  55474. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55475. standardItemHeight,
  55476. alignToRectangle, 0,
  55477. &managerOfChosenCommand,
  55478. componentAttachedTo));
  55479. if (popupComp != 0)
  55480. {
  55481. popupComp->enterModalState (false);
  55482. popupComp->toFront (false); // need to do this after making it modal, or it could
  55483. // be stuck behind other comps that are already modal..
  55484. result = popupComp->runModalLoop();
  55485. popupComp = 0;
  55486. if (! Window::wasHiddenBecauseOfAppChange())
  55487. {
  55488. if (prevTopLevel != 0)
  55489. prevTopLevel->toFront (true);
  55490. if (prevFocused != 0)
  55491. prevFocused->grabKeyboardFocus();
  55492. }
  55493. }
  55494. if (managerOfChosenCommand != 0 && result != 0)
  55495. {
  55496. ApplicationCommandTarget::InvocationInfo info (result);
  55497. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55498. managerOfChosenCommand->invoke (info, true);
  55499. }
  55500. return result;
  55501. }
  55502. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55503. const int minimumWidth,
  55504. const int maximumNumColumns,
  55505. const int standardItemHeight)
  55506. {
  55507. const Point<int> mousePos (Desktop::getMousePosition());
  55508. return showAt (mousePos.getX(), mousePos.getY(),
  55509. itemIdThatMustBeVisible,
  55510. minimumWidth,
  55511. maximumNumColumns,
  55512. standardItemHeight);
  55513. }
  55514. int PopupMenu::showAt (const int screenX,
  55515. const int screenY,
  55516. const int itemIdThatMustBeVisible,
  55517. const int minimumWidth,
  55518. const int maximumNumColumns,
  55519. const int standardItemHeight)
  55520. {
  55521. return showMenu (screenX, screenY, 1, 1,
  55522. itemIdThatMustBeVisible,
  55523. minimumWidth, maximumNumColumns,
  55524. standardItemHeight,
  55525. false, 0);
  55526. }
  55527. int PopupMenu::showAt (Component* componentToAttachTo,
  55528. const int itemIdThatMustBeVisible,
  55529. const int minimumWidth,
  55530. const int maximumNumColumns,
  55531. const int standardItemHeight)
  55532. {
  55533. if (componentToAttachTo != 0)
  55534. {
  55535. return showMenu (componentToAttachTo->getScreenX(),
  55536. componentToAttachTo->getScreenY(),
  55537. componentToAttachTo->getWidth(),
  55538. componentToAttachTo->getHeight(),
  55539. itemIdThatMustBeVisible,
  55540. minimumWidth,
  55541. maximumNumColumns,
  55542. standardItemHeight,
  55543. true, componentToAttachTo);
  55544. }
  55545. else
  55546. {
  55547. return show (itemIdThatMustBeVisible,
  55548. minimumWidth,
  55549. maximumNumColumns,
  55550. standardItemHeight);
  55551. }
  55552. }
  55553. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55554. {
  55555. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55556. {
  55557. Window* const pmw = Window::getActiveWindows()[i];
  55558. if (pmw != 0)
  55559. pmw->dismissMenu (0);
  55560. }
  55561. }
  55562. int PopupMenu::getNumItems() const throw()
  55563. {
  55564. int num = 0;
  55565. for (int i = items.size(); --i >= 0;)
  55566. if (! (items.getUnchecked(i))->isSeparator)
  55567. ++num;
  55568. return num;
  55569. }
  55570. bool PopupMenu::containsCommandItem (const int commandID) const
  55571. {
  55572. for (int i = items.size(); --i >= 0;)
  55573. {
  55574. const Item* mi = items.getUnchecked (i);
  55575. if ((mi->itemId == commandID && mi->commandManager != 0)
  55576. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55577. {
  55578. return true;
  55579. }
  55580. }
  55581. return false;
  55582. }
  55583. bool PopupMenu::containsAnyActiveItems() const throw()
  55584. {
  55585. for (int i = items.size(); --i >= 0;)
  55586. {
  55587. const Item* const mi = items.getUnchecked (i);
  55588. if (mi->subMenu != 0)
  55589. {
  55590. if (mi->subMenu->containsAnyActiveItems())
  55591. return true;
  55592. }
  55593. else if (mi->active)
  55594. {
  55595. return true;
  55596. }
  55597. }
  55598. return false;
  55599. }
  55600. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55601. {
  55602. lookAndFeel = newLookAndFeel;
  55603. }
  55604. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55605. : isHighlighted (false),
  55606. isTriggeredAutomatically (isTriggeredAutomatically_)
  55607. {
  55608. }
  55609. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55610. {
  55611. }
  55612. void PopupMenuCustomComponent::triggerMenuItem()
  55613. {
  55614. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55615. if (mic != 0)
  55616. {
  55617. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55618. if (pmw != 0)
  55619. {
  55620. pmw->dismissMenu (&mic->itemInfo);
  55621. }
  55622. else
  55623. {
  55624. // something must have gone wrong with the component hierarchy if this happens..
  55625. jassertfalse
  55626. }
  55627. }
  55628. else
  55629. {
  55630. // why isn't this component inside a menu? Not much point triggering the item if
  55631. // there's no menu.
  55632. jassertfalse
  55633. }
  55634. }
  55635. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55636. : subMenu (0),
  55637. itemId (0),
  55638. isSeparator (false),
  55639. isTicked (false),
  55640. isEnabled (false),
  55641. isCustomComponent (false),
  55642. isSectionHeader (false),
  55643. customColour (0),
  55644. customImage (0),
  55645. menu (menu_),
  55646. index (0)
  55647. {
  55648. }
  55649. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55650. {
  55651. }
  55652. bool PopupMenu::MenuItemIterator::next()
  55653. {
  55654. if (index >= menu.items.size())
  55655. return false;
  55656. const Item* const item = menu.items.getUnchecked (index);
  55657. ++index;
  55658. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55659. subMenu = item->subMenu;
  55660. itemId = item->itemId;
  55661. isSeparator = item->isSeparator;
  55662. isTicked = item->isTicked;
  55663. isEnabled = item->active;
  55664. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55665. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55666. customColour = item->usesColour ? &(item->textColour) : 0;
  55667. customImage = item->image;
  55668. commandManager = item->commandManager;
  55669. return true;
  55670. }
  55671. END_JUCE_NAMESPACE
  55672. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55673. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55674. BEGIN_JUCE_NAMESPACE
  55675. ComponentDragger::ComponentDragger()
  55676. : constrainer (0)
  55677. {
  55678. }
  55679. ComponentDragger::~ComponentDragger()
  55680. {
  55681. }
  55682. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55683. ComponentBoundsConstrainer* const constrainer_)
  55684. {
  55685. jassert (componentToDrag->isValidComponent());
  55686. if (componentToDrag != 0)
  55687. {
  55688. constrainer = constrainer_;
  55689. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55690. }
  55691. }
  55692. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55693. {
  55694. jassert (componentToDrag->isValidComponent());
  55695. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55696. if (componentToDrag != 0)
  55697. {
  55698. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55699. const Component* const parentComp = componentToDrag->getParentComponent();
  55700. if (parentComp != 0)
  55701. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55702. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55703. if (constrainer != 0)
  55704. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55705. else
  55706. componentToDrag->setBounds (bounds);
  55707. }
  55708. }
  55709. END_JUCE_NAMESPACE
  55710. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55711. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55712. BEGIN_JUCE_NAMESPACE
  55713. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55714. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55715. class DragImageComponent : public Component,
  55716. public Timer
  55717. {
  55718. public:
  55719. DragImageComponent (Image* const im,
  55720. const String& desc,
  55721. Component* const sourceComponent,
  55722. Component* const mouseDragSource_,
  55723. DragAndDropContainer* const o,
  55724. const Point<int>& imageOffset_)
  55725. : image (im),
  55726. source (sourceComponent),
  55727. mouseDragSource (mouseDragSource_),
  55728. owner (o),
  55729. dragDesc (desc),
  55730. imageOffset (imageOffset_),
  55731. hasCheckedForExternalDrag (false),
  55732. drawImage (true)
  55733. {
  55734. setSize (im->getWidth(), im->getHeight());
  55735. if (mouseDragSource == 0)
  55736. mouseDragSource = source;
  55737. mouseDragSource->addMouseListener (this, false);
  55738. startTimer (200);
  55739. setInterceptsMouseClicks (false, false);
  55740. setAlwaysOnTop (true);
  55741. }
  55742. ~DragImageComponent()
  55743. {
  55744. if (owner->dragImageComponent == this)
  55745. owner->dragImageComponent.release();
  55746. if (mouseDragSource != 0)
  55747. {
  55748. mouseDragSource->removeMouseListener (this);
  55749. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55750. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55751. }
  55752. }
  55753. void paint (Graphics& g)
  55754. {
  55755. if (isOpaque())
  55756. g.fillAll (Colours::white);
  55757. if (drawImage)
  55758. {
  55759. g.setOpacity (1.0f);
  55760. g.drawImageAt (image, 0, 0);
  55761. }
  55762. }
  55763. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55764. {
  55765. Component* hit = getParentComponent();
  55766. if (hit == 0)
  55767. {
  55768. hit = Desktop::getInstance().findComponentAt (screenPos);
  55769. }
  55770. else
  55771. {
  55772. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55773. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55774. }
  55775. // (note: use a local copy of the dragDesc member in case the callback runs
  55776. // a modal loop and deletes this object before the method completes)
  55777. const String dragDescLocal (dragDesc);
  55778. while (hit != 0)
  55779. {
  55780. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55781. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55782. {
  55783. relativePos = hit->globalPositionToRelative (screenPos);
  55784. return ddt;
  55785. }
  55786. hit = hit->getParentComponent();
  55787. }
  55788. return 0;
  55789. }
  55790. void mouseUp (const MouseEvent& e)
  55791. {
  55792. if (e.originalComponent != this)
  55793. {
  55794. if (mouseDragSource != 0)
  55795. mouseDragSource->removeMouseListener (this);
  55796. bool dropAccepted = false;
  55797. DragAndDropTarget* ddt = 0;
  55798. Point<int> relPos;
  55799. if (isVisible())
  55800. {
  55801. setVisible (false);
  55802. ddt = findTarget (e.getScreenPosition(), relPos);
  55803. // fade this component and remove it - it'll be deleted later by the timer callback
  55804. dropAccepted = ddt != 0;
  55805. setVisible (true);
  55806. if (dropAccepted || source == 0)
  55807. {
  55808. fadeOutComponent (120);
  55809. }
  55810. else
  55811. {
  55812. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55813. source->getHeight() / 2)));
  55814. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55815. getHeight() / 2)));
  55816. fadeOutComponent (120,
  55817. target.getX() - ourCentre.getX(),
  55818. target.getY() - ourCentre.getY());
  55819. }
  55820. }
  55821. if (getParentComponent() != 0)
  55822. getParentComponent()->removeChildComponent (this);
  55823. if (dropAccepted && ddt != 0)
  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 the method completes)
  55827. const String dragDescLocal (dragDesc);
  55828. currentlyOverComp = 0;
  55829. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55830. }
  55831. // careful - this object could now be deleted..
  55832. }
  55833. }
  55834. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55835. {
  55836. // (note: use a local copy of the dragDesc member in case the callback runs
  55837. // a modal loop and deletes this object before it returns)
  55838. const String dragDescLocal (dragDesc);
  55839. Point<int> newPos (screenPos + imageOffset);
  55840. if (getParentComponent() != 0)
  55841. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55842. //if (newX != getX() || newY != getY())
  55843. {
  55844. setTopLeftPosition (newPos.getX(), newPos.getY());
  55845. Point<int> relPos;
  55846. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55847. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55848. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55849. if (ddtComp != currentlyOverComp)
  55850. {
  55851. if (currentlyOverComp != 0 && source != 0
  55852. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55853. {
  55854. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55855. }
  55856. currentlyOverComp = ddtComp;
  55857. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55858. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55859. }
  55860. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55861. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55862. if (getCurrentlyOver() == 0
  55863. && canDoExternalDrag
  55864. && ! hasCheckedForExternalDrag)
  55865. {
  55866. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55867. {
  55868. hasCheckedForExternalDrag = true;
  55869. StringArray files;
  55870. bool canMoveFiles = false;
  55871. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55872. && files.size() > 0)
  55873. {
  55874. Component::SafePointer<Component> cdw (this);
  55875. setVisible (false);
  55876. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55877. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  55878. if (cdw != 0)
  55879. delete this;
  55880. return;
  55881. }
  55882. }
  55883. }
  55884. }
  55885. }
  55886. void mouseDrag (const MouseEvent& e)
  55887. {
  55888. if (e.originalComponent != this)
  55889. updateLocation (true, e.getScreenPosition());
  55890. }
  55891. void timerCallback()
  55892. {
  55893. if (source == 0)
  55894. {
  55895. delete this;
  55896. }
  55897. else if (! isMouseButtonDownAnywhere())
  55898. {
  55899. if (mouseDragSource != 0)
  55900. mouseDragSource->removeMouseListener (this);
  55901. delete this;
  55902. }
  55903. }
  55904. private:
  55905. ScopedPointer<Image> image;
  55906. Component::SafePointer<Component> source;
  55907. Component::SafePointer<Component> mouseDragSource;
  55908. DragAndDropContainer* const owner;
  55909. Component::SafePointer<Component> currentlyOverComp;
  55910. DragAndDropTarget* getCurrentlyOver()
  55911. {
  55912. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  55913. }
  55914. String dragDesc;
  55915. const Point<int> imageOffset;
  55916. bool hasCheckedForExternalDrag, drawImage;
  55917. DragImageComponent (const DragImageComponent&);
  55918. DragImageComponent& operator= (const DragImageComponent&);
  55919. };
  55920. DragAndDropContainer::DragAndDropContainer()
  55921. {
  55922. }
  55923. DragAndDropContainer::~DragAndDropContainer()
  55924. {
  55925. dragImageComponent = 0;
  55926. }
  55927. void DragAndDropContainer::startDragging (const String& sourceDescription,
  55928. Component* sourceComponent,
  55929. Image* dragImage_,
  55930. const bool allowDraggingToExternalWindows,
  55931. const Point<int>* imageOffsetFromMouse)
  55932. {
  55933. ScopedPointer <Image> dragImage (dragImage_);
  55934. if (dragImageComponent == 0)
  55935. {
  55936. Component* const thisComp = dynamic_cast <Component*> (this);
  55937. if (thisComp == 0)
  55938. {
  55939. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  55940. return;
  55941. }
  55942. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  55943. if (draggingSource == 0 || ! draggingSource->isDragging())
  55944. {
  55945. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  55946. return;
  55947. }
  55948. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  55949. Point<int> imageOffset;
  55950. if (dragImage == 0)
  55951. {
  55952. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  55953. if (dragImage->getFormat() != Image::ARGB)
  55954. {
  55955. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  55956. Graphics g2 (*newIm);
  55957. g2.drawImageAt (dragImage, 0, 0);
  55958. dragImage = newIm;
  55959. }
  55960. dragImage->multiplyAllAlphas (0.6f);
  55961. const int lo = 150;
  55962. const int hi = 400;
  55963. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  55964. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  55965. .getConstrainedPoint (relPos));
  55966. for (int y = dragImage->getHeight(); --y >= 0;)
  55967. {
  55968. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  55969. for (int x = dragImage->getWidth(); --x >= 0;)
  55970. {
  55971. const int dx = x - clipped.getX();
  55972. const int distance = roundToInt (sqrt (dx * dx + dy));
  55973. if (distance > lo)
  55974. {
  55975. const float alpha = (distance > hi) ? 0
  55976. : (hi - distance) / (float) (hi - lo)
  55977. + Random::getSystemRandom().nextFloat() * 0.008f;
  55978. dragImage->multiplyAlphaAt (x, y, alpha);
  55979. }
  55980. }
  55981. }
  55982. imageOffset = -clipped;
  55983. }
  55984. else
  55985. {
  55986. if (imageOffsetFromMouse == 0)
  55987. imageOffset = Point<int> (dragImage->getWidth() / -2,
  55988. dragImage->getHeight() / -2);
  55989. else
  55990. imageOffset = *imageOffsetFromMouse;
  55991. }
  55992. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  55993. draggingSource->getComponentUnderMouse(), this, imageOffset);
  55994. currentDragDesc = sourceDescription;
  55995. if (allowDraggingToExternalWindows)
  55996. {
  55997. if (! Desktop::canUseSemiTransparentWindows())
  55998. dragImageComponent->setOpaque (true);
  55999. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56000. | ComponentPeer::windowIsTemporary
  56001. | ComponentPeer::windowIgnoresKeyPresses);
  56002. }
  56003. else
  56004. thisComp->addChildComponent (dragImageComponent);
  56005. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  56006. dragImageComponent->setVisible (true);
  56007. }
  56008. }
  56009. bool DragAndDropContainer::isDragAndDropActive() const
  56010. {
  56011. return dragImageComponent != 0;
  56012. }
  56013. const String DragAndDropContainer::getCurrentDragDescription() const
  56014. {
  56015. return (dragImageComponent != 0) ? currentDragDesc
  56016. : String::empty;
  56017. }
  56018. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56019. {
  56020. if (c == 0)
  56021. return 0;
  56022. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56023. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56024. }
  56025. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56026. {
  56027. return false;
  56028. }
  56029. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56030. {
  56031. }
  56032. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56033. {
  56034. }
  56035. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56036. {
  56037. }
  56038. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56039. {
  56040. return true;
  56041. }
  56042. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56043. {
  56044. }
  56045. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56046. {
  56047. }
  56048. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56049. {
  56050. }
  56051. END_JUCE_NAMESPACE
  56052. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56053. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56054. BEGIN_JUCE_NAMESPACE
  56055. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56056. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56057. // isStandard set depending on which interface was used to create the cursor
  56058. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56059. static CriticalSection activeCursorListLock;
  56060. static VoidArray activeCursors;
  56061. class SharedMouseCursorInternal : public ReferenceCountedObject
  56062. {
  56063. public:
  56064. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56065. : standardType (type),
  56066. isStandard (true)
  56067. {
  56068. handle = juce_createStandardMouseCursor (standardType);
  56069. activeCursors.add (this);
  56070. }
  56071. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56072. : standardType (MouseCursor::NormalCursor),
  56073. isStandard (false)
  56074. {
  56075. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56076. }
  56077. ~SharedMouseCursorInternal() throw()
  56078. {
  56079. juce_deleteMouseCursor (handle, isStandard);
  56080. activeCursors.removeValue (this);
  56081. }
  56082. void* getHandle() const throw()
  56083. {
  56084. return handle;
  56085. }
  56086. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56087. {
  56088. for (int i = activeCursors.size(); --i >= 0;)
  56089. {
  56090. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56091. if (r->standardType == type)
  56092. return r;
  56093. }
  56094. return new SharedMouseCursorInternal (type);
  56095. }
  56096. juce_UseDebuggingNewOperator
  56097. private:
  56098. void* handle;
  56099. const MouseCursor::StandardCursorType standardType;
  56100. const bool isStandard;
  56101. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56102. };
  56103. MouseCursor::MouseCursor() throw()
  56104. {
  56105. const ScopedLock sl (activeCursorListLock);
  56106. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56107. }
  56108. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56109. {
  56110. const ScopedLock sl (activeCursorListLock);
  56111. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56112. }
  56113. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56114. {
  56115. const ScopedLock sl (activeCursorListLock);
  56116. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56117. }
  56118. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56119. : cursorHandle (other.cursorHandle)
  56120. {
  56121. }
  56122. MouseCursor::~MouseCursor() throw()
  56123. {
  56124. }
  56125. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56126. {
  56127. cursorHandle = other.cursorHandle;
  56128. return *this;
  56129. }
  56130. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56131. {
  56132. return cursorHandle == other.cursorHandle;
  56133. }
  56134. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56135. {
  56136. return cursorHandle != other.cursorHandle;
  56137. }
  56138. void* MouseCursor::getHandle() const throw()
  56139. {
  56140. return cursorHandle->getHandle();
  56141. }
  56142. void MouseCursor::showWaitCursor() throw()
  56143. {
  56144. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56145. }
  56146. void MouseCursor::hideWaitCursor() throw()
  56147. {
  56148. Desktop::getInstance().getMainMouseSource().revealCursor();
  56149. }
  56150. END_JUCE_NAMESPACE
  56151. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56152. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56153. BEGIN_JUCE_NAMESPACE
  56154. MouseEvent::MouseEvent (MouseInputSource& source_,
  56155. const Point<int>& position,
  56156. const ModifierKeys& mods_,
  56157. Component* const originator,
  56158. const Time& eventTime_,
  56159. const Point<int> mouseDownPos_,
  56160. const Time& mouseDownTime_,
  56161. const int numberOfClicks_,
  56162. const bool mouseWasDragged) throw()
  56163. : x (position.getX()),
  56164. y (position.getY()),
  56165. mods (mods_),
  56166. eventComponent (originator),
  56167. originalComponent (originator),
  56168. eventTime (eventTime_),
  56169. source (source_),
  56170. mouseDownPos (mouseDownPos_),
  56171. mouseDownTime (mouseDownTime_),
  56172. numberOfClicks (numberOfClicks_),
  56173. wasMovedSinceMouseDown (mouseWasDragged)
  56174. {
  56175. }
  56176. MouseEvent::~MouseEvent() throw()
  56177. {
  56178. }
  56179. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56180. {
  56181. if (otherComponent == 0)
  56182. {
  56183. jassertfalse
  56184. return *this;
  56185. }
  56186. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56187. mods, originalComponent, eventTime,
  56188. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56189. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56190. }
  56191. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56192. {
  56193. return MouseEvent (source, newPosition, mods, originalComponent,
  56194. eventTime, mouseDownPos, mouseDownTime,
  56195. numberOfClicks, wasMovedSinceMouseDown);
  56196. }
  56197. bool MouseEvent::mouseWasClicked() const throw()
  56198. {
  56199. return ! wasMovedSinceMouseDown;
  56200. }
  56201. int MouseEvent::getMouseDownX() const throw()
  56202. {
  56203. return mouseDownPos.getX();
  56204. }
  56205. int MouseEvent::getMouseDownY() const throw()
  56206. {
  56207. return mouseDownPos.getY();
  56208. }
  56209. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56210. {
  56211. return mouseDownPos;
  56212. }
  56213. int MouseEvent::getDistanceFromDragStartX() const throw()
  56214. {
  56215. return x - mouseDownPos.getX();
  56216. }
  56217. int MouseEvent::getDistanceFromDragStartY() const throw()
  56218. {
  56219. return y - mouseDownPos.getY();
  56220. }
  56221. int MouseEvent::getDistanceFromDragStart() const throw()
  56222. {
  56223. return mouseDownPos.getDistanceFrom (getPosition());
  56224. }
  56225. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56226. {
  56227. return getPosition() - mouseDownPos;
  56228. }
  56229. int MouseEvent::getLengthOfMousePress() const throw()
  56230. {
  56231. if (mouseDownTime.toMilliseconds() > 0)
  56232. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56233. return 0;
  56234. }
  56235. const Point<int> MouseEvent::getPosition() const throw()
  56236. {
  56237. return Point<int> (x, y);
  56238. }
  56239. int MouseEvent::getScreenX() const
  56240. {
  56241. return getScreenPosition().getX();
  56242. }
  56243. int MouseEvent::getScreenY() const
  56244. {
  56245. return getScreenPosition().getY();
  56246. }
  56247. const Point<int> MouseEvent::getScreenPosition() const
  56248. {
  56249. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56250. }
  56251. int MouseEvent::getMouseDownScreenX() const
  56252. {
  56253. return getMouseDownScreenPosition().getX();
  56254. }
  56255. int MouseEvent::getMouseDownScreenY() const
  56256. {
  56257. return getMouseDownScreenPosition().getY();
  56258. }
  56259. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56260. {
  56261. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56262. }
  56263. static int doubleClickTimeOutMs = 400;
  56264. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56265. {
  56266. doubleClickTimeOutMs = newTime;
  56267. }
  56268. int MouseEvent::getDoubleClickTimeout() throw()
  56269. {
  56270. return doubleClickTimeOutMs;
  56271. }
  56272. END_JUCE_NAMESPACE
  56273. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56274. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56275. BEGIN_JUCE_NAMESPACE
  56276. class MouseInputSourceInternal : public AsyncUpdater
  56277. {
  56278. public:
  56279. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56280. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56281. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56282. {
  56283. zerostruct (mouseDowns);
  56284. }
  56285. ~MouseInputSourceInternal()
  56286. {
  56287. }
  56288. bool isDragging() const throw()
  56289. {
  56290. return buttonState.isAnyMouseButtonDown();
  56291. }
  56292. Component* getComponentUnderMouse() const
  56293. {
  56294. return static_cast <Component*> (componentUnderMouse);
  56295. }
  56296. const ModifierKeys getCurrentModifiers() const
  56297. {
  56298. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56299. }
  56300. ComponentPeer* getPeer()
  56301. {
  56302. if (! ComponentPeer::isValidPeer (lastPeer))
  56303. lastPeer = 0;
  56304. return lastPeer;
  56305. }
  56306. Component* findComponentAt (const Point<int>& screenPos)
  56307. {
  56308. ComponentPeer* const peer = getPeer();
  56309. if (peer != 0)
  56310. {
  56311. Component* const comp = peer->getComponent();
  56312. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56313. // (the contains() call is needed to test for overlapping desktop windows)
  56314. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56315. return comp->getComponentAt (relativePos);
  56316. }
  56317. return 0;
  56318. }
  56319. const Point<int> getScreenPosition() const throw()
  56320. {
  56321. return lastScreenPos + unboundedMouseOffset;
  56322. }
  56323. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56324. {
  56325. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56326. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56327. }
  56328. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56329. {
  56330. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56331. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56332. }
  56333. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56334. {
  56335. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56336. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56337. }
  56338. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56339. {
  56340. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56341. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56342. }
  56343. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56344. {
  56345. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56346. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56347. }
  56348. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56349. {
  56350. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56351. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56352. }
  56353. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56354. {
  56355. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56356. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56357. }
  56358. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56359. {
  56360. if (buttonState != newButtonState)
  56361. {
  56362. // (ignore secondary clicks when there's already a button down)
  56363. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56364. {
  56365. buttonState = newButtonState;
  56366. return;
  56367. }
  56368. if (buttonState.isAnyMouseButtonDown())
  56369. {
  56370. Component* const current = getComponentUnderMouse();
  56371. if (current != 0)
  56372. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56373. enableUnboundedMouseMovement (false, false);
  56374. }
  56375. buttonState = newButtonState;
  56376. if (buttonState.isAnyMouseButtonDown())
  56377. {
  56378. Desktop::getInstance().incrementMouseClickCounter();
  56379. Component* const current = getComponentUnderMouse();
  56380. if (current != 0)
  56381. {
  56382. registerMouseDown (screenPos, time, current);
  56383. sendMouseDown (current, screenPos, time);
  56384. }
  56385. }
  56386. }
  56387. }
  56388. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56389. {
  56390. Component* current = getComponentUnderMouse();
  56391. if (newComponent != current)
  56392. {
  56393. Component::SafePointer<Component> safeNewComp (newComponent);
  56394. const ModifierKeys originalButtonState (buttonState);
  56395. if (current != 0)
  56396. {
  56397. setButtons (screenPos, time, ModifierKeys());
  56398. sendMouseExit (current, screenPos, time);
  56399. buttonState = originalButtonState;
  56400. }
  56401. componentUnderMouse = safeNewComp;
  56402. current = getComponentUnderMouse();
  56403. if (current != 0)
  56404. sendMouseEnter (current, screenPos, time);
  56405. revealCursor (false);
  56406. setButtons (screenPos, time, originalButtonState);
  56407. }
  56408. }
  56409. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56410. {
  56411. ModifierKeys::updateCurrentModifiers();
  56412. if (newPeer != lastPeer)
  56413. {
  56414. setComponentUnderMouse (0, screenPos, time);
  56415. lastPeer = newPeer;
  56416. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56417. }
  56418. }
  56419. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56420. {
  56421. if (! isDragging())
  56422. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56423. if (newScreenPos != lastScreenPos || forceUpdate)
  56424. {
  56425. cancelPendingUpdate();
  56426. lastScreenPos = newScreenPos;
  56427. Component* const current = getComponentUnderMouse();
  56428. if (current != 0)
  56429. {
  56430. if (isDragging())
  56431. {
  56432. registerMouseDrag (newScreenPos);
  56433. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56434. if (isUnboundedMouseModeOn)
  56435. handleUnboundedDrag (current);
  56436. }
  56437. else
  56438. {
  56439. sendMouseMove (current, newScreenPos, time);
  56440. }
  56441. }
  56442. revealCursor (false);
  56443. }
  56444. }
  56445. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56446. {
  56447. jassert (newPeer != 0);
  56448. lastTime = time;
  56449. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56450. if (isDragging() && newMods.isAnyMouseButtonDown())
  56451. {
  56452. setScreenPos (screenPos, time, false);
  56453. }
  56454. else
  56455. {
  56456. setPeer (newPeer, screenPos, time);
  56457. ComponentPeer* peer = getPeer();
  56458. if (peer != 0)
  56459. {
  56460. setButtons (screenPos, time, newMods);
  56461. peer = getPeer();
  56462. if (peer != 0)
  56463. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56464. }
  56465. }
  56466. }
  56467. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56468. {
  56469. jassert (peer != 0);
  56470. lastTime = time;
  56471. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56472. setPeer (peer, screenPos, time);
  56473. setScreenPos (screenPos, time, false);
  56474. triggerFakeMove();
  56475. if (! isDragging())
  56476. {
  56477. Component* current = getComponentUnderMouse();
  56478. if (current != 0)
  56479. sendMouseWheel (current, screenPos, time, x, y);
  56480. }
  56481. }
  56482. const Time getLastMouseDownTime() const throw()
  56483. {
  56484. return Time (mouseDowns[0].time);
  56485. }
  56486. const Point<int> getLastMouseDownPosition() const throw()
  56487. {
  56488. return mouseDowns[0].position;
  56489. }
  56490. int getNumberOfMultipleClicks() const throw()
  56491. {
  56492. int numClicks = 0;
  56493. if (mouseDowns[0].time != 0)
  56494. {
  56495. if (! mouseMovedSignificantlySincePressed)
  56496. ++numClicks;
  56497. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56498. {
  56499. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56500. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56501. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56502. && mouseDowns[0].component == mouseDowns[i].component)
  56503. {
  56504. ++numClicks;
  56505. }
  56506. else
  56507. {
  56508. break;
  56509. }
  56510. }
  56511. }
  56512. return numClicks;
  56513. }
  56514. bool hasMouseMovedSignificantlySincePressed() const throw()
  56515. {
  56516. return mouseMovedSignificantlySincePressed
  56517. || lastTime > mouseDowns[0].time + 300;
  56518. }
  56519. void triggerFakeMove()
  56520. {
  56521. triggerAsyncUpdate();
  56522. }
  56523. void handleAsyncUpdate()
  56524. {
  56525. if (! isDragging())
  56526. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56527. }
  56528. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56529. {
  56530. enable = enable && isDragging();
  56531. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56532. if (enable != isUnboundedMouseModeOn)
  56533. {
  56534. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56535. {
  56536. // when released, return the mouse to within the component's bounds
  56537. Component* current = getComponentUnderMouse();
  56538. if (current != 0)
  56539. Desktop::setMousePosition (current->getScreenBounds()
  56540. .getConstrainedPoint (current->getMouseXYRelative()));
  56541. }
  56542. isUnboundedMouseModeOn = enable;
  56543. unboundedMouseOffset = Point<int>();
  56544. revealCursor (true);
  56545. }
  56546. }
  56547. void handleUnboundedDrag (Component* current)
  56548. {
  56549. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56550. if (! screenArea.contains (lastScreenPos))
  56551. {
  56552. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  56553. unboundedMouseOffset += (lastScreenPos - componentCentre);
  56554. Desktop::setMousePosition (componentCentre);
  56555. }
  56556. else if (isCursorVisibleUntilOffscreen
  56557. && (! unboundedMouseOffset.isOrigin())
  56558. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56559. {
  56560. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56561. unboundedMouseOffset = Point<int>();
  56562. }
  56563. }
  56564. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56565. {
  56566. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56567. {
  56568. cursor = MouseCursor::NoCursor;
  56569. forcedUpdate = true;
  56570. }
  56571. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56572. {
  56573. currentCursorHandle = cursor.getHandle();
  56574. cursor.showInWindow (getPeer());
  56575. }
  56576. }
  56577. void hideCursor()
  56578. {
  56579. showMouseCursor (MouseCursor::NoCursor, true);
  56580. }
  56581. void revealCursor (bool forcedUpdate)
  56582. {
  56583. MouseCursor mc (MouseCursor::NormalCursor);
  56584. Component* current = getComponentUnderMouse();
  56585. if (current != 0)
  56586. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56587. showMouseCursor (mc, forcedUpdate);
  56588. }
  56589. int index;
  56590. bool isMouseDevice;
  56591. Point<int> lastScreenPos;
  56592. ModifierKeys buttonState;
  56593. private:
  56594. MouseInputSource& source;
  56595. Component::SafePointer<Component> componentUnderMouse;
  56596. ComponentPeer* lastPeer;
  56597. Point<int> unboundedMouseOffset;
  56598. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56599. void* currentCursorHandle;
  56600. struct RecentMouseDown
  56601. {
  56602. Point<int> position;
  56603. int64 time;
  56604. Component* component;
  56605. };
  56606. RecentMouseDown mouseDowns[4];
  56607. bool mouseMovedSignificantlySincePressed;
  56608. int64 lastTime;
  56609. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56610. {
  56611. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56612. mouseDowns[i] = mouseDowns[i - 1];
  56613. mouseDowns[0].position = screenPos;
  56614. mouseDowns[0].time = time;
  56615. mouseDowns[0].component = component;
  56616. mouseMovedSignificantlySincePressed = false;
  56617. }
  56618. void registerMouseDrag (const Point<int>& screenPos) throw()
  56619. {
  56620. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56621. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56622. }
  56623. };
  56624. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56625. {
  56626. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56627. }
  56628. MouseInputSource::~MouseInputSource()
  56629. {
  56630. }
  56631. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56632. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56633. bool MouseInputSource::canHover() const { return isMouse(); }
  56634. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56635. int MouseInputSource::getIndex() const { return pimpl->index; }
  56636. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56637. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56638. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56639. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56640. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56641. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56642. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56643. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56644. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56645. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56646. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56647. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56648. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56649. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56650. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56651. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56652. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56653. {
  56654. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56655. }
  56656. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56657. {
  56658. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56659. }
  56660. END_JUCE_NAMESPACE
  56661. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56662. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56663. BEGIN_JUCE_NAMESPACE
  56664. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56665. : source (0),
  56666. hoverTimeMillisecs (hoverTimeMillisecs_),
  56667. hasJustHovered (false)
  56668. {
  56669. internalTimer.owner = this;
  56670. }
  56671. MouseHoverDetector::~MouseHoverDetector()
  56672. {
  56673. setHoverComponent (0);
  56674. }
  56675. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56676. {
  56677. hoverTimeMillisecs = newTimeInMillisecs;
  56678. }
  56679. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56680. {
  56681. if (source != newSourceComponent)
  56682. {
  56683. internalTimer.stopTimer();
  56684. hasJustHovered = false;
  56685. if (source != 0)
  56686. {
  56687. // ! you need to delete the hover detector before deleting its component
  56688. jassert (source->isValidComponent());
  56689. source->removeMouseListener (&internalTimer);
  56690. }
  56691. source = newSourceComponent;
  56692. if (newSourceComponent != 0)
  56693. newSourceComponent->addMouseListener (&internalTimer, false);
  56694. }
  56695. }
  56696. void MouseHoverDetector::hoverTimerCallback()
  56697. {
  56698. internalTimer.stopTimer();
  56699. if (source != 0)
  56700. {
  56701. const Point<int> pos (source->getMouseXYRelative());
  56702. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56703. {
  56704. hasJustHovered = true;
  56705. mouseHovered (pos.getX(), pos.getY());
  56706. }
  56707. }
  56708. }
  56709. void MouseHoverDetector::checkJustHoveredCallback()
  56710. {
  56711. if (hasJustHovered)
  56712. {
  56713. hasJustHovered = false;
  56714. mouseMovedAfterHover();
  56715. }
  56716. }
  56717. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56718. {
  56719. owner->hoverTimerCallback();
  56720. }
  56721. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56722. {
  56723. stopTimer();
  56724. owner->checkJustHoveredCallback();
  56725. }
  56726. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56727. {
  56728. stopTimer();
  56729. owner->checkJustHoveredCallback();
  56730. }
  56731. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56732. {
  56733. stopTimer();
  56734. owner->checkJustHoveredCallback();
  56735. }
  56736. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56737. {
  56738. stopTimer();
  56739. owner->checkJustHoveredCallback();
  56740. }
  56741. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56742. {
  56743. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56744. {
  56745. lastX = e.x;
  56746. lastY = e.y;
  56747. if (owner->source != 0)
  56748. startTimer (owner->hoverTimeMillisecs);
  56749. owner->checkJustHoveredCallback();
  56750. }
  56751. }
  56752. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56753. {
  56754. stopTimer();
  56755. owner->checkJustHoveredCallback();
  56756. }
  56757. END_JUCE_NAMESPACE
  56758. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56759. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56760. BEGIN_JUCE_NAMESPACE
  56761. void MouseListener::mouseEnter (const MouseEvent&)
  56762. {
  56763. }
  56764. void MouseListener::mouseExit (const MouseEvent&)
  56765. {
  56766. }
  56767. void MouseListener::mouseDown (const MouseEvent&)
  56768. {
  56769. }
  56770. void MouseListener::mouseUp (const MouseEvent&)
  56771. {
  56772. }
  56773. void MouseListener::mouseDrag (const MouseEvent&)
  56774. {
  56775. }
  56776. void MouseListener::mouseMove (const MouseEvent&)
  56777. {
  56778. }
  56779. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56780. {
  56781. }
  56782. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56783. {
  56784. }
  56785. END_JUCE_NAMESPACE
  56786. /*** End of inlined file: juce_MouseListener.cpp ***/
  56787. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56788. BEGIN_JUCE_NAMESPACE
  56789. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56790. const String& buttonTextWhenTrue,
  56791. const String& buttonTextWhenFalse)
  56792. : PropertyComponent (name),
  56793. onText (buttonTextWhenTrue),
  56794. offText (buttonTextWhenFalse)
  56795. {
  56796. createButton();
  56797. button->addButtonListener (this);
  56798. }
  56799. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56800. const String& name,
  56801. const String& buttonText)
  56802. : PropertyComponent (name),
  56803. onText (buttonText),
  56804. offText (buttonText)
  56805. {
  56806. createButton();
  56807. button->setButtonText (buttonText);
  56808. button->getToggleStateValue().referTo (valueToControl);
  56809. button->setClickingTogglesState (true);
  56810. }
  56811. BooleanPropertyComponent::~BooleanPropertyComponent()
  56812. {
  56813. deleteAllChildren();
  56814. }
  56815. void BooleanPropertyComponent::createButton()
  56816. {
  56817. addAndMakeVisible (button = new ToggleButton (String::empty));
  56818. button->setClickingTogglesState (false);
  56819. }
  56820. void BooleanPropertyComponent::setState (const bool newState)
  56821. {
  56822. button->setToggleState (newState, true);
  56823. }
  56824. bool BooleanPropertyComponent::getState() const
  56825. {
  56826. return button->getToggleState();
  56827. }
  56828. void BooleanPropertyComponent::paint (Graphics& g)
  56829. {
  56830. PropertyComponent::paint (g);
  56831. const Rectangle<int> r (button->getBounds());
  56832. g.setColour (Colours::white);
  56833. g.fillRect (r);
  56834. g.setColour (findColour (ComboBox::outlineColourId));
  56835. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56836. }
  56837. void BooleanPropertyComponent::refresh()
  56838. {
  56839. button->setToggleState (getState(), false);
  56840. button->setButtonText (button->getToggleState() ? onText : offText);
  56841. }
  56842. void BooleanPropertyComponent::buttonClicked (Button*)
  56843. {
  56844. setState (! getState());
  56845. }
  56846. END_JUCE_NAMESPACE
  56847. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56848. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56849. BEGIN_JUCE_NAMESPACE
  56850. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56851. const bool triggerOnMouseDown)
  56852. : PropertyComponent (name)
  56853. {
  56854. addAndMakeVisible (button = new TextButton (String::empty));
  56855. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56856. button->addButtonListener (this);
  56857. }
  56858. ButtonPropertyComponent::~ButtonPropertyComponent()
  56859. {
  56860. deleteAllChildren();
  56861. }
  56862. void ButtonPropertyComponent::refresh()
  56863. {
  56864. button->setButtonText (getButtonText());
  56865. }
  56866. void ButtonPropertyComponent::buttonClicked (Button*)
  56867. {
  56868. buttonClicked();
  56869. }
  56870. END_JUCE_NAMESPACE
  56871. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56872. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56873. BEGIN_JUCE_NAMESPACE
  56874. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  56875. : PropertyComponent (name),
  56876. comboBox (0)
  56877. {
  56878. }
  56879. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  56880. const String& name,
  56881. const StringArray& choices_,
  56882. const Array <int>* choiceIDs)
  56883. : PropertyComponent (name),
  56884. choices (choices_),
  56885. comboBox (0)
  56886. {
  56887. createComboBox (choiceIDs);
  56888. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  56889. }
  56890. ChoicePropertyComponent::~ChoicePropertyComponent()
  56891. {
  56892. deleteAllChildren();
  56893. }
  56894. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  56895. {
  56896. // The array of IDs must contain the same number of values as the choices list!
  56897. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  56898. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  56899. for (int i = 0; i < choices.size(); ++i)
  56900. {
  56901. if (choices[i].isNotEmpty())
  56902. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  56903. : ((*choiceIDs)[i]));
  56904. else
  56905. comboBox->addSeparator();
  56906. }
  56907. comboBox->setEditableText (false);
  56908. }
  56909. void ChoicePropertyComponent::setIndex (const int newIndex)
  56910. {
  56911. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  56912. }
  56913. int ChoicePropertyComponent::getIndex() const
  56914. {
  56915. return comboBox->getSelectedItemIndex();
  56916. }
  56917. const StringArray& ChoicePropertyComponent::getChoices() const
  56918. {
  56919. return choices;
  56920. }
  56921. void ChoicePropertyComponent::refresh()
  56922. {
  56923. if (comboBox == 0)
  56924. {
  56925. createComboBox (0);
  56926. comboBox->addListener (this);
  56927. }
  56928. comboBox->setSelectedId (getIndex() + 1, true);
  56929. }
  56930. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  56931. {
  56932. const int newIndex = comboBox->getSelectedId() - 1;
  56933. if (newIndex != getIndex())
  56934. setIndex (newIndex);
  56935. }
  56936. END_JUCE_NAMESPACE
  56937. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56938. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  56939. BEGIN_JUCE_NAMESPACE
  56940. PropertyComponent::PropertyComponent (const String& name,
  56941. const int preferredHeight_)
  56942. : Component (name),
  56943. preferredHeight (preferredHeight_)
  56944. {
  56945. jassert (name.isNotEmpty());
  56946. }
  56947. PropertyComponent::~PropertyComponent()
  56948. {
  56949. }
  56950. void PropertyComponent::paint (Graphics& g)
  56951. {
  56952. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  56953. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  56954. }
  56955. void PropertyComponent::resized()
  56956. {
  56957. if (getNumChildComponents() > 0)
  56958. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  56959. }
  56960. void PropertyComponent::enablementChanged()
  56961. {
  56962. repaint();
  56963. }
  56964. END_JUCE_NAMESPACE
  56965. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  56966. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  56967. BEGIN_JUCE_NAMESPACE
  56968. class PropertyHolderComponent : public Component
  56969. {
  56970. public:
  56971. PropertyHolderComponent()
  56972. {
  56973. }
  56974. ~PropertyHolderComponent()
  56975. {
  56976. deleteAllChildren();
  56977. }
  56978. void paint (Graphics&)
  56979. {
  56980. }
  56981. void updateLayout (const int width);
  56982. void refreshAll() const;
  56983. };
  56984. class PropertySectionComponent : public Component
  56985. {
  56986. public:
  56987. PropertySectionComponent (const String& sectionTitle,
  56988. const Array <PropertyComponent*>& newProperties,
  56989. const bool open)
  56990. : Component (sectionTitle),
  56991. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  56992. isOpen_ (open)
  56993. {
  56994. for (int i = newProperties.size(); --i >= 0;)
  56995. {
  56996. addAndMakeVisible (newProperties.getUnchecked(i));
  56997. newProperties.getUnchecked(i)->refresh();
  56998. }
  56999. }
  57000. ~PropertySectionComponent()
  57001. {
  57002. deleteAllChildren();
  57003. }
  57004. void paint (Graphics& g)
  57005. {
  57006. if (titleHeight > 0)
  57007. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57008. }
  57009. void resized()
  57010. {
  57011. int y = titleHeight;
  57012. for (int i = getNumChildComponents(); --i >= 0;)
  57013. {
  57014. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57015. if (pec != 0)
  57016. {
  57017. const int prefH = pec->getPreferredHeight();
  57018. pec->setBounds (1, y, getWidth() - 2, prefH);
  57019. y += prefH;
  57020. }
  57021. }
  57022. }
  57023. int getPreferredHeight() const
  57024. {
  57025. int y = titleHeight;
  57026. if (isOpen())
  57027. {
  57028. for (int i = 0; i < getNumChildComponents(); ++i)
  57029. {
  57030. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57031. if (pec != 0)
  57032. y += pec->getPreferredHeight();
  57033. }
  57034. }
  57035. return y;
  57036. }
  57037. void setOpen (const bool open)
  57038. {
  57039. if (isOpen_ != open)
  57040. {
  57041. isOpen_ = open;
  57042. for (int i = 0; i < getNumChildComponents(); ++i)
  57043. {
  57044. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57045. if (pec != 0)
  57046. pec->setVisible (open);
  57047. }
  57048. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57049. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57050. if (pp != 0)
  57051. pp->resized();
  57052. }
  57053. }
  57054. bool isOpen() const
  57055. {
  57056. return isOpen_;
  57057. }
  57058. void refreshAll() const
  57059. {
  57060. for (int i = 0; i < getNumChildComponents(); ++i)
  57061. {
  57062. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57063. if (pec != 0)
  57064. pec->refresh();
  57065. }
  57066. }
  57067. void mouseDown (const MouseEvent&)
  57068. {
  57069. }
  57070. void mouseUp (const MouseEvent& e)
  57071. {
  57072. if (e.getMouseDownX() < titleHeight
  57073. && e.x < titleHeight
  57074. && e.y < titleHeight
  57075. && e.getNumberOfClicks() != 2)
  57076. {
  57077. setOpen (! isOpen());
  57078. }
  57079. }
  57080. void mouseDoubleClick (const MouseEvent& e)
  57081. {
  57082. if (e.y < titleHeight)
  57083. setOpen (! isOpen());
  57084. }
  57085. private:
  57086. int titleHeight;
  57087. bool isOpen_;
  57088. };
  57089. void PropertyHolderComponent::updateLayout (const int width)
  57090. {
  57091. int y = 0;
  57092. for (int i = getNumChildComponents(); --i >= 0;)
  57093. {
  57094. PropertySectionComponent* const section
  57095. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57096. if (section != 0)
  57097. {
  57098. const int prefH = section->getPreferredHeight();
  57099. section->setBounds (0, y, width, prefH);
  57100. y += prefH;
  57101. }
  57102. }
  57103. setSize (width, y);
  57104. repaint();
  57105. }
  57106. void PropertyHolderComponent::refreshAll() const
  57107. {
  57108. for (int i = getNumChildComponents(); --i >= 0;)
  57109. {
  57110. PropertySectionComponent* const section
  57111. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57112. if (section != 0)
  57113. section->refreshAll();
  57114. }
  57115. }
  57116. PropertyPanel::PropertyPanel()
  57117. {
  57118. messageWhenEmpty = TRANS("(nothing selected)");
  57119. addAndMakeVisible (viewport = new Viewport());
  57120. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57121. viewport->setFocusContainer (true);
  57122. }
  57123. PropertyPanel::~PropertyPanel()
  57124. {
  57125. clear();
  57126. deleteAllChildren();
  57127. }
  57128. void PropertyPanel::paint (Graphics& g)
  57129. {
  57130. if (propertyHolderComponent->getNumChildComponents() == 0)
  57131. {
  57132. g.setColour (Colours::black.withAlpha (0.5f));
  57133. g.setFont (14.0f);
  57134. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57135. Justification::centred, true);
  57136. }
  57137. }
  57138. void PropertyPanel::resized()
  57139. {
  57140. viewport->setBounds (0, 0, getWidth(), getHeight());
  57141. updatePropHolderLayout();
  57142. }
  57143. void PropertyPanel::clear()
  57144. {
  57145. if (propertyHolderComponent->getNumChildComponents() > 0)
  57146. {
  57147. propertyHolderComponent->deleteAllChildren();
  57148. repaint();
  57149. }
  57150. }
  57151. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57152. {
  57153. if (propertyHolderComponent->getNumChildComponents() == 0)
  57154. repaint();
  57155. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57156. newProperties,
  57157. true), 0);
  57158. updatePropHolderLayout();
  57159. }
  57160. void PropertyPanel::addSection (const String& sectionTitle,
  57161. const Array <PropertyComponent*>& newProperties,
  57162. const bool shouldBeOpen)
  57163. {
  57164. jassert (sectionTitle.isNotEmpty());
  57165. if (propertyHolderComponent->getNumChildComponents() == 0)
  57166. repaint();
  57167. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57168. newProperties,
  57169. shouldBeOpen), 0);
  57170. updatePropHolderLayout();
  57171. }
  57172. void PropertyPanel::updatePropHolderLayout() const
  57173. {
  57174. const int maxWidth = viewport->getMaximumVisibleWidth();
  57175. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57176. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57177. if (maxWidth != newMaxWidth)
  57178. {
  57179. // need to do this twice because of scrollbars changing the size, etc.
  57180. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57181. }
  57182. }
  57183. void PropertyPanel::refreshAll() const
  57184. {
  57185. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57186. }
  57187. const StringArray PropertyPanel::getSectionNames() const
  57188. {
  57189. StringArray s;
  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. s.add (section->getName());
  57195. }
  57196. return s;
  57197. }
  57198. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57199. {
  57200. int index = 0;
  57201. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57202. {
  57203. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57204. if (section != 0 && section->getName().isNotEmpty())
  57205. {
  57206. if (index == sectionIndex)
  57207. return section->isOpen();
  57208. ++index;
  57209. }
  57210. }
  57211. return false;
  57212. }
  57213. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57214. {
  57215. int index = 0;
  57216. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57217. {
  57218. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57219. if (section != 0 && section->getName().isNotEmpty())
  57220. {
  57221. if (index == sectionIndex)
  57222. {
  57223. section->setOpen (shouldBeOpen);
  57224. break;
  57225. }
  57226. ++index;
  57227. }
  57228. }
  57229. }
  57230. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57231. {
  57232. int index = 0;
  57233. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57234. {
  57235. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57236. if (section != 0 && section->getName().isNotEmpty())
  57237. {
  57238. if (index == sectionIndex)
  57239. {
  57240. section->setEnabled (shouldBeEnabled);
  57241. break;
  57242. }
  57243. ++index;
  57244. }
  57245. }
  57246. }
  57247. XmlElement* PropertyPanel::getOpennessState() const
  57248. {
  57249. XmlElement* const xml = new XmlElement ("PROPERTYPANELSTATE");
  57250. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57251. const StringArray sections (getSectionNames());
  57252. for (int i = 0; i < sections.size(); ++i)
  57253. {
  57254. if (sections[i].isNotEmpty())
  57255. {
  57256. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57257. e->setAttribute ("name", sections[i]);
  57258. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57259. }
  57260. }
  57261. return xml;
  57262. }
  57263. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57264. {
  57265. if (xml.hasTagName ("PROPERTYPANELSTATE"))
  57266. {
  57267. const StringArray sections (getSectionNames());
  57268. forEachXmlChildElementWithTagName (xml, e, "SECTION")
  57269. {
  57270. setSectionOpen (sections.indexOf (e->getStringAttribute ("name")),
  57271. e->getBoolAttribute ("open"));
  57272. }
  57273. viewport->setViewPosition (viewport->getViewPositionX(),
  57274. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57275. }
  57276. }
  57277. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57278. {
  57279. if (messageWhenEmpty != newMessage)
  57280. {
  57281. messageWhenEmpty = newMessage;
  57282. repaint();
  57283. }
  57284. }
  57285. const String& PropertyPanel::getMessageWhenEmpty() const
  57286. {
  57287. return messageWhenEmpty;
  57288. }
  57289. END_JUCE_NAMESPACE
  57290. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57291. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57292. BEGIN_JUCE_NAMESPACE
  57293. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57294. const double rangeMin,
  57295. const double rangeMax,
  57296. const double interval,
  57297. const double skewFactor)
  57298. : PropertyComponent (name)
  57299. {
  57300. addAndMakeVisible (slider = new Slider (name));
  57301. slider->setRange (rangeMin, rangeMax, interval);
  57302. slider->setSkewFactor (skewFactor);
  57303. slider->setSliderStyle (Slider::LinearBar);
  57304. slider->addListener (this);
  57305. }
  57306. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57307. const String& name,
  57308. const double rangeMin,
  57309. const double rangeMax,
  57310. const double interval,
  57311. const double skewFactor)
  57312. : PropertyComponent (name)
  57313. {
  57314. addAndMakeVisible (slider = new Slider (name));
  57315. slider->setRange (rangeMin, rangeMax, interval);
  57316. slider->setSkewFactor (skewFactor);
  57317. slider->setSliderStyle (Slider::LinearBar);
  57318. slider->getValueObject().referTo (valueToControl);
  57319. }
  57320. SliderPropertyComponent::~SliderPropertyComponent()
  57321. {
  57322. deleteAllChildren();
  57323. }
  57324. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57325. {
  57326. }
  57327. double SliderPropertyComponent::getValue() const
  57328. {
  57329. return slider->getValue();
  57330. }
  57331. void SliderPropertyComponent::refresh()
  57332. {
  57333. slider->setValue (getValue(), false);
  57334. }
  57335. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57336. {
  57337. if (getValue() != slider->getValue())
  57338. setValue (slider->getValue());
  57339. }
  57340. END_JUCE_NAMESPACE
  57341. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57342. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57343. BEGIN_JUCE_NAMESPACE
  57344. class TextPropLabel : public Label
  57345. {
  57346. TextPropertyComponent& owner;
  57347. int maxChars;
  57348. bool isMultiline;
  57349. public:
  57350. TextPropLabel (TextPropertyComponent& owner_,
  57351. const int maxChars_, const bool isMultiline_)
  57352. : Label (String::empty, String::empty),
  57353. owner (owner_),
  57354. maxChars (maxChars_),
  57355. isMultiline (isMultiline_)
  57356. {
  57357. setEditable (true, true, false);
  57358. setColour (backgroundColourId, Colours::white);
  57359. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57360. }
  57361. ~TextPropLabel()
  57362. {
  57363. }
  57364. TextEditor* createEditorComponent()
  57365. {
  57366. TextEditor* const textEditor = Label::createEditorComponent();
  57367. textEditor->setInputRestrictions (maxChars);
  57368. if (isMultiline)
  57369. {
  57370. textEditor->setMultiLine (true, true);
  57371. textEditor->setReturnKeyStartsNewLine (true);
  57372. }
  57373. return textEditor;
  57374. }
  57375. void textWasEdited()
  57376. {
  57377. owner.textWasEdited();
  57378. }
  57379. };
  57380. TextPropertyComponent::TextPropertyComponent (const String& name,
  57381. const int maxNumChars,
  57382. const bool isMultiLine)
  57383. : PropertyComponent (name)
  57384. {
  57385. createEditor (maxNumChars, isMultiLine);
  57386. }
  57387. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57388. const String& name,
  57389. const int maxNumChars,
  57390. const bool isMultiLine)
  57391. : PropertyComponent (name)
  57392. {
  57393. createEditor (maxNumChars, isMultiLine);
  57394. textEditor->getTextValue().referTo (valueToControl);
  57395. }
  57396. TextPropertyComponent::~TextPropertyComponent()
  57397. {
  57398. deleteAllChildren();
  57399. }
  57400. void TextPropertyComponent::setText (const String& newText)
  57401. {
  57402. textEditor->setText (newText, true);
  57403. }
  57404. const String TextPropertyComponent::getText() const
  57405. {
  57406. return textEditor->getText();
  57407. }
  57408. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57409. {
  57410. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57411. if (isMultiLine)
  57412. {
  57413. textEditor->setJustificationType (Justification::topLeft);
  57414. preferredHeight = 120;
  57415. }
  57416. }
  57417. void TextPropertyComponent::refresh()
  57418. {
  57419. textEditor->setText (getText(), false);
  57420. }
  57421. void TextPropertyComponent::textWasEdited()
  57422. {
  57423. const String newText (textEditor->getText());
  57424. if (getText() != newText)
  57425. setText (newText);
  57426. }
  57427. END_JUCE_NAMESPACE
  57428. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57429. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57430. BEGIN_JUCE_NAMESPACE
  57431. class SimpleDeviceManagerInputLevelMeter : public Component,
  57432. public Timer
  57433. {
  57434. public:
  57435. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57436. : manager (manager_),
  57437. level (0)
  57438. {
  57439. startTimer (50);
  57440. manager->enableInputLevelMeasurement (true);
  57441. }
  57442. ~SimpleDeviceManagerInputLevelMeter()
  57443. {
  57444. manager->enableInputLevelMeasurement (false);
  57445. }
  57446. void timerCallback()
  57447. {
  57448. const float newLevel = (float) manager->getCurrentInputLevel();
  57449. if (fabsf (level - newLevel) > 0.005f)
  57450. {
  57451. level = newLevel;
  57452. repaint();
  57453. }
  57454. }
  57455. void paint (Graphics& g)
  57456. {
  57457. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57458. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57459. }
  57460. private:
  57461. AudioDeviceManager* const manager;
  57462. float level;
  57463. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57464. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57465. };
  57466. class MidiInputSelectorComponentListBox : public ListBox,
  57467. public ListBoxModel
  57468. {
  57469. public:
  57470. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57471. const String& noItemsMessage_,
  57472. const int minNumber_,
  57473. const int maxNumber_)
  57474. : ListBox (String::empty, 0),
  57475. deviceManager (deviceManager_),
  57476. noItemsMessage (noItemsMessage_),
  57477. minNumber (minNumber_),
  57478. maxNumber (maxNumber_)
  57479. {
  57480. items = MidiInput::getDevices();
  57481. setModel (this);
  57482. setOutlineThickness (1);
  57483. }
  57484. ~MidiInputSelectorComponentListBox()
  57485. {
  57486. }
  57487. int getNumRows()
  57488. {
  57489. return items.size();
  57490. }
  57491. void paintListBoxItem (int row,
  57492. Graphics& g,
  57493. int width, int height,
  57494. bool rowIsSelected)
  57495. {
  57496. if (((unsigned int) row) < (unsigned int) items.size())
  57497. {
  57498. if (rowIsSelected)
  57499. g.fillAll (findColour (TextEditor::highlightColourId)
  57500. .withMultipliedAlpha (0.3f));
  57501. const String item (items [row]);
  57502. bool enabled = deviceManager.isMidiInputEnabled (item);
  57503. const int x = getTickX();
  57504. const float tickW = height * 0.75f;
  57505. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57506. enabled, true, true, false);
  57507. g.setFont (height * 0.6f);
  57508. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57509. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57510. }
  57511. }
  57512. void listBoxItemClicked (int row, const MouseEvent& e)
  57513. {
  57514. selectRow (row);
  57515. if (e.x < getTickX())
  57516. flipEnablement (row);
  57517. }
  57518. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57519. {
  57520. flipEnablement (row);
  57521. }
  57522. void returnKeyPressed (int row)
  57523. {
  57524. flipEnablement (row);
  57525. }
  57526. void paint (Graphics& g)
  57527. {
  57528. ListBox::paint (g);
  57529. if (items.size() == 0)
  57530. {
  57531. g.setColour (Colours::grey);
  57532. g.setFont (13.0f);
  57533. g.drawText (noItemsMessage,
  57534. 0, 0, getWidth(), getHeight() / 2,
  57535. Justification::centred, true);
  57536. }
  57537. }
  57538. int getBestHeight (const int preferredHeight)
  57539. {
  57540. const int extra = getOutlineThickness() * 2;
  57541. return jmax (getRowHeight() * 2 + extra,
  57542. jmin (getRowHeight() * getNumRows() + extra,
  57543. preferredHeight));
  57544. }
  57545. juce_UseDebuggingNewOperator
  57546. private:
  57547. AudioDeviceManager& deviceManager;
  57548. const String noItemsMessage;
  57549. StringArray items;
  57550. int minNumber, maxNumber;
  57551. void flipEnablement (const int row)
  57552. {
  57553. if (((unsigned int) row) < (unsigned int) items.size())
  57554. {
  57555. const String item (items [row]);
  57556. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57557. }
  57558. }
  57559. int getTickX() const
  57560. {
  57561. return getRowHeight() + 5;
  57562. }
  57563. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57564. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57565. };
  57566. class AudioDeviceSettingsPanel : public Component,
  57567. public ComboBoxListener,
  57568. public ChangeListener,
  57569. public ButtonListener
  57570. {
  57571. public:
  57572. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57573. AudioIODeviceType::DeviceSetupDetails& setup_,
  57574. const bool hideAdvancedOptionsWithButton)
  57575. : type (type_),
  57576. setup (setup_)
  57577. {
  57578. sampleRateDropDown = 0;
  57579. sampleRateLabel = 0;
  57580. bufferSizeDropDown = 0;
  57581. bufferSizeLabel = 0;
  57582. outputDeviceDropDown = 0;
  57583. outputDeviceLabel = 0;
  57584. inputDeviceDropDown = 0;
  57585. inputDeviceLabel = 0;
  57586. testButton = 0;
  57587. inputLevelMeter = 0;
  57588. showUIButton = 0;
  57589. inputChanList = 0;
  57590. outputChanList = 0;
  57591. inputChanLabel = 0;
  57592. outputChanLabel = 0;
  57593. showAdvancedSettingsButton = 0;
  57594. if (hideAdvancedOptionsWithButton)
  57595. {
  57596. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57597. showAdvancedSettingsButton->addButtonListener (this);
  57598. }
  57599. type->scanForDevices();
  57600. setup.manager->addChangeListener (this);
  57601. changeListenerCallback (0);
  57602. }
  57603. ~AudioDeviceSettingsPanel()
  57604. {
  57605. setup.manager->removeChangeListener (this);
  57606. deleteAndZero (outputDeviceLabel);
  57607. deleteAndZero (inputDeviceLabel);
  57608. deleteAndZero (sampleRateLabel);
  57609. deleteAndZero (bufferSizeLabel);
  57610. deleteAndZero (showUIButton);
  57611. deleteAndZero (inputChanLabel);
  57612. deleteAndZero (outputChanLabel);
  57613. deleteAndZero (showAdvancedSettingsButton);
  57614. deleteAllChildren();
  57615. }
  57616. void resized()
  57617. {
  57618. const int lx = proportionOfWidth (0.35f);
  57619. const int w = proportionOfWidth (0.4f);
  57620. const int h = 24;
  57621. const int space = 6;
  57622. const int dh = h + space;
  57623. int y = 0;
  57624. if (outputDeviceDropDown != 0)
  57625. {
  57626. outputDeviceDropDown->setBounds (lx, y, w, h);
  57627. if (testButton != 0)
  57628. testButton->setBounds (proportionOfWidth (0.77f),
  57629. outputDeviceDropDown->getY(),
  57630. proportionOfWidth (0.18f),
  57631. h);
  57632. y += dh;
  57633. }
  57634. if (inputDeviceDropDown != 0)
  57635. {
  57636. inputDeviceDropDown->setBounds (lx, y, w, h);
  57637. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57638. inputDeviceDropDown->getY(),
  57639. proportionOfWidth (0.18f),
  57640. h);
  57641. y += dh;
  57642. }
  57643. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57644. if (outputChanList != 0)
  57645. {
  57646. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57647. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57648. y += bh + space;
  57649. }
  57650. if (inputChanList != 0)
  57651. {
  57652. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57653. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57654. y += bh + space;
  57655. }
  57656. y += space * 2;
  57657. if (showAdvancedSettingsButton != 0)
  57658. {
  57659. showAdvancedSettingsButton->changeWidthToFitText (h);
  57660. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57661. }
  57662. if (sampleRateDropDown != 0)
  57663. {
  57664. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57665. || ! showAdvancedSettingsButton->isVisible());
  57666. sampleRateDropDown->setBounds (lx, y, w, h);
  57667. y += dh;
  57668. }
  57669. if (bufferSizeDropDown != 0)
  57670. {
  57671. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57672. || ! showAdvancedSettingsButton->isVisible());
  57673. bufferSizeDropDown->setBounds (lx, y, w, h);
  57674. y += dh;
  57675. }
  57676. if (showUIButton != 0)
  57677. {
  57678. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57679. || ! showAdvancedSettingsButton->isVisible());
  57680. showUIButton->changeWidthToFitText (h);
  57681. showUIButton->setTopLeftPosition (lx, y);
  57682. }
  57683. }
  57684. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57685. {
  57686. if (comboBoxThatHasChanged == 0)
  57687. return;
  57688. AudioDeviceManager::AudioDeviceSetup config;
  57689. setup.manager->getAudioDeviceSetup (config);
  57690. String error;
  57691. if (comboBoxThatHasChanged == outputDeviceDropDown
  57692. || comboBoxThatHasChanged == inputDeviceDropDown)
  57693. {
  57694. if (outputDeviceDropDown != 0)
  57695. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57696. : outputDeviceDropDown->getText();
  57697. if (inputDeviceDropDown != 0)
  57698. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57699. : inputDeviceDropDown->getText();
  57700. if (! type->hasSeparateInputsAndOutputs())
  57701. config.inputDeviceName = config.outputDeviceName;
  57702. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57703. config.useDefaultInputChannels = true;
  57704. else
  57705. config.useDefaultOutputChannels = true;
  57706. error = setup.manager->setAudioDeviceSetup (config, true);
  57707. showCorrectDeviceName (inputDeviceDropDown, true);
  57708. showCorrectDeviceName (outputDeviceDropDown, false);
  57709. updateControlPanelButton();
  57710. resized();
  57711. }
  57712. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57713. {
  57714. if (sampleRateDropDown->getSelectedId() > 0)
  57715. {
  57716. config.sampleRate = sampleRateDropDown->getSelectedId();
  57717. error = setup.manager->setAudioDeviceSetup (config, true);
  57718. }
  57719. }
  57720. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57721. {
  57722. if (bufferSizeDropDown->getSelectedId() > 0)
  57723. {
  57724. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57725. error = setup.manager->setAudioDeviceSetup (config, true);
  57726. }
  57727. }
  57728. if (error.isNotEmpty())
  57729. {
  57730. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57731. "Error when trying to open audio device!",
  57732. error);
  57733. }
  57734. }
  57735. void buttonClicked (Button* button)
  57736. {
  57737. if (button == showAdvancedSettingsButton)
  57738. {
  57739. showAdvancedSettingsButton->setVisible (false);
  57740. resized();
  57741. }
  57742. else if (button == showUIButton)
  57743. {
  57744. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57745. if (device != 0 && device->showControlPanel())
  57746. {
  57747. setup.manager->closeAudioDevice();
  57748. setup.manager->restartLastAudioDevice();
  57749. getTopLevelComponent()->toFront (true);
  57750. }
  57751. }
  57752. else if (button == testButton && testButton != 0)
  57753. {
  57754. setup.manager->playTestSound();
  57755. }
  57756. }
  57757. void updateControlPanelButton()
  57758. {
  57759. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57760. deleteAndZero (showUIButton);
  57761. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57762. {
  57763. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57764. TRANS ("opens the device's own control panel")));
  57765. showUIButton->addButtonListener (this);
  57766. }
  57767. resized();
  57768. }
  57769. void changeListenerCallback (void*)
  57770. {
  57771. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57772. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57773. {
  57774. if (outputDeviceDropDown == 0)
  57775. {
  57776. outputDeviceDropDown = new ComboBox (String::empty);
  57777. outputDeviceDropDown->addListener (this);
  57778. addAndMakeVisible (outputDeviceDropDown);
  57779. outputDeviceLabel = new Label (String::empty,
  57780. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57781. : TRANS ("device:"));
  57782. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57783. if (setup.maxNumOutputChannels > 0)
  57784. {
  57785. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57786. testButton->addButtonListener (this);
  57787. }
  57788. }
  57789. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57790. }
  57791. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57792. {
  57793. if (inputDeviceDropDown == 0)
  57794. {
  57795. inputDeviceDropDown = new ComboBox (String::empty);
  57796. inputDeviceDropDown->addListener (this);
  57797. addAndMakeVisible (inputDeviceDropDown);
  57798. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57799. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57800. addAndMakeVisible (inputLevelMeter
  57801. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57802. }
  57803. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57804. }
  57805. updateControlPanelButton();
  57806. showCorrectDeviceName (inputDeviceDropDown, true);
  57807. showCorrectDeviceName (outputDeviceDropDown, false);
  57808. if (currentDevice != 0)
  57809. {
  57810. if (setup.maxNumOutputChannels > 0
  57811. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57812. {
  57813. if (outputChanList == 0)
  57814. {
  57815. addAndMakeVisible (outputChanList
  57816. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57817. TRANS ("(no audio output channels found)")));
  57818. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57819. outputChanLabel->attachToComponent (outputChanList, true);
  57820. }
  57821. outputChanList->refresh();
  57822. }
  57823. else
  57824. {
  57825. deleteAndZero (outputChanLabel);
  57826. deleteAndZero (outputChanList);
  57827. }
  57828. if (setup.maxNumInputChannels > 0
  57829. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57830. {
  57831. if (inputChanList == 0)
  57832. {
  57833. addAndMakeVisible (inputChanList
  57834. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57835. TRANS ("(no audio input channels found)")));
  57836. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57837. inputChanLabel->attachToComponent (inputChanList, true);
  57838. }
  57839. inputChanList->refresh();
  57840. }
  57841. else
  57842. {
  57843. deleteAndZero (inputChanLabel);
  57844. deleteAndZero (inputChanList);
  57845. }
  57846. // sample rate..
  57847. {
  57848. if (sampleRateDropDown == 0)
  57849. {
  57850. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57851. sampleRateDropDown->addListener (this);
  57852. delete sampleRateLabel;
  57853. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57854. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57855. }
  57856. else
  57857. {
  57858. sampleRateDropDown->clear();
  57859. sampleRateDropDown->removeListener (this);
  57860. }
  57861. const int numRates = currentDevice->getNumSampleRates();
  57862. for (int i = 0; i < numRates; ++i)
  57863. {
  57864. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57865. sampleRateDropDown->addItem (String (rate) + " Hz", rate);
  57866. }
  57867. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57868. sampleRateDropDown->addListener (this);
  57869. }
  57870. // buffer size
  57871. {
  57872. if (bufferSizeDropDown == 0)
  57873. {
  57874. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  57875. bufferSizeDropDown->addListener (this);
  57876. delete bufferSizeLabel;
  57877. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  57878. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  57879. }
  57880. else
  57881. {
  57882. bufferSizeDropDown->clear();
  57883. }
  57884. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  57885. double currentRate = currentDevice->getCurrentSampleRate();
  57886. if (currentRate == 0)
  57887. currentRate = 48000.0;
  57888. for (int i = 0; i < numBufferSizes; ++i)
  57889. {
  57890. const int bs = currentDevice->getBufferSizeSamples (i);
  57891. bufferSizeDropDown->addItem (String (bs)
  57892. + " samples ("
  57893. + String (bs * 1000.0 / currentRate, 1)
  57894. + " ms)",
  57895. bs);
  57896. }
  57897. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  57898. }
  57899. }
  57900. else
  57901. {
  57902. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  57903. deleteAndZero (sampleRateLabel);
  57904. deleteAndZero (bufferSizeLabel);
  57905. deleteAndZero (sampleRateDropDown);
  57906. deleteAndZero (bufferSizeDropDown);
  57907. if (outputDeviceDropDown != 0)
  57908. outputDeviceDropDown->setSelectedId (-1, true);
  57909. if (inputDeviceDropDown != 0)
  57910. inputDeviceDropDown->setSelectedId (-1, true);
  57911. }
  57912. resized();
  57913. setSize (getWidth(), getLowestY() + 4);
  57914. }
  57915. private:
  57916. AudioIODeviceType* const type;
  57917. const AudioIODeviceType::DeviceSetupDetails setup;
  57918. ComboBox* outputDeviceDropDown;
  57919. ComboBox* inputDeviceDropDown;
  57920. ComboBox* sampleRateDropDown;
  57921. ComboBox* bufferSizeDropDown;
  57922. Label* outputDeviceLabel;
  57923. Label* inputDeviceLabel;
  57924. Label* sampleRateLabel;
  57925. Label* bufferSizeLabel;
  57926. Label* inputChanLabel;
  57927. Label* outputChanLabel;
  57928. TextButton* testButton;
  57929. Component* inputLevelMeter;
  57930. TextButton* showUIButton;
  57931. TextButton* showAdvancedSettingsButton;
  57932. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  57933. {
  57934. if (box != 0)
  57935. {
  57936. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  57937. const int index = type->getIndexOfDevice (currentDevice, isInput);
  57938. box->setSelectedId (index + 1, true);
  57939. if (testButton != 0 && ! isInput)
  57940. testButton->setEnabled (index >= 0);
  57941. }
  57942. }
  57943. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  57944. {
  57945. const StringArray devs (type->getDeviceNames (isInputs));
  57946. combo.clear (true);
  57947. for (int i = 0; i < devs.size(); ++i)
  57948. combo.addItem (devs[i], i + 1);
  57949. combo.addItem (TRANS("<< none >>"), -1);
  57950. combo.setSelectedId (-1, true);
  57951. }
  57952. int getLowestY() const
  57953. {
  57954. int y = 0;
  57955. for (int i = getNumChildComponents(); --i >= 0;)
  57956. y = jmax (y, getChildComponent (i)->getBottom());
  57957. return y;
  57958. }
  57959. public:
  57960. class ChannelSelectorListBox : public ListBox,
  57961. public ListBoxModel
  57962. {
  57963. public:
  57964. enum BoxType
  57965. {
  57966. audioInputType,
  57967. audioOutputType
  57968. };
  57969. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  57970. const BoxType type_,
  57971. const String& noItemsMessage_)
  57972. : ListBox (String::empty, 0),
  57973. setup (setup_),
  57974. type (type_),
  57975. noItemsMessage (noItemsMessage_)
  57976. {
  57977. refresh();
  57978. setModel (this);
  57979. setOutlineThickness (1);
  57980. }
  57981. ~ChannelSelectorListBox()
  57982. {
  57983. }
  57984. void refresh()
  57985. {
  57986. items.clear();
  57987. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57988. if (currentDevice != 0)
  57989. {
  57990. if (type == audioInputType)
  57991. items = currentDevice->getInputChannelNames();
  57992. else if (type == audioOutputType)
  57993. items = currentDevice->getOutputChannelNames();
  57994. if (setup.useStereoPairs)
  57995. {
  57996. StringArray pairs;
  57997. for (int i = 0; i < items.size(); i += 2)
  57998. {
  57999. String name (items[i]);
  58000. String name2 (items[i + 1]);
  58001. String commonBit;
  58002. for (int j = 0; j < name.length(); ++j)
  58003. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58004. commonBit = name.substring (0, j);
  58005. pairs.add (name.trim()
  58006. + " + "
  58007. + name2.substring (commonBit.length()).trim());
  58008. }
  58009. items = pairs;
  58010. }
  58011. }
  58012. updateContent();
  58013. repaint();
  58014. }
  58015. int getNumRows()
  58016. {
  58017. return items.size();
  58018. }
  58019. void paintListBoxItem (int row,
  58020. Graphics& g,
  58021. int width, int height,
  58022. bool rowIsSelected)
  58023. {
  58024. if (((unsigned int) row) < (unsigned int) items.size())
  58025. {
  58026. if (rowIsSelected)
  58027. g.fillAll (findColour (TextEditor::highlightColourId)
  58028. .withMultipliedAlpha (0.3f));
  58029. const String item (items [row]);
  58030. bool enabled = false;
  58031. AudioDeviceManager::AudioDeviceSetup config;
  58032. setup.manager->getAudioDeviceSetup (config);
  58033. if (setup.useStereoPairs)
  58034. {
  58035. if (type == audioInputType)
  58036. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58037. else if (type == audioOutputType)
  58038. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58039. }
  58040. else
  58041. {
  58042. if (type == audioInputType)
  58043. enabled = config.inputChannels [row];
  58044. else if (type == audioOutputType)
  58045. enabled = config.outputChannels [row];
  58046. }
  58047. const int x = getTickX();
  58048. const float tickW = height * 0.75f;
  58049. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58050. enabled, true, true, false);
  58051. g.setFont (height * 0.6f);
  58052. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58053. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58054. }
  58055. }
  58056. void listBoxItemClicked (int row, const MouseEvent& e)
  58057. {
  58058. selectRow (row);
  58059. if (e.x < getTickX())
  58060. flipEnablement (row);
  58061. }
  58062. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58063. {
  58064. flipEnablement (row);
  58065. }
  58066. void returnKeyPressed (int row)
  58067. {
  58068. flipEnablement (row);
  58069. }
  58070. void paint (Graphics& g)
  58071. {
  58072. ListBox::paint (g);
  58073. if (items.size() == 0)
  58074. {
  58075. g.setColour (Colours::grey);
  58076. g.setFont (13.0f);
  58077. g.drawText (noItemsMessage,
  58078. 0, 0, getWidth(), getHeight() / 2,
  58079. Justification::centred, true);
  58080. }
  58081. }
  58082. int getBestHeight (int maxHeight)
  58083. {
  58084. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58085. getNumRows())
  58086. + getOutlineThickness() * 2;
  58087. }
  58088. juce_UseDebuggingNewOperator
  58089. private:
  58090. const AudioIODeviceType::DeviceSetupDetails setup;
  58091. const BoxType type;
  58092. const String noItemsMessage;
  58093. StringArray items;
  58094. void flipEnablement (const int row)
  58095. {
  58096. jassert (type == audioInputType || type == audioOutputType);
  58097. if (((unsigned int) row) < (unsigned int) items.size())
  58098. {
  58099. AudioDeviceManager::AudioDeviceSetup config;
  58100. setup.manager->getAudioDeviceSetup (config);
  58101. if (setup.useStereoPairs)
  58102. {
  58103. BigInteger bits;
  58104. BigInteger& original = (type == audioInputType ? config.inputChannels
  58105. : config.outputChannels);
  58106. int i;
  58107. for (i = 0; i < 256; i += 2)
  58108. bits.setBit (i / 2, original [i] || original [i + 1]);
  58109. if (type == audioInputType)
  58110. {
  58111. config.useDefaultInputChannels = false;
  58112. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58113. }
  58114. else
  58115. {
  58116. config.useDefaultOutputChannels = false;
  58117. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58118. }
  58119. for (i = 0; i < 256; ++i)
  58120. original.setBit (i, bits [i / 2]);
  58121. }
  58122. else
  58123. {
  58124. if (type == audioInputType)
  58125. {
  58126. config.useDefaultInputChannels = false;
  58127. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58128. }
  58129. else
  58130. {
  58131. config.useDefaultOutputChannels = false;
  58132. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58133. }
  58134. }
  58135. String error (setup.manager->setAudioDeviceSetup (config, true));
  58136. if (! error.isEmpty())
  58137. {
  58138. //xxx
  58139. }
  58140. }
  58141. }
  58142. static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber)
  58143. {
  58144. const int numActive = chans.countNumberOfSetBits();
  58145. if (chans [index])
  58146. {
  58147. if (numActive > minNumber)
  58148. chans.setBit (index, false);
  58149. }
  58150. else
  58151. {
  58152. if (numActive >= maxNumber)
  58153. {
  58154. const int firstActiveChan = chans.findNextSetBit();
  58155. chans.setBit (index > firstActiveChan
  58156. ? firstActiveChan : chans.getHighestBit(),
  58157. false);
  58158. }
  58159. chans.setBit (index, true);
  58160. }
  58161. }
  58162. int getTickX() const
  58163. {
  58164. return getRowHeight() + 5;
  58165. }
  58166. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58167. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58168. };
  58169. private:
  58170. ChannelSelectorListBox* inputChanList;
  58171. ChannelSelectorListBox* outputChanList;
  58172. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58173. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58174. };
  58175. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58176. const int minInputChannels_,
  58177. const int maxInputChannels_,
  58178. const int minOutputChannels_,
  58179. const int maxOutputChannels_,
  58180. const bool showMidiInputOptions,
  58181. const bool showMidiOutputSelector,
  58182. const bool showChannelsAsStereoPairs_,
  58183. const bool hideAdvancedOptionsWithButton_)
  58184. : deviceManager (deviceManager_),
  58185. deviceTypeDropDown (0),
  58186. deviceTypeDropDownLabel (0),
  58187. audioDeviceSettingsComp (0),
  58188. minOutputChannels (minOutputChannels_),
  58189. maxOutputChannels (maxOutputChannels_),
  58190. minInputChannels (minInputChannels_),
  58191. maxInputChannels (maxInputChannels_),
  58192. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58193. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58194. {
  58195. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58196. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58197. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58198. {
  58199. deviceTypeDropDown = new ComboBox (String::empty);
  58200. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58201. {
  58202. deviceTypeDropDown
  58203. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58204. i + 1);
  58205. }
  58206. addAndMakeVisible (deviceTypeDropDown);
  58207. deviceTypeDropDown->addListener (this);
  58208. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58209. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58210. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58211. }
  58212. if (showMidiInputOptions)
  58213. {
  58214. addAndMakeVisible (midiInputsList
  58215. = new MidiInputSelectorComponentListBox (deviceManager,
  58216. TRANS("(no midi inputs available)"),
  58217. 0, 0));
  58218. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58219. midiInputsLabel->setJustificationType (Justification::topRight);
  58220. midiInputsLabel->attachToComponent (midiInputsList, true);
  58221. }
  58222. else
  58223. {
  58224. midiInputsList = 0;
  58225. midiInputsLabel = 0;
  58226. }
  58227. if (showMidiOutputSelector)
  58228. {
  58229. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58230. midiOutputSelector->addListener (this);
  58231. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58232. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58233. }
  58234. else
  58235. {
  58236. midiOutputSelector = 0;
  58237. midiOutputLabel = 0;
  58238. }
  58239. deviceManager_.addChangeListener (this);
  58240. changeListenerCallback (0);
  58241. }
  58242. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58243. {
  58244. deviceManager.removeChangeListener (this);
  58245. deleteAllChildren();
  58246. }
  58247. void AudioDeviceSelectorComponent::resized()
  58248. {
  58249. const int lx = proportionOfWidth (0.35f);
  58250. const int w = proportionOfWidth (0.4f);
  58251. const int h = 24;
  58252. const int space = 6;
  58253. const int dh = h + space;
  58254. int y = 15;
  58255. if (deviceTypeDropDown != 0)
  58256. {
  58257. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58258. y += dh + space * 2;
  58259. }
  58260. if (audioDeviceSettingsComp != 0)
  58261. {
  58262. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58263. y += audioDeviceSettingsComp->getHeight() + space;
  58264. }
  58265. if (midiInputsList != 0)
  58266. {
  58267. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58268. midiInputsList->setBounds (lx, y, w, bh);
  58269. y += bh + space;
  58270. }
  58271. if (midiOutputSelector != 0)
  58272. midiOutputSelector->setBounds (lx, y, w, h);
  58273. }
  58274. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58275. {
  58276. if (child == audioDeviceSettingsComp)
  58277. resized();
  58278. }
  58279. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58280. {
  58281. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58282. if (device != 0 && device->hasControlPanel())
  58283. {
  58284. if (device->showControlPanel())
  58285. deviceManager.restartLastAudioDevice();
  58286. getTopLevelComponent()->toFront (true);
  58287. }
  58288. }
  58289. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58290. {
  58291. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58292. {
  58293. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58294. if (type != 0)
  58295. {
  58296. deleteAndZero (audioDeviceSettingsComp);
  58297. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58298. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58299. }
  58300. }
  58301. else if (comboBoxThatHasChanged == midiOutputSelector)
  58302. {
  58303. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58304. }
  58305. }
  58306. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58307. {
  58308. if (deviceTypeDropDown != 0)
  58309. {
  58310. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58311. }
  58312. if (audioDeviceSettingsComp == 0
  58313. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58314. {
  58315. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58316. deleteAndZero (audioDeviceSettingsComp);
  58317. AudioIODeviceType* const type
  58318. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58319. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58320. if (type != 0)
  58321. {
  58322. AudioIODeviceType::DeviceSetupDetails details;
  58323. details.manager = &deviceManager;
  58324. details.minNumInputChannels = minInputChannels;
  58325. details.maxNumInputChannels = maxInputChannels;
  58326. details.minNumOutputChannels = minOutputChannels;
  58327. details.maxNumOutputChannels = maxOutputChannels;
  58328. details.useStereoPairs = showChannelsAsStereoPairs;
  58329. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58330. if (audioDeviceSettingsComp != 0)
  58331. {
  58332. addAndMakeVisible (audioDeviceSettingsComp);
  58333. audioDeviceSettingsComp->resized();
  58334. }
  58335. }
  58336. }
  58337. if (midiInputsList != 0)
  58338. {
  58339. midiInputsList->updateContent();
  58340. midiInputsList->repaint();
  58341. }
  58342. if (midiOutputSelector != 0)
  58343. {
  58344. midiOutputSelector->clear();
  58345. const StringArray midiOuts (MidiOutput::getDevices());
  58346. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58347. midiOutputSelector->addSeparator();
  58348. for (int i = 0; i < midiOuts.size(); ++i)
  58349. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58350. int current = -1;
  58351. if (deviceManager.getDefaultMidiOutput() != 0)
  58352. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58353. midiOutputSelector->setSelectedId (current, true);
  58354. }
  58355. resized();
  58356. }
  58357. END_JUCE_NAMESPACE
  58358. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58359. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58360. BEGIN_JUCE_NAMESPACE
  58361. BubbleComponent::BubbleComponent()
  58362. : side (0),
  58363. allowablePlacements (above | below | left | right),
  58364. arrowTipX (0.0f),
  58365. arrowTipY (0.0f)
  58366. {
  58367. setInterceptsMouseClicks (false, false);
  58368. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58369. setComponentEffect (&shadow);
  58370. }
  58371. BubbleComponent::~BubbleComponent()
  58372. {
  58373. }
  58374. void BubbleComponent::paint (Graphics& g)
  58375. {
  58376. int x = content.getX();
  58377. int y = content.getY();
  58378. int w = content.getWidth();
  58379. int h = content.getHeight();
  58380. int cw, ch;
  58381. getContentSize (cw, ch);
  58382. if (side == 3)
  58383. x += w - cw;
  58384. else if (side != 1)
  58385. x += (w - cw) / 2;
  58386. w = cw;
  58387. if (side == 2)
  58388. y += h - ch;
  58389. else if (side != 0)
  58390. y += (h - ch) / 2;
  58391. h = ch;
  58392. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58393. (float) x, (float) y,
  58394. (float) w, (float) h);
  58395. const int cx = x + (w - cw) / 2;
  58396. const int cy = y + (h - ch) / 2;
  58397. const int indent = 3;
  58398. g.setOrigin (cx + indent, cy + indent);
  58399. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58400. paintContent (g, cw - indent * 2, ch - indent * 2);
  58401. }
  58402. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58403. {
  58404. allowablePlacements = newPlacement;
  58405. }
  58406. void BubbleComponent::setPosition (Component* componentToPointTo)
  58407. {
  58408. jassert (componentToPointTo->isValidComponent());
  58409. Point<int> pos;
  58410. if (getParentComponent() != 0)
  58411. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58412. else
  58413. pos = componentToPointTo->relativePositionToGlobal (pos);
  58414. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58415. }
  58416. void BubbleComponent::setPosition (const int arrowTipX_,
  58417. const int arrowTipY_)
  58418. {
  58419. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58420. }
  58421. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58422. {
  58423. Rectangle<int> availableSpace;
  58424. if (getParentComponent() != 0)
  58425. {
  58426. availableSpace.setSize (getParentComponent()->getWidth(),
  58427. getParentComponent()->getHeight());
  58428. }
  58429. else
  58430. {
  58431. availableSpace = getParentMonitorArea();
  58432. }
  58433. int x = 0;
  58434. int y = 0;
  58435. int w = 150;
  58436. int h = 30;
  58437. getContentSize (w, h);
  58438. w += 30;
  58439. h += 30;
  58440. const float edgeIndent = 2.0f;
  58441. const int arrowLength = jmin (10, h / 3, w / 3);
  58442. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58443. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58444. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58445. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58446. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58447. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58448. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58449. {
  58450. spaceLeft = spaceRight = 0;
  58451. }
  58452. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58453. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58454. {
  58455. spaceAbove = spaceBelow = 0;
  58456. }
  58457. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58458. {
  58459. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58460. arrowTipX = w * 0.5f;
  58461. content.setSize (w, h - arrowLength);
  58462. if (spaceAbove >= spaceBelow)
  58463. {
  58464. // above
  58465. y = rectangleToPointTo.getY() - h;
  58466. content.setPosition (0, 0);
  58467. arrowTipY = h - edgeIndent;
  58468. side = 2;
  58469. }
  58470. else
  58471. {
  58472. // below
  58473. y = rectangleToPointTo.getBottom();
  58474. content.setPosition (0, arrowLength);
  58475. arrowTipY = edgeIndent;
  58476. side = 0;
  58477. }
  58478. }
  58479. else
  58480. {
  58481. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58482. arrowTipY = h * 0.5f;
  58483. content.setSize (w - arrowLength, h);
  58484. if (spaceLeft > spaceRight)
  58485. {
  58486. // on the left
  58487. x = rectangleToPointTo.getX() - w;
  58488. content.setPosition (0, 0);
  58489. arrowTipX = w - edgeIndent;
  58490. side = 3;
  58491. }
  58492. else
  58493. {
  58494. // on the right
  58495. x = rectangleToPointTo.getRight();
  58496. content.setPosition (arrowLength, 0);
  58497. arrowTipX = edgeIndent;
  58498. side = 1;
  58499. }
  58500. }
  58501. setBounds (x, y, w, h);
  58502. }
  58503. END_JUCE_NAMESPACE
  58504. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58505. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58506. BEGIN_JUCE_NAMESPACE
  58507. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58508. : fadeOutLength (fadeOutLengthMs),
  58509. deleteAfterUse (false)
  58510. {
  58511. }
  58512. BubbleMessageComponent::~BubbleMessageComponent()
  58513. {
  58514. fadeOutComponent (fadeOutLength);
  58515. }
  58516. void BubbleMessageComponent::showAt (int x, int y,
  58517. const String& text,
  58518. const int numMillisecondsBeforeRemoving,
  58519. const bool removeWhenMouseClicked,
  58520. const bool deleteSelfAfterUse)
  58521. {
  58522. textLayout.clear();
  58523. textLayout.setText (text, Font (14.0f));
  58524. textLayout.layout (256, Justification::centredLeft, true);
  58525. setPosition (x, y);
  58526. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58527. }
  58528. void BubbleMessageComponent::showAt (Component* const component,
  58529. const String& text,
  58530. const int numMillisecondsBeforeRemoving,
  58531. const bool removeWhenMouseClicked,
  58532. const bool deleteSelfAfterUse)
  58533. {
  58534. textLayout.clear();
  58535. textLayout.setText (text, Font (14.0f));
  58536. textLayout.layout (256, Justification::centredLeft, true);
  58537. setPosition (component);
  58538. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58539. }
  58540. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58541. const bool removeWhenMouseClicked,
  58542. const bool deleteSelfAfterUse)
  58543. {
  58544. setVisible (true);
  58545. deleteAfterUse = deleteSelfAfterUse;
  58546. if (numMillisecondsBeforeRemoving > 0)
  58547. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58548. else
  58549. expiryTime = 0;
  58550. startTimer (77);
  58551. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58552. if (! (removeWhenMouseClicked && isShowing()))
  58553. mouseClickCounter += 0xfffff;
  58554. repaint();
  58555. }
  58556. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58557. {
  58558. w = textLayout.getWidth() + 16;
  58559. h = textLayout.getHeight() + 16;
  58560. }
  58561. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58562. {
  58563. g.setColour (findColour (TooltipWindow::textColourId));
  58564. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58565. }
  58566. void BubbleMessageComponent::timerCallback()
  58567. {
  58568. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58569. {
  58570. stopTimer();
  58571. setVisible (false);
  58572. if (deleteAfterUse)
  58573. delete this;
  58574. }
  58575. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58576. {
  58577. stopTimer();
  58578. fadeOutComponent (fadeOutLength);
  58579. if (deleteAfterUse)
  58580. delete this;
  58581. }
  58582. }
  58583. END_JUCE_NAMESPACE
  58584. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58585. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58586. BEGIN_JUCE_NAMESPACE
  58587. static const int swatchesPerRow = 8;
  58588. static const int swatchHeight = 22;
  58589. class ColourComponentSlider : public Slider
  58590. {
  58591. public:
  58592. ColourComponentSlider (const String& name)
  58593. : Slider (name)
  58594. {
  58595. setRange (0.0, 255.0, 1.0);
  58596. }
  58597. ~ColourComponentSlider()
  58598. {
  58599. }
  58600. const String getTextFromValue (double value)
  58601. {
  58602. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58603. }
  58604. double getValueFromText (const String& text)
  58605. {
  58606. return (double) text.getHexValue32();
  58607. }
  58608. private:
  58609. ColourComponentSlider (const ColourComponentSlider&);
  58610. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58611. };
  58612. class ColourSpaceMarker : public Component
  58613. {
  58614. public:
  58615. ColourSpaceMarker()
  58616. {
  58617. setInterceptsMouseClicks (false, false);
  58618. }
  58619. ~ColourSpaceMarker()
  58620. {
  58621. }
  58622. void paint (Graphics& g)
  58623. {
  58624. g.setColour (Colour::greyLevel (0.1f));
  58625. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58626. g.setColour (Colour::greyLevel (0.9f));
  58627. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58628. }
  58629. private:
  58630. ColourSpaceMarker (const ColourSpaceMarker&);
  58631. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58632. };
  58633. class ColourSpaceView : public Component
  58634. {
  58635. ColourSelector* const owner;
  58636. float& h;
  58637. float& s;
  58638. float& v;
  58639. float lastHue;
  58640. ColourSpaceMarker* marker;
  58641. const int edge;
  58642. public:
  58643. ColourSpaceView (ColourSelector* owner_,
  58644. float& h_, float& s_, float& v_,
  58645. const int edgeSize)
  58646. : owner (owner_),
  58647. h (h_), s (s_), v (v_),
  58648. lastHue (0.0f),
  58649. edge (edgeSize)
  58650. {
  58651. addAndMakeVisible (marker = new ColourSpaceMarker());
  58652. setMouseCursor (MouseCursor::CrosshairCursor);
  58653. }
  58654. ~ColourSpaceView()
  58655. {
  58656. deleteAllChildren();
  58657. }
  58658. void paint (Graphics& g)
  58659. {
  58660. if (colours == 0)
  58661. {
  58662. const int width = getWidth() / 2;
  58663. const int height = getHeight() / 2;
  58664. colours = new Image (Image::RGB, width, height, false);
  58665. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58666. for (int y = 0; y < height; ++y)
  58667. {
  58668. const float v = 1.0f - y / (float) height;
  58669. for (int x = 0; x < width; ++x)
  58670. {
  58671. const float s = x / (float) width;
  58672. const Colour col (h, s, v, 1.0f);
  58673. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58674. pix->set (col.getPixelARGB());
  58675. }
  58676. }
  58677. }
  58678. g.setOpacity (1.0f);
  58679. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58680. 0, 0, colours->getWidth(), colours->getHeight());
  58681. }
  58682. void mouseDown (const MouseEvent& e)
  58683. {
  58684. mouseDrag (e);
  58685. }
  58686. void mouseDrag (const MouseEvent& e)
  58687. {
  58688. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58689. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58690. owner->setSV (s, v);
  58691. }
  58692. void updateIfNeeded()
  58693. {
  58694. if (lastHue != h)
  58695. {
  58696. lastHue = h;
  58697. colours = 0;
  58698. repaint();
  58699. }
  58700. updateMarker();
  58701. }
  58702. void resized()
  58703. {
  58704. colours = 0;
  58705. updateMarker();
  58706. }
  58707. private:
  58708. ScopedPointer <Image> colours;
  58709. void updateMarker() const throw()
  58710. {
  58711. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58712. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58713. edge * 2, edge * 2);
  58714. }
  58715. ColourSpaceView (const ColourSpaceView&);
  58716. ColourSpaceView& operator= (const ColourSpaceView&);
  58717. };
  58718. class HueSelectorMarker : public Component
  58719. {
  58720. public:
  58721. HueSelectorMarker()
  58722. {
  58723. setInterceptsMouseClicks (false, false);
  58724. }
  58725. ~HueSelectorMarker()
  58726. {
  58727. }
  58728. void paint (Graphics& g)
  58729. {
  58730. Path p;
  58731. p.addTriangle (1.0f, 1.0f,
  58732. getWidth() * 0.3f, getHeight() * 0.5f,
  58733. 1.0f, getHeight() - 1.0f);
  58734. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58735. getWidth() * 0.7f, getHeight() * 0.5f,
  58736. getWidth() - 1.0f, getHeight() - 1.0f);
  58737. g.setColour (Colours::white.withAlpha (0.75f));
  58738. g.fillPath (p);
  58739. g.setColour (Colours::black.withAlpha (0.75f));
  58740. g.strokePath (p, PathStrokeType (1.2f));
  58741. }
  58742. private:
  58743. HueSelectorMarker (const HueSelectorMarker&);
  58744. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58745. };
  58746. class HueSelectorComp : public Component
  58747. {
  58748. public:
  58749. HueSelectorComp (ColourSelector* owner_,
  58750. float& h_, float& s_, float& v_,
  58751. const int edgeSize)
  58752. : owner (owner_),
  58753. h (h_), s (s_), v (v_),
  58754. lastHue (0.0f),
  58755. edge (edgeSize)
  58756. {
  58757. addAndMakeVisible (marker = new HueSelectorMarker());
  58758. }
  58759. ~HueSelectorComp()
  58760. {
  58761. deleteAllChildren();
  58762. }
  58763. void paint (Graphics& g)
  58764. {
  58765. const float yScale = 1.0f / (getHeight() - edge * 2);
  58766. const Rectangle<int> clip (g.getClipBounds());
  58767. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58768. {
  58769. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58770. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58771. }
  58772. }
  58773. void resized()
  58774. {
  58775. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58776. getWidth(), edge * 2);
  58777. }
  58778. void mouseDown (const MouseEvent& e)
  58779. {
  58780. mouseDrag (e);
  58781. }
  58782. void mouseDrag (const MouseEvent& e)
  58783. {
  58784. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58785. owner->setHue (hue);
  58786. }
  58787. void updateIfNeeded()
  58788. {
  58789. resized();
  58790. }
  58791. private:
  58792. ColourSelector* const owner;
  58793. float& h;
  58794. float& s;
  58795. float& v;
  58796. float lastHue;
  58797. HueSelectorMarker* marker;
  58798. const int edge;
  58799. HueSelectorComp (const HueSelectorComp&);
  58800. HueSelectorComp& operator= (const HueSelectorComp&);
  58801. };
  58802. class ColourSelector::SwatchComponent : public Component
  58803. {
  58804. public:
  58805. SwatchComponent (ColourSelector* owner_, int index_)
  58806. : owner (owner_),
  58807. index (index_)
  58808. {
  58809. }
  58810. ~SwatchComponent()
  58811. {
  58812. }
  58813. void paint (Graphics& g)
  58814. {
  58815. const Colour colour (owner->getSwatchColour (index));
  58816. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58817. 6, 6,
  58818. Colour (0xffdddddd).overlaidWith (colour),
  58819. Colour (0xffffffff).overlaidWith (colour));
  58820. }
  58821. void mouseDown (const MouseEvent&)
  58822. {
  58823. PopupMenu m;
  58824. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58825. m.addSeparator();
  58826. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58827. const int r = m.showAt (this);
  58828. if (r == 1)
  58829. {
  58830. owner->setCurrentColour (owner->getSwatchColour (index));
  58831. }
  58832. else if (r == 2)
  58833. {
  58834. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58835. {
  58836. owner->setSwatchColour (index, owner->getCurrentColour());
  58837. repaint();
  58838. }
  58839. }
  58840. }
  58841. private:
  58842. ColourSelector* const owner;
  58843. const int index;
  58844. SwatchComponent (const SwatchComponent&);
  58845. SwatchComponent& operator= (const SwatchComponent&);
  58846. };
  58847. ColourSelector::ColourSelector (const int flags_,
  58848. const int edgeGap_,
  58849. const int gapAroundColourSpaceComponent)
  58850. : colour (Colours::white),
  58851. flags (flags_),
  58852. topSpace (0),
  58853. edgeGap (edgeGap_)
  58854. {
  58855. // not much point having a selector with no components in it!
  58856. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58857. updateHSV();
  58858. if ((flags & showSliders) != 0)
  58859. {
  58860. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58861. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58862. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58863. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58864. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58865. for (int i = 4; --i >= 0;)
  58866. sliders[i]->addListener (this);
  58867. }
  58868. else
  58869. {
  58870. zeromem (sliders, sizeof (sliders));
  58871. }
  58872. if ((flags & showColourspace) != 0)
  58873. {
  58874. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  58875. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  58876. }
  58877. else
  58878. {
  58879. colourSpace = 0;
  58880. hueSelector = 0;
  58881. }
  58882. update();
  58883. }
  58884. ColourSelector::~ColourSelector()
  58885. {
  58886. dispatchPendingMessages();
  58887. swatchComponents.clear();
  58888. deleteAllChildren();
  58889. }
  58890. const Colour ColourSelector::getCurrentColour() const
  58891. {
  58892. return ((flags & showAlphaChannel) != 0) ? colour
  58893. : colour.withAlpha ((uint8) 0xff);
  58894. }
  58895. void ColourSelector::setCurrentColour (const Colour& c)
  58896. {
  58897. if (c != colour)
  58898. {
  58899. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  58900. updateHSV();
  58901. update();
  58902. }
  58903. }
  58904. void ColourSelector::setHue (float newH)
  58905. {
  58906. newH = jlimit (0.0f, 1.0f, newH);
  58907. if (h != newH)
  58908. {
  58909. h = newH;
  58910. colour = Colour (h, s, v, colour.getFloatAlpha());
  58911. update();
  58912. }
  58913. }
  58914. void ColourSelector::setSV (float newS, float newV)
  58915. {
  58916. newS = jlimit (0.0f, 1.0f, newS);
  58917. newV = jlimit (0.0f, 1.0f, newV);
  58918. if (s != newS || v != newV)
  58919. {
  58920. s = newS;
  58921. v = newV;
  58922. colour = Colour (h, s, v, colour.getFloatAlpha());
  58923. update();
  58924. }
  58925. }
  58926. void ColourSelector::updateHSV()
  58927. {
  58928. colour.getHSB (h, s, v);
  58929. }
  58930. void ColourSelector::update()
  58931. {
  58932. if (sliders[0] != 0)
  58933. {
  58934. sliders[0]->setValue ((int) colour.getRed());
  58935. sliders[1]->setValue ((int) colour.getGreen());
  58936. sliders[2]->setValue ((int) colour.getBlue());
  58937. sliders[3]->setValue ((int) colour.getAlpha());
  58938. }
  58939. if (colourSpace != 0)
  58940. {
  58941. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  58942. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  58943. }
  58944. if ((flags & showColourAtTop) != 0)
  58945. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  58946. sendChangeMessage (this);
  58947. }
  58948. void ColourSelector::paint (Graphics& g)
  58949. {
  58950. g.fillAll (findColour (backgroundColourId));
  58951. if ((flags & showColourAtTop) != 0)
  58952. {
  58953. const Colour colour (getCurrentColour());
  58954. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  58955. 10, 10,
  58956. Colour (0xffdddddd).overlaidWith (colour),
  58957. Colour (0xffffffff).overlaidWith (colour));
  58958. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  58959. g.setFont (14.0f, true);
  58960. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  58961. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  58962. Justification::centred, false);
  58963. }
  58964. if ((flags & showSliders) != 0)
  58965. {
  58966. g.setColour (findColour (labelTextColourId));
  58967. g.setFont (11.0f);
  58968. for (int i = 4; --i >= 0;)
  58969. {
  58970. if (sliders[i]->isVisible())
  58971. g.drawText (sliders[i]->getName() + ":",
  58972. 0, sliders[i]->getY(),
  58973. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  58974. Justification::centredRight, false);
  58975. }
  58976. }
  58977. }
  58978. void ColourSelector::resized()
  58979. {
  58980. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  58981. const int numSwatches = getNumSwatches();
  58982. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  58983. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  58984. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  58985. int y = topSpace;
  58986. if ((flags & showColourspace) != 0)
  58987. {
  58988. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  58989. colourSpace->setBounds (edgeGap, y,
  58990. getWidth() - hueWidth - edgeGap - 4,
  58991. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  58992. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  58993. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  58994. colourSpace->getHeight());
  58995. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  58996. }
  58997. if ((flags & showSliders) != 0)
  58998. {
  58999. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59000. for (int i = 0; i < numSliders; ++i)
  59001. {
  59002. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59003. proportionOfWidth (0.72f), sliderHeight - 2);
  59004. y += sliderHeight;
  59005. }
  59006. }
  59007. if (numSwatches > 0)
  59008. {
  59009. const int startX = 8;
  59010. const int xGap = 4;
  59011. const int yGap = 4;
  59012. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59013. y += edgeGap;
  59014. if (swatchComponents.size() != numSwatches)
  59015. {
  59016. swatchComponents.clear();
  59017. for (int i = 0; i < numSwatches; ++i)
  59018. {
  59019. SwatchComponent* const sc = new SwatchComponent (this, i);
  59020. swatchComponents.add (sc);
  59021. addAndMakeVisible (sc);
  59022. }
  59023. }
  59024. int x = startX;
  59025. for (int i = 0; i < swatchComponents.size(); ++i)
  59026. {
  59027. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59028. sc->setBounds (x + xGap / 2,
  59029. y + yGap / 2,
  59030. swatchWidth - xGap,
  59031. swatchHeight - yGap);
  59032. if (((i + 1) % swatchesPerRow) == 0)
  59033. {
  59034. x = startX;
  59035. y += swatchHeight;
  59036. }
  59037. else
  59038. {
  59039. x += swatchWidth;
  59040. }
  59041. }
  59042. }
  59043. }
  59044. void ColourSelector::sliderValueChanged (Slider*)
  59045. {
  59046. if (sliders[0] != 0)
  59047. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59048. (uint8) sliders[1]->getValue(),
  59049. (uint8) sliders[2]->getValue(),
  59050. (uint8) sliders[3]->getValue()));
  59051. }
  59052. int ColourSelector::getNumSwatches() const
  59053. {
  59054. return 0;
  59055. }
  59056. const Colour ColourSelector::getSwatchColour (const int) const
  59057. {
  59058. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59059. return Colours::black;
  59060. }
  59061. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59062. {
  59063. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59064. }
  59065. END_JUCE_NAMESPACE
  59066. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59067. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59068. BEGIN_JUCE_NAMESPACE
  59069. class ShadowWindow : public Component
  59070. {
  59071. Component* owner;
  59072. Image** shadowImageSections;
  59073. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59074. public:
  59075. ShadowWindow (Component* const owner_,
  59076. const int type_,
  59077. Image** const shadowImageSections_)
  59078. : owner (owner_),
  59079. shadowImageSections (shadowImageSections_),
  59080. type (type_)
  59081. {
  59082. setInterceptsMouseClicks (false, false);
  59083. if (owner_->isOnDesktop())
  59084. {
  59085. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59086. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59087. | ComponentPeer::windowIsTemporary
  59088. | ComponentPeer::windowIgnoresKeyPresses);
  59089. }
  59090. else if (owner_->getParentComponent() != 0)
  59091. {
  59092. owner_->getParentComponent()->addChildComponent (this);
  59093. }
  59094. }
  59095. ~ShadowWindow()
  59096. {
  59097. }
  59098. void paint (Graphics& g)
  59099. {
  59100. Image* const topLeft = shadowImageSections [type * 3];
  59101. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59102. Image* const filler = shadowImageSections [type * 3 + 2];
  59103. g.setOpacity (1.0f);
  59104. if (type < 2)
  59105. {
  59106. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59107. g.drawImage (topLeft,
  59108. 0, 0, topLeft->getWidth(), imH,
  59109. 0, 0, topLeft->getWidth(), imH);
  59110. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59111. g.drawImage (bottomRight,
  59112. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59113. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59114. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59115. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59116. }
  59117. else
  59118. {
  59119. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59120. g.drawImage (topLeft,
  59121. 0, 0, imW, topLeft->getHeight(),
  59122. 0, 0, imW, topLeft->getHeight());
  59123. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59124. g.drawImage (bottomRight,
  59125. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59126. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59127. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59128. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59129. }
  59130. }
  59131. void resized()
  59132. {
  59133. repaint(); // (needed for correct repainting)
  59134. }
  59135. private:
  59136. ShadowWindow (const ShadowWindow&);
  59137. ShadowWindow& operator= (const ShadowWindow&);
  59138. };
  59139. DropShadower::DropShadower (const float alpha_,
  59140. const int xOffset_,
  59141. const int yOffset_,
  59142. const float blurRadius_)
  59143. : owner (0),
  59144. numShadows (0),
  59145. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59146. xOffset (xOffset_),
  59147. yOffset (yOffset_),
  59148. alpha (alpha_),
  59149. blurRadius (blurRadius_),
  59150. inDestructor (false),
  59151. reentrant (false)
  59152. {
  59153. }
  59154. DropShadower::~DropShadower()
  59155. {
  59156. if (owner != 0)
  59157. owner->removeComponentListener (this);
  59158. inDestructor = true;
  59159. deleteShadowWindows();
  59160. }
  59161. void DropShadower::deleteShadowWindows()
  59162. {
  59163. if (numShadows > 0)
  59164. {
  59165. int i;
  59166. for (i = numShadows; --i >= 0;)
  59167. delete shadowWindows[i];
  59168. for (i = 12; --i >= 0;)
  59169. delete shadowImageSections[i];
  59170. numShadows = 0;
  59171. }
  59172. }
  59173. void DropShadower::setOwner (Component* componentToFollow)
  59174. {
  59175. if (componentToFollow != owner)
  59176. {
  59177. if (owner != 0)
  59178. owner->removeComponentListener (this);
  59179. // (the component can't be null)
  59180. jassert (componentToFollow != 0);
  59181. owner = componentToFollow;
  59182. jassert (owner != 0);
  59183. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59184. owner->addComponentListener (this);
  59185. updateShadows();
  59186. }
  59187. }
  59188. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59189. {
  59190. updateShadows();
  59191. }
  59192. void DropShadower::componentBroughtToFront (Component&)
  59193. {
  59194. bringShadowWindowsToFront();
  59195. }
  59196. void DropShadower::componentChildrenChanged (Component&)
  59197. {
  59198. }
  59199. void DropShadower::componentParentHierarchyChanged (Component&)
  59200. {
  59201. deleteShadowWindows();
  59202. updateShadows();
  59203. }
  59204. void DropShadower::componentVisibilityChanged (Component&)
  59205. {
  59206. updateShadows();
  59207. }
  59208. void DropShadower::updateShadows()
  59209. {
  59210. if (reentrant || inDestructor || (owner == 0))
  59211. return;
  59212. reentrant = true;
  59213. ComponentPeer* const nw = owner->getPeer();
  59214. const bool isOwnerVisible = owner->isVisible()
  59215. && (nw == 0 || ! nw->isMinimised());
  59216. const bool createShadowWindows = numShadows == 0
  59217. && owner->getWidth() > 0
  59218. && owner->getHeight() > 0
  59219. && isOwnerVisible
  59220. && (Desktop::canUseSemiTransparentWindows()
  59221. || owner->getParentComponent() != 0);
  59222. if (createShadowWindows)
  59223. {
  59224. // keep a cached version of the image to save doing the gaussian too often
  59225. String imageId;
  59226. imageId << shadowEdge << ',' << xOffset << ',' << yOffset << ',' << alpha;
  59227. const int hash = imageId.hashCode();
  59228. Image* bigIm = ImageCache::getFromHashCode (hash);
  59229. if (bigIm == 0)
  59230. {
  59231. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59232. Graphics bigG (*bigIm);
  59233. bigG.setColour (Colours::black.withAlpha (alpha));
  59234. bigG.fillRect (shadowEdge + xOffset,
  59235. shadowEdge + yOffset,
  59236. bigIm->getWidth() - (shadowEdge * 2),
  59237. bigIm->getHeight() - (shadowEdge * 2));
  59238. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59239. blurKernel.createGaussianBlur (blurRadius);
  59240. blurKernel.applyToImage (*bigIm, 0,
  59241. Rectangle<int> (xOffset, yOffset,
  59242. bigIm->getWidth(), bigIm->getHeight()));
  59243. ImageCache::addImageToCache (bigIm, hash);
  59244. }
  59245. const int iw = bigIm->getWidth();
  59246. const int ih = bigIm->getHeight();
  59247. const int shadowEdge2 = shadowEdge * 2;
  59248. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59249. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59250. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59251. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59252. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59253. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59254. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59255. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59256. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59257. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59258. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59259. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59260. ImageCache::release (bigIm);
  59261. for (int i = 0; i < 4; ++i)
  59262. {
  59263. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59264. ++numShadows;
  59265. }
  59266. }
  59267. if (numShadows > 0)
  59268. {
  59269. for (int i = numShadows; --i >= 0;)
  59270. {
  59271. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59272. shadowWindows[i]->setVisible (isOwnerVisible);
  59273. }
  59274. const int x = owner->getX();
  59275. const int y = owner->getY() - shadowEdge;
  59276. const int w = owner->getWidth();
  59277. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59278. shadowWindows[0]->setBounds (x - shadowEdge,
  59279. y,
  59280. shadowEdge,
  59281. h);
  59282. shadowWindows[1]->setBounds (x + w,
  59283. y,
  59284. shadowEdge,
  59285. h);
  59286. shadowWindows[2]->setBounds (x,
  59287. y,
  59288. w,
  59289. shadowEdge);
  59290. shadowWindows[3]->setBounds (x,
  59291. owner->getBottom(),
  59292. w,
  59293. shadowEdge);
  59294. }
  59295. reentrant = false;
  59296. if (createShadowWindows)
  59297. bringShadowWindowsToFront();
  59298. }
  59299. void DropShadower::setShadowImage (Image* const src, const int num, const int w, const int h,
  59300. const int sx, const int sy)
  59301. {
  59302. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59303. Graphics g (*shadowImageSections[num]);
  59304. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59305. }
  59306. void DropShadower::bringShadowWindowsToFront()
  59307. {
  59308. if (! (inDestructor || reentrant))
  59309. {
  59310. updateShadows();
  59311. reentrant = true;
  59312. for (int i = numShadows; --i >= 0;)
  59313. shadowWindows[i]->toBehind (owner);
  59314. reentrant = false;
  59315. }
  59316. }
  59317. END_JUCE_NAMESPACE
  59318. /*** End of inlined file: juce_DropShadower.cpp ***/
  59319. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59320. BEGIN_JUCE_NAMESPACE
  59321. class MagnifyingPeer : public ComponentPeer
  59322. {
  59323. public:
  59324. MagnifyingPeer (Component* const component_,
  59325. MagnifierComponent* const magnifierComp_)
  59326. : ComponentPeer (component_, 0),
  59327. magnifierComp (magnifierComp_)
  59328. {
  59329. }
  59330. ~MagnifyingPeer()
  59331. {
  59332. }
  59333. void* getNativeHandle() const { return 0; }
  59334. void setVisible (bool) {}
  59335. void setTitle (const String&) {}
  59336. void setPosition (int, int) {}
  59337. void setSize (int, int) {}
  59338. void setBounds (int, int, int, int, bool) {}
  59339. void setMinimised (bool) {}
  59340. bool isMinimised() const { return false; }
  59341. void setFullScreen (bool) {}
  59342. bool isFullScreen() const { return false; }
  59343. const BorderSize getFrameSize() const { return BorderSize (0); }
  59344. bool setAlwaysOnTop (bool) { return true; }
  59345. void toFront (bool) {}
  59346. void toBehind (ComponentPeer*) {}
  59347. void setIcon (const Image&) {}
  59348. bool isFocused() const
  59349. {
  59350. return magnifierComp->hasKeyboardFocus (true);
  59351. }
  59352. void grabFocus()
  59353. {
  59354. ComponentPeer* peer = magnifierComp->getPeer();
  59355. if (peer != 0)
  59356. peer->grabFocus();
  59357. }
  59358. void textInputRequired (const Point<int>& position)
  59359. {
  59360. ComponentPeer* peer = magnifierComp->getPeer();
  59361. if (peer != 0)
  59362. peer->textInputRequired (position);
  59363. }
  59364. const Rectangle<int> getBounds() const
  59365. {
  59366. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59367. component->getWidth(), component->getHeight());
  59368. }
  59369. const Point<int> getScreenPosition() const
  59370. {
  59371. return magnifierComp->getScreenPosition();
  59372. }
  59373. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59374. {
  59375. const double zoom = magnifierComp->getScaleFactor();
  59376. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59377. roundToInt (relativePosition.getY() * zoom)));
  59378. }
  59379. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59380. {
  59381. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59382. const double zoom = magnifierComp->getScaleFactor();
  59383. return Point<int> (roundToInt (p.getX() / zoom),
  59384. roundToInt (p.getY() / zoom));
  59385. }
  59386. bool contains (const Point<int>& position, bool) const
  59387. {
  59388. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59389. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59390. }
  59391. void repaint (int x, int y, int w, int h)
  59392. {
  59393. const double zoom = magnifierComp->getScaleFactor();
  59394. magnifierComp->repaint ((int) (x * zoom),
  59395. (int) (y * zoom),
  59396. roundToInt (w * zoom) + 1,
  59397. roundToInt (h * zoom) + 1);
  59398. }
  59399. void performAnyPendingRepaintsNow()
  59400. {
  59401. }
  59402. juce_UseDebuggingNewOperator
  59403. private:
  59404. MagnifierComponent* const magnifierComp;
  59405. MagnifyingPeer (const MagnifyingPeer&);
  59406. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59407. };
  59408. class PeerHolderComp : public Component
  59409. {
  59410. public:
  59411. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59412. : magnifierComp (magnifierComp_)
  59413. {
  59414. setVisible (true);
  59415. }
  59416. ~PeerHolderComp()
  59417. {
  59418. }
  59419. ComponentPeer* createNewPeer (int, void*)
  59420. {
  59421. return new MagnifyingPeer (this, magnifierComp);
  59422. }
  59423. void childBoundsChanged (Component* c)
  59424. {
  59425. if (c != 0)
  59426. {
  59427. setSize (c->getWidth(), c->getHeight());
  59428. magnifierComp->childBoundsChanged (this);
  59429. }
  59430. }
  59431. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59432. {
  59433. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59434. Component* const p = magnifierComp->getParentComponent();
  59435. if (p != 0)
  59436. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59437. }
  59438. private:
  59439. MagnifierComponent* const magnifierComp;
  59440. PeerHolderComp (const PeerHolderComp&);
  59441. PeerHolderComp& operator= (const PeerHolderComp&);
  59442. };
  59443. MagnifierComponent::MagnifierComponent (Component* const content_,
  59444. const bool deleteContentCompWhenNoLongerNeeded)
  59445. : content (content_),
  59446. scaleFactor (0.0),
  59447. peer (0),
  59448. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59449. quality (Graphics::lowResamplingQuality),
  59450. mouseSource (0, true)
  59451. {
  59452. holderComp = new PeerHolderComp (this);
  59453. setScaleFactor (1.0);
  59454. }
  59455. MagnifierComponent::~MagnifierComponent()
  59456. {
  59457. delete holderComp;
  59458. if (deleteContent)
  59459. delete content;
  59460. }
  59461. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59462. {
  59463. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59464. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59465. if (scaleFactor != newScaleFactor)
  59466. {
  59467. scaleFactor = newScaleFactor;
  59468. if (scaleFactor == 1.0)
  59469. {
  59470. holderComp->removeFromDesktop();
  59471. peer = 0;
  59472. addChildComponent (content);
  59473. childBoundsChanged (content);
  59474. }
  59475. else
  59476. {
  59477. holderComp->addAndMakeVisible (content);
  59478. holderComp->childBoundsChanged (content);
  59479. childBoundsChanged (holderComp);
  59480. holderComp->addToDesktop (0);
  59481. peer = holderComp->getPeer();
  59482. }
  59483. repaint();
  59484. }
  59485. }
  59486. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59487. {
  59488. quality = newQuality;
  59489. }
  59490. void MagnifierComponent::paint (Graphics& g)
  59491. {
  59492. const int w = holderComp->getWidth();
  59493. const int h = holderComp->getHeight();
  59494. if (w == 0 || h == 0)
  59495. return;
  59496. const Rectangle<int> r (g.getClipBounds());
  59497. const int srcX = (int) (r.getX() / scaleFactor);
  59498. const int srcY = (int) (r.getY() / scaleFactor);
  59499. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59500. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59501. if (scaleFactor >= 1.0)
  59502. {
  59503. ++srcW;
  59504. ++srcH;
  59505. }
  59506. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59507. temp.clear (srcX, srcY, srcW, srcH);
  59508. {
  59509. Graphics g2 (temp);
  59510. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59511. holderComp->paintEntireComponent (g2);
  59512. }
  59513. g.setImageResamplingQuality (quality);
  59514. g.drawImageTransformed (&temp, temp.getBounds(),
  59515. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59516. false);
  59517. }
  59518. void MagnifierComponent::childBoundsChanged (Component* c)
  59519. {
  59520. if (c != 0)
  59521. setSize (roundToInt (c->getWidth() * scaleFactor),
  59522. roundToInt (c->getHeight() * scaleFactor));
  59523. }
  59524. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59525. {
  59526. if (peer != 0)
  59527. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59528. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59529. }
  59530. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59531. {
  59532. passOnMouseEventToPeer (e);
  59533. }
  59534. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59535. {
  59536. passOnMouseEventToPeer (e);
  59537. }
  59538. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59539. {
  59540. passOnMouseEventToPeer (e);
  59541. }
  59542. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59543. {
  59544. passOnMouseEventToPeer (e);
  59545. }
  59546. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59547. {
  59548. passOnMouseEventToPeer (e);
  59549. }
  59550. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59551. {
  59552. passOnMouseEventToPeer (e);
  59553. }
  59554. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59555. {
  59556. if (peer != 0)
  59557. peer->handleMouseWheel (e.source.getIndex(),
  59558. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59559. ix * 256.0f, iy * 256.0f);
  59560. else
  59561. Component::mouseWheelMove (e, ix, iy);
  59562. }
  59563. int MagnifierComponent::scaleInt (const int n) const
  59564. {
  59565. return roundToInt (n / scaleFactor);
  59566. }
  59567. END_JUCE_NAMESPACE
  59568. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59569. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59570. BEGIN_JUCE_NAMESPACE
  59571. class MidiKeyboardUpDownButton : public Button
  59572. {
  59573. public:
  59574. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59575. const int delta_)
  59576. : Button (String::empty),
  59577. owner (owner_),
  59578. delta (delta_)
  59579. {
  59580. setOpaque (true);
  59581. }
  59582. ~MidiKeyboardUpDownButton()
  59583. {
  59584. }
  59585. void clicked()
  59586. {
  59587. int note = owner->getLowestVisibleKey();
  59588. if (delta < 0)
  59589. note = (note - 1) / 12;
  59590. else
  59591. note = note / 12 + 1;
  59592. owner->setLowestVisibleKey (note * 12);
  59593. }
  59594. void paintButton (Graphics& g,
  59595. bool isMouseOverButton,
  59596. bool isButtonDown)
  59597. {
  59598. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59599. isMouseOverButton, isButtonDown,
  59600. delta > 0);
  59601. }
  59602. private:
  59603. MidiKeyboardComponent* const owner;
  59604. const int delta;
  59605. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59606. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59607. };
  59608. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59609. const Orientation orientation_)
  59610. : state (state_),
  59611. xOffset (0),
  59612. blackNoteLength (1),
  59613. keyWidth (16.0f),
  59614. orientation (orientation_),
  59615. midiChannel (1),
  59616. midiInChannelMask (0xffff),
  59617. velocity (1.0f),
  59618. noteUnderMouse (-1),
  59619. mouseDownNote (-1),
  59620. rangeStart (0),
  59621. rangeEnd (127),
  59622. firstKey (12 * 4),
  59623. canScroll (true),
  59624. mouseDragging (false),
  59625. useMousePositionForVelocity (true),
  59626. keyMappingOctave (6),
  59627. octaveNumForMiddleC (3)
  59628. {
  59629. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59630. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59631. // initialise with a default set of querty key-mappings..
  59632. const char* const keymap = "awsedftgyhujkolp;";
  59633. for (int i = String (keymap).length(); --i >= 0;)
  59634. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59635. setOpaque (true);
  59636. setWantsKeyboardFocus (true);
  59637. state.addListener (this);
  59638. }
  59639. MidiKeyboardComponent::~MidiKeyboardComponent()
  59640. {
  59641. state.removeListener (this);
  59642. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59643. deleteAllChildren();
  59644. }
  59645. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59646. {
  59647. keyWidth = widthInPixels;
  59648. resized();
  59649. }
  59650. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59651. {
  59652. if (orientation != newOrientation)
  59653. {
  59654. orientation = newOrientation;
  59655. resized();
  59656. }
  59657. }
  59658. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59659. const int highestNote)
  59660. {
  59661. jassert (lowestNote >= 0 && lowestNote <= 127);
  59662. jassert (highestNote >= 0 && highestNote <= 127);
  59663. jassert (lowestNote <= highestNote);
  59664. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59665. {
  59666. rangeStart = jlimit (0, 127, lowestNote);
  59667. rangeEnd = jlimit (0, 127, highestNote);
  59668. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59669. resized();
  59670. }
  59671. }
  59672. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59673. {
  59674. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59675. if (noteNumber != firstKey)
  59676. {
  59677. firstKey = noteNumber;
  59678. sendChangeMessage (this);
  59679. resized();
  59680. }
  59681. }
  59682. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59683. {
  59684. if (canScroll != canScroll_)
  59685. {
  59686. canScroll = canScroll_;
  59687. resized();
  59688. }
  59689. }
  59690. void MidiKeyboardComponent::colourChanged()
  59691. {
  59692. repaint();
  59693. }
  59694. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59695. {
  59696. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59697. if (midiChannel != midiChannelNumber)
  59698. {
  59699. resetAnyKeysInUse();
  59700. midiChannel = jlimit (1, 16, midiChannelNumber);
  59701. }
  59702. }
  59703. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59704. {
  59705. midiInChannelMask = midiChannelMask;
  59706. triggerAsyncUpdate();
  59707. }
  59708. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59709. {
  59710. velocity = jlimit (0.0f, 1.0f, velocity_);
  59711. useMousePositionForVelocity = useMousePositionForVelocity_;
  59712. }
  59713. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59714. {
  59715. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59716. static const float blackNoteWidth = 0.7f;
  59717. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59718. 1.0f, 2 - blackNoteWidth * 0.4f,
  59719. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59720. 4.0f, 5 - blackNoteWidth * 0.5f,
  59721. 5.0f, 6 - blackNoteWidth * 0.3f,
  59722. 6.0f };
  59723. static const float widths[] = { 1.0f, blackNoteWidth,
  59724. 1.0f, blackNoteWidth,
  59725. 1.0f, 1.0f, blackNoteWidth,
  59726. 1.0f, blackNoteWidth,
  59727. 1.0f, blackNoteWidth,
  59728. 1.0f };
  59729. const int octave = midiNoteNumber / 12;
  59730. const int note = midiNoteNumber % 12;
  59731. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59732. w = roundToInt (widths [note] * keyWidth);
  59733. }
  59734. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59735. {
  59736. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59737. int rx, rw;
  59738. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59739. x -= xOffset + rx;
  59740. }
  59741. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59742. {
  59743. int x, y;
  59744. getKeyPos (midiNoteNumber, x, y);
  59745. return x;
  59746. }
  59747. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59748. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59749. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59750. {
  59751. if (! reallyContains (pos.getX(), pos.getY(), false))
  59752. return -1;
  59753. Point<int> p (pos);
  59754. if (orientation != horizontalKeyboard)
  59755. {
  59756. p = Point<int> (p.getY(), p.getX());
  59757. if (orientation == verticalKeyboardFacingLeft)
  59758. p = Point<int> (p.getX(), getWidth() - p.getY());
  59759. else
  59760. p = Point<int> (getHeight() - p.getX(), p.getY());
  59761. }
  59762. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59763. }
  59764. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59765. {
  59766. if (pos.getY() < blackNoteLength)
  59767. {
  59768. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59769. {
  59770. for (int i = 0; i < 5; ++i)
  59771. {
  59772. const int note = octaveStart + blackNotes [i];
  59773. if (note >= rangeStart && note <= rangeEnd)
  59774. {
  59775. int kx, kw;
  59776. getKeyPos (note, kx, kw);
  59777. kx += xOffset;
  59778. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59779. {
  59780. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59781. return note;
  59782. }
  59783. }
  59784. }
  59785. }
  59786. }
  59787. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59788. {
  59789. for (int i = 0; i < 7; ++i)
  59790. {
  59791. const int note = octaveStart + whiteNotes [i];
  59792. if (note >= rangeStart && note <= rangeEnd)
  59793. {
  59794. int kx, kw;
  59795. getKeyPos (note, kx, kw);
  59796. kx += xOffset;
  59797. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59798. {
  59799. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59800. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59801. return note;
  59802. }
  59803. }
  59804. }
  59805. }
  59806. mousePositionVelocity = 0;
  59807. return -1;
  59808. }
  59809. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59810. {
  59811. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59812. {
  59813. int x, w;
  59814. getKeyPos (noteNum, x, w);
  59815. if (orientation == horizontalKeyboard)
  59816. repaint (x, 0, w, getHeight());
  59817. else if (orientation == verticalKeyboardFacingLeft)
  59818. repaint (0, x, getWidth(), w);
  59819. else if (orientation == verticalKeyboardFacingRight)
  59820. repaint (0, getHeight() - x - w, getWidth(), w);
  59821. }
  59822. }
  59823. void MidiKeyboardComponent::paint (Graphics& g)
  59824. {
  59825. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59826. const Colour lineColour (findColour (keySeparatorLineColourId));
  59827. const Colour textColour (findColour (textLabelColourId));
  59828. int x, w, octave;
  59829. for (octave = 0; octave < 128; octave += 12)
  59830. {
  59831. for (int white = 0; white < 7; ++white)
  59832. {
  59833. const int noteNum = octave + whiteNotes [white];
  59834. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59835. {
  59836. getKeyPos (noteNum, x, w);
  59837. if (orientation == horizontalKeyboard)
  59838. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59839. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59840. noteUnderMouse == noteNum,
  59841. lineColour, textColour);
  59842. else if (orientation == verticalKeyboardFacingLeft)
  59843. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59844. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59845. noteUnderMouse == noteNum,
  59846. lineColour, textColour);
  59847. else if (orientation == verticalKeyboardFacingRight)
  59848. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59849. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59850. noteUnderMouse == noteNum,
  59851. lineColour, textColour);
  59852. }
  59853. }
  59854. }
  59855. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59856. if (orientation == verticalKeyboardFacingLeft)
  59857. {
  59858. x1 = getWidth() - 1.0f;
  59859. x2 = getWidth() - 5.0f;
  59860. }
  59861. else if (orientation == verticalKeyboardFacingRight)
  59862. x2 = 5.0f;
  59863. else
  59864. y2 = 5.0f;
  59865. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  59866. Colours::transparentBlack, x2, y2, false));
  59867. getKeyPos (rangeEnd, x, w);
  59868. x += w;
  59869. if (orientation == verticalKeyboardFacingLeft)
  59870. g.fillRect (getWidth() - 5, 0, 5, x);
  59871. else if (orientation == verticalKeyboardFacingRight)
  59872. g.fillRect (0, 0, 5, x);
  59873. else
  59874. g.fillRect (0, 0, x, 5);
  59875. g.setColour (lineColour);
  59876. if (orientation == verticalKeyboardFacingLeft)
  59877. g.fillRect (0, 0, 1, x);
  59878. else if (orientation == verticalKeyboardFacingRight)
  59879. g.fillRect (getWidth() - 1, 0, 1, x);
  59880. else
  59881. g.fillRect (0, getHeight() - 1, x, 1);
  59882. const Colour blackNoteColour (findColour (blackNoteColourId));
  59883. for (octave = 0; octave < 128; octave += 12)
  59884. {
  59885. for (int black = 0; black < 5; ++black)
  59886. {
  59887. const int noteNum = octave + blackNotes [black];
  59888. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59889. {
  59890. getKeyPos (noteNum, x, w);
  59891. if (orientation == horizontalKeyboard)
  59892. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  59893. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59894. noteUnderMouse == noteNum,
  59895. blackNoteColour);
  59896. else if (orientation == verticalKeyboardFacingLeft)
  59897. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  59898. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59899. noteUnderMouse == noteNum,
  59900. blackNoteColour);
  59901. else if (orientation == verticalKeyboardFacingRight)
  59902. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  59903. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59904. noteUnderMouse == noteNum,
  59905. blackNoteColour);
  59906. }
  59907. }
  59908. }
  59909. }
  59910. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  59911. Graphics& g, int x, int y, int w, int h,
  59912. bool isDown, bool isOver,
  59913. const Colour& lineColour,
  59914. const Colour& textColour)
  59915. {
  59916. Colour c (Colours::transparentWhite);
  59917. if (isDown)
  59918. c = findColour (keyDownOverlayColourId);
  59919. if (isOver)
  59920. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59921. g.setColour (c);
  59922. g.fillRect (x, y, w, h);
  59923. const String text (getWhiteNoteText (midiNoteNumber));
  59924. if (! text.isEmpty())
  59925. {
  59926. g.setColour (textColour);
  59927. Font f (jmin (12.0f, keyWidth * 0.9f));
  59928. f.setHorizontalScale (0.8f);
  59929. g.setFont (f);
  59930. Justification justification (Justification::centredBottom);
  59931. if (orientation == verticalKeyboardFacingLeft)
  59932. justification = Justification::centredLeft;
  59933. else if (orientation == verticalKeyboardFacingRight)
  59934. justification = Justification::centredRight;
  59935. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  59936. }
  59937. g.setColour (lineColour);
  59938. if (orientation == horizontalKeyboard)
  59939. g.fillRect (x, y, 1, h);
  59940. else if (orientation == verticalKeyboardFacingLeft)
  59941. g.fillRect (x, y, w, 1);
  59942. else if (orientation == verticalKeyboardFacingRight)
  59943. g.fillRect (x, y + h - 1, w, 1);
  59944. if (midiNoteNumber == rangeEnd)
  59945. {
  59946. if (orientation == horizontalKeyboard)
  59947. g.fillRect (x + w, y, 1, h);
  59948. else if (orientation == verticalKeyboardFacingLeft)
  59949. g.fillRect (x, y + h, w, 1);
  59950. else if (orientation == verticalKeyboardFacingRight)
  59951. g.fillRect (x, y - 1, w, 1);
  59952. }
  59953. }
  59954. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  59955. Graphics& g, int x, int y, int w, int h,
  59956. bool isDown, bool isOver,
  59957. const Colour& noteFillColour)
  59958. {
  59959. Colour c (noteFillColour);
  59960. if (isDown)
  59961. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  59962. if (isOver)
  59963. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59964. g.setColour (c);
  59965. g.fillRect (x, y, w, h);
  59966. if (isDown)
  59967. {
  59968. g.setColour (noteFillColour);
  59969. g.drawRect (x, y, w, h);
  59970. }
  59971. else
  59972. {
  59973. const int xIndent = jmax (1, jmin (w, h) / 8);
  59974. g.setColour (c.brighter());
  59975. if (orientation == horizontalKeyboard)
  59976. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  59977. else if (orientation == verticalKeyboardFacingLeft)
  59978. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  59979. else if (orientation == verticalKeyboardFacingRight)
  59980. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  59981. }
  59982. }
  59983. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  59984. {
  59985. octaveNumForMiddleC = octaveNumForMiddleC_;
  59986. repaint();
  59987. }
  59988. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  59989. {
  59990. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  59991. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  59992. return String::empty;
  59993. }
  59994. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  59995. const bool isMouseOver,
  59996. const bool isButtonDown,
  59997. const bool movesOctavesUp)
  59998. {
  59999. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60000. float angle;
  60001. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60002. angle = movesOctavesUp ? 0.0f : 0.5f;
  60003. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60004. angle = movesOctavesUp ? 0.25f : 0.75f;
  60005. else
  60006. angle = movesOctavesUp ? 0.75f : 0.25f;
  60007. Path path;
  60008. path.lineTo (0.0f, 1.0f);
  60009. path.lineTo (1.0f, 0.5f);
  60010. path.closeSubPath();
  60011. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60012. g.setColour (findColour (upDownButtonArrowColourId)
  60013. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60014. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60015. w - 2.0f,
  60016. h - 2.0f,
  60017. true));
  60018. }
  60019. void MidiKeyboardComponent::resized()
  60020. {
  60021. int w = getWidth();
  60022. int h = getHeight();
  60023. if (w > 0 && h > 0)
  60024. {
  60025. if (orientation != horizontalKeyboard)
  60026. swapVariables (w, h);
  60027. blackNoteLength = roundToInt (h * 0.7f);
  60028. int kx2, kw2;
  60029. getKeyPos (rangeEnd, kx2, kw2);
  60030. kx2 += kw2;
  60031. if (firstKey != rangeStart)
  60032. {
  60033. int kx1, kw1;
  60034. getKeyPos (rangeStart, kx1, kw1);
  60035. if (kx2 - kx1 <= w)
  60036. {
  60037. firstKey = rangeStart;
  60038. sendChangeMessage (this);
  60039. repaint();
  60040. }
  60041. }
  60042. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60043. scrollDown->setVisible (showScrollButtons);
  60044. scrollUp->setVisible (showScrollButtons);
  60045. xOffset = 0;
  60046. if (showScrollButtons)
  60047. {
  60048. const int scrollButtonW = jmin (12, w / 2);
  60049. if (orientation == horizontalKeyboard)
  60050. {
  60051. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60052. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60053. }
  60054. else if (orientation == verticalKeyboardFacingLeft)
  60055. {
  60056. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60057. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60058. }
  60059. else if (orientation == verticalKeyboardFacingRight)
  60060. {
  60061. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60062. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60063. }
  60064. int endOfLastKey, kw;
  60065. getKeyPos (rangeEnd, endOfLastKey, kw);
  60066. endOfLastKey += kw;
  60067. float mousePositionVelocity;
  60068. const int spaceAvailable = w - scrollButtonW * 2;
  60069. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60070. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60071. {
  60072. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60073. sendChangeMessage (this);
  60074. }
  60075. int newOffset = 0;
  60076. getKeyPos (firstKey, newOffset, kw);
  60077. xOffset = newOffset - scrollButtonW;
  60078. }
  60079. else
  60080. {
  60081. firstKey = rangeStart;
  60082. }
  60083. timerCallback();
  60084. repaint();
  60085. }
  60086. }
  60087. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60088. {
  60089. triggerAsyncUpdate();
  60090. }
  60091. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60092. {
  60093. triggerAsyncUpdate();
  60094. }
  60095. void MidiKeyboardComponent::handleAsyncUpdate()
  60096. {
  60097. for (int i = rangeStart; i <= rangeEnd; ++i)
  60098. {
  60099. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60100. {
  60101. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60102. repaintNote (i);
  60103. }
  60104. }
  60105. }
  60106. void MidiKeyboardComponent::resetAnyKeysInUse()
  60107. {
  60108. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60109. {
  60110. state.allNotesOff (midiChannel);
  60111. keysPressed.clear();
  60112. mouseDownNote = -1;
  60113. }
  60114. }
  60115. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60116. {
  60117. float mousePositionVelocity = 0.0f;
  60118. const int newNote = (mouseDragging || isMouseOver())
  60119. ? xyToNote (pos, mousePositionVelocity) : -1;
  60120. if (noteUnderMouse != newNote)
  60121. {
  60122. if (mouseDownNote >= 0)
  60123. {
  60124. state.noteOff (midiChannel, mouseDownNote);
  60125. mouseDownNote = -1;
  60126. }
  60127. if (mouseDragging && newNote >= 0)
  60128. {
  60129. if (! useMousePositionForVelocity)
  60130. mousePositionVelocity = 1.0f;
  60131. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60132. mouseDownNote = newNote;
  60133. }
  60134. repaintNote (noteUnderMouse);
  60135. noteUnderMouse = newNote;
  60136. repaintNote (noteUnderMouse);
  60137. }
  60138. else if (mouseDownNote >= 0 && ! mouseDragging)
  60139. {
  60140. state.noteOff (midiChannel, mouseDownNote);
  60141. mouseDownNote = -1;
  60142. }
  60143. }
  60144. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60145. {
  60146. updateNoteUnderMouse (e.getPosition());
  60147. stopTimer();
  60148. }
  60149. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60150. {
  60151. float mousePositionVelocity;
  60152. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60153. if (newNote >= 0)
  60154. mouseDraggedToKey (newNote, e);
  60155. updateNoteUnderMouse (e.getPosition());
  60156. }
  60157. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60158. {
  60159. return true;
  60160. }
  60161. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60162. {
  60163. }
  60164. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60165. {
  60166. float mousePositionVelocity;
  60167. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60168. mouseDragging = false;
  60169. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60170. {
  60171. repaintNote (noteUnderMouse);
  60172. noteUnderMouse = -1;
  60173. mouseDragging = true;
  60174. updateNoteUnderMouse (e.getPosition());
  60175. startTimer (500);
  60176. }
  60177. }
  60178. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60179. {
  60180. mouseDragging = false;
  60181. updateNoteUnderMouse (e.getPosition());
  60182. stopTimer();
  60183. }
  60184. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60185. {
  60186. updateNoteUnderMouse (e.getPosition());
  60187. }
  60188. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60189. {
  60190. updateNoteUnderMouse (e.getPosition());
  60191. }
  60192. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60193. {
  60194. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60195. }
  60196. void MidiKeyboardComponent::timerCallback()
  60197. {
  60198. updateNoteUnderMouse (getMouseXYRelative());
  60199. }
  60200. void MidiKeyboardComponent::clearKeyMappings()
  60201. {
  60202. resetAnyKeysInUse();
  60203. keyPressNotes.clear();
  60204. keyPresses.clear();
  60205. }
  60206. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60207. const int midiNoteOffsetFromC)
  60208. {
  60209. removeKeyPressForNote (midiNoteOffsetFromC);
  60210. keyPressNotes.add (midiNoteOffsetFromC);
  60211. keyPresses.add (key);
  60212. }
  60213. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60214. {
  60215. for (int i = keyPressNotes.size(); --i >= 0;)
  60216. {
  60217. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60218. {
  60219. keyPressNotes.remove (i);
  60220. keyPresses.remove (i);
  60221. }
  60222. }
  60223. }
  60224. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60225. {
  60226. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60227. keyMappingOctave = newOctaveNumber;
  60228. }
  60229. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60230. {
  60231. bool keyPressUsed = false;
  60232. for (int i = keyPresses.size(); --i >= 0;)
  60233. {
  60234. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60235. if (keyPresses.getReference(i).isCurrentlyDown())
  60236. {
  60237. if (! keysPressed [note])
  60238. {
  60239. keysPressed.setBit (note);
  60240. state.noteOn (midiChannel, note, velocity);
  60241. keyPressUsed = true;
  60242. }
  60243. }
  60244. else
  60245. {
  60246. if (keysPressed [note])
  60247. {
  60248. keysPressed.clearBit (note);
  60249. state.noteOff (midiChannel, note);
  60250. keyPressUsed = true;
  60251. }
  60252. }
  60253. }
  60254. return keyPressUsed;
  60255. }
  60256. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60257. {
  60258. resetAnyKeysInUse();
  60259. }
  60260. END_JUCE_NAMESPACE
  60261. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60262. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60263. #if JUCE_OPENGL
  60264. BEGIN_JUCE_NAMESPACE
  60265. extern void juce_glViewport (const int w, const int h);
  60266. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60267. const int alphaBits_,
  60268. const int depthBufferBits_,
  60269. const int stencilBufferBits_)
  60270. : redBits (bitsPerRGBComponent),
  60271. greenBits (bitsPerRGBComponent),
  60272. blueBits (bitsPerRGBComponent),
  60273. alphaBits (alphaBits_),
  60274. depthBufferBits (depthBufferBits_),
  60275. stencilBufferBits (stencilBufferBits_),
  60276. accumulationBufferRedBits (0),
  60277. accumulationBufferGreenBits (0),
  60278. accumulationBufferBlueBits (0),
  60279. accumulationBufferAlphaBits (0),
  60280. fullSceneAntiAliasingNumSamples (0)
  60281. {
  60282. }
  60283. OpenGLPixelFormat::OpenGLPixelFormat (const OpenGLPixelFormat& other)
  60284. : redBits (other.redBits),
  60285. greenBits (other.greenBits),
  60286. blueBits (other.blueBits),
  60287. alphaBits (other.alphaBits),
  60288. depthBufferBits (other.depthBufferBits),
  60289. stencilBufferBits (other.stencilBufferBits),
  60290. accumulationBufferRedBits (other.accumulationBufferRedBits),
  60291. accumulationBufferGreenBits (other.accumulationBufferGreenBits),
  60292. accumulationBufferBlueBits (other.accumulationBufferBlueBits),
  60293. accumulationBufferAlphaBits (other.accumulationBufferAlphaBits),
  60294. fullSceneAntiAliasingNumSamples (other.fullSceneAntiAliasingNumSamples)
  60295. {
  60296. }
  60297. OpenGLPixelFormat& OpenGLPixelFormat::operator= (const OpenGLPixelFormat& other)
  60298. {
  60299. redBits = other.redBits;
  60300. greenBits = other.greenBits;
  60301. blueBits = other.blueBits;
  60302. alphaBits = other.alphaBits;
  60303. depthBufferBits = other.depthBufferBits;
  60304. stencilBufferBits = other.stencilBufferBits;
  60305. accumulationBufferRedBits = other.accumulationBufferRedBits;
  60306. accumulationBufferGreenBits = other.accumulationBufferGreenBits;
  60307. accumulationBufferBlueBits = other.accumulationBufferBlueBits;
  60308. accumulationBufferAlphaBits = other.accumulationBufferAlphaBits;
  60309. fullSceneAntiAliasingNumSamples = other.fullSceneAntiAliasingNumSamples;
  60310. return *this;
  60311. }
  60312. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const
  60313. {
  60314. return redBits == other.redBits
  60315. && greenBits == other.greenBits
  60316. && blueBits == other.blueBits
  60317. && alphaBits == other.alphaBits
  60318. && depthBufferBits == other.depthBufferBits
  60319. && stencilBufferBits == other.stencilBufferBits
  60320. && accumulationBufferRedBits == other.accumulationBufferRedBits
  60321. && accumulationBufferGreenBits == other.accumulationBufferGreenBits
  60322. && accumulationBufferBlueBits == other.accumulationBufferBlueBits
  60323. && accumulationBufferAlphaBits == other.accumulationBufferAlphaBits
  60324. && fullSceneAntiAliasingNumSamples == other.fullSceneAntiAliasingNumSamples;
  60325. }
  60326. static VoidArray knownContexts;
  60327. OpenGLContext::OpenGLContext() throw()
  60328. {
  60329. knownContexts.add (this);
  60330. }
  60331. OpenGLContext::~OpenGLContext()
  60332. {
  60333. knownContexts.removeValue (this);
  60334. }
  60335. OpenGLContext* OpenGLContext::getCurrentContext()
  60336. {
  60337. for (int i = knownContexts.size(); --i >= 0;)
  60338. {
  60339. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60340. if (oglc->isActive())
  60341. return oglc;
  60342. }
  60343. return 0;
  60344. }
  60345. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60346. {
  60347. public:
  60348. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60349. : ComponentMovementWatcher (owner_),
  60350. owner (owner_),
  60351. wasShowing (false)
  60352. {
  60353. }
  60354. ~OpenGLComponentWatcher() {}
  60355. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60356. {
  60357. owner->updateContextPosition();
  60358. }
  60359. void componentPeerChanged()
  60360. {
  60361. const ScopedLock sl (owner->getContextLock());
  60362. owner->deleteContext();
  60363. }
  60364. void componentVisibilityChanged (Component&)
  60365. {
  60366. const bool isShowingNow = owner->isShowing();
  60367. if (wasShowing != isShowingNow)
  60368. {
  60369. wasShowing = isShowingNow;
  60370. owner->updateContextPosition();
  60371. }
  60372. }
  60373. juce_UseDebuggingNewOperator
  60374. private:
  60375. OpenGLComponent* const owner;
  60376. bool wasShowing;
  60377. };
  60378. OpenGLComponent::OpenGLComponent (const OpenGLType type_)
  60379. : type (type_),
  60380. contextToShareListsWith (0),
  60381. needToUpdateViewport (true)
  60382. {
  60383. setOpaque (true);
  60384. componentWatcher = new OpenGLComponentWatcher (this);
  60385. }
  60386. OpenGLComponent::~OpenGLComponent()
  60387. {
  60388. deleteContext();
  60389. componentWatcher = 0;
  60390. }
  60391. void OpenGLComponent::deleteContext()
  60392. {
  60393. const ScopedLock sl (contextLock);
  60394. context = 0;
  60395. }
  60396. void OpenGLComponent::updateContextPosition()
  60397. {
  60398. needToUpdateViewport = true;
  60399. if (getWidth() > 0 && getHeight() > 0)
  60400. {
  60401. Component* const topComp = getTopLevelComponent();
  60402. if (topComp->getPeer() != 0)
  60403. {
  60404. const ScopedLock sl (contextLock);
  60405. if (context != 0)
  60406. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60407. getScreenY() - topComp->getScreenY(),
  60408. getWidth(),
  60409. getHeight(),
  60410. topComp->getHeight());
  60411. }
  60412. }
  60413. }
  60414. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60415. {
  60416. OpenGLPixelFormat pf;
  60417. const ScopedLock sl (contextLock);
  60418. if (context != 0)
  60419. pf = context->getPixelFormat();
  60420. return pf;
  60421. }
  60422. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60423. {
  60424. if (! (preferredPixelFormat == formatToUse))
  60425. {
  60426. const ScopedLock sl (contextLock);
  60427. deleteContext();
  60428. preferredPixelFormat = formatToUse;
  60429. }
  60430. }
  60431. void OpenGLComponent::shareWith (OpenGLContext* c)
  60432. {
  60433. if (contextToShareListsWith != c)
  60434. {
  60435. const ScopedLock sl (contextLock);
  60436. deleteContext();
  60437. contextToShareListsWith = c;
  60438. }
  60439. }
  60440. bool OpenGLComponent::makeCurrentContextActive()
  60441. {
  60442. if (context == 0)
  60443. {
  60444. const ScopedLock sl (contextLock);
  60445. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60446. {
  60447. context = createContext();
  60448. if (context != 0)
  60449. {
  60450. updateContextPosition();
  60451. if (context->makeActive())
  60452. newOpenGLContextCreated();
  60453. }
  60454. }
  60455. }
  60456. return context != 0 && context->makeActive();
  60457. }
  60458. void OpenGLComponent::makeCurrentContextInactive()
  60459. {
  60460. if (context != 0)
  60461. context->makeInactive();
  60462. }
  60463. bool OpenGLComponent::isActiveContext() const throw()
  60464. {
  60465. return context != 0 && context->isActive();
  60466. }
  60467. void OpenGLComponent::swapBuffers()
  60468. {
  60469. if (context != 0)
  60470. context->swapBuffers();
  60471. }
  60472. void OpenGLComponent::paint (Graphics&)
  60473. {
  60474. if (renderAndSwapBuffers())
  60475. {
  60476. ComponentPeer* const peer = getPeer();
  60477. if (peer != 0)
  60478. {
  60479. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60480. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60481. }
  60482. }
  60483. }
  60484. bool OpenGLComponent::renderAndSwapBuffers()
  60485. {
  60486. const ScopedLock sl (contextLock);
  60487. if (! makeCurrentContextActive())
  60488. return false;
  60489. if (needToUpdateViewport)
  60490. {
  60491. needToUpdateViewport = false;
  60492. juce_glViewport (getWidth(), getHeight());
  60493. }
  60494. renderOpenGL();
  60495. swapBuffers();
  60496. return true;
  60497. }
  60498. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60499. {
  60500. Component::internalRepaint (x, y, w, h);
  60501. if (context != 0)
  60502. context->repaint();
  60503. }
  60504. END_JUCE_NAMESPACE
  60505. #endif
  60506. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60507. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60508. BEGIN_JUCE_NAMESPACE
  60509. PreferencesPanel::PreferencesPanel()
  60510. : buttonSize (70)
  60511. {
  60512. }
  60513. PreferencesPanel::~PreferencesPanel()
  60514. {
  60515. currentPage = 0;
  60516. deleteAllChildren();
  60517. }
  60518. void PreferencesPanel::addSettingsPage (const String& title,
  60519. const Drawable* icon,
  60520. const Drawable* overIcon,
  60521. const Drawable* downIcon)
  60522. {
  60523. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60524. button->setImages (icon, overIcon, downIcon);
  60525. button->setRadioGroupId (1);
  60526. button->addButtonListener (this);
  60527. button->setClickingTogglesState (true);
  60528. button->setWantsKeyboardFocus (false);
  60529. addAndMakeVisible (button);
  60530. resized();
  60531. if (currentPage == 0)
  60532. setCurrentPage (title);
  60533. }
  60534. void PreferencesPanel::addSettingsPage (const String& title,
  60535. const char* imageData,
  60536. const int imageDataSize)
  60537. {
  60538. DrawableImage icon, iconOver, iconDown;
  60539. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60540. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60541. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60542. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60543. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60544. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60545. }
  60546. class PrefsDialogWindow : public DialogWindow
  60547. {
  60548. public:
  60549. PrefsDialogWindow (const String& dialogtitle,
  60550. const Colour& backgroundColour)
  60551. : DialogWindow (dialogtitle, backgroundColour, true)
  60552. {
  60553. }
  60554. ~PrefsDialogWindow()
  60555. {
  60556. }
  60557. void closeButtonPressed()
  60558. {
  60559. exitModalState (0);
  60560. }
  60561. private:
  60562. PrefsDialogWindow (const PrefsDialogWindow&);
  60563. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60564. };
  60565. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60566. int dialogWidth,
  60567. int dialogHeight,
  60568. const Colour& backgroundColour)
  60569. {
  60570. setSize (dialogWidth, dialogHeight);
  60571. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60572. dw.setContentComponent (this, true, true);
  60573. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60574. dw.runModalLoop();
  60575. dw.setContentComponent (0, false, false);
  60576. }
  60577. void PreferencesPanel::resized()
  60578. {
  60579. int x = 0;
  60580. for (int i = 0; i < getNumChildComponents(); ++i)
  60581. {
  60582. Component* c = getChildComponent (i);
  60583. if (dynamic_cast <DrawableButton*> (c) == 0)
  60584. {
  60585. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60586. }
  60587. else
  60588. {
  60589. c->setBounds (x, 0, buttonSize, buttonSize);
  60590. x += buttonSize;
  60591. }
  60592. }
  60593. }
  60594. void PreferencesPanel::paint (Graphics& g)
  60595. {
  60596. g.setColour (Colours::grey);
  60597. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60598. }
  60599. void PreferencesPanel::setCurrentPage (const String& pageName)
  60600. {
  60601. if (currentPageName != pageName)
  60602. {
  60603. currentPageName = pageName;
  60604. currentPage = 0;
  60605. currentPage = createComponentForPage (pageName);
  60606. if (currentPage != 0)
  60607. {
  60608. addAndMakeVisible (currentPage);
  60609. currentPage->toBack();
  60610. resized();
  60611. }
  60612. for (int i = 0; i < getNumChildComponents(); ++i)
  60613. {
  60614. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60615. if (db != 0 && db->getName() == pageName)
  60616. {
  60617. db->setToggleState (true, false);
  60618. break;
  60619. }
  60620. }
  60621. }
  60622. }
  60623. void PreferencesPanel::buttonClicked (Button*)
  60624. {
  60625. for (int i = 0; i < getNumChildComponents(); ++i)
  60626. {
  60627. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60628. if (db != 0 && db->getToggleState())
  60629. {
  60630. setCurrentPage (db->getName());
  60631. break;
  60632. }
  60633. }
  60634. }
  60635. END_JUCE_NAMESPACE
  60636. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60637. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60638. #if JUCE_WINDOWS || JUCE_LINUX
  60639. BEGIN_JUCE_NAMESPACE
  60640. SystemTrayIconComponent::SystemTrayIconComponent()
  60641. {
  60642. addToDesktop (0);
  60643. }
  60644. SystemTrayIconComponent::~SystemTrayIconComponent()
  60645. {
  60646. }
  60647. END_JUCE_NAMESPACE
  60648. #endif
  60649. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60650. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60651. BEGIN_JUCE_NAMESPACE
  60652. static const int titleH = 24;
  60653. static const int iconWidth = 80;
  60654. class AlertWindowTextEditor : public TextEditor
  60655. {
  60656. public:
  60657. static const tchar passwordChar;
  60658. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60659. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60660. {
  60661. setSelectAllWhenFocused (true);
  60662. }
  60663. ~AlertWindowTextEditor()
  60664. {
  60665. }
  60666. void returnPressed()
  60667. {
  60668. // pass these up the component hierarchy to be trigger the buttons
  60669. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, '\n'));
  60670. }
  60671. void escapePressed()
  60672. {
  60673. // pass these up the component hierarchy to be trigger the buttons
  60674. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60675. }
  60676. private:
  60677. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60678. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60679. };
  60680. #if JUCE_LINUX
  60681. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  60682. #else
  60683. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  60684. #endif
  60685. AlertWindow::AlertWindow (const String& title,
  60686. const String& message,
  60687. AlertIconType iconType,
  60688. Component* associatedComponent_)
  60689. : TopLevelWindow (title, true),
  60690. alertIconType (iconType),
  60691. associatedComponent (associatedComponent_)
  60692. {
  60693. if (message.isEmpty())
  60694. text = " "; // to force an update if the message is empty
  60695. setMessage (message);
  60696. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60697. {
  60698. Component* const c = Desktop::getInstance().getComponent (i);
  60699. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60700. {
  60701. setAlwaysOnTop (true);
  60702. break;
  60703. }
  60704. }
  60705. if (JUCEApplication::getInstance() == 0)
  60706. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60707. lookAndFeelChanged();
  60708. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60709. }
  60710. AlertWindow::~AlertWindow()
  60711. {
  60712. for (int i = customComps.size(); --i >= 0;)
  60713. removeChildComponent ((Component*) customComps[i]);
  60714. deleteAllChildren();
  60715. }
  60716. void AlertWindow::userTriedToCloseWindow()
  60717. {
  60718. exitModalState (0);
  60719. }
  60720. void AlertWindow::setMessage (const String& message)
  60721. {
  60722. const String newMessage (message.substring (0, 2048));
  60723. if (text != newMessage)
  60724. {
  60725. text = newMessage;
  60726. font.setHeight (15.0f);
  60727. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60728. textLayout.setText (getName() + "\n\n", titleFont);
  60729. textLayout.appendText (text, font);
  60730. updateLayout (true);
  60731. repaint();
  60732. }
  60733. }
  60734. void AlertWindow::buttonClicked (Button* button)
  60735. {
  60736. for (int i = 0; i < buttons.size(); i++)
  60737. {
  60738. TextButton* const c = (TextButton*) buttons[i];
  60739. if (button->getName() == c->getName())
  60740. {
  60741. if (c->getParentComponent() != 0)
  60742. c->getParentComponent()->exitModalState (c->getCommandID());
  60743. break;
  60744. }
  60745. }
  60746. }
  60747. void AlertWindow::addButton (const String& name,
  60748. const int returnValue,
  60749. const KeyPress& shortcutKey1,
  60750. const KeyPress& shortcutKey2)
  60751. {
  60752. TextButton* const b = new TextButton (name, String::empty);
  60753. b->setWantsKeyboardFocus (true);
  60754. b->setMouseClickGrabsKeyboardFocus (false);
  60755. b->setCommandToTrigger (0, returnValue, false);
  60756. b->addShortcut (shortcutKey1);
  60757. b->addShortcut (shortcutKey2);
  60758. b->addButtonListener (this);
  60759. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60760. addAndMakeVisible (b, 0);
  60761. buttons.add (b);
  60762. updateLayout (false);
  60763. }
  60764. int AlertWindow::getNumButtons() const
  60765. {
  60766. return buttons.size();
  60767. }
  60768. void AlertWindow::addTextEditor (const String& name,
  60769. const String& initialContents,
  60770. const String& onScreenLabel,
  60771. const bool isPasswordBox)
  60772. {
  60773. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60774. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60775. tc->setFont (font);
  60776. tc->setText (initialContents);
  60777. tc->setCaretPosition (initialContents.length());
  60778. addAndMakeVisible (tc);
  60779. textBoxes.add (tc);
  60780. allComps.add (tc);
  60781. textboxNames.add (onScreenLabel);
  60782. updateLayout (false);
  60783. }
  60784. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60785. {
  60786. for (int i = textBoxes.size(); --i >= 0;)
  60787. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60788. return ((TextEditor*)textBoxes[i])->getText();
  60789. return String::empty;
  60790. }
  60791. void AlertWindow::addComboBox (const String& name,
  60792. const StringArray& items,
  60793. const String& onScreenLabel)
  60794. {
  60795. ComboBox* const cb = new ComboBox (name);
  60796. for (int i = 0; i < items.size(); ++i)
  60797. cb->addItem (items[i], i + 1);
  60798. addAndMakeVisible (cb);
  60799. cb->setSelectedItemIndex (0);
  60800. comboBoxes.add (cb);
  60801. allComps.add (cb);
  60802. comboBoxNames.add (onScreenLabel);
  60803. updateLayout (false);
  60804. }
  60805. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60806. {
  60807. for (int i = comboBoxes.size(); --i >= 0;)
  60808. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60809. return (ComboBox*) comboBoxes[i];
  60810. return 0;
  60811. }
  60812. class AlertTextComp : public TextEditor
  60813. {
  60814. public:
  60815. AlertTextComp (const String& message,
  60816. const Font& font)
  60817. {
  60818. setReadOnly (true);
  60819. setMultiLine (true, true);
  60820. setCaretVisible (false);
  60821. setScrollbarsShown (true);
  60822. lookAndFeelChanged();
  60823. setWantsKeyboardFocus (false);
  60824. setFont (font);
  60825. setText (message, false);
  60826. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60827. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60828. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60829. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60830. }
  60831. ~AlertTextComp()
  60832. {
  60833. }
  60834. int getPreferredWidth() const throw() { return bestWidth; }
  60835. void updateLayout (const int width)
  60836. {
  60837. TextLayout text;
  60838. text.appendText (getText(), getFont());
  60839. text.layout (width - 8, Justification::topLeft, true);
  60840. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60841. }
  60842. private:
  60843. int bestWidth;
  60844. AlertTextComp (const AlertTextComp&);
  60845. AlertTextComp& operator= (const AlertTextComp&);
  60846. };
  60847. void AlertWindow::addTextBlock (const String& text)
  60848. {
  60849. AlertTextComp* const c = new AlertTextComp (text, font);
  60850. textBlocks.add (c);
  60851. allComps.add (c);
  60852. addAndMakeVisible (c);
  60853. updateLayout (false);
  60854. }
  60855. void AlertWindow::addProgressBarComponent (double& progressValue)
  60856. {
  60857. ProgressBar* const pb = new ProgressBar (progressValue);
  60858. progressBars.add (pb);
  60859. allComps.add (pb);
  60860. addAndMakeVisible (pb);
  60861. updateLayout (false);
  60862. }
  60863. void AlertWindow::addCustomComponent (Component* const component)
  60864. {
  60865. customComps.add (component);
  60866. allComps.add (component);
  60867. addAndMakeVisible (component);
  60868. updateLayout (false);
  60869. }
  60870. int AlertWindow::getNumCustomComponents() const
  60871. {
  60872. return customComps.size();
  60873. }
  60874. Component* AlertWindow::getCustomComponent (const int index) const
  60875. {
  60876. return (Component*) customComps [index];
  60877. }
  60878. Component* AlertWindow::removeCustomComponent (const int index)
  60879. {
  60880. Component* const c = getCustomComponent (index);
  60881. if (c != 0)
  60882. {
  60883. customComps.removeValue (c);
  60884. allComps.removeValue (c);
  60885. removeChildComponent (c);
  60886. updateLayout (false);
  60887. }
  60888. return c;
  60889. }
  60890. void AlertWindow::paint (Graphics& g)
  60891. {
  60892. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60893. g.setColour (findColour (textColourId));
  60894. g.setFont (getLookAndFeel().getAlertWindowFont());
  60895. int i;
  60896. for (i = textBoxes.size(); --i >= 0;)
  60897. {
  60898. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60899. g.drawFittedText (textboxNames[i],
  60900. te->getX(), te->getY() - 14,
  60901. te->getWidth(), 14,
  60902. Justification::centredLeft, 1);
  60903. }
  60904. for (i = comboBoxNames.size(); --i >= 0;)
  60905. {
  60906. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  60907. g.drawFittedText (comboBoxNames[i],
  60908. cb->getX(), cb->getY() - 14,
  60909. cb->getWidth(), 14,
  60910. Justification::centredLeft, 1);
  60911. }
  60912. for (i = customComps.size(); --i >= 0;)
  60913. {
  60914. const Component* const c = (Component*) customComps[i];
  60915. g.drawFittedText (c->getName(),
  60916. c->getX(), c->getY() - 14,
  60917. c->getWidth(), 14,
  60918. Justification::centredLeft, 1);
  60919. }
  60920. }
  60921. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  60922. {
  60923. const int wid = jmax (font.getStringWidth (text),
  60924. font.getStringWidth (getName()));
  60925. const int sw = (int) sqrt (font.getHeight() * wid);
  60926. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  60927. const int edgeGap = 10;
  60928. const int labelHeight = 18;
  60929. int iconSpace;
  60930. if (alertIconType == NoIcon)
  60931. {
  60932. textLayout.layout (w, Justification::horizontallyCentred, true);
  60933. iconSpace = 0;
  60934. }
  60935. else
  60936. {
  60937. textLayout.layout (w, Justification::left, true);
  60938. iconSpace = iconWidth;
  60939. }
  60940. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  60941. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60942. const int textLayoutH = textLayout.getHeight();
  60943. const int textBottom = 16 + titleH + textLayoutH;
  60944. int h = textBottom;
  60945. int buttonW = 40;
  60946. int i;
  60947. for (i = 0; i < buttons.size(); ++i)
  60948. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  60949. w = jmax (buttonW, w);
  60950. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  60951. if (buttons.size() > 0)
  60952. h += 20 + ((TextButton*) buttons[0])->getHeight();
  60953. for (i = customComps.size(); --i >= 0;)
  60954. {
  60955. Component* c = (Component*) customComps[i];
  60956. w = jmax (w, (c->getWidth() * 100) / 80);
  60957. h += 10 + c->getHeight();
  60958. if (c->getName().isNotEmpty())
  60959. h += labelHeight;
  60960. }
  60961. for (i = textBlocks.size(); --i >= 0;)
  60962. {
  60963. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60964. w = jmax (w, ac->getPreferredWidth());
  60965. }
  60966. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60967. for (i = textBlocks.size(); --i >= 0;)
  60968. {
  60969. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60970. ac->updateLayout ((int) (w * 0.8f));
  60971. h += ac->getHeight() + 10;
  60972. }
  60973. h = jmin (getParentHeight() - 50, h);
  60974. if (onlyIncreaseSize)
  60975. {
  60976. w = jmax (w, getWidth());
  60977. h = jmax (h, getHeight());
  60978. }
  60979. if (! isVisible())
  60980. {
  60981. centreAroundComponent (associatedComponent, w, h);
  60982. }
  60983. else
  60984. {
  60985. const int cx = getX() + getWidth() / 2;
  60986. const int cy = getY() + getHeight() / 2;
  60987. setBounds (cx - w / 2,
  60988. cy - h / 2,
  60989. w, h);
  60990. }
  60991. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  60992. const int spacer = 16;
  60993. int totalWidth = -spacer;
  60994. for (i = buttons.size(); --i >= 0;)
  60995. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  60996. int x = (w - totalWidth) / 2;
  60997. int y = (int) (getHeight() * 0.95f);
  60998. for (i = 0; i < buttons.size(); ++i)
  60999. {
  61000. TextButton* const c = (TextButton*) buttons[i];
  61001. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61002. c->setTopLeftPosition (x, ny);
  61003. if (ny < y)
  61004. y = ny;
  61005. x += c->getWidth() + spacer;
  61006. c->toFront (false);
  61007. }
  61008. y = textBottom;
  61009. for (i = 0; i < allComps.size(); ++i)
  61010. {
  61011. Component* const c = (Component*) allComps[i];
  61012. int h = 22;
  61013. const int comboIndex = comboBoxes.indexOf (c);
  61014. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61015. y += labelHeight;
  61016. const int tbIndex = textBoxes.indexOf (c);
  61017. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61018. y += labelHeight;
  61019. if (customComps.contains (c))
  61020. {
  61021. if (c->getName().isNotEmpty())
  61022. y += labelHeight;
  61023. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61024. h = c->getHeight();
  61025. }
  61026. else if (textBlocks.contains (c))
  61027. {
  61028. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61029. h = c->getHeight();
  61030. }
  61031. else
  61032. {
  61033. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61034. }
  61035. y += h + 10;
  61036. }
  61037. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61038. }
  61039. bool AlertWindow::containsAnyExtraComponents() const
  61040. {
  61041. return textBoxes.size()
  61042. + comboBoxes.size()
  61043. + progressBars.size()
  61044. + customComps.size() > 0;
  61045. }
  61046. void AlertWindow::mouseDown (const MouseEvent&)
  61047. {
  61048. dragger.startDraggingComponent (this, &constrainer);
  61049. }
  61050. void AlertWindow::mouseDrag (const MouseEvent& e)
  61051. {
  61052. dragger.dragComponent (this, e);
  61053. }
  61054. bool AlertWindow::keyPressed (const KeyPress& key)
  61055. {
  61056. for (int i = buttons.size(); --i >= 0;)
  61057. {
  61058. TextButton* const b = (TextButton*) buttons[i];
  61059. if (b->isRegisteredForShortcut (key))
  61060. {
  61061. b->triggerClick();
  61062. return true;
  61063. }
  61064. }
  61065. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61066. {
  61067. exitModalState (0);
  61068. return true;
  61069. }
  61070. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61071. {
  61072. ((TextButton*) buttons.getFirst())->triggerClick();
  61073. return true;
  61074. }
  61075. return false;
  61076. }
  61077. void AlertWindow::lookAndFeelChanged()
  61078. {
  61079. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61080. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61081. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61082. }
  61083. int AlertWindow::getDesktopWindowStyleFlags() const
  61084. {
  61085. return getLookAndFeel().getAlertBoxWindowFlags();
  61086. }
  61087. struct AlertWindowInfo
  61088. {
  61089. String title, message, button1, button2, button3;
  61090. AlertWindow::AlertIconType iconType;
  61091. int numButtons;
  61092. Component::SafePointer<Component> associatedComponent;
  61093. int run() const
  61094. {
  61095. return (int) (pointer_sized_int)
  61096. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61097. }
  61098. private:
  61099. int show() const
  61100. {
  61101. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61102. : LookAndFeel::getDefaultLookAndFeel();
  61103. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61104. iconType, numButtons, associatedComponent));
  61105. jassert (alertBox != 0); // you have to return one of these!
  61106. return alertBox->runModalLoop();
  61107. }
  61108. static void* showCallback (void* userData)
  61109. {
  61110. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61111. }
  61112. };
  61113. void AlertWindow::showMessageBox (AlertIconType iconType,
  61114. const String& title,
  61115. const String& message,
  61116. const String& buttonText,
  61117. Component* associatedComponent)
  61118. {
  61119. AlertWindowInfo info;
  61120. info.title = title;
  61121. info.message = message;
  61122. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61123. info.iconType = iconType;
  61124. info.numButtons = 1;
  61125. info.associatedComponent = associatedComponent;
  61126. info.run();
  61127. }
  61128. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61129. const String& title,
  61130. const String& message,
  61131. const String& button1Text,
  61132. const String& button2Text,
  61133. Component* associatedComponent)
  61134. {
  61135. AlertWindowInfo info;
  61136. info.title = title;
  61137. info.message = message;
  61138. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61139. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61140. info.iconType = iconType;
  61141. info.numButtons = 2;
  61142. info.associatedComponent = associatedComponent;
  61143. return info.run() != 0;
  61144. }
  61145. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61146. const String& title,
  61147. const String& message,
  61148. const String& button1Text,
  61149. const String& button2Text,
  61150. const String& button3Text,
  61151. Component* associatedComponent)
  61152. {
  61153. AlertWindowInfo info;
  61154. info.title = title;
  61155. info.message = message;
  61156. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61157. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61158. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61159. info.iconType = iconType;
  61160. info.numButtons = 3;
  61161. info.associatedComponent = associatedComponent;
  61162. return info.run();
  61163. }
  61164. END_JUCE_NAMESPACE
  61165. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61166. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61167. BEGIN_JUCE_NAMESPACE
  61168. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61169. static VoidArray heavyweightPeers;
  61170. ComponentPeer::ComponentPeer (Component* const component_,
  61171. const int styleFlags_) throw()
  61172. : component (component_),
  61173. styleFlags (styleFlags_),
  61174. lastPaintTime (0),
  61175. constrainer (0),
  61176. lastDragAndDropCompUnderMouse (0),
  61177. fakeMouseMessageSent (false),
  61178. isWindowMinimised (false)
  61179. {
  61180. heavyweightPeers.add (this);
  61181. }
  61182. ComponentPeer::~ComponentPeer()
  61183. {
  61184. heavyweightPeers.removeValue (this);
  61185. Desktop::getInstance().triggerFocusCallback();
  61186. }
  61187. int ComponentPeer::getNumPeers() throw()
  61188. {
  61189. return heavyweightPeers.size();
  61190. }
  61191. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61192. {
  61193. return (ComponentPeer*) heavyweightPeers [index];
  61194. }
  61195. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61196. {
  61197. for (int i = heavyweightPeers.size(); --i >= 0;)
  61198. {
  61199. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61200. if (peer->getComponent() == component)
  61201. return peer;
  61202. }
  61203. return 0;
  61204. }
  61205. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61206. {
  61207. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61208. }
  61209. void ComponentPeer::updateCurrentModifiers() throw()
  61210. {
  61211. ModifierKeys::updateCurrentModifiers();
  61212. }
  61213. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61214. {
  61215. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61216. jassert (mouse != 0); // not enough sources!
  61217. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61218. }
  61219. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61220. {
  61221. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61222. jassert (mouse != 0); // not enough sources!
  61223. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61224. }
  61225. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61226. {
  61227. Graphics g (&contextToPaintTo);
  61228. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61229. g.saveState();
  61230. #endif
  61231. JUCE_TRY
  61232. {
  61233. component->paintEntireComponent (g);
  61234. }
  61235. JUCE_CATCH_EXCEPTION
  61236. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61237. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61238. // clearly when things are being repainted.
  61239. {
  61240. g.restoreState();
  61241. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61242. (uint8) Random::getSystemRandom().nextInt (255),
  61243. (uint8) Random::getSystemRandom().nextInt (255),
  61244. (uint8) 0x50));
  61245. }
  61246. #endif
  61247. }
  61248. bool ComponentPeer::handleKeyPress (const int keyCode,
  61249. const juce_wchar textCharacter)
  61250. {
  61251. updateCurrentModifiers();
  61252. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61253. ? Component::getCurrentlyFocusedComponent()
  61254. : component;
  61255. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61256. {
  61257. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61258. if (currentModalComp != 0)
  61259. target = currentModalComp;
  61260. }
  61261. const KeyPress keyInfo (keyCode,
  61262. ModifierKeys::getCurrentModifiers().getRawFlags()
  61263. & ModifierKeys::allKeyboardModifiers,
  61264. textCharacter);
  61265. bool keyWasUsed = false;
  61266. while (target != 0)
  61267. {
  61268. const Component::SafePointer<Component> deletionChecker (target);
  61269. if (target->keyListeners_ != 0)
  61270. {
  61271. for (int i = target->keyListeners_->size(); --i >= 0;)
  61272. {
  61273. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61274. if (keyWasUsed || deletionChecker == 0)
  61275. return keyWasUsed;
  61276. i = jmin (i, target->keyListeners_->size());
  61277. }
  61278. }
  61279. keyWasUsed = target->keyPressed (keyInfo);
  61280. if (keyWasUsed || deletionChecker == 0)
  61281. break;
  61282. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61283. {
  61284. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61285. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61286. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61287. break;
  61288. }
  61289. target = target->parentComponent_;
  61290. }
  61291. return keyWasUsed;
  61292. }
  61293. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61294. {
  61295. updateCurrentModifiers();
  61296. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61297. ? Component::getCurrentlyFocusedComponent()
  61298. : component;
  61299. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61300. {
  61301. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61302. if (currentModalComp != 0)
  61303. target = currentModalComp;
  61304. }
  61305. bool keyWasUsed = false;
  61306. while (target != 0)
  61307. {
  61308. const Component::SafePointer<Component> deletionChecker (target);
  61309. keyWasUsed = target->keyStateChanged (isKeyDown);
  61310. if (keyWasUsed || deletionChecker == 0)
  61311. break;
  61312. if (target->keyListeners_ != 0)
  61313. {
  61314. for (int i = target->keyListeners_->size(); --i >= 0;)
  61315. {
  61316. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61317. if (keyWasUsed || deletionChecker == 0)
  61318. return keyWasUsed;
  61319. i = jmin (i, target->keyListeners_->size());
  61320. }
  61321. }
  61322. target = target->parentComponent_;
  61323. }
  61324. return keyWasUsed;
  61325. }
  61326. void ComponentPeer::handleModifierKeysChange()
  61327. {
  61328. updateCurrentModifiers();
  61329. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61330. if (target == 0)
  61331. target = Component::getCurrentlyFocusedComponent();
  61332. if (target == 0)
  61333. target = component;
  61334. if (target != 0)
  61335. target->internalModifierKeysChanged();
  61336. }
  61337. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61338. {
  61339. Component* const c = Component::getCurrentlyFocusedComponent();
  61340. if (component->isParentOf (c))
  61341. return dynamic_cast <TextInputTarget*> (c);
  61342. return 0;
  61343. }
  61344. void ComponentPeer::handleBroughtToFront()
  61345. {
  61346. updateCurrentModifiers();
  61347. if (component != 0)
  61348. component->internalBroughtToFront();
  61349. }
  61350. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61351. {
  61352. constrainer = newConstrainer;
  61353. }
  61354. void ComponentPeer::handleMovedOrResized()
  61355. {
  61356. jassert (component->isValidComponent());
  61357. updateCurrentModifiers();
  61358. const bool nowMinimised = isMinimised();
  61359. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61360. {
  61361. const Component::SafePointer<Component> deletionChecker (component);
  61362. const Rectangle<int> newBounds (getBounds());
  61363. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61364. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61365. if (wasMoved || wasResized)
  61366. {
  61367. component->bounds_ = newBounds;
  61368. if (wasResized)
  61369. component->repaint();
  61370. component->sendMovedResizedMessages (wasMoved, wasResized);
  61371. if (deletionChecker == 0)
  61372. return;
  61373. }
  61374. }
  61375. if (isWindowMinimised != nowMinimised)
  61376. {
  61377. isWindowMinimised = nowMinimised;
  61378. component->minimisationStateChanged (nowMinimised);
  61379. component->sendVisibilityChangeMessage();
  61380. }
  61381. if (! isFullScreen())
  61382. lastNonFullscreenBounds = component->getBounds();
  61383. }
  61384. void ComponentPeer::handleFocusGain()
  61385. {
  61386. updateCurrentModifiers();
  61387. if (component->isParentOf (lastFocusedComponent))
  61388. {
  61389. Component::currentlyFocusedComponent = lastFocusedComponent;
  61390. Desktop::getInstance().triggerFocusCallback();
  61391. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61392. }
  61393. else
  61394. {
  61395. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61396. component->grabKeyboardFocus();
  61397. else
  61398. Component::bringModalComponentToFront();
  61399. }
  61400. }
  61401. void ComponentPeer::handleFocusLoss()
  61402. {
  61403. updateCurrentModifiers();
  61404. if (component->hasKeyboardFocus (true))
  61405. {
  61406. lastFocusedComponent = Component::currentlyFocusedComponent;
  61407. if (lastFocusedComponent != 0)
  61408. {
  61409. Component::currentlyFocusedComponent = 0;
  61410. Desktop::getInstance().triggerFocusCallback();
  61411. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61412. }
  61413. }
  61414. }
  61415. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61416. {
  61417. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61418. ? static_cast <Component*> (lastFocusedComponent)
  61419. : component;
  61420. }
  61421. void ComponentPeer::handleScreenSizeChange()
  61422. {
  61423. updateCurrentModifiers();
  61424. component->parentSizeChanged();
  61425. handleMovedOrResized();
  61426. }
  61427. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61428. {
  61429. lastNonFullscreenBounds = newBounds;
  61430. }
  61431. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61432. {
  61433. return lastNonFullscreenBounds;
  61434. }
  61435. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61436. const StringArray& files,
  61437. FileDragAndDropTarget* const lastOne)
  61438. {
  61439. while (c != 0)
  61440. {
  61441. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61442. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61443. return t;
  61444. c = c->getParentComponent();
  61445. }
  61446. return 0;
  61447. }
  61448. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61449. {
  61450. updateCurrentModifiers();
  61451. FileDragAndDropTarget* lastTarget
  61452. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61453. FileDragAndDropTarget* newTarget = 0;
  61454. Component* const compUnderMouse = component->getComponentAt (position);
  61455. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61456. {
  61457. lastDragAndDropCompUnderMouse = compUnderMouse;
  61458. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61459. if (newTarget != lastTarget)
  61460. {
  61461. if (lastTarget != 0)
  61462. lastTarget->fileDragExit (files);
  61463. dragAndDropTargetComponent = 0;
  61464. if (newTarget != 0)
  61465. {
  61466. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61467. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61468. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61469. }
  61470. }
  61471. }
  61472. else
  61473. {
  61474. newTarget = lastTarget;
  61475. }
  61476. if (newTarget != 0)
  61477. {
  61478. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61479. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61480. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61481. }
  61482. }
  61483. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61484. {
  61485. handleFileDragMove (files, Point<int> (-1, -1));
  61486. jassert (dragAndDropTargetComponent == 0);
  61487. lastDragAndDropCompUnderMouse = 0;
  61488. }
  61489. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61490. {
  61491. handleFileDragMove (files, position);
  61492. if (dragAndDropTargetComponent != 0)
  61493. {
  61494. FileDragAndDropTarget* const target
  61495. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61496. dragAndDropTargetComponent = 0;
  61497. lastDragAndDropCompUnderMouse = 0;
  61498. if (target != 0)
  61499. {
  61500. Component* const targetComp = dynamic_cast <Component*> (target);
  61501. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61502. {
  61503. targetComp->internalModalInputAttempt();
  61504. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61505. return;
  61506. }
  61507. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61508. target->filesDropped (files, pos.getX(), pos.getY());
  61509. }
  61510. }
  61511. }
  61512. void ComponentPeer::handleUserClosingWindow()
  61513. {
  61514. updateCurrentModifiers();
  61515. component->userTriedToCloseWindow();
  61516. }
  61517. void ComponentPeer::bringModalComponentToFront()
  61518. {
  61519. Component::bringModalComponentToFront();
  61520. }
  61521. void ComponentPeer::clearMaskedRegion() throw()
  61522. {
  61523. maskedRegion.clear();
  61524. }
  61525. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61526. {
  61527. maskedRegion.add (x, y, w, h);
  61528. }
  61529. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61530. {
  61531. StringArray s;
  61532. s.add ("Software Renderer");
  61533. return s;
  61534. }
  61535. int ComponentPeer::getCurrentRenderingEngine() throw()
  61536. {
  61537. return 0;
  61538. }
  61539. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61540. {
  61541. }
  61542. END_JUCE_NAMESPACE
  61543. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61544. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61545. BEGIN_JUCE_NAMESPACE
  61546. DialogWindow::DialogWindow (const String& name,
  61547. const Colour& backgroundColour_,
  61548. const bool escapeKeyTriggersCloseButton_,
  61549. const bool addToDesktop_)
  61550. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61551. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61552. {
  61553. }
  61554. DialogWindow::~DialogWindow()
  61555. {
  61556. }
  61557. void DialogWindow::resized()
  61558. {
  61559. DocumentWindow::resized();
  61560. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61561. if (escapeKeyTriggersCloseButton
  61562. && getCloseButton() != 0
  61563. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61564. {
  61565. getCloseButton()->addShortcut (esc);
  61566. }
  61567. }
  61568. class TempDialogWindow : public DialogWindow
  61569. {
  61570. public:
  61571. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61572. : DialogWindow (title, colour, escapeCloses, true)
  61573. {
  61574. }
  61575. ~TempDialogWindow()
  61576. {
  61577. }
  61578. void closeButtonPressed()
  61579. {
  61580. setVisible (false);
  61581. }
  61582. private:
  61583. TempDialogWindow (const TempDialogWindow&);
  61584. TempDialogWindow& operator= (const TempDialogWindow&);
  61585. };
  61586. int DialogWindow::showModalDialog (const String& dialogTitle,
  61587. Component* contentComponent,
  61588. Component* componentToCentreAround,
  61589. const Colour& colour,
  61590. const bool escapeKeyTriggersCloseButton,
  61591. const bool shouldBeResizable,
  61592. const bool useBottomRightCornerResizer)
  61593. {
  61594. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61595. dw.setContentComponent (contentComponent, true, true);
  61596. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61597. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61598. const int result = dw.runModalLoop();
  61599. dw.setContentComponent (0, false);
  61600. return result;
  61601. }
  61602. END_JUCE_NAMESPACE
  61603. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61604. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61605. BEGIN_JUCE_NAMESPACE
  61606. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61607. {
  61608. public:
  61609. ButtonListenerProxy (DocumentWindow& owner_)
  61610. : owner (owner_)
  61611. {
  61612. }
  61613. void buttonClicked (Button* button)
  61614. {
  61615. if (button == owner.getMinimiseButton())
  61616. owner.minimiseButtonPressed();
  61617. else if (button == owner.getMaximiseButton())
  61618. owner.maximiseButtonPressed();
  61619. else if (button == owner.getCloseButton())
  61620. owner.closeButtonPressed();
  61621. }
  61622. juce_UseDebuggingNewOperator
  61623. private:
  61624. DocumentWindow& owner;
  61625. ButtonListenerProxy (const ButtonListenerProxy&);
  61626. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61627. };
  61628. DocumentWindow::DocumentWindow (const String& title,
  61629. const Colour& backgroundColour,
  61630. const int requiredButtons_,
  61631. const bool addToDesktop_)
  61632. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61633. titleBarHeight (26),
  61634. menuBarHeight (24),
  61635. requiredButtons (requiredButtons_),
  61636. #if JUCE_MAC
  61637. positionTitleBarButtonsOnLeft (true),
  61638. #else
  61639. positionTitleBarButtonsOnLeft (false),
  61640. #endif
  61641. drawTitleTextCentred (true),
  61642. menuBarModel (0)
  61643. {
  61644. setResizeLimits (128, 128, 32768, 32768);
  61645. lookAndFeelChanged();
  61646. }
  61647. DocumentWindow::~DocumentWindow()
  61648. {
  61649. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61650. titleBarButtons[i] = 0;
  61651. menuBar = 0;
  61652. }
  61653. void DocumentWindow::repaintTitleBar()
  61654. {
  61655. const Rectangle<int> titleBarArea (getTitleBarArea());
  61656. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61657. titleBarArea.getWidth(), titleBarArea.getHeight());
  61658. }
  61659. void DocumentWindow::setName (const String& newName)
  61660. {
  61661. if (newName != getName())
  61662. {
  61663. Component::setName (newName);
  61664. repaintTitleBar();
  61665. }
  61666. }
  61667. void DocumentWindow::setIcon (const Image* imageToUse)
  61668. {
  61669. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61670. repaintTitleBar();
  61671. }
  61672. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61673. {
  61674. titleBarHeight = newHeight;
  61675. resized();
  61676. repaintTitleBar();
  61677. }
  61678. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61679. const bool positionTitleBarButtonsOnLeft_)
  61680. {
  61681. requiredButtons = requiredButtons_;
  61682. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61683. lookAndFeelChanged();
  61684. }
  61685. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61686. {
  61687. drawTitleTextCentred = textShouldBeCentred;
  61688. repaintTitleBar();
  61689. }
  61690. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61691. const int menuBarHeight_)
  61692. {
  61693. if (menuBarModel != menuBarModel_)
  61694. {
  61695. menuBar = 0;
  61696. menuBarModel = menuBarModel_;
  61697. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61698. : getLookAndFeel().getDefaultMenuBarHeight();
  61699. if (menuBarModel != 0)
  61700. {
  61701. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61702. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61703. menuBar->setEnabled (isActiveWindow());
  61704. }
  61705. resized();
  61706. }
  61707. }
  61708. void DocumentWindow::closeButtonPressed()
  61709. {
  61710. /* If you've got a close button, you have to override this method to get
  61711. rid of your window!
  61712. If the window is just a pop-up, you should override this method and make
  61713. it delete the window in whatever way is appropriate for your app. E.g. you
  61714. might just want to call "delete this".
  61715. If your app is centred around this window such that the whole app should quit when
  61716. the window is closed, then you will probably want to use this method as an opportunity
  61717. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61718. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61719. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61720. or closing it via the taskbar icon on Windows).
  61721. */
  61722. jassertfalse
  61723. }
  61724. void DocumentWindow::minimiseButtonPressed()
  61725. {
  61726. setMinimised (true);
  61727. }
  61728. void DocumentWindow::maximiseButtonPressed()
  61729. {
  61730. setFullScreen (! isFullScreen());
  61731. }
  61732. void DocumentWindow::paint (Graphics& g)
  61733. {
  61734. ResizableWindow::paint (g);
  61735. if (resizableBorder == 0)
  61736. {
  61737. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61738. const BorderSize border (getBorderThickness());
  61739. g.fillRect (0, 0, getWidth(), border.getTop());
  61740. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61741. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61742. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61743. }
  61744. const Rectangle<int> titleBarArea (getTitleBarArea());
  61745. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61746. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61747. int titleSpaceX1 = 6;
  61748. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61749. for (int i = 0; i < 3; ++i)
  61750. {
  61751. if (titleBarButtons[i] != 0)
  61752. {
  61753. if (positionTitleBarButtonsOnLeft)
  61754. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61755. else
  61756. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61757. }
  61758. }
  61759. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61760. titleBarArea.getWidth(),
  61761. titleBarArea.getHeight(),
  61762. titleSpaceX1,
  61763. jmax (1, titleSpaceX2 - titleSpaceX1),
  61764. titleBarIcon,
  61765. ! drawTitleTextCentred);
  61766. }
  61767. void DocumentWindow::resized()
  61768. {
  61769. ResizableWindow::resized();
  61770. if (titleBarButtons[1] != 0)
  61771. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61772. const Rectangle<int> titleBarArea (getTitleBarArea());
  61773. getLookAndFeel()
  61774. .positionDocumentWindowButtons (*this,
  61775. titleBarArea.getX(), titleBarArea.getY(),
  61776. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61777. titleBarButtons[0],
  61778. titleBarButtons[1],
  61779. titleBarButtons[2],
  61780. positionTitleBarButtonsOnLeft);
  61781. if (menuBar != 0)
  61782. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61783. titleBarArea.getWidth(), menuBarHeight);
  61784. }
  61785. const BorderSize DocumentWindow::getBorderThickness()
  61786. {
  61787. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61788. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61789. }
  61790. const BorderSize DocumentWindow::getContentComponentBorder()
  61791. {
  61792. BorderSize border (getBorderThickness());
  61793. border.setTop (border.getTop()
  61794. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61795. + (menuBar != 0 ? menuBarHeight : 0));
  61796. return border;
  61797. }
  61798. int DocumentWindow::getTitleBarHeight() const
  61799. {
  61800. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61801. }
  61802. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61803. {
  61804. const BorderSize border (getBorderThickness());
  61805. return Rectangle<int> (border.getLeft(), border.getTop(),
  61806. getWidth() - border.getLeftAndRight(),
  61807. getTitleBarHeight());
  61808. }
  61809. Button* DocumentWindow::getCloseButton() const throw()
  61810. {
  61811. return titleBarButtons[2];
  61812. }
  61813. Button* DocumentWindow::getMinimiseButton() const throw()
  61814. {
  61815. return titleBarButtons[0];
  61816. }
  61817. Button* DocumentWindow::getMaximiseButton() const throw()
  61818. {
  61819. return titleBarButtons[1];
  61820. }
  61821. int DocumentWindow::getDesktopWindowStyleFlags() const
  61822. {
  61823. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61824. if ((requiredButtons & minimiseButton) != 0)
  61825. flags |= ComponentPeer::windowHasMinimiseButton;
  61826. if ((requiredButtons & maximiseButton) != 0)
  61827. flags |= ComponentPeer::windowHasMaximiseButton;
  61828. if ((requiredButtons & closeButton) != 0)
  61829. flags |= ComponentPeer::windowHasCloseButton;
  61830. return flags;
  61831. }
  61832. void DocumentWindow::lookAndFeelChanged()
  61833. {
  61834. int i;
  61835. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61836. titleBarButtons[i] = 0;
  61837. if (! isUsingNativeTitleBar())
  61838. {
  61839. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61840. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61841. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61842. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61843. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61844. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61845. for (i = 0; i < 3; ++i)
  61846. {
  61847. if (titleBarButtons[i] != 0)
  61848. {
  61849. if (buttonListener == 0)
  61850. buttonListener = new ButtonListenerProxy (*this);
  61851. titleBarButtons[i]->addButtonListener (buttonListener);
  61852. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61853. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61854. Component::addAndMakeVisible (titleBarButtons[i]);
  61855. }
  61856. }
  61857. if (getCloseButton() != 0)
  61858. {
  61859. #if JUCE_MAC
  61860. getCloseButton()->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
  61861. #else
  61862. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61863. #endif
  61864. }
  61865. }
  61866. activeWindowStatusChanged();
  61867. ResizableWindow::lookAndFeelChanged();
  61868. }
  61869. void DocumentWindow::parentHierarchyChanged()
  61870. {
  61871. lookAndFeelChanged();
  61872. }
  61873. void DocumentWindow::activeWindowStatusChanged()
  61874. {
  61875. ResizableWindow::activeWindowStatusChanged();
  61876. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61877. if (titleBarButtons[i] != 0)
  61878. titleBarButtons[i]->setEnabled (isActiveWindow());
  61879. if (menuBar != 0)
  61880. menuBar->setEnabled (isActiveWindow());
  61881. }
  61882. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61883. {
  61884. if (getTitleBarArea().contains (e.x, e.y)
  61885. && getMaximiseButton() != 0)
  61886. {
  61887. getMaximiseButton()->triggerClick();
  61888. }
  61889. }
  61890. void DocumentWindow::userTriedToCloseWindow()
  61891. {
  61892. closeButtonPressed();
  61893. }
  61894. END_JUCE_NAMESPACE
  61895. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61896. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61897. BEGIN_JUCE_NAMESPACE
  61898. ResizableWindow::ResizableWindow (const String& name,
  61899. const bool addToDesktop_)
  61900. : TopLevelWindow (name, addToDesktop_),
  61901. resizeToFitContent (false),
  61902. fullscreen (false),
  61903. lastNonFullScreenPos (50, 50, 256, 256),
  61904. constrainer (0)
  61905. #ifdef JUCE_DEBUG
  61906. , hasBeenResized (false)
  61907. #endif
  61908. {
  61909. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61910. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  61911. if (addToDesktop_)
  61912. Component::addToDesktop (getDesktopWindowStyleFlags());
  61913. }
  61914. ResizableWindow::ResizableWindow (const String& name,
  61915. const Colour& backgroundColour_,
  61916. const bool addToDesktop_)
  61917. : TopLevelWindow (name, addToDesktop_),
  61918. resizeToFitContent (false),
  61919. fullscreen (false),
  61920. lastNonFullScreenPos (50, 50, 256, 256),
  61921. constrainer (0)
  61922. #ifdef JUCE_DEBUG
  61923. , hasBeenResized (false)
  61924. #endif
  61925. {
  61926. setBackgroundColour (backgroundColour_);
  61927. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61928. if (addToDesktop_)
  61929. Component::addToDesktop (getDesktopWindowStyleFlags());
  61930. }
  61931. ResizableWindow::~ResizableWindow()
  61932. {
  61933. resizableCorner = 0;
  61934. resizableBorder = 0;
  61935. contentComponent = 0;
  61936. // have you been adding your own components directly to this window..? tut tut tut.
  61937. // Read the instructions for using a ResizableWindow!
  61938. jassert (getNumChildComponents() == 0);
  61939. }
  61940. int ResizableWindow::getDesktopWindowStyleFlags() const
  61941. {
  61942. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  61943. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  61944. flags |= ComponentPeer::windowIsResizable;
  61945. return flags;
  61946. }
  61947. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  61948. const bool deleteOldOne,
  61949. const bool resizeToFit)
  61950. {
  61951. resizeToFitContent = resizeToFit;
  61952. if (newContentComponent != (Component*) contentComponent)
  61953. {
  61954. if (! deleteOldOne)
  61955. removeChildComponent (contentComponent.release());
  61956. contentComponent = newContentComponent;
  61957. Component::addAndMakeVisible (contentComponent);
  61958. }
  61959. if (resizeToFit)
  61960. childBoundsChanged (contentComponent);
  61961. resized(); // must always be called to position the new content comp
  61962. }
  61963. void ResizableWindow::setContentComponentSize (int width, int height)
  61964. {
  61965. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  61966. const BorderSize border (getContentComponentBorder());
  61967. setSize (width + border.getLeftAndRight(),
  61968. height + border.getTopAndBottom());
  61969. }
  61970. const BorderSize ResizableWindow::getBorderThickness()
  61971. {
  61972. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  61973. }
  61974. const BorderSize ResizableWindow::getContentComponentBorder()
  61975. {
  61976. return getBorderThickness();
  61977. }
  61978. void ResizableWindow::moved()
  61979. {
  61980. updateLastPos();
  61981. }
  61982. void ResizableWindow::visibilityChanged()
  61983. {
  61984. TopLevelWindow::visibilityChanged();
  61985. updateLastPos();
  61986. }
  61987. void ResizableWindow::resized()
  61988. {
  61989. if (resizableBorder != 0)
  61990. {
  61991. resizableBorder->setVisible (! isFullScreen());
  61992. resizableBorder->setBorderThickness (getBorderThickness());
  61993. resizableBorder->setSize (getWidth(), getHeight());
  61994. resizableBorder->toBack();
  61995. }
  61996. if (resizableCorner != 0)
  61997. {
  61998. resizableCorner->setVisible (! isFullScreen());
  61999. const int resizerSize = 18;
  62000. resizableCorner->setBounds (getWidth() - resizerSize,
  62001. getHeight() - resizerSize,
  62002. resizerSize, resizerSize);
  62003. }
  62004. if (contentComponent != 0)
  62005. contentComponent->setBoundsInset (getContentComponentBorder());
  62006. updateLastPos();
  62007. #ifdef JUCE_DEBUG
  62008. hasBeenResized = true;
  62009. #endif
  62010. }
  62011. void ResizableWindow::childBoundsChanged (Component* child)
  62012. {
  62013. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62014. {
  62015. // not going to look very good if this component has a zero size..
  62016. jassert (child->getWidth() > 0);
  62017. jassert (child->getHeight() > 0);
  62018. const BorderSize borders (getContentComponentBorder());
  62019. setSize (child->getWidth() + borders.getLeftAndRight(),
  62020. child->getHeight() + borders.getTopAndBottom());
  62021. }
  62022. }
  62023. void ResizableWindow::activeWindowStatusChanged()
  62024. {
  62025. const BorderSize borders (getContentComponentBorder());
  62026. repaint (0, 0, getWidth(), borders.getTop());
  62027. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62028. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62029. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62030. }
  62031. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62032. const bool useBottomRightCornerResizer)
  62033. {
  62034. if (shouldBeResizable)
  62035. {
  62036. if (useBottomRightCornerResizer)
  62037. {
  62038. resizableBorder = 0;
  62039. if (resizableCorner == 0)
  62040. {
  62041. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62042. resizableCorner->setAlwaysOnTop (true);
  62043. }
  62044. }
  62045. else
  62046. {
  62047. resizableCorner = 0;
  62048. if (resizableBorder == 0)
  62049. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62050. }
  62051. }
  62052. else
  62053. {
  62054. resizableCorner = 0;
  62055. resizableBorder = 0;
  62056. }
  62057. if (isUsingNativeTitleBar())
  62058. recreateDesktopWindow();
  62059. childBoundsChanged (contentComponent);
  62060. resized();
  62061. }
  62062. bool ResizableWindow::isResizable() const throw()
  62063. {
  62064. return resizableCorner != 0
  62065. || resizableBorder != 0;
  62066. }
  62067. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62068. const int newMinimumHeight,
  62069. const int newMaximumWidth,
  62070. const int newMaximumHeight) throw()
  62071. {
  62072. // if you've set up a custom constrainer then these settings won't have any effect..
  62073. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62074. if (constrainer == 0)
  62075. setConstrainer (&defaultConstrainer);
  62076. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62077. newMaximumWidth, newMaximumHeight);
  62078. setBoundsConstrained (getBounds());
  62079. }
  62080. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62081. {
  62082. if (constrainer != newConstrainer)
  62083. {
  62084. constrainer = newConstrainer;
  62085. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62086. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62087. resizableCorner = 0;
  62088. resizableBorder = 0;
  62089. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62090. ComponentPeer* const peer = getPeer();
  62091. if (peer != 0)
  62092. peer->setConstrainer (newConstrainer);
  62093. }
  62094. }
  62095. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62096. {
  62097. if (constrainer != 0)
  62098. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62099. else
  62100. setBounds (bounds);
  62101. }
  62102. void ResizableWindow::paint (Graphics& g)
  62103. {
  62104. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62105. getBorderThickness(), *this);
  62106. if (! isFullScreen())
  62107. {
  62108. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62109. getBorderThickness(), *this);
  62110. }
  62111. #ifdef JUCE_DEBUG
  62112. /* If this fails, then you've probably written a subclass with a resized()
  62113. callback but forgotten to make it call its parent class's resized() method.
  62114. It's important when you override methods like resized(), moved(),
  62115. etc., that you make sure the base class methods also get called.
  62116. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62117. because your content should all be inside the content component - and it's the
  62118. content component's resized() method that you should be using to do your
  62119. layout.
  62120. */
  62121. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62122. #endif
  62123. }
  62124. void ResizableWindow::lookAndFeelChanged()
  62125. {
  62126. resized();
  62127. if (isOnDesktop())
  62128. {
  62129. Component::addToDesktop (getDesktopWindowStyleFlags());
  62130. ComponentPeer* const peer = getPeer();
  62131. if (peer != 0)
  62132. peer->setConstrainer (constrainer);
  62133. }
  62134. }
  62135. const Colour ResizableWindow::getBackgroundColour() const throw()
  62136. {
  62137. return findColour (backgroundColourId, false);
  62138. }
  62139. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62140. {
  62141. Colour backgroundColour (newColour);
  62142. if (! Desktop::canUseSemiTransparentWindows())
  62143. backgroundColour = newColour.withAlpha (1.0f);
  62144. setColour (backgroundColourId, backgroundColour);
  62145. setOpaque (backgroundColour.isOpaque());
  62146. repaint();
  62147. }
  62148. bool ResizableWindow::isFullScreen() const
  62149. {
  62150. if (isOnDesktop())
  62151. {
  62152. ComponentPeer* const peer = getPeer();
  62153. return peer != 0 && peer->isFullScreen();
  62154. }
  62155. return fullscreen;
  62156. }
  62157. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62158. {
  62159. if (shouldBeFullScreen != isFullScreen())
  62160. {
  62161. updateLastPos();
  62162. fullscreen = shouldBeFullScreen;
  62163. if (isOnDesktop())
  62164. {
  62165. ComponentPeer* const peer = getPeer();
  62166. if (peer != 0)
  62167. {
  62168. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62169. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62170. peer->setFullScreen (shouldBeFullScreen);
  62171. if (! shouldBeFullScreen)
  62172. setBounds (lastPos);
  62173. }
  62174. else
  62175. {
  62176. jassertfalse
  62177. }
  62178. }
  62179. else
  62180. {
  62181. if (shouldBeFullScreen)
  62182. setBounds (0, 0, getParentWidth(), getParentHeight());
  62183. else
  62184. setBounds (lastNonFullScreenPos);
  62185. }
  62186. resized();
  62187. }
  62188. }
  62189. bool ResizableWindow::isMinimised() const
  62190. {
  62191. ComponentPeer* const peer = getPeer();
  62192. return (peer != 0) && peer->isMinimised();
  62193. }
  62194. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62195. {
  62196. if (shouldMinimise != isMinimised())
  62197. {
  62198. ComponentPeer* const peer = getPeer();
  62199. if (peer != 0)
  62200. {
  62201. updateLastPos();
  62202. peer->setMinimised (shouldMinimise);
  62203. }
  62204. else
  62205. {
  62206. jassertfalse
  62207. }
  62208. }
  62209. }
  62210. void ResizableWindow::updateLastPos()
  62211. {
  62212. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62213. {
  62214. lastNonFullScreenPos = getBounds();
  62215. }
  62216. }
  62217. void ResizableWindow::parentSizeChanged()
  62218. {
  62219. if (isFullScreen() && getParentComponent() != 0)
  62220. {
  62221. setBounds (0, 0, getParentWidth(), getParentHeight());
  62222. }
  62223. }
  62224. const String ResizableWindow::getWindowStateAsString()
  62225. {
  62226. updateLastPos();
  62227. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62228. }
  62229. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62230. {
  62231. StringArray tokens;
  62232. tokens.addTokens (s, false);
  62233. tokens.removeEmptyStrings();
  62234. tokens.trim();
  62235. const bool fs = tokens[0].startsWithIgnoreCase ("fs");
  62236. const int firstCoord = fs ? 1 : 0;
  62237. if (tokens.size() != firstCoord + 4)
  62238. return false;
  62239. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62240. tokens[firstCoord + 1].getIntValue(),
  62241. tokens[firstCoord + 2].getIntValue(),
  62242. tokens[firstCoord + 3].getIntValue());
  62243. if (newPos.isEmpty())
  62244. return false;
  62245. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62246. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62247. if (peer != 0)
  62248. peer->getFrameSize().addTo (newPos);
  62249. if (! screen.contains (newPos))
  62250. {
  62251. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62252. jmin (newPos.getHeight(), screen.getHeight()));
  62253. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62254. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62255. }
  62256. if (peer != 0)
  62257. {
  62258. peer->getFrameSize().subtractFrom (newPos);
  62259. peer->setNonFullScreenBounds (newPos);
  62260. }
  62261. lastNonFullScreenPos = newPos;
  62262. setFullScreen (fs);
  62263. if (! fs)
  62264. setBoundsConstrained (newPos);
  62265. return true;
  62266. }
  62267. void ResizableWindow::mouseDown (const MouseEvent&)
  62268. {
  62269. if (! isFullScreen())
  62270. dragger.startDraggingComponent (this, constrainer);
  62271. }
  62272. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62273. {
  62274. if (! isFullScreen())
  62275. dragger.dragComponent (this, e);
  62276. }
  62277. #ifdef JUCE_DEBUG
  62278. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62279. {
  62280. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62281. manages its child components automatically, and if you add your own it'll cause
  62282. trouble. Instead, use setContentComponent() to give it a component which
  62283. will be automatically resized and kept in the right place - then you can add
  62284. subcomponents to the content comp. See the notes for the ResizableWindow class
  62285. for more info.
  62286. If you really know what you're doing and want to avoid this assertion, just call
  62287. Component::addChildComponent directly.
  62288. */
  62289. jassertfalse
  62290. Component::addChildComponent (child, zOrder);
  62291. }
  62292. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62293. {
  62294. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62295. manages its child components automatically, and if you add your own it'll cause
  62296. trouble. Instead, use setContentComponent() to give it a component which
  62297. will be automatically resized and kept in the right place - then you can add
  62298. subcomponents to the content comp. See the notes for the ResizableWindow class
  62299. for more info.
  62300. If you really know what you're doing and want to avoid this assertion, just call
  62301. Component::addAndMakeVisible directly.
  62302. */
  62303. jassertfalse
  62304. Component::addAndMakeVisible (child, zOrder);
  62305. }
  62306. #endif
  62307. END_JUCE_NAMESPACE
  62308. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62309. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62310. BEGIN_JUCE_NAMESPACE
  62311. SplashScreen::SplashScreen()
  62312. : backgroundImage (0)
  62313. {
  62314. setOpaque (true);
  62315. }
  62316. SplashScreen::~SplashScreen()
  62317. {
  62318. ImageCache::releaseOrDelete (backgroundImage);
  62319. }
  62320. void SplashScreen::show (const String& title,
  62321. Image* const backgroundImage_,
  62322. const int minimumTimeToDisplayFor,
  62323. const bool useDropShadow,
  62324. const bool removeOnMouseClick)
  62325. {
  62326. backgroundImage = backgroundImage_;
  62327. jassert (backgroundImage_ != 0);
  62328. if (backgroundImage_ != 0)
  62329. {
  62330. setOpaque (! backgroundImage_->hasAlphaChannel());
  62331. show (title,
  62332. backgroundImage_->getWidth(),
  62333. backgroundImage_->getHeight(),
  62334. minimumTimeToDisplayFor,
  62335. useDropShadow,
  62336. removeOnMouseClick);
  62337. }
  62338. }
  62339. void SplashScreen::show (const String& title,
  62340. const int width,
  62341. const int height,
  62342. const int minimumTimeToDisplayFor,
  62343. const bool useDropShadow,
  62344. const bool removeOnMouseClick)
  62345. {
  62346. setName (title);
  62347. setAlwaysOnTop (true);
  62348. setVisible (true);
  62349. centreWithSize (width, height);
  62350. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62351. toFront (false);
  62352. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62353. repaint();
  62354. originalClickCounter = removeOnMouseClick
  62355. ? Desktop::getMouseButtonClickCounter()
  62356. : std::numeric_limits<int>::max();
  62357. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62358. startTimer (50);
  62359. }
  62360. void SplashScreen::paint (Graphics& g)
  62361. {
  62362. if (backgroundImage != 0)
  62363. {
  62364. g.setOpacity (1.0f);
  62365. g.drawImage (backgroundImage,
  62366. 0, 0, getWidth(), getHeight(),
  62367. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62368. }
  62369. }
  62370. void SplashScreen::timerCallback()
  62371. {
  62372. if (Time::getCurrentTime() > earliestTimeToDelete
  62373. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62374. {
  62375. delete this;
  62376. }
  62377. }
  62378. END_JUCE_NAMESPACE
  62379. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62380. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62381. BEGIN_JUCE_NAMESPACE
  62382. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62383. const bool hasProgressBar,
  62384. const bool hasCancelButton,
  62385. const int timeOutMsWhenCancelling_,
  62386. const String& cancelButtonText)
  62387. : Thread ("Juce Progress Window"),
  62388. progress (0.0),
  62389. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62390. {
  62391. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62392. .createAlertWindow (title, String::empty, cancelButtonText,
  62393. String::empty, String::empty,
  62394. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62395. if (hasProgressBar)
  62396. alertWindow->addProgressBarComponent (progress);
  62397. }
  62398. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62399. {
  62400. stopThread (timeOutMsWhenCancelling);
  62401. }
  62402. bool ThreadWithProgressWindow::runThread (const int priority)
  62403. {
  62404. startThread (priority);
  62405. startTimer (100);
  62406. {
  62407. const ScopedLock sl (messageLock);
  62408. alertWindow->setMessage (message);
  62409. }
  62410. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62411. stopThread (timeOutMsWhenCancelling);
  62412. alertWindow->setVisible (false);
  62413. return finishedNaturally;
  62414. }
  62415. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62416. {
  62417. progress = newProgress;
  62418. }
  62419. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62420. {
  62421. const ScopedLock sl (messageLock);
  62422. message = newStatusMessage;
  62423. }
  62424. void ThreadWithProgressWindow::timerCallback()
  62425. {
  62426. if (! isThreadRunning())
  62427. {
  62428. // thread has finished normally..
  62429. alertWindow->exitModalState (1);
  62430. alertWindow->setVisible (false);
  62431. }
  62432. else
  62433. {
  62434. const ScopedLock sl (messageLock);
  62435. alertWindow->setMessage (message);
  62436. }
  62437. }
  62438. END_JUCE_NAMESPACE
  62439. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62440. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62441. BEGIN_JUCE_NAMESPACE
  62442. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62443. const int millisecondsBeforeTipAppears_)
  62444. : Component ("tooltip"),
  62445. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62446. lastHideTime (0),
  62447. lastComponentUnderMouse (0),
  62448. changedCompsSinceShown (true)
  62449. {
  62450. if (Desktop::getInstance().getMainMouseSource().canHover())
  62451. startTimer (123);
  62452. setAlwaysOnTop (true);
  62453. setOpaque (true);
  62454. if (parentComponent != 0)
  62455. parentComponent->addChildComponent (this);
  62456. }
  62457. TooltipWindow::~TooltipWindow()
  62458. {
  62459. hide();
  62460. }
  62461. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62462. {
  62463. millisecondsBeforeTipAppears = newTimeMs;
  62464. }
  62465. void TooltipWindow::paint (Graphics& g)
  62466. {
  62467. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62468. }
  62469. void TooltipWindow::mouseEnter (const MouseEvent&)
  62470. {
  62471. hide();
  62472. }
  62473. void TooltipWindow::showFor (const String& tip)
  62474. {
  62475. jassert (tip.isNotEmpty());
  62476. tipShowing = tip;
  62477. Point<int> mousePos (Desktop::getMousePosition());
  62478. if (getParentComponent() != 0)
  62479. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62480. int x, y, w, h;
  62481. getLookAndFeel().getTooltipSize (tip, w, h);
  62482. if (mousePos.getX() > getParentWidth() / 2)
  62483. x = mousePos.getX() - (w + 12);
  62484. else
  62485. x = mousePos.getX() + 24;
  62486. if (mousePos.getY() > getParentHeight() / 2)
  62487. y = mousePos.getY() - (h + 6);
  62488. else
  62489. y = mousePos.getY() + 6;
  62490. setBounds (x, y, w, h);
  62491. setVisible (true);
  62492. if (getParentComponent() == 0)
  62493. {
  62494. addToDesktop (ComponentPeer::windowHasDropShadow
  62495. | ComponentPeer::windowIsTemporary
  62496. | ComponentPeer::windowIgnoresKeyPresses);
  62497. }
  62498. toFront (false);
  62499. }
  62500. const String TooltipWindow::getTipFor (Component* const c)
  62501. {
  62502. if (c != 0
  62503. && Process::isForegroundProcess()
  62504. && ! Component::isMouseButtonDownAnywhere())
  62505. {
  62506. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62507. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62508. return ttc->getTooltip();
  62509. }
  62510. return String::empty;
  62511. }
  62512. void TooltipWindow::hide()
  62513. {
  62514. tipShowing = String::empty;
  62515. removeFromDesktop();
  62516. setVisible (false);
  62517. }
  62518. void TooltipWindow::timerCallback()
  62519. {
  62520. const unsigned int now = Time::getApproximateMillisecondCounter();
  62521. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62522. const String newTip (getTipFor (newComp));
  62523. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62524. lastComponentUnderMouse = newComp;
  62525. lastTipUnderMouse = newTip;
  62526. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62527. const bool mouseWasClicked = clickCount > mouseClicks;
  62528. mouseClicks = clickCount;
  62529. const Point<int> mousePos (Desktop::getMousePosition());
  62530. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62531. lastMousePos = mousePos;
  62532. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62533. lastCompChangeTime = now;
  62534. if (isVisible() || now < lastHideTime + 500)
  62535. {
  62536. // if a tip is currently visible (or has just disappeared), update to a new one
  62537. // immediately if needed..
  62538. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62539. {
  62540. if (isVisible())
  62541. {
  62542. lastHideTime = now;
  62543. hide();
  62544. }
  62545. }
  62546. else if (tipChanged)
  62547. {
  62548. showFor (newTip);
  62549. }
  62550. }
  62551. else
  62552. {
  62553. // if there isn't currently a tip, but one is needed, only let it
  62554. // appear after a timeout..
  62555. if (newTip.isNotEmpty()
  62556. && newTip != tipShowing
  62557. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62558. {
  62559. showFor (newTip);
  62560. }
  62561. }
  62562. }
  62563. END_JUCE_NAMESPACE
  62564. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62565. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62566. BEGIN_JUCE_NAMESPACE
  62567. class TopLevelWindowManager : public Timer,
  62568. public DeletedAtShutdown
  62569. {
  62570. public:
  62571. TopLevelWindowManager()
  62572. : currentActive (0)
  62573. {
  62574. }
  62575. ~TopLevelWindowManager()
  62576. {
  62577. clearSingletonInstance();
  62578. }
  62579. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62580. void timerCallback()
  62581. {
  62582. startTimer (jmin (1731, getTimerInterval() * 2));
  62583. TopLevelWindow* active = 0;
  62584. if (Process::isForegroundProcess())
  62585. {
  62586. active = currentActive;
  62587. Component* const c = Component::getCurrentlyFocusedComponent();
  62588. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62589. if (tlw == 0 && c != 0)
  62590. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62591. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62592. if (tlw != 0)
  62593. active = tlw;
  62594. }
  62595. if (active != currentActive)
  62596. {
  62597. currentActive = active;
  62598. for (int i = windows.size(); --i >= 0;)
  62599. {
  62600. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62601. tlw->setWindowActive (isWindowActive (tlw));
  62602. i = jmin (i, windows.size() - 1);
  62603. }
  62604. Desktop::getInstance().triggerFocusCallback();
  62605. }
  62606. }
  62607. bool addWindow (TopLevelWindow* const w) throw()
  62608. {
  62609. windows.add (w);
  62610. startTimer (10);
  62611. return isWindowActive (w);
  62612. }
  62613. void removeWindow (TopLevelWindow* const w) throw()
  62614. {
  62615. startTimer (10);
  62616. if (currentActive == w)
  62617. currentActive = 0;
  62618. windows.removeValue (w);
  62619. if (windows.size() == 0)
  62620. deleteInstance();
  62621. }
  62622. VoidArray windows;
  62623. private:
  62624. TopLevelWindow* currentActive;
  62625. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62626. {
  62627. return (tlw == currentActive
  62628. || tlw->isParentOf (currentActive)
  62629. || tlw->hasKeyboardFocus (true))
  62630. && tlw->isShowing();
  62631. }
  62632. TopLevelWindowManager (const TopLevelWindowManager&);
  62633. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62634. };
  62635. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62636. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62637. {
  62638. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62639. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62640. }
  62641. TopLevelWindow::TopLevelWindow (const String& name,
  62642. const bool addToDesktop_)
  62643. : Component (name),
  62644. useDropShadow (true),
  62645. useNativeTitleBar (false),
  62646. windowIsActive_ (false)
  62647. {
  62648. setOpaque (true);
  62649. if (addToDesktop_)
  62650. Component::addToDesktop (getDesktopWindowStyleFlags());
  62651. else
  62652. setDropShadowEnabled (true);
  62653. setWantsKeyboardFocus (true);
  62654. setBroughtToFrontOnMouseClick (true);
  62655. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62656. }
  62657. TopLevelWindow::~TopLevelWindow()
  62658. {
  62659. shadower = 0;
  62660. TopLevelWindowManager::getInstance()->removeWindow (this);
  62661. }
  62662. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62663. {
  62664. if (hasKeyboardFocus (true))
  62665. TopLevelWindowManager::getInstance()->timerCallback();
  62666. else
  62667. TopLevelWindowManager::getInstance()->startTimer (10);
  62668. }
  62669. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62670. {
  62671. if (windowIsActive_ != isNowActive)
  62672. {
  62673. windowIsActive_ = isNowActive;
  62674. activeWindowStatusChanged();
  62675. }
  62676. }
  62677. void TopLevelWindow::activeWindowStatusChanged()
  62678. {
  62679. }
  62680. void TopLevelWindow::parentHierarchyChanged()
  62681. {
  62682. setDropShadowEnabled (useDropShadow);
  62683. }
  62684. void TopLevelWindow::visibilityChanged()
  62685. {
  62686. if (isShowing())
  62687. toFront (true);
  62688. }
  62689. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62690. {
  62691. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62692. if (useDropShadow)
  62693. flags |= ComponentPeer::windowHasDropShadow;
  62694. if (useNativeTitleBar)
  62695. flags |= ComponentPeer::windowHasTitleBar;
  62696. return flags;
  62697. }
  62698. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62699. {
  62700. useDropShadow = useShadow;
  62701. if (isOnDesktop())
  62702. {
  62703. shadower = 0;
  62704. Component::addToDesktop (getDesktopWindowStyleFlags());
  62705. }
  62706. else
  62707. {
  62708. if (useShadow && isOpaque())
  62709. {
  62710. if (shadower == 0)
  62711. {
  62712. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62713. if (shadower != 0)
  62714. shadower->setOwner (this);
  62715. }
  62716. }
  62717. else
  62718. {
  62719. shadower = 0;
  62720. }
  62721. }
  62722. }
  62723. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62724. {
  62725. if (useNativeTitleBar != useNativeTitleBar_)
  62726. {
  62727. useNativeTitleBar = useNativeTitleBar_;
  62728. recreateDesktopWindow();
  62729. sendLookAndFeelChange();
  62730. }
  62731. }
  62732. void TopLevelWindow::recreateDesktopWindow()
  62733. {
  62734. if (isOnDesktop())
  62735. {
  62736. Component::addToDesktop (getDesktopWindowStyleFlags());
  62737. toFront (true);
  62738. }
  62739. }
  62740. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62741. {
  62742. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62743. because this class needs to make sure its layout corresponds with settings like whether
  62744. it's got a native title bar or not.
  62745. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62746. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62747. method, then add or remove whatever flags are necessary from this value before returning it.
  62748. */
  62749. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62750. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62751. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62752. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62753. sendLookAndFeelChange();
  62754. }
  62755. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62756. {
  62757. if (c == 0)
  62758. c = TopLevelWindow::getActiveTopLevelWindow();
  62759. if (c == 0)
  62760. {
  62761. centreWithSize (width, height);
  62762. }
  62763. else
  62764. {
  62765. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62766. (c->getHeight() - height) / 2)));
  62767. Rectangle<int> parentArea (c->getParentMonitorArea());
  62768. if (getParentComponent() != 0)
  62769. {
  62770. p = getParentComponent()->globalPositionToRelative (p);
  62771. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62772. }
  62773. parentArea.reduce (12, 12);
  62774. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62775. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62776. width, height);
  62777. }
  62778. }
  62779. int TopLevelWindow::getNumTopLevelWindows() throw()
  62780. {
  62781. return TopLevelWindowManager::getInstance()->windows.size();
  62782. }
  62783. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62784. {
  62785. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  62786. }
  62787. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62788. {
  62789. TopLevelWindow* best = 0;
  62790. int bestNumTWLParents = -1;
  62791. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62792. {
  62793. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62794. if (tlw->isActiveWindow())
  62795. {
  62796. int numTWLParents = 0;
  62797. const Component* c = tlw->getParentComponent();
  62798. while (c != 0)
  62799. {
  62800. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62801. ++numTWLParents;
  62802. c = c->getParentComponent();
  62803. }
  62804. if (bestNumTWLParents < numTWLParents)
  62805. {
  62806. best = tlw;
  62807. bestNumTWLParents = numTWLParents;
  62808. }
  62809. }
  62810. }
  62811. return best;
  62812. }
  62813. END_JUCE_NAMESPACE
  62814. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62815. /*** Start of inlined file: juce_Colour.cpp ***/
  62816. BEGIN_JUCE_NAMESPACE
  62817. namespace ColourHelpers
  62818. {
  62819. static uint8 floatAlphaToInt (const float alpha) throw()
  62820. {
  62821. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62822. }
  62823. static void convertHSBtoRGB (float h, float s, float v,
  62824. uint8& r, uint8& g, uint8& b) throw()
  62825. {
  62826. v = jlimit (0.0f, 1.0f, v);
  62827. v *= 255.0f;
  62828. const uint8 intV = (uint8) roundToInt (v);
  62829. if (s <= 0)
  62830. {
  62831. r = intV;
  62832. g = intV;
  62833. b = intV;
  62834. }
  62835. else
  62836. {
  62837. s = jmin (1.0f, s);
  62838. h = jlimit (0.0f, 1.0f, h);
  62839. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62840. const float f = h - floorf (h);
  62841. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62842. const float y = v * (1.0f - s * f);
  62843. const float z = v * (1.0f - (s * (1.0f - f)));
  62844. if (h < 1.0f)
  62845. {
  62846. r = intV;
  62847. g = (uint8) roundToInt (z);
  62848. b = x;
  62849. }
  62850. else if (h < 2.0f)
  62851. {
  62852. r = (uint8) roundToInt (y);
  62853. g = intV;
  62854. b = x;
  62855. }
  62856. else if (h < 3.0f)
  62857. {
  62858. r = x;
  62859. g = intV;
  62860. b = (uint8) roundToInt (z);
  62861. }
  62862. else if (h < 4.0f)
  62863. {
  62864. r = x;
  62865. g = (uint8) roundToInt (y);
  62866. b = intV;
  62867. }
  62868. else if (h < 5.0f)
  62869. {
  62870. r = (uint8) roundToInt (z);
  62871. g = x;
  62872. b = intV;
  62873. }
  62874. else if (h < 6.0f)
  62875. {
  62876. r = intV;
  62877. g = x;
  62878. b = (uint8) roundToInt (y);
  62879. }
  62880. else
  62881. {
  62882. r = 0;
  62883. g = 0;
  62884. b = 0;
  62885. }
  62886. }
  62887. }
  62888. }
  62889. Colour::Colour() throw()
  62890. : argb (0)
  62891. {
  62892. }
  62893. Colour::Colour (const Colour& other) throw()
  62894. : argb (other.argb)
  62895. {
  62896. }
  62897. Colour& Colour::operator= (const Colour& other) throw()
  62898. {
  62899. argb = other.argb;
  62900. return *this;
  62901. }
  62902. bool Colour::operator== (const Colour& other) const throw()
  62903. {
  62904. return argb.getARGB() == other.argb.getARGB();
  62905. }
  62906. bool Colour::operator!= (const Colour& other) const throw()
  62907. {
  62908. return argb.getARGB() != other.argb.getARGB();
  62909. }
  62910. Colour::Colour (const uint32 argb_) throw()
  62911. : argb (argb_)
  62912. {
  62913. }
  62914. Colour::Colour (const uint8 red,
  62915. const uint8 green,
  62916. const uint8 blue) throw()
  62917. {
  62918. argb.setARGB (0xff, red, green, blue);
  62919. }
  62920. const Colour Colour::fromRGB (const uint8 red,
  62921. const uint8 green,
  62922. const uint8 blue) throw()
  62923. {
  62924. return Colour (red, green, blue);
  62925. }
  62926. Colour::Colour (const uint8 red,
  62927. const uint8 green,
  62928. const uint8 blue,
  62929. const uint8 alpha) throw()
  62930. {
  62931. argb.setARGB (alpha, red, green, blue);
  62932. }
  62933. const Colour Colour::fromRGBA (const uint8 red,
  62934. const uint8 green,
  62935. const uint8 blue,
  62936. const uint8 alpha) throw()
  62937. {
  62938. return Colour (red, green, blue, alpha);
  62939. }
  62940. Colour::Colour (const uint8 red,
  62941. const uint8 green,
  62942. const uint8 blue,
  62943. const float alpha) throw()
  62944. {
  62945. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  62946. }
  62947. const Colour Colour::fromRGBAFloat (const uint8 red,
  62948. const uint8 green,
  62949. const uint8 blue,
  62950. const float alpha) throw()
  62951. {
  62952. return Colour (red, green, blue, alpha);
  62953. }
  62954. Colour::Colour (const float hue,
  62955. const float saturation,
  62956. const float brightness,
  62957. const float alpha) throw()
  62958. {
  62959. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62960. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62961. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  62962. }
  62963. const Colour Colour::fromHSV (const float hue,
  62964. const float saturation,
  62965. const float brightness,
  62966. const float alpha) throw()
  62967. {
  62968. return Colour (hue, saturation, brightness, alpha);
  62969. }
  62970. Colour::Colour (const float hue,
  62971. const float saturation,
  62972. const float brightness,
  62973. const uint8 alpha) throw()
  62974. {
  62975. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62976. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62977. argb.setARGB (alpha, r, g, b);
  62978. }
  62979. Colour::~Colour() throw()
  62980. {
  62981. }
  62982. const PixelARGB Colour::getPixelARGB() const throw()
  62983. {
  62984. PixelARGB p (argb);
  62985. p.premultiply();
  62986. return p;
  62987. }
  62988. uint32 Colour::getARGB() const throw()
  62989. {
  62990. return argb.getARGB();
  62991. }
  62992. bool Colour::isTransparent() const throw()
  62993. {
  62994. return getAlpha() == 0;
  62995. }
  62996. bool Colour::isOpaque() const throw()
  62997. {
  62998. return getAlpha() == 0xff;
  62999. }
  63000. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63001. {
  63002. PixelARGB newCol (argb);
  63003. newCol.setAlpha (newAlpha);
  63004. return Colour (newCol.getARGB());
  63005. }
  63006. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63007. {
  63008. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63009. PixelARGB newCol (argb);
  63010. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  63011. return Colour (newCol.getARGB());
  63012. }
  63013. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63014. {
  63015. jassert (alphaMultiplier >= 0);
  63016. PixelARGB newCol (argb);
  63017. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63018. return Colour (newCol.getARGB());
  63019. }
  63020. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63021. {
  63022. const int destAlpha = getAlpha();
  63023. if (destAlpha > 0)
  63024. {
  63025. const int invA = 0xff - (int) src.getAlpha();
  63026. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63027. if (resA > 0)
  63028. {
  63029. const int da = (invA * destAlpha) / resA;
  63030. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63031. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63032. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63033. (uint8) resA);
  63034. }
  63035. return *this;
  63036. }
  63037. else
  63038. {
  63039. return src;
  63040. }
  63041. }
  63042. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63043. {
  63044. if (proportionOfOther <= 0)
  63045. return *this;
  63046. if (proportionOfOther >= 1.0f)
  63047. return other;
  63048. PixelARGB c1 (getPixelARGB());
  63049. const PixelARGB c2 (other.getPixelARGB());
  63050. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63051. c1.unpremultiply();
  63052. return Colour (c1.getARGB());
  63053. }
  63054. float Colour::getFloatRed() const throw()
  63055. {
  63056. return getRed() / 255.0f;
  63057. }
  63058. float Colour::getFloatGreen() const throw()
  63059. {
  63060. return getGreen() / 255.0f;
  63061. }
  63062. float Colour::getFloatBlue() const throw()
  63063. {
  63064. return getBlue() / 255.0f;
  63065. }
  63066. float Colour::getFloatAlpha() const throw()
  63067. {
  63068. return getAlpha() / 255.0f;
  63069. }
  63070. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63071. {
  63072. const int r = getRed();
  63073. const int g = getGreen();
  63074. const int b = getBlue();
  63075. const int hi = jmax (r, g, b);
  63076. const int lo = jmin (r, g, b);
  63077. if (hi != 0)
  63078. {
  63079. s = (hi - lo) / (float) hi;
  63080. if (s != 0)
  63081. {
  63082. const float invDiff = 1.0f / (hi - lo);
  63083. const float red = (hi - r) * invDiff;
  63084. const float green = (hi - g) * invDiff;
  63085. const float blue = (hi - b) * invDiff;
  63086. if (r == hi)
  63087. h = blue - green;
  63088. else if (g == hi)
  63089. h = 2.0f + red - blue;
  63090. else
  63091. h = 4.0f + green - red;
  63092. h *= 1.0f / 6.0f;
  63093. if (h < 0)
  63094. ++h;
  63095. }
  63096. else
  63097. {
  63098. h = 0;
  63099. }
  63100. }
  63101. else
  63102. {
  63103. s = 0;
  63104. h = 0;
  63105. }
  63106. v = hi / 255.0f;
  63107. }
  63108. float Colour::getHue() const throw()
  63109. {
  63110. float h, s, b;
  63111. getHSB (h, s, b);
  63112. return h;
  63113. }
  63114. const Colour Colour::withHue (const float hue) const throw()
  63115. {
  63116. float h, s, b;
  63117. getHSB (h, s, b);
  63118. return Colour (hue, s, b, getAlpha());
  63119. }
  63120. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63121. {
  63122. float h, s, b;
  63123. getHSB (h, s, b);
  63124. h += amountToRotate;
  63125. h -= floorf (h);
  63126. return Colour (h, s, b, getAlpha());
  63127. }
  63128. float Colour::getSaturation() const throw()
  63129. {
  63130. float h, s, b;
  63131. getHSB (h, s, b);
  63132. return s;
  63133. }
  63134. const Colour Colour::withSaturation (const float saturation) const throw()
  63135. {
  63136. float h, s, b;
  63137. getHSB (h, s, b);
  63138. return Colour (h, saturation, b, getAlpha());
  63139. }
  63140. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63141. {
  63142. float h, s, b;
  63143. getHSB (h, s, b);
  63144. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63145. }
  63146. float Colour::getBrightness() const throw()
  63147. {
  63148. float h, s, b;
  63149. getHSB (h, s, b);
  63150. return b;
  63151. }
  63152. const Colour Colour::withBrightness (const float brightness) const throw()
  63153. {
  63154. float h, s, b;
  63155. getHSB (h, s, b);
  63156. return Colour (h, s, brightness, getAlpha());
  63157. }
  63158. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63159. {
  63160. float h, s, b;
  63161. getHSB (h, s, b);
  63162. b *= amount;
  63163. if (b > 1.0f)
  63164. b = 1.0f;
  63165. return Colour (h, s, b, getAlpha());
  63166. }
  63167. const Colour Colour::brighter (float amount) const throw()
  63168. {
  63169. amount = 1.0f / (1.0f + amount);
  63170. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63171. (uint8) (255 - (amount * (255 - getGreen()))),
  63172. (uint8) (255 - (amount * (255 - getBlue()))),
  63173. getAlpha());
  63174. }
  63175. const Colour Colour::darker (float amount) const throw()
  63176. {
  63177. amount = 1.0f / (1.0f + amount);
  63178. return Colour ((uint8) (amount * getRed()),
  63179. (uint8) (amount * getGreen()),
  63180. (uint8) (amount * getBlue()),
  63181. getAlpha());
  63182. }
  63183. const Colour Colour::greyLevel (const float brightness) throw()
  63184. {
  63185. const uint8 level
  63186. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63187. return Colour (level, level, level);
  63188. }
  63189. const Colour Colour::contrasting (const float amount) const throw()
  63190. {
  63191. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63192. ? Colours::black
  63193. : Colours::white).withAlpha (amount));
  63194. }
  63195. const Colour Colour::contrasting (const Colour& colour1,
  63196. const Colour& colour2) throw()
  63197. {
  63198. const float b1 = colour1.getBrightness();
  63199. const float b2 = colour2.getBrightness();
  63200. float best = 0.0f;
  63201. float bestDist = 0.0f;
  63202. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63203. {
  63204. const float d1 = fabsf (i - b1);
  63205. const float d2 = fabsf (i - b2);
  63206. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63207. if (dist > bestDist)
  63208. {
  63209. best = i;
  63210. bestDist = dist;
  63211. }
  63212. }
  63213. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63214. .withBrightness (best);
  63215. }
  63216. const String Colour::toString() const
  63217. {
  63218. return String::toHexString ((int) argb.getARGB());
  63219. }
  63220. const Colour Colour::fromString (const String& encodedColourString)
  63221. {
  63222. return Colour ((uint32) encodedColourString.getHexValue32());
  63223. }
  63224. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63225. {
  63226. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63227. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63228. .toUpperCase();
  63229. }
  63230. END_JUCE_NAMESPACE
  63231. /*** End of inlined file: juce_Colour.cpp ***/
  63232. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63233. BEGIN_JUCE_NAMESPACE
  63234. ColourGradient::ColourGradient() throw()
  63235. {
  63236. #ifdef JUCE_DEBUG
  63237. x1 = 987654.0f;
  63238. #endif
  63239. }
  63240. ColourGradient::ColourGradient (const Colour& colour1,
  63241. const float x1_,
  63242. const float y1_,
  63243. const Colour& colour2,
  63244. const float x2_,
  63245. const float y2_,
  63246. const bool isRadial_) throw()
  63247. : x1 (x1_),
  63248. y1 (y1_),
  63249. x2 (x2_),
  63250. y2 (y2_),
  63251. isRadial (isRadial_)
  63252. {
  63253. colours.add (0);
  63254. colours.add (colour1.getARGB());
  63255. colours.add (1 << 16);
  63256. colours.add (colour2.getARGB());
  63257. }
  63258. ColourGradient::~ColourGradient() throw()
  63259. {
  63260. }
  63261. void ColourGradient::clearColours() throw()
  63262. {
  63263. colours.clear();
  63264. }
  63265. void ColourGradient::addColour (const double proportionAlongGradient,
  63266. const Colour& colour) throw()
  63267. {
  63268. // must be within the two end-points
  63269. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63270. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63271. int i;
  63272. for (i = 0; i < colours.size(); i += 2)
  63273. if (colours.getUnchecked(i) > pos)
  63274. break;
  63275. colours.insert (i, pos);
  63276. colours.insert (i + 1, colour.getARGB());
  63277. }
  63278. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63279. {
  63280. for (int i = 1; i < colours.size(); i += 2)
  63281. {
  63282. const Colour c (colours.getUnchecked(i));
  63283. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63284. }
  63285. }
  63286. int ColourGradient::getNumColours() const throw()
  63287. {
  63288. return colours.size() >> 1;
  63289. }
  63290. double ColourGradient::getColourPosition (const int index) const throw()
  63291. {
  63292. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63293. }
  63294. const Colour ColourGradient::getColour (const int index) const throw()
  63295. {
  63296. return Colour (colours [(index << 1) + 1]);
  63297. }
  63298. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63299. {
  63300. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63301. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63302. if (integerPos <= 0 || colours.size() <= 2)
  63303. return getColour (0);
  63304. int i = colours.size() - 2;
  63305. while (integerPos < (int) colours.getUnchecked(i))
  63306. i -= 2;
  63307. if (i >= colours.size() - 2)
  63308. return Colour (colours.getUnchecked(i));
  63309. const int pos1 = colours.getUnchecked (i);
  63310. const Colour col1 (colours.getUnchecked (i + 1));
  63311. const int pos2 = colours.getUnchecked (i + 2);
  63312. const Colour col2 (colours.getUnchecked (i + 3));
  63313. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63314. }
  63315. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63316. {
  63317. #ifdef JUCE_DEBUG
  63318. // trying to use the object without setting its co-ordinates? Have a careful read of
  63319. // the comments for the constructors.
  63320. jassert (x1 != 987654.0f);
  63321. #endif
  63322. const int numColours = colours.size() >> 1;
  63323. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63324. transform.transformPoint (tx1, ty1);
  63325. transform.transformPoint (tx2, ty2);
  63326. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63327. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63328. lookupTable.malloc (numEntries);
  63329. if (numColours >= 2)
  63330. {
  63331. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63332. PixelARGB pix1 (colours.getUnchecked (1));
  63333. pix1.premultiply();
  63334. int index = 0;
  63335. for (int j = 2; j < colours.size(); j += 2)
  63336. {
  63337. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63338. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63339. pix2.premultiply();
  63340. for (int i = 0; i < numToDo; ++i)
  63341. {
  63342. jassert (index >= 0 && index < numEntries);
  63343. lookupTable[index] = pix1;
  63344. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63345. ++index;
  63346. }
  63347. pix1 = pix2;
  63348. }
  63349. while (index < numEntries)
  63350. lookupTable [index++] = pix1;
  63351. }
  63352. else
  63353. {
  63354. jassertfalse // no colours specified!
  63355. }
  63356. return numEntries;
  63357. }
  63358. bool ColourGradient::isOpaque() const throw()
  63359. {
  63360. for (int i = 1; i < colours.size(); i += 2)
  63361. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63362. return false;
  63363. return true;
  63364. }
  63365. bool ColourGradient::isInvisible() const throw()
  63366. {
  63367. for (int i = 1; i < colours.size(); i += 2)
  63368. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63369. return false;
  63370. return true;
  63371. }
  63372. END_JUCE_NAMESPACE
  63373. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63374. /*** Start of inlined file: juce_Colours.cpp ***/
  63375. BEGIN_JUCE_NAMESPACE
  63376. const Colour Colours::transparentBlack (0);
  63377. const Colour Colours::transparentWhite (0x00ffffff);
  63378. const Colour Colours::aliceblue (0xfff0f8ff);
  63379. const Colour Colours::antiquewhite (0xfffaebd7);
  63380. const Colour Colours::aqua (0xff00ffff);
  63381. const Colour Colours::aquamarine (0xff7fffd4);
  63382. const Colour Colours::azure (0xfff0ffff);
  63383. const Colour Colours::beige (0xfff5f5dc);
  63384. const Colour Colours::bisque (0xffffe4c4);
  63385. const Colour Colours::black (0xff000000);
  63386. const Colour Colours::blanchedalmond (0xffffebcd);
  63387. const Colour Colours::blue (0xff0000ff);
  63388. const Colour Colours::blueviolet (0xff8a2be2);
  63389. const Colour Colours::brown (0xffa52a2a);
  63390. const Colour Colours::burlywood (0xffdeb887);
  63391. const Colour Colours::cadetblue (0xff5f9ea0);
  63392. const Colour Colours::chartreuse (0xff7fff00);
  63393. const Colour Colours::chocolate (0xffd2691e);
  63394. const Colour Colours::coral (0xffff7f50);
  63395. const Colour Colours::cornflowerblue (0xff6495ed);
  63396. const Colour Colours::cornsilk (0xfffff8dc);
  63397. const Colour Colours::crimson (0xffdc143c);
  63398. const Colour Colours::cyan (0xff00ffff);
  63399. const Colour Colours::darkblue (0xff00008b);
  63400. const Colour Colours::darkcyan (0xff008b8b);
  63401. const Colour Colours::darkgoldenrod (0xffb8860b);
  63402. const Colour Colours::darkgrey (0xff555555);
  63403. const Colour Colours::darkgreen (0xff006400);
  63404. const Colour Colours::darkkhaki (0xffbdb76b);
  63405. const Colour Colours::darkmagenta (0xff8b008b);
  63406. const Colour Colours::darkolivegreen (0xff556b2f);
  63407. const Colour Colours::darkorange (0xffff8c00);
  63408. const Colour Colours::darkorchid (0xff9932cc);
  63409. const Colour Colours::darkred (0xff8b0000);
  63410. const Colour Colours::darksalmon (0xffe9967a);
  63411. const Colour Colours::darkseagreen (0xff8fbc8f);
  63412. const Colour Colours::darkslateblue (0xff483d8b);
  63413. const Colour Colours::darkslategrey (0xff2f4f4f);
  63414. const Colour Colours::darkturquoise (0xff00ced1);
  63415. const Colour Colours::darkviolet (0xff9400d3);
  63416. const Colour Colours::deeppink (0xffff1493);
  63417. const Colour Colours::deepskyblue (0xff00bfff);
  63418. const Colour Colours::dimgrey (0xff696969);
  63419. const Colour Colours::dodgerblue (0xff1e90ff);
  63420. const Colour Colours::firebrick (0xffb22222);
  63421. const Colour Colours::floralwhite (0xfffffaf0);
  63422. const Colour Colours::forestgreen (0xff228b22);
  63423. const Colour Colours::fuchsia (0xffff00ff);
  63424. const Colour Colours::gainsboro (0xffdcdcdc);
  63425. const Colour Colours::gold (0xffffd700);
  63426. const Colour Colours::goldenrod (0xffdaa520);
  63427. const Colour Colours::grey (0xff808080);
  63428. const Colour Colours::green (0xff008000);
  63429. const Colour Colours::greenyellow (0xffadff2f);
  63430. const Colour Colours::honeydew (0xfff0fff0);
  63431. const Colour Colours::hotpink (0xffff69b4);
  63432. const Colour Colours::indianred (0xffcd5c5c);
  63433. const Colour Colours::indigo (0xff4b0082);
  63434. const Colour Colours::ivory (0xfffffff0);
  63435. const Colour Colours::khaki (0xfff0e68c);
  63436. const Colour Colours::lavender (0xffe6e6fa);
  63437. const Colour Colours::lavenderblush (0xfffff0f5);
  63438. const Colour Colours::lemonchiffon (0xfffffacd);
  63439. const Colour Colours::lightblue (0xffadd8e6);
  63440. const Colour Colours::lightcoral (0xfff08080);
  63441. const Colour Colours::lightcyan (0xffe0ffff);
  63442. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63443. const Colour Colours::lightgreen (0xff90ee90);
  63444. const Colour Colours::lightgrey (0xffd3d3d3);
  63445. const Colour Colours::lightpink (0xffffb6c1);
  63446. const Colour Colours::lightsalmon (0xffffa07a);
  63447. const Colour Colours::lightseagreen (0xff20b2aa);
  63448. const Colour Colours::lightskyblue (0xff87cefa);
  63449. const Colour Colours::lightslategrey (0xff778899);
  63450. const Colour Colours::lightsteelblue (0xffb0c4de);
  63451. const Colour Colours::lightyellow (0xffffffe0);
  63452. const Colour Colours::lime (0xff00ff00);
  63453. const Colour Colours::limegreen (0xff32cd32);
  63454. const Colour Colours::linen (0xfffaf0e6);
  63455. const Colour Colours::magenta (0xffff00ff);
  63456. const Colour Colours::maroon (0xff800000);
  63457. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63458. const Colour Colours::mediumblue (0xff0000cd);
  63459. const Colour Colours::mediumorchid (0xffba55d3);
  63460. const Colour Colours::mediumpurple (0xff9370db);
  63461. const Colour Colours::mediumseagreen (0xff3cb371);
  63462. const Colour Colours::mediumslateblue (0xff7b68ee);
  63463. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63464. const Colour Colours::mediumturquoise (0xff48d1cc);
  63465. const Colour Colours::mediumvioletred (0xffc71585);
  63466. const Colour Colours::midnightblue (0xff191970);
  63467. const Colour Colours::mintcream (0xfff5fffa);
  63468. const Colour Colours::mistyrose (0xffffe4e1);
  63469. const Colour Colours::navajowhite (0xffffdead);
  63470. const Colour Colours::navy (0xff000080);
  63471. const Colour Colours::oldlace (0xfffdf5e6);
  63472. const Colour Colours::olive (0xff808000);
  63473. const Colour Colours::olivedrab (0xff6b8e23);
  63474. const Colour Colours::orange (0xffffa500);
  63475. const Colour Colours::orangered (0xffff4500);
  63476. const Colour Colours::orchid (0xffda70d6);
  63477. const Colour Colours::palegoldenrod (0xffeee8aa);
  63478. const Colour Colours::palegreen (0xff98fb98);
  63479. const Colour Colours::paleturquoise (0xffafeeee);
  63480. const Colour Colours::palevioletred (0xffdb7093);
  63481. const Colour Colours::papayawhip (0xffffefd5);
  63482. const Colour Colours::peachpuff (0xffffdab9);
  63483. const Colour Colours::peru (0xffcd853f);
  63484. const Colour Colours::pink (0xffffc0cb);
  63485. const Colour Colours::plum (0xffdda0dd);
  63486. const Colour Colours::powderblue (0xffb0e0e6);
  63487. const Colour Colours::purple (0xff800080);
  63488. const Colour Colours::red (0xffff0000);
  63489. const Colour Colours::rosybrown (0xffbc8f8f);
  63490. const Colour Colours::royalblue (0xff4169e1);
  63491. const Colour Colours::saddlebrown (0xff8b4513);
  63492. const Colour Colours::salmon (0xfffa8072);
  63493. const Colour Colours::sandybrown (0xfff4a460);
  63494. const Colour Colours::seagreen (0xff2e8b57);
  63495. const Colour Colours::seashell (0xfffff5ee);
  63496. const Colour Colours::sienna (0xffa0522d);
  63497. const Colour Colours::silver (0xffc0c0c0);
  63498. const Colour Colours::skyblue (0xff87ceeb);
  63499. const Colour Colours::slateblue (0xff6a5acd);
  63500. const Colour Colours::slategrey (0xff708090);
  63501. const Colour Colours::snow (0xfffffafa);
  63502. const Colour Colours::springgreen (0xff00ff7f);
  63503. const Colour Colours::steelblue (0xff4682b4);
  63504. const Colour Colours::tan (0xffd2b48c);
  63505. const Colour Colours::teal (0xff008080);
  63506. const Colour Colours::thistle (0xffd8bfd8);
  63507. const Colour Colours::tomato (0xffff6347);
  63508. const Colour Colours::turquoise (0xff40e0d0);
  63509. const Colour Colours::violet (0xffee82ee);
  63510. const Colour Colours::wheat (0xfff5deb3);
  63511. const Colour Colours::white (0xffffffff);
  63512. const Colour Colours::whitesmoke (0xfff5f5f5);
  63513. const Colour Colours::yellow (0xffffff00);
  63514. const Colour Colours::yellowgreen (0xff9acd32);
  63515. const Colour Colours::findColourForName (const String& colourName,
  63516. const Colour& defaultColour)
  63517. {
  63518. static const int presets[] =
  63519. {
  63520. // (first value is the string's hashcode, second is ARGB)
  63521. 0x05978fff, 0xff000000, /* black */
  63522. 0x06bdcc29, 0xffffffff, /* white */
  63523. 0x002e305a, 0xff0000ff, /* blue */
  63524. 0x00308adf, 0xff808080, /* grey */
  63525. 0x05e0cf03, 0xff008000, /* green */
  63526. 0x0001b891, 0xffff0000, /* red */
  63527. 0xd43c6474, 0xffffff00, /* yellow */
  63528. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63529. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63530. 0x002dcebc, 0xff00ffff, /* aqua */
  63531. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63532. 0x0590228f, 0xfff0ffff, /* azure */
  63533. 0x05947fe4, 0xfff5f5dc, /* beige */
  63534. 0xad388e35, 0xffffe4c4, /* bisque */
  63535. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63536. 0x39129959, 0xff8a2be2, /* blueviolet */
  63537. 0x059a8136, 0xffa52a2a, /* brown */
  63538. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63539. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63540. 0x6b748956, 0xff7fff00, /* chartreuse */
  63541. 0x2903623c, 0xffd2691e, /* chocolate */
  63542. 0x05a74431, 0xffff7f50, /* coral */
  63543. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63544. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63545. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63546. 0x002ed323, 0xff00ffff, /* cyan */
  63547. 0x67cc74d0, 0xff00008b, /* darkblue */
  63548. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63549. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63550. 0x67cecf55, 0xff555555, /* darkgrey */
  63551. 0x920b194d, 0xff006400, /* darkgreen */
  63552. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63553. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63554. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63555. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63556. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63557. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63558. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63559. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63560. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63561. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63562. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63563. 0xc8769375, 0xff9400d3, /* darkviolet */
  63564. 0x25832862, 0xffff1493, /* deeppink */
  63565. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63566. 0x634c8b67, 0xff696969, /* dimgrey */
  63567. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63568. 0xef19e3cb, 0xffb22222, /* firebrick */
  63569. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63570. 0xd086fd06, 0xff228b22, /* forestgreen */
  63571. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63572. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63573. 0x00308060, 0xffffd700, /* gold */
  63574. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63575. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63576. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63577. 0x41892743, 0xffff69b4, /* hotpink */
  63578. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63579. 0xb969fed2, 0xff4b0082, /* indigo */
  63580. 0x05fef6a9, 0xfffffff0, /* ivory */
  63581. 0x06149302, 0xfff0e68c, /* khaki */
  63582. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63583. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63584. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63585. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63586. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63587. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63588. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63589. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63590. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63591. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63592. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63593. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63594. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63595. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63596. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63597. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63598. 0x0032afd5, 0xff00ff00, /* lime */
  63599. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63600. 0x06234efa, 0xfffaf0e6, /* linen */
  63601. 0x316858a9, 0xffff00ff, /* magenta */
  63602. 0xbf8ca470, 0xff800000, /* maroon */
  63603. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63604. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63605. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63606. 0x07556b71, 0xff9370db, /* mediumpurple */
  63607. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63608. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63609. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63610. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63611. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63612. 0x168eb32a, 0xff191970, /* midnightblue */
  63613. 0x4306b960, 0xfff5fffa, /* mintcream */
  63614. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63615. 0xe97218a6, 0xffffdead, /* navajowhite */
  63616. 0x00337bb6, 0xff000080, /* navy */
  63617. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63618. 0x064ee1db, 0xff808000, /* olive */
  63619. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63620. 0xc3de262e, 0xffffa500, /* orange */
  63621. 0x58bebba3, 0xffff4500, /* orangered */
  63622. 0xc3def8a3, 0xffda70d6, /* orchid */
  63623. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63624. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63625. 0x74022737, 0xffafeeee, /* paleturquoise */
  63626. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63627. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63628. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63629. 0x003472f8, 0xffcd853f, /* peru */
  63630. 0x00348176, 0xffffc0cb, /* pink */
  63631. 0x00348d94, 0xffdda0dd, /* plum */
  63632. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63633. 0xc5c507bc, 0xff800080, /* purple */
  63634. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63635. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63636. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63637. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63638. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63639. 0x34636c14, 0xff2e8b57, /* seagreen */
  63640. 0x3507fb41, 0xfffff5ee, /* seashell */
  63641. 0xca348772, 0xffa0522d, /* sienna */
  63642. 0xca37d30d, 0xffc0c0c0, /* silver */
  63643. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63644. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63645. 0x44ab37f8, 0xff708090, /* slategrey */
  63646. 0x0035f183, 0xfffffafa, /* snow */
  63647. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63648. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63649. 0x0001bfa1, 0xffd2b48c, /* tan */
  63650. 0x0036425c, 0xff008080, /* teal */
  63651. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63652. 0xcc41600a, 0xffff6347, /* tomato */
  63653. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63654. 0xcf57947f, 0xffee82ee, /* violet */
  63655. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63656. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63657. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63658. };
  63659. const int hash = colourName.trim().toLowerCase().hashCode();
  63660. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63661. if (presets [i] == hash)
  63662. return Colour (presets [i + 1]);
  63663. return defaultColour;
  63664. }
  63665. END_JUCE_NAMESPACE
  63666. /*** End of inlined file: juce_Colours.cpp ***/
  63667. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63668. BEGIN_JUCE_NAMESPACE
  63669. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63670. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63671. const Path& path, const AffineTransform& transform)
  63672. : bounds (bounds_),
  63673. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63674. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63675. needToCheckEmptinesss (true)
  63676. {
  63677. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63678. int* t = table;
  63679. for (int i = bounds.getHeight(); --i >= 0;)
  63680. {
  63681. *t = 0;
  63682. t += lineStrideElements;
  63683. }
  63684. const int topLimit = bounds.getY() << 8;
  63685. const int heightLimit = bounds.getHeight() << 8;
  63686. const int leftLimit = bounds.getX() << 8;
  63687. const int rightLimit = bounds.getRight() << 8;
  63688. PathFlatteningIterator iter (path, transform);
  63689. while (iter.next())
  63690. {
  63691. int y1 = roundToInt (iter.y1 * 256.0f);
  63692. int y2 = roundToInt (iter.y2 * 256.0f);
  63693. if (y1 != y2)
  63694. {
  63695. y1 -= topLimit;
  63696. y2 -= topLimit;
  63697. const int startY = y1;
  63698. int direction = -1;
  63699. if (y1 > y2)
  63700. {
  63701. swapVariables (y1, y2);
  63702. direction = 1;
  63703. }
  63704. if (y1 < 0)
  63705. y1 = 0;
  63706. if (y2 > heightLimit)
  63707. y2 = heightLimit;
  63708. if (y1 < y2)
  63709. {
  63710. const double startX = 256.0f * iter.x1;
  63711. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63712. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63713. do
  63714. {
  63715. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63716. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63717. if (x < leftLimit)
  63718. x = leftLimit;
  63719. else if (x >= rightLimit)
  63720. x = rightLimit - 1;
  63721. addEdgePoint (x, y1 >> 8, direction * step);
  63722. y1 += step;
  63723. }
  63724. while (y1 < y2);
  63725. }
  63726. }
  63727. }
  63728. sanitiseLevels (path.isUsingNonZeroWinding());
  63729. }
  63730. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63731. : bounds (rectangleToAdd),
  63732. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63733. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63734. needToCheckEmptinesss (true)
  63735. {
  63736. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63737. table[0] = 0;
  63738. const int x1 = rectangleToAdd.getX() << 8;
  63739. const int x2 = rectangleToAdd.getRight() << 8;
  63740. int* t = table;
  63741. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63742. {
  63743. t[0] = 2;
  63744. t[1] = x1;
  63745. t[2] = 255;
  63746. t[3] = x2;
  63747. t[4] = 0;
  63748. t += lineStrideElements;
  63749. }
  63750. }
  63751. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63752. : bounds (rectanglesToAdd.getBounds()),
  63753. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63754. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63755. needToCheckEmptinesss (true)
  63756. {
  63757. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63758. int* t = table;
  63759. for (int i = bounds.getHeight(); --i >= 0;)
  63760. {
  63761. *t = 0;
  63762. t += lineStrideElements;
  63763. }
  63764. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63765. {
  63766. const Rectangle<int>* const r = iter.getRectangle();
  63767. const int x1 = r->getX() << 8;
  63768. const int x2 = r->getRight() << 8;
  63769. int y = r->getY() - bounds.getY();
  63770. for (int j = r->getHeight(); --j >= 0;)
  63771. {
  63772. addEdgePoint (x1, y, 255);
  63773. addEdgePoint (x2, y, -255);
  63774. ++y;
  63775. }
  63776. }
  63777. sanitiseLevels (true);
  63778. }
  63779. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63780. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63781. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63782. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63783. needToCheckEmptinesss (true)
  63784. {
  63785. jassert (w > 0 && h > 0);
  63786. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63787. table[0] = 0;
  63788. const int x1 = roundToInt (x * 256.0f);
  63789. const int x2 = roundToInt ((x + w) * 256.0f);
  63790. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63791. jassert (y1 < 256);
  63792. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63793. if (x2 <= x1 || y2 <= y1)
  63794. {
  63795. bounds.setHeight (0);
  63796. return;
  63797. }
  63798. int lineY = 0;
  63799. int* t = table;
  63800. if ((y1 >> 8) == (y2 >> 8))
  63801. {
  63802. t[0] = 2;
  63803. t[1] = x1;
  63804. t[2] = y2 - y1;
  63805. t[3] = x2;
  63806. t[4] = 0;
  63807. ++lineY;
  63808. t += lineStrideElements;
  63809. }
  63810. else
  63811. {
  63812. t[0] = 2;
  63813. t[1] = x1;
  63814. t[2] = 255 - (y1 & 255);
  63815. t[3] = x2;
  63816. t[4] = 0;
  63817. ++lineY;
  63818. t += lineStrideElements;
  63819. while (lineY < (y2 >> 8))
  63820. {
  63821. t[0] = 2;
  63822. t[1] = x1;
  63823. t[2] = 255;
  63824. t[3] = x2;
  63825. t[4] = 0;
  63826. ++lineY;
  63827. t += lineStrideElements;
  63828. }
  63829. jassert (lineY < bounds.getHeight());
  63830. t[0] = 2;
  63831. t[1] = x1;
  63832. t[2] = y2 & 255;
  63833. t[3] = x2;
  63834. t[4] = 0;
  63835. ++lineY;
  63836. t += lineStrideElements;
  63837. }
  63838. while (lineY < bounds.getHeight())
  63839. {
  63840. t[0] = 0;
  63841. t += lineStrideElements;
  63842. ++lineY;
  63843. }
  63844. }
  63845. EdgeTable::EdgeTable (const EdgeTable& other)
  63846. : table (0)
  63847. {
  63848. operator= (other);
  63849. }
  63850. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63851. {
  63852. bounds = other.bounds;
  63853. maxEdgesPerLine = other.maxEdgesPerLine;
  63854. lineStrideElements = other.lineStrideElements;
  63855. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63856. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63857. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63858. return *this;
  63859. }
  63860. EdgeTable::~EdgeTable()
  63861. {
  63862. }
  63863. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63864. {
  63865. while (--numLines >= 0)
  63866. {
  63867. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63868. src += srcLineStride;
  63869. dest += destLineStride;
  63870. }
  63871. }
  63872. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63873. {
  63874. // Convert the table from relative windings to absolute levels..
  63875. int* lineStart = table;
  63876. for (int i = bounds.getHeight(); --i >= 0;)
  63877. {
  63878. int* line = lineStart;
  63879. lineStart += lineStrideElements;
  63880. int num = *line;
  63881. if (num == 0)
  63882. continue;
  63883. int level = 0;
  63884. if (useNonZeroWinding)
  63885. {
  63886. while (--num > 0)
  63887. {
  63888. line += 2;
  63889. level += *line;
  63890. int corrected = abs (level);
  63891. if (corrected >> 8)
  63892. corrected = 255;
  63893. *line = corrected;
  63894. }
  63895. }
  63896. else
  63897. {
  63898. while (--num > 0)
  63899. {
  63900. line += 2;
  63901. level += *line;
  63902. int corrected = abs (level);
  63903. if (corrected >> 8)
  63904. {
  63905. corrected &= 511;
  63906. if (corrected >> 8)
  63907. corrected = 511 - corrected;
  63908. }
  63909. *line = corrected;
  63910. }
  63911. }
  63912. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  63913. }
  63914. }
  63915. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  63916. {
  63917. if (newNumEdgesPerLine != maxEdgesPerLine)
  63918. {
  63919. maxEdgesPerLine = newNumEdgesPerLine;
  63920. jassert (bounds.getHeight() > 0);
  63921. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  63922. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  63923. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  63924. table.swapWith (newTable);
  63925. lineStrideElements = newLineStrideElements;
  63926. }
  63927. }
  63928. void EdgeTable::optimiseTable() throw()
  63929. {
  63930. int maxLineElements = 0;
  63931. for (int i = bounds.getHeight(); --i >= 0;)
  63932. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  63933. remapTableForNumEdges (maxLineElements);
  63934. }
  63935. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  63936. {
  63937. jassert (y >= 0 && y < bounds.getHeight());
  63938. int* line = table + lineStrideElements * y;
  63939. const int numPoints = line[0];
  63940. int n = numPoints << 1;
  63941. if (n > 0)
  63942. {
  63943. while (n > 0)
  63944. {
  63945. const int cx = line [n - 1];
  63946. if (cx <= x)
  63947. {
  63948. if (cx == x)
  63949. {
  63950. line [n] += winding;
  63951. return;
  63952. }
  63953. break;
  63954. }
  63955. n -= 2;
  63956. }
  63957. if (numPoints >= maxEdgesPerLine)
  63958. {
  63959. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  63960. jassert (numPoints < maxEdgesPerLine);
  63961. line = table + lineStrideElements * y;
  63962. }
  63963. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  63964. }
  63965. line [n + 1] = x;
  63966. line [n + 2] = winding;
  63967. line[0]++;
  63968. }
  63969. void EdgeTable::translate (float dx, int dy) throw()
  63970. {
  63971. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  63972. int* lineStart = table;
  63973. const int intDx = (int) (dx * 256.0f);
  63974. for (int i = bounds.getHeight(); --i >= 0;)
  63975. {
  63976. int* line = lineStart;
  63977. lineStart += lineStrideElements;
  63978. int num = *line++;
  63979. while (--num >= 0)
  63980. {
  63981. *line += intDx;
  63982. line += 2;
  63983. }
  63984. }
  63985. }
  63986. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  63987. {
  63988. jassert (y >= 0 && y < bounds.getHeight());
  63989. int* dest = table + lineStrideElements * y;
  63990. if (dest[0] == 0)
  63991. return;
  63992. int otherNumPoints = *otherLine;
  63993. if (otherNumPoints == 0)
  63994. {
  63995. *dest = 0;
  63996. return;
  63997. }
  63998. const int right = bounds.getRight() << 8;
  63999. // optimise for the common case where our line lies entirely within a
  64000. // single pair of points, as happens when clipping to a simple rect.
  64001. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64002. {
  64003. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64004. return;
  64005. }
  64006. ++otherLine;
  64007. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64008. int* temp = (int*) alloca (lineSizeBytes);
  64009. memcpy (temp, dest, lineSizeBytes);
  64010. const int* src1 = temp;
  64011. int srcNum1 = *src1++;
  64012. int x1 = *src1++;
  64013. const int* src2 = otherLine;
  64014. int srcNum2 = otherNumPoints;
  64015. int x2 = *src2++;
  64016. int destIndex = 0, destTotal = 0;
  64017. int level1 = 0, level2 = 0;
  64018. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64019. while (srcNum1 > 0 && srcNum2 > 0)
  64020. {
  64021. int nextX;
  64022. if (x1 < x2)
  64023. {
  64024. nextX = x1;
  64025. level1 = *src1++;
  64026. x1 = *src1++;
  64027. --srcNum1;
  64028. }
  64029. else if (x1 == x2)
  64030. {
  64031. nextX = x1;
  64032. level1 = *src1++;
  64033. level2 = *src2++;
  64034. x1 = *src1++;
  64035. x2 = *src2++;
  64036. --srcNum1;
  64037. --srcNum2;
  64038. }
  64039. else
  64040. {
  64041. nextX = x2;
  64042. level2 = *src2++;
  64043. x2 = *src2++;
  64044. --srcNum2;
  64045. }
  64046. if (nextX > lastX)
  64047. {
  64048. if (nextX >= right)
  64049. break;
  64050. lastX = nextX;
  64051. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64052. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64053. if (nextLevel != lastLevel)
  64054. {
  64055. if (destTotal >= maxEdgesPerLine)
  64056. {
  64057. dest[0] = destTotal;
  64058. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64059. dest = table + lineStrideElements * y;
  64060. }
  64061. ++destTotal;
  64062. lastLevel = nextLevel;
  64063. dest[++destIndex] = nextX;
  64064. dest[++destIndex] = nextLevel;
  64065. }
  64066. }
  64067. }
  64068. if (lastLevel > 0)
  64069. {
  64070. if (destTotal >= maxEdgesPerLine)
  64071. {
  64072. dest[0] = destTotal;
  64073. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64074. dest = table + lineStrideElements * y;
  64075. }
  64076. ++destTotal;
  64077. dest[++destIndex] = right;
  64078. dest[++destIndex] = 0;
  64079. }
  64080. dest[0] = destTotal;
  64081. #if JUCE_DEBUG
  64082. int last = std::numeric_limits<int>::min();
  64083. for (int i = 0; i < dest[0]; ++i)
  64084. {
  64085. jassert (dest[i * 2 + 1] > last);
  64086. last = dest[i * 2 + 1];
  64087. }
  64088. jassert (dest [dest[0] * 2] == 0);
  64089. #endif
  64090. }
  64091. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64092. {
  64093. int* lastItem = dest + (dest[0] * 2 - 1);
  64094. if (x2 < lastItem[0])
  64095. {
  64096. if (x2 <= dest[1])
  64097. {
  64098. dest[0] = 0;
  64099. return;
  64100. }
  64101. while (x2 < lastItem[-2])
  64102. {
  64103. --(dest[0]);
  64104. lastItem -= 2;
  64105. }
  64106. lastItem[0] = x2;
  64107. lastItem[1] = 0;
  64108. }
  64109. if (x1 > dest[1])
  64110. {
  64111. while (lastItem[0] > x1)
  64112. lastItem -= 2;
  64113. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64114. if (itemsRemoved > 0)
  64115. {
  64116. dest[0] -= itemsRemoved;
  64117. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64118. }
  64119. dest[1] = x1;
  64120. }
  64121. }
  64122. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64123. {
  64124. const Rectangle<int> clipped (r.getIntersection (bounds));
  64125. if (clipped.isEmpty())
  64126. {
  64127. needToCheckEmptinesss = false;
  64128. bounds.setHeight (0);
  64129. }
  64130. else
  64131. {
  64132. const int top = clipped.getY() - bounds.getY();
  64133. const int bottom = clipped.getBottom() - bounds.getY();
  64134. if (bottom < bounds.getHeight())
  64135. bounds.setHeight (bottom);
  64136. if (clipped.getRight() < bounds.getRight())
  64137. bounds.setRight (clipped.getRight());
  64138. for (int i = top; --i >= 0;)
  64139. table [lineStrideElements * i] = 0;
  64140. if (clipped.getX() > bounds.getX())
  64141. {
  64142. const int x1 = clipped.getX() << 8;
  64143. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64144. int* line = table + lineStrideElements * top;
  64145. for (int i = bottom - top; --i >= 0;)
  64146. {
  64147. if (line[0] != 0)
  64148. clipEdgeTableLineToRange (line, x1, x2);
  64149. line += lineStrideElements;
  64150. }
  64151. }
  64152. needToCheckEmptinesss = true;
  64153. }
  64154. }
  64155. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64156. {
  64157. const Rectangle<int> clipped (r.getIntersection (bounds));
  64158. if (! clipped.isEmpty())
  64159. {
  64160. const int top = clipped.getY() - bounds.getY();
  64161. const int bottom = clipped.getBottom() - bounds.getY();
  64162. //XXX optimise here by shortening the table if it fills top or bottom
  64163. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64164. clipped.getX() << 8, 0,
  64165. clipped.getRight() << 8, 255,
  64166. std::numeric_limits<int>::max(), 0 };
  64167. for (int i = top; i < bottom; ++i)
  64168. intersectWithEdgeTableLine (i, rectLine);
  64169. needToCheckEmptinesss = true;
  64170. }
  64171. }
  64172. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64173. {
  64174. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64175. if (clipped.isEmpty())
  64176. {
  64177. needToCheckEmptinesss = false;
  64178. bounds.setHeight (0);
  64179. }
  64180. else
  64181. {
  64182. const int top = clipped.getY() - bounds.getY();
  64183. const int bottom = clipped.getBottom() - bounds.getY();
  64184. if (bottom < bounds.getHeight())
  64185. bounds.setHeight (bottom);
  64186. if (clipped.getRight() < bounds.getRight())
  64187. bounds.setRight (clipped.getRight());
  64188. int i = 0;
  64189. for (i = top; --i >= 0;)
  64190. table [lineStrideElements * i] = 0;
  64191. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64192. for (i = top; i < bottom; ++i)
  64193. {
  64194. intersectWithEdgeTableLine (i, otherLine);
  64195. otherLine += other.lineStrideElements;
  64196. }
  64197. needToCheckEmptinesss = true;
  64198. }
  64199. }
  64200. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64201. {
  64202. y -= bounds.getY();
  64203. if (y < 0 || y >= bounds.getHeight())
  64204. return;
  64205. needToCheckEmptinesss = true;
  64206. if (numPixels <= 0)
  64207. {
  64208. table [lineStrideElements * y] = 0;
  64209. return;
  64210. }
  64211. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64212. int destIndex = 0, lastLevel = 0;
  64213. while (--numPixels >= 0)
  64214. {
  64215. const int alpha = *mask;
  64216. mask += maskStride;
  64217. if (alpha != lastLevel)
  64218. {
  64219. tempLine[++destIndex] = (x << 8);
  64220. tempLine[++destIndex] = alpha;
  64221. lastLevel = alpha;
  64222. }
  64223. ++x;
  64224. }
  64225. if (lastLevel > 0)
  64226. {
  64227. tempLine[++destIndex] = (x << 8);
  64228. tempLine[++destIndex] = 0;
  64229. }
  64230. tempLine[0] = destIndex >> 1;
  64231. intersectWithEdgeTableLine (y, tempLine);
  64232. }
  64233. bool EdgeTable::isEmpty() throw()
  64234. {
  64235. if (needToCheckEmptinesss)
  64236. {
  64237. needToCheckEmptinesss = false;
  64238. int* t = table;
  64239. for (int i = bounds.getHeight(); --i >= 0;)
  64240. {
  64241. if (t[0] > 1)
  64242. return false;
  64243. t += lineStrideElements;
  64244. }
  64245. bounds.setHeight (0);
  64246. }
  64247. return bounds.getHeight() == 0;
  64248. }
  64249. END_JUCE_NAMESPACE
  64250. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64251. /*** Start of inlined file: juce_FillType.cpp ***/
  64252. BEGIN_JUCE_NAMESPACE
  64253. FillType::FillType() throw()
  64254. : colour (0xff000000), image (0)
  64255. {
  64256. }
  64257. FillType::FillType (const Colour& colour_) throw()
  64258. : colour (colour_), image (0)
  64259. {
  64260. }
  64261. FillType::FillType (const ColourGradient& gradient_) throw()
  64262. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64263. {
  64264. }
  64265. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64266. : colour (0xff000000), image (&image_), transform (transform_)
  64267. {
  64268. }
  64269. FillType::FillType (const FillType& other) throw()
  64270. : colour (other.colour),
  64271. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64272. image (other.image), transform (other.transform)
  64273. {
  64274. }
  64275. FillType& FillType::operator= (const FillType& other) throw()
  64276. {
  64277. if (this != &other)
  64278. {
  64279. colour = other.colour;
  64280. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64281. image = other.image;
  64282. transform = other.transform;
  64283. }
  64284. return *this;
  64285. }
  64286. FillType::~FillType() throw()
  64287. {
  64288. }
  64289. void FillType::setColour (const Colour& newColour) throw()
  64290. {
  64291. gradient = 0;
  64292. image = 0;
  64293. colour = newColour;
  64294. }
  64295. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64296. {
  64297. if (gradient != 0)
  64298. {
  64299. *gradient = newGradient;
  64300. }
  64301. else
  64302. {
  64303. image = 0;
  64304. gradient = new ColourGradient (newGradient);
  64305. colour = Colours::black;
  64306. }
  64307. }
  64308. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64309. {
  64310. gradient = 0;
  64311. image = &image_;
  64312. transform = transform_;
  64313. colour = Colours::black;
  64314. }
  64315. void FillType::setOpacity (const float newOpacity) throw()
  64316. {
  64317. colour = colour.withAlpha (newOpacity);
  64318. }
  64319. END_JUCE_NAMESPACE
  64320. /*** End of inlined file: juce_FillType.cpp ***/
  64321. /*** Start of inlined file: juce_Graphics.cpp ***/
  64322. BEGIN_JUCE_NAMESPACE
  64323. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64324. template <typename Type>
  64325. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64326. {
  64327. const int maxVal = 0x3fffffff;
  64328. return (int) x >= -maxVal && (int) x <= maxVal
  64329. && (int) y >= -maxVal && (int) y <= maxVal
  64330. && (int) w >= -maxVal && (int) w <= maxVal
  64331. && (int) h >= -maxVal && (int) h <= maxVal;
  64332. }
  64333. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64334. {
  64335. }
  64336. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64337. {
  64338. }
  64339. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64340. : context (imageToDrawOnto.createLowLevelContext()),
  64341. contextToDelete (context),
  64342. saveStatePending (false)
  64343. {
  64344. }
  64345. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64346. : context (internalContext),
  64347. saveStatePending (false)
  64348. {
  64349. }
  64350. Graphics::~Graphics() throw()
  64351. {
  64352. }
  64353. void Graphics::resetToDefaultState() throw()
  64354. {
  64355. saveStateIfPending();
  64356. context->setFill (FillType());
  64357. context->setFont (Font());
  64358. context->setInterpolationQuality (defaultQuality);
  64359. }
  64360. bool Graphics::isVectorDevice() const throw()
  64361. {
  64362. return context->isVectorDevice();
  64363. }
  64364. bool Graphics::reduceClipRegion (const int x, const int y,
  64365. const int w, const int h) throw()
  64366. {
  64367. saveStateIfPending();
  64368. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64369. }
  64370. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64371. {
  64372. saveStateIfPending();
  64373. return context->clipToRectangleList (clipRegion);
  64374. }
  64375. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64376. {
  64377. saveStateIfPending();
  64378. context->clipToPath (path, transform);
  64379. return ! context->isClipEmpty();
  64380. }
  64381. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64382. {
  64383. saveStateIfPending();
  64384. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64385. return ! context->isClipEmpty();
  64386. }
  64387. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude) throw()
  64388. {
  64389. saveStateIfPending();
  64390. context->excludeClipRectangle (rectangleToExclude);
  64391. }
  64392. bool Graphics::isClipEmpty() const throw()
  64393. {
  64394. return context->isClipEmpty();
  64395. }
  64396. const Rectangle<int> Graphics::getClipBounds() const throw()
  64397. {
  64398. return context->getClipBounds();
  64399. }
  64400. void Graphics::saveState() throw()
  64401. {
  64402. saveStateIfPending();
  64403. saveStatePending = true;
  64404. }
  64405. void Graphics::restoreState() throw()
  64406. {
  64407. if (saveStatePending)
  64408. saveStatePending = false;
  64409. else
  64410. context->restoreState();
  64411. }
  64412. void Graphics::saveStateIfPending() throw()
  64413. {
  64414. if (saveStatePending)
  64415. {
  64416. saveStatePending = false;
  64417. context->saveState();
  64418. }
  64419. }
  64420. void Graphics::setOrigin (const int newOriginX,
  64421. const int newOriginY) throw()
  64422. {
  64423. saveStateIfPending();
  64424. context->setOrigin (newOriginX, newOriginY);
  64425. }
  64426. bool Graphics::clipRegionIntersects (const int x, const int y,
  64427. const int w, const int h) const throw()
  64428. {
  64429. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64430. }
  64431. void Graphics::setColour (const Colour& newColour) throw()
  64432. {
  64433. saveStateIfPending();
  64434. context->setFill (FillType (newColour));
  64435. }
  64436. void Graphics::setOpacity (const float newOpacity) throw()
  64437. {
  64438. saveStateIfPending();
  64439. context->setOpacity (newOpacity);
  64440. }
  64441. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64442. {
  64443. saveStateIfPending();
  64444. context->setFill (FillType (gradient));
  64445. }
  64446. void Graphics::setTiledImageFill (const Image& imageToUse,
  64447. const int anchorX,
  64448. const int anchorY,
  64449. const float opacity) throw()
  64450. {
  64451. saveStateIfPending();
  64452. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64453. context->setOpacity (opacity);
  64454. }
  64455. void Graphics::setFillType (const FillType& newFill) throw()
  64456. {
  64457. saveStateIfPending();
  64458. context->setFill (newFill);
  64459. }
  64460. void Graphics::setFont (const Font& newFont) throw()
  64461. {
  64462. saveStateIfPending();
  64463. context->setFont (newFont);
  64464. }
  64465. void Graphics::setFont (const float newFontHeight,
  64466. const int newFontStyleFlags) throw()
  64467. {
  64468. saveStateIfPending();
  64469. Font f (context->getFont());
  64470. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64471. context->setFont (f);
  64472. }
  64473. void Graphics::drawSingleLineText (const String& text,
  64474. const int startX,
  64475. const int baselineY) const throw()
  64476. {
  64477. if (text.isNotEmpty()
  64478. && startX < context->getClipBounds().getRight())
  64479. {
  64480. GlyphArrangement arr;
  64481. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64482. arr.draw (*this);
  64483. }
  64484. }
  64485. void Graphics::drawTextAsPath (const String& text,
  64486. const AffineTransform& transform) const throw()
  64487. {
  64488. if (text.isNotEmpty())
  64489. {
  64490. GlyphArrangement arr;
  64491. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64492. arr.draw (*this, transform);
  64493. }
  64494. }
  64495. void Graphics::drawMultiLineText (const String& text,
  64496. const int startX,
  64497. const int baselineY,
  64498. const int maximumLineWidth) const throw()
  64499. {
  64500. if (text.isNotEmpty()
  64501. && startX < context->getClipBounds().getRight())
  64502. {
  64503. GlyphArrangement arr;
  64504. arr.addJustifiedText (context->getFont(), text,
  64505. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64506. Justification::left);
  64507. arr.draw (*this);
  64508. }
  64509. }
  64510. void Graphics::drawText (const String& text,
  64511. const int x,
  64512. const int y,
  64513. const int width,
  64514. const int height,
  64515. const Justification& justificationType,
  64516. const bool useEllipsesIfTooBig) const throw()
  64517. {
  64518. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64519. {
  64520. GlyphArrangement arr;
  64521. arr.addCurtailedLineOfText (context->getFont(), text,
  64522. 0.0f, 0.0f, (float)width,
  64523. useEllipsesIfTooBig);
  64524. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64525. (float) x, (float) y,
  64526. (float) width, (float) height,
  64527. justificationType);
  64528. arr.draw (*this);
  64529. }
  64530. }
  64531. void Graphics::drawFittedText (const String& text,
  64532. const int x,
  64533. const int y,
  64534. const int width,
  64535. const int height,
  64536. const Justification& justification,
  64537. const int maximumNumberOfLines,
  64538. const float minimumHorizontalScale) const throw()
  64539. {
  64540. if (text.isNotEmpty()
  64541. && width > 0 && height > 0
  64542. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64543. {
  64544. GlyphArrangement arr;
  64545. arr.addFittedText (context->getFont(), text,
  64546. (float) x, (float) y,
  64547. (float) width, (float) height,
  64548. justification,
  64549. maximumNumberOfLines,
  64550. minimumHorizontalScale);
  64551. arr.draw (*this);
  64552. }
  64553. }
  64554. void Graphics::fillRect (int x,
  64555. int y,
  64556. int width,
  64557. int height) const throw()
  64558. {
  64559. // passing in a silly number can cause maths problems in rendering!
  64560. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64561. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64562. }
  64563. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  64564. {
  64565. context->fillRect (r, false);
  64566. }
  64567. void Graphics::fillRect (const float x,
  64568. const float y,
  64569. const float width,
  64570. const float height) const throw()
  64571. {
  64572. // passing in a silly number can cause maths problems in rendering!
  64573. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64574. Path p;
  64575. p.addRectangle (x, y, width, height);
  64576. fillPath (p);
  64577. }
  64578. void Graphics::setPixel (int x, int y) const throw()
  64579. {
  64580. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64581. }
  64582. void Graphics::fillAll() const throw()
  64583. {
  64584. fillRect (context->getClipBounds());
  64585. }
  64586. void Graphics::fillAll (const Colour& colourToUse) const throw()
  64587. {
  64588. if (! colourToUse.isTransparent())
  64589. {
  64590. const Rectangle<int> clip (context->getClipBounds());
  64591. context->saveState();
  64592. context->setFill (FillType (colourToUse));
  64593. context->fillRect (clip, false);
  64594. context->restoreState();
  64595. }
  64596. }
  64597. void Graphics::fillPath (const Path& path,
  64598. const AffineTransform& transform) const throw()
  64599. {
  64600. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64601. context->fillPath (path, transform);
  64602. }
  64603. void Graphics::strokePath (const Path& path,
  64604. const PathStrokeType& strokeType,
  64605. const AffineTransform& transform) const throw()
  64606. {
  64607. Path stroke;
  64608. strokeType.createStrokedPath (stroke, path, transform);
  64609. fillPath (stroke);
  64610. }
  64611. void Graphics::drawRect (const int x,
  64612. const int y,
  64613. const int width,
  64614. const int height,
  64615. const int lineThickness) const throw()
  64616. {
  64617. // passing in a silly number can cause maths problems in rendering!
  64618. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64619. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64620. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64621. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64622. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64623. }
  64624. void Graphics::drawRect (const float x,
  64625. const float y,
  64626. const float width,
  64627. const float height,
  64628. const float lineThickness) const throw()
  64629. {
  64630. // passing in a silly number can cause maths problems in rendering!
  64631. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64632. Path p;
  64633. p.addRectangle (x, y, width, lineThickness);
  64634. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64635. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64636. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64637. fillPath (p);
  64638. }
  64639. void Graphics::drawRect (const Rectangle<int>& r,
  64640. const int lineThickness) const throw()
  64641. {
  64642. drawRect (r.getX(), r.getY(),
  64643. r.getWidth(), r.getHeight(),
  64644. lineThickness);
  64645. }
  64646. void Graphics::drawBevel (const int x,
  64647. const int y,
  64648. const int width,
  64649. const int height,
  64650. const int bevelThickness,
  64651. const Colour& topLeftColour,
  64652. const Colour& bottomRightColour,
  64653. const bool useGradient,
  64654. const bool sharpEdgeOnOutside) const throw()
  64655. {
  64656. // passing in a silly number can cause maths problems in rendering!
  64657. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64658. if (clipRegionIntersects (x, y, width, height))
  64659. {
  64660. context->saveState();
  64661. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64662. const float ramp = oldOpacity / bevelThickness;
  64663. for (int i = bevelThickness; --i >= 0;)
  64664. {
  64665. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64666. : oldOpacity;
  64667. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  64668. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64669. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  64670. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64671. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  64672. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64673. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  64674. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64675. }
  64676. context->restoreState();
  64677. }
  64678. }
  64679. void Graphics::fillEllipse (const float x,
  64680. const float y,
  64681. const float width,
  64682. const float height) const throw()
  64683. {
  64684. // passing in a silly number can cause maths problems in rendering!
  64685. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64686. Path p;
  64687. p.addEllipse (x, y, width, height);
  64688. fillPath (p);
  64689. }
  64690. void Graphics::drawEllipse (const float x,
  64691. const float y,
  64692. const float width,
  64693. const float height,
  64694. const float lineThickness) const throw()
  64695. {
  64696. // passing in a silly number can cause maths problems in rendering!
  64697. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64698. Path p;
  64699. p.addEllipse (x, y, width, height);
  64700. strokePath (p, PathStrokeType (lineThickness));
  64701. }
  64702. void Graphics::fillRoundedRectangle (const float x,
  64703. const float y,
  64704. const float width,
  64705. const float height,
  64706. const float cornerSize) const throw()
  64707. {
  64708. // passing in a silly number can cause maths problems in rendering!
  64709. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64710. Path p;
  64711. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64712. fillPath (p);
  64713. }
  64714. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  64715. const float cornerSize) const throw()
  64716. {
  64717. fillRoundedRectangle ((float) r.getX(),
  64718. (float) r.getY(),
  64719. (float) r.getWidth(),
  64720. (float) r.getHeight(),
  64721. cornerSize);
  64722. }
  64723. void Graphics::drawRoundedRectangle (const float x,
  64724. const float y,
  64725. const float width,
  64726. const float height,
  64727. const float cornerSize,
  64728. const float lineThickness) const throw()
  64729. {
  64730. // passing in a silly number can cause maths problems in rendering!
  64731. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64732. Path p;
  64733. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64734. strokePath (p, PathStrokeType (lineThickness));
  64735. }
  64736. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  64737. const float cornerSize,
  64738. const float lineThickness) const throw()
  64739. {
  64740. drawRoundedRectangle ((float) r.getX(),
  64741. (float) r.getY(),
  64742. (float) r.getWidth(),
  64743. (float) r.getHeight(),
  64744. cornerSize, lineThickness);
  64745. }
  64746. void Graphics::drawArrow (const float startX,
  64747. const float startY,
  64748. const float endX,
  64749. const float endY,
  64750. const float lineThickness,
  64751. const float arrowheadWidth,
  64752. const float arrowheadLength) const throw()
  64753. {
  64754. Path p;
  64755. p.addArrow (startX, startY, endX, endY,
  64756. lineThickness, arrowheadWidth, arrowheadLength);
  64757. fillPath (p);
  64758. }
  64759. void Graphics::fillCheckerBoard (int x, int y,
  64760. int width, int height,
  64761. const int checkWidth,
  64762. const int checkHeight,
  64763. const Colour& colour1,
  64764. const Colour& colour2) const throw()
  64765. {
  64766. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64767. if (checkWidth > 0 && checkHeight > 0)
  64768. {
  64769. context->saveState();
  64770. if (colour1 == colour2)
  64771. {
  64772. context->setFill (FillType (colour1));
  64773. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64774. }
  64775. else
  64776. {
  64777. const Rectangle<int> clip (context->getClipBounds());
  64778. const int right = jmin (x + width, clip.getRight());
  64779. const int bottom = jmin (y + height, clip.getBottom());
  64780. int cy = 0;
  64781. while (y < bottom)
  64782. {
  64783. int cx = cy;
  64784. for (int xx = x; xx < right; xx += checkWidth)
  64785. {
  64786. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  64787. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64788. false);
  64789. }
  64790. ++cy;
  64791. y += checkHeight;
  64792. }
  64793. }
  64794. context->restoreState();
  64795. }
  64796. }
  64797. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  64798. {
  64799. context->drawVerticalLine (x, top, bottom);
  64800. }
  64801. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  64802. {
  64803. context->drawHorizontalLine (y, left, right);
  64804. }
  64805. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  64806. {
  64807. context->drawLine (x1, y1, x2, y2);
  64808. }
  64809. void Graphics::drawLine (const float startX,
  64810. const float startY,
  64811. const float endX,
  64812. const float endY,
  64813. const float lineThickness) const throw()
  64814. {
  64815. Path p;
  64816. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64817. fillPath (p);
  64818. }
  64819. void Graphics::drawLine (const Line& line) const throw()
  64820. {
  64821. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64822. }
  64823. void Graphics::drawLine (const Line& line,
  64824. const float lineThickness) const throw()
  64825. {
  64826. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64827. }
  64828. void Graphics::drawDashedLine (const float startX,
  64829. const float startY,
  64830. const float endX,
  64831. const float endY,
  64832. const float* const dashLengths,
  64833. const int numDashLengths,
  64834. const float lineThickness) const throw()
  64835. {
  64836. const double dx = endX - startX;
  64837. const double dy = endY - startY;
  64838. const double totalLen = juce_hypot (dx, dy);
  64839. if (totalLen >= 0.5)
  64840. {
  64841. const double onePixAlpha = 1.0 / totalLen;
  64842. double alpha = 0.0;
  64843. float x = startX;
  64844. float y = startY;
  64845. int n = 0;
  64846. while (alpha < 1.0f)
  64847. {
  64848. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64849. n = n % numDashLengths;
  64850. const float oldX = x;
  64851. const float oldY = y;
  64852. x = (float) (startX + dx * alpha);
  64853. y = (float) (startY + dy * alpha);
  64854. if ((n & 1) != 0)
  64855. {
  64856. if (lineThickness != 1.0f)
  64857. drawLine (oldX, oldY, x, y, lineThickness);
  64858. else
  64859. drawLine (oldX, oldY, x, y);
  64860. }
  64861. }
  64862. }
  64863. }
  64864. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  64865. {
  64866. saveStateIfPending();
  64867. context->setInterpolationQuality (newQuality);
  64868. }
  64869. void Graphics::drawImageAt (const Image* const imageToDraw,
  64870. const int topLeftX,
  64871. const int topLeftY,
  64872. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64873. {
  64874. if (imageToDraw != 0)
  64875. {
  64876. const int imageW = imageToDraw->getWidth();
  64877. const int imageH = imageToDraw->getHeight();
  64878. drawImage (imageToDraw,
  64879. topLeftX, topLeftY, imageW, imageH,
  64880. 0, 0, imageW, imageH,
  64881. fillAlphaChannelWithCurrentBrush);
  64882. }
  64883. }
  64884. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64885. const int destX,
  64886. const int destY,
  64887. const int destW,
  64888. const int destH,
  64889. const RectanglePlacement& placementWithinTarget,
  64890. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64891. {
  64892. // passing in a silly number can cause maths problems in rendering!
  64893. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64894. if (imageToDraw != 0)
  64895. {
  64896. const int imageW = imageToDraw->getWidth();
  64897. const int imageH = imageToDraw->getHeight();
  64898. if (imageW > 0 && imageH > 0)
  64899. {
  64900. double newX = 0.0, newY = 0.0;
  64901. double newW = imageW;
  64902. double newH = imageH;
  64903. placementWithinTarget.applyTo (newX, newY, newW, newH,
  64904. destX, destY, destW, destH);
  64905. if (newW > 0 && newH > 0)
  64906. {
  64907. drawImage (imageToDraw,
  64908. roundToInt (newX), roundToInt (newY),
  64909. roundToInt (newW), roundToInt (newH),
  64910. 0, 0, imageW, imageH,
  64911. fillAlphaChannelWithCurrentBrush);
  64912. }
  64913. }
  64914. }
  64915. }
  64916. void Graphics::drawImage (const Image* const imageToDraw,
  64917. int dx, int dy, int dw, int dh,
  64918. int sx, int sy, int sw, int sh,
  64919. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64920. {
  64921. // passing in a silly number can cause maths problems in rendering!
  64922. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  64923. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  64924. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  64925. {
  64926. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  64927. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  64928. .translated ((float) dx, (float) dy),
  64929. fillAlphaChannelWithCurrentBrush);
  64930. }
  64931. }
  64932. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  64933. const Rectangle<int>& imageSubRegion,
  64934. const AffineTransform& transform,
  64935. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64936. {
  64937. if (imageToDraw != 0 && ! context->isClipEmpty())
  64938. {
  64939. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  64940. if (fillAlphaChannelWithCurrentBrush)
  64941. {
  64942. context->saveState();
  64943. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  64944. fillAll();
  64945. context->restoreState();
  64946. }
  64947. else
  64948. {
  64949. context->drawImage (*imageToDraw, srcClip, transform, false);
  64950. }
  64951. }
  64952. }
  64953. END_JUCE_NAMESPACE
  64954. /*** End of inlined file: juce_Graphics.cpp ***/
  64955. /*** Start of inlined file: juce_Justification.cpp ***/
  64956. BEGIN_JUCE_NAMESPACE
  64957. Justification::Justification (const Justification& other) throw()
  64958. : flags (other.flags)
  64959. {
  64960. }
  64961. Justification& Justification::operator= (const Justification& other) throw()
  64962. {
  64963. flags = other.flags;
  64964. return *this;
  64965. }
  64966. int Justification::getOnlyVerticalFlags() const throw()
  64967. {
  64968. return flags & (top | bottom | verticallyCentred);
  64969. }
  64970. int Justification::getOnlyHorizontalFlags() const throw()
  64971. {
  64972. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  64973. }
  64974. void Justification::applyToRectangle (int& x, int& y,
  64975. const int w, const int h,
  64976. const int spaceX, const int spaceY,
  64977. const int spaceW, const int spaceH) const throw()
  64978. {
  64979. if ((flags & horizontallyCentred) != 0)
  64980. {
  64981. x = spaceX + ((spaceW - w) >> 1);
  64982. }
  64983. else if ((flags & right) != 0)
  64984. {
  64985. x = spaceX + spaceW - w;
  64986. }
  64987. else
  64988. {
  64989. x = spaceX;
  64990. }
  64991. if ((flags & verticallyCentred) != 0)
  64992. {
  64993. y = spaceY + ((spaceH - h) >> 1);
  64994. }
  64995. else if ((flags & bottom) != 0)
  64996. {
  64997. y = spaceY + spaceH - h;
  64998. }
  64999. else
  65000. {
  65001. y = spaceY;
  65002. }
  65003. }
  65004. END_JUCE_NAMESPACE
  65005. /*** End of inlined file: juce_Justification.cpp ***/
  65006. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65007. BEGIN_JUCE_NAMESPACE
  65008. // this will throw an assertion if you try to draw something that's not
  65009. // possible in postscript
  65010. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65011. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65012. #define notPossibleInPostscriptAssert jassertfalse
  65013. #else
  65014. #define notPossibleInPostscriptAssert
  65015. #endif
  65016. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65017. const String& documentTitle,
  65018. const int totalWidth_,
  65019. const int totalHeight_)
  65020. : out (resultingPostScript),
  65021. totalWidth (totalWidth_),
  65022. totalHeight (totalHeight_),
  65023. needToClip (true)
  65024. {
  65025. stateStack.add (new SavedState());
  65026. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65027. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65028. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65029. "\n%%BoundingBox: 0 0 600 824"
  65030. "\n%%Pages: 0"
  65031. "\n%%Creator: Raw Material Software JUCE"
  65032. "\n%%Title: " << documentTitle <<
  65033. "\n%%CreationDate: none"
  65034. "\n%%LanguageLevel: 2"
  65035. "\n%%EndComments"
  65036. "\n%%BeginProlog"
  65037. "\n%%BeginResource: JRes"
  65038. "\n/bd {bind def} bind def"
  65039. "\n/c {setrgbcolor} bd"
  65040. "\n/m {moveto} bd"
  65041. "\n/l {lineto} bd"
  65042. "\n/rl {rlineto} bd"
  65043. "\n/ct {curveto} bd"
  65044. "\n/cp {closepath} bd"
  65045. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65046. "\n/doclip {initclip newpath} bd"
  65047. "\n/endclip {clip newpath} bd"
  65048. "\n%%EndResource"
  65049. "\n%%EndProlog"
  65050. "\n%%BeginSetup"
  65051. "\n%%EndSetup"
  65052. "\n%%Page: 1 1"
  65053. "\n%%BeginPageSetup"
  65054. "\n%%EndPageSetup\n\n"
  65055. << "40 800 translate\n"
  65056. << scale << ' ' << scale << " scale\n\n";
  65057. }
  65058. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65059. {
  65060. }
  65061. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65062. {
  65063. return true;
  65064. }
  65065. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65066. {
  65067. if (x != 0 || y != 0)
  65068. {
  65069. stateStack.getLast()->xOffset += x;
  65070. stateStack.getLast()->yOffset += y;
  65071. needToClip = true;
  65072. }
  65073. }
  65074. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65075. {
  65076. needToClip = true;
  65077. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65078. }
  65079. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65080. {
  65081. needToClip = true;
  65082. return stateStack.getLast()->clip.clipTo (clipRegion);
  65083. }
  65084. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65085. {
  65086. needToClip = true;
  65087. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65088. }
  65089. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65090. {
  65091. writeClip();
  65092. Path p (path);
  65093. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65094. writePath (p);
  65095. out << "clip\n";
  65096. }
  65097. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65098. {
  65099. needToClip = true;
  65100. jassertfalse // xxx
  65101. }
  65102. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65103. {
  65104. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65105. }
  65106. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65107. {
  65108. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65109. -stateStack.getLast()->yOffset);
  65110. }
  65111. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65112. {
  65113. return stateStack.getLast()->clip.isEmpty();
  65114. }
  65115. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65116. : xOffset (0),
  65117. yOffset (0)
  65118. {
  65119. }
  65120. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65121. {
  65122. }
  65123. void LowLevelGraphicsPostScriptRenderer::saveState()
  65124. {
  65125. stateStack.add (new SavedState (*stateStack.getLast()));
  65126. }
  65127. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65128. {
  65129. jassert (stateStack.size() > 0);
  65130. if (stateStack.size() > 0)
  65131. stateStack.removeLast();
  65132. }
  65133. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65134. {
  65135. if (needToClip)
  65136. {
  65137. needToClip = false;
  65138. out << "doclip ";
  65139. int itemsOnLine = 0;
  65140. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65141. {
  65142. if (++itemsOnLine == 6)
  65143. {
  65144. itemsOnLine = 0;
  65145. out << '\n';
  65146. }
  65147. const Rectangle<int>& r = *i.getRectangle();
  65148. out << r.getX() << ' ' << -r.getY() << ' '
  65149. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65150. }
  65151. out << "endclip\n";
  65152. }
  65153. }
  65154. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65155. {
  65156. Colour c (Colours::white.overlaidWith (colour));
  65157. if (lastColour != c)
  65158. {
  65159. lastColour = c;
  65160. out << String (c.getFloatRed(), 3) << ' '
  65161. << String (c.getFloatGreen(), 3) << ' '
  65162. << String (c.getFloatBlue(), 3) << " c\n";
  65163. }
  65164. }
  65165. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65166. {
  65167. out << String (x, 2) << ' '
  65168. << String (-y, 2) << ' ';
  65169. }
  65170. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65171. {
  65172. out << "newpath ";
  65173. float lastX = 0.0f;
  65174. float lastY = 0.0f;
  65175. int itemsOnLine = 0;
  65176. Path::Iterator i (path);
  65177. while (i.next())
  65178. {
  65179. if (++itemsOnLine == 4)
  65180. {
  65181. itemsOnLine = 0;
  65182. out << '\n';
  65183. }
  65184. switch (i.elementType)
  65185. {
  65186. case Path::Iterator::startNewSubPath:
  65187. writeXY (i.x1, i.y1);
  65188. lastX = i.x1;
  65189. lastY = i.y1;
  65190. out << "m ";
  65191. break;
  65192. case Path::Iterator::lineTo:
  65193. writeXY (i.x1, i.y1);
  65194. lastX = i.x1;
  65195. lastY = i.y1;
  65196. out << "l ";
  65197. break;
  65198. case Path::Iterator::quadraticTo:
  65199. {
  65200. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65201. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65202. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65203. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65204. writeXY (cp1x, cp1y);
  65205. writeXY (cp2x, cp2y);
  65206. writeXY (i.x2, i.y2);
  65207. out << "ct ";
  65208. lastX = i.x2;
  65209. lastY = i.y2;
  65210. }
  65211. break;
  65212. case Path::Iterator::cubicTo:
  65213. writeXY (i.x1, i.y1);
  65214. writeXY (i.x2, i.y2);
  65215. writeXY (i.x3, i.y3);
  65216. out << "ct ";
  65217. lastX = i.x3;
  65218. lastY = i.y3;
  65219. break;
  65220. case Path::Iterator::closePath:
  65221. out << "cp ";
  65222. break;
  65223. default:
  65224. jassertfalse
  65225. break;
  65226. }
  65227. }
  65228. out << '\n';
  65229. }
  65230. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65231. {
  65232. out << "[ "
  65233. << trans.mat00 << ' '
  65234. << trans.mat10 << ' '
  65235. << trans.mat01 << ' '
  65236. << trans.mat11 << ' '
  65237. << trans.mat02 << ' '
  65238. << trans.mat12 << " ] concat ";
  65239. }
  65240. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65241. {
  65242. stateStack.getLast()->fillType = fillType;
  65243. }
  65244. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65245. {
  65246. }
  65247. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65248. {
  65249. }
  65250. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65251. {
  65252. if (stateStack.getLast()->fillType.isColour())
  65253. {
  65254. writeClip();
  65255. writeColour (stateStack.getLast()->fillType.colour);
  65256. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65257. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65258. }
  65259. else
  65260. {
  65261. Path p;
  65262. p.addRectangle (r);
  65263. fillPath (p, AffineTransform::identity);
  65264. }
  65265. }
  65266. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65267. {
  65268. if (stateStack.getLast()->fillType.isColour())
  65269. {
  65270. writeClip();
  65271. Path p (path);
  65272. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65273. (float) stateStack.getLast()->yOffset));
  65274. writePath (p);
  65275. writeColour (stateStack.getLast()->fillType.colour);
  65276. out << "fill\n";
  65277. }
  65278. else if (stateStack.getLast()->fillType.isGradient())
  65279. {
  65280. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65281. // postscript can't do semi-transparent ones.
  65282. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65283. writeClip();
  65284. out << "gsave ";
  65285. {
  65286. Path p (path);
  65287. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65288. writePath (p);
  65289. out << "clip\n";
  65290. }
  65291. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65292. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65293. // time-being, this just fills it with the average colour..
  65294. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65295. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65296. out << "grestore\n";
  65297. }
  65298. }
  65299. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65300. const int sx, const int sy,
  65301. const int maxW, const int maxH) const
  65302. {
  65303. out << "{<\n";
  65304. const int w = jmin (maxW, im.getWidth());
  65305. const int h = jmin (maxH, im.getHeight());
  65306. int charsOnLine = 0;
  65307. const Image::BitmapData srcData (im, 0, 0, w, h);
  65308. Colour pixel;
  65309. for (int y = h; --y >= 0;)
  65310. {
  65311. for (int x = 0; x < w; ++x)
  65312. {
  65313. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65314. if (x >= sx && y >= sy)
  65315. {
  65316. if (im.isARGB())
  65317. {
  65318. PixelARGB p (*(const PixelARGB*) pixelData);
  65319. p.unpremultiply();
  65320. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65321. }
  65322. else if (im.isRGB())
  65323. {
  65324. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65325. }
  65326. else
  65327. {
  65328. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65329. }
  65330. }
  65331. else
  65332. {
  65333. pixel = Colours::transparentWhite;
  65334. }
  65335. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65336. out << String::toHexString (pixelValues, 3, 0);
  65337. charsOnLine += 3;
  65338. if (charsOnLine > 100)
  65339. {
  65340. out << '\n';
  65341. charsOnLine = 0;
  65342. }
  65343. }
  65344. }
  65345. out << "\n>}\n";
  65346. }
  65347. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65348. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65349. {
  65350. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65351. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65352. writeClip();
  65353. out << "gsave ";
  65354. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65355. .scaled (1.0f, -1.0f));
  65356. RectangleList imageClip;
  65357. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65358. imageClip.clipTo (srcClip);
  65359. out << "newpath ";
  65360. int itemsOnLine = 0;
  65361. for (RectangleList::Iterator i (imageClip); i.next();)
  65362. {
  65363. if (++itemsOnLine == 6)
  65364. {
  65365. out << '\n';
  65366. itemsOnLine = 0;
  65367. }
  65368. const Rectangle<int>& r = *i.getRectangle();
  65369. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65370. }
  65371. out << " clip newpath\n";
  65372. out << w << ' ' << h << " scale\n";
  65373. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65374. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65375. out << "false 3 colorimage grestore\n";
  65376. needToClip = true;
  65377. }
  65378. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65379. {
  65380. Path p;
  65381. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65382. fillPath (p, AffineTransform::identity);
  65383. }
  65384. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65385. {
  65386. drawLine (x, top, x, bottom);
  65387. }
  65388. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65389. {
  65390. drawLine (left, y, right, y);
  65391. }
  65392. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65393. {
  65394. stateStack.getLast()->font = newFont;
  65395. }
  65396. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65397. {
  65398. return stateStack.getLast()->font;
  65399. }
  65400. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65401. {
  65402. Path p;
  65403. Font& font = stateStack.getLast()->font;
  65404. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65405. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65406. }
  65407. END_JUCE_NAMESPACE
  65408. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65409. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65410. BEGIN_JUCE_NAMESPACE
  65411. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65412. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65413. #endif
  65414. #if JUCE_MSVC && JUCE_DEBUG
  65415. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65416. #endif
  65417. #if JUCE_MSVC
  65418. #pragma warning (push)
  65419. #pragma warning (disable: 4127) // "expression is constant" warning
  65420. #endif
  65421. template <class PixelType, bool replaceExisting = false>
  65422. class SolidColourEdgeTableRenderer
  65423. {
  65424. public:
  65425. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65426. : data (data_),
  65427. sourceColour (colour)
  65428. {
  65429. if (sizeof (PixelType) == 3)
  65430. {
  65431. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65432. && sourceColour.getGreen() == sourceColour.getBlue();
  65433. filler[0].set (sourceColour);
  65434. filler[1].set (sourceColour);
  65435. filler[2].set (sourceColour);
  65436. filler[3].set (sourceColour);
  65437. }
  65438. }
  65439. forcedinline void setEdgeTableYPos (const int y) throw()
  65440. {
  65441. linePixels = (PixelType*) data.getLinePointer (y);
  65442. }
  65443. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65444. {
  65445. if (replaceExisting)
  65446. linePixels[x].set (sourceColour);
  65447. else
  65448. linePixels[x].blend (sourceColour, alphaLevel);
  65449. }
  65450. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65451. {
  65452. PixelARGB p (sourceColour);
  65453. p.multiplyAlpha (alphaLevel);
  65454. PixelType* dest = linePixels + x;
  65455. if (replaceExisting || p.getAlpha() >= 0xff)
  65456. replaceLine (dest, p, width);
  65457. else
  65458. blendLine (dest, p, width);
  65459. }
  65460. private:
  65461. const Image::BitmapData& data;
  65462. PixelType* linePixels;
  65463. PixelARGB sourceColour;
  65464. PixelRGB filler [4];
  65465. bool areRGBComponentsEqual;
  65466. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65467. {
  65468. do
  65469. {
  65470. dest->blend (colour);
  65471. ++dest;
  65472. } while (--width > 0);
  65473. }
  65474. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65475. {
  65476. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65477. {
  65478. memset (dest, colour.getRed(), width * 3);
  65479. }
  65480. else
  65481. {
  65482. if (width >> 5)
  65483. {
  65484. const int* const intFiller = (const int*) filler;
  65485. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65486. {
  65487. dest->set (colour);
  65488. ++dest;
  65489. --width;
  65490. }
  65491. while (width > 4)
  65492. {
  65493. ((int*) dest) [0] = intFiller[0];
  65494. ((int*) dest) [1] = intFiller[1];
  65495. ((int*) dest) [2] = intFiller[2];
  65496. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65497. width -= 4;
  65498. }
  65499. }
  65500. while (--width >= 0)
  65501. {
  65502. dest->set (colour);
  65503. ++dest;
  65504. }
  65505. }
  65506. }
  65507. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65508. {
  65509. memset (dest, colour.getAlpha(), width);
  65510. }
  65511. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65512. {
  65513. do
  65514. {
  65515. dest->set (colour);
  65516. ++dest;
  65517. } while (--width > 0);
  65518. }
  65519. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65520. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65521. };
  65522. class LinearGradientPixelGenerator
  65523. {
  65524. public:
  65525. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65526. : lookupTable (lookupTable_), numEntries (numEntries_)
  65527. {
  65528. jassert (numEntries_ >= 0);
  65529. float x1 = gradient.x1;
  65530. float y1 = gradient.y1;
  65531. float x2 = gradient.x2;
  65532. float y2 = gradient.y2;
  65533. if (! transform.isIdentity())
  65534. {
  65535. const Line l (x2, y2, x1, y1);
  65536. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65537. float x3 = p3.getX();
  65538. float y3 = p3.getY();
  65539. transform.transformPoint (x1, y1);
  65540. transform.transformPoint (x2, y2);
  65541. transform.transformPoint (x3, y3);
  65542. const Line l2 (x2, y2, x3, y3);
  65543. const float prop = l2.findNearestPointTo (x1, y1);
  65544. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65545. x2 = newP2.getX();
  65546. y2 = newP2.getY();
  65547. }
  65548. vertical = fabs (x1 - x2) < 0.001f;
  65549. horizontal = fabs (y1 - y2) < 0.001f;
  65550. if (vertical)
  65551. {
  65552. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65553. start = roundToInt (y1 * scale);
  65554. }
  65555. else if (horizontal)
  65556. {
  65557. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65558. start = roundToInt (x1 * scale);
  65559. }
  65560. else
  65561. {
  65562. grad = (y2 - y1) / (double) (x1 - x2);
  65563. yTerm = y1 - x1 / grad;
  65564. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65565. grad *= scale;
  65566. }
  65567. }
  65568. forcedinline void setY (const int y) throw()
  65569. {
  65570. if (vertical)
  65571. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65572. else if (! horizontal)
  65573. start = roundToInt ((y - yTerm) * grad);
  65574. }
  65575. inline const PixelARGB getPixel (const int x) const throw()
  65576. {
  65577. return vertical ? linePix
  65578. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65579. }
  65580. private:
  65581. const PixelARGB* const lookupTable;
  65582. const int numEntries;
  65583. PixelARGB linePix;
  65584. int start, scale;
  65585. double grad, yTerm;
  65586. bool vertical, horizontal;
  65587. enum { numScaleBits = 12 };
  65588. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65589. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65590. };
  65591. class RadialGradientPixelGenerator
  65592. {
  65593. public:
  65594. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65595. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65596. : lookupTable (lookupTable_),
  65597. numEntries (numEntries_),
  65598. gx1 (gradient.x1),
  65599. gy1 (gradient.y1)
  65600. {
  65601. jassert (numEntries_ >= 0);
  65602. const float gdx = gradient.x1 - gradient.x2;
  65603. const float gdy = gradient.y1 - gradient.y2;
  65604. maxDist = gdx * gdx + gdy * gdy;
  65605. invScale = numEntries / sqrt (maxDist);
  65606. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65607. }
  65608. forcedinline void setY (const int y) throw()
  65609. {
  65610. dy = y - gy1;
  65611. dy *= dy;
  65612. }
  65613. inline const PixelARGB getPixel (const int px) const throw()
  65614. {
  65615. double x = px - gx1;
  65616. x *= x;
  65617. x += dy;
  65618. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65619. }
  65620. protected:
  65621. const PixelARGB* const lookupTable;
  65622. const int numEntries;
  65623. const double gx1, gy1;
  65624. double maxDist, invScale, dy;
  65625. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65626. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65627. };
  65628. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65629. {
  65630. public:
  65631. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65632. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65633. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65634. inverseTransform (transform.inverted())
  65635. {
  65636. tM10 = inverseTransform.mat10;
  65637. tM00 = inverseTransform.mat00;
  65638. }
  65639. forcedinline void setY (const int y) throw()
  65640. {
  65641. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65642. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65643. }
  65644. inline const PixelARGB getPixel (const int px) const throw()
  65645. {
  65646. double x = px;
  65647. const double y = tM10 * x + lineYM11;
  65648. x = tM00 * x + lineYM01;
  65649. x *= x;
  65650. x += y * y;
  65651. if (x >= maxDist)
  65652. return lookupTable [numEntries];
  65653. else
  65654. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65655. }
  65656. private:
  65657. double tM10, tM00, lineYM01, lineYM11;
  65658. const AffineTransform inverseTransform;
  65659. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65660. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65661. };
  65662. template <class PixelType, class GradientType>
  65663. class GradientEdgeTableRenderer : public GradientType
  65664. {
  65665. public:
  65666. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65667. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65668. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65669. destData (destData_)
  65670. {
  65671. }
  65672. forcedinline void setEdgeTableYPos (const int y) throw()
  65673. {
  65674. linePixels = (PixelType*) destData.getLinePointer (y);
  65675. GradientType::setY (y);
  65676. }
  65677. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65678. {
  65679. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65680. }
  65681. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65682. {
  65683. PixelType* dest = linePixels + x;
  65684. if (alphaLevel < 0xff)
  65685. {
  65686. do
  65687. {
  65688. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65689. } while (--width > 0);
  65690. }
  65691. else
  65692. {
  65693. do
  65694. {
  65695. (dest++)->blend (GradientType::getPixel (x++));
  65696. } while (--width > 0);
  65697. }
  65698. }
  65699. private:
  65700. const Image::BitmapData& destData;
  65701. PixelType* linePixels;
  65702. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65703. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65704. };
  65705. static forcedinline int safeModulo (int n, const int divisor) throw()
  65706. {
  65707. jassert (divisor > 0);
  65708. n %= divisor;
  65709. return (n < 0) ? (n + divisor) : n;
  65710. }
  65711. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65712. class ImageFillEdgeTableRenderer
  65713. {
  65714. public:
  65715. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65716. const Image::BitmapData& srcData_,
  65717. const int extraAlpha_,
  65718. const int x, const int y) throw()
  65719. : destData (destData_),
  65720. srcData (srcData_),
  65721. extraAlpha (extraAlpha_ + 1),
  65722. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65723. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65724. {
  65725. }
  65726. forcedinline void setEdgeTableYPos (int y) throw()
  65727. {
  65728. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65729. y -= yOffset;
  65730. if (repeatPattern)
  65731. {
  65732. jassert (y >= 0);
  65733. y %= srcData.height;
  65734. }
  65735. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65736. }
  65737. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65738. {
  65739. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65740. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65741. }
  65742. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65743. {
  65744. DestPixelType* dest = linePixels + x;
  65745. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65746. x -= xOffset;
  65747. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65748. if (alphaLevel < 0xfe)
  65749. {
  65750. do
  65751. {
  65752. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65753. } while (--width > 0);
  65754. }
  65755. else
  65756. {
  65757. if (repeatPattern)
  65758. {
  65759. do
  65760. {
  65761. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65762. } while (--width > 0);
  65763. }
  65764. else
  65765. {
  65766. copyRow (dest, sourceLineStart + x, width);
  65767. }
  65768. }
  65769. }
  65770. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65771. {
  65772. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65773. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65774. uint8* mask = (uint8*) (s + x - xOffset);
  65775. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65776. mask += PixelARGB::indexA;
  65777. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65778. }
  65779. private:
  65780. const Image::BitmapData& destData;
  65781. const Image::BitmapData& srcData;
  65782. const int extraAlpha, xOffset, yOffset;
  65783. DestPixelType* linePixels;
  65784. SrcPixelType* sourceLineStart;
  65785. template <class PixelType1, class PixelType2>
  65786. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65787. {
  65788. do
  65789. {
  65790. dest++ ->blend (*src++);
  65791. } while (--width > 0);
  65792. }
  65793. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65794. {
  65795. memcpy (dest, src, width * sizeof (PixelRGB));
  65796. }
  65797. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65798. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65799. };
  65800. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65801. class TransformedImageFillEdgeTableRenderer
  65802. {
  65803. public:
  65804. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65805. const Image::BitmapData& srcData_,
  65806. const AffineTransform& transform,
  65807. const int extraAlpha_,
  65808. const bool betterQuality_) throw()
  65809. : interpolator (transform),
  65810. destData (destData_),
  65811. srcData (srcData_),
  65812. extraAlpha (extraAlpha_ + 1),
  65813. betterQuality (betterQuality_),
  65814. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65815. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65816. maxX (srcData_.width - 1),
  65817. maxY (srcData_.height - 1),
  65818. scratchSize (2048)
  65819. {
  65820. scratchBuffer.malloc (scratchSize);
  65821. }
  65822. ~TransformedImageFillEdgeTableRenderer() throw()
  65823. {
  65824. }
  65825. forcedinline void setEdgeTableYPos (const int newY) throw()
  65826. {
  65827. y = newY;
  65828. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65829. }
  65830. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65831. {
  65832. alphaLevel *= extraAlpha;
  65833. alphaLevel >>= 8;
  65834. SrcPixelType p;
  65835. generate (&p, x, 1);
  65836. linePixels[x].blend (p, alphaLevel);
  65837. }
  65838. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65839. {
  65840. if (width > scratchSize)
  65841. {
  65842. scratchSize = width;
  65843. scratchBuffer.malloc (scratchSize);
  65844. }
  65845. SrcPixelType* span = scratchBuffer;
  65846. generate (span, x, width);
  65847. DestPixelType* dest = linePixels + x;
  65848. alphaLevel *= extraAlpha;
  65849. alphaLevel >>= 8;
  65850. if (alphaLevel < 0xfe)
  65851. {
  65852. do
  65853. {
  65854. dest++ ->blend (*span++, alphaLevel);
  65855. } while (--width > 0);
  65856. }
  65857. else
  65858. {
  65859. do
  65860. {
  65861. dest++ ->blend (*span++);
  65862. } while (--width > 0);
  65863. }
  65864. }
  65865. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65866. {
  65867. if (width > scratchSize)
  65868. {
  65869. scratchSize = width;
  65870. scratchBuffer.malloc (scratchSize);
  65871. }
  65872. y = y_;
  65873. generate (scratchBuffer, x, width);
  65874. et.clipLineToMask (x, y_,
  65875. reinterpret_cast<uint8*> (scratchBuffer.getData()) + SrcPixelType::indexA,
  65876. sizeof (SrcPixelType), width);
  65877. }
  65878. private:
  65879. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65880. {
  65881. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65882. do
  65883. {
  65884. int hiResX, hiResY;
  65885. this->interpolator.next (hiResX, hiResY);
  65886. hiResX += pixelOffsetInt;
  65887. hiResY += pixelOffsetInt;
  65888. int loResX = hiResX >> 8;
  65889. int loResY = hiResY >> 8;
  65890. if (repeatPattern)
  65891. {
  65892. loResX = safeModulo (loResX, srcData.width);
  65893. loResY = safeModulo (loResY, srcData.height);
  65894. }
  65895. if (betterQuality
  65896. && ((unsigned int) loResX) < (unsigned int) maxX
  65897. && ((unsigned int) loResY) < (unsigned int) maxY)
  65898. {
  65899. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65900. hiResX &= 255;
  65901. hiResY &= 255;
  65902. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65903. uint32 weight = (256 - hiResX) * (256 - hiResY);
  65904. c[0] += weight * src[0];
  65905. c[1] += weight * src[1];
  65906. c[2] += weight * src[2];
  65907. c[3] += weight * src[3];
  65908. weight = hiResX * (256 - hiResY);
  65909. c[0] += weight * src[4];
  65910. c[1] += weight * src[5];
  65911. c[2] += weight * src[6];
  65912. c[3] += weight * src[7];
  65913. src += this->srcData.lineStride;
  65914. weight = (256 - hiResX) * hiResY;
  65915. c[0] += weight * src[0];
  65916. c[1] += weight * src[1];
  65917. c[2] += weight * src[2];
  65918. c[3] += weight * src[3];
  65919. weight = hiResX * hiResY;
  65920. c[0] += weight * src[4];
  65921. c[1] += weight * src[5];
  65922. c[2] += weight * src[6];
  65923. c[3] += weight * src[7];
  65924. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  65925. (uint8) (c[PixelARGB::indexR] >> 16),
  65926. (uint8) (c[PixelARGB::indexG] >> 16),
  65927. (uint8) (c[PixelARGB::indexB] >> 16));
  65928. }
  65929. else
  65930. {
  65931. if (! repeatPattern)
  65932. {
  65933. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65934. if (loResX < 0) loResX = 0;
  65935. if (loResY < 0) loResY = 0;
  65936. if (loResX > maxX) loResX = maxX;
  65937. if (loResY > maxY) loResY = maxY;
  65938. }
  65939. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  65940. }
  65941. ++dest;
  65942. } while (--numPixels > 0);
  65943. }
  65944. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  65945. {
  65946. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65947. do
  65948. {
  65949. int hiResX, hiResY;
  65950. this->interpolator.next (hiResX, hiResY);
  65951. hiResX += pixelOffsetInt;
  65952. hiResY += pixelOffsetInt;
  65953. int loResX = hiResX >> 8;
  65954. int loResY = hiResY >> 8;
  65955. if (repeatPattern)
  65956. {
  65957. loResX = safeModulo (loResX, srcData.width);
  65958. loResY = safeModulo (loResY, srcData.height);
  65959. }
  65960. if (betterQuality
  65961. && ((unsigned int) loResX) < (unsigned int) maxX
  65962. && ((unsigned int) loResY) < (unsigned int) maxY)
  65963. {
  65964. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  65965. hiResX &= 255;
  65966. hiResY &= 255;
  65967. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65968. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  65969. c[0] += weight * src[0];
  65970. c[1] += weight * src[1];
  65971. c[2] += weight * src[2];
  65972. weight = hiResX * (256 - hiResY);
  65973. c[0] += weight * src[3];
  65974. c[1] += weight * src[4];
  65975. c[2] += weight * src[5];
  65976. src += this->srcData.lineStride;
  65977. weight = (256 - hiResX) * hiResY;
  65978. c[0] += weight * src[0];
  65979. c[1] += weight * src[1];
  65980. c[2] += weight * src[2];
  65981. weight = hiResX * hiResY;
  65982. c[0] += weight * src[3];
  65983. c[1] += weight * src[4];
  65984. c[2] += weight * src[5];
  65985. dest->setARGB ((uint8) 255,
  65986. (uint8) (c[PixelRGB::indexR] >> 16),
  65987. (uint8) (c[PixelRGB::indexG] >> 16),
  65988. (uint8) (c[PixelRGB::indexB] >> 16));
  65989. }
  65990. else
  65991. {
  65992. if (! repeatPattern)
  65993. {
  65994. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65995. if (loResX < 0) loResX = 0;
  65996. if (loResY < 0) loResY = 0;
  65997. if (loResX > maxX) loResX = maxX;
  65998. if (loResY > maxY) loResY = maxY;
  65999. }
  66000. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66001. }
  66002. ++dest;
  66003. } while (--numPixels > 0);
  66004. }
  66005. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66006. {
  66007. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66008. do
  66009. {
  66010. int hiResX, hiResY;
  66011. this->interpolator.next (hiResX, hiResY);
  66012. hiResX += pixelOffsetInt;
  66013. hiResY += pixelOffsetInt;
  66014. int loResX = hiResX >> 8;
  66015. int loResY = hiResY >> 8;
  66016. if (repeatPattern)
  66017. {
  66018. loResX = safeModulo (loResX, srcData.width);
  66019. loResY = safeModulo (loResY, srcData.height);
  66020. }
  66021. if (betterQuality
  66022. && ((unsigned int) loResX) < (unsigned int) maxX
  66023. && ((unsigned int) loResY) < (unsigned int) maxY)
  66024. {
  66025. hiResX &= 255;
  66026. hiResY &= 255;
  66027. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66028. uint32 c = 256 * 128;
  66029. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66030. c += src[1] * (hiResX * (256 - hiResY));
  66031. src += this->srcData.lineStride;
  66032. c += src[0] * ((256 - hiResX) * hiResY);
  66033. c += src[1] * (hiResX * hiResY);
  66034. *((uint8*) dest) = (uint8) c;
  66035. }
  66036. else
  66037. {
  66038. if (! repeatPattern)
  66039. {
  66040. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66041. if (loResX < 0) loResX = 0;
  66042. if (loResY < 0) loResY = 0;
  66043. if (loResX > maxX) loResX = maxX;
  66044. if (loResY > maxY) loResY = maxY;
  66045. }
  66046. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66047. }
  66048. ++dest;
  66049. } while (--numPixels > 0);
  66050. }
  66051. class TransformedImageSpanInterpolator
  66052. {
  66053. public:
  66054. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66055. : inverseTransform (transform.inverted())
  66056. {}
  66057. void setStartOfLine (float x, float y, const int numPixels) throw()
  66058. {
  66059. float x1 = x, y1 = y;
  66060. inverseTransform.transformPoint (x1, y1);
  66061. x += numPixels;
  66062. inverseTransform.transformPoint (x, y);
  66063. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66064. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66065. }
  66066. void next (int& x, int& y) throw()
  66067. {
  66068. x = xBresenham.n;
  66069. xBresenham.stepToNext();
  66070. y = yBresenham.n;
  66071. yBresenham.stepToNext();
  66072. }
  66073. private:
  66074. class BresenhamInterpolator
  66075. {
  66076. public:
  66077. BresenhamInterpolator() throw() {}
  66078. void set (const int n1, const int n2, const int numSteps_) throw()
  66079. {
  66080. numSteps = jmax (1, numSteps_);
  66081. step = (n2 - n1) / numSteps;
  66082. remainder = modulo = (n2 - n1) % numSteps;
  66083. n = n1;
  66084. if (modulo <= 0)
  66085. {
  66086. modulo += numSteps;
  66087. remainder += numSteps;
  66088. --step;
  66089. }
  66090. modulo -= numSteps;
  66091. }
  66092. forcedinline void stepToNext() throw()
  66093. {
  66094. modulo += remainder;
  66095. n += step;
  66096. if (modulo > 0)
  66097. {
  66098. modulo -= numSteps;
  66099. ++n;
  66100. }
  66101. }
  66102. int n;
  66103. private:
  66104. int numSteps, step, modulo, remainder;
  66105. };
  66106. const AffineTransform inverseTransform;
  66107. BresenhamInterpolator xBresenham, yBresenham;
  66108. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66109. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66110. };
  66111. TransformedImageSpanInterpolator interpolator;
  66112. const Image::BitmapData& destData;
  66113. const Image::BitmapData& srcData;
  66114. const int extraAlpha;
  66115. const bool betterQuality;
  66116. const float pixelOffset;
  66117. const int pixelOffsetInt, maxX, maxY;
  66118. int y;
  66119. DestPixelType* linePixels;
  66120. HeapBlock <SrcPixelType> scratchBuffer;
  66121. int scratchSize;
  66122. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66123. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66124. };
  66125. class LLGCSavedState
  66126. {
  66127. public:
  66128. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66129. const Font& font_, const FillType& fillType_,
  66130. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66131. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66132. xOffset (xOffset_), yOffset (yOffset_),
  66133. font (font_), fillType (fillType_),
  66134. interpolationQuality (interpolationQuality_)
  66135. {
  66136. }
  66137. LLGCSavedState (const LLGCSavedState& other) throw()
  66138. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66139. yOffset (other.yOffset), font (other.font),
  66140. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66141. {
  66142. }
  66143. ~LLGCSavedState() throw()
  66144. {
  66145. }
  66146. bool clipToRectangle (const Rectangle<int>& r) throw()
  66147. {
  66148. dupeEdgeTableIfMultiplyReferenced();
  66149. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66150. return ! edgeTable->edgeTable.isEmpty();
  66151. }
  66152. bool clipToRectangleList (const RectangleList& r) throw()
  66153. {
  66154. dupeEdgeTableIfMultiplyReferenced();
  66155. RectangleList offsetList (r);
  66156. offsetList.offsetAll (xOffset, yOffset);
  66157. EdgeTable e2 (offsetList);
  66158. edgeTable->edgeTable.clipToEdgeTable (e2);
  66159. return ! edgeTable->edgeTable.isEmpty();
  66160. }
  66161. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66162. {
  66163. dupeEdgeTableIfMultiplyReferenced();
  66164. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66165. return ! edgeTable->edgeTable.isEmpty();
  66166. }
  66167. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66168. {
  66169. dupeEdgeTableIfMultiplyReferenced();
  66170. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66171. edgeTable->edgeTable.clipToEdgeTable (et);
  66172. }
  66173. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66174. {
  66175. et.clipToEdgeTable (edgeTable->edgeTable);
  66176. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66177. if (fillType.isGradient())
  66178. {
  66179. jassert (! replaceContents); // that option is just for solid colours
  66180. ColourGradient g2 (*(fillType.gradient));
  66181. g2.multiplyOpacity (fillType.getOpacity());
  66182. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66183. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66184. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66185. const bool isIdentity = transform.isOnlyTranslation();
  66186. if (isIdentity)
  66187. {
  66188. // If our translation doesn't involve any distortion, we can speed it up..
  66189. transform.transformPoint (g2.x1, g2.y1);
  66190. transform.transformPoint (g2.x2, g2.y2);
  66191. transform = AffineTransform::identity;
  66192. }
  66193. HeapBlock <PixelARGB> lookupTable;
  66194. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66195. jassert (numLookupEntries > 0);
  66196. switch (image.getFormat())
  66197. {
  66198. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66199. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66200. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66201. }
  66202. }
  66203. else if (fillType.isTiledImage())
  66204. {
  66205. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66206. }
  66207. else
  66208. {
  66209. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66210. switch (image.getFormat())
  66211. {
  66212. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66213. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66214. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66215. }
  66216. }
  66217. }
  66218. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66219. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66220. {
  66221. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66222. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66223. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66224. const int alpha = fillType.colour.getAlpha();
  66225. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66226. if (transform.isOnlyTranslation())
  66227. {
  66228. // If our translation doesn't involve any distortion, just use a simple blit..
  66229. int tx = (int) (transform.getTranslationX() * 256.0f);
  66230. int ty = (int) (transform.getTranslationY() * 256.0f);
  66231. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66232. {
  66233. tx = ((tx + 128) >> 8);
  66234. ty = ((ty + 128) >> 8);
  66235. if (tiledFillClipRegion != 0)
  66236. {
  66237. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66238. }
  66239. else
  66240. {
  66241. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66242. et.clipToEdgeTable (edgeTable->edgeTable);
  66243. if (! et.isEmpty())
  66244. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66245. }
  66246. return;
  66247. }
  66248. }
  66249. if (transform.isSingularity())
  66250. return;
  66251. if (tiledFillClipRegion != 0)
  66252. {
  66253. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66254. }
  66255. else
  66256. {
  66257. Path p;
  66258. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66259. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66260. et.clipToEdgeTable (edgeTable->edgeTable);
  66261. if (! et.isEmpty())
  66262. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66263. }
  66264. }
  66265. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66266. {
  66267. if (! image.hasAlphaChannel())
  66268. {
  66269. Path p;
  66270. p.addRectangle (srcClip);
  66271. clipToPath (p, t);
  66272. return;
  66273. }
  66274. dupeEdgeTableIfMultiplyReferenced();
  66275. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66276. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66277. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66278. EdgeTable& et = edgeTable->edgeTable;
  66279. if (transform.isOnlyTranslation())
  66280. {
  66281. // If our translation doesn't involve any distortion, just use a simple blit..
  66282. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66283. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66284. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66285. {
  66286. const int imageX = ((tx + 128) >> 8);
  66287. const int imageY = ((ty + 128) >> 8);
  66288. if (image.getFormat() == Image::ARGB)
  66289. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66290. else
  66291. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66292. return;
  66293. }
  66294. }
  66295. if (transform.isSingularity())
  66296. {
  66297. et.clipToRectangle (Rectangle<int>());
  66298. return;
  66299. }
  66300. {
  66301. Path p;
  66302. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66303. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66304. et.clipToEdgeTable (et2);
  66305. }
  66306. if (! et.isEmpty())
  66307. {
  66308. if (image.getFormat() == Image::ARGB)
  66309. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66310. else
  66311. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66312. }
  66313. }
  66314. template <class SrcPixelType>
  66315. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66316. {
  66317. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66318. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66319. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66320. et.getMaximumBounds().getWidth());
  66321. }
  66322. template <class SrcPixelType>
  66323. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66324. {
  66325. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66326. et.clipToRectangle (r);
  66327. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66328. for (int y = 0; y < r.getHeight(); ++y)
  66329. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66330. }
  66331. class EdgeTableHolder : public ReferenceCountedObject
  66332. {
  66333. public:
  66334. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66335. EdgeTable edgeTable;
  66336. };
  66337. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66338. int xOffset, yOffset;
  66339. Font font;
  66340. FillType fillType;
  66341. Graphics::ResamplingQuality interpolationQuality;
  66342. private:
  66343. LLGCSavedState& operator= (const LLGCSavedState&);
  66344. void dupeEdgeTableIfMultiplyReferenced() throw()
  66345. {
  66346. if (edgeTable->getReferenceCount() > 1)
  66347. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66348. }
  66349. template <class DestPixelType>
  66350. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66351. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66352. {
  66353. jassert (destData.pixelStride == sizeof (DestPixelType));
  66354. if (g.isRadial)
  66355. {
  66356. if (isIdentity)
  66357. {
  66358. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66359. et.iterate (renderer);
  66360. }
  66361. else
  66362. {
  66363. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66364. et.iterate (renderer);
  66365. }
  66366. }
  66367. else
  66368. {
  66369. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66370. et.iterate (renderer);
  66371. }
  66372. }
  66373. template <class DestPixelType>
  66374. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66375. {
  66376. jassert (destData.pixelStride == sizeof (DestPixelType));
  66377. if (replaceContents)
  66378. {
  66379. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66380. et.iterate (r);
  66381. }
  66382. else
  66383. {
  66384. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66385. et.iterate (r);
  66386. }
  66387. }
  66388. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66389. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66390. {
  66391. switch (destImage.getFormat())
  66392. {
  66393. case Image::ARGB:
  66394. switch (srcImage.getFormat())
  66395. {
  66396. case Image::ARGB:
  66397. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66398. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66399. break;
  66400. case Image::RGB:
  66401. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66402. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66403. break;
  66404. default:
  66405. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66406. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66407. break;
  66408. }
  66409. break;
  66410. case Image::RGB:
  66411. switch (srcImage.getFormat())
  66412. {
  66413. case Image::ARGB:
  66414. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66415. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66416. break;
  66417. case Image::RGB:
  66418. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66419. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66420. break;
  66421. default:
  66422. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66423. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66424. break;
  66425. }
  66426. break;
  66427. default:
  66428. switch (srcImage.getFormat())
  66429. {
  66430. case Image::ARGB:
  66431. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66432. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66433. break;
  66434. case Image::RGB:
  66435. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66436. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66437. break;
  66438. default:
  66439. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66440. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66441. break;
  66442. }
  66443. break;
  66444. }
  66445. }
  66446. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66447. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66448. {
  66449. switch (destImage.getFormat())
  66450. {
  66451. case Image::ARGB:
  66452. switch (srcImage.getFormat())
  66453. {
  66454. case Image::ARGB:
  66455. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66456. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66457. break;
  66458. case Image::RGB:
  66459. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66460. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66461. break;
  66462. default:
  66463. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66464. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66465. break;
  66466. }
  66467. break;
  66468. case Image::RGB:
  66469. switch (srcImage.getFormat())
  66470. {
  66471. case Image::ARGB:
  66472. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66473. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66474. break;
  66475. case Image::RGB:
  66476. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66477. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66478. break;
  66479. default:
  66480. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66481. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66482. break;
  66483. }
  66484. break;
  66485. default:
  66486. switch (srcImage.getFormat())
  66487. {
  66488. case Image::ARGB:
  66489. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66490. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66491. break;
  66492. case Image::RGB:
  66493. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66494. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66495. break;
  66496. default:
  66497. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66498. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66499. break;
  66500. }
  66501. break;
  66502. }
  66503. }
  66504. };
  66505. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66506. : image (image_)
  66507. {
  66508. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66509. FillType(), Graphics::mediumResamplingQuality);
  66510. }
  66511. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66512. {
  66513. }
  66514. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66515. {
  66516. return false;
  66517. }
  66518. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66519. {
  66520. currentState->xOffset += x;
  66521. currentState->yOffset += y;
  66522. }
  66523. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66524. {
  66525. return currentState->clipToRectangle (r);
  66526. }
  66527. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66528. {
  66529. return currentState->clipToRectangleList (clipRegion);
  66530. }
  66531. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66532. {
  66533. currentState->excludeClipRectangle (r);
  66534. }
  66535. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66536. {
  66537. currentState->clipToPath (path, transform);
  66538. }
  66539. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66540. {
  66541. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66542. }
  66543. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66544. {
  66545. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66546. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66547. }
  66548. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66549. {
  66550. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66551. }
  66552. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66553. {
  66554. return currentState->edgeTable->edgeTable.isEmpty();
  66555. }
  66556. void LowLevelGraphicsSoftwareRenderer::saveState()
  66557. {
  66558. stateStack.add (new LLGCSavedState (*currentState));
  66559. }
  66560. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66561. {
  66562. LLGCSavedState* const top = stateStack.getLast();
  66563. if (top != 0)
  66564. {
  66565. currentState = top;
  66566. stateStack.removeLast (1, false);
  66567. }
  66568. else
  66569. {
  66570. jassertfalse // trying to pop with an empty stack!
  66571. }
  66572. }
  66573. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66574. {
  66575. currentState->fillType = fillType;
  66576. }
  66577. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66578. {
  66579. currentState->fillType.setOpacity (newOpacity);
  66580. }
  66581. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66582. {
  66583. currentState->interpolationQuality = quality;
  66584. }
  66585. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66586. {
  66587. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66588. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66589. if (! clipped.isEmpty())
  66590. {
  66591. EdgeTable et (clipped);
  66592. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66593. }
  66594. }
  66595. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66596. {
  66597. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66598. path, transform.translated ((float) currentState->xOffset,
  66599. (float) currentState->yOffset));
  66600. currentState->fillEdgeTable (image, et);
  66601. }
  66602. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66603. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66604. {
  66605. jassert (sourceImage.getBounds().contains (srcClip));
  66606. currentState->renderImage (image, sourceImage, srcClip, transform,
  66607. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66608. }
  66609. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66610. {
  66611. Path p;
  66612. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66613. fillPath (p, AffineTransform::identity);
  66614. }
  66615. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66616. {
  66617. if (bottom > top)
  66618. {
  66619. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66620. currentState->fillEdgeTable (image, et);
  66621. }
  66622. }
  66623. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66624. {
  66625. if (right > left)
  66626. {
  66627. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66628. (float) (right - left), 1.0f);
  66629. currentState->fillEdgeTable (image, et);
  66630. }
  66631. }
  66632. class GlyphCache : private DeletedAtShutdown
  66633. {
  66634. public:
  66635. GlyphCache() throw()
  66636. : accessCounter (0), hits (0), misses (0)
  66637. {
  66638. for (int i = 120; --i >= 0;)
  66639. glyphs.add (new CachedGlyph());
  66640. }
  66641. ~GlyphCache() throw()
  66642. {
  66643. clearSingletonInstance();
  66644. }
  66645. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66646. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66647. {
  66648. ++accessCounter;
  66649. int oldestCounter = std::numeric_limits<int>::max();
  66650. CachedGlyph* oldest = 0;
  66651. for (int i = glyphs.size(); --i >= 0;)
  66652. {
  66653. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66654. if (glyph->glyph == glyphNumber && glyph->font == font)
  66655. {
  66656. ++hits;
  66657. glyph->lastAccessCount = accessCounter;
  66658. glyph->draw (state, image, x, y);
  66659. return;
  66660. }
  66661. if (glyph->lastAccessCount <= oldestCounter)
  66662. {
  66663. oldestCounter = glyph->lastAccessCount;
  66664. oldest = glyph;
  66665. }
  66666. }
  66667. if (hits + ++misses > (glyphs.size() << 4))
  66668. {
  66669. if (misses * 2 > hits)
  66670. {
  66671. for (int i = 32; --i >= 0;)
  66672. glyphs.add (new CachedGlyph());
  66673. }
  66674. hits = misses = 0;
  66675. oldest = glyphs.getLast();
  66676. }
  66677. jassert (oldest != 0);
  66678. oldest->lastAccessCount = accessCounter;
  66679. oldest->generate (font, glyphNumber);
  66680. oldest->draw (state, image, x, y);
  66681. }
  66682. class CachedGlyph
  66683. {
  66684. public:
  66685. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66686. ~CachedGlyph() {}
  66687. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66688. {
  66689. if (edgeTable != 0)
  66690. {
  66691. EdgeTable et (*edgeTable);
  66692. et.translate (x, roundToInt (y));
  66693. state.fillEdgeTable (image, et, false);
  66694. }
  66695. }
  66696. void generate (const Font& newFont, const int glyphNumber) throw()
  66697. {
  66698. font = newFont;
  66699. glyph = glyphNumber;
  66700. edgeTable = 0;
  66701. Path glyphPath;
  66702. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66703. if (! glyphPath.isEmpty())
  66704. {
  66705. const float fontHeight = font.getHeight();
  66706. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66707. .translated (0.0f, -0.5f));
  66708. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66709. glyphPath, transform);
  66710. }
  66711. }
  66712. int glyph, lastAccessCount;
  66713. Font font;
  66714. juce_UseDebuggingNewOperator
  66715. private:
  66716. ScopedPointer <EdgeTable> edgeTable;
  66717. CachedGlyph (const CachedGlyph&);
  66718. CachedGlyph& operator= (const CachedGlyph&);
  66719. };
  66720. juce_UseDebuggingNewOperator
  66721. private:
  66722. OwnedArray <CachedGlyph> glyphs;
  66723. int accessCounter, hits, misses;
  66724. GlyphCache (const GlyphCache&);
  66725. GlyphCache& operator= (const GlyphCache&);
  66726. };
  66727. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66728. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66729. {
  66730. currentState->font = newFont;
  66731. }
  66732. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66733. {
  66734. return currentState->font;
  66735. }
  66736. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66737. {
  66738. Font& f = currentState->font;
  66739. if (transform.isOnlyTranslation())
  66740. {
  66741. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66742. transform.getTranslationX() + (float) currentState->xOffset,
  66743. transform.getTranslationY() + (float) currentState->yOffset);
  66744. }
  66745. else
  66746. {
  66747. Path p;
  66748. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66749. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66750. }
  66751. }
  66752. #if JUCE_MSVC
  66753. #pragma warning (pop)
  66754. #endif
  66755. END_JUCE_NAMESPACE
  66756. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66757. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66758. BEGIN_JUCE_NAMESPACE
  66759. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66760. : flags (other.flags)
  66761. {
  66762. }
  66763. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66764. {
  66765. flags = other.flags;
  66766. return *this;
  66767. }
  66768. void RectanglePlacement::applyTo (double& x, double& y,
  66769. double& w, double& h,
  66770. const double dx, const double dy,
  66771. const double dw, const double dh) const throw()
  66772. {
  66773. if (w == 0 || h == 0)
  66774. return;
  66775. if ((flags & stretchToFit) != 0)
  66776. {
  66777. x = dx;
  66778. y = dy;
  66779. w = dw;
  66780. h = dh;
  66781. }
  66782. else
  66783. {
  66784. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66785. : jmin (dw / w, dh / h);
  66786. if ((flags & onlyReduceInSize) != 0)
  66787. scale = jmin (scale, 1.0);
  66788. if ((flags & onlyIncreaseInSize) != 0)
  66789. scale = jmax (scale, 1.0);
  66790. w *= scale;
  66791. h *= scale;
  66792. if ((flags & xLeft) != 0)
  66793. x = dx;
  66794. else if ((flags & xRight) != 0)
  66795. x = dx + dw - w;
  66796. else
  66797. x = dx + (dw - w) * 0.5;
  66798. if ((flags & yTop) != 0)
  66799. y = dy;
  66800. else if ((flags & yBottom) != 0)
  66801. y = dy + dh - h;
  66802. else
  66803. y = dy + (dh - h) * 0.5;
  66804. }
  66805. }
  66806. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66807. float w, float h,
  66808. const float dx, const float dy,
  66809. const float dw, const float dh) const throw()
  66810. {
  66811. if (w == 0 || h == 0)
  66812. return AffineTransform::identity;
  66813. const float scaleX = dw / w;
  66814. const float scaleY = dh / h;
  66815. if ((flags & stretchToFit) != 0)
  66816. return AffineTransform::translation (-x, -y)
  66817. .scaled (scaleX, scaleY)
  66818. .translated (dx, dy);
  66819. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66820. : jmin (scaleX, scaleY);
  66821. if ((flags & onlyReduceInSize) != 0)
  66822. scale = jmin (scale, 1.0f);
  66823. if ((flags & onlyIncreaseInSize) != 0)
  66824. scale = jmax (scale, 1.0f);
  66825. w *= scale;
  66826. h *= scale;
  66827. float newX = dx;
  66828. if ((flags & xRight) != 0)
  66829. newX += dw - w; // right
  66830. else if ((flags & xLeft) == 0)
  66831. newX += (dw - w) / 2.0f; // centre
  66832. float newY = dy;
  66833. if ((flags & yBottom) != 0)
  66834. newY += dh - h; // bottom
  66835. else if ((flags & yTop) == 0)
  66836. newY += (dh - h) / 2.0f; // centre
  66837. return AffineTransform::translation (-x, -y)
  66838. .scaled (scale, scale)
  66839. .translated (newX, newY);
  66840. }
  66841. END_JUCE_NAMESPACE
  66842. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66843. /*** Start of inlined file: juce_Drawable.cpp ***/
  66844. BEGIN_JUCE_NAMESPACE
  66845. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66846. const AffineTransform& transform_,
  66847. const float opacity_) throw()
  66848. : g (g_),
  66849. transform (transform_),
  66850. opacity (opacity_)
  66851. {
  66852. }
  66853. Drawable::Drawable()
  66854. {
  66855. }
  66856. Drawable::~Drawable()
  66857. {
  66858. }
  66859. void Drawable::draw (Graphics& g, const float opacity,
  66860. const AffineTransform& transform) const
  66861. {
  66862. render (RenderingContext (g, transform, opacity));
  66863. }
  66864. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66865. {
  66866. draw (g, opacity, AffineTransform::translation (x, y));
  66867. }
  66868. void Drawable::drawWithin (Graphics& g,
  66869. const int destX,
  66870. const int destY,
  66871. const int destW,
  66872. const int destH,
  66873. const RectanglePlacement& placement,
  66874. const float opacity) const
  66875. {
  66876. if (destW > 0 && destH > 0)
  66877. {
  66878. Rectangle<float> bounds (getBounds());
  66879. draw (g, opacity,
  66880. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66881. (float) destX, (float) destY,
  66882. (float) destW, (float) destH));
  66883. }
  66884. }
  66885. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66886. {
  66887. Drawable* result = 0;
  66888. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66889. if (image != 0)
  66890. {
  66891. DrawableImage* const di = new DrawableImage();
  66892. di->setImage (image, true);
  66893. result = di;
  66894. }
  66895. else
  66896. {
  66897. const String asString (String::createStringFromData (data, (int) numBytes));
  66898. XmlDocument doc (asString);
  66899. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66900. if (outer != 0 && outer->hasTagName ("svg"))
  66901. {
  66902. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  66903. if (svg != 0)
  66904. result = Drawable::createFromSVG (*svg);
  66905. }
  66906. }
  66907. return result;
  66908. }
  66909. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  66910. {
  66911. MemoryBlock mb;
  66912. dataSource.readIntoMemoryBlock (mb);
  66913. return createFromImageData (mb.getData(), mb.getSize());
  66914. }
  66915. Drawable* Drawable::createFromImageFile (const File& file)
  66916. {
  66917. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  66918. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  66919. }
  66920. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  66921. {
  66922. Drawable* d = DrawablePath::createFromValueTree (tree);
  66923. if (d == 0)
  66924. {
  66925. d = DrawableComposite::createFromValueTree (tree);
  66926. if (d == 0)
  66927. {
  66928. d = DrawableImage::createFromValueTree (tree);
  66929. if (d == 0)
  66930. d = DrawableText::createFromValueTree (tree);
  66931. }
  66932. }
  66933. return d;
  66934. }
  66935. END_JUCE_NAMESPACE
  66936. /*** End of inlined file: juce_Drawable.cpp ***/
  66937. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  66938. BEGIN_JUCE_NAMESPACE
  66939. DrawableComposite::DrawableComposite()
  66940. {
  66941. }
  66942. DrawableComposite::~DrawableComposite()
  66943. {
  66944. }
  66945. void DrawableComposite::insertDrawable (Drawable* drawable,
  66946. const AffineTransform& transform,
  66947. const int index)
  66948. {
  66949. if (drawable != 0)
  66950. {
  66951. if (! drawables.contains (drawable))
  66952. {
  66953. drawables.insert (index, drawable);
  66954. if (transform.isIdentity())
  66955. transforms.insert (index, 0);
  66956. else
  66957. transforms.insert (index, new AffineTransform (transform));
  66958. }
  66959. else
  66960. {
  66961. jassertfalse // trying to add a drawable that's already in here!
  66962. }
  66963. }
  66964. }
  66965. void DrawableComposite::insertDrawable (const Drawable& drawable,
  66966. const AffineTransform& transform,
  66967. const int index)
  66968. {
  66969. insertDrawable (drawable.createCopy(), transform, index);
  66970. }
  66971. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  66972. {
  66973. drawables.remove (index, deleteDrawable);
  66974. transforms.remove (index);
  66975. }
  66976. void DrawableComposite::bringToFront (const int index)
  66977. {
  66978. if (index >= 0 && index < drawables.size() - 1)
  66979. {
  66980. drawables.move (index, -1);
  66981. transforms.move (index, -1);
  66982. }
  66983. }
  66984. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  66985. {
  66986. if (drawables.size() > 0 && context.opacity > 0)
  66987. {
  66988. if (context.opacity >= 1.0f || drawables.size() == 1)
  66989. {
  66990. Drawable::RenderingContext contextCopy (context);
  66991. for (int i = 0; i < drawables.size(); ++i)
  66992. {
  66993. const AffineTransform* const t = transforms.getUnchecked(i);
  66994. contextCopy.transform = (t == 0) ? context.transform
  66995. : t->followedBy (context.transform);
  66996. drawables.getUnchecked(i)->render (contextCopy);
  66997. }
  66998. }
  66999. else
  67000. {
  67001. // To correctly render a whole composite layer with an overall transparency,
  67002. // we need to render everything opaquely into a temp buffer, then blend that
  67003. // with the target opacity...
  67004. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67005. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67006. {
  67007. Graphics tempG (tempImage);
  67008. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67009. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67010. render (tempContext);
  67011. }
  67012. context.g.setOpacity (context.opacity);
  67013. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67014. }
  67015. }
  67016. }
  67017. const Rectangle<float> DrawableComposite::getBounds() const
  67018. {
  67019. Rectangle<float> bounds;
  67020. for (int i = 0; i < drawables.size(); ++i)
  67021. {
  67022. const Drawable* const d = drawables.getUnchecked(i);
  67023. const AffineTransform* const t = transforms.getUnchecked(i);
  67024. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  67025. : d->getBounds().transformed (*t));
  67026. if (bounds.isEmpty())
  67027. bounds = childBounds;
  67028. else if (! childBounds.isEmpty())
  67029. bounds = bounds.getUnion (childBounds);
  67030. }
  67031. return bounds;
  67032. }
  67033. bool DrawableComposite::hitTest (float x, float y) const
  67034. {
  67035. for (int i = 0; i < drawables.size(); ++i)
  67036. {
  67037. float tx = x;
  67038. float ty = y;
  67039. const AffineTransform* const t = transforms.getUnchecked(i);
  67040. if (t != 0)
  67041. t->inverted().transformPoint (tx, ty);
  67042. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67043. return true;
  67044. }
  67045. return false;
  67046. }
  67047. Drawable* DrawableComposite::createCopy() const
  67048. {
  67049. DrawableComposite* const dc = new DrawableComposite();
  67050. for (int i = 0; i < drawables.size(); ++i)
  67051. {
  67052. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67053. const AffineTransform* const t = transforms.getUnchecked(i);
  67054. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67055. }
  67056. return dc;
  67057. }
  67058. ValueTree DrawableComposite::createValueTree() const throw()
  67059. {
  67060. ValueTree v ("Group");
  67061. if (getName().isNotEmpty())
  67062. v.setProperty ("id", getName(), 0);
  67063. for (int i = 0; i < drawables.size(); ++i)
  67064. {
  67065. Drawable* const d = drawables.getUnchecked(i);
  67066. ValueTree child (d->createValueTree());
  67067. AffineTransform* transform = transforms.getUnchecked(i);
  67068. if (transform != 0)
  67069. {
  67070. String t;
  67071. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67072. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67073. child.setProperty ("transform", t, 0);
  67074. }
  67075. v.addChild (child, -1, 0);
  67076. }
  67077. return v;
  67078. }
  67079. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67080. {
  67081. if (! tree.hasType ("Group"))
  67082. return 0;
  67083. DrawableComposite* dc = new DrawableComposite();
  67084. dc->setName (tree ["id"]);
  67085. for (int i = 0; i < tree.getNumChildren(); ++i)
  67086. {
  67087. ValueTree childTree (tree.getChild (i));
  67088. Drawable* d = Drawable::createFromValueTree (childTree);
  67089. if (d != 0)
  67090. {
  67091. AffineTransform transform;
  67092. const String transformAtt (childTree ["transform"].toString());
  67093. if (transformAtt.isNotEmpty())
  67094. {
  67095. StringArray tokens;
  67096. tokens.addTokens (transformAtt.trim(), false);
  67097. tokens.removeEmptyStrings (true);
  67098. if (tokens.size() == 6)
  67099. {
  67100. float f[6];
  67101. for (int j = 0; j < 6; ++j)
  67102. f[j] = (float) tokens[j].getDoubleValue();
  67103. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67104. }
  67105. }
  67106. dc->insertDrawable (d, transform);
  67107. }
  67108. }
  67109. return dc;
  67110. }
  67111. END_JUCE_NAMESPACE
  67112. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67113. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67114. BEGIN_JUCE_NAMESPACE
  67115. DrawableImage::DrawableImage()
  67116. : image (0),
  67117. canDeleteImage (false),
  67118. opacity (1.0f),
  67119. overlayColour (0x00000000)
  67120. {
  67121. }
  67122. DrawableImage::~DrawableImage()
  67123. {
  67124. clearImage();
  67125. }
  67126. void DrawableImage::clearImage()
  67127. {
  67128. if (canDeleteImage && image != 0)
  67129. ImageCache::releaseOrDelete (image);
  67130. image = 0;
  67131. }
  67132. void DrawableImage::setImage (const Image& imageToCopy)
  67133. {
  67134. clearImage();
  67135. image = new Image (imageToCopy);
  67136. canDeleteImage = true;
  67137. }
  67138. void DrawableImage::setImage (Image* imageToUse,
  67139. const bool releaseWhenNotNeeded)
  67140. {
  67141. clearImage();
  67142. image = imageToUse;
  67143. canDeleteImage = releaseWhenNotNeeded;
  67144. }
  67145. void DrawableImage::setOpacity (const float newOpacity)
  67146. {
  67147. opacity = newOpacity;
  67148. }
  67149. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67150. {
  67151. overlayColour = newOverlayColour;
  67152. }
  67153. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67154. {
  67155. if (image != 0)
  67156. {
  67157. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67158. {
  67159. context.g.setOpacity (context.opacity * opacity);
  67160. context.g.drawImageTransformed (image, image->getBounds(),
  67161. context.transform, false);
  67162. }
  67163. if (! overlayColour.isTransparent())
  67164. {
  67165. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67166. context.g.drawImageTransformed (image, image->getBounds(),
  67167. context.transform, true);
  67168. }
  67169. }
  67170. }
  67171. const Rectangle<float> DrawableImage::getBounds() const
  67172. {
  67173. if (image == 0)
  67174. return Rectangle<float>();
  67175. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67176. }
  67177. bool DrawableImage::hitTest (float x, float y) const
  67178. {
  67179. return image != 0
  67180. && x >= 0.0f
  67181. && y >= 0.0f
  67182. && x < image->getWidth()
  67183. && y < image->getHeight()
  67184. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67185. }
  67186. Drawable* DrawableImage::createCopy() const
  67187. {
  67188. DrawableImage* const di = new DrawableImage();
  67189. di->opacity = opacity;
  67190. di->overlayColour = overlayColour;
  67191. if (image != 0)
  67192. {
  67193. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67194. {
  67195. di->setImage (*image);
  67196. }
  67197. else
  67198. {
  67199. ImageCache::incReferenceCount (image);
  67200. di->setImage (image, true);
  67201. }
  67202. }
  67203. return di;
  67204. }
  67205. ValueTree DrawableImage::createValueTree() const throw()
  67206. {
  67207. ValueTree v ("Image");
  67208. if (getName().isNotEmpty())
  67209. v.setProperty ("id", getName(), 0);
  67210. if (opacity < 1.0f)
  67211. v.setProperty ("opacity", (double) opacity, 0);
  67212. if (! overlayColour.isTransparent())
  67213. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67214. if (image != 0)
  67215. {
  67216. MemoryOutputStream imageData;
  67217. PNGImageFormat pngFormat;
  67218. if (pngFormat.writeImageToStream (*image, imageData))
  67219. {
  67220. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67221. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67222. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67223. v.setProperty ("data", base64, 0);
  67224. }
  67225. }
  67226. return v;
  67227. }
  67228. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67229. {
  67230. if (! tree.hasType ("Image"))
  67231. return 0;
  67232. DrawableImage* di = new DrawableImage();
  67233. di->setName (tree ["id"]);
  67234. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67235. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67236. MemoryBlock imageData;
  67237. if (imageData.fromBase64Encoding (tree ["data"]))
  67238. {
  67239. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67240. if (im == 0)
  67241. return false;
  67242. di->setImage (im, true);
  67243. }
  67244. return di;
  67245. }
  67246. END_JUCE_NAMESPACE
  67247. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67248. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67249. BEGIN_JUCE_NAMESPACE
  67250. DrawablePath::DrawablePath()
  67251. : mainFill (FillType (Colours::black)),
  67252. strokeFill (FillType (Colours::transparentBlack)),
  67253. strokeType (0.0f)
  67254. {
  67255. }
  67256. DrawablePath::~DrawablePath()
  67257. {
  67258. }
  67259. void DrawablePath::setPath (const Path& newPath) throw()
  67260. {
  67261. path = newPath;
  67262. updateOutline();
  67263. }
  67264. void DrawablePath::setFill (const FillType& newFill) throw()
  67265. {
  67266. mainFill = newFill;
  67267. }
  67268. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67269. {
  67270. strokeFill = newFill;
  67271. }
  67272. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67273. {
  67274. strokeType = newStrokeType;
  67275. updateOutline();
  67276. }
  67277. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67278. {
  67279. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67280. }
  67281. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67282. {
  67283. {
  67284. FillType f (mainFill);
  67285. if (f.isGradient())
  67286. f.gradient->multiplyOpacity (context.opacity);
  67287. f.transform = f.transform.followedBy (context.transform);
  67288. context.g.setFillType (f);
  67289. context.g.fillPath (path, context.transform);
  67290. }
  67291. if (strokeType.getStrokeThickness() > 0.0f)
  67292. {
  67293. FillType f (strokeFill);
  67294. if (f.isGradient())
  67295. f.gradient->multiplyOpacity (context.opacity);
  67296. f.transform = f.transform.followedBy (context.transform);
  67297. context.g.setFillType (f);
  67298. context.g.fillPath (stroke, context.transform);
  67299. }
  67300. }
  67301. void DrawablePath::updateOutline()
  67302. {
  67303. stroke.clear();
  67304. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67305. }
  67306. const Rectangle<float> DrawablePath::getBounds() const
  67307. {
  67308. if (strokeType.getStrokeThickness() > 0.0f)
  67309. return stroke.getBounds();
  67310. else
  67311. return path.getBounds();
  67312. }
  67313. bool DrawablePath::hitTest (float x, float y) const
  67314. {
  67315. return path.contains (x, y)
  67316. || stroke.contains (x, y);
  67317. }
  67318. Drawable* DrawablePath::createCopy() const
  67319. {
  67320. DrawablePath* const dp = new DrawablePath();
  67321. dp->path = path;
  67322. dp->stroke = stroke;
  67323. dp->mainFill = mainFill;
  67324. dp->strokeFill = strokeFill;
  67325. dp->strokeType = strokeType;
  67326. return dp;
  67327. }
  67328. static const FillType readFillTypeFromTree (const ValueTree& v)
  67329. {
  67330. const String type (v["type"].toString());
  67331. if (type.equalsIgnoreCase ("solid"))
  67332. {
  67333. const String colour (v ["colour"].toString());
  67334. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67335. : (uint32) colour.getHexValue32()));
  67336. }
  67337. else if (type.equalsIgnoreCase ("gradient"))
  67338. {
  67339. ColourGradient g;
  67340. g.x1 = v["x1"];
  67341. g.y1 = v["y1"];
  67342. g.x2 = v["x2"];
  67343. g.y2 = v["y2"];
  67344. g.isRadial = v["radial"];
  67345. StringArray colours;
  67346. colours.addTokens (v["colours"].toString(), false);
  67347. for (int i = 0; i < colours.size() / 2; ++i)
  67348. g.addColour (colours[i * 2].getDoubleValue(),
  67349. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67350. return FillType (g);
  67351. }
  67352. jassertfalse
  67353. return FillType();
  67354. }
  67355. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67356. {
  67357. ValueTree v (tagName);
  67358. if (fillType.isColour())
  67359. {
  67360. v.setProperty ("type", "solid", 0);
  67361. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67362. }
  67363. else if (fillType.isGradient())
  67364. {
  67365. v.setProperty ("type", "gradient", 0);
  67366. v.setProperty ("x1", fillType.gradient->x1, 0);
  67367. v.setProperty ("y1", fillType.gradient->y1, 0);
  67368. v.setProperty ("x2", fillType.gradient->x2, 0);
  67369. v.setProperty ("y2", fillType.gradient->y2, 0);
  67370. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67371. String s;
  67372. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67373. s << " " << fillType.gradient->getColourPosition (i)
  67374. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67375. v.setProperty ("colours", s.trimStart(), 0);
  67376. }
  67377. else
  67378. {
  67379. jassertfalse //xxx
  67380. }
  67381. return v;
  67382. }
  67383. ValueTree DrawablePath::createValueTree() const throw()
  67384. {
  67385. ValueTree v ("Path");
  67386. v.addChild (createTreeForFillType ("fill", mainFill), -1, 0);
  67387. v.addChild (createTreeForFillType ("stroke", strokeFill), -1, 0);
  67388. if (getName().isNotEmpty())
  67389. v.setProperty ("id", getName(), 0);
  67390. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67391. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67392. ? "miter" : (strokeType.getJointStyle() == PathStrokeType::curved ? "curved" : "bevel"), 0);
  67393. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67394. ? "butt" : (strokeType.getEndStyle() == PathStrokeType::square ? "square" : "round"), 0);
  67395. v.setProperty ("path", path.toString(), 0);
  67396. return v;
  67397. }
  67398. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67399. {
  67400. if (! tree.hasType ("Path"))
  67401. return 0;
  67402. DrawablePath* p = new DrawablePath();
  67403. p->setName (tree ["id"]);
  67404. p->mainFill = readFillTypeFromTree (tree.getChildWithName ("fill"));
  67405. p->strokeFill = readFillTypeFromTree (tree.getChildWithName ("stroke"));
  67406. const String jointStyle (tree ["jointStyle"].toString());
  67407. const String endStyle (tree ["capStyle"].toString());
  67408. p->strokeType
  67409. = PathStrokeType (tree ["strokeWidth"],
  67410. jointStyle.equalsIgnoreCase ("curved") ? PathStrokeType::curved
  67411. : (jointStyle.equalsIgnoreCase ("bevel") ? PathStrokeType::beveled
  67412. : PathStrokeType::mitered),
  67413. endStyle.equalsIgnoreCase ("square") ? PathStrokeType::square
  67414. : (endStyle.equalsIgnoreCase ("round") ? PathStrokeType::rounded
  67415. : PathStrokeType::butt));
  67416. p->path.clear();
  67417. p->path.restoreFromString (tree ["path"]);
  67418. p->updateOutline();
  67419. return p;
  67420. }
  67421. END_JUCE_NAMESPACE
  67422. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67423. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67424. BEGIN_JUCE_NAMESPACE
  67425. DrawableText::DrawableText()
  67426. : colour (Colours::white)
  67427. {
  67428. }
  67429. DrawableText::~DrawableText()
  67430. {
  67431. }
  67432. void DrawableText::setText (const GlyphArrangement& newText)
  67433. {
  67434. text = newText;
  67435. }
  67436. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67437. {
  67438. text.clear();
  67439. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67440. }
  67441. void DrawableText::setColour (const Colour& newColour)
  67442. {
  67443. colour = newColour;
  67444. }
  67445. void DrawableText::render (const Drawable::RenderingContext& context) const
  67446. {
  67447. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67448. text.draw (context.g, context.transform);
  67449. }
  67450. const Rectangle<float> DrawableText::getBounds() const
  67451. {
  67452. float x, y, w, h;
  67453. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67454. w -= x;
  67455. h -= y;
  67456. return Rectangle<float> (x, y, w, h);
  67457. }
  67458. bool DrawableText::hitTest (float x, float y) const
  67459. {
  67460. return text.findGlyphIndexAt (x, y) >= 0;
  67461. }
  67462. Drawable* DrawableText::createCopy() const
  67463. {
  67464. DrawableText* const dt = new DrawableText();
  67465. dt->text = text;
  67466. dt->colour = colour;
  67467. return dt;
  67468. }
  67469. ValueTree DrawableText::createValueTree() const throw()
  67470. {
  67471. ValueTree v ("Text");
  67472. if (getName().isNotEmpty())
  67473. v.setProperty ("id", getName(), 0);
  67474. jassertfalse // xxx not finished!
  67475. return v;
  67476. }
  67477. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67478. {
  67479. if (! tree.hasType ("Text"))
  67480. return 0;
  67481. DrawableText* dt = new DrawableText();
  67482. dt->setName (tree ["id"]);
  67483. jassertfalse // xxx not finished!
  67484. return dt;
  67485. }
  67486. END_JUCE_NAMESPACE
  67487. /*** End of inlined file: juce_DrawableText.cpp ***/
  67488. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67489. BEGIN_JUCE_NAMESPACE
  67490. class SVGState
  67491. {
  67492. public:
  67493. SVGState (const XmlElement* const topLevel)
  67494. : topLevelXml (topLevel),
  67495. elementX (0), elementY (0),
  67496. width (512), height (512),
  67497. viewBoxW (0), viewBoxH (0)
  67498. {
  67499. }
  67500. ~SVGState()
  67501. {
  67502. }
  67503. Drawable* parseSVGElement (const XmlElement& xml)
  67504. {
  67505. if (! xml.hasTagName ("svg"))
  67506. return 0;
  67507. DrawableComposite* const drawable = new DrawableComposite();
  67508. drawable->setName (xml.getStringAttribute ("id"));
  67509. SVGState newState (*this);
  67510. if (xml.hasAttribute ("transform"))
  67511. newState.addTransform (xml);
  67512. newState.elementX = getCoordLength (xml.getStringAttribute ("x", String (newState.elementX)), viewBoxW);
  67513. newState.elementY = getCoordLength (xml.getStringAttribute ("y", String (newState.elementY)), viewBoxH);
  67514. newState.width = getCoordLength (xml.getStringAttribute ("width", String (newState.width)), viewBoxW);
  67515. newState.height = getCoordLength (xml.getStringAttribute ("height", String (newState.height)), viewBoxH);
  67516. if (xml.hasAttribute ("viewBox"))
  67517. {
  67518. const String viewParams (xml.getStringAttribute ("viewBox"));
  67519. int i = 0;
  67520. float vx, vy, vw, vh;
  67521. if (parseCoords (viewParams, vx, vy, i, true)
  67522. && parseCoords (viewParams, vw, vh, i, true)
  67523. && vw > 0
  67524. && vh > 0)
  67525. {
  67526. newState.viewBoxW = vw;
  67527. newState.viewBoxH = vh;
  67528. int placementFlags = 0;
  67529. const String aspect (xml.getStringAttribute ("preserveAspectRatio"));
  67530. if (aspect.containsIgnoreCase ("none"))
  67531. {
  67532. placementFlags = RectanglePlacement::stretchToFit;
  67533. }
  67534. else
  67535. {
  67536. if (aspect.containsIgnoreCase ("slice"))
  67537. placementFlags |= RectanglePlacement::fillDestination;
  67538. if (aspect.containsIgnoreCase ("xMin"))
  67539. placementFlags |= RectanglePlacement::xLeft;
  67540. else if (aspect.containsIgnoreCase ("xMax"))
  67541. placementFlags |= RectanglePlacement::xRight;
  67542. else
  67543. placementFlags |= RectanglePlacement::xMid;
  67544. if (aspect.containsIgnoreCase ("yMin"))
  67545. placementFlags |= RectanglePlacement::yTop;
  67546. else if (aspect.containsIgnoreCase ("yMax"))
  67547. placementFlags |= RectanglePlacement::yBottom;
  67548. else
  67549. placementFlags |= RectanglePlacement::yMid;
  67550. }
  67551. const RectanglePlacement placement (placementFlags);
  67552. newState.transform
  67553. = placement.getTransformToFit (vx, vy, vw, vh,
  67554. 0.0f, 0.0f, newState.width, newState.height)
  67555. .followedBy (newState.transform);
  67556. }
  67557. }
  67558. else
  67559. {
  67560. if (viewBoxW == 0)
  67561. newState.viewBoxW = newState.width;
  67562. if (viewBoxH == 0)
  67563. newState.viewBoxH = newState.height;
  67564. }
  67565. newState.parseSubElements (xml, drawable);
  67566. return drawable;
  67567. }
  67568. private:
  67569. const XmlElement* const topLevelXml;
  67570. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67571. AffineTransform transform;
  67572. String cssStyleText;
  67573. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67574. {
  67575. forEachXmlChildElement (xml, e)
  67576. {
  67577. Drawable* d = 0;
  67578. if (e->hasTagName ("g"))
  67579. d = parseGroupElement (*e);
  67580. else if (e->hasTagName ("svg"))
  67581. d = parseSVGElement (*e);
  67582. else if (e->hasTagName ("path"))
  67583. d = parsePath (*e);
  67584. else if (e->hasTagName ("rect"))
  67585. d = parseRect (*e);
  67586. else if (e->hasTagName ("circle"))
  67587. d = parseCircle (*e);
  67588. else if (e->hasTagName ("ellipse"))
  67589. d = parseEllipse (*e);
  67590. else if (e->hasTagName ("line"))
  67591. d = parseLine (*e);
  67592. else if (e->hasTagName ("polyline"))
  67593. d = parsePolygon (*e, true);
  67594. else if (e->hasTagName ("polygon"))
  67595. d = parsePolygon (*e, false);
  67596. else if (e->hasTagName ("text"))
  67597. d = parseText (*e);
  67598. else if (e->hasTagName ("switch"))
  67599. d = parseSwitch (*e);
  67600. else if (e->hasTagName ("style"))
  67601. parseCSSStyle (*e);
  67602. parentDrawable->insertDrawable (d);
  67603. }
  67604. }
  67605. DrawableComposite* parseSwitch (const XmlElement& xml)
  67606. {
  67607. const XmlElement* const group = xml.getChildByName ("g");
  67608. if (group != 0)
  67609. return parseGroupElement (*group);
  67610. return 0;
  67611. }
  67612. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67613. {
  67614. DrawableComposite* const drawable = new DrawableComposite();
  67615. drawable->setName (xml.getStringAttribute ("id"));
  67616. if (xml.hasAttribute ("transform"))
  67617. {
  67618. SVGState newState (*this);
  67619. newState.addTransform (xml);
  67620. newState.parseSubElements (xml, drawable);
  67621. }
  67622. else
  67623. {
  67624. parseSubElements (xml, drawable);
  67625. }
  67626. return drawable;
  67627. }
  67628. Drawable* parsePath (const XmlElement& xml) const
  67629. {
  67630. const String d (xml.getStringAttribute ("d").trimStart());
  67631. Path path;
  67632. if (getStyleAttribute (&xml, "fill-rule").trim().equalsIgnoreCase ("evenodd"))
  67633. path.setUsingNonZeroWinding (false);
  67634. int index = 0;
  67635. float lastX = 0, lastY = 0;
  67636. float lastX2 = 0, lastY2 = 0;
  67637. tchar lastCommandChar = 0;
  67638. bool isRelative = true;
  67639. bool carryOn = true;
  67640. const String validCommandChars ("MmLlHhVvCcSsQqTtAaZz");
  67641. while (d[index] != 0)
  67642. {
  67643. float x, y, x2, y2, x3, y3;
  67644. if (validCommandChars.containsChar (d[index]))
  67645. {
  67646. lastCommandChar = d [index++];
  67647. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67648. }
  67649. switch (lastCommandChar)
  67650. {
  67651. case 'M':
  67652. case 'm':
  67653. case 'L':
  67654. case 'l':
  67655. if (parseCoords (d, x, y, index, false))
  67656. {
  67657. if (isRelative)
  67658. {
  67659. x += lastX;
  67660. y += lastY;
  67661. }
  67662. if (lastCommandChar == 'M' || lastCommandChar == 'm')
  67663. path.startNewSubPath (x, y);
  67664. else
  67665. path.lineTo (x, y);
  67666. lastX2 = lastX;
  67667. lastY2 = lastY;
  67668. lastX = x;
  67669. lastY = y;
  67670. }
  67671. else
  67672. {
  67673. ++index;
  67674. }
  67675. break;
  67676. case 'H':
  67677. case 'h':
  67678. if (parseCoord (d, x, index, false, true))
  67679. {
  67680. if (isRelative)
  67681. x += lastX;
  67682. path.lineTo (x, lastY);
  67683. lastX2 = lastX;
  67684. lastX = x;
  67685. }
  67686. else
  67687. {
  67688. ++index;
  67689. }
  67690. break;
  67691. case 'V':
  67692. case 'v':
  67693. if (parseCoord (d, y, index, false, false))
  67694. {
  67695. if (isRelative)
  67696. y += lastY;
  67697. path.lineTo (lastX, y);
  67698. lastY2 = lastY;
  67699. lastY = y;
  67700. }
  67701. else
  67702. {
  67703. ++index;
  67704. }
  67705. break;
  67706. case 'C':
  67707. case 'c':
  67708. if (parseCoords (d, x, y, index, false)
  67709. && parseCoords (d, x2, y2, index, false)
  67710. && parseCoords (d, x3, y3, index, false))
  67711. {
  67712. if (isRelative)
  67713. {
  67714. x += lastX;
  67715. y += lastY;
  67716. x2 += lastX;
  67717. y2 += lastY;
  67718. x3 += lastX;
  67719. y3 += lastY;
  67720. }
  67721. path.cubicTo (x, y, x2, y2, x3, y3);
  67722. lastX2 = x2;
  67723. lastY2 = y2;
  67724. lastX = x3;
  67725. lastY = y3;
  67726. }
  67727. else
  67728. {
  67729. ++index;
  67730. }
  67731. break;
  67732. case 'S':
  67733. case 's':
  67734. if (parseCoords (d, x, y, index, false)
  67735. && parseCoords (d, x3, y3, index, false))
  67736. {
  67737. if (isRelative)
  67738. {
  67739. x += lastX;
  67740. y += lastY;
  67741. x3 += lastX;
  67742. y3 += lastY;
  67743. }
  67744. x2 = lastX + (lastX - lastX2);
  67745. y2 = lastY + (lastY - lastY2);
  67746. path.cubicTo (x2, y2, x, y, x3, y3);
  67747. lastX2 = x;
  67748. lastY2 = y;
  67749. lastX = x3;
  67750. lastY = y3;
  67751. }
  67752. else
  67753. {
  67754. ++index;
  67755. }
  67756. break;
  67757. case 'Q':
  67758. case 'q':
  67759. if (parseCoords (d, x, y, index, false)
  67760. && parseCoords (d, x2, y2, index, false))
  67761. {
  67762. if (isRelative)
  67763. {
  67764. x += lastX;
  67765. y += lastY;
  67766. x2 += lastX;
  67767. y2 += lastY;
  67768. }
  67769. path.quadraticTo (x, y, x2, y2);
  67770. lastX2 = x;
  67771. lastY2 = y;
  67772. lastX = x2;
  67773. lastY = y2;
  67774. }
  67775. else
  67776. {
  67777. ++index;
  67778. }
  67779. break;
  67780. case 'T':
  67781. case 't':
  67782. if (parseCoords (d, x, y, index, false))
  67783. {
  67784. if (isRelative)
  67785. {
  67786. x += lastX;
  67787. y += lastY;
  67788. }
  67789. x2 = lastX + (lastX - lastX2);
  67790. y2 = lastY + (lastY - lastY2);
  67791. path.quadraticTo (x2, y2, x, y);
  67792. lastX2 = x2;
  67793. lastY2 = y2;
  67794. lastX = x;
  67795. lastY = y;
  67796. }
  67797. else
  67798. {
  67799. ++index;
  67800. }
  67801. break;
  67802. case 'A':
  67803. case 'a':
  67804. if (parseCoords (d, x, y, index, false))
  67805. {
  67806. String num;
  67807. if (parseNextNumber (d, num, index, false))
  67808. {
  67809. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67810. if (parseNextNumber (d, num, index, false))
  67811. {
  67812. const bool largeArc = num.getIntValue() != 0;
  67813. if (parseNextNumber (d, num, index, false))
  67814. {
  67815. const bool sweep = num.getIntValue() != 0;
  67816. if (parseCoords (d, x2, y2, index, false))
  67817. {
  67818. if (isRelative)
  67819. {
  67820. x2 += lastX;
  67821. y2 += lastY;
  67822. }
  67823. if (lastX != x2 || lastY != y2)
  67824. {
  67825. double centreX, centreY, startAngle, deltaAngle;
  67826. double rx = x, ry = y;
  67827. endpointToCentreParameters (lastX, lastY, x2, y2,
  67828. angle, largeArc, sweep,
  67829. rx, ry, centreX, centreY,
  67830. startAngle, deltaAngle);
  67831. path.addCentredArc ((float) centreX, (float) centreY,
  67832. (float) rx, (float) ry,
  67833. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67834. false);
  67835. path.lineTo (x2, y2);
  67836. }
  67837. lastX2 = lastX;
  67838. lastY2 = lastY;
  67839. lastX = x2;
  67840. lastY = y2;
  67841. }
  67842. }
  67843. }
  67844. }
  67845. }
  67846. else
  67847. {
  67848. ++index;
  67849. }
  67850. break;
  67851. case 'Z':
  67852. case 'z':
  67853. path.closeSubPath();
  67854. while (CharacterFunctions::isWhitespace (d [index]))
  67855. ++index;
  67856. break;
  67857. default:
  67858. carryOn = false;
  67859. break;
  67860. }
  67861. if (! carryOn)
  67862. break;
  67863. }
  67864. return parseShape (xml, path);
  67865. }
  67866. Drawable* parseRect (const XmlElement& xml) const
  67867. {
  67868. Path rect;
  67869. const bool hasRX = xml.hasAttribute ("rx");
  67870. const bool hasRY = xml.hasAttribute ("ry");
  67871. if (hasRX || hasRY)
  67872. {
  67873. float rx = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67874. float ry = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67875. if (! hasRX)
  67876. rx = ry;
  67877. else if (! hasRY)
  67878. ry = rx;
  67879. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67880. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67881. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67882. getCoordLength (xml.getStringAttribute ("height"), viewBoxH),
  67883. rx, ry);
  67884. }
  67885. else
  67886. {
  67887. rect.addRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67888. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67889. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67890. getCoordLength (xml.getStringAttribute ("height"), viewBoxH));
  67891. }
  67892. return parseShape (xml, rect);
  67893. }
  67894. Drawable* parseCircle (const XmlElement& xml) const
  67895. {
  67896. Path circle;
  67897. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67898. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67899. const float radius = getCoordLength (xml.getStringAttribute ("r"), viewBoxW);
  67900. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67901. return parseShape (xml, circle);
  67902. }
  67903. Drawable* parseEllipse (const XmlElement& xml) const
  67904. {
  67905. Path ellipse;
  67906. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67907. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67908. const float radiusX = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67909. const float radiusY = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67910. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  67911. return parseShape (xml, ellipse);
  67912. }
  67913. Drawable* parseLine (const XmlElement& xml) const
  67914. {
  67915. Path line;
  67916. const float x1 = getCoordLength (xml.getStringAttribute ("x1"), viewBoxW);
  67917. const float y1 = getCoordLength (xml.getStringAttribute ("y1"), viewBoxH);
  67918. const float x2 = getCoordLength (xml.getStringAttribute ("x2"), viewBoxW);
  67919. const float y2 = getCoordLength (xml.getStringAttribute ("y2"), viewBoxH);
  67920. line.startNewSubPath (x1, y1);
  67921. line.lineTo (x2, y2);
  67922. return parseShape (xml, line);
  67923. }
  67924. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  67925. {
  67926. const String points (xml.getStringAttribute ("points"));
  67927. Path path;
  67928. int index = 0;
  67929. float x, y;
  67930. if (parseCoords (points, x, y, index, true))
  67931. {
  67932. float firstX = x;
  67933. float firstY = y;
  67934. float lastX = 0, lastY = 0;
  67935. path.startNewSubPath (x, y);
  67936. while (parseCoords (points, x, y, index, true))
  67937. {
  67938. lastX = x;
  67939. lastY = y;
  67940. path.lineTo (x, y);
  67941. }
  67942. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  67943. path.closeSubPath();
  67944. }
  67945. return parseShape (xml, path);
  67946. }
  67947. Drawable* parseShape (const XmlElement& xml, Path& path,
  67948. const bool shouldParseTransform = true) const
  67949. {
  67950. if (shouldParseTransform && xml.hasAttribute ("transform"))
  67951. {
  67952. SVGState newState (*this);
  67953. newState.addTransform (xml);
  67954. return newState.parseShape (xml, path, false);
  67955. }
  67956. DrawablePath* dp = new DrawablePath();
  67957. dp->setName (xml.getStringAttribute ("id"));
  67958. dp->setFill (FillType (Colours::transparentBlack));
  67959. path.applyTransform (transform);
  67960. dp->setPath (path);
  67961. Path::Iterator iter (path);
  67962. bool containsClosedSubPath = false;
  67963. while (iter.next())
  67964. {
  67965. if (iter.elementType == Path::Iterator::closePath)
  67966. {
  67967. containsClosedSubPath = true;
  67968. break;
  67969. }
  67970. }
  67971. dp->setFill (getPathFillType (path,
  67972. getStyleAttribute (&xml, "fill"),
  67973. getStyleAttribute (&xml, "fill-opacity"),
  67974. getStyleAttribute (&xml, "opacity"),
  67975. containsClosedSubPath ? Colours::black
  67976. : Colours::transparentBlack));
  67977. const String strokeType (getStyleAttribute (&xml, "stroke"));
  67978. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase ("none"))
  67979. {
  67980. dp->setStrokeFill (getPathFillType (path, strokeType,
  67981. getStyleAttribute (&xml, "stroke-opacity"),
  67982. getStyleAttribute (&xml, "opacity"),
  67983. Colours::transparentBlack));
  67984. dp->setStrokeType (getStrokeFor (&xml));
  67985. }
  67986. return dp;
  67987. }
  67988. const XmlElement* findLinkedElement (const XmlElement* e) const
  67989. {
  67990. const String id (e->getStringAttribute ("xlink:href"));
  67991. if (! id.startsWithChar ('#'))
  67992. return 0;
  67993. return findElementForId (topLevelXml, id.substring (1));
  67994. }
  67995. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  67996. {
  67997. if (fillXml == 0)
  67998. return;
  67999. forEachXmlChildElementWithTagName (*fillXml, e, "stop")
  68000. {
  68001. int index = 0;
  68002. Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black));
  68003. const String opacity (getStyleAttribute (e, "stop-opacity", "1"));
  68004. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68005. double offset = e->getDoubleAttribute ("offset");
  68006. if (e->getStringAttribute ("offset").containsChar ('%'))
  68007. offset *= 0.01;
  68008. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68009. }
  68010. }
  68011. const FillType getPathFillType (const Path& path,
  68012. const String& fill,
  68013. const String& fillOpacity,
  68014. const String& overallOpacity,
  68015. const Colour& defaultColour) const
  68016. {
  68017. float opacity = 1.0f;
  68018. if (overallOpacity.isNotEmpty())
  68019. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68020. if (fillOpacity.isNotEmpty())
  68021. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68022. if (fill.startsWithIgnoreCase ("url"))
  68023. {
  68024. const String id (fill.fromFirstOccurrenceOf ("#", false, false)
  68025. .upToLastOccurrenceOf (")", false, false).trim());
  68026. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68027. if (fillXml != 0
  68028. && (fillXml->hasTagName ("linearGradient")
  68029. || fillXml->hasTagName ("radialGradient")))
  68030. {
  68031. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68032. ColourGradient gradient;
  68033. addGradientStopsIn (gradient, inheritedFrom);
  68034. addGradientStopsIn (gradient, fillXml);
  68035. if (gradient.getNumColours() > 0)
  68036. {
  68037. gradient.addColour (0.0, gradient.getColour (0));
  68038. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68039. }
  68040. else
  68041. {
  68042. gradient.addColour (0.0, Colours::black);
  68043. gradient.addColour (1.0, Colours::black);
  68044. }
  68045. if (overallOpacity.isNotEmpty())
  68046. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68047. jassert (gradient.getNumColours() > 0);
  68048. gradient.isRadial = fillXml->hasTagName ("radialGradient");
  68049. float width = viewBoxW;
  68050. float height = viewBoxH;
  68051. float dx = 0.0f;
  68052. float dy = 0.0f;
  68053. const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse");
  68054. if (! userSpace)
  68055. {
  68056. const Rectangle<float> bounds (path.getBounds());
  68057. dx = bounds.getX();
  68058. dy = bounds.getY();
  68059. width = bounds.getWidth();
  68060. height = bounds.getHeight();
  68061. }
  68062. if (gradient.isRadial)
  68063. {
  68064. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), width);
  68065. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), height);
  68066. const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), width);
  68067. gradient.x2 = gradient.x1 + radius;
  68068. gradient.y2 = gradient.y1;
  68069. //xxx (the fx, fy focal point isn't handled properly here..)
  68070. }
  68071. else
  68072. {
  68073. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), width);
  68074. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), height);
  68075. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), width);
  68076. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), height);
  68077. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68078. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68079. }
  68080. FillType type (gradient);
  68081. type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform"))
  68082. .followedBy (transform);
  68083. return type;
  68084. }
  68085. }
  68086. if (fill.equalsIgnoreCase ("none"))
  68087. return Colours::transparentBlack;
  68088. int i = 0;
  68089. const Colour colour (parseColour (fill, i, defaultColour));
  68090. return colour.withMultipliedAlpha (opacity);
  68091. }
  68092. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68093. {
  68094. const String width (getStyleAttribute (xml, "stroke-width"));
  68095. const String cap (getStyleAttribute (xml, "stroke-linecap"));
  68096. const String join (getStyleAttribute (xml, "stroke-linejoin"));
  68097. //const String mitreLimit (getStyleAttribute (xml, "stroke-miterlimit"));
  68098. //const String dashArray (getStyleAttribute (xml, "stroke-dasharray"));
  68099. //const String dashOffset (getStyleAttribute (xml, "stroke-dashoffset"));
  68100. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68101. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68102. if (join.equalsIgnoreCase ("round"))
  68103. joinStyle = PathStrokeType::curved;
  68104. else if (join.equalsIgnoreCase ("bevel"))
  68105. joinStyle = PathStrokeType::beveled;
  68106. if (cap.equalsIgnoreCase ("round"))
  68107. capStyle = PathStrokeType::rounded;
  68108. else if (cap.equalsIgnoreCase ("square"))
  68109. capStyle = PathStrokeType::square;
  68110. float ox = 0.0f, oy = 0.0f;
  68111. transform.transformPoint (ox, oy);
  68112. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68113. transform.transformPoint (x, y);
  68114. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68115. joinStyle, capStyle);
  68116. }
  68117. Drawable* parseText (const XmlElement& xml)
  68118. {
  68119. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68120. getCoordList (xCoords, getInheritedAttribute (&xml, "x"), true, true);
  68121. getCoordList (yCoords, getInheritedAttribute (&xml, "y"), true, false);
  68122. getCoordList (dxCoords, getInheritedAttribute (&xml, "dx"), true, true);
  68123. getCoordList (dyCoords, getInheritedAttribute (&xml, "dy"), true, false);
  68124. //xxx not done text yet!
  68125. forEachXmlChildElement (xml, e)
  68126. {
  68127. if (e->isTextElement())
  68128. {
  68129. const String text (e->getText());
  68130. Path path;
  68131. Drawable* s = parseShape (*e, path);
  68132. delete s;
  68133. }
  68134. else if (e->hasTagName ("tspan"))
  68135. {
  68136. Drawable* s = parseText (*e);
  68137. delete s;
  68138. }
  68139. }
  68140. return 0;
  68141. }
  68142. void addTransform (const XmlElement& xml)
  68143. {
  68144. transform = parseTransform (xml.getStringAttribute ("transform"))
  68145. .followedBy (transform);
  68146. }
  68147. bool parseCoord (const String& s, float& value, int& index,
  68148. const bool allowUnits, const bool isX) const
  68149. {
  68150. String number;
  68151. if (! parseNextNumber (s, number, index, allowUnits))
  68152. {
  68153. value = 0;
  68154. return false;
  68155. }
  68156. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68157. return true;
  68158. }
  68159. bool parseCoords (const String& s, float& x, float& y,
  68160. int& index, const bool allowUnits) const
  68161. {
  68162. return parseCoord (s, x, index, allowUnits, true)
  68163. && parseCoord (s, y, index, allowUnits, false);
  68164. }
  68165. float getCoordLength (const String& s, const float sizeForProportions) const
  68166. {
  68167. float n = s.getFloatValue();
  68168. const int len = s.length();
  68169. if (len > 2)
  68170. {
  68171. const float dpi = 96.0f;
  68172. const tchar n1 = s [len - 2];
  68173. const tchar n2 = s [len - 1];
  68174. if (n1 == 'i' && n2 == 'n')
  68175. n *= dpi;
  68176. else if (n1 == 'm' && n2 == 'm')
  68177. n *= dpi / 25.4f;
  68178. else if (n1 == 'c' && n2 == 'm')
  68179. n *= dpi / 2.54f;
  68180. else if (n1 == 'p' && n2 == 'c')
  68181. n *= 15.0f;
  68182. else if (n2 == '%')
  68183. n *= 0.01f * sizeForProportions;
  68184. }
  68185. return n;
  68186. }
  68187. void getCoordList (Array <float>& coords, const String& list,
  68188. const bool allowUnits, const bool isX) const
  68189. {
  68190. int index = 0;
  68191. float value;
  68192. while (parseCoord (list, value, index, allowUnits, isX))
  68193. coords.add (value);
  68194. }
  68195. void parseCSSStyle (const XmlElement& xml)
  68196. {
  68197. cssStyleText = xml.getAllSubText() + "\n" + cssStyleText;
  68198. }
  68199. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68200. const String& defaultValue = String::empty) const
  68201. {
  68202. if (xml->hasAttribute (attributeName))
  68203. return xml->getStringAttribute (attributeName, defaultValue);
  68204. const String styleAtt (xml->getStringAttribute ("style"));
  68205. if (styleAtt.isNotEmpty())
  68206. {
  68207. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68208. if (value.isNotEmpty())
  68209. return value;
  68210. }
  68211. else if (xml->hasAttribute ("class"))
  68212. {
  68213. const String className ("." + xml->getStringAttribute ("class"));
  68214. int index = cssStyleText.indexOfIgnoreCase (className + " ");
  68215. if (index < 0)
  68216. index = cssStyleText.indexOfIgnoreCase (className + "{");
  68217. if (index >= 0)
  68218. {
  68219. const int openBracket = cssStyleText.indexOfChar (index, '{');
  68220. if (openBracket > index)
  68221. {
  68222. const int closeBracket = cssStyleText.indexOfChar (openBracket, '}');
  68223. if (closeBracket > openBracket)
  68224. {
  68225. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68226. if (value.isNotEmpty())
  68227. return value;
  68228. }
  68229. }
  68230. }
  68231. }
  68232. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68233. if (xml != 0)
  68234. return getStyleAttribute (xml, attributeName, defaultValue);
  68235. return defaultValue;
  68236. }
  68237. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68238. {
  68239. if (xml->hasAttribute (attributeName))
  68240. return xml->getStringAttribute (attributeName);
  68241. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68242. if (xml != 0)
  68243. return getInheritedAttribute (xml, attributeName);
  68244. return String::empty;
  68245. }
  68246. static bool isIdentifierChar (const tchar c)
  68247. {
  68248. return CharacterFunctions::isLetter (c) || c == '-';
  68249. }
  68250. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68251. {
  68252. int i = 0;
  68253. for (;;)
  68254. {
  68255. i = list.indexOf (i, attributeName);
  68256. if (i < 0)
  68257. break;
  68258. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68259. && ! isIdentifierChar (list [i + attributeName.length()]))
  68260. {
  68261. i = list.indexOfChar (i, ':');
  68262. if (i < 0)
  68263. break;
  68264. int end = list.indexOfChar (i, ';');
  68265. if (end < 0)
  68266. end = 0x7ffff;
  68267. return list.substring (i + 1, end).trim();
  68268. }
  68269. ++i;
  68270. }
  68271. return defaultValue;
  68272. }
  68273. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68274. {
  68275. const tchar* const s = (const tchar*) source;
  68276. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68277. ++index;
  68278. int start = index;
  68279. if (CharacterFunctions::isDigit (s[index]) || s[index] == '.' || s[index] == '-')
  68280. ++index;
  68281. while (CharacterFunctions::isDigit (s[index]) || s[index] == '.')
  68282. ++index;
  68283. if ((s[index] == 'e' || s[index] == 'E')
  68284. && (CharacterFunctions::isDigit (s[index + 1])
  68285. || s[index + 1] == '-'
  68286. || s[index + 1] == '+'))
  68287. {
  68288. index += 2;
  68289. while (CharacterFunctions::isDigit (s[index]))
  68290. ++index;
  68291. }
  68292. if (allowUnits)
  68293. {
  68294. while (CharacterFunctions::isLetter (s[index]))
  68295. ++index;
  68296. }
  68297. if (index == start)
  68298. return false;
  68299. value = String (s + start, index - start);
  68300. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68301. ++index;
  68302. return true;
  68303. }
  68304. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68305. {
  68306. if (s [index] == '#')
  68307. {
  68308. uint32 hex [6];
  68309. zeromem (hex, sizeof (hex));
  68310. int numChars = 0;
  68311. for (int i = 6; --i >= 0;)
  68312. {
  68313. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68314. if (hexValue >= 0)
  68315. hex [numChars++] = hexValue;
  68316. else
  68317. break;
  68318. }
  68319. if (numChars <= 3)
  68320. return Colour ((uint8) (hex [0] * 0x11),
  68321. (uint8) (hex [1] * 0x11),
  68322. (uint8) (hex [2] * 0x11));
  68323. else
  68324. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68325. (uint8) ((hex [2] << 4) + hex [3]),
  68326. (uint8) ((hex [4] << 4) + hex [5]));
  68327. }
  68328. else if (s [index] == 'r'
  68329. && s [index + 1] == 'g'
  68330. && s [index + 2] == 'b')
  68331. {
  68332. const int openBracket = s.indexOfChar (index, '(');
  68333. const int closeBracket = s.indexOfChar (openBracket, ')');
  68334. if (openBracket >= 3 && closeBracket > openBracket)
  68335. {
  68336. index = closeBracket;
  68337. StringArray tokens;
  68338. tokens.addTokens (s.substring (openBracket + 1, closeBracket), ",", "");
  68339. tokens.trim();
  68340. tokens.removeEmptyStrings();
  68341. if (tokens[0].containsChar ('%'))
  68342. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68343. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68344. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68345. else
  68346. return Colour ((uint8) tokens[0].getIntValue(),
  68347. (uint8) tokens[1].getIntValue(),
  68348. (uint8) tokens[2].getIntValue());
  68349. }
  68350. }
  68351. return Colours::findColourForName (s, defaultColour);
  68352. }
  68353. static const AffineTransform parseTransform (String t)
  68354. {
  68355. AffineTransform result;
  68356. while (t.isNotEmpty())
  68357. {
  68358. StringArray tokens;
  68359. tokens.addTokens (t.fromFirstOccurrenceOf ("(", false, false)
  68360. .upToFirstOccurrenceOf (")", false, false),
  68361. ", ", String::empty);
  68362. tokens.removeEmptyStrings (true);
  68363. float numbers [6];
  68364. for (int i = 0; i < 6; ++i)
  68365. numbers[i] = tokens[i].getFloatValue();
  68366. AffineTransform trans;
  68367. if (t.startsWithIgnoreCase ("matrix"))
  68368. {
  68369. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68370. numbers[1], numbers[3], numbers[5]);
  68371. }
  68372. else if (t.startsWithIgnoreCase ("translate"))
  68373. {
  68374. jassert (tokens.size() == 2);
  68375. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68376. }
  68377. else if (t.startsWithIgnoreCase ("scale"))
  68378. {
  68379. if (tokens.size() == 1)
  68380. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68381. else
  68382. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68383. }
  68384. else if (t.startsWithIgnoreCase ("rotate"))
  68385. {
  68386. if (tokens.size() != 3)
  68387. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68388. else
  68389. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68390. numbers[1], numbers[2]);
  68391. }
  68392. else if (t.startsWithIgnoreCase ("skewX"))
  68393. {
  68394. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68395. 0.0f, 1.0f, 0.0f);
  68396. }
  68397. else if (t.startsWithIgnoreCase ("skewY"))
  68398. {
  68399. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68400. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68401. }
  68402. result = trans.followedBy (result);
  68403. t = t.fromFirstOccurrenceOf (")", false, false).trimStart();
  68404. }
  68405. return result;
  68406. }
  68407. static void endpointToCentreParameters (const double x1, const double y1,
  68408. const double x2, const double y2,
  68409. const double angle,
  68410. const bool largeArc, const bool sweep,
  68411. double& rx, double& ry,
  68412. double& centreX, double& centreY,
  68413. double& startAngle, double& deltaAngle)
  68414. {
  68415. const double midX = (x1 - x2) * 0.5;
  68416. const double midY = (y1 - y2) * 0.5;
  68417. const double cosAngle = cos (angle);
  68418. const double sinAngle = sin (angle);
  68419. const double xp = cosAngle * midX + sinAngle * midY;
  68420. const double yp = cosAngle * midY - sinAngle * midX;
  68421. const double xp2 = xp * xp;
  68422. const double yp2 = yp * yp;
  68423. double rx2 = rx * rx;
  68424. double ry2 = ry * ry;
  68425. const double s = (xp2 / rx2) + (yp2 / ry2);
  68426. double c;
  68427. if (s <= 1.0)
  68428. {
  68429. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68430. / (( rx2 * yp2) + (ry2 * xp2))));
  68431. if (largeArc == sweep)
  68432. c = -c;
  68433. }
  68434. else
  68435. {
  68436. const double s2 = sqrt (s);
  68437. rx *= s2;
  68438. ry *= s2;
  68439. rx2 = rx * rx;
  68440. ry2 = ry * ry;
  68441. c = 0;
  68442. }
  68443. const double cpx = ((rx * yp) / ry) * c;
  68444. const double cpy = ((-ry * xp) / rx) * c;
  68445. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68446. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68447. const double ux = (xp - cpx) / rx;
  68448. const double uy = (yp - cpy) / ry;
  68449. const double vx = (-xp - cpx) / rx;
  68450. const double vy = (-yp - cpy) / ry;
  68451. const double length = juce_hypot (ux, uy);
  68452. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68453. if (uy < 0)
  68454. startAngle = -startAngle;
  68455. startAngle += double_Pi * 0.5;
  68456. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68457. / (length * juce_hypot (vx, vy))));
  68458. if ((ux * vy) - (uy * vx) < 0)
  68459. deltaAngle = -deltaAngle;
  68460. if (sweep)
  68461. {
  68462. if (deltaAngle < 0)
  68463. deltaAngle += double_Pi * 2.0;
  68464. }
  68465. else
  68466. {
  68467. if (deltaAngle > 0)
  68468. deltaAngle -= double_Pi * 2.0;
  68469. }
  68470. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68471. }
  68472. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68473. {
  68474. forEachXmlChildElement (*parent, e)
  68475. {
  68476. if (e->compareAttribute ("id", id))
  68477. return e;
  68478. const XmlElement* const found = findElementForId (e, id);
  68479. if (found != 0)
  68480. return found;
  68481. }
  68482. return 0;
  68483. }
  68484. SVGState& operator= (const SVGState&);
  68485. };
  68486. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68487. {
  68488. SVGState state (&svgDocument);
  68489. return state.parseSVGElement (svgDocument);
  68490. }
  68491. END_JUCE_NAMESPACE
  68492. /*** End of inlined file: juce_SVGParser.cpp ***/
  68493. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68494. BEGIN_JUCE_NAMESPACE
  68495. #if JUCE_MSVC
  68496. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68497. #endif
  68498. DropShadowEffect::DropShadowEffect()
  68499. : offsetX (0),
  68500. offsetY (0),
  68501. radius (4),
  68502. opacity (0.6f)
  68503. {
  68504. }
  68505. DropShadowEffect::~DropShadowEffect()
  68506. {
  68507. }
  68508. void DropShadowEffect::setShadowProperties (const float newRadius,
  68509. const float newOpacity,
  68510. const int newShadowOffsetX,
  68511. const int newShadowOffsetY)
  68512. {
  68513. radius = jmax (1.1f, newRadius);
  68514. offsetX = newShadowOffsetX;
  68515. offsetY = newShadowOffsetY;
  68516. opacity = newOpacity;
  68517. }
  68518. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68519. {
  68520. const int w = image.getWidth();
  68521. const int h = image.getHeight();
  68522. Image shadowImage (Image::SingleChannel, w, h, false);
  68523. const Image::BitmapData srcData (image, 0, 0, w, h);
  68524. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68525. const int filter = roundToInt (63.0f / radius);
  68526. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68527. for (int x = w; --x >= 0;)
  68528. {
  68529. int shadowAlpha = 0;
  68530. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68531. uint8* shadowPix = destData.data + x;
  68532. for (int y = h; --y >= 0;)
  68533. {
  68534. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68535. *shadowPix = (uint8) shadowAlpha;
  68536. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68537. shadowPix += destData.lineStride;
  68538. }
  68539. }
  68540. for (int y = h; --y >= 0;)
  68541. {
  68542. int shadowAlpha = 0;
  68543. uint8* shadowPix = destData.getLinePointer (y);
  68544. for (int x = w; --x >= 0;)
  68545. {
  68546. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68547. *shadowPix++ = (uint8) shadowAlpha;
  68548. }
  68549. }
  68550. g.setColour (Colours::black.withAlpha (opacity));
  68551. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68552. g.setOpacity (1.0f);
  68553. g.drawImageAt (&image, 0, 0);
  68554. }
  68555. END_JUCE_NAMESPACE
  68556. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68557. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68558. BEGIN_JUCE_NAMESPACE
  68559. GlowEffect::GlowEffect()
  68560. : radius (2.0f),
  68561. colour (Colours::white)
  68562. {
  68563. }
  68564. GlowEffect::~GlowEffect()
  68565. {
  68566. }
  68567. void GlowEffect::setGlowProperties (const float newRadius,
  68568. const Colour& newColour)
  68569. {
  68570. radius = newRadius;
  68571. colour = newColour;
  68572. }
  68573. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68574. {
  68575. Image temp (image.getFormat(), image.getWidth(), image.getHeight(), true);
  68576. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68577. blurKernel.createGaussianBlur (radius);
  68578. blurKernel.rescaleAllValues (radius);
  68579. blurKernel.applyToImage (temp, &image, image.getBounds());
  68580. g.setColour (colour);
  68581. g.drawImageAt (&temp, 0, 0, true);
  68582. g.setOpacity (1.0f);
  68583. g.drawImageAt (&image, 0, 0, false);
  68584. }
  68585. END_JUCE_NAMESPACE
  68586. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68587. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68588. BEGIN_JUCE_NAMESPACE
  68589. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68590. : opacity (opacity_)
  68591. {
  68592. }
  68593. ReduceOpacityEffect::~ReduceOpacityEffect()
  68594. {
  68595. }
  68596. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68597. {
  68598. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68599. }
  68600. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68601. {
  68602. g.setOpacity (opacity);
  68603. g.drawImageAt (&image, 0, 0);
  68604. }
  68605. END_JUCE_NAMESPACE
  68606. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68607. /*** Start of inlined file: juce_Font.cpp ***/
  68608. BEGIN_JUCE_NAMESPACE
  68609. namespace FontValues
  68610. {
  68611. static float limitFontHeight (const float height) throw()
  68612. {
  68613. return jlimit (0.1f, 10000.0f, height);
  68614. }
  68615. static const float defaultFontHeight = 14.0f;
  68616. }
  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 (getDefaultSansSerifFontName(), FontValues::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 (getDefaultSansSerifFontName(), FontValues::limitFontHeight (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_, FontValues::limitFontHeight (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(), FontValues::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. static const String name ("<Sans-Serif>");
  68694. return name;
  68695. }
  68696. const String Font::getDefaultSerifFontName() throw()
  68697. {
  68698. static const String name ("<Serif>");
  68699. return name;
  68700. }
  68701. const String Font::getDefaultMonospacedFontName() throw()
  68702. {
  68703. static const String name ("<Monospaced>");
  68704. return name;
  68705. }
  68706. void Font::setTypefaceName (const String& faceName) throw()
  68707. {
  68708. if (faceName != font->typefaceName)
  68709. {
  68710. dupeInternalIfShared();
  68711. font->typefaceName = faceName;
  68712. font->typeface = 0;
  68713. font->ascent = 0;
  68714. }
  68715. }
  68716. static String fallbackFont;
  68717. const String Font::getFallbackFontName() throw()
  68718. {
  68719. return fallbackFont;
  68720. }
  68721. void Font::setFallbackFontName (const String& name) throw()
  68722. {
  68723. fallbackFont = name;
  68724. }
  68725. void Font::setHeight (float newHeight) throw()
  68726. {
  68727. newHeight = FontValues::limitFontHeight (newHeight);
  68728. if (font->height != newHeight)
  68729. {
  68730. dupeInternalIfShared();
  68731. font->height = newHeight;
  68732. }
  68733. }
  68734. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68735. {
  68736. newHeight = FontValues::limitFontHeight (newHeight);
  68737. if (font->height != newHeight)
  68738. {
  68739. dupeInternalIfShared();
  68740. font->horizontalScale *= (font->height / newHeight);
  68741. font->height = newHeight;
  68742. }
  68743. }
  68744. void Font::setStyleFlags (const int newFlags) throw()
  68745. {
  68746. if (font->styleFlags != newFlags)
  68747. {
  68748. dupeInternalIfShared();
  68749. font->styleFlags = newFlags;
  68750. font->typeface = 0;
  68751. font->ascent = 0;
  68752. }
  68753. }
  68754. void Font::setSizeAndStyle (float newHeight,
  68755. const int newStyleFlags,
  68756. const float newHorizontalScale,
  68757. const float newKerningAmount) throw()
  68758. {
  68759. newHeight = FontValues::limitFontHeight (newHeight);
  68760. if (font->height != newHeight
  68761. || font->horizontalScale != newHorizontalScale
  68762. || font->kerning != newKerningAmount)
  68763. {
  68764. dupeInternalIfShared();
  68765. font->height = newHeight;
  68766. font->horizontalScale = newHorizontalScale;
  68767. font->kerning = newKerningAmount;
  68768. }
  68769. setStyleFlags (newStyleFlags);
  68770. }
  68771. void Font::setHorizontalScale (const float scaleFactor) throw()
  68772. {
  68773. dupeInternalIfShared();
  68774. font->horizontalScale = scaleFactor;
  68775. }
  68776. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68777. {
  68778. dupeInternalIfShared();
  68779. font->kerning = extraKerning;
  68780. }
  68781. void Font::setBold (const bool shouldBeBold) throw()
  68782. {
  68783. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68784. : (font->styleFlags & ~bold));
  68785. }
  68786. bool Font::isBold() const throw()
  68787. {
  68788. return (font->styleFlags & bold) != 0;
  68789. }
  68790. void Font::setItalic (const bool shouldBeItalic) throw()
  68791. {
  68792. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68793. : (font->styleFlags & ~italic));
  68794. }
  68795. bool Font::isItalic() const throw()
  68796. {
  68797. return (font->styleFlags & italic) != 0;
  68798. }
  68799. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68800. {
  68801. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68802. : (font->styleFlags & ~underlined));
  68803. }
  68804. bool Font::isUnderlined() const throw()
  68805. {
  68806. return (font->styleFlags & underlined) != 0;
  68807. }
  68808. float Font::getAscent() const throw()
  68809. {
  68810. if (font->ascent == 0)
  68811. font->ascent = getTypeface()->getAscent();
  68812. return font->height * font->ascent;
  68813. }
  68814. float Font::getDescent() const throw()
  68815. {
  68816. return font->height - getAscent();
  68817. }
  68818. int Font::getStringWidth (const String& text) const throw()
  68819. {
  68820. return roundToInt (getStringWidthFloat (text));
  68821. }
  68822. float Font::getStringWidthFloat (const String& text) const throw()
  68823. {
  68824. float w = getTypeface()->getStringWidth (text);
  68825. if (font->kerning != 0)
  68826. w += font->kerning * text.length();
  68827. return w * font->height * font->horizontalScale;
  68828. }
  68829. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68830. {
  68831. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68832. const float scale = font->height * font->horizontalScale;
  68833. const int num = xOffsets.size();
  68834. if (num > 0)
  68835. {
  68836. float* const x = &(xOffsets.getReference(0));
  68837. if (font->kerning != 0)
  68838. {
  68839. for (int i = 0; i < num; ++i)
  68840. x[i] = (x[i] + i * font->kerning) * scale;
  68841. }
  68842. else
  68843. {
  68844. for (int i = 0; i < num; ++i)
  68845. x[i] *= scale;
  68846. }
  68847. }
  68848. }
  68849. void Font::findFonts (Array<Font>& destArray) throw()
  68850. {
  68851. const StringArray names (findAllTypefaceNames());
  68852. for (int i = 0; i < names.size(); ++i)
  68853. destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain));
  68854. }
  68855. class TypefaceCache : public DeletedAtShutdown
  68856. {
  68857. public:
  68858. TypefaceCache (int numToCache = 10) throw()
  68859. : counter (1)
  68860. {
  68861. while (--numToCache >= 0)
  68862. faces.add (new CachedFace());
  68863. }
  68864. ~TypefaceCache()
  68865. {
  68866. clearSingletonInstance();
  68867. }
  68868. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68869. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68870. {
  68871. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68872. const String faceName (font.getTypefaceName());
  68873. int i;
  68874. for (i = faces.size(); --i >= 0;)
  68875. {
  68876. CachedFace* const face = faces.getUnchecked(i);
  68877. if (face->flags == flags
  68878. && face->typefaceName == faceName)
  68879. {
  68880. face->lastUsageCount = ++counter;
  68881. return face->typeFace;
  68882. }
  68883. }
  68884. int replaceIndex = 0;
  68885. int bestLastUsageCount = std::numeric_limits<int>::max();
  68886. for (i = faces.size(); --i >= 0;)
  68887. {
  68888. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68889. if (bestLastUsageCount > lu)
  68890. {
  68891. bestLastUsageCount = lu;
  68892. replaceIndex = i;
  68893. }
  68894. }
  68895. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68896. face->typefaceName = faceName;
  68897. face->flags = flags;
  68898. face->lastUsageCount = ++counter;
  68899. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68900. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68901. return face->typeFace;
  68902. }
  68903. juce_UseDebuggingNewOperator
  68904. private:
  68905. struct CachedFace
  68906. {
  68907. CachedFace() throw()
  68908. : lastUsageCount (0), flags (-1)
  68909. {
  68910. }
  68911. String typefaceName;
  68912. int lastUsageCount;
  68913. int flags;
  68914. Typeface::Ptr typeFace;
  68915. };
  68916. int counter;
  68917. OwnedArray <CachedFace> faces;
  68918. TypefaceCache (const TypefaceCache&);
  68919. TypefaceCache& operator= (const TypefaceCache&);
  68920. };
  68921. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  68922. Typeface* Font::getTypeface() const throw()
  68923. {
  68924. if (font->typeface == 0)
  68925. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  68926. return font->typeface;
  68927. }
  68928. END_JUCE_NAMESPACE
  68929. /*** End of inlined file: juce_Font.cpp ***/
  68930. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  68931. BEGIN_JUCE_NAMESPACE
  68932. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  68933. const juce_wchar character_, const int glyph_)
  68934. : x (x_),
  68935. y (y_),
  68936. w (w_),
  68937. font (font_),
  68938. character (character_),
  68939. glyph (glyph_)
  68940. {
  68941. }
  68942. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  68943. : x (other.x),
  68944. y (other.y),
  68945. w (other.w),
  68946. font (other.font),
  68947. character (other.character),
  68948. glyph (other.glyph)
  68949. {
  68950. }
  68951. void PositionedGlyph::draw (const Graphics& g) const
  68952. {
  68953. if (! isWhitespace())
  68954. {
  68955. g.getInternalContext()->setFont (font);
  68956. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  68957. }
  68958. }
  68959. void PositionedGlyph::draw (const Graphics& g,
  68960. const AffineTransform& transform) const
  68961. {
  68962. if (! isWhitespace())
  68963. {
  68964. g.getInternalContext()->setFont (font);
  68965. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  68966. .followedBy (transform));
  68967. }
  68968. }
  68969. void PositionedGlyph::createPath (Path& path) const
  68970. {
  68971. if (! isWhitespace())
  68972. {
  68973. Typeface* const t = font.getTypeface();
  68974. if (t != 0)
  68975. {
  68976. Path p;
  68977. t->getOutlineForGlyph (glyph, p);
  68978. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  68979. .translated (x, y));
  68980. }
  68981. }
  68982. }
  68983. bool PositionedGlyph::hitTest (float px, float py) const
  68984. {
  68985. if (px >= getLeft() && px < getRight()
  68986. && py >= getTop() && py < getBottom()
  68987. && ! isWhitespace())
  68988. {
  68989. Typeface* const t = font.getTypeface();
  68990. if (t != 0)
  68991. {
  68992. Path p;
  68993. t->getOutlineForGlyph (glyph, p);
  68994. AffineTransform::translation (-x, -y)
  68995. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  68996. .transformPoint (px, py);
  68997. return p.contains (px, py);
  68998. }
  68999. }
  69000. return false;
  69001. }
  69002. void PositionedGlyph::moveBy (const float deltaX,
  69003. const float deltaY)
  69004. {
  69005. x += deltaX;
  69006. y += deltaY;
  69007. }
  69008. GlyphArrangement::GlyphArrangement()
  69009. {
  69010. glyphs.ensureStorageAllocated (128);
  69011. }
  69012. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69013. {
  69014. addGlyphArrangement (other);
  69015. }
  69016. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69017. {
  69018. if (this != &other)
  69019. {
  69020. clear();
  69021. addGlyphArrangement (other);
  69022. }
  69023. return *this;
  69024. }
  69025. GlyphArrangement::~GlyphArrangement()
  69026. {
  69027. }
  69028. void GlyphArrangement::clear()
  69029. {
  69030. glyphs.clear();
  69031. }
  69032. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69033. {
  69034. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69035. return *glyphs [index];
  69036. }
  69037. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69038. {
  69039. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69040. for (int i = 0; i < other.glyphs.size(); ++i)
  69041. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69042. }
  69043. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69044. {
  69045. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69046. }
  69047. void GlyphArrangement::addLineOfText (const Font& font,
  69048. const String& text,
  69049. const float xOffset,
  69050. const float yOffset)
  69051. {
  69052. addCurtailedLineOfText (font, text,
  69053. xOffset, yOffset,
  69054. 1.0e10f, false);
  69055. }
  69056. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69057. const String& text,
  69058. float xOffset,
  69059. const float yOffset,
  69060. const float maxWidthPixels,
  69061. const bool useEllipsis)
  69062. {
  69063. if (text.isNotEmpty())
  69064. {
  69065. Array <int> newGlyphs;
  69066. Array <float> xOffsets;
  69067. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69068. const int textLen = newGlyphs.size();
  69069. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69070. for (int i = 0; i < textLen; ++i)
  69071. {
  69072. const float thisX = xOffsets.getUnchecked (i);
  69073. const float nextX = xOffsets.getUnchecked (i + 1);
  69074. if (nextX > maxWidthPixels + 1.0f)
  69075. {
  69076. // curtail the string if it's too wide..
  69077. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69078. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69079. break;
  69080. }
  69081. else
  69082. {
  69083. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  69084. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  69085. }
  69086. }
  69087. }
  69088. }
  69089. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69090. const int startIndex, int endIndex)
  69091. {
  69092. int numDeleted = 0;
  69093. if (glyphs.size() > 0)
  69094. {
  69095. Array<int> dotGlyphs;
  69096. Array<float> dotXs;
  69097. font.getGlyphPositions ("..", dotGlyphs, dotXs);
  69098. const float dx = dotXs[1];
  69099. float xOffset = 0.0f, yOffset = 0.0f;
  69100. while (endIndex > startIndex)
  69101. {
  69102. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69103. xOffset = pg->x;
  69104. yOffset = pg->y;
  69105. glyphs.remove (endIndex);
  69106. ++numDeleted;
  69107. if (xOffset + dx * 3 <= maxXPos)
  69108. break;
  69109. }
  69110. for (int i = 3; --i >= 0;)
  69111. {
  69112. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  69113. font, '.', dotGlyphs.getFirst()));
  69114. --numDeleted;
  69115. xOffset += dx;
  69116. if (xOffset > maxXPos)
  69117. break;
  69118. }
  69119. }
  69120. return numDeleted;
  69121. }
  69122. void GlyphArrangement::addJustifiedText (const Font& font,
  69123. const String& text,
  69124. float x, float y,
  69125. const float maxLineWidth,
  69126. const Justification& horizontalLayout)
  69127. {
  69128. int lineStartIndex = glyphs.size();
  69129. addLineOfText (font, text, x, y);
  69130. const float originalY = y;
  69131. while (lineStartIndex < glyphs.size())
  69132. {
  69133. int i = lineStartIndex;
  69134. if (glyphs.getUnchecked(i)->getCharacter() != '\n'
  69135. && glyphs.getUnchecked(i)->getCharacter() != '\r')
  69136. ++i;
  69137. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69138. int lastWordBreakIndex = -1;
  69139. while (i < glyphs.size())
  69140. {
  69141. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69142. const juce_wchar c = pg->getCharacter();
  69143. if (c == '\r' || c == '\n')
  69144. {
  69145. ++i;
  69146. if (c == '\r' && i < glyphs.size()
  69147. && glyphs.getUnchecked(i)->getCharacter() == '\n')
  69148. ++i;
  69149. break;
  69150. }
  69151. else if (pg->isWhitespace())
  69152. {
  69153. lastWordBreakIndex = i + 1;
  69154. }
  69155. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69156. {
  69157. if (lastWordBreakIndex >= 0)
  69158. i = lastWordBreakIndex;
  69159. break;
  69160. }
  69161. ++i;
  69162. }
  69163. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69164. float currentLineEndX = currentLineStartX;
  69165. for (int j = i; --j >= lineStartIndex;)
  69166. {
  69167. if (! glyphs.getUnchecked (j)->isWhitespace())
  69168. {
  69169. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69170. break;
  69171. }
  69172. }
  69173. float deltaX = 0.0f;
  69174. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69175. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69176. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69177. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69178. else if (horizontalLayout.testFlags (Justification::right))
  69179. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69180. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69181. x + deltaX - currentLineStartX, y - originalY);
  69182. lineStartIndex = i;
  69183. y += font.getHeight();
  69184. }
  69185. }
  69186. void GlyphArrangement::addFittedText (const Font& f,
  69187. const String& text,
  69188. const float x, const float y,
  69189. const float width, const float height,
  69190. const Justification& layout,
  69191. int maximumLines,
  69192. const float minimumHorizontalScale)
  69193. {
  69194. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69195. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69196. if (text.containsAnyOf ("\r\n"))
  69197. {
  69198. GlyphArrangement ga;
  69199. ga.addJustifiedText (f, text, x, y, width, layout);
  69200. float l, t, r, b;
  69201. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69202. float dy = y - t;
  69203. if (layout.testFlags (Justification::verticallyCentred))
  69204. dy += (height - (b - t)) * 0.5f;
  69205. else if (layout.testFlags (Justification::bottom))
  69206. dy += height - (b - t);
  69207. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69208. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69209. for (int i = 0; i < ga.glyphs.size(); ++i)
  69210. glyphs.add (ga.glyphs.getUnchecked (i));
  69211. ga.glyphs.clear (false);
  69212. return;
  69213. }
  69214. int startIndex = glyphs.size();
  69215. addLineOfText (f, text.trim(), x, y);
  69216. if (glyphs.size() > startIndex)
  69217. {
  69218. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69219. - glyphs.getUnchecked (startIndex)->getLeft();
  69220. if (lineWidth <= 0)
  69221. return;
  69222. if (lineWidth * minimumHorizontalScale < width)
  69223. {
  69224. if (lineWidth > width)
  69225. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69226. width / lineWidth);
  69227. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69228. x, y, width, height, layout);
  69229. }
  69230. else if (maximumLines <= 1)
  69231. {
  69232. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69233. x, y, width, height, f, layout, minimumHorizontalScale);
  69234. }
  69235. else
  69236. {
  69237. Font font (f);
  69238. String txt (text.trim());
  69239. const int length = txt.length();
  69240. const int originalStartIndex = startIndex;
  69241. int numLines = 1;
  69242. if (length <= 12 && ! txt.containsAnyOf (" -\t\r\n"))
  69243. maximumLines = 1;
  69244. maximumLines = jmin (maximumLines, length);
  69245. while (numLines < maximumLines)
  69246. {
  69247. ++numLines;
  69248. const float newFontHeight = height / (float) numLines;
  69249. if (newFontHeight < font.getHeight())
  69250. {
  69251. font.setHeight (jmax (8.0f, newFontHeight));
  69252. removeRangeOfGlyphs (startIndex, -1);
  69253. addLineOfText (font, txt, x, y);
  69254. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69255. - glyphs.getUnchecked (startIndex)->getLeft();
  69256. }
  69257. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69258. break;
  69259. }
  69260. if (numLines < 1)
  69261. numLines = 1;
  69262. float lineY = y;
  69263. float widthPerLine = lineWidth / numLines;
  69264. int lastLineStartIndex = 0;
  69265. for (int line = 0; line < numLines; ++line)
  69266. {
  69267. int i = startIndex;
  69268. lastLineStartIndex = i;
  69269. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69270. if (line == numLines - 1)
  69271. {
  69272. widthPerLine = width;
  69273. i = glyphs.size();
  69274. }
  69275. else
  69276. {
  69277. while (i < glyphs.size())
  69278. {
  69279. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69280. if (lineWidth > widthPerLine)
  69281. {
  69282. // got to a point where the line's too long, so skip forward to find a
  69283. // good place to break it..
  69284. const int searchStartIndex = i;
  69285. while (i < glyphs.size())
  69286. {
  69287. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69288. {
  69289. if (glyphs.getUnchecked (i)->isWhitespace()
  69290. || glyphs.getUnchecked (i)->getCharacter() == '-')
  69291. {
  69292. ++i;
  69293. break;
  69294. }
  69295. }
  69296. else
  69297. {
  69298. // can't find a suitable break, so try looking backwards..
  69299. i = searchStartIndex;
  69300. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69301. {
  69302. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69303. || glyphs.getUnchecked (i - back)->getCharacter() == '-')
  69304. {
  69305. i -= back - 1;
  69306. break;
  69307. }
  69308. }
  69309. break;
  69310. }
  69311. ++i;
  69312. }
  69313. break;
  69314. }
  69315. ++i;
  69316. }
  69317. int wsStart = i;
  69318. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69319. --wsStart;
  69320. int wsEnd = i;
  69321. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69322. ++wsEnd;
  69323. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69324. i = jmax (wsStart, startIndex + 1);
  69325. }
  69326. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69327. x, lineY, width, font.getHeight(), font,
  69328. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69329. minimumHorizontalScale);
  69330. startIndex = i;
  69331. lineY += font.getHeight();
  69332. if (startIndex >= glyphs.size())
  69333. break;
  69334. }
  69335. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69336. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69337. }
  69338. }
  69339. }
  69340. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69341. const float dx, const float dy)
  69342. {
  69343. jassert (startIndex >= 0);
  69344. if (dx != 0.0f || dy != 0.0f)
  69345. {
  69346. if (num < 0 || startIndex + num > glyphs.size())
  69347. num = glyphs.size() - startIndex;
  69348. while (--num >= 0)
  69349. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69350. }
  69351. }
  69352. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69353. const Justification& justification, float minimumHorizontalScale)
  69354. {
  69355. int numDeleted = 0;
  69356. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69357. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69358. if (lineWidth > w)
  69359. {
  69360. if (minimumHorizontalScale < 1.0f)
  69361. {
  69362. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69363. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69364. }
  69365. if (lineWidth > w)
  69366. {
  69367. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69368. numGlyphs -= numDeleted;
  69369. }
  69370. }
  69371. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69372. return numDeleted;
  69373. }
  69374. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69375. const float horizontalScaleFactor)
  69376. {
  69377. jassert (startIndex >= 0);
  69378. if (num < 0 || startIndex + num > glyphs.size())
  69379. num = glyphs.size() - startIndex;
  69380. if (num > 0)
  69381. {
  69382. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69383. while (--num >= 0)
  69384. {
  69385. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69386. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69387. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69388. pg->w *= horizontalScaleFactor;
  69389. }
  69390. }
  69391. }
  69392. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69393. float& left,
  69394. float& top,
  69395. float& right,
  69396. float& bottom,
  69397. const bool includeWhitespace) const
  69398. {
  69399. jassert (startIndex >= 0);
  69400. if (num < 0 || startIndex + num > glyphs.size())
  69401. num = glyphs.size() - startIndex;
  69402. left = 0.0f;
  69403. top = 0.0f;
  69404. right = 0.0f;
  69405. bottom = 0.0f;
  69406. bool isFirst = true;
  69407. while (--num >= 0)
  69408. {
  69409. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69410. if (includeWhitespace || ! pg->isWhitespace())
  69411. {
  69412. if (isFirst)
  69413. {
  69414. isFirst = false;
  69415. left = pg->getLeft();
  69416. top = pg->getTop();
  69417. right = pg->getRight();
  69418. bottom = pg->getBottom();
  69419. }
  69420. else
  69421. {
  69422. left = jmin (left, pg->getLeft());
  69423. top = jmin (top, pg->getTop());
  69424. right = jmax (right, pg->getRight());
  69425. bottom = jmax (bottom, pg->getBottom());
  69426. }
  69427. }
  69428. }
  69429. }
  69430. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69431. const int num,
  69432. const float x, const float y,
  69433. const float width, const float height,
  69434. const Justification& justification)
  69435. {
  69436. jassert (num >= 0 && startIndex >= 0);
  69437. if (glyphs.size() > 0 && num > 0)
  69438. {
  69439. float left, top, right, bottom;
  69440. getBoundingBox (startIndex, num, left, top, right, bottom,
  69441. ! justification.testFlags (Justification::horizontallyJustified
  69442. | Justification::horizontallyCentred));
  69443. float deltaX = 0.0f;
  69444. if (justification.testFlags (Justification::horizontallyJustified))
  69445. deltaX = x - left;
  69446. else if (justification.testFlags (Justification::horizontallyCentred))
  69447. deltaX = x + (width - (right - left)) * 0.5f - left;
  69448. else if (justification.testFlags (Justification::right))
  69449. deltaX = (x + width) - right;
  69450. else
  69451. deltaX = x - left;
  69452. float deltaY = 0.0f;
  69453. if (justification.testFlags (Justification::top))
  69454. deltaY = y - top;
  69455. else if (justification.testFlags (Justification::bottom))
  69456. deltaY = (y + height) - bottom;
  69457. else
  69458. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69459. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69460. if (justification.testFlags (Justification::horizontallyJustified))
  69461. {
  69462. int lineStart = 0;
  69463. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69464. int i;
  69465. for (i = 0; i < num; ++i)
  69466. {
  69467. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69468. if (glyphY != baseY)
  69469. {
  69470. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69471. lineStart = i;
  69472. baseY = glyphY;
  69473. }
  69474. }
  69475. if (i > lineStart)
  69476. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69477. }
  69478. }
  69479. }
  69480. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69481. {
  69482. if (start + num < glyphs.size()
  69483. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\r'
  69484. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\n')
  69485. {
  69486. int numSpaces = 0;
  69487. int spacesAtEnd = 0;
  69488. for (int i = 0; i < num; ++i)
  69489. {
  69490. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69491. {
  69492. ++spacesAtEnd;
  69493. ++numSpaces;
  69494. }
  69495. else
  69496. {
  69497. spacesAtEnd = 0;
  69498. }
  69499. }
  69500. numSpaces -= spacesAtEnd;
  69501. if (numSpaces > 0)
  69502. {
  69503. const float startX = glyphs.getUnchecked (start)->getLeft();
  69504. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69505. const float extraPaddingBetweenWords
  69506. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69507. float deltaX = 0.0f;
  69508. for (int i = 0; i < num; ++i)
  69509. {
  69510. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69511. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69512. deltaX += extraPaddingBetweenWords;
  69513. }
  69514. }
  69515. }
  69516. }
  69517. void GlyphArrangement::draw (const Graphics& g) const
  69518. {
  69519. for (int i = 0; i < glyphs.size(); ++i)
  69520. {
  69521. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69522. if (pg->font.isUnderlined())
  69523. {
  69524. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69525. float nextX = pg->x + pg->w;
  69526. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69527. nextX = glyphs.getUnchecked (i + 1)->x;
  69528. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69529. nextX - pg->x, lineThickness);
  69530. }
  69531. pg->draw (g);
  69532. }
  69533. }
  69534. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69535. {
  69536. for (int i = 0; i < glyphs.size(); ++i)
  69537. {
  69538. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69539. if (pg->font.isUnderlined())
  69540. {
  69541. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69542. float nextX = pg->x + pg->w;
  69543. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69544. nextX = glyphs.getUnchecked (i + 1)->x;
  69545. Path p;
  69546. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69547. nextX, pg->y + lineThickness * 2.0f,
  69548. lineThickness);
  69549. g.fillPath (p, transform);
  69550. }
  69551. pg->draw (g, transform);
  69552. }
  69553. }
  69554. void GlyphArrangement::createPath (Path& path) const
  69555. {
  69556. for (int i = 0; i < glyphs.size(); ++i)
  69557. glyphs.getUnchecked (i)->createPath (path);
  69558. }
  69559. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69560. {
  69561. for (int i = 0; i < glyphs.size(); ++i)
  69562. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69563. return i;
  69564. return -1;
  69565. }
  69566. END_JUCE_NAMESPACE
  69567. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69568. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69569. BEGIN_JUCE_NAMESPACE
  69570. class TextLayout::Token
  69571. {
  69572. public:
  69573. String text;
  69574. Font font;
  69575. int x, y, w, h;
  69576. int line, lineHeight;
  69577. bool isWhitespace, isNewLine;
  69578. Token (const String& t,
  69579. const Font& f,
  69580. const bool isWhitespace_)
  69581. : text (t),
  69582. font (f),
  69583. x(0),
  69584. y(0),
  69585. isWhitespace (isWhitespace_)
  69586. {
  69587. w = font.getStringWidth (t);
  69588. h = roundToInt (f.getHeight());
  69589. isNewLine = t.containsChar ('\n') || t.containsChar ('\r');
  69590. }
  69591. Token (const Token& other) throw()
  69592. : text (other.text),
  69593. font (other.font),
  69594. x (other.x),
  69595. y (other.y),
  69596. w (other.w),
  69597. h (other.h),
  69598. line (other.line),
  69599. lineHeight (other.lineHeight),
  69600. isWhitespace (other.isWhitespace),
  69601. isNewLine (other.isNewLine)
  69602. {
  69603. }
  69604. ~Token() throw()
  69605. {
  69606. }
  69607. void draw (Graphics& g,
  69608. const int xOffset,
  69609. const int yOffset)
  69610. {
  69611. if (! isWhitespace)
  69612. {
  69613. g.setFont (font);
  69614. g.drawSingleLineText (text.trimEnd(),
  69615. xOffset + x,
  69616. yOffset + y + (lineHeight - h)
  69617. + roundToInt (font.getAscent()));
  69618. }
  69619. }
  69620. juce_UseDebuggingNewOperator
  69621. };
  69622. TextLayout::TextLayout() throw()
  69623. : totalLines (0)
  69624. {
  69625. tokens.ensureStorageAllocated (64);
  69626. }
  69627. TextLayout::TextLayout (const String& text,
  69628. const Font& font) throw()
  69629. : totalLines (0)
  69630. {
  69631. tokens.ensureStorageAllocated (64);
  69632. appendText (text, font);
  69633. }
  69634. TextLayout::TextLayout (const TextLayout& other) throw()
  69635. : totalLines (0)
  69636. {
  69637. *this = other;
  69638. }
  69639. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  69640. {
  69641. if (this != &other)
  69642. {
  69643. clear();
  69644. totalLines = other.totalLines;
  69645. for (int i = 0; i < other.tokens.size(); ++i)
  69646. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69647. }
  69648. return *this;
  69649. }
  69650. TextLayout::~TextLayout() throw()
  69651. {
  69652. clear();
  69653. }
  69654. void TextLayout::clear() throw()
  69655. {
  69656. tokens.clear();
  69657. totalLines = 0;
  69658. }
  69659. void TextLayout::appendText (const String& text,
  69660. const Font& font) throw()
  69661. {
  69662. const tchar* t = text;
  69663. String currentString;
  69664. int lastCharType = 0;
  69665. for (;;)
  69666. {
  69667. const tchar c = *t++;
  69668. if (c == 0)
  69669. break;
  69670. int charType;
  69671. if (c == '\r' || c == '\n')
  69672. {
  69673. charType = 0;
  69674. }
  69675. else if (CharacterFunctions::isWhitespace (c))
  69676. {
  69677. charType = 2;
  69678. }
  69679. else
  69680. {
  69681. charType = 1;
  69682. }
  69683. if (charType == 0 || charType != lastCharType)
  69684. {
  69685. if (currentString.isNotEmpty())
  69686. {
  69687. tokens.add (new Token (currentString, font,
  69688. lastCharType == 2 || lastCharType == 0));
  69689. }
  69690. currentString = String::charToString (c);
  69691. if (c == '\r' && *t == '\n')
  69692. currentString += *t++;
  69693. }
  69694. else
  69695. {
  69696. currentString += c;
  69697. }
  69698. lastCharType = charType;
  69699. }
  69700. if (currentString.isNotEmpty())
  69701. tokens.add (new Token (currentString, font, lastCharType == 2));
  69702. }
  69703. void TextLayout::setText (const String& text, const Font& font) throw()
  69704. {
  69705. clear();
  69706. appendText (text, font);
  69707. }
  69708. void TextLayout::layout (int maxWidth,
  69709. const Justification& justification,
  69710. const bool attemptToBalanceLineLengths) throw()
  69711. {
  69712. if (attemptToBalanceLineLengths)
  69713. {
  69714. const int originalW = maxWidth;
  69715. int bestWidth = maxWidth;
  69716. float bestLineProportion = 0.0f;
  69717. while (maxWidth > originalW / 2)
  69718. {
  69719. layout (maxWidth, justification, false);
  69720. if (getNumLines() <= 1)
  69721. return;
  69722. const int lastLineW = getLineWidth (getNumLines() - 1);
  69723. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69724. const float prop = lastLineW / (float) lastButOneLineW;
  69725. if (prop > 0.9f)
  69726. return;
  69727. if (prop > bestLineProportion)
  69728. {
  69729. bestLineProportion = prop;
  69730. bestWidth = maxWidth;
  69731. }
  69732. maxWidth -= 10;
  69733. }
  69734. layout (bestWidth, justification, false);
  69735. }
  69736. else
  69737. {
  69738. int x = 0;
  69739. int y = 0;
  69740. int h = 0;
  69741. totalLines = 0;
  69742. int i;
  69743. for (i = 0; i < tokens.size(); ++i)
  69744. {
  69745. Token* const t = tokens.getUnchecked(i);
  69746. t->x = x;
  69747. t->y = y;
  69748. t->line = totalLines;
  69749. x += t->w;
  69750. h = jmax (h, t->h);
  69751. const Token* nextTok = tokens [i + 1];
  69752. if (nextTok == 0)
  69753. break;
  69754. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69755. {
  69756. // finished a line, so go back and update the heights of the things on it
  69757. for (int j = i; j >= 0; --j)
  69758. {
  69759. Token* const tok = tokens.getUnchecked(j);
  69760. if (tok->line == totalLines)
  69761. tok->lineHeight = h;
  69762. else
  69763. break;
  69764. }
  69765. x = 0;
  69766. y += h;
  69767. h = 0;
  69768. ++totalLines;
  69769. }
  69770. }
  69771. // finished a line, so go back and update the heights of the things on it
  69772. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69773. {
  69774. Token* const t = tokens.getUnchecked(j);
  69775. if (t->line == totalLines)
  69776. t->lineHeight = h;
  69777. else
  69778. break;
  69779. }
  69780. ++totalLines;
  69781. if (! justification.testFlags (Justification::left))
  69782. {
  69783. int totalW = getWidth();
  69784. for (i = totalLines; --i >= 0;)
  69785. {
  69786. const int lineW = getLineWidth (i);
  69787. int dx = 0;
  69788. if (justification.testFlags (Justification::horizontallyCentred))
  69789. dx = (totalW - lineW) / 2;
  69790. else if (justification.testFlags (Justification::right))
  69791. dx = totalW - lineW;
  69792. for (int j = tokens.size(); --j >= 0;)
  69793. {
  69794. Token* const t = tokens.getUnchecked(j);
  69795. if (t->line == i)
  69796. t->x += dx;
  69797. }
  69798. }
  69799. }
  69800. }
  69801. }
  69802. int TextLayout::getLineWidth (const int lineNumber) const throw()
  69803. {
  69804. int maxW = 0;
  69805. for (int i = tokens.size(); --i >= 0;)
  69806. {
  69807. const Token* const t = tokens.getUnchecked(i);
  69808. if (t->line == lineNumber && ! t->isWhitespace)
  69809. maxW = jmax (maxW, t->x + t->w);
  69810. }
  69811. return maxW;
  69812. }
  69813. int TextLayout::getWidth() const throw()
  69814. {
  69815. int maxW = 0;
  69816. for (int i = tokens.size(); --i >= 0;)
  69817. {
  69818. const Token* const t = tokens.getUnchecked(i);
  69819. if (! t->isWhitespace)
  69820. maxW = jmax (maxW, t->x + t->w);
  69821. }
  69822. return maxW;
  69823. }
  69824. int TextLayout::getHeight() const throw()
  69825. {
  69826. int maxH = 0;
  69827. for (int i = tokens.size(); --i >= 0;)
  69828. {
  69829. const Token* const t = tokens.getUnchecked(i);
  69830. if (! t->isWhitespace)
  69831. maxH = jmax (maxH, t->y + t->h);
  69832. }
  69833. return maxH;
  69834. }
  69835. void TextLayout::draw (Graphics& g,
  69836. const int xOffset,
  69837. const int yOffset) const throw()
  69838. {
  69839. for (int i = tokens.size(); --i >= 0;)
  69840. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69841. }
  69842. void TextLayout::drawWithin (Graphics& g,
  69843. int x, int y, int w, int h,
  69844. const Justification& justification) const throw()
  69845. {
  69846. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69847. x, y, w, h);
  69848. draw (g, x, y);
  69849. }
  69850. END_JUCE_NAMESPACE
  69851. /*** End of inlined file: juce_TextLayout.cpp ***/
  69852. /*** Start of inlined file: juce_Typeface.cpp ***/
  69853. BEGIN_JUCE_NAMESPACE
  69854. Typeface::Typeface (const String& name_) throw()
  69855. : name (name_)
  69856. {
  69857. }
  69858. Typeface::~Typeface()
  69859. {
  69860. }
  69861. class CustomTypeface::GlyphInfo
  69862. {
  69863. public:
  69864. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69865. : character (character_), path (path_), width (width_)
  69866. {
  69867. }
  69868. ~GlyphInfo() throw()
  69869. {
  69870. }
  69871. struct KerningPair
  69872. {
  69873. juce_wchar character2;
  69874. float kerningAmount;
  69875. };
  69876. void addKerningPair (const juce_wchar subsequentCharacter,
  69877. const float extraKerningAmount) throw()
  69878. {
  69879. KerningPair kp;
  69880. kp.character2 = subsequentCharacter;
  69881. kp.kerningAmount = extraKerningAmount;
  69882. kerningPairs.add (kp);
  69883. }
  69884. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69885. {
  69886. if (subsequentCharacter != 0)
  69887. {
  69888. for (int i = kerningPairs.size(); --i >= 0;)
  69889. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69890. return width + kerningPairs.getReference(i).kerningAmount;
  69891. }
  69892. return width;
  69893. }
  69894. const juce_wchar character;
  69895. const Path path;
  69896. float width;
  69897. Array <KerningPair> kerningPairs;
  69898. juce_UseDebuggingNewOperator
  69899. private:
  69900. GlyphInfo (const GlyphInfo&);
  69901. GlyphInfo& operator= (const GlyphInfo&);
  69902. };
  69903. CustomTypeface::CustomTypeface()
  69904. : Typeface (String::empty)
  69905. {
  69906. clear();
  69907. }
  69908. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  69909. : Typeface (String::empty)
  69910. {
  69911. clear();
  69912. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  69913. BufferedInputStream in (&gzin, 32768, false);
  69914. name = in.readString();
  69915. isBold = in.readBool();
  69916. isItalic = in.readBool();
  69917. ascent = in.readFloat();
  69918. defaultCharacter = (juce_wchar) in.readShort();
  69919. int i, numChars = in.readInt();
  69920. for (i = 0; i < numChars; ++i)
  69921. {
  69922. const juce_wchar c = (juce_wchar) in.readShort();
  69923. const float width = in.readFloat();
  69924. Path p;
  69925. p.loadPathFromStream (in);
  69926. addGlyph (c, p, width);
  69927. }
  69928. const int numKerningPairs = in.readInt();
  69929. for (i = 0; i < numKerningPairs; ++i)
  69930. {
  69931. const juce_wchar char1 = (juce_wchar) in.readShort();
  69932. const juce_wchar char2 = (juce_wchar) in.readShort();
  69933. addKerningPair (char1, char2, in.readFloat());
  69934. }
  69935. }
  69936. CustomTypeface::~CustomTypeface()
  69937. {
  69938. }
  69939. void CustomTypeface::clear()
  69940. {
  69941. defaultCharacter = 0;
  69942. ascent = 1.0f;
  69943. isBold = isItalic = false;
  69944. zeromem (lookupTable, sizeof (lookupTable));
  69945. glyphs.clear();
  69946. }
  69947. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  69948. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  69949. {
  69950. name = name_;
  69951. defaultCharacter = defaultCharacter_;
  69952. ascent = ascent_;
  69953. isBold = isBold_;
  69954. isItalic = isItalic_;
  69955. }
  69956. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  69957. {
  69958. // Check that you're not trying to add the same character twice..
  69959. jassert (findGlyph (character, false) == 0);
  69960. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  69961. lookupTable [character] = (short) glyphs.size();
  69962. glyphs.add (new GlyphInfo (character, path, width));
  69963. }
  69964. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  69965. {
  69966. if (extraAmount != 0)
  69967. {
  69968. GlyphInfo* const g = findGlyph (char1, true);
  69969. jassert (g != 0); // can only add kerning pairs for characters that exist!
  69970. if (g != 0)
  69971. g->addKerningPair (char2, extraAmount);
  69972. }
  69973. }
  69974. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  69975. {
  69976. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  69977. return glyphs [(int) lookupTable [(int) character]];
  69978. for (int i = 0; i < glyphs.size(); ++i)
  69979. {
  69980. GlyphInfo* const g = glyphs.getUnchecked(i);
  69981. if (g->character == character)
  69982. return g;
  69983. }
  69984. if (loadIfNeeded && loadGlyphIfPossible (character))
  69985. return findGlyph (character, false);
  69986. return 0;
  69987. }
  69988. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  69989. {
  69990. GlyphInfo* glyph = findGlyph (character, true);
  69991. if (glyph == 0)
  69992. {
  69993. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  69994. glyph = findGlyph (L' ', true);
  69995. if (glyph == 0)
  69996. {
  69997. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  69998. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  69999. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70000. {
  70001. //xxx
  70002. }
  70003. if (glyph == 0)
  70004. glyph = findGlyph (defaultCharacter, true);
  70005. }
  70006. }
  70007. return glyph;
  70008. }
  70009. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70010. {
  70011. return false;
  70012. }
  70013. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70014. {
  70015. for (int i = 0; i < numCharacters; ++i)
  70016. {
  70017. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70018. Array <int> glyphIndexes;
  70019. Array <float> offsets;
  70020. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70021. const int glyphIndex = glyphIndexes.getFirst();
  70022. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70023. {
  70024. const float glyphWidth = offsets[1];
  70025. Path p;
  70026. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70027. addGlyph (c, p, glyphWidth);
  70028. for (int j = glyphs.size() - 1; --j >= 0;)
  70029. {
  70030. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70031. glyphIndexes.clearQuick();
  70032. offsets.clearQuick();
  70033. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70034. if (offsets.size() > 1)
  70035. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70036. }
  70037. }
  70038. }
  70039. }
  70040. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70041. {
  70042. GZIPCompressorOutputStream out (&outputStream);
  70043. out.writeString (name);
  70044. out.writeBool (isBold);
  70045. out.writeBool (isItalic);
  70046. out.writeFloat (ascent);
  70047. out.writeShort ((short) (unsigned short) defaultCharacter);
  70048. out.writeInt (glyphs.size());
  70049. int i, numKerningPairs = 0;
  70050. for (i = 0; i < glyphs.size(); ++i)
  70051. {
  70052. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70053. out.writeShort ((short) (unsigned short) g->character);
  70054. out.writeFloat (g->width);
  70055. g->path.writePathToStream (out);
  70056. numKerningPairs += g->kerningPairs.size();
  70057. }
  70058. out.writeInt (numKerningPairs);
  70059. for (i = 0; i < glyphs.size(); ++i)
  70060. {
  70061. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70062. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70063. {
  70064. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70065. out.writeShort ((short) (unsigned short) g->character);
  70066. out.writeShort ((short) (unsigned short) p.character2);
  70067. out.writeFloat (p.kerningAmount);
  70068. }
  70069. }
  70070. return true;
  70071. }
  70072. float CustomTypeface::getAscent() const
  70073. {
  70074. return ascent;
  70075. }
  70076. float CustomTypeface::getDescent() const
  70077. {
  70078. return 1.0f - ascent;
  70079. }
  70080. float CustomTypeface::getStringWidth (const String& text)
  70081. {
  70082. float x = 0;
  70083. const juce_wchar* t = (const juce_wchar*) text;
  70084. while (*t != 0)
  70085. {
  70086. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70087. if (glyph != 0)
  70088. x += glyph->getHorizontalSpacing (*t);
  70089. }
  70090. return x;
  70091. }
  70092. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70093. {
  70094. xOffsets.add (0);
  70095. float x = 0;
  70096. const juce_wchar* t = (const juce_wchar*) text;
  70097. while (*t != 0)
  70098. {
  70099. const juce_wchar c = *t++;
  70100. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70101. if (glyph != 0)
  70102. {
  70103. x += glyph->getHorizontalSpacing (*t);
  70104. resultGlyphs.add ((int) glyph->character);
  70105. xOffsets.add (x);
  70106. }
  70107. }
  70108. }
  70109. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70110. {
  70111. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70112. if (glyph != 0)
  70113. {
  70114. path = glyph->path;
  70115. return true;
  70116. }
  70117. return false;
  70118. }
  70119. END_JUCE_NAMESPACE
  70120. /*** End of inlined file: juce_Typeface.cpp ***/
  70121. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70122. BEGIN_JUCE_NAMESPACE
  70123. AffineTransform::AffineTransform() throw()
  70124. : mat00 (1.0f),
  70125. mat01 (0),
  70126. mat02 (0),
  70127. mat10 (0),
  70128. mat11 (1.0f),
  70129. mat12 (0)
  70130. {
  70131. }
  70132. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70133. : mat00 (other.mat00),
  70134. mat01 (other.mat01),
  70135. mat02 (other.mat02),
  70136. mat10 (other.mat10),
  70137. mat11 (other.mat11),
  70138. mat12 (other.mat12)
  70139. {
  70140. }
  70141. AffineTransform::AffineTransform (const float mat00_,
  70142. const float mat01_,
  70143. const float mat02_,
  70144. const float mat10_,
  70145. const float mat11_,
  70146. const float mat12_) throw()
  70147. : mat00 (mat00_),
  70148. mat01 (mat01_),
  70149. mat02 (mat02_),
  70150. mat10 (mat10_),
  70151. mat11 (mat11_),
  70152. mat12 (mat12_)
  70153. {
  70154. }
  70155. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70156. {
  70157. mat00 = other.mat00;
  70158. mat01 = other.mat01;
  70159. mat02 = other.mat02;
  70160. mat10 = other.mat10;
  70161. mat11 = other.mat11;
  70162. mat12 = other.mat12;
  70163. return *this;
  70164. }
  70165. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70166. {
  70167. return mat00 == other.mat00
  70168. && mat01 == other.mat01
  70169. && mat02 == other.mat02
  70170. && mat10 == other.mat10
  70171. && mat11 == other.mat11
  70172. && mat12 == other.mat12;
  70173. }
  70174. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70175. {
  70176. return ! operator== (other);
  70177. }
  70178. bool AffineTransform::isIdentity() const throw()
  70179. {
  70180. return (mat01 == 0)
  70181. && (mat02 == 0)
  70182. && (mat10 == 0)
  70183. && (mat12 == 0)
  70184. && (mat00 == 1.0f)
  70185. && (mat11 == 1.0f);
  70186. }
  70187. const AffineTransform AffineTransform::identity;
  70188. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70189. {
  70190. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70191. other.mat00 * mat01 + other.mat01 * mat11,
  70192. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70193. other.mat10 * mat00 + other.mat11 * mat10,
  70194. other.mat10 * mat01 + other.mat11 * mat11,
  70195. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70196. }
  70197. const AffineTransform AffineTransform::followedBy (const float omat00,
  70198. const float omat01,
  70199. const float omat02,
  70200. const float omat10,
  70201. const float omat11,
  70202. const float omat12) const throw()
  70203. {
  70204. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70205. omat00 * mat01 + omat01 * mat11,
  70206. omat00 * mat02 + omat01 * mat12 + omat02,
  70207. omat10 * mat00 + omat11 * mat10,
  70208. omat10 * mat01 + omat11 * mat11,
  70209. omat10 * mat02 + omat11 * mat12 + omat12);
  70210. }
  70211. const AffineTransform AffineTransform::translated (const float dx,
  70212. const float dy) const throw()
  70213. {
  70214. return AffineTransform (mat00, mat01, mat02 + dx,
  70215. mat10, mat11, mat12 + dy);
  70216. }
  70217. const AffineTransform AffineTransform::translation (const float dx,
  70218. const float dy) throw()
  70219. {
  70220. return AffineTransform (1.0f, 0, dx,
  70221. 0, 1.0f, dy);
  70222. }
  70223. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70224. {
  70225. const float cosRad = cosf (rad);
  70226. const float sinRad = sinf (rad);
  70227. return followedBy (cosRad, -sinRad, 0,
  70228. sinRad, cosRad, 0);
  70229. }
  70230. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70231. {
  70232. const float cosRad = cosf (rad);
  70233. const float sinRad = sinf (rad);
  70234. return AffineTransform (cosRad, -sinRad, 0,
  70235. sinRad, cosRad, 0);
  70236. }
  70237. const AffineTransform AffineTransform::rotated (const float angle,
  70238. const float pivotX,
  70239. const float pivotY) const throw()
  70240. {
  70241. return translated (-pivotX, -pivotY)
  70242. .rotated (angle)
  70243. .translated (pivotX, pivotY);
  70244. }
  70245. const AffineTransform AffineTransform::rotation (const float angle,
  70246. const float pivotX,
  70247. const float pivotY) throw()
  70248. {
  70249. return translation (-pivotX, -pivotY)
  70250. .rotated (angle)
  70251. .translated (pivotX, pivotY);
  70252. }
  70253. const AffineTransform AffineTransform::scaled (const float factorX,
  70254. const float factorY) const throw()
  70255. {
  70256. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70257. factorY * mat10, factorY * mat11, factorY * mat12);
  70258. }
  70259. const AffineTransform AffineTransform::scale (const float factorX,
  70260. const float factorY) throw()
  70261. {
  70262. return AffineTransform (factorX, 0, 0,
  70263. 0, factorY, 0);
  70264. }
  70265. const AffineTransform AffineTransform::sheared (const float shearX,
  70266. const float shearY) const throw()
  70267. {
  70268. return followedBy (1.0f, shearX, 0,
  70269. shearY, 1.0f, 0);
  70270. }
  70271. const AffineTransform AffineTransform::inverted() const throw()
  70272. {
  70273. double determinant = (mat00 * mat11 - mat10 * mat01);
  70274. if (determinant != 0.0)
  70275. {
  70276. determinant = 1.0 / determinant;
  70277. const float dst00 = (float) (mat11 * determinant);
  70278. const float dst10 = (float) (-mat10 * determinant);
  70279. const float dst01 = (float) (-mat01 * determinant);
  70280. const float dst11 = (float) (mat00 * determinant);
  70281. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70282. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70283. }
  70284. else
  70285. {
  70286. // singularity..
  70287. return *this;
  70288. }
  70289. }
  70290. bool AffineTransform::isSingularity() const throw()
  70291. {
  70292. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70293. }
  70294. bool AffineTransform::isOnlyTranslation() const throw()
  70295. {
  70296. return (mat01 == 0)
  70297. && (mat10 == 0)
  70298. && (mat00 == 1.0f)
  70299. && (mat11 == 1.0f);
  70300. }
  70301. void AffineTransform::transformPoint (float& x,
  70302. float& y) const throw()
  70303. {
  70304. const float oldX = x;
  70305. x = mat00 * oldX + mat01 * y + mat02;
  70306. y = mat10 * oldX + mat11 * y + mat12;
  70307. }
  70308. void AffineTransform::transformPoint (double& x,
  70309. double& y) const throw()
  70310. {
  70311. const double oldX = x;
  70312. x = mat00 * oldX + mat01 * y + mat02;
  70313. y = mat10 * oldX + mat11 * y + mat12;
  70314. }
  70315. END_JUCE_NAMESPACE
  70316. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70317. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70318. BEGIN_JUCE_NAMESPACE
  70319. BorderSize::BorderSize() throw()
  70320. : top (0),
  70321. left (0),
  70322. bottom (0),
  70323. right (0)
  70324. {
  70325. }
  70326. BorderSize::BorderSize (const BorderSize& other) throw()
  70327. : top (other.top),
  70328. left (other.left),
  70329. bottom (other.bottom),
  70330. right (other.right)
  70331. {
  70332. }
  70333. BorderSize::BorderSize (const int topGap,
  70334. const int leftGap,
  70335. const int bottomGap,
  70336. const int rightGap) throw()
  70337. : top (topGap),
  70338. left (leftGap),
  70339. bottom (bottomGap),
  70340. right (rightGap)
  70341. {
  70342. }
  70343. BorderSize::BorderSize (const int allGaps) throw()
  70344. : top (allGaps),
  70345. left (allGaps),
  70346. bottom (allGaps),
  70347. right (allGaps)
  70348. {
  70349. }
  70350. BorderSize::~BorderSize() throw()
  70351. {
  70352. }
  70353. void BorderSize::setTop (const int newTopGap) throw()
  70354. {
  70355. top = newTopGap;
  70356. }
  70357. void BorderSize::setLeft (const int newLeftGap) throw()
  70358. {
  70359. left = newLeftGap;
  70360. }
  70361. void BorderSize::setBottom (const int newBottomGap) throw()
  70362. {
  70363. bottom = newBottomGap;
  70364. }
  70365. void BorderSize::setRight (const int newRightGap) throw()
  70366. {
  70367. right = newRightGap;
  70368. }
  70369. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70370. {
  70371. return Rectangle<int> (r.getX() + left,
  70372. r.getY() + top,
  70373. r.getWidth() - (left + right),
  70374. r.getHeight() - (top + bottom));
  70375. }
  70376. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70377. {
  70378. r.setBounds (r.getX() + left,
  70379. r.getY() + top,
  70380. r.getWidth() - (left + right),
  70381. r.getHeight() - (top + bottom));
  70382. }
  70383. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70384. {
  70385. return Rectangle<int> (r.getX() - left,
  70386. r.getY() - top,
  70387. r.getWidth() + (left + right),
  70388. r.getHeight() + (top + bottom));
  70389. }
  70390. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70391. {
  70392. r.setBounds (r.getX() - left,
  70393. r.getY() - top,
  70394. r.getWidth() + (left + right),
  70395. r.getHeight() + (top + bottom));
  70396. }
  70397. bool BorderSize::operator== (const BorderSize& other) const throw()
  70398. {
  70399. return top == other.top
  70400. && left == other.left
  70401. && bottom == other.bottom
  70402. && right == other.right;
  70403. }
  70404. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70405. {
  70406. return ! operator== (other);
  70407. }
  70408. END_JUCE_NAMESPACE
  70409. /*** End of inlined file: juce_BorderSize.cpp ***/
  70410. /*** Start of inlined file: juce_Line.cpp ***/
  70411. BEGIN_JUCE_NAMESPACE
  70412. static bool juce_lineIntersection (const float x1, const float y1,
  70413. const float x2, const float y2,
  70414. const float x3, const float y3,
  70415. const float x4, const float y4,
  70416. float& intersectionX,
  70417. float& intersectionY) throw()
  70418. {
  70419. if (x2 != x3 || y2 != y3)
  70420. {
  70421. const float dx1 = x2 - x1;
  70422. const float dy1 = y2 - y1;
  70423. const float dx2 = x4 - x3;
  70424. const float dy2 = y4 - y3;
  70425. const float divisor = dx1 * dy2 - dx2 * dy1;
  70426. if (divisor == 0)
  70427. {
  70428. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70429. {
  70430. if (dy1 == 0 && dy2 != 0)
  70431. {
  70432. const float along = (y1 - y3) / dy2;
  70433. intersectionX = x3 + along * dx2;
  70434. intersectionY = y1;
  70435. return along >= 0 && along <= 1.0f;
  70436. }
  70437. else if (dy2 == 0 && dy1 != 0)
  70438. {
  70439. const float along = (y3 - y1) / dy1;
  70440. intersectionX = x1 + along * dx1;
  70441. intersectionY = y3;
  70442. return along >= 0 && along <= 1.0f;
  70443. }
  70444. else if (dx1 == 0 && dx2 != 0)
  70445. {
  70446. const float along = (x1 - x3) / dx2;
  70447. intersectionX = x1;
  70448. intersectionY = y3 + along * dy2;
  70449. return along >= 0 && along <= 1.0f;
  70450. }
  70451. else if (dx2 == 0 && dx1 != 0)
  70452. {
  70453. const float along = (x3 - x1) / dx1;
  70454. intersectionX = x3;
  70455. intersectionY = y1 + along * dy1;
  70456. return along >= 0 && along <= 1.0f;
  70457. }
  70458. }
  70459. intersectionX = 0.5f * (x2 + x3);
  70460. intersectionY = 0.5f * (y2 + y3);
  70461. return false;
  70462. }
  70463. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70464. intersectionX = x1 + along1 * dx1;
  70465. intersectionY = y1 + along1 * dy1;
  70466. if (along1 < 0 || along1 > 1.0f)
  70467. return false;
  70468. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70469. return along2 >= 0 && along2 <= 1.0f;
  70470. }
  70471. intersectionX = x2;
  70472. intersectionY = y2;
  70473. return true;
  70474. }
  70475. Line::Line() throw()
  70476. : startX (0.0f),
  70477. startY (0.0f),
  70478. endX (0.0f),
  70479. endY (0.0f)
  70480. {
  70481. }
  70482. Line::Line (const Line& other) throw()
  70483. : startX (other.startX),
  70484. startY (other.startY),
  70485. endX (other.endX),
  70486. endY (other.endY)
  70487. {
  70488. }
  70489. Line::Line (const float startX_, const float startY_,
  70490. const float endX_, const float endY_) throw()
  70491. : startX (startX_),
  70492. startY (startY_),
  70493. endX (endX_),
  70494. endY (endY_)
  70495. {
  70496. }
  70497. Line::Line (const Point<float>& start,
  70498. const Point<float>& end) throw()
  70499. : startX (start.getX()),
  70500. startY (start.getY()),
  70501. endX (end.getX()),
  70502. endY (end.getY())
  70503. {
  70504. }
  70505. Line& Line::operator= (const Line& other) throw()
  70506. {
  70507. startX = other.startX;
  70508. startY = other.startY;
  70509. endX = other.endX;
  70510. endY = other.endY;
  70511. return *this;
  70512. }
  70513. Line::~Line() throw()
  70514. {
  70515. }
  70516. const Point<float> Line::getStart() const throw()
  70517. {
  70518. return Point<float> (startX, startY);
  70519. }
  70520. const Point<float> Line::getEnd() const throw()
  70521. {
  70522. return Point<float> (endX, endY);
  70523. }
  70524. void Line::setStart (const float newStartX,
  70525. const float newStartY) throw()
  70526. {
  70527. startX = newStartX;
  70528. startY = newStartY;
  70529. }
  70530. void Line::setStart (const Point<float>& newStart) throw()
  70531. {
  70532. startX = newStart.getX();
  70533. startY = newStart.getY();
  70534. }
  70535. void Line::setEnd (const float newEndX,
  70536. const float newEndY) throw()
  70537. {
  70538. endX = newEndX;
  70539. endY = newEndY;
  70540. }
  70541. void Line::setEnd (const Point<float>& newEnd) throw()
  70542. {
  70543. endX = newEnd.getX();
  70544. endY = newEnd.getY();
  70545. }
  70546. bool Line::operator== (const Line& other) const throw()
  70547. {
  70548. return startX == other.startX
  70549. && startY == other.startY
  70550. && endX == other.endX
  70551. && endY == other.endY;
  70552. }
  70553. bool Line::operator!= (const Line& other) const throw()
  70554. {
  70555. return startX != other.startX
  70556. || startY != other.startY
  70557. || endX != other.endX
  70558. || endY != other.endY;
  70559. }
  70560. void Line::applyTransform (const AffineTransform& transform) throw()
  70561. {
  70562. transform.transformPoint (startX, startY);
  70563. transform.transformPoint (endX, endY);
  70564. }
  70565. float Line::getLength() const throw()
  70566. {
  70567. return (float) juce_hypot (startX - endX,
  70568. startY - endY);
  70569. }
  70570. float Line::getAngle() const throw()
  70571. {
  70572. return atan2f (endX - startX,
  70573. endY - startY);
  70574. }
  70575. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70576. {
  70577. const float alpha = distanceFromStart / getLength();
  70578. return Point<float> (startX + (endX - startX) * alpha,
  70579. startY + (endY - startY) * alpha);
  70580. }
  70581. const Point<float> Line::getPointAlongLine (const float offsetX,
  70582. const float offsetY) const throw()
  70583. {
  70584. const float dx = endX - startX;
  70585. const float dy = endY - startY;
  70586. const double length = juce_hypot (dx, dy);
  70587. if (length == 0)
  70588. return Point<float> (startX, startY);
  70589. else
  70590. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70591. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70592. }
  70593. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70594. {
  70595. return Point<float> (startX + (endX - startX) * alpha,
  70596. startY + (endY - startY) * alpha);
  70597. }
  70598. float Line::getDistanceFromLine (const float x,
  70599. const float y) const throw()
  70600. {
  70601. const double dx = endX - startX;
  70602. const double dy = endY - startY;
  70603. const double length = dx * dx + dy * dy;
  70604. if (length > 0)
  70605. {
  70606. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70607. if (prop >= 0.0f && prop < 1.0f)
  70608. {
  70609. return (float) juce_hypot (x - (startX + prop * dx),
  70610. y - (startY + prop * dy));
  70611. }
  70612. }
  70613. return (float) jmin (juce_hypot (x - startX, y - startY),
  70614. juce_hypot (x - endX, y - endY));
  70615. }
  70616. float Line::findNearestPointTo (const float x,
  70617. const float y) const throw()
  70618. {
  70619. const double dx = endX - startX;
  70620. const double dy = endY - startY;
  70621. const double length = dx * dx + dy * dy;
  70622. if (length <= 0.0)
  70623. return 0.0f;
  70624. return jlimit (0.0f, 1.0f,
  70625. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70626. }
  70627. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70628. {
  70629. const float length = getLength();
  70630. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70631. getEnd());
  70632. }
  70633. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70634. {
  70635. const float length = getLength();
  70636. return Line (getStart(),
  70637. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70638. }
  70639. bool Line::clipToPath (const Path& path,
  70640. const bool keepSectionOutsidePath) throw()
  70641. {
  70642. const bool startInside = path.contains (startX, startY);
  70643. const bool endInside = path.contains (endX, endY);
  70644. if (startInside == endInside)
  70645. {
  70646. if (keepSectionOutsidePath != startInside)
  70647. {
  70648. // entirely outside the path
  70649. return false;
  70650. }
  70651. else
  70652. {
  70653. // entirely inside the path
  70654. startX = 0.0f;
  70655. startY = 0.0f;
  70656. endX = 0.0f;
  70657. endY = 0.0f;
  70658. return true;
  70659. }
  70660. }
  70661. else
  70662. {
  70663. bool changed = false;
  70664. PathFlatteningIterator iter (path, AffineTransform::identity);
  70665. while (iter.next())
  70666. {
  70667. float ix, iy;
  70668. if (intersects (Line (iter.x1, iter.y1,
  70669. iter.x2, iter.y2),
  70670. ix, iy))
  70671. {
  70672. if ((startInside && keepSectionOutsidePath)
  70673. || (endInside && ! keepSectionOutsidePath))
  70674. {
  70675. setStart (ix, iy);
  70676. }
  70677. else
  70678. {
  70679. setEnd (ix, iy);
  70680. }
  70681. changed = true;
  70682. }
  70683. }
  70684. return changed;
  70685. }
  70686. }
  70687. bool Line::intersects (const Line& line,
  70688. float& intersectionX,
  70689. float& intersectionY) const throw()
  70690. {
  70691. return juce_lineIntersection (startX, startY,
  70692. endX, endY,
  70693. line.startX, line.startY,
  70694. line.endX, line.endY,
  70695. intersectionX,
  70696. intersectionY);
  70697. }
  70698. bool Line::isVertical() const throw()
  70699. {
  70700. return startX == endX;
  70701. }
  70702. bool Line::isHorizontal() const throw()
  70703. {
  70704. return startY == endY;
  70705. }
  70706. bool Line::isPointAbove (const float x, const float y) const throw()
  70707. {
  70708. return startX != endX
  70709. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70710. }
  70711. END_JUCE_NAMESPACE
  70712. /*** End of inlined file: juce_Line.cpp ***/
  70713. /*** Start of inlined file: juce_Path.cpp ***/
  70714. BEGIN_JUCE_NAMESPACE
  70715. // tests that some co-ords aren't NaNs
  70716. #define CHECK_COORDS_ARE_VALID(x, y) \
  70717. jassert (x == x && y == y);
  70718. namespace PathHelpers
  70719. {
  70720. static const float ellipseAngularIncrement = 0.05f;
  70721. static void perpendicularOffset (const float x1, const float y1,
  70722. const float x2, const float y2,
  70723. const float offsetX, const float offsetY,
  70724. float& resultX, float& resultY) throw()
  70725. {
  70726. const float dx = x2 - x1;
  70727. const float dy = y2 - y1;
  70728. const float len = juce_hypotf (dx, dy);
  70729. if (len == 0)
  70730. {
  70731. resultX = x1;
  70732. resultY = y1;
  70733. }
  70734. else
  70735. {
  70736. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  70737. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  70738. }
  70739. }
  70740. static const String nextToken (const tchar*& t)
  70741. {
  70742. while (CharacterFunctions::isWhitespace (*t))
  70743. ++t;
  70744. const tchar* const start = t;
  70745. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  70746. ++t;
  70747. const int length = (int) (t - start);
  70748. while (CharacterFunctions::isWhitespace (*t))
  70749. ++t;
  70750. return String (start, length);
  70751. }
  70752. }
  70753. const float Path::lineMarker = 100001.0f;
  70754. const float Path::moveMarker = 100002.0f;
  70755. const float Path::quadMarker = 100003.0f;
  70756. const float Path::cubicMarker = 100004.0f;
  70757. const float Path::closeSubPathMarker = 100005.0f;
  70758. Path::Path()
  70759. : numElements (0),
  70760. pathXMin (0),
  70761. pathXMax (0),
  70762. pathYMin (0),
  70763. pathYMax (0),
  70764. useNonZeroWinding (true)
  70765. {
  70766. }
  70767. Path::~Path()
  70768. {
  70769. }
  70770. Path::Path (const Path& other)
  70771. : numElements (other.numElements),
  70772. pathXMin (other.pathXMin),
  70773. pathXMax (other.pathXMax),
  70774. pathYMin (other.pathYMin),
  70775. pathYMax (other.pathYMax),
  70776. useNonZeroWinding (other.useNonZeroWinding)
  70777. {
  70778. if (numElements > 0)
  70779. {
  70780. data.setAllocatedSize (numElements);
  70781. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70782. }
  70783. }
  70784. Path& Path::operator= (const Path& other)
  70785. {
  70786. if (this != &other)
  70787. {
  70788. data.ensureAllocatedSize (other.numElements);
  70789. numElements = other.numElements;
  70790. pathXMin = other.pathXMin;
  70791. pathXMax = other.pathXMax;
  70792. pathYMin = other.pathYMin;
  70793. pathYMax = other.pathYMax;
  70794. useNonZeroWinding = other.useNonZeroWinding;
  70795. if (numElements > 0)
  70796. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70797. }
  70798. return *this;
  70799. }
  70800. void Path::clear() throw()
  70801. {
  70802. numElements = 0;
  70803. pathXMin = 0;
  70804. pathYMin = 0;
  70805. pathYMax = 0;
  70806. pathXMax = 0;
  70807. }
  70808. void Path::swapWithPath (Path& other)
  70809. {
  70810. data.swapWith (other.data);
  70811. swapVariables <size_t> (numElements, other.numElements);
  70812. swapVariables <float> (pathXMin, other.pathXMin);
  70813. swapVariables <float> (pathXMax, other.pathXMax);
  70814. swapVariables <float> (pathYMin, other.pathYMin);
  70815. swapVariables <float> (pathYMax, other.pathYMax);
  70816. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70817. }
  70818. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70819. {
  70820. useNonZeroWinding = isNonZero;
  70821. }
  70822. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70823. const bool preserveProportions) throw()
  70824. {
  70825. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70826. }
  70827. bool Path::isEmpty() const throw()
  70828. {
  70829. size_t i = 0;
  70830. while (i < numElements)
  70831. {
  70832. const float type = data.elements [i++];
  70833. if (type == moveMarker)
  70834. {
  70835. i += 2;
  70836. }
  70837. else if (type == lineMarker
  70838. || type == quadMarker
  70839. || type == cubicMarker)
  70840. {
  70841. return false;
  70842. }
  70843. }
  70844. return true;
  70845. }
  70846. const Rectangle<float> Path::getBounds() const throw()
  70847. {
  70848. return Rectangle<float> (pathXMin, pathYMin,
  70849. pathXMax - pathXMin,
  70850. pathYMax - pathYMin);
  70851. }
  70852. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70853. {
  70854. return getBounds().transformed (transform);
  70855. }
  70856. void Path::startNewSubPath (const float x, const float y)
  70857. {
  70858. CHECK_COORDS_ARE_VALID (x, y);
  70859. if (numElements == 0)
  70860. {
  70861. pathXMin = pathXMax = x;
  70862. pathYMin = pathYMax = y;
  70863. }
  70864. else
  70865. {
  70866. pathXMin = jmin (pathXMin, x);
  70867. pathXMax = jmax (pathXMax, x);
  70868. pathYMin = jmin (pathYMin, y);
  70869. pathYMax = jmax (pathYMax, y);
  70870. }
  70871. data.ensureAllocatedSize (numElements + 3);
  70872. data.elements [numElements++] = moveMarker;
  70873. data.elements [numElements++] = x;
  70874. data.elements [numElements++] = y;
  70875. }
  70876. void Path::lineTo (const float x, const float y)
  70877. {
  70878. CHECK_COORDS_ARE_VALID (x, y);
  70879. if (numElements == 0)
  70880. startNewSubPath (0, 0);
  70881. data.ensureAllocatedSize (numElements + 3);
  70882. data.elements [numElements++] = lineMarker;
  70883. data.elements [numElements++] = x;
  70884. data.elements [numElements++] = y;
  70885. pathXMin = jmin (pathXMin, x);
  70886. pathXMax = jmax (pathXMax, x);
  70887. pathYMin = jmin (pathYMin, y);
  70888. pathYMax = jmax (pathYMax, y);
  70889. }
  70890. void Path::quadraticTo (const float x1, const float y1,
  70891. const float x2, const float y2)
  70892. {
  70893. CHECK_COORDS_ARE_VALID (x1, y1);
  70894. CHECK_COORDS_ARE_VALID (x2, y2);
  70895. if (numElements == 0)
  70896. startNewSubPath (0, 0);
  70897. data.ensureAllocatedSize (numElements + 5);
  70898. data.elements [numElements++] = quadMarker;
  70899. data.elements [numElements++] = x1;
  70900. data.elements [numElements++] = y1;
  70901. data.elements [numElements++] = x2;
  70902. data.elements [numElements++] = y2;
  70903. pathXMin = jmin (pathXMin, x1, x2);
  70904. pathXMax = jmax (pathXMax, x1, x2);
  70905. pathYMin = jmin (pathYMin, y1, y2);
  70906. pathYMax = jmax (pathYMax, y1, y2);
  70907. }
  70908. void Path::cubicTo (const float x1, const float y1,
  70909. const float x2, const float y2,
  70910. const float x3, const float y3)
  70911. {
  70912. CHECK_COORDS_ARE_VALID (x1, y1);
  70913. CHECK_COORDS_ARE_VALID (x2, y2);
  70914. CHECK_COORDS_ARE_VALID (x3, y3);
  70915. if (numElements == 0)
  70916. startNewSubPath (0, 0);
  70917. data.ensureAllocatedSize (numElements + 7);
  70918. data.elements [numElements++] = cubicMarker;
  70919. data.elements [numElements++] = x1;
  70920. data.elements [numElements++] = y1;
  70921. data.elements [numElements++] = x2;
  70922. data.elements [numElements++] = y2;
  70923. data.elements [numElements++] = x3;
  70924. data.elements [numElements++] = y3;
  70925. pathXMin = jmin (pathXMin, x1, x2, x3);
  70926. pathXMax = jmax (pathXMax, x1, x2, x3);
  70927. pathYMin = jmin (pathYMin, y1, y2, y3);
  70928. pathYMax = jmax (pathYMax, y1, y2, y3);
  70929. }
  70930. void Path::closeSubPath()
  70931. {
  70932. if (numElements > 0
  70933. && data.elements [numElements - 1] != closeSubPathMarker)
  70934. {
  70935. data.ensureAllocatedSize (numElements + 1);
  70936. data.elements [numElements++] = closeSubPathMarker;
  70937. }
  70938. }
  70939. const Point<float> Path::getCurrentPosition() const
  70940. {
  70941. int i = numElements - 1;
  70942. if (i > 0 && data.elements[i] == closeSubPathMarker)
  70943. {
  70944. while (i >= 0)
  70945. {
  70946. if (data.elements[i] == moveMarker)
  70947. {
  70948. i += 2;
  70949. break;
  70950. }
  70951. --i;
  70952. }
  70953. }
  70954. if (i > 0)
  70955. return Point<float> (data.elements [i - 1], data.elements [i]);
  70956. return Point<float>();
  70957. }
  70958. void Path::addRectangle (const float x, const float y,
  70959. const float w, const float h)
  70960. {
  70961. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  70962. if (w < 0)
  70963. swapVariables (x1, x2);
  70964. if (h < 0)
  70965. swapVariables (y1, y2);
  70966. data.ensureAllocatedSize (numElements + 13);
  70967. if (numElements == 0)
  70968. {
  70969. pathXMin = x1;
  70970. pathXMax = x2;
  70971. pathYMin = y1;
  70972. pathYMax = y2;
  70973. }
  70974. else
  70975. {
  70976. pathXMin = jmin (pathXMin, x1);
  70977. pathXMax = jmax (pathXMax, x2);
  70978. pathYMin = jmin (pathYMin, y1);
  70979. pathYMax = jmax (pathYMax, y2);
  70980. }
  70981. data.elements [numElements++] = moveMarker;
  70982. data.elements [numElements++] = x1;
  70983. data.elements [numElements++] = y2;
  70984. data.elements [numElements++] = lineMarker;
  70985. data.elements [numElements++] = x1;
  70986. data.elements [numElements++] = y1;
  70987. data.elements [numElements++] = lineMarker;
  70988. data.elements [numElements++] = x2;
  70989. data.elements [numElements++] = y1;
  70990. data.elements [numElements++] = lineMarker;
  70991. data.elements [numElements++] = x2;
  70992. data.elements [numElements++] = y2;
  70993. data.elements [numElements++] = closeSubPathMarker;
  70994. }
  70995. void Path::addRectangle (const Rectangle<int>& rectangle)
  70996. {
  70997. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  70998. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  70999. }
  71000. void Path::addRoundedRectangle (const float x, const float y,
  71001. const float w, const float h,
  71002. float csx,
  71003. float csy)
  71004. {
  71005. csx = jmin (csx, w * 0.5f);
  71006. csy = jmin (csy, h * 0.5f);
  71007. const float cs45x = csx * 0.45f;
  71008. const float cs45y = csy * 0.45f;
  71009. const float x2 = x + w;
  71010. const float y2 = y + h;
  71011. startNewSubPath (x + csx, y);
  71012. lineTo (x2 - csx, y);
  71013. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71014. lineTo (x2, y2 - csy);
  71015. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71016. lineTo (x + csx, y2);
  71017. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71018. lineTo (x, y + csy);
  71019. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71020. closeSubPath();
  71021. }
  71022. void Path::addRoundedRectangle (const float x, const float y,
  71023. const float w, const float h,
  71024. float cs)
  71025. {
  71026. addRoundedRectangle (x, y, w, h, cs, cs);
  71027. }
  71028. void Path::addTriangle (const float x1, const float y1,
  71029. const float x2, const float y2,
  71030. const float x3, const float y3)
  71031. {
  71032. startNewSubPath (x1, y1);
  71033. lineTo (x2, y2);
  71034. lineTo (x3, y3);
  71035. closeSubPath();
  71036. }
  71037. void Path::addQuadrilateral (const float x1, const float y1,
  71038. const float x2, const float y2,
  71039. const float x3, const float y3,
  71040. const float x4, const float y4)
  71041. {
  71042. startNewSubPath (x1, y1);
  71043. lineTo (x2, y2);
  71044. lineTo (x3, y3);
  71045. lineTo (x4, y4);
  71046. closeSubPath();
  71047. }
  71048. void Path::addEllipse (const float x, const float y,
  71049. const float w, const float h)
  71050. {
  71051. const float hw = w * 0.5f;
  71052. const float hw55 = hw * 0.55f;
  71053. const float hh = h * 0.5f;
  71054. const float hh45 = hh * 0.55f;
  71055. const float cx = x + hw;
  71056. const float cy = y + hh;
  71057. startNewSubPath (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. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71061. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71062. closeSubPath();
  71063. }
  71064. void Path::addArc (const float x, const float y,
  71065. const float w, const float h,
  71066. const float fromRadians,
  71067. const float toRadians,
  71068. const bool startAsNewSubPath)
  71069. {
  71070. const float radiusX = w / 2.0f;
  71071. const float radiusY = h / 2.0f;
  71072. addCentredArc (x + radiusX,
  71073. y + radiusY,
  71074. radiusX, radiusY,
  71075. 0.0f,
  71076. fromRadians, toRadians,
  71077. startAsNewSubPath);
  71078. }
  71079. void Path::addCentredArc (const float centreX, const float centreY,
  71080. const float radiusX, const float radiusY,
  71081. const float rotationOfEllipse,
  71082. const float fromRadians,
  71083. const float toRadians,
  71084. const bool startAsNewSubPath)
  71085. {
  71086. if (radiusX > 0.0f && radiusY > 0.0f)
  71087. {
  71088. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71089. float angle = fromRadians;
  71090. if (startAsNewSubPath)
  71091. {
  71092. float x = centreX + radiusX * sinf (angle);
  71093. float y = centreY - radiusY * cosf (angle);
  71094. if (rotationOfEllipse != 0)
  71095. rotation.transformPoint (x, y);
  71096. startNewSubPath (x, y);
  71097. }
  71098. if (fromRadians < toRadians)
  71099. {
  71100. if (startAsNewSubPath)
  71101. angle += PathHelpers::ellipseAngularIncrement;
  71102. while (angle < toRadians)
  71103. {
  71104. float x = centreX + radiusX * sinf (angle);
  71105. float y = centreY - radiusY * cosf (angle);
  71106. if (rotationOfEllipse != 0)
  71107. rotation.transformPoint (x, y);
  71108. lineTo (x, y);
  71109. angle += PathHelpers::ellipseAngularIncrement;
  71110. }
  71111. }
  71112. else
  71113. {
  71114. if (startAsNewSubPath)
  71115. angle -= PathHelpers::ellipseAngularIncrement;
  71116. while (angle > toRadians)
  71117. {
  71118. float x = centreX + radiusX * sinf (angle);
  71119. float y = centreY - radiusY * cosf (angle);
  71120. if (rotationOfEllipse != 0)
  71121. rotation.transformPoint (x, y);
  71122. lineTo (x, y);
  71123. angle -= PathHelpers::ellipseAngularIncrement;
  71124. }
  71125. }
  71126. float x = centreX + radiusX * sinf (toRadians);
  71127. float y = centreY - radiusY * cosf (toRadians);
  71128. if (rotationOfEllipse != 0)
  71129. rotation.transformPoint (x, y);
  71130. lineTo (x, y);
  71131. }
  71132. }
  71133. void Path::addPieSegment (const float x, const float y,
  71134. const float width, const float height,
  71135. const float fromRadians,
  71136. const float toRadians,
  71137. const float innerCircleProportionalSize)
  71138. {
  71139. float hw = width * 0.5f;
  71140. float hh = height * 0.5f;
  71141. const float centreX = x + hw;
  71142. const float centreY = y + hh;
  71143. startNewSubPath (centreX + hw * sinf (fromRadians),
  71144. centreY - hh * cosf (fromRadians));
  71145. addArc (x, y, width, height, fromRadians, toRadians);
  71146. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71147. {
  71148. closeSubPath();
  71149. if (innerCircleProportionalSize > 0)
  71150. {
  71151. hw *= innerCircleProportionalSize;
  71152. hh *= innerCircleProportionalSize;
  71153. startNewSubPath (centreX + hw * sinf (toRadians),
  71154. centreY - hh * cosf (toRadians));
  71155. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71156. toRadians, fromRadians);
  71157. }
  71158. }
  71159. else
  71160. {
  71161. if (innerCircleProportionalSize > 0)
  71162. {
  71163. hw *= innerCircleProportionalSize;
  71164. hh *= innerCircleProportionalSize;
  71165. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71166. toRadians, fromRadians);
  71167. }
  71168. else
  71169. {
  71170. lineTo (centreX, centreY);
  71171. }
  71172. }
  71173. closeSubPath();
  71174. }
  71175. void Path::addLineSegment (const float startX, const float startY,
  71176. const float endX, const float endY,
  71177. float lineThickness)
  71178. {
  71179. lineThickness *= 0.5f;
  71180. float x, y;
  71181. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71182. 0, lineThickness, x, y);
  71183. startNewSubPath (x, y);
  71184. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71185. 0, -lineThickness, x, y);
  71186. lineTo (x, y);
  71187. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71188. 0, lineThickness, x, y);
  71189. lineTo (x, y);
  71190. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71191. 0, -lineThickness, x, y);
  71192. lineTo (x, y);
  71193. closeSubPath();
  71194. }
  71195. void Path::addArrow (const float startX, const float startY,
  71196. const float endX, const float endY,
  71197. float lineThickness,
  71198. float arrowheadWidth,
  71199. float arrowheadLength)
  71200. {
  71201. lineThickness *= 0.5f;
  71202. arrowheadWidth *= 0.5f;
  71203. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71204. startY - endY));
  71205. float x, y;
  71206. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71207. 0, lineThickness, x, y);
  71208. startNewSubPath (x, y);
  71209. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71210. 0, -lineThickness, x, y);
  71211. lineTo (x, y);
  71212. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71213. arrowheadLength, lineThickness, x, y);
  71214. lineTo (x, y);
  71215. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71216. arrowheadLength, arrowheadWidth, x, y);
  71217. lineTo (x, y);
  71218. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71219. 0, 0, x, y);
  71220. lineTo (x, y);
  71221. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71222. arrowheadLength, -arrowheadWidth, x, y);
  71223. lineTo (x, y);
  71224. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71225. arrowheadLength, -lineThickness, x, y);
  71226. lineTo (x, y);
  71227. closeSubPath();
  71228. }
  71229. void Path::addStar (const float centreX,
  71230. const float centreY,
  71231. const int numberOfPoints,
  71232. const float innerRadius,
  71233. const float outerRadius,
  71234. const float startAngle)
  71235. {
  71236. jassert (numberOfPoints > 1); // this would be silly.
  71237. if (numberOfPoints > 1)
  71238. {
  71239. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71240. for (int i = 0; i < numberOfPoints; ++i)
  71241. {
  71242. float angle = startAngle + i * angleBetweenPoints;
  71243. const float x = centreX + outerRadius * sinf (angle);
  71244. const float y = centreY - outerRadius * cosf (angle);
  71245. if (i == 0)
  71246. startNewSubPath (x, y);
  71247. else
  71248. lineTo (x, y);
  71249. angle += angleBetweenPoints * 0.5f;
  71250. lineTo (centreX + innerRadius * sinf (angle),
  71251. centreY - innerRadius * cosf (angle));
  71252. }
  71253. closeSubPath();
  71254. }
  71255. }
  71256. void Path::addBubble (float x, float y,
  71257. float w, float h,
  71258. float cs,
  71259. float tipX,
  71260. float tipY,
  71261. int whichSide,
  71262. float arrowPos,
  71263. float arrowWidth)
  71264. {
  71265. if (w > 1.0f && h > 1.0f)
  71266. {
  71267. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71268. const float cs2 = 2.0f * cs;
  71269. startNewSubPath (x + cs, y);
  71270. if (whichSide == 0)
  71271. {
  71272. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71273. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71274. lineTo (arrowX1, y);
  71275. lineTo (tipX, tipY);
  71276. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71277. }
  71278. lineTo (x + w - cs, y);
  71279. if (cs > 0.0f)
  71280. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71281. if (whichSide == 3)
  71282. {
  71283. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71284. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71285. lineTo (x + w, arrowY1);
  71286. lineTo (tipX, tipY);
  71287. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71288. }
  71289. lineTo (x + w, y + h - cs);
  71290. if (cs > 0.0f)
  71291. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71292. if (whichSide == 2)
  71293. {
  71294. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71295. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71296. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71297. lineTo (tipX, tipY);
  71298. lineTo (arrowX1, y + h);
  71299. }
  71300. lineTo (x + cs, y + h);
  71301. if (cs > 0.0f)
  71302. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71303. if (whichSide == 1)
  71304. {
  71305. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71306. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71307. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71308. lineTo (tipX, tipY);
  71309. lineTo (x, arrowY1);
  71310. }
  71311. lineTo (x, y + cs);
  71312. if (cs > 0.0f)
  71313. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement);
  71314. closeSubPath();
  71315. }
  71316. }
  71317. void Path::addPath (const Path& other)
  71318. {
  71319. size_t i = 0;
  71320. while (i < other.numElements)
  71321. {
  71322. const float type = other.data.elements [i++];
  71323. if (type == moveMarker)
  71324. {
  71325. startNewSubPath (other.data.elements [i],
  71326. other.data.elements [i + 1]);
  71327. i += 2;
  71328. }
  71329. else if (type == lineMarker)
  71330. {
  71331. lineTo (other.data.elements [i],
  71332. other.data.elements [i + 1]);
  71333. i += 2;
  71334. }
  71335. else if (type == quadMarker)
  71336. {
  71337. quadraticTo (other.data.elements [i],
  71338. other.data.elements [i + 1],
  71339. other.data.elements [i + 2],
  71340. other.data.elements [i + 3]);
  71341. i += 4;
  71342. }
  71343. else if (type == cubicMarker)
  71344. {
  71345. cubicTo (other.data.elements [i],
  71346. other.data.elements [i + 1],
  71347. other.data.elements [i + 2],
  71348. other.data.elements [i + 3],
  71349. other.data.elements [i + 4],
  71350. other.data.elements [i + 5]);
  71351. i += 6;
  71352. }
  71353. else if (type == closeSubPathMarker)
  71354. {
  71355. closeSubPath();
  71356. }
  71357. else
  71358. {
  71359. // something's gone wrong with the element list!
  71360. jassertfalse
  71361. }
  71362. }
  71363. }
  71364. void Path::addPath (const Path& other,
  71365. const AffineTransform& transformToApply)
  71366. {
  71367. size_t i = 0;
  71368. while (i < other.numElements)
  71369. {
  71370. const float type = other.data.elements [i++];
  71371. if (type == closeSubPathMarker)
  71372. {
  71373. closeSubPath();
  71374. }
  71375. else
  71376. {
  71377. float x = other.data.elements [i++];
  71378. float y = other.data.elements [i++];
  71379. transformToApply.transformPoint (x, y);
  71380. if (type == moveMarker)
  71381. {
  71382. startNewSubPath (x, y);
  71383. }
  71384. else if (type == lineMarker)
  71385. {
  71386. lineTo (x, y);
  71387. }
  71388. else if (type == quadMarker)
  71389. {
  71390. float x2 = other.data.elements [i++];
  71391. float y2 = other.data.elements [i++];
  71392. transformToApply.transformPoint (x2, y2);
  71393. quadraticTo (x, y, x2, y2);
  71394. }
  71395. else if (type == cubicMarker)
  71396. {
  71397. float x2 = other.data.elements [i++];
  71398. float y2 = other.data.elements [i++];
  71399. float x3 = other.data.elements [i++];
  71400. float y3 = other.data.elements [i++];
  71401. transformToApply.transformPoint (x2, y2);
  71402. transformToApply.transformPoint (x3, y3);
  71403. cubicTo (x, y, x2, y2, x3, y3);
  71404. }
  71405. else
  71406. {
  71407. // something's gone wrong with the element list!
  71408. jassertfalse
  71409. }
  71410. }
  71411. }
  71412. }
  71413. void Path::applyTransform (const AffineTransform& transform) throw()
  71414. {
  71415. size_t i = 0;
  71416. pathYMin = pathXMin = 0;
  71417. pathYMax = pathXMax = 0;
  71418. bool setMaxMin = false;
  71419. while (i < numElements)
  71420. {
  71421. const float type = data.elements [i++];
  71422. if (type == moveMarker)
  71423. {
  71424. transform.transformPoint (data.elements [i],
  71425. data.elements [i + 1]);
  71426. if (setMaxMin)
  71427. {
  71428. pathXMin = jmin (pathXMin, data.elements [i]);
  71429. pathXMax = jmax (pathXMax, data.elements [i]);
  71430. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71431. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71432. }
  71433. else
  71434. {
  71435. pathXMin = pathXMax = data.elements [i];
  71436. pathYMin = pathYMax = data.elements [i + 1];
  71437. setMaxMin = true;
  71438. }
  71439. i += 2;
  71440. }
  71441. else if (type == lineMarker)
  71442. {
  71443. transform.transformPoint (data.elements [i],
  71444. data.elements [i + 1]);
  71445. pathXMin = jmin (pathXMin, data.elements [i]);
  71446. pathXMax = jmax (pathXMax, data.elements [i]);
  71447. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71448. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71449. i += 2;
  71450. }
  71451. else if (type == quadMarker)
  71452. {
  71453. transform.transformPoint (data.elements [i],
  71454. data.elements [i + 1]);
  71455. transform.transformPoint (data.elements [i + 2],
  71456. data.elements [i + 3]);
  71457. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71458. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71459. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71460. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71461. i += 4;
  71462. }
  71463. else if (type == cubicMarker)
  71464. {
  71465. transform.transformPoint (data.elements [i],
  71466. data.elements [i + 1]);
  71467. transform.transformPoint (data.elements [i + 2],
  71468. data.elements [i + 3]);
  71469. transform.transformPoint (data.elements [i + 4],
  71470. data.elements [i + 5]);
  71471. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71472. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71473. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71474. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71475. i += 6;
  71476. }
  71477. }
  71478. }
  71479. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71480. const float w, const float h,
  71481. const bool preserveProportions,
  71482. const Justification& justification) const
  71483. {
  71484. Rectangle<float> bounds (getBounds());
  71485. if (preserveProportions)
  71486. {
  71487. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71488. return AffineTransform::identity;
  71489. float newW, newH;
  71490. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71491. if (srcRatio > h / w)
  71492. {
  71493. newW = h / srcRatio;
  71494. newH = h;
  71495. }
  71496. else
  71497. {
  71498. newW = w;
  71499. newH = w * srcRatio;
  71500. }
  71501. float newXCentre = x;
  71502. float newYCentre = y;
  71503. if (justification.testFlags (Justification::left))
  71504. newXCentre += newW * 0.5f;
  71505. else if (justification.testFlags (Justification::right))
  71506. newXCentre += w - newW * 0.5f;
  71507. else
  71508. newXCentre += w * 0.5f;
  71509. if (justification.testFlags (Justification::top))
  71510. newYCentre += newH * 0.5f;
  71511. else if (justification.testFlags (Justification::bottom))
  71512. newYCentre += h - newH * 0.5f;
  71513. else
  71514. newYCentre += h * 0.5f;
  71515. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71516. bounds.getHeight() * -0.5f - bounds.getY())
  71517. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71518. .translated (newXCentre, newYCentre);
  71519. }
  71520. else
  71521. {
  71522. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71523. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71524. .translated (x, y);
  71525. }
  71526. }
  71527. bool Path::contains (const float x, const float y, const float tolerence) const
  71528. {
  71529. if (x <= pathXMin || x >= pathXMax
  71530. || y <= pathYMin || y >= pathYMax)
  71531. return false;
  71532. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71533. int positiveCrossings = 0;
  71534. int negativeCrossings = 0;
  71535. while (i.next())
  71536. {
  71537. if ((i.y1 <= y && i.y2 > y)
  71538. || (i.y2 <= y && i.y1 > y))
  71539. {
  71540. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71541. if (intersectX <= x)
  71542. {
  71543. if (i.y1 < i.y2)
  71544. ++positiveCrossings;
  71545. else
  71546. ++negativeCrossings;
  71547. }
  71548. }
  71549. }
  71550. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71551. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71552. }
  71553. bool Path::intersectsLine (const float x1, const float y1,
  71554. const float x2, const float y2,
  71555. const float tolerence)
  71556. {
  71557. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71558. const Line line1 (x1, y1, x2, y2);
  71559. while (i.next())
  71560. {
  71561. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71562. float ix, iy;
  71563. if (line1.intersects (line2, ix, iy))
  71564. return true;
  71565. }
  71566. return false;
  71567. }
  71568. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  71569. {
  71570. if (cornerRadius <= 0.01f)
  71571. return *this;
  71572. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71573. size_t n = 0;
  71574. bool lastWasLine = false, firstWasLine = false;
  71575. Path p;
  71576. while (n < numElements)
  71577. {
  71578. const float type = data.elements [n++];
  71579. if (type == moveMarker)
  71580. {
  71581. indexOfPathStart = p.numElements;
  71582. indexOfPathStartThis = n - 1;
  71583. const float x = data.elements [n++];
  71584. const float y = data.elements [n++];
  71585. p.startNewSubPath (x, y);
  71586. lastWasLine = false;
  71587. firstWasLine = (data.elements [n] == lineMarker);
  71588. }
  71589. else if (type == lineMarker || type == closeSubPathMarker)
  71590. {
  71591. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71592. if (type == lineMarker)
  71593. {
  71594. endX = data.elements [n++];
  71595. endY = data.elements [n++];
  71596. if (n > 8)
  71597. {
  71598. startX = data.elements [n - 8];
  71599. startY = data.elements [n - 7];
  71600. joinX = data.elements [n - 5];
  71601. joinY = data.elements [n - 4];
  71602. }
  71603. }
  71604. else
  71605. {
  71606. endX = data.elements [indexOfPathStartThis + 1];
  71607. endY = data.elements [indexOfPathStartThis + 2];
  71608. if (n > 6)
  71609. {
  71610. startX = data.elements [n - 6];
  71611. startY = data.elements [n - 5];
  71612. joinX = data.elements [n - 3];
  71613. joinY = data.elements [n - 2];
  71614. }
  71615. }
  71616. if (lastWasLine)
  71617. {
  71618. const double len1 = juce_hypot (startX - joinX,
  71619. startY - joinY);
  71620. if (len1 > 0)
  71621. {
  71622. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71623. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71624. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71625. }
  71626. const double len2 = juce_hypot (endX - joinX,
  71627. endY - joinY);
  71628. if (len2 > 0)
  71629. {
  71630. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71631. p.quadraticTo (joinX, joinY,
  71632. (float) (joinX + (endX - joinX) * propNeeded),
  71633. (float) (joinY + (endY - joinY) * propNeeded));
  71634. }
  71635. p.lineTo (endX, endY);
  71636. }
  71637. else if (type == lineMarker)
  71638. {
  71639. p.lineTo (endX, endY);
  71640. lastWasLine = true;
  71641. }
  71642. if (type == closeSubPathMarker)
  71643. {
  71644. if (firstWasLine)
  71645. {
  71646. startX = data.elements [n - 3];
  71647. startY = data.elements [n - 2];
  71648. joinX = endX;
  71649. joinY = endY;
  71650. endX = data.elements [indexOfPathStartThis + 4];
  71651. endY = data.elements [indexOfPathStartThis + 5];
  71652. const double len1 = juce_hypot (startX - joinX,
  71653. startY - joinY);
  71654. if (len1 > 0)
  71655. {
  71656. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71657. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71658. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71659. }
  71660. const double len2 = juce_hypot (endX - joinX,
  71661. endY - joinY);
  71662. if (len2 > 0)
  71663. {
  71664. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71665. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71666. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71667. p.quadraticTo (joinX, joinY, endX, endY);
  71668. p.data.elements [indexOfPathStart + 1] = endX;
  71669. p.data.elements [indexOfPathStart + 2] = endY;
  71670. }
  71671. }
  71672. p.closeSubPath();
  71673. }
  71674. }
  71675. else if (type == quadMarker)
  71676. {
  71677. lastWasLine = false;
  71678. const float x1 = data.elements [n++];
  71679. const float y1 = data.elements [n++];
  71680. const float x2 = data.elements [n++];
  71681. const float y2 = data.elements [n++];
  71682. p.quadraticTo (x1, y1, x2, y2);
  71683. }
  71684. else if (type == cubicMarker)
  71685. {
  71686. lastWasLine = false;
  71687. const float x1 = data.elements [n++];
  71688. const float y1 = data.elements [n++];
  71689. const float x2 = data.elements [n++];
  71690. const float y2 = data.elements [n++];
  71691. const float x3 = data.elements [n++];
  71692. const float y3 = data.elements [n++];
  71693. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71694. }
  71695. }
  71696. return p;
  71697. }
  71698. void Path::loadPathFromStream (InputStream& source)
  71699. {
  71700. while (! source.isExhausted())
  71701. {
  71702. switch (source.readByte())
  71703. {
  71704. case 'm':
  71705. {
  71706. const float x = source.readFloat();
  71707. const float y = source.readFloat();
  71708. startNewSubPath (x, y);
  71709. break;
  71710. }
  71711. case 'l':
  71712. {
  71713. const float x = source.readFloat();
  71714. const float y = source.readFloat();
  71715. lineTo (x, y);
  71716. break;
  71717. }
  71718. case 'q':
  71719. {
  71720. const float x1 = source.readFloat();
  71721. const float y1 = source.readFloat();
  71722. const float x2 = source.readFloat();
  71723. const float y2 = source.readFloat();
  71724. quadraticTo (x1, y1, x2, y2);
  71725. break;
  71726. }
  71727. case 'b':
  71728. {
  71729. const float x1 = source.readFloat();
  71730. const float y1 = source.readFloat();
  71731. const float x2 = source.readFloat();
  71732. const float y2 = source.readFloat();
  71733. const float x3 = source.readFloat();
  71734. const float y3 = source.readFloat();
  71735. cubicTo (x1, y1, x2, y2, x3, y3);
  71736. break;
  71737. }
  71738. case 'c':
  71739. closeSubPath();
  71740. break;
  71741. case 'n':
  71742. useNonZeroWinding = true;
  71743. break;
  71744. case 'z':
  71745. useNonZeroWinding = false;
  71746. break;
  71747. case 'e':
  71748. return; // end of path marker
  71749. default:
  71750. jassertfalse // illegal char in the stream
  71751. break;
  71752. }
  71753. }
  71754. }
  71755. void Path::loadPathFromData (const void* const data, const int numberOfBytes)
  71756. {
  71757. MemoryInputStream in (data, numberOfBytes, false);
  71758. loadPathFromStream (in);
  71759. }
  71760. void Path::writePathToStream (OutputStream& dest) const
  71761. {
  71762. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  71763. size_t i = 0;
  71764. while (i < numElements)
  71765. {
  71766. const float type = data.elements [i++];
  71767. if (type == moveMarker)
  71768. {
  71769. dest.writeByte ('m');
  71770. dest.writeFloat (data.elements [i++]);
  71771. dest.writeFloat (data.elements [i++]);
  71772. }
  71773. else if (type == lineMarker)
  71774. {
  71775. dest.writeByte ('l');
  71776. dest.writeFloat (data.elements [i++]);
  71777. dest.writeFloat (data.elements [i++]);
  71778. }
  71779. else if (type == quadMarker)
  71780. {
  71781. dest.writeByte ('q');
  71782. dest.writeFloat (data.elements [i++]);
  71783. dest.writeFloat (data.elements [i++]);
  71784. dest.writeFloat (data.elements [i++]);
  71785. dest.writeFloat (data.elements [i++]);
  71786. }
  71787. else if (type == cubicMarker)
  71788. {
  71789. dest.writeByte ('b');
  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. dest.writeFloat (data.elements [i++]);
  71795. dest.writeFloat (data.elements [i++]);
  71796. }
  71797. else if (type == closeSubPathMarker)
  71798. {
  71799. dest.writeByte ('c');
  71800. }
  71801. }
  71802. dest.writeByte ('e'); // marks the end-of-path
  71803. }
  71804. const String Path::toString() const
  71805. {
  71806. MemoryOutputStream s (2048, 2048);
  71807. if (! useNonZeroWinding)
  71808. s << 'a';
  71809. size_t i = 0;
  71810. float lastMarker = 0.0f;
  71811. while (i < numElements)
  71812. {
  71813. const float marker = data.elements [i++];
  71814. char markerChar = 0;
  71815. int numCoords = 0;
  71816. if (marker == moveMarker)
  71817. {
  71818. markerChar = 'm';
  71819. numCoords = 2;
  71820. }
  71821. else if (marker == lineMarker)
  71822. {
  71823. markerChar = 'l';
  71824. numCoords = 2;
  71825. }
  71826. else if (marker == quadMarker)
  71827. {
  71828. markerChar = 'q';
  71829. numCoords = 4;
  71830. }
  71831. else if (marker == cubicMarker)
  71832. {
  71833. markerChar = 'c';
  71834. numCoords = 6;
  71835. }
  71836. else
  71837. {
  71838. jassert (marker == closeSubPathMarker);
  71839. markerChar = 'z';
  71840. }
  71841. if (marker != lastMarker)
  71842. {
  71843. if (s.getDataSize() != 0)
  71844. s << ' ';
  71845. s << markerChar;
  71846. lastMarker = marker;
  71847. }
  71848. while (--numCoords >= 0 && i < numElements)
  71849. {
  71850. String coord (data.elements [i++], 3);
  71851. while (coord.endsWithChar ('0') && coord != "0")
  71852. coord = coord.dropLastCharacters (1);
  71853. if (coord.endsWithChar ('.'))
  71854. coord = coord.dropLastCharacters (1);
  71855. if (s.getDataSize() != 0)
  71856. s << ' ';
  71857. s << coord;
  71858. }
  71859. }
  71860. return s.toUTF8();
  71861. }
  71862. void Path::restoreFromString (const String& stringVersion)
  71863. {
  71864. clear();
  71865. setUsingNonZeroWinding (true);
  71866. const juce_wchar* t = stringVersion;
  71867. juce_wchar marker = 'm';
  71868. int numValues = 2;
  71869. float values [6];
  71870. while (*t != 0)
  71871. {
  71872. const String token (PathHelpers::nextToken (t));
  71873. const juce_wchar firstChar = token[0];
  71874. int startNum = 0;
  71875. if (firstChar == 'm' || firstChar == 'l')
  71876. {
  71877. marker = firstChar;
  71878. numValues = 2;
  71879. }
  71880. else if (firstChar == 'q')
  71881. {
  71882. marker = firstChar;
  71883. numValues = 4;
  71884. }
  71885. else if (firstChar == 'c')
  71886. {
  71887. marker = firstChar;
  71888. numValues = 6;
  71889. }
  71890. else if (firstChar == 'z')
  71891. {
  71892. marker = firstChar;
  71893. numValues = 0;
  71894. }
  71895. else if (firstChar == 'a')
  71896. {
  71897. setUsingNonZeroWinding (false);
  71898. continue;
  71899. }
  71900. else
  71901. {
  71902. ++startNum;
  71903. values [0] = token.getFloatValue();
  71904. }
  71905. for (int i = startNum; i < numValues; ++i)
  71906. values [i] = PathHelpers::nextToken (t).getFloatValue();
  71907. switch (marker)
  71908. {
  71909. case 'm':
  71910. startNewSubPath (values[0], values[1]);
  71911. break;
  71912. case 'l':
  71913. lineTo (values[0], values[1]);
  71914. break;
  71915. case 'q':
  71916. quadraticTo (values[0], values[1],
  71917. values[2], values[3]);
  71918. break;
  71919. case 'c':
  71920. cubicTo (values[0], values[1],
  71921. values[2], values[3],
  71922. values[4], values[5]);
  71923. break;
  71924. case 'z':
  71925. closeSubPath();
  71926. break;
  71927. default:
  71928. jassertfalse // illegal string format?
  71929. break;
  71930. }
  71931. }
  71932. }
  71933. Path::Iterator::Iterator (const Path& path_)
  71934. : path (path_),
  71935. index (0)
  71936. {
  71937. }
  71938. Path::Iterator::~Iterator()
  71939. {
  71940. }
  71941. bool Path::Iterator::next()
  71942. {
  71943. const float* const elements = path.data.elements;
  71944. if (index < path.numElements)
  71945. {
  71946. const float type = elements [index++];
  71947. if (type == moveMarker)
  71948. {
  71949. elementType = startNewSubPath;
  71950. x1 = elements [index++];
  71951. y1 = elements [index++];
  71952. }
  71953. else if (type == lineMarker)
  71954. {
  71955. elementType = lineTo;
  71956. x1 = elements [index++];
  71957. y1 = elements [index++];
  71958. }
  71959. else if (type == quadMarker)
  71960. {
  71961. elementType = quadraticTo;
  71962. x1 = elements [index++];
  71963. y1 = elements [index++];
  71964. x2 = elements [index++];
  71965. y2 = elements [index++];
  71966. }
  71967. else if (type == cubicMarker)
  71968. {
  71969. elementType = cubicTo;
  71970. x1 = elements [index++];
  71971. y1 = elements [index++];
  71972. x2 = elements [index++];
  71973. y2 = elements [index++];
  71974. x3 = elements [index++];
  71975. y3 = elements [index++];
  71976. }
  71977. else if (type == closeSubPathMarker)
  71978. {
  71979. elementType = closePath;
  71980. }
  71981. return true;
  71982. }
  71983. return false;
  71984. }
  71985. END_JUCE_NAMESPACE
  71986. /*** End of inlined file: juce_Path.cpp ***/
  71987. /*** Start of inlined file: juce_PathIterator.cpp ***/
  71988. BEGIN_JUCE_NAMESPACE
  71989. #if JUCE_MSVC
  71990. #pragma optimize ("t", on)
  71991. #endif
  71992. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  71993. const AffineTransform& transform_,
  71994. float tolerence_)
  71995. : x2 (0),
  71996. y2 (0),
  71997. closesSubPath (false),
  71998. subPathIndex (-1),
  71999. path (path_),
  72000. transform (transform_),
  72001. points (path_.data.elements),
  72002. tolerence (tolerence_ * tolerence_),
  72003. subPathCloseX (0),
  72004. subPathCloseY (0),
  72005. isIdentityTransform (transform_.isIdentity()),
  72006. stackBase (32),
  72007. index (0),
  72008. stackSize (32)
  72009. {
  72010. stackPos = stackBase;
  72011. }
  72012. PathFlatteningIterator::~PathFlatteningIterator()
  72013. {
  72014. }
  72015. bool PathFlatteningIterator::next()
  72016. {
  72017. x1 = x2;
  72018. y1 = y2;
  72019. float x3 = 0;
  72020. float y3 = 0;
  72021. float x4 = 0;
  72022. float y4 = 0;
  72023. float type;
  72024. for (;;)
  72025. {
  72026. if (stackPos == stackBase)
  72027. {
  72028. if (index >= path.numElements)
  72029. {
  72030. return false;
  72031. }
  72032. else
  72033. {
  72034. type = points [index++];
  72035. if (type != Path::closeSubPathMarker)
  72036. {
  72037. x2 = points [index++];
  72038. y2 = points [index++];
  72039. if (! isIdentityTransform)
  72040. transform.transformPoint (x2, y2);
  72041. if (type == Path::quadMarker)
  72042. {
  72043. x3 = points [index++];
  72044. y3 = points [index++];
  72045. if (! isIdentityTransform)
  72046. transform.transformPoint (x3, y3);
  72047. }
  72048. else if (type == Path::cubicMarker)
  72049. {
  72050. x3 = points [index++];
  72051. y3 = points [index++];
  72052. x4 = points [index++];
  72053. y4 = points [index++];
  72054. if (! isIdentityTransform)
  72055. {
  72056. transform.transformPoint (x3, y3);
  72057. transform.transformPoint (x4, y4);
  72058. }
  72059. }
  72060. }
  72061. }
  72062. }
  72063. else
  72064. {
  72065. type = *--stackPos;
  72066. if (type != Path::closeSubPathMarker)
  72067. {
  72068. x2 = *--stackPos;
  72069. y2 = *--stackPos;
  72070. if (type == Path::quadMarker)
  72071. {
  72072. x3 = *--stackPos;
  72073. y3 = *--stackPos;
  72074. }
  72075. else if (type == Path::cubicMarker)
  72076. {
  72077. x3 = *--stackPos;
  72078. y3 = *--stackPos;
  72079. x4 = *--stackPos;
  72080. y4 = *--stackPos;
  72081. }
  72082. }
  72083. }
  72084. if (type == Path::lineMarker)
  72085. {
  72086. ++subPathIndex;
  72087. closesSubPath = (stackPos == stackBase)
  72088. && (index < path.numElements)
  72089. && (points [index] == Path::closeSubPathMarker)
  72090. && x2 == subPathCloseX
  72091. && y2 == subPathCloseY;
  72092. return true;
  72093. }
  72094. else if (type == Path::quadMarker)
  72095. {
  72096. const size_t offset = (size_t) (stackPos - stackBase);
  72097. if (offset >= stackSize - 10)
  72098. {
  72099. stackSize <<= 1;
  72100. stackBase.realloc (stackSize);
  72101. stackPos = stackBase + offset;
  72102. }
  72103. const float dx1 = x1 - x2;
  72104. const float dy1 = y1 - y2;
  72105. const float dx2 = x2 - x3;
  72106. const float dy2 = y2 - y3;
  72107. const float m1x = (x1 + x2) * 0.5f;
  72108. const float m1y = (y1 + y2) * 0.5f;
  72109. const float m2x = (x2 + x3) * 0.5f;
  72110. const float m2y = (y2 + y3) * 0.5f;
  72111. const float m3x = (m1x + m2x) * 0.5f;
  72112. const float m3y = (m1y + m2y) * 0.5f;
  72113. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72114. {
  72115. *stackPos++ = y3;
  72116. *stackPos++ = x3;
  72117. *stackPos++ = m2y;
  72118. *stackPos++ = m2x;
  72119. *stackPos++ = Path::quadMarker;
  72120. *stackPos++ = m3y;
  72121. *stackPos++ = m3x;
  72122. *stackPos++ = m1y;
  72123. *stackPos++ = m1x;
  72124. *stackPos++ = Path::quadMarker;
  72125. }
  72126. else
  72127. {
  72128. *stackPos++ = y3;
  72129. *stackPos++ = x3;
  72130. *stackPos++ = Path::lineMarker;
  72131. *stackPos++ = m3y;
  72132. *stackPos++ = m3x;
  72133. *stackPos++ = Path::lineMarker;
  72134. }
  72135. jassert (stackPos < stackBase + stackSize);
  72136. }
  72137. else if (type == Path::cubicMarker)
  72138. {
  72139. const size_t offset = (size_t) (stackPos - stackBase);
  72140. if (offset >= stackSize - 16)
  72141. {
  72142. stackSize <<= 1;
  72143. stackBase.realloc (stackSize);
  72144. stackPos = stackBase + offset;
  72145. }
  72146. const float dx1 = x1 - x2;
  72147. const float dy1 = y1 - y2;
  72148. const float dx2 = x2 - x3;
  72149. const float dy2 = y2 - y3;
  72150. const float dx3 = x3 - x4;
  72151. const float dy3 = y3 - y4;
  72152. const float m1x = (x1 + x2) * 0.5f;
  72153. const float m1y = (y1 + y2) * 0.5f;
  72154. const float m2x = (x3 + x2) * 0.5f;
  72155. const float m2y = (y3 + y2) * 0.5f;
  72156. const float m3x = (x3 + x4) * 0.5f;
  72157. const float m3y = (y3 + y4) * 0.5f;
  72158. const float m4x = (m1x + m2x) * 0.5f;
  72159. const float m4y = (m1y + m2y) * 0.5f;
  72160. const float m5x = (m3x + m2x) * 0.5f;
  72161. const float m5y = (m3y + m2y) * 0.5f;
  72162. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72163. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72164. {
  72165. *stackPos++ = y4;
  72166. *stackPos++ = x4;
  72167. *stackPos++ = m3y;
  72168. *stackPos++ = m3x;
  72169. *stackPos++ = m5y;
  72170. *stackPos++ = m5x;
  72171. *stackPos++ = Path::cubicMarker;
  72172. *stackPos++ = (m4y + m5y) * 0.5f;
  72173. *stackPos++ = (m4x + m5x) * 0.5f;
  72174. *stackPos++ = m4y;
  72175. *stackPos++ = m4x;
  72176. *stackPos++ = m1y;
  72177. *stackPos++ = m1x;
  72178. *stackPos++ = Path::cubicMarker;
  72179. }
  72180. else
  72181. {
  72182. *stackPos++ = y4;
  72183. *stackPos++ = x4;
  72184. *stackPos++ = Path::lineMarker;
  72185. *stackPos++ = m5y;
  72186. *stackPos++ = m5x;
  72187. *stackPos++ = Path::lineMarker;
  72188. *stackPos++ = m4y;
  72189. *stackPos++ = m4x;
  72190. *stackPos++ = Path::lineMarker;
  72191. }
  72192. }
  72193. else if (type == Path::closeSubPathMarker)
  72194. {
  72195. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72196. {
  72197. x1 = x2;
  72198. y1 = y2;
  72199. x2 = subPathCloseX;
  72200. y2 = subPathCloseY;
  72201. closesSubPath = true;
  72202. return true;
  72203. }
  72204. }
  72205. else
  72206. {
  72207. jassert (type == Path::moveMarker);
  72208. subPathIndex = -1;
  72209. subPathCloseX = x1 = x2;
  72210. subPathCloseY = y1 = y2;
  72211. }
  72212. }
  72213. }
  72214. END_JUCE_NAMESPACE
  72215. /*** End of inlined file: juce_PathIterator.cpp ***/
  72216. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72217. BEGIN_JUCE_NAMESPACE
  72218. PathStrokeType::PathStrokeType (const float strokeThickness,
  72219. const JointStyle jointStyle_,
  72220. const EndCapStyle endStyle_) throw()
  72221. : thickness (strokeThickness),
  72222. jointStyle (jointStyle_),
  72223. endStyle (endStyle_)
  72224. {
  72225. }
  72226. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72227. : thickness (other.thickness),
  72228. jointStyle (other.jointStyle),
  72229. endStyle (other.endStyle)
  72230. {
  72231. }
  72232. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72233. {
  72234. thickness = other.thickness;
  72235. jointStyle = other.jointStyle;
  72236. endStyle = other.endStyle;
  72237. return *this;
  72238. }
  72239. PathStrokeType::~PathStrokeType() throw()
  72240. {
  72241. }
  72242. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72243. {
  72244. return thickness == other.thickness
  72245. && jointStyle == other.jointStyle
  72246. && endStyle == other.endStyle;
  72247. }
  72248. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72249. {
  72250. return ! operator== (other);
  72251. }
  72252. static bool lineIntersection (const float x1, const float y1,
  72253. const float x2, const float y2,
  72254. const float x3, const float y3,
  72255. const float x4, const float y4,
  72256. float& intersectionX,
  72257. float& intersectionY,
  72258. float& distanceBeyondLine1EndSquared) throw()
  72259. {
  72260. if (x2 != x3 || y2 != y3)
  72261. {
  72262. const float dx1 = x2 - x1;
  72263. const float dy1 = y2 - y1;
  72264. const float dx2 = x4 - x3;
  72265. const float dy2 = y4 - y3;
  72266. const float divisor = dx1 * dy2 - dx2 * dy1;
  72267. if (divisor == 0)
  72268. {
  72269. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72270. {
  72271. if (dy1 == 0 && dy2 != 0)
  72272. {
  72273. const float along = (y1 - y3) / dy2;
  72274. intersectionX = x3 + along * dx2;
  72275. intersectionY = y1;
  72276. distanceBeyondLine1EndSquared = intersectionX - x2;
  72277. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72278. if ((x2 > x1) == (intersectionX < x2))
  72279. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72280. return along >= 0 && along <= 1.0f;
  72281. }
  72282. else if (dy2 == 0 && dy1 != 0)
  72283. {
  72284. const float along = (y3 - y1) / dy1;
  72285. intersectionX = x1 + along * dx1;
  72286. intersectionY = y3;
  72287. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72288. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72289. if (along < 1.0f)
  72290. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72291. return along >= 0 && along <= 1.0f;
  72292. }
  72293. else if (dx1 == 0 && dx2 != 0)
  72294. {
  72295. const float along = (x1 - x3) / dx2;
  72296. intersectionX = x1;
  72297. intersectionY = y3 + along * dy2;
  72298. distanceBeyondLine1EndSquared = intersectionY - y2;
  72299. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72300. if ((y2 > y1) == (intersectionY < y2))
  72301. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72302. return along >= 0 && along <= 1.0f;
  72303. }
  72304. else if (dx2 == 0 && dx1 != 0)
  72305. {
  72306. const float along = (x3 - x1) / dx1;
  72307. intersectionX = x3;
  72308. intersectionY = y1 + along * dy1;
  72309. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72310. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72311. if (along < 1.0f)
  72312. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72313. return along >= 0 && along <= 1.0f;
  72314. }
  72315. }
  72316. intersectionX = 0.5f * (x2 + x3);
  72317. intersectionY = 0.5f * (y2 + y3);
  72318. distanceBeyondLine1EndSquared = 0.0f;
  72319. return false;
  72320. }
  72321. else
  72322. {
  72323. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72324. intersectionX = x1 + along1 * dx1;
  72325. intersectionY = y1 + along1 * dy1;
  72326. if (along1 >= 0 && along1 <= 1.0f)
  72327. {
  72328. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72329. if (along2 >= 0 && along2 <= divisor)
  72330. {
  72331. distanceBeyondLine1EndSquared = 0.0f;
  72332. return true;
  72333. }
  72334. }
  72335. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72336. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72337. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72338. if (along1 < 1.0f)
  72339. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72340. return false;
  72341. }
  72342. }
  72343. intersectionX = x2;
  72344. intersectionY = y2;
  72345. distanceBeyondLine1EndSquared = 0.0f;
  72346. return true;
  72347. }
  72348. namespace PathFunctions
  72349. {
  72350. // part of stroke drawing stuff
  72351. static void addEdgeAndJoint (Path& destPath,
  72352. const PathStrokeType::JointStyle style,
  72353. const float maxMiterExtensionSquared, const float width,
  72354. const float x1, const float y1,
  72355. const float x2, const float y2,
  72356. const float x3, const float y3,
  72357. const float x4, const float y4,
  72358. const float midX, const float midY)
  72359. {
  72360. if (style == PathStrokeType::beveled
  72361. || (x3 == x4 && y3 == y4)
  72362. || (x1 == x2 && y1 == y2))
  72363. {
  72364. destPath.lineTo (x2, y2);
  72365. destPath.lineTo (x3, y3);
  72366. }
  72367. else
  72368. {
  72369. float jx, jy, distanceBeyondLine1EndSquared;
  72370. // if they intersect, use this point..
  72371. if (lineIntersection (x1, y1, x2, y2,
  72372. x3, y3, x4, y4,
  72373. jx, jy, distanceBeyondLine1EndSquared))
  72374. {
  72375. destPath.lineTo (jx, jy);
  72376. }
  72377. else
  72378. {
  72379. if (style == PathStrokeType::mitered)
  72380. {
  72381. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72382. && distanceBeyondLine1EndSquared > 0.0f)
  72383. {
  72384. destPath.lineTo (jx, jy);
  72385. }
  72386. else
  72387. {
  72388. // the end sticks out too far, so just use a blunt joint
  72389. destPath.lineTo (x2, y2);
  72390. destPath.lineTo (x3, y3);
  72391. }
  72392. }
  72393. else
  72394. {
  72395. // curved joints
  72396. float angle1 = atan2f (x2 - midX, y2 - midY);
  72397. float angle2 = atan2f (x3 - midX, y3 - midY);
  72398. const float angleIncrement = 0.1f;
  72399. destPath.lineTo (x2, y2);
  72400. if (fabs (angle1 - angle2) > angleIncrement)
  72401. {
  72402. if (angle2 > angle1 + float_Pi
  72403. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72404. {
  72405. if (angle2 > angle1)
  72406. angle2 -= float_Pi * 2.0f;
  72407. jassert (angle1 <= angle2 + float_Pi);
  72408. angle1 -= angleIncrement;
  72409. while (angle1 > angle2)
  72410. {
  72411. destPath.lineTo (midX + width * sinf (angle1),
  72412. midY + width * cosf (angle1));
  72413. angle1 -= angleIncrement;
  72414. }
  72415. }
  72416. else
  72417. {
  72418. if (angle1 > angle2)
  72419. angle1 -= float_Pi * 2.0f;
  72420. jassert (angle1 >= angle2 - float_Pi);
  72421. angle1 += angleIncrement;
  72422. while (angle1 < angle2)
  72423. {
  72424. destPath.lineTo (midX + width * sinf (angle1),
  72425. midY + width * cosf (angle1));
  72426. angle1 += angleIncrement;
  72427. }
  72428. }
  72429. }
  72430. destPath.lineTo (x3, y3);
  72431. }
  72432. }
  72433. }
  72434. }
  72435. static void addLineEnd (Path& destPath,
  72436. const PathStrokeType::EndCapStyle style,
  72437. const float x1, const float y1,
  72438. const float x2, const float y2,
  72439. const float width)
  72440. {
  72441. if (style == PathStrokeType::butt)
  72442. {
  72443. destPath.lineTo (x2, y2);
  72444. }
  72445. else
  72446. {
  72447. float offx1, offy1, offx2, offy2;
  72448. float dx = x2 - x1;
  72449. float dy = y2 - y1;
  72450. const float len = juce_hypotf (dx, dy);
  72451. if (len == 0)
  72452. {
  72453. offx1 = offx2 = x1;
  72454. offy1 = offy2 = y1;
  72455. }
  72456. else
  72457. {
  72458. const float offset = width / len;
  72459. dx *= offset;
  72460. dy *= offset;
  72461. offx1 = x1 + dy;
  72462. offy1 = y1 - dx;
  72463. offx2 = x2 + dy;
  72464. offy2 = y2 - dx;
  72465. }
  72466. if (style == PathStrokeType::square)
  72467. {
  72468. // sqaure ends
  72469. destPath.lineTo (offx1, offy1);
  72470. destPath.lineTo (offx2, offy2);
  72471. destPath.lineTo (x2, y2);
  72472. }
  72473. else
  72474. {
  72475. // rounded ends
  72476. const float midx = (offx1 + offx2) * 0.5f;
  72477. const float midy = (offy1 + offy2) * 0.5f;
  72478. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72479. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72480. midx, midy);
  72481. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72482. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72483. x2, y2);
  72484. }
  72485. }
  72486. }
  72487. struct LineSection
  72488. {
  72489. LineSection() {}
  72490. LineSection (int) {}
  72491. float x1, y1, x2, y2; // original line
  72492. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72493. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72494. };
  72495. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72496. const bool isClosed,
  72497. const float width, const float maxMiterExtensionSquared,
  72498. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72499. {
  72500. jassert (subPath.size() > 0);
  72501. const LineSection& firstLine = subPath.getReference (0);
  72502. float lastX1 = firstLine.lx1;
  72503. float lastY1 = firstLine.ly1;
  72504. float lastX2 = firstLine.lx2;
  72505. float lastY2 = firstLine.ly2;
  72506. if (isClosed)
  72507. {
  72508. destPath.startNewSubPath (lastX1, lastY1);
  72509. }
  72510. else
  72511. {
  72512. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72513. addLineEnd (destPath, endStyle,
  72514. firstLine.rx2, firstLine.ry2,
  72515. lastX1, lastY1,
  72516. width);
  72517. }
  72518. int i;
  72519. for (i = 1; i < subPath.size(); ++i)
  72520. {
  72521. const LineSection& l = subPath.getReference (i);
  72522. addEdgeAndJoint (destPath, jointStyle,
  72523. maxMiterExtensionSquared, width,
  72524. lastX1, lastY1, lastX2, lastY2,
  72525. l.lx1, l.ly1, l.lx2, l.ly2,
  72526. l.x1, l.y1);
  72527. lastX1 = l.lx1;
  72528. lastY1 = l.ly1;
  72529. lastX2 = l.lx2;
  72530. lastY2 = l.ly2;
  72531. }
  72532. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72533. if (isClosed)
  72534. {
  72535. const LineSection& l = subPath.getReference (0);
  72536. addEdgeAndJoint (destPath, jointStyle,
  72537. maxMiterExtensionSquared, width,
  72538. lastX1, lastY1, lastX2, lastY2,
  72539. l.lx1, l.ly1, l.lx2, l.ly2,
  72540. l.x1, l.y1);
  72541. destPath.closeSubPath();
  72542. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72543. }
  72544. else
  72545. {
  72546. destPath.lineTo (lastX2, lastY2);
  72547. addLineEnd (destPath, endStyle,
  72548. lastX2, lastY2,
  72549. lastLine.rx1, lastLine.ry1,
  72550. width);
  72551. }
  72552. lastX1 = lastLine.rx1;
  72553. lastY1 = lastLine.ry1;
  72554. lastX2 = lastLine.rx2;
  72555. lastY2 = lastLine.ry2;
  72556. for (i = subPath.size() - 1; --i >= 0;)
  72557. {
  72558. const LineSection& l = subPath.getReference (i);
  72559. addEdgeAndJoint (destPath, jointStyle,
  72560. maxMiterExtensionSquared, width,
  72561. lastX1, lastY1, lastX2, lastY2,
  72562. l.rx1, l.ry1, l.rx2, l.ry2,
  72563. l.x2, l.y2);
  72564. lastX1 = l.rx1;
  72565. lastY1 = l.ry1;
  72566. lastX2 = l.rx2;
  72567. lastY2 = l.ry2;
  72568. }
  72569. if (isClosed)
  72570. {
  72571. addEdgeAndJoint (destPath, jointStyle,
  72572. maxMiterExtensionSquared, width,
  72573. lastX1, lastY1, lastX2, lastY2,
  72574. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72575. lastLine.x2, lastLine.y2);
  72576. }
  72577. else
  72578. {
  72579. // do the last line
  72580. destPath.lineTo (lastX2, lastY2);
  72581. }
  72582. destPath.closeSubPath();
  72583. }
  72584. }
  72585. void PathStrokeType::createStrokedPath (Path& destPath,
  72586. const Path& source,
  72587. const AffineTransform& transform,
  72588. const float extraAccuracy) const
  72589. {
  72590. if (thickness <= 0)
  72591. {
  72592. destPath.clear();
  72593. return;
  72594. }
  72595. const Path* sourcePath = &source;
  72596. Path temp;
  72597. if (sourcePath == &destPath)
  72598. {
  72599. destPath.swapWithPath (temp);
  72600. sourcePath = &temp;
  72601. }
  72602. else
  72603. {
  72604. destPath.clear();
  72605. }
  72606. destPath.setUsingNonZeroWinding (true);
  72607. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72608. const float width = 0.5f * thickness;
  72609. // Iterate the path, creating a list of the
  72610. // left/right-hand lines along either side of it...
  72611. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72612. using namespace PathFunctions;
  72613. Array <LineSection> subPath;
  72614. LineSection l;
  72615. l.x1 = 0;
  72616. l.y1 = 0;
  72617. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72618. while (it.next())
  72619. {
  72620. if (it.subPathIndex == 0)
  72621. {
  72622. if (subPath.size() > 0)
  72623. {
  72624. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72625. subPath.clearQuick();
  72626. }
  72627. l.x1 = it.x1;
  72628. l.y1 = it.y1;
  72629. }
  72630. l.x2 = it.x2;
  72631. l.y2 = it.y2;
  72632. float dx = l.x2 - l.x1;
  72633. float dy = l.y2 - l.y1;
  72634. const float hypotSquared = dx*dx + dy*dy;
  72635. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72636. {
  72637. const float len = sqrtf (hypotSquared);
  72638. if (len == 0)
  72639. {
  72640. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72641. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72642. }
  72643. else
  72644. {
  72645. const float offset = width / len;
  72646. dx *= offset;
  72647. dy *= offset;
  72648. l.rx2 = l.x1 - dy;
  72649. l.ry2 = l.y1 + dx;
  72650. l.lx1 = l.x1 + dy;
  72651. l.ly1 = l.y1 - dx;
  72652. l.lx2 = l.x2 + dy;
  72653. l.ly2 = l.y2 - dx;
  72654. l.rx1 = l.x2 - dy;
  72655. l.ry1 = l.y2 + dx;
  72656. }
  72657. subPath.add (l);
  72658. if (it.closesSubPath)
  72659. {
  72660. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72661. subPath.clearQuick();
  72662. }
  72663. else
  72664. {
  72665. l.x1 = it.x2;
  72666. l.y1 = it.y2;
  72667. }
  72668. }
  72669. }
  72670. if (subPath.size() > 0)
  72671. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72672. }
  72673. void PathStrokeType::createDashedStroke (Path& destPath,
  72674. const Path& sourcePath,
  72675. const float* dashLengths,
  72676. int numDashLengths,
  72677. const AffineTransform& transform,
  72678. const float extraAccuracy) const
  72679. {
  72680. if (thickness <= 0)
  72681. return;
  72682. // this should really be an even number..
  72683. jassert ((numDashLengths & 1) == 0);
  72684. Path newDestPath;
  72685. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72686. bool first = true;
  72687. int dashNum = 0;
  72688. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72689. float dx = 0.0f, dy = 0.0f;
  72690. for (;;)
  72691. {
  72692. const bool isSolid = ((dashNum & 1) == 0);
  72693. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72694. jassert (dashLen > 0); // must be a positive increment!
  72695. if (dashLen <= 0)
  72696. break;
  72697. pos += dashLen;
  72698. while (pos > lineEndPos)
  72699. {
  72700. if (! it.next())
  72701. {
  72702. if (isSolid && ! first)
  72703. newDestPath.lineTo (it.x2, it.y2);
  72704. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72705. return;
  72706. }
  72707. if (isSolid && ! first)
  72708. newDestPath.lineTo (it.x1, it.y1);
  72709. else
  72710. newDestPath.startNewSubPath (it.x1, it.y1);
  72711. dx = it.x2 - it.x1;
  72712. dy = it.y2 - it.y1;
  72713. lineLen = juce_hypotf (dx, dy);
  72714. lineEndPos += lineLen;
  72715. first = it.closesSubPath;
  72716. }
  72717. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72718. if (isSolid)
  72719. newDestPath.lineTo (it.x1 + dx * alpha,
  72720. it.y1 + dy * alpha);
  72721. else
  72722. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72723. it.y1 + dy * alpha);
  72724. }
  72725. }
  72726. END_JUCE_NAMESPACE
  72727. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72728. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72729. BEGIN_JUCE_NAMESPACE
  72730. PositionedRectangle::PositionedRectangle() throw()
  72731. : x (0.0),
  72732. y (0.0),
  72733. w (0.0),
  72734. h (0.0),
  72735. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72736. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72737. wMode (absoluteSize),
  72738. hMode (absoluteSize)
  72739. {
  72740. }
  72741. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72742. : x (other.x),
  72743. y (other.y),
  72744. w (other.w),
  72745. h (other.h),
  72746. xMode (other.xMode),
  72747. yMode (other.yMode),
  72748. wMode (other.wMode),
  72749. hMode (other.hMode)
  72750. {
  72751. }
  72752. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72753. {
  72754. x = other.x;
  72755. y = other.y;
  72756. w = other.w;
  72757. h = other.h;
  72758. xMode = other.xMode;
  72759. yMode = other.yMode;
  72760. wMode = other.wMode;
  72761. hMode = other.hMode;
  72762. return *this;
  72763. }
  72764. PositionedRectangle::~PositionedRectangle() throw()
  72765. {
  72766. }
  72767. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72768. {
  72769. return x == other.x
  72770. && y == other.y
  72771. && w == other.w
  72772. && h == other.h
  72773. && xMode == other.xMode
  72774. && yMode == other.yMode
  72775. && wMode == other.wMode
  72776. && hMode == other.hMode;
  72777. }
  72778. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72779. {
  72780. return ! operator== (other);
  72781. }
  72782. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72783. {
  72784. StringArray tokens;
  72785. tokens.addTokens (stringVersion, false);
  72786. decodePosString (tokens [0], xMode, x);
  72787. decodePosString (tokens [1], yMode, y);
  72788. decodeSizeString (tokens [2], wMode, w);
  72789. decodeSizeString (tokens [3], hMode, h);
  72790. }
  72791. const String PositionedRectangle::toString() const throw()
  72792. {
  72793. String s;
  72794. s.preallocateStorage (12);
  72795. addPosDescription (s, xMode, x);
  72796. s << ' ';
  72797. addPosDescription (s, yMode, y);
  72798. s << ' ';
  72799. addSizeDescription (s, wMode, w);
  72800. s << ' ';
  72801. addSizeDescription (s, hMode, h);
  72802. return s;
  72803. }
  72804. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72805. {
  72806. jassert (! target.isEmpty());
  72807. double x_, y_, w_, h_;
  72808. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72809. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72810. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72811. roundToInt (w_), roundToInt (h_));
  72812. }
  72813. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72814. double& x_, double& y_,
  72815. double& w_, double& h_) const throw()
  72816. {
  72817. jassert (! target.isEmpty());
  72818. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72819. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72820. }
  72821. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72822. {
  72823. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72824. }
  72825. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72826. const Rectangle<int>& target) throw()
  72827. {
  72828. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72829. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72830. }
  72831. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72832. const double newW, const double newH,
  72833. const Rectangle<int>& target) throw()
  72834. {
  72835. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72836. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72837. }
  72838. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72839. {
  72840. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72841. updateFrom (comp.getBounds(), Rectangle<int>());
  72842. else
  72843. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72844. }
  72845. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72846. {
  72847. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72848. }
  72849. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72850. {
  72851. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72852. | absoluteFromParentBottomRight
  72853. | absoluteFromParentCentre
  72854. | proportionOfParentSize));
  72855. }
  72856. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72857. {
  72858. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72859. }
  72860. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72861. {
  72862. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72863. | absoluteFromParentBottomRight
  72864. | absoluteFromParentCentre
  72865. | proportionOfParentSize));
  72866. }
  72867. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72868. {
  72869. return (SizeMode) wMode;
  72870. }
  72871. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72872. {
  72873. return (SizeMode) hMode;
  72874. }
  72875. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72876. const PositionMode xMode_,
  72877. const AnchorPoint yAnchor,
  72878. const PositionMode yMode_,
  72879. const SizeMode widthMode,
  72880. const SizeMode heightMode,
  72881. const Rectangle<int>& target) throw()
  72882. {
  72883. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72884. {
  72885. double tx, tw;
  72886. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72887. xMode = (uint8) (xAnchor | xMode_);
  72888. wMode = (uint8) widthMode;
  72889. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72890. }
  72891. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72892. {
  72893. double ty, th;
  72894. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72895. yMode = (uint8) (yAnchor | yMode_);
  72896. hMode = (uint8) heightMode;
  72897. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  72898. }
  72899. }
  72900. bool PositionedRectangle::isPositionAbsolute() const throw()
  72901. {
  72902. return xMode == absoluteFromParentTopLeft
  72903. && yMode == absoluteFromParentTopLeft
  72904. && wMode == absoluteSize
  72905. && hMode == absoluteSize;
  72906. }
  72907. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  72908. {
  72909. if ((mode & proportionOfParentSize) != 0)
  72910. {
  72911. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72912. }
  72913. else
  72914. {
  72915. s << (roundToInt (value * 100.0) / 100.0);
  72916. if ((mode & absoluteFromParentBottomRight) != 0)
  72917. s << 'R';
  72918. else if ((mode & absoluteFromParentCentre) != 0)
  72919. s << 'C';
  72920. }
  72921. if ((mode & anchorAtRightOrBottom) != 0)
  72922. s << 'r';
  72923. else if ((mode & anchorAtCentre) != 0)
  72924. s << 'c';
  72925. }
  72926. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  72927. {
  72928. if (mode == proportionalSize)
  72929. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72930. else if (mode == parentSizeMinusAbsolute)
  72931. s << (roundToInt (value * 100.0) / 100.0) << 'M';
  72932. else
  72933. s << (roundToInt (value * 100.0) / 100.0);
  72934. }
  72935. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  72936. {
  72937. if (s.containsChar ('r'))
  72938. mode = anchorAtRightOrBottom;
  72939. else if (s.containsChar ('c'))
  72940. mode = anchorAtCentre;
  72941. else
  72942. mode = anchorAtLeftOrTop;
  72943. if (s.containsChar ('%'))
  72944. {
  72945. mode |= proportionOfParentSize;
  72946. value = s.removeCharacters ("%rcRC").getDoubleValue() / 100.0;
  72947. }
  72948. else
  72949. {
  72950. if (s.containsChar ('R'))
  72951. mode |= absoluteFromParentBottomRight;
  72952. else if (s.containsChar ('C'))
  72953. mode |= absoluteFromParentCentre;
  72954. else
  72955. mode |= absoluteFromParentTopLeft;
  72956. value = s.removeCharacters ("rcRC").getDoubleValue();
  72957. }
  72958. }
  72959. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  72960. {
  72961. if (s.containsChar ('%'))
  72962. {
  72963. mode = proportionalSize;
  72964. value = s.upToFirstOccurrenceOf ("%", false, false).getDoubleValue() / 100.0;
  72965. }
  72966. else if (s.containsChar ('M'))
  72967. {
  72968. mode = parentSizeMinusAbsolute;
  72969. value = s.getDoubleValue();
  72970. }
  72971. else
  72972. {
  72973. mode = absoluteSize;
  72974. value = s.getDoubleValue();
  72975. }
  72976. }
  72977. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  72978. const double x_, const double w_,
  72979. const uint8 xMode_, const uint8 wMode_,
  72980. const int parentPos,
  72981. const int parentSize) const throw()
  72982. {
  72983. if (wMode_ == proportionalSize)
  72984. wOut = roundToInt (w_ * parentSize);
  72985. else if (wMode_ == parentSizeMinusAbsolute)
  72986. wOut = jmax (0, parentSize - roundToInt (w_));
  72987. else
  72988. wOut = roundToInt (w_);
  72989. if ((xMode_ & proportionOfParentSize) != 0)
  72990. xOut = parentPos + x_ * parentSize;
  72991. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72992. xOut = (parentPos + parentSize) - x_;
  72993. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72994. xOut = x_ + (parentPos + parentSize / 2);
  72995. else
  72996. xOut = x_ + parentPos;
  72997. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72998. xOut -= wOut;
  72999. else if ((xMode_ & anchorAtCentre) != 0)
  73000. xOut -= wOut / 2;
  73001. }
  73002. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73003. double x_, const double w_,
  73004. const uint8 xMode_, const uint8 wMode_,
  73005. const int parentPos,
  73006. const int parentSize) const throw()
  73007. {
  73008. if (wMode_ == proportionalSize)
  73009. {
  73010. if (parentSize > 0)
  73011. wOut = w_ / parentSize;
  73012. }
  73013. else if (wMode_ == parentSizeMinusAbsolute)
  73014. wOut = parentSize - w_;
  73015. else
  73016. wOut = w_;
  73017. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73018. x_ += w_;
  73019. else if ((xMode_ & anchorAtCentre) != 0)
  73020. x_ += w_ / 2;
  73021. if ((xMode_ & proportionOfParentSize) != 0)
  73022. {
  73023. if (parentSize > 0)
  73024. xOut = (x_ - parentPos) / parentSize;
  73025. }
  73026. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73027. xOut = (parentPos + parentSize) - x_;
  73028. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73029. xOut = x_ - (parentPos + parentSize / 2);
  73030. else
  73031. xOut = x_ - parentPos;
  73032. }
  73033. END_JUCE_NAMESPACE
  73034. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73035. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73036. BEGIN_JUCE_NAMESPACE
  73037. RectangleList::RectangleList() throw()
  73038. {
  73039. }
  73040. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73041. {
  73042. if (! rect.isEmpty())
  73043. rects.add (rect);
  73044. }
  73045. RectangleList::RectangleList (const RectangleList& other) throw()
  73046. : rects (other.rects)
  73047. {
  73048. }
  73049. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73050. {
  73051. rects = other.rects;
  73052. return *this;
  73053. }
  73054. RectangleList::~RectangleList() throw()
  73055. {
  73056. }
  73057. void RectangleList::clear() throw()
  73058. {
  73059. rects.clearQuick();
  73060. }
  73061. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73062. {
  73063. if (((unsigned int) index) < (unsigned int) rects.size())
  73064. return rects.getReference (index);
  73065. return Rectangle<int>();
  73066. }
  73067. bool RectangleList::isEmpty() const throw()
  73068. {
  73069. return rects.size() == 0;
  73070. }
  73071. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73072. : current (0),
  73073. owner (list),
  73074. index (list.rects.size())
  73075. {
  73076. }
  73077. RectangleList::Iterator::~Iterator() throw()
  73078. {
  73079. }
  73080. bool RectangleList::Iterator::next() throw()
  73081. {
  73082. if (--index >= 0)
  73083. {
  73084. current = & (owner.rects.getReference (index));
  73085. return true;
  73086. }
  73087. return false;
  73088. }
  73089. void RectangleList::add (const Rectangle<int>& rect) throw()
  73090. {
  73091. if (! rect.isEmpty())
  73092. {
  73093. if (rects.size() == 0)
  73094. {
  73095. rects.add (rect);
  73096. }
  73097. else
  73098. {
  73099. bool anyOverlaps = false;
  73100. int i;
  73101. for (i = rects.size(); --i >= 0;)
  73102. {
  73103. Rectangle<int>& ourRect = rects.getReference (i);
  73104. if (rect.intersects (ourRect))
  73105. {
  73106. if (rect.contains (ourRect))
  73107. rects.remove (i);
  73108. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73109. anyOverlaps = true;
  73110. }
  73111. }
  73112. if (anyOverlaps && rects.size() > 0)
  73113. {
  73114. RectangleList r (rect);
  73115. for (i = rects.size(); --i >= 0;)
  73116. {
  73117. const Rectangle<int>& ourRect = rects.getReference (i);
  73118. if (rect.intersects (ourRect))
  73119. {
  73120. r.subtract (ourRect);
  73121. if (r.rects.size() == 0)
  73122. return;
  73123. }
  73124. }
  73125. for (i = r.getNumRectangles(); --i >= 0;)
  73126. rects.add (r.rects.getReference (i));
  73127. }
  73128. else
  73129. {
  73130. rects.add (rect);
  73131. }
  73132. }
  73133. }
  73134. }
  73135. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73136. {
  73137. rects.add (rect);
  73138. }
  73139. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73140. {
  73141. if (rects.size() == 0)
  73142. {
  73143. if (w > 0 && h > 0)
  73144. rects.add (Rectangle<int> (x, y, w, h));
  73145. }
  73146. else
  73147. {
  73148. add (Rectangle<int> (x, y, w, h));
  73149. }
  73150. }
  73151. void RectangleList::add (const RectangleList& other) throw()
  73152. {
  73153. for (int i = 0; i < other.rects.size(); ++i)
  73154. add (other.rects.getReference (i));
  73155. }
  73156. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73157. {
  73158. const int originalNumRects = rects.size();
  73159. if (originalNumRects > 0)
  73160. {
  73161. const int x1 = rect.x;
  73162. const int y1 = rect.y;
  73163. const int x2 = x1 + rect.w;
  73164. const int y2 = y1 + rect.h;
  73165. for (int i = getNumRectangles(); --i >= 0;)
  73166. {
  73167. Rectangle<int>& r = rects.getReference (i);
  73168. const int rx1 = r.x;
  73169. const int ry1 = r.y;
  73170. const int rx2 = rx1 + r.w;
  73171. const int ry2 = ry1 + r.h;
  73172. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73173. {
  73174. if (x1 > rx1 && x1 < rx2)
  73175. {
  73176. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73177. {
  73178. r.w = x1 - rx1;
  73179. }
  73180. else
  73181. {
  73182. r.x = x1;
  73183. r.w = rx2 - x1;
  73184. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73185. i += 2;
  73186. }
  73187. }
  73188. else if (x2 > rx1 && x2 < rx2)
  73189. {
  73190. r.x = x2;
  73191. r.w = rx2 - x2;
  73192. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73193. {
  73194. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73195. i += 2;
  73196. }
  73197. }
  73198. else if (y1 > ry1 && y1 < ry2)
  73199. {
  73200. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73201. {
  73202. r.h = y1 - ry1;
  73203. }
  73204. else
  73205. {
  73206. r.y = y1;
  73207. r.h = ry2 - y1;
  73208. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73209. i += 2;
  73210. }
  73211. }
  73212. else if (y2 > ry1 && y2 < ry2)
  73213. {
  73214. r.y = y2;
  73215. r.h = ry2 - y2;
  73216. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73217. {
  73218. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73219. i += 2;
  73220. }
  73221. }
  73222. else
  73223. {
  73224. rects.remove (i);
  73225. }
  73226. }
  73227. }
  73228. if (rects.size() > originalNumRects + 10)
  73229. consolidate();
  73230. }
  73231. }
  73232. void RectangleList::subtract (const RectangleList& otherList) throw()
  73233. {
  73234. for (int i = otherList.rects.size(); --i >= 0;)
  73235. subtract (otherList.rects.getReference (i));
  73236. }
  73237. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73238. {
  73239. bool notEmpty = false;
  73240. if (rect.isEmpty())
  73241. {
  73242. clear();
  73243. }
  73244. else
  73245. {
  73246. for (int i = rects.size(); --i >= 0;)
  73247. {
  73248. Rectangle<int>& r = rects.getReference (i);
  73249. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73250. rects.remove (i);
  73251. else
  73252. notEmpty = true;
  73253. }
  73254. }
  73255. return notEmpty;
  73256. }
  73257. bool RectangleList::clipTo (const RectangleList& other) throw()
  73258. {
  73259. if (rects.size() == 0)
  73260. return false;
  73261. RectangleList result;
  73262. for (int j = 0; j < rects.size(); ++j)
  73263. {
  73264. const Rectangle<int>& rect = rects.getReference (j);
  73265. for (int i = other.rects.size(); --i >= 0;)
  73266. {
  73267. Rectangle<int> r (other.rects.getReference (i));
  73268. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73269. result.rects.add (r);
  73270. }
  73271. }
  73272. swapWith (result);
  73273. return ! isEmpty();
  73274. }
  73275. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73276. {
  73277. destRegion.clear();
  73278. if (! rect.isEmpty())
  73279. {
  73280. for (int i = rects.size(); --i >= 0;)
  73281. {
  73282. Rectangle<int> r (rects.getReference (i));
  73283. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73284. destRegion.rects.add (r);
  73285. }
  73286. }
  73287. return destRegion.rects.size() > 0;
  73288. }
  73289. void RectangleList::swapWith (RectangleList& otherList) throw()
  73290. {
  73291. rects.swapWithArray (otherList.rects);
  73292. }
  73293. void RectangleList::consolidate() throw()
  73294. {
  73295. int i;
  73296. for (i = 0; i < getNumRectangles() - 1; ++i)
  73297. {
  73298. Rectangle<int>& r = rects.getReference (i);
  73299. const int rx1 = r.x;
  73300. const int ry1 = r.y;
  73301. const int rx2 = rx1 + r.w;
  73302. const int ry2 = ry1 + r.h;
  73303. for (int j = rects.size(); --j > i;)
  73304. {
  73305. Rectangle<int>& r2 = rects.getReference (j);
  73306. const int jrx1 = r2.x;
  73307. const int jry1 = r2.y;
  73308. const int jrx2 = jrx1 + r2.w;
  73309. const int jry2 = jry1 + r2.h;
  73310. // if the vertical edges of any blocks are touching and their horizontals don't
  73311. // line up, split them horizontally..
  73312. if (jrx1 == rx2 || jrx2 == rx1)
  73313. {
  73314. if (jry1 > ry1 && jry1 < ry2)
  73315. {
  73316. r.h = jry1 - ry1;
  73317. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73318. i = -1;
  73319. break;
  73320. }
  73321. if (jry2 > ry1 && jry2 < ry2)
  73322. {
  73323. r.h = jry2 - ry1;
  73324. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73325. i = -1;
  73326. break;
  73327. }
  73328. else if (ry1 > jry1 && ry1 < jry2)
  73329. {
  73330. r2.h = ry1 - jry1;
  73331. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73332. i = -1;
  73333. break;
  73334. }
  73335. else if (ry2 > jry1 && ry2 < jry2)
  73336. {
  73337. r2.h = ry2 - jry1;
  73338. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73339. i = -1;
  73340. break;
  73341. }
  73342. }
  73343. }
  73344. }
  73345. for (i = 0; i < rects.size() - 1; ++i)
  73346. {
  73347. Rectangle<int>& r = rects.getReference (i);
  73348. for (int j = rects.size(); --j > i;)
  73349. {
  73350. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73351. {
  73352. rects.remove (j);
  73353. i = -1;
  73354. break;
  73355. }
  73356. }
  73357. }
  73358. }
  73359. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73360. {
  73361. for (int i = getNumRectangles(); --i >= 0;)
  73362. if (rects.getReference (i).contains (x, y))
  73363. return true;
  73364. return false;
  73365. }
  73366. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73367. {
  73368. if (rects.size() > 1)
  73369. {
  73370. RectangleList r (rectangleToCheck);
  73371. for (int i = rects.size(); --i >= 0;)
  73372. {
  73373. r.subtract (rects.getReference (i));
  73374. if (r.rects.size() == 0)
  73375. return true;
  73376. }
  73377. }
  73378. else if (rects.size() > 0)
  73379. {
  73380. return rects.getReference (0).contains (rectangleToCheck);
  73381. }
  73382. return false;
  73383. }
  73384. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73385. {
  73386. for (int i = rects.size(); --i >= 0;)
  73387. if (rects.getReference (i).intersects (rectangleToCheck))
  73388. return true;
  73389. return false;
  73390. }
  73391. bool RectangleList::intersects (const RectangleList& other) const throw()
  73392. {
  73393. for (int i = rects.size(); --i >= 0;)
  73394. if (other.intersectsRectangle (rects.getReference (i)))
  73395. return true;
  73396. return false;
  73397. }
  73398. const Rectangle<int> RectangleList::getBounds() const throw()
  73399. {
  73400. if (rects.size() <= 1)
  73401. {
  73402. if (rects.size() == 0)
  73403. return Rectangle<int>();
  73404. else
  73405. return rects.getReference (0);
  73406. }
  73407. else
  73408. {
  73409. const Rectangle<int>& r = rects.getReference (0);
  73410. int minX = r.x;
  73411. int minY = r.y;
  73412. int maxX = minX + r.w;
  73413. int maxY = minY + r.h;
  73414. for (int i = rects.size(); --i > 0;)
  73415. {
  73416. const Rectangle<int>& r2 = rects.getReference (i);
  73417. minX = jmin (minX, r2.x);
  73418. minY = jmin (minY, r2.y);
  73419. maxX = jmax (maxX, r2.getRight());
  73420. maxY = jmax (maxY, r2.getBottom());
  73421. }
  73422. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73423. }
  73424. }
  73425. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73426. {
  73427. for (int i = rects.size(); --i >= 0;)
  73428. {
  73429. Rectangle<int>& r = rects.getReference (i);
  73430. r.x += dx;
  73431. r.y += dy;
  73432. }
  73433. }
  73434. const Path RectangleList::toPath() const throw()
  73435. {
  73436. Path p;
  73437. for (int i = rects.size(); --i >= 0;)
  73438. {
  73439. const Rectangle<int>& r = rects.getReference (i);
  73440. p.addRectangle ((float) r.x,
  73441. (float) r.y,
  73442. (float) r.w,
  73443. (float) r.h);
  73444. }
  73445. return p;
  73446. }
  73447. END_JUCE_NAMESPACE
  73448. /*** End of inlined file: juce_RectangleList.cpp ***/
  73449. /*** Start of inlined file: juce_Image.cpp ***/
  73450. BEGIN_JUCE_NAMESPACE
  73451. static const int fullAlphaThreshold = 253;
  73452. Image::Image (const PixelFormat format_,
  73453. const int imageWidth_,
  73454. const int imageHeight_)
  73455. : format (format_),
  73456. imageWidth (imageWidth_),
  73457. imageHeight (imageHeight_),
  73458. imageData (0)
  73459. {
  73460. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73461. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73462. // actual image will be at least 1x1.
  73463. }
  73464. Image::Image (const PixelFormat format_,
  73465. const int imageWidth_,
  73466. const int imageHeight_,
  73467. const bool clearImage)
  73468. : format (format_),
  73469. imageWidth (imageWidth_),
  73470. imageHeight (imageHeight_)
  73471. {
  73472. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73473. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73474. // actual image will be at least 1x1.
  73475. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73476. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73477. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73478. imageData = imageDataAllocated;
  73479. }
  73480. Image::Image (const Image& other)
  73481. : format (other.format),
  73482. imageWidth (other.imageWidth),
  73483. imageHeight (other.imageHeight)
  73484. {
  73485. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73486. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73487. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73488. imageData = imageDataAllocated;
  73489. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73490. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73491. }
  73492. Image::~Image()
  73493. {
  73494. }
  73495. LowLevelGraphicsContext* Image::createLowLevelContext()
  73496. {
  73497. return new LowLevelGraphicsSoftwareRenderer (*this);
  73498. }
  73499. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73500. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73501. lineStride (image.lineStride),
  73502. pixelStride (image.pixelStride),
  73503. width (w),
  73504. height (h)
  73505. {
  73506. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73507. }
  73508. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73509. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73510. lineStride (image.lineStride),
  73511. pixelStride (image.pixelStride),
  73512. width (w),
  73513. height (h)
  73514. {
  73515. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73516. }
  73517. Image::BitmapData::~BitmapData()
  73518. {
  73519. }
  73520. void Image::setPixelData (int x, int y, int w, int h,
  73521. const uint8* sourcePixelData, int sourceLineStride)
  73522. {
  73523. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73524. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73525. {
  73526. const BitmapData dest (*this, x, y, w, h, true);
  73527. for (int i = 0; i < h; ++i)
  73528. {
  73529. memcpy (dest.getLinePointer(i),
  73530. sourcePixelData + sourceLineStride * i,
  73531. w * dest.pixelStride);
  73532. }
  73533. }
  73534. }
  73535. void Image::clear (int dx, int dy, int dw, int dh, const Colour& colourToClearTo)
  73536. {
  73537. if (Rectangle<int>::intersectRectangles (dx, dy, dw, dh, 0, 0, imageWidth, imageHeight))
  73538. {
  73539. const PixelARGB col (colourToClearTo.getPixelARGB());
  73540. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73541. uint8* dest = destData.data;
  73542. while (--dh >= 0)
  73543. {
  73544. uint8* line = dest;
  73545. dest += destData.lineStride;
  73546. if (isARGB())
  73547. {
  73548. for (int x = dw; --x >= 0;)
  73549. {
  73550. ((PixelARGB*) line)->set (col);
  73551. line += destData.pixelStride;
  73552. }
  73553. }
  73554. else if (isRGB())
  73555. {
  73556. for (int x = dw; --x >= 0;)
  73557. {
  73558. ((PixelRGB*) line)->set (col);
  73559. line += destData.pixelStride;
  73560. }
  73561. }
  73562. else
  73563. {
  73564. for (int x = dw; --x >= 0;)
  73565. {
  73566. *line = col.getAlpha();
  73567. line += destData.pixelStride;
  73568. }
  73569. }
  73570. }
  73571. }
  73572. }
  73573. Image* Image::createCopy (int newWidth, int newHeight,
  73574. const Graphics::ResamplingQuality quality) const
  73575. {
  73576. if (newWidth < 0)
  73577. newWidth = imageWidth;
  73578. if (newHeight < 0)
  73579. newHeight = imageHeight;
  73580. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73581. Graphics g (*newImage);
  73582. g.setImageResamplingQuality (quality);
  73583. g.drawImage (this,
  73584. 0, 0, newWidth, newHeight,
  73585. 0, 0, imageWidth, imageHeight,
  73586. false);
  73587. return newImage;
  73588. }
  73589. Image* Image::createCopyOfAlphaChannel() const
  73590. {
  73591. jassert (format != SingleChannel);
  73592. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73593. if (! hasAlphaChannel())
  73594. {
  73595. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73596. }
  73597. else
  73598. {
  73599. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73600. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73601. for (int y = 0; y < imageHeight; ++y)
  73602. {
  73603. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73604. uint8* dst = destData.getLinePointer (y);
  73605. for (int x = imageWidth; --x >= 0;)
  73606. {
  73607. *dst++ = src->getAlpha();
  73608. ++src;
  73609. }
  73610. }
  73611. }
  73612. return newImage;
  73613. }
  73614. const Colour Image::getPixelAt (const int x, const int y) const
  73615. {
  73616. Colour c;
  73617. if (((unsigned int) x) < (unsigned int) imageWidth
  73618. && ((unsigned int) y) < (unsigned int) imageHeight)
  73619. {
  73620. const BitmapData srcData (*this, x, y, 1, 1);
  73621. if (isARGB())
  73622. {
  73623. PixelARGB p (*(const PixelARGB*) srcData.data);
  73624. p.unpremultiply();
  73625. c = Colour (p.getARGB());
  73626. }
  73627. else if (isRGB())
  73628. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73629. else
  73630. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73631. }
  73632. return c;
  73633. }
  73634. void Image::setPixelAt (const int x, const int y,
  73635. const Colour& colour)
  73636. {
  73637. if (((unsigned int) x) < (unsigned int) imageWidth
  73638. && ((unsigned int) y) < (unsigned int) imageHeight)
  73639. {
  73640. const BitmapData destData (*this, x, y, 1, 1, true);
  73641. const PixelARGB col (colour.getPixelARGB());
  73642. if (isARGB())
  73643. ((PixelARGB*) destData.data)->set (col);
  73644. else if (isRGB())
  73645. ((PixelRGB*) destData.data)->set (col);
  73646. else
  73647. *(destData.data) = col.getAlpha();
  73648. }
  73649. }
  73650. void Image::multiplyAlphaAt (const int x, const int y,
  73651. const float multiplier)
  73652. {
  73653. if (((unsigned int) x) < (unsigned int) imageWidth
  73654. && ((unsigned int) y) < (unsigned int) imageHeight
  73655. && hasAlphaChannel())
  73656. {
  73657. const BitmapData destData (*this, x, y, 1, 1, true);
  73658. if (isARGB())
  73659. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73660. else
  73661. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73662. }
  73663. }
  73664. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73665. {
  73666. if (hasAlphaChannel())
  73667. {
  73668. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73669. if (isARGB())
  73670. {
  73671. for (int y = 0; y < imageHeight; ++y)
  73672. {
  73673. uint8* p = destData.getLinePointer (y);
  73674. for (int x = 0; x < imageWidth; ++x)
  73675. {
  73676. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73677. p += destData.pixelStride;
  73678. }
  73679. }
  73680. }
  73681. else
  73682. {
  73683. for (int y = 0; y < imageHeight; ++y)
  73684. {
  73685. uint8* p = destData.getLinePointer (y);
  73686. for (int x = 0; x < imageWidth; ++x)
  73687. {
  73688. *p = (uint8) (*p * amountToMultiplyBy);
  73689. p += destData.pixelStride;
  73690. }
  73691. }
  73692. }
  73693. }
  73694. else
  73695. {
  73696. jassertfalse // can't do this without an alpha-channel!
  73697. }
  73698. }
  73699. void Image::desaturate()
  73700. {
  73701. if (isARGB() || isRGB())
  73702. {
  73703. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73704. if (isARGB())
  73705. {
  73706. for (int y = 0; y < imageHeight; ++y)
  73707. {
  73708. uint8* p = destData.getLinePointer (y);
  73709. for (int x = 0; x < imageWidth; ++x)
  73710. {
  73711. ((PixelARGB*) p)->desaturate();
  73712. p += destData.pixelStride;
  73713. }
  73714. }
  73715. }
  73716. else
  73717. {
  73718. for (int y = 0; y < imageHeight; ++y)
  73719. {
  73720. uint8* p = destData.getLinePointer (y);
  73721. for (int x = 0; x < imageWidth; ++x)
  73722. {
  73723. ((PixelRGB*) p)->desaturate();
  73724. p += destData.pixelStride;
  73725. }
  73726. }
  73727. }
  73728. }
  73729. }
  73730. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73731. {
  73732. if (hasAlphaChannel())
  73733. {
  73734. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73735. SparseSet <int> pixelsOnRow;
  73736. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73737. for (int y = 0; y < imageHeight; ++y)
  73738. {
  73739. pixelsOnRow.clear();
  73740. const uint8* lineData = srcData.getLinePointer (y);
  73741. if (isARGB())
  73742. {
  73743. for (int x = 0; x < imageWidth; ++x)
  73744. {
  73745. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73746. pixelsOnRow.addRange (x, 1);
  73747. lineData += srcData.pixelStride;
  73748. }
  73749. }
  73750. else
  73751. {
  73752. for (int x = 0; x < imageWidth; ++x)
  73753. {
  73754. if (*lineData >= threshold)
  73755. pixelsOnRow.addRange (x, 1);
  73756. lineData += srcData.pixelStride;
  73757. }
  73758. }
  73759. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73760. {
  73761. int x, w;
  73762. if (pixelsOnRow.getRange (i, x, w))
  73763. result.add (Rectangle<int> (x, y, w, 1));
  73764. }
  73765. result.consolidate();
  73766. }
  73767. }
  73768. else
  73769. {
  73770. result.add (0, 0, imageWidth, imageHeight);
  73771. }
  73772. }
  73773. void Image::moveImageSection (int dx, int dy,
  73774. int sx, int sy,
  73775. int w, int h)
  73776. {
  73777. if (dx < 0)
  73778. {
  73779. w += dx;
  73780. sx -= dx;
  73781. dx = 0;
  73782. }
  73783. if (dy < 0)
  73784. {
  73785. h += dy;
  73786. sy -= dy;
  73787. dy = 0;
  73788. }
  73789. if (sx < 0)
  73790. {
  73791. w += sx;
  73792. dx -= sx;
  73793. sx = 0;
  73794. }
  73795. if (sy < 0)
  73796. {
  73797. h += sy;
  73798. dy -= sy;
  73799. sy = 0;
  73800. }
  73801. const int minX = jmin (dx, sx);
  73802. const int minY = jmin (dy, sy);
  73803. w = jmin (w, getWidth() - jmax (sx, dx));
  73804. h = jmin (h, getHeight() - jmax (sy, dy));
  73805. if (w > 0 && h > 0)
  73806. {
  73807. const int maxX = jmax (dx, sx) + w;
  73808. const int maxY = jmax (dy, sy) + h;
  73809. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73810. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73811. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73812. const int lineSize = destData.pixelStride * w;
  73813. if (dy > sy)
  73814. {
  73815. while (--h >= 0)
  73816. {
  73817. const int offset = h * destData.lineStride;
  73818. memmove (dst + offset, src + offset, lineSize);
  73819. }
  73820. }
  73821. else if (dst != src)
  73822. {
  73823. while (--h >= 0)
  73824. {
  73825. memmove (dst, src, lineSize);
  73826. dst += destData.lineStride;
  73827. src += destData.lineStride;
  73828. }
  73829. }
  73830. }
  73831. }
  73832. END_JUCE_NAMESPACE
  73833. /*** End of inlined file: juce_Image.cpp ***/
  73834. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73835. BEGIN_JUCE_NAMESPACE
  73836. struct ImageCache::Item
  73837. {
  73838. ScopedPointer <Image> image;
  73839. int64 hashCode;
  73840. int refCount;
  73841. uint32 releaseTime;
  73842. juce_UseDebuggingNewOperator
  73843. };
  73844. ImageCache* ImageCache::instance = 0;
  73845. int ImageCache::cacheTimeout = 5000;
  73846. ImageCache::ImageCache()
  73847. {
  73848. }
  73849. ImageCache::~ImageCache()
  73850. {
  73851. jassert (instance == this);
  73852. instance = 0;
  73853. }
  73854. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73855. {
  73856. if (instance != 0)
  73857. {
  73858. const ScopedLock sl (instance->lock);
  73859. for (int i = instance->images.size(); --i >= 0;)
  73860. {
  73861. Item* const ci = instance->images.getUnchecked(i);
  73862. if (ci->hashCode == hashCode)
  73863. {
  73864. ci->refCount++;
  73865. return ci->image;
  73866. }
  73867. }
  73868. }
  73869. return 0;
  73870. }
  73871. void ImageCache::addImageToCache (Image* const image, const int64 hashCode)
  73872. {
  73873. if (image != 0)
  73874. {
  73875. if (instance == 0)
  73876. instance = new ImageCache();
  73877. Item* const newC = new Item();
  73878. newC->hashCode = hashCode;
  73879. newC->image = image;
  73880. newC->refCount = 1;
  73881. newC->releaseTime = 0;
  73882. const ScopedLock sl (instance->lock);
  73883. instance->images.add (newC);
  73884. }
  73885. }
  73886. void ImageCache::release (Image* const imageToRelease)
  73887. {
  73888. if (imageToRelease != 0 && instance != 0)
  73889. {
  73890. const ScopedLock sl (instance->lock);
  73891. for (int i = instance->images.size(); --i >= 0;)
  73892. {
  73893. Item* const ci = instance->images.getUnchecked(i);
  73894. if (static_cast <Image*> (ci->image) == imageToRelease)
  73895. {
  73896. if (--(ci->refCount) == 0)
  73897. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73898. if (! instance->isTimerRunning())
  73899. instance->startTimer (999);
  73900. break;
  73901. }
  73902. }
  73903. }
  73904. }
  73905. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  73906. {
  73907. if (isImageInCache (imageToRelease))
  73908. release (imageToRelease);
  73909. else
  73910. delete imageToRelease;
  73911. }
  73912. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  73913. {
  73914. if (instance != 0)
  73915. {
  73916. const ScopedLock sl (instance->lock);
  73917. for (int i = instance->images.size(); --i >= 0;)
  73918. if (static_cast <Image*> (instance->images.getUnchecked(i)->image) == imageToLookFor)
  73919. return true;
  73920. }
  73921. return false;
  73922. }
  73923. void ImageCache::incReferenceCount (Image* const image)
  73924. {
  73925. if (instance != 0)
  73926. {
  73927. const ScopedLock sl (instance->lock);
  73928. for (int i = instance->images.size(); --i >= 0;)
  73929. {
  73930. Item* const ci = instance->images.getUnchecked(i);
  73931. if (static_cast <Image*> (ci->image) == image)
  73932. {
  73933. ci->refCount++;
  73934. return;
  73935. }
  73936. }
  73937. }
  73938. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  73939. }
  73940. void ImageCache::timerCallback()
  73941. {
  73942. int numberStillNeedingReleasing = 0;
  73943. const uint32 now = Time::getApproximateMillisecondCounter();
  73944. const ScopedLock sl (lock);
  73945. for (int i = images.size(); --i >= 0;)
  73946. {
  73947. Item* const ci = images.getUnchecked(i);
  73948. if (ci->refCount <= 0)
  73949. {
  73950. if (now > ci->releaseTime + cacheTimeout
  73951. || now < ci->releaseTime - 1000)
  73952. {
  73953. images.remove (i);
  73954. }
  73955. else
  73956. {
  73957. ++numberStillNeedingReleasing;
  73958. }
  73959. }
  73960. }
  73961. if (numberStillNeedingReleasing == 0)
  73962. stopTimer();
  73963. }
  73964. Image* ImageCache::getFromFile (const File& file)
  73965. {
  73966. const int64 hashCode = file.hashCode64();
  73967. Image* image = getFromHashCode (hashCode);
  73968. if (image == 0)
  73969. {
  73970. image = ImageFileFormat::loadFrom (file);
  73971. addImageToCache (image, hashCode);
  73972. }
  73973. return image;
  73974. }
  73975. Image* ImageCache::getFromMemory (const void* imageData, const int dataSize)
  73976. {
  73977. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  73978. Image* image = getFromHashCode (hashCode);
  73979. if (image == 0)
  73980. {
  73981. image = ImageFileFormat::loadFrom (imageData, dataSize);
  73982. addImageToCache (image, hashCode);
  73983. }
  73984. return image;
  73985. }
  73986. void ImageCache::setCacheTimeout (const int millisecs)
  73987. {
  73988. cacheTimeout = millisecs;
  73989. }
  73990. END_JUCE_NAMESPACE
  73991. /*** End of inlined file: juce_ImageCache.cpp ***/
  73992. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  73993. BEGIN_JUCE_NAMESPACE
  73994. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  73995. : values (size_ * size_),
  73996. size (size_)
  73997. {
  73998. clear();
  73999. }
  74000. ImageConvolutionKernel::~ImageConvolutionKernel()
  74001. {
  74002. }
  74003. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  74004. {
  74005. if (((unsigned int) x) < (unsigned int) size
  74006. && ((unsigned int) y) < (unsigned int) size)
  74007. {
  74008. return values [x + y * size];
  74009. }
  74010. else
  74011. {
  74012. jassertfalse;
  74013. return 0;
  74014. }
  74015. }
  74016. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  74017. {
  74018. if (((unsigned int) x) < (unsigned int) size
  74019. && ((unsigned int) y) < (unsigned int) size)
  74020. {
  74021. values [x + y * size] = value;
  74022. }
  74023. else
  74024. {
  74025. jassertfalse;
  74026. }
  74027. }
  74028. void ImageConvolutionKernel::clear()
  74029. {
  74030. for (int i = size * size; --i >= 0;)
  74031. values[i] = 0;
  74032. }
  74033. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74034. {
  74035. double currentTotal = 0.0;
  74036. for (int i = size * size; --i >= 0;)
  74037. currentTotal += values[i];
  74038. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74039. }
  74040. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74041. {
  74042. for (int i = size * size; --i >= 0;)
  74043. values[i] *= multiplier;
  74044. }
  74045. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74046. {
  74047. const double radiusFactor = -1.0 / (radius * radius * 2);
  74048. const int centre = size >> 1;
  74049. for (int y = size; --y >= 0;)
  74050. {
  74051. for (int x = size; --x >= 0;)
  74052. {
  74053. const int cx = x - centre;
  74054. const int cy = y - centre;
  74055. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74056. }
  74057. }
  74058. setOverallSum (1.0f);
  74059. }
  74060. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74061. const Image* sourceImage,
  74062. const Rectangle<int>& destinationArea) const
  74063. {
  74064. ScopedPointer <Image> imageCreated;
  74065. if (sourceImage == 0)
  74066. {
  74067. sourceImage = imageCreated = destImage.createCopy();
  74068. }
  74069. else
  74070. {
  74071. jassert (sourceImage->getWidth() == destImage.getWidth()
  74072. && sourceImage->getHeight() == destImage.getHeight()
  74073. && sourceImage->getFormat() == destImage.getFormat());
  74074. if (sourceImage->getWidth() != destImage.getWidth()
  74075. || sourceImage->getHeight() != destImage.getHeight()
  74076. || sourceImage->getFormat() != destImage.getFormat())
  74077. return;
  74078. }
  74079. const Rectangle<int> area (destinationArea.getIntersection (destImage.getBounds()));
  74080. if (area.isEmpty())
  74081. return;
  74082. const int right = area.getRight();
  74083. const int bottom = area.getBottom();
  74084. const Image::BitmapData destData (destImage, area.getX(), area.getY(), area.getWidth(), area.getHeight(), true);
  74085. uint8* line = destData.data;
  74086. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74087. if (destData.pixelStride == 4)
  74088. {
  74089. for (int y = area.getY(); y < bottom; ++y)
  74090. {
  74091. uint8* dest = line;
  74092. line += destData.lineStride;
  74093. for (int x = area.getX(); x < right; ++x)
  74094. {
  74095. float c1 = 0;
  74096. float c2 = 0;
  74097. float c3 = 0;
  74098. float c4 = 0;
  74099. for (int yy = 0; yy < size; ++yy)
  74100. {
  74101. const int sy = y + yy - (size >> 1);
  74102. if (sy >= srcData.height)
  74103. break;
  74104. if (sy >= 0)
  74105. {
  74106. int sx = x - (size >> 1);
  74107. const uint8* src = srcData.getPixelPointer (sx, sy);
  74108. for (int xx = 0; xx < size; ++xx)
  74109. {
  74110. if (sx >= srcData.width)
  74111. break;
  74112. if (sx >= 0)
  74113. {
  74114. const float kernelMult = values [xx + yy * size];
  74115. c1 += kernelMult * *src++;
  74116. c2 += kernelMult * *src++;
  74117. c3 += kernelMult * *src++;
  74118. c4 += kernelMult * *src++;
  74119. }
  74120. else
  74121. {
  74122. src += 4;
  74123. }
  74124. ++sx;
  74125. }
  74126. }
  74127. }
  74128. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74129. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74130. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74131. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74132. }
  74133. }
  74134. }
  74135. else if (destData.pixelStride == 3)
  74136. {
  74137. for (int y = area.getY(); y < bottom; ++y)
  74138. {
  74139. uint8* dest = line;
  74140. line += destData.lineStride;
  74141. for (int x = area.getX(); x < right; ++x)
  74142. {
  74143. float c1 = 0;
  74144. float c2 = 0;
  74145. float c3 = 0;
  74146. for (int yy = 0; yy < size; ++yy)
  74147. {
  74148. const int sy = y + yy - (size >> 1);
  74149. if (sy >= srcData.height)
  74150. break;
  74151. if (sy >= 0)
  74152. {
  74153. int sx = x - (size >> 1);
  74154. const uint8* src = srcData.getPixelPointer (sx, sy);
  74155. for (int xx = 0; xx < size; ++xx)
  74156. {
  74157. if (sx >= srcData.width)
  74158. break;
  74159. if (sx >= 0)
  74160. {
  74161. const float kernelMult = values [xx + yy * size];
  74162. c1 += kernelMult * *src++;
  74163. c2 += kernelMult * *src++;
  74164. c3 += kernelMult * *src++;
  74165. }
  74166. else
  74167. {
  74168. src += 3;
  74169. }
  74170. ++sx;
  74171. }
  74172. }
  74173. }
  74174. *dest++ = (uint8) roundToInt (c1);
  74175. *dest++ = (uint8) roundToInt (c2);
  74176. *dest++ = (uint8) roundToInt (c3);
  74177. }
  74178. }
  74179. }
  74180. }
  74181. END_JUCE_NAMESPACE
  74182. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74183. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74184. BEGIN_JUCE_NAMESPACE
  74185. /*** Start of inlined file: juce_GIFLoader.h ***/
  74186. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74187. #define __JUCE_GIFLOADER_JUCEHEADER__
  74188. #ifndef DOXYGEN
  74189. class GIFLoader
  74190. {
  74191. public:
  74192. GIFLoader (InputStream& in);
  74193. ~GIFLoader();
  74194. Image* getImage() const { return image; }
  74195. private:
  74196. Image* image;
  74197. InputStream& input;
  74198. uint8 buffer [300];
  74199. uint8 palette [256][4];
  74200. bool dataBlockIsZero, fresh, finished;
  74201. int currentBit, lastBit, lastByteIndex;
  74202. int codeSize, setCodeSize;
  74203. int maxCode, maxCodeSize;
  74204. int firstcode, oldcode;
  74205. int clearCode, end_code;
  74206. enum { maxGifCode = 1 << 12 };
  74207. int table [2] [maxGifCode];
  74208. int stack [2 * maxGifCode];
  74209. int *sp;
  74210. bool getSizeFromHeader (int& width, int& height);
  74211. bool readPalette (const int numCols);
  74212. int readDataBlock (unsigned char* dest);
  74213. int processExtension (int type, int& transparent);
  74214. int readLZWByte (bool initialise, int input_code_size);
  74215. int getCode (int code_size, bool initialise);
  74216. bool readImage (int width, int height, int interlace, int transparent);
  74217. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74218. GIFLoader (const GIFLoader&);
  74219. GIFLoader& operator= (const GIFLoader&);
  74220. };
  74221. #endif // DOXYGEN
  74222. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74223. /*** End of inlined file: juce_GIFLoader.h ***/
  74224. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74225. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74226. PNGImageFormat::PNGImageFormat() {}
  74227. PNGImageFormat::~PNGImageFormat() {}
  74228. const String PNGImageFormat::getFormatName()
  74229. {
  74230. return "PNG";
  74231. }
  74232. bool PNGImageFormat::canUnderstand (InputStream& in)
  74233. {
  74234. const int bytesNeeded = 4;
  74235. char header [bytesNeeded];
  74236. return in.read (header, bytesNeeded) == bytesNeeded
  74237. && header[1] == 'P'
  74238. && header[2] == 'N'
  74239. && header[3] == 'G';
  74240. }
  74241. Image* PNGImageFormat::decodeImage (InputStream& in)
  74242. {
  74243. return juce_loadPNGImageFromStream (in);
  74244. }
  74245. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74246. OutputStream& destStream)
  74247. {
  74248. return juce_writePNGImageToStream (sourceImage, destStream);
  74249. }
  74250. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74251. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74252. JPEGImageFormat::JPEGImageFormat()
  74253. : quality (-1.0f)
  74254. {
  74255. }
  74256. JPEGImageFormat::~JPEGImageFormat() {}
  74257. void JPEGImageFormat::setQuality (const float newQuality)
  74258. {
  74259. quality = newQuality;
  74260. }
  74261. const String JPEGImageFormat::getFormatName()
  74262. {
  74263. return "JPEG";
  74264. }
  74265. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74266. {
  74267. const int bytesNeeded = 10;
  74268. uint8 header [bytesNeeded];
  74269. if (in.read (header, bytesNeeded) == bytesNeeded)
  74270. {
  74271. return header[0] == 0xff
  74272. && header[1] == 0xd8
  74273. && header[2] == 0xff
  74274. && (header[3] == 0xe0 || header[3] == 0xe1);
  74275. }
  74276. return false;
  74277. }
  74278. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74279. {
  74280. return juce_loadJPEGImageFromStream (in);
  74281. }
  74282. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74283. OutputStream& destStream)
  74284. {
  74285. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74286. }
  74287. class GIFImageFormat : public ImageFileFormat
  74288. {
  74289. public:
  74290. GIFImageFormat() {}
  74291. ~GIFImageFormat() {}
  74292. const String getFormatName()
  74293. {
  74294. return "GIF";
  74295. }
  74296. bool canUnderstand (InputStream& in)
  74297. {
  74298. const int bytesNeeded = 4;
  74299. char header [bytesNeeded];
  74300. return (in.read (header, bytesNeeded) == bytesNeeded)
  74301. && header[0] == 'G'
  74302. && header[1] == 'I'
  74303. && header[2] == 'F';
  74304. }
  74305. Image* decodeImage (InputStream& in)
  74306. {
  74307. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74308. return loader->getImage();
  74309. }
  74310. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74311. {
  74312. return false;
  74313. }
  74314. };
  74315. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74316. {
  74317. static PNGImageFormat png;
  74318. static JPEGImageFormat jpg;
  74319. static GIFImageFormat gif;
  74320. ImageFileFormat* formats[4];
  74321. int numFormats = 0;
  74322. formats [numFormats++] = &png;
  74323. formats [numFormats++] = &jpg;
  74324. formats [numFormats++] = &gif;
  74325. const int64 streamPos = input.getPosition();
  74326. for (int i = 0; i < numFormats; ++i)
  74327. {
  74328. const bool found = formats[i]->canUnderstand (input);
  74329. input.setPosition (streamPos);
  74330. if (found)
  74331. return formats[i];
  74332. }
  74333. return 0;
  74334. }
  74335. Image* ImageFileFormat::loadFrom (InputStream& input)
  74336. {
  74337. ImageFileFormat* const format = findImageFormatForStream (input);
  74338. if (format != 0)
  74339. return format->decodeImage (input);
  74340. return 0;
  74341. }
  74342. Image* ImageFileFormat::loadFrom (const File& file)
  74343. {
  74344. InputStream* const in = file.createInputStream();
  74345. if (in != 0)
  74346. {
  74347. BufferedInputStream b (in, 8192, true);
  74348. return loadFrom (b);
  74349. }
  74350. return 0;
  74351. }
  74352. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74353. {
  74354. if (rawData != 0 && numBytes > 4)
  74355. {
  74356. MemoryInputStream stream (rawData, numBytes, false);
  74357. return loadFrom (stream);
  74358. }
  74359. return 0;
  74360. }
  74361. END_JUCE_NAMESPACE
  74362. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74363. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74364. BEGIN_JUCE_NAMESPACE
  74365. GIFLoader::GIFLoader (InputStream& in)
  74366. : image (0),
  74367. input (in),
  74368. dataBlockIsZero (false),
  74369. fresh (false),
  74370. finished (false)
  74371. {
  74372. currentBit = lastBit = lastByteIndex = 0;
  74373. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74374. firstcode = oldcode = 0;
  74375. clearCode = end_code = 0;
  74376. int imageWidth, imageHeight;
  74377. int transparent = -1;
  74378. if (! getSizeFromHeader (imageWidth, imageHeight))
  74379. return;
  74380. if ((imageWidth <= 0) || (imageHeight <= 0))
  74381. return;
  74382. unsigned char buf [16];
  74383. if (in.read (buf, 3) != 3)
  74384. return;
  74385. int numColours = 2 << (buf[0] & 7);
  74386. if ((buf[0] & 0x80) != 0)
  74387. readPalette (numColours);
  74388. for (;;)
  74389. {
  74390. if (input.read (buf, 1) != 1)
  74391. break;
  74392. if (buf[0] == ';')
  74393. break;
  74394. if (buf[0] == '!')
  74395. {
  74396. if (input.read (buf, 1) != 1)
  74397. break;
  74398. if (processExtension (buf[0], transparent) < 0)
  74399. break;
  74400. continue;
  74401. }
  74402. if (buf[0] != ',')
  74403. continue;
  74404. if (input.read (buf, 9) != 9)
  74405. break;
  74406. imageWidth = makeWord (buf[4], buf[5]);
  74407. imageHeight = makeWord (buf[6], buf[7]);
  74408. numColours = 2 << (buf[8] & 7);
  74409. if ((buf[8] & 0x80) != 0)
  74410. if (! readPalette (numColours))
  74411. break;
  74412. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74413. imageWidth, imageHeight, (transparent >= 0));
  74414. readImage (imageWidth, imageHeight,
  74415. (buf[8] & 0x40) != 0,
  74416. transparent);
  74417. break;
  74418. }
  74419. }
  74420. GIFLoader::~GIFLoader()
  74421. {
  74422. }
  74423. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74424. {
  74425. unsigned char b [8];
  74426. if (input.read (b, 6) == 6)
  74427. {
  74428. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74429. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74430. {
  74431. if (input.read (b, 4) == 4)
  74432. {
  74433. w = makeWord (b[0], b[1]);
  74434. h = makeWord (b[2], b[3]);
  74435. return true;
  74436. }
  74437. }
  74438. }
  74439. return false;
  74440. }
  74441. bool GIFLoader::readPalette (const int numCols)
  74442. {
  74443. unsigned char rgb[4];
  74444. for (int i = 0; i < numCols; ++i)
  74445. {
  74446. input.read (rgb, 3);
  74447. palette [i][0] = rgb[0];
  74448. palette [i][1] = rgb[1];
  74449. palette [i][2] = rgb[2];
  74450. palette [i][3] = 0xff;
  74451. }
  74452. return true;
  74453. }
  74454. int GIFLoader::readDataBlock (unsigned char* const dest)
  74455. {
  74456. unsigned char n;
  74457. if (input.read (&n, 1) == 1)
  74458. {
  74459. dataBlockIsZero = (n == 0);
  74460. if (dataBlockIsZero || (input.read (dest, n) == n))
  74461. return n;
  74462. }
  74463. return -1;
  74464. }
  74465. int GIFLoader::processExtension (const int type, int& transparent)
  74466. {
  74467. unsigned char b [300];
  74468. int n = 0;
  74469. if (type == 0xf9)
  74470. {
  74471. n = readDataBlock (b);
  74472. if (n < 0)
  74473. return 1;
  74474. if ((b[0] & 0x1) != 0)
  74475. transparent = b[3];
  74476. }
  74477. do
  74478. {
  74479. n = readDataBlock (b);
  74480. }
  74481. while (n > 0);
  74482. return n;
  74483. }
  74484. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74485. {
  74486. if (initialise)
  74487. {
  74488. currentBit = 0;
  74489. lastBit = 0;
  74490. finished = false;
  74491. return 0;
  74492. }
  74493. if ((currentBit + codeSize_) >= lastBit)
  74494. {
  74495. if (finished)
  74496. return -1;
  74497. buffer[0] = buffer [lastByteIndex - 2];
  74498. buffer[1] = buffer [lastByteIndex - 1];
  74499. const int n = readDataBlock (&buffer[2]);
  74500. if (n == 0)
  74501. finished = true;
  74502. lastByteIndex = 2 + n;
  74503. currentBit = (currentBit - lastBit) + 16;
  74504. lastBit = (2 + n) * 8 ;
  74505. }
  74506. int result = 0;
  74507. int i = currentBit;
  74508. for (int j = 0; j < codeSize_; ++j)
  74509. {
  74510. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74511. ++i;
  74512. }
  74513. currentBit += codeSize_;
  74514. return result;
  74515. }
  74516. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74517. {
  74518. int code, incode, i;
  74519. if (initialise)
  74520. {
  74521. setCodeSize = inputCodeSize;
  74522. codeSize = setCodeSize + 1;
  74523. clearCode = 1 << setCodeSize;
  74524. end_code = clearCode + 1;
  74525. maxCodeSize = 2 * clearCode;
  74526. maxCode = clearCode + 2;
  74527. getCode (0, true);
  74528. fresh = true;
  74529. for (i = 0; i < clearCode; ++i)
  74530. {
  74531. table[0][i] = 0;
  74532. table[1][i] = i;
  74533. }
  74534. for (; i < maxGifCode; ++i)
  74535. {
  74536. table[0][i] = 0;
  74537. table[1][i] = 0;
  74538. }
  74539. sp = stack;
  74540. return 0;
  74541. }
  74542. else if (fresh)
  74543. {
  74544. fresh = false;
  74545. do
  74546. {
  74547. firstcode = oldcode
  74548. = getCode (codeSize, false);
  74549. }
  74550. while (firstcode == clearCode);
  74551. return firstcode;
  74552. }
  74553. if (sp > stack)
  74554. return *--sp;
  74555. while ((code = getCode (codeSize, false)) >= 0)
  74556. {
  74557. if (code == clearCode)
  74558. {
  74559. for (i = 0; i < clearCode; ++i)
  74560. {
  74561. table[0][i] = 0;
  74562. table[1][i] = i;
  74563. }
  74564. for (; i < maxGifCode; ++i)
  74565. {
  74566. table[0][i] = 0;
  74567. table[1][i] = 0;
  74568. }
  74569. codeSize = setCodeSize + 1;
  74570. maxCodeSize = 2 * clearCode;
  74571. maxCode = clearCode + 2;
  74572. sp = stack;
  74573. firstcode = oldcode = getCode (codeSize, false);
  74574. return firstcode;
  74575. }
  74576. else if (code == end_code)
  74577. {
  74578. if (dataBlockIsZero)
  74579. return -2;
  74580. unsigned char buf [260];
  74581. int n;
  74582. while ((n = readDataBlock (buf)) > 0)
  74583. {}
  74584. if (n != 0)
  74585. return -2;
  74586. }
  74587. incode = code;
  74588. if (code >= maxCode)
  74589. {
  74590. *sp++ = firstcode;
  74591. code = oldcode;
  74592. }
  74593. while (code >= clearCode)
  74594. {
  74595. *sp++ = table[1][code];
  74596. if (code == table[0][code])
  74597. return -2;
  74598. code = table[0][code];
  74599. }
  74600. *sp++ = firstcode = table[1][code];
  74601. if ((code = maxCode) < maxGifCode)
  74602. {
  74603. table[0][code] = oldcode;
  74604. table[1][code] = firstcode;
  74605. ++maxCode;
  74606. if ((maxCode >= maxCodeSize)
  74607. && (maxCodeSize < maxGifCode))
  74608. {
  74609. maxCodeSize <<= 1;
  74610. ++codeSize;
  74611. }
  74612. }
  74613. oldcode = incode;
  74614. if (sp > stack)
  74615. return *--sp;
  74616. }
  74617. return code;
  74618. }
  74619. bool GIFLoader::readImage (const int width, const int height,
  74620. const int interlace, const int transparent)
  74621. {
  74622. unsigned char c;
  74623. if (input.read (&c, 1) != 1
  74624. || readLZWByte (true, c) < 0)
  74625. return false;
  74626. if (transparent >= 0)
  74627. {
  74628. palette [transparent][0] = 0;
  74629. palette [transparent][1] = 0;
  74630. palette [transparent][2] = 0;
  74631. palette [transparent][3] = 0;
  74632. }
  74633. int index;
  74634. int xpos = 0, ypos = 0, pass = 0;
  74635. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74636. uint8* p = destData.data;
  74637. const bool hasAlpha = image->hasAlphaChannel();
  74638. while ((index = readLZWByte (false, c)) >= 0)
  74639. {
  74640. const uint8* const paletteEntry = palette [index];
  74641. if (hasAlpha)
  74642. {
  74643. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74644. paletteEntry[0],
  74645. paletteEntry[1],
  74646. paletteEntry[2]);
  74647. ((PixelARGB*) p)->premultiply();
  74648. }
  74649. else
  74650. {
  74651. ((PixelRGB*) p)->setARGB (0,
  74652. paletteEntry[0],
  74653. paletteEntry[1],
  74654. paletteEntry[2]);
  74655. }
  74656. p += destData.pixelStride;
  74657. ++xpos;
  74658. if (xpos == width)
  74659. {
  74660. xpos = 0;
  74661. if (interlace)
  74662. {
  74663. switch (pass)
  74664. {
  74665. case 0:
  74666. case 1:
  74667. ypos += 8;
  74668. break;
  74669. case 2:
  74670. ypos += 4;
  74671. break;
  74672. case 3:
  74673. ypos += 2;
  74674. break;
  74675. }
  74676. while (ypos >= height)
  74677. {
  74678. ++pass;
  74679. switch (pass)
  74680. {
  74681. case 1:
  74682. ypos = 4;
  74683. break;
  74684. case 2:
  74685. ypos = 2;
  74686. break;
  74687. case 3:
  74688. ypos = 1;
  74689. break;
  74690. default:
  74691. return true;
  74692. }
  74693. }
  74694. }
  74695. else
  74696. {
  74697. ++ypos;
  74698. }
  74699. p = destData.getPixelPointer (xpos, ypos);
  74700. }
  74701. if (ypos >= height)
  74702. break;
  74703. }
  74704. return true;
  74705. }
  74706. END_JUCE_NAMESPACE
  74707. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74708. #endif
  74709. //==============================================================================
  74710. // some files include lots of library code, so leave them to the end to avoid cluttering
  74711. // up the build for the clean files.
  74712. #if JUCE_BUILD_CORE
  74713. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74714. namespace zlibNamespace
  74715. {
  74716. #if JUCE_INCLUDE_ZLIB_CODE
  74717. #undef OS_CODE
  74718. #undef fdopen
  74719. /*** Start of inlined file: zlib.h ***/
  74720. #ifndef ZLIB_H
  74721. #define ZLIB_H
  74722. /*** Start of inlined file: zconf.h ***/
  74723. #ifndef ZCONF_H
  74724. #define ZCONF_H
  74725. // *** Just a few hacks here to make it compile nicely with Juce..
  74726. #define Z_PREFIX 1
  74727. #undef __MACTYPES__
  74728. #ifdef _MSC_VER
  74729. #pragma warning (disable : 4131 4127 4244 4267)
  74730. #endif
  74731. #ifdef Z_PREFIX
  74732. # define deflateInit_ z_deflateInit_
  74733. # define deflate z_deflate
  74734. # define deflateEnd z_deflateEnd
  74735. # define inflateInit_ z_inflateInit_
  74736. # define inflate z_inflate
  74737. # define inflateEnd z_inflateEnd
  74738. # define deflateInit2_ z_deflateInit2_
  74739. # define deflateSetDictionary z_deflateSetDictionary
  74740. # define deflateCopy z_deflateCopy
  74741. # define deflateReset z_deflateReset
  74742. # define deflateParams z_deflateParams
  74743. # define deflateBound z_deflateBound
  74744. # define deflatePrime z_deflatePrime
  74745. # define inflateInit2_ z_inflateInit2_
  74746. # define inflateSetDictionary z_inflateSetDictionary
  74747. # define inflateSync z_inflateSync
  74748. # define inflateSyncPoint z_inflateSyncPoint
  74749. # define inflateCopy z_inflateCopy
  74750. # define inflateReset z_inflateReset
  74751. # define inflateBack z_inflateBack
  74752. # define inflateBackEnd z_inflateBackEnd
  74753. # define compress z_compress
  74754. # define compress2 z_compress2
  74755. # define compressBound z_compressBound
  74756. # define uncompress z_uncompress
  74757. # define adler32 z_adler32
  74758. # define crc32 z_crc32
  74759. # define get_crc_table z_get_crc_table
  74760. # define zError z_zError
  74761. # define alloc_func z_alloc_func
  74762. # define free_func z_free_func
  74763. # define in_func z_in_func
  74764. # define out_func z_out_func
  74765. # define Byte z_Byte
  74766. # define uInt z_uInt
  74767. # define uLong z_uLong
  74768. # define Bytef z_Bytef
  74769. # define charf z_charf
  74770. # define intf z_intf
  74771. # define uIntf z_uIntf
  74772. # define uLongf z_uLongf
  74773. # define voidpf z_voidpf
  74774. # define voidp z_voidp
  74775. #endif
  74776. #if defined(__MSDOS__) && !defined(MSDOS)
  74777. # define MSDOS
  74778. #endif
  74779. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74780. # define OS2
  74781. #endif
  74782. #if defined(_WINDOWS) && !defined(WINDOWS)
  74783. # define WINDOWS
  74784. #endif
  74785. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74786. # ifndef WIN32
  74787. # define WIN32
  74788. # endif
  74789. #endif
  74790. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74791. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74792. # ifndef SYS16BIT
  74793. # define SYS16BIT
  74794. # endif
  74795. # endif
  74796. #endif
  74797. #ifdef SYS16BIT
  74798. # define MAXSEG_64K
  74799. #endif
  74800. #ifdef MSDOS
  74801. # define UNALIGNED_OK
  74802. #endif
  74803. #ifdef __STDC_VERSION__
  74804. # ifndef STDC
  74805. # define STDC
  74806. # endif
  74807. # if __STDC_VERSION__ >= 199901L
  74808. # ifndef STDC99
  74809. # define STDC99
  74810. # endif
  74811. # endif
  74812. #endif
  74813. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74814. # define STDC
  74815. #endif
  74816. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74817. # define STDC
  74818. #endif
  74819. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74820. # define STDC
  74821. #endif
  74822. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74823. # define STDC
  74824. #endif
  74825. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74826. # define STDC
  74827. #endif
  74828. #ifndef STDC
  74829. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74830. # define const /* note: need a more gentle solution here */
  74831. # endif
  74832. #endif
  74833. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74834. # define NO_DUMMY_DECL
  74835. #endif
  74836. #ifndef MAX_MEM_LEVEL
  74837. # ifdef MAXSEG_64K
  74838. # define MAX_MEM_LEVEL 8
  74839. # else
  74840. # define MAX_MEM_LEVEL 9
  74841. # endif
  74842. #endif
  74843. #ifndef MAX_WBITS
  74844. # define MAX_WBITS 15 /* 32K LZ77 window */
  74845. #endif
  74846. #ifndef OF /* function prototypes */
  74847. # ifdef STDC
  74848. # define OF(args) args
  74849. # else
  74850. # define OF(args) ()
  74851. # endif
  74852. #endif
  74853. #ifdef SYS16BIT
  74854. # if defined(M_I86SM) || defined(M_I86MM)
  74855. # define SMALL_MEDIUM
  74856. # ifdef _MSC_VER
  74857. # define FAR _far
  74858. # else
  74859. # define FAR far
  74860. # endif
  74861. # endif
  74862. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74863. # define SMALL_MEDIUM
  74864. # ifdef __BORLANDC__
  74865. # define FAR _far
  74866. # else
  74867. # define FAR far
  74868. # endif
  74869. # endif
  74870. #endif
  74871. #if defined(WINDOWS) || defined(WIN32)
  74872. # ifdef ZLIB_DLL
  74873. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74874. # ifdef ZLIB_INTERNAL
  74875. # define ZEXTERN extern __declspec(dllexport)
  74876. # else
  74877. # define ZEXTERN extern __declspec(dllimport)
  74878. # endif
  74879. # endif
  74880. # endif /* ZLIB_DLL */
  74881. # ifdef ZLIB_WINAPI
  74882. # ifdef FAR
  74883. # undef FAR
  74884. # endif
  74885. # include <windows.h>
  74886. # define ZEXPORT WINAPI
  74887. # ifdef WIN32
  74888. # define ZEXPORTVA WINAPIV
  74889. # else
  74890. # define ZEXPORTVA FAR CDECL
  74891. # endif
  74892. # endif
  74893. #endif
  74894. #if defined (__BEOS__)
  74895. # ifdef ZLIB_DLL
  74896. # ifdef ZLIB_INTERNAL
  74897. # define ZEXPORT __declspec(dllexport)
  74898. # define ZEXPORTVA __declspec(dllexport)
  74899. # else
  74900. # define ZEXPORT __declspec(dllimport)
  74901. # define ZEXPORTVA __declspec(dllimport)
  74902. # endif
  74903. # endif
  74904. #endif
  74905. #ifndef ZEXTERN
  74906. # define ZEXTERN extern
  74907. #endif
  74908. #ifndef ZEXPORT
  74909. # define ZEXPORT
  74910. #endif
  74911. #ifndef ZEXPORTVA
  74912. # define ZEXPORTVA
  74913. #endif
  74914. #ifndef FAR
  74915. # define FAR
  74916. #endif
  74917. #if !defined(__MACTYPES__)
  74918. typedef unsigned char Byte; /* 8 bits */
  74919. #endif
  74920. typedef unsigned int uInt; /* 16 bits or more */
  74921. typedef unsigned long uLong; /* 32 bits or more */
  74922. #ifdef SMALL_MEDIUM
  74923. # define Bytef Byte FAR
  74924. #else
  74925. typedef Byte FAR Bytef;
  74926. #endif
  74927. typedef char FAR charf;
  74928. typedef int FAR intf;
  74929. typedef uInt FAR uIntf;
  74930. typedef uLong FAR uLongf;
  74931. #ifdef STDC
  74932. typedef void const *voidpc;
  74933. typedef void FAR *voidpf;
  74934. typedef void *voidp;
  74935. #else
  74936. typedef Byte const *voidpc;
  74937. typedef Byte FAR *voidpf;
  74938. typedef Byte *voidp;
  74939. #endif
  74940. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  74941. # include <sys/types.h> /* for off_t */
  74942. # include <unistd.h> /* for SEEK_* and off_t */
  74943. # ifdef VMS
  74944. # include <unixio.h> /* for off_t */
  74945. # endif
  74946. # define z_off_t off_t
  74947. #endif
  74948. #ifndef SEEK_SET
  74949. # define SEEK_SET 0 /* Seek from beginning of file. */
  74950. # define SEEK_CUR 1 /* Seek from current position. */
  74951. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  74952. #endif
  74953. #ifndef z_off_t
  74954. # define z_off_t long
  74955. #endif
  74956. #if defined(__OS400__)
  74957. # define NO_vsnprintf
  74958. #endif
  74959. #if defined(__MVS__)
  74960. # define NO_vsnprintf
  74961. # ifdef FAR
  74962. # undef FAR
  74963. # endif
  74964. #endif
  74965. #if defined(__MVS__)
  74966. # pragma map(deflateInit_,"DEIN")
  74967. # pragma map(deflateInit2_,"DEIN2")
  74968. # pragma map(deflateEnd,"DEEND")
  74969. # pragma map(deflateBound,"DEBND")
  74970. # pragma map(inflateInit_,"ININ")
  74971. # pragma map(inflateInit2_,"ININ2")
  74972. # pragma map(inflateEnd,"INEND")
  74973. # pragma map(inflateSync,"INSY")
  74974. # pragma map(inflateSetDictionary,"INSEDI")
  74975. # pragma map(compressBound,"CMBND")
  74976. # pragma map(inflate_table,"INTABL")
  74977. # pragma map(inflate_fast,"INFA")
  74978. # pragma map(inflate_copyright,"INCOPY")
  74979. #endif
  74980. #endif /* ZCONF_H */
  74981. /*** End of inlined file: zconf.h ***/
  74982. #ifdef __cplusplus
  74983. extern "C" {
  74984. #endif
  74985. #define ZLIB_VERSION "1.2.3"
  74986. #define ZLIB_VERNUM 0x1230
  74987. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  74988. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  74989. struct internal_state;
  74990. typedef struct z_stream_s {
  74991. Bytef *next_in; /* next input byte */
  74992. uInt avail_in; /* number of bytes available at next_in */
  74993. uLong total_in; /* total nb of input bytes read so far */
  74994. Bytef *next_out; /* next output byte should be put there */
  74995. uInt avail_out; /* remaining free space at next_out */
  74996. uLong total_out; /* total nb of bytes output so far */
  74997. char *msg; /* last error message, NULL if no error */
  74998. struct internal_state FAR *state; /* not visible by applications */
  74999. alloc_func zalloc; /* used to allocate the internal state */
  75000. free_func zfree; /* used to free the internal state */
  75001. voidpf opaque; /* private data object passed to zalloc and zfree */
  75002. int data_type; /* best guess about the data type: binary or text */
  75003. uLong adler; /* adler32 value of the uncompressed data */
  75004. uLong reserved; /* reserved for future use */
  75005. } z_stream;
  75006. typedef z_stream FAR *z_streamp;
  75007. typedef struct gz_header_s {
  75008. int text; /* true if compressed data believed to be text */
  75009. uLong time; /* modification time */
  75010. int xflags; /* extra flags (not used when writing a gzip file) */
  75011. int os; /* operating system */
  75012. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75013. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75014. uInt extra_max; /* space at extra (only when reading header) */
  75015. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75016. uInt name_max; /* space at name (only when reading header) */
  75017. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75018. uInt comm_max; /* space at comment (only when reading header) */
  75019. int hcrc; /* true if there was or will be a header crc */
  75020. int done; /* true when done reading gzip header (not used
  75021. when writing a gzip file) */
  75022. } gz_header;
  75023. typedef gz_header FAR *gz_headerp;
  75024. #define Z_NO_FLUSH 0
  75025. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75026. #define Z_SYNC_FLUSH 2
  75027. #define Z_FULL_FLUSH 3
  75028. #define Z_FINISH 4
  75029. #define Z_BLOCK 5
  75030. #define Z_OK 0
  75031. #define Z_STREAM_END 1
  75032. #define Z_NEED_DICT 2
  75033. #define Z_ERRNO (-1)
  75034. #define Z_STREAM_ERROR (-2)
  75035. #define Z_DATA_ERROR (-3)
  75036. #define Z_MEM_ERROR (-4)
  75037. #define Z_BUF_ERROR (-5)
  75038. #define Z_VERSION_ERROR (-6)
  75039. #define Z_NO_COMPRESSION 0
  75040. #define Z_BEST_SPEED 1
  75041. #define Z_BEST_COMPRESSION 9
  75042. #define Z_DEFAULT_COMPRESSION (-1)
  75043. #define Z_FILTERED 1
  75044. #define Z_HUFFMAN_ONLY 2
  75045. #define Z_RLE 3
  75046. #define Z_FIXED 4
  75047. #define Z_DEFAULT_STRATEGY 0
  75048. #define Z_BINARY 0
  75049. #define Z_TEXT 1
  75050. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75051. #define Z_UNKNOWN 2
  75052. #define Z_DEFLATED 8
  75053. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75054. #define zlib_version zlibVersion()
  75055. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75056. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75057. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75058. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75059. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75060. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75061. const Bytef *dictionary,
  75062. uInt dictLength));
  75063. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75064. z_streamp source));
  75065. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75066. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75067. int level,
  75068. int strategy));
  75069. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75070. int good_length,
  75071. int max_lazy,
  75072. int nice_length,
  75073. int max_chain));
  75074. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75075. uLong sourceLen));
  75076. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75077. int bits,
  75078. int value));
  75079. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75080. gz_headerp head));
  75081. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75082. const Bytef *dictionary,
  75083. uInt dictLength));
  75084. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75085. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75086. z_streamp source));
  75087. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75088. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75089. int bits,
  75090. int value));
  75091. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75092. gz_headerp head));
  75093. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75094. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75095. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75096. in_func in, void FAR *in_desc,
  75097. out_func out, void FAR *out_desc));
  75098. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75099. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75100. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75101. const Bytef *source, uLong sourceLen));
  75102. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75103. const Bytef *source, uLong sourceLen,
  75104. int level));
  75105. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75106. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75107. const Bytef *source, uLong sourceLen));
  75108. typedef voidp gzFile;
  75109. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75110. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75111. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75112. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75113. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75114. voidpc buf, unsigned len));
  75115. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75116. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75117. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75118. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75119. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75120. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75121. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75122. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75123. z_off_t offset, int whence));
  75124. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75125. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75126. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75127. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75128. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75129. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75130. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75131. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75132. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75133. z_off_t len2));
  75134. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75135. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75136. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75137. const char *version, int stream_size));
  75138. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75139. const char *version, int stream_size));
  75140. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75141. int windowBits, int memLevel,
  75142. int strategy, const char *version,
  75143. int stream_size));
  75144. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75145. const char *version, int stream_size));
  75146. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75147. unsigned char FAR *window,
  75148. const char *version,
  75149. int stream_size));
  75150. #define deflateInit(strm, level) \
  75151. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75152. #define inflateInit(strm) \
  75153. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75154. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75155. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75156. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75157. #define inflateInit2(strm, windowBits) \
  75158. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75159. #define inflateBackInit(strm, windowBits, window) \
  75160. inflateBackInit_((strm), (windowBits), (window), \
  75161. ZLIB_VERSION, sizeof(z_stream))
  75162. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75163. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75164. #endif
  75165. ZEXTERN const char * ZEXPORT zError OF((int));
  75166. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75167. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75168. #ifdef __cplusplus
  75169. }
  75170. #endif
  75171. #endif /* ZLIB_H */
  75172. /*** End of inlined file: zlib.h ***/
  75173. #undef OS_CODE
  75174. #else
  75175. #include <zlib.h>
  75176. #endif
  75177. }
  75178. BEGIN_JUCE_NAMESPACE
  75179. // internal helper object that holds the zlib structures so they don't have to be
  75180. // included publicly.
  75181. class GZIPCompressorHelper
  75182. {
  75183. public:
  75184. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75185. : data (0),
  75186. dataSize (0),
  75187. compLevel (compressionLevel),
  75188. strategy (0),
  75189. setParams (true),
  75190. streamIsValid (false),
  75191. finished (false),
  75192. shouldFinish (false)
  75193. {
  75194. using namespace zlibNamespace;
  75195. zerostruct (stream);
  75196. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75197. nowrap ? -MAX_WBITS : MAX_WBITS,
  75198. 8, strategy) == Z_OK);
  75199. }
  75200. ~GZIPCompressorHelper()
  75201. {
  75202. using namespace zlibNamespace;
  75203. if (streamIsValid)
  75204. deflateEnd (&stream);
  75205. }
  75206. bool needsInput() const throw()
  75207. {
  75208. return dataSize <= 0;
  75209. }
  75210. void setInput (uint8* const newData, const int size) throw()
  75211. {
  75212. data = newData;
  75213. dataSize = size;
  75214. }
  75215. int doNextBlock (uint8* const dest, const int destSize) throw()
  75216. {
  75217. using namespace zlibNamespace;
  75218. if (streamIsValid)
  75219. {
  75220. stream.next_in = data;
  75221. stream.next_out = dest;
  75222. stream.avail_in = dataSize;
  75223. stream.avail_out = destSize;
  75224. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75225. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75226. setParams = false;
  75227. switch (result)
  75228. {
  75229. case Z_STREAM_END:
  75230. finished = true;
  75231. // Deliberate fall-through..
  75232. case Z_OK:
  75233. data += dataSize - stream.avail_in;
  75234. dataSize = stream.avail_in;
  75235. return destSize - stream.avail_out;
  75236. default:
  75237. break;
  75238. }
  75239. }
  75240. return 0;
  75241. }
  75242. private:
  75243. zlibNamespace::z_stream stream;
  75244. uint8* data;
  75245. int dataSize, compLevel, strategy;
  75246. bool setParams, streamIsValid;
  75247. public:
  75248. bool finished, shouldFinish;
  75249. };
  75250. const int gzipCompBufferSize = 32768;
  75251. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75252. int compressionLevel,
  75253. const bool deleteDestStream,
  75254. const bool noWrap)
  75255. : destStream (destStream_),
  75256. streamToDelete (deleteDestStream ? destStream_ : 0),
  75257. buffer (gzipCompBufferSize)
  75258. {
  75259. if (compressionLevel < 1 || compressionLevel > 9)
  75260. compressionLevel = -1;
  75261. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75262. }
  75263. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75264. {
  75265. flush();
  75266. }
  75267. void GZIPCompressorOutputStream::flush()
  75268. {
  75269. if (! helper->finished)
  75270. {
  75271. helper->shouldFinish = true;
  75272. while (! helper->finished)
  75273. doNextBlock();
  75274. }
  75275. destStream->flush();
  75276. }
  75277. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75278. {
  75279. if (! helper->finished)
  75280. {
  75281. helper->setInput ((uint8*) destBuffer, howMany);
  75282. while (! helper->needsInput())
  75283. {
  75284. if (! doNextBlock())
  75285. return false;
  75286. }
  75287. }
  75288. return true;
  75289. }
  75290. bool GZIPCompressorOutputStream::doNextBlock()
  75291. {
  75292. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75293. if (len > 0)
  75294. return destStream->write (buffer, len);
  75295. else
  75296. return true;
  75297. }
  75298. int64 GZIPCompressorOutputStream::getPosition()
  75299. {
  75300. return destStream->getPosition();
  75301. }
  75302. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75303. {
  75304. jassertfalse // can't do it!
  75305. return false;
  75306. }
  75307. END_JUCE_NAMESPACE
  75308. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75309. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75310. #if JUCE_MSVC
  75311. #pragma warning (push)
  75312. #pragma warning (disable: 4309 4305)
  75313. #endif
  75314. namespace zlibNamespace
  75315. {
  75316. #if JUCE_INCLUDE_ZLIB_CODE
  75317. extern "C"
  75318. {
  75319. #undef OS_CODE
  75320. #undef fdopen
  75321. #define ZLIB_INTERNAL
  75322. #define NO_DUMMY_DECL
  75323. /*** Start of inlined file: adler32.c ***/
  75324. #define ZLIB_INTERNAL
  75325. #define BASE 65521UL /* largest prime smaller than 65536 */
  75326. #define NMAX 5552
  75327. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75328. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75329. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75330. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75331. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75332. #ifdef NO_DIVIDE
  75333. # define MOD(a) \
  75334. do { \
  75335. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75336. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75337. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75338. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75339. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75340. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75341. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75342. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75343. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75344. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75345. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75346. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75347. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75348. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75349. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75350. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75351. if (a >= BASE) a -= BASE; \
  75352. } while (0)
  75353. # define MOD4(a) \
  75354. do { \
  75355. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75356. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75357. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75358. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75359. if (a >= BASE) a -= BASE; \
  75360. } while (0)
  75361. #else
  75362. # define MOD(a) a %= BASE
  75363. # define MOD4(a) a %= BASE
  75364. #endif
  75365. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75366. {
  75367. unsigned long sum2;
  75368. unsigned n;
  75369. sum2 = (adler >> 16) & 0xffff;
  75370. adler &= 0xffff;
  75371. if (len == 1) {
  75372. adler += buf[0];
  75373. if (adler >= BASE)
  75374. adler -= BASE;
  75375. sum2 += adler;
  75376. if (sum2 >= BASE)
  75377. sum2 -= BASE;
  75378. return adler | (sum2 << 16);
  75379. }
  75380. if (buf == Z_NULL)
  75381. return 1L;
  75382. if (len < 16) {
  75383. while (len--) {
  75384. adler += *buf++;
  75385. sum2 += adler;
  75386. }
  75387. if (adler >= BASE)
  75388. adler -= BASE;
  75389. MOD4(sum2); /* only added so many BASE's */
  75390. return adler | (sum2 << 16);
  75391. }
  75392. while (len >= NMAX) {
  75393. len -= NMAX;
  75394. n = NMAX / 16; /* NMAX is divisible by 16 */
  75395. do {
  75396. DO16(buf); /* 16 sums unrolled */
  75397. buf += 16;
  75398. } while (--n);
  75399. MOD(adler);
  75400. MOD(sum2);
  75401. }
  75402. if (len) { /* avoid modulos if none remaining */
  75403. while (len >= 16) {
  75404. len -= 16;
  75405. DO16(buf);
  75406. buf += 16;
  75407. }
  75408. while (len--) {
  75409. adler += *buf++;
  75410. sum2 += adler;
  75411. }
  75412. MOD(adler);
  75413. MOD(sum2);
  75414. }
  75415. return adler | (sum2 << 16);
  75416. }
  75417. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75418. {
  75419. unsigned long sum1;
  75420. unsigned long sum2;
  75421. unsigned rem;
  75422. rem = (unsigned)(len2 % BASE);
  75423. sum1 = adler1 & 0xffff;
  75424. sum2 = rem * sum1;
  75425. MOD(sum2);
  75426. sum1 += (adler2 & 0xffff) + BASE - 1;
  75427. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75428. if (sum1 > BASE) sum1 -= BASE;
  75429. if (sum1 > BASE) sum1 -= BASE;
  75430. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75431. if (sum2 > BASE) sum2 -= BASE;
  75432. return sum1 | (sum2 << 16);
  75433. }
  75434. /*** End of inlined file: adler32.c ***/
  75435. /*** Start of inlined file: compress.c ***/
  75436. #define ZLIB_INTERNAL
  75437. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75438. uLong sourceLen, int level)
  75439. {
  75440. z_stream stream;
  75441. int err;
  75442. stream.next_in = (Bytef*)source;
  75443. stream.avail_in = (uInt)sourceLen;
  75444. #ifdef MAXSEG_64K
  75445. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75446. #endif
  75447. stream.next_out = dest;
  75448. stream.avail_out = (uInt)*destLen;
  75449. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75450. stream.zalloc = (alloc_func)0;
  75451. stream.zfree = (free_func)0;
  75452. stream.opaque = (voidpf)0;
  75453. err = deflateInit(&stream, level);
  75454. if (err != Z_OK) return err;
  75455. err = deflate(&stream, Z_FINISH);
  75456. if (err != Z_STREAM_END) {
  75457. deflateEnd(&stream);
  75458. return err == Z_OK ? Z_BUF_ERROR : err;
  75459. }
  75460. *destLen = stream.total_out;
  75461. err = deflateEnd(&stream);
  75462. return err;
  75463. }
  75464. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75465. {
  75466. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75467. }
  75468. uLong ZEXPORT compressBound (uLong sourceLen)
  75469. {
  75470. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75471. }
  75472. /*** End of inlined file: compress.c ***/
  75473. #undef DO1
  75474. #undef DO8
  75475. /*** Start of inlined file: crc32.c ***/
  75476. #ifdef MAKECRCH
  75477. # include <stdio.h>
  75478. # ifndef DYNAMIC_CRC_TABLE
  75479. # define DYNAMIC_CRC_TABLE
  75480. # endif /* !DYNAMIC_CRC_TABLE */
  75481. #endif /* MAKECRCH */
  75482. /*** Start of inlined file: zutil.h ***/
  75483. #ifndef ZUTIL_H
  75484. #define ZUTIL_H
  75485. #define ZLIB_INTERNAL
  75486. #ifdef STDC
  75487. # ifndef _WIN32_WCE
  75488. # include <stddef.h>
  75489. # endif
  75490. # include <string.h>
  75491. # include <stdlib.h>
  75492. #endif
  75493. #ifdef NO_ERRNO_H
  75494. # ifdef _WIN32_WCE
  75495. # define errno z_errno
  75496. # endif
  75497. extern int errno;
  75498. #else
  75499. # ifndef _WIN32_WCE
  75500. # include <errno.h>
  75501. # endif
  75502. #endif
  75503. #ifndef local
  75504. # define local static
  75505. #endif
  75506. typedef unsigned char uch;
  75507. typedef uch FAR uchf;
  75508. typedef unsigned short ush;
  75509. typedef ush FAR ushf;
  75510. typedef unsigned long ulg;
  75511. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75512. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75513. #define ERR_RETURN(strm,err) \
  75514. return (strm->msg = (char*)ERR_MSG(err), (err))
  75515. #ifndef DEF_WBITS
  75516. # define DEF_WBITS MAX_WBITS
  75517. #endif
  75518. #if MAX_MEM_LEVEL >= 8
  75519. # define DEF_MEM_LEVEL 8
  75520. #else
  75521. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75522. #endif
  75523. #define STORED_BLOCK 0
  75524. #define STATIC_TREES 1
  75525. #define DYN_TREES 2
  75526. #define MIN_MATCH 3
  75527. #define MAX_MATCH 258
  75528. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75529. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75530. # define OS_CODE 0x00
  75531. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75532. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75533. void _Cdecl farfree( void *block );
  75534. void *_Cdecl farmalloc( unsigned long nbytes );
  75535. # else
  75536. # include <alloc.h>
  75537. # endif
  75538. # else /* MSC or DJGPP */
  75539. # include <malloc.h>
  75540. # endif
  75541. #endif
  75542. #ifdef AMIGA
  75543. # define OS_CODE 0x01
  75544. #endif
  75545. #if defined(VAXC) || defined(VMS)
  75546. # define OS_CODE 0x02
  75547. # define F_OPEN(name, mode) \
  75548. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75549. #endif
  75550. #if defined(ATARI) || defined(atarist)
  75551. # define OS_CODE 0x05
  75552. #endif
  75553. #ifdef OS2
  75554. # define OS_CODE 0x06
  75555. # ifdef M_I86
  75556. #include <malloc.h>
  75557. # endif
  75558. #endif
  75559. #if defined(MACOS) || TARGET_OS_MAC
  75560. # define OS_CODE 0x07
  75561. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75562. # include <unix.h> /* for fdopen */
  75563. # else
  75564. # ifndef fdopen
  75565. # define fdopen(fd,mode) NULL /* No fdopen() */
  75566. # endif
  75567. # endif
  75568. #endif
  75569. #ifdef TOPS20
  75570. # define OS_CODE 0x0a
  75571. #endif
  75572. #ifdef WIN32
  75573. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75574. # define OS_CODE 0x0b
  75575. # endif
  75576. #endif
  75577. #ifdef __50SERIES /* Prime/PRIMOS */
  75578. # define OS_CODE 0x0f
  75579. #endif
  75580. #if defined(_BEOS_) || defined(RISCOS)
  75581. # define fdopen(fd,mode) NULL /* No fdopen() */
  75582. #endif
  75583. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75584. # if defined(_WIN32_WCE)
  75585. # define fdopen(fd,mode) NULL /* No fdopen() */
  75586. # ifndef _PTRDIFF_T_DEFINED
  75587. typedef int ptrdiff_t;
  75588. # define _PTRDIFF_T_DEFINED
  75589. # endif
  75590. # else
  75591. # define fdopen(fd,type) _fdopen(fd,type)
  75592. # endif
  75593. #endif
  75594. #ifndef OS_CODE
  75595. # define OS_CODE 0x03 /* assume Unix */
  75596. #endif
  75597. #ifndef F_OPEN
  75598. # define F_OPEN(name, mode) fopen((name), (mode))
  75599. #endif
  75600. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75601. # ifndef HAVE_VSNPRINTF
  75602. # define HAVE_VSNPRINTF
  75603. # endif
  75604. #endif
  75605. #if defined(__CYGWIN__)
  75606. # ifndef HAVE_VSNPRINTF
  75607. # define HAVE_VSNPRINTF
  75608. # endif
  75609. #endif
  75610. #ifndef HAVE_VSNPRINTF
  75611. # ifdef MSDOS
  75612. # define NO_vsnprintf
  75613. # endif
  75614. # ifdef __TURBOC__
  75615. # define NO_vsnprintf
  75616. # endif
  75617. # ifdef WIN32
  75618. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75619. # define vsnprintf _vsnprintf
  75620. # endif
  75621. # endif
  75622. # ifdef __SASC
  75623. # define NO_vsnprintf
  75624. # endif
  75625. #endif
  75626. #ifdef VMS
  75627. # define NO_vsnprintf
  75628. #endif
  75629. #if defined(pyr)
  75630. # define NO_MEMCPY
  75631. #endif
  75632. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75633. # define NO_MEMCPY
  75634. #endif
  75635. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75636. # define HAVE_MEMCPY
  75637. #endif
  75638. #ifdef HAVE_MEMCPY
  75639. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75640. # define zmemcpy _fmemcpy
  75641. # define zmemcmp _fmemcmp
  75642. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75643. # else
  75644. # define zmemcpy memcpy
  75645. # define zmemcmp memcmp
  75646. # define zmemzero(dest, len) memset(dest, 0, len)
  75647. # endif
  75648. #else
  75649. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75650. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75651. extern void zmemzero OF((Bytef* dest, uInt len));
  75652. #endif
  75653. #ifdef DEBUG
  75654. # include <stdio.h>
  75655. extern int z_verbose;
  75656. extern void z_error OF((const char *m));
  75657. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75658. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75659. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75660. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75661. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75662. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75663. #else
  75664. # define Assert(cond,msg)
  75665. # define Trace(x)
  75666. # define Tracev(x)
  75667. # define Tracevv(x)
  75668. # define Tracec(c,x)
  75669. # define Tracecv(c,x)
  75670. #endif
  75671. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75672. void zcfree OF((voidpf opaque, voidpf ptr));
  75673. #define ZALLOC(strm, items, size) \
  75674. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75675. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75676. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75677. #endif /* ZUTIL_H */
  75678. /*** End of inlined file: zutil.h ***/
  75679. /* for STDC and FAR definitions */
  75680. #define local static
  75681. #ifndef NOBYFOUR
  75682. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75683. # include <limits.h>
  75684. # define BYFOUR
  75685. # if (UINT_MAX == 0xffffffffUL)
  75686. typedef unsigned int u4;
  75687. # else
  75688. # if (ULONG_MAX == 0xffffffffUL)
  75689. typedef unsigned long u4;
  75690. # else
  75691. # if (USHRT_MAX == 0xffffffffUL)
  75692. typedef unsigned short u4;
  75693. # else
  75694. # undef BYFOUR /* can't find a four-byte integer type! */
  75695. # endif
  75696. # endif
  75697. # endif
  75698. # endif /* STDC */
  75699. #endif /* !NOBYFOUR */
  75700. #ifdef BYFOUR
  75701. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75702. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75703. local unsigned long crc32_little OF((unsigned long,
  75704. const unsigned char FAR *, unsigned));
  75705. local unsigned long crc32_big OF((unsigned long,
  75706. const unsigned char FAR *, unsigned));
  75707. # define TBLS 8
  75708. #else
  75709. # define TBLS 1
  75710. #endif /* BYFOUR */
  75711. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75712. unsigned long vec));
  75713. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75714. #ifdef DYNAMIC_CRC_TABLE
  75715. local volatile int crc_table_empty = 1;
  75716. local unsigned long FAR crc_table[TBLS][256];
  75717. local void make_crc_table OF((void));
  75718. #ifdef MAKECRCH
  75719. local void write_table OF((FILE *, const unsigned long FAR *));
  75720. #endif /* MAKECRCH */
  75721. local void make_crc_table()
  75722. {
  75723. unsigned long c;
  75724. int n, k;
  75725. unsigned long poly; /* polynomial exclusive-or pattern */
  75726. static volatile int first = 1; /* flag to limit concurrent making */
  75727. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75728. if (first) {
  75729. first = 0;
  75730. poly = 0UL;
  75731. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75732. poly |= 1UL << (31 - p[n]);
  75733. for (n = 0; n < 256; n++) {
  75734. c = (unsigned long)n;
  75735. for (k = 0; k < 8; k++)
  75736. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75737. crc_table[0][n] = c;
  75738. }
  75739. #ifdef BYFOUR
  75740. for (n = 0; n < 256; n++) {
  75741. c = crc_table[0][n];
  75742. crc_table[4][n] = REV(c);
  75743. for (k = 1; k < 4; k++) {
  75744. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75745. crc_table[k][n] = c;
  75746. crc_table[k + 4][n] = REV(c);
  75747. }
  75748. }
  75749. #endif /* BYFOUR */
  75750. crc_table_empty = 0;
  75751. }
  75752. else { /* not first */
  75753. while (crc_table_empty)
  75754. ;
  75755. }
  75756. #ifdef MAKECRCH
  75757. {
  75758. FILE *out;
  75759. out = fopen("crc32.h", "w");
  75760. if (out == NULL) return;
  75761. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75762. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75763. fprintf(out, "local const unsigned long FAR ");
  75764. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75765. write_table(out, crc_table[0]);
  75766. # ifdef BYFOUR
  75767. fprintf(out, "#ifdef BYFOUR\n");
  75768. for (k = 1; k < 8; k++) {
  75769. fprintf(out, " },\n {\n");
  75770. write_table(out, crc_table[k]);
  75771. }
  75772. fprintf(out, "#endif\n");
  75773. # endif /* BYFOUR */
  75774. fprintf(out, " }\n};\n");
  75775. fclose(out);
  75776. }
  75777. #endif /* MAKECRCH */
  75778. }
  75779. #ifdef MAKECRCH
  75780. local void write_table(out, table)
  75781. FILE *out;
  75782. const unsigned long FAR *table;
  75783. {
  75784. int n;
  75785. for (n = 0; n < 256; n++)
  75786. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75787. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75788. }
  75789. #endif /* MAKECRCH */
  75790. #else /* !DYNAMIC_CRC_TABLE */
  75791. /*** Start of inlined file: crc32.h ***/
  75792. local const unsigned long FAR crc_table[TBLS][256] =
  75793. {
  75794. {
  75795. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75796. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75797. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75798. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75799. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75800. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75801. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75802. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75803. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75804. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75805. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75806. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75807. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75808. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75809. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75810. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75811. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75812. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75813. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75814. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75815. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75816. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75817. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75818. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75819. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75820. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75821. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75822. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75823. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75824. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75825. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75826. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75827. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75828. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75829. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75830. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75831. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75832. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75833. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75834. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75835. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75836. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75837. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75838. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75839. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75840. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75841. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75842. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75843. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75844. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75845. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75846. 0x2d02ef8dUL
  75847. #ifdef BYFOUR
  75848. },
  75849. {
  75850. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75851. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75852. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75853. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75854. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75855. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75856. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75857. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75858. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75859. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75860. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75861. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75862. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75863. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75864. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75865. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75866. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75867. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75868. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75869. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75870. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75871. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75872. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75873. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75874. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75875. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75876. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75877. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75878. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75879. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75880. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75881. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75882. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75883. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75884. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75885. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75886. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75887. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75888. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75889. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75890. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75891. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  75892. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  75893. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  75894. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  75895. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  75896. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  75897. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  75898. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  75899. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  75900. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  75901. 0x9324fd72UL
  75902. },
  75903. {
  75904. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  75905. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  75906. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  75907. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  75908. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  75909. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  75910. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  75911. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  75912. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  75913. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  75914. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  75915. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  75916. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  75917. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  75918. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  75919. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  75920. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  75921. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  75922. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  75923. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  75924. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  75925. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  75926. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  75927. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  75928. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  75929. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  75930. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  75931. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  75932. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  75933. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  75934. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  75935. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  75936. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  75937. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  75938. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  75939. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  75940. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  75941. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  75942. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  75943. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  75944. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  75945. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  75946. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  75947. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  75948. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  75949. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  75950. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  75951. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  75952. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  75953. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  75954. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  75955. 0xbe9834edUL
  75956. },
  75957. {
  75958. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  75959. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  75960. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  75961. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  75962. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  75963. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  75964. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  75965. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  75966. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  75967. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  75968. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  75969. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  75970. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  75971. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  75972. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  75973. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  75974. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  75975. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  75976. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  75977. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  75978. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  75979. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  75980. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  75981. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  75982. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  75983. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  75984. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  75985. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  75986. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  75987. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  75988. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  75989. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  75990. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  75991. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  75992. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  75993. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  75994. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  75995. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  75996. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  75997. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  75998. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  75999. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76000. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76001. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76002. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76003. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76004. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76005. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76006. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76007. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76008. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76009. 0xde0506f1UL
  76010. },
  76011. {
  76012. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76013. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76014. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76015. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76016. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76017. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76018. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76019. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76020. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76021. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76022. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76023. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76024. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76025. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76026. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76027. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76028. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76029. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76030. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76031. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76032. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76033. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76034. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76035. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76036. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76037. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76038. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76039. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76040. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76041. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76042. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76043. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76044. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76045. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76046. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76047. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76048. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76049. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76050. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76051. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76052. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76053. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76054. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76055. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76056. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76057. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76058. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76059. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76060. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76061. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76062. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76063. 0x8def022dUL
  76064. },
  76065. {
  76066. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76067. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76068. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76069. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76070. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76071. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76072. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76073. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76074. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76075. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76076. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76077. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76078. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76079. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76080. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76081. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76082. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76083. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76084. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76085. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76086. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76087. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76088. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76089. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76090. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76091. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76092. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76093. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76094. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76095. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76096. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76097. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76098. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76099. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76100. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76101. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76102. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76103. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76104. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76105. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76106. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76107. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76108. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76109. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76110. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76111. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76112. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76113. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76114. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76115. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76116. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76117. 0x72fd2493UL
  76118. },
  76119. {
  76120. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76121. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76122. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76123. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76124. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76125. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76126. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76127. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76128. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76129. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76130. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76131. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76132. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76133. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76134. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76135. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76136. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76137. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76138. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76139. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76140. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76141. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76142. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76143. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76144. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76145. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76146. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76147. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76148. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76149. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76150. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76151. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76152. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76153. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76154. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76155. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76156. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76157. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76158. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76159. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76160. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76161. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76162. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76163. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76164. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76165. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76166. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76167. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76168. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76169. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76170. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76171. 0xed3498beUL
  76172. },
  76173. {
  76174. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76175. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76176. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76177. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76178. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76179. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76180. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76181. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76182. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76183. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76184. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76185. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76186. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76187. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76188. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76189. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76190. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76191. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76192. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76193. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76194. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76195. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76196. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76197. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76198. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76199. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76200. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76201. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76202. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76203. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76204. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76205. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76206. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76207. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76208. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76209. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76210. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76211. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76212. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76213. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76214. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76215. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76216. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76217. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76218. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76219. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76220. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76221. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76222. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76223. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76224. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76225. 0xf10605deUL
  76226. #endif
  76227. }
  76228. };
  76229. /*** End of inlined file: crc32.h ***/
  76230. #endif /* DYNAMIC_CRC_TABLE */
  76231. const unsigned long FAR * ZEXPORT get_crc_table()
  76232. {
  76233. #ifdef DYNAMIC_CRC_TABLE
  76234. if (crc_table_empty)
  76235. make_crc_table();
  76236. #endif /* DYNAMIC_CRC_TABLE */
  76237. return (const unsigned long FAR *)crc_table;
  76238. }
  76239. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76240. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76241. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76242. {
  76243. if (buf == Z_NULL) return 0UL;
  76244. #ifdef DYNAMIC_CRC_TABLE
  76245. if (crc_table_empty)
  76246. make_crc_table();
  76247. #endif /* DYNAMIC_CRC_TABLE */
  76248. #ifdef BYFOUR
  76249. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76250. u4 endian;
  76251. endian = 1;
  76252. if (*((unsigned char *)(&endian)))
  76253. return crc32_little(crc, buf, len);
  76254. else
  76255. return crc32_big(crc, buf, len);
  76256. }
  76257. #endif /* BYFOUR */
  76258. crc = crc ^ 0xffffffffUL;
  76259. while (len >= 8) {
  76260. DO8;
  76261. len -= 8;
  76262. }
  76263. if (len) do {
  76264. DO1;
  76265. } while (--len);
  76266. return crc ^ 0xffffffffUL;
  76267. }
  76268. #ifdef BYFOUR
  76269. #define DOLIT4 c ^= *buf4++; \
  76270. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76271. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76272. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76273. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76274. {
  76275. register u4 c;
  76276. register const u4 FAR *buf4;
  76277. c = (u4)crc;
  76278. c = ~c;
  76279. while (len && ((ptrdiff_t)buf & 3)) {
  76280. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76281. len--;
  76282. }
  76283. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76284. while (len >= 32) {
  76285. DOLIT32;
  76286. len -= 32;
  76287. }
  76288. while (len >= 4) {
  76289. DOLIT4;
  76290. len -= 4;
  76291. }
  76292. buf = (const unsigned char FAR *)buf4;
  76293. if (len) do {
  76294. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76295. } while (--len);
  76296. c = ~c;
  76297. return (unsigned long)c;
  76298. }
  76299. #define DOBIG4 c ^= *++buf4; \
  76300. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76301. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76302. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76303. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76304. {
  76305. register u4 c;
  76306. register const u4 FAR *buf4;
  76307. c = REV((u4)crc);
  76308. c = ~c;
  76309. while (len && ((ptrdiff_t)buf & 3)) {
  76310. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76311. len--;
  76312. }
  76313. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76314. buf4--;
  76315. while (len >= 32) {
  76316. DOBIG32;
  76317. len -= 32;
  76318. }
  76319. while (len >= 4) {
  76320. DOBIG4;
  76321. len -= 4;
  76322. }
  76323. buf4++;
  76324. buf = (const unsigned char FAR *)buf4;
  76325. if (len) do {
  76326. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76327. } while (--len);
  76328. c = ~c;
  76329. return (unsigned long)(REV(c));
  76330. }
  76331. #endif /* BYFOUR */
  76332. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76333. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76334. {
  76335. unsigned long sum;
  76336. sum = 0;
  76337. while (vec) {
  76338. if (vec & 1)
  76339. sum ^= *mat;
  76340. vec >>= 1;
  76341. mat++;
  76342. }
  76343. return sum;
  76344. }
  76345. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76346. {
  76347. int n;
  76348. for (n = 0; n < GF2_DIM; n++)
  76349. square[n] = gf2_matrix_times(mat, mat[n]);
  76350. }
  76351. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76352. {
  76353. int n;
  76354. unsigned long row;
  76355. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76356. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76357. if (len2 == 0)
  76358. return crc1;
  76359. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76360. row = 1;
  76361. for (n = 1; n < GF2_DIM; n++) {
  76362. odd[n] = row;
  76363. row <<= 1;
  76364. }
  76365. gf2_matrix_square(even, odd);
  76366. gf2_matrix_square(odd, even);
  76367. do {
  76368. gf2_matrix_square(even, odd);
  76369. if (len2 & 1)
  76370. crc1 = gf2_matrix_times(even, crc1);
  76371. len2 >>= 1;
  76372. if (len2 == 0)
  76373. break;
  76374. gf2_matrix_square(odd, even);
  76375. if (len2 & 1)
  76376. crc1 = gf2_matrix_times(odd, crc1);
  76377. len2 >>= 1;
  76378. } while (len2 != 0);
  76379. crc1 ^= crc2;
  76380. return crc1;
  76381. }
  76382. /*** End of inlined file: crc32.c ***/
  76383. /*** Start of inlined file: deflate.c ***/
  76384. /*** Start of inlined file: deflate.h ***/
  76385. #ifndef DEFLATE_H
  76386. #define DEFLATE_H
  76387. #ifndef NO_GZIP
  76388. # define GZIP
  76389. #endif
  76390. #define NO_DUMMY_DECL
  76391. #define LENGTH_CODES 29
  76392. #define LITERALS 256
  76393. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76394. #define D_CODES 30
  76395. #define BL_CODES 19
  76396. #define HEAP_SIZE (2*L_CODES+1)
  76397. #define MAX_BITS 15
  76398. #define INIT_STATE 42
  76399. #define EXTRA_STATE 69
  76400. #define NAME_STATE 73
  76401. #define COMMENT_STATE 91
  76402. #define HCRC_STATE 103
  76403. #define BUSY_STATE 113
  76404. #define FINISH_STATE 666
  76405. typedef struct ct_data_s {
  76406. union {
  76407. ush freq; /* frequency count */
  76408. ush code; /* bit string */
  76409. } fc;
  76410. union {
  76411. ush dad; /* father node in Huffman tree */
  76412. ush len; /* length of bit string */
  76413. } dl;
  76414. } FAR ct_data;
  76415. #define Freq fc.freq
  76416. #define Code fc.code
  76417. #define Dad dl.dad
  76418. #define Len dl.len
  76419. typedef struct static_tree_desc_s static_tree_desc;
  76420. typedef struct tree_desc_s {
  76421. ct_data *dyn_tree; /* the dynamic tree */
  76422. int max_code; /* largest code with non zero frequency */
  76423. static_tree_desc *stat_desc; /* the corresponding static tree */
  76424. } FAR tree_desc;
  76425. typedef ush Pos;
  76426. typedef Pos FAR Posf;
  76427. typedef unsigned IPos;
  76428. typedef struct internal_state {
  76429. z_streamp strm; /* pointer back to this zlib stream */
  76430. int status; /* as the name implies */
  76431. Bytef *pending_buf; /* output still pending */
  76432. ulg pending_buf_size; /* size of pending_buf */
  76433. Bytef *pending_out; /* next pending byte to output to the stream */
  76434. uInt pending; /* nb of bytes in the pending buffer */
  76435. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76436. gz_headerp gzhead; /* gzip header information to write */
  76437. uInt gzindex; /* where in extra, name, or comment */
  76438. Byte method; /* STORED (for zip only) or DEFLATED */
  76439. int last_flush; /* value of flush param for previous deflate call */
  76440. uInt w_size; /* LZ77 window size (32K by default) */
  76441. uInt w_bits; /* log2(w_size) (8..16) */
  76442. uInt w_mask; /* w_size - 1 */
  76443. Bytef *window;
  76444. ulg window_size;
  76445. Posf *prev;
  76446. Posf *head; /* Heads of the hash chains or NIL. */
  76447. uInt ins_h; /* hash index of string to be inserted */
  76448. uInt hash_size; /* number of elements in hash table */
  76449. uInt hash_bits; /* log2(hash_size) */
  76450. uInt hash_mask; /* hash_size-1 */
  76451. uInt hash_shift;
  76452. long block_start;
  76453. uInt match_length; /* length of best match */
  76454. IPos prev_match; /* previous match */
  76455. int match_available; /* set if previous match exists */
  76456. uInt strstart; /* start of string to insert */
  76457. uInt match_start; /* start of matching string */
  76458. uInt lookahead; /* number of valid bytes ahead in window */
  76459. uInt prev_length;
  76460. uInt max_chain_length;
  76461. uInt max_lazy_match;
  76462. # define max_insert_length max_lazy_match
  76463. int level; /* compression level (1..9) */
  76464. int strategy; /* favor or force Huffman coding*/
  76465. uInt good_match;
  76466. int nice_match; /* Stop searching when current match exceeds this */
  76467. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76468. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76469. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76470. struct tree_desc_s l_desc; /* desc. for literal tree */
  76471. struct tree_desc_s d_desc; /* desc. for distance tree */
  76472. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76473. ush bl_count[MAX_BITS+1];
  76474. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76475. int heap_len; /* number of elements in the heap */
  76476. int heap_max; /* element of largest frequency */
  76477. uch depth[2*L_CODES+1];
  76478. uchf *l_buf; /* buffer for literals or lengths */
  76479. uInt lit_bufsize;
  76480. uInt last_lit; /* running index in l_buf */
  76481. ushf *d_buf;
  76482. ulg opt_len; /* bit length of current block with optimal trees */
  76483. ulg static_len; /* bit length of current block with static trees */
  76484. uInt matches; /* number of string matches in current block */
  76485. int last_eob_len; /* bit length of EOB code for last block */
  76486. #ifdef DEBUG
  76487. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76488. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76489. #endif
  76490. ush bi_buf;
  76491. int bi_valid;
  76492. } FAR deflate_state;
  76493. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76494. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76495. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76496. void _tr_init OF((deflate_state *s));
  76497. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76498. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76499. int eof));
  76500. void _tr_align OF((deflate_state *s));
  76501. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76502. int eof));
  76503. #define d_code(dist) \
  76504. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76505. #ifndef DEBUG
  76506. #if defined(GEN_TREES_H) || !defined(STDC)
  76507. extern uch _length_code[];
  76508. extern uch _dist_code[];
  76509. #else
  76510. extern const uch _length_code[];
  76511. extern const uch _dist_code[];
  76512. #endif
  76513. # define _tr_tally_lit(s, c, flush) \
  76514. { uch cc = (c); \
  76515. s->d_buf[s->last_lit] = 0; \
  76516. s->l_buf[s->last_lit++] = cc; \
  76517. s->dyn_ltree[cc].Freq++; \
  76518. flush = (s->last_lit == s->lit_bufsize-1); \
  76519. }
  76520. # define _tr_tally_dist(s, distance, length, flush) \
  76521. { uch len = (length); \
  76522. ush dist = (distance); \
  76523. s->d_buf[s->last_lit] = dist; \
  76524. s->l_buf[s->last_lit++] = len; \
  76525. dist--; \
  76526. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76527. s->dyn_dtree[d_code(dist)].Freq++; \
  76528. flush = (s->last_lit == s->lit_bufsize-1); \
  76529. }
  76530. #else
  76531. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76532. # define _tr_tally_dist(s, distance, length, flush) \
  76533. flush = _tr_tally(s, distance, length)
  76534. #endif
  76535. #endif /* DEFLATE_H */
  76536. /*** End of inlined file: deflate.h ***/
  76537. const char deflate_copyright[] =
  76538. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76539. typedef enum {
  76540. need_more, /* block not completed, need more input or more output */
  76541. block_done, /* block flush performed */
  76542. finish_started, /* finish started, need only more output at next deflate */
  76543. finish_done /* finish done, accept no more input or output */
  76544. } block_state;
  76545. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76546. local void fill_window OF((deflate_state *s));
  76547. local block_state deflate_stored OF((deflate_state *s, int flush));
  76548. local block_state deflate_fast OF((deflate_state *s, int flush));
  76549. #ifndef FASTEST
  76550. local block_state deflate_slow OF((deflate_state *s, int flush));
  76551. #endif
  76552. local void lm_init OF((deflate_state *s));
  76553. local void putShortMSB OF((deflate_state *s, uInt b));
  76554. local void flush_pending OF((z_streamp strm));
  76555. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76556. #ifndef FASTEST
  76557. #ifdef ASMV
  76558. void match_init OF((void)); /* asm code initialization */
  76559. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76560. #else
  76561. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76562. #endif
  76563. #endif
  76564. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76565. #ifdef DEBUG
  76566. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76567. int length));
  76568. #endif
  76569. #define NIL 0
  76570. #ifndef TOO_FAR
  76571. # define TOO_FAR 4096
  76572. #endif
  76573. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76574. typedef struct config_s {
  76575. ush good_length; /* reduce lazy search above this match length */
  76576. ush max_lazy; /* do not perform lazy search above this match length */
  76577. ush nice_length; /* quit search above this match length */
  76578. ush max_chain;
  76579. compress_func func;
  76580. } config;
  76581. #ifdef FASTEST
  76582. local const config configuration_table[2] = {
  76583. {0, 0, 0, 0, deflate_stored}, /* store only */
  76584. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76585. #else
  76586. local const config configuration_table[10] = {
  76587. {0, 0, 0, 0, deflate_stored}, /* store only */
  76588. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76589. {4, 5, 16, 8, deflate_fast},
  76590. {4, 6, 32, 32, deflate_fast},
  76591. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76592. {8, 16, 32, 32, deflate_slow},
  76593. {8, 16, 128, 128, deflate_slow},
  76594. {8, 32, 128, 256, deflate_slow},
  76595. {32, 128, 258, 1024, deflate_slow},
  76596. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76597. #endif
  76598. #define EQUAL 0
  76599. #ifndef NO_DUMMY_DECL
  76600. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76601. #endif
  76602. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76603. #ifdef FASTEST
  76604. #define INSERT_STRING(s, str, match_head) \
  76605. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76606. match_head = s->head[s->ins_h], \
  76607. s->head[s->ins_h] = (Pos)(str))
  76608. #else
  76609. #define INSERT_STRING(s, str, match_head) \
  76610. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76611. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76612. s->head[s->ins_h] = (Pos)(str))
  76613. #endif
  76614. #define CLEAR_HASH(s) \
  76615. s->head[s->hash_size-1] = NIL; \
  76616. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76617. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76618. {
  76619. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76620. Z_DEFAULT_STRATEGY, version, stream_size);
  76621. }
  76622. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76623. {
  76624. deflate_state *s;
  76625. int wrap = 1;
  76626. static const char my_version[] = ZLIB_VERSION;
  76627. ushf *overlay;
  76628. if (version == Z_NULL || version[0] != my_version[0] ||
  76629. stream_size != sizeof(z_stream)) {
  76630. return Z_VERSION_ERROR;
  76631. }
  76632. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76633. strm->msg = Z_NULL;
  76634. if (strm->zalloc == (alloc_func)0) {
  76635. strm->zalloc = zcalloc;
  76636. strm->opaque = (voidpf)0;
  76637. }
  76638. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76639. #ifdef FASTEST
  76640. if (level != 0) level = 1;
  76641. #else
  76642. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76643. #endif
  76644. if (windowBits < 0) { /* suppress zlib wrapper */
  76645. wrap = 0;
  76646. windowBits = -windowBits;
  76647. }
  76648. #ifdef GZIP
  76649. else if (windowBits > 15) {
  76650. wrap = 2; /* write gzip wrapper instead */
  76651. windowBits -= 16;
  76652. }
  76653. #endif
  76654. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76655. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76656. strategy < 0 || strategy > Z_FIXED) {
  76657. return Z_STREAM_ERROR;
  76658. }
  76659. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76660. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76661. if (s == Z_NULL) return Z_MEM_ERROR;
  76662. strm->state = (struct internal_state FAR *)s;
  76663. s->strm = strm;
  76664. s->wrap = wrap;
  76665. s->gzhead = Z_NULL;
  76666. s->w_bits = windowBits;
  76667. s->w_size = 1 << s->w_bits;
  76668. s->w_mask = s->w_size - 1;
  76669. s->hash_bits = memLevel + 7;
  76670. s->hash_size = 1 << s->hash_bits;
  76671. s->hash_mask = s->hash_size - 1;
  76672. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76673. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76674. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76675. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76676. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76677. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76678. s->pending_buf = (uchf *) overlay;
  76679. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76680. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76681. s->pending_buf == Z_NULL) {
  76682. s->status = FINISH_STATE;
  76683. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76684. deflateEnd (strm);
  76685. return Z_MEM_ERROR;
  76686. }
  76687. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76688. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76689. s->level = level;
  76690. s->strategy = strategy;
  76691. s->method = (Byte)method;
  76692. return deflateReset(strm);
  76693. }
  76694. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76695. {
  76696. deflate_state *s;
  76697. uInt length = dictLength;
  76698. uInt n;
  76699. IPos hash_head = 0;
  76700. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76701. strm->state->wrap == 2 ||
  76702. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76703. return Z_STREAM_ERROR;
  76704. s = strm->state;
  76705. if (s->wrap)
  76706. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76707. if (length < MIN_MATCH) return Z_OK;
  76708. if (length > MAX_DIST(s)) {
  76709. length = MAX_DIST(s);
  76710. dictionary += dictLength - length; /* use the tail of the dictionary */
  76711. }
  76712. zmemcpy(s->window, dictionary, length);
  76713. s->strstart = length;
  76714. s->block_start = (long)length;
  76715. s->ins_h = s->window[0];
  76716. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76717. for (n = 0; n <= length - MIN_MATCH; n++) {
  76718. INSERT_STRING(s, n, hash_head);
  76719. }
  76720. if (hash_head) hash_head = 0; /* to make compiler happy */
  76721. return Z_OK;
  76722. }
  76723. int ZEXPORT deflateReset (z_streamp strm)
  76724. {
  76725. deflate_state *s;
  76726. if (strm == Z_NULL || strm->state == Z_NULL ||
  76727. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76728. return Z_STREAM_ERROR;
  76729. }
  76730. strm->total_in = strm->total_out = 0;
  76731. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76732. strm->data_type = Z_UNKNOWN;
  76733. s = (deflate_state *)strm->state;
  76734. s->pending = 0;
  76735. s->pending_out = s->pending_buf;
  76736. if (s->wrap < 0) {
  76737. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76738. }
  76739. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76740. strm->adler =
  76741. #ifdef GZIP
  76742. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76743. #endif
  76744. adler32(0L, Z_NULL, 0);
  76745. s->last_flush = Z_NO_FLUSH;
  76746. _tr_init(s);
  76747. lm_init(s);
  76748. return Z_OK;
  76749. }
  76750. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76751. {
  76752. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76753. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76754. strm->state->gzhead = head;
  76755. return Z_OK;
  76756. }
  76757. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76758. {
  76759. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76760. strm->state->bi_valid = bits;
  76761. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76762. return Z_OK;
  76763. }
  76764. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76765. {
  76766. deflate_state *s;
  76767. compress_func func;
  76768. int err = Z_OK;
  76769. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76770. s = strm->state;
  76771. #ifdef FASTEST
  76772. if (level != 0) level = 1;
  76773. #else
  76774. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76775. #endif
  76776. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76777. return Z_STREAM_ERROR;
  76778. }
  76779. func = configuration_table[s->level].func;
  76780. if (func != configuration_table[level].func && strm->total_in != 0) {
  76781. err = deflate(strm, Z_PARTIAL_FLUSH);
  76782. }
  76783. if (s->level != level) {
  76784. s->level = level;
  76785. s->max_lazy_match = configuration_table[level].max_lazy;
  76786. s->good_match = configuration_table[level].good_length;
  76787. s->nice_match = configuration_table[level].nice_length;
  76788. s->max_chain_length = configuration_table[level].max_chain;
  76789. }
  76790. s->strategy = strategy;
  76791. return err;
  76792. }
  76793. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76794. {
  76795. deflate_state *s;
  76796. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76797. s = strm->state;
  76798. s->good_match = good_length;
  76799. s->max_lazy_match = max_lazy;
  76800. s->nice_match = nice_length;
  76801. s->max_chain_length = max_chain;
  76802. return Z_OK;
  76803. }
  76804. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76805. {
  76806. deflate_state *s;
  76807. uLong destLen;
  76808. destLen = sourceLen +
  76809. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76810. if (strm == Z_NULL || strm->state == Z_NULL)
  76811. return destLen;
  76812. s = strm->state;
  76813. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76814. return destLen;
  76815. return compressBound(sourceLen);
  76816. }
  76817. local void putShortMSB (deflate_state *s, uInt b)
  76818. {
  76819. put_byte(s, (Byte)(b >> 8));
  76820. put_byte(s, (Byte)(b & 0xff));
  76821. }
  76822. local void flush_pending (z_streamp strm)
  76823. {
  76824. unsigned len = strm->state->pending;
  76825. if (len > strm->avail_out) len = strm->avail_out;
  76826. if (len == 0) return;
  76827. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76828. strm->next_out += len;
  76829. strm->state->pending_out += len;
  76830. strm->total_out += len;
  76831. strm->avail_out -= len;
  76832. strm->state->pending -= len;
  76833. if (strm->state->pending == 0) {
  76834. strm->state->pending_out = strm->state->pending_buf;
  76835. }
  76836. }
  76837. int ZEXPORT deflate (z_streamp strm, int flush)
  76838. {
  76839. int old_flush; /* value of flush param for previous deflate call */
  76840. deflate_state *s;
  76841. if (strm == Z_NULL || strm->state == Z_NULL ||
  76842. flush > Z_FINISH || flush < 0) {
  76843. return Z_STREAM_ERROR;
  76844. }
  76845. s = strm->state;
  76846. if (strm->next_out == Z_NULL ||
  76847. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76848. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76849. ERR_RETURN(strm, Z_STREAM_ERROR);
  76850. }
  76851. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76852. s->strm = strm; /* just in case */
  76853. old_flush = s->last_flush;
  76854. s->last_flush = flush;
  76855. if (s->status == INIT_STATE) {
  76856. #ifdef GZIP
  76857. if (s->wrap == 2) {
  76858. strm->adler = crc32(0L, Z_NULL, 0);
  76859. put_byte(s, 31);
  76860. put_byte(s, 139);
  76861. put_byte(s, 8);
  76862. if (s->gzhead == NULL) {
  76863. put_byte(s, 0);
  76864. put_byte(s, 0);
  76865. put_byte(s, 0);
  76866. put_byte(s, 0);
  76867. put_byte(s, 0);
  76868. put_byte(s, s->level == 9 ? 2 :
  76869. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76870. 4 : 0));
  76871. put_byte(s, OS_CODE);
  76872. s->status = BUSY_STATE;
  76873. }
  76874. else {
  76875. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76876. (s->gzhead->hcrc ? 2 : 0) +
  76877. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76878. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76879. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76880. );
  76881. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76882. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76883. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76884. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76885. put_byte(s, s->level == 9 ? 2 :
  76886. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76887. 4 : 0));
  76888. put_byte(s, s->gzhead->os & 0xff);
  76889. if (s->gzhead->extra != NULL) {
  76890. put_byte(s, s->gzhead->extra_len & 0xff);
  76891. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  76892. }
  76893. if (s->gzhead->hcrc)
  76894. strm->adler = crc32(strm->adler, s->pending_buf,
  76895. s->pending);
  76896. s->gzindex = 0;
  76897. s->status = EXTRA_STATE;
  76898. }
  76899. }
  76900. else
  76901. #endif
  76902. {
  76903. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  76904. uInt level_flags;
  76905. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  76906. level_flags = 0;
  76907. else if (s->level < 6)
  76908. level_flags = 1;
  76909. else if (s->level == 6)
  76910. level_flags = 2;
  76911. else
  76912. level_flags = 3;
  76913. header |= (level_flags << 6);
  76914. if (s->strstart != 0) header |= PRESET_DICT;
  76915. header += 31 - (header % 31);
  76916. s->status = BUSY_STATE;
  76917. putShortMSB(s, header);
  76918. if (s->strstart != 0) {
  76919. putShortMSB(s, (uInt)(strm->adler >> 16));
  76920. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76921. }
  76922. strm->adler = adler32(0L, Z_NULL, 0);
  76923. }
  76924. }
  76925. #ifdef GZIP
  76926. if (s->status == EXTRA_STATE) {
  76927. if (s->gzhead->extra != NULL) {
  76928. uInt beg = s->pending; /* start of bytes to update crc */
  76929. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  76930. if (s->pending == s->pending_buf_size) {
  76931. if (s->gzhead->hcrc && s->pending > beg)
  76932. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76933. s->pending - beg);
  76934. flush_pending(strm);
  76935. beg = s->pending;
  76936. if (s->pending == s->pending_buf_size)
  76937. break;
  76938. }
  76939. put_byte(s, s->gzhead->extra[s->gzindex]);
  76940. s->gzindex++;
  76941. }
  76942. if (s->gzhead->hcrc && s->pending > beg)
  76943. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76944. s->pending - beg);
  76945. if (s->gzindex == s->gzhead->extra_len) {
  76946. s->gzindex = 0;
  76947. s->status = NAME_STATE;
  76948. }
  76949. }
  76950. else
  76951. s->status = NAME_STATE;
  76952. }
  76953. if (s->status == NAME_STATE) {
  76954. if (s->gzhead->name != NULL) {
  76955. uInt beg = s->pending; /* start of bytes to update crc */
  76956. int val;
  76957. do {
  76958. if (s->pending == s->pending_buf_size) {
  76959. if (s->gzhead->hcrc && s->pending > beg)
  76960. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76961. s->pending - beg);
  76962. flush_pending(strm);
  76963. beg = s->pending;
  76964. if (s->pending == s->pending_buf_size) {
  76965. val = 1;
  76966. break;
  76967. }
  76968. }
  76969. val = s->gzhead->name[s->gzindex++];
  76970. put_byte(s, val);
  76971. } while (val != 0);
  76972. if (s->gzhead->hcrc && s->pending > beg)
  76973. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76974. s->pending - beg);
  76975. if (val == 0) {
  76976. s->gzindex = 0;
  76977. s->status = COMMENT_STATE;
  76978. }
  76979. }
  76980. else
  76981. s->status = COMMENT_STATE;
  76982. }
  76983. if (s->status == COMMENT_STATE) {
  76984. if (s->gzhead->comment != NULL) {
  76985. uInt beg = s->pending; /* start of bytes to update crc */
  76986. int val;
  76987. do {
  76988. if (s->pending == s->pending_buf_size) {
  76989. if (s->gzhead->hcrc && s->pending > beg)
  76990. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76991. s->pending - beg);
  76992. flush_pending(strm);
  76993. beg = s->pending;
  76994. if (s->pending == s->pending_buf_size) {
  76995. val = 1;
  76996. break;
  76997. }
  76998. }
  76999. val = s->gzhead->comment[s->gzindex++];
  77000. put_byte(s, val);
  77001. } while (val != 0);
  77002. if (s->gzhead->hcrc && s->pending > beg)
  77003. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77004. s->pending - beg);
  77005. if (val == 0)
  77006. s->status = HCRC_STATE;
  77007. }
  77008. else
  77009. s->status = HCRC_STATE;
  77010. }
  77011. if (s->status == HCRC_STATE) {
  77012. if (s->gzhead->hcrc) {
  77013. if (s->pending + 2 > s->pending_buf_size)
  77014. flush_pending(strm);
  77015. if (s->pending + 2 <= s->pending_buf_size) {
  77016. put_byte(s, (Byte)(strm->adler & 0xff));
  77017. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77018. strm->adler = crc32(0L, Z_NULL, 0);
  77019. s->status = BUSY_STATE;
  77020. }
  77021. }
  77022. else
  77023. s->status = BUSY_STATE;
  77024. }
  77025. #endif
  77026. if (s->pending != 0) {
  77027. flush_pending(strm);
  77028. if (strm->avail_out == 0) {
  77029. s->last_flush = -1;
  77030. return Z_OK;
  77031. }
  77032. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77033. flush != Z_FINISH) {
  77034. ERR_RETURN(strm, Z_BUF_ERROR);
  77035. }
  77036. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77037. ERR_RETURN(strm, Z_BUF_ERROR);
  77038. }
  77039. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77040. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77041. block_state bstate;
  77042. bstate = (*(configuration_table[s->level].func))(s, flush);
  77043. if (bstate == finish_started || bstate == finish_done) {
  77044. s->status = FINISH_STATE;
  77045. }
  77046. if (bstate == need_more || bstate == finish_started) {
  77047. if (strm->avail_out == 0) {
  77048. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77049. }
  77050. return Z_OK;
  77051. }
  77052. if (bstate == block_done) {
  77053. if (flush == Z_PARTIAL_FLUSH) {
  77054. _tr_align(s);
  77055. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77056. _tr_stored_block(s, (char*)0, 0L, 0);
  77057. if (flush == Z_FULL_FLUSH) {
  77058. CLEAR_HASH(s); /* forget history */
  77059. }
  77060. }
  77061. flush_pending(strm);
  77062. if (strm->avail_out == 0) {
  77063. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77064. return Z_OK;
  77065. }
  77066. }
  77067. }
  77068. Assert(strm->avail_out > 0, "bug2");
  77069. if (flush != Z_FINISH) return Z_OK;
  77070. if (s->wrap <= 0) return Z_STREAM_END;
  77071. #ifdef GZIP
  77072. if (s->wrap == 2) {
  77073. put_byte(s, (Byte)(strm->adler & 0xff));
  77074. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77075. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77076. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77077. put_byte(s, (Byte)(strm->total_in & 0xff));
  77078. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77079. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77080. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77081. }
  77082. else
  77083. #endif
  77084. {
  77085. putShortMSB(s, (uInt)(strm->adler >> 16));
  77086. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77087. }
  77088. flush_pending(strm);
  77089. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77090. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77091. }
  77092. int ZEXPORT deflateEnd (z_streamp strm)
  77093. {
  77094. int status;
  77095. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77096. status = strm->state->status;
  77097. if (status != INIT_STATE &&
  77098. status != EXTRA_STATE &&
  77099. status != NAME_STATE &&
  77100. status != COMMENT_STATE &&
  77101. status != HCRC_STATE &&
  77102. status != BUSY_STATE &&
  77103. status != FINISH_STATE) {
  77104. return Z_STREAM_ERROR;
  77105. }
  77106. TRY_FREE(strm, strm->state->pending_buf);
  77107. TRY_FREE(strm, strm->state->head);
  77108. TRY_FREE(strm, strm->state->prev);
  77109. TRY_FREE(strm, strm->state->window);
  77110. ZFREE(strm, strm->state);
  77111. strm->state = Z_NULL;
  77112. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77113. }
  77114. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77115. {
  77116. #ifdef MAXSEG_64K
  77117. return Z_STREAM_ERROR;
  77118. #else
  77119. deflate_state *ds;
  77120. deflate_state *ss;
  77121. ushf *overlay;
  77122. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77123. return Z_STREAM_ERROR;
  77124. }
  77125. ss = source->state;
  77126. zmemcpy(dest, source, sizeof(z_stream));
  77127. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77128. if (ds == Z_NULL) return Z_MEM_ERROR;
  77129. dest->state = (struct internal_state FAR *) ds;
  77130. zmemcpy(ds, ss, sizeof(deflate_state));
  77131. ds->strm = dest;
  77132. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77133. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77134. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77135. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77136. ds->pending_buf = (uchf *) overlay;
  77137. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77138. ds->pending_buf == Z_NULL) {
  77139. deflateEnd (dest);
  77140. return Z_MEM_ERROR;
  77141. }
  77142. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77143. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77144. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77145. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77146. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77147. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77148. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77149. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77150. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77151. ds->bl_desc.dyn_tree = ds->bl_tree;
  77152. return Z_OK;
  77153. #endif /* MAXSEG_64K */
  77154. }
  77155. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77156. {
  77157. unsigned len = strm->avail_in;
  77158. if (len > size) len = size;
  77159. if (len == 0) return 0;
  77160. strm->avail_in -= len;
  77161. if (strm->state->wrap == 1) {
  77162. strm->adler = adler32(strm->adler, strm->next_in, len);
  77163. }
  77164. #ifdef GZIP
  77165. else if (strm->state->wrap == 2) {
  77166. strm->adler = crc32(strm->adler, strm->next_in, len);
  77167. }
  77168. #endif
  77169. zmemcpy(buf, strm->next_in, len);
  77170. strm->next_in += len;
  77171. strm->total_in += len;
  77172. return (int)len;
  77173. }
  77174. local void lm_init (deflate_state *s)
  77175. {
  77176. s->window_size = (ulg)2L*s->w_size;
  77177. CLEAR_HASH(s);
  77178. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77179. s->good_match = configuration_table[s->level].good_length;
  77180. s->nice_match = configuration_table[s->level].nice_length;
  77181. s->max_chain_length = configuration_table[s->level].max_chain;
  77182. s->strstart = 0;
  77183. s->block_start = 0L;
  77184. s->lookahead = 0;
  77185. s->match_length = s->prev_length = MIN_MATCH-1;
  77186. s->match_available = 0;
  77187. s->ins_h = 0;
  77188. #ifndef FASTEST
  77189. #ifdef ASMV
  77190. match_init(); /* initialize the asm code */
  77191. #endif
  77192. #endif
  77193. }
  77194. #ifndef FASTEST
  77195. #ifndef ASMV
  77196. local uInt longest_match(deflate_state *s, IPos cur_match)
  77197. {
  77198. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77199. register Bytef *scan = s->window + s->strstart; /* current string */
  77200. register Bytef *match; /* matched string */
  77201. register int len; /* length of current match */
  77202. int best_len = s->prev_length; /* best match length so far */
  77203. int nice_match = s->nice_match; /* stop if match long enough */
  77204. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77205. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77206. Posf *prev = s->prev;
  77207. uInt wmask = s->w_mask;
  77208. #ifdef UNALIGNED_OK
  77209. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77210. register ush scan_start = *(ushf*)scan;
  77211. register ush scan_end = *(ushf*)(scan+best_len-1);
  77212. #else
  77213. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77214. register Byte scan_end1 = scan[best_len-1];
  77215. register Byte scan_end = scan[best_len];
  77216. #endif
  77217. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77218. if (s->prev_length >= s->good_match) {
  77219. chain_length >>= 2;
  77220. }
  77221. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77222. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77223. do {
  77224. Assert(cur_match < s->strstart, "no future");
  77225. match = s->window + cur_match;
  77226. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77227. if (*(ushf*)(match+best_len-1) != scan_end ||
  77228. *(ushf*)match != scan_start) continue;
  77229. Assert(scan[2] == match[2], "scan[2]?");
  77230. scan++, match++;
  77231. do {
  77232. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77233. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77234. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77235. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77236. scan < strend);
  77237. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77238. if (*scan == *match) scan++;
  77239. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77240. scan = strend - (MAX_MATCH-1);
  77241. #else /* UNALIGNED_OK */
  77242. if (match[best_len] != scan_end ||
  77243. match[best_len-1] != scan_end1 ||
  77244. *match != *scan ||
  77245. *++match != scan[1]) continue;
  77246. scan += 2, match++;
  77247. Assert(*scan == *match, "match[2]?");
  77248. do {
  77249. } while (*++scan == *++match && *++scan == *++match &&
  77250. *++scan == *++match && *++scan == *++match &&
  77251. *++scan == *++match && *++scan == *++match &&
  77252. *++scan == *++match && *++scan == *++match &&
  77253. scan < strend);
  77254. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77255. len = MAX_MATCH - (int)(strend - scan);
  77256. scan = strend - MAX_MATCH;
  77257. #endif /* UNALIGNED_OK */
  77258. if (len > best_len) {
  77259. s->match_start = cur_match;
  77260. best_len = len;
  77261. if (len >= nice_match) break;
  77262. #ifdef UNALIGNED_OK
  77263. scan_end = *(ushf*)(scan+best_len-1);
  77264. #else
  77265. scan_end1 = scan[best_len-1];
  77266. scan_end = scan[best_len];
  77267. #endif
  77268. }
  77269. } while ((cur_match = prev[cur_match & wmask]) > limit
  77270. && --chain_length != 0);
  77271. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77272. return s->lookahead;
  77273. }
  77274. #endif /* ASMV */
  77275. #endif /* FASTEST */
  77276. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77277. {
  77278. register Bytef *scan = s->window + s->strstart; /* current string */
  77279. register Bytef *match; /* matched string */
  77280. register int len; /* length of current match */
  77281. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77282. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77283. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77284. Assert(cur_match < s->strstart, "no future");
  77285. match = s->window + cur_match;
  77286. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77287. scan += 2, match += 2;
  77288. Assert(*scan == *match, "match[2]?");
  77289. do {
  77290. } while (*++scan == *++match && *++scan == *++match &&
  77291. *++scan == *++match && *++scan == *++match &&
  77292. *++scan == *++match && *++scan == *++match &&
  77293. *++scan == *++match && *++scan == *++match &&
  77294. scan < strend);
  77295. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77296. len = MAX_MATCH - (int)(strend - scan);
  77297. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77298. s->match_start = cur_match;
  77299. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77300. }
  77301. #ifdef DEBUG
  77302. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77303. {
  77304. if (zmemcmp(s->window + match,
  77305. s->window + start, length) != EQUAL) {
  77306. fprintf(stderr, " start %u, match %u, length %d\n",
  77307. start, match, length);
  77308. do {
  77309. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77310. } while (--length != 0);
  77311. z_error("invalid match");
  77312. }
  77313. if (z_verbose > 1) {
  77314. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77315. do { putc(s->window[start++], stderr); } while (--length != 0);
  77316. }
  77317. }
  77318. #else
  77319. # define check_match(s, start, match, length)
  77320. #endif /* DEBUG */
  77321. local void fill_window (deflate_state *s)
  77322. {
  77323. register unsigned n, m;
  77324. register Posf *p;
  77325. unsigned more; /* Amount of free space at the end of the window. */
  77326. uInt wsize = s->w_size;
  77327. do {
  77328. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77329. if (sizeof(int) <= 2) {
  77330. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77331. more = wsize;
  77332. } else if (more == (unsigned)(-1)) {
  77333. more--;
  77334. }
  77335. }
  77336. if (s->strstart >= wsize+MAX_DIST(s)) {
  77337. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77338. s->match_start -= wsize;
  77339. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77340. s->block_start -= (long) wsize;
  77341. n = s->hash_size;
  77342. p = &s->head[n];
  77343. do {
  77344. m = *--p;
  77345. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77346. } while (--n);
  77347. n = wsize;
  77348. #ifndef FASTEST
  77349. p = &s->prev[n];
  77350. do {
  77351. m = *--p;
  77352. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77353. } while (--n);
  77354. #endif
  77355. more += wsize;
  77356. }
  77357. if (s->strm->avail_in == 0) return;
  77358. Assert(more >= 2, "more < 2");
  77359. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77360. s->lookahead += n;
  77361. if (s->lookahead >= MIN_MATCH) {
  77362. s->ins_h = s->window[s->strstart];
  77363. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77364. #if MIN_MATCH != 3
  77365. Call UPDATE_HASH() MIN_MATCH-3 more times
  77366. #endif
  77367. }
  77368. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77369. }
  77370. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77371. _tr_flush_block(s, (s->block_start >= 0L ? \
  77372. (charf *)&s->window[(unsigned)s->block_start] : \
  77373. (charf *)Z_NULL), \
  77374. (ulg)((long)s->strstart - s->block_start), \
  77375. (eof)); \
  77376. s->block_start = s->strstart; \
  77377. flush_pending(s->strm); \
  77378. Tracev((stderr,"[FLUSH]")); \
  77379. }
  77380. #define FLUSH_BLOCK(s, eof) { \
  77381. FLUSH_BLOCK_ONLY(s, eof); \
  77382. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77383. }
  77384. local block_state deflate_stored(deflate_state *s, int flush)
  77385. {
  77386. ulg max_block_size = 0xffff;
  77387. ulg max_start;
  77388. if (max_block_size > s->pending_buf_size - 5) {
  77389. max_block_size = s->pending_buf_size - 5;
  77390. }
  77391. for (;;) {
  77392. if (s->lookahead <= 1) {
  77393. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77394. s->block_start >= (long)s->w_size, "slide too late");
  77395. fill_window(s);
  77396. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77397. if (s->lookahead == 0) break; /* flush the current block */
  77398. }
  77399. Assert(s->block_start >= 0L, "block gone");
  77400. s->strstart += s->lookahead;
  77401. s->lookahead = 0;
  77402. max_start = s->block_start + max_block_size;
  77403. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77404. s->lookahead = (uInt)(s->strstart - max_start);
  77405. s->strstart = (uInt)max_start;
  77406. FLUSH_BLOCK(s, 0);
  77407. }
  77408. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77409. FLUSH_BLOCK(s, 0);
  77410. }
  77411. }
  77412. FLUSH_BLOCK(s, flush == Z_FINISH);
  77413. return flush == Z_FINISH ? finish_done : block_done;
  77414. }
  77415. local block_state deflate_fast(deflate_state *s, int flush)
  77416. {
  77417. IPos hash_head = NIL; /* head of the hash chain */
  77418. int bflush; /* set if current block must be flushed */
  77419. for (;;) {
  77420. if (s->lookahead < MIN_LOOKAHEAD) {
  77421. fill_window(s);
  77422. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77423. return need_more;
  77424. }
  77425. if (s->lookahead == 0) break; /* flush the current block */
  77426. }
  77427. if (s->lookahead >= MIN_MATCH) {
  77428. INSERT_STRING(s, s->strstart, hash_head);
  77429. }
  77430. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77431. #ifdef FASTEST
  77432. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77433. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77434. s->match_length = longest_match_fast (s, hash_head);
  77435. }
  77436. #else
  77437. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77438. s->match_length = longest_match (s, hash_head);
  77439. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77440. s->match_length = longest_match_fast (s, hash_head);
  77441. }
  77442. #endif
  77443. }
  77444. if (s->match_length >= MIN_MATCH) {
  77445. check_match(s, s->strstart, s->match_start, s->match_length);
  77446. _tr_tally_dist(s, s->strstart - s->match_start,
  77447. s->match_length - MIN_MATCH, bflush);
  77448. s->lookahead -= s->match_length;
  77449. #ifndef FASTEST
  77450. if (s->match_length <= s->max_insert_length &&
  77451. s->lookahead >= MIN_MATCH) {
  77452. s->match_length--; /* string at strstart already in table */
  77453. do {
  77454. s->strstart++;
  77455. INSERT_STRING(s, s->strstart, hash_head);
  77456. } while (--s->match_length != 0);
  77457. s->strstart++;
  77458. } else
  77459. #endif
  77460. {
  77461. s->strstart += s->match_length;
  77462. s->match_length = 0;
  77463. s->ins_h = s->window[s->strstart];
  77464. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77465. #if MIN_MATCH != 3
  77466. Call UPDATE_HASH() MIN_MATCH-3 more times
  77467. #endif
  77468. }
  77469. } else {
  77470. Tracevv((stderr,"%c", s->window[s->strstart]));
  77471. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77472. s->lookahead--;
  77473. s->strstart++;
  77474. }
  77475. if (bflush) FLUSH_BLOCK(s, 0);
  77476. }
  77477. FLUSH_BLOCK(s, flush == Z_FINISH);
  77478. return flush == Z_FINISH ? finish_done : block_done;
  77479. }
  77480. #ifndef FASTEST
  77481. local block_state deflate_slow(deflate_state *s, int flush)
  77482. {
  77483. IPos hash_head = NIL; /* head of hash chain */
  77484. int bflush; /* set if current block must be flushed */
  77485. for (;;) {
  77486. if (s->lookahead < MIN_LOOKAHEAD) {
  77487. fill_window(s);
  77488. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77489. return need_more;
  77490. }
  77491. if (s->lookahead == 0) break; /* flush the current block */
  77492. }
  77493. if (s->lookahead >= MIN_MATCH) {
  77494. INSERT_STRING(s, s->strstart, hash_head);
  77495. }
  77496. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77497. s->match_length = MIN_MATCH-1;
  77498. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77499. s->strstart - hash_head <= MAX_DIST(s)) {
  77500. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77501. s->match_length = longest_match (s, hash_head);
  77502. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77503. s->match_length = longest_match_fast (s, hash_head);
  77504. }
  77505. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77506. #if TOO_FAR <= 32767
  77507. || (s->match_length == MIN_MATCH &&
  77508. s->strstart - s->match_start > TOO_FAR)
  77509. #endif
  77510. )) {
  77511. s->match_length = MIN_MATCH-1;
  77512. }
  77513. }
  77514. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77515. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77516. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77517. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77518. s->prev_length - MIN_MATCH, bflush);
  77519. s->lookahead -= s->prev_length-1;
  77520. s->prev_length -= 2;
  77521. do {
  77522. if (++s->strstart <= max_insert) {
  77523. INSERT_STRING(s, s->strstart, hash_head);
  77524. }
  77525. } while (--s->prev_length != 0);
  77526. s->match_available = 0;
  77527. s->match_length = MIN_MATCH-1;
  77528. s->strstart++;
  77529. if (bflush) FLUSH_BLOCK(s, 0);
  77530. } else if (s->match_available) {
  77531. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77532. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77533. if (bflush) {
  77534. FLUSH_BLOCK_ONLY(s, 0);
  77535. }
  77536. s->strstart++;
  77537. s->lookahead--;
  77538. if (s->strm->avail_out == 0) return need_more;
  77539. } else {
  77540. s->match_available = 1;
  77541. s->strstart++;
  77542. s->lookahead--;
  77543. }
  77544. }
  77545. Assert (flush != Z_NO_FLUSH, "no flush?");
  77546. if (s->match_available) {
  77547. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77548. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77549. s->match_available = 0;
  77550. }
  77551. FLUSH_BLOCK(s, flush == Z_FINISH);
  77552. return flush == Z_FINISH ? finish_done : block_done;
  77553. }
  77554. #endif /* FASTEST */
  77555. #if 0
  77556. local block_state deflate_rle(s, flush)
  77557. deflate_state *s;
  77558. int flush;
  77559. {
  77560. int bflush; /* set if current block must be flushed */
  77561. uInt run; /* length of run */
  77562. uInt max; /* maximum length of run */
  77563. uInt prev; /* byte at distance one to match */
  77564. Bytef *scan; /* scan for end of run */
  77565. for (;;) {
  77566. if (s->lookahead < MAX_MATCH) {
  77567. fill_window(s);
  77568. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77569. return need_more;
  77570. }
  77571. if (s->lookahead == 0) break; /* flush the current block */
  77572. }
  77573. run = 0;
  77574. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77575. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77576. scan = s->window + s->strstart - 1;
  77577. prev = *scan++;
  77578. do {
  77579. if (*scan++ != prev)
  77580. break;
  77581. } while (++run < max);
  77582. }
  77583. if (run >= MIN_MATCH) {
  77584. check_match(s, s->strstart, s->strstart - 1, run);
  77585. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77586. s->lookahead -= run;
  77587. s->strstart += run;
  77588. } else {
  77589. Tracevv((stderr,"%c", s->window[s->strstart]));
  77590. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77591. s->lookahead--;
  77592. s->strstart++;
  77593. }
  77594. if (bflush) FLUSH_BLOCK(s, 0);
  77595. }
  77596. FLUSH_BLOCK(s, flush == Z_FINISH);
  77597. return flush == Z_FINISH ? finish_done : block_done;
  77598. }
  77599. #endif
  77600. /*** End of inlined file: deflate.c ***/
  77601. /*** Start of inlined file: inffast.c ***/
  77602. /*** Start of inlined file: inftrees.h ***/
  77603. #ifndef _INFTREES_H_
  77604. #define _INFTREES_H_
  77605. typedef struct {
  77606. unsigned char op; /* operation, extra bits, table bits */
  77607. unsigned char bits; /* bits in this part of the code */
  77608. unsigned short val; /* offset in table or code value */
  77609. } code;
  77610. #define ENOUGH 2048
  77611. #define MAXD 592
  77612. typedef enum {
  77613. CODES,
  77614. LENS,
  77615. DISTS
  77616. } codetype;
  77617. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77618. unsigned codes, code FAR * FAR *table,
  77619. unsigned FAR *bits, unsigned short FAR *work));
  77620. #endif
  77621. /*** End of inlined file: inftrees.h ***/
  77622. /*** Start of inlined file: inflate.h ***/
  77623. #ifndef _INFLATE_H_
  77624. #define _INFLATE_H_
  77625. #ifndef NO_GZIP
  77626. # define GUNZIP
  77627. #endif
  77628. typedef enum {
  77629. HEAD, /* i: waiting for magic header */
  77630. FLAGS, /* i: waiting for method and flags (gzip) */
  77631. TIME, /* i: waiting for modification time (gzip) */
  77632. OS, /* i: waiting for extra flags and operating system (gzip) */
  77633. EXLEN, /* i: waiting for extra length (gzip) */
  77634. EXTRA, /* i: waiting for extra bytes (gzip) */
  77635. NAME, /* i: waiting for end of file name (gzip) */
  77636. COMMENT, /* i: waiting for end of comment (gzip) */
  77637. HCRC, /* i: waiting for header crc (gzip) */
  77638. DICTID, /* i: waiting for dictionary check value */
  77639. DICT, /* waiting for inflateSetDictionary() call */
  77640. TYPE, /* i: waiting for type bits, including last-flag bit */
  77641. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77642. STORED, /* i: waiting for stored size (length and complement) */
  77643. COPY, /* i/o: waiting for input or output to copy stored block */
  77644. TABLE, /* i: waiting for dynamic block table lengths */
  77645. LENLENS, /* i: waiting for code length code lengths */
  77646. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77647. LEN, /* i: waiting for length/lit code */
  77648. LENEXT, /* i: waiting for length extra bits */
  77649. DIST, /* i: waiting for distance code */
  77650. DISTEXT, /* i: waiting for distance extra bits */
  77651. MATCH, /* o: waiting for output space to copy string */
  77652. LIT, /* o: waiting for output space to write literal */
  77653. CHECK, /* i: waiting for 32-bit check value */
  77654. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77655. DONE, /* finished check, done -- remain here until reset */
  77656. BAD, /* got a data error -- remain here until reset */
  77657. MEM, /* got an inflate() memory error -- remain here until reset */
  77658. SYNC /* looking for synchronization bytes to restart inflate() */
  77659. } inflate_mode;
  77660. struct inflate_state {
  77661. inflate_mode mode; /* current inflate mode */
  77662. int last; /* true if processing last block */
  77663. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77664. int havedict; /* true if dictionary provided */
  77665. int flags; /* gzip header method and flags (0 if zlib) */
  77666. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77667. unsigned long check; /* protected copy of check value */
  77668. unsigned long total; /* protected copy of output count */
  77669. gz_headerp head; /* where to save gzip header information */
  77670. unsigned wbits; /* log base 2 of requested window size */
  77671. unsigned wsize; /* window size or zero if not using window */
  77672. unsigned whave; /* valid bytes in the window */
  77673. unsigned write; /* window write index */
  77674. unsigned char FAR *window; /* allocated sliding window, if needed */
  77675. unsigned long hold; /* input bit accumulator */
  77676. unsigned bits; /* number of bits in "in" */
  77677. unsigned length; /* literal or length of data to copy */
  77678. unsigned offset; /* distance back to copy string from */
  77679. unsigned extra; /* extra bits needed */
  77680. code const FAR *lencode; /* starting table for length/literal codes */
  77681. code const FAR *distcode; /* starting table for distance codes */
  77682. unsigned lenbits; /* index bits for lencode */
  77683. unsigned distbits; /* index bits for distcode */
  77684. unsigned ncode; /* number of code length code lengths */
  77685. unsigned nlen; /* number of length code lengths */
  77686. unsigned ndist; /* number of distance code lengths */
  77687. unsigned have; /* number of code lengths in lens[] */
  77688. code FAR *next; /* next available space in codes[] */
  77689. unsigned short lens[320]; /* temporary storage for code lengths */
  77690. unsigned short work[288]; /* work area for code table building */
  77691. code codes[ENOUGH]; /* space for code tables */
  77692. };
  77693. #endif
  77694. /*** End of inlined file: inflate.h ***/
  77695. /*** Start of inlined file: inffast.h ***/
  77696. void inflate_fast OF((z_streamp strm, unsigned start));
  77697. /*** End of inlined file: inffast.h ***/
  77698. #ifndef ASMINF
  77699. #ifdef POSTINC
  77700. # define OFF 0
  77701. # define PUP(a) *(a)++
  77702. #else
  77703. # define OFF 1
  77704. # define PUP(a) *++(a)
  77705. #endif
  77706. void inflate_fast (z_streamp strm, unsigned start)
  77707. {
  77708. struct inflate_state FAR *state;
  77709. unsigned char FAR *in; /* local strm->next_in */
  77710. unsigned char FAR *last; /* while in < last, enough input available */
  77711. unsigned char FAR *out; /* local strm->next_out */
  77712. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77713. unsigned char FAR *end; /* while out < end, enough space available */
  77714. #ifdef INFLATE_STRICT
  77715. unsigned dmax; /* maximum distance from zlib header */
  77716. #endif
  77717. unsigned wsize; /* window size or zero if not using window */
  77718. unsigned whave; /* valid bytes in the window */
  77719. unsigned write; /* window write index */
  77720. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77721. unsigned long hold; /* local strm->hold */
  77722. unsigned bits; /* local strm->bits */
  77723. code const FAR *lcode; /* local strm->lencode */
  77724. code const FAR *dcode; /* local strm->distcode */
  77725. unsigned lmask; /* mask for first level of length codes */
  77726. unsigned dmask; /* mask for first level of distance codes */
  77727. code thisx; /* retrieved table entry */
  77728. unsigned op; /* code bits, operation, extra bits, or */
  77729. unsigned len; /* match length, unused bytes */
  77730. unsigned dist; /* match distance */
  77731. unsigned char FAR *from; /* where to copy match from */
  77732. state = (struct inflate_state FAR *)strm->state;
  77733. in = strm->next_in - OFF;
  77734. last = in + (strm->avail_in - 5);
  77735. out = strm->next_out - OFF;
  77736. beg = out - (start - strm->avail_out);
  77737. end = out + (strm->avail_out - 257);
  77738. #ifdef INFLATE_STRICT
  77739. dmax = state->dmax;
  77740. #endif
  77741. wsize = state->wsize;
  77742. whave = state->whave;
  77743. write = state->write;
  77744. window = state->window;
  77745. hold = state->hold;
  77746. bits = state->bits;
  77747. lcode = state->lencode;
  77748. dcode = state->distcode;
  77749. lmask = (1U << state->lenbits) - 1;
  77750. dmask = (1U << state->distbits) - 1;
  77751. do {
  77752. if (bits < 15) {
  77753. hold += (unsigned long)(PUP(in)) << bits;
  77754. bits += 8;
  77755. hold += (unsigned long)(PUP(in)) << bits;
  77756. bits += 8;
  77757. }
  77758. thisx = lcode[hold & lmask];
  77759. dolen:
  77760. op = (unsigned)(thisx.bits);
  77761. hold >>= op;
  77762. bits -= op;
  77763. op = (unsigned)(thisx.op);
  77764. if (op == 0) { /* literal */
  77765. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77766. "inflate: literal '%c'\n" :
  77767. "inflate: literal 0x%02x\n", thisx.val));
  77768. PUP(out) = (unsigned char)(thisx.val);
  77769. }
  77770. else if (op & 16) { /* length base */
  77771. len = (unsigned)(thisx.val);
  77772. op &= 15; /* number of extra bits */
  77773. if (op) {
  77774. if (bits < op) {
  77775. hold += (unsigned long)(PUP(in)) << bits;
  77776. bits += 8;
  77777. }
  77778. len += (unsigned)hold & ((1U << op) - 1);
  77779. hold >>= op;
  77780. bits -= op;
  77781. }
  77782. Tracevv((stderr, "inflate: length %u\n", len));
  77783. if (bits < 15) {
  77784. hold += (unsigned long)(PUP(in)) << bits;
  77785. bits += 8;
  77786. hold += (unsigned long)(PUP(in)) << bits;
  77787. bits += 8;
  77788. }
  77789. thisx = dcode[hold & dmask];
  77790. dodist:
  77791. op = (unsigned)(thisx.bits);
  77792. hold >>= op;
  77793. bits -= op;
  77794. op = (unsigned)(thisx.op);
  77795. if (op & 16) { /* distance base */
  77796. dist = (unsigned)(thisx.val);
  77797. op &= 15; /* number of extra bits */
  77798. if (bits < op) {
  77799. hold += (unsigned long)(PUP(in)) << bits;
  77800. bits += 8;
  77801. if (bits < op) {
  77802. hold += (unsigned long)(PUP(in)) << bits;
  77803. bits += 8;
  77804. }
  77805. }
  77806. dist += (unsigned)hold & ((1U << op) - 1);
  77807. #ifdef INFLATE_STRICT
  77808. if (dist > dmax) {
  77809. strm->msg = (char *)"invalid distance too far back";
  77810. state->mode = BAD;
  77811. break;
  77812. }
  77813. #endif
  77814. hold >>= op;
  77815. bits -= op;
  77816. Tracevv((stderr, "inflate: distance %u\n", dist));
  77817. op = (unsigned)(out - beg); /* max distance in output */
  77818. if (dist > op) { /* see if copy from window */
  77819. op = dist - op; /* distance back in window */
  77820. if (op > whave) {
  77821. strm->msg = (char *)"invalid distance too far back";
  77822. state->mode = BAD;
  77823. break;
  77824. }
  77825. from = window - OFF;
  77826. if (write == 0) { /* very common case */
  77827. from += wsize - op;
  77828. if (op < len) { /* some from window */
  77829. len -= op;
  77830. do {
  77831. PUP(out) = PUP(from);
  77832. } while (--op);
  77833. from = out - dist; /* rest from output */
  77834. }
  77835. }
  77836. else if (write < op) { /* wrap around window */
  77837. from += wsize + write - op;
  77838. op -= write;
  77839. if (op < len) { /* some from end of window */
  77840. len -= op;
  77841. do {
  77842. PUP(out) = PUP(from);
  77843. } while (--op);
  77844. from = window - OFF;
  77845. if (write < len) { /* some from start of window */
  77846. op = write;
  77847. len -= op;
  77848. do {
  77849. PUP(out) = PUP(from);
  77850. } while (--op);
  77851. from = out - dist; /* rest from output */
  77852. }
  77853. }
  77854. }
  77855. else { /* contiguous in window */
  77856. from += write - op;
  77857. if (op < len) { /* some from window */
  77858. len -= op;
  77859. do {
  77860. PUP(out) = PUP(from);
  77861. } while (--op);
  77862. from = out - dist; /* rest from output */
  77863. }
  77864. }
  77865. while (len > 2) {
  77866. PUP(out) = PUP(from);
  77867. PUP(out) = PUP(from);
  77868. PUP(out) = PUP(from);
  77869. len -= 3;
  77870. }
  77871. if (len) {
  77872. PUP(out) = PUP(from);
  77873. if (len > 1)
  77874. PUP(out) = PUP(from);
  77875. }
  77876. }
  77877. else {
  77878. from = out - dist; /* copy direct from output */
  77879. do { /* minimum length is three */
  77880. PUP(out) = PUP(from);
  77881. PUP(out) = PUP(from);
  77882. PUP(out) = PUP(from);
  77883. len -= 3;
  77884. } while (len > 2);
  77885. if (len) {
  77886. PUP(out) = PUP(from);
  77887. if (len > 1)
  77888. PUP(out) = PUP(from);
  77889. }
  77890. }
  77891. }
  77892. else if ((op & 64) == 0) { /* 2nd level distance code */
  77893. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  77894. goto dodist;
  77895. }
  77896. else {
  77897. strm->msg = (char *)"invalid distance code";
  77898. state->mode = BAD;
  77899. break;
  77900. }
  77901. }
  77902. else if ((op & 64) == 0) { /* 2nd level length code */
  77903. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  77904. goto dolen;
  77905. }
  77906. else if (op & 32) { /* end-of-block */
  77907. Tracevv((stderr, "inflate: end of block\n"));
  77908. state->mode = TYPE;
  77909. break;
  77910. }
  77911. else {
  77912. strm->msg = (char *)"invalid literal/length code";
  77913. state->mode = BAD;
  77914. break;
  77915. }
  77916. } while (in < last && out < end);
  77917. len = bits >> 3;
  77918. in -= len;
  77919. bits -= len << 3;
  77920. hold &= (1U << bits) - 1;
  77921. strm->next_in = in + OFF;
  77922. strm->next_out = out + OFF;
  77923. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  77924. strm->avail_out = (unsigned)(out < end ?
  77925. 257 + (end - out) : 257 - (out - end));
  77926. state->hold = hold;
  77927. state->bits = bits;
  77928. return;
  77929. }
  77930. #endif /* !ASMINF */
  77931. /*** End of inlined file: inffast.c ***/
  77932. #undef PULLBYTE
  77933. #undef LOAD
  77934. #undef RESTORE
  77935. #undef INITBITS
  77936. #undef NEEDBITS
  77937. #undef DROPBITS
  77938. #undef BYTEBITS
  77939. /*** Start of inlined file: inflate.c ***/
  77940. /*** Start of inlined file: inffast.h ***/
  77941. void inflate_fast OF((z_streamp strm, unsigned start));
  77942. /*** End of inlined file: inffast.h ***/
  77943. #ifdef MAKEFIXED
  77944. # ifndef BUILDFIXED
  77945. # define BUILDFIXED
  77946. # endif
  77947. #endif
  77948. local void fixedtables OF((struct inflate_state FAR *state));
  77949. local int updatewindow OF((z_streamp strm, unsigned out));
  77950. #ifdef BUILDFIXED
  77951. void makefixed OF((void));
  77952. #endif
  77953. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  77954. unsigned len));
  77955. int ZEXPORT inflateReset (z_streamp strm)
  77956. {
  77957. struct inflate_state FAR *state;
  77958. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77959. state = (struct inflate_state FAR *)strm->state;
  77960. strm->total_in = strm->total_out = state->total = 0;
  77961. strm->msg = Z_NULL;
  77962. strm->adler = 1; /* to support ill-conceived Java test suite */
  77963. state->mode = HEAD;
  77964. state->last = 0;
  77965. state->havedict = 0;
  77966. state->dmax = 32768U;
  77967. state->head = Z_NULL;
  77968. state->wsize = 0;
  77969. state->whave = 0;
  77970. state->write = 0;
  77971. state->hold = 0;
  77972. state->bits = 0;
  77973. state->lencode = state->distcode = state->next = state->codes;
  77974. Tracev((stderr, "inflate: reset\n"));
  77975. return Z_OK;
  77976. }
  77977. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  77978. {
  77979. struct inflate_state FAR *state;
  77980. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77981. state = (struct inflate_state FAR *)strm->state;
  77982. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  77983. value &= (1L << bits) - 1;
  77984. state->hold += value << state->bits;
  77985. state->bits += bits;
  77986. return Z_OK;
  77987. }
  77988. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  77989. {
  77990. struct inflate_state FAR *state;
  77991. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  77992. stream_size != (int)(sizeof(z_stream)))
  77993. return Z_VERSION_ERROR;
  77994. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77995. strm->msg = Z_NULL; /* in case we return an error */
  77996. if (strm->zalloc == (alloc_func)0) {
  77997. strm->zalloc = zcalloc;
  77998. strm->opaque = (voidpf)0;
  77999. }
  78000. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78001. state = (struct inflate_state FAR *)
  78002. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78003. if (state == Z_NULL) return Z_MEM_ERROR;
  78004. Tracev((stderr, "inflate: allocated\n"));
  78005. strm->state = (struct internal_state FAR *)state;
  78006. if (windowBits < 0) {
  78007. state->wrap = 0;
  78008. windowBits = -windowBits;
  78009. }
  78010. else {
  78011. state->wrap = (windowBits >> 4) + 1;
  78012. #ifdef GUNZIP
  78013. if (windowBits < 48) windowBits &= 15;
  78014. #endif
  78015. }
  78016. if (windowBits < 8 || windowBits > 15) {
  78017. ZFREE(strm, state);
  78018. strm->state = Z_NULL;
  78019. return Z_STREAM_ERROR;
  78020. }
  78021. state->wbits = (unsigned)windowBits;
  78022. state->window = Z_NULL;
  78023. return inflateReset(strm);
  78024. }
  78025. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78026. {
  78027. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78028. }
  78029. local void fixedtables (struct inflate_state FAR *state)
  78030. {
  78031. #ifdef BUILDFIXED
  78032. static int virgin = 1;
  78033. static code *lenfix, *distfix;
  78034. static code fixed[544];
  78035. if (virgin) {
  78036. unsigned sym, bits;
  78037. static code *next;
  78038. sym = 0;
  78039. while (sym < 144) state->lens[sym++] = 8;
  78040. while (sym < 256) state->lens[sym++] = 9;
  78041. while (sym < 280) state->lens[sym++] = 7;
  78042. while (sym < 288) state->lens[sym++] = 8;
  78043. next = fixed;
  78044. lenfix = next;
  78045. bits = 9;
  78046. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78047. sym = 0;
  78048. while (sym < 32) state->lens[sym++] = 5;
  78049. distfix = next;
  78050. bits = 5;
  78051. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78052. virgin = 0;
  78053. }
  78054. #else /* !BUILDFIXED */
  78055. /*** Start of inlined file: inffixed.h ***/
  78056. static const code lenfix[512] = {
  78057. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78058. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78059. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78060. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78061. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78062. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78063. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78064. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78065. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78066. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78067. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78068. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78069. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78070. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78071. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78072. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78073. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78074. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78075. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78076. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78077. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78078. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78079. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78080. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78081. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78082. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78083. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78084. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78085. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78086. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78087. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78088. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78089. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78090. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78091. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78092. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78093. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78094. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78095. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78096. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78097. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78098. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78099. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78100. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78101. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78102. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78103. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78104. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78105. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78106. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78107. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78108. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78109. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78110. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78111. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78112. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78113. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78114. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78115. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78116. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78117. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78118. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78119. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78120. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78121. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78122. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78123. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78124. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78125. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78126. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78127. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78128. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78129. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78130. {0,9,255}
  78131. };
  78132. static const code distfix[32] = {
  78133. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78134. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78135. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78136. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78137. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78138. {22,5,193},{64,5,0}
  78139. };
  78140. /*** End of inlined file: inffixed.h ***/
  78141. #endif /* BUILDFIXED */
  78142. state->lencode = lenfix;
  78143. state->lenbits = 9;
  78144. state->distcode = distfix;
  78145. state->distbits = 5;
  78146. }
  78147. #ifdef MAKEFIXED
  78148. #include <stdio.h>
  78149. void makefixed()
  78150. {
  78151. unsigned low, size;
  78152. struct inflate_state state;
  78153. fixedtables(&state);
  78154. puts(" /* inffixed.h -- table for decoding fixed codes");
  78155. puts(" * Generated automatically by makefixed().");
  78156. puts(" */");
  78157. puts("");
  78158. puts(" /* WARNING: this file should *not* be used by applications.");
  78159. puts(" It is part of the implementation of this library and is");
  78160. puts(" subject to change. Applications should only use zlib.h.");
  78161. puts(" */");
  78162. puts("");
  78163. size = 1U << 9;
  78164. printf(" static const code lenfix[%u] = {", size);
  78165. low = 0;
  78166. for (;;) {
  78167. if ((low % 7) == 0) printf("\n ");
  78168. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78169. state.lencode[low].val);
  78170. if (++low == size) break;
  78171. putchar(',');
  78172. }
  78173. puts("\n };");
  78174. size = 1U << 5;
  78175. printf("\n static const code distfix[%u] = {", size);
  78176. low = 0;
  78177. for (;;) {
  78178. if ((low % 6) == 0) printf("\n ");
  78179. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78180. state.distcode[low].val);
  78181. if (++low == size) break;
  78182. putchar(',');
  78183. }
  78184. puts("\n };");
  78185. }
  78186. #endif /* MAKEFIXED */
  78187. local int updatewindow (z_streamp strm, unsigned out)
  78188. {
  78189. struct inflate_state FAR *state;
  78190. unsigned copy, dist;
  78191. state = (struct inflate_state FAR *)strm->state;
  78192. if (state->window == Z_NULL) {
  78193. state->window = (unsigned char FAR *)
  78194. ZALLOC(strm, 1U << state->wbits,
  78195. sizeof(unsigned char));
  78196. if (state->window == Z_NULL) return 1;
  78197. }
  78198. if (state->wsize == 0) {
  78199. state->wsize = 1U << state->wbits;
  78200. state->write = 0;
  78201. state->whave = 0;
  78202. }
  78203. copy = out - strm->avail_out;
  78204. if (copy >= state->wsize) {
  78205. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78206. state->write = 0;
  78207. state->whave = state->wsize;
  78208. }
  78209. else {
  78210. dist = state->wsize - state->write;
  78211. if (dist > copy) dist = copy;
  78212. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78213. copy -= dist;
  78214. if (copy) {
  78215. zmemcpy(state->window, strm->next_out - copy, copy);
  78216. state->write = copy;
  78217. state->whave = state->wsize;
  78218. }
  78219. else {
  78220. state->write += dist;
  78221. if (state->write == state->wsize) state->write = 0;
  78222. if (state->whave < state->wsize) state->whave += dist;
  78223. }
  78224. }
  78225. return 0;
  78226. }
  78227. #ifdef GUNZIP
  78228. # define UPDATE(check, buf, len) \
  78229. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78230. #else
  78231. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78232. #endif
  78233. #ifdef GUNZIP
  78234. # define CRC2(check, word) \
  78235. do { \
  78236. hbuf[0] = (unsigned char)(word); \
  78237. hbuf[1] = (unsigned char)((word) >> 8); \
  78238. check = crc32(check, hbuf, 2); \
  78239. } while (0)
  78240. # define CRC4(check, word) \
  78241. do { \
  78242. hbuf[0] = (unsigned char)(word); \
  78243. hbuf[1] = (unsigned char)((word) >> 8); \
  78244. hbuf[2] = (unsigned char)((word) >> 16); \
  78245. hbuf[3] = (unsigned char)((word) >> 24); \
  78246. check = crc32(check, hbuf, 4); \
  78247. } while (0)
  78248. #endif
  78249. #define LOAD() \
  78250. do { \
  78251. put = strm->next_out; \
  78252. left = strm->avail_out; \
  78253. next = strm->next_in; \
  78254. have = strm->avail_in; \
  78255. hold = state->hold; \
  78256. bits = state->bits; \
  78257. } while (0)
  78258. #define RESTORE() \
  78259. do { \
  78260. strm->next_out = put; \
  78261. strm->avail_out = left; \
  78262. strm->next_in = next; \
  78263. strm->avail_in = have; \
  78264. state->hold = hold; \
  78265. state->bits = bits; \
  78266. } while (0)
  78267. #define INITBITS() \
  78268. do { \
  78269. hold = 0; \
  78270. bits = 0; \
  78271. } while (0)
  78272. #define PULLBYTE() \
  78273. do { \
  78274. if (have == 0) goto inf_leave; \
  78275. have--; \
  78276. hold += (unsigned long)(*next++) << bits; \
  78277. bits += 8; \
  78278. } while (0)
  78279. #define NEEDBITS(n) \
  78280. do { \
  78281. while (bits < (unsigned)(n)) \
  78282. PULLBYTE(); \
  78283. } while (0)
  78284. #define BITS(n) \
  78285. ((unsigned)hold & ((1U << (n)) - 1))
  78286. #define DROPBITS(n) \
  78287. do { \
  78288. hold >>= (n); \
  78289. bits -= (unsigned)(n); \
  78290. } while (0)
  78291. #define BYTEBITS() \
  78292. do { \
  78293. hold >>= bits & 7; \
  78294. bits -= bits & 7; \
  78295. } while (0)
  78296. #define REVERSE(q) \
  78297. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78298. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78299. int ZEXPORT inflate (z_streamp strm, int flush)
  78300. {
  78301. struct inflate_state FAR *state;
  78302. unsigned char FAR *next; /* next input */
  78303. unsigned char FAR *put; /* next output */
  78304. unsigned have, left; /* available input and output */
  78305. unsigned long hold; /* bit buffer */
  78306. unsigned bits; /* bits in bit buffer */
  78307. unsigned in, out; /* save starting available input and output */
  78308. unsigned copy; /* number of stored or match bytes to copy */
  78309. unsigned char FAR *from; /* where to copy match bytes from */
  78310. code thisx; /* current decoding table entry */
  78311. code last; /* parent table entry */
  78312. unsigned len; /* length to copy for repeats, bits to drop */
  78313. int ret; /* return code */
  78314. #ifdef GUNZIP
  78315. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78316. #endif
  78317. static const unsigned short order[19] = /* permutation of code lengths */
  78318. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78319. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78320. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78321. return Z_STREAM_ERROR;
  78322. state = (struct inflate_state FAR *)strm->state;
  78323. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78324. LOAD();
  78325. in = have;
  78326. out = left;
  78327. ret = Z_OK;
  78328. for (;;)
  78329. switch (state->mode) {
  78330. case HEAD:
  78331. if (state->wrap == 0) {
  78332. state->mode = TYPEDO;
  78333. break;
  78334. }
  78335. NEEDBITS(16);
  78336. #ifdef GUNZIP
  78337. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78338. state->check = crc32(0L, Z_NULL, 0);
  78339. CRC2(state->check, hold);
  78340. INITBITS();
  78341. state->mode = FLAGS;
  78342. break;
  78343. }
  78344. state->flags = 0; /* expect zlib header */
  78345. if (state->head != Z_NULL)
  78346. state->head->done = -1;
  78347. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78348. #else
  78349. if (
  78350. #endif
  78351. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78352. strm->msg = (char *)"incorrect header check";
  78353. state->mode = BAD;
  78354. break;
  78355. }
  78356. if (BITS(4) != Z_DEFLATED) {
  78357. strm->msg = (char *)"unknown compression method";
  78358. state->mode = BAD;
  78359. break;
  78360. }
  78361. DROPBITS(4);
  78362. len = BITS(4) + 8;
  78363. if (len > state->wbits) {
  78364. strm->msg = (char *)"invalid window size";
  78365. state->mode = BAD;
  78366. break;
  78367. }
  78368. state->dmax = 1U << len;
  78369. Tracev((stderr, "inflate: zlib header ok\n"));
  78370. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78371. state->mode = hold & 0x200 ? DICTID : TYPE;
  78372. INITBITS();
  78373. break;
  78374. #ifdef GUNZIP
  78375. case FLAGS:
  78376. NEEDBITS(16);
  78377. state->flags = (int)(hold);
  78378. if ((state->flags & 0xff) != Z_DEFLATED) {
  78379. strm->msg = (char *)"unknown compression method";
  78380. state->mode = BAD;
  78381. break;
  78382. }
  78383. if (state->flags & 0xe000) {
  78384. strm->msg = (char *)"unknown header flags set";
  78385. state->mode = BAD;
  78386. break;
  78387. }
  78388. if (state->head != Z_NULL)
  78389. state->head->text = (int)((hold >> 8) & 1);
  78390. if (state->flags & 0x0200) CRC2(state->check, hold);
  78391. INITBITS();
  78392. state->mode = TIME;
  78393. case TIME:
  78394. NEEDBITS(32);
  78395. if (state->head != Z_NULL)
  78396. state->head->time = hold;
  78397. if (state->flags & 0x0200) CRC4(state->check, hold);
  78398. INITBITS();
  78399. state->mode = OS;
  78400. case OS:
  78401. NEEDBITS(16);
  78402. if (state->head != Z_NULL) {
  78403. state->head->xflags = (int)(hold & 0xff);
  78404. state->head->os = (int)(hold >> 8);
  78405. }
  78406. if (state->flags & 0x0200) CRC2(state->check, hold);
  78407. INITBITS();
  78408. state->mode = EXLEN;
  78409. case EXLEN:
  78410. if (state->flags & 0x0400) {
  78411. NEEDBITS(16);
  78412. state->length = (unsigned)(hold);
  78413. if (state->head != Z_NULL)
  78414. state->head->extra_len = (unsigned)hold;
  78415. if (state->flags & 0x0200) CRC2(state->check, hold);
  78416. INITBITS();
  78417. }
  78418. else if (state->head != Z_NULL)
  78419. state->head->extra = Z_NULL;
  78420. state->mode = EXTRA;
  78421. case EXTRA:
  78422. if (state->flags & 0x0400) {
  78423. copy = state->length;
  78424. if (copy > have) copy = have;
  78425. if (copy) {
  78426. if (state->head != Z_NULL &&
  78427. state->head->extra != Z_NULL) {
  78428. len = state->head->extra_len - state->length;
  78429. zmemcpy(state->head->extra + len, next,
  78430. len + copy > state->head->extra_max ?
  78431. state->head->extra_max - len : copy);
  78432. }
  78433. if (state->flags & 0x0200)
  78434. state->check = crc32(state->check, next, copy);
  78435. have -= copy;
  78436. next += copy;
  78437. state->length -= copy;
  78438. }
  78439. if (state->length) goto inf_leave;
  78440. }
  78441. state->length = 0;
  78442. state->mode = NAME;
  78443. case NAME:
  78444. if (state->flags & 0x0800) {
  78445. if (have == 0) goto inf_leave;
  78446. copy = 0;
  78447. do {
  78448. len = (unsigned)(next[copy++]);
  78449. if (state->head != Z_NULL &&
  78450. state->head->name != Z_NULL &&
  78451. state->length < state->head->name_max)
  78452. state->head->name[state->length++] = len;
  78453. } while (len && copy < have);
  78454. if (state->flags & 0x0200)
  78455. state->check = crc32(state->check, next, copy);
  78456. have -= copy;
  78457. next += copy;
  78458. if (len) goto inf_leave;
  78459. }
  78460. else if (state->head != Z_NULL)
  78461. state->head->name = Z_NULL;
  78462. state->length = 0;
  78463. state->mode = COMMENT;
  78464. case COMMENT:
  78465. if (state->flags & 0x1000) {
  78466. if (have == 0) goto inf_leave;
  78467. copy = 0;
  78468. do {
  78469. len = (unsigned)(next[copy++]);
  78470. if (state->head != Z_NULL &&
  78471. state->head->comment != Z_NULL &&
  78472. state->length < state->head->comm_max)
  78473. state->head->comment[state->length++] = len;
  78474. } while (len && copy < have);
  78475. if (state->flags & 0x0200)
  78476. state->check = crc32(state->check, next, copy);
  78477. have -= copy;
  78478. next += copy;
  78479. if (len) goto inf_leave;
  78480. }
  78481. else if (state->head != Z_NULL)
  78482. state->head->comment = Z_NULL;
  78483. state->mode = HCRC;
  78484. case HCRC:
  78485. if (state->flags & 0x0200) {
  78486. NEEDBITS(16);
  78487. if (hold != (state->check & 0xffff)) {
  78488. strm->msg = (char *)"header crc mismatch";
  78489. state->mode = BAD;
  78490. break;
  78491. }
  78492. INITBITS();
  78493. }
  78494. if (state->head != Z_NULL) {
  78495. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78496. state->head->done = 1;
  78497. }
  78498. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78499. state->mode = TYPE;
  78500. break;
  78501. #endif
  78502. case DICTID:
  78503. NEEDBITS(32);
  78504. strm->adler = state->check = REVERSE(hold);
  78505. INITBITS();
  78506. state->mode = DICT;
  78507. case DICT:
  78508. if (state->havedict == 0) {
  78509. RESTORE();
  78510. return Z_NEED_DICT;
  78511. }
  78512. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78513. state->mode = TYPE;
  78514. case TYPE:
  78515. if (flush == Z_BLOCK) goto inf_leave;
  78516. case TYPEDO:
  78517. if (state->last) {
  78518. BYTEBITS();
  78519. state->mode = CHECK;
  78520. break;
  78521. }
  78522. NEEDBITS(3);
  78523. state->last = BITS(1);
  78524. DROPBITS(1);
  78525. switch (BITS(2)) {
  78526. case 0: /* stored block */
  78527. Tracev((stderr, "inflate: stored block%s\n",
  78528. state->last ? " (last)" : ""));
  78529. state->mode = STORED;
  78530. break;
  78531. case 1: /* fixed block */
  78532. fixedtables(state);
  78533. Tracev((stderr, "inflate: fixed codes block%s\n",
  78534. state->last ? " (last)" : ""));
  78535. state->mode = LEN; /* decode codes */
  78536. break;
  78537. case 2: /* dynamic block */
  78538. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78539. state->last ? " (last)" : ""));
  78540. state->mode = TABLE;
  78541. break;
  78542. case 3:
  78543. strm->msg = (char *)"invalid block type";
  78544. state->mode = BAD;
  78545. }
  78546. DROPBITS(2);
  78547. break;
  78548. case STORED:
  78549. BYTEBITS(); /* go to byte boundary */
  78550. NEEDBITS(32);
  78551. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78552. strm->msg = (char *)"invalid stored block lengths";
  78553. state->mode = BAD;
  78554. break;
  78555. }
  78556. state->length = (unsigned)hold & 0xffff;
  78557. Tracev((stderr, "inflate: stored length %u\n",
  78558. state->length));
  78559. INITBITS();
  78560. state->mode = COPY;
  78561. case COPY:
  78562. copy = state->length;
  78563. if (copy) {
  78564. if (copy > have) copy = have;
  78565. if (copy > left) copy = left;
  78566. if (copy == 0) goto inf_leave;
  78567. zmemcpy(put, next, copy);
  78568. have -= copy;
  78569. next += copy;
  78570. left -= copy;
  78571. put += copy;
  78572. state->length -= copy;
  78573. break;
  78574. }
  78575. Tracev((stderr, "inflate: stored end\n"));
  78576. state->mode = TYPE;
  78577. break;
  78578. case TABLE:
  78579. NEEDBITS(14);
  78580. state->nlen = BITS(5) + 257;
  78581. DROPBITS(5);
  78582. state->ndist = BITS(5) + 1;
  78583. DROPBITS(5);
  78584. state->ncode = BITS(4) + 4;
  78585. DROPBITS(4);
  78586. #ifndef PKZIP_BUG_WORKAROUND
  78587. if (state->nlen > 286 || state->ndist > 30) {
  78588. strm->msg = (char *)"too many length or distance symbols";
  78589. state->mode = BAD;
  78590. break;
  78591. }
  78592. #endif
  78593. Tracev((stderr, "inflate: table sizes ok\n"));
  78594. state->have = 0;
  78595. state->mode = LENLENS;
  78596. case LENLENS:
  78597. while (state->have < state->ncode) {
  78598. NEEDBITS(3);
  78599. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78600. DROPBITS(3);
  78601. }
  78602. while (state->have < 19)
  78603. state->lens[order[state->have++]] = 0;
  78604. state->next = state->codes;
  78605. state->lencode = (code const FAR *)(state->next);
  78606. state->lenbits = 7;
  78607. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78608. &(state->lenbits), state->work);
  78609. if (ret) {
  78610. strm->msg = (char *)"invalid code lengths set";
  78611. state->mode = BAD;
  78612. break;
  78613. }
  78614. Tracev((stderr, "inflate: code lengths ok\n"));
  78615. state->have = 0;
  78616. state->mode = CODELENS;
  78617. case CODELENS:
  78618. while (state->have < state->nlen + state->ndist) {
  78619. for (;;) {
  78620. thisx = state->lencode[BITS(state->lenbits)];
  78621. if ((unsigned)(thisx.bits) <= bits) break;
  78622. PULLBYTE();
  78623. }
  78624. if (thisx.val < 16) {
  78625. NEEDBITS(thisx.bits);
  78626. DROPBITS(thisx.bits);
  78627. state->lens[state->have++] = thisx.val;
  78628. }
  78629. else {
  78630. if (thisx.val == 16) {
  78631. NEEDBITS(thisx.bits + 2);
  78632. DROPBITS(thisx.bits);
  78633. if (state->have == 0) {
  78634. strm->msg = (char *)"invalid bit length repeat";
  78635. state->mode = BAD;
  78636. break;
  78637. }
  78638. len = state->lens[state->have - 1];
  78639. copy = 3 + BITS(2);
  78640. DROPBITS(2);
  78641. }
  78642. else if (thisx.val == 17) {
  78643. NEEDBITS(thisx.bits + 3);
  78644. DROPBITS(thisx.bits);
  78645. len = 0;
  78646. copy = 3 + BITS(3);
  78647. DROPBITS(3);
  78648. }
  78649. else {
  78650. NEEDBITS(thisx.bits + 7);
  78651. DROPBITS(thisx.bits);
  78652. len = 0;
  78653. copy = 11 + BITS(7);
  78654. DROPBITS(7);
  78655. }
  78656. if (state->have + copy > state->nlen + state->ndist) {
  78657. strm->msg = (char *)"invalid bit length repeat";
  78658. state->mode = BAD;
  78659. break;
  78660. }
  78661. while (copy--)
  78662. state->lens[state->have++] = (unsigned short)len;
  78663. }
  78664. }
  78665. if (state->mode == BAD) break;
  78666. state->next = state->codes;
  78667. state->lencode = (code const FAR *)(state->next);
  78668. state->lenbits = 9;
  78669. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78670. &(state->lenbits), state->work);
  78671. if (ret) {
  78672. strm->msg = (char *)"invalid literal/lengths set";
  78673. state->mode = BAD;
  78674. break;
  78675. }
  78676. state->distcode = (code const FAR *)(state->next);
  78677. state->distbits = 6;
  78678. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78679. &(state->next), &(state->distbits), state->work);
  78680. if (ret) {
  78681. strm->msg = (char *)"invalid distances set";
  78682. state->mode = BAD;
  78683. break;
  78684. }
  78685. Tracev((stderr, "inflate: codes ok\n"));
  78686. state->mode = LEN;
  78687. case LEN:
  78688. if (have >= 6 && left >= 258) {
  78689. RESTORE();
  78690. inflate_fast(strm, out);
  78691. LOAD();
  78692. break;
  78693. }
  78694. for (;;) {
  78695. thisx = state->lencode[BITS(state->lenbits)];
  78696. if ((unsigned)(thisx.bits) <= bits) break;
  78697. PULLBYTE();
  78698. }
  78699. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78700. last = thisx;
  78701. for (;;) {
  78702. thisx = state->lencode[last.val +
  78703. (BITS(last.bits + last.op) >> last.bits)];
  78704. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78705. PULLBYTE();
  78706. }
  78707. DROPBITS(last.bits);
  78708. }
  78709. DROPBITS(thisx.bits);
  78710. state->length = (unsigned)thisx.val;
  78711. if ((int)(thisx.op) == 0) {
  78712. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78713. "inflate: literal '%c'\n" :
  78714. "inflate: literal 0x%02x\n", thisx.val));
  78715. state->mode = LIT;
  78716. break;
  78717. }
  78718. if (thisx.op & 32) {
  78719. Tracevv((stderr, "inflate: end of block\n"));
  78720. state->mode = TYPE;
  78721. break;
  78722. }
  78723. if (thisx.op & 64) {
  78724. strm->msg = (char *)"invalid literal/length code";
  78725. state->mode = BAD;
  78726. break;
  78727. }
  78728. state->extra = (unsigned)(thisx.op) & 15;
  78729. state->mode = LENEXT;
  78730. case LENEXT:
  78731. if (state->extra) {
  78732. NEEDBITS(state->extra);
  78733. state->length += BITS(state->extra);
  78734. DROPBITS(state->extra);
  78735. }
  78736. Tracevv((stderr, "inflate: length %u\n", state->length));
  78737. state->mode = DIST;
  78738. case DIST:
  78739. for (;;) {
  78740. thisx = state->distcode[BITS(state->distbits)];
  78741. if ((unsigned)(thisx.bits) <= bits) break;
  78742. PULLBYTE();
  78743. }
  78744. if ((thisx.op & 0xf0) == 0) {
  78745. last = thisx;
  78746. for (;;) {
  78747. thisx = state->distcode[last.val +
  78748. (BITS(last.bits + last.op) >> last.bits)];
  78749. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78750. PULLBYTE();
  78751. }
  78752. DROPBITS(last.bits);
  78753. }
  78754. DROPBITS(thisx.bits);
  78755. if (thisx.op & 64) {
  78756. strm->msg = (char *)"invalid distance code";
  78757. state->mode = BAD;
  78758. break;
  78759. }
  78760. state->offset = (unsigned)thisx.val;
  78761. state->extra = (unsigned)(thisx.op) & 15;
  78762. state->mode = DISTEXT;
  78763. case DISTEXT:
  78764. if (state->extra) {
  78765. NEEDBITS(state->extra);
  78766. state->offset += BITS(state->extra);
  78767. DROPBITS(state->extra);
  78768. }
  78769. #ifdef INFLATE_STRICT
  78770. if (state->offset > state->dmax) {
  78771. strm->msg = (char *)"invalid distance too far back";
  78772. state->mode = BAD;
  78773. break;
  78774. }
  78775. #endif
  78776. if (state->offset > state->whave + out - left) {
  78777. strm->msg = (char *)"invalid distance too far back";
  78778. state->mode = BAD;
  78779. break;
  78780. }
  78781. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78782. state->mode = MATCH;
  78783. case MATCH:
  78784. if (left == 0) goto inf_leave;
  78785. copy = out - left;
  78786. if (state->offset > copy) { /* copy from window */
  78787. copy = state->offset - copy;
  78788. if (copy > state->write) {
  78789. copy -= state->write;
  78790. from = state->window + (state->wsize - copy);
  78791. }
  78792. else
  78793. from = state->window + (state->write - copy);
  78794. if (copy > state->length) copy = state->length;
  78795. }
  78796. else { /* copy from output */
  78797. from = put - state->offset;
  78798. copy = state->length;
  78799. }
  78800. if (copy > left) copy = left;
  78801. left -= copy;
  78802. state->length -= copy;
  78803. do {
  78804. *put++ = *from++;
  78805. } while (--copy);
  78806. if (state->length == 0) state->mode = LEN;
  78807. break;
  78808. case LIT:
  78809. if (left == 0) goto inf_leave;
  78810. *put++ = (unsigned char)(state->length);
  78811. left--;
  78812. state->mode = LEN;
  78813. break;
  78814. case CHECK:
  78815. if (state->wrap) {
  78816. NEEDBITS(32);
  78817. out -= left;
  78818. strm->total_out += out;
  78819. state->total += out;
  78820. if (out)
  78821. strm->adler = state->check =
  78822. UPDATE(state->check, put - out, out);
  78823. out = left;
  78824. if ((
  78825. #ifdef GUNZIP
  78826. state->flags ? hold :
  78827. #endif
  78828. REVERSE(hold)) != state->check) {
  78829. strm->msg = (char *)"incorrect data check";
  78830. state->mode = BAD;
  78831. break;
  78832. }
  78833. INITBITS();
  78834. Tracev((stderr, "inflate: check matches trailer\n"));
  78835. }
  78836. #ifdef GUNZIP
  78837. state->mode = LENGTH;
  78838. case LENGTH:
  78839. if (state->wrap && state->flags) {
  78840. NEEDBITS(32);
  78841. if (hold != (state->total & 0xffffffffUL)) {
  78842. strm->msg = (char *)"incorrect length check";
  78843. state->mode = BAD;
  78844. break;
  78845. }
  78846. INITBITS();
  78847. Tracev((stderr, "inflate: length matches trailer\n"));
  78848. }
  78849. #endif
  78850. state->mode = DONE;
  78851. case DONE:
  78852. ret = Z_STREAM_END;
  78853. goto inf_leave;
  78854. case BAD:
  78855. ret = Z_DATA_ERROR;
  78856. goto inf_leave;
  78857. case MEM:
  78858. return Z_MEM_ERROR;
  78859. case SYNC:
  78860. default:
  78861. return Z_STREAM_ERROR;
  78862. }
  78863. inf_leave:
  78864. RESTORE();
  78865. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78866. if (updatewindow(strm, out)) {
  78867. state->mode = MEM;
  78868. return Z_MEM_ERROR;
  78869. }
  78870. in -= strm->avail_in;
  78871. out -= strm->avail_out;
  78872. strm->total_in += in;
  78873. strm->total_out += out;
  78874. state->total += out;
  78875. if (state->wrap && out)
  78876. strm->adler = state->check =
  78877. UPDATE(state->check, strm->next_out - out, out);
  78878. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78879. (state->mode == TYPE ? 128 : 0);
  78880. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78881. ret = Z_BUF_ERROR;
  78882. return ret;
  78883. }
  78884. int ZEXPORT inflateEnd (z_streamp strm)
  78885. {
  78886. struct inflate_state FAR *state;
  78887. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78888. return Z_STREAM_ERROR;
  78889. state = (struct inflate_state FAR *)strm->state;
  78890. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78891. ZFREE(strm, strm->state);
  78892. strm->state = Z_NULL;
  78893. Tracev((stderr, "inflate: end\n"));
  78894. return Z_OK;
  78895. }
  78896. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  78897. {
  78898. struct inflate_state FAR *state;
  78899. unsigned long id_;
  78900. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78901. state = (struct inflate_state FAR *)strm->state;
  78902. if (state->wrap != 0 && state->mode != DICT)
  78903. return Z_STREAM_ERROR;
  78904. if (state->mode == DICT) {
  78905. id_ = adler32(0L, Z_NULL, 0);
  78906. id_ = adler32(id_, dictionary, dictLength);
  78907. if (id_ != state->check)
  78908. return Z_DATA_ERROR;
  78909. }
  78910. if (updatewindow(strm, strm->avail_out)) {
  78911. state->mode = MEM;
  78912. return Z_MEM_ERROR;
  78913. }
  78914. if (dictLength > state->wsize) {
  78915. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  78916. state->wsize);
  78917. state->whave = state->wsize;
  78918. }
  78919. else {
  78920. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  78921. dictLength);
  78922. state->whave = dictLength;
  78923. }
  78924. state->havedict = 1;
  78925. Tracev((stderr, "inflate: dictionary set\n"));
  78926. return Z_OK;
  78927. }
  78928. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  78929. {
  78930. struct inflate_state FAR *state;
  78931. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78932. state = (struct inflate_state FAR *)strm->state;
  78933. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  78934. state->head = head;
  78935. head->done = 0;
  78936. return Z_OK;
  78937. }
  78938. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  78939. {
  78940. unsigned got;
  78941. unsigned next;
  78942. got = *have;
  78943. next = 0;
  78944. while (next < len && got < 4) {
  78945. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  78946. got++;
  78947. else if (buf[next])
  78948. got = 0;
  78949. else
  78950. got = 4 - got;
  78951. next++;
  78952. }
  78953. *have = got;
  78954. return next;
  78955. }
  78956. int ZEXPORT inflateSync (z_streamp strm)
  78957. {
  78958. unsigned len; /* number of bytes to look at or looked at */
  78959. unsigned long in, out; /* temporary to save total_in and total_out */
  78960. unsigned char buf[4]; /* to restore bit buffer to byte string */
  78961. struct inflate_state FAR *state;
  78962. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78963. state = (struct inflate_state FAR *)strm->state;
  78964. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  78965. if (state->mode != SYNC) {
  78966. state->mode = SYNC;
  78967. state->hold <<= state->bits & 7;
  78968. state->bits -= state->bits & 7;
  78969. len = 0;
  78970. while (state->bits >= 8) {
  78971. buf[len++] = (unsigned char)(state->hold);
  78972. state->hold >>= 8;
  78973. state->bits -= 8;
  78974. }
  78975. state->have = 0;
  78976. syncsearch(&(state->have), buf, len);
  78977. }
  78978. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  78979. strm->avail_in -= len;
  78980. strm->next_in += len;
  78981. strm->total_in += len;
  78982. if (state->have != 4) return Z_DATA_ERROR;
  78983. in = strm->total_in; out = strm->total_out;
  78984. inflateReset(strm);
  78985. strm->total_in = in; strm->total_out = out;
  78986. state->mode = TYPE;
  78987. return Z_OK;
  78988. }
  78989. int ZEXPORT inflateSyncPoint (z_streamp strm)
  78990. {
  78991. struct inflate_state FAR *state;
  78992. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78993. state = (struct inflate_state FAR *)strm->state;
  78994. return state->mode == STORED && state->bits == 0;
  78995. }
  78996. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  78997. {
  78998. struct inflate_state FAR *state;
  78999. struct inflate_state FAR *copy;
  79000. unsigned char FAR *window;
  79001. unsigned wsize;
  79002. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79003. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79004. return Z_STREAM_ERROR;
  79005. state = (struct inflate_state FAR *)source->state;
  79006. copy = (struct inflate_state FAR *)
  79007. ZALLOC(source, 1, sizeof(struct inflate_state));
  79008. if (copy == Z_NULL) return Z_MEM_ERROR;
  79009. window = Z_NULL;
  79010. if (state->window != Z_NULL) {
  79011. window = (unsigned char FAR *)
  79012. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79013. if (window == Z_NULL) {
  79014. ZFREE(source, copy);
  79015. return Z_MEM_ERROR;
  79016. }
  79017. }
  79018. zmemcpy(dest, source, sizeof(z_stream));
  79019. zmemcpy(copy, state, sizeof(struct inflate_state));
  79020. if (state->lencode >= state->codes &&
  79021. state->lencode <= state->codes + ENOUGH - 1) {
  79022. copy->lencode = copy->codes + (state->lencode - state->codes);
  79023. copy->distcode = copy->codes + (state->distcode - state->codes);
  79024. }
  79025. copy->next = copy->codes + (state->next - state->codes);
  79026. if (window != Z_NULL) {
  79027. wsize = 1U << state->wbits;
  79028. zmemcpy(window, state->window, wsize);
  79029. }
  79030. copy->window = window;
  79031. dest->state = (struct internal_state FAR *)copy;
  79032. return Z_OK;
  79033. }
  79034. /*** End of inlined file: inflate.c ***/
  79035. /*** Start of inlined file: inftrees.c ***/
  79036. #define MAXBITS 15
  79037. const char inflate_copyright[] =
  79038. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79039. int inflate_table (codetype type,
  79040. unsigned short FAR *lens,
  79041. unsigned codes,
  79042. code FAR * FAR *table,
  79043. unsigned FAR *bits,
  79044. unsigned short FAR *work)
  79045. {
  79046. unsigned len; /* a code's length in bits */
  79047. unsigned sym; /* index of code symbols */
  79048. unsigned min, max; /* minimum and maximum code lengths */
  79049. unsigned root; /* number of index bits for root table */
  79050. unsigned curr; /* number of index bits for current table */
  79051. unsigned drop; /* code bits to drop for sub-table */
  79052. int left; /* number of prefix codes available */
  79053. unsigned used; /* code entries in table used */
  79054. unsigned huff; /* Huffman code */
  79055. unsigned incr; /* for incrementing code, index */
  79056. unsigned fill; /* index for replicating entries */
  79057. unsigned low; /* low bits for current root entry */
  79058. unsigned mask; /* mask for low root bits */
  79059. code thisx; /* table entry for duplication */
  79060. code FAR *next; /* next available space in table */
  79061. const unsigned short FAR *base; /* base value table to use */
  79062. const unsigned short FAR *extra; /* extra bits table to use */
  79063. int end; /* use base and extra for symbol > end */
  79064. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79065. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79066. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79067. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79068. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79069. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79070. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79071. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79072. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79073. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79074. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79075. 8193, 12289, 16385, 24577, 0, 0};
  79076. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79077. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79078. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79079. 28, 28, 29, 29, 64, 64};
  79080. for (len = 0; len <= MAXBITS; len++)
  79081. count[len] = 0;
  79082. for (sym = 0; sym < codes; sym++)
  79083. count[lens[sym]]++;
  79084. root = *bits;
  79085. for (max = MAXBITS; max >= 1; max--)
  79086. if (count[max] != 0) break;
  79087. if (root > max) root = max;
  79088. if (max == 0) { /* no symbols to code at all */
  79089. thisx.op = (unsigned char)64; /* invalid code marker */
  79090. thisx.bits = (unsigned char)1;
  79091. thisx.val = (unsigned short)0;
  79092. *(*table)++ = thisx; /* make a table to force an error */
  79093. *(*table)++ = thisx;
  79094. *bits = 1;
  79095. return 0; /* no symbols, but wait for decoding to report error */
  79096. }
  79097. for (min = 1; min <= MAXBITS; min++)
  79098. if (count[min] != 0) break;
  79099. if (root < min) root = min;
  79100. left = 1;
  79101. for (len = 1; len <= MAXBITS; len++) {
  79102. left <<= 1;
  79103. left -= count[len];
  79104. if (left < 0) return -1; /* over-subscribed */
  79105. }
  79106. if (left > 0 && (type == CODES || max != 1))
  79107. return -1; /* incomplete set */
  79108. offs[1] = 0;
  79109. for (len = 1; len < MAXBITS; len++)
  79110. offs[len + 1] = offs[len] + count[len];
  79111. for (sym = 0; sym < codes; sym++)
  79112. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79113. switch (type) {
  79114. case CODES:
  79115. base = extra = work; /* dummy value--not used */
  79116. end = 19;
  79117. break;
  79118. case LENS:
  79119. base = lbase;
  79120. base -= 257;
  79121. extra = lext;
  79122. extra -= 257;
  79123. end = 256;
  79124. break;
  79125. default: /* DISTS */
  79126. base = dbase;
  79127. extra = dext;
  79128. end = -1;
  79129. }
  79130. huff = 0; /* starting code */
  79131. sym = 0; /* starting code symbol */
  79132. len = min; /* starting code length */
  79133. next = *table; /* current table to fill in */
  79134. curr = root; /* current table index bits */
  79135. drop = 0; /* current bits to drop from code for index */
  79136. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79137. used = 1U << root; /* use root table entries */
  79138. mask = used - 1; /* mask for comparing low */
  79139. if (type == LENS && used >= ENOUGH - MAXD)
  79140. return 1;
  79141. for (;;) {
  79142. thisx.bits = (unsigned char)(len - drop);
  79143. if ((int)(work[sym]) < end) {
  79144. thisx.op = (unsigned char)0;
  79145. thisx.val = work[sym];
  79146. }
  79147. else if ((int)(work[sym]) > end) {
  79148. thisx.op = (unsigned char)(extra[work[sym]]);
  79149. thisx.val = base[work[sym]];
  79150. }
  79151. else {
  79152. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79153. thisx.val = 0;
  79154. }
  79155. incr = 1U << (len - drop);
  79156. fill = 1U << curr;
  79157. min = fill; /* save offset to next table */
  79158. do {
  79159. fill -= incr;
  79160. next[(huff >> drop) + fill] = thisx;
  79161. } while (fill != 0);
  79162. incr = 1U << (len - 1);
  79163. while (huff & incr)
  79164. incr >>= 1;
  79165. if (incr != 0) {
  79166. huff &= incr - 1;
  79167. huff += incr;
  79168. }
  79169. else
  79170. huff = 0;
  79171. sym++;
  79172. if (--(count[len]) == 0) {
  79173. if (len == max) break;
  79174. len = lens[work[sym]];
  79175. }
  79176. if (len > root && (huff & mask) != low) {
  79177. if (drop == 0)
  79178. drop = root;
  79179. next += min; /* here min is 1 << curr */
  79180. curr = len - drop;
  79181. left = (int)(1 << curr);
  79182. while (curr + drop < max) {
  79183. left -= count[curr + drop];
  79184. if (left <= 0) break;
  79185. curr++;
  79186. left <<= 1;
  79187. }
  79188. used += 1U << curr;
  79189. if (type == LENS && used >= ENOUGH - MAXD)
  79190. return 1;
  79191. low = huff & mask;
  79192. (*table)[low].op = (unsigned char)curr;
  79193. (*table)[low].bits = (unsigned char)root;
  79194. (*table)[low].val = (unsigned short)(next - *table);
  79195. }
  79196. }
  79197. thisx.op = (unsigned char)64; /* invalid code marker */
  79198. thisx.bits = (unsigned char)(len - drop);
  79199. thisx.val = (unsigned short)0;
  79200. while (huff != 0) {
  79201. if (drop != 0 && (huff & mask) != low) {
  79202. drop = 0;
  79203. len = root;
  79204. next = *table;
  79205. thisx.bits = (unsigned char)len;
  79206. }
  79207. next[huff >> drop] = thisx;
  79208. incr = 1U << (len - 1);
  79209. while (huff & incr)
  79210. incr >>= 1;
  79211. if (incr != 0) {
  79212. huff &= incr - 1;
  79213. huff += incr;
  79214. }
  79215. else
  79216. huff = 0;
  79217. }
  79218. *table += used;
  79219. *bits = root;
  79220. return 0;
  79221. }
  79222. /*** End of inlined file: inftrees.c ***/
  79223. /*** Start of inlined file: trees.c ***/
  79224. #ifdef DEBUG
  79225. # include <ctype.h>
  79226. #endif
  79227. #define MAX_BL_BITS 7
  79228. #define END_BLOCK 256
  79229. #define REP_3_6 16
  79230. #define REPZ_3_10 17
  79231. #define REPZ_11_138 18
  79232. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79233. = {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};
  79234. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79235. = {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};
  79236. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79237. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79238. local const uch bl_order[BL_CODES]
  79239. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79240. #define Buf_size (8 * 2*sizeof(char))
  79241. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79242. #if defined(GEN_TREES_H) || !defined(STDC)
  79243. local ct_data static_ltree[L_CODES+2];
  79244. local ct_data static_dtree[D_CODES];
  79245. uch _dist_code[DIST_CODE_LEN];
  79246. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79247. local int base_length[LENGTH_CODES];
  79248. local int base_dist[D_CODES];
  79249. #else
  79250. /*** Start of inlined file: trees.h ***/
  79251. local const ct_data static_ltree[L_CODES+2] = {
  79252. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79253. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79254. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79255. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79256. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79257. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79258. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79259. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79260. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79261. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79262. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79263. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79264. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79265. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79266. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79267. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79268. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79269. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79270. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79271. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79272. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79273. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79274. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79275. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79276. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79277. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79278. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79279. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79280. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79281. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79282. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79283. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79284. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79285. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79286. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79287. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79288. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79289. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79290. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79291. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79292. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79293. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79294. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79295. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79296. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79297. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79298. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79299. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79300. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79301. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79302. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79303. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79304. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79305. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79306. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79307. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79308. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79309. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79310. };
  79311. local const ct_data static_dtree[D_CODES] = {
  79312. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79313. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79314. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79315. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79316. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79317. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79318. };
  79319. const uch _dist_code[DIST_CODE_LEN] = {
  79320. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79321. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79322. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79323. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79324. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79325. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79326. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79327. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79328. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79329. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79330. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79331. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79332. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79333. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79334. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79335. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79336. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79337. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79338. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79339. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79340. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79341. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79342. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79343. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79344. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79345. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79346. };
  79347. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79348. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79349. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79350. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79351. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79352. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79353. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79354. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79355. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79356. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79357. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79358. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79359. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79360. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79361. };
  79362. local const int base_length[LENGTH_CODES] = {
  79363. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79364. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79365. };
  79366. local const int base_dist[D_CODES] = {
  79367. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79368. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79369. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79370. };
  79371. /*** End of inlined file: trees.h ***/
  79372. #endif /* GEN_TREES_H */
  79373. struct static_tree_desc_s {
  79374. const ct_data *static_tree; /* static tree or NULL */
  79375. const intf *extra_bits; /* extra bits for each code or NULL */
  79376. int extra_base; /* base index for extra_bits */
  79377. int elems; /* max number of elements in the tree */
  79378. int max_length; /* max bit length for the codes */
  79379. };
  79380. local static_tree_desc static_l_desc =
  79381. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79382. local static_tree_desc static_d_desc =
  79383. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79384. local static_tree_desc static_bl_desc =
  79385. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79386. local void tr_static_init OF((void));
  79387. local void init_block OF((deflate_state *s));
  79388. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79389. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79390. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79391. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79392. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79393. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79394. local int build_bl_tree OF((deflate_state *s));
  79395. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79396. int blcodes));
  79397. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79398. ct_data *dtree));
  79399. local void set_data_type OF((deflate_state *s));
  79400. local unsigned bi_reverse OF((unsigned value, int length));
  79401. local void bi_windup OF((deflate_state *s));
  79402. local void bi_flush OF((deflate_state *s));
  79403. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79404. int header));
  79405. #ifdef GEN_TREES_H
  79406. local void gen_trees_header OF((void));
  79407. #endif
  79408. #ifndef DEBUG
  79409. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79410. #else /* DEBUG */
  79411. # define send_code(s, c, tree) \
  79412. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79413. send_bits(s, tree[c].Code, tree[c].Len); }
  79414. #endif
  79415. #define put_short(s, w) { \
  79416. put_byte(s, (uch)((w) & 0xff)); \
  79417. put_byte(s, (uch)((ush)(w) >> 8)); \
  79418. }
  79419. #ifdef DEBUG
  79420. local void send_bits OF((deflate_state *s, int value, int length));
  79421. local void send_bits (deflate_state *s, int value, int length)
  79422. {
  79423. Tracevv((stderr," l %2d v %4x ", length, value));
  79424. Assert(length > 0 && length <= 15, "invalid length");
  79425. s->bits_sent += (ulg)length;
  79426. if (s->bi_valid > (int)Buf_size - length) {
  79427. s->bi_buf |= (value << s->bi_valid);
  79428. put_short(s, s->bi_buf);
  79429. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79430. s->bi_valid += length - Buf_size;
  79431. } else {
  79432. s->bi_buf |= value << s->bi_valid;
  79433. s->bi_valid += length;
  79434. }
  79435. }
  79436. #else /* !DEBUG */
  79437. #define send_bits(s, value, length) \
  79438. { int len = length;\
  79439. if (s->bi_valid > (int)Buf_size - len) {\
  79440. int val = value;\
  79441. s->bi_buf |= (val << s->bi_valid);\
  79442. put_short(s, s->bi_buf);\
  79443. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79444. s->bi_valid += len - Buf_size;\
  79445. } else {\
  79446. s->bi_buf |= (value) << s->bi_valid;\
  79447. s->bi_valid += len;\
  79448. }\
  79449. }
  79450. #endif /* DEBUG */
  79451. local void tr_static_init()
  79452. {
  79453. #if defined(GEN_TREES_H) || !defined(STDC)
  79454. static int static_init_done = 0;
  79455. int n; /* iterates over tree elements */
  79456. int bits; /* bit counter */
  79457. int length; /* length value */
  79458. int code; /* code value */
  79459. int dist; /* distance index */
  79460. ush bl_count[MAX_BITS+1];
  79461. if (static_init_done) return;
  79462. static_l_desc.static_tree = static_ltree;
  79463. static_l_desc.extra_bits = extra_lbits;
  79464. static_d_desc.static_tree = static_dtree;
  79465. static_d_desc.extra_bits = extra_dbits;
  79466. static_bl_desc.extra_bits = extra_blbits;
  79467. length = 0;
  79468. for (code = 0; code < LENGTH_CODES-1; code++) {
  79469. base_length[code] = length;
  79470. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79471. _length_code[length++] = (uch)code;
  79472. }
  79473. }
  79474. Assert (length == 256, "tr_static_init: length != 256");
  79475. _length_code[length-1] = (uch)code;
  79476. dist = 0;
  79477. for (code = 0 ; code < 16; code++) {
  79478. base_dist[code] = dist;
  79479. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79480. _dist_code[dist++] = (uch)code;
  79481. }
  79482. }
  79483. Assert (dist == 256, "tr_static_init: dist != 256");
  79484. dist >>= 7; /* from now on, all distances are divided by 128 */
  79485. for ( ; code < D_CODES; code++) {
  79486. base_dist[code] = dist << 7;
  79487. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79488. _dist_code[256 + dist++] = (uch)code;
  79489. }
  79490. }
  79491. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79492. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79493. n = 0;
  79494. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79495. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79496. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79497. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79498. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79499. for (n = 0; n < D_CODES; n++) {
  79500. static_dtree[n].Len = 5;
  79501. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79502. }
  79503. static_init_done = 1;
  79504. # ifdef GEN_TREES_H
  79505. gen_trees_header();
  79506. # endif
  79507. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79508. }
  79509. #ifdef GEN_TREES_H
  79510. # ifndef DEBUG
  79511. # include <stdio.h>
  79512. # endif
  79513. # define SEPARATOR(i, last, width) \
  79514. ((i) == (last)? "\n};\n\n" : \
  79515. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79516. void gen_trees_header()
  79517. {
  79518. FILE *header = fopen("trees.h", "w");
  79519. int i;
  79520. Assert (header != NULL, "Can't open trees.h");
  79521. fprintf(header,
  79522. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79523. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79524. for (i = 0; i < L_CODES+2; i++) {
  79525. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79526. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79527. }
  79528. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79529. for (i = 0; i < D_CODES; i++) {
  79530. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79531. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79532. }
  79533. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79534. for (i = 0; i < DIST_CODE_LEN; i++) {
  79535. fprintf(header, "%2u%s", _dist_code[i],
  79536. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79537. }
  79538. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79539. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79540. fprintf(header, "%2u%s", _length_code[i],
  79541. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79542. }
  79543. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79544. for (i = 0; i < LENGTH_CODES; i++) {
  79545. fprintf(header, "%1u%s", base_length[i],
  79546. SEPARATOR(i, LENGTH_CODES-1, 20));
  79547. }
  79548. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79549. for (i = 0; i < D_CODES; i++) {
  79550. fprintf(header, "%5u%s", base_dist[i],
  79551. SEPARATOR(i, D_CODES-1, 10));
  79552. }
  79553. fclose(header);
  79554. }
  79555. #endif /* GEN_TREES_H */
  79556. void _tr_init(deflate_state *s)
  79557. {
  79558. tr_static_init();
  79559. s->l_desc.dyn_tree = s->dyn_ltree;
  79560. s->l_desc.stat_desc = &static_l_desc;
  79561. s->d_desc.dyn_tree = s->dyn_dtree;
  79562. s->d_desc.stat_desc = &static_d_desc;
  79563. s->bl_desc.dyn_tree = s->bl_tree;
  79564. s->bl_desc.stat_desc = &static_bl_desc;
  79565. s->bi_buf = 0;
  79566. s->bi_valid = 0;
  79567. s->last_eob_len = 8; /* enough lookahead for inflate */
  79568. #ifdef DEBUG
  79569. s->compressed_len = 0L;
  79570. s->bits_sent = 0L;
  79571. #endif
  79572. init_block(s);
  79573. }
  79574. local void init_block (deflate_state *s)
  79575. {
  79576. int n; /* iterates over tree elements */
  79577. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79578. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79579. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79580. s->dyn_ltree[END_BLOCK].Freq = 1;
  79581. s->opt_len = s->static_len = 0L;
  79582. s->last_lit = s->matches = 0;
  79583. }
  79584. #define SMALLEST 1
  79585. #define pqremove(s, tree, top) \
  79586. {\
  79587. top = s->heap[SMALLEST]; \
  79588. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79589. pqdownheap(s, tree, SMALLEST); \
  79590. }
  79591. #define smaller(tree, n, m, depth) \
  79592. (tree[n].Freq < tree[m].Freq || \
  79593. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79594. local void pqdownheap (deflate_state *s,
  79595. ct_data *tree, /* the tree to restore */
  79596. int k) /* node to move down */
  79597. {
  79598. int v = s->heap[k];
  79599. int j = k << 1; /* left son of k */
  79600. while (j <= s->heap_len) {
  79601. if (j < s->heap_len &&
  79602. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79603. j++;
  79604. }
  79605. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79606. s->heap[k] = s->heap[j]; k = j;
  79607. j <<= 1;
  79608. }
  79609. s->heap[k] = v;
  79610. }
  79611. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79612. {
  79613. ct_data *tree = desc->dyn_tree;
  79614. int max_code = desc->max_code;
  79615. const ct_data *stree = desc->stat_desc->static_tree;
  79616. const intf *extra = desc->stat_desc->extra_bits;
  79617. int base = desc->stat_desc->extra_base;
  79618. int max_length = desc->stat_desc->max_length;
  79619. int h; /* heap index */
  79620. int n, m; /* iterate over the tree elements */
  79621. int bits; /* bit length */
  79622. int xbits; /* extra bits */
  79623. ush f; /* frequency */
  79624. int overflow = 0; /* number of elements with bit length too large */
  79625. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79626. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79627. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79628. n = s->heap[h];
  79629. bits = tree[tree[n].Dad].Len + 1;
  79630. if (bits > max_length) bits = max_length, overflow++;
  79631. tree[n].Len = (ush)bits;
  79632. if (n > max_code) continue; /* not a leaf node */
  79633. s->bl_count[bits]++;
  79634. xbits = 0;
  79635. if (n >= base) xbits = extra[n-base];
  79636. f = tree[n].Freq;
  79637. s->opt_len += (ulg)f * (bits + xbits);
  79638. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79639. }
  79640. if (overflow == 0) return;
  79641. Trace((stderr,"\nbit length overflow\n"));
  79642. do {
  79643. bits = max_length-1;
  79644. while (s->bl_count[bits] == 0) bits--;
  79645. s->bl_count[bits]--; /* move one leaf down the tree */
  79646. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79647. s->bl_count[max_length]--;
  79648. overflow -= 2;
  79649. } while (overflow > 0);
  79650. for (bits = max_length; bits != 0; bits--) {
  79651. n = s->bl_count[bits];
  79652. while (n != 0) {
  79653. m = s->heap[--h];
  79654. if (m > max_code) continue;
  79655. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79656. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79657. s->opt_len += ((long)bits - (long)tree[m].Len)
  79658. *(long)tree[m].Freq;
  79659. tree[m].Len = (ush)bits;
  79660. }
  79661. n--;
  79662. }
  79663. }
  79664. }
  79665. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79666. int max_code, /* largest code with non zero frequency */
  79667. ushf *bl_count) /* number of codes at each bit length */
  79668. {
  79669. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79670. ush code = 0; /* running code value */
  79671. int bits; /* bit index */
  79672. int n; /* code index */
  79673. for (bits = 1; bits <= MAX_BITS; bits++) {
  79674. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79675. }
  79676. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79677. "inconsistent bit counts");
  79678. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79679. for (n = 0; n <= max_code; n++) {
  79680. int len = tree[n].Len;
  79681. if (len == 0) continue;
  79682. tree[n].Code = bi_reverse(next_code[len]++, len);
  79683. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79684. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79685. }
  79686. }
  79687. local void build_tree (deflate_state *s,
  79688. tree_desc *desc) /* the tree descriptor */
  79689. {
  79690. ct_data *tree = desc->dyn_tree;
  79691. const ct_data *stree = desc->stat_desc->static_tree;
  79692. int elems = desc->stat_desc->elems;
  79693. int n, m; /* iterate over heap elements */
  79694. int max_code = -1; /* largest code with non zero frequency */
  79695. int node; /* new node being created */
  79696. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79697. for (n = 0; n < elems; n++) {
  79698. if (tree[n].Freq != 0) {
  79699. s->heap[++(s->heap_len)] = max_code = n;
  79700. s->depth[n] = 0;
  79701. } else {
  79702. tree[n].Len = 0;
  79703. }
  79704. }
  79705. while (s->heap_len < 2) {
  79706. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79707. tree[node].Freq = 1;
  79708. s->depth[node] = 0;
  79709. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79710. }
  79711. desc->max_code = max_code;
  79712. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79713. node = elems; /* next internal node of the tree */
  79714. do {
  79715. pqremove(s, tree, n); /* n = node of least frequency */
  79716. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79717. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79718. s->heap[--(s->heap_max)] = m;
  79719. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79720. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79721. s->depth[n] : s->depth[m]) + 1);
  79722. tree[n].Dad = tree[m].Dad = (ush)node;
  79723. #ifdef DUMP_BL_TREE
  79724. if (tree == s->bl_tree) {
  79725. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79726. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79727. }
  79728. #endif
  79729. s->heap[SMALLEST] = node++;
  79730. pqdownheap(s, tree, SMALLEST);
  79731. } while (s->heap_len >= 2);
  79732. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79733. gen_bitlen(s, (tree_desc *)desc);
  79734. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79735. }
  79736. local void scan_tree (deflate_state *s,
  79737. ct_data *tree, /* the tree to be scanned */
  79738. int max_code) /* and its largest code of non zero frequency */
  79739. {
  79740. int n; /* iterates over all tree elements */
  79741. int prevlen = -1; /* last emitted length */
  79742. int curlen; /* length of current code */
  79743. int nextlen = tree[0].Len; /* length of next code */
  79744. int count = 0; /* repeat count of the current code */
  79745. int max_count = 7; /* max repeat count */
  79746. int min_count = 4; /* min repeat count */
  79747. if (nextlen == 0) max_count = 138, min_count = 3;
  79748. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79749. for (n = 0; n <= max_code; n++) {
  79750. curlen = nextlen; nextlen = tree[n+1].Len;
  79751. if (++count < max_count && curlen == nextlen) {
  79752. continue;
  79753. } else if (count < min_count) {
  79754. s->bl_tree[curlen].Freq += count;
  79755. } else if (curlen != 0) {
  79756. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79757. s->bl_tree[REP_3_6].Freq++;
  79758. } else if (count <= 10) {
  79759. s->bl_tree[REPZ_3_10].Freq++;
  79760. } else {
  79761. s->bl_tree[REPZ_11_138].Freq++;
  79762. }
  79763. count = 0; prevlen = curlen;
  79764. if (nextlen == 0) {
  79765. max_count = 138, min_count = 3;
  79766. } else if (curlen == nextlen) {
  79767. max_count = 6, min_count = 3;
  79768. } else {
  79769. max_count = 7, min_count = 4;
  79770. }
  79771. }
  79772. }
  79773. local void send_tree (deflate_state *s,
  79774. ct_data *tree, /* the tree to be scanned */
  79775. int max_code) /* and its largest code of non zero frequency */
  79776. {
  79777. int n; /* iterates over all tree elements */
  79778. int prevlen = -1; /* last emitted length */
  79779. int curlen; /* length of current code */
  79780. int nextlen = tree[0].Len; /* length of next code */
  79781. int count = 0; /* repeat count of the current code */
  79782. int max_count = 7; /* max repeat count */
  79783. int min_count = 4; /* min repeat count */
  79784. /* guard already set */
  79785. if (nextlen == 0) max_count = 138, min_count = 3;
  79786. for (n = 0; n <= max_code; n++) {
  79787. curlen = nextlen; nextlen = tree[n+1].Len;
  79788. if (++count < max_count && curlen == nextlen) {
  79789. continue;
  79790. } else if (count < min_count) {
  79791. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79792. } else if (curlen != 0) {
  79793. if (curlen != prevlen) {
  79794. send_code(s, curlen, s->bl_tree); count--;
  79795. }
  79796. Assert(count >= 3 && count <= 6, " 3_6?");
  79797. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79798. } else if (count <= 10) {
  79799. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79800. } else {
  79801. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79802. }
  79803. count = 0; prevlen = curlen;
  79804. if (nextlen == 0) {
  79805. max_count = 138, min_count = 3;
  79806. } else if (curlen == nextlen) {
  79807. max_count = 6, min_count = 3;
  79808. } else {
  79809. max_count = 7, min_count = 4;
  79810. }
  79811. }
  79812. }
  79813. local int build_bl_tree (deflate_state *s)
  79814. {
  79815. int max_blindex; /* index of last bit length code of non zero freq */
  79816. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79817. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79818. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79819. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79820. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79821. }
  79822. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79823. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79824. s->opt_len, s->static_len));
  79825. return max_blindex;
  79826. }
  79827. local void send_all_trees (deflate_state *s,
  79828. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79829. {
  79830. int rank; /* index in bl_order */
  79831. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79832. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79833. "too many codes");
  79834. Tracev((stderr, "\nbl counts: "));
  79835. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79836. send_bits(s, dcodes-1, 5);
  79837. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79838. for (rank = 0; rank < blcodes; rank++) {
  79839. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79840. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79841. }
  79842. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79843. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79844. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79845. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79846. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79847. }
  79848. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79849. {
  79850. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79851. #ifdef DEBUG
  79852. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79853. s->compressed_len += (stored_len + 4) << 3;
  79854. #endif
  79855. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79856. }
  79857. void _tr_align (deflate_state *s)
  79858. {
  79859. send_bits(s, STATIC_TREES<<1, 3);
  79860. send_code(s, END_BLOCK, static_ltree);
  79861. #ifdef DEBUG
  79862. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79863. #endif
  79864. bi_flush(s);
  79865. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79866. send_bits(s, STATIC_TREES<<1, 3);
  79867. send_code(s, END_BLOCK, static_ltree);
  79868. #ifdef DEBUG
  79869. s->compressed_len += 10L;
  79870. #endif
  79871. bi_flush(s);
  79872. }
  79873. s->last_eob_len = 7;
  79874. }
  79875. void _tr_flush_block (deflate_state *s,
  79876. charf *buf, /* input block, or NULL if too old */
  79877. ulg stored_len, /* length of input block */
  79878. int eof) /* true if this is the last block for a file */
  79879. {
  79880. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79881. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79882. if (s->level > 0) {
  79883. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79884. set_data_type(s);
  79885. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79886. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79887. s->static_len));
  79888. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79889. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79890. s->static_len));
  79891. max_blindex = build_bl_tree(s);
  79892. opt_lenb = (s->opt_len+3+7)>>3;
  79893. static_lenb = (s->static_len+3+7)>>3;
  79894. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  79895. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  79896. s->last_lit));
  79897. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  79898. } else {
  79899. Assert(buf != (char*)0, "lost buf");
  79900. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  79901. }
  79902. #ifdef FORCE_STORED
  79903. if (buf != (char*)0) { /* force stored block */
  79904. #else
  79905. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  79906. #endif
  79907. _tr_stored_block(s, buf, stored_len, eof);
  79908. #ifdef FORCE_STATIC
  79909. } else if (static_lenb >= 0) { /* force static trees */
  79910. #else
  79911. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  79912. #endif
  79913. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  79914. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  79915. #ifdef DEBUG
  79916. s->compressed_len += 3 + s->static_len;
  79917. #endif
  79918. } else {
  79919. send_bits(s, (DYN_TREES<<1)+eof, 3);
  79920. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  79921. max_blindex+1);
  79922. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  79923. #ifdef DEBUG
  79924. s->compressed_len += 3 + s->opt_len;
  79925. #endif
  79926. }
  79927. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  79928. init_block(s);
  79929. if (eof) {
  79930. bi_windup(s);
  79931. #ifdef DEBUG
  79932. s->compressed_len += 7; /* align on byte boundary */
  79933. #endif
  79934. }
  79935. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  79936. s->compressed_len-7*eof));
  79937. }
  79938. int _tr_tally (deflate_state *s,
  79939. unsigned dist, /* distance of matched string */
  79940. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  79941. {
  79942. s->d_buf[s->last_lit] = (ush)dist;
  79943. s->l_buf[s->last_lit++] = (uch)lc;
  79944. if (dist == 0) {
  79945. s->dyn_ltree[lc].Freq++;
  79946. } else {
  79947. s->matches++;
  79948. dist--; /* dist = match distance - 1 */
  79949. Assert((ush)dist < (ush)MAX_DIST(s) &&
  79950. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  79951. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  79952. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  79953. s->dyn_dtree[d_code(dist)].Freq++;
  79954. }
  79955. #ifdef TRUNCATE_BLOCK
  79956. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  79957. ulg out_length = (ulg)s->last_lit*8L;
  79958. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  79959. int dcode;
  79960. for (dcode = 0; dcode < D_CODES; dcode++) {
  79961. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  79962. (5L+extra_dbits[dcode]);
  79963. }
  79964. out_length >>= 3;
  79965. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  79966. s->last_lit, in_length, out_length,
  79967. 100L - out_length*100L/in_length));
  79968. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  79969. }
  79970. #endif
  79971. return (s->last_lit == s->lit_bufsize-1);
  79972. }
  79973. local void compress_block (deflate_state *s,
  79974. ct_data *ltree, /* literal tree */
  79975. ct_data *dtree) /* distance tree */
  79976. {
  79977. unsigned dist; /* distance of matched string */
  79978. int lc; /* match length or unmatched char (if dist == 0) */
  79979. unsigned lx = 0; /* running index in l_buf */
  79980. unsigned code; /* the code to send */
  79981. int extra; /* number of extra bits to send */
  79982. if (s->last_lit != 0) do {
  79983. dist = s->d_buf[lx];
  79984. lc = s->l_buf[lx++];
  79985. if (dist == 0) {
  79986. send_code(s, lc, ltree); /* send a literal byte */
  79987. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  79988. } else {
  79989. code = _length_code[lc];
  79990. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  79991. extra = extra_lbits[code];
  79992. if (extra != 0) {
  79993. lc -= base_length[code];
  79994. send_bits(s, lc, extra); /* send the extra length bits */
  79995. }
  79996. dist--; /* dist is now the match distance - 1 */
  79997. code = d_code(dist);
  79998. Assert (code < D_CODES, "bad d_code");
  79999. send_code(s, code, dtree); /* send the distance code */
  80000. extra = extra_dbits[code];
  80001. if (extra != 0) {
  80002. dist -= base_dist[code];
  80003. send_bits(s, dist, extra); /* send the extra distance bits */
  80004. }
  80005. } /* literal or match pair ? */
  80006. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80007. "pendingBuf overflow");
  80008. } while (lx < s->last_lit);
  80009. send_code(s, END_BLOCK, ltree);
  80010. s->last_eob_len = ltree[END_BLOCK].Len;
  80011. }
  80012. local void set_data_type (deflate_state *s)
  80013. {
  80014. int n;
  80015. for (n = 0; n < 9; n++)
  80016. if (s->dyn_ltree[n].Freq != 0)
  80017. break;
  80018. if (n == 9)
  80019. for (n = 14; n < 32; n++)
  80020. if (s->dyn_ltree[n].Freq != 0)
  80021. break;
  80022. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80023. }
  80024. local unsigned bi_reverse (unsigned code, int len)
  80025. {
  80026. register unsigned res = 0;
  80027. do {
  80028. res |= code & 1;
  80029. code >>= 1, res <<= 1;
  80030. } while (--len > 0);
  80031. return res >> 1;
  80032. }
  80033. local void bi_flush (deflate_state *s)
  80034. {
  80035. if (s->bi_valid == 16) {
  80036. put_short(s, s->bi_buf);
  80037. s->bi_buf = 0;
  80038. s->bi_valid = 0;
  80039. } else if (s->bi_valid >= 8) {
  80040. put_byte(s, (Byte)s->bi_buf);
  80041. s->bi_buf >>= 8;
  80042. s->bi_valid -= 8;
  80043. }
  80044. }
  80045. local void bi_windup (deflate_state *s)
  80046. {
  80047. if (s->bi_valid > 8) {
  80048. put_short(s, s->bi_buf);
  80049. } else if (s->bi_valid > 0) {
  80050. put_byte(s, (Byte)s->bi_buf);
  80051. }
  80052. s->bi_buf = 0;
  80053. s->bi_valid = 0;
  80054. #ifdef DEBUG
  80055. s->bits_sent = (s->bits_sent+7) & ~7;
  80056. #endif
  80057. }
  80058. local void copy_block(deflate_state *s,
  80059. charf *buf, /* the input data */
  80060. unsigned len, /* its length */
  80061. int header) /* true if block header must be written */
  80062. {
  80063. bi_windup(s); /* align on byte boundary */
  80064. s->last_eob_len = 8; /* enough lookahead for inflate */
  80065. if (header) {
  80066. put_short(s, (ush)len);
  80067. put_short(s, (ush)~len);
  80068. #ifdef DEBUG
  80069. s->bits_sent += 2*16;
  80070. #endif
  80071. }
  80072. #ifdef DEBUG
  80073. s->bits_sent += (ulg)len<<3;
  80074. #endif
  80075. while (len--) {
  80076. put_byte(s, *buf++);
  80077. }
  80078. }
  80079. /*** End of inlined file: trees.c ***/
  80080. /*** Start of inlined file: zutil.c ***/
  80081. #ifndef NO_DUMMY_DECL
  80082. struct internal_state {int dummy;}; /* for buggy compilers */
  80083. #endif
  80084. const char * const z_errmsg[10] = {
  80085. "need dictionary", /* Z_NEED_DICT 2 */
  80086. "stream end", /* Z_STREAM_END 1 */
  80087. "", /* Z_OK 0 */
  80088. "file error", /* Z_ERRNO (-1) */
  80089. "stream error", /* Z_STREAM_ERROR (-2) */
  80090. "data error", /* Z_DATA_ERROR (-3) */
  80091. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80092. "buffer error", /* Z_BUF_ERROR (-5) */
  80093. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80094. ""};
  80095. #ifdef DEBUG
  80096. # ifndef verbose
  80097. # define verbose 0
  80098. # endif
  80099. int z_verbose = verbose;
  80100. void z_error (const char *m)
  80101. {
  80102. fprintf(stderr, "%s\n", m);
  80103. exit(1);
  80104. }
  80105. #endif
  80106. const char * ZEXPORT zError(int err)
  80107. {
  80108. return ERR_MSG(err);
  80109. }
  80110. #if defined(_WIN32_WCE)
  80111. int errno = 0;
  80112. #endif
  80113. #ifndef HAVE_MEMCPY
  80114. void zmemcpy(dest, source, len)
  80115. Bytef* dest;
  80116. const Bytef* source;
  80117. uInt len;
  80118. {
  80119. if (len == 0) return;
  80120. do {
  80121. *dest++ = *source++; /* ??? to be unrolled */
  80122. } while (--len != 0);
  80123. }
  80124. int zmemcmp(s1, s2, len)
  80125. const Bytef* s1;
  80126. const Bytef* s2;
  80127. uInt len;
  80128. {
  80129. uInt j;
  80130. for (j = 0; j < len; j++) {
  80131. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80132. }
  80133. return 0;
  80134. }
  80135. void zmemzero(dest, len)
  80136. Bytef* dest;
  80137. uInt len;
  80138. {
  80139. if (len == 0) return;
  80140. do {
  80141. *dest++ = 0; /* ??? to be unrolled */
  80142. } while (--len != 0);
  80143. }
  80144. #endif
  80145. #ifdef SYS16BIT
  80146. #ifdef __TURBOC__
  80147. # define MY_ZCALLOC
  80148. #define MAX_PTR 10
  80149. local int next_ptr = 0;
  80150. typedef struct ptr_table_s {
  80151. voidpf org_ptr;
  80152. voidpf new_ptr;
  80153. } ptr_table;
  80154. local ptr_table table[MAX_PTR];
  80155. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80156. {
  80157. voidpf buf = opaque; /* just to make some compilers happy */
  80158. ulg bsize = (ulg)items*size;
  80159. if (bsize < 65520L) {
  80160. buf = farmalloc(bsize);
  80161. if (*(ush*)&buf != 0) return buf;
  80162. } else {
  80163. buf = farmalloc(bsize + 16L);
  80164. }
  80165. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80166. table[next_ptr].org_ptr = buf;
  80167. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80168. *(ush*)&buf = 0;
  80169. table[next_ptr++].new_ptr = buf;
  80170. return buf;
  80171. }
  80172. void zcfree (voidpf opaque, voidpf ptr)
  80173. {
  80174. int n;
  80175. if (*(ush*)&ptr != 0) { /* object < 64K */
  80176. farfree(ptr);
  80177. return;
  80178. }
  80179. for (n = 0; n < next_ptr; n++) {
  80180. if (ptr != table[n].new_ptr) continue;
  80181. farfree(table[n].org_ptr);
  80182. while (++n < next_ptr) {
  80183. table[n-1] = table[n];
  80184. }
  80185. next_ptr--;
  80186. return;
  80187. }
  80188. ptr = opaque; /* just to make some compilers happy */
  80189. Assert(0, "zcfree: ptr not found");
  80190. }
  80191. #endif /* __TURBOC__ */
  80192. #ifdef M_I86
  80193. # define MY_ZCALLOC
  80194. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80195. # define _halloc halloc
  80196. # define _hfree hfree
  80197. #endif
  80198. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80199. {
  80200. if (opaque) opaque = 0; /* to make compiler happy */
  80201. return _halloc((long)items, size);
  80202. }
  80203. void zcfree (voidpf opaque, voidpf ptr)
  80204. {
  80205. if (opaque) opaque = 0; /* to make compiler happy */
  80206. _hfree(ptr);
  80207. }
  80208. #endif /* M_I86 */
  80209. #endif /* SYS16BIT */
  80210. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80211. #ifndef STDC
  80212. extern voidp malloc OF((uInt size));
  80213. extern voidp calloc OF((uInt items, uInt size));
  80214. extern void free OF((voidpf ptr));
  80215. #endif
  80216. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80217. {
  80218. if (opaque) items += size - size; /* make compiler happy */
  80219. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80220. (voidpf)calloc(items, size);
  80221. }
  80222. void zcfree (voidpf opaque, voidpf ptr)
  80223. {
  80224. free(ptr);
  80225. if (opaque) return; /* make compiler happy */
  80226. }
  80227. #endif /* MY_ZCALLOC */
  80228. /*** End of inlined file: zutil.c ***/
  80229. #undef Byte
  80230. }
  80231. #else
  80232. #include <zlib.h>
  80233. #endif
  80234. }
  80235. #if JUCE_MSVC
  80236. #pragma warning (pop)
  80237. #endif
  80238. BEGIN_JUCE_NAMESPACE
  80239. // internal helper object that holds the zlib structures so they don't have to be
  80240. // included publicly.
  80241. class GZIPDecompressHelper
  80242. {
  80243. public:
  80244. GZIPDecompressHelper (const bool noWrap)
  80245. : finished (true),
  80246. needsDictionary (false),
  80247. error (true),
  80248. streamIsValid (false),
  80249. data (0),
  80250. dataSize (0)
  80251. {
  80252. using namespace zlibNamespace;
  80253. zerostruct (stream);
  80254. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80255. finished = error = ! streamIsValid;
  80256. }
  80257. ~GZIPDecompressHelper()
  80258. {
  80259. using namespace zlibNamespace;
  80260. if (streamIsValid)
  80261. inflateEnd (&stream);
  80262. }
  80263. bool needsInput() const throw() { return dataSize <= 0; }
  80264. void setInput (uint8* const data_, const int size) throw()
  80265. {
  80266. data = data_;
  80267. dataSize = size;
  80268. }
  80269. int doNextBlock (uint8* const dest, const int destSize)
  80270. {
  80271. using namespace zlibNamespace;
  80272. if (streamIsValid && data != 0 && ! finished)
  80273. {
  80274. stream.next_in = data;
  80275. stream.next_out = dest;
  80276. stream.avail_in = dataSize;
  80277. stream.avail_out = destSize;
  80278. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80279. {
  80280. case Z_STREAM_END:
  80281. finished = true;
  80282. // deliberate fall-through
  80283. case Z_OK:
  80284. data += dataSize - stream.avail_in;
  80285. dataSize = stream.avail_in;
  80286. return destSize - stream.avail_out;
  80287. case Z_NEED_DICT:
  80288. needsDictionary = true;
  80289. data += dataSize - stream.avail_in;
  80290. dataSize = stream.avail_in;
  80291. break;
  80292. case Z_DATA_ERROR:
  80293. case Z_MEM_ERROR:
  80294. error = true;
  80295. default:
  80296. break;
  80297. }
  80298. }
  80299. return 0;
  80300. }
  80301. bool finished, needsDictionary, error, streamIsValid;
  80302. private:
  80303. zlibNamespace::z_stream stream;
  80304. uint8* data;
  80305. int dataSize;
  80306. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80307. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80308. };
  80309. const int gzipDecompBufferSize = 32768;
  80310. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80311. const bool deleteSourceWhenDestroyed,
  80312. const bool noWrap_,
  80313. const int64 uncompressedStreamLength_)
  80314. : sourceStream (sourceStream_),
  80315. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80316. uncompressedStreamLength (uncompressedStreamLength_),
  80317. noWrap (noWrap_),
  80318. isEof (false),
  80319. activeBufferSize (0),
  80320. originalSourcePos (sourceStream_->getPosition()),
  80321. currentPos (0),
  80322. buffer (gzipDecompBufferSize),
  80323. helper (new GZIPDecompressHelper (noWrap_))
  80324. {
  80325. }
  80326. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80327. {
  80328. }
  80329. int64 GZIPDecompressorInputStream::getTotalLength()
  80330. {
  80331. return uncompressedStreamLength;
  80332. }
  80333. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80334. {
  80335. if ((howMany > 0) && ! isEof)
  80336. {
  80337. jassert (destBuffer != 0);
  80338. if (destBuffer != 0)
  80339. {
  80340. int numRead = 0;
  80341. uint8* d = (uint8*) destBuffer;
  80342. while (! helper->error)
  80343. {
  80344. const int n = helper->doNextBlock (d, howMany);
  80345. currentPos += n;
  80346. if (n == 0)
  80347. {
  80348. if (helper->finished || helper->needsDictionary)
  80349. {
  80350. isEof = true;
  80351. return numRead;
  80352. }
  80353. if (helper->needsInput())
  80354. {
  80355. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80356. if (activeBufferSize > 0)
  80357. {
  80358. helper->setInput ((uint8*) buffer, activeBufferSize);
  80359. }
  80360. else
  80361. {
  80362. isEof = true;
  80363. return numRead;
  80364. }
  80365. }
  80366. }
  80367. else
  80368. {
  80369. numRead += n;
  80370. howMany -= n;
  80371. d += n;
  80372. if (howMany <= 0)
  80373. return numRead;
  80374. }
  80375. }
  80376. }
  80377. }
  80378. return 0;
  80379. }
  80380. bool GZIPDecompressorInputStream::isExhausted()
  80381. {
  80382. return helper->error || isEof;
  80383. }
  80384. int64 GZIPDecompressorInputStream::getPosition()
  80385. {
  80386. return currentPos;
  80387. }
  80388. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80389. {
  80390. if (newPos < currentPos)
  80391. {
  80392. // to go backwards, reset the stream and start again..
  80393. isEof = false;
  80394. activeBufferSize = 0;
  80395. currentPos = 0;
  80396. helper = new GZIPDecompressHelper (noWrap);
  80397. sourceStream->setPosition (originalSourcePos);
  80398. }
  80399. skipNextBytes (newPos - currentPos);
  80400. return true;
  80401. }
  80402. END_JUCE_NAMESPACE
  80403. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80404. #endif
  80405. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80406. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80407. #if JUCE_USE_FLAC
  80408. #if JUCE_WINDOWS
  80409. #include <windows.h>
  80410. #endif
  80411. #ifdef _MSC_VER
  80412. #pragma warning (disable : 4505)
  80413. #pragma warning (push)
  80414. #endif
  80415. namespace FlacNamespace
  80416. {
  80417. #if JUCE_INCLUDE_FLAC_CODE
  80418. #define FLAC__NO_DLL 1
  80419. #if ! defined (SIZE_MAX)
  80420. #define SIZE_MAX 0xffffffff
  80421. #endif
  80422. #define __STDC_LIMIT_MACROS 1
  80423. /*** Start of inlined file: all.h ***/
  80424. #ifndef FLAC__ALL_H
  80425. #define FLAC__ALL_H
  80426. /*** Start of inlined file: export.h ***/
  80427. #ifndef FLAC__EXPORT_H
  80428. #define FLAC__EXPORT_H
  80429. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80430. #define FLAC_API
  80431. #else
  80432. #ifdef FLAC_API_EXPORTS
  80433. #define FLAC_API _declspec(dllexport)
  80434. #else
  80435. #define FLAC_API _declspec(dllimport)
  80436. #endif
  80437. #endif
  80438. #define FLAC_API_VERSION_CURRENT 10
  80439. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80440. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80441. #ifdef __cplusplus
  80442. extern "C" {
  80443. #endif
  80444. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80445. #ifdef __cplusplus
  80446. }
  80447. #endif
  80448. #endif
  80449. /*** End of inlined file: export.h ***/
  80450. /*** Start of inlined file: assert.h ***/
  80451. #ifndef FLAC__ASSERT_H
  80452. #define FLAC__ASSERT_H
  80453. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80454. #ifdef DEBUG
  80455. #include <assert.h>
  80456. #define FLAC__ASSERT(x) assert(x)
  80457. #define FLAC__ASSERT_DECLARATION(x) x
  80458. #else
  80459. #define FLAC__ASSERT(x)
  80460. #define FLAC__ASSERT_DECLARATION(x)
  80461. #endif
  80462. #endif
  80463. /*** End of inlined file: assert.h ***/
  80464. /*** Start of inlined file: callback.h ***/
  80465. #ifndef FLAC__CALLBACK_H
  80466. #define FLAC__CALLBACK_H
  80467. /*** Start of inlined file: ordinals.h ***/
  80468. #ifndef FLAC__ORDINALS_H
  80469. #define FLAC__ORDINALS_H
  80470. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80471. #include <inttypes.h>
  80472. #endif
  80473. typedef signed char FLAC__int8;
  80474. typedef unsigned char FLAC__uint8;
  80475. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80476. typedef __int16 FLAC__int16;
  80477. typedef __int32 FLAC__int32;
  80478. typedef __int64 FLAC__int64;
  80479. typedef unsigned __int16 FLAC__uint16;
  80480. typedef unsigned __int32 FLAC__uint32;
  80481. typedef unsigned __int64 FLAC__uint64;
  80482. #elif defined(__EMX__)
  80483. typedef short FLAC__int16;
  80484. typedef long FLAC__int32;
  80485. typedef long long FLAC__int64;
  80486. typedef unsigned short FLAC__uint16;
  80487. typedef unsigned long FLAC__uint32;
  80488. typedef unsigned long long FLAC__uint64;
  80489. #else
  80490. typedef int16_t FLAC__int16;
  80491. typedef int32_t FLAC__int32;
  80492. typedef int64_t FLAC__int64;
  80493. typedef uint16_t FLAC__uint16;
  80494. typedef uint32_t FLAC__uint32;
  80495. typedef uint64_t FLAC__uint64;
  80496. #endif
  80497. typedef int FLAC__bool;
  80498. typedef FLAC__uint8 FLAC__byte;
  80499. #ifdef true
  80500. #undef true
  80501. #endif
  80502. #ifdef false
  80503. #undef false
  80504. #endif
  80505. #ifndef __cplusplus
  80506. #define true 1
  80507. #define false 0
  80508. #endif
  80509. #endif
  80510. /*** End of inlined file: ordinals.h ***/
  80511. #include <stdlib.h> /* for size_t */
  80512. #ifdef __cplusplus
  80513. extern "C" {
  80514. #endif
  80515. typedef void* FLAC__IOHandle;
  80516. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80517. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80518. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80519. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80520. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80521. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80522. typedef struct {
  80523. FLAC__IOCallback_Read read;
  80524. FLAC__IOCallback_Write write;
  80525. FLAC__IOCallback_Seek seek;
  80526. FLAC__IOCallback_Tell tell;
  80527. FLAC__IOCallback_Eof eof;
  80528. FLAC__IOCallback_Close close;
  80529. } FLAC__IOCallbacks;
  80530. #ifdef __cplusplus
  80531. }
  80532. #endif
  80533. #endif
  80534. /*** End of inlined file: callback.h ***/
  80535. /*** Start of inlined file: format.h ***/
  80536. #ifndef FLAC__FORMAT_H
  80537. #define FLAC__FORMAT_H
  80538. #ifdef __cplusplus
  80539. extern "C" {
  80540. #endif
  80541. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80542. #define FLAC__MIN_BLOCK_SIZE (16u)
  80543. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80544. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80545. #define FLAC__MAX_CHANNELS (8u)
  80546. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80547. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80548. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80549. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80550. #define FLAC__MAX_LPC_ORDER (32u)
  80551. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80552. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80553. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80554. #define FLAC__MAX_FIXED_ORDER (4u)
  80555. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80556. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80557. extern FLAC_API const char *FLAC__VERSION_STRING;
  80558. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80559. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80560. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80561. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80562. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80563. typedef enum {
  80564. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80565. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80566. } FLAC__EntropyCodingMethodType;
  80567. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80568. typedef struct {
  80569. unsigned *parameters;
  80570. unsigned *raw_bits;
  80571. unsigned capacity_by_order;
  80572. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80573. typedef struct {
  80574. unsigned order;
  80575. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80576. } FLAC__EntropyCodingMethod_PartitionedRice;
  80577. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80578. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80579. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80580. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80581. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80582. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80583. typedef struct {
  80584. FLAC__EntropyCodingMethodType type;
  80585. union {
  80586. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80587. } data;
  80588. } FLAC__EntropyCodingMethod;
  80589. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80590. typedef enum {
  80591. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80592. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80593. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80594. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80595. } FLAC__SubframeType;
  80596. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80597. typedef struct {
  80598. FLAC__int32 value; /**< The constant signal value. */
  80599. } FLAC__Subframe_Constant;
  80600. typedef struct {
  80601. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80602. } FLAC__Subframe_Verbatim;
  80603. typedef struct {
  80604. FLAC__EntropyCodingMethod entropy_coding_method;
  80605. unsigned order;
  80606. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80607. const FLAC__int32 *residual;
  80608. } FLAC__Subframe_Fixed;
  80609. typedef struct {
  80610. FLAC__EntropyCodingMethod entropy_coding_method;
  80611. unsigned order;
  80612. unsigned qlp_coeff_precision;
  80613. int quantization_level;
  80614. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80615. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80616. const FLAC__int32 *residual;
  80617. } FLAC__Subframe_LPC;
  80618. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80619. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80620. typedef struct {
  80621. FLAC__SubframeType type;
  80622. union {
  80623. FLAC__Subframe_Constant constant;
  80624. FLAC__Subframe_Fixed fixed;
  80625. FLAC__Subframe_LPC lpc;
  80626. FLAC__Subframe_Verbatim verbatim;
  80627. } data;
  80628. unsigned wasted_bits;
  80629. } FLAC__Subframe;
  80630. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80631. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80632. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80633. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80634. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80635. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80636. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80637. typedef enum {
  80638. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80639. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80640. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80641. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80642. } FLAC__ChannelAssignment;
  80643. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80644. typedef enum {
  80645. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80646. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80647. } FLAC__FrameNumberType;
  80648. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80649. typedef struct {
  80650. unsigned blocksize;
  80651. unsigned sample_rate;
  80652. unsigned channels;
  80653. FLAC__ChannelAssignment channel_assignment;
  80654. unsigned bits_per_sample;
  80655. FLAC__FrameNumberType number_type;
  80656. union {
  80657. FLAC__uint32 frame_number;
  80658. FLAC__uint64 sample_number;
  80659. } number;
  80660. FLAC__uint8 crc;
  80661. } FLAC__FrameHeader;
  80662. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80663. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80664. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80665. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80666. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80667. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80668. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80669. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80670. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80671. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80672. typedef struct {
  80673. FLAC__uint16 crc;
  80674. } FLAC__FrameFooter;
  80675. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80676. typedef struct {
  80677. FLAC__FrameHeader header;
  80678. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80679. FLAC__FrameFooter footer;
  80680. } FLAC__Frame;
  80681. typedef enum {
  80682. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80683. FLAC__METADATA_TYPE_PADDING = 1,
  80684. FLAC__METADATA_TYPE_APPLICATION = 2,
  80685. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80686. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80687. FLAC__METADATA_TYPE_CUESHEET = 5,
  80688. FLAC__METADATA_TYPE_PICTURE = 6,
  80689. FLAC__METADATA_TYPE_UNDEFINED = 7
  80690. } FLAC__MetadataType;
  80691. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80692. typedef struct {
  80693. unsigned min_blocksize, max_blocksize;
  80694. unsigned min_framesize, max_framesize;
  80695. unsigned sample_rate;
  80696. unsigned channels;
  80697. unsigned bits_per_sample;
  80698. FLAC__uint64 total_samples;
  80699. FLAC__byte md5sum[16];
  80700. } FLAC__StreamMetadata_StreamInfo;
  80701. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80702. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80703. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80704. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80705. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80706. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80707. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80708. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80709. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80710. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80711. typedef struct {
  80712. int dummy;
  80713. } FLAC__StreamMetadata_Padding;
  80714. typedef struct {
  80715. FLAC__byte id[4];
  80716. FLAC__byte *data;
  80717. } FLAC__StreamMetadata_Application;
  80718. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80719. typedef struct {
  80720. FLAC__uint64 sample_number;
  80721. FLAC__uint64 stream_offset;
  80722. unsigned frame_samples;
  80723. } FLAC__StreamMetadata_SeekPoint;
  80724. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80725. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80726. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80727. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80728. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80729. typedef struct {
  80730. unsigned num_points;
  80731. FLAC__StreamMetadata_SeekPoint *points;
  80732. } FLAC__StreamMetadata_SeekTable;
  80733. typedef struct {
  80734. FLAC__uint32 length;
  80735. FLAC__byte *entry;
  80736. } FLAC__StreamMetadata_VorbisComment_Entry;
  80737. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80738. typedef struct {
  80739. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80740. FLAC__uint32 num_comments;
  80741. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80742. } FLAC__StreamMetadata_VorbisComment;
  80743. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80744. typedef struct {
  80745. FLAC__uint64 offset;
  80746. FLAC__byte number;
  80747. } FLAC__StreamMetadata_CueSheet_Index;
  80748. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80749. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80750. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80751. typedef struct {
  80752. FLAC__uint64 offset;
  80753. FLAC__byte number;
  80754. char isrc[13];
  80755. unsigned type:1;
  80756. unsigned pre_emphasis:1;
  80757. FLAC__byte num_indices;
  80758. FLAC__StreamMetadata_CueSheet_Index *indices;
  80759. } FLAC__StreamMetadata_CueSheet_Track;
  80760. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80761. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80762. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80763. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80764. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80765. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80766. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80767. typedef struct {
  80768. char media_catalog_number[129];
  80769. FLAC__uint64 lead_in;
  80770. FLAC__bool is_cd;
  80771. unsigned num_tracks;
  80772. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80773. } FLAC__StreamMetadata_CueSheet;
  80774. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80775. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80776. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80777. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80778. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80779. typedef enum {
  80780. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80781. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80782. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80783. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80784. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80785. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80786. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80787. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80788. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80789. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80790. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80791. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80792. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80793. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80794. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80795. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80796. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80797. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80798. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80799. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80800. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80801. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80802. } FLAC__StreamMetadata_Picture_Type;
  80803. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80804. typedef struct {
  80805. FLAC__StreamMetadata_Picture_Type type;
  80806. char *mime_type;
  80807. FLAC__byte *description;
  80808. FLAC__uint32 width;
  80809. FLAC__uint32 height;
  80810. FLAC__uint32 depth;
  80811. FLAC__uint32 colors;
  80812. FLAC__uint32 data_length;
  80813. FLAC__byte *data;
  80814. } FLAC__StreamMetadata_Picture;
  80815. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80816. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80817. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80818. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80819. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80820. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80821. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80822. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80823. typedef struct {
  80824. FLAC__byte *data;
  80825. } FLAC__StreamMetadata_Unknown;
  80826. typedef struct {
  80827. FLAC__MetadataType type;
  80828. FLAC__bool is_last;
  80829. unsigned length;
  80830. union {
  80831. FLAC__StreamMetadata_StreamInfo stream_info;
  80832. FLAC__StreamMetadata_Padding padding;
  80833. FLAC__StreamMetadata_Application application;
  80834. FLAC__StreamMetadata_SeekTable seek_table;
  80835. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80836. FLAC__StreamMetadata_CueSheet cue_sheet;
  80837. FLAC__StreamMetadata_Picture picture;
  80838. FLAC__StreamMetadata_Unknown unknown;
  80839. } data;
  80840. } FLAC__StreamMetadata;
  80841. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80842. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80843. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80844. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80845. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80846. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80847. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80848. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80849. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80850. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80851. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80852. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80853. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80854. #ifdef __cplusplus
  80855. }
  80856. #endif
  80857. #endif
  80858. /*** End of inlined file: format.h ***/
  80859. /*** Start of inlined file: metadata.h ***/
  80860. #ifndef FLAC__METADATA_H
  80861. #define FLAC__METADATA_H
  80862. #include <sys/types.h> /* for off_t */
  80863. #ifdef __cplusplus
  80864. extern "C" {
  80865. #endif
  80866. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80867. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80868. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80869. 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);
  80870. struct FLAC__Metadata_SimpleIterator;
  80871. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80872. typedef enum {
  80873. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80874. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80875. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80876. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80877. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80878. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80879. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80880. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80881. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80882. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80883. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80884. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80885. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80886. } FLAC__Metadata_SimpleIteratorStatus;
  80887. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80888. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80889. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80890. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80891. 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);
  80892. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80893. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80894. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  80895. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  80896. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  80897. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  80898. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  80899. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  80900. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  80901. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80902. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80903. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  80904. struct FLAC__Metadata_Chain;
  80905. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  80906. struct FLAC__Metadata_Iterator;
  80907. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  80908. typedef enum {
  80909. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  80910. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  80911. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  80912. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  80913. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  80914. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  80915. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  80916. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  80917. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  80918. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  80919. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  80920. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  80921. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  80922. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  80923. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  80924. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  80925. } FLAC__Metadata_ChainStatus;
  80926. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  80927. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  80928. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  80929. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  80930. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  80931. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  80932. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80933. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80934. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  80935. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  80936. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80937. 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);
  80938. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  80939. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  80940. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  80941. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  80942. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  80943. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  80944. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  80945. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  80946. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  80947. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80948. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  80949. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80950. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80951. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  80952. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  80953. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  80954. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  80955. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  80956. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  80957. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80958. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80959. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  80960. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  80961. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  80962. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  80963. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  80964. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  80965. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  80966. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  80967. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80968. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  80969. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80970. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80971. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80972. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  80973. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  80974. 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);
  80975. 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);
  80976. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  80977. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  80978. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  80979. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  80980. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  80981. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  80982. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  80983. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  80984. 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);
  80985. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80986. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80987. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  80988. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80989. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80990. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  80991. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  80992. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  80993. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  80994. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  80995. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  80996. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  80997. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  80998. #ifdef __cplusplus
  80999. }
  81000. #endif
  81001. #endif
  81002. /*** End of inlined file: metadata.h ***/
  81003. /*** Start of inlined file: stream_decoder.h ***/
  81004. #ifndef FLAC__STREAM_DECODER_H
  81005. #define FLAC__STREAM_DECODER_H
  81006. #include <stdio.h> /* for FILE */
  81007. #ifdef __cplusplus
  81008. extern "C" {
  81009. #endif
  81010. typedef enum {
  81011. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81012. FLAC__STREAM_DECODER_READ_METADATA,
  81013. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81014. FLAC__STREAM_DECODER_READ_FRAME,
  81015. FLAC__STREAM_DECODER_END_OF_STREAM,
  81016. FLAC__STREAM_DECODER_OGG_ERROR,
  81017. FLAC__STREAM_DECODER_SEEK_ERROR,
  81018. FLAC__STREAM_DECODER_ABORTED,
  81019. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81020. FLAC__STREAM_DECODER_UNINITIALIZED
  81021. } FLAC__StreamDecoderState;
  81022. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81023. typedef enum {
  81024. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81025. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81026. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81027. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81028. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81029. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81030. } FLAC__StreamDecoderInitStatus;
  81031. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81032. typedef enum {
  81033. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81034. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81035. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81036. } FLAC__StreamDecoderReadStatus;
  81037. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81038. typedef enum {
  81039. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81040. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81041. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81042. } FLAC__StreamDecoderSeekStatus;
  81043. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81044. typedef enum {
  81045. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81046. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81047. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81048. } FLAC__StreamDecoderTellStatus;
  81049. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81050. typedef enum {
  81051. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81052. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81053. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81054. } FLAC__StreamDecoderLengthStatus;
  81055. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81056. typedef enum {
  81057. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81058. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81059. } FLAC__StreamDecoderWriteStatus;
  81060. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81061. typedef enum {
  81062. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81063. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81064. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81065. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81066. } FLAC__StreamDecoderErrorStatus;
  81067. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81068. struct FLAC__StreamDecoderProtected;
  81069. struct FLAC__StreamDecoderPrivate;
  81070. typedef struct {
  81071. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81072. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81073. } FLAC__StreamDecoder;
  81074. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81075. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81076. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81077. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81078. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81079. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81080. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81081. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81082. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81083. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81084. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81085. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81086. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81087. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81088. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81089. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81090. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81091. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81092. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81093. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81094. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81095. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81096. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81097. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81098. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81099. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81100. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81101. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81102. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81103. FLAC__StreamDecoder *decoder,
  81104. FLAC__StreamDecoderReadCallback read_callback,
  81105. FLAC__StreamDecoderSeekCallback seek_callback,
  81106. FLAC__StreamDecoderTellCallback tell_callback,
  81107. FLAC__StreamDecoderLengthCallback length_callback,
  81108. FLAC__StreamDecoderEofCallback eof_callback,
  81109. FLAC__StreamDecoderWriteCallback write_callback,
  81110. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81111. FLAC__StreamDecoderErrorCallback error_callback,
  81112. void *client_data
  81113. );
  81114. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81115. FLAC__StreamDecoder *decoder,
  81116. FLAC__StreamDecoderReadCallback read_callback,
  81117. FLAC__StreamDecoderSeekCallback seek_callback,
  81118. FLAC__StreamDecoderTellCallback tell_callback,
  81119. FLAC__StreamDecoderLengthCallback length_callback,
  81120. FLAC__StreamDecoderEofCallback eof_callback,
  81121. FLAC__StreamDecoderWriteCallback write_callback,
  81122. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81123. FLAC__StreamDecoderErrorCallback error_callback,
  81124. void *client_data
  81125. );
  81126. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81127. FLAC__StreamDecoder *decoder,
  81128. FILE *file,
  81129. FLAC__StreamDecoderWriteCallback write_callback,
  81130. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81131. FLAC__StreamDecoderErrorCallback error_callback,
  81132. void *client_data
  81133. );
  81134. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81135. FLAC__StreamDecoder *decoder,
  81136. FILE *file,
  81137. FLAC__StreamDecoderWriteCallback write_callback,
  81138. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81139. FLAC__StreamDecoderErrorCallback error_callback,
  81140. void *client_data
  81141. );
  81142. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81143. FLAC__StreamDecoder *decoder,
  81144. const char *filename,
  81145. FLAC__StreamDecoderWriteCallback write_callback,
  81146. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81147. FLAC__StreamDecoderErrorCallback error_callback,
  81148. void *client_data
  81149. );
  81150. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81151. FLAC__StreamDecoder *decoder,
  81152. const char *filename,
  81153. FLAC__StreamDecoderWriteCallback write_callback,
  81154. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81155. FLAC__StreamDecoderErrorCallback error_callback,
  81156. void *client_data
  81157. );
  81158. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81159. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81160. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81161. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81162. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81163. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81164. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81165. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81166. #ifdef __cplusplus
  81167. }
  81168. #endif
  81169. #endif
  81170. /*** End of inlined file: stream_decoder.h ***/
  81171. /*** Start of inlined file: stream_encoder.h ***/
  81172. #ifndef FLAC__STREAM_ENCODER_H
  81173. #define FLAC__STREAM_ENCODER_H
  81174. #include <stdio.h> /* for FILE */
  81175. #ifdef __cplusplus
  81176. extern "C" {
  81177. #endif
  81178. typedef enum {
  81179. FLAC__STREAM_ENCODER_OK = 0,
  81180. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81181. FLAC__STREAM_ENCODER_OGG_ERROR,
  81182. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81183. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81184. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81185. FLAC__STREAM_ENCODER_IO_ERROR,
  81186. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81187. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81188. } FLAC__StreamEncoderState;
  81189. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81190. typedef enum {
  81191. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81192. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81193. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81194. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81195. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81196. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81197. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81198. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81199. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81200. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81201. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81202. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81203. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81204. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81205. } FLAC__StreamEncoderInitStatus;
  81206. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81207. typedef enum {
  81208. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81209. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81210. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81211. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81212. } FLAC__StreamEncoderReadStatus;
  81213. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81214. typedef enum {
  81215. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81216. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81217. } FLAC__StreamEncoderWriteStatus;
  81218. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81219. typedef enum {
  81220. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81221. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81222. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81223. } FLAC__StreamEncoderSeekStatus;
  81224. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81225. typedef enum {
  81226. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81227. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81228. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81229. } FLAC__StreamEncoderTellStatus;
  81230. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81231. struct FLAC__StreamEncoderProtected;
  81232. struct FLAC__StreamEncoderPrivate;
  81233. typedef struct {
  81234. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81235. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81236. } FLAC__StreamEncoder;
  81237. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81238. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81239. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81240. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81241. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81242. 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);
  81243. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81244. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81245. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81246. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81247. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81248. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81249. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81250. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81251. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81252. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81253. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81254. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81255. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81256. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81257. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81258. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81259. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81260. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81261. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81262. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81263. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81264. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81265. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81266. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81267. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81268. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81269. 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);
  81270. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81271. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81272. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81273. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81274. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81275. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81276. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81277. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81278. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81279. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81280. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81281. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81282. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81283. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81284. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81285. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81286. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81287. 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);
  81288. 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);
  81289. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81290. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81291. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81292. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81293. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81294. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81295. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81296. #ifdef __cplusplus
  81297. }
  81298. #endif
  81299. #endif
  81300. /*** End of inlined file: stream_encoder.h ***/
  81301. #ifdef _MSC_VER
  81302. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81303. {
  81304. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81305. return (x>>16) | (x<<16);
  81306. }
  81307. #endif
  81308. #if defined(_MSC_VER) && defined(_X86_)
  81309. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81310. {
  81311. __asm {
  81312. mov edx, start
  81313. mov ecx, len
  81314. test ecx, ecx
  81315. loop1:
  81316. jz done1
  81317. mov eax, [edx]
  81318. bswap eax
  81319. mov [edx], eax
  81320. add edx, 4
  81321. dec ecx
  81322. jmp short loop1
  81323. done1:
  81324. }
  81325. }
  81326. #endif
  81327. #endif
  81328. /*** End of inlined file: all.h ***/
  81329. /*** Start of inlined file: bitmath.c ***/
  81330. /*** Start of inlined file: juce_FlacHeader.h ***/
  81331. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81332. // tasks..
  81333. #define VERSION "1.2.1"
  81334. #define FLAC__NO_DLL 1
  81335. #if JUCE_MSVC
  81336. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81337. #endif
  81338. #if JUCE_MAC
  81339. #define FLAC__SYS_DARWIN 1
  81340. #endif
  81341. /*** End of inlined file: juce_FlacHeader.h ***/
  81342. #if JUCE_USE_FLAC
  81343. #if HAVE_CONFIG_H
  81344. # include <config.h>
  81345. #endif
  81346. /*** Start of inlined file: bitmath.h ***/
  81347. #ifndef FLAC__PRIVATE__BITMATH_H
  81348. #define FLAC__PRIVATE__BITMATH_H
  81349. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81350. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81351. unsigned FLAC__bitmath_silog2(int v);
  81352. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81353. #endif
  81354. /*** End of inlined file: bitmath.h ***/
  81355. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81356. {
  81357. unsigned l = 0;
  81358. FLAC__ASSERT(v > 0);
  81359. while(v >>= 1)
  81360. l++;
  81361. return l;
  81362. }
  81363. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81364. {
  81365. unsigned l = 0;
  81366. FLAC__ASSERT(v > 0);
  81367. while(v >>= 1)
  81368. l++;
  81369. return l;
  81370. }
  81371. unsigned FLAC__bitmath_silog2(int v)
  81372. {
  81373. while(1) {
  81374. if(v == 0) {
  81375. return 0;
  81376. }
  81377. else if(v > 0) {
  81378. unsigned l = 0;
  81379. while(v) {
  81380. l++;
  81381. v >>= 1;
  81382. }
  81383. return l+1;
  81384. }
  81385. else if(v == -1) {
  81386. return 2;
  81387. }
  81388. else {
  81389. v++;
  81390. v = -v;
  81391. }
  81392. }
  81393. }
  81394. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81395. {
  81396. while(1) {
  81397. if(v == 0) {
  81398. return 0;
  81399. }
  81400. else if(v > 0) {
  81401. unsigned l = 0;
  81402. while(v) {
  81403. l++;
  81404. v >>= 1;
  81405. }
  81406. return l+1;
  81407. }
  81408. else if(v == -1) {
  81409. return 2;
  81410. }
  81411. else {
  81412. v++;
  81413. v = -v;
  81414. }
  81415. }
  81416. }
  81417. #endif
  81418. /*** End of inlined file: bitmath.c ***/
  81419. /*** Start of inlined file: bitreader.c ***/
  81420. /*** Start of inlined file: juce_FlacHeader.h ***/
  81421. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81422. // tasks..
  81423. #define VERSION "1.2.1"
  81424. #define FLAC__NO_DLL 1
  81425. #if JUCE_MSVC
  81426. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81427. #endif
  81428. #if JUCE_MAC
  81429. #define FLAC__SYS_DARWIN 1
  81430. #endif
  81431. /*** End of inlined file: juce_FlacHeader.h ***/
  81432. #if JUCE_USE_FLAC
  81433. #if HAVE_CONFIG_H
  81434. # include <config.h>
  81435. #endif
  81436. #include <stdlib.h> /* for malloc() */
  81437. #include <string.h> /* for memcpy(), memset() */
  81438. #ifdef _MSC_VER
  81439. #include <winsock.h> /* for ntohl() */
  81440. #elif defined FLAC__SYS_DARWIN
  81441. #include <machine/endian.h> /* for ntohl() */
  81442. #elif defined __MINGW32__
  81443. #include <winsock.h> /* for ntohl() */
  81444. #else
  81445. #include <netinet/in.h> /* for ntohl() */
  81446. #endif
  81447. /*** Start of inlined file: bitreader.h ***/
  81448. #ifndef FLAC__PRIVATE__BITREADER_H
  81449. #define FLAC__PRIVATE__BITREADER_H
  81450. #include <stdio.h> /* for FILE */
  81451. /*** Start of inlined file: cpu.h ***/
  81452. #ifndef FLAC__PRIVATE__CPU_H
  81453. #define FLAC__PRIVATE__CPU_H
  81454. #ifdef HAVE_CONFIG_H
  81455. #include <config.h>
  81456. #endif
  81457. typedef enum {
  81458. FLAC__CPUINFO_TYPE_IA32,
  81459. FLAC__CPUINFO_TYPE_PPC,
  81460. FLAC__CPUINFO_TYPE_UNKNOWN
  81461. } FLAC__CPUInfo_Type;
  81462. typedef struct {
  81463. FLAC__bool cpuid;
  81464. FLAC__bool bswap;
  81465. FLAC__bool cmov;
  81466. FLAC__bool mmx;
  81467. FLAC__bool fxsr;
  81468. FLAC__bool sse;
  81469. FLAC__bool sse2;
  81470. FLAC__bool sse3;
  81471. FLAC__bool ssse3;
  81472. FLAC__bool _3dnow;
  81473. FLAC__bool ext3dnow;
  81474. FLAC__bool extmmx;
  81475. } FLAC__CPUInfo_IA32;
  81476. typedef struct {
  81477. FLAC__bool altivec;
  81478. FLAC__bool ppc64;
  81479. } FLAC__CPUInfo_PPC;
  81480. typedef struct {
  81481. FLAC__bool use_asm;
  81482. FLAC__CPUInfo_Type type;
  81483. union {
  81484. FLAC__CPUInfo_IA32 ia32;
  81485. FLAC__CPUInfo_PPC ppc;
  81486. } data;
  81487. } FLAC__CPUInfo;
  81488. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81489. #ifndef FLAC__NO_ASM
  81490. #ifdef FLAC__CPU_IA32
  81491. #ifdef FLAC__HAS_NASM
  81492. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81493. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81494. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81495. #endif
  81496. #endif
  81497. #endif
  81498. #endif
  81499. /*** End of inlined file: cpu.h ***/
  81500. struct FLAC__BitReader;
  81501. typedef struct FLAC__BitReader FLAC__BitReader;
  81502. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81503. FLAC__BitReader *FLAC__bitreader_new(void);
  81504. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81505. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81506. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81507. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81508. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81509. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81510. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81511. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81512. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81513. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81514. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81515. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81516. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81517. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81518. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81519. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81520. 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! */
  81521. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81522. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81523. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81524. #ifndef FLAC__NO_ASM
  81525. # ifdef FLAC__CPU_IA32
  81526. # ifdef FLAC__HAS_NASM
  81527. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81528. # endif
  81529. # endif
  81530. #endif
  81531. #if 0 /* UNUSED */
  81532. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81533. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81534. #endif
  81535. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81536. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81537. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81538. #endif
  81539. /*** End of inlined file: bitreader.h ***/
  81540. /*** Start of inlined file: crc.h ***/
  81541. #ifndef FLAC__PRIVATE__CRC_H
  81542. #define FLAC__PRIVATE__CRC_H
  81543. extern FLAC__byte const FLAC__crc8_table[256];
  81544. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81545. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81546. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81547. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81548. extern unsigned FLAC__crc16_table[256];
  81549. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81550. #if 0
  81551. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81552. #endif
  81553. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81554. #endif
  81555. /*** End of inlined file: crc.h ***/
  81556. typedef FLAC__uint32 brword;
  81557. #define FLAC__BYTES_PER_WORD 4
  81558. #define FLAC__BITS_PER_WORD 32
  81559. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81560. #if WORDS_BIGENDIAN
  81561. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81562. #else
  81563. #if defined (_MSC_VER) && defined (_X86_)
  81564. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81565. #else
  81566. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81567. #endif
  81568. #endif
  81569. #define COUNT_ZERO_MSBS(word) ( \
  81570. (word) <= 0xffff ? \
  81571. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81572. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81573. )
  81574. #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])) )
  81575. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81576. static const unsigned char byte_to_unary_table[] = {
  81577. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81578. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81579. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81580. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81581. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81582. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81583. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81584. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81593. };
  81594. #ifdef min
  81595. #undef min
  81596. #endif
  81597. #define min(x,y) ((x)<(y)?(x):(y))
  81598. #ifdef max
  81599. #undef max
  81600. #endif
  81601. #define max(x,y) ((x)>(y)?(x):(y))
  81602. #ifdef _MSC_VER
  81603. #define FLAC__U64L(x) x
  81604. #else
  81605. #define FLAC__U64L(x) x##LLU
  81606. #endif
  81607. #ifndef FLaC__INLINE
  81608. #define FLaC__INLINE
  81609. #endif
  81610. struct FLAC__BitReader {
  81611. brword *buffer;
  81612. unsigned capacity; /* in words */
  81613. unsigned words; /* # of completed words in buffer */
  81614. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81615. unsigned consumed_words; /* #words ... */
  81616. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81617. unsigned read_crc16; /* the running frame CRC */
  81618. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81619. FLAC__BitReaderReadCallback read_callback;
  81620. void *client_data;
  81621. FLAC__CPUInfo cpu_info;
  81622. };
  81623. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81624. {
  81625. register unsigned crc = br->read_crc16;
  81626. #if FLAC__BYTES_PER_WORD == 4
  81627. switch(br->crc16_align) {
  81628. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81629. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81630. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81631. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81632. }
  81633. #elif FLAC__BYTES_PER_WORD == 8
  81634. switch(br->crc16_align) {
  81635. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81636. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81637. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81638. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81639. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81640. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81641. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81642. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81643. }
  81644. #else
  81645. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81646. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81647. br->read_crc16 = crc;
  81648. #endif
  81649. br->crc16_align = 0;
  81650. }
  81651. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81652. {
  81653. unsigned start, end;
  81654. size_t bytes;
  81655. FLAC__byte *target;
  81656. if(br->consumed_words > 0) {
  81657. start = br->consumed_words;
  81658. end = br->words + (br->bytes? 1:0);
  81659. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81660. br->words -= start;
  81661. br->consumed_words = 0;
  81662. }
  81663. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81664. if(bytes == 0)
  81665. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81666. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81667. #if WORDS_BIGENDIAN
  81668. #else
  81669. if(br->bytes)
  81670. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81671. #endif
  81672. if(!br->read_callback(target, &bytes, br->client_data))
  81673. return false;
  81674. #if WORDS_BIGENDIAN
  81675. #else
  81676. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81677. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81678. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81679. start = br->words;
  81680. local_swap32_block_(br->buffer + start, end - start);
  81681. }
  81682. else
  81683. # endif
  81684. for(start = br->words; start < end; start++)
  81685. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81686. #endif
  81687. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81688. br->words = end / FLAC__BYTES_PER_WORD;
  81689. br->bytes = end % FLAC__BYTES_PER_WORD;
  81690. return true;
  81691. }
  81692. FLAC__BitReader *FLAC__bitreader_new(void)
  81693. {
  81694. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81695. return br;
  81696. }
  81697. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81698. {
  81699. FLAC__ASSERT(0 != br);
  81700. FLAC__bitreader_free(br);
  81701. free(br);
  81702. }
  81703. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81704. {
  81705. FLAC__ASSERT(0 != br);
  81706. br->words = br->bytes = 0;
  81707. br->consumed_words = br->consumed_bits = 0;
  81708. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81709. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81710. if(br->buffer == 0)
  81711. return false;
  81712. br->read_callback = rcb;
  81713. br->client_data = cd;
  81714. br->cpu_info = cpu;
  81715. return true;
  81716. }
  81717. void FLAC__bitreader_free(FLAC__BitReader *br)
  81718. {
  81719. FLAC__ASSERT(0 != br);
  81720. if(0 != br->buffer)
  81721. free(br->buffer);
  81722. br->buffer = 0;
  81723. br->capacity = 0;
  81724. br->words = br->bytes = 0;
  81725. br->consumed_words = br->consumed_bits = 0;
  81726. br->read_callback = 0;
  81727. br->client_data = 0;
  81728. }
  81729. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81730. {
  81731. br->words = br->bytes = 0;
  81732. br->consumed_words = br->consumed_bits = 0;
  81733. return true;
  81734. }
  81735. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81736. {
  81737. unsigned i, j;
  81738. if(br == 0) {
  81739. fprintf(out, "bitreader is NULL\n");
  81740. }
  81741. else {
  81742. 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);
  81743. for(i = 0; i < br->words; i++) {
  81744. fprintf(out, "%08X: ", i);
  81745. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81746. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81747. fprintf(out, ".");
  81748. else
  81749. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81750. fprintf(out, "\n");
  81751. }
  81752. if(br->bytes > 0) {
  81753. fprintf(out, "%08X: ", i);
  81754. for(j = 0; j < br->bytes*8; j++)
  81755. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81756. fprintf(out, ".");
  81757. else
  81758. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81759. fprintf(out, "\n");
  81760. }
  81761. }
  81762. }
  81763. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81764. {
  81765. FLAC__ASSERT(0 != br);
  81766. FLAC__ASSERT(0 != br->buffer);
  81767. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81768. br->read_crc16 = (unsigned)seed;
  81769. br->crc16_align = br->consumed_bits;
  81770. }
  81771. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81772. {
  81773. FLAC__ASSERT(0 != br);
  81774. FLAC__ASSERT(0 != br->buffer);
  81775. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81776. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81777. if(br->consumed_bits) {
  81778. const brword tail = br->buffer[br->consumed_words];
  81779. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81780. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81781. }
  81782. return br->read_crc16;
  81783. }
  81784. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81785. {
  81786. return ((br->consumed_bits & 7) == 0);
  81787. }
  81788. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81789. {
  81790. return 8 - (br->consumed_bits & 7);
  81791. }
  81792. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81793. {
  81794. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81795. }
  81796. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81797. {
  81798. FLAC__ASSERT(0 != br);
  81799. FLAC__ASSERT(0 != br->buffer);
  81800. FLAC__ASSERT(bits <= 32);
  81801. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81802. FLAC__ASSERT(br->consumed_words <= br->words);
  81803. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81804. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81805. *val = 0;
  81806. return true;
  81807. }
  81808. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81809. if(!bitreader_read_from_client_(br))
  81810. return false;
  81811. }
  81812. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81813. if(br->consumed_bits) {
  81814. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81815. const brword word = br->buffer[br->consumed_words];
  81816. if(bits < n) {
  81817. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81818. br->consumed_bits += bits;
  81819. return true;
  81820. }
  81821. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81822. bits -= n;
  81823. crc16_update_word_(br, word);
  81824. br->consumed_words++;
  81825. br->consumed_bits = 0;
  81826. 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 */
  81827. *val <<= bits;
  81828. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81829. br->consumed_bits = bits;
  81830. }
  81831. return true;
  81832. }
  81833. else {
  81834. const brword word = br->buffer[br->consumed_words];
  81835. if(bits < FLAC__BITS_PER_WORD) {
  81836. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81837. br->consumed_bits = bits;
  81838. return true;
  81839. }
  81840. *val = word;
  81841. crc16_update_word_(br, word);
  81842. br->consumed_words++;
  81843. return true;
  81844. }
  81845. }
  81846. else {
  81847. if(br->consumed_bits) {
  81848. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81849. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81850. br->consumed_bits += bits;
  81851. return true;
  81852. }
  81853. else {
  81854. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81855. br->consumed_bits += bits;
  81856. return true;
  81857. }
  81858. }
  81859. }
  81860. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81861. {
  81862. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81863. return false;
  81864. *val <<= (32-bits);
  81865. *val >>= (32-bits);
  81866. return true;
  81867. }
  81868. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81869. {
  81870. FLAC__uint32 hi, lo;
  81871. if(bits > 32) {
  81872. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81873. return false;
  81874. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81875. return false;
  81876. *val = hi;
  81877. *val <<= 32;
  81878. *val |= lo;
  81879. }
  81880. else {
  81881. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81882. return false;
  81883. *val = lo;
  81884. }
  81885. return true;
  81886. }
  81887. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81888. {
  81889. FLAC__uint32 x8, x32 = 0;
  81890. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81891. return false;
  81892. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81893. return false;
  81894. x32 |= (x8 << 8);
  81895. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81896. return false;
  81897. x32 |= (x8 << 16);
  81898. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81899. return false;
  81900. x32 |= (x8 << 24);
  81901. *val = x32;
  81902. return true;
  81903. }
  81904. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  81905. {
  81906. FLAC__ASSERT(0 != br);
  81907. FLAC__ASSERT(0 != br->buffer);
  81908. if(bits > 0) {
  81909. const unsigned n = br->consumed_bits & 7;
  81910. unsigned m;
  81911. FLAC__uint32 x;
  81912. if(n != 0) {
  81913. m = min(8-n, bits);
  81914. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  81915. return false;
  81916. bits -= m;
  81917. }
  81918. m = bits / 8;
  81919. if(m > 0) {
  81920. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  81921. return false;
  81922. bits %= 8;
  81923. }
  81924. if(bits > 0) {
  81925. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  81926. return false;
  81927. }
  81928. }
  81929. return true;
  81930. }
  81931. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  81932. {
  81933. FLAC__uint32 x;
  81934. FLAC__ASSERT(0 != br);
  81935. FLAC__ASSERT(0 != br->buffer);
  81936. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81937. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81938. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81939. return false;
  81940. nvals--;
  81941. }
  81942. if(0 == nvals)
  81943. return true;
  81944. while(nvals >= FLAC__BYTES_PER_WORD) {
  81945. if(br->consumed_words < br->words) {
  81946. br->consumed_words++;
  81947. nvals -= FLAC__BYTES_PER_WORD;
  81948. }
  81949. else if(!bitreader_read_from_client_(br))
  81950. return false;
  81951. }
  81952. while(nvals) {
  81953. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81954. return false;
  81955. nvals--;
  81956. }
  81957. return true;
  81958. }
  81959. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  81960. {
  81961. FLAC__uint32 x;
  81962. FLAC__ASSERT(0 != br);
  81963. FLAC__ASSERT(0 != br->buffer);
  81964. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81965. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81966. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81967. return false;
  81968. *val++ = (FLAC__byte)x;
  81969. nvals--;
  81970. }
  81971. if(0 == nvals)
  81972. return true;
  81973. while(nvals >= FLAC__BYTES_PER_WORD) {
  81974. if(br->consumed_words < br->words) {
  81975. const brword word = br->buffer[br->consumed_words++];
  81976. #if FLAC__BYTES_PER_WORD == 4
  81977. val[0] = (FLAC__byte)(word >> 24);
  81978. val[1] = (FLAC__byte)(word >> 16);
  81979. val[2] = (FLAC__byte)(word >> 8);
  81980. val[3] = (FLAC__byte)word;
  81981. #elif FLAC__BYTES_PER_WORD == 8
  81982. val[0] = (FLAC__byte)(word >> 56);
  81983. val[1] = (FLAC__byte)(word >> 48);
  81984. val[2] = (FLAC__byte)(word >> 40);
  81985. val[3] = (FLAC__byte)(word >> 32);
  81986. val[4] = (FLAC__byte)(word >> 24);
  81987. val[5] = (FLAC__byte)(word >> 16);
  81988. val[6] = (FLAC__byte)(word >> 8);
  81989. val[7] = (FLAC__byte)word;
  81990. #else
  81991. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  81992. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  81993. #endif
  81994. val += FLAC__BYTES_PER_WORD;
  81995. nvals -= FLAC__BYTES_PER_WORD;
  81996. }
  81997. else if(!bitreader_read_from_client_(br))
  81998. return false;
  81999. }
  82000. while(nvals) {
  82001. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82002. return false;
  82003. *val++ = (FLAC__byte)x;
  82004. nvals--;
  82005. }
  82006. return true;
  82007. }
  82008. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82009. #if 0 /* slow but readable version */
  82010. {
  82011. unsigned bit;
  82012. FLAC__ASSERT(0 != br);
  82013. FLAC__ASSERT(0 != br->buffer);
  82014. *val = 0;
  82015. while(1) {
  82016. if(!FLAC__bitreader_read_bit(br, &bit))
  82017. return false;
  82018. if(bit)
  82019. break;
  82020. else
  82021. *val++;
  82022. }
  82023. return true;
  82024. }
  82025. #else
  82026. {
  82027. unsigned i;
  82028. FLAC__ASSERT(0 != br);
  82029. FLAC__ASSERT(0 != br->buffer);
  82030. *val = 0;
  82031. while(1) {
  82032. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82033. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82034. if(b) {
  82035. i = COUNT_ZERO_MSBS(b);
  82036. *val += i;
  82037. i++;
  82038. br->consumed_bits += i;
  82039. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82040. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82041. br->consumed_words++;
  82042. br->consumed_bits = 0;
  82043. }
  82044. return true;
  82045. }
  82046. else {
  82047. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82048. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82049. br->consumed_words++;
  82050. br->consumed_bits = 0;
  82051. }
  82052. }
  82053. if(br->bytes) {
  82054. const unsigned end = br->bytes * 8;
  82055. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82056. if(b) {
  82057. i = COUNT_ZERO_MSBS(b);
  82058. *val += i;
  82059. i++;
  82060. br->consumed_bits += i;
  82061. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82062. return true;
  82063. }
  82064. else {
  82065. *val += end - br->consumed_bits;
  82066. br->consumed_bits += end;
  82067. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82068. }
  82069. }
  82070. if(!bitreader_read_from_client_(br))
  82071. return false;
  82072. }
  82073. }
  82074. #endif
  82075. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82076. {
  82077. FLAC__uint32 lsbs = 0, msbs = 0;
  82078. unsigned uval;
  82079. FLAC__ASSERT(0 != br);
  82080. FLAC__ASSERT(0 != br->buffer);
  82081. FLAC__ASSERT(parameter <= 31);
  82082. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82083. return false;
  82084. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82085. return false;
  82086. uval = (msbs << parameter) | lsbs;
  82087. if(uval & 1)
  82088. *val = -((int)(uval >> 1)) - 1;
  82089. else
  82090. *val = (int)(uval >> 1);
  82091. return true;
  82092. }
  82093. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82094. #ifdef _MSC_VER
  82095. {
  82096. unsigned i;
  82097. unsigned uval = 0;
  82098. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82099. register unsigned cwords;
  82100. register unsigned cbits;
  82101. FLAC__ASSERT(0 != br);
  82102. FLAC__ASSERT(0 != br->buffer);
  82103. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82104. FLAC__ASSERT(parameter < 32);
  82105. if(nvals == 0)
  82106. return true;
  82107. cbits = br->consumed_bits;
  82108. cwords = br->consumed_words;
  82109. while(1) {
  82110. while(1) {
  82111. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82112. brword b = br->buffer[cwords] << cbits;
  82113. if(b) {
  82114. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82115. __asm {
  82116. bsr eax, b
  82117. not eax
  82118. and eax, 31
  82119. mov i, eax
  82120. }
  82121. #else
  82122. i = COUNT_ZERO_MSBS(b);
  82123. #endif
  82124. uval += i;
  82125. bits = parameter;
  82126. i++;
  82127. cbits += i;
  82128. if(cbits == FLAC__BITS_PER_WORD) {
  82129. crc16_update_word_(br, br->buffer[cwords]);
  82130. cwords++;
  82131. cbits = 0;
  82132. }
  82133. goto break1;
  82134. }
  82135. else {
  82136. uval += FLAC__BITS_PER_WORD - cbits;
  82137. crc16_update_word_(br, br->buffer[cwords]);
  82138. cwords++;
  82139. cbits = 0;
  82140. }
  82141. }
  82142. if(br->bytes) {
  82143. const unsigned end = br->bytes * 8;
  82144. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82145. if(b) {
  82146. i = COUNT_ZERO_MSBS(b);
  82147. uval += i;
  82148. bits = parameter;
  82149. i++;
  82150. cbits += i;
  82151. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82152. goto break1;
  82153. }
  82154. else {
  82155. uval += end - cbits;
  82156. cbits += end;
  82157. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82158. }
  82159. }
  82160. br->consumed_bits = cbits;
  82161. br->consumed_words = cwords;
  82162. if(!bitreader_read_from_client_(br))
  82163. return false;
  82164. cwords = br->consumed_words;
  82165. }
  82166. break1:
  82167. FLAC__ASSERT(cwords <= br->words);
  82168. if(bits) {
  82169. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82170. br->consumed_bits = cbits;
  82171. br->consumed_words = cwords;
  82172. if(!bitreader_read_from_client_(br))
  82173. return false;
  82174. cwords = br->consumed_words;
  82175. }
  82176. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82177. if(cbits) {
  82178. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82179. const brword word = br->buffer[cwords];
  82180. if(bits < n) {
  82181. uval <<= bits;
  82182. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82183. cbits += bits;
  82184. goto break2;
  82185. }
  82186. uval <<= n;
  82187. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82188. bits -= n;
  82189. crc16_update_word_(br, word);
  82190. cwords++;
  82191. cbits = 0;
  82192. 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 */
  82193. uval <<= bits;
  82194. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82195. cbits = bits;
  82196. }
  82197. goto break2;
  82198. }
  82199. else {
  82200. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82201. uval <<= bits;
  82202. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82203. cbits = bits;
  82204. goto break2;
  82205. }
  82206. }
  82207. else {
  82208. uval <<= bits;
  82209. if(cbits) {
  82210. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82211. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82212. cbits += bits;
  82213. goto break2;
  82214. }
  82215. else {
  82216. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82217. cbits += bits;
  82218. goto break2;
  82219. }
  82220. }
  82221. }
  82222. break2:
  82223. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82224. --nvals;
  82225. if(nvals == 0) {
  82226. br->consumed_bits = cbits;
  82227. br->consumed_words = cwords;
  82228. return true;
  82229. }
  82230. uval = 0;
  82231. ++vals;
  82232. }
  82233. }
  82234. #else
  82235. {
  82236. unsigned i;
  82237. unsigned uval = 0;
  82238. register unsigned cwords;
  82239. register unsigned cbits;
  82240. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82241. FLAC__ASSERT(0 != br);
  82242. FLAC__ASSERT(0 != br->buffer);
  82243. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82244. FLAC__ASSERT(parameter < 32);
  82245. if(nvals == 0)
  82246. return true;
  82247. cbits = br->consumed_bits;
  82248. cwords = br->consumed_words;
  82249. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82250. while(1) {
  82251. while(1) {
  82252. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82253. brword b = br->buffer[cwords] << cbits;
  82254. if(b) {
  82255. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82256. asm volatile (
  82257. "bsrl %1, %0;"
  82258. "notl %0;"
  82259. "andl $31, %0;"
  82260. : "=r"(i)
  82261. : "r"(b)
  82262. );
  82263. #else
  82264. i = COUNT_ZERO_MSBS(b);
  82265. #endif
  82266. uval += i;
  82267. cbits += i;
  82268. cbits++; /* skip over stop bit */
  82269. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82270. crc16_update_word_(br, br->buffer[cwords]);
  82271. cwords++;
  82272. cbits = 0;
  82273. }
  82274. goto break1;
  82275. }
  82276. else {
  82277. uval += FLAC__BITS_PER_WORD - cbits;
  82278. crc16_update_word_(br, br->buffer[cwords]);
  82279. cwords++;
  82280. cbits = 0;
  82281. }
  82282. }
  82283. if(br->bytes) {
  82284. const unsigned end = br->bytes * 8;
  82285. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82286. if(b) {
  82287. i = COUNT_ZERO_MSBS(b);
  82288. uval += i;
  82289. cbits += i;
  82290. cbits++; /* skip over stop bit */
  82291. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82292. goto break1;
  82293. }
  82294. else {
  82295. uval += end - cbits;
  82296. cbits += end;
  82297. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82298. }
  82299. }
  82300. br->consumed_bits = cbits;
  82301. br->consumed_words = cwords;
  82302. if(!bitreader_read_from_client_(br))
  82303. return false;
  82304. cwords = br->consumed_words;
  82305. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82306. }
  82307. break1:
  82308. ucbits -= uval;
  82309. ucbits--; /* account for stop bit */
  82310. FLAC__ASSERT(cwords <= br->words);
  82311. if(parameter) {
  82312. while(ucbits < parameter) {
  82313. br->consumed_bits = cbits;
  82314. br->consumed_words = cwords;
  82315. if(!bitreader_read_from_client_(br))
  82316. return false;
  82317. cwords = br->consumed_words;
  82318. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82319. }
  82320. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82321. if(cbits) {
  82322. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82323. const brword word = br->buffer[cwords];
  82324. if(parameter < n) {
  82325. uval <<= parameter;
  82326. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82327. cbits += parameter;
  82328. }
  82329. else {
  82330. uval <<= n;
  82331. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82332. crc16_update_word_(br, word);
  82333. cwords++;
  82334. cbits = parameter - n;
  82335. 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 */
  82336. uval <<= cbits;
  82337. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82338. }
  82339. }
  82340. }
  82341. else {
  82342. cbits = parameter;
  82343. uval <<= parameter;
  82344. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82345. }
  82346. }
  82347. else {
  82348. uval <<= parameter;
  82349. if(cbits) {
  82350. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82351. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82352. cbits += parameter;
  82353. }
  82354. else {
  82355. cbits = parameter;
  82356. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82357. }
  82358. }
  82359. }
  82360. ucbits -= parameter;
  82361. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82362. --nvals;
  82363. if(nvals == 0) {
  82364. br->consumed_bits = cbits;
  82365. br->consumed_words = cwords;
  82366. return true;
  82367. }
  82368. uval = 0;
  82369. ++vals;
  82370. }
  82371. }
  82372. #endif
  82373. #if 0 /* UNUSED */
  82374. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82375. {
  82376. FLAC__uint32 lsbs = 0, msbs = 0;
  82377. unsigned bit, uval, k;
  82378. FLAC__ASSERT(0 != br);
  82379. FLAC__ASSERT(0 != br->buffer);
  82380. k = FLAC__bitmath_ilog2(parameter);
  82381. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82382. return false;
  82383. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82384. return false;
  82385. if(parameter == 1u<<k) {
  82386. uval = (msbs << k) | lsbs;
  82387. }
  82388. else {
  82389. unsigned d = (1 << (k+1)) - parameter;
  82390. if(lsbs >= d) {
  82391. if(!FLAC__bitreader_read_bit(br, &bit))
  82392. return false;
  82393. lsbs <<= 1;
  82394. lsbs |= bit;
  82395. lsbs -= d;
  82396. }
  82397. uval = msbs * parameter + lsbs;
  82398. }
  82399. if(uval & 1)
  82400. *val = -((int)(uval >> 1)) - 1;
  82401. else
  82402. *val = (int)(uval >> 1);
  82403. return true;
  82404. }
  82405. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82406. {
  82407. FLAC__uint32 lsbs, msbs = 0;
  82408. unsigned bit, k;
  82409. FLAC__ASSERT(0 != br);
  82410. FLAC__ASSERT(0 != br->buffer);
  82411. k = FLAC__bitmath_ilog2(parameter);
  82412. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82413. return false;
  82414. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82415. return false;
  82416. if(parameter == 1u<<k) {
  82417. *val = (msbs << k) | lsbs;
  82418. }
  82419. else {
  82420. unsigned d = (1 << (k+1)) - parameter;
  82421. if(lsbs >= d) {
  82422. if(!FLAC__bitreader_read_bit(br, &bit))
  82423. return false;
  82424. lsbs <<= 1;
  82425. lsbs |= bit;
  82426. lsbs -= d;
  82427. }
  82428. *val = msbs * parameter + lsbs;
  82429. }
  82430. return true;
  82431. }
  82432. #endif /* UNUSED */
  82433. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82434. {
  82435. FLAC__uint32 v = 0;
  82436. FLAC__uint32 x;
  82437. unsigned i;
  82438. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82439. return false;
  82440. if(raw)
  82441. raw[(*rawlen)++] = (FLAC__byte)x;
  82442. if(!(x & 0x80)) { /* 0xxxxxxx */
  82443. v = x;
  82444. i = 0;
  82445. }
  82446. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82447. v = x & 0x1F;
  82448. i = 1;
  82449. }
  82450. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82451. v = x & 0x0F;
  82452. i = 2;
  82453. }
  82454. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82455. v = x & 0x07;
  82456. i = 3;
  82457. }
  82458. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82459. v = x & 0x03;
  82460. i = 4;
  82461. }
  82462. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82463. v = x & 0x01;
  82464. i = 5;
  82465. }
  82466. else {
  82467. *val = 0xffffffff;
  82468. return true;
  82469. }
  82470. for( ; i; i--) {
  82471. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82472. return false;
  82473. if(raw)
  82474. raw[(*rawlen)++] = (FLAC__byte)x;
  82475. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82476. *val = 0xffffffff;
  82477. return true;
  82478. }
  82479. v <<= 6;
  82480. v |= (x & 0x3F);
  82481. }
  82482. *val = v;
  82483. return true;
  82484. }
  82485. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82486. {
  82487. FLAC__uint64 v = 0;
  82488. FLAC__uint32 x;
  82489. unsigned i;
  82490. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82491. return false;
  82492. if(raw)
  82493. raw[(*rawlen)++] = (FLAC__byte)x;
  82494. if(!(x & 0x80)) { /* 0xxxxxxx */
  82495. v = x;
  82496. i = 0;
  82497. }
  82498. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82499. v = x & 0x1F;
  82500. i = 1;
  82501. }
  82502. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82503. v = x & 0x0F;
  82504. i = 2;
  82505. }
  82506. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82507. v = x & 0x07;
  82508. i = 3;
  82509. }
  82510. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82511. v = x & 0x03;
  82512. i = 4;
  82513. }
  82514. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82515. v = x & 0x01;
  82516. i = 5;
  82517. }
  82518. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82519. v = 0;
  82520. i = 6;
  82521. }
  82522. else {
  82523. *val = FLAC__U64L(0xffffffffffffffff);
  82524. return true;
  82525. }
  82526. for( ; i; i--) {
  82527. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82528. return false;
  82529. if(raw)
  82530. raw[(*rawlen)++] = (FLAC__byte)x;
  82531. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82532. *val = FLAC__U64L(0xffffffffffffffff);
  82533. return true;
  82534. }
  82535. v <<= 6;
  82536. v |= (x & 0x3F);
  82537. }
  82538. *val = v;
  82539. return true;
  82540. }
  82541. #endif
  82542. /*** End of inlined file: bitreader.c ***/
  82543. /*** Start of inlined file: bitwriter.c ***/
  82544. /*** Start of inlined file: juce_FlacHeader.h ***/
  82545. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82546. // tasks..
  82547. #define VERSION "1.2.1"
  82548. #define FLAC__NO_DLL 1
  82549. #if JUCE_MSVC
  82550. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82551. #endif
  82552. #if JUCE_MAC
  82553. #define FLAC__SYS_DARWIN 1
  82554. #endif
  82555. /*** End of inlined file: juce_FlacHeader.h ***/
  82556. #if JUCE_USE_FLAC
  82557. #if HAVE_CONFIG_H
  82558. # include <config.h>
  82559. #endif
  82560. #include <stdlib.h> /* for malloc() */
  82561. #include <string.h> /* for memcpy(), memset() */
  82562. #ifdef _MSC_VER
  82563. #include <winsock.h> /* for ntohl() */
  82564. #elif defined FLAC__SYS_DARWIN
  82565. #include <machine/endian.h> /* for ntohl() */
  82566. #elif defined __MINGW32__
  82567. #include <winsock.h> /* for ntohl() */
  82568. #else
  82569. #include <netinet/in.h> /* for ntohl() */
  82570. #endif
  82571. #if 0 /* UNUSED */
  82572. #endif
  82573. /*** Start of inlined file: bitwriter.h ***/
  82574. #ifndef FLAC__PRIVATE__BITWRITER_H
  82575. #define FLAC__PRIVATE__BITWRITER_H
  82576. #include <stdio.h> /* for FILE */
  82577. struct FLAC__BitWriter;
  82578. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82579. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82580. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82581. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82582. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82583. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82584. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82585. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82586. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82587. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82588. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82589. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82590. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82591. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82592. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82593. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82594. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82595. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82596. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82597. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82598. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82599. #if 0 /* UNUSED */
  82600. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82601. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82602. #endif
  82603. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82604. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82605. #if 0 /* UNUSED */
  82606. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82607. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82608. #endif
  82609. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82610. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82611. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82612. #endif
  82613. /*** End of inlined file: bitwriter.h ***/
  82614. /*** Start of inlined file: alloc.h ***/
  82615. #ifndef FLAC__SHARE__ALLOC_H
  82616. #define FLAC__SHARE__ALLOC_H
  82617. #if HAVE_CONFIG_H
  82618. # include <config.h>
  82619. #endif
  82620. #include <limits.h> /* for SIZE_MAX */
  82621. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82622. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82623. #endif
  82624. #include <stdlib.h> /* for size_t, malloc(), etc */
  82625. #ifndef SIZE_MAX
  82626. # ifndef SIZE_T_MAX
  82627. # ifdef _MSC_VER
  82628. # define SIZE_T_MAX UINT_MAX
  82629. # else
  82630. # error
  82631. # endif
  82632. # endif
  82633. # define SIZE_MAX SIZE_T_MAX
  82634. #endif
  82635. #ifndef FLaC__INLINE
  82636. #define FLaC__INLINE
  82637. #endif
  82638. static FLaC__INLINE void *safe_malloc_(size_t size)
  82639. {
  82640. if(!size)
  82641. size++;
  82642. return malloc(size);
  82643. }
  82644. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82645. {
  82646. if(!nmemb || !size)
  82647. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82648. return calloc(nmemb, size);
  82649. }
  82650. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82651. {
  82652. size2 += size1;
  82653. if(size2 < size1)
  82654. return 0;
  82655. return safe_malloc_(size2);
  82656. }
  82657. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82658. {
  82659. size2 += size1;
  82660. if(size2 < size1)
  82661. return 0;
  82662. size3 += size2;
  82663. if(size3 < size2)
  82664. return 0;
  82665. return safe_malloc_(size3);
  82666. }
  82667. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82668. {
  82669. size2 += size1;
  82670. if(size2 < size1)
  82671. return 0;
  82672. size3 += size2;
  82673. if(size3 < size2)
  82674. return 0;
  82675. size4 += size3;
  82676. if(size4 < size3)
  82677. return 0;
  82678. return safe_malloc_(size4);
  82679. }
  82680. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82681. #if 0
  82682. needs support for cases where sizeof(size_t) != 4
  82683. {
  82684. if(sizeof(size_t) == 4) {
  82685. if ((double)size1 * (double)size2 < 4294967296.0)
  82686. return malloc(size1*size2);
  82687. }
  82688. return 0;
  82689. }
  82690. #else
  82691. {
  82692. if(!size1 || !size2)
  82693. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82694. if(size1 > SIZE_MAX / size2)
  82695. return 0;
  82696. return malloc(size1*size2);
  82697. }
  82698. #endif
  82699. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82700. {
  82701. if(!size1 || !size2 || !size3)
  82702. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82703. if(size1 > SIZE_MAX / size2)
  82704. return 0;
  82705. size1 *= size2;
  82706. if(size1 > SIZE_MAX / size3)
  82707. return 0;
  82708. return malloc(size1*size3);
  82709. }
  82710. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82711. {
  82712. if(!size1 || !size2)
  82713. return safe_malloc_(size3);
  82714. if(size1 > SIZE_MAX / size2)
  82715. return 0;
  82716. return safe_malloc_add_2op_(size1*size2, size3);
  82717. }
  82718. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82719. {
  82720. if(!size1 || (!size2 && !size3))
  82721. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82722. size2 += size3;
  82723. if(size2 < size3)
  82724. return 0;
  82725. return safe_malloc_mul_2op_(size1, size2);
  82726. }
  82727. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82728. {
  82729. size2 += size1;
  82730. if(size2 < size1)
  82731. return 0;
  82732. return realloc(ptr, size2);
  82733. }
  82734. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82735. {
  82736. size2 += size1;
  82737. if(size2 < size1)
  82738. return 0;
  82739. size3 += size2;
  82740. if(size3 < size2)
  82741. return 0;
  82742. return realloc(ptr, size3);
  82743. }
  82744. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82745. {
  82746. size2 += size1;
  82747. if(size2 < size1)
  82748. return 0;
  82749. size3 += size2;
  82750. if(size3 < size2)
  82751. return 0;
  82752. size4 += size3;
  82753. if(size4 < size3)
  82754. return 0;
  82755. return realloc(ptr, size4);
  82756. }
  82757. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82758. {
  82759. if(!size1 || !size2)
  82760. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82761. if(size1 > SIZE_MAX / size2)
  82762. return 0;
  82763. return realloc(ptr, size1*size2);
  82764. }
  82765. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82766. {
  82767. if(!size1 || (!size2 && !size3))
  82768. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82769. size2 += size3;
  82770. if(size2 < size3)
  82771. return 0;
  82772. return safe_realloc_mul_2op_(ptr, size1, size2);
  82773. }
  82774. #endif
  82775. /*** End of inlined file: alloc.h ***/
  82776. typedef FLAC__uint32 bwword;
  82777. #define FLAC__BYTES_PER_WORD 4
  82778. #define FLAC__BITS_PER_WORD 32
  82779. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82780. #if WORDS_BIGENDIAN
  82781. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82782. #else
  82783. #ifdef _MSC_VER
  82784. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82785. #else
  82786. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82787. #endif
  82788. #endif
  82789. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82790. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82791. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82792. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82793. #ifdef min
  82794. #undef min
  82795. #endif
  82796. #define min(x,y) ((x)<(y)?(x):(y))
  82797. #ifdef _MSC_VER
  82798. #define FLAC__U64L(x) x
  82799. #else
  82800. #define FLAC__U64L(x) x##LLU
  82801. #endif
  82802. #ifndef FLaC__INLINE
  82803. #define FLaC__INLINE
  82804. #endif
  82805. struct FLAC__BitWriter {
  82806. bwword *buffer;
  82807. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82808. unsigned capacity; /* capacity of buffer in words */
  82809. unsigned words; /* # of complete words in buffer */
  82810. unsigned bits; /* # of used bits in accum */
  82811. };
  82812. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82813. {
  82814. unsigned new_capacity;
  82815. bwword *new_buffer;
  82816. FLAC__ASSERT(0 != bw);
  82817. FLAC__ASSERT(0 != bw->buffer);
  82818. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82819. if(bw->capacity >= new_capacity)
  82820. return true;
  82821. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82822. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82823. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82824. FLAC__ASSERT(new_capacity > bw->capacity);
  82825. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82826. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82827. if(new_buffer == 0)
  82828. return false;
  82829. bw->buffer = new_buffer;
  82830. bw->capacity = new_capacity;
  82831. return true;
  82832. }
  82833. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82834. {
  82835. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82836. return bw;
  82837. }
  82838. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82839. {
  82840. FLAC__ASSERT(0 != bw);
  82841. FLAC__bitwriter_free(bw);
  82842. free(bw);
  82843. }
  82844. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82845. {
  82846. FLAC__ASSERT(0 != bw);
  82847. bw->words = bw->bits = 0;
  82848. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82849. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82850. if(bw->buffer == 0)
  82851. return false;
  82852. return true;
  82853. }
  82854. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82855. {
  82856. FLAC__ASSERT(0 != bw);
  82857. if(0 != bw->buffer)
  82858. free(bw->buffer);
  82859. bw->buffer = 0;
  82860. bw->capacity = 0;
  82861. bw->words = bw->bits = 0;
  82862. }
  82863. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82864. {
  82865. bw->words = bw->bits = 0;
  82866. }
  82867. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82868. {
  82869. unsigned i, j;
  82870. if(bw == 0) {
  82871. fprintf(out, "bitwriter is NULL\n");
  82872. }
  82873. else {
  82874. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82875. for(i = 0; i < bw->words; i++) {
  82876. fprintf(out, "%08X: ", i);
  82877. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82878. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82879. fprintf(out, "\n");
  82880. }
  82881. if(bw->bits > 0) {
  82882. fprintf(out, "%08X: ", i);
  82883. for(j = 0; j < bw->bits; j++)
  82884. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82885. fprintf(out, "\n");
  82886. }
  82887. }
  82888. }
  82889. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82890. {
  82891. const FLAC__byte *buffer;
  82892. size_t bytes;
  82893. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82894. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82895. return false;
  82896. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  82897. FLAC__bitwriter_release_buffer(bw);
  82898. return true;
  82899. }
  82900. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *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__crc8(buffer, bytes);
  82908. FLAC__bitwriter_release_buffer(bw);
  82909. return true;
  82910. }
  82911. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  82912. {
  82913. return ((bw->bits & 7) == 0);
  82914. }
  82915. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  82916. {
  82917. return FLAC__TOTAL_BITS(bw);
  82918. }
  82919. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  82920. {
  82921. FLAC__ASSERT((bw->bits & 7) == 0);
  82922. if(bw->bits & 7)
  82923. return false;
  82924. if(bw->bits) {
  82925. FLAC__ASSERT(bw->words <= bw->capacity);
  82926. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  82927. return false;
  82928. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  82929. }
  82930. *buffer = (FLAC__byte*)bw->buffer;
  82931. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  82932. return true;
  82933. }
  82934. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  82935. {
  82936. (void)bw;
  82937. }
  82938. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  82939. {
  82940. unsigned n;
  82941. FLAC__ASSERT(0 != bw);
  82942. FLAC__ASSERT(0 != bw->buffer);
  82943. if(bits == 0)
  82944. return true;
  82945. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82946. return false;
  82947. if(bw->bits) {
  82948. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  82949. bw->accum <<= n;
  82950. bits -= n;
  82951. bw->bits += n;
  82952. if(bw->bits == FLAC__BITS_PER_WORD) {
  82953. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82954. bw->bits = 0;
  82955. }
  82956. else
  82957. return true;
  82958. }
  82959. while(bits >= FLAC__BITS_PER_WORD) {
  82960. bw->buffer[bw->words++] = 0;
  82961. bits -= FLAC__BITS_PER_WORD;
  82962. }
  82963. if(bits > 0) {
  82964. bw->accum = 0;
  82965. bw->bits = bits;
  82966. }
  82967. return true;
  82968. }
  82969. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  82970. {
  82971. register unsigned left;
  82972. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82973. FLAC__ASSERT(0 != bw);
  82974. FLAC__ASSERT(0 != bw->buffer);
  82975. FLAC__ASSERT(bits <= 32);
  82976. if(bits == 0)
  82977. return true;
  82978. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82979. return false;
  82980. left = FLAC__BITS_PER_WORD - bw->bits;
  82981. if(bits < left) {
  82982. bw->accum <<= bits;
  82983. bw->accum |= val;
  82984. bw->bits += bits;
  82985. }
  82986. 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 */
  82987. bw->accum <<= left;
  82988. bw->accum |= val >> (bw->bits = bits - left);
  82989. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82990. bw->accum = val;
  82991. }
  82992. else {
  82993. bw->accum = val;
  82994. bw->bits = 0;
  82995. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  82996. }
  82997. return true;
  82998. }
  82999. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83000. {
  83001. if(bits < 32)
  83002. val &= (~(0xffffffff << bits));
  83003. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83004. }
  83005. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83006. {
  83007. if(bits > 32) {
  83008. return
  83009. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83010. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83011. }
  83012. else
  83013. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83014. }
  83015. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83016. {
  83017. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83018. return false;
  83019. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83020. return false;
  83021. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83022. return false;
  83023. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83024. return false;
  83025. return true;
  83026. }
  83027. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83028. {
  83029. unsigned i;
  83030. for(i = 0; i < nvals; i++) {
  83031. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83032. return false;
  83033. }
  83034. return true;
  83035. }
  83036. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83037. {
  83038. if(val < 32)
  83039. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83040. else
  83041. return
  83042. FLAC__bitwriter_write_zeroes(bw, val) &&
  83043. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83044. }
  83045. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83046. {
  83047. FLAC__uint32 uval;
  83048. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83049. uval = (val<<1) ^ (val>>31);
  83050. return 1 + parameter + (uval >> parameter);
  83051. }
  83052. #if 0 /* UNUSED */
  83053. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83054. {
  83055. unsigned bits, msbs, uval;
  83056. unsigned k;
  83057. FLAC__ASSERT(parameter > 0);
  83058. if(val < 0)
  83059. uval = (unsigned)(((-(++val)) << 1) + 1);
  83060. else
  83061. uval = (unsigned)(val << 1);
  83062. k = FLAC__bitmath_ilog2(parameter);
  83063. if(parameter == 1u<<k) {
  83064. FLAC__ASSERT(k <= 30);
  83065. msbs = uval >> k;
  83066. bits = 1 + k + msbs;
  83067. }
  83068. else {
  83069. unsigned q, r, d;
  83070. d = (1 << (k+1)) - parameter;
  83071. q = uval / parameter;
  83072. r = uval - (q * parameter);
  83073. bits = 1 + q + k;
  83074. if(r >= d)
  83075. bits++;
  83076. }
  83077. return bits;
  83078. }
  83079. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83080. {
  83081. unsigned bits, msbs;
  83082. unsigned k;
  83083. FLAC__ASSERT(parameter > 0);
  83084. k = FLAC__bitmath_ilog2(parameter);
  83085. if(parameter == 1u<<k) {
  83086. FLAC__ASSERT(k <= 30);
  83087. msbs = uval >> k;
  83088. bits = 1 + k + msbs;
  83089. }
  83090. else {
  83091. unsigned q, r, d;
  83092. d = (1 << (k+1)) - parameter;
  83093. q = uval / parameter;
  83094. r = uval - (q * parameter);
  83095. bits = 1 + q + k;
  83096. if(r >= d)
  83097. bits++;
  83098. }
  83099. return bits;
  83100. }
  83101. #endif /* UNUSED */
  83102. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83103. {
  83104. unsigned total_bits, interesting_bits, msbs;
  83105. FLAC__uint32 uval, pattern;
  83106. FLAC__ASSERT(0 != bw);
  83107. FLAC__ASSERT(0 != bw->buffer);
  83108. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83109. uval = (val<<1) ^ (val>>31);
  83110. msbs = uval >> parameter;
  83111. interesting_bits = 1 + parameter;
  83112. total_bits = interesting_bits + msbs;
  83113. pattern = 1 << parameter; /* the unary end bit */
  83114. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83115. if(total_bits <= 32)
  83116. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83117. else
  83118. return
  83119. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83120. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83121. }
  83122. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83123. {
  83124. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83125. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83126. FLAC__uint32 uval;
  83127. unsigned left;
  83128. const unsigned lsbits = 1 + parameter;
  83129. unsigned msbits;
  83130. FLAC__ASSERT(0 != bw);
  83131. FLAC__ASSERT(0 != bw->buffer);
  83132. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83133. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83134. while(nvals) {
  83135. uval = (*vals<<1) ^ (*vals>>31);
  83136. msbits = uval >> parameter;
  83137. #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) */
  83138. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83139. bw->bits = bw->bits + msbits + lsbits;
  83140. uval |= mask1; /* set stop bit */
  83141. uval &= mask2; /* mask off unused top bits */
  83142. bw->accum <<= msbits;
  83143. bw->accum <<= lsbits;
  83144. bw->accum |= uval;
  83145. if(bw->bits == FLAC__BITS_PER_WORD) {
  83146. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83147. bw->bits = 0;
  83148. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83149. FLAC__ASSERT(bw->capacity == bw->words);
  83150. return false;
  83151. }
  83152. }
  83153. }
  83154. else {
  83155. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83156. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83157. bw->bits = bw->bits + msbits + lsbits;
  83158. uval |= mask1; /* set stop bit */
  83159. uval &= mask2; /* mask off unused top bits */
  83160. bw->accum <<= msbits + lsbits;
  83161. bw->accum |= uval;
  83162. }
  83163. else {
  83164. #endif
  83165. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83166. return false;
  83167. if(msbits) {
  83168. if(bw->bits) {
  83169. left = FLAC__BITS_PER_WORD - bw->bits;
  83170. if(msbits < left) {
  83171. bw->accum <<= msbits;
  83172. bw->bits += msbits;
  83173. goto break1;
  83174. }
  83175. else {
  83176. bw->accum <<= left;
  83177. msbits -= left;
  83178. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83179. bw->bits = 0;
  83180. }
  83181. }
  83182. while(msbits >= FLAC__BITS_PER_WORD) {
  83183. bw->buffer[bw->words++] = 0;
  83184. msbits -= FLAC__BITS_PER_WORD;
  83185. }
  83186. if(msbits > 0) {
  83187. bw->accum = 0;
  83188. bw->bits = msbits;
  83189. }
  83190. }
  83191. break1:
  83192. uval |= mask1; /* set stop bit */
  83193. uval &= mask2; /* mask off unused top bits */
  83194. left = FLAC__BITS_PER_WORD - bw->bits;
  83195. if(lsbits < left) {
  83196. bw->accum <<= lsbits;
  83197. bw->accum |= uval;
  83198. bw->bits += lsbits;
  83199. }
  83200. else {
  83201. FLAC__ASSERT(bw->bits);
  83202. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83203. bw->accum <<= left;
  83204. bw->accum |= uval >> (bw->bits = lsbits - left);
  83205. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83206. bw->accum = uval;
  83207. }
  83208. #if 1
  83209. }
  83210. #endif
  83211. vals++;
  83212. nvals--;
  83213. }
  83214. return true;
  83215. }
  83216. #if 0 /* UNUSED */
  83217. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83218. {
  83219. unsigned total_bits, msbs, uval;
  83220. unsigned k;
  83221. FLAC__ASSERT(0 != bw);
  83222. FLAC__ASSERT(0 != bw->buffer);
  83223. FLAC__ASSERT(parameter > 0);
  83224. if(val < 0)
  83225. uval = (unsigned)(((-(++val)) << 1) + 1);
  83226. else
  83227. uval = (unsigned)(val << 1);
  83228. k = FLAC__bitmath_ilog2(parameter);
  83229. if(parameter == 1u<<k) {
  83230. unsigned pattern;
  83231. FLAC__ASSERT(k <= 30);
  83232. msbs = uval >> k;
  83233. total_bits = 1 + k + msbs;
  83234. pattern = 1 << k; /* the unary end bit */
  83235. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83236. if(total_bits <= 32) {
  83237. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83238. return false;
  83239. }
  83240. else {
  83241. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83242. return false;
  83243. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83244. return false;
  83245. }
  83246. }
  83247. else {
  83248. unsigned q, r, d;
  83249. d = (1 << (k+1)) - parameter;
  83250. q = uval / parameter;
  83251. r = uval - (q * parameter);
  83252. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83253. return false;
  83254. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83255. return false;
  83256. if(r >= d) {
  83257. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83258. return false;
  83259. }
  83260. else {
  83261. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83262. return false;
  83263. }
  83264. }
  83265. return true;
  83266. }
  83267. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83268. {
  83269. unsigned total_bits, msbs;
  83270. unsigned k;
  83271. FLAC__ASSERT(0 != bw);
  83272. FLAC__ASSERT(0 != bw->buffer);
  83273. FLAC__ASSERT(parameter > 0);
  83274. k = FLAC__bitmath_ilog2(parameter);
  83275. if(parameter == 1u<<k) {
  83276. unsigned pattern;
  83277. FLAC__ASSERT(k <= 30);
  83278. msbs = uval >> k;
  83279. total_bits = 1 + k + msbs;
  83280. pattern = 1 << k; /* the unary end bit */
  83281. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83282. if(total_bits <= 32) {
  83283. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83284. return false;
  83285. }
  83286. else {
  83287. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83288. return false;
  83289. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83290. return false;
  83291. }
  83292. }
  83293. else {
  83294. unsigned q, r, d;
  83295. d = (1 << (k+1)) - parameter;
  83296. q = uval / parameter;
  83297. r = uval - (q * parameter);
  83298. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83299. return false;
  83300. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83301. return false;
  83302. if(r >= d) {
  83303. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83304. return false;
  83305. }
  83306. else {
  83307. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83308. return false;
  83309. }
  83310. }
  83311. return true;
  83312. }
  83313. #endif /* UNUSED */
  83314. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83315. {
  83316. FLAC__bool ok = 1;
  83317. FLAC__ASSERT(0 != bw);
  83318. FLAC__ASSERT(0 != bw->buffer);
  83319. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83320. if(val < 0x80) {
  83321. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83322. }
  83323. else if(val < 0x800) {
  83324. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83325. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83326. }
  83327. else if(val < 0x10000) {
  83328. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83329. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83330. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83331. }
  83332. else if(val < 0x200000) {
  83333. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83334. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83335. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83336. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83337. }
  83338. else if(val < 0x4000000) {
  83339. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83340. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83341. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83342. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83343. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83344. }
  83345. else {
  83346. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83347. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83348. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83349. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83350. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83351. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83352. }
  83353. return ok;
  83354. }
  83355. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83356. {
  83357. FLAC__bool ok = 1;
  83358. FLAC__ASSERT(0 != bw);
  83359. FLAC__ASSERT(0 != bw->buffer);
  83360. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83361. if(val < 0x80) {
  83362. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83363. }
  83364. else if(val < 0x800) {
  83365. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83366. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83367. }
  83368. else if(val < 0x10000) {
  83369. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83370. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83371. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83372. }
  83373. else if(val < 0x200000) {
  83374. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83375. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83376. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83377. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83378. }
  83379. else if(val < 0x4000000) {
  83380. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83381. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83382. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83383. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83384. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83385. }
  83386. else if(val < 0x80000000) {
  83387. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83388. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83389. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83390. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83391. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83392. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83393. }
  83394. else {
  83395. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83396. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83397. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83398. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83399. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83400. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83401. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83402. }
  83403. return ok;
  83404. }
  83405. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83406. {
  83407. if(bw->bits & 7u)
  83408. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83409. else
  83410. return true;
  83411. }
  83412. #endif
  83413. /*** End of inlined file: bitwriter.c ***/
  83414. /*** Start of inlined file: cpu.c ***/
  83415. /*** Start of inlined file: juce_FlacHeader.h ***/
  83416. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83417. // tasks..
  83418. #define VERSION "1.2.1"
  83419. #define FLAC__NO_DLL 1
  83420. #if JUCE_MSVC
  83421. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83422. #endif
  83423. #if JUCE_MAC
  83424. #define FLAC__SYS_DARWIN 1
  83425. #endif
  83426. /*** End of inlined file: juce_FlacHeader.h ***/
  83427. #if JUCE_USE_FLAC
  83428. #if HAVE_CONFIG_H
  83429. # include <config.h>
  83430. #endif
  83431. #include <stdlib.h>
  83432. #include <stdio.h>
  83433. #if defined FLAC__CPU_IA32
  83434. # include <signal.h>
  83435. #elif defined FLAC__CPU_PPC
  83436. # if !defined FLAC__NO_ASM
  83437. # if defined FLAC__SYS_DARWIN
  83438. # include <sys/sysctl.h>
  83439. # include <mach/mach.h>
  83440. # include <mach/mach_host.h>
  83441. # include <mach/host_info.h>
  83442. # include <mach/machine.h>
  83443. # ifndef CPU_SUBTYPE_POWERPC_970
  83444. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83445. # endif
  83446. # else /* FLAC__SYS_DARWIN */
  83447. # include <signal.h>
  83448. # include <setjmp.h>
  83449. static sigjmp_buf jmpbuf;
  83450. static volatile sig_atomic_t canjump = 0;
  83451. static void sigill_handler (int sig)
  83452. {
  83453. if (!canjump) {
  83454. signal (sig, SIG_DFL);
  83455. raise (sig);
  83456. }
  83457. canjump = 0;
  83458. siglongjmp (jmpbuf, 1);
  83459. }
  83460. # endif /* FLAC__SYS_DARWIN */
  83461. # endif /* FLAC__NO_ASM */
  83462. #endif /* FLAC__CPU_PPC */
  83463. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83464. #include <sys/param.h>
  83465. #include <sys/sysctl.h>
  83466. #include <machine/cpu.h>
  83467. #endif
  83468. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83469. #include <sys/types.h>
  83470. #include <sys/sysctl.h>
  83471. #endif
  83472. #if defined(__APPLE__)
  83473. #endif
  83474. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83475. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83476. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83477. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83478. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83479. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83480. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83481. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83482. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83483. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83484. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83485. # if defined(__linux__)
  83486. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83487. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83488. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83489. {
  83490. (void)signal;
  83491. sc.eip += 3 + 3 + 6;
  83492. }
  83493. # else
  83494. # include <sys/ucontext.h>
  83495. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83496. {
  83497. (void)signal, (void)si;
  83498. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83499. }
  83500. # endif
  83501. # elif defined(_MSC_VER)
  83502. # include <windows.h>
  83503. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83504. # ifdef USE_TRY_CATCH_FLAVOR
  83505. # else
  83506. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83507. {
  83508. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83509. ep->ContextRecord->Eip += 3 + 3 + 6;
  83510. return EXCEPTION_CONTINUE_EXECUTION;
  83511. }
  83512. return EXCEPTION_CONTINUE_SEARCH;
  83513. }
  83514. # endif
  83515. # endif
  83516. #endif
  83517. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83518. {
  83519. #ifdef FLAC__CPU_IA32
  83520. info->type = FLAC__CPUINFO_TYPE_IA32;
  83521. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83522. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83523. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83524. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83525. info->data.ia32.cmov = false;
  83526. info->data.ia32.mmx = false;
  83527. info->data.ia32.fxsr = false;
  83528. info->data.ia32.sse = false;
  83529. info->data.ia32.sse2 = false;
  83530. info->data.ia32.sse3 = false;
  83531. info->data.ia32.ssse3 = false;
  83532. info->data.ia32._3dnow = false;
  83533. info->data.ia32.ext3dnow = false;
  83534. info->data.ia32.extmmx = false;
  83535. if(info->data.ia32.cpuid) {
  83536. FLAC__uint32 flags_edx, flags_ecx;
  83537. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83538. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83539. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83540. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83541. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83542. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83543. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83544. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83545. #ifdef FLAC__USE_3DNOW
  83546. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83547. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83548. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83549. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83550. #else
  83551. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83552. #endif
  83553. #ifdef DEBUG
  83554. fprintf(stderr, "CPU info (IA-32):\n");
  83555. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83556. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83557. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83558. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83559. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83560. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83561. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83562. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83563. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83564. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83565. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83566. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83567. #endif
  83568. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83569. #if defined FLAC__NO_SSE_OS
  83570. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83571. #elif defined FLAC__SSE_OS
  83572. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83573. int sse = 0;
  83574. size_t len;
  83575. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83576. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83577. if(!sse)
  83578. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83579. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83580. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83581. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83582. size_t len = sizeof(val);
  83583. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83584. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83585. else { /* double-check SSE2 */
  83586. mib[1] = CPU_SSE2;
  83587. len = sizeof(val);
  83588. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83589. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83590. }
  83591. # else
  83592. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83593. # endif
  83594. #elif defined(__linux__)
  83595. int sse = 0;
  83596. struct sigaction sigill_save;
  83597. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83598. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83599. #else
  83600. struct sigaction sigill_sse;
  83601. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83602. __sigemptyset(&sigill_sse.sa_mask);
  83603. 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 */
  83604. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83605. #endif
  83606. {
  83607. asm volatile (
  83608. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83609. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83610. "incl %0\n\t" /* SIGILL handler will jump over this */
  83611. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83612. "nop\n\t"
  83613. "nop\n\t"
  83614. "nop\n\t"
  83615. "nop\n\t"
  83616. "nop\n\t"
  83617. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83618. "nop\n\t"
  83619. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83620. : "=r"(sse)
  83621. : "r"(sse)
  83622. );
  83623. sigaction(SIGILL, &sigill_save, NULL);
  83624. }
  83625. if(!sse)
  83626. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83627. #elif defined(_MSC_VER)
  83628. # ifdef USE_TRY_CATCH_FLAVOR
  83629. _try {
  83630. __asm {
  83631. # if _MSC_VER <= 1200
  83632. _emit 0x0F
  83633. _emit 0x57
  83634. _emit 0xC0
  83635. # else
  83636. xorps xmm0,xmm0
  83637. # endif
  83638. }
  83639. }
  83640. _except(EXCEPTION_EXECUTE_HANDLER) {
  83641. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83642. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83643. }
  83644. # else
  83645. int sse = 0;
  83646. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83647. __asm {
  83648. # if _MSC_VER <= 1200
  83649. _emit 0x0F
  83650. _emit 0x57
  83651. _emit 0xC0
  83652. # else
  83653. xorps xmm0,xmm0
  83654. # endif
  83655. inc sse
  83656. nop
  83657. nop
  83658. nop
  83659. nop
  83660. nop
  83661. nop
  83662. nop
  83663. nop
  83664. nop
  83665. }
  83666. SetUnhandledExceptionFilter(save);
  83667. if(!sse)
  83668. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83669. # endif
  83670. #else
  83671. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83672. #endif
  83673. #ifdef DEBUG
  83674. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83675. #endif
  83676. }
  83677. }
  83678. #else
  83679. info->use_asm = false;
  83680. #endif
  83681. #elif defined FLAC__CPU_PPC
  83682. info->type = FLAC__CPUINFO_TYPE_PPC;
  83683. # if !defined FLAC__NO_ASM
  83684. info->use_asm = true;
  83685. # ifdef FLAC__USE_ALTIVEC
  83686. # if defined FLAC__SYS_DARWIN
  83687. {
  83688. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83689. size_t len = sizeof(val);
  83690. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83691. }
  83692. {
  83693. host_basic_info_data_t hostInfo;
  83694. mach_msg_type_number_t infoCount;
  83695. infoCount = HOST_BASIC_INFO_COUNT;
  83696. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83697. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83698. }
  83699. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83700. {
  83701. info->data.ppc.altivec = 0;
  83702. info->data.ppc.ppc64 = 0;
  83703. signal (SIGILL, sigill_handler);
  83704. canjump = 0;
  83705. if (!sigsetjmp (jmpbuf, 1)) {
  83706. canjump = 1;
  83707. asm volatile (
  83708. "mtspr 256, %0\n\t"
  83709. "vand %%v0, %%v0, %%v0"
  83710. :
  83711. : "r" (-1)
  83712. );
  83713. info->data.ppc.altivec = 1;
  83714. }
  83715. canjump = 0;
  83716. if (!sigsetjmp (jmpbuf, 1)) {
  83717. int x = 0;
  83718. canjump = 1;
  83719. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83720. info->data.ppc.ppc64 = 1;
  83721. }
  83722. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83723. }
  83724. # endif
  83725. # else /* !FLAC__USE_ALTIVEC */
  83726. info->data.ppc.altivec = 0;
  83727. info->data.ppc.ppc64 = 0;
  83728. # endif
  83729. # else
  83730. info->use_asm = false;
  83731. # endif
  83732. #else
  83733. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83734. info->use_asm = false;
  83735. #endif
  83736. }
  83737. #endif
  83738. /*** End of inlined file: cpu.c ***/
  83739. /*** Start of inlined file: crc.c ***/
  83740. /*** Start of inlined file: juce_FlacHeader.h ***/
  83741. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83742. // tasks..
  83743. #define VERSION "1.2.1"
  83744. #define FLAC__NO_DLL 1
  83745. #if JUCE_MSVC
  83746. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83747. #endif
  83748. #if JUCE_MAC
  83749. #define FLAC__SYS_DARWIN 1
  83750. #endif
  83751. /*** End of inlined file: juce_FlacHeader.h ***/
  83752. #if JUCE_USE_FLAC
  83753. #if HAVE_CONFIG_H
  83754. # include <config.h>
  83755. #endif
  83756. FLAC__byte const FLAC__crc8_table[256] = {
  83757. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83758. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83759. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83760. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83761. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83762. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83763. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83764. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83765. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83766. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83767. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83768. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83769. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83770. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83771. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83772. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83773. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83774. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83775. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83776. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83777. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83778. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83779. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83780. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83781. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83782. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83783. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83784. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83785. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83786. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83787. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83788. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83789. };
  83790. unsigned FLAC__crc16_table[256] = {
  83791. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83792. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83793. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83794. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83795. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83796. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83797. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83798. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83799. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83800. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83801. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83802. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83803. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83804. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83805. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83806. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83807. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83808. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83809. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83810. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83811. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83812. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83813. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83814. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83815. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83816. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83817. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83818. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83819. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83820. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83821. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83822. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83823. };
  83824. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83825. {
  83826. *crc = FLAC__crc8_table[*crc ^ data];
  83827. }
  83828. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83829. {
  83830. while(len--)
  83831. *crc = FLAC__crc8_table[*crc ^ *data++];
  83832. }
  83833. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83834. {
  83835. FLAC__uint8 crc = 0;
  83836. while(len--)
  83837. crc = FLAC__crc8_table[crc ^ *data++];
  83838. return crc;
  83839. }
  83840. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83841. {
  83842. unsigned crc = 0;
  83843. while(len--)
  83844. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83845. return crc;
  83846. }
  83847. #endif
  83848. /*** End of inlined file: crc.c ***/
  83849. /*** Start of inlined file: fixed.c ***/
  83850. /*** Start of inlined file: juce_FlacHeader.h ***/
  83851. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83852. // tasks..
  83853. #define VERSION "1.2.1"
  83854. #define FLAC__NO_DLL 1
  83855. #if JUCE_MSVC
  83856. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83857. #endif
  83858. #if JUCE_MAC
  83859. #define FLAC__SYS_DARWIN 1
  83860. #endif
  83861. /*** End of inlined file: juce_FlacHeader.h ***/
  83862. #if JUCE_USE_FLAC
  83863. #if HAVE_CONFIG_H
  83864. # include <config.h>
  83865. #endif
  83866. #include <math.h>
  83867. #include <string.h>
  83868. /*** Start of inlined file: fixed.h ***/
  83869. #ifndef FLAC__PRIVATE__FIXED_H
  83870. #define FLAC__PRIVATE__FIXED_H
  83871. #ifdef HAVE_CONFIG_H
  83872. #include <config.h>
  83873. #endif
  83874. /*** Start of inlined file: float.h ***/
  83875. #ifndef FLAC__PRIVATE__FLOAT_H
  83876. #define FLAC__PRIVATE__FLOAT_H
  83877. #ifdef HAVE_CONFIG_H
  83878. #include <config.h>
  83879. #endif
  83880. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83881. typedef double FLAC__double;
  83882. typedef float FLAC__float;
  83883. typedef float FLAC__real;
  83884. #else
  83885. typedef FLAC__int32 FLAC__fixedpoint;
  83886. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83887. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83888. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83889. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83890. extern const FLAC__fixedpoint FLAC__FP_E;
  83891. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83892. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83893. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83894. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  83895. #endif
  83896. #endif
  83897. /*** End of inlined file: float.h ***/
  83898. /*** Start of inlined file: format.h ***/
  83899. #ifndef FLAC__PRIVATE__FORMAT_H
  83900. #define FLAC__PRIVATE__FORMAT_H
  83901. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  83902. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  83903. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  83904. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83905. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83906. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  83907. #endif
  83908. /*** End of inlined file: format.h ***/
  83909. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83910. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83911. # ifndef FLAC__NO_ASM
  83912. # ifdef FLAC__CPU_IA32
  83913. # ifdef FLAC__HAS_NASM
  83914. 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]);
  83915. # endif
  83916. # endif
  83917. # endif
  83918. 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]);
  83919. #else
  83920. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83921. 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]);
  83922. #endif
  83923. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  83924. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  83925. #endif
  83926. /*** End of inlined file: fixed.h ***/
  83927. #ifndef M_LN2
  83928. #define M_LN2 0.69314718055994530942
  83929. #endif
  83930. #ifdef min
  83931. #undef min
  83932. #endif
  83933. #define min(x,y) ((x) < (y)? (x) : (y))
  83934. #ifdef local_abs
  83935. #undef local_abs
  83936. #endif
  83937. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  83938. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  83939. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  83940. {
  83941. FLAC__uint32 rbps;
  83942. unsigned bits; /* the number of bits required to represent a number */
  83943. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83944. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83945. FLAC__ASSERT(err > 0);
  83946. FLAC__ASSERT(n > 0);
  83947. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83948. if(err <= n)
  83949. return 0;
  83950. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  83951. err <<= fracbits;
  83952. err /= n;
  83953. FLAC__ASSERT(err > 0);
  83954. bits = FLAC__bitmath_ilog2(err)+1;
  83955. if(bits > 16) {
  83956. err >>= (bits-16);
  83957. fracbits -= (bits-16);
  83958. }
  83959. rbps = (FLAC__uint32)err;
  83960. rbps *= FLAC__FP_LN2;
  83961. fracbits += 16;
  83962. FLAC__ASSERT(fracbits >= 0);
  83963. {
  83964. const int f = fracbits & 3;
  83965. if(f) {
  83966. rbps >>= f;
  83967. fracbits -= f;
  83968. }
  83969. }
  83970. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83971. if(rbps == 0)
  83972. return 0;
  83973. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83974. FLAC__ASSERT(fracbits >= -3);
  83975. if(fracbits < 16)
  83976. return rbps << (16-fracbits);
  83977. else if(fracbits > 16)
  83978. return rbps >> (fracbits-16);
  83979. else
  83980. return rbps;
  83981. }
  83982. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  83983. {
  83984. FLAC__uint32 rbps;
  83985. unsigned bits; /* the number of bits required to represent a number */
  83986. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83987. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83988. FLAC__ASSERT(err > 0);
  83989. FLAC__ASSERT(n > 0);
  83990. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83991. if(err <= n)
  83992. return 0;
  83993. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  83994. err <<= fracbits;
  83995. err /= n;
  83996. FLAC__ASSERT(err > 0);
  83997. bits = FLAC__bitmath_ilog2_wide(err)+1;
  83998. if(bits > 16) {
  83999. err >>= (bits-16);
  84000. fracbits -= (bits-16);
  84001. }
  84002. rbps = (FLAC__uint32)err;
  84003. rbps *= FLAC__FP_LN2;
  84004. fracbits += 16;
  84005. FLAC__ASSERT(fracbits >= 0);
  84006. {
  84007. const int f = fracbits & 3;
  84008. if(f) {
  84009. rbps >>= f;
  84010. fracbits -= f;
  84011. }
  84012. }
  84013. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84014. if(rbps == 0)
  84015. return 0;
  84016. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84017. FLAC__ASSERT(fracbits >= -3);
  84018. if(fracbits < 16)
  84019. return rbps << (16-fracbits);
  84020. else if(fracbits > 16)
  84021. return rbps >> (fracbits-16);
  84022. else
  84023. return rbps;
  84024. }
  84025. #endif
  84026. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84027. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84028. #else
  84029. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84030. #endif
  84031. {
  84032. FLAC__int32 last_error_0 = data[-1];
  84033. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84034. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84035. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84036. FLAC__int32 error, save;
  84037. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84038. unsigned i, order;
  84039. for(i = 0; i < data_len; i++) {
  84040. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84041. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84042. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84043. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84044. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84045. }
  84046. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84047. order = 0;
  84048. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84049. order = 1;
  84050. else if(total_error_2 < min(total_error_3, total_error_4))
  84051. order = 2;
  84052. else if(total_error_3 < total_error_4)
  84053. order = 3;
  84054. else
  84055. order = 4;
  84056. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84057. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84058. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84059. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84060. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84061. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84062. 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);
  84063. 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);
  84064. 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);
  84065. 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);
  84066. 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);
  84067. #else
  84068. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84069. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84070. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84071. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84072. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84073. #endif
  84074. return order;
  84075. }
  84076. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84077. 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])
  84078. #else
  84079. 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])
  84080. #endif
  84081. {
  84082. FLAC__int32 last_error_0 = data[-1];
  84083. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84084. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84085. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84086. FLAC__int32 error, save;
  84087. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84088. unsigned i, order;
  84089. for(i = 0; i < data_len; i++) {
  84090. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84091. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84092. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84093. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84094. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84095. }
  84096. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84097. order = 0;
  84098. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84099. order = 1;
  84100. else if(total_error_2 < min(total_error_3, total_error_4))
  84101. order = 2;
  84102. else if(total_error_3 < total_error_4)
  84103. order = 3;
  84104. else
  84105. order = 4;
  84106. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84107. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84108. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84109. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84110. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84111. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84112. #if defined _MSC_VER || defined __MINGW32__
  84113. 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);
  84114. 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);
  84115. 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);
  84116. 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);
  84117. 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);
  84118. #else
  84119. 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);
  84120. 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);
  84121. 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);
  84122. 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);
  84123. 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);
  84124. #endif
  84125. #else
  84126. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84127. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84128. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84129. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84130. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84131. #endif
  84132. return order;
  84133. }
  84134. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84135. {
  84136. const int idata_len = (int)data_len;
  84137. int i;
  84138. switch(order) {
  84139. case 0:
  84140. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84141. memcpy(residual, data, sizeof(residual[0])*data_len);
  84142. break;
  84143. case 1:
  84144. for(i = 0; i < idata_len; i++)
  84145. residual[i] = data[i] - data[i-1];
  84146. break;
  84147. case 2:
  84148. for(i = 0; i < idata_len; i++)
  84149. #if 1 /* OPT: may be faster with some compilers on some systems */
  84150. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84151. #else
  84152. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84153. #endif
  84154. break;
  84155. case 3:
  84156. for(i = 0; i < idata_len; i++)
  84157. #if 1 /* OPT: may be faster with some compilers on some systems */
  84158. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84159. #else
  84160. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84161. #endif
  84162. break;
  84163. case 4:
  84164. for(i = 0; i < idata_len; i++)
  84165. #if 1 /* OPT: may be faster with some compilers on some systems */
  84166. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84167. #else
  84168. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84169. #endif
  84170. break;
  84171. default:
  84172. FLAC__ASSERT(0);
  84173. }
  84174. }
  84175. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84176. {
  84177. int i, idata_len = (int)data_len;
  84178. switch(order) {
  84179. case 0:
  84180. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84181. memcpy(data, residual, sizeof(residual[0])*data_len);
  84182. break;
  84183. case 1:
  84184. for(i = 0; i < idata_len; i++)
  84185. data[i] = residual[i] + data[i-1];
  84186. break;
  84187. case 2:
  84188. for(i = 0; i < idata_len; i++)
  84189. #if 1 /* OPT: may be faster with some compilers on some systems */
  84190. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84191. #else
  84192. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84193. #endif
  84194. break;
  84195. case 3:
  84196. for(i = 0; i < idata_len; i++)
  84197. #if 1 /* OPT: may be faster with some compilers on some systems */
  84198. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84199. #else
  84200. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84201. #endif
  84202. break;
  84203. case 4:
  84204. for(i = 0; i < idata_len; i++)
  84205. #if 1 /* OPT: may be faster with some compilers on some systems */
  84206. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84207. #else
  84208. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84209. #endif
  84210. break;
  84211. default:
  84212. FLAC__ASSERT(0);
  84213. }
  84214. }
  84215. #endif
  84216. /*** End of inlined file: fixed.c ***/
  84217. /*** Start of inlined file: float.c ***/
  84218. /*** Start of inlined file: juce_FlacHeader.h ***/
  84219. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84220. // tasks..
  84221. #define VERSION "1.2.1"
  84222. #define FLAC__NO_DLL 1
  84223. #if JUCE_MSVC
  84224. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84225. #endif
  84226. #if JUCE_MAC
  84227. #define FLAC__SYS_DARWIN 1
  84228. #endif
  84229. /*** End of inlined file: juce_FlacHeader.h ***/
  84230. #if JUCE_USE_FLAC
  84231. #if HAVE_CONFIG_H
  84232. # include <config.h>
  84233. #endif
  84234. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84235. #ifdef _MSC_VER
  84236. #define FLAC__U64L(x) x
  84237. #else
  84238. #define FLAC__U64L(x) x##LLU
  84239. #endif
  84240. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84241. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84242. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84243. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84244. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84245. #define LOG2_LOOKUP_PRECISION 16
  84246. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84247. {
  84248. 0x00000000,
  84249. 0x00000001,
  84250. 0x00000000,
  84251. 0x00000000,
  84252. 0x00000000,
  84253. 0x00000000,
  84254. 0x00000000,
  84255. 0x00000000,
  84256. 0x00000000,
  84257. 0x00000000,
  84258. 0x00000000,
  84259. 0x00000000,
  84260. 0x00000000,
  84261. 0x00000000,
  84262. 0x00000000,
  84263. 0x00000000
  84264. },
  84265. {
  84266. 0x00000000,
  84267. 0x00000010,
  84268. 0x00000007,
  84269. 0x00000003,
  84270. 0x00000001,
  84271. 0x00000001,
  84272. 0x00000000,
  84273. 0x00000000,
  84274. 0x00000000,
  84275. 0x00000000,
  84276. 0x00000000,
  84277. 0x00000000,
  84278. 0x00000000,
  84279. 0x00000000,
  84280. 0x00000000,
  84281. 0x00000000
  84282. },
  84283. {
  84284. 0x00000000,
  84285. 0x00000100,
  84286. 0x0000006a,
  84287. 0x00000031,
  84288. 0x00000018,
  84289. 0x0000000c,
  84290. 0x00000006,
  84291. 0x00000003,
  84292. 0x00000001,
  84293. 0x00000001,
  84294. 0x00000000,
  84295. 0x00000000,
  84296. 0x00000000,
  84297. 0x00000000,
  84298. 0x00000000,
  84299. 0x00000000
  84300. },
  84301. {
  84302. 0x00000000,
  84303. 0x00001000,
  84304. 0x000006a4,
  84305. 0x00000315,
  84306. 0x0000017d,
  84307. 0x000000bc,
  84308. 0x0000005d,
  84309. 0x0000002e,
  84310. 0x00000017,
  84311. 0x0000000c,
  84312. 0x00000006,
  84313. 0x00000003,
  84314. 0x00000001,
  84315. 0x00000001,
  84316. 0x00000000,
  84317. 0x00000000
  84318. },
  84319. {
  84320. 0x00000000,
  84321. 0x00010000,
  84322. 0x00006a40,
  84323. 0x00003151,
  84324. 0x000017d6,
  84325. 0x00000bba,
  84326. 0x000005d1,
  84327. 0x000002e6,
  84328. 0x00000172,
  84329. 0x000000b9,
  84330. 0x0000005c,
  84331. 0x0000002e,
  84332. 0x00000017,
  84333. 0x0000000c,
  84334. 0x00000006,
  84335. 0x00000003
  84336. },
  84337. {
  84338. 0x00000000,
  84339. 0x00100000,
  84340. 0x0006a3fe,
  84341. 0x00031513,
  84342. 0x00017d60,
  84343. 0x0000bb9d,
  84344. 0x00005d10,
  84345. 0x00002e59,
  84346. 0x00001721,
  84347. 0x00000b8e,
  84348. 0x000005c6,
  84349. 0x000002e3,
  84350. 0x00000171,
  84351. 0x000000b9,
  84352. 0x0000005c,
  84353. 0x0000002e
  84354. },
  84355. {
  84356. 0x00000000,
  84357. 0x01000000,
  84358. 0x006a3fe6,
  84359. 0x00315130,
  84360. 0x0017d605,
  84361. 0x000bb9ca,
  84362. 0x0005d0fc,
  84363. 0x0002e58f,
  84364. 0x0001720e,
  84365. 0x0000b8d8,
  84366. 0x00005c61,
  84367. 0x00002e2d,
  84368. 0x00001716,
  84369. 0x00000b8b,
  84370. 0x000005c5,
  84371. 0x000002e3
  84372. },
  84373. {
  84374. 0x00000000,
  84375. 0x10000000,
  84376. 0x06a3fe5c,
  84377. 0x03151301,
  84378. 0x017d6049,
  84379. 0x00bb9ca6,
  84380. 0x005d0fba,
  84381. 0x002e58f7,
  84382. 0x001720da,
  84383. 0x000b8d87,
  84384. 0x0005c60b,
  84385. 0x0002e2d7,
  84386. 0x00017160,
  84387. 0x0000b8ad,
  84388. 0x00005c56,
  84389. 0x00002e2b
  84390. }
  84391. };
  84392. #if 0
  84393. static const FLAC__uint64 log2_lookup_wide[] = {
  84394. {
  84395. 0x00000000,
  84396. FLAC__U64L(0x100000000),
  84397. FLAC__U64L(0x6a3fe5c6),
  84398. FLAC__U64L(0x31513015),
  84399. FLAC__U64L(0x17d60497),
  84400. FLAC__U64L(0x0bb9ca65),
  84401. FLAC__U64L(0x05d0fba2),
  84402. FLAC__U64L(0x02e58f74),
  84403. FLAC__U64L(0x01720d9c),
  84404. FLAC__U64L(0x00b8d875),
  84405. FLAC__U64L(0x005c60aa),
  84406. FLAC__U64L(0x002e2d72),
  84407. FLAC__U64L(0x00171600),
  84408. FLAC__U64L(0x000b8ad2),
  84409. FLAC__U64L(0x0005c55d),
  84410. FLAC__U64L(0x0002e2ac)
  84411. },
  84412. {
  84413. 0x00000000,
  84414. FLAC__U64L(0x1000000000000),
  84415. FLAC__U64L(0x6a3fe5c60429),
  84416. FLAC__U64L(0x315130157f7a),
  84417. FLAC__U64L(0x17d60496cfbb),
  84418. FLAC__U64L(0xbb9ca64ecac),
  84419. FLAC__U64L(0x5d0fba187cd),
  84420. FLAC__U64L(0x2e58f7441ee),
  84421. FLAC__U64L(0x1720d9c06a8),
  84422. FLAC__U64L(0xb8d8752173),
  84423. FLAC__U64L(0x5c60aa252e),
  84424. FLAC__U64L(0x2e2d71b0d8),
  84425. FLAC__U64L(0x1716001719),
  84426. FLAC__U64L(0xb8ad1de1b),
  84427. FLAC__U64L(0x5c55d640d),
  84428. FLAC__U64L(0x2e2abcf52)
  84429. }
  84430. };
  84431. #endif
  84432. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84433. {
  84434. const FLAC__uint32 ONE = (1u << fracbits);
  84435. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84436. FLAC__ASSERT(fracbits < 32);
  84437. FLAC__ASSERT((fracbits & 0x3) == 0);
  84438. if(x < ONE)
  84439. return 0;
  84440. if(precision > LOG2_LOOKUP_PRECISION)
  84441. precision = LOG2_LOOKUP_PRECISION;
  84442. {
  84443. FLAC__uint32 y = 0;
  84444. FLAC__uint32 z = x >> 1, k = 1;
  84445. while (x > ONE && k < precision) {
  84446. if (x - z >= ONE) {
  84447. x -= z;
  84448. z = x >> k;
  84449. y += table[k];
  84450. }
  84451. else {
  84452. z >>= 1;
  84453. k++;
  84454. }
  84455. }
  84456. return y;
  84457. }
  84458. }
  84459. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84460. #endif
  84461. /*** End of inlined file: float.c ***/
  84462. /*** Start of inlined file: format.c ***/
  84463. /*** Start of inlined file: juce_FlacHeader.h ***/
  84464. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84465. // tasks..
  84466. #define VERSION "1.2.1"
  84467. #define FLAC__NO_DLL 1
  84468. #if JUCE_MSVC
  84469. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84470. #endif
  84471. #if JUCE_MAC
  84472. #define FLAC__SYS_DARWIN 1
  84473. #endif
  84474. /*** End of inlined file: juce_FlacHeader.h ***/
  84475. #if JUCE_USE_FLAC
  84476. #if HAVE_CONFIG_H
  84477. # include <config.h>
  84478. #endif
  84479. #include <stdio.h>
  84480. #include <stdlib.h> /* for qsort() */
  84481. #include <string.h> /* for memset() */
  84482. #ifndef FLaC__INLINE
  84483. #define FLaC__INLINE
  84484. #endif
  84485. #ifdef min
  84486. #undef min
  84487. #endif
  84488. #define min(a,b) ((a)<(b)?(a):(b))
  84489. #ifdef _MSC_VER
  84490. #define FLAC__U64L(x) x
  84491. #else
  84492. #define FLAC__U64L(x) x##LLU
  84493. #endif
  84494. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84495. ;
  84496. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84497. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84498. #else
  84499. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84500. #endif
  84501. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84502. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84503. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84504. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84505. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84506. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84507. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84508. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84509. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84510. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84511. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84512. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84513. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84514. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84515. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84516. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84517. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84518. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84519. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84520. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84521. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84522. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84523. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84524. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84525. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84526. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84527. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84528. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84529. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84530. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84531. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84532. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84533. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84534. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84535. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84536. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84537. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84538. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84539. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84540. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84541. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84542. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84543. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84544. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84545. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84546. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84547. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84548. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84549. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84550. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84551. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84552. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84553. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84554. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84555. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84556. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84557. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84558. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84559. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84560. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84561. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84562. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84563. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84564. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84565. "PARTITIONED_RICE",
  84566. "PARTITIONED_RICE2"
  84567. };
  84568. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84569. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84570. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84571. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84572. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84573. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84574. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84575. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84576. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84577. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84578. "CONSTANT",
  84579. "VERBATIM",
  84580. "FIXED",
  84581. "LPC"
  84582. };
  84583. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84584. "INDEPENDENT",
  84585. "LEFT_SIDE",
  84586. "RIGHT_SIDE",
  84587. "MID_SIDE"
  84588. };
  84589. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84590. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84591. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84592. };
  84593. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84594. "STREAMINFO",
  84595. "PADDING",
  84596. "APPLICATION",
  84597. "SEEKTABLE",
  84598. "VORBIS_COMMENT",
  84599. "CUESHEET",
  84600. "PICTURE"
  84601. };
  84602. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84603. "Other",
  84604. "32x32 pixels 'file icon' (PNG only)",
  84605. "Other file icon",
  84606. "Cover (front)",
  84607. "Cover (back)",
  84608. "Leaflet page",
  84609. "Media (e.g. label side of CD)",
  84610. "Lead artist/lead performer/soloist",
  84611. "Artist/performer",
  84612. "Conductor",
  84613. "Band/Orchestra",
  84614. "Composer",
  84615. "Lyricist/text writer",
  84616. "Recording Location",
  84617. "During recording",
  84618. "During performance",
  84619. "Movie/video screen capture",
  84620. "A bright coloured fish",
  84621. "Illustration",
  84622. "Band/artist logotype",
  84623. "Publisher/Studio logotype"
  84624. };
  84625. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84626. {
  84627. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84628. return false;
  84629. }
  84630. else
  84631. return true;
  84632. }
  84633. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84634. {
  84635. if(
  84636. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84637. (
  84638. sample_rate >= (1u << 16) &&
  84639. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84640. )
  84641. ) {
  84642. return false;
  84643. }
  84644. else
  84645. return true;
  84646. }
  84647. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84648. {
  84649. unsigned i;
  84650. FLAC__uint64 prev_sample_number = 0;
  84651. FLAC__bool got_prev = false;
  84652. FLAC__ASSERT(0 != seek_table);
  84653. for(i = 0; i < seek_table->num_points; i++) {
  84654. if(got_prev) {
  84655. if(
  84656. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84657. seek_table->points[i].sample_number <= prev_sample_number
  84658. )
  84659. return false;
  84660. }
  84661. prev_sample_number = seek_table->points[i].sample_number;
  84662. got_prev = true;
  84663. }
  84664. return true;
  84665. }
  84666. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84667. {
  84668. if(l->sample_number == r->sample_number)
  84669. return 0;
  84670. else if(l->sample_number < r->sample_number)
  84671. return -1;
  84672. else
  84673. return 1;
  84674. }
  84675. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84676. {
  84677. unsigned i, j;
  84678. FLAC__bool first;
  84679. FLAC__ASSERT(0 != seek_table);
  84680. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84681. first = true;
  84682. for(i = j = 0; i < seek_table->num_points; i++) {
  84683. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84684. if(!first) {
  84685. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84686. continue;
  84687. }
  84688. }
  84689. first = false;
  84690. seek_table->points[j++] = seek_table->points[i];
  84691. }
  84692. for(i = j; i < seek_table->num_points; i++) {
  84693. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84694. seek_table->points[i].stream_offset = 0;
  84695. seek_table->points[i].frame_samples = 0;
  84696. }
  84697. return j;
  84698. }
  84699. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84700. {
  84701. FLAC__ASSERT(0 != utf8);
  84702. if ((utf8[0] & 0x80) == 0) {
  84703. return 1;
  84704. }
  84705. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84706. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84707. return 0;
  84708. return 2;
  84709. }
  84710. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84711. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84712. return 0;
  84713. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84714. return 0;
  84715. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84716. return 0;
  84717. return 3;
  84718. }
  84719. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84720. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84721. return 0;
  84722. return 4;
  84723. }
  84724. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84725. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84726. return 0;
  84727. return 5;
  84728. }
  84729. 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) {
  84730. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84731. return 0;
  84732. return 6;
  84733. }
  84734. else {
  84735. return 0;
  84736. }
  84737. }
  84738. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84739. {
  84740. char c;
  84741. for(c = *name; c; c = *(++name))
  84742. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84743. return false;
  84744. return true;
  84745. }
  84746. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84747. {
  84748. if(length == (unsigned)(-1)) {
  84749. while(*value) {
  84750. unsigned n = utf8len_(value);
  84751. if(n == 0)
  84752. return false;
  84753. value += n;
  84754. }
  84755. }
  84756. else {
  84757. const FLAC__byte *end = value + length;
  84758. while(value < end) {
  84759. unsigned n = utf8len_(value);
  84760. if(n == 0)
  84761. return false;
  84762. value += n;
  84763. }
  84764. if(value != end)
  84765. return false;
  84766. }
  84767. return true;
  84768. }
  84769. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84770. {
  84771. const FLAC__byte *s, *end;
  84772. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84773. if(*s < 0x20 || *s > 0x7D)
  84774. return false;
  84775. }
  84776. if(s == end)
  84777. return false;
  84778. s++; /* skip '=' */
  84779. while(s < end) {
  84780. unsigned n = utf8len_(s);
  84781. if(n == 0)
  84782. return false;
  84783. s += n;
  84784. }
  84785. if(s != end)
  84786. return false;
  84787. return true;
  84788. }
  84789. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84790. {
  84791. unsigned i, j;
  84792. if(check_cd_da_subset) {
  84793. if(cue_sheet->lead_in < 2 * 44100) {
  84794. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84795. return false;
  84796. }
  84797. if(cue_sheet->lead_in % 588 != 0) {
  84798. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84799. return false;
  84800. }
  84801. }
  84802. if(cue_sheet->num_tracks == 0) {
  84803. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84804. return false;
  84805. }
  84806. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84807. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84808. return false;
  84809. }
  84810. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84811. if(cue_sheet->tracks[i].number == 0) {
  84812. if(violation) *violation = "cue sheet may not have a track number 0";
  84813. return false;
  84814. }
  84815. if(check_cd_da_subset) {
  84816. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84817. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84818. return false;
  84819. }
  84820. }
  84821. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84822. if(violation) {
  84823. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84824. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84825. else
  84826. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84827. }
  84828. return false;
  84829. }
  84830. if(i < cue_sheet->num_tracks - 1) {
  84831. if(cue_sheet->tracks[i].num_indices == 0) {
  84832. if(violation) *violation = "cue sheet track must have at least one index point";
  84833. return false;
  84834. }
  84835. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84836. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84837. return false;
  84838. }
  84839. }
  84840. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84841. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84842. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84843. return false;
  84844. }
  84845. if(j > 0) {
  84846. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84847. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84848. return false;
  84849. }
  84850. }
  84851. }
  84852. }
  84853. return true;
  84854. }
  84855. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84856. {
  84857. char *p;
  84858. FLAC__byte *b;
  84859. for(p = picture->mime_type; *p; p++) {
  84860. if(*p < 0x20 || *p > 0x7e) {
  84861. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84862. return false;
  84863. }
  84864. }
  84865. for(b = picture->description; *b; ) {
  84866. unsigned n = utf8len_(b);
  84867. if(n == 0) {
  84868. if(violation) *violation = "description string must be valid UTF-8";
  84869. return false;
  84870. }
  84871. b += n;
  84872. }
  84873. return true;
  84874. }
  84875. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84876. {
  84877. return
  84878. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84879. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84880. blocksize,
  84881. predictor_order
  84882. );
  84883. }
  84884. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84885. {
  84886. unsigned max_rice_partition_order = 0;
  84887. while(!(blocksize & 1)) {
  84888. max_rice_partition_order++;
  84889. blocksize >>= 1;
  84890. }
  84891. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84892. }
  84893. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84894. {
  84895. unsigned max_rice_partition_order = limit;
  84896. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  84897. max_rice_partition_order--;
  84898. FLAC__ASSERT(
  84899. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  84900. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  84901. );
  84902. return max_rice_partition_order;
  84903. }
  84904. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84905. {
  84906. FLAC__ASSERT(0 != object);
  84907. object->parameters = 0;
  84908. object->raw_bits = 0;
  84909. object->capacity_by_order = 0;
  84910. }
  84911. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84912. {
  84913. FLAC__ASSERT(0 != object);
  84914. if(0 != object->parameters)
  84915. free(object->parameters);
  84916. if(0 != object->raw_bits)
  84917. free(object->raw_bits);
  84918. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  84919. }
  84920. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  84921. {
  84922. FLAC__ASSERT(0 != object);
  84923. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  84924. if(object->capacity_by_order < max_partition_order) {
  84925. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  84926. return false;
  84927. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  84928. return false;
  84929. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  84930. object->capacity_by_order = max_partition_order;
  84931. }
  84932. return true;
  84933. }
  84934. #endif
  84935. /*** End of inlined file: format.c ***/
  84936. /*** Start of inlined file: lpc_flac.c ***/
  84937. /*** Start of inlined file: juce_FlacHeader.h ***/
  84938. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84939. // tasks..
  84940. #define VERSION "1.2.1"
  84941. #define FLAC__NO_DLL 1
  84942. #if JUCE_MSVC
  84943. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84944. #endif
  84945. #if JUCE_MAC
  84946. #define FLAC__SYS_DARWIN 1
  84947. #endif
  84948. /*** End of inlined file: juce_FlacHeader.h ***/
  84949. #if JUCE_USE_FLAC
  84950. #if HAVE_CONFIG_H
  84951. # include <config.h>
  84952. #endif
  84953. #include <math.h>
  84954. /*** Start of inlined file: lpc.h ***/
  84955. #ifndef FLAC__PRIVATE__LPC_H
  84956. #define FLAC__PRIVATE__LPC_H
  84957. #ifdef HAVE_CONFIG_H
  84958. #include <config.h>
  84959. #endif
  84960. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84961. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  84962. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84963. #ifndef FLAC__NO_ASM
  84964. # ifdef FLAC__CPU_IA32
  84965. # ifdef FLAC__HAS_NASM
  84966. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84967. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84968. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84969. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84970. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84971. # endif
  84972. # endif
  84973. #endif
  84974. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  84975. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  84976. 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[]);
  84977. 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[]);
  84978. #ifndef FLAC__NO_ASM
  84979. # ifdef FLAC__CPU_IA32
  84980. # ifdef FLAC__HAS_NASM
  84981. 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[]);
  84982. 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[]);
  84983. # endif
  84984. # endif
  84985. #endif
  84986. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84987. 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[]);
  84988. 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[]);
  84989. #ifndef FLAC__NO_ASM
  84990. # ifdef FLAC__CPU_IA32
  84991. # ifdef FLAC__HAS_NASM
  84992. 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[]);
  84993. 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[]);
  84994. # endif /* FLAC__HAS_NASM */
  84995. # elif defined FLAC__CPU_PPC
  84996. 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[]);
  84997. 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[]);
  84998. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  84999. #endif /* FLAC__NO_ASM */
  85000. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85001. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85002. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85003. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85004. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85005. #endif
  85006. /*** End of inlined file: lpc.h ***/
  85007. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85008. #include <stdio.h>
  85009. #endif
  85010. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85011. #ifndef M_LN2
  85012. #define M_LN2 0.69314718055994530942
  85013. #endif
  85014. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85015. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85016. {
  85017. unsigned i;
  85018. for(i = 0; i < data_len; i++)
  85019. out[i] = in[i] * window[i];
  85020. }
  85021. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85022. {
  85023. #if 0
  85024. FLAC__real d;
  85025. unsigned i;
  85026. FLAC__ASSERT(lag > 0);
  85027. FLAC__ASSERT(lag <= data_len);
  85028. while(lag--) {
  85029. for(i = lag, d = 0.0; i < data_len; i++)
  85030. d += data[i] * data[i - lag];
  85031. autoc[lag] = d;
  85032. }
  85033. #endif
  85034. FLAC__real d;
  85035. unsigned sample, coeff;
  85036. const unsigned limit = data_len - lag;
  85037. FLAC__ASSERT(lag > 0);
  85038. FLAC__ASSERT(lag <= data_len);
  85039. for(coeff = 0; coeff < lag; coeff++)
  85040. autoc[coeff] = 0.0;
  85041. for(sample = 0; sample <= limit; sample++) {
  85042. d = data[sample];
  85043. for(coeff = 0; coeff < lag; coeff++)
  85044. autoc[coeff] += d * data[sample+coeff];
  85045. }
  85046. for(; sample < data_len; sample++) {
  85047. d = data[sample];
  85048. for(coeff = 0; coeff < data_len - sample; coeff++)
  85049. autoc[coeff] += d * data[sample+coeff];
  85050. }
  85051. }
  85052. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85053. {
  85054. unsigned i, j;
  85055. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85056. FLAC__ASSERT(0 != max_order);
  85057. FLAC__ASSERT(0 < *max_order);
  85058. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85059. FLAC__ASSERT(autoc[0] != 0.0);
  85060. err = autoc[0];
  85061. for(i = 0; i < *max_order; i++) {
  85062. r = -autoc[i+1];
  85063. for(j = 0; j < i; j++)
  85064. r -= lpc[j] * autoc[i-j];
  85065. ref[i] = (r/=err);
  85066. lpc[i]=r;
  85067. for(j = 0; j < (i>>1); j++) {
  85068. FLAC__double tmp = lpc[j];
  85069. lpc[j] += r * lpc[i-1-j];
  85070. lpc[i-1-j] += r * tmp;
  85071. }
  85072. if(i & 1)
  85073. lpc[j] += lpc[j] * r;
  85074. err *= (1.0 - r * r);
  85075. for(j = 0; j <= i; j++)
  85076. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85077. error[i] = err;
  85078. if(err == 0.0) {
  85079. *max_order = i+1;
  85080. return;
  85081. }
  85082. }
  85083. }
  85084. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85085. {
  85086. unsigned i;
  85087. FLAC__double cmax;
  85088. FLAC__int32 qmax, qmin;
  85089. FLAC__ASSERT(precision > 0);
  85090. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85091. precision--;
  85092. qmax = 1 << precision;
  85093. qmin = -qmax;
  85094. qmax--;
  85095. cmax = 0.0;
  85096. for(i = 0; i < order; i++) {
  85097. const FLAC__double d = fabs(lp_coeff[i]);
  85098. if(d > cmax)
  85099. cmax = d;
  85100. }
  85101. if(cmax <= 0.0) {
  85102. return 2;
  85103. }
  85104. else {
  85105. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85106. const int min_shiftlimit = -max_shiftlimit - 1;
  85107. int log2cmax;
  85108. (void)frexp(cmax, &log2cmax);
  85109. log2cmax--;
  85110. *shift = (int)precision - log2cmax - 1;
  85111. if(*shift > max_shiftlimit)
  85112. *shift = max_shiftlimit;
  85113. else if(*shift < min_shiftlimit)
  85114. return 1;
  85115. }
  85116. if(*shift >= 0) {
  85117. FLAC__double error = 0.0;
  85118. FLAC__int32 q;
  85119. for(i = 0; i < order; i++) {
  85120. error += lp_coeff[i] * (1 << *shift);
  85121. #if 1 /* unfortunately lround() is C99 */
  85122. if(error >= 0.0)
  85123. q = (FLAC__int32)(error + 0.5);
  85124. else
  85125. q = (FLAC__int32)(error - 0.5);
  85126. #else
  85127. q = lround(error);
  85128. #endif
  85129. #ifdef FLAC__OVERFLOW_DETECT
  85130. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85131. 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]);
  85132. else if(q < qmin)
  85133. 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]);
  85134. #endif
  85135. if(q > qmax)
  85136. q = qmax;
  85137. else if(q < qmin)
  85138. q = qmin;
  85139. error -= q;
  85140. qlp_coeff[i] = q;
  85141. }
  85142. }
  85143. else {
  85144. const int nshift = -(*shift);
  85145. FLAC__double error = 0.0;
  85146. FLAC__int32 q;
  85147. #ifdef DEBUG
  85148. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85149. #endif
  85150. for(i = 0; i < order; i++) {
  85151. error += lp_coeff[i] / (1 << nshift);
  85152. #if 1 /* unfortunately lround() is C99 */
  85153. if(error >= 0.0)
  85154. q = (FLAC__int32)(error + 0.5);
  85155. else
  85156. q = (FLAC__int32)(error - 0.5);
  85157. #else
  85158. q = lround(error);
  85159. #endif
  85160. #ifdef FLAC__OVERFLOW_DETECT
  85161. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85162. 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]);
  85163. else if(q < qmin)
  85164. 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]);
  85165. #endif
  85166. if(q > qmax)
  85167. q = qmax;
  85168. else if(q < qmin)
  85169. q = qmin;
  85170. error -= q;
  85171. qlp_coeff[i] = q;
  85172. }
  85173. *shift = 0;
  85174. }
  85175. return 0;
  85176. }
  85177. 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[])
  85178. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85179. {
  85180. FLAC__int64 sumo;
  85181. unsigned i, j;
  85182. FLAC__int32 sum;
  85183. const FLAC__int32 *history;
  85184. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85185. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85186. for(i=0;i<order;i++)
  85187. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85188. fprintf(stderr,"\n");
  85189. #endif
  85190. FLAC__ASSERT(order > 0);
  85191. for(i = 0; i < data_len; i++) {
  85192. sumo = 0;
  85193. sum = 0;
  85194. history = data;
  85195. for(j = 0; j < order; j++) {
  85196. sum += qlp_coeff[j] * (*(--history));
  85197. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85198. #if defined _MSC_VER
  85199. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85200. 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);
  85201. #else
  85202. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85203. 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);
  85204. #endif
  85205. }
  85206. *(residual++) = *(data++) - (sum >> lp_quantization);
  85207. }
  85208. }
  85209. #else /* fully unrolled version for normal use */
  85210. {
  85211. int i;
  85212. FLAC__int32 sum;
  85213. FLAC__ASSERT(order > 0);
  85214. FLAC__ASSERT(order <= 32);
  85215. if(order <= 12) {
  85216. if(order > 8) {
  85217. if(order > 10) {
  85218. if(order == 12) {
  85219. for(i = 0; i < (int)data_len; i++) {
  85220. sum = 0;
  85221. sum += qlp_coeff[11] * data[i-12];
  85222. sum += qlp_coeff[10] * data[i-11];
  85223. sum += qlp_coeff[9] * data[i-10];
  85224. sum += qlp_coeff[8] * data[i-9];
  85225. sum += qlp_coeff[7] * data[i-8];
  85226. sum += qlp_coeff[6] * data[i-7];
  85227. sum += qlp_coeff[5] * data[i-6];
  85228. sum += qlp_coeff[4] * data[i-5];
  85229. sum += qlp_coeff[3] * data[i-4];
  85230. sum += qlp_coeff[2] * data[i-3];
  85231. sum += qlp_coeff[1] * data[i-2];
  85232. sum += qlp_coeff[0] * data[i-1];
  85233. residual[i] = data[i] - (sum >> lp_quantization);
  85234. }
  85235. }
  85236. else { /* order == 11 */
  85237. for(i = 0; i < (int)data_len; i++) {
  85238. sum = 0;
  85239. sum += qlp_coeff[10] * data[i-11];
  85240. sum += qlp_coeff[9] * data[i-10];
  85241. sum += qlp_coeff[8] * data[i-9];
  85242. sum += qlp_coeff[7] * data[i-8];
  85243. sum += qlp_coeff[6] * data[i-7];
  85244. sum += qlp_coeff[5] * data[i-6];
  85245. sum += qlp_coeff[4] * data[i-5];
  85246. sum += qlp_coeff[3] * data[i-4];
  85247. sum += qlp_coeff[2] * data[i-3];
  85248. sum += qlp_coeff[1] * data[i-2];
  85249. sum += qlp_coeff[0] * data[i-1];
  85250. residual[i] = data[i] - (sum >> lp_quantization);
  85251. }
  85252. }
  85253. }
  85254. else {
  85255. if(order == 10) {
  85256. for(i = 0; i < (int)data_len; i++) {
  85257. sum = 0;
  85258. sum += qlp_coeff[9] * data[i-10];
  85259. sum += qlp_coeff[8] * data[i-9];
  85260. sum += qlp_coeff[7] * data[i-8];
  85261. sum += qlp_coeff[6] * data[i-7];
  85262. sum += qlp_coeff[5] * data[i-6];
  85263. sum += qlp_coeff[4] * data[i-5];
  85264. sum += qlp_coeff[3] * data[i-4];
  85265. sum += qlp_coeff[2] * data[i-3];
  85266. sum += qlp_coeff[1] * data[i-2];
  85267. sum += qlp_coeff[0] * data[i-1];
  85268. residual[i] = data[i] - (sum >> lp_quantization);
  85269. }
  85270. }
  85271. else { /* order == 9 */
  85272. for(i = 0; i < (int)data_len; i++) {
  85273. sum = 0;
  85274. sum += qlp_coeff[8] * data[i-9];
  85275. sum += qlp_coeff[7] * data[i-8];
  85276. sum += qlp_coeff[6] * data[i-7];
  85277. sum += qlp_coeff[5] * data[i-6];
  85278. sum += qlp_coeff[4] * data[i-5];
  85279. sum += qlp_coeff[3] * data[i-4];
  85280. sum += qlp_coeff[2] * data[i-3];
  85281. sum += qlp_coeff[1] * data[i-2];
  85282. sum += qlp_coeff[0] * data[i-1];
  85283. residual[i] = data[i] - (sum >> lp_quantization);
  85284. }
  85285. }
  85286. }
  85287. }
  85288. else if(order > 4) {
  85289. if(order > 6) {
  85290. if(order == 8) {
  85291. for(i = 0; i < (int)data_len; i++) {
  85292. sum = 0;
  85293. sum += qlp_coeff[7] * data[i-8];
  85294. sum += qlp_coeff[6] * data[i-7];
  85295. sum += qlp_coeff[5] * data[i-6];
  85296. sum += qlp_coeff[4] * data[i-5];
  85297. sum += qlp_coeff[3] * data[i-4];
  85298. sum += qlp_coeff[2] * data[i-3];
  85299. sum += qlp_coeff[1] * data[i-2];
  85300. sum += qlp_coeff[0] * data[i-1];
  85301. residual[i] = data[i] - (sum >> lp_quantization);
  85302. }
  85303. }
  85304. else { /* order == 7 */
  85305. for(i = 0; i < (int)data_len; i++) {
  85306. sum = 0;
  85307. sum += qlp_coeff[6] * data[i-7];
  85308. sum += qlp_coeff[5] * data[i-6];
  85309. sum += qlp_coeff[4] * data[i-5];
  85310. sum += qlp_coeff[3] * data[i-4];
  85311. sum += qlp_coeff[2] * data[i-3];
  85312. sum += qlp_coeff[1] * data[i-2];
  85313. sum += qlp_coeff[0] * data[i-1];
  85314. residual[i] = data[i] - (sum >> lp_quantization);
  85315. }
  85316. }
  85317. }
  85318. else {
  85319. if(order == 6) {
  85320. for(i = 0; i < (int)data_len; i++) {
  85321. sum = 0;
  85322. sum += qlp_coeff[5] * data[i-6];
  85323. sum += qlp_coeff[4] * data[i-5];
  85324. sum += qlp_coeff[3] * data[i-4];
  85325. sum += qlp_coeff[2] * data[i-3];
  85326. sum += qlp_coeff[1] * data[i-2];
  85327. sum += qlp_coeff[0] * data[i-1];
  85328. residual[i] = data[i] - (sum >> lp_quantization);
  85329. }
  85330. }
  85331. else { /* order == 5 */
  85332. for(i = 0; i < (int)data_len; i++) {
  85333. sum = 0;
  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. }
  85343. }
  85344. else {
  85345. if(order > 2) {
  85346. if(order == 4) {
  85347. for(i = 0; i < (int)data_len; i++) {
  85348. sum = 0;
  85349. sum += qlp_coeff[3] * data[i-4];
  85350. sum += qlp_coeff[2] * data[i-3];
  85351. sum += qlp_coeff[1] * data[i-2];
  85352. sum += qlp_coeff[0] * data[i-1];
  85353. residual[i] = data[i] - (sum >> lp_quantization);
  85354. }
  85355. }
  85356. else { /* order == 3 */
  85357. for(i = 0; i < (int)data_len; i++) {
  85358. sum = 0;
  85359. sum += qlp_coeff[2] * data[i-3];
  85360. sum += qlp_coeff[1] * data[i-2];
  85361. sum += qlp_coeff[0] * data[i-1];
  85362. residual[i] = data[i] - (sum >> lp_quantization);
  85363. }
  85364. }
  85365. }
  85366. else {
  85367. if(order == 2) {
  85368. for(i = 0; i < (int)data_len; i++) {
  85369. sum = 0;
  85370. sum += qlp_coeff[1] * data[i-2];
  85371. sum += qlp_coeff[0] * data[i-1];
  85372. residual[i] = data[i] - (sum >> lp_quantization);
  85373. }
  85374. }
  85375. else { /* order == 1 */
  85376. for(i = 0; i < (int)data_len; i++)
  85377. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85378. }
  85379. }
  85380. }
  85381. }
  85382. else { /* order > 12 */
  85383. for(i = 0; i < (int)data_len; i++) {
  85384. sum = 0;
  85385. switch(order) {
  85386. case 32: sum += qlp_coeff[31] * data[i-32];
  85387. case 31: sum += qlp_coeff[30] * data[i-31];
  85388. case 30: sum += qlp_coeff[29] * data[i-30];
  85389. case 29: sum += qlp_coeff[28] * data[i-29];
  85390. case 28: sum += qlp_coeff[27] * data[i-28];
  85391. case 27: sum += qlp_coeff[26] * data[i-27];
  85392. case 26: sum += qlp_coeff[25] * data[i-26];
  85393. case 25: sum += qlp_coeff[24] * data[i-25];
  85394. case 24: sum += qlp_coeff[23] * data[i-24];
  85395. case 23: sum += qlp_coeff[22] * data[i-23];
  85396. case 22: sum += qlp_coeff[21] * data[i-22];
  85397. case 21: sum += qlp_coeff[20] * data[i-21];
  85398. case 20: sum += qlp_coeff[19] * data[i-20];
  85399. case 19: sum += qlp_coeff[18] * data[i-19];
  85400. case 18: sum += qlp_coeff[17] * data[i-18];
  85401. case 17: sum += qlp_coeff[16] * data[i-17];
  85402. case 16: sum += qlp_coeff[15] * data[i-16];
  85403. case 15: sum += qlp_coeff[14] * data[i-15];
  85404. case 14: sum += qlp_coeff[13] * data[i-14];
  85405. case 13: sum += qlp_coeff[12] * data[i-13];
  85406. sum += qlp_coeff[11] * data[i-12];
  85407. sum += qlp_coeff[10] * data[i-11];
  85408. sum += qlp_coeff[ 9] * data[i-10];
  85409. sum += qlp_coeff[ 8] * data[i- 9];
  85410. sum += qlp_coeff[ 7] * data[i- 8];
  85411. sum += qlp_coeff[ 6] * data[i- 7];
  85412. sum += qlp_coeff[ 5] * data[i- 6];
  85413. sum += qlp_coeff[ 4] * data[i- 5];
  85414. sum += qlp_coeff[ 3] * data[i- 4];
  85415. sum += qlp_coeff[ 2] * data[i- 3];
  85416. sum += qlp_coeff[ 1] * data[i- 2];
  85417. sum += qlp_coeff[ 0] * data[i- 1];
  85418. }
  85419. residual[i] = data[i] - (sum >> lp_quantization);
  85420. }
  85421. }
  85422. }
  85423. #endif
  85424. 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[])
  85425. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85426. {
  85427. unsigned i, j;
  85428. FLAC__int64 sum;
  85429. const FLAC__int32 *history;
  85430. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85431. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85432. for(i=0;i<order;i++)
  85433. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85434. fprintf(stderr,"\n");
  85435. #endif
  85436. FLAC__ASSERT(order > 0);
  85437. for(i = 0; i < data_len; i++) {
  85438. sum = 0;
  85439. history = data;
  85440. for(j = 0; j < order; j++)
  85441. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85442. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85443. #if defined _MSC_VER
  85444. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85445. #else
  85446. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85447. #endif
  85448. break;
  85449. }
  85450. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85451. #if defined _MSC_VER
  85452. 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));
  85453. #else
  85454. 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)));
  85455. #endif
  85456. break;
  85457. }
  85458. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85459. }
  85460. }
  85461. #else /* fully unrolled version for normal use */
  85462. {
  85463. int i;
  85464. FLAC__int64 sum;
  85465. FLAC__ASSERT(order > 0);
  85466. FLAC__ASSERT(order <= 32);
  85467. if(order <= 12) {
  85468. if(order > 8) {
  85469. if(order > 10) {
  85470. if(order == 12) {
  85471. for(i = 0; i < (int)data_len; i++) {
  85472. sum = 0;
  85473. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85474. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85475. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85476. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85477. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85478. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85479. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85480. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85481. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85482. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85483. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85484. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85485. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85486. }
  85487. }
  85488. else { /* order == 11 */
  85489. for(i = 0; i < (int)data_len; i++) {
  85490. sum = 0;
  85491. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85492. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85493. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85494. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85495. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85496. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85497. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85498. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85499. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85500. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85501. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85502. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85503. }
  85504. }
  85505. }
  85506. else {
  85507. if(order == 10) {
  85508. for(i = 0; i < (int)data_len; i++) {
  85509. sum = 0;
  85510. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85511. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85512. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85513. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85514. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85515. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85516. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85517. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85518. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85519. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85520. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85521. }
  85522. }
  85523. else { /* order == 9 */
  85524. for(i = 0; i < (int)data_len; i++) {
  85525. sum = 0;
  85526. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85527. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85528. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85529. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85530. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85531. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85532. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85533. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85534. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85535. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85536. }
  85537. }
  85538. }
  85539. }
  85540. else if(order > 4) {
  85541. if(order > 6) {
  85542. if(order == 8) {
  85543. for(i = 0; i < (int)data_len; i++) {
  85544. sum = 0;
  85545. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85546. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85547. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85548. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85549. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85550. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85551. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85552. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85553. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85554. }
  85555. }
  85556. else { /* order == 7 */
  85557. for(i = 0; i < (int)data_len; i++) {
  85558. sum = 0;
  85559. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85560. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85561. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85562. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85563. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85564. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85565. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85566. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85567. }
  85568. }
  85569. }
  85570. else {
  85571. if(order == 6) {
  85572. for(i = 0; i < (int)data_len; i++) {
  85573. sum = 0;
  85574. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85575. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85576. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85577. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85578. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85579. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85580. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85581. }
  85582. }
  85583. else { /* order == 5 */
  85584. for(i = 0; i < (int)data_len; i++) {
  85585. sum = 0;
  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. }
  85595. }
  85596. else {
  85597. if(order > 2) {
  85598. if(order == 4) {
  85599. for(i = 0; i < (int)data_len; i++) {
  85600. sum = 0;
  85601. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85602. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85603. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85604. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85605. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85606. }
  85607. }
  85608. else { /* order == 3 */
  85609. for(i = 0; i < (int)data_len; i++) {
  85610. sum = 0;
  85611. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85612. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85613. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85614. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85615. }
  85616. }
  85617. }
  85618. else {
  85619. if(order == 2) {
  85620. for(i = 0; i < (int)data_len; i++) {
  85621. sum = 0;
  85622. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85623. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85624. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85625. }
  85626. }
  85627. else { /* order == 1 */
  85628. for(i = 0; i < (int)data_len; i++)
  85629. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85630. }
  85631. }
  85632. }
  85633. }
  85634. else { /* order > 12 */
  85635. for(i = 0; i < (int)data_len; i++) {
  85636. sum = 0;
  85637. switch(order) {
  85638. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85639. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85640. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85641. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85642. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85643. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85644. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85645. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85646. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85647. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85648. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85649. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85650. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85651. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85652. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85653. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85654. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85655. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85656. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85657. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85658. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85659. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85660. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85661. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85662. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85663. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85664. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85665. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85666. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85667. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85668. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85669. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85670. }
  85671. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85672. }
  85673. }
  85674. }
  85675. #endif
  85676. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85677. 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[])
  85678. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85679. {
  85680. FLAC__int64 sumo;
  85681. unsigned i, j;
  85682. FLAC__int32 sum;
  85683. const FLAC__int32 *r = residual, *history;
  85684. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85685. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85686. for(i=0;i<order;i++)
  85687. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85688. fprintf(stderr,"\n");
  85689. #endif
  85690. FLAC__ASSERT(order > 0);
  85691. for(i = 0; i < data_len; i++) {
  85692. sumo = 0;
  85693. sum = 0;
  85694. history = data;
  85695. for(j = 0; j < order; j++) {
  85696. sum += qlp_coeff[j] * (*(--history));
  85697. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85698. #if defined _MSC_VER
  85699. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85700. 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);
  85701. #else
  85702. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85703. 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);
  85704. #endif
  85705. }
  85706. *(data++) = *(r++) + (sum >> lp_quantization);
  85707. }
  85708. }
  85709. #else /* fully unrolled version for normal use */
  85710. {
  85711. int i;
  85712. FLAC__int32 sum;
  85713. FLAC__ASSERT(order > 0);
  85714. FLAC__ASSERT(order <= 32);
  85715. if(order <= 12) {
  85716. if(order > 8) {
  85717. if(order > 10) {
  85718. if(order == 12) {
  85719. for(i = 0; i < (int)data_len; i++) {
  85720. sum = 0;
  85721. sum += qlp_coeff[11] * data[i-12];
  85722. sum += qlp_coeff[10] * data[i-11];
  85723. sum += qlp_coeff[9] * data[i-10];
  85724. sum += qlp_coeff[8] * data[i-9];
  85725. sum += qlp_coeff[7] * data[i-8];
  85726. sum += qlp_coeff[6] * data[i-7];
  85727. sum += qlp_coeff[5] * data[i-6];
  85728. sum += qlp_coeff[4] * data[i-5];
  85729. sum += qlp_coeff[3] * data[i-4];
  85730. sum += qlp_coeff[2] * data[i-3];
  85731. sum += qlp_coeff[1] * data[i-2];
  85732. sum += qlp_coeff[0] * data[i-1];
  85733. data[i] = residual[i] + (sum >> lp_quantization);
  85734. }
  85735. }
  85736. else { /* order == 11 */
  85737. for(i = 0; i < (int)data_len; i++) {
  85738. sum = 0;
  85739. sum += qlp_coeff[10] * data[i-11];
  85740. sum += qlp_coeff[9] * data[i-10];
  85741. sum += qlp_coeff[8] * data[i-9];
  85742. sum += qlp_coeff[7] * data[i-8];
  85743. sum += qlp_coeff[6] * data[i-7];
  85744. sum += qlp_coeff[5] * data[i-6];
  85745. sum += qlp_coeff[4] * data[i-5];
  85746. sum += qlp_coeff[3] * data[i-4];
  85747. sum += qlp_coeff[2] * data[i-3];
  85748. sum += qlp_coeff[1] * data[i-2];
  85749. sum += qlp_coeff[0] * data[i-1];
  85750. data[i] = residual[i] + (sum >> lp_quantization);
  85751. }
  85752. }
  85753. }
  85754. else {
  85755. if(order == 10) {
  85756. for(i = 0; i < (int)data_len; i++) {
  85757. sum = 0;
  85758. sum += qlp_coeff[9] * data[i-10];
  85759. sum += qlp_coeff[8] * data[i-9];
  85760. sum += qlp_coeff[7] * data[i-8];
  85761. sum += qlp_coeff[6] * data[i-7];
  85762. sum += qlp_coeff[5] * data[i-6];
  85763. sum += qlp_coeff[4] * data[i-5];
  85764. sum += qlp_coeff[3] * data[i-4];
  85765. sum += qlp_coeff[2] * data[i-3];
  85766. sum += qlp_coeff[1] * data[i-2];
  85767. sum += qlp_coeff[0] * data[i-1];
  85768. data[i] = residual[i] + (sum >> lp_quantization);
  85769. }
  85770. }
  85771. else { /* order == 9 */
  85772. for(i = 0; i < (int)data_len; i++) {
  85773. sum = 0;
  85774. sum += qlp_coeff[8] * data[i-9];
  85775. sum += qlp_coeff[7] * data[i-8];
  85776. sum += qlp_coeff[6] * data[i-7];
  85777. sum += qlp_coeff[5] * data[i-6];
  85778. sum += qlp_coeff[4] * data[i-5];
  85779. sum += qlp_coeff[3] * data[i-4];
  85780. sum += qlp_coeff[2] * data[i-3];
  85781. sum += qlp_coeff[1] * data[i-2];
  85782. sum += qlp_coeff[0] * data[i-1];
  85783. data[i] = residual[i] + (sum >> lp_quantization);
  85784. }
  85785. }
  85786. }
  85787. }
  85788. else if(order > 4) {
  85789. if(order > 6) {
  85790. if(order == 8) {
  85791. for(i = 0; i < (int)data_len; i++) {
  85792. sum = 0;
  85793. sum += qlp_coeff[7] * data[i-8];
  85794. sum += qlp_coeff[6] * data[i-7];
  85795. sum += qlp_coeff[5] * data[i-6];
  85796. sum += qlp_coeff[4] * data[i-5];
  85797. sum += qlp_coeff[3] * data[i-4];
  85798. sum += qlp_coeff[2] * data[i-3];
  85799. sum += qlp_coeff[1] * data[i-2];
  85800. sum += qlp_coeff[0] * data[i-1];
  85801. data[i] = residual[i] + (sum >> lp_quantization);
  85802. }
  85803. }
  85804. else { /* order == 7 */
  85805. for(i = 0; i < (int)data_len; i++) {
  85806. sum = 0;
  85807. sum += qlp_coeff[6] * data[i-7];
  85808. sum += qlp_coeff[5] * data[i-6];
  85809. sum += qlp_coeff[4] * data[i-5];
  85810. sum += qlp_coeff[3] * data[i-4];
  85811. sum += qlp_coeff[2] * data[i-3];
  85812. sum += qlp_coeff[1] * data[i-2];
  85813. sum += qlp_coeff[0] * data[i-1];
  85814. data[i] = residual[i] + (sum >> lp_quantization);
  85815. }
  85816. }
  85817. }
  85818. else {
  85819. if(order == 6) {
  85820. for(i = 0; i < (int)data_len; i++) {
  85821. sum = 0;
  85822. sum += qlp_coeff[5] * data[i-6];
  85823. sum += qlp_coeff[4] * data[i-5];
  85824. sum += qlp_coeff[3] * data[i-4];
  85825. sum += qlp_coeff[2] * data[i-3];
  85826. sum += qlp_coeff[1] * data[i-2];
  85827. sum += qlp_coeff[0] * data[i-1];
  85828. data[i] = residual[i] + (sum >> lp_quantization);
  85829. }
  85830. }
  85831. else { /* order == 5 */
  85832. for(i = 0; i < (int)data_len; i++) {
  85833. sum = 0;
  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. }
  85843. }
  85844. else {
  85845. if(order > 2) {
  85846. if(order == 4) {
  85847. for(i = 0; i < (int)data_len; i++) {
  85848. sum = 0;
  85849. sum += qlp_coeff[3] * data[i-4];
  85850. sum += qlp_coeff[2] * data[i-3];
  85851. sum += qlp_coeff[1] * data[i-2];
  85852. sum += qlp_coeff[0] * data[i-1];
  85853. data[i] = residual[i] + (sum >> lp_quantization);
  85854. }
  85855. }
  85856. else { /* order == 3 */
  85857. for(i = 0; i < (int)data_len; i++) {
  85858. sum = 0;
  85859. sum += qlp_coeff[2] * data[i-3];
  85860. sum += qlp_coeff[1] * data[i-2];
  85861. sum += qlp_coeff[0] * data[i-1];
  85862. data[i] = residual[i] + (sum >> lp_quantization);
  85863. }
  85864. }
  85865. }
  85866. else {
  85867. if(order == 2) {
  85868. for(i = 0; i < (int)data_len; i++) {
  85869. sum = 0;
  85870. sum += qlp_coeff[1] * data[i-2];
  85871. sum += qlp_coeff[0] * data[i-1];
  85872. data[i] = residual[i] + (sum >> lp_quantization);
  85873. }
  85874. }
  85875. else { /* order == 1 */
  85876. for(i = 0; i < (int)data_len; i++)
  85877. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85878. }
  85879. }
  85880. }
  85881. }
  85882. else { /* order > 12 */
  85883. for(i = 0; i < (int)data_len; i++) {
  85884. sum = 0;
  85885. switch(order) {
  85886. case 32: sum += qlp_coeff[31] * data[i-32];
  85887. case 31: sum += qlp_coeff[30] * data[i-31];
  85888. case 30: sum += qlp_coeff[29] * data[i-30];
  85889. case 29: sum += qlp_coeff[28] * data[i-29];
  85890. case 28: sum += qlp_coeff[27] * data[i-28];
  85891. case 27: sum += qlp_coeff[26] * data[i-27];
  85892. case 26: sum += qlp_coeff[25] * data[i-26];
  85893. case 25: sum += qlp_coeff[24] * data[i-25];
  85894. case 24: sum += qlp_coeff[23] * data[i-24];
  85895. case 23: sum += qlp_coeff[22] * data[i-23];
  85896. case 22: sum += qlp_coeff[21] * data[i-22];
  85897. case 21: sum += qlp_coeff[20] * data[i-21];
  85898. case 20: sum += qlp_coeff[19] * data[i-20];
  85899. case 19: sum += qlp_coeff[18] * data[i-19];
  85900. case 18: sum += qlp_coeff[17] * data[i-18];
  85901. case 17: sum += qlp_coeff[16] * data[i-17];
  85902. case 16: sum += qlp_coeff[15] * data[i-16];
  85903. case 15: sum += qlp_coeff[14] * data[i-15];
  85904. case 14: sum += qlp_coeff[13] * data[i-14];
  85905. case 13: sum += qlp_coeff[12] * data[i-13];
  85906. sum += qlp_coeff[11] * data[i-12];
  85907. sum += qlp_coeff[10] * data[i-11];
  85908. sum += qlp_coeff[ 9] * data[i-10];
  85909. sum += qlp_coeff[ 8] * data[i- 9];
  85910. sum += qlp_coeff[ 7] * data[i- 8];
  85911. sum += qlp_coeff[ 6] * data[i- 7];
  85912. sum += qlp_coeff[ 5] * data[i- 6];
  85913. sum += qlp_coeff[ 4] * data[i- 5];
  85914. sum += qlp_coeff[ 3] * data[i- 4];
  85915. sum += qlp_coeff[ 2] * data[i- 3];
  85916. sum += qlp_coeff[ 1] * data[i- 2];
  85917. sum += qlp_coeff[ 0] * data[i- 1];
  85918. }
  85919. data[i] = residual[i] + (sum >> lp_quantization);
  85920. }
  85921. }
  85922. }
  85923. #endif
  85924. 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[])
  85925. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85926. {
  85927. unsigned i, j;
  85928. FLAC__int64 sum;
  85929. const FLAC__int32 *r = residual, *history;
  85930. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85931. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85932. for(i=0;i<order;i++)
  85933. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85934. fprintf(stderr,"\n");
  85935. #endif
  85936. FLAC__ASSERT(order > 0);
  85937. for(i = 0; i < data_len; i++) {
  85938. sum = 0;
  85939. history = data;
  85940. for(j = 0; j < order; j++)
  85941. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85942. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85943. #ifdef _MSC_VER
  85944. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85945. #else
  85946. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85947. #endif
  85948. break;
  85949. }
  85950. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  85951. #ifdef _MSC_VER
  85952. 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));
  85953. #else
  85954. 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)));
  85955. #endif
  85956. break;
  85957. }
  85958. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  85959. }
  85960. }
  85961. #else /* fully unrolled version for normal use */
  85962. {
  85963. int i;
  85964. FLAC__int64 sum;
  85965. FLAC__ASSERT(order > 0);
  85966. FLAC__ASSERT(order <= 32);
  85967. if(order <= 12) {
  85968. if(order > 8) {
  85969. if(order > 10) {
  85970. if(order == 12) {
  85971. for(i = 0; i < (int)data_len; i++) {
  85972. sum = 0;
  85973. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85974. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85975. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85976. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85977. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85978. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85979. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85980. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85981. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85982. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85983. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85984. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85985. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85986. }
  85987. }
  85988. else { /* order == 11 */
  85989. for(i = 0; i < (int)data_len; i++) {
  85990. sum = 0;
  85991. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85992. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85993. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85994. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85995. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85996. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85997. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85998. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85999. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86000. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86001. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86002. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86003. }
  86004. }
  86005. }
  86006. else {
  86007. if(order == 10) {
  86008. for(i = 0; i < (int)data_len; i++) {
  86009. sum = 0;
  86010. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86011. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86012. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86013. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86014. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86015. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86016. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86017. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86018. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86019. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86020. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86021. }
  86022. }
  86023. else { /* order == 9 */
  86024. for(i = 0; i < (int)data_len; i++) {
  86025. sum = 0;
  86026. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86027. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86028. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86029. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86030. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86031. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86032. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86033. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86034. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86035. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86036. }
  86037. }
  86038. }
  86039. }
  86040. else if(order > 4) {
  86041. if(order > 6) {
  86042. if(order == 8) {
  86043. for(i = 0; i < (int)data_len; i++) {
  86044. sum = 0;
  86045. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86046. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86047. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86048. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86049. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86050. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86051. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86052. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86053. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86054. }
  86055. }
  86056. else { /* order == 7 */
  86057. for(i = 0; i < (int)data_len; i++) {
  86058. sum = 0;
  86059. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86060. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86061. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86062. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86063. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86064. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86065. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86066. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86067. }
  86068. }
  86069. }
  86070. else {
  86071. if(order == 6) {
  86072. for(i = 0; i < (int)data_len; i++) {
  86073. sum = 0;
  86074. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86075. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86076. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86077. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86078. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86079. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86080. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86081. }
  86082. }
  86083. else { /* order == 5 */
  86084. for(i = 0; i < (int)data_len; i++) {
  86085. sum = 0;
  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. }
  86095. }
  86096. else {
  86097. if(order > 2) {
  86098. if(order == 4) {
  86099. for(i = 0; i < (int)data_len; i++) {
  86100. sum = 0;
  86101. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86102. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86103. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86104. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86105. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86106. }
  86107. }
  86108. else { /* order == 3 */
  86109. for(i = 0; i < (int)data_len; i++) {
  86110. sum = 0;
  86111. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86112. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86113. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86114. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86115. }
  86116. }
  86117. }
  86118. else {
  86119. if(order == 2) {
  86120. for(i = 0; i < (int)data_len; i++) {
  86121. sum = 0;
  86122. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86123. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86124. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86125. }
  86126. }
  86127. else { /* order == 1 */
  86128. for(i = 0; i < (int)data_len; i++)
  86129. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86130. }
  86131. }
  86132. }
  86133. }
  86134. else { /* order > 12 */
  86135. for(i = 0; i < (int)data_len; i++) {
  86136. sum = 0;
  86137. switch(order) {
  86138. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86139. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86140. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86141. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86142. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86143. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86144. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86145. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86146. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86147. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86148. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86149. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86150. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86151. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86152. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86153. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86154. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86155. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86156. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86157. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86158. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86159. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86160. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86161. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86162. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86163. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86164. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86165. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86166. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86167. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86168. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86169. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86170. }
  86171. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86172. }
  86173. }
  86174. }
  86175. #endif
  86176. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86177. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86178. {
  86179. FLAC__double error_scale;
  86180. FLAC__ASSERT(total_samples > 0);
  86181. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86182. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86183. }
  86184. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86185. {
  86186. if(lpc_error > 0.0) {
  86187. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86188. if(bps >= 0.0)
  86189. return bps;
  86190. else
  86191. return 0.0;
  86192. }
  86193. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86194. return 1e32;
  86195. }
  86196. else {
  86197. return 0.0;
  86198. }
  86199. }
  86200. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86201. {
  86202. 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 */
  86203. FLAC__double bits, best_bits, error_scale;
  86204. FLAC__ASSERT(max_order > 0);
  86205. FLAC__ASSERT(total_samples > 0);
  86206. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86207. best_index = 0;
  86208. best_bits = (unsigned)(-1);
  86209. for(index = 0, order = 1; index < max_order; index++, order++) {
  86210. 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);
  86211. if(bits < best_bits) {
  86212. best_index = index;
  86213. best_bits = bits;
  86214. }
  86215. }
  86216. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86217. }
  86218. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86219. #endif
  86220. /*** End of inlined file: lpc_flac.c ***/
  86221. /*** Start of inlined file: md5.c ***/
  86222. /*** Start of inlined file: juce_FlacHeader.h ***/
  86223. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86224. // tasks..
  86225. #define VERSION "1.2.1"
  86226. #define FLAC__NO_DLL 1
  86227. #if JUCE_MSVC
  86228. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86229. #endif
  86230. #if JUCE_MAC
  86231. #define FLAC__SYS_DARWIN 1
  86232. #endif
  86233. /*** End of inlined file: juce_FlacHeader.h ***/
  86234. #if JUCE_USE_FLAC
  86235. #if HAVE_CONFIG_H
  86236. # include <config.h>
  86237. #endif
  86238. #include <stdlib.h> /* for malloc() */
  86239. #include <string.h> /* for memcpy() */
  86240. /*** Start of inlined file: md5.h ***/
  86241. #ifndef FLAC__PRIVATE__MD5_H
  86242. #define FLAC__PRIVATE__MD5_H
  86243. typedef struct {
  86244. FLAC__uint32 in[16];
  86245. FLAC__uint32 buf[4];
  86246. FLAC__uint32 bytes[2];
  86247. FLAC__byte *internal_buf;
  86248. size_t capacity;
  86249. } FLAC__MD5Context;
  86250. void FLAC__MD5Init(FLAC__MD5Context *context);
  86251. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86252. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86253. #endif
  86254. /*** End of inlined file: md5.h ***/
  86255. #ifndef FLaC__INLINE
  86256. #define FLaC__INLINE
  86257. #endif
  86258. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86259. #define F2(x, y, z) F1(z, x, y)
  86260. #define F3(x, y, z) (x ^ y ^ z)
  86261. #define F4(x, y, z) (y ^ (x | ~z))
  86262. #define MD5STEP(f,w,x,y,z,in,s) \
  86263. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86264. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86265. {
  86266. register FLAC__uint32 a, b, c, d;
  86267. a = buf[0];
  86268. b = buf[1];
  86269. c = buf[2];
  86270. d = buf[3];
  86271. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86272. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86273. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86274. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86275. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86276. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86277. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86278. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86279. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86280. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86281. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86282. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86283. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86284. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86285. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86286. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86287. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86288. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86289. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86290. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86291. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86292. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86293. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86294. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86295. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86296. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86297. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86298. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86299. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86300. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86301. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86302. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86303. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86304. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86305. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86306. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86307. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86308. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86309. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86310. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86311. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86312. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86313. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86314. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86315. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86316. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86317. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86318. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86319. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86320. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86321. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86322. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86323. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86324. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86325. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86326. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86327. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86328. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86329. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86330. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86331. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86332. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86333. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86334. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86335. buf[0] += a;
  86336. buf[1] += b;
  86337. buf[2] += c;
  86338. buf[3] += d;
  86339. }
  86340. #if WORDS_BIGENDIAN
  86341. //@@@@@@ OPT: use bswap/intrinsics
  86342. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86343. {
  86344. register FLAC__uint32 x;
  86345. do {
  86346. x = *buf;
  86347. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86348. *buf++ = (x >> 16) | (x << 16);
  86349. } while (--words);
  86350. }
  86351. static void byteSwapX16(FLAC__uint32 *buf)
  86352. {
  86353. register FLAC__uint32 x;
  86354. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86355. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86356. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86357. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86358. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86359. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86360. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86361. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86362. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86363. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86364. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  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. }
  86371. #else
  86372. #define byteSwap(buf, words)
  86373. #define byteSwapX16(buf)
  86374. #endif
  86375. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86376. {
  86377. FLAC__uint32 t;
  86378. t = ctx->bytes[0];
  86379. if ((ctx->bytes[0] = t + len) < t)
  86380. ctx->bytes[1]++; /* Carry from low to high */
  86381. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86382. if (t > len) {
  86383. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86384. return;
  86385. }
  86386. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86387. byteSwapX16(ctx->in);
  86388. FLAC__MD5Transform(ctx->buf, ctx->in);
  86389. buf += t;
  86390. len -= t;
  86391. while (len >= 64) {
  86392. memcpy(ctx->in, buf, 64);
  86393. byteSwapX16(ctx->in);
  86394. FLAC__MD5Transform(ctx->buf, ctx->in);
  86395. buf += 64;
  86396. len -= 64;
  86397. }
  86398. memcpy(ctx->in, buf, len);
  86399. }
  86400. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86401. {
  86402. ctx->buf[0] = 0x67452301;
  86403. ctx->buf[1] = 0xefcdab89;
  86404. ctx->buf[2] = 0x98badcfe;
  86405. ctx->buf[3] = 0x10325476;
  86406. ctx->bytes[0] = 0;
  86407. ctx->bytes[1] = 0;
  86408. ctx->internal_buf = 0;
  86409. ctx->capacity = 0;
  86410. }
  86411. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86412. {
  86413. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86414. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86415. *p++ = 0x80;
  86416. count = 56 - 1 - count;
  86417. if (count < 0) { /* Padding forces an extra block */
  86418. memset(p, 0, count + 8);
  86419. byteSwapX16(ctx->in);
  86420. FLAC__MD5Transform(ctx->buf, ctx->in);
  86421. p = (FLAC__byte *)ctx->in;
  86422. count = 56;
  86423. }
  86424. memset(p, 0, count);
  86425. byteSwap(ctx->in, 14);
  86426. ctx->in[14] = ctx->bytes[0] << 3;
  86427. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86428. FLAC__MD5Transform(ctx->buf, ctx->in);
  86429. byteSwap(ctx->buf, 4);
  86430. memcpy(digest, ctx->buf, 16);
  86431. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86432. if(0 != ctx->internal_buf) {
  86433. free(ctx->internal_buf);
  86434. ctx->internal_buf = 0;
  86435. ctx->capacity = 0;
  86436. }
  86437. }
  86438. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86439. {
  86440. unsigned channel, sample;
  86441. register FLAC__int32 a_word;
  86442. register FLAC__byte *buf_ = buf;
  86443. #if WORDS_BIGENDIAN
  86444. #else
  86445. if(channels == 2 && bytes_per_sample == 2) {
  86446. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86447. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86448. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86449. *buf1_ = (FLAC__int16)signal[1][sample];
  86450. }
  86451. else if(channels == 1 && bytes_per_sample == 2) {
  86452. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86453. for(sample = 0; sample < samples; sample++)
  86454. *buf1_++ = (FLAC__int16)signal[0][sample];
  86455. }
  86456. else
  86457. #endif
  86458. if(bytes_per_sample == 2) {
  86459. if(channels == 2) {
  86460. for(sample = 0; sample < samples; sample++) {
  86461. a_word = signal[0][sample];
  86462. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86463. *buf_++ = (FLAC__byte)a_word;
  86464. a_word = signal[1][sample];
  86465. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86466. *buf_++ = (FLAC__byte)a_word;
  86467. }
  86468. }
  86469. else if(channels == 1) {
  86470. for(sample = 0; sample < samples; sample++) {
  86471. a_word = signal[0][sample];
  86472. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86473. *buf_++ = (FLAC__byte)a_word;
  86474. }
  86475. }
  86476. else {
  86477. for(sample = 0; sample < samples; sample++) {
  86478. for(channel = 0; channel < channels; channel++) {
  86479. a_word = signal[channel][sample];
  86480. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86481. *buf_++ = (FLAC__byte)a_word;
  86482. }
  86483. }
  86484. }
  86485. }
  86486. else if(bytes_per_sample == 3) {
  86487. if(channels == 2) {
  86488. for(sample = 0; sample < samples; sample++) {
  86489. a_word = signal[0][sample];
  86490. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86491. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86492. *buf_++ = (FLAC__byte)a_word;
  86493. a_word = signal[1][sample];
  86494. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86495. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86496. *buf_++ = (FLAC__byte)a_word;
  86497. }
  86498. }
  86499. else if(channels == 1) {
  86500. for(sample = 0; sample < samples; sample++) {
  86501. a_word = signal[0][sample];
  86502. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86503. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86504. *buf_++ = (FLAC__byte)a_word;
  86505. }
  86506. }
  86507. else {
  86508. for(sample = 0; sample < samples; sample++) {
  86509. for(channel = 0; channel < channels; channel++) {
  86510. a_word = signal[channel][sample];
  86511. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86512. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86513. *buf_++ = (FLAC__byte)a_word;
  86514. }
  86515. }
  86516. }
  86517. }
  86518. else if(bytes_per_sample == 1) {
  86519. if(channels == 2) {
  86520. for(sample = 0; sample < samples; sample++) {
  86521. a_word = signal[0][sample];
  86522. *buf_++ = (FLAC__byte)a_word;
  86523. a_word = signal[1][sample];
  86524. *buf_++ = (FLAC__byte)a_word;
  86525. }
  86526. }
  86527. else if(channels == 1) {
  86528. for(sample = 0; sample < samples; sample++) {
  86529. a_word = signal[0][sample];
  86530. *buf_++ = (FLAC__byte)a_word;
  86531. }
  86532. }
  86533. else {
  86534. for(sample = 0; sample < samples; sample++) {
  86535. for(channel = 0; channel < channels; channel++) {
  86536. a_word = signal[channel][sample];
  86537. *buf_++ = (FLAC__byte)a_word;
  86538. }
  86539. }
  86540. }
  86541. }
  86542. else { /* bytes_per_sample == 4, maybe optimize more later */
  86543. for(sample = 0; sample < samples; sample++) {
  86544. for(channel = 0; channel < channels; channel++) {
  86545. a_word = signal[channel][sample];
  86546. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86547. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86548. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86549. *buf_++ = (FLAC__byte)a_word;
  86550. }
  86551. }
  86552. }
  86553. }
  86554. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86555. {
  86556. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86557. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86558. return false;
  86559. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86560. return false;
  86561. if(ctx->capacity < bytes_needed) {
  86562. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86563. if(0 == tmp) {
  86564. free(ctx->internal_buf);
  86565. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86566. return false;
  86567. }
  86568. ctx->internal_buf = tmp;
  86569. ctx->capacity = bytes_needed;
  86570. }
  86571. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86572. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86573. return true;
  86574. }
  86575. #endif
  86576. /*** End of inlined file: md5.c ***/
  86577. /*** Start of inlined file: memory.c ***/
  86578. /*** Start of inlined file: juce_FlacHeader.h ***/
  86579. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86580. // tasks..
  86581. #define VERSION "1.2.1"
  86582. #define FLAC__NO_DLL 1
  86583. #if JUCE_MSVC
  86584. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86585. #endif
  86586. #if JUCE_MAC
  86587. #define FLAC__SYS_DARWIN 1
  86588. #endif
  86589. /*** End of inlined file: juce_FlacHeader.h ***/
  86590. #if JUCE_USE_FLAC
  86591. #if HAVE_CONFIG_H
  86592. # include <config.h>
  86593. #endif
  86594. /*** Start of inlined file: memory.h ***/
  86595. #ifndef FLAC__PRIVATE__MEMORY_H
  86596. #define FLAC__PRIVATE__MEMORY_H
  86597. #ifdef HAVE_CONFIG_H
  86598. #include <config.h>
  86599. #endif
  86600. #include <stdlib.h> /* for size_t */
  86601. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86602. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86603. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86604. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86605. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86606. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86607. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86608. #endif
  86609. #endif
  86610. /*** End of inlined file: memory.h ***/
  86611. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86612. {
  86613. void *x;
  86614. FLAC__ASSERT(0 != aligned_address);
  86615. #ifdef FLAC__ALIGN_MALLOC_DATA
  86616. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86617. #ifdef SIZEOF_VOIDP
  86618. #if SIZEOF_VOIDP == 4
  86619. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86620. #elif SIZEOF_VOIDP == 8
  86621. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86622. #else
  86623. # error Unsupported sizeof(void*)
  86624. #endif
  86625. #else
  86626. if(sizeof(void*) == sizeof(unsigned))
  86627. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86628. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86629. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86630. else
  86631. return 0;
  86632. #endif
  86633. #else
  86634. x = safe_malloc_(bytes);
  86635. *aligned_address = x;
  86636. #endif
  86637. return x;
  86638. }
  86639. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86640. {
  86641. FLAC__int32 *pu; /* unaligned pointer */
  86642. union { /* union needed to comply with C99 pointer aliasing rules */
  86643. FLAC__int32 *pa; /* aligned pointer */
  86644. void *pv; /* aligned pointer alias */
  86645. } u;
  86646. FLAC__ASSERT(elements > 0);
  86647. FLAC__ASSERT(0 != unaligned_pointer);
  86648. FLAC__ASSERT(0 != aligned_pointer);
  86649. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86650. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86651. if(0 == pu) {
  86652. return false;
  86653. }
  86654. else {
  86655. if(*unaligned_pointer != 0)
  86656. free(*unaligned_pointer);
  86657. *unaligned_pointer = pu;
  86658. *aligned_pointer = u.pa;
  86659. return true;
  86660. }
  86661. }
  86662. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86663. {
  86664. FLAC__uint32 *pu; /* unaligned pointer */
  86665. union { /* union needed to comply with C99 pointer aliasing rules */
  86666. FLAC__uint32 *pa; /* aligned pointer */
  86667. void *pv; /* aligned pointer alias */
  86668. } u;
  86669. FLAC__ASSERT(elements > 0);
  86670. FLAC__ASSERT(0 != unaligned_pointer);
  86671. FLAC__ASSERT(0 != aligned_pointer);
  86672. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86673. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86674. if(0 == pu) {
  86675. return false;
  86676. }
  86677. else {
  86678. if(*unaligned_pointer != 0)
  86679. free(*unaligned_pointer);
  86680. *unaligned_pointer = pu;
  86681. *aligned_pointer = u.pa;
  86682. return true;
  86683. }
  86684. }
  86685. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86686. {
  86687. FLAC__uint64 *pu; /* unaligned pointer */
  86688. union { /* union needed to comply with C99 pointer aliasing rules */
  86689. FLAC__uint64 *pa; /* aligned pointer */
  86690. void *pv; /* aligned pointer alias */
  86691. } u;
  86692. FLAC__ASSERT(elements > 0);
  86693. FLAC__ASSERT(0 != unaligned_pointer);
  86694. FLAC__ASSERT(0 != aligned_pointer);
  86695. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86696. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86697. if(0 == pu) {
  86698. return false;
  86699. }
  86700. else {
  86701. if(*unaligned_pointer != 0)
  86702. free(*unaligned_pointer);
  86703. *unaligned_pointer = pu;
  86704. *aligned_pointer = u.pa;
  86705. return true;
  86706. }
  86707. }
  86708. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86709. {
  86710. unsigned *pu; /* unaligned pointer */
  86711. union { /* union needed to comply with C99 pointer aliasing rules */
  86712. unsigned *pa; /* aligned pointer */
  86713. void *pv; /* aligned pointer alias */
  86714. } u;
  86715. FLAC__ASSERT(elements > 0);
  86716. FLAC__ASSERT(0 != unaligned_pointer);
  86717. FLAC__ASSERT(0 != aligned_pointer);
  86718. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86719. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86720. if(0 == pu) {
  86721. return false;
  86722. }
  86723. else {
  86724. if(*unaligned_pointer != 0)
  86725. free(*unaligned_pointer);
  86726. *unaligned_pointer = pu;
  86727. *aligned_pointer = u.pa;
  86728. return true;
  86729. }
  86730. }
  86731. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86732. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86733. {
  86734. FLAC__real *pu; /* unaligned pointer */
  86735. union { /* union needed to comply with C99 pointer aliasing rules */
  86736. FLAC__real *pa; /* aligned pointer */
  86737. void *pv; /* aligned pointer alias */
  86738. } u;
  86739. FLAC__ASSERT(elements > 0);
  86740. FLAC__ASSERT(0 != unaligned_pointer);
  86741. FLAC__ASSERT(0 != aligned_pointer);
  86742. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86743. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86744. if(0 == pu) {
  86745. return false;
  86746. }
  86747. else {
  86748. if(*unaligned_pointer != 0)
  86749. free(*unaligned_pointer);
  86750. *unaligned_pointer = pu;
  86751. *aligned_pointer = u.pa;
  86752. return true;
  86753. }
  86754. }
  86755. #endif
  86756. #endif
  86757. /*** End of inlined file: memory.c ***/
  86758. /*** Start of inlined file: stream_decoder.c ***/
  86759. /*** Start of inlined file: juce_FlacHeader.h ***/
  86760. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86761. // tasks..
  86762. #define VERSION "1.2.1"
  86763. #define FLAC__NO_DLL 1
  86764. #if JUCE_MSVC
  86765. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86766. #endif
  86767. #if JUCE_MAC
  86768. #define FLAC__SYS_DARWIN 1
  86769. #endif
  86770. /*** End of inlined file: juce_FlacHeader.h ***/
  86771. #if JUCE_USE_FLAC
  86772. #if HAVE_CONFIG_H
  86773. # include <config.h>
  86774. #endif
  86775. #if defined _MSC_VER || defined __MINGW32__
  86776. #include <io.h> /* for _setmode() */
  86777. #include <fcntl.h> /* for _O_BINARY */
  86778. #endif
  86779. #if defined __CYGWIN__ || defined __EMX__
  86780. #include <io.h> /* for setmode(), O_BINARY */
  86781. #include <fcntl.h> /* for _O_BINARY */
  86782. #endif
  86783. #include <stdio.h>
  86784. #include <stdlib.h> /* for malloc() */
  86785. #include <string.h> /* for memset/memcpy() */
  86786. #include <sys/stat.h> /* for stat() */
  86787. #include <sys/types.h> /* for off_t */
  86788. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86789. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86790. #define fseeko fseek
  86791. #define ftello ftell
  86792. #endif
  86793. #endif
  86794. /*** Start of inlined file: stream_decoder.h ***/
  86795. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86796. #define FLAC__PROTECTED__STREAM_DECODER_H
  86797. #if FLAC__HAS_OGG
  86798. #include "include/private/ogg_decoder_aspect.h"
  86799. #endif
  86800. typedef struct FLAC__StreamDecoderProtected {
  86801. FLAC__StreamDecoderState state;
  86802. unsigned channels;
  86803. FLAC__ChannelAssignment channel_assignment;
  86804. unsigned bits_per_sample;
  86805. unsigned sample_rate; /* in Hz */
  86806. unsigned blocksize; /* in samples (per channel) */
  86807. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86808. #if FLAC__HAS_OGG
  86809. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86810. #endif
  86811. } FLAC__StreamDecoderProtected;
  86812. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86813. #endif
  86814. /*** End of inlined file: stream_decoder.h ***/
  86815. #ifdef max
  86816. #undef max
  86817. #endif
  86818. #define max(a,b) ((a)>(b)?(a):(b))
  86819. #ifdef _MSC_VER
  86820. #define FLAC__U64L(x) x
  86821. #else
  86822. #define FLAC__U64L(x) x##LLU
  86823. #endif
  86824. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86825. #if FLAC__HAS_OGG
  86826. 1
  86827. #else
  86828. 0
  86829. #endif
  86830. ;
  86831. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86832. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86833. static FILE *get_binary_stdin_(void);
  86834. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86835. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86836. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86837. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86838. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86839. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86840. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86841. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86842. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86843. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86844. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86845. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86846. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86847. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86848. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86849. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86850. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86851. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86852. 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);
  86853. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86854. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86855. #if FLAC__HAS_OGG
  86856. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86857. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86858. #endif
  86859. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86860. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86861. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86862. #if FLAC__HAS_OGG
  86863. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86864. #endif
  86865. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86866. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86867. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86868. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86869. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86870. typedef struct FLAC__StreamDecoderPrivate {
  86871. #if FLAC__HAS_OGG
  86872. FLAC__bool is_ogg;
  86873. #endif
  86874. FLAC__StreamDecoderReadCallback read_callback;
  86875. FLAC__StreamDecoderSeekCallback seek_callback;
  86876. FLAC__StreamDecoderTellCallback tell_callback;
  86877. FLAC__StreamDecoderLengthCallback length_callback;
  86878. FLAC__StreamDecoderEofCallback eof_callback;
  86879. FLAC__StreamDecoderWriteCallback write_callback;
  86880. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86881. FLAC__StreamDecoderErrorCallback error_callback;
  86882. 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[]);
  86883. 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[]);
  86884. 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[]);
  86885. 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[]);
  86886. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86887. void *client_data;
  86888. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86889. FLAC__BitReader *input;
  86890. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86891. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86892. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86893. unsigned output_capacity, output_channels;
  86894. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  86895. FLAC__uint64 samples_decoded;
  86896. FLAC__bool has_stream_info, has_seek_table;
  86897. FLAC__StreamMetadata stream_info;
  86898. FLAC__StreamMetadata seek_table;
  86899. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  86900. FLAC__byte *metadata_filter_ids;
  86901. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  86902. FLAC__Frame frame;
  86903. FLAC__bool cached; /* true if there is a byte in lookahead */
  86904. FLAC__CPUInfo cpuinfo;
  86905. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  86906. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  86907. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  86908. 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 */
  86909. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  86910. FLAC__bool is_seeking;
  86911. FLAC__MD5Context md5context;
  86912. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  86913. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  86914. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  86915. FLAC__uint64 target_sample;
  86916. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  86917. #if FLAC__HAS_OGG
  86918. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  86919. #endif
  86920. } FLAC__StreamDecoderPrivate;
  86921. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  86922. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  86923. "FLAC__STREAM_DECODER_READ_METADATA",
  86924. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  86925. "FLAC__STREAM_DECODER_READ_FRAME",
  86926. "FLAC__STREAM_DECODER_END_OF_STREAM",
  86927. "FLAC__STREAM_DECODER_OGG_ERROR",
  86928. "FLAC__STREAM_DECODER_SEEK_ERROR",
  86929. "FLAC__STREAM_DECODER_ABORTED",
  86930. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  86931. "FLAC__STREAM_DECODER_UNINITIALIZED"
  86932. };
  86933. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  86934. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  86935. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  86936. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  86937. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  86938. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  86939. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  86940. };
  86941. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  86942. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  86943. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  86944. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  86945. };
  86946. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  86947. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  86948. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  86949. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  86950. };
  86951. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  86952. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  86953. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  86954. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  86955. };
  86956. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  86957. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  86958. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  86959. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  86960. };
  86961. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  86962. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  86963. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  86964. };
  86965. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  86966. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  86967. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  86968. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  86969. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  86970. };
  86971. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  86972. {
  86973. FLAC__StreamDecoder *decoder;
  86974. unsigned i;
  86975. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  86976. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  86977. if(decoder == 0) {
  86978. return 0;
  86979. }
  86980. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  86981. if(decoder->protected_ == 0) {
  86982. free(decoder);
  86983. return 0;
  86984. }
  86985. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  86986. if(decoder->private_ == 0) {
  86987. free(decoder->protected_);
  86988. free(decoder);
  86989. return 0;
  86990. }
  86991. decoder->private_->input = FLAC__bitreader_new();
  86992. if(decoder->private_->input == 0) {
  86993. free(decoder->private_);
  86994. free(decoder->protected_);
  86995. free(decoder);
  86996. return 0;
  86997. }
  86998. decoder->private_->metadata_filter_ids_capacity = 16;
  86999. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87000. FLAC__bitreader_delete(decoder->private_->input);
  87001. free(decoder->private_);
  87002. free(decoder->protected_);
  87003. free(decoder);
  87004. return 0;
  87005. }
  87006. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87007. decoder->private_->output[i] = 0;
  87008. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87009. }
  87010. decoder->private_->output_capacity = 0;
  87011. decoder->private_->output_channels = 0;
  87012. decoder->private_->has_seek_table = false;
  87013. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87014. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87015. decoder->private_->file = 0;
  87016. set_defaults_dec(decoder);
  87017. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87018. return decoder;
  87019. }
  87020. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87021. {
  87022. unsigned i;
  87023. FLAC__ASSERT(0 != decoder);
  87024. FLAC__ASSERT(0 != decoder->protected_);
  87025. FLAC__ASSERT(0 != decoder->private_);
  87026. FLAC__ASSERT(0 != decoder->private_->input);
  87027. (void)FLAC__stream_decoder_finish(decoder);
  87028. if(0 != decoder->private_->metadata_filter_ids)
  87029. free(decoder->private_->metadata_filter_ids);
  87030. FLAC__bitreader_delete(decoder->private_->input);
  87031. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87032. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87033. free(decoder->private_);
  87034. free(decoder->protected_);
  87035. free(decoder);
  87036. }
  87037. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87038. FLAC__StreamDecoder *decoder,
  87039. FLAC__StreamDecoderReadCallback read_callback,
  87040. FLAC__StreamDecoderSeekCallback seek_callback,
  87041. FLAC__StreamDecoderTellCallback tell_callback,
  87042. FLAC__StreamDecoderLengthCallback length_callback,
  87043. FLAC__StreamDecoderEofCallback eof_callback,
  87044. FLAC__StreamDecoderWriteCallback write_callback,
  87045. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87046. FLAC__StreamDecoderErrorCallback error_callback,
  87047. void *client_data,
  87048. FLAC__bool is_ogg
  87049. )
  87050. {
  87051. FLAC__ASSERT(0 != decoder);
  87052. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87053. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87054. #if !FLAC__HAS_OGG
  87055. if(is_ogg)
  87056. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87057. #endif
  87058. if(
  87059. 0 == read_callback ||
  87060. 0 == write_callback ||
  87061. 0 == error_callback ||
  87062. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87063. )
  87064. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87065. #if FLAC__HAS_OGG
  87066. decoder->private_->is_ogg = is_ogg;
  87067. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87068. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87069. #endif
  87070. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87071. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87072. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87073. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87074. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87075. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87076. #ifndef FLAC__NO_ASM
  87077. if(decoder->private_->cpuinfo.use_asm) {
  87078. #ifdef FLAC__CPU_IA32
  87079. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87080. #ifdef FLAC__HAS_NASM
  87081. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87082. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87083. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87084. #endif
  87085. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87086. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87087. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87088. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87089. }
  87090. else {
  87091. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87092. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87093. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87094. }
  87095. #endif
  87096. #elif defined FLAC__CPU_PPC
  87097. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87098. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87099. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87100. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87101. }
  87102. #endif
  87103. }
  87104. #endif
  87105. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87106. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87107. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87108. }
  87109. decoder->private_->read_callback = read_callback;
  87110. decoder->private_->seek_callback = seek_callback;
  87111. decoder->private_->tell_callback = tell_callback;
  87112. decoder->private_->length_callback = length_callback;
  87113. decoder->private_->eof_callback = eof_callback;
  87114. decoder->private_->write_callback = write_callback;
  87115. decoder->private_->metadata_callback = metadata_callback;
  87116. decoder->private_->error_callback = error_callback;
  87117. decoder->private_->client_data = client_data;
  87118. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87119. decoder->private_->samples_decoded = 0;
  87120. decoder->private_->has_stream_info = false;
  87121. decoder->private_->cached = false;
  87122. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87123. decoder->private_->is_seeking = false;
  87124. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87125. if(!FLAC__stream_decoder_reset(decoder)) {
  87126. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87127. }
  87128. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87129. }
  87130. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87131. FLAC__StreamDecoder *decoder,
  87132. FLAC__StreamDecoderReadCallback read_callback,
  87133. FLAC__StreamDecoderSeekCallback seek_callback,
  87134. FLAC__StreamDecoderTellCallback tell_callback,
  87135. FLAC__StreamDecoderLengthCallback length_callback,
  87136. FLAC__StreamDecoderEofCallback eof_callback,
  87137. FLAC__StreamDecoderWriteCallback write_callback,
  87138. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87139. FLAC__StreamDecoderErrorCallback error_callback,
  87140. void *client_data
  87141. )
  87142. {
  87143. return init_stream_internal_dec(
  87144. decoder,
  87145. read_callback,
  87146. seek_callback,
  87147. tell_callback,
  87148. length_callback,
  87149. eof_callback,
  87150. write_callback,
  87151. metadata_callback,
  87152. error_callback,
  87153. client_data,
  87154. false
  87155. );
  87156. }
  87157. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87158. FLAC__StreamDecoder *decoder,
  87159. FLAC__StreamDecoderReadCallback read_callback,
  87160. FLAC__StreamDecoderSeekCallback seek_callback,
  87161. FLAC__StreamDecoderTellCallback tell_callback,
  87162. FLAC__StreamDecoderLengthCallback length_callback,
  87163. FLAC__StreamDecoderEofCallback eof_callback,
  87164. FLAC__StreamDecoderWriteCallback write_callback,
  87165. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87166. FLAC__StreamDecoderErrorCallback error_callback,
  87167. void *client_data
  87168. )
  87169. {
  87170. return init_stream_internal_dec(
  87171. decoder,
  87172. read_callback,
  87173. seek_callback,
  87174. tell_callback,
  87175. length_callback,
  87176. eof_callback,
  87177. write_callback,
  87178. metadata_callback,
  87179. error_callback,
  87180. client_data,
  87181. true
  87182. );
  87183. }
  87184. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87185. FLAC__StreamDecoder *decoder,
  87186. FILE *file,
  87187. FLAC__StreamDecoderWriteCallback write_callback,
  87188. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87189. FLAC__StreamDecoderErrorCallback error_callback,
  87190. void *client_data,
  87191. FLAC__bool is_ogg
  87192. )
  87193. {
  87194. FLAC__ASSERT(0 != decoder);
  87195. FLAC__ASSERT(0 != file);
  87196. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87197. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87198. if(0 == write_callback || 0 == error_callback)
  87199. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87200. if(file == stdin)
  87201. file = get_binary_stdin_(); /* just to be safe */
  87202. decoder->private_->file = file;
  87203. return init_stream_internal_dec(
  87204. decoder,
  87205. file_read_callback_dec,
  87206. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87207. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87208. decoder->private_->file == stdin? 0: file_length_callback_,
  87209. file_eof_callback_,
  87210. write_callback,
  87211. metadata_callback,
  87212. error_callback,
  87213. client_data,
  87214. is_ogg
  87215. );
  87216. }
  87217. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87218. FLAC__StreamDecoder *decoder,
  87219. FILE *file,
  87220. FLAC__StreamDecoderWriteCallback write_callback,
  87221. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87222. FLAC__StreamDecoderErrorCallback error_callback,
  87223. void *client_data
  87224. )
  87225. {
  87226. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87227. }
  87228. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_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=*/true);
  87238. }
  87239. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87240. FLAC__StreamDecoder *decoder,
  87241. const char *filename,
  87242. FLAC__StreamDecoderWriteCallback write_callback,
  87243. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87244. FLAC__StreamDecoderErrorCallback error_callback,
  87245. void *client_data,
  87246. FLAC__bool is_ogg
  87247. )
  87248. {
  87249. FILE *file;
  87250. FLAC__ASSERT(0 != decoder);
  87251. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87252. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87253. if(0 == write_callback || 0 == error_callback)
  87254. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87255. file = filename? fopen(filename, "rb") : stdin;
  87256. if(0 == file)
  87257. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87258. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87259. }
  87260. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87261. FLAC__StreamDecoder *decoder,
  87262. const char *filename,
  87263. FLAC__StreamDecoderWriteCallback write_callback,
  87264. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87265. FLAC__StreamDecoderErrorCallback error_callback,
  87266. void *client_data
  87267. )
  87268. {
  87269. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87270. }
  87271. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_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=*/true);
  87281. }
  87282. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87283. {
  87284. FLAC__bool md5_failed = false;
  87285. unsigned i;
  87286. FLAC__ASSERT(0 != decoder);
  87287. FLAC__ASSERT(0 != decoder->private_);
  87288. FLAC__ASSERT(0 != decoder->protected_);
  87289. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87290. return true;
  87291. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87292. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87293. free(decoder->private_->seek_table.data.seek_table.points);
  87294. decoder->private_->seek_table.data.seek_table.points = 0;
  87295. decoder->private_->has_seek_table = false;
  87296. }
  87297. FLAC__bitreader_free(decoder->private_->input);
  87298. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87299. if(0 != decoder->private_->output[i]) {
  87300. free(decoder->private_->output[i]-4);
  87301. decoder->private_->output[i] = 0;
  87302. }
  87303. if(0 != decoder->private_->residual_unaligned[i]) {
  87304. free(decoder->private_->residual_unaligned[i]);
  87305. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87306. }
  87307. }
  87308. decoder->private_->output_capacity = 0;
  87309. decoder->private_->output_channels = 0;
  87310. #if FLAC__HAS_OGG
  87311. if(decoder->private_->is_ogg)
  87312. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87313. #endif
  87314. if(0 != decoder->private_->file) {
  87315. if(decoder->private_->file != stdin)
  87316. fclose(decoder->private_->file);
  87317. decoder->private_->file = 0;
  87318. }
  87319. if(decoder->private_->do_md5_checking) {
  87320. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87321. md5_failed = true;
  87322. }
  87323. decoder->private_->is_seeking = false;
  87324. set_defaults_dec(decoder);
  87325. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87326. return !md5_failed;
  87327. }
  87328. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87329. {
  87330. FLAC__ASSERT(0 != decoder);
  87331. FLAC__ASSERT(0 != decoder->private_);
  87332. FLAC__ASSERT(0 != decoder->protected_);
  87333. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87334. return false;
  87335. #if FLAC__HAS_OGG
  87336. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87337. return true;
  87338. #else
  87339. (void)value;
  87340. return false;
  87341. #endif
  87342. }
  87343. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87344. {
  87345. FLAC__ASSERT(0 != decoder);
  87346. FLAC__ASSERT(0 != decoder->protected_);
  87347. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87348. return false;
  87349. decoder->protected_->md5_checking = value;
  87350. return true;
  87351. }
  87352. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87353. {
  87354. FLAC__ASSERT(0 != decoder);
  87355. FLAC__ASSERT(0 != decoder->private_);
  87356. FLAC__ASSERT(0 != decoder->protected_);
  87357. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87358. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87359. return false;
  87360. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87361. return false;
  87362. decoder->private_->metadata_filter[type] = true;
  87363. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87364. decoder->private_->metadata_filter_ids_count = 0;
  87365. return true;
  87366. }
  87367. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87368. {
  87369. FLAC__ASSERT(0 != decoder);
  87370. FLAC__ASSERT(0 != decoder->private_);
  87371. FLAC__ASSERT(0 != decoder->protected_);
  87372. FLAC__ASSERT(0 != id);
  87373. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87374. return false;
  87375. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87376. return true;
  87377. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87378. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87379. 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))) {
  87380. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87381. return false;
  87382. }
  87383. decoder->private_->metadata_filter_ids_capacity *= 2;
  87384. }
  87385. 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));
  87386. decoder->private_->metadata_filter_ids_count++;
  87387. return true;
  87388. }
  87389. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87390. {
  87391. unsigned i;
  87392. FLAC__ASSERT(0 != decoder);
  87393. FLAC__ASSERT(0 != decoder->private_);
  87394. FLAC__ASSERT(0 != decoder->protected_);
  87395. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87396. return false;
  87397. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87398. decoder->private_->metadata_filter[i] = true;
  87399. decoder->private_->metadata_filter_ids_count = 0;
  87400. return true;
  87401. }
  87402. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87403. {
  87404. FLAC__ASSERT(0 != decoder);
  87405. FLAC__ASSERT(0 != decoder->private_);
  87406. FLAC__ASSERT(0 != decoder->protected_);
  87407. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87408. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87409. return false;
  87410. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87411. return false;
  87412. decoder->private_->metadata_filter[type] = false;
  87413. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87414. decoder->private_->metadata_filter_ids_count = 0;
  87415. return true;
  87416. }
  87417. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87418. {
  87419. FLAC__ASSERT(0 != decoder);
  87420. FLAC__ASSERT(0 != decoder->private_);
  87421. FLAC__ASSERT(0 != decoder->protected_);
  87422. FLAC__ASSERT(0 != id);
  87423. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87424. return false;
  87425. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87426. return true;
  87427. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87428. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87429. 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))) {
  87430. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87431. return false;
  87432. }
  87433. decoder->private_->metadata_filter_ids_capacity *= 2;
  87434. }
  87435. 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));
  87436. decoder->private_->metadata_filter_ids_count++;
  87437. return true;
  87438. }
  87439. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87440. {
  87441. FLAC__ASSERT(0 != decoder);
  87442. FLAC__ASSERT(0 != decoder->private_);
  87443. FLAC__ASSERT(0 != decoder->protected_);
  87444. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87445. return false;
  87446. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87447. decoder->private_->metadata_filter_ids_count = 0;
  87448. return true;
  87449. }
  87450. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87451. {
  87452. FLAC__ASSERT(0 != decoder);
  87453. FLAC__ASSERT(0 != decoder->protected_);
  87454. return decoder->protected_->state;
  87455. }
  87456. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87457. {
  87458. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87459. }
  87460. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87461. {
  87462. FLAC__ASSERT(0 != decoder);
  87463. FLAC__ASSERT(0 != decoder->protected_);
  87464. return decoder->protected_->md5_checking;
  87465. }
  87466. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87467. {
  87468. FLAC__ASSERT(0 != decoder);
  87469. FLAC__ASSERT(0 != decoder->protected_);
  87470. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87471. }
  87472. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87473. {
  87474. FLAC__ASSERT(0 != decoder);
  87475. FLAC__ASSERT(0 != decoder->protected_);
  87476. return decoder->protected_->channels;
  87477. }
  87478. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87479. {
  87480. FLAC__ASSERT(0 != decoder);
  87481. FLAC__ASSERT(0 != decoder->protected_);
  87482. return decoder->protected_->channel_assignment;
  87483. }
  87484. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87485. {
  87486. FLAC__ASSERT(0 != decoder);
  87487. FLAC__ASSERT(0 != decoder->protected_);
  87488. return decoder->protected_->bits_per_sample;
  87489. }
  87490. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87491. {
  87492. FLAC__ASSERT(0 != decoder);
  87493. FLAC__ASSERT(0 != decoder->protected_);
  87494. return decoder->protected_->sample_rate;
  87495. }
  87496. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87497. {
  87498. FLAC__ASSERT(0 != decoder);
  87499. FLAC__ASSERT(0 != decoder->protected_);
  87500. return decoder->protected_->blocksize;
  87501. }
  87502. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87503. {
  87504. FLAC__ASSERT(0 != decoder);
  87505. FLAC__ASSERT(0 != decoder->private_);
  87506. FLAC__ASSERT(0 != position);
  87507. #if FLAC__HAS_OGG
  87508. if(decoder->private_->is_ogg)
  87509. return false;
  87510. #endif
  87511. if(0 == decoder->private_->tell_callback)
  87512. return false;
  87513. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87514. return false;
  87515. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87516. return false;
  87517. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87518. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87519. return true;
  87520. }
  87521. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87522. {
  87523. FLAC__ASSERT(0 != decoder);
  87524. FLAC__ASSERT(0 != decoder->private_);
  87525. FLAC__ASSERT(0 != decoder->protected_);
  87526. decoder->private_->samples_decoded = 0;
  87527. decoder->private_->do_md5_checking = false;
  87528. #if FLAC__HAS_OGG
  87529. if(decoder->private_->is_ogg)
  87530. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87531. #endif
  87532. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87533. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87534. return false;
  87535. }
  87536. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87537. return true;
  87538. }
  87539. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87540. {
  87541. FLAC__ASSERT(0 != decoder);
  87542. FLAC__ASSERT(0 != decoder->private_);
  87543. FLAC__ASSERT(0 != decoder->protected_);
  87544. if(!FLAC__stream_decoder_flush(decoder)) {
  87545. return false;
  87546. }
  87547. #if FLAC__HAS_OGG
  87548. if(decoder->private_->is_ogg)
  87549. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87550. #endif
  87551. if(!decoder->private_->internal_reset_hack) {
  87552. if(decoder->private_->file == stdin)
  87553. return false; /* can't rewind stdin, reset fails */
  87554. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87555. return false; /* seekable and seek fails, reset fails */
  87556. }
  87557. else
  87558. decoder->private_->internal_reset_hack = false;
  87559. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87560. decoder->private_->has_stream_info = false;
  87561. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87562. free(decoder->private_->seek_table.data.seek_table.points);
  87563. decoder->private_->seek_table.data.seek_table.points = 0;
  87564. decoder->private_->has_seek_table = false;
  87565. }
  87566. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87567. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87568. FLAC__MD5Init(&decoder->private_->md5context);
  87569. decoder->private_->first_frame_offset = 0;
  87570. decoder->private_->unparseable_frame_count = 0;
  87571. return true;
  87572. }
  87573. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87574. {
  87575. FLAC__bool got_a_frame;
  87576. FLAC__ASSERT(0 != decoder);
  87577. FLAC__ASSERT(0 != decoder->protected_);
  87578. while(1) {
  87579. switch(decoder->protected_->state) {
  87580. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87581. if(!find_metadata_(decoder))
  87582. return false; /* above function sets the status for us */
  87583. break;
  87584. case FLAC__STREAM_DECODER_READ_METADATA:
  87585. if(!read_metadata_(decoder))
  87586. return false; /* above function sets the status for us */
  87587. else
  87588. return true;
  87589. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87590. if(!frame_sync_(decoder))
  87591. return true; /* above function sets the status for us */
  87592. break;
  87593. case FLAC__STREAM_DECODER_READ_FRAME:
  87594. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87595. return false; /* above function sets the status for us */
  87596. if(got_a_frame)
  87597. return true; /* above function sets the status for us */
  87598. break;
  87599. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87600. case FLAC__STREAM_DECODER_ABORTED:
  87601. return true;
  87602. default:
  87603. FLAC__ASSERT(0);
  87604. return false;
  87605. }
  87606. }
  87607. }
  87608. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87609. {
  87610. FLAC__ASSERT(0 != decoder);
  87611. FLAC__ASSERT(0 != decoder->protected_);
  87612. while(1) {
  87613. switch(decoder->protected_->state) {
  87614. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87615. if(!find_metadata_(decoder))
  87616. return false; /* above function sets the status for us */
  87617. break;
  87618. case FLAC__STREAM_DECODER_READ_METADATA:
  87619. if(!read_metadata_(decoder))
  87620. return false; /* above function sets the status for us */
  87621. break;
  87622. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87623. case FLAC__STREAM_DECODER_READ_FRAME:
  87624. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87625. case FLAC__STREAM_DECODER_ABORTED:
  87626. return true;
  87627. default:
  87628. FLAC__ASSERT(0);
  87629. return false;
  87630. }
  87631. }
  87632. }
  87633. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87634. {
  87635. FLAC__bool dummy;
  87636. FLAC__ASSERT(0 != decoder);
  87637. FLAC__ASSERT(0 != decoder->protected_);
  87638. while(1) {
  87639. switch(decoder->protected_->state) {
  87640. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87641. if(!find_metadata_(decoder))
  87642. return false; /* above function sets the status for us */
  87643. break;
  87644. case FLAC__STREAM_DECODER_READ_METADATA:
  87645. if(!read_metadata_(decoder))
  87646. return false; /* above function sets the status for us */
  87647. break;
  87648. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87649. if(!frame_sync_(decoder))
  87650. return true; /* above function sets the status for us */
  87651. break;
  87652. case FLAC__STREAM_DECODER_READ_FRAME:
  87653. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87654. return false; /* above function sets the status for us */
  87655. break;
  87656. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87657. case FLAC__STREAM_DECODER_ABORTED:
  87658. return true;
  87659. default:
  87660. FLAC__ASSERT(0);
  87661. return false;
  87662. }
  87663. }
  87664. }
  87665. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87666. {
  87667. FLAC__bool got_a_frame;
  87668. FLAC__ASSERT(0 != decoder);
  87669. FLAC__ASSERT(0 != decoder->protected_);
  87670. while(1) {
  87671. switch(decoder->protected_->state) {
  87672. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87673. case FLAC__STREAM_DECODER_READ_METADATA:
  87674. return false; /* above function sets the status for us */
  87675. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87676. if(!frame_sync_(decoder))
  87677. return true; /* above function sets the status for us */
  87678. break;
  87679. case FLAC__STREAM_DECODER_READ_FRAME:
  87680. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87681. return false; /* above function sets the status for us */
  87682. if(got_a_frame)
  87683. return true; /* above function sets the status for us */
  87684. break;
  87685. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87686. case FLAC__STREAM_DECODER_ABORTED:
  87687. return true;
  87688. default:
  87689. FLAC__ASSERT(0);
  87690. return false;
  87691. }
  87692. }
  87693. }
  87694. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87695. {
  87696. FLAC__uint64 length;
  87697. FLAC__ASSERT(0 != decoder);
  87698. if(
  87699. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87700. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87701. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87702. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87703. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87704. )
  87705. return false;
  87706. if(0 == decoder->private_->seek_callback)
  87707. return false;
  87708. FLAC__ASSERT(decoder->private_->seek_callback);
  87709. FLAC__ASSERT(decoder->private_->tell_callback);
  87710. FLAC__ASSERT(decoder->private_->length_callback);
  87711. FLAC__ASSERT(decoder->private_->eof_callback);
  87712. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87713. return false;
  87714. decoder->private_->is_seeking = true;
  87715. decoder->private_->do_md5_checking = false;
  87716. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87717. decoder->private_->is_seeking = false;
  87718. return false;
  87719. }
  87720. if(
  87721. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87722. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87723. ) {
  87724. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87725. decoder->private_->is_seeking = false;
  87726. return false;
  87727. }
  87728. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87729. decoder->private_->is_seeking = false;
  87730. return false;
  87731. }
  87732. }
  87733. {
  87734. const FLAC__bool ok =
  87735. #if FLAC__HAS_OGG
  87736. decoder->private_->is_ogg?
  87737. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87738. #endif
  87739. seek_to_absolute_sample_(decoder, length, sample)
  87740. ;
  87741. decoder->private_->is_seeking = false;
  87742. return ok;
  87743. }
  87744. }
  87745. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87746. {
  87747. FLAC__ASSERT(0 != decoder);
  87748. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87749. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87750. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87751. }
  87752. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87753. {
  87754. #if FLAC__HAS_OGG
  87755. decoder->private_->is_ogg = false;
  87756. #endif
  87757. decoder->private_->read_callback = 0;
  87758. decoder->private_->seek_callback = 0;
  87759. decoder->private_->tell_callback = 0;
  87760. decoder->private_->length_callback = 0;
  87761. decoder->private_->eof_callback = 0;
  87762. decoder->private_->write_callback = 0;
  87763. decoder->private_->metadata_callback = 0;
  87764. decoder->private_->error_callback = 0;
  87765. decoder->private_->client_data = 0;
  87766. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87767. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87768. decoder->private_->metadata_filter_ids_count = 0;
  87769. decoder->protected_->md5_checking = false;
  87770. #if FLAC__HAS_OGG
  87771. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87772. #endif
  87773. }
  87774. FILE *get_binary_stdin_(void)
  87775. {
  87776. #if defined _MSC_VER || defined __MINGW32__
  87777. _setmode(_fileno(stdin), _O_BINARY);
  87778. #elif defined __CYGWIN__
  87779. setmode(_fileno(stdin), _O_BINARY);
  87780. #elif defined __EMX__
  87781. setmode(fileno(stdin), O_BINARY);
  87782. #endif
  87783. return stdin;
  87784. }
  87785. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87786. {
  87787. unsigned i;
  87788. FLAC__int32 *tmp;
  87789. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87790. return true;
  87791. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87792. if(0 != decoder->private_->output[i]) {
  87793. free(decoder->private_->output[i]-4);
  87794. decoder->private_->output[i] = 0;
  87795. }
  87796. if(0 != decoder->private_->residual_unaligned[i]) {
  87797. free(decoder->private_->residual_unaligned[i]);
  87798. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87799. }
  87800. }
  87801. for(i = 0; i < channels; i++) {
  87802. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87803. if(tmp == 0) {
  87804. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87805. return false;
  87806. }
  87807. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87808. decoder->private_->output[i] = tmp + 4;
  87809. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87810. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87811. return false;
  87812. }
  87813. }
  87814. decoder->private_->output_capacity = size;
  87815. decoder->private_->output_channels = channels;
  87816. return true;
  87817. }
  87818. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87819. {
  87820. size_t i;
  87821. FLAC__ASSERT(0 != decoder);
  87822. FLAC__ASSERT(0 != decoder->private_);
  87823. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87824. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87825. return true;
  87826. return false;
  87827. }
  87828. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87829. {
  87830. FLAC__uint32 x;
  87831. unsigned i, id_;
  87832. FLAC__bool first = true;
  87833. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87834. for(i = id_ = 0; i < 4; ) {
  87835. if(decoder->private_->cached) {
  87836. x = (FLAC__uint32)decoder->private_->lookahead;
  87837. decoder->private_->cached = false;
  87838. }
  87839. else {
  87840. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87841. return false; /* read_callback_ sets the state for us */
  87842. }
  87843. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87844. first = true;
  87845. i++;
  87846. id_ = 0;
  87847. continue;
  87848. }
  87849. if(x == ID3V2_TAG_[id_]) {
  87850. id_++;
  87851. i = 0;
  87852. if(id_ == 3) {
  87853. if(!skip_id3v2_tag_(decoder))
  87854. return false; /* skip_id3v2_tag_ sets the state for us */
  87855. }
  87856. continue;
  87857. }
  87858. id_ = 0;
  87859. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87860. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87861. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87862. return false; /* read_callback_ sets the state for us */
  87863. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87864. decoder->private_->lookahead = (FLAC__byte)x;
  87865. decoder->private_->cached = true;
  87866. }
  87867. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87868. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87869. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87870. return true;
  87871. }
  87872. }
  87873. i = 0;
  87874. if(first) {
  87875. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87876. first = false;
  87877. }
  87878. }
  87879. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87880. return true;
  87881. }
  87882. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87883. {
  87884. FLAC__bool is_last;
  87885. FLAC__uint32 i, x, type, length;
  87886. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87887. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87888. return false; /* read_callback_ sets the state for us */
  87889. is_last = x? true : false;
  87890. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87891. return false; /* read_callback_ sets the state for us */
  87892. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87893. return false; /* read_callback_ sets the state for us */
  87894. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  87895. if(!read_metadata_streaminfo_(decoder, is_last, length))
  87896. return false;
  87897. decoder->private_->has_stream_info = true;
  87898. 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))
  87899. decoder->private_->do_md5_checking = false;
  87900. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  87901. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  87902. }
  87903. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  87904. if(!read_metadata_seektable_(decoder, is_last, length))
  87905. return false;
  87906. decoder->private_->has_seek_table = true;
  87907. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  87908. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  87909. }
  87910. else {
  87911. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  87912. unsigned real_length = length;
  87913. FLAC__StreamMetadata block;
  87914. block.is_last = is_last;
  87915. block.type = (FLAC__MetadataType)type;
  87916. block.length = length;
  87917. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  87918. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  87919. return false; /* read_callback_ sets the state for us */
  87920. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  87921. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  87922. return false;
  87923. }
  87924. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  87925. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  87926. skip_it = !skip_it;
  87927. }
  87928. if(skip_it) {
  87929. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87930. return false; /* read_callback_ sets the state for us */
  87931. }
  87932. else {
  87933. switch(type) {
  87934. case FLAC__METADATA_TYPE_PADDING:
  87935. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87936. return false; /* read_callback_ sets the state for us */
  87937. break;
  87938. case FLAC__METADATA_TYPE_APPLICATION:
  87939. if(real_length > 0) {
  87940. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  87941. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87942. return false;
  87943. }
  87944. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  87945. return false; /* read_callback_ sets the state for us */
  87946. }
  87947. else
  87948. block.data.application.data = 0;
  87949. break;
  87950. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87951. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  87952. return false;
  87953. break;
  87954. case FLAC__METADATA_TYPE_CUESHEET:
  87955. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  87956. return false;
  87957. break;
  87958. case FLAC__METADATA_TYPE_PICTURE:
  87959. if(!read_metadata_picture_(decoder, &block.data.picture))
  87960. return false;
  87961. break;
  87962. case FLAC__METADATA_TYPE_STREAMINFO:
  87963. case FLAC__METADATA_TYPE_SEEKTABLE:
  87964. FLAC__ASSERT(0);
  87965. break;
  87966. default:
  87967. if(real_length > 0) {
  87968. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  87969. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87970. return false;
  87971. }
  87972. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  87973. return false; /* read_callback_ sets the state for us */
  87974. }
  87975. else
  87976. block.data.unknown.data = 0;
  87977. break;
  87978. }
  87979. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  87980. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  87981. switch(type) {
  87982. case FLAC__METADATA_TYPE_PADDING:
  87983. break;
  87984. case FLAC__METADATA_TYPE_APPLICATION:
  87985. if(0 != block.data.application.data)
  87986. free(block.data.application.data);
  87987. break;
  87988. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87989. if(0 != block.data.vorbis_comment.vendor_string.entry)
  87990. free(block.data.vorbis_comment.vendor_string.entry);
  87991. if(block.data.vorbis_comment.num_comments > 0)
  87992. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  87993. if(0 != block.data.vorbis_comment.comments[i].entry)
  87994. free(block.data.vorbis_comment.comments[i].entry);
  87995. if(0 != block.data.vorbis_comment.comments)
  87996. free(block.data.vorbis_comment.comments);
  87997. break;
  87998. case FLAC__METADATA_TYPE_CUESHEET:
  87999. if(block.data.cue_sheet.num_tracks > 0)
  88000. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88001. if(0 != block.data.cue_sheet.tracks[i].indices)
  88002. free(block.data.cue_sheet.tracks[i].indices);
  88003. if(0 != block.data.cue_sheet.tracks)
  88004. free(block.data.cue_sheet.tracks);
  88005. break;
  88006. case FLAC__METADATA_TYPE_PICTURE:
  88007. if(0 != block.data.picture.mime_type)
  88008. free(block.data.picture.mime_type);
  88009. if(0 != block.data.picture.description)
  88010. free(block.data.picture.description);
  88011. if(0 != block.data.picture.data)
  88012. free(block.data.picture.data);
  88013. break;
  88014. case FLAC__METADATA_TYPE_STREAMINFO:
  88015. case FLAC__METADATA_TYPE_SEEKTABLE:
  88016. FLAC__ASSERT(0);
  88017. default:
  88018. if(0 != block.data.unknown.data)
  88019. free(block.data.unknown.data);
  88020. break;
  88021. }
  88022. }
  88023. }
  88024. if(is_last) {
  88025. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88026. decoder->private_->first_frame_offset = 0;
  88027. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88028. }
  88029. return true;
  88030. }
  88031. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88032. {
  88033. FLAC__uint32 x;
  88034. unsigned bits, used_bits = 0;
  88035. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88036. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88037. decoder->private_->stream_info.is_last = is_last;
  88038. decoder->private_->stream_info.length = length;
  88039. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88040. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88041. return false; /* read_callback_ sets the state for us */
  88042. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88043. used_bits += bits;
  88044. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88045. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88046. return false; /* read_callback_ sets the state for us */
  88047. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88048. used_bits += bits;
  88049. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88050. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88051. return false; /* read_callback_ sets the state for us */
  88052. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88053. used_bits += bits;
  88054. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88055. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88056. return false; /* read_callback_ sets the state for us */
  88057. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88058. used_bits += bits;
  88059. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88060. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88061. return false; /* read_callback_ sets the state for us */
  88062. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88063. used_bits += bits;
  88064. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88065. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88066. return false; /* read_callback_ sets the state for us */
  88067. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88068. used_bits += bits;
  88069. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88070. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88071. return false; /* read_callback_ sets the state for us */
  88072. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88073. used_bits += bits;
  88074. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88075. 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))
  88076. return false; /* read_callback_ sets the state for us */
  88077. used_bits += bits;
  88078. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88079. return false; /* read_callback_ sets the state for us */
  88080. used_bits += 16*8;
  88081. FLAC__ASSERT(used_bits % 8 == 0);
  88082. length -= (used_bits / 8);
  88083. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88084. return false; /* read_callback_ sets the state for us */
  88085. return true;
  88086. }
  88087. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88088. {
  88089. FLAC__uint32 i, x;
  88090. FLAC__uint64 xx;
  88091. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88092. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88093. decoder->private_->seek_table.is_last = is_last;
  88094. decoder->private_->seek_table.length = length;
  88095. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88096. 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)))) {
  88097. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88098. return false;
  88099. }
  88100. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88101. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88102. return false; /* read_callback_ sets the state for us */
  88103. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88104. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88105. return false; /* read_callback_ sets the state for us */
  88106. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88107. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88108. return false; /* read_callback_ sets the state for us */
  88109. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88110. }
  88111. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88112. if(length > 0) {
  88113. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88114. return false; /* read_callback_ sets the state for us */
  88115. }
  88116. return true;
  88117. }
  88118. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88119. {
  88120. FLAC__uint32 i;
  88121. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88122. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88123. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88124. return false; /* read_callback_ sets the state for us */
  88125. if(obj->vendor_string.length > 0) {
  88126. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88127. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88128. return false;
  88129. }
  88130. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88131. return false; /* read_callback_ sets the state for us */
  88132. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88133. }
  88134. else
  88135. obj->vendor_string.entry = 0;
  88136. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88137. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88138. return false; /* read_callback_ sets the state for us */
  88139. if(obj->num_comments > 0) {
  88140. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88141. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88142. return false;
  88143. }
  88144. for(i = 0; i < obj->num_comments; i++) {
  88145. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88146. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88147. return false; /* read_callback_ sets the state for us */
  88148. if(obj->comments[i].length > 0) {
  88149. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88150. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88151. return false;
  88152. }
  88153. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88154. return false; /* read_callback_ sets the state for us */
  88155. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88156. }
  88157. else
  88158. obj->comments[i].entry = 0;
  88159. }
  88160. }
  88161. else {
  88162. obj->comments = 0;
  88163. }
  88164. return true;
  88165. }
  88166. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88167. {
  88168. FLAC__uint32 i, j, x;
  88169. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88170. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88171. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88172. 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))
  88173. return false; /* read_callback_ sets the state for us */
  88174. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88175. return false; /* read_callback_ sets the state for us */
  88176. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88177. return false; /* read_callback_ sets the state for us */
  88178. obj->is_cd = x? true : false;
  88179. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88180. return false; /* read_callback_ sets the state for us */
  88181. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88182. return false; /* read_callback_ sets the state for us */
  88183. obj->num_tracks = x;
  88184. if(obj->num_tracks > 0) {
  88185. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88186. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88187. return false;
  88188. }
  88189. for(i = 0; i < obj->num_tracks; i++) {
  88190. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88191. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88192. return false; /* read_callback_ sets the state for us */
  88193. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88194. return false; /* read_callback_ sets the state for us */
  88195. track->number = (FLAC__byte)x;
  88196. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88197. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88198. return false; /* read_callback_ sets the state for us */
  88199. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88200. return false; /* read_callback_ sets the state for us */
  88201. track->type = x;
  88202. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88203. return false; /* read_callback_ sets the state for us */
  88204. track->pre_emphasis = x;
  88205. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88206. return false; /* read_callback_ sets the state for us */
  88207. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88208. return false; /* read_callback_ sets the state for us */
  88209. track->num_indices = (FLAC__byte)x;
  88210. if(track->num_indices > 0) {
  88211. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88212. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88213. return false;
  88214. }
  88215. for(j = 0; j < track->num_indices; j++) {
  88216. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88217. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88218. return false; /* read_callback_ sets the state for us */
  88219. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88220. return false; /* read_callback_ sets the state for us */
  88221. index->number = (FLAC__byte)x;
  88222. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88223. return false; /* read_callback_ sets the state for us */
  88224. }
  88225. }
  88226. }
  88227. }
  88228. return true;
  88229. }
  88230. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88231. {
  88232. FLAC__uint32 x;
  88233. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88234. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88235. return false; /* read_callback_ sets the state for us */
  88236. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88237. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88238. return false; /* read_callback_ sets the state for us */
  88239. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88240. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88241. return false;
  88242. }
  88243. if(x > 0) {
  88244. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88245. return false; /* read_callback_ sets the state for us */
  88246. }
  88247. obj->mime_type[x] = '\0';
  88248. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88249. return false; /* read_callback_ sets the state for us */
  88250. if(0 == (obj->description = (FLAC__byte*)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, obj->description, x))
  88256. return false; /* read_callback_ sets the state for us */
  88257. }
  88258. obj->description[x] = '\0';
  88259. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88260. return false; /* read_callback_ sets the state for us */
  88261. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88262. return false; /* read_callback_ sets the state for us */
  88263. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88264. return false; /* read_callback_ sets the state for us */
  88265. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88266. return false; /* read_callback_ sets the state for us */
  88267. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88268. return false; /* read_callback_ sets the state for us */
  88269. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88270. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88271. return false;
  88272. }
  88273. if(obj->data_length > 0) {
  88274. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88275. return false; /* read_callback_ sets the state for us */
  88276. }
  88277. return true;
  88278. }
  88279. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88280. {
  88281. FLAC__uint32 x;
  88282. unsigned i, skip;
  88283. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88284. return false; /* read_callback_ sets the state for us */
  88285. skip = 0;
  88286. for(i = 0; i < 4; i++) {
  88287. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88288. return false; /* read_callback_ sets the state for us */
  88289. skip <<= 7;
  88290. skip |= (x & 0x7f);
  88291. }
  88292. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88293. return false; /* read_callback_ sets the state for us */
  88294. return true;
  88295. }
  88296. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88297. {
  88298. FLAC__uint32 x;
  88299. FLAC__bool first = true;
  88300. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88301. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88302. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88303. return true;
  88304. }
  88305. }
  88306. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88307. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88308. return false; /* read_callback_ sets the state for us */
  88309. }
  88310. while(1) {
  88311. if(decoder->private_->cached) {
  88312. x = (FLAC__uint32)decoder->private_->lookahead;
  88313. decoder->private_->cached = false;
  88314. }
  88315. else {
  88316. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88317. return false; /* read_callback_ sets the state for us */
  88318. }
  88319. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88320. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88321. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88322. return false; /* read_callback_ sets the state for us */
  88323. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88324. decoder->private_->lookahead = (FLAC__byte)x;
  88325. decoder->private_->cached = true;
  88326. }
  88327. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88328. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88329. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88330. return true;
  88331. }
  88332. }
  88333. if(first) {
  88334. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88335. first = false;
  88336. }
  88337. }
  88338. return true;
  88339. }
  88340. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88341. {
  88342. unsigned channel;
  88343. unsigned i;
  88344. FLAC__int32 mid, side;
  88345. unsigned frame_crc; /* the one we calculate from the input stream */
  88346. FLAC__uint32 x;
  88347. *got_a_frame = false;
  88348. frame_crc = 0;
  88349. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88350. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88351. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88352. if(!read_frame_header_(decoder))
  88353. return false;
  88354. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88355. return true;
  88356. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88357. return false;
  88358. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88359. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88360. switch(decoder->private_->frame.header.channel_assignment) {
  88361. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88362. break;
  88363. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88364. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88365. if(channel == 1)
  88366. bps++;
  88367. break;
  88368. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88369. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88370. if(channel == 0)
  88371. bps++;
  88372. break;
  88373. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88374. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88375. if(channel == 1)
  88376. bps++;
  88377. break;
  88378. default:
  88379. FLAC__ASSERT(0);
  88380. }
  88381. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88382. return false;
  88383. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88384. return true;
  88385. }
  88386. if(!read_zero_padding_(decoder))
  88387. return false;
  88388. 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) */
  88389. return true;
  88390. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88391. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88392. return false; /* read_callback_ sets the state for us */
  88393. if(frame_crc == x) {
  88394. if(do_full_decode) {
  88395. switch(decoder->private_->frame.header.channel_assignment) {
  88396. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88397. break;
  88398. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88399. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88400. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88401. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88402. break;
  88403. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88404. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88405. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88406. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88407. break;
  88408. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88409. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88410. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88411. #if 1
  88412. mid = decoder->private_->output[0][i];
  88413. side = decoder->private_->output[1][i];
  88414. mid <<= 1;
  88415. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88416. decoder->private_->output[0][i] = (mid + side) >> 1;
  88417. decoder->private_->output[1][i] = (mid - side) >> 1;
  88418. #else
  88419. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88420. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88421. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88422. #endif
  88423. }
  88424. break;
  88425. default:
  88426. FLAC__ASSERT(0);
  88427. break;
  88428. }
  88429. }
  88430. }
  88431. else {
  88432. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88433. if(do_full_decode) {
  88434. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88435. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88436. }
  88437. }
  88438. }
  88439. *got_a_frame = true;
  88440. if(decoder->private_->next_fixed_block_size)
  88441. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88442. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88443. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88444. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88445. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88446. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88447. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88448. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88449. if(do_full_decode) {
  88450. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88451. return false;
  88452. }
  88453. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88454. return true;
  88455. }
  88456. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88457. {
  88458. FLAC__uint32 x;
  88459. FLAC__uint64 xx;
  88460. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88461. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88462. unsigned raw_header_len;
  88463. FLAC__bool is_unparseable = false;
  88464. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88465. raw_header[0] = decoder->private_->header_warmup[0];
  88466. raw_header[1] = decoder->private_->header_warmup[1];
  88467. raw_header_len = 2;
  88468. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88469. is_unparseable = true;
  88470. for(i = 0; i < 2; i++) {
  88471. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88472. return false; /* read_callback_ sets the state for us */
  88473. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88474. decoder->private_->lookahead = (FLAC__byte)x;
  88475. decoder->private_->cached = true;
  88476. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88477. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88478. return true;
  88479. }
  88480. raw_header[raw_header_len++] = (FLAC__byte)x;
  88481. }
  88482. switch(x = raw_header[2] >> 4) {
  88483. case 0:
  88484. is_unparseable = true;
  88485. break;
  88486. case 1:
  88487. decoder->private_->frame.header.blocksize = 192;
  88488. break;
  88489. case 2:
  88490. case 3:
  88491. case 4:
  88492. case 5:
  88493. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88494. break;
  88495. case 6:
  88496. case 7:
  88497. blocksize_hint = x;
  88498. break;
  88499. case 8:
  88500. case 9:
  88501. case 10:
  88502. case 11:
  88503. case 12:
  88504. case 13:
  88505. case 14:
  88506. case 15:
  88507. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88508. break;
  88509. default:
  88510. FLAC__ASSERT(0);
  88511. break;
  88512. }
  88513. switch(x = raw_header[2] & 0x0f) {
  88514. case 0:
  88515. if(decoder->private_->has_stream_info)
  88516. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88517. else
  88518. is_unparseable = true;
  88519. break;
  88520. case 1:
  88521. decoder->private_->frame.header.sample_rate = 88200;
  88522. break;
  88523. case 2:
  88524. decoder->private_->frame.header.sample_rate = 176400;
  88525. break;
  88526. case 3:
  88527. decoder->private_->frame.header.sample_rate = 192000;
  88528. break;
  88529. case 4:
  88530. decoder->private_->frame.header.sample_rate = 8000;
  88531. break;
  88532. case 5:
  88533. decoder->private_->frame.header.sample_rate = 16000;
  88534. break;
  88535. case 6:
  88536. decoder->private_->frame.header.sample_rate = 22050;
  88537. break;
  88538. case 7:
  88539. decoder->private_->frame.header.sample_rate = 24000;
  88540. break;
  88541. case 8:
  88542. decoder->private_->frame.header.sample_rate = 32000;
  88543. break;
  88544. case 9:
  88545. decoder->private_->frame.header.sample_rate = 44100;
  88546. break;
  88547. case 10:
  88548. decoder->private_->frame.header.sample_rate = 48000;
  88549. break;
  88550. case 11:
  88551. decoder->private_->frame.header.sample_rate = 96000;
  88552. break;
  88553. case 12:
  88554. case 13:
  88555. case 14:
  88556. sample_rate_hint = x;
  88557. break;
  88558. case 15:
  88559. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88560. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88561. return true;
  88562. default:
  88563. FLAC__ASSERT(0);
  88564. }
  88565. x = (unsigned)(raw_header[3] >> 4);
  88566. if(x & 8) {
  88567. decoder->private_->frame.header.channels = 2;
  88568. switch(x & 7) {
  88569. case 0:
  88570. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88571. break;
  88572. case 1:
  88573. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88574. break;
  88575. case 2:
  88576. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88577. break;
  88578. default:
  88579. is_unparseable = true;
  88580. break;
  88581. }
  88582. }
  88583. else {
  88584. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88585. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88586. }
  88587. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88588. case 0:
  88589. if(decoder->private_->has_stream_info)
  88590. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88591. else
  88592. is_unparseable = true;
  88593. break;
  88594. case 1:
  88595. decoder->private_->frame.header.bits_per_sample = 8;
  88596. break;
  88597. case 2:
  88598. decoder->private_->frame.header.bits_per_sample = 12;
  88599. break;
  88600. case 4:
  88601. decoder->private_->frame.header.bits_per_sample = 16;
  88602. break;
  88603. case 5:
  88604. decoder->private_->frame.header.bits_per_sample = 20;
  88605. break;
  88606. case 6:
  88607. decoder->private_->frame.header.bits_per_sample = 24;
  88608. break;
  88609. case 3:
  88610. case 7:
  88611. is_unparseable = true;
  88612. break;
  88613. default:
  88614. FLAC__ASSERT(0);
  88615. break;
  88616. }
  88617. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88618. is_unparseable = true;
  88619. if(
  88620. raw_header[1] & 0x01 ||
  88621. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88622. ) { /* variable blocksize */
  88623. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88624. return false; /* read_callback_ sets the state for us */
  88625. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88626. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88627. decoder->private_->cached = true;
  88628. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88629. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88630. return true;
  88631. }
  88632. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88633. decoder->private_->frame.header.number.sample_number = xx;
  88634. }
  88635. else { /* fixed blocksize */
  88636. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88637. return false; /* read_callback_ sets the state for us */
  88638. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88639. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88640. decoder->private_->cached = true;
  88641. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88642. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88643. return true;
  88644. }
  88645. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88646. decoder->private_->frame.header.number.frame_number = x;
  88647. }
  88648. if(blocksize_hint) {
  88649. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88650. return false; /* read_callback_ sets the state for us */
  88651. raw_header[raw_header_len++] = (FLAC__byte)x;
  88652. if(blocksize_hint == 7) {
  88653. FLAC__uint32 _x;
  88654. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88655. return false; /* read_callback_ sets the state for us */
  88656. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88657. x = (x << 8) | _x;
  88658. }
  88659. decoder->private_->frame.header.blocksize = x+1;
  88660. }
  88661. if(sample_rate_hint) {
  88662. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88663. return false; /* read_callback_ sets the state for us */
  88664. raw_header[raw_header_len++] = (FLAC__byte)x;
  88665. if(sample_rate_hint != 12) {
  88666. FLAC__uint32 _x;
  88667. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88668. return false; /* read_callback_ sets the state for us */
  88669. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88670. x = (x << 8) | _x;
  88671. }
  88672. if(sample_rate_hint == 12)
  88673. decoder->private_->frame.header.sample_rate = x*1000;
  88674. else if(sample_rate_hint == 13)
  88675. decoder->private_->frame.header.sample_rate = x;
  88676. else
  88677. decoder->private_->frame.header.sample_rate = x*10;
  88678. }
  88679. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88680. return false; /* read_callback_ sets the state for us */
  88681. crc8 = (FLAC__byte)x;
  88682. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88683. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88684. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88685. return true;
  88686. }
  88687. decoder->private_->next_fixed_block_size = 0;
  88688. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88689. x = decoder->private_->frame.header.number.frame_number;
  88690. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88691. if(decoder->private_->fixed_block_size)
  88692. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88693. else if(decoder->private_->has_stream_info) {
  88694. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88695. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88696. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88697. }
  88698. else
  88699. is_unparseable = true;
  88700. }
  88701. else if(x == 0) {
  88702. decoder->private_->frame.header.number.sample_number = 0;
  88703. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88704. }
  88705. else {
  88706. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88707. }
  88708. }
  88709. if(is_unparseable) {
  88710. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88711. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88712. return true;
  88713. }
  88714. return true;
  88715. }
  88716. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88717. {
  88718. FLAC__uint32 x;
  88719. FLAC__bool wasted_bits;
  88720. unsigned i;
  88721. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88722. return false; /* read_callback_ sets the state for us */
  88723. wasted_bits = (x & 1);
  88724. x &= 0xfe;
  88725. if(wasted_bits) {
  88726. unsigned u;
  88727. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88728. return false; /* read_callback_ sets the state for us */
  88729. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88730. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88731. }
  88732. else
  88733. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88734. if(x & 0x80) {
  88735. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88736. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88737. return true;
  88738. }
  88739. else if(x == 0) {
  88740. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88741. return false;
  88742. }
  88743. else if(x == 2) {
  88744. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88745. return false;
  88746. }
  88747. else if(x < 16) {
  88748. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88749. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88750. return true;
  88751. }
  88752. else if(x <= 24) {
  88753. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88754. return false;
  88755. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88756. return true;
  88757. }
  88758. else if(x < 64) {
  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 {
  88764. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, 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. if(wasted_bits && do_full_decode) {
  88770. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88771. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88772. decoder->private_->output[channel][i] <<= x;
  88773. }
  88774. return true;
  88775. }
  88776. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88777. {
  88778. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88779. FLAC__int32 x;
  88780. unsigned i;
  88781. FLAC__int32 *output = decoder->private_->output[channel];
  88782. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88783. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88784. return false; /* read_callback_ sets the state for us */
  88785. subframe->value = x;
  88786. if(do_full_decode) {
  88787. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88788. output[i] = x;
  88789. }
  88790. return true;
  88791. }
  88792. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88793. {
  88794. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88795. FLAC__int32 i32;
  88796. FLAC__uint32 u32;
  88797. unsigned u;
  88798. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88799. subframe->residual = decoder->private_->residual[channel];
  88800. subframe->order = order;
  88801. for(u = 0; u < order; u++) {
  88802. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88803. return false; /* read_callback_ sets the state for us */
  88804. subframe->warmup[u] = i32;
  88805. }
  88806. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88807. return false; /* read_callback_ sets the state for us */
  88808. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88809. switch(subframe->entropy_coding_method.type) {
  88810. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88811. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88812. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88813. return false; /* read_callback_ sets the state for us */
  88814. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88815. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88816. break;
  88817. default:
  88818. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88819. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88820. return true;
  88821. }
  88822. switch(subframe->entropy_coding_method.type) {
  88823. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88824. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88825. 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))
  88826. return false;
  88827. break;
  88828. default:
  88829. FLAC__ASSERT(0);
  88830. }
  88831. if(do_full_decode) {
  88832. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88833. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88834. }
  88835. return true;
  88836. }
  88837. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88838. {
  88839. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88840. FLAC__int32 i32;
  88841. FLAC__uint32 u32;
  88842. unsigned u;
  88843. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88844. subframe->residual = decoder->private_->residual[channel];
  88845. subframe->order = order;
  88846. for(u = 0; u < order; u++) {
  88847. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88848. return false; /* read_callback_ sets the state for us */
  88849. subframe->warmup[u] = i32;
  88850. }
  88851. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88852. return false; /* read_callback_ sets the state for us */
  88853. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88854. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88855. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88856. return true;
  88857. }
  88858. subframe->qlp_coeff_precision = u32+1;
  88859. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88860. return false; /* read_callback_ sets the state for us */
  88861. subframe->quantization_level = i32;
  88862. for(u = 0; u < order; u++) {
  88863. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88864. return false; /* read_callback_ sets the state for us */
  88865. subframe->qlp_coeff[u] = i32;
  88866. }
  88867. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88868. return false; /* read_callback_ sets the state for us */
  88869. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88870. switch(subframe->entropy_coding_method.type) {
  88871. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88872. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88873. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88874. return false; /* read_callback_ sets the state for us */
  88875. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88876. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88877. break;
  88878. default:
  88879. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88880. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88881. return true;
  88882. }
  88883. switch(subframe->entropy_coding_method.type) {
  88884. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88885. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88886. 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))
  88887. return false;
  88888. break;
  88889. default:
  88890. FLAC__ASSERT(0);
  88891. }
  88892. if(do_full_decode) {
  88893. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88894. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  88895. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  88896. if(order <= 8)
  88897. 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);
  88898. else
  88899. 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);
  88900. }
  88901. else
  88902. 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);
  88903. else
  88904. 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);
  88905. }
  88906. return true;
  88907. }
  88908. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88909. {
  88910. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  88911. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  88912. unsigned i;
  88913. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  88914. subframe->data = residual;
  88915. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88916. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88917. return false; /* read_callback_ sets the state for us */
  88918. residual[i] = x;
  88919. }
  88920. if(do_full_decode)
  88921. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88922. return true;
  88923. }
  88924. 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)
  88925. {
  88926. FLAC__uint32 rice_parameter;
  88927. int i;
  88928. unsigned partition, sample, u;
  88929. const unsigned partitions = 1u << partition_order;
  88930. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  88931. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  88932. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  88933. if(partition_order == 0) {
  88934. if(decoder->private_->frame.header.blocksize < predictor_order) {
  88935. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88936. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88937. return true;
  88938. }
  88939. }
  88940. else {
  88941. if(partition_samples < predictor_order) {
  88942. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88943. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88944. return true;
  88945. }
  88946. }
  88947. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  88948. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88949. return false;
  88950. }
  88951. sample = 0;
  88952. for(partition = 0; partition < partitions; partition++) {
  88953. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  88954. return false; /* read_callback_ sets the state for us */
  88955. partitioned_rice_contents->parameters[partition] = rice_parameter;
  88956. if(rice_parameter < pesc) {
  88957. partitioned_rice_contents->raw_bits[partition] = 0;
  88958. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  88959. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  88960. return false; /* read_callback_ sets the state for us */
  88961. sample += u;
  88962. }
  88963. else {
  88964. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  88965. return false; /* read_callback_ sets the state for us */
  88966. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  88967. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  88968. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  88969. return false; /* read_callback_ sets the state for us */
  88970. residual[sample] = i;
  88971. }
  88972. }
  88973. }
  88974. return true;
  88975. }
  88976. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  88977. {
  88978. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88979. FLAC__uint32 zero = 0;
  88980. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88981. return false; /* read_callback_ sets the state for us */
  88982. if(zero != 0) {
  88983. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88984. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88985. }
  88986. }
  88987. return true;
  88988. }
  88989. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  88990. {
  88991. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  88992. if(
  88993. #if FLAC__HAS_OGG
  88994. !decoder->private_->is_ogg &&
  88995. #endif
  88996. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88997. ) {
  88998. *bytes = 0;
  88999. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89000. return false;
  89001. }
  89002. else if(*bytes > 0) {
  89003. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89004. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89005. return false;
  89006. }
  89007. else {
  89008. const FLAC__StreamDecoderReadStatus status =
  89009. #if FLAC__HAS_OGG
  89010. decoder->private_->is_ogg?
  89011. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89012. #endif
  89013. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89014. ;
  89015. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89016. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89017. return false;
  89018. }
  89019. else if(*bytes == 0) {
  89020. if(
  89021. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89022. (
  89023. #if FLAC__HAS_OGG
  89024. !decoder->private_->is_ogg &&
  89025. #endif
  89026. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89027. )
  89028. ) {
  89029. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89030. return false;
  89031. }
  89032. else
  89033. return true;
  89034. }
  89035. else
  89036. return true;
  89037. }
  89038. }
  89039. else {
  89040. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89041. return false;
  89042. }
  89043. }
  89044. #if FLAC__HAS_OGG
  89045. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89046. {
  89047. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89048. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89049. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89050. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89051. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89052. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89053. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89054. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89055. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89056. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89057. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89058. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89059. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89060. default:
  89061. FLAC__ASSERT(0);
  89062. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89063. }
  89064. }
  89065. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89066. {
  89067. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89068. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89069. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89070. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89071. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89072. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89073. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89074. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89075. default:
  89076. FLAC__ASSERT(0);
  89077. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89078. }
  89079. }
  89080. #endif
  89081. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89082. {
  89083. if(decoder->private_->is_seeking) {
  89084. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89085. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89086. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89087. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89088. #if FLAC__HAS_OGG
  89089. decoder->private_->got_a_frame = true;
  89090. #endif
  89091. decoder->private_->last_frame = *frame; /* save the frame */
  89092. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89093. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89094. decoder->private_->is_seeking = false;
  89095. if(delta > 0) {
  89096. unsigned channel;
  89097. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89098. for(channel = 0; channel < frame->header.channels; channel++)
  89099. newbuffer[channel] = buffer[channel] + delta;
  89100. decoder->private_->last_frame.header.blocksize -= delta;
  89101. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89102. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89103. }
  89104. else {
  89105. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89106. }
  89107. }
  89108. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89109. }
  89110. if(!decoder->private_->has_stream_info)
  89111. decoder->private_->do_md5_checking = false;
  89112. if(decoder->private_->do_md5_checking) {
  89113. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89114. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89115. }
  89116. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89117. }
  89118. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89119. {
  89120. if(!decoder->private_->is_seeking)
  89121. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89122. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89123. decoder->private_->unparseable_frame_count++;
  89124. }
  89125. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89126. {
  89127. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89128. FLAC__int64 pos = -1;
  89129. int i;
  89130. unsigned approx_bytes_per_frame;
  89131. FLAC__bool first_seek = true;
  89132. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89133. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89134. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89135. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89136. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89137. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89138. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89139. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89140. if(channels == 0)
  89141. channels = decoder->private_->stream_info.data.stream_info.channels;
  89142. if(bps == 0)
  89143. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89144. if(max_framesize > 0)
  89145. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89146. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89147. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89148. }
  89149. else
  89150. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89151. lower_bound = first_frame_offset;
  89152. lower_bound_sample = 0;
  89153. upper_bound = stream_length;
  89154. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89155. if(seek_table) {
  89156. FLAC__uint64 new_lower_bound = lower_bound;
  89157. FLAC__uint64 new_upper_bound = upper_bound;
  89158. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89159. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89160. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89161. if(
  89162. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89163. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89164. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89165. seek_table->points[i].sample_number <= target_sample
  89166. )
  89167. break;
  89168. }
  89169. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89170. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89171. new_lower_bound_sample = seek_table->points[i].sample_number;
  89172. }
  89173. for(i = 0; i < (int)seek_table->num_points; i++) {
  89174. if(
  89175. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89176. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89177. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89178. seek_table->points[i].sample_number > target_sample
  89179. )
  89180. break;
  89181. }
  89182. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89183. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89184. new_upper_bound_sample = seek_table->points[i].sample_number;
  89185. }
  89186. if(new_upper_bound >= new_lower_bound) {
  89187. lower_bound = new_lower_bound;
  89188. upper_bound = new_upper_bound;
  89189. lower_bound_sample = new_lower_bound_sample;
  89190. upper_bound_sample = new_upper_bound_sample;
  89191. }
  89192. }
  89193. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89194. if(upper_bound_sample == lower_bound_sample)
  89195. upper_bound_sample++;
  89196. decoder->private_->target_sample = target_sample;
  89197. while(1) {
  89198. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89199. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89200. return false;
  89201. }
  89202. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89203. #if defined _MSC_VER || defined __MINGW32__
  89204. 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;
  89205. #else
  89206. 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;
  89207. #endif
  89208. #else
  89209. if(upper_bound - lower_bound < 0xffffffff)
  89210. 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;
  89211. else /* @@@ WATCHOUT, ~2TB limit */
  89212. 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;
  89213. #endif
  89214. if(pos >= (FLAC__int64)upper_bound)
  89215. pos = (FLAC__int64)upper_bound - 1;
  89216. if(pos < (FLAC__int64)lower_bound)
  89217. pos = (FLAC__int64)lower_bound;
  89218. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89219. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89220. return false;
  89221. }
  89222. if(!FLAC__stream_decoder_flush(decoder)) {
  89223. return false;
  89224. }
  89225. decoder->private_->unparseable_frame_count = 0;
  89226. if(!FLAC__stream_decoder_process_single(decoder)) {
  89227. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89228. return false;
  89229. }
  89230. #if 0
  89231. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89232. break;
  89233. #endif
  89234. if(!decoder->private_->is_seeking)
  89235. break;
  89236. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89237. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89238. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89239. if (pos == (FLAC__int64)lower_bound) {
  89240. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89241. return false;
  89242. }
  89243. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89244. continue;
  89245. }
  89246. first_seek = false;
  89247. if (this_frame_sample < lower_bound_sample) {
  89248. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89249. return false;
  89250. }
  89251. if(target_sample < this_frame_sample) {
  89252. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89253. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89254. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89255. return false;
  89256. }
  89257. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89258. }
  89259. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89260. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89261. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89262. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89263. return false;
  89264. }
  89265. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89266. }
  89267. }
  89268. return true;
  89269. }
  89270. #if FLAC__HAS_OGG
  89271. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89272. {
  89273. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89274. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89275. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89276. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89277. FLAC__bool did_a_seek;
  89278. unsigned iteration = 0;
  89279. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89280. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89281. if(right_sample == 0) {
  89282. right_sample = (FLAC__uint64)(-1);
  89283. BINARY_SEARCH_AFTER_ITERATION = 0;
  89284. }
  89285. decoder->private_->target_sample = target_sample;
  89286. for( ; ; iteration++) {
  89287. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89288. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89289. pos = (right_pos + left_pos) / 2;
  89290. }
  89291. else {
  89292. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89293. #if defined _MSC_VER || defined __MINGW32__
  89294. 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));
  89295. #else
  89296. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89297. #endif
  89298. #else
  89299. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89300. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89301. else /* @@@ WATCHOUT, ~2TB limit */
  89302. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89303. #endif
  89304. }
  89305. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89306. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89307. return false;
  89308. }
  89309. if(!FLAC__stream_decoder_flush(decoder)) {
  89310. return false;
  89311. }
  89312. did_a_seek = true;
  89313. }
  89314. else
  89315. did_a_seek = false;
  89316. decoder->private_->got_a_frame = false;
  89317. if(!FLAC__stream_decoder_process_single(decoder)) {
  89318. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89319. return false;
  89320. }
  89321. if(!decoder->private_->got_a_frame) {
  89322. if(did_a_seek) {
  89323. right_pos = pos;
  89324. BINARY_SEARCH_AFTER_ITERATION = 0;
  89325. }
  89326. else {
  89327. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89328. return false;
  89329. }
  89330. }
  89331. else if(!decoder->private_->is_seeking) {
  89332. break;
  89333. }
  89334. else {
  89335. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89336. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89337. if (did_a_seek) {
  89338. if (this_frame_sample <= target_sample) {
  89339. FLAC__ASSERT(this_frame_sample != target_sample);
  89340. left_sample = this_frame_sample;
  89341. if (left_pos == pos) {
  89342. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89343. return false;
  89344. }
  89345. left_pos = pos;
  89346. }
  89347. else if(this_frame_sample > target_sample) {
  89348. right_sample = this_frame_sample;
  89349. if (right_pos == pos) {
  89350. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89351. return false;
  89352. }
  89353. right_pos = pos;
  89354. }
  89355. }
  89356. }
  89357. }
  89358. return true;
  89359. }
  89360. #endif
  89361. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89362. {
  89363. (void)client_data;
  89364. if(*bytes > 0) {
  89365. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89366. if(ferror(decoder->private_->file))
  89367. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89368. else if(*bytes == 0)
  89369. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89370. else
  89371. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89372. }
  89373. else
  89374. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89375. }
  89376. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89377. {
  89378. (void)client_data;
  89379. if(decoder->private_->file == stdin)
  89380. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89381. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89382. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89383. else
  89384. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89385. }
  89386. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89387. {
  89388. off_t pos;
  89389. (void)client_data;
  89390. if(decoder->private_->file == stdin)
  89391. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89392. else if((pos = ftello(decoder->private_->file)) < 0)
  89393. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89394. else {
  89395. *absolute_byte_offset = (FLAC__uint64)pos;
  89396. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89397. }
  89398. }
  89399. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89400. {
  89401. struct stat filestats;
  89402. (void)client_data;
  89403. if(decoder->private_->file == stdin)
  89404. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89405. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89406. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89407. else {
  89408. *stream_length = (FLAC__uint64)filestats.st_size;
  89409. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89410. }
  89411. }
  89412. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89413. {
  89414. (void)client_data;
  89415. return feof(decoder->private_->file)? true : false;
  89416. }
  89417. #endif
  89418. /*** End of inlined file: stream_decoder.c ***/
  89419. /*** Start of inlined file: stream_encoder.c ***/
  89420. /*** Start of inlined file: juce_FlacHeader.h ***/
  89421. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89422. // tasks..
  89423. #define VERSION "1.2.1"
  89424. #define FLAC__NO_DLL 1
  89425. #if JUCE_MSVC
  89426. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89427. #endif
  89428. #if JUCE_MAC
  89429. #define FLAC__SYS_DARWIN 1
  89430. #endif
  89431. /*** End of inlined file: juce_FlacHeader.h ***/
  89432. #if JUCE_USE_FLAC
  89433. #if HAVE_CONFIG_H
  89434. # include <config.h>
  89435. #endif
  89436. #if defined _MSC_VER || defined __MINGW32__
  89437. #include <io.h> /* for _setmode() */
  89438. #include <fcntl.h> /* for _O_BINARY */
  89439. #endif
  89440. #if defined __CYGWIN__ || defined __EMX__
  89441. #include <io.h> /* for setmode(), O_BINARY */
  89442. #include <fcntl.h> /* for _O_BINARY */
  89443. #endif
  89444. #include <limits.h>
  89445. #include <stdio.h>
  89446. #include <stdlib.h> /* for malloc() */
  89447. #include <string.h> /* for memcpy() */
  89448. #include <sys/types.h> /* for off_t */
  89449. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89450. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89451. #define fseeko fseek
  89452. #define ftello ftell
  89453. #endif
  89454. #endif
  89455. /*** Start of inlined file: stream_encoder.h ***/
  89456. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89457. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89458. #if FLAC__HAS_OGG
  89459. #include "private/ogg_encoder_aspect.h"
  89460. #endif
  89461. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89462. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89463. typedef enum {
  89464. FLAC__APODIZATION_BARTLETT,
  89465. FLAC__APODIZATION_BARTLETT_HANN,
  89466. FLAC__APODIZATION_BLACKMAN,
  89467. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89468. FLAC__APODIZATION_CONNES,
  89469. FLAC__APODIZATION_FLATTOP,
  89470. FLAC__APODIZATION_GAUSS,
  89471. FLAC__APODIZATION_HAMMING,
  89472. FLAC__APODIZATION_HANN,
  89473. FLAC__APODIZATION_KAISER_BESSEL,
  89474. FLAC__APODIZATION_NUTTALL,
  89475. FLAC__APODIZATION_RECTANGLE,
  89476. FLAC__APODIZATION_TRIANGLE,
  89477. FLAC__APODIZATION_TUKEY,
  89478. FLAC__APODIZATION_WELCH
  89479. } FLAC__ApodizationFunction;
  89480. typedef struct {
  89481. FLAC__ApodizationFunction type;
  89482. union {
  89483. struct {
  89484. FLAC__real stddev;
  89485. } gauss;
  89486. struct {
  89487. FLAC__real p;
  89488. } tukey;
  89489. } parameters;
  89490. } FLAC__ApodizationSpecification;
  89491. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89492. typedef struct FLAC__StreamEncoderProtected {
  89493. FLAC__StreamEncoderState state;
  89494. FLAC__bool verify;
  89495. FLAC__bool streamable_subset;
  89496. FLAC__bool do_md5;
  89497. FLAC__bool do_mid_side_stereo;
  89498. FLAC__bool loose_mid_side_stereo;
  89499. unsigned channels;
  89500. unsigned bits_per_sample;
  89501. unsigned sample_rate;
  89502. unsigned blocksize;
  89503. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89504. unsigned num_apodizations;
  89505. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89506. #endif
  89507. unsigned max_lpc_order;
  89508. unsigned qlp_coeff_precision;
  89509. FLAC__bool do_qlp_coeff_prec_search;
  89510. FLAC__bool do_exhaustive_model_search;
  89511. FLAC__bool do_escape_coding;
  89512. unsigned min_residual_partition_order;
  89513. unsigned max_residual_partition_order;
  89514. unsigned rice_parameter_search_dist;
  89515. FLAC__uint64 total_samples_estimate;
  89516. FLAC__StreamMetadata **metadata;
  89517. unsigned num_metadata_blocks;
  89518. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89519. #if FLAC__HAS_OGG
  89520. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89521. #endif
  89522. } FLAC__StreamEncoderProtected;
  89523. #endif
  89524. /*** End of inlined file: stream_encoder.h ***/
  89525. #if FLAC__HAS_OGG
  89526. #include "include/private/ogg_helper.h"
  89527. #include "include/private/ogg_mapping.h"
  89528. #endif
  89529. /*** Start of inlined file: stream_encoder_framing.h ***/
  89530. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89531. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89532. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89533. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89534. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89535. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89536. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89537. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89538. #endif
  89539. /*** End of inlined file: stream_encoder_framing.h ***/
  89540. /*** Start of inlined file: window.h ***/
  89541. #ifndef FLAC__PRIVATE__WINDOW_H
  89542. #define FLAC__PRIVATE__WINDOW_H
  89543. #ifdef HAVE_CONFIG_H
  89544. #include <config.h>
  89545. #endif
  89546. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89547. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89548. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89549. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89550. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89551. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89552. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89553. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89554. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89555. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89556. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89557. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89558. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89559. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89560. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89561. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89562. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89563. #endif
  89564. /*** End of inlined file: window.h ***/
  89565. #ifndef FLaC__INLINE
  89566. #define FLaC__INLINE
  89567. #endif
  89568. #ifdef min
  89569. #undef min
  89570. #endif
  89571. #define min(x,y) ((x)<(y)?(x):(y))
  89572. #ifdef max
  89573. #undef max
  89574. #endif
  89575. #define max(x,y) ((x)>(y)?(x):(y))
  89576. #undef EXACT_RICE_BITS_CALCULATION
  89577. #undef ENABLE_RICE_PARAMETER_SEARCH
  89578. typedef struct {
  89579. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89580. unsigned size; /* of each data[] in samples */
  89581. unsigned tail;
  89582. } verify_input_fifo;
  89583. typedef struct {
  89584. const FLAC__byte *data;
  89585. unsigned capacity;
  89586. unsigned bytes;
  89587. } verify_output;
  89588. typedef enum {
  89589. ENCODER_IN_MAGIC = 0,
  89590. ENCODER_IN_METADATA = 1,
  89591. ENCODER_IN_AUDIO = 2
  89592. } EncoderStateHint;
  89593. static struct CompressionLevels {
  89594. FLAC__bool do_mid_side_stereo;
  89595. FLAC__bool loose_mid_side_stereo;
  89596. unsigned max_lpc_order;
  89597. unsigned qlp_coeff_precision;
  89598. FLAC__bool do_qlp_coeff_prec_search;
  89599. FLAC__bool do_escape_coding;
  89600. FLAC__bool do_exhaustive_model_search;
  89601. unsigned min_residual_partition_order;
  89602. unsigned max_residual_partition_order;
  89603. unsigned rice_parameter_search_dist;
  89604. } compression_levels_[] = {
  89605. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89606. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89607. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89608. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89609. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89610. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89611. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89612. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89613. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89614. };
  89615. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89616. static void free_(FLAC__StreamEncoder *encoder);
  89617. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89618. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89619. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89620. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89621. #if FLAC__HAS_OGG
  89622. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89623. #endif
  89624. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89625. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89626. static FLAC__bool process_subframe_(
  89627. FLAC__StreamEncoder *encoder,
  89628. unsigned min_partition_order,
  89629. unsigned max_partition_order,
  89630. const FLAC__FrameHeader *frame_header,
  89631. unsigned subframe_bps,
  89632. const FLAC__int32 integer_signal[],
  89633. FLAC__Subframe *subframe[2],
  89634. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89635. FLAC__int32 *residual[2],
  89636. unsigned *best_subframe,
  89637. unsigned *best_bits
  89638. );
  89639. static FLAC__bool add_subframe_(
  89640. FLAC__StreamEncoder *encoder,
  89641. unsigned blocksize,
  89642. unsigned subframe_bps,
  89643. const FLAC__Subframe *subframe,
  89644. FLAC__BitWriter *frame
  89645. );
  89646. static unsigned evaluate_constant_subframe_(
  89647. FLAC__StreamEncoder *encoder,
  89648. const FLAC__int32 signal,
  89649. unsigned blocksize,
  89650. unsigned subframe_bps,
  89651. FLAC__Subframe *subframe
  89652. );
  89653. static unsigned evaluate_fixed_subframe_(
  89654. FLAC__StreamEncoder *encoder,
  89655. const FLAC__int32 signal[],
  89656. FLAC__int32 residual[],
  89657. FLAC__uint64 abs_residual_partition_sums[],
  89658. unsigned raw_bits_per_partition[],
  89659. unsigned blocksize,
  89660. unsigned subframe_bps,
  89661. unsigned order,
  89662. unsigned rice_parameter,
  89663. unsigned rice_parameter_limit,
  89664. unsigned min_partition_order,
  89665. unsigned max_partition_order,
  89666. FLAC__bool do_escape_coding,
  89667. unsigned rice_parameter_search_dist,
  89668. FLAC__Subframe *subframe,
  89669. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89670. );
  89671. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89672. static unsigned evaluate_lpc_subframe_(
  89673. FLAC__StreamEncoder *encoder,
  89674. const FLAC__int32 signal[],
  89675. FLAC__int32 residual[],
  89676. FLAC__uint64 abs_residual_partition_sums[],
  89677. unsigned raw_bits_per_partition[],
  89678. const FLAC__real lp_coeff[],
  89679. unsigned blocksize,
  89680. unsigned subframe_bps,
  89681. unsigned order,
  89682. unsigned qlp_coeff_precision,
  89683. unsigned rice_parameter,
  89684. unsigned rice_parameter_limit,
  89685. unsigned min_partition_order,
  89686. unsigned max_partition_order,
  89687. FLAC__bool do_escape_coding,
  89688. unsigned rice_parameter_search_dist,
  89689. FLAC__Subframe *subframe,
  89690. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89691. );
  89692. #endif
  89693. static unsigned evaluate_verbatim_subframe_(
  89694. FLAC__StreamEncoder *encoder,
  89695. const FLAC__int32 signal[],
  89696. unsigned blocksize,
  89697. unsigned subframe_bps,
  89698. FLAC__Subframe *subframe
  89699. );
  89700. static unsigned find_best_partition_order_(
  89701. struct FLAC__StreamEncoderPrivate *private_,
  89702. const FLAC__int32 residual[],
  89703. FLAC__uint64 abs_residual_partition_sums[],
  89704. unsigned raw_bits_per_partition[],
  89705. unsigned residual_samples,
  89706. unsigned predictor_order,
  89707. unsigned rice_parameter,
  89708. unsigned rice_parameter_limit,
  89709. unsigned min_partition_order,
  89710. unsigned max_partition_order,
  89711. unsigned bps,
  89712. FLAC__bool do_escape_coding,
  89713. unsigned rice_parameter_search_dist,
  89714. FLAC__EntropyCodingMethod *best_ecm
  89715. );
  89716. static void precompute_partition_info_sums_(
  89717. const FLAC__int32 residual[],
  89718. FLAC__uint64 abs_residual_partition_sums[],
  89719. unsigned residual_samples,
  89720. unsigned predictor_order,
  89721. unsigned min_partition_order,
  89722. unsigned max_partition_order,
  89723. unsigned bps
  89724. );
  89725. static void precompute_partition_info_escapes_(
  89726. const FLAC__int32 residual[],
  89727. unsigned raw_bits_per_partition[],
  89728. unsigned residual_samples,
  89729. unsigned predictor_order,
  89730. unsigned min_partition_order,
  89731. unsigned max_partition_order
  89732. );
  89733. static FLAC__bool set_partitioned_rice_(
  89734. #ifdef EXACT_RICE_BITS_CALCULATION
  89735. const FLAC__int32 residual[],
  89736. #endif
  89737. const FLAC__uint64 abs_residual_partition_sums[],
  89738. const unsigned raw_bits_per_partition[],
  89739. const unsigned residual_samples,
  89740. const unsigned predictor_order,
  89741. const unsigned suggested_rice_parameter,
  89742. const unsigned rice_parameter_limit,
  89743. const unsigned rice_parameter_search_dist,
  89744. const unsigned partition_order,
  89745. const FLAC__bool search_for_escapes,
  89746. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89747. unsigned *bits
  89748. );
  89749. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89750. static void append_to_verify_fifo_(
  89751. verify_input_fifo *fifo,
  89752. const FLAC__int32 * const input[],
  89753. unsigned input_offset,
  89754. unsigned channels,
  89755. unsigned wide_samples
  89756. );
  89757. static void append_to_verify_fifo_interleaved_(
  89758. verify_input_fifo *fifo,
  89759. const FLAC__int32 input[],
  89760. unsigned input_offset,
  89761. unsigned channels,
  89762. unsigned wide_samples
  89763. );
  89764. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89765. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89766. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89767. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89768. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89769. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89770. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89771. 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);
  89772. static FILE *get_binary_stdout_(void);
  89773. typedef struct FLAC__StreamEncoderPrivate {
  89774. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89775. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89776. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89777. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89778. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89779. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89780. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89781. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89782. #endif
  89783. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89784. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89785. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89786. FLAC__int32 *residual_workspace_mid_side[2][2];
  89787. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89788. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89789. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89790. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89791. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89792. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89793. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89794. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89795. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89796. unsigned best_subframe_mid_side[2];
  89797. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89798. unsigned best_subframe_bits_mid_side[2];
  89799. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89800. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89801. FLAC__BitWriter *frame; /* the current frame being worked on */
  89802. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89803. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89804. FLAC__ChannelAssignment last_channel_assignment;
  89805. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89806. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89807. unsigned current_sample_number;
  89808. unsigned current_frame_number;
  89809. FLAC__MD5Context md5context;
  89810. FLAC__CPUInfo cpuinfo;
  89811. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89812. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89813. #else
  89814. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89815. #endif
  89816. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89817. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89818. 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[]);
  89819. 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[]);
  89820. 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[]);
  89821. #endif
  89822. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89823. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89824. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89825. FLAC__bool disable_constant_subframes;
  89826. FLAC__bool disable_fixed_subframes;
  89827. FLAC__bool disable_verbatim_subframes;
  89828. #if FLAC__HAS_OGG
  89829. FLAC__bool is_ogg;
  89830. #endif
  89831. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89832. FLAC__StreamEncoderSeekCallback seek_callback;
  89833. FLAC__StreamEncoderTellCallback tell_callback;
  89834. FLAC__StreamEncoderWriteCallback write_callback;
  89835. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89836. FLAC__StreamEncoderProgressCallback progress_callback;
  89837. void *client_data;
  89838. unsigned first_seekpoint_to_check;
  89839. FILE *file; /* only used when encoding to a file */
  89840. FLAC__uint64 bytes_written;
  89841. FLAC__uint64 samples_written;
  89842. unsigned frames_written;
  89843. unsigned total_frames_estimate;
  89844. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89845. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89846. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89847. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89848. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89849. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89850. FLAC__real *windowed_signal_unaligned;
  89851. #endif
  89852. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89853. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89854. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89855. unsigned *raw_bits_per_partition_unaligned;
  89856. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89857. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89858. #endif
  89859. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89860. struct {
  89861. FLAC__StreamDecoder *decoder;
  89862. EncoderStateHint state_hint;
  89863. FLAC__bool needs_magic_hack;
  89864. verify_input_fifo input_fifo;
  89865. verify_output output;
  89866. struct {
  89867. FLAC__uint64 absolute_sample;
  89868. unsigned frame_number;
  89869. unsigned channel;
  89870. unsigned sample;
  89871. FLAC__int32 expected;
  89872. FLAC__int32 got;
  89873. } error_stats;
  89874. } verify;
  89875. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89876. } FLAC__StreamEncoderPrivate;
  89877. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89878. "FLAC__STREAM_ENCODER_OK",
  89879. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89880. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89881. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89882. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89883. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89884. "FLAC__STREAM_ENCODER_IO_ERROR",
  89885. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89886. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89887. };
  89888. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89889. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89890. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89891. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89892. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89893. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89894. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  89895. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  89896. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  89897. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  89898. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  89899. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  89900. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  89901. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  89902. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  89903. };
  89904. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  89905. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  89906. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  89907. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  89908. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  89909. };
  89910. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  89911. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  89912. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  89913. };
  89914. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  89915. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  89916. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  89917. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  89918. };
  89919. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  89920. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  89921. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  89922. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  89923. };
  89924. static const unsigned OVERREAD_ = 1;
  89925. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  89926. {
  89927. FLAC__StreamEncoder *encoder;
  89928. unsigned i;
  89929. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  89930. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  89931. if(encoder == 0) {
  89932. return 0;
  89933. }
  89934. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  89935. if(encoder->protected_ == 0) {
  89936. free(encoder);
  89937. return 0;
  89938. }
  89939. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  89940. if(encoder->private_ == 0) {
  89941. free(encoder->protected_);
  89942. free(encoder);
  89943. return 0;
  89944. }
  89945. encoder->private_->frame = FLAC__bitwriter_new();
  89946. if(encoder->private_->frame == 0) {
  89947. free(encoder->private_);
  89948. free(encoder->protected_);
  89949. free(encoder);
  89950. return 0;
  89951. }
  89952. encoder->private_->file = 0;
  89953. set_defaults_enc(encoder);
  89954. encoder->private_->is_being_deleted = false;
  89955. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89956. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  89957. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  89958. }
  89959. for(i = 0; i < 2; i++) {
  89960. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  89961. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  89962. }
  89963. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89964. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  89965. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  89966. }
  89967. for(i = 0; i < 2; i++) {
  89968. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  89969. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  89970. }
  89971. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89972. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89973. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89974. }
  89975. for(i = 0; i < 2; i++) {
  89976. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89977. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89978. }
  89979. for(i = 0; i < 2; i++)
  89980. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  89981. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  89982. return encoder;
  89983. }
  89984. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  89985. {
  89986. unsigned i;
  89987. FLAC__ASSERT(0 != encoder);
  89988. FLAC__ASSERT(0 != encoder->protected_);
  89989. FLAC__ASSERT(0 != encoder->private_);
  89990. FLAC__ASSERT(0 != encoder->private_->frame);
  89991. encoder->private_->is_being_deleted = true;
  89992. (void)FLAC__stream_encoder_finish(encoder);
  89993. if(0 != encoder->private_->verify.decoder)
  89994. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  89995. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89996. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89997. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89998. }
  89999. for(i = 0; i < 2; i++) {
  90000. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90001. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90002. }
  90003. for(i = 0; i < 2; i++)
  90004. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90005. FLAC__bitwriter_delete(encoder->private_->frame);
  90006. free(encoder->private_);
  90007. free(encoder->protected_);
  90008. free(encoder);
  90009. }
  90010. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90011. FLAC__StreamEncoder *encoder,
  90012. FLAC__StreamEncoderReadCallback read_callback,
  90013. FLAC__StreamEncoderWriteCallback write_callback,
  90014. FLAC__StreamEncoderSeekCallback seek_callback,
  90015. FLAC__StreamEncoderTellCallback tell_callback,
  90016. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90017. void *client_data,
  90018. FLAC__bool is_ogg
  90019. )
  90020. {
  90021. unsigned i;
  90022. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90023. FLAC__ASSERT(0 != encoder);
  90024. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90025. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90026. #if !FLAC__HAS_OGG
  90027. if(is_ogg)
  90028. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90029. #endif
  90030. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90031. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90032. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90033. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90034. if(encoder->protected_->channels != 2) {
  90035. encoder->protected_->do_mid_side_stereo = false;
  90036. encoder->protected_->loose_mid_side_stereo = false;
  90037. }
  90038. else if(!encoder->protected_->do_mid_side_stereo)
  90039. encoder->protected_->loose_mid_side_stereo = false;
  90040. if(encoder->protected_->bits_per_sample >= 32)
  90041. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90042. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90043. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90044. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90045. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90046. if(encoder->protected_->blocksize == 0) {
  90047. if(encoder->protected_->max_lpc_order == 0)
  90048. encoder->protected_->blocksize = 1152;
  90049. else
  90050. encoder->protected_->blocksize = 4096;
  90051. }
  90052. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90053. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90054. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90055. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90056. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90057. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90058. if(encoder->protected_->qlp_coeff_precision == 0) {
  90059. if(encoder->protected_->bits_per_sample < 16) {
  90060. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90061. }
  90062. else if(encoder->protected_->bits_per_sample == 16) {
  90063. if(encoder->protected_->blocksize <= 192)
  90064. encoder->protected_->qlp_coeff_precision = 7;
  90065. else if(encoder->protected_->blocksize <= 384)
  90066. encoder->protected_->qlp_coeff_precision = 8;
  90067. else if(encoder->protected_->blocksize <= 576)
  90068. encoder->protected_->qlp_coeff_precision = 9;
  90069. else if(encoder->protected_->blocksize <= 1152)
  90070. encoder->protected_->qlp_coeff_precision = 10;
  90071. else if(encoder->protected_->blocksize <= 2304)
  90072. encoder->protected_->qlp_coeff_precision = 11;
  90073. else if(encoder->protected_->blocksize <= 4608)
  90074. encoder->protected_->qlp_coeff_precision = 12;
  90075. else
  90076. encoder->protected_->qlp_coeff_precision = 13;
  90077. }
  90078. else {
  90079. if(encoder->protected_->blocksize <= 384)
  90080. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90081. else if(encoder->protected_->blocksize <= 1152)
  90082. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90083. else
  90084. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90085. }
  90086. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90087. }
  90088. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90089. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90090. if(encoder->protected_->streamable_subset) {
  90091. if(
  90092. encoder->protected_->blocksize != 192 &&
  90093. encoder->protected_->blocksize != 576 &&
  90094. encoder->protected_->blocksize != 1152 &&
  90095. encoder->protected_->blocksize != 2304 &&
  90096. encoder->protected_->blocksize != 4608 &&
  90097. encoder->protected_->blocksize != 256 &&
  90098. encoder->protected_->blocksize != 512 &&
  90099. encoder->protected_->blocksize != 1024 &&
  90100. encoder->protected_->blocksize != 2048 &&
  90101. encoder->protected_->blocksize != 4096 &&
  90102. encoder->protected_->blocksize != 8192 &&
  90103. encoder->protected_->blocksize != 16384
  90104. )
  90105. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90106. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90107. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90108. if(
  90109. encoder->protected_->bits_per_sample != 8 &&
  90110. encoder->protected_->bits_per_sample != 12 &&
  90111. encoder->protected_->bits_per_sample != 16 &&
  90112. encoder->protected_->bits_per_sample != 20 &&
  90113. encoder->protected_->bits_per_sample != 24
  90114. )
  90115. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90116. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90117. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90118. if(
  90119. encoder->protected_->sample_rate <= 48000 &&
  90120. (
  90121. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90122. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90123. )
  90124. ) {
  90125. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90126. }
  90127. }
  90128. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90129. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90130. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90131. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90132. #if FLAC__HAS_OGG
  90133. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90134. unsigned i;
  90135. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90136. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90137. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90138. for( ; i > 0; i--)
  90139. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90140. encoder->protected_->metadata[0] = vc;
  90141. break;
  90142. }
  90143. }
  90144. }
  90145. #endif
  90146. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90147. unsigned i;
  90148. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90149. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90150. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90151. break; /* take only the first one */
  90152. }
  90153. }
  90154. }
  90155. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90156. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90157. metadata_has_seektable = false;
  90158. metadata_has_vorbis_comment = false;
  90159. metadata_picture_has_type1 = false;
  90160. metadata_picture_has_type2 = false;
  90161. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90162. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90163. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90164. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90165. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90166. if(metadata_has_seektable) /* only one is allowed */
  90167. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90168. metadata_has_seektable = true;
  90169. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90170. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90171. }
  90172. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90173. if(metadata_has_vorbis_comment) /* only one is allowed */
  90174. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90175. metadata_has_vorbis_comment = true;
  90176. }
  90177. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90178. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90179. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90180. }
  90181. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90182. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90183. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90184. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90185. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90186. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90187. metadata_picture_has_type1 = true;
  90188. if(
  90189. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90190. (
  90191. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90192. m->data.picture.width != 32 ||
  90193. m->data.picture.height != 32
  90194. )
  90195. )
  90196. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90197. }
  90198. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90199. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90200. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90201. metadata_picture_has_type2 = true;
  90202. }
  90203. }
  90204. }
  90205. encoder->private_->input_capacity = 0;
  90206. for(i = 0; i < encoder->protected_->channels; i++) {
  90207. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90208. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90209. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90210. #endif
  90211. }
  90212. for(i = 0; i < 2; i++) {
  90213. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90214. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90215. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90216. #endif
  90217. }
  90218. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90219. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90220. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90221. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90222. #endif
  90223. for(i = 0; i < encoder->protected_->channels; i++) {
  90224. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90225. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90226. encoder->private_->best_subframe[i] = 0;
  90227. }
  90228. for(i = 0; i < 2; i++) {
  90229. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90230. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90231. encoder->private_->best_subframe_mid_side[i] = 0;
  90232. }
  90233. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90234. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90235. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90236. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90237. #else
  90238. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90239. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90240. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90241. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90242. 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);
  90243. #endif
  90244. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90245. encoder->private_->loose_mid_side_stereo_frames = 1;
  90246. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90247. encoder->private_->current_sample_number = 0;
  90248. encoder->private_->current_frame_number = 0;
  90249. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90250. 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? */
  90251. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90252. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90253. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90254. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90255. #endif
  90256. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90257. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90258. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90259. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90260. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90261. #endif
  90262. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90263. # ifndef FLAC__NO_ASM
  90264. if(encoder->private_->cpuinfo.use_asm) {
  90265. # ifdef FLAC__CPU_IA32
  90266. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90267. # ifdef FLAC__HAS_NASM
  90268. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90269. if(encoder->protected_->max_lpc_order < 4)
  90270. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90271. else if(encoder->protected_->max_lpc_order < 8)
  90272. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90273. else if(encoder->protected_->max_lpc_order < 12)
  90274. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90275. else
  90276. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90277. }
  90278. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90279. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90280. else
  90281. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90282. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90283. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90284. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90285. }
  90286. else {
  90287. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90288. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90289. }
  90290. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90291. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90292. # endif /* FLAC__HAS_NASM */
  90293. # endif /* FLAC__CPU_IA32 */
  90294. }
  90295. # endif /* !FLAC__NO_ASM */
  90296. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90297. if(encoder->private_->use_wide_by_block) {
  90298. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90299. }
  90300. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90301. #if FLAC__HAS_OGG
  90302. encoder->private_->is_ogg = is_ogg;
  90303. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90304. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90305. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90306. }
  90307. #endif
  90308. encoder->private_->read_callback = read_callback;
  90309. encoder->private_->write_callback = write_callback;
  90310. encoder->private_->seek_callback = seek_callback;
  90311. encoder->private_->tell_callback = tell_callback;
  90312. encoder->private_->metadata_callback = metadata_callback;
  90313. encoder->private_->client_data = client_data;
  90314. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90315. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90316. }
  90317. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90318. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90319. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90320. }
  90321. if(encoder->protected_->verify) {
  90322. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90323. for(i = 0; i < encoder->protected_->channels; i++) {
  90324. 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))) {
  90325. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90326. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90327. }
  90328. }
  90329. encoder->private_->verify.input_fifo.tail = 0;
  90330. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90331. if(0 == encoder->private_->verify.decoder) {
  90332. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90333. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90334. }
  90335. 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) {
  90336. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90337. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90338. }
  90339. }
  90340. encoder->private_->verify.error_stats.absolute_sample = 0;
  90341. encoder->private_->verify.error_stats.frame_number = 0;
  90342. encoder->private_->verify.error_stats.channel = 0;
  90343. encoder->private_->verify.error_stats.sample = 0;
  90344. encoder->private_->verify.error_stats.expected = 0;
  90345. encoder->private_->verify.error_stats.got = 0;
  90346. encoder->private_->first_seekpoint_to_check = 0;
  90347. encoder->private_->samples_written = 0;
  90348. encoder->protected_->streaminfo_offset = 0;
  90349. encoder->protected_->seektable_offset = 0;
  90350. encoder->protected_->audio_offset = 0;
  90351. if(encoder->protected_->verify)
  90352. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90353. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90354. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90355. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90356. }
  90357. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90358. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90359. }
  90360. if(encoder->protected_->verify)
  90361. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90362. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90363. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90364. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90365. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90366. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90367. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90368. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90369. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90370. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90371. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90372. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90373. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90374. if(encoder->protected_->do_md5)
  90375. FLAC__MD5Init(&encoder->private_->md5context);
  90376. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90377. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90378. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90379. }
  90380. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90381. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90382. }
  90383. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90384. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90385. if(!metadata_has_vorbis_comment) {
  90386. FLAC__StreamMetadata vorbis_comment;
  90387. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90388. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90389. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90390. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90391. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90392. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90393. vorbis_comment.data.vorbis_comment.comments = 0;
  90394. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90395. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90396. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90397. }
  90398. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90399. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90400. }
  90401. }
  90402. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90403. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90404. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90405. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90406. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90407. }
  90408. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90409. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90410. }
  90411. }
  90412. 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 */
  90413. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90414. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90415. }
  90416. if(encoder->protected_->verify)
  90417. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90418. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90419. }
  90420. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90421. FLAC__StreamEncoder *encoder,
  90422. FLAC__StreamEncoderWriteCallback write_callback,
  90423. FLAC__StreamEncoderSeekCallback seek_callback,
  90424. FLAC__StreamEncoderTellCallback tell_callback,
  90425. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90426. void *client_data
  90427. )
  90428. {
  90429. return init_stream_internal_enc(
  90430. encoder,
  90431. 0,
  90432. write_callback,
  90433. seek_callback,
  90434. tell_callback,
  90435. metadata_callback,
  90436. client_data,
  90437. false
  90438. );
  90439. }
  90440. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90441. FLAC__StreamEncoder *encoder,
  90442. FLAC__StreamEncoderReadCallback read_callback,
  90443. FLAC__StreamEncoderWriteCallback write_callback,
  90444. FLAC__StreamEncoderSeekCallback seek_callback,
  90445. FLAC__StreamEncoderTellCallback tell_callback,
  90446. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90447. void *client_data
  90448. )
  90449. {
  90450. return init_stream_internal_enc(
  90451. encoder,
  90452. read_callback,
  90453. write_callback,
  90454. seek_callback,
  90455. tell_callback,
  90456. metadata_callback,
  90457. client_data,
  90458. true
  90459. );
  90460. }
  90461. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90462. FLAC__StreamEncoder *encoder,
  90463. FILE *file,
  90464. FLAC__StreamEncoderProgressCallback progress_callback,
  90465. void *client_data,
  90466. FLAC__bool is_ogg
  90467. )
  90468. {
  90469. FLAC__StreamEncoderInitStatus init_status;
  90470. FLAC__ASSERT(0 != encoder);
  90471. FLAC__ASSERT(0 != file);
  90472. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90473. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90474. if(file == 0) {
  90475. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90476. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90477. }
  90478. if(file == stdout)
  90479. file = get_binary_stdout_(); /* just to be safe */
  90480. encoder->private_->file = file;
  90481. encoder->private_->progress_callback = progress_callback;
  90482. encoder->private_->bytes_written = 0;
  90483. encoder->private_->samples_written = 0;
  90484. encoder->private_->frames_written = 0;
  90485. init_status = init_stream_internal_enc(
  90486. encoder,
  90487. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90488. file_write_callback_,
  90489. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90490. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90491. 0,
  90492. client_data,
  90493. is_ogg
  90494. );
  90495. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90496. return init_status;
  90497. }
  90498. {
  90499. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90500. FLAC__ASSERT(blocksize != 0);
  90501. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90502. }
  90503. return init_status;
  90504. }
  90505. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90506. FLAC__StreamEncoder *encoder,
  90507. FILE *file,
  90508. FLAC__StreamEncoderProgressCallback progress_callback,
  90509. void *client_data
  90510. )
  90511. {
  90512. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90513. }
  90514. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90515. FLAC__StreamEncoder *encoder,
  90516. FILE *file,
  90517. FLAC__StreamEncoderProgressCallback progress_callback,
  90518. void *client_data
  90519. )
  90520. {
  90521. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90522. }
  90523. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90524. FLAC__StreamEncoder *encoder,
  90525. const char *filename,
  90526. FLAC__StreamEncoderProgressCallback progress_callback,
  90527. void *client_data,
  90528. FLAC__bool is_ogg
  90529. )
  90530. {
  90531. FILE *file;
  90532. FLAC__ASSERT(0 != encoder);
  90533. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90534. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90535. file = filename? fopen(filename, "w+b") : stdout;
  90536. if(file == 0) {
  90537. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90538. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90539. }
  90540. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90541. }
  90542. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90543. FLAC__StreamEncoder *encoder,
  90544. const char *filename,
  90545. FLAC__StreamEncoderProgressCallback progress_callback,
  90546. void *client_data
  90547. )
  90548. {
  90549. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90550. }
  90551. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90552. FLAC__StreamEncoder *encoder,
  90553. const char *filename,
  90554. FLAC__StreamEncoderProgressCallback progress_callback,
  90555. void *client_data
  90556. )
  90557. {
  90558. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90559. }
  90560. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90561. {
  90562. FLAC__bool error = false;
  90563. FLAC__ASSERT(0 != encoder);
  90564. FLAC__ASSERT(0 != encoder->private_);
  90565. FLAC__ASSERT(0 != encoder->protected_);
  90566. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90567. return true;
  90568. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90569. if(encoder->private_->current_sample_number != 0) {
  90570. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90571. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90572. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90573. error = true;
  90574. }
  90575. }
  90576. if(encoder->protected_->do_md5)
  90577. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90578. if(!encoder->private_->is_being_deleted) {
  90579. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90580. if(encoder->private_->seek_callback) {
  90581. #if FLAC__HAS_OGG
  90582. if(encoder->private_->is_ogg)
  90583. update_ogg_metadata_(encoder);
  90584. else
  90585. #endif
  90586. update_metadata_(encoder);
  90587. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90588. error = true;
  90589. }
  90590. if(encoder->private_->metadata_callback)
  90591. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90592. }
  90593. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90594. if(!error)
  90595. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90596. error = true;
  90597. }
  90598. }
  90599. if(0 != encoder->private_->file) {
  90600. if(encoder->private_->file != stdout)
  90601. fclose(encoder->private_->file);
  90602. encoder->private_->file = 0;
  90603. }
  90604. #if FLAC__HAS_OGG
  90605. if(encoder->private_->is_ogg)
  90606. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90607. #endif
  90608. free_(encoder);
  90609. set_defaults_enc(encoder);
  90610. if(!error)
  90611. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90612. return !error;
  90613. }
  90614. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90615. {
  90616. FLAC__ASSERT(0 != encoder);
  90617. FLAC__ASSERT(0 != encoder->private_);
  90618. FLAC__ASSERT(0 != encoder->protected_);
  90619. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90620. return false;
  90621. #if FLAC__HAS_OGG
  90622. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90623. return true;
  90624. #else
  90625. (void)value;
  90626. return false;
  90627. #endif
  90628. }
  90629. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90630. {
  90631. FLAC__ASSERT(0 != encoder);
  90632. FLAC__ASSERT(0 != encoder->private_);
  90633. FLAC__ASSERT(0 != encoder->protected_);
  90634. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90635. return false;
  90636. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90637. encoder->protected_->verify = value;
  90638. #endif
  90639. return true;
  90640. }
  90641. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90642. {
  90643. FLAC__ASSERT(0 != encoder);
  90644. FLAC__ASSERT(0 != encoder->private_);
  90645. FLAC__ASSERT(0 != encoder->protected_);
  90646. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90647. return false;
  90648. encoder->protected_->streamable_subset = value;
  90649. return true;
  90650. }
  90651. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90652. {
  90653. FLAC__ASSERT(0 != encoder);
  90654. FLAC__ASSERT(0 != encoder->private_);
  90655. FLAC__ASSERT(0 != encoder->protected_);
  90656. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90657. return false;
  90658. encoder->protected_->do_md5 = value;
  90659. return true;
  90660. }
  90661. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90662. {
  90663. FLAC__ASSERT(0 != encoder);
  90664. FLAC__ASSERT(0 != encoder->private_);
  90665. FLAC__ASSERT(0 != encoder->protected_);
  90666. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90667. return false;
  90668. encoder->protected_->channels = value;
  90669. return true;
  90670. }
  90671. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90672. {
  90673. FLAC__ASSERT(0 != encoder);
  90674. FLAC__ASSERT(0 != encoder->private_);
  90675. FLAC__ASSERT(0 != encoder->protected_);
  90676. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90677. return false;
  90678. encoder->protected_->bits_per_sample = value;
  90679. return true;
  90680. }
  90681. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90682. {
  90683. FLAC__ASSERT(0 != encoder);
  90684. FLAC__ASSERT(0 != encoder->private_);
  90685. FLAC__ASSERT(0 != encoder->protected_);
  90686. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90687. return false;
  90688. encoder->protected_->sample_rate = value;
  90689. return true;
  90690. }
  90691. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90692. {
  90693. FLAC__bool ok = true;
  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. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90700. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90701. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90702. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90703. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90704. #if 0
  90705. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90706. #else
  90707. encoder->protected_->num_apodizations = 1;
  90708. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90709. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90710. #endif
  90711. #endif
  90712. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90713. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90714. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90715. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90716. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90717. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90718. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90719. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90720. return ok;
  90721. }
  90722. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90723. {
  90724. FLAC__ASSERT(0 != encoder);
  90725. FLAC__ASSERT(0 != encoder->private_);
  90726. FLAC__ASSERT(0 != encoder->protected_);
  90727. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90728. return false;
  90729. encoder->protected_->blocksize = value;
  90730. return true;
  90731. }
  90732. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90733. {
  90734. FLAC__ASSERT(0 != encoder);
  90735. FLAC__ASSERT(0 != encoder->private_);
  90736. FLAC__ASSERT(0 != encoder->protected_);
  90737. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90738. return false;
  90739. encoder->protected_->do_mid_side_stereo = value;
  90740. return true;
  90741. }
  90742. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90743. {
  90744. FLAC__ASSERT(0 != encoder);
  90745. FLAC__ASSERT(0 != encoder->private_);
  90746. FLAC__ASSERT(0 != encoder->protected_);
  90747. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90748. return false;
  90749. encoder->protected_->loose_mid_side_stereo = value;
  90750. return true;
  90751. }
  90752. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90753. {
  90754. FLAC__ASSERT(0 != encoder);
  90755. FLAC__ASSERT(0 != encoder->private_);
  90756. FLAC__ASSERT(0 != encoder->protected_);
  90757. FLAC__ASSERT(0 != specification);
  90758. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90759. return false;
  90760. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90761. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90762. #else
  90763. encoder->protected_->num_apodizations = 0;
  90764. while(1) {
  90765. const char *s = strchr(specification, ';');
  90766. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90767. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90768. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90769. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90770. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90771. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90772. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90773. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90774. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90775. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90776. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90777. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90778. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90779. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90780. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90781. if (stddev > 0.0 && stddev <= 0.5) {
  90782. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90783. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90784. }
  90785. }
  90786. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90787. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90788. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90789. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90790. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90791. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90792. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90793. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90794. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90795. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90796. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90797. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90798. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90799. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90800. if (p >= 0.0 && p <= 1.0) {
  90801. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90802. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90803. }
  90804. }
  90805. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90806. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90807. if (encoder->protected_->num_apodizations == 32)
  90808. break;
  90809. if (s)
  90810. specification = s+1;
  90811. else
  90812. break;
  90813. }
  90814. if(encoder->protected_->num_apodizations == 0) {
  90815. encoder->protected_->num_apodizations = 1;
  90816. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90817. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90818. }
  90819. #endif
  90820. return true;
  90821. }
  90822. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90823. {
  90824. FLAC__ASSERT(0 != encoder);
  90825. FLAC__ASSERT(0 != encoder->private_);
  90826. FLAC__ASSERT(0 != encoder->protected_);
  90827. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90828. return false;
  90829. encoder->protected_->max_lpc_order = value;
  90830. return true;
  90831. }
  90832. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90833. {
  90834. FLAC__ASSERT(0 != encoder);
  90835. FLAC__ASSERT(0 != encoder->private_);
  90836. FLAC__ASSERT(0 != encoder->protected_);
  90837. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90838. return false;
  90839. encoder->protected_->qlp_coeff_precision = value;
  90840. return true;
  90841. }
  90842. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90843. {
  90844. FLAC__ASSERT(0 != encoder);
  90845. FLAC__ASSERT(0 != encoder->private_);
  90846. FLAC__ASSERT(0 != encoder->protected_);
  90847. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90848. return false;
  90849. encoder->protected_->do_qlp_coeff_prec_search = value;
  90850. return true;
  90851. }
  90852. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90853. {
  90854. FLAC__ASSERT(0 != encoder);
  90855. FLAC__ASSERT(0 != encoder->private_);
  90856. FLAC__ASSERT(0 != encoder->protected_);
  90857. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90858. return false;
  90859. #if 0
  90860. encoder->protected_->do_escape_coding = value;
  90861. #else
  90862. (void)value;
  90863. #endif
  90864. return true;
  90865. }
  90866. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90867. {
  90868. FLAC__ASSERT(0 != encoder);
  90869. FLAC__ASSERT(0 != encoder->private_);
  90870. FLAC__ASSERT(0 != encoder->protected_);
  90871. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90872. return false;
  90873. encoder->protected_->do_exhaustive_model_search = value;
  90874. return true;
  90875. }
  90876. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90877. {
  90878. FLAC__ASSERT(0 != encoder);
  90879. FLAC__ASSERT(0 != encoder->private_);
  90880. FLAC__ASSERT(0 != encoder->protected_);
  90881. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90882. return false;
  90883. encoder->protected_->min_residual_partition_order = value;
  90884. return true;
  90885. }
  90886. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90887. {
  90888. FLAC__ASSERT(0 != encoder);
  90889. FLAC__ASSERT(0 != encoder->private_);
  90890. FLAC__ASSERT(0 != encoder->protected_);
  90891. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90892. return false;
  90893. encoder->protected_->max_residual_partition_order = value;
  90894. return true;
  90895. }
  90896. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  90897. {
  90898. FLAC__ASSERT(0 != encoder);
  90899. FLAC__ASSERT(0 != encoder->private_);
  90900. FLAC__ASSERT(0 != encoder->protected_);
  90901. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90902. return false;
  90903. #if 0
  90904. encoder->protected_->rice_parameter_search_dist = value;
  90905. #else
  90906. (void)value;
  90907. #endif
  90908. return true;
  90909. }
  90910. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  90911. {
  90912. FLAC__ASSERT(0 != encoder);
  90913. FLAC__ASSERT(0 != encoder->private_);
  90914. FLAC__ASSERT(0 != encoder->protected_);
  90915. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90916. return false;
  90917. encoder->protected_->total_samples_estimate = value;
  90918. return true;
  90919. }
  90920. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  90921. {
  90922. FLAC__ASSERT(0 != encoder);
  90923. FLAC__ASSERT(0 != encoder->private_);
  90924. FLAC__ASSERT(0 != encoder->protected_);
  90925. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90926. return false;
  90927. if(0 == metadata)
  90928. num_blocks = 0;
  90929. if(0 == num_blocks)
  90930. metadata = 0;
  90931. if(encoder->protected_->metadata) {
  90932. free(encoder->protected_->metadata);
  90933. encoder->protected_->metadata = 0;
  90934. encoder->protected_->num_metadata_blocks = 0;
  90935. }
  90936. if(num_blocks) {
  90937. FLAC__StreamMetadata **m;
  90938. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  90939. return false;
  90940. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  90941. encoder->protected_->metadata = m;
  90942. encoder->protected_->num_metadata_blocks = num_blocks;
  90943. }
  90944. #if FLAC__HAS_OGG
  90945. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  90946. return false;
  90947. #endif
  90948. return true;
  90949. }
  90950. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90951. {
  90952. FLAC__ASSERT(0 != encoder);
  90953. FLAC__ASSERT(0 != encoder->private_);
  90954. FLAC__ASSERT(0 != encoder->protected_);
  90955. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90956. return false;
  90957. encoder->private_->disable_constant_subframes = value;
  90958. return true;
  90959. }
  90960. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90961. {
  90962. FLAC__ASSERT(0 != encoder);
  90963. FLAC__ASSERT(0 != encoder->private_);
  90964. FLAC__ASSERT(0 != encoder->protected_);
  90965. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90966. return false;
  90967. encoder->private_->disable_fixed_subframes = value;
  90968. return true;
  90969. }
  90970. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90971. {
  90972. FLAC__ASSERT(0 != encoder);
  90973. FLAC__ASSERT(0 != encoder->private_);
  90974. FLAC__ASSERT(0 != encoder->protected_);
  90975. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90976. return false;
  90977. encoder->private_->disable_verbatim_subframes = value;
  90978. return true;
  90979. }
  90980. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  90981. {
  90982. FLAC__ASSERT(0 != encoder);
  90983. FLAC__ASSERT(0 != encoder->private_);
  90984. FLAC__ASSERT(0 != encoder->protected_);
  90985. return encoder->protected_->state;
  90986. }
  90987. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  90988. {
  90989. FLAC__ASSERT(0 != encoder);
  90990. FLAC__ASSERT(0 != encoder->private_);
  90991. FLAC__ASSERT(0 != encoder->protected_);
  90992. if(encoder->protected_->verify)
  90993. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  90994. else
  90995. return FLAC__STREAM_DECODER_UNINITIALIZED;
  90996. }
  90997. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  90998. {
  90999. FLAC__ASSERT(0 != encoder);
  91000. FLAC__ASSERT(0 != encoder->private_);
  91001. FLAC__ASSERT(0 != encoder->protected_);
  91002. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91003. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91004. else
  91005. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91006. }
  91007. 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)
  91008. {
  91009. FLAC__ASSERT(0 != encoder);
  91010. FLAC__ASSERT(0 != encoder->private_);
  91011. FLAC__ASSERT(0 != encoder->protected_);
  91012. if(0 != absolute_sample)
  91013. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91014. if(0 != frame_number)
  91015. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91016. if(0 != channel)
  91017. *channel = encoder->private_->verify.error_stats.channel;
  91018. if(0 != sample)
  91019. *sample = encoder->private_->verify.error_stats.sample;
  91020. if(0 != expected)
  91021. *expected = encoder->private_->verify.error_stats.expected;
  91022. if(0 != got)
  91023. *got = encoder->private_->verify.error_stats.got;
  91024. }
  91025. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91026. {
  91027. FLAC__ASSERT(0 != encoder);
  91028. FLAC__ASSERT(0 != encoder->private_);
  91029. FLAC__ASSERT(0 != encoder->protected_);
  91030. return encoder->protected_->verify;
  91031. }
  91032. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91033. {
  91034. FLAC__ASSERT(0 != encoder);
  91035. FLAC__ASSERT(0 != encoder->private_);
  91036. FLAC__ASSERT(0 != encoder->protected_);
  91037. return encoder->protected_->streamable_subset;
  91038. }
  91039. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91040. {
  91041. FLAC__ASSERT(0 != encoder);
  91042. FLAC__ASSERT(0 != encoder->private_);
  91043. FLAC__ASSERT(0 != encoder->protected_);
  91044. return encoder->protected_->do_md5;
  91045. }
  91046. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91047. {
  91048. FLAC__ASSERT(0 != encoder);
  91049. FLAC__ASSERT(0 != encoder->private_);
  91050. FLAC__ASSERT(0 != encoder->protected_);
  91051. return encoder->protected_->channels;
  91052. }
  91053. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91054. {
  91055. FLAC__ASSERT(0 != encoder);
  91056. FLAC__ASSERT(0 != encoder->private_);
  91057. FLAC__ASSERT(0 != encoder->protected_);
  91058. return encoder->protected_->bits_per_sample;
  91059. }
  91060. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91061. {
  91062. FLAC__ASSERT(0 != encoder);
  91063. FLAC__ASSERT(0 != encoder->private_);
  91064. FLAC__ASSERT(0 != encoder->protected_);
  91065. return encoder->protected_->sample_rate;
  91066. }
  91067. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91068. {
  91069. FLAC__ASSERT(0 != encoder);
  91070. FLAC__ASSERT(0 != encoder->private_);
  91071. FLAC__ASSERT(0 != encoder->protected_);
  91072. return encoder->protected_->blocksize;
  91073. }
  91074. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91075. {
  91076. FLAC__ASSERT(0 != encoder);
  91077. FLAC__ASSERT(0 != encoder->private_);
  91078. FLAC__ASSERT(0 != encoder->protected_);
  91079. return encoder->protected_->do_mid_side_stereo;
  91080. }
  91081. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91082. {
  91083. FLAC__ASSERT(0 != encoder);
  91084. FLAC__ASSERT(0 != encoder->private_);
  91085. FLAC__ASSERT(0 != encoder->protected_);
  91086. return encoder->protected_->loose_mid_side_stereo;
  91087. }
  91088. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91089. {
  91090. FLAC__ASSERT(0 != encoder);
  91091. FLAC__ASSERT(0 != encoder->private_);
  91092. FLAC__ASSERT(0 != encoder->protected_);
  91093. return encoder->protected_->max_lpc_order;
  91094. }
  91095. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91096. {
  91097. FLAC__ASSERT(0 != encoder);
  91098. FLAC__ASSERT(0 != encoder->private_);
  91099. FLAC__ASSERT(0 != encoder->protected_);
  91100. return encoder->protected_->qlp_coeff_precision;
  91101. }
  91102. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91103. {
  91104. FLAC__ASSERT(0 != encoder);
  91105. FLAC__ASSERT(0 != encoder->private_);
  91106. FLAC__ASSERT(0 != encoder->protected_);
  91107. return encoder->protected_->do_qlp_coeff_prec_search;
  91108. }
  91109. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91110. {
  91111. FLAC__ASSERT(0 != encoder);
  91112. FLAC__ASSERT(0 != encoder->private_);
  91113. FLAC__ASSERT(0 != encoder->protected_);
  91114. return encoder->protected_->do_escape_coding;
  91115. }
  91116. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91117. {
  91118. FLAC__ASSERT(0 != encoder);
  91119. FLAC__ASSERT(0 != encoder->private_);
  91120. FLAC__ASSERT(0 != encoder->protected_);
  91121. return encoder->protected_->do_exhaustive_model_search;
  91122. }
  91123. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91124. {
  91125. FLAC__ASSERT(0 != encoder);
  91126. FLAC__ASSERT(0 != encoder->private_);
  91127. FLAC__ASSERT(0 != encoder->protected_);
  91128. return encoder->protected_->min_residual_partition_order;
  91129. }
  91130. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91131. {
  91132. FLAC__ASSERT(0 != encoder);
  91133. FLAC__ASSERT(0 != encoder->private_);
  91134. FLAC__ASSERT(0 != encoder->protected_);
  91135. return encoder->protected_->max_residual_partition_order;
  91136. }
  91137. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91138. {
  91139. FLAC__ASSERT(0 != encoder);
  91140. FLAC__ASSERT(0 != encoder->private_);
  91141. FLAC__ASSERT(0 != encoder->protected_);
  91142. return encoder->protected_->rice_parameter_search_dist;
  91143. }
  91144. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91145. {
  91146. FLAC__ASSERT(0 != encoder);
  91147. FLAC__ASSERT(0 != encoder->private_);
  91148. FLAC__ASSERT(0 != encoder->protected_);
  91149. return encoder->protected_->total_samples_estimate;
  91150. }
  91151. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91152. {
  91153. unsigned i, j = 0, channel;
  91154. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91155. FLAC__ASSERT(0 != encoder);
  91156. FLAC__ASSERT(0 != encoder->private_);
  91157. FLAC__ASSERT(0 != encoder->protected_);
  91158. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91159. do {
  91160. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91161. if(encoder->protected_->verify)
  91162. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91163. for(channel = 0; channel < channels; channel++)
  91164. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91165. if(encoder->protected_->do_mid_side_stereo) {
  91166. FLAC__ASSERT(channels == 2);
  91167. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91168. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91169. 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' ! */
  91170. }
  91171. }
  91172. else
  91173. j += n;
  91174. encoder->private_->current_sample_number += n;
  91175. if(encoder->private_->current_sample_number > blocksize) {
  91176. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91177. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91178. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91179. return false;
  91180. for(channel = 0; channel < channels; channel++)
  91181. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91182. if(encoder->protected_->do_mid_side_stereo) {
  91183. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91184. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91185. }
  91186. encoder->private_->current_sample_number = 1;
  91187. }
  91188. } while(j < samples);
  91189. return true;
  91190. }
  91191. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91192. {
  91193. unsigned i, j, k, channel;
  91194. FLAC__int32 x, mid, side;
  91195. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91196. FLAC__ASSERT(0 != encoder);
  91197. FLAC__ASSERT(0 != encoder->private_);
  91198. FLAC__ASSERT(0 != encoder->protected_);
  91199. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91200. j = k = 0;
  91201. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91202. do {
  91203. if(encoder->protected_->verify)
  91204. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91205. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91206. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91207. x = buffer[k++];
  91208. encoder->private_->integer_signal[1][i] = x;
  91209. mid += x;
  91210. side -= x;
  91211. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91212. encoder->private_->integer_signal_mid_side[1][i] = side;
  91213. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91214. }
  91215. encoder->private_->current_sample_number = i;
  91216. if(i > blocksize) {
  91217. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91218. return false;
  91219. /* move unprocessed overread samples to beginnings of arrays */
  91220. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91221. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91222. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91223. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91224. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91225. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91226. encoder->private_->current_sample_number = 1;
  91227. }
  91228. } while(j < samples);
  91229. }
  91230. else {
  91231. do {
  91232. if(encoder->protected_->verify)
  91233. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91234. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91235. for(channel = 0; channel < channels; channel++)
  91236. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91237. }
  91238. encoder->private_->current_sample_number = i;
  91239. if(i > blocksize) {
  91240. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91241. return false;
  91242. /* move unprocessed overread samples to beginnings of arrays */
  91243. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91244. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91245. for(channel = 0; channel < channels; channel++)
  91246. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91247. encoder->private_->current_sample_number = 1;
  91248. }
  91249. } while(j < samples);
  91250. }
  91251. return true;
  91252. }
  91253. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91254. {
  91255. FLAC__ASSERT(0 != encoder);
  91256. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91257. encoder->protected_->verify = true;
  91258. #else
  91259. encoder->protected_->verify = false;
  91260. #endif
  91261. encoder->protected_->streamable_subset = true;
  91262. encoder->protected_->do_md5 = true;
  91263. encoder->protected_->do_mid_side_stereo = false;
  91264. encoder->protected_->loose_mid_side_stereo = false;
  91265. encoder->protected_->channels = 2;
  91266. encoder->protected_->bits_per_sample = 16;
  91267. encoder->protected_->sample_rate = 44100;
  91268. encoder->protected_->blocksize = 0;
  91269. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91270. encoder->protected_->num_apodizations = 1;
  91271. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91272. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91273. #endif
  91274. encoder->protected_->max_lpc_order = 0;
  91275. encoder->protected_->qlp_coeff_precision = 0;
  91276. encoder->protected_->do_qlp_coeff_prec_search = false;
  91277. encoder->protected_->do_exhaustive_model_search = false;
  91278. encoder->protected_->do_escape_coding = false;
  91279. encoder->protected_->min_residual_partition_order = 0;
  91280. encoder->protected_->max_residual_partition_order = 0;
  91281. encoder->protected_->rice_parameter_search_dist = 0;
  91282. encoder->protected_->total_samples_estimate = 0;
  91283. encoder->protected_->metadata = 0;
  91284. encoder->protected_->num_metadata_blocks = 0;
  91285. encoder->private_->seek_table = 0;
  91286. encoder->private_->disable_constant_subframes = false;
  91287. encoder->private_->disable_fixed_subframes = false;
  91288. encoder->private_->disable_verbatim_subframes = false;
  91289. #if FLAC__HAS_OGG
  91290. encoder->private_->is_ogg = false;
  91291. #endif
  91292. encoder->private_->read_callback = 0;
  91293. encoder->private_->write_callback = 0;
  91294. encoder->private_->seek_callback = 0;
  91295. encoder->private_->tell_callback = 0;
  91296. encoder->private_->metadata_callback = 0;
  91297. encoder->private_->progress_callback = 0;
  91298. encoder->private_->client_data = 0;
  91299. #if FLAC__HAS_OGG
  91300. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91301. #endif
  91302. }
  91303. void free_(FLAC__StreamEncoder *encoder)
  91304. {
  91305. unsigned i, channel;
  91306. FLAC__ASSERT(0 != encoder);
  91307. if(encoder->protected_->metadata) {
  91308. free(encoder->protected_->metadata);
  91309. encoder->protected_->metadata = 0;
  91310. encoder->protected_->num_metadata_blocks = 0;
  91311. }
  91312. for(i = 0; i < encoder->protected_->channels; i++) {
  91313. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91314. free(encoder->private_->integer_signal_unaligned[i]);
  91315. encoder->private_->integer_signal_unaligned[i] = 0;
  91316. }
  91317. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91318. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91319. free(encoder->private_->real_signal_unaligned[i]);
  91320. encoder->private_->real_signal_unaligned[i] = 0;
  91321. }
  91322. #endif
  91323. }
  91324. for(i = 0; i < 2; i++) {
  91325. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91326. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91327. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91328. }
  91329. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91330. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91331. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91332. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91333. }
  91334. #endif
  91335. }
  91336. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91337. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91338. if(0 != encoder->private_->window_unaligned[i]) {
  91339. free(encoder->private_->window_unaligned[i]);
  91340. encoder->private_->window_unaligned[i] = 0;
  91341. }
  91342. }
  91343. if(0 != encoder->private_->windowed_signal_unaligned) {
  91344. free(encoder->private_->windowed_signal_unaligned);
  91345. encoder->private_->windowed_signal_unaligned = 0;
  91346. }
  91347. #endif
  91348. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91349. for(i = 0; i < 2; i++) {
  91350. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91351. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91352. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91353. }
  91354. }
  91355. }
  91356. for(channel = 0; channel < 2; channel++) {
  91357. for(i = 0; i < 2; i++) {
  91358. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91359. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91360. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91361. }
  91362. }
  91363. }
  91364. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91365. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91366. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91367. }
  91368. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91369. free(encoder->private_->raw_bits_per_partition_unaligned);
  91370. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91371. }
  91372. if(encoder->protected_->verify) {
  91373. for(i = 0; i < encoder->protected_->channels; i++) {
  91374. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91375. free(encoder->private_->verify.input_fifo.data[i]);
  91376. encoder->private_->verify.input_fifo.data[i] = 0;
  91377. }
  91378. }
  91379. }
  91380. FLAC__bitwriter_free(encoder->private_->frame);
  91381. }
  91382. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91383. {
  91384. FLAC__bool ok;
  91385. unsigned i, channel;
  91386. FLAC__ASSERT(new_blocksize > 0);
  91387. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91388. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91389. if(new_blocksize <= encoder->private_->input_capacity)
  91390. return true;
  91391. ok = true;
  91392. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91393. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91394. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91395. encoder->private_->integer_signal[i] += 4;
  91396. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91397. #if 0 /* @@@ currently unused */
  91398. if(encoder->protected_->max_lpc_order > 0)
  91399. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91400. #endif
  91401. #endif
  91402. }
  91403. for(i = 0; ok && i < 2; i++) {
  91404. 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]);
  91405. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91406. encoder->private_->integer_signal_mid_side[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_mid_side_unaligned[i], &encoder->private_->real_signal_mid_side[i]);
  91411. #endif
  91412. #endif
  91413. }
  91414. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91415. if(ok && encoder->protected_->max_lpc_order > 0) {
  91416. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91417. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91418. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91419. }
  91420. #endif
  91421. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91422. for(i = 0; ok && i < 2; i++) {
  91423. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91424. }
  91425. }
  91426. for(channel = 0; ok && channel < 2; channel++) {
  91427. for(i = 0; ok && i < 2; i++) {
  91428. 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]);
  91429. }
  91430. }
  91431. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91432. if(encoder->protected_->do_escape_coding)
  91433. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91434. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91435. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91436. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91437. switch(encoder->protected_->apodizations[i].type) {
  91438. case FLAC__APODIZATION_BARTLETT:
  91439. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91440. break;
  91441. case FLAC__APODIZATION_BARTLETT_HANN:
  91442. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91443. break;
  91444. case FLAC__APODIZATION_BLACKMAN:
  91445. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91446. break;
  91447. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91448. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91449. break;
  91450. case FLAC__APODIZATION_CONNES:
  91451. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91452. break;
  91453. case FLAC__APODIZATION_FLATTOP:
  91454. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91455. break;
  91456. case FLAC__APODIZATION_GAUSS:
  91457. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91458. break;
  91459. case FLAC__APODIZATION_HAMMING:
  91460. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91461. break;
  91462. case FLAC__APODIZATION_HANN:
  91463. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91464. break;
  91465. case FLAC__APODIZATION_KAISER_BESSEL:
  91466. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91467. break;
  91468. case FLAC__APODIZATION_NUTTALL:
  91469. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91470. break;
  91471. case FLAC__APODIZATION_RECTANGLE:
  91472. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91473. break;
  91474. case FLAC__APODIZATION_TRIANGLE:
  91475. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91476. break;
  91477. case FLAC__APODIZATION_TUKEY:
  91478. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91479. break;
  91480. case FLAC__APODIZATION_WELCH:
  91481. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91482. break;
  91483. default:
  91484. FLAC__ASSERT(0);
  91485. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91486. break;
  91487. }
  91488. }
  91489. }
  91490. #endif
  91491. if(ok)
  91492. encoder->private_->input_capacity = new_blocksize;
  91493. else
  91494. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91495. return ok;
  91496. }
  91497. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91498. {
  91499. const FLAC__byte *buffer;
  91500. size_t bytes;
  91501. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91502. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91503. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91504. return false;
  91505. }
  91506. if(encoder->protected_->verify) {
  91507. encoder->private_->verify.output.data = buffer;
  91508. encoder->private_->verify.output.bytes = bytes;
  91509. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91510. encoder->private_->verify.needs_magic_hack = true;
  91511. }
  91512. else {
  91513. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91514. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91515. FLAC__bitwriter_clear(encoder->private_->frame);
  91516. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91517. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91518. return false;
  91519. }
  91520. }
  91521. }
  91522. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91523. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91524. FLAC__bitwriter_clear(encoder->private_->frame);
  91525. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91526. return false;
  91527. }
  91528. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91529. FLAC__bitwriter_clear(encoder->private_->frame);
  91530. if(samples > 0) {
  91531. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91532. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91533. }
  91534. return true;
  91535. }
  91536. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91537. {
  91538. FLAC__StreamEncoderWriteStatus status;
  91539. FLAC__uint64 output_position = 0;
  91540. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91541. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91542. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91543. }
  91544. if(samples == 0) {
  91545. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91546. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91547. encoder->protected_->streaminfo_offset = output_position;
  91548. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91549. encoder->protected_->seektable_offset = output_position;
  91550. }
  91551. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91552. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91553. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91554. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91555. FLAC__uint64 test_sample;
  91556. unsigned i;
  91557. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91558. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91559. if(test_sample > frame_last_sample) {
  91560. break;
  91561. }
  91562. else if(test_sample >= frame_first_sample) {
  91563. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91564. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91565. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91566. encoder->private_->first_seekpoint_to_check++;
  91567. }
  91568. else {
  91569. encoder->private_->first_seekpoint_to_check++;
  91570. }
  91571. }
  91572. }
  91573. #if FLAC__HAS_OGG
  91574. if(encoder->private_->is_ogg) {
  91575. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91576. &encoder->protected_->ogg_encoder_aspect,
  91577. buffer,
  91578. bytes,
  91579. samples,
  91580. encoder->private_->current_frame_number,
  91581. is_last_block,
  91582. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91583. encoder,
  91584. encoder->private_->client_data
  91585. );
  91586. }
  91587. else
  91588. #endif
  91589. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91590. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91591. encoder->private_->bytes_written += bytes;
  91592. encoder->private_->samples_written += samples;
  91593. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91594. }
  91595. else
  91596. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91597. return status;
  91598. }
  91599. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91600. {
  91601. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91602. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91603. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91604. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91605. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91606. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91607. FLAC__StreamEncoderSeekStatus seek_status;
  91608. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91609. {
  91610. const unsigned md5_offset =
  91611. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91612. (
  91613. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91614. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91615. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91616. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91617. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91618. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91619. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91620. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91621. ) / 8;
  91622. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91623. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91624. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91625. return;
  91626. }
  91627. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91628. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91629. return;
  91630. }
  91631. }
  91632. {
  91633. const unsigned total_samples_byte_offset =
  91634. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91635. (
  91636. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91637. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91638. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91639. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91640. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91641. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91642. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91643. - 4
  91644. ) / 8;
  91645. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91646. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91647. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91648. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91649. b[4] = (FLAC__byte)(samples & 0xFF);
  91650. 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) {
  91651. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91652. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91653. return;
  91654. }
  91655. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91656. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91657. return;
  91658. }
  91659. }
  91660. {
  91661. const unsigned min_framesize_offset =
  91662. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91663. (
  91664. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91665. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91666. ) / 8;
  91667. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91668. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91669. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91670. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91671. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91672. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91673. 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) {
  91674. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91675. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91676. return;
  91677. }
  91678. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91679. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91680. return;
  91681. }
  91682. }
  91683. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91684. unsigned i;
  91685. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91686. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91687. 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) {
  91688. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91689. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91690. return;
  91691. }
  91692. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91693. FLAC__uint64 xx;
  91694. unsigned x;
  91695. xx = encoder->private_->seek_table->points[i].sample_number;
  91696. b[7] = (FLAC__byte)xx; xx >>= 8;
  91697. b[6] = (FLAC__byte)xx; xx >>= 8;
  91698. b[5] = (FLAC__byte)xx; xx >>= 8;
  91699. b[4] = (FLAC__byte)xx; xx >>= 8;
  91700. b[3] = (FLAC__byte)xx; xx >>= 8;
  91701. b[2] = (FLAC__byte)xx; xx >>= 8;
  91702. b[1] = (FLAC__byte)xx; xx >>= 8;
  91703. b[0] = (FLAC__byte)xx; xx >>= 8;
  91704. xx = encoder->private_->seek_table->points[i].stream_offset;
  91705. b[15] = (FLAC__byte)xx; xx >>= 8;
  91706. b[14] = (FLAC__byte)xx; xx >>= 8;
  91707. b[13] = (FLAC__byte)xx; xx >>= 8;
  91708. b[12] = (FLAC__byte)xx; xx >>= 8;
  91709. b[11] = (FLAC__byte)xx; xx >>= 8;
  91710. b[10] = (FLAC__byte)xx; xx >>= 8;
  91711. b[9] = (FLAC__byte)xx; xx >>= 8;
  91712. b[8] = (FLAC__byte)xx; xx >>= 8;
  91713. x = encoder->private_->seek_table->points[i].frame_samples;
  91714. b[17] = (FLAC__byte)x; x >>= 8;
  91715. b[16] = (FLAC__byte)x; x >>= 8;
  91716. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91717. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91718. return;
  91719. }
  91720. }
  91721. }
  91722. }
  91723. #if FLAC__HAS_OGG
  91724. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91725. {
  91726. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91727. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91728. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91729. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91730. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91731. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91732. FLAC__STREAM_SYNC_LENGTH
  91733. ;
  91734. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91735. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91736. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91737. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91738. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91739. ogg_page page;
  91740. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91741. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91742. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91743. return;
  91744. simple_ogg_page__init(&page);
  91745. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91746. simple_ogg_page__clear(&page);
  91747. return; /* state already set */
  91748. }
  91749. {
  91750. const unsigned md5_offset =
  91751. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91752. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91753. (
  91754. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91755. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91756. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91757. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91758. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91759. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91760. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91761. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91762. ) / 8;
  91763. if(md5_offset + 16 > (unsigned)page.body_len) {
  91764. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91765. simple_ogg_page__clear(&page);
  91766. return;
  91767. }
  91768. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91769. }
  91770. {
  91771. const unsigned total_samples_byte_offset =
  91772. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91773. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91774. (
  91775. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91776. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91777. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91778. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91779. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91780. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91781. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91782. - 4
  91783. ) / 8;
  91784. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91785. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91786. simple_ogg_page__clear(&page);
  91787. return;
  91788. }
  91789. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91790. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91791. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91792. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91793. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91794. b[4] = (FLAC__byte)(samples & 0xFF);
  91795. memcpy(page.body + total_samples_byte_offset, b, 5);
  91796. }
  91797. {
  91798. const unsigned min_framesize_offset =
  91799. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91800. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91801. (
  91802. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91803. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91804. ) / 8;
  91805. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91806. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91807. simple_ogg_page__clear(&page);
  91808. return;
  91809. }
  91810. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91811. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91812. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91813. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91814. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91815. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91816. memcpy(page.body + min_framesize_offset, b, 6);
  91817. }
  91818. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91819. simple_ogg_page__clear(&page);
  91820. return; /* state already set */
  91821. }
  91822. simple_ogg_page__clear(&page);
  91823. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91824. unsigned i;
  91825. FLAC__byte *p;
  91826. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91827. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91828. simple_ogg_page__init(&page);
  91829. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91830. simple_ogg_page__clear(&page);
  91831. return; /* state already set */
  91832. }
  91833. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91834. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91835. simple_ogg_page__clear(&page);
  91836. return;
  91837. }
  91838. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91839. FLAC__uint64 xx;
  91840. unsigned x;
  91841. xx = encoder->private_->seek_table->points[i].sample_number;
  91842. b[7] = (FLAC__byte)xx; xx >>= 8;
  91843. b[6] = (FLAC__byte)xx; xx >>= 8;
  91844. b[5] = (FLAC__byte)xx; xx >>= 8;
  91845. b[4] = (FLAC__byte)xx; xx >>= 8;
  91846. b[3] = (FLAC__byte)xx; xx >>= 8;
  91847. b[2] = (FLAC__byte)xx; xx >>= 8;
  91848. b[1] = (FLAC__byte)xx; xx >>= 8;
  91849. b[0] = (FLAC__byte)xx; xx >>= 8;
  91850. xx = encoder->private_->seek_table->points[i].stream_offset;
  91851. b[15] = (FLAC__byte)xx; xx >>= 8;
  91852. b[14] = (FLAC__byte)xx; xx >>= 8;
  91853. b[13] = (FLAC__byte)xx; xx >>= 8;
  91854. b[12] = (FLAC__byte)xx; xx >>= 8;
  91855. b[11] = (FLAC__byte)xx; xx >>= 8;
  91856. b[10] = (FLAC__byte)xx; xx >>= 8;
  91857. b[9] = (FLAC__byte)xx; xx >>= 8;
  91858. b[8] = (FLAC__byte)xx; xx >>= 8;
  91859. x = encoder->private_->seek_table->points[i].frame_samples;
  91860. b[17] = (FLAC__byte)x; x >>= 8;
  91861. b[16] = (FLAC__byte)x; x >>= 8;
  91862. memcpy(p, b, 18);
  91863. }
  91864. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91865. simple_ogg_page__clear(&page);
  91866. return; /* state already set */
  91867. }
  91868. simple_ogg_page__clear(&page);
  91869. }
  91870. }
  91871. #endif
  91872. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91873. {
  91874. FLAC__uint16 crc;
  91875. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91876. 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)) {
  91877. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91878. return false;
  91879. }
  91880. if(!process_subframes_(encoder, is_fractional_block)) {
  91881. return false;
  91882. }
  91883. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91884. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91885. return false;
  91886. }
  91887. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91888. if(
  91889. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91890. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91891. ) {
  91892. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91893. return false;
  91894. }
  91895. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  91896. return false;
  91897. }
  91898. encoder->private_->current_sample_number = 0;
  91899. encoder->private_->current_frame_number++;
  91900. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  91901. return true;
  91902. }
  91903. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  91904. {
  91905. FLAC__FrameHeader frame_header;
  91906. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  91907. FLAC__bool do_independent, do_mid_side;
  91908. if(is_fractional_block) {
  91909. max_partition_order = 0;
  91910. }
  91911. else {
  91912. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  91913. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  91914. }
  91915. min_partition_order = min(min_partition_order, max_partition_order);
  91916. frame_header.blocksize = encoder->protected_->blocksize;
  91917. frame_header.sample_rate = encoder->protected_->sample_rate;
  91918. frame_header.channels = encoder->protected_->channels;
  91919. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  91920. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  91921. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  91922. frame_header.number.frame_number = encoder->private_->current_frame_number;
  91923. if(encoder->protected_->do_mid_side_stereo) {
  91924. if(encoder->protected_->loose_mid_side_stereo) {
  91925. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  91926. do_independent = true;
  91927. do_mid_side = true;
  91928. }
  91929. else {
  91930. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  91931. do_mid_side = !do_independent;
  91932. }
  91933. }
  91934. else {
  91935. do_independent = true;
  91936. do_mid_side = true;
  91937. }
  91938. }
  91939. else {
  91940. do_independent = true;
  91941. do_mid_side = false;
  91942. }
  91943. FLAC__ASSERT(do_independent || do_mid_side);
  91944. if(do_independent) {
  91945. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91946. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  91947. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  91948. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  91949. }
  91950. }
  91951. if(do_mid_side) {
  91952. FLAC__ASSERT(encoder->protected_->channels == 2);
  91953. for(channel = 0; channel < 2; channel++) {
  91954. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  91955. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  91956. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  91957. }
  91958. }
  91959. if(do_independent) {
  91960. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91961. if(!
  91962. process_subframe_(
  91963. encoder,
  91964. min_partition_order,
  91965. max_partition_order,
  91966. &frame_header,
  91967. encoder->private_->subframe_bps[channel],
  91968. encoder->private_->integer_signal[channel],
  91969. encoder->private_->subframe_workspace_ptr[channel],
  91970. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  91971. encoder->private_->residual_workspace[channel],
  91972. encoder->private_->best_subframe+channel,
  91973. encoder->private_->best_subframe_bits+channel
  91974. )
  91975. )
  91976. return false;
  91977. }
  91978. }
  91979. if(do_mid_side) {
  91980. FLAC__ASSERT(encoder->protected_->channels == 2);
  91981. for(channel = 0; channel < 2; channel++) {
  91982. if(!
  91983. process_subframe_(
  91984. encoder,
  91985. min_partition_order,
  91986. max_partition_order,
  91987. &frame_header,
  91988. encoder->private_->subframe_bps_mid_side[channel],
  91989. encoder->private_->integer_signal_mid_side[channel],
  91990. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  91991. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  91992. encoder->private_->residual_workspace_mid_side[channel],
  91993. encoder->private_->best_subframe_mid_side+channel,
  91994. encoder->private_->best_subframe_bits_mid_side+channel
  91995. )
  91996. )
  91997. return false;
  91998. }
  91999. }
  92000. if(do_mid_side) {
  92001. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92002. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92003. FLAC__ChannelAssignment channel_assignment;
  92004. FLAC__ASSERT(encoder->protected_->channels == 2);
  92005. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92006. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92007. }
  92008. else {
  92009. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92010. unsigned min_bits;
  92011. int ca;
  92012. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92013. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92014. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92015. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92016. FLAC__ASSERT(do_independent && do_mid_side);
  92017. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92018. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92019. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92020. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92021. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92022. min_bits = bits[channel_assignment];
  92023. for(ca = 1; ca <= 3; ca++) {
  92024. if(bits[ca] < min_bits) {
  92025. min_bits = bits[ca];
  92026. channel_assignment = (FLAC__ChannelAssignment)ca;
  92027. }
  92028. }
  92029. }
  92030. frame_header.channel_assignment = channel_assignment;
  92031. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92032. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92033. return false;
  92034. }
  92035. switch(channel_assignment) {
  92036. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92037. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92038. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92039. break;
  92040. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92041. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92042. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92043. break;
  92044. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92045. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92046. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92047. break;
  92048. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92049. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92050. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92051. break;
  92052. default:
  92053. FLAC__ASSERT(0);
  92054. }
  92055. switch(channel_assignment) {
  92056. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92057. left_bps = encoder->private_->subframe_bps [0];
  92058. right_bps = encoder->private_->subframe_bps [1];
  92059. break;
  92060. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92061. left_bps = encoder->private_->subframe_bps [0];
  92062. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92063. break;
  92064. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92065. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92066. right_bps = encoder->private_->subframe_bps [1];
  92067. break;
  92068. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92069. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92070. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92071. break;
  92072. default:
  92073. FLAC__ASSERT(0);
  92074. }
  92075. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92076. return false;
  92077. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92078. return false;
  92079. }
  92080. else {
  92081. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92082. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92083. return false;
  92084. }
  92085. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92086. 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)) {
  92087. return false;
  92088. }
  92089. }
  92090. }
  92091. if(encoder->protected_->loose_mid_side_stereo) {
  92092. encoder->private_->loose_mid_side_stereo_frame_count++;
  92093. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92094. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92095. }
  92096. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92097. return true;
  92098. }
  92099. FLAC__bool process_subframe_(
  92100. FLAC__StreamEncoder *encoder,
  92101. unsigned min_partition_order,
  92102. unsigned max_partition_order,
  92103. const FLAC__FrameHeader *frame_header,
  92104. unsigned subframe_bps,
  92105. const FLAC__int32 integer_signal[],
  92106. FLAC__Subframe *subframe[2],
  92107. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92108. FLAC__int32 *residual[2],
  92109. unsigned *best_subframe,
  92110. unsigned *best_bits
  92111. )
  92112. {
  92113. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92114. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92115. #else
  92116. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92117. #endif
  92118. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92119. FLAC__double lpc_residual_bits_per_sample;
  92120. 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 */
  92121. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92122. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92123. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92124. #endif
  92125. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92126. unsigned rice_parameter;
  92127. unsigned _candidate_bits, _best_bits;
  92128. unsigned _best_subframe;
  92129. 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;
  92130. FLAC__ASSERT(frame_header->blocksize > 0);
  92131. _best_subframe = 0;
  92132. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92133. _best_bits = UINT_MAX;
  92134. else
  92135. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92136. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92137. unsigned signal_is_constant = false;
  92138. 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);
  92139. if(
  92140. !encoder->private_->disable_constant_subframes &&
  92141. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92142. fixed_residual_bits_per_sample[1] == 0.0
  92143. #else
  92144. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92145. #endif
  92146. ) {
  92147. unsigned i;
  92148. signal_is_constant = true;
  92149. for(i = 1; i < frame_header->blocksize; i++) {
  92150. if(integer_signal[0] != integer_signal[i]) {
  92151. signal_is_constant = false;
  92152. break;
  92153. }
  92154. }
  92155. }
  92156. if(signal_is_constant) {
  92157. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92158. if(_candidate_bits < _best_bits) {
  92159. _best_subframe = !_best_subframe;
  92160. _best_bits = _candidate_bits;
  92161. }
  92162. }
  92163. else {
  92164. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92165. if(encoder->protected_->do_exhaustive_model_search) {
  92166. min_fixed_order = 0;
  92167. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92168. }
  92169. else {
  92170. min_fixed_order = max_fixed_order = guess_fixed_order;
  92171. }
  92172. if(max_fixed_order >= frame_header->blocksize)
  92173. max_fixed_order = frame_header->blocksize - 1;
  92174. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92175. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92176. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92177. continue; /* don't even try */
  92178. 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 */
  92179. #else
  92180. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92181. continue; /* don't even try */
  92182. 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 */
  92183. #endif
  92184. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92185. if(rice_parameter >= rice_parameter_limit) {
  92186. #ifdef DEBUG_VERBOSE
  92187. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92188. #endif
  92189. rice_parameter = rice_parameter_limit - 1;
  92190. }
  92191. _candidate_bits =
  92192. evaluate_fixed_subframe_(
  92193. encoder,
  92194. integer_signal,
  92195. residual[!_best_subframe],
  92196. encoder->private_->abs_residual_partition_sums,
  92197. encoder->private_->raw_bits_per_partition,
  92198. frame_header->blocksize,
  92199. subframe_bps,
  92200. fixed_order,
  92201. rice_parameter,
  92202. rice_parameter_limit,
  92203. min_partition_order,
  92204. max_partition_order,
  92205. encoder->protected_->do_escape_coding,
  92206. encoder->protected_->rice_parameter_search_dist,
  92207. subframe[!_best_subframe],
  92208. partitioned_rice_contents[!_best_subframe]
  92209. );
  92210. if(_candidate_bits < _best_bits) {
  92211. _best_subframe = !_best_subframe;
  92212. _best_bits = _candidate_bits;
  92213. }
  92214. }
  92215. }
  92216. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92217. if(encoder->protected_->max_lpc_order > 0) {
  92218. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92219. max_lpc_order = frame_header->blocksize-1;
  92220. else
  92221. max_lpc_order = encoder->protected_->max_lpc_order;
  92222. if(max_lpc_order > 0) {
  92223. unsigned a;
  92224. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92225. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92226. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92227. if(autoc[0] != 0.0) {
  92228. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92229. if(encoder->protected_->do_exhaustive_model_search) {
  92230. min_lpc_order = 1;
  92231. }
  92232. else {
  92233. const unsigned guess_lpc_order =
  92234. FLAC__lpc_compute_best_order(
  92235. lpc_error,
  92236. max_lpc_order,
  92237. frame_header->blocksize,
  92238. subframe_bps + (
  92239. encoder->protected_->do_qlp_coeff_prec_search?
  92240. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92241. encoder->protected_->qlp_coeff_precision
  92242. )
  92243. );
  92244. min_lpc_order = max_lpc_order = guess_lpc_order;
  92245. }
  92246. if(max_lpc_order >= frame_header->blocksize)
  92247. max_lpc_order = frame_header->blocksize - 1;
  92248. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92249. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92250. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92251. continue; /* don't even try */
  92252. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92253. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92254. if(rice_parameter >= rice_parameter_limit) {
  92255. #ifdef DEBUG_VERBOSE
  92256. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92257. #endif
  92258. rice_parameter = rice_parameter_limit - 1;
  92259. }
  92260. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92261. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92262. if(subframe_bps <= 17) {
  92263. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92264. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92265. }
  92266. else
  92267. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92268. }
  92269. else {
  92270. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92271. }
  92272. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92273. _candidate_bits =
  92274. evaluate_lpc_subframe_(
  92275. encoder,
  92276. integer_signal,
  92277. residual[!_best_subframe],
  92278. encoder->private_->abs_residual_partition_sums,
  92279. encoder->private_->raw_bits_per_partition,
  92280. encoder->private_->lp_coeff[lpc_order-1],
  92281. frame_header->blocksize,
  92282. subframe_bps,
  92283. lpc_order,
  92284. qlp_coeff_precision,
  92285. rice_parameter,
  92286. rice_parameter_limit,
  92287. min_partition_order,
  92288. max_partition_order,
  92289. encoder->protected_->do_escape_coding,
  92290. encoder->protected_->rice_parameter_search_dist,
  92291. subframe[!_best_subframe],
  92292. partitioned_rice_contents[!_best_subframe]
  92293. );
  92294. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92295. if(_candidate_bits < _best_bits) {
  92296. _best_subframe = !_best_subframe;
  92297. _best_bits = _candidate_bits;
  92298. }
  92299. }
  92300. }
  92301. }
  92302. }
  92303. }
  92304. }
  92305. }
  92306. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92307. }
  92308. }
  92309. if(_best_bits == UINT_MAX) {
  92310. FLAC__ASSERT(_best_subframe == 0);
  92311. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92312. }
  92313. *best_subframe = _best_subframe;
  92314. *best_bits = _best_bits;
  92315. return true;
  92316. }
  92317. FLAC__bool add_subframe_(
  92318. FLAC__StreamEncoder *encoder,
  92319. unsigned blocksize,
  92320. unsigned subframe_bps,
  92321. const FLAC__Subframe *subframe,
  92322. FLAC__BitWriter *frame
  92323. )
  92324. {
  92325. switch(subframe->type) {
  92326. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92327. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92328. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92329. return false;
  92330. }
  92331. break;
  92332. case FLAC__SUBFRAME_TYPE_FIXED:
  92333. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92334. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92335. return false;
  92336. }
  92337. break;
  92338. case FLAC__SUBFRAME_TYPE_LPC:
  92339. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92340. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92341. return false;
  92342. }
  92343. break;
  92344. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92345. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92346. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92347. return false;
  92348. }
  92349. break;
  92350. default:
  92351. FLAC__ASSERT(0);
  92352. }
  92353. return true;
  92354. }
  92355. #define SPOTCHECK_ESTIMATE 0
  92356. #if SPOTCHECK_ESTIMATE
  92357. static void spotcheck_subframe_estimate_(
  92358. FLAC__StreamEncoder *encoder,
  92359. unsigned blocksize,
  92360. unsigned subframe_bps,
  92361. const FLAC__Subframe *subframe,
  92362. unsigned estimate
  92363. )
  92364. {
  92365. FLAC__bool ret;
  92366. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92367. if(frame == 0) {
  92368. fprintf(stderr, "EST: can't allocate frame\n");
  92369. return;
  92370. }
  92371. if(!FLAC__bitwriter_init(frame)) {
  92372. fprintf(stderr, "EST: can't init frame\n");
  92373. return;
  92374. }
  92375. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92376. FLAC__ASSERT(ret);
  92377. {
  92378. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92379. if(estimate != actual)
  92380. 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);
  92381. }
  92382. FLAC__bitwriter_delete(frame);
  92383. }
  92384. #endif
  92385. unsigned evaluate_constant_subframe_(
  92386. FLAC__StreamEncoder *encoder,
  92387. const FLAC__int32 signal,
  92388. unsigned blocksize,
  92389. unsigned subframe_bps,
  92390. FLAC__Subframe *subframe
  92391. )
  92392. {
  92393. unsigned estimate;
  92394. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92395. subframe->data.constant.value = signal;
  92396. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92397. #if SPOTCHECK_ESTIMATE
  92398. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92399. #else
  92400. (void)encoder, (void)blocksize;
  92401. #endif
  92402. return estimate;
  92403. }
  92404. unsigned evaluate_fixed_subframe_(
  92405. FLAC__StreamEncoder *encoder,
  92406. const FLAC__int32 signal[],
  92407. FLAC__int32 residual[],
  92408. FLAC__uint64 abs_residual_partition_sums[],
  92409. unsigned raw_bits_per_partition[],
  92410. unsigned blocksize,
  92411. unsigned subframe_bps,
  92412. unsigned order,
  92413. unsigned rice_parameter,
  92414. unsigned rice_parameter_limit,
  92415. unsigned min_partition_order,
  92416. unsigned max_partition_order,
  92417. FLAC__bool do_escape_coding,
  92418. unsigned rice_parameter_search_dist,
  92419. FLAC__Subframe *subframe,
  92420. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92421. )
  92422. {
  92423. unsigned i, residual_bits, estimate;
  92424. const unsigned residual_samples = blocksize - order;
  92425. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92426. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92427. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92428. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92429. subframe->data.fixed.residual = residual;
  92430. residual_bits =
  92431. find_best_partition_order_(
  92432. encoder->private_,
  92433. residual,
  92434. abs_residual_partition_sums,
  92435. raw_bits_per_partition,
  92436. residual_samples,
  92437. order,
  92438. rice_parameter,
  92439. rice_parameter_limit,
  92440. min_partition_order,
  92441. max_partition_order,
  92442. subframe_bps,
  92443. do_escape_coding,
  92444. rice_parameter_search_dist,
  92445. &subframe->data.fixed.entropy_coding_method
  92446. );
  92447. subframe->data.fixed.order = order;
  92448. for(i = 0; i < order; i++)
  92449. subframe->data.fixed.warmup[i] = signal[i];
  92450. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92451. #if SPOTCHECK_ESTIMATE
  92452. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92453. #endif
  92454. return estimate;
  92455. }
  92456. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92457. unsigned evaluate_lpc_subframe_(
  92458. FLAC__StreamEncoder *encoder,
  92459. const FLAC__int32 signal[],
  92460. FLAC__int32 residual[],
  92461. FLAC__uint64 abs_residual_partition_sums[],
  92462. unsigned raw_bits_per_partition[],
  92463. const FLAC__real lp_coeff[],
  92464. unsigned blocksize,
  92465. unsigned subframe_bps,
  92466. unsigned order,
  92467. unsigned qlp_coeff_precision,
  92468. unsigned rice_parameter,
  92469. unsigned rice_parameter_limit,
  92470. unsigned min_partition_order,
  92471. unsigned max_partition_order,
  92472. FLAC__bool do_escape_coding,
  92473. unsigned rice_parameter_search_dist,
  92474. FLAC__Subframe *subframe,
  92475. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92476. )
  92477. {
  92478. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92479. unsigned i, residual_bits, estimate;
  92480. int quantization, ret;
  92481. const unsigned residual_samples = blocksize - order;
  92482. if(subframe_bps <= 16) {
  92483. FLAC__ASSERT(order > 0);
  92484. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92485. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92486. }
  92487. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92488. if(ret != 0)
  92489. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92490. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92491. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92492. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92493. else
  92494. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92495. else
  92496. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92497. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92498. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92499. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92500. subframe->data.lpc.residual = residual;
  92501. residual_bits =
  92502. find_best_partition_order_(
  92503. encoder->private_,
  92504. residual,
  92505. abs_residual_partition_sums,
  92506. raw_bits_per_partition,
  92507. residual_samples,
  92508. order,
  92509. rice_parameter,
  92510. rice_parameter_limit,
  92511. min_partition_order,
  92512. max_partition_order,
  92513. subframe_bps,
  92514. do_escape_coding,
  92515. rice_parameter_search_dist,
  92516. &subframe->data.lpc.entropy_coding_method
  92517. );
  92518. subframe->data.lpc.order = order;
  92519. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92520. subframe->data.lpc.quantization_level = quantization;
  92521. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92522. for(i = 0; i < order; i++)
  92523. subframe->data.lpc.warmup[i] = signal[i];
  92524. 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;
  92525. #if SPOTCHECK_ESTIMATE
  92526. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92527. #endif
  92528. return estimate;
  92529. }
  92530. #endif
  92531. unsigned evaluate_verbatim_subframe_(
  92532. FLAC__StreamEncoder *encoder,
  92533. const FLAC__int32 signal[],
  92534. unsigned blocksize,
  92535. unsigned subframe_bps,
  92536. FLAC__Subframe *subframe
  92537. )
  92538. {
  92539. unsigned estimate;
  92540. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92541. subframe->data.verbatim.data = signal;
  92542. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92543. #if SPOTCHECK_ESTIMATE
  92544. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92545. #else
  92546. (void)encoder;
  92547. #endif
  92548. return estimate;
  92549. }
  92550. unsigned find_best_partition_order_(
  92551. FLAC__StreamEncoderPrivate *private_,
  92552. const FLAC__int32 residual[],
  92553. FLAC__uint64 abs_residual_partition_sums[],
  92554. unsigned raw_bits_per_partition[],
  92555. unsigned residual_samples,
  92556. unsigned predictor_order,
  92557. unsigned rice_parameter,
  92558. unsigned rice_parameter_limit,
  92559. unsigned min_partition_order,
  92560. unsigned max_partition_order,
  92561. unsigned bps,
  92562. FLAC__bool do_escape_coding,
  92563. unsigned rice_parameter_search_dist,
  92564. FLAC__EntropyCodingMethod *best_ecm
  92565. )
  92566. {
  92567. unsigned residual_bits, best_residual_bits = 0;
  92568. unsigned best_parameters_index = 0;
  92569. unsigned best_partition_order = 0;
  92570. const unsigned blocksize = residual_samples + predictor_order;
  92571. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92572. min_partition_order = min(min_partition_order, max_partition_order);
  92573. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92574. if(do_escape_coding)
  92575. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92576. {
  92577. int partition_order;
  92578. unsigned sum;
  92579. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92580. if(!
  92581. set_partitioned_rice_(
  92582. #ifdef EXACT_RICE_BITS_CALCULATION
  92583. residual,
  92584. #endif
  92585. abs_residual_partition_sums+sum,
  92586. raw_bits_per_partition+sum,
  92587. residual_samples,
  92588. predictor_order,
  92589. rice_parameter,
  92590. rice_parameter_limit,
  92591. rice_parameter_search_dist,
  92592. (unsigned)partition_order,
  92593. do_escape_coding,
  92594. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92595. &residual_bits
  92596. )
  92597. )
  92598. {
  92599. FLAC__ASSERT(best_residual_bits != 0);
  92600. break;
  92601. }
  92602. sum += 1u << partition_order;
  92603. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92604. best_residual_bits = residual_bits;
  92605. best_parameters_index = !best_parameters_index;
  92606. best_partition_order = partition_order;
  92607. }
  92608. }
  92609. }
  92610. best_ecm->data.partitioned_rice.order = best_partition_order;
  92611. {
  92612. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92613. unsigned partition;
  92614. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92615. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92616. if(do_escape_coding)
  92617. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92618. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92619. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92620. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92621. break;
  92622. }
  92623. }
  92624. }
  92625. return best_residual_bits;
  92626. }
  92627. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92628. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92629. const FLAC__int32 residual[],
  92630. FLAC__uint64 abs_residual_partition_sums[],
  92631. unsigned blocksize,
  92632. unsigned predictor_order,
  92633. unsigned min_partition_order,
  92634. unsigned max_partition_order
  92635. );
  92636. #endif
  92637. void precompute_partition_info_sums_(
  92638. const FLAC__int32 residual[],
  92639. FLAC__uint64 abs_residual_partition_sums[],
  92640. unsigned residual_samples,
  92641. unsigned predictor_order,
  92642. unsigned min_partition_order,
  92643. unsigned max_partition_order,
  92644. unsigned bps
  92645. )
  92646. {
  92647. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92648. unsigned partitions = 1u << max_partition_order;
  92649. FLAC__ASSERT(default_partition_samples > predictor_order);
  92650. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92651. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92652. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92653. return;
  92654. }
  92655. #endif
  92656. {
  92657. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92658. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92659. FLAC__uint32 abs_residual_partition_sum;
  92660. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92661. end += default_partition_samples;
  92662. abs_residual_partition_sum = 0;
  92663. for( ; residual_sample < end; residual_sample++)
  92664. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92665. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92666. }
  92667. }
  92668. else { /* have to pessimistically use 64 bits for accumulator */
  92669. FLAC__uint64 abs_residual_partition_sum;
  92670. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92671. end += default_partition_samples;
  92672. abs_residual_partition_sum = 0;
  92673. for( ; residual_sample < end; residual_sample++)
  92674. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92675. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92676. }
  92677. }
  92678. }
  92679. {
  92680. unsigned from_partition = 0, to_partition = partitions;
  92681. int partition_order;
  92682. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92683. unsigned i;
  92684. partitions >>= 1;
  92685. for(i = 0; i < partitions; i++) {
  92686. abs_residual_partition_sums[to_partition++] =
  92687. abs_residual_partition_sums[from_partition ] +
  92688. abs_residual_partition_sums[from_partition+1];
  92689. from_partition += 2;
  92690. }
  92691. }
  92692. }
  92693. }
  92694. void precompute_partition_info_escapes_(
  92695. const FLAC__int32 residual[],
  92696. unsigned raw_bits_per_partition[],
  92697. unsigned residual_samples,
  92698. unsigned predictor_order,
  92699. unsigned min_partition_order,
  92700. unsigned max_partition_order
  92701. )
  92702. {
  92703. int partition_order;
  92704. unsigned from_partition, to_partition = 0;
  92705. const unsigned blocksize = residual_samples + predictor_order;
  92706. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92707. FLAC__int32 r;
  92708. FLAC__uint32 rmax;
  92709. unsigned partition, partition_sample, partition_samples, residual_sample;
  92710. const unsigned partitions = 1u << partition_order;
  92711. const unsigned default_partition_samples = blocksize >> partition_order;
  92712. FLAC__ASSERT(default_partition_samples > predictor_order);
  92713. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92714. partition_samples = default_partition_samples;
  92715. if(partition == 0)
  92716. partition_samples -= predictor_order;
  92717. rmax = 0;
  92718. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92719. r = residual[residual_sample++];
  92720. if(r < 0)
  92721. rmax |= ~r;
  92722. else
  92723. rmax |= r;
  92724. }
  92725. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92726. }
  92727. to_partition = partitions;
  92728. break; /*@@@ yuck, should remove the 'for' loop instead */
  92729. }
  92730. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92731. unsigned m;
  92732. unsigned i;
  92733. const unsigned partitions = 1u << partition_order;
  92734. for(i = 0; i < partitions; i++) {
  92735. m = raw_bits_per_partition[from_partition];
  92736. from_partition++;
  92737. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92738. from_partition++;
  92739. to_partition++;
  92740. }
  92741. }
  92742. }
  92743. #ifdef EXACT_RICE_BITS_CALCULATION
  92744. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92745. const unsigned rice_parameter,
  92746. const unsigned partition_samples,
  92747. const FLAC__int32 *residual
  92748. )
  92749. {
  92750. unsigned i, partition_bits =
  92751. 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 */
  92752. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92753. ;
  92754. for(i = 0; i < partition_samples; i++)
  92755. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92756. return partition_bits;
  92757. }
  92758. #else
  92759. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92760. const unsigned rice_parameter,
  92761. const unsigned partition_samples,
  92762. const FLAC__uint64 abs_residual_partition_sum
  92763. )
  92764. {
  92765. return
  92766. 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 */
  92767. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92768. (
  92769. rice_parameter?
  92770. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92771. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92772. )
  92773. - (partition_samples >> 1)
  92774. ;
  92775. }
  92776. #endif
  92777. FLAC__bool set_partitioned_rice_(
  92778. #ifdef EXACT_RICE_BITS_CALCULATION
  92779. const FLAC__int32 residual[],
  92780. #endif
  92781. const FLAC__uint64 abs_residual_partition_sums[],
  92782. const unsigned raw_bits_per_partition[],
  92783. const unsigned residual_samples,
  92784. const unsigned predictor_order,
  92785. const unsigned suggested_rice_parameter,
  92786. const unsigned rice_parameter_limit,
  92787. const unsigned rice_parameter_search_dist,
  92788. const unsigned partition_order,
  92789. const FLAC__bool search_for_escapes,
  92790. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92791. unsigned *bits
  92792. )
  92793. {
  92794. unsigned rice_parameter, partition_bits;
  92795. unsigned best_partition_bits, best_rice_parameter = 0;
  92796. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92797. unsigned *parameters, *raw_bits;
  92798. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92799. unsigned min_rice_parameter, max_rice_parameter;
  92800. #else
  92801. (void)rice_parameter_search_dist;
  92802. #endif
  92803. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92804. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92805. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92806. parameters = partitioned_rice_contents->parameters;
  92807. raw_bits = partitioned_rice_contents->raw_bits;
  92808. if(partition_order == 0) {
  92809. best_partition_bits = (unsigned)(-1);
  92810. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92811. if(rice_parameter_search_dist) {
  92812. if(suggested_rice_parameter < rice_parameter_search_dist)
  92813. min_rice_parameter = 0;
  92814. else
  92815. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92816. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92817. if(max_rice_parameter >= rice_parameter_limit) {
  92818. #ifdef DEBUG_VERBOSE
  92819. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92820. #endif
  92821. max_rice_parameter = rice_parameter_limit - 1;
  92822. }
  92823. }
  92824. else
  92825. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92826. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92827. #else
  92828. rice_parameter = suggested_rice_parameter;
  92829. #endif
  92830. #ifdef EXACT_RICE_BITS_CALCULATION
  92831. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92832. #else
  92833. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92834. #endif
  92835. if(partition_bits < best_partition_bits) {
  92836. best_rice_parameter = rice_parameter;
  92837. best_partition_bits = partition_bits;
  92838. }
  92839. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92840. }
  92841. #endif
  92842. if(search_for_escapes) {
  92843. 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;
  92844. if(partition_bits <= best_partition_bits) {
  92845. raw_bits[0] = raw_bits_per_partition[0];
  92846. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92847. best_partition_bits = partition_bits;
  92848. }
  92849. else
  92850. raw_bits[0] = 0;
  92851. }
  92852. parameters[0] = best_rice_parameter;
  92853. bits_ += best_partition_bits;
  92854. }
  92855. else {
  92856. unsigned partition, residual_sample;
  92857. unsigned partition_samples;
  92858. FLAC__uint64 mean, k;
  92859. const unsigned partitions = 1u << partition_order;
  92860. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92861. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92862. if(partition == 0) {
  92863. if(partition_samples <= predictor_order)
  92864. return false;
  92865. else
  92866. partition_samples -= predictor_order;
  92867. }
  92868. mean = abs_residual_partition_sums[partition];
  92869. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92870. ;
  92871. if(rice_parameter >= rice_parameter_limit) {
  92872. #ifdef DEBUG_VERBOSE
  92873. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92874. #endif
  92875. rice_parameter = rice_parameter_limit - 1;
  92876. }
  92877. best_partition_bits = (unsigned)(-1);
  92878. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92879. if(rice_parameter_search_dist) {
  92880. if(rice_parameter < rice_parameter_search_dist)
  92881. min_rice_parameter = 0;
  92882. else
  92883. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92884. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  92885. if(max_rice_parameter >= rice_parameter_limit) {
  92886. #ifdef DEBUG_VERBOSE
  92887. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  92888. #endif
  92889. max_rice_parameter = rice_parameter_limit - 1;
  92890. }
  92891. }
  92892. else
  92893. min_rice_parameter = max_rice_parameter = rice_parameter;
  92894. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92895. #endif
  92896. #ifdef EXACT_RICE_BITS_CALCULATION
  92897. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  92898. #else
  92899. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  92900. #endif
  92901. if(partition_bits < best_partition_bits) {
  92902. best_rice_parameter = rice_parameter;
  92903. best_partition_bits = partition_bits;
  92904. }
  92905. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92906. }
  92907. #endif
  92908. if(search_for_escapes) {
  92909. 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;
  92910. if(partition_bits <= best_partition_bits) {
  92911. raw_bits[partition] = raw_bits_per_partition[partition];
  92912. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92913. best_partition_bits = partition_bits;
  92914. }
  92915. else
  92916. raw_bits[partition] = 0;
  92917. }
  92918. parameters[partition] = best_rice_parameter;
  92919. bits_ += best_partition_bits;
  92920. residual_sample += partition_samples;
  92921. }
  92922. }
  92923. *bits = bits_;
  92924. return true;
  92925. }
  92926. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  92927. {
  92928. unsigned i, shift;
  92929. FLAC__int32 x = 0;
  92930. for(i = 0; i < samples && !(x&1); i++)
  92931. x |= signal[i];
  92932. if(x == 0) {
  92933. shift = 0;
  92934. }
  92935. else {
  92936. for(shift = 0; !(x&1); shift++)
  92937. x >>= 1;
  92938. }
  92939. if(shift > 0) {
  92940. for(i = 0; i < samples; i++)
  92941. signal[i] >>= shift;
  92942. }
  92943. return shift;
  92944. }
  92945. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92946. {
  92947. unsigned channel;
  92948. for(channel = 0; channel < channels; channel++)
  92949. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  92950. fifo->tail += wide_samples;
  92951. FLAC__ASSERT(fifo->tail <= fifo->size);
  92952. }
  92953. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92954. {
  92955. unsigned channel;
  92956. unsigned sample, wide_sample;
  92957. unsigned tail = fifo->tail;
  92958. sample = input_offset * channels;
  92959. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  92960. for(channel = 0; channel < channels; channel++)
  92961. fifo->data[channel][tail] = input[sample++];
  92962. tail++;
  92963. }
  92964. fifo->tail = tail;
  92965. FLAC__ASSERT(fifo->tail <= fifo->size);
  92966. }
  92967. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92968. {
  92969. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92970. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  92971. (void)decoder;
  92972. if(encoder->private_->verify.needs_magic_hack) {
  92973. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  92974. *bytes = FLAC__STREAM_SYNC_LENGTH;
  92975. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  92976. encoder->private_->verify.needs_magic_hack = false;
  92977. }
  92978. else {
  92979. if(encoded_bytes == 0) {
  92980. FLAC__ASSERT(0);
  92981. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  92982. }
  92983. else if(encoded_bytes < *bytes)
  92984. *bytes = encoded_bytes;
  92985. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  92986. encoder->private_->verify.output.data += *bytes;
  92987. encoder->private_->verify.output.bytes -= *bytes;
  92988. }
  92989. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  92990. }
  92991. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  92992. {
  92993. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  92994. unsigned channel;
  92995. const unsigned channels = frame->header.channels;
  92996. const unsigned blocksize = frame->header.blocksize;
  92997. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  92998. (void)decoder;
  92999. for(channel = 0; channel < channels; channel++) {
  93000. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93001. unsigned i, sample = 0;
  93002. FLAC__int32 expect = 0, got = 0;
  93003. for(i = 0; i < blocksize; i++) {
  93004. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93005. sample = i;
  93006. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93007. got = (FLAC__int32)buffer[channel][i];
  93008. break;
  93009. }
  93010. }
  93011. FLAC__ASSERT(i < blocksize);
  93012. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93013. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93014. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93015. encoder->private_->verify.error_stats.channel = channel;
  93016. encoder->private_->verify.error_stats.sample = sample;
  93017. encoder->private_->verify.error_stats.expected = expect;
  93018. encoder->private_->verify.error_stats.got = got;
  93019. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93020. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93021. }
  93022. }
  93023. encoder->private_->verify.input_fifo.tail -= blocksize;
  93024. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93025. for(channel = 0; channel < channels; channel++)
  93026. 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]));
  93027. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93028. }
  93029. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93030. {
  93031. (void)decoder, (void)metadata, (void)client_data;
  93032. }
  93033. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93034. {
  93035. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93036. (void)decoder, (void)status;
  93037. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93038. }
  93039. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93040. {
  93041. (void)client_data;
  93042. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93043. if (*bytes == 0) {
  93044. if (feof(encoder->private_->file))
  93045. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93046. else if (ferror(encoder->private_->file))
  93047. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93048. }
  93049. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93050. }
  93051. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93052. {
  93053. (void)client_data;
  93054. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93055. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93056. else
  93057. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93058. }
  93059. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93060. {
  93061. off_t offset;
  93062. (void)client_data;
  93063. offset = ftello(encoder->private_->file);
  93064. if(offset < 0) {
  93065. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93066. }
  93067. else {
  93068. *absolute_byte_offset = (FLAC__uint64)offset;
  93069. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93070. }
  93071. }
  93072. #ifdef FLAC__VALGRIND_TESTING
  93073. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93074. {
  93075. size_t ret = fwrite(ptr, size, nmemb, stream);
  93076. if(!ferror(stream))
  93077. fflush(stream);
  93078. return ret;
  93079. }
  93080. #else
  93081. #define local__fwrite fwrite
  93082. #endif
  93083. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93084. {
  93085. (void)client_data, (void)current_frame;
  93086. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93087. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93088. #if FLAC__HAS_OGG
  93089. encoder->private_->is_ogg? true :
  93090. #endif
  93091. samples > 0
  93092. );
  93093. if(call_it) {
  93094. 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);
  93095. }
  93096. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93097. }
  93098. else
  93099. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93100. }
  93101. FILE *get_binary_stdout_(void)
  93102. {
  93103. #if defined _MSC_VER || defined __MINGW32__
  93104. _setmode(_fileno(stdout), _O_BINARY);
  93105. #elif defined __CYGWIN__
  93106. setmode(_fileno(stdout), _O_BINARY);
  93107. #elif defined __EMX__
  93108. setmode(fileno(stdout), O_BINARY);
  93109. #endif
  93110. return stdout;
  93111. }
  93112. #endif
  93113. /*** End of inlined file: stream_encoder.c ***/
  93114. /*** Start of inlined file: stream_encoder_framing.c ***/
  93115. /*** Start of inlined file: juce_FlacHeader.h ***/
  93116. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93117. // tasks..
  93118. #define VERSION "1.2.1"
  93119. #define FLAC__NO_DLL 1
  93120. #if JUCE_MSVC
  93121. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93122. #endif
  93123. #if JUCE_MAC
  93124. #define FLAC__SYS_DARWIN 1
  93125. #endif
  93126. /*** End of inlined file: juce_FlacHeader.h ***/
  93127. #if JUCE_USE_FLAC
  93128. #if HAVE_CONFIG_H
  93129. # include <config.h>
  93130. #endif
  93131. #include <stdio.h>
  93132. #include <string.h> /* for strlen() */
  93133. #ifdef max
  93134. #undef max
  93135. #endif
  93136. #define max(x,y) ((x)>(y)?(x):(y))
  93137. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93138. 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);
  93139. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93140. {
  93141. unsigned i, j;
  93142. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93143. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93144. return false;
  93145. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93146. return false;
  93147. i = metadata->length;
  93148. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93149. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93150. i -= metadata->data.vorbis_comment.vendor_string.length;
  93151. i += vendor_string_length;
  93152. }
  93153. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93154. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93155. return false;
  93156. switch(metadata->type) {
  93157. case FLAC__METADATA_TYPE_STREAMINFO:
  93158. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93159. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93160. return false;
  93161. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93162. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93163. return false;
  93164. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93165. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93166. return false;
  93167. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93168. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93169. return false;
  93170. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93171. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93172. return false;
  93173. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93174. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93175. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93176. return false;
  93177. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93178. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93179. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93180. return false;
  93181. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93182. return false;
  93183. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93184. return false;
  93185. break;
  93186. case FLAC__METADATA_TYPE_PADDING:
  93187. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93188. return false;
  93189. break;
  93190. case FLAC__METADATA_TYPE_APPLICATION:
  93191. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93192. return false;
  93193. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93194. return false;
  93195. break;
  93196. case FLAC__METADATA_TYPE_SEEKTABLE:
  93197. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93198. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93199. return false;
  93200. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93201. return false;
  93202. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93203. return false;
  93204. }
  93205. break;
  93206. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93207. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93208. return false;
  93209. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93210. return false;
  93211. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93212. return false;
  93213. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93214. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93215. return false;
  93216. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93217. return false;
  93218. }
  93219. break;
  93220. case FLAC__METADATA_TYPE_CUESHEET:
  93221. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93222. 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))
  93223. return false;
  93224. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93225. return false;
  93226. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93227. return false;
  93228. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93229. return false;
  93230. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93231. return false;
  93232. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93233. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93234. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93235. return false;
  93236. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93237. return false;
  93238. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93239. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93240. return false;
  93241. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93242. return false;
  93243. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93244. return false;
  93245. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93246. return false;
  93247. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93248. return false;
  93249. for(j = 0; j < track->num_indices; j++) {
  93250. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93251. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93252. return false;
  93253. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93254. return false;
  93255. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93256. return false;
  93257. }
  93258. }
  93259. break;
  93260. case FLAC__METADATA_TYPE_PICTURE:
  93261. {
  93262. size_t len;
  93263. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93264. return false;
  93265. len = strlen(metadata->data.picture.mime_type);
  93266. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93267. return false;
  93268. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93269. return false;
  93270. len = strlen((const char *)metadata->data.picture.description);
  93271. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93272. return false;
  93273. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93274. return false;
  93275. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93276. return false;
  93277. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93278. return false;
  93279. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93280. return false;
  93281. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93282. return false;
  93283. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93284. return false;
  93285. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93286. return false;
  93287. }
  93288. break;
  93289. default:
  93290. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93291. return false;
  93292. break;
  93293. }
  93294. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93295. return true;
  93296. }
  93297. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93298. {
  93299. unsigned u, blocksize_hint, sample_rate_hint;
  93300. FLAC__byte crc;
  93301. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93302. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93303. return false;
  93304. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93305. return false;
  93306. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93307. return false;
  93308. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93309. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93310. blocksize_hint = 0;
  93311. switch(header->blocksize) {
  93312. case 192: u = 1; break;
  93313. case 576: u = 2; break;
  93314. case 1152: u = 3; break;
  93315. case 2304: u = 4; break;
  93316. case 4608: u = 5; break;
  93317. case 256: u = 8; break;
  93318. case 512: u = 9; break;
  93319. case 1024: u = 10; break;
  93320. case 2048: u = 11; break;
  93321. case 4096: u = 12; break;
  93322. case 8192: u = 13; break;
  93323. case 16384: u = 14; break;
  93324. case 32768: u = 15; break;
  93325. default:
  93326. if(header->blocksize <= 0x100)
  93327. blocksize_hint = u = 6;
  93328. else
  93329. blocksize_hint = u = 7;
  93330. break;
  93331. }
  93332. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93333. return false;
  93334. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93335. sample_rate_hint = 0;
  93336. switch(header->sample_rate) {
  93337. case 88200: u = 1; break;
  93338. case 176400: u = 2; break;
  93339. case 192000: u = 3; break;
  93340. case 8000: u = 4; break;
  93341. case 16000: u = 5; break;
  93342. case 22050: u = 6; break;
  93343. case 24000: u = 7; break;
  93344. case 32000: u = 8; break;
  93345. case 44100: u = 9; break;
  93346. case 48000: u = 10; break;
  93347. case 96000: u = 11; break;
  93348. default:
  93349. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93350. sample_rate_hint = u = 12;
  93351. else if(header->sample_rate % 10 == 0)
  93352. sample_rate_hint = u = 14;
  93353. else if(header->sample_rate <= 0xffff)
  93354. sample_rate_hint = u = 13;
  93355. else
  93356. u = 0;
  93357. break;
  93358. }
  93359. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93360. return false;
  93361. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93362. switch(header->channel_assignment) {
  93363. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93364. u = header->channels - 1;
  93365. break;
  93366. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93367. FLAC__ASSERT(header->channels == 2);
  93368. u = 8;
  93369. break;
  93370. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93371. FLAC__ASSERT(header->channels == 2);
  93372. u = 9;
  93373. break;
  93374. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93375. FLAC__ASSERT(header->channels == 2);
  93376. u = 10;
  93377. break;
  93378. default:
  93379. FLAC__ASSERT(0);
  93380. }
  93381. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93382. return false;
  93383. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93384. switch(header->bits_per_sample) {
  93385. case 8 : u = 1; break;
  93386. case 12: u = 2; break;
  93387. case 16: u = 4; break;
  93388. case 20: u = 5; break;
  93389. case 24: u = 6; break;
  93390. default: u = 0; break;
  93391. }
  93392. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93393. return false;
  93394. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93395. return false;
  93396. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93397. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93398. return false;
  93399. }
  93400. else {
  93401. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93402. return false;
  93403. }
  93404. if(blocksize_hint)
  93405. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93406. return false;
  93407. switch(sample_rate_hint) {
  93408. case 12:
  93409. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93410. return false;
  93411. break;
  93412. case 13:
  93413. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93414. return false;
  93415. break;
  93416. case 14:
  93417. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93418. return false;
  93419. break;
  93420. }
  93421. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93422. return false;
  93423. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93424. return false;
  93425. return true;
  93426. }
  93427. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93428. {
  93429. FLAC__bool ok;
  93430. ok =
  93431. 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) &&
  93432. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93433. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93434. ;
  93435. return ok;
  93436. }
  93437. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93438. {
  93439. unsigned i;
  93440. 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))
  93441. return false;
  93442. if(wasted_bits)
  93443. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93444. return false;
  93445. for(i = 0; i < subframe->order; i++)
  93446. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93447. return false;
  93448. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93449. return false;
  93450. switch(subframe->entropy_coding_method.type) {
  93451. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93452. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93453. if(!add_residual_partitioned_rice_(
  93454. bw,
  93455. subframe->residual,
  93456. residual_samples,
  93457. subframe->order,
  93458. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93459. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93460. subframe->entropy_coding_method.data.partitioned_rice.order,
  93461. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93462. ))
  93463. return false;
  93464. break;
  93465. default:
  93466. FLAC__ASSERT(0);
  93467. }
  93468. return true;
  93469. }
  93470. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93471. {
  93472. unsigned i;
  93473. 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))
  93474. return false;
  93475. if(wasted_bits)
  93476. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93477. return false;
  93478. for(i = 0; i < subframe->order; i++)
  93479. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93480. return false;
  93481. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93482. return false;
  93483. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93484. return false;
  93485. for(i = 0; i < subframe->order; i++)
  93486. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93487. return false;
  93488. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93489. return false;
  93490. switch(subframe->entropy_coding_method.type) {
  93491. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93492. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93493. if(!add_residual_partitioned_rice_(
  93494. bw,
  93495. subframe->residual,
  93496. residual_samples,
  93497. subframe->order,
  93498. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93499. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93500. subframe->entropy_coding_method.data.partitioned_rice.order,
  93501. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93502. ))
  93503. return false;
  93504. break;
  93505. default:
  93506. FLAC__ASSERT(0);
  93507. }
  93508. return true;
  93509. }
  93510. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93511. {
  93512. unsigned i;
  93513. const FLAC__int32 *signal = subframe->data;
  93514. 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))
  93515. return false;
  93516. if(wasted_bits)
  93517. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93518. return false;
  93519. for(i = 0; i < samples; i++)
  93520. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93521. return false;
  93522. return true;
  93523. }
  93524. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93525. {
  93526. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93527. return false;
  93528. switch(method->type) {
  93529. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93530. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93531. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93532. return false;
  93533. break;
  93534. default:
  93535. FLAC__ASSERT(0);
  93536. }
  93537. return true;
  93538. }
  93539. 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)
  93540. {
  93541. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93542. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93543. if(partition_order == 0) {
  93544. unsigned i;
  93545. if(raw_bits[0] == 0) {
  93546. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93547. return false;
  93548. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93549. return false;
  93550. }
  93551. else {
  93552. FLAC__ASSERT(rice_parameters[0] == 0);
  93553. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93554. return false;
  93555. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93556. return false;
  93557. for(i = 0; i < residual_samples; i++) {
  93558. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93559. return false;
  93560. }
  93561. }
  93562. return true;
  93563. }
  93564. else {
  93565. unsigned i, j, k = 0, k_last = 0;
  93566. unsigned partition_samples;
  93567. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93568. for(i = 0; i < (1u<<partition_order); i++) {
  93569. partition_samples = default_partition_samples;
  93570. if(i == 0)
  93571. partition_samples -= predictor_order;
  93572. k += partition_samples;
  93573. if(raw_bits[i] == 0) {
  93574. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93575. return false;
  93576. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93577. return false;
  93578. }
  93579. else {
  93580. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93581. return false;
  93582. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93583. return false;
  93584. for(j = k_last; j < k; j++) {
  93585. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93586. return false;
  93587. }
  93588. }
  93589. k_last = k;
  93590. }
  93591. return true;
  93592. }
  93593. }
  93594. #endif
  93595. /*** End of inlined file: stream_encoder_framing.c ***/
  93596. /*** Start of inlined file: window_flac.c ***/
  93597. /*** Start of inlined file: juce_FlacHeader.h ***/
  93598. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93599. // tasks..
  93600. #define VERSION "1.2.1"
  93601. #define FLAC__NO_DLL 1
  93602. #if JUCE_MSVC
  93603. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93604. #endif
  93605. #if JUCE_MAC
  93606. #define FLAC__SYS_DARWIN 1
  93607. #endif
  93608. /*** End of inlined file: juce_FlacHeader.h ***/
  93609. #if JUCE_USE_FLAC
  93610. #if HAVE_CONFIG_H
  93611. # include <config.h>
  93612. #endif
  93613. #include <math.h>
  93614. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93615. #ifndef M_PI
  93616. #define M_PI 3.14159265358979323846
  93617. #endif
  93618. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93619. {
  93620. const FLAC__int32 N = L - 1;
  93621. FLAC__int32 n;
  93622. if (L & 1) {
  93623. for (n = 0; n <= N/2; n++)
  93624. window[n] = 2.0f * n / (float)N;
  93625. for (; n <= N; n++)
  93626. window[n] = 2.0f - 2.0f * n / (float)N;
  93627. }
  93628. else {
  93629. for (n = 0; n <= L/2-1; n++)
  93630. window[n] = 2.0f * n / (float)N;
  93631. for (; n <= N; n++)
  93632. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93633. }
  93634. }
  93635. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93636. {
  93637. const FLAC__int32 N = L - 1;
  93638. FLAC__int32 n;
  93639. for (n = 0; n < L; n++)
  93640. 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)));
  93641. }
  93642. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93643. {
  93644. const FLAC__int32 N = L - 1;
  93645. FLAC__int32 n;
  93646. for (n = 0; n < L; n++)
  93647. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93648. }
  93649. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93650. {
  93651. const FLAC__int32 N = L - 1;
  93652. FLAC__int32 n;
  93653. for (n = 0; n <= N; n++)
  93654. 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));
  93655. }
  93656. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93657. {
  93658. const FLAC__int32 N = L - 1;
  93659. const double N2 = (double)N / 2.;
  93660. FLAC__int32 n;
  93661. for (n = 0; n <= N; n++) {
  93662. double k = ((double)n - N2) / N2;
  93663. k = 1.0f - k * k;
  93664. window[n] = (FLAC__real)(k * k);
  93665. }
  93666. }
  93667. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93668. {
  93669. const FLAC__int32 N = L - 1;
  93670. FLAC__int32 n;
  93671. for (n = 0; n < L; n++)
  93672. 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));
  93673. }
  93674. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93675. {
  93676. const FLAC__int32 N = L - 1;
  93677. const double N2 = (double)N / 2.;
  93678. FLAC__int32 n;
  93679. for (n = 0; n <= N; n++) {
  93680. const double k = ((double)n - N2) / (stddev * N2);
  93681. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93682. }
  93683. }
  93684. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93685. {
  93686. const FLAC__int32 N = L - 1;
  93687. FLAC__int32 n;
  93688. for (n = 0; n < L; n++)
  93689. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93690. }
  93691. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93692. {
  93693. const FLAC__int32 N = L - 1;
  93694. FLAC__int32 n;
  93695. for (n = 0; n < L; n++)
  93696. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93697. }
  93698. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93699. {
  93700. const FLAC__int32 N = L - 1;
  93701. FLAC__int32 n;
  93702. for (n = 0; n < L; n++)
  93703. 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));
  93704. }
  93705. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93706. {
  93707. const FLAC__int32 N = L - 1;
  93708. FLAC__int32 n;
  93709. for (n = 0; n < L; n++)
  93710. 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));
  93711. }
  93712. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93713. {
  93714. FLAC__int32 n;
  93715. for (n = 0; n < L; n++)
  93716. window[n] = 1.0f;
  93717. }
  93718. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93719. {
  93720. FLAC__int32 n;
  93721. if (L & 1) {
  93722. for (n = 1; n <= L+1/2; n++)
  93723. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93724. for (; n <= L; n++)
  93725. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93726. }
  93727. else {
  93728. for (n = 1; n <= L/2; n++)
  93729. window[n-1] = 2.0f * n / (float)L;
  93730. for (; n <= L; n++)
  93731. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93732. }
  93733. }
  93734. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93735. {
  93736. if (p <= 0.0)
  93737. FLAC__window_rectangle(window, L);
  93738. else if (p >= 1.0)
  93739. FLAC__window_hann(window, L);
  93740. else {
  93741. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93742. FLAC__int32 n;
  93743. FLAC__window_rectangle(window, L);
  93744. if (Np > 0) {
  93745. for (n = 0; n <= Np; n++) {
  93746. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93747. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93748. }
  93749. }
  93750. }
  93751. }
  93752. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93753. {
  93754. const FLAC__int32 N = L - 1;
  93755. const double N2 = (double)N / 2.;
  93756. FLAC__int32 n;
  93757. for (n = 0; n <= N; n++) {
  93758. const double k = ((double)n - N2) / N2;
  93759. window[n] = (FLAC__real)(1.0f - k * k);
  93760. }
  93761. }
  93762. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93763. #endif
  93764. /*** End of inlined file: window_flac.c ***/
  93765. #else
  93766. #include <FLAC/all.h>
  93767. #endif
  93768. }
  93769. #undef max
  93770. #undef min
  93771. #ifdef _MSC_VER
  93772. #pragma warning (pop)
  93773. #endif
  93774. BEGIN_JUCE_NAMESPACE
  93775. static const char* const flacFormatName = "FLAC file";
  93776. static const juce_wchar* const flacExtensions[] = { T(".flac"), 0 };
  93777. class FlacReader : public AudioFormatReader
  93778. {
  93779. public:
  93780. FlacReader (InputStream* const in)
  93781. : AudioFormatReader (in, TRANS (flacFormatName)),
  93782. reservoir (2, 0),
  93783. reservoirStart (0),
  93784. samplesInReservoir (0),
  93785. scanningForLength (false)
  93786. {
  93787. using namespace FlacNamespace;
  93788. lengthInSamples = 0;
  93789. decoder = FLAC__stream_decoder_new();
  93790. ok = FLAC__stream_decoder_init_stream (decoder,
  93791. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93792. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93793. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93794. if (ok)
  93795. {
  93796. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93797. if (lengthInSamples == 0 && sampleRate > 0)
  93798. {
  93799. // the length hasn't been stored in the metadata, so we'll need to
  93800. // work it out the length the hard way, by scanning the whole file..
  93801. scanningForLength = true;
  93802. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93803. scanningForLength = false;
  93804. const int64 tempLength = lengthInSamples;
  93805. FLAC__stream_decoder_reset (decoder);
  93806. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93807. lengthInSamples = tempLength;
  93808. }
  93809. }
  93810. }
  93811. ~FlacReader()
  93812. {
  93813. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93814. }
  93815. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93816. {
  93817. sampleRate = info.sample_rate;
  93818. bitsPerSample = info.bits_per_sample;
  93819. lengthInSamples = (unsigned int) info.total_samples;
  93820. numChannels = info.channels;
  93821. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93822. }
  93823. // returns the number of samples read
  93824. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93825. int64 startSampleInFile, int numSamples)
  93826. {
  93827. using namespace FlacNamespace;
  93828. if (! ok)
  93829. return false;
  93830. while (numSamples > 0)
  93831. {
  93832. if (startSampleInFile >= reservoirStart
  93833. && startSampleInFile < reservoirStart + samplesInReservoir)
  93834. {
  93835. const int num = (int) jmin ((int64) numSamples,
  93836. reservoirStart + samplesInReservoir - startSampleInFile);
  93837. jassert (num > 0);
  93838. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93839. if (destSamples[i] != 0)
  93840. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93841. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93842. sizeof (int) * num);
  93843. startOffsetInDestBuffer += num;
  93844. startSampleInFile += num;
  93845. numSamples -= num;
  93846. }
  93847. else
  93848. {
  93849. if (startSampleInFile >= (int) lengthInSamples)
  93850. {
  93851. samplesInReservoir = 0;
  93852. }
  93853. else if (startSampleInFile < reservoirStart
  93854. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93855. {
  93856. // had some problems with flac crashing if the read pos is aligned more
  93857. // accurately than this. Probably fixed in newer versions of the library, though.
  93858. reservoirStart = (int) (startSampleInFile & ~511);
  93859. samplesInReservoir = 0;
  93860. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93861. }
  93862. else
  93863. {
  93864. reservoirStart += samplesInReservoir;
  93865. samplesInReservoir = 0;
  93866. FLAC__stream_decoder_process_single (decoder);
  93867. }
  93868. if (samplesInReservoir == 0)
  93869. break;
  93870. }
  93871. }
  93872. if (numSamples > 0)
  93873. {
  93874. for (int i = numDestChannels; --i >= 0;)
  93875. if (destSamples[i] != 0)
  93876. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93877. sizeof (int) * numSamples);
  93878. }
  93879. return true;
  93880. }
  93881. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93882. {
  93883. if (scanningForLength)
  93884. {
  93885. lengthInSamples += numSamples;
  93886. }
  93887. else
  93888. {
  93889. if (numSamples > reservoir.getNumSamples())
  93890. reservoir.setSize (numChannels, numSamples, false, false, true);
  93891. const int bitsToShift = 32 - bitsPerSample;
  93892. for (int i = 0; i < (int) numChannels; ++i)
  93893. {
  93894. const FlacNamespace::FLAC__int32* src = buffer[i];
  93895. int n = i;
  93896. while (src == 0 && n > 0)
  93897. src = buffer [--n];
  93898. if (src != 0)
  93899. {
  93900. int* dest = (int*) reservoir.getSampleData(i);
  93901. for (int j = 0; j < numSamples; ++j)
  93902. dest[j] = src[j] << bitsToShift;
  93903. }
  93904. }
  93905. samplesInReservoir = numSamples;
  93906. }
  93907. }
  93908. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  93909. {
  93910. using namespace FlacNamespace;
  93911. *bytes = (size_t) static_cast <const FlacReader*> (client_data)->input->read (buffer, (int) *bytes);
  93912. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93913. }
  93914. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  93915. {
  93916. using namespace FlacNamespace;
  93917. static_cast <const FlacReader*> (client_data)->input->setPosition ((int) absolute_byte_offset);
  93918. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  93919. }
  93920. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93921. {
  93922. using namespace FlacNamespace;
  93923. *absolute_byte_offset = static_cast <const FlacReader*> (client_data)->input->getPosition();
  93924. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  93925. }
  93926. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  93927. {
  93928. using namespace FlacNamespace;
  93929. *stream_length = static_cast <const FlacReader*> (client_data)->input->getTotalLength();
  93930. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  93931. }
  93932. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  93933. {
  93934. return static_cast <const FlacReader*> (client_data)->input->isExhausted();
  93935. }
  93936. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93937. const FlacNamespace::FLAC__Frame* frame,
  93938. const FlacNamespace::FLAC__int32* const buffer[],
  93939. void* client_data)
  93940. {
  93941. using namespace FlacNamespace;
  93942. static_cast <FlacReader*> (client_data)->useSamples (buffer, frame->header.blocksize);
  93943. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93944. }
  93945. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93946. const FlacNamespace::FLAC__StreamMetadata* metadata,
  93947. void* client_data)
  93948. {
  93949. static_cast <FlacReader*> (client_data)->useMetadata (metadata->data.stream_info);
  93950. }
  93951. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  93952. {
  93953. }
  93954. juce_UseDebuggingNewOperator
  93955. private:
  93956. FlacNamespace::FLAC__StreamDecoder* decoder;
  93957. AudioSampleBuffer reservoir;
  93958. int reservoirStart, samplesInReservoir;
  93959. bool ok, scanningForLength;
  93960. FlacReader (const FlacReader&);
  93961. FlacReader& operator= (const FlacReader&);
  93962. };
  93963. class FlacWriter : public AudioFormatWriter
  93964. {
  93965. public:
  93966. FlacWriter (OutputStream* const out,
  93967. const double sampleRate_,
  93968. const int numChannels_,
  93969. const int bitsPerSample_)
  93970. : AudioFormatWriter (out, TRANS (flacFormatName),
  93971. sampleRate_,
  93972. numChannels_,
  93973. bitsPerSample_)
  93974. {
  93975. using namespace FlacNamespace;
  93976. encoder = FLAC__stream_encoder_new();
  93977. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  93978. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  93979. FLAC__stream_encoder_set_channels (encoder, numChannels);
  93980. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  93981. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  93982. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  93983. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  93984. ok = FLAC__stream_encoder_init_stream (encoder,
  93985. encodeWriteCallback, encodeSeekCallback,
  93986. encodeTellCallback, encodeMetadataCallback,
  93987. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  93988. }
  93989. ~FlacWriter()
  93990. {
  93991. if (ok)
  93992. {
  93993. FlacNamespace::FLAC__stream_encoder_finish (encoder);
  93994. output->flush();
  93995. }
  93996. else
  93997. {
  93998. output = 0; // to stop the base class deleting this, as it needs to be returned
  93999. // to the caller of createWriter()
  94000. }
  94001. FlacNamespace::FLAC__stream_encoder_delete (encoder);
  94002. }
  94003. bool write (const int** samplesToWrite, int numSamples)
  94004. {
  94005. using namespace FlacNamespace;
  94006. if (! ok)
  94007. return false;
  94008. int* buf[3];
  94009. const int bitsToShift = 32 - bitsPerSample;
  94010. if (bitsToShift > 0)
  94011. {
  94012. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94013. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94014. buf[0] = (int*) temp.getData();
  94015. buf[1] = buf[0] + numSamples;
  94016. buf[2] = 0;
  94017. for (int i = numChannelsToWrite; --i >= 0;)
  94018. {
  94019. if (samplesToWrite[i] != 0)
  94020. {
  94021. for (int j = 0; j < numSamples; ++j)
  94022. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94023. }
  94024. }
  94025. samplesToWrite = (const int**) buf;
  94026. }
  94027. return FLAC__stream_encoder_process (encoder,
  94028. (const FLAC__int32**) samplesToWrite,
  94029. numSamples) != 0;
  94030. }
  94031. bool writeData (const void* const data, const int size) const
  94032. {
  94033. return output->write (data, size);
  94034. }
  94035. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  94036. {
  94037. using namespace FlacNamespace;
  94038. b += bytes;
  94039. for (int i = 0; i < bytes; ++i)
  94040. {
  94041. *(--b) = (FLAC__byte) (val & 0xff);
  94042. val >>= 8;
  94043. }
  94044. }
  94045. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  94046. {
  94047. using namespace FlacNamespace;
  94048. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94049. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94050. const unsigned int channelsMinus1 = info.channels - 1;
  94051. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94052. packUint32 (info.min_blocksize, buffer, 2);
  94053. packUint32 (info.max_blocksize, buffer + 2, 2);
  94054. packUint32 (info.min_framesize, buffer + 4, 3);
  94055. packUint32 (info.max_framesize, buffer + 7, 3);
  94056. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94057. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94058. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94059. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94060. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94061. memcpy (buffer + 18, info.md5sum, 16);
  94062. const bool seekOk = output->setPosition (4);
  94063. (void) seekOk;
  94064. // if this fails, you've given it an output stream that can't seek! It needs
  94065. // to be able to seek back to write the header
  94066. jassert (seekOk);
  94067. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94068. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94069. }
  94070. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  94071. const FlacNamespace::FLAC__byte buffer[],
  94072. size_t bytes,
  94073. unsigned int /*samples*/,
  94074. unsigned int /*current_frame*/,
  94075. void* client_data)
  94076. {
  94077. using namespace FlacNamespace;
  94078. return static_cast <FlacWriter*> (client_data)->writeData (buffer, (int) bytes)
  94079. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94080. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94081. }
  94082. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  94083. {
  94084. using namespace FlacNamespace;
  94085. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94086. }
  94087. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  94088. {
  94089. using namespace FlacNamespace;
  94090. if (client_data == 0)
  94091. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94092. *absolute_byte_offset = (FLAC__uint64) static_cast <FlacWriter*> (client_data)->output->getPosition();
  94093. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94094. }
  94095. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*, const FlacNamespace::FLAC__StreamMetadata* metadata, void* client_data)
  94096. {
  94097. static_cast <FlacWriter*> (client_data)->writeMetaData (metadata);
  94098. }
  94099. juce_UseDebuggingNewOperator
  94100. bool ok;
  94101. private:
  94102. FlacNamespace::FLAC__StreamEncoder* encoder;
  94103. MemoryBlock temp;
  94104. FlacWriter (const FlacWriter&);
  94105. FlacWriter& operator= (const FlacWriter&);
  94106. };
  94107. FlacAudioFormat::FlacAudioFormat()
  94108. : AudioFormat (TRANS (flacFormatName), (const juce_wchar**) flacExtensions)
  94109. {
  94110. }
  94111. FlacAudioFormat::~FlacAudioFormat()
  94112. {
  94113. }
  94114. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94115. {
  94116. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94117. return Array <int> (rates);
  94118. }
  94119. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94120. {
  94121. const int depths[] = { 16, 24, 0 };
  94122. return Array <int> (depths);
  94123. }
  94124. bool FlacAudioFormat::canDoStereo()
  94125. {
  94126. return true;
  94127. }
  94128. bool FlacAudioFormat::canDoMono()
  94129. {
  94130. return true;
  94131. }
  94132. bool FlacAudioFormat::isCompressed()
  94133. {
  94134. return true;
  94135. }
  94136. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94137. const bool deleteStreamIfOpeningFails)
  94138. {
  94139. ScopedPointer<FlacReader> r (new FlacReader (in));
  94140. if (r->sampleRate != 0)
  94141. return r.release();
  94142. if (! deleteStreamIfOpeningFails)
  94143. r->input = 0;
  94144. return 0;
  94145. }
  94146. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94147. double sampleRate,
  94148. unsigned int numberOfChannels,
  94149. int bitsPerSample,
  94150. const StringPairArray& /*metadataValues*/,
  94151. int /*qualityOptionIndex*/)
  94152. {
  94153. if (getPossibleBitDepths().contains (bitsPerSample))
  94154. {
  94155. ScopedPointer<FlacWriter> w (new FlacWriter (out, sampleRate, numberOfChannels, bitsPerSample));
  94156. if (w->ok)
  94157. return w.release();
  94158. }
  94159. return 0;
  94160. }
  94161. END_JUCE_NAMESPACE
  94162. #endif
  94163. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94164. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94165. #if JUCE_USE_OGGVORBIS
  94166. #if JUCE_MAC
  94167. #define __MACOSX__ 1
  94168. #endif
  94169. namespace OggVorbisNamespace
  94170. {
  94171. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94172. /*** Start of inlined file: vorbisenc.h ***/
  94173. #ifndef _OV_ENC_H_
  94174. #define _OV_ENC_H_
  94175. #ifdef __cplusplus
  94176. extern "C"
  94177. {
  94178. #endif /* __cplusplus */
  94179. /*** Start of inlined file: codec.h ***/
  94180. #ifndef _vorbis_codec_h_
  94181. #define _vorbis_codec_h_
  94182. #ifdef __cplusplus
  94183. extern "C"
  94184. {
  94185. #endif /* __cplusplus */
  94186. /*** Start of inlined file: ogg.h ***/
  94187. #ifndef _OGG_H
  94188. #define _OGG_H
  94189. #ifdef __cplusplus
  94190. extern "C" {
  94191. #endif
  94192. /*** Start of inlined file: os_types.h ***/
  94193. #ifndef _OS_TYPES_H
  94194. #define _OS_TYPES_H
  94195. #define _ogg_malloc malloc
  94196. #define _ogg_calloc calloc
  94197. #define _ogg_realloc realloc
  94198. #define _ogg_free free
  94199. #if defined(_WIN32)
  94200. # if defined(__CYGWIN__)
  94201. # include <_G_config.h>
  94202. typedef _G_int64_t ogg_int64_t;
  94203. typedef _G_int32_t ogg_int32_t;
  94204. typedef _G_uint32_t ogg_uint32_t;
  94205. typedef _G_int16_t ogg_int16_t;
  94206. typedef _G_uint16_t ogg_uint16_t;
  94207. # elif defined(__MINGW32__)
  94208. typedef short ogg_int16_t;
  94209. typedef unsigned short ogg_uint16_t;
  94210. typedef int ogg_int32_t;
  94211. typedef unsigned int ogg_uint32_t;
  94212. typedef long long ogg_int64_t;
  94213. typedef unsigned long long ogg_uint64_t;
  94214. # elif defined(__MWERKS__)
  94215. typedef long long ogg_int64_t;
  94216. typedef int ogg_int32_t;
  94217. typedef unsigned int ogg_uint32_t;
  94218. typedef short ogg_int16_t;
  94219. typedef unsigned short ogg_uint16_t;
  94220. # else
  94221. typedef __int64 ogg_int64_t;
  94222. typedef __int32 ogg_int32_t;
  94223. typedef unsigned __int32 ogg_uint32_t;
  94224. typedef __int16 ogg_int16_t;
  94225. typedef unsigned __int16 ogg_uint16_t;
  94226. # endif
  94227. #elif defined(__MACOS__)
  94228. # include <sys/types.h>
  94229. typedef SInt16 ogg_int16_t;
  94230. typedef UInt16 ogg_uint16_t;
  94231. typedef SInt32 ogg_int32_t;
  94232. typedef UInt32 ogg_uint32_t;
  94233. typedef SInt64 ogg_int64_t;
  94234. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94235. # include <sys/types.h>
  94236. typedef int16_t ogg_int16_t;
  94237. typedef u_int16_t ogg_uint16_t;
  94238. typedef int32_t ogg_int32_t;
  94239. typedef u_int32_t ogg_uint32_t;
  94240. typedef int64_t ogg_int64_t;
  94241. #elif defined(__BEOS__)
  94242. # include <inttypes.h>
  94243. typedef int16_t ogg_int16_t;
  94244. typedef u_int16_t ogg_uint16_t;
  94245. typedef int32_t ogg_int32_t;
  94246. typedef u_int32_t ogg_uint32_t;
  94247. typedef int64_t ogg_int64_t;
  94248. #elif defined (__EMX__)
  94249. typedef short ogg_int16_t;
  94250. typedef unsigned short ogg_uint16_t;
  94251. typedef int ogg_int32_t;
  94252. typedef unsigned int ogg_uint32_t;
  94253. typedef long long ogg_int64_t;
  94254. #elif defined (DJGPP)
  94255. typedef short ogg_int16_t;
  94256. typedef int ogg_int32_t;
  94257. typedef unsigned int ogg_uint32_t;
  94258. typedef long long ogg_int64_t;
  94259. #elif defined(R5900)
  94260. typedef long ogg_int64_t;
  94261. typedef int ogg_int32_t;
  94262. typedef unsigned ogg_uint32_t;
  94263. typedef short ogg_int16_t;
  94264. #elif defined(__SYMBIAN32__)
  94265. typedef signed short ogg_int16_t;
  94266. typedef unsigned short ogg_uint16_t;
  94267. typedef signed int ogg_int32_t;
  94268. typedef unsigned int ogg_uint32_t;
  94269. typedef long long int ogg_int64_t;
  94270. #else
  94271. # include <sys/types.h>
  94272. /*** Start of inlined file: config_types.h ***/
  94273. #ifndef __CONFIG_TYPES_H__
  94274. #define __CONFIG_TYPES_H__
  94275. typedef int16_t ogg_int16_t;
  94276. typedef unsigned short ogg_uint16_t;
  94277. typedef int32_t ogg_int32_t;
  94278. typedef unsigned int ogg_uint32_t;
  94279. typedef int64_t ogg_int64_t;
  94280. #endif
  94281. /*** End of inlined file: config_types.h ***/
  94282. #endif
  94283. #endif /* _OS_TYPES_H */
  94284. /*** End of inlined file: os_types.h ***/
  94285. typedef struct {
  94286. long endbyte;
  94287. int endbit;
  94288. unsigned char *buffer;
  94289. unsigned char *ptr;
  94290. long storage;
  94291. } oggpack_buffer;
  94292. typedef struct {
  94293. unsigned char *header;
  94294. long header_len;
  94295. unsigned char *body;
  94296. long body_len;
  94297. } ogg_page;
  94298. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94299. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94300. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94301. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94302. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94303. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94304. }
  94305. typedef struct {
  94306. unsigned char *body_data; /* bytes from packet bodies */
  94307. long body_storage; /* storage elements allocated */
  94308. long body_fill; /* elements stored; fill mark */
  94309. long body_returned; /* elements of fill returned */
  94310. int *lacing_vals; /* The values that will go to the segment table */
  94311. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94312. this way, but it is simple coupled to the
  94313. lacing fifo */
  94314. long lacing_storage;
  94315. long lacing_fill;
  94316. long lacing_packet;
  94317. long lacing_returned;
  94318. unsigned char header[282]; /* working space for header encode */
  94319. int header_fill;
  94320. int e_o_s; /* set when we have buffered the last packet in the
  94321. logical bitstream */
  94322. int b_o_s; /* set after we've written the initial page
  94323. of a logical bitstream */
  94324. long serialno;
  94325. long pageno;
  94326. ogg_int64_t packetno; /* sequence number for decode; the framing
  94327. knows where there's a hole in the data,
  94328. but we need coupling so that the codec
  94329. (which is in a seperate abstraction
  94330. layer) also knows about the gap */
  94331. ogg_int64_t granulepos;
  94332. } ogg_stream_state;
  94333. typedef struct {
  94334. unsigned char *packet;
  94335. long bytes;
  94336. long b_o_s;
  94337. long e_o_s;
  94338. ogg_int64_t granulepos;
  94339. ogg_int64_t packetno; /* sequence number for decode; the framing
  94340. knows where there's a hole in the data,
  94341. but we need coupling so that the codec
  94342. (which is in a seperate abstraction
  94343. layer) also knows about the gap */
  94344. } ogg_packet;
  94345. typedef struct {
  94346. unsigned char *data;
  94347. int storage;
  94348. int fill;
  94349. int returned;
  94350. int unsynced;
  94351. int headerbytes;
  94352. int bodybytes;
  94353. } ogg_sync_state;
  94354. extern void oggpack_writeinit(oggpack_buffer *b);
  94355. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94356. extern void oggpack_writealign(oggpack_buffer *b);
  94357. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94358. extern void oggpack_reset(oggpack_buffer *b);
  94359. extern void oggpack_writeclear(oggpack_buffer *b);
  94360. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94361. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94362. extern long oggpack_look(oggpack_buffer *b,int bits);
  94363. extern long oggpack_look1(oggpack_buffer *b);
  94364. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94365. extern void oggpack_adv1(oggpack_buffer *b);
  94366. extern long oggpack_read(oggpack_buffer *b,int bits);
  94367. extern long oggpack_read1(oggpack_buffer *b);
  94368. extern long oggpack_bytes(oggpack_buffer *b);
  94369. extern long oggpack_bits(oggpack_buffer *b);
  94370. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94371. extern void oggpackB_writeinit(oggpack_buffer *b);
  94372. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94373. extern void oggpackB_writealign(oggpack_buffer *b);
  94374. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94375. extern void oggpackB_reset(oggpack_buffer *b);
  94376. extern void oggpackB_writeclear(oggpack_buffer *b);
  94377. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94378. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94379. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94380. extern long oggpackB_look1(oggpack_buffer *b);
  94381. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94382. extern void oggpackB_adv1(oggpack_buffer *b);
  94383. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94384. extern long oggpackB_read1(oggpack_buffer *b);
  94385. extern long oggpackB_bytes(oggpack_buffer *b);
  94386. extern long oggpackB_bits(oggpack_buffer *b);
  94387. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94388. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94389. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94390. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94391. extern int ogg_sync_init(ogg_sync_state *oy);
  94392. extern int ogg_sync_clear(ogg_sync_state *oy);
  94393. extern int ogg_sync_reset(ogg_sync_state *oy);
  94394. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94395. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94396. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94397. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94398. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94399. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94400. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94401. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94402. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94403. extern int ogg_stream_clear(ogg_stream_state *os);
  94404. extern int ogg_stream_reset(ogg_stream_state *os);
  94405. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94406. extern int ogg_stream_destroy(ogg_stream_state *os);
  94407. extern int ogg_stream_eos(ogg_stream_state *os);
  94408. extern void ogg_page_checksum_set(ogg_page *og);
  94409. extern int ogg_page_version(ogg_page *og);
  94410. extern int ogg_page_continued(ogg_page *og);
  94411. extern int ogg_page_bos(ogg_page *og);
  94412. extern int ogg_page_eos(ogg_page *og);
  94413. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94414. extern int ogg_page_serialno(ogg_page *og);
  94415. extern long ogg_page_pageno(ogg_page *og);
  94416. extern int ogg_page_packets(ogg_page *og);
  94417. extern void ogg_packet_clear(ogg_packet *op);
  94418. #ifdef __cplusplus
  94419. }
  94420. #endif
  94421. #endif /* _OGG_H */
  94422. /*** End of inlined file: ogg.h ***/
  94423. typedef struct vorbis_info{
  94424. int version;
  94425. int channels;
  94426. long rate;
  94427. long bitrate_upper;
  94428. long bitrate_nominal;
  94429. long bitrate_lower;
  94430. long bitrate_window;
  94431. void *codec_setup;
  94432. } vorbis_info;
  94433. typedef struct vorbis_dsp_state{
  94434. int analysisp;
  94435. vorbis_info *vi;
  94436. float **pcm;
  94437. float **pcmret;
  94438. int pcm_storage;
  94439. int pcm_current;
  94440. int pcm_returned;
  94441. int preextrapolate;
  94442. int eofflag;
  94443. long lW;
  94444. long W;
  94445. long nW;
  94446. long centerW;
  94447. ogg_int64_t granulepos;
  94448. ogg_int64_t sequence;
  94449. ogg_int64_t glue_bits;
  94450. ogg_int64_t time_bits;
  94451. ogg_int64_t floor_bits;
  94452. ogg_int64_t res_bits;
  94453. void *backend_state;
  94454. } vorbis_dsp_state;
  94455. typedef struct vorbis_block{
  94456. float **pcm; /* this is a pointer into local storage */
  94457. oggpack_buffer opb;
  94458. long lW;
  94459. long W;
  94460. long nW;
  94461. int pcmend;
  94462. int mode;
  94463. int eofflag;
  94464. ogg_int64_t granulepos;
  94465. ogg_int64_t sequence;
  94466. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94467. void *localstore;
  94468. long localtop;
  94469. long localalloc;
  94470. long totaluse;
  94471. struct alloc_chain *reap;
  94472. long glue_bits;
  94473. long time_bits;
  94474. long floor_bits;
  94475. long res_bits;
  94476. void *internal;
  94477. } vorbis_block;
  94478. struct alloc_chain{
  94479. void *ptr;
  94480. struct alloc_chain *next;
  94481. };
  94482. typedef struct vorbis_comment{
  94483. char **user_comments;
  94484. int *comment_lengths;
  94485. int comments;
  94486. char *vendor;
  94487. } vorbis_comment;
  94488. extern void vorbis_info_init(vorbis_info *vi);
  94489. extern void vorbis_info_clear(vorbis_info *vi);
  94490. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94491. extern void vorbis_comment_init(vorbis_comment *vc);
  94492. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94493. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94494. const char *tag, char *contents);
  94495. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94496. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94497. extern void vorbis_comment_clear(vorbis_comment *vc);
  94498. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94499. extern int vorbis_block_clear(vorbis_block *vb);
  94500. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94501. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94502. ogg_int64_t granulepos);
  94503. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94504. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94505. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94506. vorbis_comment *vc,
  94507. ogg_packet *op,
  94508. ogg_packet *op_comm,
  94509. ogg_packet *op_code);
  94510. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94511. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94512. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94513. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94514. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94515. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94516. ogg_packet *op);
  94517. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94518. ogg_packet *op);
  94519. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94520. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94521. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94522. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94523. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94524. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94525. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94526. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94527. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94528. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94529. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94530. #define OV_FALSE -1
  94531. #define OV_EOF -2
  94532. #define OV_HOLE -3
  94533. #define OV_EREAD -128
  94534. #define OV_EFAULT -129
  94535. #define OV_EIMPL -130
  94536. #define OV_EINVAL -131
  94537. #define OV_ENOTVORBIS -132
  94538. #define OV_EBADHEADER -133
  94539. #define OV_EVERSION -134
  94540. #define OV_ENOTAUDIO -135
  94541. #define OV_EBADPACKET -136
  94542. #define OV_EBADLINK -137
  94543. #define OV_ENOSEEK -138
  94544. #ifdef __cplusplus
  94545. }
  94546. #endif /* __cplusplus */
  94547. #endif
  94548. /*** End of inlined file: codec.h ***/
  94549. extern int vorbis_encode_init(vorbis_info *vi,
  94550. long channels,
  94551. long rate,
  94552. long max_bitrate,
  94553. long nominal_bitrate,
  94554. long min_bitrate);
  94555. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94556. long channels,
  94557. long rate,
  94558. long max_bitrate,
  94559. long nominal_bitrate,
  94560. long min_bitrate);
  94561. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94562. long channels,
  94563. long rate,
  94564. float quality /* quality level from 0. (lo) to 1. (hi) */
  94565. );
  94566. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94567. long channels,
  94568. long rate,
  94569. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94570. );
  94571. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94572. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94573. #define OV_ECTL_RATEMANAGE_GET 0x10
  94574. #define OV_ECTL_RATEMANAGE_SET 0x11
  94575. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94576. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94577. struct ovectl_ratemanage_arg {
  94578. int management_active;
  94579. long bitrate_hard_min;
  94580. long bitrate_hard_max;
  94581. double bitrate_hard_window;
  94582. long bitrate_av_lo;
  94583. long bitrate_av_hi;
  94584. double bitrate_av_window;
  94585. double bitrate_av_window_center;
  94586. };
  94587. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94588. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94589. struct ovectl_ratemanage2_arg {
  94590. int management_active;
  94591. long bitrate_limit_min_kbps;
  94592. long bitrate_limit_max_kbps;
  94593. long bitrate_limit_reservoir_bits;
  94594. double bitrate_limit_reservoir_bias;
  94595. long bitrate_average_kbps;
  94596. double bitrate_average_damping;
  94597. };
  94598. #define OV_ECTL_LOWPASS_GET 0x20
  94599. #define OV_ECTL_LOWPASS_SET 0x21
  94600. #define OV_ECTL_IBLOCK_GET 0x30
  94601. #define OV_ECTL_IBLOCK_SET 0x31
  94602. #ifdef __cplusplus
  94603. }
  94604. #endif /* __cplusplus */
  94605. #endif
  94606. /*** End of inlined file: vorbisenc.h ***/
  94607. /*** Start of inlined file: vorbisfile.h ***/
  94608. #ifndef _OV_FILE_H_
  94609. #define _OV_FILE_H_
  94610. #ifdef __cplusplus
  94611. extern "C"
  94612. {
  94613. #endif /* __cplusplus */
  94614. #include <stdio.h>
  94615. typedef struct {
  94616. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94617. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94618. int (*close_func) (void *datasource);
  94619. long (*tell_func) (void *datasource);
  94620. } ov_callbacks;
  94621. #define NOTOPEN 0
  94622. #define PARTOPEN 1
  94623. #define OPENED 2
  94624. #define STREAMSET 3
  94625. #define INITSET 4
  94626. typedef struct OggVorbis_File {
  94627. void *datasource; /* Pointer to a FILE *, etc. */
  94628. int seekable;
  94629. ogg_int64_t offset;
  94630. ogg_int64_t end;
  94631. ogg_sync_state oy;
  94632. int links;
  94633. ogg_int64_t *offsets;
  94634. ogg_int64_t *dataoffsets;
  94635. long *serialnos;
  94636. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94637. compatability; x2 size, stores both
  94638. beginning and end values */
  94639. vorbis_info *vi;
  94640. vorbis_comment *vc;
  94641. ogg_int64_t pcm_offset;
  94642. int ready_state;
  94643. long current_serialno;
  94644. int current_link;
  94645. double bittrack;
  94646. double samptrack;
  94647. ogg_stream_state os; /* take physical pages, weld into a logical
  94648. stream of packets */
  94649. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94650. vorbis_block vb; /* local working space for packet->PCM decode */
  94651. ov_callbacks callbacks;
  94652. } OggVorbis_File;
  94653. extern int ov_clear(OggVorbis_File *vf);
  94654. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94655. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94656. char *initial, long ibytes, ov_callbacks callbacks);
  94657. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94658. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94659. char *initial, long ibytes, ov_callbacks callbacks);
  94660. extern int ov_test_open(OggVorbis_File *vf);
  94661. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94662. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94663. extern long ov_streams(OggVorbis_File *vf);
  94664. extern long ov_seekable(OggVorbis_File *vf);
  94665. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94666. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94667. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94668. extern double ov_time_total(OggVorbis_File *vf,int i);
  94669. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94670. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94671. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94672. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94673. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94674. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94675. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94676. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94677. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94678. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94679. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94680. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94681. extern double ov_time_tell(OggVorbis_File *vf);
  94682. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94683. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94684. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94685. int *bitstream);
  94686. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94687. int bigendianp,int word,int sgned,int *bitstream);
  94688. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94689. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94690. extern int ov_halfrate_p(OggVorbis_File *vf);
  94691. #ifdef __cplusplus
  94692. }
  94693. #endif /* __cplusplus */
  94694. #endif
  94695. /*** End of inlined file: vorbisfile.h ***/
  94696. /*** Start of inlined file: bitwise.c ***/
  94697. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94698. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94699. // tasks..
  94700. #if JUCE_MSVC
  94701. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94702. #endif
  94703. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94704. #if JUCE_USE_OGGVORBIS
  94705. #include <string.h>
  94706. #include <stdlib.h>
  94707. #define BUFFER_INCREMENT 256
  94708. static const unsigned long mask[]=
  94709. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94710. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94711. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94712. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94713. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94714. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94715. 0x3fffffff,0x7fffffff,0xffffffff };
  94716. static const unsigned int mask8B[]=
  94717. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94718. void oggpack_writeinit(oggpack_buffer *b){
  94719. memset(b,0,sizeof(*b));
  94720. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94721. b->buffer[0]='\0';
  94722. b->storage=BUFFER_INCREMENT;
  94723. }
  94724. void oggpackB_writeinit(oggpack_buffer *b){
  94725. oggpack_writeinit(b);
  94726. }
  94727. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94728. long bytes=bits>>3;
  94729. bits-=bytes*8;
  94730. b->ptr=b->buffer+bytes;
  94731. b->endbit=bits;
  94732. b->endbyte=bytes;
  94733. *b->ptr&=mask[bits];
  94734. }
  94735. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94736. long bytes=bits>>3;
  94737. bits-=bytes*8;
  94738. b->ptr=b->buffer+bytes;
  94739. b->endbit=bits;
  94740. b->endbyte=bytes;
  94741. *b->ptr&=mask8B[bits];
  94742. }
  94743. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94744. if(b->endbyte+4>=b->storage){
  94745. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94746. b->storage+=BUFFER_INCREMENT;
  94747. b->ptr=b->buffer+b->endbyte;
  94748. }
  94749. value&=mask[bits];
  94750. bits+=b->endbit;
  94751. b->ptr[0]|=value<<b->endbit;
  94752. if(bits>=8){
  94753. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94754. if(bits>=16){
  94755. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94756. if(bits>=24){
  94757. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94758. if(bits>=32){
  94759. if(b->endbit)
  94760. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94761. else
  94762. b->ptr[4]=0;
  94763. }
  94764. }
  94765. }
  94766. }
  94767. b->endbyte+=bits/8;
  94768. b->ptr+=bits/8;
  94769. b->endbit=bits&7;
  94770. }
  94771. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94772. if(b->endbyte+4>=b->storage){
  94773. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94774. b->storage+=BUFFER_INCREMENT;
  94775. b->ptr=b->buffer+b->endbyte;
  94776. }
  94777. value=(value&mask[bits])<<(32-bits);
  94778. bits+=b->endbit;
  94779. b->ptr[0]|=value>>(24+b->endbit);
  94780. if(bits>=8){
  94781. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94782. if(bits>=16){
  94783. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94784. if(bits>=24){
  94785. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94786. if(bits>=32){
  94787. if(b->endbit)
  94788. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94789. else
  94790. b->ptr[4]=0;
  94791. }
  94792. }
  94793. }
  94794. }
  94795. b->endbyte+=bits/8;
  94796. b->ptr+=bits/8;
  94797. b->endbit=bits&7;
  94798. }
  94799. void oggpack_writealign(oggpack_buffer *b){
  94800. int bits=8-b->endbit;
  94801. if(bits<8)
  94802. oggpack_write(b,0,bits);
  94803. }
  94804. void oggpackB_writealign(oggpack_buffer *b){
  94805. int bits=8-b->endbit;
  94806. if(bits<8)
  94807. oggpackB_write(b,0,bits);
  94808. }
  94809. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94810. void *source,
  94811. long bits,
  94812. void (*w)(oggpack_buffer *,
  94813. unsigned long,
  94814. int),
  94815. int msb){
  94816. unsigned char *ptr=(unsigned char *)source;
  94817. long bytes=bits/8;
  94818. bits-=bytes*8;
  94819. if(b->endbit){
  94820. int i;
  94821. for(i=0;i<bytes;i++)
  94822. w(b,(unsigned long)(ptr[i]),8);
  94823. }else{
  94824. if(b->endbyte+bytes+1>=b->storage){
  94825. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94826. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94827. b->ptr=b->buffer+b->endbyte;
  94828. }
  94829. memmove(b->ptr,source,bytes);
  94830. b->ptr+=bytes;
  94831. b->endbyte+=bytes;
  94832. *b->ptr=0;
  94833. }
  94834. if(bits){
  94835. if(msb)
  94836. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94837. else
  94838. w(b,(unsigned long)(ptr[bytes]),bits);
  94839. }
  94840. }
  94841. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94842. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94843. }
  94844. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94845. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94846. }
  94847. void oggpack_reset(oggpack_buffer *b){
  94848. b->ptr=b->buffer;
  94849. b->buffer[0]=0;
  94850. b->endbit=b->endbyte=0;
  94851. }
  94852. void oggpackB_reset(oggpack_buffer *b){
  94853. oggpack_reset(b);
  94854. }
  94855. void oggpack_writeclear(oggpack_buffer *b){
  94856. _ogg_free(b->buffer);
  94857. memset(b,0,sizeof(*b));
  94858. }
  94859. void oggpackB_writeclear(oggpack_buffer *b){
  94860. oggpack_writeclear(b);
  94861. }
  94862. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94863. memset(b,0,sizeof(*b));
  94864. b->buffer=b->ptr=buf;
  94865. b->storage=bytes;
  94866. }
  94867. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94868. oggpack_readinit(b,buf,bytes);
  94869. }
  94870. long oggpack_look(oggpack_buffer *b,int bits){
  94871. unsigned long ret;
  94872. unsigned long m=mask[bits];
  94873. bits+=b->endbit;
  94874. if(b->endbyte+4>=b->storage){
  94875. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94876. }
  94877. ret=b->ptr[0]>>b->endbit;
  94878. if(bits>8){
  94879. ret|=b->ptr[1]<<(8-b->endbit);
  94880. if(bits>16){
  94881. ret|=b->ptr[2]<<(16-b->endbit);
  94882. if(bits>24){
  94883. ret|=b->ptr[3]<<(24-b->endbit);
  94884. if(bits>32 && b->endbit)
  94885. ret|=b->ptr[4]<<(32-b->endbit);
  94886. }
  94887. }
  94888. }
  94889. return(m&ret);
  94890. }
  94891. long oggpackB_look(oggpack_buffer *b,int bits){
  94892. unsigned long ret;
  94893. int m=32-bits;
  94894. bits+=b->endbit;
  94895. if(b->endbyte+4>=b->storage){
  94896. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94897. }
  94898. ret=b->ptr[0]<<(24+b->endbit);
  94899. if(bits>8){
  94900. ret|=b->ptr[1]<<(16+b->endbit);
  94901. if(bits>16){
  94902. ret|=b->ptr[2]<<(8+b->endbit);
  94903. if(bits>24){
  94904. ret|=b->ptr[3]<<(b->endbit);
  94905. if(bits>32 && b->endbit)
  94906. ret|=b->ptr[4]>>(8-b->endbit);
  94907. }
  94908. }
  94909. }
  94910. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  94911. }
  94912. long oggpack_look1(oggpack_buffer *b){
  94913. if(b->endbyte>=b->storage)return(-1);
  94914. return((b->ptr[0]>>b->endbit)&1);
  94915. }
  94916. long oggpackB_look1(oggpack_buffer *b){
  94917. if(b->endbyte>=b->storage)return(-1);
  94918. return((b->ptr[0]>>(7-b->endbit))&1);
  94919. }
  94920. void oggpack_adv(oggpack_buffer *b,int bits){
  94921. bits+=b->endbit;
  94922. b->ptr+=bits/8;
  94923. b->endbyte+=bits/8;
  94924. b->endbit=bits&7;
  94925. }
  94926. void oggpackB_adv(oggpack_buffer *b,int bits){
  94927. oggpack_adv(b,bits);
  94928. }
  94929. void oggpack_adv1(oggpack_buffer *b){
  94930. if(++(b->endbit)>7){
  94931. b->endbit=0;
  94932. b->ptr++;
  94933. b->endbyte++;
  94934. }
  94935. }
  94936. void oggpackB_adv1(oggpack_buffer *b){
  94937. oggpack_adv1(b);
  94938. }
  94939. long oggpack_read(oggpack_buffer *b,int bits){
  94940. long ret;
  94941. unsigned long m=mask[bits];
  94942. bits+=b->endbit;
  94943. if(b->endbyte+4>=b->storage){
  94944. ret=-1L;
  94945. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94946. }
  94947. ret=b->ptr[0]>>b->endbit;
  94948. if(bits>8){
  94949. ret|=b->ptr[1]<<(8-b->endbit);
  94950. if(bits>16){
  94951. ret|=b->ptr[2]<<(16-b->endbit);
  94952. if(bits>24){
  94953. ret|=b->ptr[3]<<(24-b->endbit);
  94954. if(bits>32 && b->endbit){
  94955. ret|=b->ptr[4]<<(32-b->endbit);
  94956. }
  94957. }
  94958. }
  94959. }
  94960. ret&=m;
  94961. overflow:
  94962. b->ptr+=bits/8;
  94963. b->endbyte+=bits/8;
  94964. b->endbit=bits&7;
  94965. return(ret);
  94966. }
  94967. long oggpackB_read(oggpack_buffer *b,int bits){
  94968. long ret;
  94969. long m=32-bits;
  94970. bits+=b->endbit;
  94971. if(b->endbyte+4>=b->storage){
  94972. ret=-1L;
  94973. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94974. }
  94975. ret=b->ptr[0]<<(24+b->endbit);
  94976. if(bits>8){
  94977. ret|=b->ptr[1]<<(16+b->endbit);
  94978. if(bits>16){
  94979. ret|=b->ptr[2]<<(8+b->endbit);
  94980. if(bits>24){
  94981. ret|=b->ptr[3]<<(b->endbit);
  94982. if(bits>32 && b->endbit)
  94983. ret|=b->ptr[4]>>(8-b->endbit);
  94984. }
  94985. }
  94986. }
  94987. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  94988. overflow:
  94989. b->ptr+=bits/8;
  94990. b->endbyte+=bits/8;
  94991. b->endbit=bits&7;
  94992. return(ret);
  94993. }
  94994. long oggpack_read1(oggpack_buffer *b){
  94995. long ret;
  94996. if(b->endbyte>=b->storage){
  94997. ret=-1L;
  94998. goto overflow;
  94999. }
  95000. ret=(b->ptr[0]>>b->endbit)&1;
  95001. overflow:
  95002. b->endbit++;
  95003. if(b->endbit>7){
  95004. b->endbit=0;
  95005. b->ptr++;
  95006. b->endbyte++;
  95007. }
  95008. return(ret);
  95009. }
  95010. long oggpackB_read1(oggpack_buffer *b){
  95011. long ret;
  95012. if(b->endbyte>=b->storage){
  95013. ret=-1L;
  95014. goto overflow;
  95015. }
  95016. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95017. overflow:
  95018. b->endbit++;
  95019. if(b->endbit>7){
  95020. b->endbit=0;
  95021. b->ptr++;
  95022. b->endbyte++;
  95023. }
  95024. return(ret);
  95025. }
  95026. long oggpack_bytes(oggpack_buffer *b){
  95027. return(b->endbyte+(b->endbit+7)/8);
  95028. }
  95029. long oggpack_bits(oggpack_buffer *b){
  95030. return(b->endbyte*8+b->endbit);
  95031. }
  95032. long oggpackB_bytes(oggpack_buffer *b){
  95033. return oggpack_bytes(b);
  95034. }
  95035. long oggpackB_bits(oggpack_buffer *b){
  95036. return oggpack_bits(b);
  95037. }
  95038. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95039. return(b->buffer);
  95040. }
  95041. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95042. return oggpack_get_buffer(b);
  95043. }
  95044. #ifdef _V_SELFTEST
  95045. #include <stdio.h>
  95046. static int ilog(unsigned int v){
  95047. int ret=0;
  95048. while(v){
  95049. ret++;
  95050. v>>=1;
  95051. }
  95052. return(ret);
  95053. }
  95054. oggpack_buffer o;
  95055. oggpack_buffer r;
  95056. void report(char *in){
  95057. fprintf(stderr,"%s",in);
  95058. exit(1);
  95059. }
  95060. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95061. long bytes,i;
  95062. unsigned char *buffer;
  95063. oggpack_reset(&o);
  95064. for(i=0;i<vals;i++)
  95065. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95066. buffer=oggpack_get_buffer(&o);
  95067. bytes=oggpack_bytes(&o);
  95068. if(bytes!=compsize)report("wrong number of bytes!\n");
  95069. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95070. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95071. report("wrote incorrect value!\n");
  95072. }
  95073. oggpack_readinit(&r,buffer,bytes);
  95074. for(i=0;i<vals;i++){
  95075. int tbit=bits?bits:ilog(b[i]);
  95076. if(oggpack_look(&r,tbit)==-1)
  95077. report("out of data!\n");
  95078. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95079. report("looked at incorrect value!\n");
  95080. if(tbit==1)
  95081. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95082. report("looked at single bit incorrect value!\n");
  95083. if(tbit==1){
  95084. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95085. report("read incorrect single bit value!\n");
  95086. }else{
  95087. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95088. report("read incorrect value!\n");
  95089. }
  95090. }
  95091. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95092. }
  95093. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95094. long bytes,i;
  95095. unsigned char *buffer;
  95096. oggpackB_reset(&o);
  95097. for(i=0;i<vals;i++)
  95098. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95099. buffer=oggpackB_get_buffer(&o);
  95100. bytes=oggpackB_bytes(&o);
  95101. if(bytes!=compsize)report("wrong number of bytes!\n");
  95102. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95103. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95104. report("wrote incorrect value!\n");
  95105. }
  95106. oggpackB_readinit(&r,buffer,bytes);
  95107. for(i=0;i<vals;i++){
  95108. int tbit=bits?bits:ilog(b[i]);
  95109. if(oggpackB_look(&r,tbit)==-1)
  95110. report("out of data!\n");
  95111. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95112. report("looked at incorrect value!\n");
  95113. if(tbit==1)
  95114. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95115. report("looked at single bit incorrect value!\n");
  95116. if(tbit==1){
  95117. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95118. report("read incorrect single bit value!\n");
  95119. }else{
  95120. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95121. report("read incorrect value!\n");
  95122. }
  95123. }
  95124. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95125. }
  95126. int main(void){
  95127. unsigned char *buffer;
  95128. long bytes,i;
  95129. static unsigned long testbuffer1[]=
  95130. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95131. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95132. int test1size=43;
  95133. static unsigned long testbuffer2[]=
  95134. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95135. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95136. 85525151,0,12321,1,349528352};
  95137. int test2size=21;
  95138. static unsigned long testbuffer3[]=
  95139. {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,
  95140. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95141. int test3size=56;
  95142. static unsigned long large[]=
  95143. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95144. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95145. 85525151,0,12321,1,2146528352};
  95146. int onesize=33;
  95147. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95148. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95149. 223,4};
  95150. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95151. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95152. 245,251,128};
  95153. int twosize=6;
  95154. static int two[6]={61,255,255,251,231,29};
  95155. static int twoB[6]={247,63,255,253,249,120};
  95156. int threesize=54;
  95157. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95158. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95159. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95160. 100,52,4,14,18,86,77,1};
  95161. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95162. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95163. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95164. 200,20,254,4,58,106,176,144,0};
  95165. int foursize=38;
  95166. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95167. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95168. 28,2,133,0,1};
  95169. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95170. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95171. 129,10,4,32};
  95172. int fivesize=45;
  95173. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95174. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95175. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95176. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95177. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95178. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95179. int sixsize=7;
  95180. static int six[7]={17,177,170,242,169,19,148};
  95181. static int sixB[7]={136,141,85,79,149,200,41};
  95182. oggpack_writeinit(&o);
  95183. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95184. cliptest(testbuffer1,test1size,0,one,onesize);
  95185. fprintf(stderr,"ok.");
  95186. fprintf(stderr,"\nNull bit call (LSb): ");
  95187. cliptest(testbuffer3,test3size,0,two,twosize);
  95188. fprintf(stderr,"ok.");
  95189. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95190. cliptest(testbuffer2,test2size,0,three,threesize);
  95191. fprintf(stderr,"ok.");
  95192. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95193. oggpack_reset(&o);
  95194. for(i=0;i<test2size;i++)
  95195. oggpack_write(&o,large[i],32);
  95196. buffer=oggpack_get_buffer(&o);
  95197. bytes=oggpack_bytes(&o);
  95198. oggpack_readinit(&r,buffer,bytes);
  95199. for(i=0;i<test2size;i++){
  95200. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95201. if(oggpack_look(&r,32)!=large[i]){
  95202. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95203. oggpack_look(&r,32),large[i]);
  95204. report("read incorrect value!\n");
  95205. }
  95206. oggpack_adv(&r,32);
  95207. }
  95208. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95209. fprintf(stderr,"ok.");
  95210. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95211. cliptest(testbuffer1,test1size,7,four,foursize);
  95212. fprintf(stderr,"ok.");
  95213. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95214. cliptest(testbuffer2,test2size,17,five,fivesize);
  95215. fprintf(stderr,"ok.");
  95216. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95217. cliptest(testbuffer3,test3size,1,six,sixsize);
  95218. fprintf(stderr,"ok.");
  95219. fprintf(stderr,"\nTesting read past end (LSb): ");
  95220. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95221. for(i=0;i<64;i++){
  95222. if(oggpack_read(&r,1)!=0){
  95223. fprintf(stderr,"failed; got -1 prematurely.\n");
  95224. exit(1);
  95225. }
  95226. }
  95227. if(oggpack_look(&r,1)!=-1 ||
  95228. oggpack_read(&r,1)!=-1){
  95229. fprintf(stderr,"failed; read past end without -1.\n");
  95230. exit(1);
  95231. }
  95232. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95233. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95234. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95235. exit(1);
  95236. }
  95237. if(oggpack_look(&r,18)!=0 ||
  95238. oggpack_look(&r,18)!=0){
  95239. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95240. exit(1);
  95241. }
  95242. if(oggpack_look(&r,19)!=-1 ||
  95243. oggpack_look(&r,19)!=-1){
  95244. fprintf(stderr,"failed; read past end without -1.\n");
  95245. exit(1);
  95246. }
  95247. if(oggpack_look(&r,32)!=-1 ||
  95248. oggpack_look(&r,32)!=-1){
  95249. fprintf(stderr,"failed; read past end without -1.\n");
  95250. exit(1);
  95251. }
  95252. oggpack_writeclear(&o);
  95253. fprintf(stderr,"ok.\n");
  95254. oggpackB_writeinit(&o);
  95255. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95256. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95257. fprintf(stderr,"ok.");
  95258. fprintf(stderr,"\nNull bit call (MSb): ");
  95259. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95260. fprintf(stderr,"ok.");
  95261. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95262. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95263. fprintf(stderr,"ok.");
  95264. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95265. oggpackB_reset(&o);
  95266. for(i=0;i<test2size;i++)
  95267. oggpackB_write(&o,large[i],32);
  95268. buffer=oggpackB_get_buffer(&o);
  95269. bytes=oggpackB_bytes(&o);
  95270. oggpackB_readinit(&r,buffer,bytes);
  95271. for(i=0;i<test2size;i++){
  95272. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95273. if(oggpackB_look(&r,32)!=large[i]){
  95274. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95275. oggpackB_look(&r,32),large[i]);
  95276. report("read incorrect value!\n");
  95277. }
  95278. oggpackB_adv(&r,32);
  95279. }
  95280. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95281. fprintf(stderr,"ok.");
  95282. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95283. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95284. fprintf(stderr,"ok.");
  95285. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95286. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95287. fprintf(stderr,"ok.");
  95288. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95289. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95290. fprintf(stderr,"ok.");
  95291. fprintf(stderr,"\nTesting read past end (MSb): ");
  95292. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95293. for(i=0;i<64;i++){
  95294. if(oggpackB_read(&r,1)!=0){
  95295. fprintf(stderr,"failed; got -1 prematurely.\n");
  95296. exit(1);
  95297. }
  95298. }
  95299. if(oggpackB_look(&r,1)!=-1 ||
  95300. oggpackB_read(&r,1)!=-1){
  95301. fprintf(stderr,"failed; read past end without -1.\n");
  95302. exit(1);
  95303. }
  95304. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95305. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95306. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95307. exit(1);
  95308. }
  95309. if(oggpackB_look(&r,18)!=0 ||
  95310. oggpackB_look(&r,18)!=0){
  95311. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95312. exit(1);
  95313. }
  95314. if(oggpackB_look(&r,19)!=-1 ||
  95315. oggpackB_look(&r,19)!=-1){
  95316. fprintf(stderr,"failed; read past end without -1.\n");
  95317. exit(1);
  95318. }
  95319. if(oggpackB_look(&r,32)!=-1 ||
  95320. oggpackB_look(&r,32)!=-1){
  95321. fprintf(stderr,"failed; read past end without -1.\n");
  95322. exit(1);
  95323. }
  95324. oggpackB_writeclear(&o);
  95325. fprintf(stderr,"ok.\n\n");
  95326. return(0);
  95327. }
  95328. #endif /* _V_SELFTEST */
  95329. #undef BUFFER_INCREMENT
  95330. #endif
  95331. /*** End of inlined file: bitwise.c ***/
  95332. /*** Start of inlined file: framing.c ***/
  95333. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95334. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95335. // tasks..
  95336. #if JUCE_MSVC
  95337. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95338. #endif
  95339. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95340. #if JUCE_USE_OGGVORBIS
  95341. #include <stdlib.h>
  95342. #include <string.h>
  95343. int ogg_page_version(ogg_page *og){
  95344. return((int)(og->header[4]));
  95345. }
  95346. int ogg_page_continued(ogg_page *og){
  95347. return((int)(og->header[5]&0x01));
  95348. }
  95349. int ogg_page_bos(ogg_page *og){
  95350. return((int)(og->header[5]&0x02));
  95351. }
  95352. int ogg_page_eos(ogg_page *og){
  95353. return((int)(og->header[5]&0x04));
  95354. }
  95355. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95356. unsigned char *page=og->header;
  95357. ogg_int64_t granulepos=page[13]&(0xff);
  95358. granulepos= (granulepos<<8)|(page[12]&0xff);
  95359. granulepos= (granulepos<<8)|(page[11]&0xff);
  95360. granulepos= (granulepos<<8)|(page[10]&0xff);
  95361. granulepos= (granulepos<<8)|(page[9]&0xff);
  95362. granulepos= (granulepos<<8)|(page[8]&0xff);
  95363. granulepos= (granulepos<<8)|(page[7]&0xff);
  95364. granulepos= (granulepos<<8)|(page[6]&0xff);
  95365. return(granulepos);
  95366. }
  95367. int ogg_page_serialno(ogg_page *og){
  95368. return(og->header[14] |
  95369. (og->header[15]<<8) |
  95370. (og->header[16]<<16) |
  95371. (og->header[17]<<24));
  95372. }
  95373. long ogg_page_pageno(ogg_page *og){
  95374. return(og->header[18] |
  95375. (og->header[19]<<8) |
  95376. (og->header[20]<<16) |
  95377. (og->header[21]<<24));
  95378. }
  95379. int ogg_page_packets(ogg_page *og){
  95380. int i,n=og->header[26],count=0;
  95381. for(i=0;i<n;i++)
  95382. if(og->header[27+i]<255)count++;
  95383. return(count);
  95384. }
  95385. #if 0
  95386. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95387. int i;
  95388. unsigned long r;
  95389. r = index << 24;
  95390. for (i=0; i<8; i++)
  95391. if (r & 0x80000000UL)
  95392. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95393. polynomial, although we use an
  95394. unreflected alg and an init/final
  95395. of 0, not 0xffffffff */
  95396. else
  95397. r<<=1;
  95398. return (r & 0xffffffffUL);
  95399. }
  95400. #endif
  95401. static const ogg_uint32_t crc_lookup[256]={
  95402. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95403. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95404. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95405. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95406. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95407. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95408. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95409. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95410. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95411. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95412. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95413. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95414. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95415. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95416. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95417. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95418. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95419. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95420. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95421. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95422. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95423. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95424. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95425. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95426. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95427. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95428. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95429. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95430. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95431. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95432. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95433. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95434. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95435. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95436. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95437. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95438. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95439. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95440. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95441. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95442. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95443. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95444. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95445. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95446. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95447. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95448. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95449. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95450. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95451. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95452. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95453. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95454. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95455. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95456. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95457. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95458. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95459. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95460. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95461. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95462. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95463. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95464. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95465. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95466. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95467. if(os){
  95468. memset(os,0,sizeof(*os));
  95469. os->body_storage=16*1024;
  95470. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95471. os->lacing_storage=1024;
  95472. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95473. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95474. os->serialno=serialno;
  95475. return(0);
  95476. }
  95477. return(-1);
  95478. }
  95479. int ogg_stream_clear(ogg_stream_state *os){
  95480. if(os){
  95481. if(os->body_data)_ogg_free(os->body_data);
  95482. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95483. if(os->granule_vals)_ogg_free(os->granule_vals);
  95484. memset(os,0,sizeof(*os));
  95485. }
  95486. return(0);
  95487. }
  95488. int ogg_stream_destroy(ogg_stream_state *os){
  95489. if(os){
  95490. ogg_stream_clear(os);
  95491. _ogg_free(os);
  95492. }
  95493. return(0);
  95494. }
  95495. static void _os_body_expand(ogg_stream_state *os,int needed){
  95496. if(os->body_storage<=os->body_fill+needed){
  95497. os->body_storage+=(needed+1024);
  95498. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95499. }
  95500. }
  95501. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95502. if(os->lacing_storage<=os->lacing_fill+needed){
  95503. os->lacing_storage+=(needed+32);
  95504. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95505. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95506. }
  95507. }
  95508. void ogg_page_checksum_set(ogg_page *og){
  95509. if(og){
  95510. ogg_uint32_t crc_reg=0;
  95511. int i;
  95512. og->header[22]=0;
  95513. og->header[23]=0;
  95514. og->header[24]=0;
  95515. og->header[25]=0;
  95516. for(i=0;i<og->header_len;i++)
  95517. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95518. for(i=0;i<og->body_len;i++)
  95519. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95520. og->header[22]=(unsigned char)(crc_reg&0xff);
  95521. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95522. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95523. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95524. }
  95525. }
  95526. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95527. int lacing_vals=op->bytes/255+1,i;
  95528. if(os->body_returned){
  95529. os->body_fill-=os->body_returned;
  95530. if(os->body_fill)
  95531. memmove(os->body_data,os->body_data+os->body_returned,
  95532. os->body_fill);
  95533. os->body_returned=0;
  95534. }
  95535. _os_body_expand(os,op->bytes);
  95536. _os_lacing_expand(os,lacing_vals);
  95537. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95538. os->body_fill+=op->bytes;
  95539. for(i=0;i<lacing_vals-1;i++){
  95540. os->lacing_vals[os->lacing_fill+i]=255;
  95541. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95542. }
  95543. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95544. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95545. os->lacing_vals[os->lacing_fill]|= 0x100;
  95546. os->lacing_fill+=lacing_vals;
  95547. os->packetno++;
  95548. if(op->e_o_s)os->e_o_s=1;
  95549. return(0);
  95550. }
  95551. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95552. int i;
  95553. int vals=0;
  95554. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95555. int bytes=0;
  95556. long acc=0;
  95557. ogg_int64_t granule_pos=-1;
  95558. if(maxvals==0)return(0);
  95559. if(os->b_o_s==0){ /* 'initial header page' case */
  95560. granule_pos=0;
  95561. for(vals=0;vals<maxvals;vals++){
  95562. if((os->lacing_vals[vals]&0x0ff)<255){
  95563. vals++;
  95564. break;
  95565. }
  95566. }
  95567. }else{
  95568. for(vals=0;vals<maxvals;vals++){
  95569. if(acc>4096)break;
  95570. acc+=os->lacing_vals[vals]&0x0ff;
  95571. if((os->lacing_vals[vals]&0xff)<255)
  95572. granule_pos=os->granule_vals[vals];
  95573. }
  95574. }
  95575. memcpy(os->header,"OggS",4);
  95576. os->header[4]=0x00;
  95577. os->header[5]=0x00;
  95578. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95579. if(os->b_o_s==0)os->header[5]|=0x02;
  95580. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95581. os->b_o_s=1;
  95582. for(i=6;i<14;i++){
  95583. os->header[i]=(unsigned char)(granule_pos&0xff);
  95584. granule_pos>>=8;
  95585. }
  95586. {
  95587. long serialno=os->serialno;
  95588. for(i=14;i<18;i++){
  95589. os->header[i]=(unsigned char)(serialno&0xff);
  95590. serialno>>=8;
  95591. }
  95592. }
  95593. if(os->pageno==-1)os->pageno=0; /* because someone called
  95594. stream_reset; this would be a
  95595. strange thing to do in an
  95596. encode stream, but it has
  95597. plausible uses */
  95598. {
  95599. long pageno=os->pageno++;
  95600. for(i=18;i<22;i++){
  95601. os->header[i]=(unsigned char)(pageno&0xff);
  95602. pageno>>=8;
  95603. }
  95604. }
  95605. os->header[22]=0;
  95606. os->header[23]=0;
  95607. os->header[24]=0;
  95608. os->header[25]=0;
  95609. os->header[26]=(unsigned char)(vals&0xff);
  95610. for(i=0;i<vals;i++)
  95611. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95612. og->header=os->header;
  95613. og->header_len=os->header_fill=vals+27;
  95614. og->body=os->body_data+os->body_returned;
  95615. og->body_len=bytes;
  95616. os->lacing_fill-=vals;
  95617. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95618. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95619. os->body_returned+=bytes;
  95620. ogg_page_checksum_set(og);
  95621. return(1);
  95622. }
  95623. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95624. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95625. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95626. os->lacing_fill>=255 || /* 'segment table full' case */
  95627. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95628. return(ogg_stream_flush(os,og));
  95629. }
  95630. return(0);
  95631. }
  95632. int ogg_stream_eos(ogg_stream_state *os){
  95633. return os->e_o_s;
  95634. }
  95635. int ogg_sync_init(ogg_sync_state *oy){
  95636. if(oy){
  95637. memset(oy,0,sizeof(*oy));
  95638. }
  95639. return(0);
  95640. }
  95641. int ogg_sync_clear(ogg_sync_state *oy){
  95642. if(oy){
  95643. if(oy->data)_ogg_free(oy->data);
  95644. ogg_sync_init(oy);
  95645. }
  95646. return(0);
  95647. }
  95648. int ogg_sync_destroy(ogg_sync_state *oy){
  95649. if(oy){
  95650. ogg_sync_clear(oy);
  95651. _ogg_free(oy);
  95652. }
  95653. return(0);
  95654. }
  95655. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95656. if(oy->returned){
  95657. oy->fill-=oy->returned;
  95658. if(oy->fill>0)
  95659. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95660. oy->returned=0;
  95661. }
  95662. if(size>oy->storage-oy->fill){
  95663. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95664. if(oy->data)
  95665. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95666. else
  95667. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95668. oy->storage=newsize;
  95669. }
  95670. return((char *)oy->data+oy->fill);
  95671. }
  95672. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95673. if(oy->fill+bytes>oy->storage)return(-1);
  95674. oy->fill+=bytes;
  95675. return(0);
  95676. }
  95677. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95678. unsigned char *page=oy->data+oy->returned;
  95679. unsigned char *next;
  95680. long bytes=oy->fill-oy->returned;
  95681. if(oy->headerbytes==0){
  95682. int headerbytes,i;
  95683. if(bytes<27)return(0); /* not enough for a header */
  95684. if(memcmp(page,"OggS",4))goto sync_fail;
  95685. headerbytes=page[26]+27;
  95686. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95687. for(i=0;i<page[26];i++)
  95688. oy->bodybytes+=page[27+i];
  95689. oy->headerbytes=headerbytes;
  95690. }
  95691. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95692. {
  95693. char chksum[4];
  95694. ogg_page log;
  95695. memcpy(chksum,page+22,4);
  95696. memset(page+22,0,4);
  95697. log.header=page;
  95698. log.header_len=oy->headerbytes;
  95699. log.body=page+oy->headerbytes;
  95700. log.body_len=oy->bodybytes;
  95701. ogg_page_checksum_set(&log);
  95702. if(memcmp(chksum,page+22,4)){
  95703. memcpy(page+22,chksum,4);
  95704. goto sync_fail;
  95705. }
  95706. }
  95707. {
  95708. unsigned char *page=oy->data+oy->returned;
  95709. long bytes;
  95710. if(og){
  95711. og->header=page;
  95712. og->header_len=oy->headerbytes;
  95713. og->body=page+oy->headerbytes;
  95714. og->body_len=oy->bodybytes;
  95715. }
  95716. oy->unsynced=0;
  95717. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95718. oy->headerbytes=0;
  95719. oy->bodybytes=0;
  95720. return(bytes);
  95721. }
  95722. sync_fail:
  95723. oy->headerbytes=0;
  95724. oy->bodybytes=0;
  95725. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95726. if(!next)
  95727. next=oy->data+oy->fill;
  95728. oy->returned=next-oy->data;
  95729. return(-(next-page));
  95730. }
  95731. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95732. for(;;){
  95733. long ret=ogg_sync_pageseek(oy,og);
  95734. if(ret>0){
  95735. return(1);
  95736. }
  95737. if(ret==0){
  95738. return(0);
  95739. }
  95740. if(!oy->unsynced){
  95741. oy->unsynced=1;
  95742. return(-1);
  95743. }
  95744. }
  95745. }
  95746. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95747. unsigned char *header=og->header;
  95748. unsigned char *body=og->body;
  95749. long bodysize=og->body_len;
  95750. int segptr=0;
  95751. int version=ogg_page_version(og);
  95752. int continued=ogg_page_continued(og);
  95753. int bos=ogg_page_bos(og);
  95754. int eos=ogg_page_eos(og);
  95755. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95756. int serialno=ogg_page_serialno(og);
  95757. long pageno=ogg_page_pageno(og);
  95758. int segments=header[26];
  95759. {
  95760. long lr=os->lacing_returned;
  95761. long br=os->body_returned;
  95762. if(br){
  95763. os->body_fill-=br;
  95764. if(os->body_fill)
  95765. memmove(os->body_data,os->body_data+br,os->body_fill);
  95766. os->body_returned=0;
  95767. }
  95768. if(lr){
  95769. if(os->lacing_fill-lr){
  95770. memmove(os->lacing_vals,os->lacing_vals+lr,
  95771. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95772. memmove(os->granule_vals,os->granule_vals+lr,
  95773. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95774. }
  95775. os->lacing_fill-=lr;
  95776. os->lacing_packet-=lr;
  95777. os->lacing_returned=0;
  95778. }
  95779. }
  95780. if(serialno!=os->serialno)return(-1);
  95781. if(version>0)return(-1);
  95782. _os_lacing_expand(os,segments+1);
  95783. if(pageno!=os->pageno){
  95784. int i;
  95785. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95786. os->body_fill-=os->lacing_vals[i]&0xff;
  95787. os->lacing_fill=os->lacing_packet;
  95788. if(os->pageno!=-1){
  95789. os->lacing_vals[os->lacing_fill++]=0x400;
  95790. os->lacing_packet++;
  95791. }
  95792. }
  95793. if(continued){
  95794. if(os->lacing_fill<1 ||
  95795. os->lacing_vals[os->lacing_fill-1]==0x400){
  95796. bos=0;
  95797. for(;segptr<segments;segptr++){
  95798. int val=header[27+segptr];
  95799. body+=val;
  95800. bodysize-=val;
  95801. if(val<255){
  95802. segptr++;
  95803. break;
  95804. }
  95805. }
  95806. }
  95807. }
  95808. if(bodysize){
  95809. _os_body_expand(os,bodysize);
  95810. memcpy(os->body_data+os->body_fill,body,bodysize);
  95811. os->body_fill+=bodysize;
  95812. }
  95813. {
  95814. int saved=-1;
  95815. while(segptr<segments){
  95816. int val=header[27+segptr];
  95817. os->lacing_vals[os->lacing_fill]=val;
  95818. os->granule_vals[os->lacing_fill]=-1;
  95819. if(bos){
  95820. os->lacing_vals[os->lacing_fill]|=0x100;
  95821. bos=0;
  95822. }
  95823. if(val<255)saved=os->lacing_fill;
  95824. os->lacing_fill++;
  95825. segptr++;
  95826. if(val<255)os->lacing_packet=os->lacing_fill;
  95827. }
  95828. if(saved!=-1){
  95829. os->granule_vals[saved]=granulepos;
  95830. }
  95831. }
  95832. if(eos){
  95833. os->e_o_s=1;
  95834. if(os->lacing_fill>0)
  95835. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95836. }
  95837. os->pageno=pageno+1;
  95838. return(0);
  95839. }
  95840. int ogg_sync_reset(ogg_sync_state *oy){
  95841. oy->fill=0;
  95842. oy->returned=0;
  95843. oy->unsynced=0;
  95844. oy->headerbytes=0;
  95845. oy->bodybytes=0;
  95846. return(0);
  95847. }
  95848. int ogg_stream_reset(ogg_stream_state *os){
  95849. os->body_fill=0;
  95850. os->body_returned=0;
  95851. os->lacing_fill=0;
  95852. os->lacing_packet=0;
  95853. os->lacing_returned=0;
  95854. os->header_fill=0;
  95855. os->e_o_s=0;
  95856. os->b_o_s=0;
  95857. os->pageno=-1;
  95858. os->packetno=0;
  95859. os->granulepos=0;
  95860. return(0);
  95861. }
  95862. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95863. ogg_stream_reset(os);
  95864. os->serialno=serialno;
  95865. return(0);
  95866. }
  95867. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95868. int ptr=os->lacing_returned;
  95869. if(os->lacing_packet<=ptr)return(0);
  95870. if(os->lacing_vals[ptr]&0x400){
  95871. os->lacing_returned++;
  95872. os->packetno++;
  95873. return(-1);
  95874. }
  95875. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95876. to ask if there's a whole packet
  95877. waiting */
  95878. {
  95879. int size=os->lacing_vals[ptr]&0xff;
  95880. int bytes=size;
  95881. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95882. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95883. while(size==255){
  95884. int val=os->lacing_vals[++ptr];
  95885. size=val&0xff;
  95886. if(val&0x200)eos=0x200;
  95887. bytes+=size;
  95888. }
  95889. if(op){
  95890. op->e_o_s=eos;
  95891. op->b_o_s=bos;
  95892. op->packet=os->body_data+os->body_returned;
  95893. op->packetno=os->packetno;
  95894. op->granulepos=os->granule_vals[ptr];
  95895. op->bytes=bytes;
  95896. }
  95897. if(adv){
  95898. os->body_returned+=bytes;
  95899. os->lacing_returned=ptr+1;
  95900. os->packetno++;
  95901. }
  95902. }
  95903. return(1);
  95904. }
  95905. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  95906. return _packetout(os,op,1);
  95907. }
  95908. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  95909. return _packetout(os,op,0);
  95910. }
  95911. void ogg_packet_clear(ogg_packet *op) {
  95912. _ogg_free(op->packet);
  95913. memset(op, 0, sizeof(*op));
  95914. }
  95915. #ifdef _V_SELFTEST
  95916. #include <stdio.h>
  95917. ogg_stream_state os_en, os_de;
  95918. ogg_sync_state oy;
  95919. void checkpacket(ogg_packet *op,int len, int no, int pos){
  95920. long j;
  95921. static int sequence=0;
  95922. static int lastno=0;
  95923. if(op->bytes!=len){
  95924. fprintf(stderr,"incorrect packet length!\n");
  95925. exit(1);
  95926. }
  95927. if(op->granulepos!=pos){
  95928. fprintf(stderr,"incorrect packet position!\n");
  95929. exit(1);
  95930. }
  95931. if(no==0){
  95932. sequence=0;
  95933. }else{
  95934. sequence++;
  95935. if(no>lastno+1)
  95936. sequence++;
  95937. }
  95938. lastno=no;
  95939. if(op->packetno!=sequence){
  95940. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  95941. (long)(op->packetno),sequence);
  95942. exit(1);
  95943. }
  95944. for(j=0;j<op->bytes;j++)
  95945. if(op->packet[j]!=((j+no)&0xff)){
  95946. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  95947. j,op->packet[j],(j+no)&0xff);
  95948. exit(1);
  95949. }
  95950. }
  95951. void check_page(unsigned char *data,const int *header,ogg_page *og){
  95952. long j;
  95953. for(j=0;j<og->body_len;j++)
  95954. if(og->body[j]!=data[j]){
  95955. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  95956. j,data[j],og->body[j]);
  95957. exit(1);
  95958. }
  95959. for(j=0;j<og->header_len;j++){
  95960. if(og->header[j]!=header[j]){
  95961. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  95962. for(j=0;j<header[26]+27;j++)
  95963. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  95964. fprintf(stderr,"\n");
  95965. exit(1);
  95966. }
  95967. }
  95968. if(og->header_len!=header[26]+27){
  95969. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  95970. og->header_len,header[26]+27);
  95971. exit(1);
  95972. }
  95973. }
  95974. void print_header(ogg_page *og){
  95975. int j;
  95976. fprintf(stderr,"\nHEADER:\n");
  95977. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  95978. og->header[0],og->header[1],og->header[2],og->header[3],
  95979. (int)og->header[4],(int)og->header[5]);
  95980. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  95981. (og->header[9]<<24)|(og->header[8]<<16)|
  95982. (og->header[7]<<8)|og->header[6],
  95983. (og->header[17]<<24)|(og->header[16]<<16)|
  95984. (og->header[15]<<8)|og->header[14],
  95985. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  95986. (og->header[19]<<8)|og->header[18]);
  95987. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  95988. (int)og->header[22],(int)og->header[23],
  95989. (int)og->header[24],(int)og->header[25],
  95990. (int)og->header[26]);
  95991. for(j=27;j<og->header_len;j++)
  95992. fprintf(stderr,"%d ",(int)og->header[j]);
  95993. fprintf(stderr,")\n\n");
  95994. }
  95995. void copy_page(ogg_page *og){
  95996. unsigned char *temp=_ogg_malloc(og->header_len);
  95997. memcpy(temp,og->header,og->header_len);
  95998. og->header=temp;
  95999. temp=_ogg_malloc(og->body_len);
  96000. memcpy(temp,og->body,og->body_len);
  96001. og->body=temp;
  96002. }
  96003. void free_page(ogg_page *og){
  96004. _ogg_free (og->header);
  96005. _ogg_free (og->body);
  96006. }
  96007. void error(void){
  96008. fprintf(stderr,"error!\n");
  96009. exit(1);
  96010. }
  96011. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96012. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96013. 0x01,0x02,0x03,0x04,0,0,0,0,
  96014. 0x15,0xed,0xec,0x91,
  96015. 1,
  96016. 17};
  96017. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96018. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96019. 0x01,0x02,0x03,0x04,0,0,0,0,
  96020. 0x59,0x10,0x6c,0x2c,
  96021. 1,
  96022. 17};
  96023. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96024. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96025. 0x01,0x02,0x03,0x04,1,0,0,0,
  96026. 0x89,0x33,0x85,0xce,
  96027. 13,
  96028. 254,255,0,255,1,255,245,255,255,0,
  96029. 255,255,90};
  96030. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96031. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96032. 0x01,0x02,0x03,0x04,0,0,0,0,
  96033. 0xff,0x7b,0x23,0x17,
  96034. 1,
  96035. 0};
  96036. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96037. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96038. 0x01,0x02,0x03,0x04,1,0,0,0,
  96039. 0x5c,0x3f,0x66,0xcb,
  96040. 17,
  96041. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96042. 255,255,90,0};
  96043. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96044. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96045. 0x01,0x02,0x03,0x04,0,0,0,0,
  96046. 0x01,0x27,0x31,0xaa,
  96047. 18,
  96048. 255,255,255,255,255,255,255,255,
  96049. 255,255,255,255,255,255,255,255,255,10};
  96050. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96051. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96052. 0x01,0x02,0x03,0x04,1,0,0,0,
  96053. 0x7f,0x4e,0x8a,0xd2,
  96054. 4,
  96055. 255,4,255,0};
  96056. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96057. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96058. 0x01,0x02,0x03,0x04,0,0,0,0,
  96059. 0xff,0x7b,0x23,0x17,
  96060. 1,
  96061. 0};
  96062. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96063. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96064. 0x01,0x02,0x03,0x04,1,0,0,0,
  96065. 0x54,0x05,0x51,0xc8,
  96066. 17,
  96067. 255,255,255,255,255,255,255,255,
  96068. 255,255,255,255,255,255,255,255,255};
  96069. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96070. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96071. 0x01,0x02,0x03,0x04,2,0,0,0,
  96072. 0xc8,0xc3,0xcb,0xed,
  96073. 5,
  96074. 10,255,4,255,0};
  96075. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96076. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96077. 0x01,0x02,0x03,0x04,0,0,0,0,
  96078. 0xff,0x7b,0x23,0x17,
  96079. 1,
  96080. 0};
  96081. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96082. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96083. 0x01,0x02,0x03,0x04,1,0,0,0,
  96084. 0xed,0x2a,0x2e,0xa7,
  96085. 255,
  96086. 10,10,10,10,10,10,10,10,
  96087. 10,10,10,10,10,10,10,10,
  96088. 10,10,10,10,10,10,10,10,
  96089. 10,10,10,10,10,10,10,10,
  96090. 10,10,10,10,10,10,10,10,
  96091. 10,10,10,10,10,10,10,10,
  96092. 10,10,10,10,10,10,10,10,
  96093. 10,10,10,10,10,10,10,10,
  96094. 10,10,10,10,10,10,10,10,
  96095. 10,10,10,10,10,10,10,10,
  96096. 10,10,10,10,10,10,10,10,
  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};
  96118. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96119. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96120. 0x01,0x02,0x03,0x04,2,0,0,0,
  96121. 0x6c,0x3b,0x82,0x3d,
  96122. 1,
  96123. 50};
  96124. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96125. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96126. 0x01,0x02,0x03,0x04,0,0,0,0,
  96127. 0xff,0x7b,0x23,0x17,
  96128. 1,
  96129. 0};
  96130. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96131. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96132. 0x01,0x02,0x03,0x04,1,0,0,0,
  96133. 0x3c,0xd9,0x4d,0x3f,
  96134. 17,
  96135. 100,255,255,255,255,255,255,255,255,
  96136. 255,255,255,255,255,255,255,255};
  96137. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96138. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96139. 0x01,0x02,0x03,0x04,2,0,0,0,
  96140. 0x01,0xd2,0xe5,0xe5,
  96141. 17,
  96142. 255,255,255,255,255,255,255,255,
  96143. 255,255,255,255,255,255,255,255,255};
  96144. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96145. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96146. 0x01,0x02,0x03,0x04,3,0,0,0,
  96147. 0xef,0xdd,0x88,0xde,
  96148. 7,
  96149. 255,255,75,255,4,255,0};
  96150. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96151. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96152. 0x01,0x02,0x03,0x04,0,0,0,0,
  96153. 0xff,0x7b,0x23,0x17,
  96154. 1,
  96155. 0};
  96156. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96157. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96158. 0x01,0x02,0x03,0x04,1,0,0,0,
  96159. 0x3c,0xd9,0x4d,0x3f,
  96160. 17,
  96161. 100,255,255,255,255,255,255,255,255,
  96162. 255,255,255,255,255,255,255,255};
  96163. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96164. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96165. 0x01,0x02,0x03,0x04,2,0,0,0,
  96166. 0xd4,0xe0,0x60,0xe5,
  96167. 1,0};
  96168. void test_pack(const int *pl, const int **headers, int byteskip,
  96169. int pageskip, int packetskip){
  96170. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96171. long inptr=0;
  96172. long outptr=0;
  96173. long deptr=0;
  96174. long depacket=0;
  96175. long granule_pos=7,pageno=0;
  96176. int i,j,packets,pageout=pageskip;
  96177. int eosflag=0;
  96178. int bosflag=0;
  96179. int byteskipcount=0;
  96180. ogg_stream_reset(&os_en);
  96181. ogg_stream_reset(&os_de);
  96182. ogg_sync_reset(&oy);
  96183. for(packets=0;packets<packetskip;packets++)
  96184. depacket+=pl[packets];
  96185. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96186. for(i=0;i<packets;i++){
  96187. ogg_packet op;
  96188. int len=pl[i];
  96189. op.packet=data+inptr;
  96190. op.bytes=len;
  96191. op.e_o_s=(pl[i+1]<0?1:0);
  96192. op.granulepos=granule_pos;
  96193. granule_pos+=1024;
  96194. for(j=0;j<len;j++)data[inptr++]=i+j;
  96195. ogg_stream_packetin(&os_en,&op);
  96196. {
  96197. ogg_page og;
  96198. while(ogg_stream_pageout(&os_en,&og)){
  96199. fprintf(stderr,"%ld, ",pageno);
  96200. if(headers[pageno]==NULL){
  96201. fprintf(stderr,"coded too many pages!\n");
  96202. exit(1);
  96203. }
  96204. check_page(data+outptr,headers[pageno],&og);
  96205. outptr+=og.body_len;
  96206. pageno++;
  96207. if(pageskip){
  96208. bosflag=1;
  96209. pageskip--;
  96210. deptr+=og.body_len;
  96211. }
  96212. {
  96213. ogg_page og_de;
  96214. ogg_packet op_de,op_de2;
  96215. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96216. char *next=buf;
  96217. byteskipcount+=og.header_len;
  96218. if(byteskipcount>byteskip){
  96219. memcpy(next,og.header,byteskipcount-byteskip);
  96220. next+=byteskipcount-byteskip;
  96221. byteskipcount=byteskip;
  96222. }
  96223. byteskipcount+=og.body_len;
  96224. if(byteskipcount>byteskip){
  96225. memcpy(next,og.body,byteskipcount-byteskip);
  96226. next+=byteskipcount-byteskip;
  96227. byteskipcount=byteskip;
  96228. }
  96229. ogg_sync_wrote(&oy,next-buf);
  96230. while(1){
  96231. int ret=ogg_sync_pageout(&oy,&og_de);
  96232. if(ret==0)break;
  96233. if(ret<0)continue;
  96234. fprintf(stderr,"(%ld), ",pageout);
  96235. check_page(data+deptr,headers[pageout],&og_de);
  96236. deptr+=og_de.body_len;
  96237. pageout++;
  96238. ogg_stream_pagein(&os_de,&og_de);
  96239. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96240. ogg_stream_packetpeek(&os_de,NULL);
  96241. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96242. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96243. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96244. depacket);
  96245. exit(1);
  96246. }
  96247. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96248. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96249. depacket);
  96250. exit(1);
  96251. }
  96252. if(bosflag==0 && op_de.b_o_s==0){
  96253. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96254. exit(1);
  96255. }
  96256. if(bosflag && op_de.b_o_s){
  96257. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96258. exit(1);
  96259. }
  96260. bosflag=1;
  96261. depacket+=op_de.bytes;
  96262. if(eosflag){
  96263. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96264. exit(1);
  96265. }
  96266. if(op_de.e_o_s)eosflag=1;
  96267. if(op_de.granulepos!=-1){
  96268. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96269. }
  96270. }
  96271. }
  96272. }
  96273. }
  96274. }
  96275. }
  96276. _ogg_free(data);
  96277. if(headers[pageno]!=NULL){
  96278. fprintf(stderr,"did not write last page!\n");
  96279. exit(1);
  96280. }
  96281. if(headers[pageout]!=NULL){
  96282. fprintf(stderr,"did not decode last page!\n");
  96283. exit(1);
  96284. }
  96285. if(inptr!=outptr){
  96286. fprintf(stderr,"encoded page data incomplete!\n");
  96287. exit(1);
  96288. }
  96289. if(inptr!=deptr){
  96290. fprintf(stderr,"decoded page data incomplete!\n");
  96291. exit(1);
  96292. }
  96293. if(inptr!=depacket){
  96294. fprintf(stderr,"decoded packet data incomplete!\n");
  96295. exit(1);
  96296. }
  96297. if(!eosflag){
  96298. fprintf(stderr,"Never got a packet with EOS set!\n");
  96299. exit(1);
  96300. }
  96301. fprintf(stderr,"ok.\n");
  96302. }
  96303. int main(void){
  96304. ogg_stream_init(&os_en,0x04030201);
  96305. ogg_stream_init(&os_de,0x04030201);
  96306. ogg_sync_init(&oy);
  96307. {
  96308. const int packets[]={17, -1};
  96309. const int *headret[]={head1_0,NULL};
  96310. fprintf(stderr,"testing single page encoding... ");
  96311. test_pack(packets,headret,0,0,0);
  96312. }
  96313. {
  96314. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96315. const int *headret[]={head1_1,head2_1,NULL};
  96316. fprintf(stderr,"testing basic page encoding... ");
  96317. test_pack(packets,headret,0,0,0);
  96318. }
  96319. {
  96320. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96321. const int *headret[]={head1_2,head2_2,NULL};
  96322. fprintf(stderr,"testing basic nil packets... ");
  96323. test_pack(packets,headret,0,0,0);
  96324. }
  96325. {
  96326. const int packets[]={4345,259,255,-1};
  96327. const int *headret[]={head1_3,head2_3,NULL};
  96328. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96329. test_pack(packets,headret,0,0,0);
  96330. }
  96331. {
  96332. const int packets[]={0,4345,259,255,-1};
  96333. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96334. fprintf(stderr,"testing single packet page span... ");
  96335. test_pack(packets,headret,0,0,0);
  96336. }
  96337. {
  96338. const int packets[]={0,10,10,10,10,10,10,10,10,
  96339. 10,10,10,10,10,10,10,10,
  96340. 10,10,10,10,10,10,10,10,
  96341. 10,10,10,10,10,10,10,10,
  96342. 10,10,10,10,10,10,10,10,
  96343. 10,10,10,10,10,10,10,10,
  96344. 10,10,10,10,10,10,10,10,
  96345. 10,10,10,10,10,10,10,10,
  96346. 10,10,10,10,10,10,10,10,
  96347. 10,10,10,10,10,10,10,10,
  96348. 10,10,10,10,10,10,10,10,
  96349. 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,50,-1};
  96370. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96371. fprintf(stderr,"testing max packet segments... ");
  96372. test_pack(packets,headret,0,0,0);
  96373. }
  96374. {
  96375. const int packets[]={0,100,9000,259,255,-1};
  96376. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96377. fprintf(stderr,"testing very large packets... ");
  96378. test_pack(packets,headret,0,0,0);
  96379. }
  96380. {
  96381. const int packets[]={0,100,9000,259,255,-1};
  96382. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96383. fprintf(stderr,"testing continuation resync in very large packets... ");
  96384. test_pack(packets,headret,100,2,3);
  96385. }
  96386. {
  96387. const int packets[]={0,100,4080,-1};
  96388. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96389. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96390. test_pack(packets,headret,0,0,0);
  96391. }
  96392. {
  96393. unsigned char *data=_ogg_malloc(1024*1024);
  96394. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96395. int inptr=0,i,j;
  96396. ogg_page og[5];
  96397. ogg_stream_reset(&os_en);
  96398. for(i=0;pl[i]!=-1;i++){
  96399. ogg_packet op;
  96400. int len=pl[i];
  96401. op.packet=data+inptr;
  96402. op.bytes=len;
  96403. op.e_o_s=(pl[i+1]<0?1:0);
  96404. op.granulepos=(i+1)*1000;
  96405. for(j=0;j<len;j++)data[inptr++]=i+j;
  96406. ogg_stream_packetin(&os_en,&op);
  96407. }
  96408. _ogg_free(data);
  96409. for(i=0;i<5;i++){
  96410. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96411. fprintf(stderr,"Too few pages output building sync tests!\n");
  96412. exit(1);
  96413. }
  96414. copy_page(&og[i]);
  96415. }
  96416. {
  96417. ogg_page temp;
  96418. ogg_packet test;
  96419. fprintf(stderr,"Testing loss of pages... ");
  96420. ogg_sync_reset(&oy);
  96421. ogg_stream_reset(&os_de);
  96422. for(i=0;i<5;i++){
  96423. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96424. og[i].header_len);
  96425. ogg_sync_wrote(&oy,og[i].header_len);
  96426. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96427. ogg_sync_wrote(&oy,og[i].body_len);
  96428. }
  96429. ogg_sync_pageout(&oy,&temp);
  96430. ogg_stream_pagein(&os_de,&temp);
  96431. ogg_sync_pageout(&oy,&temp);
  96432. ogg_stream_pagein(&os_de,&temp);
  96433. ogg_sync_pageout(&oy,&temp);
  96434. ogg_sync_pageout(&oy,&temp);
  96435. ogg_stream_pagein(&os_de,&temp);
  96436. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96437. checkpacket(&test,0,0,0);
  96438. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96439. checkpacket(&test,100,1,-1);
  96440. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96441. checkpacket(&test,4079,2,3000);
  96442. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96443. fprintf(stderr,"Error: loss of page did not return error\n");
  96444. exit(1);
  96445. }
  96446. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96447. checkpacket(&test,76,5,-1);
  96448. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96449. checkpacket(&test,34,6,-1);
  96450. fprintf(stderr,"ok.\n");
  96451. }
  96452. {
  96453. ogg_page temp;
  96454. ogg_packet test;
  96455. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96456. ogg_sync_reset(&oy);
  96457. ogg_stream_reset(&os_de);
  96458. for(i=0;i<5;i++){
  96459. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96460. og[i].header_len);
  96461. ogg_sync_wrote(&oy,og[i].header_len);
  96462. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96463. ogg_sync_wrote(&oy,og[i].body_len);
  96464. }
  96465. ogg_sync_pageout(&oy,&temp);
  96466. ogg_stream_pagein(&os_de,&temp);
  96467. ogg_sync_pageout(&oy,&temp);
  96468. ogg_stream_pagein(&os_de,&temp);
  96469. ogg_sync_pageout(&oy,&temp);
  96470. ogg_stream_pagein(&os_de,&temp);
  96471. ogg_sync_pageout(&oy,&temp);
  96472. ogg_sync_pageout(&oy,&temp);
  96473. ogg_stream_pagein(&os_de,&temp);
  96474. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96475. checkpacket(&test,0,0,0);
  96476. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96477. checkpacket(&test,100,1,-1);
  96478. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96479. checkpacket(&test,4079,2,3000);
  96480. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96481. checkpacket(&test,2956,3,4000);
  96482. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96483. fprintf(stderr,"Error: loss of page did not return error\n");
  96484. exit(1);
  96485. }
  96486. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96487. checkpacket(&test,300,13,14000);
  96488. fprintf(stderr,"ok.\n");
  96489. }
  96490. {
  96491. ogg_page og_de;
  96492. fprintf(stderr,"Testing sync on partial inputs... ");
  96493. ogg_sync_reset(&oy);
  96494. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96495. 3);
  96496. ogg_sync_wrote(&oy,3);
  96497. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96498. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96499. 20);
  96500. ogg_sync_wrote(&oy,20);
  96501. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96502. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96503. 5);
  96504. ogg_sync_wrote(&oy,5);
  96505. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96506. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96507. og[1].header_len-28);
  96508. ogg_sync_wrote(&oy,og[1].header_len-28);
  96509. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96510. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96511. ogg_sync_wrote(&oy,1000);
  96512. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96513. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96514. og[1].body_len-1000);
  96515. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96516. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96517. fprintf(stderr,"ok.\n");
  96518. }
  96519. {
  96520. ogg_page og_de;
  96521. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96522. ogg_sync_reset(&oy);
  96523. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96524. og[1].header_len);
  96525. ogg_sync_wrote(&oy,og[1].header_len);
  96526. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96527. og[1].body_len);
  96528. ogg_sync_wrote(&oy,og[1].body_len);
  96529. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96530. 20);
  96531. ogg_sync_wrote(&oy,20);
  96532. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96533. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96534. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96535. og[1].header_len-20);
  96536. ogg_sync_wrote(&oy,og[1].header_len-20);
  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. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96541. fprintf(stderr,"ok.\n");
  96542. }
  96543. {
  96544. ogg_page og_de;
  96545. fprintf(stderr,"Testing search for capture... ");
  96546. ogg_sync_reset(&oy);
  96547. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96548. og[1].body_len);
  96549. ogg_sync_wrote(&oy,og[1].body_len);
  96550. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96551. og[1].header_len);
  96552. ogg_sync_wrote(&oy,og[1].header_len);
  96553. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96554. og[1].body_len);
  96555. ogg_sync_wrote(&oy,og[1].body_len);
  96556. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96557. 20);
  96558. ogg_sync_wrote(&oy,20);
  96559. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96560. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96561. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96562. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96563. og[2].header_len-20);
  96564. ogg_sync_wrote(&oy,og[2].header_len-20);
  96565. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96566. og[2].body_len);
  96567. ogg_sync_wrote(&oy,og[2].body_len);
  96568. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96569. fprintf(stderr,"ok.\n");
  96570. }
  96571. {
  96572. ogg_page og_de;
  96573. fprintf(stderr,"Testing recapture... ");
  96574. ogg_sync_reset(&oy);
  96575. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96576. og[1].header_len);
  96577. ogg_sync_wrote(&oy,og[1].header_len);
  96578. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96579. og[1].body_len);
  96580. ogg_sync_wrote(&oy,og[1].body_len);
  96581. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96582. og[2].header_len);
  96583. ogg_sync_wrote(&oy,og[2].header_len);
  96584. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96585. og[2].header_len);
  96586. ogg_sync_wrote(&oy,og[2].header_len);
  96587. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96588. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96589. og[2].body_len-5);
  96590. ogg_sync_wrote(&oy,og[2].body_len-5);
  96591. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96592. og[3].header_len);
  96593. ogg_sync_wrote(&oy,og[3].header_len);
  96594. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96595. og[3].body_len);
  96596. ogg_sync_wrote(&oy,og[3].body_len);
  96597. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96598. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96599. fprintf(stderr,"ok.\n");
  96600. }
  96601. {
  96602. for(i=0;i<5;i++){
  96603. free_page(&og[i]);
  96604. }
  96605. }
  96606. }
  96607. return(0);
  96608. }
  96609. #endif
  96610. #endif
  96611. /*** End of inlined file: framing.c ***/
  96612. /*** Start of inlined file: analysis.c ***/
  96613. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96614. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96615. // tasks..
  96616. #if JUCE_MSVC
  96617. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96618. #endif
  96619. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96620. #if JUCE_USE_OGGVORBIS
  96621. #include <stdio.h>
  96622. #include <string.h>
  96623. #include <math.h>
  96624. /*** Start of inlined file: codec_internal.h ***/
  96625. #ifndef _V_CODECI_H_
  96626. #define _V_CODECI_H_
  96627. /*** Start of inlined file: envelope.h ***/
  96628. #ifndef _V_ENVELOPE_
  96629. #define _V_ENVELOPE_
  96630. /*** Start of inlined file: mdct.h ***/
  96631. #ifndef _OGG_mdct_H_
  96632. #define _OGG_mdct_H_
  96633. #ifdef MDCT_INTEGERIZED
  96634. #define DATA_TYPE int
  96635. #define REG_TYPE register int
  96636. #define TRIGBITS 14
  96637. #define cPI3_8 6270
  96638. #define cPI2_8 11585
  96639. #define cPI1_8 15137
  96640. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96641. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96642. #define HALVE(x) ((x)>>1)
  96643. #else
  96644. #define DATA_TYPE float
  96645. #define REG_TYPE float
  96646. #define cPI3_8 .38268343236508977175F
  96647. #define cPI2_8 .70710678118654752441F
  96648. #define cPI1_8 .92387953251128675613F
  96649. #define FLOAT_CONV(x) (x)
  96650. #define MULT_NORM(x) (x)
  96651. #define HALVE(x) ((x)*.5f)
  96652. #endif
  96653. typedef struct {
  96654. int n;
  96655. int log2n;
  96656. DATA_TYPE *trig;
  96657. int *bitrev;
  96658. DATA_TYPE scale;
  96659. } mdct_lookup;
  96660. extern void mdct_init(mdct_lookup *lookup,int n);
  96661. extern void mdct_clear(mdct_lookup *l);
  96662. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96663. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96664. #endif
  96665. /*** End of inlined file: mdct.h ***/
  96666. #define VE_PRE 16
  96667. #define VE_WIN 4
  96668. #define VE_POST 2
  96669. #define VE_AMP (VE_PRE+VE_POST-1)
  96670. #define VE_BANDS 7
  96671. #define VE_NEARDC 15
  96672. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96673. #define VE_MAXSTRETCH 12 /* one-third full block */
  96674. typedef struct {
  96675. float ampbuf[VE_AMP];
  96676. int ampptr;
  96677. float nearDC[VE_NEARDC];
  96678. float nearDC_acc;
  96679. float nearDC_partialacc;
  96680. int nearptr;
  96681. } envelope_filter_state;
  96682. typedef struct {
  96683. int begin;
  96684. int end;
  96685. float *window;
  96686. float total;
  96687. } envelope_band;
  96688. typedef struct {
  96689. int ch;
  96690. int winlength;
  96691. int searchstep;
  96692. float minenergy;
  96693. mdct_lookup mdct;
  96694. float *mdct_win;
  96695. envelope_band band[VE_BANDS];
  96696. envelope_filter_state *filter;
  96697. int stretch;
  96698. int *mark;
  96699. long storage;
  96700. long current;
  96701. long curmark;
  96702. long cursor;
  96703. } envelope_lookup;
  96704. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96705. extern void _ve_envelope_clear(envelope_lookup *e);
  96706. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96707. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96708. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96709. #endif
  96710. /*** End of inlined file: envelope.h ***/
  96711. /*** Start of inlined file: codebook.h ***/
  96712. #ifndef _V_CODEBOOK_H_
  96713. #define _V_CODEBOOK_H_
  96714. typedef struct static_codebook{
  96715. long dim; /* codebook dimensions (elements per vector) */
  96716. long entries; /* codebook entries */
  96717. long *lengthlist; /* codeword lengths in bits */
  96718. int maptype; /* 0=none
  96719. 1=implicitly populated values from map column
  96720. 2=listed arbitrary values */
  96721. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96722. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96723. int q_quant; /* bits: 0 < quant <= 16 */
  96724. int q_sequencep; /* bitflag */
  96725. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96726. map == 2: list of dim*entries quantized entry vals
  96727. */
  96728. struct encode_aux_nearestmatch *nearest_tree;
  96729. struct encode_aux_threshmatch *thresh_tree;
  96730. struct encode_aux_pigeonhole *pigeon_tree;
  96731. int allocedp;
  96732. } static_codebook;
  96733. typedef struct encode_aux_nearestmatch{
  96734. long *ptr0;
  96735. long *ptr1;
  96736. long *p; /* decision points (each is an entry) */
  96737. long *q; /* decision points (each is an entry) */
  96738. long aux; /* number of tree entries */
  96739. long alloc;
  96740. } encode_aux_nearestmatch;
  96741. typedef struct encode_aux_threshmatch{
  96742. float *quantthresh;
  96743. long *quantmap;
  96744. int quantvals;
  96745. int threshvals;
  96746. } encode_aux_threshmatch;
  96747. typedef struct encode_aux_pigeonhole{
  96748. float min;
  96749. float del;
  96750. int mapentries;
  96751. int quantvals;
  96752. long *pigeonmap;
  96753. long fittotal;
  96754. long *fitlist;
  96755. long *fitmap;
  96756. long *fitlength;
  96757. } encode_aux_pigeonhole;
  96758. typedef struct codebook{
  96759. long dim; /* codebook dimensions (elements per vector) */
  96760. long entries; /* codebook entries */
  96761. long used_entries; /* populated codebook entries */
  96762. const static_codebook *c;
  96763. float *valuelist; /* list of dim*entries actual entry values */
  96764. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96765. int *dec_index; /* only used if sparseness collapsed */
  96766. char *dec_codelengths;
  96767. ogg_uint32_t *dec_firsttable;
  96768. int dec_firsttablen;
  96769. int dec_maxlength;
  96770. } codebook;
  96771. extern void vorbis_staticbook_clear(static_codebook *b);
  96772. extern void vorbis_staticbook_destroy(static_codebook *b);
  96773. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96774. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96775. extern void vorbis_book_clear(codebook *b);
  96776. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96777. extern float *_book_logdist(const static_codebook *b,float *vals);
  96778. extern float _float32_unpack(long val);
  96779. extern long _float32_pack(float val);
  96780. extern int _best(codebook *book, float *a, int step);
  96781. extern int _ilog(unsigned int v);
  96782. extern long _book_maptype1_quantvals(const static_codebook *b);
  96783. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96784. extern long vorbis_book_codeword(codebook *book,int entry);
  96785. extern long vorbis_book_codelen(codebook *book,int entry);
  96786. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96787. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96788. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96789. extern int vorbis_book_errorv(codebook *book, float *a);
  96790. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96791. oggpack_buffer *b);
  96792. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96793. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96794. oggpack_buffer *b,int n);
  96795. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96796. oggpack_buffer *b,int n);
  96797. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96798. oggpack_buffer *b,int n);
  96799. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96800. long off,int ch,
  96801. oggpack_buffer *b,int n);
  96802. #endif
  96803. /*** End of inlined file: codebook.h ***/
  96804. #define BLOCKTYPE_IMPULSE 0
  96805. #define BLOCKTYPE_PADDING 1
  96806. #define BLOCKTYPE_TRANSITION 0
  96807. #define BLOCKTYPE_LONG 1
  96808. #define PACKETBLOBS 15
  96809. typedef struct vorbis_block_internal{
  96810. float **pcmdelay; /* this is a pointer into local storage */
  96811. float ampmax;
  96812. int blocktype;
  96813. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96814. blob [PACKETBLOBS/2] points to
  96815. the oggpack_buffer in the
  96816. main vorbis_block */
  96817. } vorbis_block_internal;
  96818. typedef void vorbis_look_floor;
  96819. typedef void vorbis_look_residue;
  96820. typedef void vorbis_look_transform;
  96821. typedef struct {
  96822. int blockflag;
  96823. int windowtype;
  96824. int transformtype;
  96825. int mapping;
  96826. } vorbis_info_mode;
  96827. typedef void vorbis_info_floor;
  96828. typedef void vorbis_info_residue;
  96829. typedef void vorbis_info_mapping;
  96830. /*** Start of inlined file: psy.h ***/
  96831. #ifndef _V_PSY_H_
  96832. #define _V_PSY_H_
  96833. /*** Start of inlined file: smallft.h ***/
  96834. #ifndef _V_SMFT_H_
  96835. #define _V_SMFT_H_
  96836. typedef struct {
  96837. int n;
  96838. float *trigcache;
  96839. int *splitcache;
  96840. } drft_lookup;
  96841. extern void drft_forward(drft_lookup *l,float *data);
  96842. extern void drft_backward(drft_lookup *l,float *data);
  96843. extern void drft_init(drft_lookup *l,int n);
  96844. extern void drft_clear(drft_lookup *l);
  96845. #endif
  96846. /*** End of inlined file: smallft.h ***/
  96847. /*** Start of inlined file: backends.h ***/
  96848. #ifndef _vorbis_backend_h_
  96849. #define _vorbis_backend_h_
  96850. typedef struct{
  96851. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96852. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96853. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96854. void (*free_info) (vorbis_info_floor *);
  96855. void (*free_look) (vorbis_look_floor *);
  96856. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96857. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96858. void *buffer,float *);
  96859. } vorbis_func_floor;
  96860. typedef struct{
  96861. int order;
  96862. long rate;
  96863. long barkmap;
  96864. int ampbits;
  96865. int ampdB;
  96866. int numbooks; /* <= 16 */
  96867. int books[16];
  96868. float lessthan; /* encode-only config setting hacks for libvorbis */
  96869. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96870. } vorbis_info_floor0;
  96871. #define VIF_POSIT 63
  96872. #define VIF_CLASS 16
  96873. #define VIF_PARTS 31
  96874. typedef struct{
  96875. int partitions; /* 0 to 31 */
  96876. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96877. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96878. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96879. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96880. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96881. int mult; /* 1 2 3 or 4 */
  96882. int postlist[VIF_POSIT+2]; /* first two implicit */
  96883. float maxover;
  96884. float maxunder;
  96885. float maxerr;
  96886. float twofitweight;
  96887. float twofitatten;
  96888. int n;
  96889. } vorbis_info_floor1;
  96890. typedef struct{
  96891. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96892. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96893. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96894. vorbis_info_residue *);
  96895. void (*free_info) (vorbis_info_residue *);
  96896. void (*free_look) (vorbis_look_residue *);
  96897. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96898. float **,int *,int);
  96899. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96900. vorbis_look_residue *,
  96901. float **,float **,int *,int,long **);
  96902. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96903. float **,int *,int);
  96904. } vorbis_func_residue;
  96905. typedef struct vorbis_info_residue0{
  96906. long begin;
  96907. long end;
  96908. int grouping; /* group n vectors per partition */
  96909. int partitions; /* possible codebooks for a partition */
  96910. int groupbook; /* huffbook for partitioning */
  96911. int secondstages[64]; /* expanded out to pointers in lookup */
  96912. int booklist[256]; /* list of second stage books */
  96913. float classmetric1[64];
  96914. float classmetric2[64];
  96915. } vorbis_info_residue0;
  96916. typedef struct{
  96917. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  96918. oggpack_buffer *);
  96919. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  96920. void (*free_info) (vorbis_info_mapping *);
  96921. int (*forward) (struct vorbis_block *vb);
  96922. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  96923. } vorbis_func_mapping;
  96924. typedef struct vorbis_info_mapping0{
  96925. int submaps; /* <= 16 */
  96926. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  96927. int floorsubmap[16]; /* [mux] submap to floors */
  96928. int residuesubmap[16]; /* [mux] submap to residue */
  96929. int coupling_steps;
  96930. int coupling_mag[256];
  96931. int coupling_ang[256];
  96932. } vorbis_info_mapping0;
  96933. #endif
  96934. /*** End of inlined file: backends.h ***/
  96935. #ifndef EHMER_MAX
  96936. #define EHMER_MAX 56
  96937. #endif
  96938. #define P_BANDS 17 /* 62Hz to 16kHz */
  96939. #define P_LEVELS 8 /* 30dB to 100dB */
  96940. #define P_LEVEL_0 30. /* 30 dB */
  96941. #define P_NOISECURVES 3
  96942. #define NOISE_COMPAND_LEVELS 40
  96943. typedef struct vorbis_info_psy{
  96944. int blockflag;
  96945. float ath_adjatt;
  96946. float ath_maxatt;
  96947. float tone_masteratt[P_NOISECURVES];
  96948. float tone_centerboost;
  96949. float tone_decay;
  96950. float tone_abs_limit;
  96951. float toneatt[P_BANDS];
  96952. int noisemaskp;
  96953. float noisemaxsupp;
  96954. float noisewindowlo;
  96955. float noisewindowhi;
  96956. int noisewindowlomin;
  96957. int noisewindowhimin;
  96958. int noisewindowfixed;
  96959. float noiseoff[P_NOISECURVES][P_BANDS];
  96960. float noisecompand[NOISE_COMPAND_LEVELS];
  96961. float max_curve_dB;
  96962. int normal_channel_p;
  96963. int normal_point_p;
  96964. int normal_start;
  96965. int normal_partition;
  96966. double normal_thresh;
  96967. } vorbis_info_psy;
  96968. typedef struct{
  96969. int eighth_octave_lines;
  96970. float preecho_thresh[VE_BANDS];
  96971. float postecho_thresh[VE_BANDS];
  96972. float stretch_penalty;
  96973. float preecho_minenergy;
  96974. float ampmax_att_per_sec;
  96975. int coupling_pkHz[PACKETBLOBS];
  96976. int coupling_pointlimit[2][PACKETBLOBS];
  96977. int coupling_prepointamp[PACKETBLOBS];
  96978. int coupling_postpointamp[PACKETBLOBS];
  96979. int sliding_lowpass[2][PACKETBLOBS];
  96980. } vorbis_info_psy_global;
  96981. typedef struct {
  96982. float ampmax;
  96983. int channels;
  96984. vorbis_info_psy_global *gi;
  96985. int coupling_pointlimit[2][P_NOISECURVES];
  96986. } vorbis_look_psy_global;
  96987. typedef struct {
  96988. int n;
  96989. struct vorbis_info_psy *vi;
  96990. float ***tonecurves;
  96991. float **noiseoffset;
  96992. float *ath;
  96993. long *octave; /* in n.ocshift format */
  96994. long *bark;
  96995. long firstoc;
  96996. long shiftoc;
  96997. int eighth_octave_lines; /* power of two, please */
  96998. int total_octave_lines;
  96999. long rate; /* cache it */
  97000. float m_val; /* Masking compensation value */
  97001. } vorbis_look_psy;
  97002. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97003. vorbis_info_psy_global *gi,int n,long rate);
  97004. extern void _vp_psy_clear(vorbis_look_psy *p);
  97005. extern void *_vi_psy_dup(void *source);
  97006. extern void _vi_psy_free(vorbis_info_psy *i);
  97007. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97008. extern void _vp_remove_floor(vorbis_look_psy *p,
  97009. float *mdct,
  97010. int *icodedflr,
  97011. float *residue,
  97012. int sliding_lowpass);
  97013. extern void _vp_noisemask(vorbis_look_psy *p,
  97014. float *logmdct,
  97015. float *logmask);
  97016. extern void _vp_tonemask(vorbis_look_psy *p,
  97017. float *logfft,
  97018. float *logmask,
  97019. float global_specmax,
  97020. float local_specmax);
  97021. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97022. float *noise,
  97023. float *tone,
  97024. int offset_select,
  97025. float *logmask,
  97026. float *mdct,
  97027. float *logmdct);
  97028. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97029. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97030. vorbis_info_psy_global *g,
  97031. vorbis_look_psy *p,
  97032. vorbis_info_mapping0 *vi,
  97033. float **mdct);
  97034. extern void _vp_couple(int blobno,
  97035. vorbis_info_psy_global *g,
  97036. vorbis_look_psy *p,
  97037. vorbis_info_mapping0 *vi,
  97038. float **res,
  97039. float **mag_memo,
  97040. int **mag_sort,
  97041. int **ifloor,
  97042. int *nonzero,
  97043. int sliding_lowpass);
  97044. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97045. float *in,float *out,int *sortedindex);
  97046. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97047. float *magnitudes,int *sortedindex);
  97048. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97049. vorbis_look_psy *p,
  97050. vorbis_info_mapping0 *vi,
  97051. float **mags);
  97052. extern void hf_reduction(vorbis_info_psy_global *g,
  97053. vorbis_look_psy *p,
  97054. vorbis_info_mapping0 *vi,
  97055. float **mdct);
  97056. #endif
  97057. /*** End of inlined file: psy.h ***/
  97058. /*** Start of inlined file: bitrate.h ***/
  97059. #ifndef _V_BITRATE_H_
  97060. #define _V_BITRATE_H_
  97061. /*** Start of inlined file: os.h ***/
  97062. #ifndef _OS_H
  97063. #define _OS_H
  97064. #ifdef HAVE_CONFIG_H
  97065. #include "config.h"
  97066. #endif
  97067. #include <math.h>
  97068. /*** Start of inlined file: misc.h ***/
  97069. #ifndef _V_RANDOM_H_
  97070. #define _V_RANDOM_H_
  97071. extern int analysis_noisy;
  97072. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97073. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97074. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97075. ogg_int64_t off);
  97076. #ifdef DEBUG_MALLOC
  97077. #define _VDBG_GRAPHFILE "malloc.m"
  97078. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97079. extern void _VDBG_free(void *ptr,char *file,long line);
  97080. #ifndef MISC_C
  97081. #undef _ogg_malloc
  97082. #undef _ogg_calloc
  97083. #undef _ogg_realloc
  97084. #undef _ogg_free
  97085. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97086. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97087. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97088. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97089. #endif
  97090. #endif
  97091. #endif
  97092. /*** End of inlined file: misc.h ***/
  97093. #ifndef _V_IFDEFJAIL_H_
  97094. # define _V_IFDEFJAIL_H_
  97095. # ifdef __GNUC__
  97096. # define STIN static __inline__
  97097. # elif _WIN32
  97098. # define STIN static __inline
  97099. # else
  97100. # define STIN static
  97101. # endif
  97102. #ifdef DJGPP
  97103. # define rint(x) (floor((x)+0.5f))
  97104. #endif
  97105. #ifndef M_PI
  97106. # define M_PI (3.1415926536f)
  97107. #endif
  97108. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97109. # include <malloc.h>
  97110. # define rint(x) (floor((x)+0.5f))
  97111. # define NO_FLOAT_MATH_LIB
  97112. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97113. #endif
  97114. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97115. void *_alloca(size_t size);
  97116. # define alloca _alloca
  97117. #endif
  97118. #ifndef FAST_HYPOT
  97119. # define FAST_HYPOT hypot
  97120. #endif
  97121. #endif
  97122. #ifdef HAVE_ALLOCA_H
  97123. # include <alloca.h>
  97124. #endif
  97125. #ifdef USE_MEMORY_H
  97126. # include <memory.h>
  97127. #endif
  97128. #ifndef min
  97129. # define min(x,y) ((x)>(y)?(y):(x))
  97130. #endif
  97131. #ifndef max
  97132. # define max(x,y) ((x)<(y)?(y):(x))
  97133. #endif
  97134. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97135. # define VORBIS_FPU_CONTROL
  97136. typedef ogg_int16_t vorbis_fpu_control;
  97137. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97138. ogg_int16_t ret;
  97139. ogg_int16_t temp;
  97140. __asm__ __volatile__("fnstcw %0\n\t"
  97141. "movw %0,%%dx\n\t"
  97142. "orw $62463,%%dx\n\t"
  97143. "movw %%dx,%1\n\t"
  97144. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97145. *fpu=ret;
  97146. }
  97147. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97148. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97149. }
  97150. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97151. we get extra fst/fld to
  97152. truncate precision */
  97153. int i;
  97154. __asm__("fistl %0": "=m"(i) : "t"(f));
  97155. return(i);
  97156. }
  97157. #endif
  97158. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97159. # define VORBIS_FPU_CONTROL
  97160. typedef ogg_int16_t vorbis_fpu_control;
  97161. static __inline int vorbis_ftoi(double f){
  97162. int i;
  97163. __asm{
  97164. fld f
  97165. fistp i
  97166. }
  97167. return i;
  97168. }
  97169. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97170. }
  97171. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97172. }
  97173. #endif
  97174. #ifndef VORBIS_FPU_CONTROL
  97175. typedef int vorbis_fpu_control;
  97176. static int vorbis_ftoi(double f){
  97177. return (int)(f+.5);
  97178. }
  97179. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97180. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97181. #endif
  97182. #endif /* _OS_H */
  97183. /*** End of inlined file: os.h ***/
  97184. typedef struct bitrate_manager_state {
  97185. int managed;
  97186. long avg_reservoir;
  97187. long minmax_reservoir;
  97188. long avg_bitsper;
  97189. long min_bitsper;
  97190. long max_bitsper;
  97191. long short_per_long;
  97192. double avgfloat;
  97193. vorbis_block *vb;
  97194. int choice;
  97195. } bitrate_manager_state;
  97196. typedef struct bitrate_manager_info{
  97197. long avg_rate;
  97198. long min_rate;
  97199. long max_rate;
  97200. long reservoir_bits;
  97201. double reservoir_bias;
  97202. double slew_damp;
  97203. } bitrate_manager_info;
  97204. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97205. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97206. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97207. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97208. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97209. #endif
  97210. /*** End of inlined file: bitrate.h ***/
  97211. static int ilog(unsigned int v){
  97212. int ret=0;
  97213. while(v){
  97214. ret++;
  97215. v>>=1;
  97216. }
  97217. return(ret);
  97218. }
  97219. static int ilog2(unsigned int v){
  97220. int ret=0;
  97221. if(v)--v;
  97222. while(v){
  97223. ret++;
  97224. v>>=1;
  97225. }
  97226. return(ret);
  97227. }
  97228. typedef struct private_state {
  97229. envelope_lookup *ve; /* envelope lookup */
  97230. int window[2];
  97231. vorbis_look_transform **transform[2]; /* block, type */
  97232. drft_lookup fft_look[2];
  97233. int modebits;
  97234. vorbis_look_floor **flr;
  97235. vorbis_look_residue **residue;
  97236. vorbis_look_psy *psy;
  97237. vorbis_look_psy_global *psy_g_look;
  97238. unsigned char *header;
  97239. unsigned char *header1;
  97240. unsigned char *header2;
  97241. bitrate_manager_state bms;
  97242. ogg_int64_t sample_count;
  97243. } private_state;
  97244. /*** Start of inlined file: highlevel.h ***/
  97245. typedef struct highlevel_byblocktype {
  97246. double tone_mask_setting;
  97247. double tone_peaklimit_setting;
  97248. double noise_bias_setting;
  97249. double noise_compand_setting;
  97250. } highlevel_byblocktype;
  97251. typedef struct highlevel_encode_setup {
  97252. void *setup;
  97253. int set_in_stone;
  97254. double base_setting;
  97255. double long_setting;
  97256. double short_setting;
  97257. double impulse_noisetune;
  97258. int managed;
  97259. long bitrate_min;
  97260. long bitrate_av;
  97261. double bitrate_av_damp;
  97262. long bitrate_max;
  97263. long bitrate_reservoir;
  97264. double bitrate_reservoir_bias;
  97265. int impulse_block_p;
  97266. int noise_normalize_p;
  97267. double stereo_point_setting;
  97268. double lowpass_kHz;
  97269. double ath_floating_dB;
  97270. double ath_absolute_dB;
  97271. double amplitude_track_dBpersec;
  97272. double trigger_setting;
  97273. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97274. } highlevel_encode_setup;
  97275. /*** End of inlined file: highlevel.h ***/
  97276. typedef struct codec_setup_info {
  97277. long blocksizes[2];
  97278. int modes;
  97279. int maps;
  97280. int floors;
  97281. int residues;
  97282. int books;
  97283. int psys; /* encode only */
  97284. vorbis_info_mode *mode_param[64];
  97285. int map_type[64];
  97286. vorbis_info_mapping *map_param[64];
  97287. int floor_type[64];
  97288. vorbis_info_floor *floor_param[64];
  97289. int residue_type[64];
  97290. vorbis_info_residue *residue_param[64];
  97291. static_codebook *book_param[256];
  97292. codebook *fullbooks;
  97293. vorbis_info_psy *psy_param[4]; /* encode only */
  97294. vorbis_info_psy_global psy_g_param;
  97295. bitrate_manager_info bi;
  97296. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97297. highly redundant structure, but
  97298. improves clarity of program flow. */
  97299. int halfrate_flag; /* painless downsample for decode */
  97300. } codec_setup_info;
  97301. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97302. extern void _vp_global_free(vorbis_look_psy_global *look);
  97303. #endif
  97304. /*** End of inlined file: codec_internal.h ***/
  97305. /*** Start of inlined file: registry.h ***/
  97306. #ifndef _V_REG_H_
  97307. #define _V_REG_H_
  97308. #define VI_TRANSFORMB 1
  97309. #define VI_WINDOWB 1
  97310. #define VI_TIMEB 1
  97311. #define VI_FLOORB 2
  97312. #define VI_RESB 3
  97313. #define VI_MAPB 1
  97314. extern vorbis_func_floor *_floor_P[];
  97315. extern vorbis_func_residue *_residue_P[];
  97316. extern vorbis_func_mapping *_mapping_P[];
  97317. #endif
  97318. /*** End of inlined file: registry.h ***/
  97319. /*** Start of inlined file: scales.h ***/
  97320. #ifndef _V_SCALES_H_
  97321. #define _V_SCALES_H_
  97322. #include <math.h>
  97323. #define VORBIS_IEEE_FLOAT32 1
  97324. #ifdef VORBIS_IEEE_FLOAT32
  97325. static float unitnorm(float x){
  97326. union {
  97327. ogg_uint32_t i;
  97328. float f;
  97329. } ix;
  97330. ix.f = x;
  97331. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97332. return ix.f;
  97333. }
  97334. static float todB(const float *x){
  97335. union {
  97336. ogg_uint32_t i;
  97337. float f;
  97338. } ix;
  97339. ix.f = *x;
  97340. ix.i = ix.i&0x7fffffff;
  97341. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97342. }
  97343. #define todB_nn(x) todB(x)
  97344. #else
  97345. static float unitnorm(float x){
  97346. if(x<0)return(-1.f);
  97347. return(1.f);
  97348. }
  97349. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97350. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97351. #endif
  97352. #define fromdB(x) (exp((x)*.11512925f))
  97353. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97354. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97355. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97356. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97357. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97358. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97359. #endif
  97360. /*** End of inlined file: scales.h ***/
  97361. int analysis_noisy=1;
  97362. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97363. int ret,i;
  97364. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97365. vb->glue_bits=0;
  97366. vb->time_bits=0;
  97367. vb->floor_bits=0;
  97368. vb->res_bits=0;
  97369. for(i=0;i<PACKETBLOBS;i++)
  97370. oggpack_reset(vbi->packetblob[i]);
  97371. if((ret=_mapping_P[0]->forward(vb)))
  97372. return(ret);
  97373. if(op){
  97374. if(vorbis_bitrate_managed(vb))
  97375. return(OV_EINVAL);
  97376. op->packet=oggpack_get_buffer(&vb->opb);
  97377. op->bytes=oggpack_bytes(&vb->opb);
  97378. op->b_o_s=0;
  97379. op->e_o_s=vb->eofflag;
  97380. op->granulepos=vb->granulepos;
  97381. op->packetno=vb->sequence; /* for sake of completeness */
  97382. }
  97383. return(0);
  97384. }
  97385. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97386. int j;
  97387. FILE *of;
  97388. char buffer[80];
  97389. sprintf(buffer,"%s_%d.m",base,i);
  97390. of=fopen(buffer,"w");
  97391. if(!of)perror("failed to open data dump file");
  97392. for(j=0;j<n;j++){
  97393. if(bark){
  97394. float b=toBARK((4000.f*j/n)+.25);
  97395. fprintf(of,"%f ",b);
  97396. }else
  97397. if(off!=0)
  97398. fprintf(of,"%f ",(double)(j+off)/8000.);
  97399. else
  97400. fprintf(of,"%f ",(double)j);
  97401. if(dB){
  97402. float val;
  97403. if(v[j]==0.)
  97404. val=-140.;
  97405. else
  97406. val=todB(v+j);
  97407. fprintf(of,"%f\n",val);
  97408. }else{
  97409. fprintf(of,"%f\n",v[j]);
  97410. }
  97411. }
  97412. fclose(of);
  97413. }
  97414. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97415. ogg_int64_t off){
  97416. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97417. }
  97418. #endif
  97419. /*** End of inlined file: analysis.c ***/
  97420. /*** Start of inlined file: bitrate.c ***/
  97421. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97422. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97423. // tasks..
  97424. #if JUCE_MSVC
  97425. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97426. #endif
  97427. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97428. #if JUCE_USE_OGGVORBIS
  97429. #include <stdlib.h>
  97430. #include <string.h>
  97431. #include <math.h>
  97432. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97433. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97434. bitrate_manager_info *bi=&ci->bi;
  97435. memset(bm,0,sizeof(*bm));
  97436. if(bi && (bi->reservoir_bits>0)){
  97437. long ratesamples=vi->rate;
  97438. int halfsamples=ci->blocksizes[0]>>1;
  97439. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97440. bm->managed=1;
  97441. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97442. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97443. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97444. bm->avgfloat=PACKETBLOBS/2;
  97445. {
  97446. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97447. bm->minmax_reservoir=desired_fill;
  97448. bm->avg_reservoir=desired_fill;
  97449. }
  97450. }
  97451. }
  97452. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97453. memset(bm,0,sizeof(*bm));
  97454. return;
  97455. }
  97456. int vorbis_bitrate_managed(vorbis_block *vb){
  97457. vorbis_dsp_state *vd=vb->vd;
  97458. private_state *b=(private_state*)vd->backend_state;
  97459. bitrate_manager_state *bm=&b->bms;
  97460. if(bm && bm->managed)return(1);
  97461. return(0);
  97462. }
  97463. int vorbis_bitrate_addblock(vorbis_block *vb){
  97464. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97465. vorbis_dsp_state *vd=vb->vd;
  97466. private_state *b=(private_state*)vd->backend_state;
  97467. bitrate_manager_state *bm=&b->bms;
  97468. vorbis_info *vi=vd->vi;
  97469. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97470. bitrate_manager_info *bi=&ci->bi;
  97471. int choice=rint(bm->avgfloat);
  97472. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97473. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97474. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97475. int samples=ci->blocksizes[vb->W]>>1;
  97476. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97477. if(!bm->managed){
  97478. if(bm->vb)return(-1); /* one has been submitted without
  97479. being claimed */
  97480. bm->vb=vb;
  97481. return(0);
  97482. }
  97483. bm->vb=vb;
  97484. if(bm->avg_bitsper>0){
  97485. double slew=0.;
  97486. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97487. double slewlimit= 15./bi->slew_damp;
  97488. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97489. while(choice>0 && this_bits>avg_target_bits &&
  97490. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97491. choice--;
  97492. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97493. }
  97494. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97495. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97496. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97497. choice++;
  97498. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97499. }
  97500. }
  97501. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97502. if(slew<-slewlimit)slew=-slewlimit;
  97503. if(slew>slewlimit)slew=slewlimit;
  97504. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97505. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97506. }
  97507. if(bm->min_bitsper>0){
  97508. if(this_bits<min_target_bits){
  97509. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97510. choice++;
  97511. if(choice>=PACKETBLOBS)break;
  97512. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97513. }
  97514. }
  97515. }
  97516. if(bm->max_bitsper>0){
  97517. if(this_bits>max_target_bits){
  97518. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97519. choice--;
  97520. if(choice<0)break;
  97521. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97522. }
  97523. }
  97524. }
  97525. if(choice<0){
  97526. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97527. bm->choice=choice=0;
  97528. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97529. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97530. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97531. }
  97532. }else{
  97533. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97534. if(choice>=PACKETBLOBS)
  97535. choice=PACKETBLOBS-1;
  97536. bm->choice=choice;
  97537. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97538. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97539. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97540. }
  97541. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97542. if(max_target_bits>0 && this_bits>max_target_bits){
  97543. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97544. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97545. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97546. }else{
  97547. if(bm->minmax_reservoir>desired_fill){
  97548. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97549. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97550. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97551. }else{
  97552. bm->minmax_reservoir=desired_fill;
  97553. }
  97554. }else{
  97555. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97556. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97557. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97558. }else{
  97559. bm->minmax_reservoir=desired_fill;
  97560. }
  97561. }
  97562. }
  97563. }
  97564. if(bm->avg_bitsper>0){
  97565. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97566. bm->avg_reservoir+=this_bits-avg_target_bits;
  97567. }
  97568. return(0);
  97569. }
  97570. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97571. private_state *b=(private_state*)vd->backend_state;
  97572. bitrate_manager_state *bm=&b->bms;
  97573. vorbis_block *vb=bm->vb;
  97574. int choice=PACKETBLOBS/2;
  97575. if(!vb)return 0;
  97576. if(op){
  97577. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97578. if(vorbis_bitrate_managed(vb))
  97579. choice=bm->choice;
  97580. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97581. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97582. op->b_o_s=0;
  97583. op->e_o_s=vb->eofflag;
  97584. op->granulepos=vb->granulepos;
  97585. op->packetno=vb->sequence; /* for sake of completeness */
  97586. }
  97587. bm->vb=0;
  97588. return(1);
  97589. }
  97590. #endif
  97591. /*** End of inlined file: bitrate.c ***/
  97592. /*** Start of inlined file: block.c ***/
  97593. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97594. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97595. // tasks..
  97596. #if JUCE_MSVC
  97597. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97598. #endif
  97599. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97600. #if JUCE_USE_OGGVORBIS
  97601. #include <stdio.h>
  97602. #include <stdlib.h>
  97603. #include <string.h>
  97604. /*** Start of inlined file: window.h ***/
  97605. #ifndef _V_WINDOW_
  97606. #define _V_WINDOW_
  97607. extern float *_vorbis_window_get(int n);
  97608. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97609. int lW,int W,int nW);
  97610. #endif
  97611. /*** End of inlined file: window.h ***/
  97612. /*** Start of inlined file: lpc.h ***/
  97613. #ifndef _V_LPC_H_
  97614. #define _V_LPC_H_
  97615. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97616. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97617. float *data,long n);
  97618. #endif
  97619. /*** End of inlined file: lpc.h ***/
  97620. #ifndef WORD_ALIGN
  97621. #define WORD_ALIGN 8
  97622. #endif
  97623. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97624. int i;
  97625. memset(vb,0,sizeof(*vb));
  97626. vb->vd=v;
  97627. vb->localalloc=0;
  97628. vb->localstore=NULL;
  97629. if(v->analysisp){
  97630. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97631. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97632. vbi->ampmax=-9999;
  97633. for(i=0;i<PACKETBLOBS;i++){
  97634. if(i==PACKETBLOBS/2){
  97635. vbi->packetblob[i]=&vb->opb;
  97636. }else{
  97637. vbi->packetblob[i]=
  97638. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97639. }
  97640. oggpack_writeinit(vbi->packetblob[i]);
  97641. }
  97642. }
  97643. return(0);
  97644. }
  97645. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97646. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97647. if(bytes+vb->localtop>vb->localalloc){
  97648. if(vb->localstore){
  97649. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97650. vb->totaluse+=vb->localtop;
  97651. link->next=vb->reap;
  97652. link->ptr=vb->localstore;
  97653. vb->reap=link;
  97654. }
  97655. vb->localalloc=bytes;
  97656. vb->localstore=_ogg_malloc(vb->localalloc);
  97657. vb->localtop=0;
  97658. }
  97659. {
  97660. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97661. vb->localtop+=bytes;
  97662. return ret;
  97663. }
  97664. }
  97665. void _vorbis_block_ripcord(vorbis_block *vb){
  97666. struct alloc_chain *reap=vb->reap;
  97667. while(reap){
  97668. struct alloc_chain *next=reap->next;
  97669. _ogg_free(reap->ptr);
  97670. memset(reap,0,sizeof(*reap));
  97671. _ogg_free(reap);
  97672. reap=next;
  97673. }
  97674. if(vb->totaluse){
  97675. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97676. vb->localalloc+=vb->totaluse;
  97677. vb->totaluse=0;
  97678. }
  97679. vb->localtop=0;
  97680. vb->reap=NULL;
  97681. }
  97682. int vorbis_block_clear(vorbis_block *vb){
  97683. int i;
  97684. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97685. _vorbis_block_ripcord(vb);
  97686. if(vb->localstore)_ogg_free(vb->localstore);
  97687. if(vbi){
  97688. for(i=0;i<PACKETBLOBS;i++){
  97689. oggpack_writeclear(vbi->packetblob[i]);
  97690. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97691. }
  97692. _ogg_free(vbi);
  97693. }
  97694. memset(vb,0,sizeof(*vb));
  97695. return(0);
  97696. }
  97697. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97698. int i;
  97699. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97700. private_state *b=NULL;
  97701. int hs;
  97702. if(ci==NULL) return 1;
  97703. hs=ci->halfrate_flag;
  97704. memset(v,0,sizeof(*v));
  97705. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97706. v->vi=vi;
  97707. b->modebits=ilog2(ci->modes);
  97708. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97709. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97710. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97711. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97712. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97713. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97714. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97715. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97716. if(encp){ /* encode/decode differ here */
  97717. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97718. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97719. if(!ci->fullbooks){
  97720. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97721. for(i=0;i<ci->books;i++)
  97722. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97723. }
  97724. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97725. for(i=0;i<ci->psys;i++){
  97726. _vp_psy_init(b->psy+i,
  97727. ci->psy_param[i],
  97728. &ci->psy_g_param,
  97729. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97730. vi->rate);
  97731. }
  97732. v->analysisp=1;
  97733. }else{
  97734. if(!ci->fullbooks){
  97735. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97736. for(i=0;i<ci->books;i++){
  97737. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97738. vorbis_staticbook_destroy(ci->book_param[i]);
  97739. ci->book_param[i]=NULL;
  97740. }
  97741. }
  97742. }
  97743. v->pcm_storage=ci->blocksizes[1];
  97744. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97745. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97746. {
  97747. int i;
  97748. for(i=0;i<vi->channels;i++)
  97749. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97750. }
  97751. v->lW=0; /* previous window size */
  97752. v->W=0; /* current window size */
  97753. v->centerW=ci->blocksizes[1]/2;
  97754. v->pcm_current=v->centerW;
  97755. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97756. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97757. for(i=0;i<ci->floors;i++)
  97758. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97759. look(v,ci->floor_param[i]);
  97760. for(i=0;i<ci->residues;i++)
  97761. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97762. look(v,ci->residue_param[i]);
  97763. return 0;
  97764. }
  97765. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97766. private_state *b=NULL;
  97767. if(_vds_shared_init(v,vi,1))return 1;
  97768. b=(private_state*)v->backend_state;
  97769. b->psy_g_look=_vp_global_look(vi);
  97770. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97771. _ve_envelope_init(b->ve,vi);
  97772. vorbis_bitrate_init(vi,&b->bms);
  97773. v->sequence=3;
  97774. return(0);
  97775. }
  97776. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97777. int i;
  97778. if(v){
  97779. vorbis_info *vi=v->vi;
  97780. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97781. private_state *b=(private_state*)v->backend_state;
  97782. if(b){
  97783. if(b->ve){
  97784. _ve_envelope_clear(b->ve);
  97785. _ogg_free(b->ve);
  97786. }
  97787. if(b->transform[0]){
  97788. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97789. _ogg_free(b->transform[0][0]);
  97790. _ogg_free(b->transform[0]);
  97791. }
  97792. if(b->transform[1]){
  97793. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97794. _ogg_free(b->transform[1][0]);
  97795. _ogg_free(b->transform[1]);
  97796. }
  97797. if(b->flr){
  97798. for(i=0;i<ci->floors;i++)
  97799. _floor_P[ci->floor_type[i]]->
  97800. free_look(b->flr[i]);
  97801. _ogg_free(b->flr);
  97802. }
  97803. if(b->residue){
  97804. for(i=0;i<ci->residues;i++)
  97805. _residue_P[ci->residue_type[i]]->
  97806. free_look(b->residue[i]);
  97807. _ogg_free(b->residue);
  97808. }
  97809. if(b->psy){
  97810. for(i=0;i<ci->psys;i++)
  97811. _vp_psy_clear(b->psy+i);
  97812. _ogg_free(b->psy);
  97813. }
  97814. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97815. vorbis_bitrate_clear(&b->bms);
  97816. drft_clear(&b->fft_look[0]);
  97817. drft_clear(&b->fft_look[1]);
  97818. }
  97819. if(v->pcm){
  97820. for(i=0;i<vi->channels;i++)
  97821. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97822. _ogg_free(v->pcm);
  97823. if(v->pcmret)_ogg_free(v->pcmret);
  97824. }
  97825. if(b){
  97826. if(b->header)_ogg_free(b->header);
  97827. if(b->header1)_ogg_free(b->header1);
  97828. if(b->header2)_ogg_free(b->header2);
  97829. _ogg_free(b);
  97830. }
  97831. memset(v,0,sizeof(*v));
  97832. }
  97833. }
  97834. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97835. int i;
  97836. vorbis_info *vi=v->vi;
  97837. private_state *b=(private_state*)v->backend_state;
  97838. if(b->header)_ogg_free(b->header);b->header=NULL;
  97839. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97840. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97841. if(v->pcm_current+vals>=v->pcm_storage){
  97842. v->pcm_storage=v->pcm_current+vals*2;
  97843. for(i=0;i<vi->channels;i++){
  97844. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97845. }
  97846. }
  97847. for(i=0;i<vi->channels;i++)
  97848. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97849. return(v->pcmret);
  97850. }
  97851. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97852. int i;
  97853. int order=32;
  97854. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97855. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97856. long j;
  97857. v->preextrapolate=1;
  97858. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97859. for(i=0;i<v->vi->channels;i++){
  97860. for(j=0;j<v->pcm_current;j++)
  97861. work[j]=v->pcm[i][v->pcm_current-j-1];
  97862. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97863. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97864. order,
  97865. work+v->pcm_current-v->centerW,
  97866. v->centerW);
  97867. for(j=0;j<v->pcm_current;j++)
  97868. v->pcm[i][v->pcm_current-j-1]=work[j];
  97869. }
  97870. }
  97871. }
  97872. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97873. vorbis_info *vi=v->vi;
  97874. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97875. if(vals<=0){
  97876. int order=32;
  97877. int i;
  97878. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97879. if(!v->preextrapolate)
  97880. _preextrapolate_helper(v);
  97881. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97882. v->eofflag=v->pcm_current;
  97883. v->pcm_current+=ci->blocksizes[1]*3;
  97884. for(i=0;i<vi->channels;i++){
  97885. if(v->eofflag>order*2){
  97886. long n;
  97887. n=v->eofflag;
  97888. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97889. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97890. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97891. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97892. }else{
  97893. memset(v->pcm[i]+v->eofflag,0,
  97894. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97895. }
  97896. }
  97897. }else{
  97898. if(v->pcm_current+vals>v->pcm_storage)
  97899. return(OV_EINVAL);
  97900. v->pcm_current+=vals;
  97901. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97902. _preextrapolate_helper(v);
  97903. }
  97904. return(0);
  97905. }
  97906. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  97907. int i;
  97908. vorbis_info *vi=v->vi;
  97909. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97910. private_state *b=(private_state*)v->backend_state;
  97911. vorbis_look_psy_global *g=b->psy_g_look;
  97912. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  97913. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97914. if(!v->preextrapolate)return(0);
  97915. if(v->eofflag==-1)return(0);
  97916. {
  97917. long bp=_ve_envelope_search(v);
  97918. if(bp==-1){
  97919. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  97920. full long block */
  97921. v->nW=0;
  97922. }else{
  97923. if(ci->blocksizes[0]==ci->blocksizes[1])
  97924. v->nW=0;
  97925. else
  97926. v->nW=bp;
  97927. }
  97928. }
  97929. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  97930. {
  97931. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  97932. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  97933. although this check is
  97934. less strict that the
  97935. _ve_envelope_search,
  97936. the search is not run
  97937. if we only use one
  97938. block size */
  97939. }
  97940. _vorbis_block_ripcord(vb);
  97941. vb->lW=v->lW;
  97942. vb->W=v->W;
  97943. vb->nW=v->nW;
  97944. if(v->W){
  97945. if(!v->lW || !v->nW){
  97946. vbi->blocktype=BLOCKTYPE_TRANSITION;
  97947. }else{
  97948. vbi->blocktype=BLOCKTYPE_LONG;
  97949. }
  97950. }else{
  97951. if(_ve_envelope_mark(v)){
  97952. vbi->blocktype=BLOCKTYPE_IMPULSE;
  97953. }else{
  97954. vbi->blocktype=BLOCKTYPE_PADDING;
  97955. }
  97956. }
  97957. vb->vd=v;
  97958. vb->sequence=v->sequence++;
  97959. vb->granulepos=v->granulepos;
  97960. vb->pcmend=ci->blocksizes[v->W];
  97961. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  97962. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  97963. vbi->ampmax=g->ampmax;
  97964. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  97965. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  97966. for(i=0;i<vi->channels;i++){
  97967. vbi->pcmdelay[i]=
  97968. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97969. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97970. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  97971. }
  97972. if(v->eofflag){
  97973. if(v->centerW>=v->eofflag){
  97974. v->eofflag=-1;
  97975. vb->eofflag=1;
  97976. return(1);
  97977. }
  97978. }
  97979. {
  97980. int new_centerNext=ci->blocksizes[1]/2;
  97981. int movementW=centerNext-new_centerNext;
  97982. if(movementW>0){
  97983. _ve_envelope_shift(b->ve,movementW);
  97984. v->pcm_current-=movementW;
  97985. for(i=0;i<vi->channels;i++)
  97986. memmove(v->pcm[i],v->pcm[i]+movementW,
  97987. v->pcm_current*sizeof(*v->pcm[i]));
  97988. v->lW=v->W;
  97989. v->W=v->nW;
  97990. v->centerW=new_centerNext;
  97991. if(v->eofflag){
  97992. v->eofflag-=movementW;
  97993. if(v->eofflag<=0)v->eofflag=-1;
  97994. if(v->centerW>=v->eofflag){
  97995. v->granulepos+=movementW-(v->centerW-v->eofflag);
  97996. }else{
  97997. v->granulepos+=movementW;
  97998. }
  97999. }else{
  98000. v->granulepos+=movementW;
  98001. }
  98002. }
  98003. }
  98004. return(1);
  98005. }
  98006. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98007. vorbis_info *vi=v->vi;
  98008. codec_setup_info *ci;
  98009. int hs;
  98010. if(!v->backend_state)return -1;
  98011. if(!vi)return -1;
  98012. ci=(codec_setup_info*) vi->codec_setup;
  98013. if(!ci)return -1;
  98014. hs=ci->halfrate_flag;
  98015. v->centerW=ci->blocksizes[1]>>(hs+1);
  98016. v->pcm_current=v->centerW>>hs;
  98017. v->pcm_returned=-1;
  98018. v->granulepos=-1;
  98019. v->sequence=-1;
  98020. v->eofflag=0;
  98021. ((private_state *)(v->backend_state))->sample_count=-1;
  98022. return(0);
  98023. }
  98024. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98025. if(_vds_shared_init(v,vi,0)) return 1;
  98026. vorbis_synthesis_restart(v);
  98027. return 0;
  98028. }
  98029. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98030. vorbis_info *vi=v->vi;
  98031. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98032. private_state *b=(private_state*)v->backend_state;
  98033. int hs=ci->halfrate_flag;
  98034. int i,j;
  98035. if(!vb)return(OV_EINVAL);
  98036. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98037. v->lW=v->W;
  98038. v->W=vb->W;
  98039. v->nW=-1;
  98040. if((v->sequence==-1)||
  98041. (v->sequence+1 != vb->sequence)){
  98042. v->granulepos=-1; /* out of sequence; lose count */
  98043. b->sample_count=-1;
  98044. }
  98045. v->sequence=vb->sequence;
  98046. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98047. was called on block */
  98048. int n=ci->blocksizes[v->W]>>(hs+1);
  98049. int n0=ci->blocksizes[0]>>(hs+1);
  98050. int n1=ci->blocksizes[1]>>(hs+1);
  98051. int thisCenter;
  98052. int prevCenter;
  98053. v->glue_bits+=vb->glue_bits;
  98054. v->time_bits+=vb->time_bits;
  98055. v->floor_bits+=vb->floor_bits;
  98056. v->res_bits+=vb->res_bits;
  98057. if(v->centerW){
  98058. thisCenter=n1;
  98059. prevCenter=0;
  98060. }else{
  98061. thisCenter=0;
  98062. prevCenter=n1;
  98063. }
  98064. for(j=0;j<vi->channels;j++){
  98065. if(v->lW){
  98066. if(v->W){
  98067. float *w=_vorbis_window_get(b->window[1]-hs);
  98068. float *pcm=v->pcm[j]+prevCenter;
  98069. float *p=vb->pcm[j];
  98070. for(i=0;i<n1;i++)
  98071. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98072. }else{
  98073. float *w=_vorbis_window_get(b->window[0]-hs);
  98074. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98075. float *p=vb->pcm[j];
  98076. for(i=0;i<n0;i++)
  98077. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98078. }
  98079. }else{
  98080. if(v->W){
  98081. float *w=_vorbis_window_get(b->window[0]-hs);
  98082. float *pcm=v->pcm[j]+prevCenter;
  98083. float *p=vb->pcm[j]+n1/2-n0/2;
  98084. for(i=0;i<n0;i++)
  98085. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98086. for(;i<n1/2+n0/2;i++)
  98087. pcm[i]=p[i];
  98088. }else{
  98089. float *w=_vorbis_window_get(b->window[0]-hs);
  98090. float *pcm=v->pcm[j]+prevCenter;
  98091. float *p=vb->pcm[j];
  98092. for(i=0;i<n0;i++)
  98093. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98094. }
  98095. }
  98096. {
  98097. float *pcm=v->pcm[j]+thisCenter;
  98098. float *p=vb->pcm[j]+n;
  98099. for(i=0;i<n;i++)
  98100. pcm[i]=p[i];
  98101. }
  98102. }
  98103. if(v->centerW)
  98104. v->centerW=0;
  98105. else
  98106. v->centerW=n1;
  98107. if(v->pcm_returned==-1){
  98108. v->pcm_returned=thisCenter;
  98109. v->pcm_current=thisCenter;
  98110. }else{
  98111. v->pcm_returned=prevCenter;
  98112. v->pcm_current=prevCenter+
  98113. ((ci->blocksizes[v->lW]/4+
  98114. ci->blocksizes[v->W]/4)>>hs);
  98115. }
  98116. }
  98117. if(b->sample_count==-1){
  98118. b->sample_count=0;
  98119. }else{
  98120. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98121. }
  98122. if(v->granulepos==-1){
  98123. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98124. v->granulepos=vb->granulepos;
  98125. if(b->sample_count>v->granulepos){
  98126. if(vb->eofflag){
  98127. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98128. }else{
  98129. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98130. if(v->pcm_returned>v->pcm_current)
  98131. v->pcm_returned=v->pcm_current;
  98132. }
  98133. }
  98134. }
  98135. }else{
  98136. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98137. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98138. if(v->granulepos>vb->granulepos){
  98139. long extra=v->granulepos-vb->granulepos;
  98140. if(extra)
  98141. if(vb->eofflag){
  98142. v->pcm_current-=extra>>hs;
  98143. } /* else {Shouldn't happen *unless* the bitstream is out of
  98144. spec. Either way, believe the bitstream } */
  98145. } /* else {Shouldn't happen *unless* the bitstream is out of
  98146. spec. Either way, believe the bitstream } */
  98147. v->granulepos=vb->granulepos;
  98148. }
  98149. }
  98150. if(vb->eofflag)v->eofflag=1;
  98151. return(0);
  98152. }
  98153. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98154. vorbis_info *vi=v->vi;
  98155. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98156. if(pcm){
  98157. int i;
  98158. for(i=0;i<vi->channels;i++)
  98159. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98160. *pcm=v->pcmret;
  98161. }
  98162. return(v->pcm_current-v->pcm_returned);
  98163. }
  98164. return(0);
  98165. }
  98166. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98167. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98168. v->pcm_returned+=n;
  98169. return(0);
  98170. }
  98171. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98172. vorbis_info *vi=v->vi;
  98173. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98174. int hs=ci->halfrate_flag;
  98175. int n=ci->blocksizes[v->W]>>(hs+1);
  98176. int n0=ci->blocksizes[0]>>(hs+1);
  98177. int n1=ci->blocksizes[1]>>(hs+1);
  98178. int i,j;
  98179. if(v->pcm_returned<0)return 0;
  98180. if(v->centerW==n1){
  98181. for(j=0;j<vi->channels;j++){
  98182. float *p=v->pcm[j];
  98183. for(i=0;i<n1;i++){
  98184. float temp=p[i];
  98185. p[i]=p[i+n1];
  98186. p[i+n1]=temp;
  98187. }
  98188. }
  98189. v->pcm_current-=n1;
  98190. v->pcm_returned-=n1;
  98191. v->centerW=0;
  98192. }
  98193. if((v->lW^v->W)==1){
  98194. for(j=0;j<vi->channels;j++){
  98195. float *s=v->pcm[j];
  98196. float *d=v->pcm[j]+(n1-n0)/2;
  98197. for(i=(n1+n0)/2-1;i>=0;--i)
  98198. d[i]=s[i];
  98199. }
  98200. v->pcm_returned+=(n1-n0)/2;
  98201. v->pcm_current+=(n1-n0)/2;
  98202. }else{
  98203. if(v->lW==0){
  98204. for(j=0;j<vi->channels;j++){
  98205. float *s=v->pcm[j];
  98206. float *d=v->pcm[j]+n1-n0;
  98207. for(i=n0-1;i>=0;--i)
  98208. d[i]=s[i];
  98209. }
  98210. v->pcm_returned+=n1-n0;
  98211. v->pcm_current+=n1-n0;
  98212. }
  98213. }
  98214. if(pcm){
  98215. int i;
  98216. for(i=0;i<vi->channels;i++)
  98217. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98218. *pcm=v->pcmret;
  98219. }
  98220. return(n1+n-v->pcm_returned);
  98221. }
  98222. float *vorbis_window(vorbis_dsp_state *v,int W){
  98223. vorbis_info *vi=v->vi;
  98224. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98225. int hs=ci->halfrate_flag;
  98226. private_state *b=(private_state*)v->backend_state;
  98227. if(b->window[W]-1<0)return NULL;
  98228. return _vorbis_window_get(b->window[W]-hs);
  98229. }
  98230. #endif
  98231. /*** End of inlined file: block.c ***/
  98232. /*** Start of inlined file: codebook.c ***/
  98233. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98234. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98235. // tasks..
  98236. #if JUCE_MSVC
  98237. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98238. #endif
  98239. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98240. #if JUCE_USE_OGGVORBIS
  98241. #include <stdlib.h>
  98242. #include <string.h>
  98243. #include <math.h>
  98244. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98245. long i,j;
  98246. int ordered=0;
  98247. oggpack_write(opb,0x564342,24);
  98248. oggpack_write(opb,c->dim,16);
  98249. oggpack_write(opb,c->entries,24);
  98250. for(i=1;i<c->entries;i++)
  98251. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98252. if(i==c->entries)ordered=1;
  98253. if(ordered){
  98254. long count=0;
  98255. oggpack_write(opb,1,1); /* ordered */
  98256. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98257. for(i=1;i<c->entries;i++){
  98258. long thisx=c->lengthlist[i];
  98259. long last=c->lengthlist[i-1];
  98260. if(thisx>last){
  98261. for(j=last;j<thisx;j++){
  98262. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98263. count=i;
  98264. }
  98265. }
  98266. }
  98267. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98268. }else{
  98269. oggpack_write(opb,0,1); /* unordered */
  98270. for(i=0;i<c->entries;i++)
  98271. if(c->lengthlist[i]==0)break;
  98272. if(i==c->entries){
  98273. oggpack_write(opb,0,1); /* no unused entries */
  98274. for(i=0;i<c->entries;i++)
  98275. oggpack_write(opb,c->lengthlist[i]-1,5);
  98276. }else{
  98277. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98278. for(i=0;i<c->entries;i++){
  98279. if(c->lengthlist[i]==0){
  98280. oggpack_write(opb,0,1);
  98281. }else{
  98282. oggpack_write(opb,1,1);
  98283. oggpack_write(opb,c->lengthlist[i]-1,5);
  98284. }
  98285. }
  98286. }
  98287. }
  98288. oggpack_write(opb,c->maptype,4);
  98289. switch(c->maptype){
  98290. case 0:
  98291. break;
  98292. case 1:case 2:
  98293. if(!c->quantlist){
  98294. return(-1);
  98295. }
  98296. oggpack_write(opb,c->q_min,32);
  98297. oggpack_write(opb,c->q_delta,32);
  98298. oggpack_write(opb,c->q_quant-1,4);
  98299. oggpack_write(opb,c->q_sequencep,1);
  98300. {
  98301. int quantvals;
  98302. switch(c->maptype){
  98303. case 1:
  98304. quantvals=_book_maptype1_quantvals(c);
  98305. break;
  98306. case 2:
  98307. quantvals=c->entries*c->dim;
  98308. break;
  98309. default: /* NOT_REACHABLE */
  98310. quantvals=-1;
  98311. }
  98312. for(i=0;i<quantvals;i++)
  98313. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98314. }
  98315. break;
  98316. default:
  98317. return(-1);
  98318. }
  98319. return(0);
  98320. }
  98321. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98322. long i,j;
  98323. memset(s,0,sizeof(*s));
  98324. s->allocedp=1;
  98325. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98326. s->dim=oggpack_read(opb,16);
  98327. s->entries=oggpack_read(opb,24);
  98328. if(s->entries==-1)goto _eofout;
  98329. switch((int)oggpack_read(opb,1)){
  98330. case 0:
  98331. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98332. if(oggpack_read(opb,1)){
  98333. for(i=0;i<s->entries;i++){
  98334. if(oggpack_read(opb,1)){
  98335. long num=oggpack_read(opb,5);
  98336. if(num==-1)goto _eofout;
  98337. s->lengthlist[i]=num+1;
  98338. }else
  98339. s->lengthlist[i]=0;
  98340. }
  98341. }else{
  98342. for(i=0;i<s->entries;i++){
  98343. long num=oggpack_read(opb,5);
  98344. if(num==-1)goto _eofout;
  98345. s->lengthlist[i]=num+1;
  98346. }
  98347. }
  98348. break;
  98349. case 1:
  98350. {
  98351. long length=oggpack_read(opb,5)+1;
  98352. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98353. for(i=0;i<s->entries;){
  98354. long num=oggpack_read(opb,_ilog(s->entries-i));
  98355. if(num==-1)goto _eofout;
  98356. for(j=0;j<num && i<s->entries;j++,i++)
  98357. s->lengthlist[i]=length;
  98358. length++;
  98359. }
  98360. }
  98361. break;
  98362. default:
  98363. return(-1);
  98364. }
  98365. switch((s->maptype=oggpack_read(opb,4))){
  98366. case 0:
  98367. break;
  98368. case 1: case 2:
  98369. s->q_min=oggpack_read(opb,32);
  98370. s->q_delta=oggpack_read(opb,32);
  98371. s->q_quant=oggpack_read(opb,4)+1;
  98372. s->q_sequencep=oggpack_read(opb,1);
  98373. {
  98374. int quantvals=0;
  98375. switch(s->maptype){
  98376. case 1:
  98377. quantvals=_book_maptype1_quantvals(s);
  98378. break;
  98379. case 2:
  98380. quantvals=s->entries*s->dim;
  98381. break;
  98382. }
  98383. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98384. for(i=0;i<quantvals;i++)
  98385. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98386. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98387. }
  98388. break;
  98389. default:
  98390. goto _errout;
  98391. }
  98392. return(0);
  98393. _errout:
  98394. _eofout:
  98395. vorbis_staticbook_clear(s);
  98396. return(-1);
  98397. }
  98398. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98399. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98400. return(book->c->lengthlist[a]);
  98401. }
  98402. int vorbis_book_errorv(codebook *book,float *a){
  98403. int dim=book->dim,k;
  98404. int best=_best(book,a,1);
  98405. for(k=0;k<dim;k++)
  98406. a[k]=(book->valuelist+best*dim)[k];
  98407. return(best);
  98408. }
  98409. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98410. int k,dim=book->dim;
  98411. for(k=0;k<dim;k++)
  98412. a[k]=(book->valuelist+best*dim)[k];
  98413. return(vorbis_book_encode(book,best,b));
  98414. }
  98415. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98416. int read=book->dec_maxlength;
  98417. long lo,hi;
  98418. long lok = oggpack_look(b,book->dec_firsttablen);
  98419. if (lok >= 0) {
  98420. long entry = book->dec_firsttable[lok];
  98421. if(entry&0x80000000UL){
  98422. lo=(entry>>15)&0x7fff;
  98423. hi=book->used_entries-(entry&0x7fff);
  98424. }else{
  98425. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98426. return(entry-1);
  98427. }
  98428. }else{
  98429. lo=0;
  98430. hi=book->used_entries;
  98431. }
  98432. lok = oggpack_look(b, read);
  98433. while(lok<0 && read>1)
  98434. lok = oggpack_look(b, --read);
  98435. if(lok<0)return -1;
  98436. {
  98437. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98438. while(hi-lo>1){
  98439. long p=(hi-lo)>>1;
  98440. long test=book->codelist[lo+p]>testword;
  98441. lo+=p&(test-1);
  98442. hi-=p&(-test);
  98443. }
  98444. if(book->dec_codelengths[lo]<=read){
  98445. oggpack_adv(b, book->dec_codelengths[lo]);
  98446. return(lo);
  98447. }
  98448. }
  98449. oggpack_adv(b, read);
  98450. return(-1);
  98451. }
  98452. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98453. long packed_entry=decode_packed_entry_number(book,b);
  98454. if(packed_entry>=0)
  98455. return(book->dec_index[packed_entry]);
  98456. return(packed_entry);
  98457. }
  98458. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98459. int step=n/book->dim;
  98460. long *entry = (long*)alloca(sizeof(*entry)*step);
  98461. float **t = (float**)alloca(sizeof(*t)*step);
  98462. int i,j,o;
  98463. for (i = 0; i < step; i++) {
  98464. entry[i]=decode_packed_entry_number(book,b);
  98465. if(entry[i]==-1)return(-1);
  98466. t[i] = book->valuelist+entry[i]*book->dim;
  98467. }
  98468. for(i=0,o=0;i<book->dim;i++,o+=step)
  98469. for (j=0;j<step;j++)
  98470. a[o+j]+=t[j][i];
  98471. return(0);
  98472. }
  98473. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98474. int i,j,entry;
  98475. float *t;
  98476. if(book->dim>8){
  98477. for(i=0;i<n;){
  98478. entry = decode_packed_entry_number(book,b);
  98479. if(entry==-1)return(-1);
  98480. t = book->valuelist+entry*book->dim;
  98481. for (j=0;j<book->dim;)
  98482. a[i++]+=t[j++];
  98483. }
  98484. }else{
  98485. for(i=0;i<n;){
  98486. entry = decode_packed_entry_number(book,b);
  98487. if(entry==-1)return(-1);
  98488. t = book->valuelist+entry*book->dim;
  98489. j=0;
  98490. switch((int)book->dim){
  98491. case 8:
  98492. a[i++]+=t[j++];
  98493. case 7:
  98494. a[i++]+=t[j++];
  98495. case 6:
  98496. a[i++]+=t[j++];
  98497. case 5:
  98498. a[i++]+=t[j++];
  98499. case 4:
  98500. a[i++]+=t[j++];
  98501. case 3:
  98502. a[i++]+=t[j++];
  98503. case 2:
  98504. a[i++]+=t[j++];
  98505. case 1:
  98506. a[i++]+=t[j++];
  98507. case 0:
  98508. break;
  98509. }
  98510. }
  98511. }
  98512. return(0);
  98513. }
  98514. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98515. int i,j,entry;
  98516. float *t;
  98517. for(i=0;i<n;){
  98518. entry = decode_packed_entry_number(book,b);
  98519. if(entry==-1)return(-1);
  98520. t = book->valuelist+entry*book->dim;
  98521. for (j=0;j<book->dim;)
  98522. a[i++]=t[j++];
  98523. }
  98524. return(0);
  98525. }
  98526. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98527. oggpack_buffer *b,int n){
  98528. long i,j,entry;
  98529. int chptr=0;
  98530. for(i=offset/ch;i<(offset+n)/ch;){
  98531. entry = decode_packed_entry_number(book,b);
  98532. if(entry==-1)return(-1);
  98533. {
  98534. const float *t = book->valuelist+entry*book->dim;
  98535. for (j=0;j<book->dim;j++){
  98536. a[chptr++][i]+=t[j];
  98537. if(chptr==ch){
  98538. chptr=0;
  98539. i++;
  98540. }
  98541. }
  98542. }
  98543. }
  98544. return(0);
  98545. }
  98546. #ifdef _V_SELFTEST
  98547. #include <stdio.h>
  98548. #include "vorbis/book/lsp20_0.vqh"
  98549. #include "vorbis/book/res0a_13.vqh"
  98550. #define TESTSIZE 40
  98551. float test1[TESTSIZE]={
  98552. 0.105939f,
  98553. 0.215373f,
  98554. 0.429117f,
  98555. 0.587974f,
  98556. 0.181173f,
  98557. 0.296583f,
  98558. 0.515707f,
  98559. 0.715261f,
  98560. 0.162327f,
  98561. 0.263834f,
  98562. 0.342876f,
  98563. 0.406025f,
  98564. 0.103571f,
  98565. 0.223561f,
  98566. 0.368513f,
  98567. 0.540313f,
  98568. 0.136672f,
  98569. 0.395882f,
  98570. 0.587183f,
  98571. 0.652476f,
  98572. 0.114338f,
  98573. 0.417300f,
  98574. 0.525486f,
  98575. 0.698679f,
  98576. 0.147492f,
  98577. 0.324481f,
  98578. 0.643089f,
  98579. 0.757582f,
  98580. 0.139556f,
  98581. 0.215795f,
  98582. 0.324559f,
  98583. 0.399387f,
  98584. 0.120236f,
  98585. 0.267420f,
  98586. 0.446940f,
  98587. 0.608760f,
  98588. 0.115587f,
  98589. 0.287234f,
  98590. 0.571081f,
  98591. 0.708603f,
  98592. };
  98593. float test3[TESTSIZE]={
  98594. 0,1,-2,3,4,-5,6,7,8,9,
  98595. 8,-2,7,-1,4,6,8,3,1,-9,
  98596. 10,11,12,13,14,15,26,17,18,19,
  98597. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98598. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98599. &_vq_book_res0a_13,NULL};
  98600. float *testvec[]={test1,test3};
  98601. int main(){
  98602. oggpack_buffer write;
  98603. oggpack_buffer read;
  98604. long ptr=0,i;
  98605. oggpack_writeinit(&write);
  98606. fprintf(stderr,"Testing codebook abstraction...:\n");
  98607. while(testlist[ptr]){
  98608. codebook c;
  98609. static_codebook s;
  98610. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98611. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98612. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98613. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98614. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98615. oggpack_reset(&write);
  98616. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98617. we can write */
  98618. vorbis_staticbook_pack(testlist[ptr],&write);
  98619. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98620. for(i=0;i<TESTSIZE;i+=c.dim){
  98621. int best=_best(&c,qv+i,1);
  98622. vorbis_book_encodev(&c,best,qv+i,&write);
  98623. }
  98624. vorbis_book_clear(&c);
  98625. fprintf(stderr,"OK.\n");
  98626. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98627. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98628. if(vorbis_staticbook_unpack(&read,&s)){
  98629. fprintf(stderr,"Error unpacking codebook.\n");
  98630. exit(1);
  98631. }
  98632. if(vorbis_book_init_decode(&c,&s)){
  98633. fprintf(stderr,"Error initializing codebook.\n");
  98634. exit(1);
  98635. }
  98636. for(i=0;i<TESTSIZE;i+=c.dim)
  98637. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98638. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98639. exit(1);
  98640. }
  98641. for(i=0;i<TESTSIZE;i++)
  98642. if(fabs(qv[i]-iv[i])>.000001){
  98643. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98644. iv[i],qv[i],i);
  98645. exit(1);
  98646. }
  98647. fprintf(stderr,"OK\n");
  98648. ptr++;
  98649. }
  98650. exit(0);
  98651. }
  98652. #endif
  98653. #endif
  98654. /*** End of inlined file: codebook.c ***/
  98655. /*** Start of inlined file: envelope.c ***/
  98656. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98657. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98658. // tasks..
  98659. #if JUCE_MSVC
  98660. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98661. #endif
  98662. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98663. #if JUCE_USE_OGGVORBIS
  98664. #include <stdlib.h>
  98665. #include <string.h>
  98666. #include <stdio.h>
  98667. #include <math.h>
  98668. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98669. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98670. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98671. int ch=vi->channels;
  98672. int i,j;
  98673. int n=e->winlength=128;
  98674. e->searchstep=64; /* not random */
  98675. e->minenergy=gi->preecho_minenergy;
  98676. e->ch=ch;
  98677. e->storage=128;
  98678. e->cursor=ci->blocksizes[1]/2;
  98679. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98680. mdct_init(&e->mdct,n);
  98681. for(i=0;i<n;i++){
  98682. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98683. e->mdct_win[i]*=e->mdct_win[i];
  98684. }
  98685. e->band[0].begin=2; e->band[0].end=4;
  98686. e->band[1].begin=4; e->band[1].end=5;
  98687. e->band[2].begin=6; e->band[2].end=6;
  98688. e->band[3].begin=9; e->band[3].end=8;
  98689. e->band[4].begin=13; e->band[4].end=8;
  98690. e->band[5].begin=17; e->band[5].end=8;
  98691. e->band[6].begin=22; e->band[6].end=8;
  98692. for(j=0;j<VE_BANDS;j++){
  98693. n=e->band[j].end;
  98694. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98695. for(i=0;i<n;i++){
  98696. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98697. e->band[j].total+=e->band[j].window[i];
  98698. }
  98699. e->band[j].total=1./e->band[j].total;
  98700. }
  98701. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98702. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98703. }
  98704. void _ve_envelope_clear(envelope_lookup *e){
  98705. int i;
  98706. mdct_clear(&e->mdct);
  98707. for(i=0;i<VE_BANDS;i++)
  98708. _ogg_free(e->band[i].window);
  98709. _ogg_free(e->mdct_win);
  98710. _ogg_free(e->filter);
  98711. _ogg_free(e->mark);
  98712. memset(e,0,sizeof(*e));
  98713. }
  98714. static int _ve_amp(envelope_lookup *ve,
  98715. vorbis_info_psy_global *gi,
  98716. float *data,
  98717. envelope_band *bands,
  98718. envelope_filter_state *filters,
  98719. long pos){
  98720. long n=ve->winlength;
  98721. int ret=0;
  98722. long i,j;
  98723. float decay;
  98724. float minV=ve->minenergy;
  98725. float *vec=(float*) alloca(n*sizeof(*vec));
  98726. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98727. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98728. if(penalty<0.f)penalty=0.f;
  98729. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98730. for(i=0;i<n;i++)
  98731. vec[i]=data[i]*ve->mdct_win[i];
  98732. mdct_forward(&ve->mdct,vec,vec);
  98733. {
  98734. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98735. int ptr=filters->nearptr;
  98736. if(ptr==0){
  98737. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98738. filters->nearDC_partialacc=temp;
  98739. }else{
  98740. decay=filters->nearDC_acc+=temp;
  98741. filters->nearDC_partialacc+=temp;
  98742. }
  98743. filters->nearDC_acc-=filters->nearDC[ptr];
  98744. filters->nearDC[ptr]=temp;
  98745. decay*=(1./(VE_NEARDC+1));
  98746. filters->nearptr++;
  98747. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98748. decay=todB(&decay)*.5-15.f;
  98749. }
  98750. for(i=0;i<n/2;i+=2){
  98751. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98752. val=todB(&val)*.5f;
  98753. if(val<decay)val=decay;
  98754. if(val<minV)val=minV;
  98755. vec[i>>1]=val;
  98756. decay-=8.;
  98757. }
  98758. for(j=0;j<VE_BANDS;j++){
  98759. float acc=0.;
  98760. float valmax,valmin;
  98761. for(i=0;i<bands[j].end;i++)
  98762. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98763. acc*=bands[j].total;
  98764. {
  98765. int p,thisx=filters[j].ampptr;
  98766. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98767. p=thisx;
  98768. p--;
  98769. if(p<0)p+=VE_AMP;
  98770. postmax=max(acc,filters[j].ampbuf[p]);
  98771. postmin=min(acc,filters[j].ampbuf[p]);
  98772. for(i=0;i<stretch;i++){
  98773. p--;
  98774. if(p<0)p+=VE_AMP;
  98775. premax=max(premax,filters[j].ampbuf[p]);
  98776. premin=min(premin,filters[j].ampbuf[p]);
  98777. }
  98778. valmin=postmin-premin;
  98779. valmax=postmax-premax;
  98780. filters[j].ampbuf[thisx]=acc;
  98781. filters[j].ampptr++;
  98782. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98783. }
  98784. if(valmax>gi->preecho_thresh[j]+penalty){
  98785. ret|=1;
  98786. ret|=4;
  98787. }
  98788. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98789. }
  98790. return(ret);
  98791. }
  98792. #if 0
  98793. static int seq=0;
  98794. static ogg_int64_t totalshift=-1024;
  98795. #endif
  98796. long _ve_envelope_search(vorbis_dsp_state *v){
  98797. vorbis_info *vi=v->vi;
  98798. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98799. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98800. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98801. long i,j;
  98802. int first=ve->current/ve->searchstep;
  98803. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98804. if(first<0)first=0;
  98805. if(last+VE_WIN+VE_POST>ve->storage){
  98806. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98807. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98808. }
  98809. for(j=first;j<last;j++){
  98810. int ret=0;
  98811. ve->stretch++;
  98812. if(ve->stretch>VE_MAXSTRETCH*2)
  98813. ve->stretch=VE_MAXSTRETCH*2;
  98814. for(i=0;i<ve->ch;i++){
  98815. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98816. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98817. }
  98818. ve->mark[j+VE_POST]=0;
  98819. if(ret&1){
  98820. ve->mark[j]=1;
  98821. ve->mark[j+1]=1;
  98822. }
  98823. if(ret&2){
  98824. ve->mark[j]=1;
  98825. if(j>0)ve->mark[j-1]=1;
  98826. }
  98827. if(ret&4)ve->stretch=-1;
  98828. }
  98829. ve->current=last*ve->searchstep;
  98830. {
  98831. long centerW=v->centerW;
  98832. long testW=
  98833. centerW+
  98834. ci->blocksizes[v->W]/4+
  98835. ci->blocksizes[1]/2+
  98836. ci->blocksizes[0]/4;
  98837. j=ve->cursor;
  98838. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98839. working back one window */
  98840. if(j>=testW)return(1);
  98841. ve->cursor=j;
  98842. if(ve->mark[j/ve->searchstep]){
  98843. if(j>centerW){
  98844. #if 0
  98845. if(j>ve->curmark){
  98846. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98847. int l,m;
  98848. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98849. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98850. seq,
  98851. (totalshift+ve->cursor)/44100.,
  98852. (totalshift+j)/44100.);
  98853. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98854. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98855. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98856. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98857. for(m=0;m<VE_BANDS;m++){
  98858. char buf[80];
  98859. sprintf(buf,"delL%d",m);
  98860. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98861. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98862. }
  98863. for(m=0;m<VE_BANDS;m++){
  98864. char buf[80];
  98865. sprintf(buf,"delR%d",m);
  98866. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98867. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98868. }
  98869. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98870. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98871. seq++;
  98872. }
  98873. #endif
  98874. ve->curmark=j;
  98875. if(j>=testW)return(1);
  98876. return(0);
  98877. }
  98878. }
  98879. j+=ve->searchstep;
  98880. }
  98881. }
  98882. return(-1);
  98883. }
  98884. int _ve_envelope_mark(vorbis_dsp_state *v){
  98885. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98886. vorbis_info *vi=v->vi;
  98887. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98888. long centerW=v->centerW;
  98889. long beginW=centerW-ci->blocksizes[v->W]/4;
  98890. long endW=centerW+ci->blocksizes[v->W]/4;
  98891. if(v->W){
  98892. beginW-=ci->blocksizes[v->lW]/4;
  98893. endW+=ci->blocksizes[v->nW]/4;
  98894. }else{
  98895. beginW-=ci->blocksizes[0]/4;
  98896. endW+=ci->blocksizes[0]/4;
  98897. }
  98898. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98899. {
  98900. long first=beginW/ve->searchstep;
  98901. long last=endW/ve->searchstep;
  98902. long i;
  98903. for(i=first;i<last;i++)
  98904. if(ve->mark[i])return(1);
  98905. }
  98906. return(0);
  98907. }
  98908. void _ve_envelope_shift(envelope_lookup *e,long shift){
  98909. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  98910. ahead of ve->current */
  98911. int smallshift=shift/e->searchstep;
  98912. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  98913. #if 0
  98914. for(i=0;i<VE_BANDS*e->ch;i++)
  98915. memmove(e->filter[i].markers,
  98916. e->filter[i].markers+smallshift,
  98917. (1024-smallshift)*sizeof(*(*e->filter).markers));
  98918. totalshift+=shift;
  98919. #endif
  98920. e->current-=shift;
  98921. if(e->curmark>=0)
  98922. e->curmark-=shift;
  98923. e->cursor-=shift;
  98924. }
  98925. #endif
  98926. /*** End of inlined file: envelope.c ***/
  98927. /*** Start of inlined file: floor0.c ***/
  98928. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98929. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98930. // tasks..
  98931. #if JUCE_MSVC
  98932. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98933. #endif
  98934. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98935. #if JUCE_USE_OGGVORBIS
  98936. #include <stdlib.h>
  98937. #include <string.h>
  98938. #include <math.h>
  98939. /*** Start of inlined file: lsp.h ***/
  98940. #ifndef _V_LSP_H_
  98941. #define _V_LSP_H_
  98942. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  98943. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  98944. float *lsp,int m,
  98945. float amp,float ampoffset);
  98946. #endif
  98947. /*** End of inlined file: lsp.h ***/
  98948. #include <stdio.h>
  98949. typedef struct {
  98950. int ln;
  98951. int m;
  98952. int **linearmap;
  98953. int n[2];
  98954. vorbis_info_floor0 *vi;
  98955. long bits;
  98956. long frames;
  98957. } vorbis_look_floor0;
  98958. static void floor0_free_info(vorbis_info_floor *i){
  98959. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  98960. if(info){
  98961. memset(info,0,sizeof(*info));
  98962. _ogg_free(info);
  98963. }
  98964. }
  98965. static void floor0_free_look(vorbis_look_floor *i){
  98966. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98967. if(look){
  98968. if(look->linearmap){
  98969. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  98970. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  98971. _ogg_free(look->linearmap);
  98972. }
  98973. memset(look,0,sizeof(*look));
  98974. _ogg_free(look);
  98975. }
  98976. }
  98977. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  98978. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98979. int j;
  98980. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  98981. info->order=oggpack_read(opb,8);
  98982. info->rate=oggpack_read(opb,16);
  98983. info->barkmap=oggpack_read(opb,16);
  98984. info->ampbits=oggpack_read(opb,6);
  98985. info->ampdB=oggpack_read(opb,8);
  98986. info->numbooks=oggpack_read(opb,4)+1;
  98987. if(info->order<1)goto err_out;
  98988. if(info->rate<1)goto err_out;
  98989. if(info->barkmap<1)goto err_out;
  98990. if(info->numbooks<1)goto err_out;
  98991. for(j=0;j<info->numbooks;j++){
  98992. info->books[j]=oggpack_read(opb,8);
  98993. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  98994. }
  98995. return(info);
  98996. err_out:
  98997. floor0_free_info(info);
  98998. return(NULL);
  98999. }
  99000. static void floor0_map_lazy_init(vorbis_block *vb,
  99001. vorbis_info_floor *infoX,
  99002. vorbis_look_floor0 *look){
  99003. if(!look->linearmap[vb->W]){
  99004. vorbis_dsp_state *vd=vb->vd;
  99005. vorbis_info *vi=vd->vi;
  99006. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99007. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99008. int W=vb->W;
  99009. int n=ci->blocksizes[W]/2,j;
  99010. float scale=look->ln/toBARK(info->rate/2.f);
  99011. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99012. for(j=0;j<n;j++){
  99013. int val=floor( toBARK((info->rate/2.f)/n*j)
  99014. *scale); /* bark numbers represent band edges */
  99015. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99016. look->linearmap[W][j]=val;
  99017. }
  99018. look->linearmap[W][j]=-1;
  99019. look->n[W]=n;
  99020. }
  99021. }
  99022. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99023. vorbis_info_floor *i){
  99024. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99025. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99026. look->m=info->order;
  99027. look->ln=info->barkmap;
  99028. look->vi=info;
  99029. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99030. return look;
  99031. }
  99032. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99033. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99034. vorbis_info_floor0 *info=look->vi;
  99035. int j,k;
  99036. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99037. if(ampraw>0){ /* also handles the -1 out of data case */
  99038. long maxval=(1<<info->ampbits)-1;
  99039. float amp=(float)ampraw/maxval*info->ampdB;
  99040. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99041. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99042. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99043. codebook *b=ci->fullbooks+info->books[booknum];
  99044. float last=0.f;
  99045. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99046. for(j=0;j<look->m;j+=b->dim)
  99047. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99048. for(j=0;j<look->m;){
  99049. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99050. last=lsp[j-1];
  99051. }
  99052. lsp[look->m]=amp;
  99053. return(lsp);
  99054. }
  99055. }
  99056. eop:
  99057. return(NULL);
  99058. }
  99059. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99060. void *memo,float *out){
  99061. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99062. vorbis_info_floor0 *info=look->vi;
  99063. floor0_map_lazy_init(vb,info,look);
  99064. if(memo){
  99065. float *lsp=(float *)memo;
  99066. float amp=lsp[look->m];
  99067. vorbis_lsp_to_curve(out,
  99068. look->linearmap[vb->W],
  99069. look->n[vb->W],
  99070. look->ln,
  99071. lsp,look->m,amp,(float)info->ampdB);
  99072. return(1);
  99073. }
  99074. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99075. return(0);
  99076. }
  99077. vorbis_func_floor floor0_exportbundle={
  99078. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99079. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99080. };
  99081. #endif
  99082. /*** End of inlined file: floor0.c ***/
  99083. /*** Start of inlined file: floor1.c ***/
  99084. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99085. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99086. // tasks..
  99087. #if JUCE_MSVC
  99088. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99089. #endif
  99090. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99091. #if JUCE_USE_OGGVORBIS
  99092. #include <stdlib.h>
  99093. #include <string.h>
  99094. #include <math.h>
  99095. #include <stdio.h>
  99096. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99097. typedef struct {
  99098. int sorted_index[VIF_POSIT+2];
  99099. int forward_index[VIF_POSIT+2];
  99100. int reverse_index[VIF_POSIT+2];
  99101. int hineighbor[VIF_POSIT];
  99102. int loneighbor[VIF_POSIT];
  99103. int posts;
  99104. int n;
  99105. int quant_q;
  99106. vorbis_info_floor1 *vi;
  99107. long phrasebits;
  99108. long postbits;
  99109. long frames;
  99110. } vorbis_look_floor1;
  99111. typedef struct lsfit_acc{
  99112. long x0;
  99113. long x1;
  99114. long xa;
  99115. long ya;
  99116. long x2a;
  99117. long y2a;
  99118. long xya;
  99119. long an;
  99120. } lsfit_acc;
  99121. static void floor1_free_info(vorbis_info_floor *i){
  99122. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99123. if(info){
  99124. memset(info,0,sizeof(*info));
  99125. _ogg_free(info);
  99126. }
  99127. }
  99128. static void floor1_free_look(vorbis_look_floor *i){
  99129. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99130. if(look){
  99131. memset(look,0,sizeof(*look));
  99132. _ogg_free(look);
  99133. }
  99134. }
  99135. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99136. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99137. int j,k;
  99138. int count=0;
  99139. int rangebits;
  99140. int maxposit=info->postlist[1];
  99141. int maxclass=-1;
  99142. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99143. for(j=0;j<info->partitions;j++){
  99144. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99145. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99146. }
  99147. for(j=0;j<maxclass+1;j++){
  99148. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99149. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99150. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99151. for(k=0;k<(1<<info->class_subs[j]);k++)
  99152. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99153. }
  99154. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99155. oggpack_write(opb,ilog2(maxposit),4);
  99156. rangebits=ilog2(maxposit);
  99157. for(j=0,k=0;j<info->partitions;j++){
  99158. count+=info->class_dim[info->partitionclass[j]];
  99159. for(;k<count;k++)
  99160. oggpack_write(opb,info->postlist[k+2],rangebits);
  99161. }
  99162. }
  99163. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99164. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99165. int j,k,count=0,maxclass=-1,rangebits;
  99166. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99167. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99168. for(j=0;j<info->partitions;j++){
  99169. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99170. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99171. }
  99172. for(j=0;j<maxclass+1;j++){
  99173. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99174. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99175. if(info->class_subs[j]<0)
  99176. goto err_out;
  99177. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99178. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99179. goto err_out;
  99180. for(k=0;k<(1<<info->class_subs[j]);k++){
  99181. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99182. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99183. goto err_out;
  99184. }
  99185. }
  99186. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99187. rangebits=oggpack_read(opb,4);
  99188. for(j=0,k=0;j<info->partitions;j++){
  99189. count+=info->class_dim[info->partitionclass[j]];
  99190. for(;k<count;k++){
  99191. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99192. if(t<0 || t>=(1<<rangebits))
  99193. goto err_out;
  99194. }
  99195. }
  99196. info->postlist[0]=0;
  99197. info->postlist[1]=1<<rangebits;
  99198. return(info);
  99199. err_out:
  99200. floor1_free_info(info);
  99201. return(NULL);
  99202. }
  99203. static int icomp(const void *a,const void *b){
  99204. return(**(int **)a-**(int **)b);
  99205. }
  99206. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99207. vorbis_info_floor *in){
  99208. int *sortpointer[VIF_POSIT+2];
  99209. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99210. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99211. int i,j,n=0;
  99212. look->vi=info;
  99213. look->n=info->postlist[1];
  99214. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99215. n+=2;
  99216. look->posts=n;
  99217. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99218. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99219. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99220. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99221. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99222. switch(info->mult){
  99223. case 1: /* 1024 -> 256 */
  99224. look->quant_q=256;
  99225. break;
  99226. case 2: /* 1024 -> 128 */
  99227. look->quant_q=128;
  99228. break;
  99229. case 3: /* 1024 -> 86 */
  99230. look->quant_q=86;
  99231. break;
  99232. case 4: /* 1024 -> 64 */
  99233. look->quant_q=64;
  99234. break;
  99235. }
  99236. for(i=0;i<n-2;i++){
  99237. int lo=0;
  99238. int hi=1;
  99239. int lx=0;
  99240. int hx=look->n;
  99241. int currentx=info->postlist[i+2];
  99242. for(j=0;j<i+2;j++){
  99243. int x=info->postlist[j];
  99244. if(x>lx && x<currentx){
  99245. lo=j;
  99246. lx=x;
  99247. }
  99248. if(x<hx && x>currentx){
  99249. hi=j;
  99250. hx=x;
  99251. }
  99252. }
  99253. look->loneighbor[i]=lo;
  99254. look->hineighbor[i]=hi;
  99255. }
  99256. return(look);
  99257. }
  99258. static int render_point(int x0,int x1,int y0,int y1,int x){
  99259. y0&=0x7fff; /* mask off flag */
  99260. y1&=0x7fff;
  99261. {
  99262. int dy=y1-y0;
  99263. int adx=x1-x0;
  99264. int ady=abs(dy);
  99265. int err=ady*(x-x0);
  99266. int off=err/adx;
  99267. if(dy<0)return(y0-off);
  99268. return(y0+off);
  99269. }
  99270. }
  99271. static int vorbis_dBquant(const float *x){
  99272. int i= *x*7.3142857f+1023.5f;
  99273. if(i>1023)return(1023);
  99274. if(i<0)return(0);
  99275. return i;
  99276. }
  99277. static float FLOOR1_fromdB_LOOKUP[256]={
  99278. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99279. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99280. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99281. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99282. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99283. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99284. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99285. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99286. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99287. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99288. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99289. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99290. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99291. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99292. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99293. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99294. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99295. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99296. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99297. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99298. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99299. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99300. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99301. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99302. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99303. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99304. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99305. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99306. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99307. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99308. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99309. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99310. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99311. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99312. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99313. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99314. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99315. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99316. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99317. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99318. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99319. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99320. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99321. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99322. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99323. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99324. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99325. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99326. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99327. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99328. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99329. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99330. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99331. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99332. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99333. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99334. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99335. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99336. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99337. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99338. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99339. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99340. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99341. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99342. };
  99343. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99344. int dy=y1-y0;
  99345. int adx=x1-x0;
  99346. int ady=abs(dy);
  99347. int base=dy/adx;
  99348. int sy=(dy<0?base-1:base+1);
  99349. int x=x0;
  99350. int y=y0;
  99351. int err=0;
  99352. ady-=abs(base*adx);
  99353. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99354. while(++x<x1){
  99355. err=err+ady;
  99356. if(err>=adx){
  99357. err-=adx;
  99358. y+=sy;
  99359. }else{
  99360. y+=base;
  99361. }
  99362. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99363. }
  99364. }
  99365. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99366. int dy=y1-y0;
  99367. int adx=x1-x0;
  99368. int ady=abs(dy);
  99369. int base=dy/adx;
  99370. int sy=(dy<0?base-1:base+1);
  99371. int x=x0;
  99372. int y=y0;
  99373. int err=0;
  99374. ady-=abs(base*adx);
  99375. d[x]=y;
  99376. while(++x<x1){
  99377. err=err+ady;
  99378. if(err>=adx){
  99379. err-=adx;
  99380. y+=sy;
  99381. }else{
  99382. y+=base;
  99383. }
  99384. d[x]=y;
  99385. }
  99386. }
  99387. static int accumulate_fit(const float *flr,const float *mdct,
  99388. int x0, int x1,lsfit_acc *a,
  99389. int n,vorbis_info_floor1 *info){
  99390. long i;
  99391. 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;
  99392. memset(a,0,sizeof(*a));
  99393. a->x0=x0;
  99394. a->x1=x1;
  99395. if(x1>=n)x1=n-1;
  99396. for(i=x0;i<=x1;i++){
  99397. int quantized=vorbis_dBquant(flr+i);
  99398. if(quantized){
  99399. if(mdct[i]+info->twofitatten>=flr[i]){
  99400. xa += i;
  99401. ya += quantized;
  99402. x2a += i*i;
  99403. y2a += quantized*quantized;
  99404. xya += i*quantized;
  99405. na++;
  99406. }else{
  99407. xb += i;
  99408. yb += quantized;
  99409. x2b += i*i;
  99410. y2b += quantized*quantized;
  99411. xyb += i*quantized;
  99412. nb++;
  99413. }
  99414. }
  99415. }
  99416. xb+=xa;
  99417. yb+=ya;
  99418. x2b+=x2a;
  99419. y2b+=y2a;
  99420. xyb+=xya;
  99421. nb+=na;
  99422. {
  99423. int weight=nb*info->twofitweight/(na+1);
  99424. a->xa=xa*weight+xb;
  99425. a->ya=ya*weight+yb;
  99426. a->x2a=x2a*weight+x2b;
  99427. a->y2a=y2a*weight+y2b;
  99428. a->xya=xya*weight+xyb;
  99429. a->an=na*weight+nb;
  99430. }
  99431. return(na);
  99432. }
  99433. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99434. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99435. long x0=a[0].x0;
  99436. long x1=a[fits-1].x1;
  99437. for(i=0;i<fits;i++){
  99438. x+=a[i].xa;
  99439. y+=a[i].ya;
  99440. x2+=a[i].x2a;
  99441. y2+=a[i].y2a;
  99442. xy+=a[i].xya;
  99443. an+=a[i].an;
  99444. }
  99445. if(*y0>=0){
  99446. x+= x0;
  99447. y+= *y0;
  99448. x2+= x0 * x0;
  99449. y2+= *y0 * *y0;
  99450. xy+= *y0 * x0;
  99451. an++;
  99452. }
  99453. if(*y1>=0){
  99454. x+= x1;
  99455. y+= *y1;
  99456. x2+= x1 * x1;
  99457. y2+= *y1 * *y1;
  99458. xy+= *y1 * x1;
  99459. an++;
  99460. }
  99461. if(an){
  99462. double fx=x;
  99463. double fy=y;
  99464. double fx2=x2;
  99465. double fxy=xy;
  99466. double denom=1./(an*fx2-fx*fx);
  99467. double a=(fy*fx2-fxy*fx)*denom;
  99468. double b=(an*fxy-fx*fy)*denom;
  99469. *y0=rint(a+b*x0);
  99470. *y1=rint(a+b*x1);
  99471. if(*y0>1023)*y0=1023;
  99472. if(*y1>1023)*y1=1023;
  99473. if(*y0<0)*y0=0;
  99474. if(*y1<0)*y1=0;
  99475. }else{
  99476. *y0=0;
  99477. *y1=0;
  99478. }
  99479. }
  99480. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99481. const float *mdct,
  99482. vorbis_info_floor1 *info){
  99483. int dy=y1-y0;
  99484. int adx=x1-x0;
  99485. int ady=abs(dy);
  99486. int base=dy/adx;
  99487. int sy=(dy<0?base-1:base+1);
  99488. int x=x0;
  99489. int y=y0;
  99490. int err=0;
  99491. int val=vorbis_dBquant(mask+x);
  99492. int mse=0;
  99493. int n=0;
  99494. ady-=abs(base*adx);
  99495. mse=(y-val);
  99496. mse*=mse;
  99497. n++;
  99498. if(mdct[x]+info->twofitatten>=mask[x]){
  99499. if(y+info->maxover<val)return(1);
  99500. if(y-info->maxunder>val)return(1);
  99501. }
  99502. while(++x<x1){
  99503. err=err+ady;
  99504. if(err>=adx){
  99505. err-=adx;
  99506. y+=sy;
  99507. }else{
  99508. y+=base;
  99509. }
  99510. val=vorbis_dBquant(mask+x);
  99511. mse+=((y-val)*(y-val));
  99512. n++;
  99513. if(mdct[x]+info->twofitatten>=mask[x]){
  99514. if(val){
  99515. if(y+info->maxover<val)return(1);
  99516. if(y-info->maxunder>val)return(1);
  99517. }
  99518. }
  99519. }
  99520. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99521. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99522. if(mse/n>info->maxerr)return(1);
  99523. return(0);
  99524. }
  99525. static int post_Y(int *A,int *B,int pos){
  99526. if(A[pos]<0)
  99527. return B[pos];
  99528. if(B[pos]<0)
  99529. return A[pos];
  99530. return (A[pos]+B[pos])>>1;
  99531. }
  99532. int *floor1_fit(vorbis_block *vb,void *look_,
  99533. const float *logmdct, /* in */
  99534. const float *logmask){
  99535. long i,j;
  99536. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99537. vorbis_info_floor1 *info=look->vi;
  99538. long n=look->n;
  99539. long posts=look->posts;
  99540. long nonzero=0;
  99541. lsfit_acc fits[VIF_POSIT+1];
  99542. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99543. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99544. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99545. int hineighbor[VIF_POSIT+2];
  99546. int *output=NULL;
  99547. int memo[VIF_POSIT+2];
  99548. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99549. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99550. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99551. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99552. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99553. if(posts==0){
  99554. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99555. }else{
  99556. for(i=0;i<posts-1;i++)
  99557. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99558. look->sorted_index[i+1],fits+i,
  99559. n,info);
  99560. }
  99561. if(nonzero){
  99562. int y0=-200;
  99563. int y1=-200;
  99564. fit_line(fits,posts-1,&y0,&y1);
  99565. fit_valueA[0]=y0;
  99566. fit_valueB[0]=y0;
  99567. fit_valueB[1]=y1;
  99568. fit_valueA[1]=y1;
  99569. for(i=2;i<posts;i++){
  99570. int sortpos=look->reverse_index[i];
  99571. int ln=loneighbor[sortpos];
  99572. int hn=hineighbor[sortpos];
  99573. if(memo[ln]!=hn){
  99574. int lsortpos=look->reverse_index[ln];
  99575. int hsortpos=look->reverse_index[hn];
  99576. memo[ln]=hn;
  99577. {
  99578. int lx=info->postlist[ln];
  99579. int hx=info->postlist[hn];
  99580. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99581. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99582. if(ly==-1 || hy==-1){
  99583. exit(1);
  99584. }
  99585. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99586. int ly0=-200;
  99587. int ly1=-200;
  99588. int hy0=-200;
  99589. int hy1=-200;
  99590. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99591. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99592. fit_valueB[ln]=ly0;
  99593. if(ln==0)fit_valueA[ln]=ly0;
  99594. fit_valueA[i]=ly1;
  99595. fit_valueB[i]=hy0;
  99596. fit_valueA[hn]=hy1;
  99597. if(hn==1)fit_valueB[hn]=hy1;
  99598. if(ly1>=0 || hy0>=0){
  99599. for(j=sortpos-1;j>=0;j--)
  99600. if(hineighbor[j]==hn)
  99601. hineighbor[j]=i;
  99602. else
  99603. break;
  99604. for(j=sortpos+1;j<posts;j++)
  99605. if(loneighbor[j]==ln)
  99606. loneighbor[j]=i;
  99607. else
  99608. break;
  99609. }
  99610. }else{
  99611. fit_valueA[i]=-200;
  99612. fit_valueB[i]=-200;
  99613. }
  99614. }
  99615. }
  99616. }
  99617. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99618. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99619. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99620. for(i=2;i<posts;i++){
  99621. int ln=look->loneighbor[i-2];
  99622. int hn=look->hineighbor[i-2];
  99623. int x0=info->postlist[ln];
  99624. int x1=info->postlist[hn];
  99625. int y0=output[ln];
  99626. int y1=output[hn];
  99627. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99628. int vx=post_Y(fit_valueA,fit_valueB,i);
  99629. if(vx>=0 && predicted!=vx){
  99630. output[i]=vx;
  99631. }else{
  99632. output[i]= predicted|0x8000;
  99633. }
  99634. }
  99635. }
  99636. return(output);
  99637. }
  99638. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99639. int *A,int *B,
  99640. int del){
  99641. long i;
  99642. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99643. long posts=look->posts;
  99644. int *output=NULL;
  99645. if(A && B){
  99646. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99647. for(i=0;i<posts;i++){
  99648. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99649. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99650. }
  99651. }
  99652. return(output);
  99653. }
  99654. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99655. void*look_,
  99656. int *post,int *ilogmask){
  99657. long i,j;
  99658. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99659. vorbis_info_floor1 *info=look->vi;
  99660. long posts=look->posts;
  99661. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99662. int out[VIF_POSIT+2];
  99663. static_codebook **sbooks=ci->book_param;
  99664. codebook *books=ci->fullbooks;
  99665. static long seq=0;
  99666. if(post){
  99667. for(i=0;i<posts;i++){
  99668. int val=post[i]&0x7fff;
  99669. switch(info->mult){
  99670. case 1: /* 1024 -> 256 */
  99671. val>>=2;
  99672. break;
  99673. case 2: /* 1024 -> 128 */
  99674. val>>=3;
  99675. break;
  99676. case 3: /* 1024 -> 86 */
  99677. val/=12;
  99678. break;
  99679. case 4: /* 1024 -> 64 */
  99680. val>>=4;
  99681. break;
  99682. }
  99683. post[i]=val | (post[i]&0x8000);
  99684. }
  99685. out[0]=post[0];
  99686. out[1]=post[1];
  99687. for(i=2;i<posts;i++){
  99688. int ln=look->loneighbor[i-2];
  99689. int hn=look->hineighbor[i-2];
  99690. int x0=info->postlist[ln];
  99691. int x1=info->postlist[hn];
  99692. int y0=post[ln];
  99693. int y1=post[hn];
  99694. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99695. if((post[i]&0x8000) || (predicted==post[i])){
  99696. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99697. in interpolation */
  99698. out[i]=0;
  99699. }else{
  99700. int headroom=(look->quant_q-predicted<predicted?
  99701. look->quant_q-predicted:predicted);
  99702. int val=post[i]-predicted;
  99703. if(val<0)
  99704. if(val<-headroom)
  99705. val=headroom-val-1;
  99706. else
  99707. val=-1-(val<<1);
  99708. else
  99709. if(val>=headroom)
  99710. val= val+headroom;
  99711. else
  99712. val<<=1;
  99713. out[i]=val;
  99714. post[ln]&=0x7fff;
  99715. post[hn]&=0x7fff;
  99716. }
  99717. }
  99718. oggpack_write(opb,1,1);
  99719. look->frames++;
  99720. look->postbits+=ilog(look->quant_q-1)*2;
  99721. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99722. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99723. for(i=0,j=2;i<info->partitions;i++){
  99724. int classx=info->partitionclass[i];
  99725. int cdim=info->class_dim[classx];
  99726. int csubbits=info->class_subs[classx];
  99727. int csub=1<<csubbits;
  99728. int bookas[8]={0,0,0,0,0,0,0,0};
  99729. int cval=0;
  99730. int cshift=0;
  99731. int k,l;
  99732. if(csubbits){
  99733. int maxval[8];
  99734. for(k=0;k<csub;k++){
  99735. int booknum=info->class_subbook[classx][k];
  99736. if(booknum<0){
  99737. maxval[k]=1;
  99738. }else{
  99739. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99740. }
  99741. }
  99742. for(k=0;k<cdim;k++){
  99743. for(l=0;l<csub;l++){
  99744. int val=out[j+k];
  99745. if(val<maxval[l]){
  99746. bookas[k]=l;
  99747. break;
  99748. }
  99749. }
  99750. cval|= bookas[k]<<cshift;
  99751. cshift+=csubbits;
  99752. }
  99753. look->phrasebits+=
  99754. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99755. #ifdef TRAIN_FLOOR1
  99756. {
  99757. FILE *of;
  99758. char buffer[80];
  99759. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99760. vb->pcmend/2,posts-2,class);
  99761. of=fopen(buffer,"a");
  99762. fprintf(of,"%d\n",cval);
  99763. fclose(of);
  99764. }
  99765. #endif
  99766. }
  99767. for(k=0;k<cdim;k++){
  99768. int book=info->class_subbook[classx][bookas[k]];
  99769. if(book>=0){
  99770. if(out[j+k]<(books+book)->entries)
  99771. look->postbits+=vorbis_book_encode(books+book,
  99772. out[j+k],opb);
  99773. #ifdef TRAIN_FLOOR1
  99774. {
  99775. FILE *of;
  99776. char buffer[80];
  99777. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99778. vb->pcmend/2,posts-2,class,bookas[k]);
  99779. of=fopen(buffer,"a");
  99780. fprintf(of,"%d\n",out[j+k]);
  99781. fclose(of);
  99782. }
  99783. #endif
  99784. }
  99785. }
  99786. j+=cdim;
  99787. }
  99788. {
  99789. int hx=0;
  99790. int lx=0;
  99791. int ly=post[0]*info->mult;
  99792. for(j=1;j<look->posts;j++){
  99793. int current=look->forward_index[j];
  99794. int hy=post[current]&0x7fff;
  99795. if(hy==post[current]){
  99796. hy*=info->mult;
  99797. hx=info->postlist[current];
  99798. render_line0(lx,hx,ly,hy,ilogmask);
  99799. lx=hx;
  99800. ly=hy;
  99801. }
  99802. }
  99803. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99804. seq++;
  99805. return(1);
  99806. }
  99807. }else{
  99808. oggpack_write(opb,0,1);
  99809. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99810. seq++;
  99811. return(0);
  99812. }
  99813. }
  99814. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99815. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99816. vorbis_info_floor1 *info=look->vi;
  99817. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99818. int i,j,k;
  99819. codebook *books=ci->fullbooks;
  99820. if(oggpack_read(&vb->opb,1)==1){
  99821. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99822. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99823. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99824. for(i=0,j=2;i<info->partitions;i++){
  99825. int classx=info->partitionclass[i];
  99826. int cdim=info->class_dim[classx];
  99827. int csubbits=info->class_subs[classx];
  99828. int csub=1<<csubbits;
  99829. int cval=0;
  99830. if(csubbits){
  99831. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99832. if(cval==-1)goto eop;
  99833. }
  99834. for(k=0;k<cdim;k++){
  99835. int book=info->class_subbook[classx][cval&(csub-1)];
  99836. cval>>=csubbits;
  99837. if(book>=0){
  99838. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99839. goto eop;
  99840. }else{
  99841. fit_value[j+k]=0;
  99842. }
  99843. }
  99844. j+=cdim;
  99845. }
  99846. for(i=2;i<look->posts;i++){
  99847. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99848. info->postlist[look->hineighbor[i-2]],
  99849. fit_value[look->loneighbor[i-2]],
  99850. fit_value[look->hineighbor[i-2]],
  99851. info->postlist[i]);
  99852. int hiroom=look->quant_q-predicted;
  99853. int loroom=predicted;
  99854. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99855. int val=fit_value[i];
  99856. if(val){
  99857. if(val>=room){
  99858. if(hiroom>loroom){
  99859. val = val-loroom;
  99860. }else{
  99861. val = -1-(val-hiroom);
  99862. }
  99863. }else{
  99864. if(val&1){
  99865. val= -((val+1)>>1);
  99866. }else{
  99867. val>>=1;
  99868. }
  99869. }
  99870. fit_value[i]=val+predicted;
  99871. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99872. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99873. }else{
  99874. fit_value[i]=predicted|0x8000;
  99875. }
  99876. }
  99877. return(fit_value);
  99878. }
  99879. eop:
  99880. return(NULL);
  99881. }
  99882. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99883. float *out){
  99884. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99885. vorbis_info_floor1 *info=look->vi;
  99886. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99887. int n=ci->blocksizes[vb->W]/2;
  99888. int j;
  99889. if(memo){
  99890. int *fit_value=(int *)memo;
  99891. int hx=0;
  99892. int lx=0;
  99893. int ly=fit_value[0]*info->mult;
  99894. for(j=1;j<look->posts;j++){
  99895. int current=look->forward_index[j];
  99896. int hy=fit_value[current]&0x7fff;
  99897. if(hy==fit_value[current]){
  99898. hy*=info->mult;
  99899. hx=info->postlist[current];
  99900. render_line(lx,hx,ly,hy,out);
  99901. lx=hx;
  99902. ly=hy;
  99903. }
  99904. }
  99905. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  99906. return(1);
  99907. }
  99908. memset(out,0,sizeof(*out)*n);
  99909. return(0);
  99910. }
  99911. vorbis_func_floor floor1_exportbundle={
  99912. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  99913. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  99914. };
  99915. #endif
  99916. /*** End of inlined file: floor1.c ***/
  99917. /*** Start of inlined file: info.c ***/
  99918. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99919. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99920. // tasks..
  99921. #if JUCE_MSVC
  99922. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99923. #endif
  99924. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99925. #if JUCE_USE_OGGVORBIS
  99926. #include <stdlib.h>
  99927. #include <string.h>
  99928. #include <ctype.h>
  99929. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  99930. while(bytes--){
  99931. oggpack_write(o,*s++,8);
  99932. }
  99933. }
  99934. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  99935. while(bytes--){
  99936. *buf++=oggpack_read(o,8);
  99937. }
  99938. }
  99939. void vorbis_comment_init(vorbis_comment *vc){
  99940. memset(vc,0,sizeof(*vc));
  99941. }
  99942. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  99943. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  99944. (vc->comments+2)*sizeof(*vc->user_comments));
  99945. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  99946. (vc->comments+2)*sizeof(*vc->comment_lengths));
  99947. vc->comment_lengths[vc->comments]=strlen(comment);
  99948. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  99949. strcpy(vc->user_comments[vc->comments], comment);
  99950. vc->comments++;
  99951. vc->user_comments[vc->comments]=NULL;
  99952. }
  99953. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  99954. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  99955. strcpy(comment, tag);
  99956. strcat(comment, "=");
  99957. strcat(comment, contents);
  99958. vorbis_comment_add(vc, comment);
  99959. }
  99960. static int tagcompare(const char *s1, const char *s2, int n){
  99961. int c=0;
  99962. while(c < n){
  99963. if(toupper(s1[c]) != toupper(s2[c]))
  99964. return !0;
  99965. c++;
  99966. }
  99967. return 0;
  99968. }
  99969. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  99970. long i;
  99971. int found = 0;
  99972. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99973. char *fulltag = (char*)alloca(taglen+ 1);
  99974. strcpy(fulltag, tag);
  99975. strcat(fulltag, "=");
  99976. for(i=0;i<vc->comments;i++){
  99977. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  99978. if(count == found)
  99979. return vc->user_comments[i] + taglen;
  99980. else
  99981. found++;
  99982. }
  99983. }
  99984. return NULL; /* didn't find anything */
  99985. }
  99986. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  99987. int i,count=0;
  99988. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99989. char *fulltag = (char*)alloca(taglen+1);
  99990. strcpy(fulltag,tag);
  99991. strcat(fulltag, "=");
  99992. for(i=0;i<vc->comments;i++){
  99993. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  99994. count++;
  99995. }
  99996. return count;
  99997. }
  99998. void vorbis_comment_clear(vorbis_comment *vc){
  99999. if(vc){
  100000. long i;
  100001. for(i=0;i<vc->comments;i++)
  100002. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100003. if(vc->user_comments)_ogg_free(vc->user_comments);
  100004. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100005. if(vc->vendor)_ogg_free(vc->vendor);
  100006. }
  100007. memset(vc,0,sizeof(*vc));
  100008. }
  100009. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100010. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100011. return ci ? ci->blocksizes[zo] : -1;
  100012. }
  100013. void vorbis_info_init(vorbis_info *vi){
  100014. memset(vi,0,sizeof(*vi));
  100015. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100016. }
  100017. void vorbis_info_clear(vorbis_info *vi){
  100018. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100019. int i;
  100020. if(ci){
  100021. for(i=0;i<ci->modes;i++)
  100022. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100023. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100024. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100025. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100026. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100027. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100028. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100029. for(i=0;i<ci->books;i++){
  100030. if(ci->book_param[i]){
  100031. vorbis_staticbook_destroy(ci->book_param[i]);
  100032. }
  100033. if(ci->fullbooks)
  100034. vorbis_book_clear(ci->fullbooks+i);
  100035. }
  100036. if(ci->fullbooks)
  100037. _ogg_free(ci->fullbooks);
  100038. for(i=0;i<ci->psys;i++)
  100039. _vi_psy_free(ci->psy_param[i]);
  100040. _ogg_free(ci);
  100041. }
  100042. memset(vi,0,sizeof(*vi));
  100043. }
  100044. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100045. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100046. if(!ci)return(OV_EFAULT);
  100047. vi->version=oggpack_read(opb,32);
  100048. if(vi->version!=0)return(OV_EVERSION);
  100049. vi->channels=oggpack_read(opb,8);
  100050. vi->rate=oggpack_read(opb,32);
  100051. vi->bitrate_upper=oggpack_read(opb,32);
  100052. vi->bitrate_nominal=oggpack_read(opb,32);
  100053. vi->bitrate_lower=oggpack_read(opb,32);
  100054. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100055. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100056. if(vi->rate<1)goto err_out;
  100057. if(vi->channels<1)goto err_out;
  100058. if(ci->blocksizes[0]<8)goto err_out;
  100059. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100060. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100061. return(0);
  100062. err_out:
  100063. vorbis_info_clear(vi);
  100064. return(OV_EBADHEADER);
  100065. }
  100066. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100067. int i;
  100068. int vendorlen=oggpack_read(opb,32);
  100069. if(vendorlen<0)goto err_out;
  100070. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100071. _v_readstring(opb,vc->vendor,vendorlen);
  100072. vc->comments=oggpack_read(opb,32);
  100073. if(vc->comments<0)goto err_out;
  100074. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100075. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100076. for(i=0;i<vc->comments;i++){
  100077. int len=oggpack_read(opb,32);
  100078. if(len<0)goto err_out;
  100079. vc->comment_lengths[i]=len;
  100080. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100081. _v_readstring(opb,vc->user_comments[i],len);
  100082. }
  100083. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100084. return(0);
  100085. err_out:
  100086. vorbis_comment_clear(vc);
  100087. return(OV_EBADHEADER);
  100088. }
  100089. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100090. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100091. int i;
  100092. if(!ci)return(OV_EFAULT);
  100093. ci->books=oggpack_read(opb,8)+1;
  100094. for(i=0;i<ci->books;i++){
  100095. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100096. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100097. }
  100098. {
  100099. int times=oggpack_read(opb,6)+1;
  100100. for(i=0;i<times;i++){
  100101. int test=oggpack_read(opb,16);
  100102. if(test<0 || test>=VI_TIMEB)goto err_out;
  100103. }
  100104. }
  100105. ci->floors=oggpack_read(opb,6)+1;
  100106. for(i=0;i<ci->floors;i++){
  100107. ci->floor_type[i]=oggpack_read(opb,16);
  100108. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100109. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100110. if(!ci->floor_param[i])goto err_out;
  100111. }
  100112. ci->residues=oggpack_read(opb,6)+1;
  100113. for(i=0;i<ci->residues;i++){
  100114. ci->residue_type[i]=oggpack_read(opb,16);
  100115. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100116. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100117. if(!ci->residue_param[i])goto err_out;
  100118. }
  100119. ci->maps=oggpack_read(opb,6)+1;
  100120. for(i=0;i<ci->maps;i++){
  100121. ci->map_type[i]=oggpack_read(opb,16);
  100122. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100123. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100124. if(!ci->map_param[i])goto err_out;
  100125. }
  100126. ci->modes=oggpack_read(opb,6)+1;
  100127. for(i=0;i<ci->modes;i++){
  100128. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100129. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100130. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100131. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100132. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100133. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100134. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100135. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100136. }
  100137. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100138. return(0);
  100139. err_out:
  100140. vorbis_info_clear(vi);
  100141. return(OV_EBADHEADER);
  100142. }
  100143. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100144. oggpack_buffer opb;
  100145. if(op){
  100146. oggpack_readinit(&opb,op->packet,op->bytes);
  100147. {
  100148. char buffer[6];
  100149. int packtype=oggpack_read(&opb,8);
  100150. memset(buffer,0,6);
  100151. _v_readstring(&opb,buffer,6);
  100152. if(memcmp(buffer,"vorbis",6)){
  100153. return(OV_ENOTVORBIS);
  100154. }
  100155. switch(packtype){
  100156. case 0x01: /* least significant *bit* is read first */
  100157. if(!op->b_o_s){
  100158. return(OV_EBADHEADER);
  100159. }
  100160. if(vi->rate!=0){
  100161. return(OV_EBADHEADER);
  100162. }
  100163. return(_vorbis_unpack_info(vi,&opb));
  100164. case 0x03: /* least significant *bit* is read first */
  100165. if(vi->rate==0){
  100166. return(OV_EBADHEADER);
  100167. }
  100168. return(_vorbis_unpack_comment(vc,&opb));
  100169. case 0x05: /* least significant *bit* is read first */
  100170. if(vi->rate==0 || vc->vendor==NULL){
  100171. return(OV_EBADHEADER);
  100172. }
  100173. return(_vorbis_unpack_books(vi,&opb));
  100174. default:
  100175. return(OV_EBADHEADER);
  100176. break;
  100177. }
  100178. }
  100179. }
  100180. return(OV_EBADHEADER);
  100181. }
  100182. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100183. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100184. if(!ci)return(OV_EFAULT);
  100185. oggpack_write(opb,0x01,8);
  100186. _v_writestring(opb,"vorbis", 6);
  100187. oggpack_write(opb,0x00,32);
  100188. oggpack_write(opb,vi->channels,8);
  100189. oggpack_write(opb,vi->rate,32);
  100190. oggpack_write(opb,vi->bitrate_upper,32);
  100191. oggpack_write(opb,vi->bitrate_nominal,32);
  100192. oggpack_write(opb,vi->bitrate_lower,32);
  100193. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100194. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100195. oggpack_write(opb,1,1);
  100196. return(0);
  100197. }
  100198. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100199. char temp[]="Xiph.Org libVorbis I 20050304";
  100200. int bytes = strlen(temp);
  100201. oggpack_write(opb,0x03,8);
  100202. _v_writestring(opb,"vorbis", 6);
  100203. oggpack_write(opb,bytes,32);
  100204. _v_writestring(opb,temp, bytes);
  100205. oggpack_write(opb,vc->comments,32);
  100206. if(vc->comments){
  100207. int i;
  100208. for(i=0;i<vc->comments;i++){
  100209. if(vc->user_comments[i]){
  100210. oggpack_write(opb,vc->comment_lengths[i],32);
  100211. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100212. }else{
  100213. oggpack_write(opb,0,32);
  100214. }
  100215. }
  100216. }
  100217. oggpack_write(opb,1,1);
  100218. return(0);
  100219. }
  100220. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100221. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100222. int i;
  100223. if(!ci)return(OV_EFAULT);
  100224. oggpack_write(opb,0x05,8);
  100225. _v_writestring(opb,"vorbis", 6);
  100226. oggpack_write(opb,ci->books-1,8);
  100227. for(i=0;i<ci->books;i++)
  100228. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100229. oggpack_write(opb,0,6);
  100230. oggpack_write(opb,0,16);
  100231. oggpack_write(opb,ci->floors-1,6);
  100232. for(i=0;i<ci->floors;i++){
  100233. oggpack_write(opb,ci->floor_type[i],16);
  100234. if(_floor_P[ci->floor_type[i]]->pack)
  100235. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100236. else
  100237. goto err_out;
  100238. }
  100239. oggpack_write(opb,ci->residues-1,6);
  100240. for(i=0;i<ci->residues;i++){
  100241. oggpack_write(opb,ci->residue_type[i],16);
  100242. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100243. }
  100244. oggpack_write(opb,ci->maps-1,6);
  100245. for(i=0;i<ci->maps;i++){
  100246. oggpack_write(opb,ci->map_type[i],16);
  100247. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100248. }
  100249. oggpack_write(opb,ci->modes-1,6);
  100250. for(i=0;i<ci->modes;i++){
  100251. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100252. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100253. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100254. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100255. }
  100256. oggpack_write(opb,1,1);
  100257. return(0);
  100258. err_out:
  100259. return(-1);
  100260. }
  100261. int vorbis_commentheader_out(vorbis_comment *vc,
  100262. ogg_packet *op){
  100263. oggpack_buffer opb;
  100264. oggpack_writeinit(&opb);
  100265. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100266. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100267. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100268. op->bytes=oggpack_bytes(&opb);
  100269. op->b_o_s=0;
  100270. op->e_o_s=0;
  100271. op->granulepos=0;
  100272. op->packetno=1;
  100273. return 0;
  100274. }
  100275. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100276. vorbis_comment *vc,
  100277. ogg_packet *op,
  100278. ogg_packet *op_comm,
  100279. ogg_packet *op_code){
  100280. int ret=OV_EIMPL;
  100281. vorbis_info *vi=v->vi;
  100282. oggpack_buffer opb;
  100283. private_state *b=(private_state*)v->backend_state;
  100284. if(!b){
  100285. ret=OV_EFAULT;
  100286. goto err_out;
  100287. }
  100288. oggpack_writeinit(&opb);
  100289. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100290. if(b->header)_ogg_free(b->header);
  100291. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100292. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100293. op->packet=b->header;
  100294. op->bytes=oggpack_bytes(&opb);
  100295. op->b_o_s=1;
  100296. op->e_o_s=0;
  100297. op->granulepos=0;
  100298. op->packetno=0;
  100299. oggpack_reset(&opb);
  100300. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100301. if(b->header1)_ogg_free(b->header1);
  100302. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100303. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100304. op_comm->packet=b->header1;
  100305. op_comm->bytes=oggpack_bytes(&opb);
  100306. op_comm->b_o_s=0;
  100307. op_comm->e_o_s=0;
  100308. op_comm->granulepos=0;
  100309. op_comm->packetno=1;
  100310. oggpack_reset(&opb);
  100311. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100312. if(b->header2)_ogg_free(b->header2);
  100313. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100314. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100315. op_code->packet=b->header2;
  100316. op_code->bytes=oggpack_bytes(&opb);
  100317. op_code->b_o_s=0;
  100318. op_code->e_o_s=0;
  100319. op_code->granulepos=0;
  100320. op_code->packetno=2;
  100321. oggpack_writeclear(&opb);
  100322. return(0);
  100323. err_out:
  100324. oggpack_writeclear(&opb);
  100325. memset(op,0,sizeof(*op));
  100326. memset(op_comm,0,sizeof(*op_comm));
  100327. memset(op_code,0,sizeof(*op_code));
  100328. if(b->header)_ogg_free(b->header);
  100329. if(b->header1)_ogg_free(b->header1);
  100330. if(b->header2)_ogg_free(b->header2);
  100331. b->header=NULL;
  100332. b->header1=NULL;
  100333. b->header2=NULL;
  100334. return(ret);
  100335. }
  100336. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100337. if(granulepos>=0)
  100338. return((double)granulepos/v->vi->rate);
  100339. return(-1);
  100340. }
  100341. #endif
  100342. /*** End of inlined file: info.c ***/
  100343. /*** Start of inlined file: lpc.c ***/
  100344. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100345. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100346. // tasks..
  100347. #if JUCE_MSVC
  100348. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100349. #endif
  100350. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100351. #if JUCE_USE_OGGVORBIS
  100352. #include <stdlib.h>
  100353. #include <string.h>
  100354. #include <math.h>
  100355. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100356. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100357. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100358. double error;
  100359. int i,j;
  100360. j=m+1;
  100361. while(j--){
  100362. double d=0; /* double needed for accumulator depth */
  100363. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100364. aut[j]=d;
  100365. }
  100366. error=aut[0];
  100367. for(i=0;i<m;i++){
  100368. double r= -aut[i+1];
  100369. if(error==0){
  100370. memset(lpci,0,m*sizeof(*lpci));
  100371. return 0;
  100372. }
  100373. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100374. r/=error;
  100375. lpc[i]=r;
  100376. for(j=0;j<i/2;j++){
  100377. double tmp=lpc[j];
  100378. lpc[j]+=r*lpc[i-1-j];
  100379. lpc[i-1-j]+=r*tmp;
  100380. }
  100381. if(i%2)lpc[j]+=lpc[j]*r;
  100382. error*=1.f-r*r;
  100383. }
  100384. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100385. return error;
  100386. }
  100387. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100388. float *data,long n){
  100389. long i,j,o,p;
  100390. float y;
  100391. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100392. if(!prime)
  100393. for(i=0;i<m;i++)
  100394. work[i]=0.f;
  100395. else
  100396. for(i=0;i<m;i++)
  100397. work[i]=prime[i];
  100398. for(i=0;i<n;i++){
  100399. y=0;
  100400. o=i;
  100401. p=m;
  100402. for(j=0;j<m;j++)
  100403. y-=work[o++]*coeff[--p];
  100404. data[i]=work[o]=y;
  100405. }
  100406. }
  100407. #endif
  100408. /*** End of inlined file: lpc.c ***/
  100409. /*** Start of inlined file: lsp.c ***/
  100410. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100411. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100412. // tasks..
  100413. #if JUCE_MSVC
  100414. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100415. #endif
  100416. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100417. #if JUCE_USE_OGGVORBIS
  100418. #include <math.h>
  100419. #include <string.h>
  100420. #include <stdlib.h>
  100421. /*** Start of inlined file: lookup.h ***/
  100422. #ifndef _V_LOOKUP_H_
  100423. #ifdef FLOAT_LOOKUP
  100424. extern float vorbis_coslook(float a);
  100425. extern float vorbis_invsqlook(float a);
  100426. extern float vorbis_invsq2explook(int a);
  100427. extern float vorbis_fromdBlook(float a);
  100428. #endif
  100429. #ifdef INT_LOOKUP
  100430. extern long vorbis_invsqlook_i(long a,long e);
  100431. extern long vorbis_coslook_i(long a);
  100432. extern float vorbis_fromdBlook_i(long a);
  100433. #endif
  100434. #endif
  100435. /*** End of inlined file: lookup.h ***/
  100436. #define FLOAT_LOOKUP
  100437. #undef INT_LOOKUP
  100438. #ifdef FLOAT_LOOKUP
  100439. /*** Start of inlined file: lookup.c ***/
  100440. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100441. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100442. // tasks..
  100443. #if JUCE_MSVC
  100444. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100445. #endif
  100446. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100447. #if JUCE_USE_OGGVORBIS
  100448. #include <math.h>
  100449. /*** Start of inlined file: lookup.h ***/
  100450. #ifndef _V_LOOKUP_H_
  100451. #ifdef FLOAT_LOOKUP
  100452. extern float vorbis_coslook(float a);
  100453. extern float vorbis_invsqlook(float a);
  100454. extern float vorbis_invsq2explook(int a);
  100455. extern float vorbis_fromdBlook(float a);
  100456. #endif
  100457. #ifdef INT_LOOKUP
  100458. extern long vorbis_invsqlook_i(long a,long e);
  100459. extern long vorbis_coslook_i(long a);
  100460. extern float vorbis_fromdBlook_i(long a);
  100461. #endif
  100462. #endif
  100463. /*** End of inlined file: lookup.h ***/
  100464. /*** Start of inlined file: lookup_data.h ***/
  100465. #ifndef _V_LOOKUP_DATA_H_
  100466. #ifdef FLOAT_LOOKUP
  100467. #define COS_LOOKUP_SZ 128
  100468. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100469. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100470. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100471. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100472. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100473. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100474. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100475. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100476. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100477. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100478. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100479. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100480. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100481. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100482. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100483. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100484. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100485. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100486. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100487. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100488. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100489. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100490. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100491. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100492. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100493. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100494. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100495. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100496. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100497. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100498. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100499. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100500. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100501. -1.0000000000000f,
  100502. };
  100503. #define INVSQ_LOOKUP_SZ 32
  100504. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100505. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100506. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100507. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100508. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100509. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100510. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100511. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100512. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100513. 1.000000000000f,
  100514. };
  100515. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100516. #define INVSQ2EXP_LOOKUP_MAX 32
  100517. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100518. INVSQ2EXP_LOOKUP_MIN+1]={
  100519. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100520. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100521. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100522. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100523. 256.f, 181.019336f, 128.f, 90.50966799f,
  100524. 64.f, 45.254834f, 32.f, 22.627417f,
  100525. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100526. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100527. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100528. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100529. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100530. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100531. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100532. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100533. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100534. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100535. 1.525878906e-05f,
  100536. };
  100537. #endif
  100538. #define FROMdB_LOOKUP_SZ 35
  100539. #define FROMdB2_LOOKUP_SZ 32
  100540. #define FROMdB_SHIFT 5
  100541. #define FROMdB2_SHIFT 3
  100542. #define FROMdB2_MASK 31
  100543. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100544. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100545. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100546. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100547. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100548. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100549. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100550. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100551. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100552. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100553. };
  100554. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100555. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100556. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100557. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100558. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100559. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100560. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100561. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100562. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100563. };
  100564. #ifdef INT_LOOKUP
  100565. #define INVSQ_LOOKUP_I_SHIFT 10
  100566. #define INVSQ_LOOKUP_I_MASK 1023
  100567. static long INVSQ_LOOKUP_I[64+1]={
  100568. 92682l, 91966l, 91267l, 90583l,
  100569. 89915l, 89261l, 88621l, 87995l,
  100570. 87381l, 86781l, 86192l, 85616l,
  100571. 85051l, 84497l, 83953l, 83420l,
  100572. 82897l, 82384l, 81880l, 81385l,
  100573. 80899l, 80422l, 79953l, 79492l,
  100574. 79039l, 78594l, 78156l, 77726l,
  100575. 77302l, 76885l, 76475l, 76072l,
  100576. 75674l, 75283l, 74898l, 74519l,
  100577. 74146l, 73778l, 73415l, 73058l,
  100578. 72706l, 72359l, 72016l, 71679l,
  100579. 71347l, 71019l, 70695l, 70376l,
  100580. 70061l, 69750l, 69444l, 69141l,
  100581. 68842l, 68548l, 68256l, 67969l,
  100582. 67685l, 67405l, 67128l, 66855l,
  100583. 66585l, 66318l, 66054l, 65794l,
  100584. 65536l,
  100585. };
  100586. #define COS_LOOKUP_I_SHIFT 9
  100587. #define COS_LOOKUP_I_MASK 511
  100588. #define COS_LOOKUP_I_SZ 128
  100589. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100590. 16384l, 16379l, 16364l, 16340l,
  100591. 16305l, 16261l, 16207l, 16143l,
  100592. 16069l, 15986l, 15893l, 15791l,
  100593. 15679l, 15557l, 15426l, 15286l,
  100594. 15137l, 14978l, 14811l, 14635l,
  100595. 14449l, 14256l, 14053l, 13842l,
  100596. 13623l, 13395l, 13160l, 12916l,
  100597. 12665l, 12406l, 12140l, 11866l,
  100598. 11585l, 11297l, 11003l, 10702l,
  100599. 10394l, 10080l, 9760l, 9434l,
  100600. 9102l, 8765l, 8423l, 8076l,
  100601. 7723l, 7366l, 7005l, 6639l,
  100602. 6270l, 5897l, 5520l, 5139l,
  100603. 4756l, 4370l, 3981l, 3590l,
  100604. 3196l, 2801l, 2404l, 2006l,
  100605. 1606l, 1205l, 804l, 402l,
  100606. 0l, -401l, -803l, -1204l,
  100607. -1605l, -2005l, -2403l, -2800l,
  100608. -3195l, -3589l, -3980l, -4369l,
  100609. -4755l, -5138l, -5519l, -5896l,
  100610. -6269l, -6638l, -7004l, -7365l,
  100611. -7722l, -8075l, -8422l, -8764l,
  100612. -9101l, -9433l, -9759l, -10079l,
  100613. -10393l, -10701l, -11002l, -11296l,
  100614. -11584l, -11865l, -12139l, -12405l,
  100615. -12664l, -12915l, -13159l, -13394l,
  100616. -13622l, -13841l, -14052l, -14255l,
  100617. -14448l, -14634l, -14810l, -14977l,
  100618. -15136l, -15285l, -15425l, -15556l,
  100619. -15678l, -15790l, -15892l, -15985l,
  100620. -16068l, -16142l, -16206l, -16260l,
  100621. -16304l, -16339l, -16363l, -16378l,
  100622. -16383l,
  100623. };
  100624. #endif
  100625. #endif
  100626. /*** End of inlined file: lookup_data.h ***/
  100627. #ifdef FLOAT_LOOKUP
  100628. float vorbis_coslook(float a){
  100629. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100630. int i=vorbis_ftoi(d-.5);
  100631. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100632. }
  100633. float vorbis_invsqlook(float a){
  100634. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100635. int i=vorbis_ftoi(d-.5f);
  100636. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100637. }
  100638. float vorbis_invsq2explook(int a){
  100639. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100640. }
  100641. #include <stdio.h>
  100642. float vorbis_fromdBlook(float a){
  100643. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100644. return (i<0)?1.f:
  100645. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100646. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100647. }
  100648. #endif
  100649. #ifdef INT_LOOKUP
  100650. long vorbis_invsqlook_i(long a,long e){
  100651. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100652. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100653. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100654. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100655. d)>>16); /* result 1.16 */
  100656. e+=32;
  100657. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100658. e=(e>>1)-8;
  100659. return(val>>e);
  100660. }
  100661. float vorbis_fromdBlook_i(long a){
  100662. int i=(-a)>>(12-FROMdB2_SHIFT);
  100663. return (i<0)?1.f:
  100664. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100665. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100666. }
  100667. long vorbis_coslook_i(long a){
  100668. int i=a>>COS_LOOKUP_I_SHIFT;
  100669. int d=a&COS_LOOKUP_I_MASK;
  100670. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100671. COS_LOOKUP_I_SHIFT);
  100672. }
  100673. #endif
  100674. #endif
  100675. /*** End of inlined file: lookup.c ***/
  100676. /* catch this in the build system; we #include for
  100677. compilers (like gcc) that can't inline across
  100678. modules */
  100679. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100680. float amp,float ampoffset){
  100681. int i;
  100682. float wdel=M_PI/ln;
  100683. vorbis_fpu_control fpu;
  100684. (void) fpu; // to avoid an unused variable warning
  100685. vorbis_fpu_setround(&fpu);
  100686. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100687. i=0;
  100688. while(i<n){
  100689. int k=map[i];
  100690. int qexp;
  100691. float p=.7071067812f;
  100692. float q=.7071067812f;
  100693. float w=vorbis_coslook(wdel*k);
  100694. float *ftmp=lsp;
  100695. int c=m>>1;
  100696. do{
  100697. q*=ftmp[0]-w;
  100698. p*=ftmp[1]-w;
  100699. ftmp+=2;
  100700. }while(--c);
  100701. if(m&1){
  100702. q*=ftmp[0]-w;
  100703. q*=q;
  100704. p*=p*(1.f-w*w);
  100705. }else{
  100706. q*=q*(1.f+w);
  100707. p*=p*(1.f-w);
  100708. }
  100709. q=frexp(p+q,&qexp);
  100710. q=vorbis_fromdBlook(amp*
  100711. vorbis_invsqlook(q)*
  100712. vorbis_invsq2explook(qexp+m)-
  100713. ampoffset);
  100714. do{
  100715. curve[i++]*=q;
  100716. }while(map[i]==k);
  100717. }
  100718. vorbis_fpu_restore(fpu);
  100719. }
  100720. #else
  100721. #ifdef INT_LOOKUP
  100722. /*** Start of inlined file: lookup.c ***/
  100723. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100724. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100725. // tasks..
  100726. #if JUCE_MSVC
  100727. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100728. #endif
  100729. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100730. #if JUCE_USE_OGGVORBIS
  100731. #include <math.h>
  100732. /*** Start of inlined file: lookup.h ***/
  100733. #ifndef _V_LOOKUP_H_
  100734. #ifdef FLOAT_LOOKUP
  100735. extern float vorbis_coslook(float a);
  100736. extern float vorbis_invsqlook(float a);
  100737. extern float vorbis_invsq2explook(int a);
  100738. extern float vorbis_fromdBlook(float a);
  100739. #endif
  100740. #ifdef INT_LOOKUP
  100741. extern long vorbis_invsqlook_i(long a,long e);
  100742. extern long vorbis_coslook_i(long a);
  100743. extern float vorbis_fromdBlook_i(long a);
  100744. #endif
  100745. #endif
  100746. /*** End of inlined file: lookup.h ***/
  100747. /*** Start of inlined file: lookup_data.h ***/
  100748. #ifndef _V_LOOKUP_DATA_H_
  100749. #ifdef FLOAT_LOOKUP
  100750. #define COS_LOOKUP_SZ 128
  100751. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100752. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100753. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100754. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100755. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100756. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100757. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100758. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100759. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100760. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100761. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100762. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100763. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100764. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100765. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100766. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100767. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100768. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100769. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100770. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100771. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100772. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100773. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100774. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100775. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100776. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100777. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100778. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100779. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100780. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100781. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100782. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100783. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100784. -1.0000000000000f,
  100785. };
  100786. #define INVSQ_LOOKUP_SZ 32
  100787. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100788. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100789. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100790. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100791. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100792. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100793. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100794. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100795. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100796. 1.000000000000f,
  100797. };
  100798. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100799. #define INVSQ2EXP_LOOKUP_MAX 32
  100800. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100801. INVSQ2EXP_LOOKUP_MIN+1]={
  100802. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100803. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100804. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100805. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100806. 256.f, 181.019336f, 128.f, 90.50966799f,
  100807. 64.f, 45.254834f, 32.f, 22.627417f,
  100808. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100809. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100810. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100811. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100812. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100813. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100814. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100815. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100816. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100817. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100818. 1.525878906e-05f,
  100819. };
  100820. #endif
  100821. #define FROMdB_LOOKUP_SZ 35
  100822. #define FROMdB2_LOOKUP_SZ 32
  100823. #define FROMdB_SHIFT 5
  100824. #define FROMdB2_SHIFT 3
  100825. #define FROMdB2_MASK 31
  100826. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100827. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100828. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100829. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100830. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100831. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100832. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100833. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100834. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100835. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100836. };
  100837. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100838. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100839. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100840. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100841. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100842. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100843. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100844. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100845. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100846. };
  100847. #ifdef INT_LOOKUP
  100848. #define INVSQ_LOOKUP_I_SHIFT 10
  100849. #define INVSQ_LOOKUP_I_MASK 1023
  100850. static long INVSQ_LOOKUP_I[64+1]={
  100851. 92682l, 91966l, 91267l, 90583l,
  100852. 89915l, 89261l, 88621l, 87995l,
  100853. 87381l, 86781l, 86192l, 85616l,
  100854. 85051l, 84497l, 83953l, 83420l,
  100855. 82897l, 82384l, 81880l, 81385l,
  100856. 80899l, 80422l, 79953l, 79492l,
  100857. 79039l, 78594l, 78156l, 77726l,
  100858. 77302l, 76885l, 76475l, 76072l,
  100859. 75674l, 75283l, 74898l, 74519l,
  100860. 74146l, 73778l, 73415l, 73058l,
  100861. 72706l, 72359l, 72016l, 71679l,
  100862. 71347l, 71019l, 70695l, 70376l,
  100863. 70061l, 69750l, 69444l, 69141l,
  100864. 68842l, 68548l, 68256l, 67969l,
  100865. 67685l, 67405l, 67128l, 66855l,
  100866. 66585l, 66318l, 66054l, 65794l,
  100867. 65536l,
  100868. };
  100869. #define COS_LOOKUP_I_SHIFT 9
  100870. #define COS_LOOKUP_I_MASK 511
  100871. #define COS_LOOKUP_I_SZ 128
  100872. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100873. 16384l, 16379l, 16364l, 16340l,
  100874. 16305l, 16261l, 16207l, 16143l,
  100875. 16069l, 15986l, 15893l, 15791l,
  100876. 15679l, 15557l, 15426l, 15286l,
  100877. 15137l, 14978l, 14811l, 14635l,
  100878. 14449l, 14256l, 14053l, 13842l,
  100879. 13623l, 13395l, 13160l, 12916l,
  100880. 12665l, 12406l, 12140l, 11866l,
  100881. 11585l, 11297l, 11003l, 10702l,
  100882. 10394l, 10080l, 9760l, 9434l,
  100883. 9102l, 8765l, 8423l, 8076l,
  100884. 7723l, 7366l, 7005l, 6639l,
  100885. 6270l, 5897l, 5520l, 5139l,
  100886. 4756l, 4370l, 3981l, 3590l,
  100887. 3196l, 2801l, 2404l, 2006l,
  100888. 1606l, 1205l, 804l, 402l,
  100889. 0l, -401l, -803l, -1204l,
  100890. -1605l, -2005l, -2403l, -2800l,
  100891. -3195l, -3589l, -3980l, -4369l,
  100892. -4755l, -5138l, -5519l, -5896l,
  100893. -6269l, -6638l, -7004l, -7365l,
  100894. -7722l, -8075l, -8422l, -8764l,
  100895. -9101l, -9433l, -9759l, -10079l,
  100896. -10393l, -10701l, -11002l, -11296l,
  100897. -11584l, -11865l, -12139l, -12405l,
  100898. -12664l, -12915l, -13159l, -13394l,
  100899. -13622l, -13841l, -14052l, -14255l,
  100900. -14448l, -14634l, -14810l, -14977l,
  100901. -15136l, -15285l, -15425l, -15556l,
  100902. -15678l, -15790l, -15892l, -15985l,
  100903. -16068l, -16142l, -16206l, -16260l,
  100904. -16304l, -16339l, -16363l, -16378l,
  100905. -16383l,
  100906. };
  100907. #endif
  100908. #endif
  100909. /*** End of inlined file: lookup_data.h ***/
  100910. #ifdef FLOAT_LOOKUP
  100911. float vorbis_coslook(float a){
  100912. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100913. int i=vorbis_ftoi(d-.5);
  100914. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100915. }
  100916. float vorbis_invsqlook(float a){
  100917. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100918. int i=vorbis_ftoi(d-.5f);
  100919. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100920. }
  100921. float vorbis_invsq2explook(int a){
  100922. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100923. }
  100924. #include <stdio.h>
  100925. float vorbis_fromdBlook(float a){
  100926. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100927. return (i<0)?1.f:
  100928. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100929. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100930. }
  100931. #endif
  100932. #ifdef INT_LOOKUP
  100933. long vorbis_invsqlook_i(long a,long e){
  100934. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100935. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100936. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100937. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100938. d)>>16); /* result 1.16 */
  100939. e+=32;
  100940. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100941. e=(e>>1)-8;
  100942. return(val>>e);
  100943. }
  100944. float vorbis_fromdBlook_i(long a){
  100945. int i=(-a)>>(12-FROMdB2_SHIFT);
  100946. return (i<0)?1.f:
  100947. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100948. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100949. }
  100950. long vorbis_coslook_i(long a){
  100951. int i=a>>COS_LOOKUP_I_SHIFT;
  100952. int d=a&COS_LOOKUP_I_MASK;
  100953. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100954. COS_LOOKUP_I_SHIFT);
  100955. }
  100956. #endif
  100957. #endif
  100958. /*** End of inlined file: lookup.c ***/
  100959. /* catch this in the build system; we #include for
  100960. compilers (like gcc) that can't inline across
  100961. modules */
  100962. static int MLOOP_1[64]={
  100963. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  100964. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  100965. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100966. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100967. };
  100968. static int MLOOP_2[64]={
  100969. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  100970. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  100971. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100972. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100973. };
  100974. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  100975. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100976. float amp,float ampoffset){
  100977. int i;
  100978. int ampoffseti=rint(ampoffset*4096.f);
  100979. int ampi=rint(amp*16.f);
  100980. long *ilsp=alloca(m*sizeof(*ilsp));
  100981. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  100982. i=0;
  100983. while(i<n){
  100984. int j,k=map[i];
  100985. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  100986. unsigned long qi=46341;
  100987. int qexp=0,shift;
  100988. long wi=vorbis_coslook_i(k*65536/ln);
  100989. qi*=labs(ilsp[0]-wi);
  100990. pi*=labs(ilsp[1]-wi);
  100991. for(j=3;j<m;j+=2){
  100992. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100993. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100994. shift=MLOOP_3[(pi|qi)>>16];
  100995. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100996. pi=(pi>>shift)*labs(ilsp[j]-wi);
  100997. qexp+=shift;
  100998. }
  100999. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101000. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101001. shift=MLOOP_3[(pi|qi)>>16];
  101002. if(m&1){
  101003. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101004. pi=(pi>>shift)<<14;
  101005. qexp+=shift;
  101006. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101007. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101008. shift=MLOOP_3[(pi|qi)>>16];
  101009. pi>>=shift;
  101010. qi>>=shift;
  101011. qexp+=shift-14*((m+1)>>1);
  101012. pi=((pi*pi)>>16);
  101013. qi=((qi*qi)>>16);
  101014. qexp=qexp*2+m;
  101015. pi*=(1<<14)-((wi*wi)>>14);
  101016. qi+=pi>>14;
  101017. }else{
  101018. pi>>=shift;
  101019. qi>>=shift;
  101020. qexp+=shift-7*m;
  101021. pi=((pi*pi)>>16);
  101022. qi=((qi*qi)>>16);
  101023. qexp=qexp*2+m;
  101024. pi*=(1<<14)-wi;
  101025. qi*=(1<<14)+wi;
  101026. qi=(qi+pi)>>14;
  101027. }
  101028. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101029. qi>>=1; qexp++;
  101030. }else
  101031. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101032. qi<<=1; qexp--;
  101033. }
  101034. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101035. vorbis_invsqlook_i(qi,qexp)-
  101036. ampoffseti); /* 8.12[0] */
  101037. curve[i]*=amp;
  101038. while(map[++i]==k)curve[i]*=amp;
  101039. }
  101040. }
  101041. #else
  101042. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101043. float amp,float ampoffset){
  101044. int i;
  101045. float wdel=M_PI/ln;
  101046. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101047. i=0;
  101048. while(i<n){
  101049. int j,k=map[i];
  101050. float p=.5f;
  101051. float q=.5f;
  101052. float w=2.f*cos(wdel*k);
  101053. for(j=1;j<m;j+=2){
  101054. q *= w-lsp[j-1];
  101055. p *= w-lsp[j];
  101056. }
  101057. if(j==m){
  101058. q*=w-lsp[j-1];
  101059. p*=p*(4.f-w*w);
  101060. q*=q;
  101061. }else{
  101062. p*=p*(2.f-w);
  101063. q*=q*(2.f+w);
  101064. }
  101065. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101066. curve[i]*=q;
  101067. while(map[++i]==k)curve[i]*=q;
  101068. }
  101069. }
  101070. #endif
  101071. #endif
  101072. static void cheby(float *g, int ord) {
  101073. int i, j;
  101074. g[0] *= .5f;
  101075. for(i=2; i<= ord; i++) {
  101076. for(j=ord; j >= i; j--) {
  101077. g[j-2] -= g[j];
  101078. g[j] += g[j];
  101079. }
  101080. }
  101081. }
  101082. static int comp(const void *a,const void *b){
  101083. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101084. }
  101085. #define EPSILON 10e-7
  101086. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101087. int i,m;
  101088. double lastdelta=0.f;
  101089. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101090. for(i=0;i<=ord;i++)defl[i]=a[i];
  101091. for(m=ord;m>0;m--){
  101092. double newx=0.f,delta;
  101093. while(1){
  101094. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101095. for(i=m;i>0;i--){
  101096. ppp = newx*ppp + pp;
  101097. pp = newx*pp + p;
  101098. p = newx*p + defl[i-1];
  101099. }
  101100. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101101. if(denom<0)
  101102. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101103. if(pp>0){
  101104. denom = pp + sqrt(denom);
  101105. if(denom<EPSILON)denom=EPSILON;
  101106. }else{
  101107. denom = pp - sqrt(denom);
  101108. if(denom>-(EPSILON))denom=-(EPSILON);
  101109. }
  101110. delta = m*p/denom;
  101111. newx -= delta;
  101112. if(delta<0.f)delta*=-1;
  101113. if(fabs(delta/newx)<10e-12)break;
  101114. lastdelta=delta;
  101115. }
  101116. r[m-1]=newx;
  101117. for(i=m;i>0;i--)
  101118. defl[i-1]+=newx*defl[i];
  101119. defl++;
  101120. }
  101121. return(0);
  101122. }
  101123. static int Newton_Raphson(float *a,int ord,float *r){
  101124. int i, k, count=0;
  101125. double error=1.f;
  101126. double *root=(double*)alloca(ord*sizeof(*root));
  101127. for(i=0; i<ord;i++) root[i] = r[i];
  101128. while(error>1e-20){
  101129. error=0;
  101130. for(i=0; i<ord; i++) { /* Update each point. */
  101131. double pp=0.,delta;
  101132. double rooti=root[i];
  101133. double p=a[ord];
  101134. for(k=ord-1; k>= 0; k--) {
  101135. pp= pp* rooti + p;
  101136. p = p * rooti + a[k];
  101137. }
  101138. delta = p/pp;
  101139. root[i] -= delta;
  101140. error+= delta*delta;
  101141. }
  101142. if(count>40)return(-1);
  101143. count++;
  101144. }
  101145. for(i=0; i<ord;i++) r[i] = root[i];
  101146. return(0);
  101147. }
  101148. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101149. int order2=(m+1)>>1;
  101150. int g1_order,g2_order;
  101151. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101152. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101153. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101154. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101155. int i;
  101156. g1_order=(m+1)>>1;
  101157. g2_order=(m) >>1;
  101158. g1[g1_order] = 1.f;
  101159. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101160. g2[g2_order] = 1.f;
  101161. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101162. if(g1_order>g2_order){
  101163. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101164. }else{
  101165. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101166. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101167. }
  101168. cheby(g1,g1_order);
  101169. cheby(g2,g2_order);
  101170. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101171. Laguerre_With_Deflation(g2,g2_order,g2r))
  101172. return(-1);
  101173. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101174. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101175. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101176. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101177. for(i=0;i<g1_order;i++)
  101178. lsp[i*2] = acos(g1r[i]);
  101179. for(i=0;i<g2_order;i++)
  101180. lsp[i*2+1] = acos(g2r[i]);
  101181. return(0);
  101182. }
  101183. #endif
  101184. /*** End of inlined file: lsp.c ***/
  101185. /*** Start of inlined file: mapping0.c ***/
  101186. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101187. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101188. // tasks..
  101189. #if JUCE_MSVC
  101190. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101191. #endif
  101192. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101193. #if JUCE_USE_OGGVORBIS
  101194. #include <stdlib.h>
  101195. #include <stdio.h>
  101196. #include <string.h>
  101197. #include <math.h>
  101198. static void mapping0_free_info(vorbis_info_mapping *i){
  101199. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101200. if(info){
  101201. memset(info,0,sizeof(*info));
  101202. _ogg_free(info);
  101203. }
  101204. }
  101205. static int ilog3(unsigned int v){
  101206. int ret=0;
  101207. if(v)--v;
  101208. while(v){
  101209. ret++;
  101210. v>>=1;
  101211. }
  101212. return(ret);
  101213. }
  101214. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101215. oggpack_buffer *opb){
  101216. int i;
  101217. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101218. if(info->submaps>1){
  101219. oggpack_write(opb,1,1);
  101220. oggpack_write(opb,info->submaps-1,4);
  101221. }else
  101222. oggpack_write(opb,0,1);
  101223. if(info->coupling_steps>0){
  101224. oggpack_write(opb,1,1);
  101225. oggpack_write(opb,info->coupling_steps-1,8);
  101226. for(i=0;i<info->coupling_steps;i++){
  101227. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101228. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101229. }
  101230. }else
  101231. oggpack_write(opb,0,1);
  101232. oggpack_write(opb,0,2); /* 2,3:reserved */
  101233. if(info->submaps>1){
  101234. for(i=0;i<vi->channels;i++)
  101235. oggpack_write(opb,info->chmuxlist[i],4);
  101236. }
  101237. for(i=0;i<info->submaps;i++){
  101238. oggpack_write(opb,0,8); /* time submap unused */
  101239. oggpack_write(opb,info->floorsubmap[i],8);
  101240. oggpack_write(opb,info->residuesubmap[i],8);
  101241. }
  101242. }
  101243. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101244. int i;
  101245. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101246. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101247. memset(info,0,sizeof(*info));
  101248. if(oggpack_read(opb,1))
  101249. info->submaps=oggpack_read(opb,4)+1;
  101250. else
  101251. info->submaps=1;
  101252. if(oggpack_read(opb,1)){
  101253. info->coupling_steps=oggpack_read(opb,8)+1;
  101254. for(i=0;i<info->coupling_steps;i++){
  101255. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101256. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101257. if(testM<0 ||
  101258. testA<0 ||
  101259. testM==testA ||
  101260. testM>=vi->channels ||
  101261. testA>=vi->channels) goto err_out;
  101262. }
  101263. }
  101264. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101265. if(info->submaps>1){
  101266. for(i=0;i<vi->channels;i++){
  101267. info->chmuxlist[i]=oggpack_read(opb,4);
  101268. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101269. }
  101270. }
  101271. for(i=0;i<info->submaps;i++){
  101272. oggpack_read(opb,8); /* time submap unused */
  101273. info->floorsubmap[i]=oggpack_read(opb,8);
  101274. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101275. info->residuesubmap[i]=oggpack_read(opb,8);
  101276. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101277. }
  101278. return info;
  101279. err_out:
  101280. mapping0_free_info(info);
  101281. return(NULL);
  101282. }
  101283. #if 0
  101284. static long seq=0;
  101285. static ogg_int64_t total=0;
  101286. static float FLOOR1_fromdB_LOOKUP[256]={
  101287. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101288. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101289. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101290. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101291. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101292. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101293. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101294. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101295. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101296. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101297. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101298. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101299. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101300. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101301. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101302. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101303. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101304. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101305. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101306. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101307. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101308. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101309. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101310. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101311. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101312. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101313. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101314. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101315. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101316. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101317. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101318. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101319. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101320. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101321. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101322. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101323. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101324. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101325. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101326. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101327. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101328. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101329. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101330. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101331. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101332. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101333. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101334. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101335. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101336. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101337. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101338. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101339. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101340. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101341. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101342. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101343. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101344. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101345. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101346. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101347. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101348. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101349. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101350. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101351. };
  101352. #endif
  101353. extern int *floor1_fit(vorbis_block *vb,void *look,
  101354. const float *logmdct, /* in */
  101355. const float *logmask);
  101356. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101357. int *A,int *B,
  101358. int del);
  101359. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101360. void*look,
  101361. int *post,int *ilogmask);
  101362. static int mapping0_forward(vorbis_block *vb){
  101363. vorbis_dsp_state *vd=vb->vd;
  101364. vorbis_info *vi=vd->vi;
  101365. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101366. private_state *b=(private_state*)vb->vd->backend_state;
  101367. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101368. int n=vb->pcmend;
  101369. int i,j,k;
  101370. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101371. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101372. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101373. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101374. float global_ampmax=vbi->ampmax;
  101375. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101376. int blocktype=vbi->blocktype;
  101377. int modenumber=vb->W;
  101378. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101379. vorbis_look_psy *psy_look=
  101380. b->psy+blocktype+(vb->W?2:0);
  101381. vb->mode=modenumber;
  101382. for(i=0;i<vi->channels;i++){
  101383. float scale=4.f/n;
  101384. float scale_dB;
  101385. float *pcm =vb->pcm[i];
  101386. float *logfft =pcm;
  101387. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101388. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101389. todB estimation used on IEEE 754
  101390. compliant machines had a bug that
  101391. returned dB values about a third
  101392. of a decibel too high. The bug
  101393. was harmless because tunings
  101394. implicitly took that into
  101395. account. However, fixing the bug
  101396. in the estimator requires
  101397. changing all the tunings as well.
  101398. For now, it's easier to sync
  101399. things back up here, and
  101400. recalibrate the tunings in the
  101401. next major model upgrade. */
  101402. #if 0
  101403. if(vi->channels==2)
  101404. if(i==0)
  101405. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101406. else
  101407. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101408. #endif
  101409. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101410. #if 0
  101411. if(vi->channels==2)
  101412. if(i==0)
  101413. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101414. else
  101415. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101416. #endif
  101417. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101418. drft_forward(&b->fft_look[vb->W],pcm);
  101419. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101420. original todB estimation used on
  101421. IEEE 754 compliant machines had a
  101422. bug that returned dB values about
  101423. a third of a decibel too high.
  101424. The bug was harmless because
  101425. tunings implicitly took that into
  101426. account. However, fixing the bug
  101427. in the estimator requires
  101428. changing all the tunings as well.
  101429. For now, it's easier to sync
  101430. things back up here, and
  101431. recalibrate the tunings in the
  101432. next major model upgrade. */
  101433. local_ampmax[i]=logfft[0];
  101434. for(j=1;j<n-1;j+=2){
  101435. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101436. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101437. .345 is a hack; the original todB
  101438. estimation used on IEEE 754
  101439. compliant machines had a bug that
  101440. returned dB values about a third
  101441. of a decibel too high. The bug
  101442. was harmless because tunings
  101443. implicitly took that into
  101444. account. However, fixing the bug
  101445. in the estimator requires
  101446. changing all the tunings as well.
  101447. For now, it's easier to sync
  101448. things back up here, and
  101449. recalibrate the tunings in the
  101450. next major model upgrade. */
  101451. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101452. }
  101453. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101454. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101455. #if 0
  101456. if(vi->channels==2){
  101457. if(i==0){
  101458. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101459. }else{
  101460. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101461. }
  101462. }
  101463. #endif
  101464. }
  101465. {
  101466. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101467. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101468. for(i=0;i<vi->channels;i++){
  101469. int submap=info->chmuxlist[i];
  101470. float *mdct =gmdct[i];
  101471. float *logfft =vb->pcm[i];
  101472. float *logmdct =logfft+n/2;
  101473. float *logmask =logfft;
  101474. vb->mode=modenumber;
  101475. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101476. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101477. for(j=0;j<n/2;j++)
  101478. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101479. todB estimation used on IEEE 754
  101480. compliant machines had a bug that
  101481. returned dB values about a third
  101482. of a decibel too high. The bug
  101483. was harmless because tunings
  101484. implicitly took that into
  101485. account. However, fixing the bug
  101486. in the estimator requires
  101487. changing all the tunings as well.
  101488. For now, it's easier to sync
  101489. things back up here, and
  101490. recalibrate the tunings in the
  101491. next major model upgrade. */
  101492. #if 0
  101493. if(vi->channels==2){
  101494. if(i==0)
  101495. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101496. else
  101497. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101498. }else{
  101499. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101500. }
  101501. #endif
  101502. _vp_noisemask(psy_look,
  101503. logmdct,
  101504. noise); /* noise does not have by-frequency offset
  101505. bias applied yet */
  101506. #if 0
  101507. if(vi->channels==2){
  101508. if(i==0)
  101509. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101510. else
  101511. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101512. }
  101513. #endif
  101514. _vp_tonemask(psy_look,
  101515. logfft,
  101516. tone,
  101517. global_ampmax,
  101518. local_ampmax[i]);
  101519. #if 0
  101520. if(vi->channels==2){
  101521. if(i==0)
  101522. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101523. else
  101524. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101525. }
  101526. #endif
  101527. #if 0
  101528. {
  101529. float aotuv[psy_look->n];
  101530. #endif
  101531. _vp_offset_and_mix(psy_look,
  101532. noise,
  101533. tone,
  101534. 1,
  101535. logmask,
  101536. mdct,
  101537. logmdct);
  101538. #if 0
  101539. if(vi->channels==2){
  101540. if(i==0)
  101541. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101542. else
  101543. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101544. }
  101545. }
  101546. #endif
  101547. #if 0
  101548. if(vi->channels==2){
  101549. if(i==0)
  101550. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101551. else
  101552. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101553. }
  101554. #endif
  101555. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101556. floor_posts[i][PACKETBLOBS/2]=
  101557. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101558. logmdct,
  101559. logmask);
  101560. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101561. _vp_offset_and_mix(psy_look,
  101562. noise,
  101563. tone,
  101564. 2,
  101565. logmask,
  101566. mdct,
  101567. logmdct);
  101568. #if 0
  101569. if(vi->channels==2){
  101570. if(i==0)
  101571. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101572. else
  101573. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101574. }
  101575. #endif
  101576. floor_posts[i][PACKETBLOBS-1]=
  101577. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101578. logmdct,
  101579. logmask);
  101580. _vp_offset_and_mix(psy_look,
  101581. noise,
  101582. tone,
  101583. 0,
  101584. logmask,
  101585. mdct,
  101586. logmdct);
  101587. #if 0
  101588. if(vi->channels==2)
  101589. if(i==0)
  101590. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101591. else
  101592. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101593. #endif
  101594. floor_posts[i][0]=
  101595. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101596. logmdct,
  101597. logmask);
  101598. for(k=1;k<PACKETBLOBS/2;k++)
  101599. floor_posts[i][k]=
  101600. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101601. floor_posts[i][0],
  101602. floor_posts[i][PACKETBLOBS/2],
  101603. k*65536/(PACKETBLOBS/2));
  101604. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101605. floor_posts[i][k]=
  101606. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101607. floor_posts[i][PACKETBLOBS/2],
  101608. floor_posts[i][PACKETBLOBS-1],
  101609. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101610. }
  101611. }
  101612. }
  101613. vbi->ampmax=global_ampmax;
  101614. {
  101615. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101616. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101617. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101618. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101619. float **mag_memo;
  101620. int **mag_sort;
  101621. if(info->coupling_steps){
  101622. mag_memo=_vp_quantize_couple_memo(vb,
  101623. &ci->psy_g_param,
  101624. psy_look,
  101625. info,
  101626. gmdct);
  101627. mag_sort=_vp_quantize_couple_sort(vb,
  101628. psy_look,
  101629. info,
  101630. mag_memo);
  101631. hf_reduction(&ci->psy_g_param,
  101632. psy_look,
  101633. info,
  101634. mag_memo);
  101635. }
  101636. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101637. if(psy_look->vi->normal_channel_p){
  101638. for(i=0;i<vi->channels;i++){
  101639. float *mdct =gmdct[i];
  101640. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101641. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101642. }
  101643. }
  101644. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101645. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101646. k++){
  101647. oggpack_buffer *opb=vbi->packetblob[k];
  101648. oggpack_write(opb,0,1);
  101649. oggpack_write(opb,modenumber,b->modebits);
  101650. if(vb->W){
  101651. oggpack_write(opb,vb->lW,1);
  101652. oggpack_write(opb,vb->nW,1);
  101653. }
  101654. for(i=0;i<vi->channels;i++){
  101655. int submap=info->chmuxlist[i];
  101656. float *mdct =gmdct[i];
  101657. float *res =vb->pcm[i];
  101658. int *ilogmask=ilogmaskch[i]=
  101659. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101660. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101661. floor_posts[i][k],
  101662. ilogmask);
  101663. #if 0
  101664. {
  101665. char buf[80];
  101666. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101667. float work[n/2];
  101668. for(j=0;j<n/2;j++)
  101669. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101670. _analysis_output(buf,seq,work,n/2,1,1,0);
  101671. }
  101672. #endif
  101673. _vp_remove_floor(psy_look,
  101674. mdct,
  101675. ilogmask,
  101676. res,
  101677. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101678. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101679. #if 0
  101680. {
  101681. char buf[80];
  101682. float work[n/2];
  101683. for(j=0;j<n/2;j++)
  101684. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101685. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101686. _analysis_output(buf,seq,work,n/2,1,1,0);
  101687. }
  101688. #endif
  101689. }
  101690. if(info->coupling_steps){
  101691. _vp_couple(k,
  101692. &ci->psy_g_param,
  101693. psy_look,
  101694. info,
  101695. vb->pcm,
  101696. mag_memo,
  101697. mag_sort,
  101698. ilogmaskch,
  101699. nonzero,
  101700. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101701. }
  101702. for(i=0;i<info->submaps;i++){
  101703. int ch_in_bundle=0;
  101704. long **classifications;
  101705. int resnum=info->residuesubmap[i];
  101706. for(j=0;j<vi->channels;j++){
  101707. if(info->chmuxlist[j]==i){
  101708. zerobundle[ch_in_bundle]=0;
  101709. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101710. res_bundle[ch_in_bundle]=vb->pcm[j];
  101711. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101712. }
  101713. }
  101714. classifications=_residue_P[ci->residue_type[resnum]]->
  101715. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101716. _residue_P[ci->residue_type[resnum]]->
  101717. forward(opb,vb,b->residue[resnum],
  101718. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101719. }
  101720. }
  101721. }
  101722. #if 0
  101723. seq++;
  101724. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101725. #endif
  101726. return(0);
  101727. }
  101728. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101729. vorbis_dsp_state *vd=vb->vd;
  101730. vorbis_info *vi=vd->vi;
  101731. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101732. private_state *b=(private_state*)vd->backend_state;
  101733. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101734. int i,j;
  101735. long n=vb->pcmend=ci->blocksizes[vb->W];
  101736. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101737. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101738. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101739. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101740. for(i=0;i<vi->channels;i++){
  101741. int submap=info->chmuxlist[i];
  101742. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101743. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101744. if(floormemo[i])
  101745. nonzero[i]=1;
  101746. else
  101747. nonzero[i]=0;
  101748. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101749. }
  101750. for(i=0;i<info->coupling_steps;i++){
  101751. if(nonzero[info->coupling_mag[i]] ||
  101752. nonzero[info->coupling_ang[i]]){
  101753. nonzero[info->coupling_mag[i]]=1;
  101754. nonzero[info->coupling_ang[i]]=1;
  101755. }
  101756. }
  101757. for(i=0;i<info->submaps;i++){
  101758. int ch_in_bundle=0;
  101759. for(j=0;j<vi->channels;j++){
  101760. if(info->chmuxlist[j]==i){
  101761. if(nonzero[j])
  101762. zerobundle[ch_in_bundle]=1;
  101763. else
  101764. zerobundle[ch_in_bundle]=0;
  101765. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101766. }
  101767. }
  101768. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101769. inverse(vb,b->residue[info->residuesubmap[i]],
  101770. pcmbundle,zerobundle,ch_in_bundle);
  101771. }
  101772. for(i=info->coupling_steps-1;i>=0;i--){
  101773. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101774. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101775. for(j=0;j<n/2;j++){
  101776. float mag=pcmM[j];
  101777. float ang=pcmA[j];
  101778. if(mag>0)
  101779. if(ang>0){
  101780. pcmM[j]=mag;
  101781. pcmA[j]=mag-ang;
  101782. }else{
  101783. pcmA[j]=mag;
  101784. pcmM[j]=mag+ang;
  101785. }
  101786. else
  101787. if(ang>0){
  101788. pcmM[j]=mag;
  101789. pcmA[j]=mag+ang;
  101790. }else{
  101791. pcmA[j]=mag;
  101792. pcmM[j]=mag-ang;
  101793. }
  101794. }
  101795. }
  101796. for(i=0;i<vi->channels;i++){
  101797. float *pcm=vb->pcm[i];
  101798. int submap=info->chmuxlist[i];
  101799. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101800. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101801. floormemo[i],pcm);
  101802. }
  101803. for(i=0;i<vi->channels;i++){
  101804. float *pcm=vb->pcm[i];
  101805. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101806. }
  101807. return(0);
  101808. }
  101809. vorbis_func_mapping mapping0_exportbundle={
  101810. &mapping0_pack,
  101811. &mapping0_unpack,
  101812. &mapping0_free_info,
  101813. &mapping0_forward,
  101814. &mapping0_inverse
  101815. };
  101816. #endif
  101817. /*** End of inlined file: mapping0.c ***/
  101818. /*** Start of inlined file: mdct.c ***/
  101819. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101820. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101821. // tasks..
  101822. #if JUCE_MSVC
  101823. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101824. #endif
  101825. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101826. #if JUCE_USE_OGGVORBIS
  101827. #include <stdio.h>
  101828. #include <stdlib.h>
  101829. #include <string.h>
  101830. #include <math.h>
  101831. void mdct_init(mdct_lookup *lookup,int n){
  101832. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101833. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101834. int i;
  101835. int n2=n>>1;
  101836. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101837. lookup->n=n;
  101838. lookup->trig=T;
  101839. lookup->bitrev=bitrev;
  101840. for(i=0;i<n/4;i++){
  101841. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101842. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101843. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101844. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101845. }
  101846. for(i=0;i<n/8;i++){
  101847. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101848. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101849. }
  101850. {
  101851. int mask=(1<<(log2n-1))-1,i,j;
  101852. int msb=1<<(log2n-2);
  101853. for(i=0;i<n/8;i++){
  101854. int acc=0;
  101855. for(j=0;msb>>j;j++)
  101856. if((msb>>j)&i)acc|=1<<j;
  101857. bitrev[i*2]=((~acc)&mask)-1;
  101858. bitrev[i*2+1]=acc;
  101859. }
  101860. }
  101861. lookup->scale=FLOAT_CONV(4.f/n);
  101862. }
  101863. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101864. REG_TYPE r0 = x[6] + x[2];
  101865. REG_TYPE r1 = x[6] - x[2];
  101866. REG_TYPE r2 = x[4] + x[0];
  101867. REG_TYPE r3 = x[4] - x[0];
  101868. x[6] = r0 + r2;
  101869. x[4] = r0 - r2;
  101870. r0 = x[5] - x[1];
  101871. r2 = x[7] - x[3];
  101872. x[0] = r1 + r0;
  101873. x[2] = r1 - r0;
  101874. r0 = x[5] + x[1];
  101875. r1 = x[7] + x[3];
  101876. x[3] = r2 + r3;
  101877. x[1] = r2 - r3;
  101878. x[7] = r1 + r0;
  101879. x[5] = r1 - r0;
  101880. }
  101881. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101882. REG_TYPE r0 = x[1] - x[9];
  101883. REG_TYPE r1 = x[0] - x[8];
  101884. x[8] += x[0];
  101885. x[9] += x[1];
  101886. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101887. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101888. r0 = x[3] - x[11];
  101889. r1 = x[10] - x[2];
  101890. x[10] += x[2];
  101891. x[11] += x[3];
  101892. x[2] = r0;
  101893. x[3] = r1;
  101894. r0 = x[12] - x[4];
  101895. r1 = x[13] - x[5];
  101896. x[12] += x[4];
  101897. x[13] += x[5];
  101898. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101899. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101900. r0 = x[14] - x[6];
  101901. r1 = x[15] - x[7];
  101902. x[14] += x[6];
  101903. x[15] += x[7];
  101904. x[6] = r0;
  101905. x[7] = r1;
  101906. mdct_butterfly_8(x);
  101907. mdct_butterfly_8(x+8);
  101908. }
  101909. STIN void mdct_butterfly_32(DATA_TYPE *x){
  101910. REG_TYPE r0 = x[30] - x[14];
  101911. REG_TYPE r1 = x[31] - x[15];
  101912. x[30] += x[14];
  101913. x[31] += x[15];
  101914. x[14] = r0;
  101915. x[15] = r1;
  101916. r0 = x[28] - x[12];
  101917. r1 = x[29] - x[13];
  101918. x[28] += x[12];
  101919. x[29] += x[13];
  101920. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  101921. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  101922. r0 = x[26] - x[10];
  101923. r1 = x[27] - x[11];
  101924. x[26] += x[10];
  101925. x[27] += x[11];
  101926. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  101927. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  101928. r0 = x[24] - x[8];
  101929. r1 = x[25] - x[9];
  101930. x[24] += x[8];
  101931. x[25] += x[9];
  101932. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  101933. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101934. r0 = x[22] - x[6];
  101935. r1 = x[7] - x[23];
  101936. x[22] += x[6];
  101937. x[23] += x[7];
  101938. x[6] = r1;
  101939. x[7] = r0;
  101940. r0 = x[4] - x[20];
  101941. r1 = x[5] - x[21];
  101942. x[20] += x[4];
  101943. x[21] += x[5];
  101944. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  101945. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  101946. r0 = x[2] - x[18];
  101947. r1 = x[3] - x[19];
  101948. x[18] += x[2];
  101949. x[19] += x[3];
  101950. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  101951. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  101952. r0 = x[0] - x[16];
  101953. r1 = x[1] - x[17];
  101954. x[16] += x[0];
  101955. x[17] += x[1];
  101956. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101957. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  101958. mdct_butterfly_16(x);
  101959. mdct_butterfly_16(x+16);
  101960. }
  101961. STIN void mdct_butterfly_first(DATA_TYPE *T,
  101962. DATA_TYPE *x,
  101963. int points){
  101964. DATA_TYPE *x1 = x + points - 8;
  101965. DATA_TYPE *x2 = x + (points>>1) - 8;
  101966. REG_TYPE r0;
  101967. REG_TYPE r1;
  101968. do{
  101969. r0 = x1[6] - x2[6];
  101970. r1 = x1[7] - x2[7];
  101971. x1[6] += x2[6];
  101972. x1[7] += x2[7];
  101973. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101974. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101975. r0 = x1[4] - x2[4];
  101976. r1 = x1[5] - x2[5];
  101977. x1[4] += x2[4];
  101978. x1[5] += x2[5];
  101979. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  101980. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  101981. r0 = x1[2] - x2[2];
  101982. r1 = x1[3] - x2[3];
  101983. x1[2] += x2[2];
  101984. x1[3] += x2[3];
  101985. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  101986. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  101987. r0 = x1[0] - x2[0];
  101988. r1 = x1[1] - x2[1];
  101989. x1[0] += x2[0];
  101990. x1[1] += x2[1];
  101991. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  101992. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  101993. x1-=8;
  101994. x2-=8;
  101995. T+=16;
  101996. }while(x2>=x);
  101997. }
  101998. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  101999. DATA_TYPE *x,
  102000. int points,
  102001. int trigint){
  102002. DATA_TYPE *x1 = x + points - 8;
  102003. DATA_TYPE *x2 = x + (points>>1) - 8;
  102004. REG_TYPE r0;
  102005. REG_TYPE r1;
  102006. do{
  102007. r0 = x1[6] - x2[6];
  102008. r1 = x1[7] - x2[7];
  102009. x1[6] += x2[6];
  102010. x1[7] += x2[7];
  102011. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102012. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102013. T+=trigint;
  102014. r0 = x1[4] - x2[4];
  102015. r1 = x1[5] - x2[5];
  102016. x1[4] += x2[4];
  102017. x1[5] += x2[5];
  102018. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102019. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102020. T+=trigint;
  102021. r0 = x1[2] - x2[2];
  102022. r1 = x1[3] - x2[3];
  102023. x1[2] += x2[2];
  102024. x1[3] += x2[3];
  102025. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102026. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102027. T+=trigint;
  102028. r0 = x1[0] - x2[0];
  102029. r1 = x1[1] - x2[1];
  102030. x1[0] += x2[0];
  102031. x1[1] += x2[1];
  102032. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102033. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102034. T+=trigint;
  102035. x1-=8;
  102036. x2-=8;
  102037. }while(x2>=x);
  102038. }
  102039. STIN void mdct_butterflies(mdct_lookup *init,
  102040. DATA_TYPE *x,
  102041. int points){
  102042. DATA_TYPE *T=init->trig;
  102043. int stages=init->log2n-5;
  102044. int i,j;
  102045. if(--stages>0){
  102046. mdct_butterfly_first(T,x,points);
  102047. }
  102048. for(i=1;--stages>0;i++){
  102049. for(j=0;j<(1<<i);j++)
  102050. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102051. }
  102052. for(j=0;j<points;j+=32)
  102053. mdct_butterfly_32(x+j);
  102054. }
  102055. void mdct_clear(mdct_lookup *l){
  102056. if(l){
  102057. if(l->trig)_ogg_free(l->trig);
  102058. if(l->bitrev)_ogg_free(l->bitrev);
  102059. memset(l,0,sizeof(*l));
  102060. }
  102061. }
  102062. STIN void mdct_bitreverse(mdct_lookup *init,
  102063. DATA_TYPE *x){
  102064. int n = init->n;
  102065. int *bit = init->bitrev;
  102066. DATA_TYPE *w0 = x;
  102067. DATA_TYPE *w1 = x = w0+(n>>1);
  102068. DATA_TYPE *T = init->trig+n;
  102069. do{
  102070. DATA_TYPE *x0 = x+bit[0];
  102071. DATA_TYPE *x1 = x+bit[1];
  102072. REG_TYPE r0 = x0[1] - x1[1];
  102073. REG_TYPE r1 = x0[0] + x1[0];
  102074. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102075. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102076. w1 -= 4;
  102077. r0 = HALVE(x0[1] + x1[1]);
  102078. r1 = HALVE(x0[0] - x1[0]);
  102079. w0[0] = r0 + r2;
  102080. w1[2] = r0 - r2;
  102081. w0[1] = r1 + r3;
  102082. w1[3] = r3 - r1;
  102083. x0 = x+bit[2];
  102084. x1 = x+bit[3];
  102085. r0 = x0[1] - x1[1];
  102086. r1 = x0[0] + x1[0];
  102087. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102088. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102089. r0 = HALVE(x0[1] + x1[1]);
  102090. r1 = HALVE(x0[0] - x1[0]);
  102091. w0[2] = r0 + r2;
  102092. w1[0] = r0 - r2;
  102093. w0[3] = r1 + r3;
  102094. w1[1] = r3 - r1;
  102095. T += 4;
  102096. bit += 4;
  102097. w0 += 4;
  102098. }while(w0<w1);
  102099. }
  102100. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102101. int n=init->n;
  102102. int n2=n>>1;
  102103. int n4=n>>2;
  102104. DATA_TYPE *iX = in+n2-7;
  102105. DATA_TYPE *oX = out+n2+n4;
  102106. DATA_TYPE *T = init->trig+n4;
  102107. do{
  102108. oX -= 4;
  102109. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102110. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102111. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102112. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102113. iX -= 8;
  102114. T += 4;
  102115. }while(iX>=in);
  102116. iX = in+n2-8;
  102117. oX = out+n2+n4;
  102118. T = init->trig+n4;
  102119. do{
  102120. T -= 4;
  102121. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102122. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102123. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102124. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102125. iX -= 8;
  102126. oX += 4;
  102127. }while(iX>=in);
  102128. mdct_butterflies(init,out+n2,n2);
  102129. mdct_bitreverse(init,out);
  102130. {
  102131. DATA_TYPE *oX1=out+n2+n4;
  102132. DATA_TYPE *oX2=out+n2+n4;
  102133. DATA_TYPE *iX =out;
  102134. T =init->trig+n2;
  102135. do{
  102136. oX1-=4;
  102137. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102138. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102139. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102140. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102141. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102142. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102143. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102144. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102145. oX2+=4;
  102146. iX += 8;
  102147. T += 8;
  102148. }while(iX<oX1);
  102149. iX=out+n2+n4;
  102150. oX1=out+n4;
  102151. oX2=oX1;
  102152. do{
  102153. oX1-=4;
  102154. iX-=4;
  102155. oX2[0] = -(oX1[3] = iX[3]);
  102156. oX2[1] = -(oX1[2] = iX[2]);
  102157. oX2[2] = -(oX1[1] = iX[1]);
  102158. oX2[3] = -(oX1[0] = iX[0]);
  102159. oX2+=4;
  102160. }while(oX2<iX);
  102161. iX=out+n2+n4;
  102162. oX1=out+n2+n4;
  102163. oX2=out+n2;
  102164. do{
  102165. oX1-=4;
  102166. oX1[0]= iX[3];
  102167. oX1[1]= iX[2];
  102168. oX1[2]= iX[1];
  102169. oX1[3]= iX[0];
  102170. iX+=4;
  102171. }while(oX1>oX2);
  102172. }
  102173. }
  102174. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102175. int n=init->n;
  102176. int n2=n>>1;
  102177. int n4=n>>2;
  102178. int n8=n>>3;
  102179. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102180. DATA_TYPE *w2=w+n2;
  102181. REG_TYPE r0;
  102182. REG_TYPE r1;
  102183. DATA_TYPE *x0=in+n2+n4;
  102184. DATA_TYPE *x1=x0+1;
  102185. DATA_TYPE *T=init->trig+n2;
  102186. int i=0;
  102187. for(i=0;i<n8;i+=2){
  102188. x0 -=4;
  102189. T-=2;
  102190. r0= x0[2] + x1[0];
  102191. r1= x0[0] + x1[2];
  102192. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102193. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102194. x1 +=4;
  102195. }
  102196. x1=in+1;
  102197. for(;i<n2-n8;i+=2){
  102198. T-=2;
  102199. x0 -=4;
  102200. r0= x0[2] - x1[0];
  102201. r1= x0[0] - x1[2];
  102202. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102203. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102204. x1 +=4;
  102205. }
  102206. x0=in+n;
  102207. for(;i<n2;i+=2){
  102208. T-=2;
  102209. x0 -=4;
  102210. r0= -x0[2] - x1[0];
  102211. r1= -x0[0] - x1[2];
  102212. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102213. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102214. x1 +=4;
  102215. }
  102216. mdct_butterflies(init,w+n2,n2);
  102217. mdct_bitreverse(init,w);
  102218. T=init->trig+n2;
  102219. x0=out+n2;
  102220. for(i=0;i<n4;i++){
  102221. x0--;
  102222. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102223. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102224. w+=2;
  102225. T+=2;
  102226. }
  102227. }
  102228. #endif
  102229. /*** End of inlined file: mdct.c ***/
  102230. /*** Start of inlined file: psy.c ***/
  102231. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102232. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102233. // tasks..
  102234. #if JUCE_MSVC
  102235. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102236. #endif
  102237. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102238. #if JUCE_USE_OGGVORBIS
  102239. #include <stdlib.h>
  102240. #include <math.h>
  102241. #include <string.h>
  102242. /*** Start of inlined file: masking.h ***/
  102243. #ifndef _V_MASKING_H_
  102244. #define _V_MASKING_H_
  102245. #define MAX_ATH 88
  102246. static float ATH[]={
  102247. -51, -52, -53, -54, -55, -56, -57, -58,
  102248. -59, -60, -61, -62, -63, -64, -65, -66,
  102249. -67, -68, -69, -70, -71, -72, -73, -74,
  102250. -75, -76, -77, -78, -80, -81, -82, -83,
  102251. -84, -85, -86, -87, -88, -88, -89, -89,
  102252. -90, -91, -91, -92, -93, -94, -95, -96,
  102253. -96, -97, -98, -98, -99, -99,-100,-100,
  102254. -101,-102,-103,-104,-106,-107,-107,-107,
  102255. -107,-105,-103,-102,-101, -99, -98, -96,
  102256. -95, -95, -96, -97, -96, -95, -93, -90,
  102257. -80, -70, -50, -40, -30, -30, -30, -30
  102258. };
  102259. #define EHMER_OFFSET 16
  102260. #define EHMER_MAX 56
  102261. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102262. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102263. -60, -60, -60, -60, -62, -62, -65, -73,
  102264. -69, -68, -68, -67, -70, -70, -72, -74,
  102265. -75, -79, -79, -80, -83, -88, -93, -100,
  102266. -110, -999, -999, -999, -999, -999, -999, -999,
  102267. -999, -999, -999, -999, -999, -999, -999, -999,
  102268. -999, -999, -999, -999, -999, -999, -999, -999},
  102269. { -48, -48, -48, -48, -48, -48, -48, -48,
  102270. -48, -48, -48, -48, -48, -53, -61, -66,
  102271. -66, -68, -67, -70, -76, -76, -72, -73,
  102272. -75, -76, -78, -79, -83, -88, -93, -100,
  102273. -110, -999, -999, -999, -999, -999, -999, -999,
  102274. -999, -999, -999, -999, -999, -999, -999, -999,
  102275. -999, -999, -999, -999, -999, -999, -999, -999},
  102276. { -37, -37, -37, -37, -37, -37, -37, -37,
  102277. -38, -40, -42, -46, -48, -53, -55, -62,
  102278. -65, -58, -56, -56, -61, -60, -65, -67,
  102279. -69, -71, -77, -77, -78, -80, -82, -84,
  102280. -88, -93, -98, -106, -112, -999, -999, -999,
  102281. -999, -999, -999, -999, -999, -999, -999, -999,
  102282. -999, -999, -999, -999, -999, -999, -999, -999},
  102283. { -25, -25, -25, -25, -25, -25, -25, -25,
  102284. -25, -26, -27, -29, -32, -38, -48, -52,
  102285. -52, -50, -48, -48, -51, -52, -54, -60,
  102286. -67, -67, -66, -68, -69, -73, -73, -76,
  102287. -80, -81, -81, -85, -85, -86, -88, -93,
  102288. -100, -110, -999, -999, -999, -999, -999, -999,
  102289. -999, -999, -999, -999, -999, -999, -999, -999},
  102290. { -16, -16, -16, -16, -16, -16, -16, -16,
  102291. -17, -19, -20, -22, -26, -28, -31, -40,
  102292. -47, -39, -39, -40, -42, -43, -47, -51,
  102293. -57, -52, -55, -55, -60, -58, -62, -63,
  102294. -70, -67, -69, -72, -73, -77, -80, -82,
  102295. -83, -87, -90, -94, -98, -104, -115, -999,
  102296. -999, -999, -999, -999, -999, -999, -999, -999},
  102297. { -8, -8, -8, -8, -8, -8, -8, -8,
  102298. -8, -8, -10, -11, -15, -19, -25, -30,
  102299. -34, -31, -30, -31, -29, -32, -35, -42,
  102300. -48, -42, -44, -46, -50, -50, -51, -52,
  102301. -59, -54, -55, -55, -58, -62, -63, -66,
  102302. -72, -73, -76, -75, -78, -80, -80, -81,
  102303. -84, -88, -90, -94, -98, -101, -106, -110}},
  102304. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102305. -66, -66, -66, -66, -66, -67, -67, -67,
  102306. -76, -72, -71, -74, -76, -76, -75, -78,
  102307. -79, -79, -81, -83, -86, -89, -93, -97,
  102308. -100, -105, -110, -999, -999, -999, -999, -999,
  102309. -999, -999, -999, -999, -999, -999, -999, -999,
  102310. -999, -999, -999, -999, -999, -999, -999, -999},
  102311. { -47, -47, -47, -47, -47, -47, -47, -47,
  102312. -47, -47, -47, -48, -51, -55, -59, -66,
  102313. -66, -66, -67, -66, -68, -69, -70, -74,
  102314. -79, -77, -77, -78, -80, -81, -82, -84,
  102315. -86, -88, -91, -95, -100, -108, -116, -999,
  102316. -999, -999, -999, -999, -999, -999, -999, -999,
  102317. -999, -999, -999, -999, -999, -999, -999, -999},
  102318. { -36, -36, -36, -36, -36, -36, -36, -36,
  102319. -36, -37, -37, -41, -44, -48, -51, -58,
  102320. -62, -60, -57, -59, -59, -60, -63, -65,
  102321. -72, -71, -70, -72, -74, -77, -76, -78,
  102322. -81, -81, -80, -83, -86, -91, -96, -100,
  102323. -105, -110, -999, -999, -999, -999, -999, -999,
  102324. -999, -999, -999, -999, -999, -999, -999, -999},
  102325. { -28, -28, -28, -28, -28, -28, -28, -28,
  102326. -28, -30, -32, -32, -33, -35, -41, -49,
  102327. -50, -49, -47, -48, -48, -52, -51, -57,
  102328. -65, -61, -59, -61, -64, -69, -70, -74,
  102329. -77, -77, -78, -81, -84, -85, -87, -90,
  102330. -92, -96, -100, -107, -112, -999, -999, -999,
  102331. -999, -999, -999, -999, -999, -999, -999, -999},
  102332. { -19, -19, -19, -19, -19, -19, -19, -19,
  102333. -20, -21, -23, -27, -30, -35, -36, -41,
  102334. -46, -44, -42, -40, -41, -41, -43, -48,
  102335. -55, -53, -52, -53, -56, -59, -58, -60,
  102336. -67, -66, -69, -71, -72, -75, -79, -81,
  102337. -84, -87, -90, -93, -97, -101, -107, -114,
  102338. -999, -999, -999, -999, -999, -999, -999, -999},
  102339. { -9, -9, -9, -9, -9, -9, -9, -9,
  102340. -11, -12, -12, -15, -16, -20, -23, -30,
  102341. -37, -34, -33, -34, -31, -32, -32, -38,
  102342. -47, -44, -41, -40, -47, -49, -46, -46,
  102343. -58, -50, -50, -54, -58, -62, -64, -67,
  102344. -67, -70, -72, -76, -79, -83, -87, -91,
  102345. -96, -100, -104, -110, -999, -999, -999, -999}},
  102346. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102347. -62, -62, -63, -64, -66, -67, -66, -68,
  102348. -75, -72, -76, -75, -76, -78, -79, -82,
  102349. -84, -85, -90, -94, -101, -110, -999, -999,
  102350. -999, -999, -999, -999, -999, -999, -999, -999,
  102351. -999, -999, -999, -999, -999, -999, -999, -999,
  102352. -999, -999, -999, -999, -999, -999, -999, -999},
  102353. { -59, -59, -59, -59, -59, -59, -59, -59,
  102354. -59, -59, -59, -60, -60, -61, -63, -66,
  102355. -71, -68, -70, -70, -71, -72, -72, -75,
  102356. -81, -78, -79, -82, -83, -86, -90, -97,
  102357. -103, -113, -999, -999, -999, -999, -999, -999,
  102358. -999, -999, -999, -999, -999, -999, -999, -999,
  102359. -999, -999, -999, -999, -999, -999, -999, -999},
  102360. { -53, -53, -53, -53, -53, -53, -53, -53,
  102361. -53, -54, -55, -57, -56, -57, -55, -61,
  102362. -65, -60, -60, -62, -63, -63, -66, -68,
  102363. -74, -73, -75, -75, -78, -80, -80, -82,
  102364. -85, -90, -96, -101, -108, -999, -999, -999,
  102365. -999, -999, -999, -999, -999, -999, -999, -999,
  102366. -999, -999, -999, -999, -999, -999, -999, -999},
  102367. { -46, -46, -46, -46, -46, -46, -46, -46,
  102368. -46, -46, -47, -47, -47, -47, -48, -51,
  102369. -57, -51, -49, -50, -51, -53, -54, -59,
  102370. -66, -60, -62, -67, -67, -70, -72, -75,
  102371. -76, -78, -81, -85, -88, -94, -97, -104,
  102372. -112, -999, -999, -999, -999, -999, -999, -999,
  102373. -999, -999, -999, -999, -999, -999, -999, -999},
  102374. { -36, -36, -36, -36, -36, -36, -36, -36,
  102375. -39, -41, -42, -42, -39, -38, -41, -43,
  102376. -52, -44, -40, -39, -37, -37, -40, -47,
  102377. -54, -50, -48, -50, -55, -61, -59, -62,
  102378. -66, -66, -66, -69, -69, -73, -74, -74,
  102379. -75, -77, -79, -82, -87, -91, -95, -100,
  102380. -108, -115, -999, -999, -999, -999, -999, -999},
  102381. { -28, -26, -24, -22, -20, -20, -23, -29,
  102382. -30, -31, -28, -27, -28, -28, -28, -35,
  102383. -40, -33, -32, -29, -30, -30, -30, -37,
  102384. -45, -41, -37, -38, -45, -47, -47, -48,
  102385. -53, -49, -48, -50, -49, -49, -51, -52,
  102386. -58, -56, -57, -56, -60, -61, -62, -70,
  102387. -72, -74, -78, -83, -88, -93, -100, -106}},
  102388. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102389. -999, -110, -105, -100, -95, -91, -87, -83,
  102390. -80, -78, -76, -78, -78, -81, -83, -85,
  102391. -86, -85, -86, -87, -90, -97, -107, -999,
  102392. -999, -999, -999, -999, -999, -999, -999, -999,
  102393. -999, -999, -999, -999, -999, -999, -999, -999,
  102394. -999, -999, -999, -999, -999, -999, -999, -999},
  102395. {-999, -999, -999, -110, -105, -100, -95, -90,
  102396. -85, -81, -77, -73, -70, -67, -67, -68,
  102397. -75, -73, -70, -69, -70, -72, -75, -79,
  102398. -84, -83, -84, -86, -88, -89, -89, -93,
  102399. -98, -105, -112, -999, -999, -999, -999, -999,
  102400. -999, -999, -999, -999, -999, -999, -999, -999,
  102401. -999, -999, -999, -999, -999, -999, -999, -999},
  102402. {-105, -100, -95, -90, -85, -80, -76, -71,
  102403. -68, -68, -65, -63, -63, -62, -62, -64,
  102404. -65, -64, -61, -62, -63, -64, -66, -68,
  102405. -73, -73, -74, -75, -76, -81, -83, -85,
  102406. -88, -89, -92, -95, -100, -108, -999, -999,
  102407. -999, -999, -999, -999, -999, -999, -999, -999,
  102408. -999, -999, -999, -999, -999, -999, -999, -999},
  102409. { -80, -75, -71, -68, -65, -63, -62, -61,
  102410. -61, -61, -61, -59, -56, -57, -53, -50,
  102411. -58, -52, -50, -50, -52, -53, -54, -58,
  102412. -67, -63, -67, -68, -72, -75, -78, -80,
  102413. -81, -81, -82, -85, -89, -90, -93, -97,
  102414. -101, -107, -114, -999, -999, -999, -999, -999,
  102415. -999, -999, -999, -999, -999, -999, -999, -999},
  102416. { -65, -61, -59, -57, -56, -55, -55, -56,
  102417. -56, -57, -55, -53, -52, -47, -44, -44,
  102418. -50, -44, -41, -39, -39, -42, -40, -46,
  102419. -51, -49, -50, -53, -54, -63, -60, -61,
  102420. -62, -66, -66, -66, -70, -73, -74, -75,
  102421. -76, -75, -79, -85, -89, -91, -96, -102,
  102422. -110, -999, -999, -999, -999, -999, -999, -999},
  102423. { -52, -50, -49, -49, -48, -48, -48, -49,
  102424. -50, -50, -49, -46, -43, -39, -35, -33,
  102425. -38, -36, -32, -29, -32, -32, -32, -35,
  102426. -44, -39, -38, -38, -46, -50, -45, -46,
  102427. -53, -50, -50, -50, -54, -54, -53, -53,
  102428. -56, -57, -59, -66, -70, -72, -74, -79,
  102429. -83, -85, -90, -97, -114, -999, -999, -999}},
  102430. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102431. -100, -95, -90, -86, -80, -75, -75, -79,
  102432. -80, -79, -80, -81, -82, -88, -95, -103,
  102433. -110, -999, -999, -999, -999, -999, -999, -999,
  102434. -999, -999, -999, -999, -999, -999, -999, -999,
  102435. -999, -999, -999, -999, -999, -999, -999, -999,
  102436. -999, -999, -999, -999, -999, -999, -999, -999},
  102437. {-999, -999, -999, -999, -108, -103, -98, -93,
  102438. -88, -83, -79, -78, -75, -71, -67, -68,
  102439. -73, -73, -72, -73, -75, -77, -80, -82,
  102440. -88, -93, -100, -107, -114, -999, -999, -999,
  102441. -999, -999, -999, -999, -999, -999, -999, -999,
  102442. -999, -999, -999, -999, -999, -999, -999, -999,
  102443. -999, -999, -999, -999, -999, -999, -999, -999},
  102444. {-999, -999, -999, -110, -105, -101, -96, -90,
  102445. -86, -81, -77, -73, -69, -66, -61, -62,
  102446. -66, -64, -62, -65, -66, -70, -72, -76,
  102447. -81, -80, -84, -90, -95, -102, -110, -999,
  102448. -999, -999, -999, -999, -999, -999, -999, -999,
  102449. -999, -999, -999, -999, -999, -999, -999, -999,
  102450. -999, -999, -999, -999, -999, -999, -999, -999},
  102451. {-999, -999, -999, -107, -103, -97, -92, -88,
  102452. -83, -79, -74, -70, -66, -59, -53, -58,
  102453. -62, -55, -54, -54, -54, -58, -61, -62,
  102454. -72, -70, -72, -75, -78, -80, -81, -80,
  102455. -83, -83, -88, -93, -100, -107, -115, -999,
  102456. -999, -999, -999, -999, -999, -999, -999, -999,
  102457. -999, -999, -999, -999, -999, -999, -999, -999},
  102458. {-999, -999, -999, -105, -100, -95, -90, -85,
  102459. -80, -75, -70, -66, -62, -56, -48, -44,
  102460. -48, -46, -46, -43, -46, -48, -48, -51,
  102461. -58, -58, -59, -60, -62, -62, -61, -61,
  102462. -65, -64, -65, -68, -70, -74, -75, -78,
  102463. -81, -86, -95, -110, -999, -999, -999, -999,
  102464. -999, -999, -999, -999, -999, -999, -999, -999},
  102465. {-999, -999, -105, -100, -95, -90, -85, -80,
  102466. -75, -70, -65, -61, -55, -49, -39, -33,
  102467. -40, -35, -32, -38, -40, -33, -35, -37,
  102468. -46, -41, -45, -44, -46, -42, -45, -46,
  102469. -52, -50, -50, -50, -54, -54, -55, -57,
  102470. -62, -64, -66, -68, -70, -76, -81, -90,
  102471. -100, -110, -999, -999, -999, -999, -999, -999}},
  102472. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102473. -105, -98, -90, -85, -82, -83, -80, -78,
  102474. -84, -79, -80, -83, -87, -89, -91, -93,
  102475. -99, -106, -117, -999, -999, -999, -999, -999,
  102476. -999, -999, -999, -999, -999, -999, -999, -999,
  102477. -999, -999, -999, -999, -999, -999, -999, -999,
  102478. -999, -999, -999, -999, -999, -999, -999, -999},
  102479. {-999, -999, -999, -999, -999, -999, -999, -999,
  102480. -105, -98, -90, -85, -80, -75, -70, -68,
  102481. -74, -72, -74, -77, -80, -82, -85, -87,
  102482. -92, -89, -91, -95, -100, -106, -112, -999,
  102483. -999, -999, -999, -999, -999, -999, -999, -999,
  102484. -999, -999, -999, -999, -999, -999, -999, -999,
  102485. -999, -999, -999, -999, -999, -999, -999, -999},
  102486. {-999, -999, -999, -999, -999, -999, -999, -999,
  102487. -105, -98, -90, -83, -75, -71, -63, -64,
  102488. -67, -62, -64, -67, -70, -73, -77, -81,
  102489. -84, -83, -85, -89, -90, -93, -98, -104,
  102490. -109, -114, -999, -999, -999, -999, -999, -999,
  102491. -999, -999, -999, -999, -999, -999, -999, -999,
  102492. -999, -999, -999, -999, -999, -999, -999, -999},
  102493. {-999, -999, -999, -999, -999, -999, -999, -999,
  102494. -103, -96, -88, -81, -75, -68, -58, -54,
  102495. -56, -54, -56, -56, -58, -60, -63, -66,
  102496. -74, -69, -72, -72, -75, -74, -77, -81,
  102497. -81, -82, -84, -87, -93, -96, -99, -104,
  102498. -110, -999, -999, -999, -999, -999, -999, -999,
  102499. -999, -999, -999, -999, -999, -999, -999, -999},
  102500. {-999, -999, -999, -999, -999, -108, -102, -96,
  102501. -91, -85, -80, -74, -68, -60, -51, -46,
  102502. -48, -46, -43, -45, -47, -47, -49, -48,
  102503. -56, -53, -55, -58, -57, -63, -58, -60,
  102504. -66, -64, -67, -70, -70, -74, -77, -84,
  102505. -86, -89, -91, -93, -94, -101, -109, -118,
  102506. -999, -999, -999, -999, -999, -999, -999, -999},
  102507. {-999, -999, -999, -108, -103, -98, -93, -88,
  102508. -83, -78, -73, -68, -60, -53, -44, -35,
  102509. -38, -38, -34, -34, -36, -40, -41, -44,
  102510. -51, -45, -46, -47, -46, -54, -50, -49,
  102511. -50, -50, -50, -51, -54, -57, -58, -60,
  102512. -66, -66, -66, -64, -65, -68, -77, -82,
  102513. -87, -95, -110, -999, -999, -999, -999, -999}},
  102514. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102515. -107, -102, -97, -92, -87, -83, -78, -75,
  102516. -82, -79, -83, -85, -89, -92, -95, -98,
  102517. -101, -105, -109, -113, -999, -999, -999, -999,
  102518. -999, -999, -999, -999, -999, -999, -999, -999,
  102519. -999, -999, -999, -999, -999, -999, -999, -999,
  102520. -999, -999, -999, -999, -999, -999, -999, -999},
  102521. {-999, -999, -999, -999, -999, -999, -999, -106,
  102522. -100, -95, -90, -86, -81, -78, -74, -69,
  102523. -74, -74, -76, -79, -83, -84, -86, -89,
  102524. -92, -97, -93, -100, -103, -107, -110, -999,
  102525. -999, -999, -999, -999, -999, -999, -999, -999,
  102526. -999, -999, -999, -999, -999, -999, -999, -999,
  102527. -999, -999, -999, -999, -999, -999, -999, -999},
  102528. {-999, -999, -999, -999, -999, -999, -106, -100,
  102529. -95, -90, -87, -83, -80, -75, -69, -60,
  102530. -66, -66, -68, -70, -74, -78, -79, -81,
  102531. -81, -83, -84, -87, -93, -96, -99, -103,
  102532. -107, -110, -999, -999, -999, -999, -999, -999,
  102533. -999, -999, -999, -999, -999, -999, -999, -999,
  102534. -999, -999, -999, -999, -999, -999, -999, -999},
  102535. {-999, -999, -999, -999, -999, -108, -103, -98,
  102536. -93, -89, -85, -82, -78, -71, -62, -55,
  102537. -58, -58, -54, -54, -55, -59, -61, -62,
  102538. -70, -66, -66, -67, -70, -72, -75, -78,
  102539. -84, -84, -84, -88, -91, -90, -95, -98,
  102540. -102, -103, -106, -110, -999, -999, -999, -999,
  102541. -999, -999, -999, -999, -999, -999, -999, -999},
  102542. {-999, -999, -999, -999, -108, -103, -98, -94,
  102543. -90, -87, -82, -79, -73, -67, -58, -47,
  102544. -50, -45, -41, -45, -48, -44, -44, -49,
  102545. -54, -51, -48, -47, -49, -50, -51, -57,
  102546. -58, -60, -63, -69, -70, -69, -71, -74,
  102547. -78, -82, -90, -95, -101, -105, -110, -999,
  102548. -999, -999, -999, -999, -999, -999, -999, -999},
  102549. {-999, -999, -999, -105, -101, -97, -93, -90,
  102550. -85, -80, -77, -72, -65, -56, -48, -37,
  102551. -40, -36, -34, -40, -50, -47, -38, -41,
  102552. -47, -38, -35, -39, -38, -43, -40, -45,
  102553. -50, -45, -44, -47, -50, -55, -48, -48,
  102554. -52, -66, -70, -76, -82, -90, -97, -105,
  102555. -110, -999, -999, -999, -999, -999, -999, -999}},
  102556. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102557. -999, -108, -103, -98, -93, -86, -79, -76,
  102558. -83, -81, -85, -87, -89, -93, -98, -102,
  102559. -107, -112, -999, -999, -999, -999, -999, -999,
  102560. -999, -999, -999, -999, -999, -999, -999, -999,
  102561. -999, -999, -999, -999, -999, -999, -999, -999,
  102562. -999, -999, -999, -999, -999, -999, -999, -999},
  102563. {-999, -999, -999, -999, -999, -999, -999, -999,
  102564. -999, -108, -103, -98, -93, -86, -79, -71,
  102565. -77, -74, -77, -79, -81, -84, -85, -90,
  102566. -92, -93, -92, -98, -101, -108, -112, -999,
  102567. -999, -999, -999, -999, -999, -999, -999, -999,
  102568. -999, -999, -999, -999, -999, -999, -999, -999,
  102569. -999, -999, -999, -999, -999, -999, -999, -999},
  102570. {-999, -999, -999, -999, -999, -999, -999, -999,
  102571. -108, -103, -98, -93, -87, -78, -68, -65,
  102572. -66, -62, -65, -67, -70, -73, -75, -78,
  102573. -82, -82, -83, -84, -91, -93, -98, -102,
  102574. -106, -110, -999, -999, -999, -999, -999, -999,
  102575. -999, -999, -999, -999, -999, -999, -999, -999,
  102576. -999, -999, -999, -999, -999, -999, -999, -999},
  102577. {-999, -999, -999, -999, -999, -999, -999, -999,
  102578. -105, -100, -95, -90, -82, -74, -62, -57,
  102579. -58, -56, -51, -52, -52, -54, -54, -58,
  102580. -66, -59, -60, -63, -66, -69, -73, -79,
  102581. -83, -84, -80, -81, -81, -82, -88, -92,
  102582. -98, -105, -113, -999, -999, -999, -999, -999,
  102583. -999, -999, -999, -999, -999, -999, -999, -999},
  102584. {-999, -999, -999, -999, -999, -999, -999, -107,
  102585. -102, -97, -92, -84, -79, -69, -57, -47,
  102586. -52, -47, -44, -45, -50, -52, -42, -42,
  102587. -53, -43, -43, -48, -51, -56, -55, -52,
  102588. -57, -59, -61, -62, -67, -71, -78, -83,
  102589. -86, -94, -98, -103, -110, -999, -999, -999,
  102590. -999, -999, -999, -999, -999, -999, -999, -999},
  102591. {-999, -999, -999, -999, -999, -999, -105, -100,
  102592. -95, -90, -84, -78, -70, -61, -51, -41,
  102593. -40, -38, -40, -46, -52, -51, -41, -40,
  102594. -46, -40, -38, -38, -41, -46, -41, -46,
  102595. -47, -43, -43, -45, -41, -45, -56, -67,
  102596. -68, -83, -87, -90, -95, -102, -107, -113,
  102597. -999, -999, -999, -999, -999, -999, -999, -999}},
  102598. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102599. -999, -109, -105, -101, -96, -91, -84, -77,
  102600. -82, -82, -85, -89, -94, -100, -106, -110,
  102601. -999, -999, -999, -999, -999, -999, -999, -999,
  102602. -999, -999, -999, -999, -999, -999, -999, -999,
  102603. -999, -999, -999, -999, -999, -999, -999, -999,
  102604. -999, -999, -999, -999, -999, -999, -999, -999},
  102605. {-999, -999, -999, -999, -999, -999, -999, -999,
  102606. -999, -106, -103, -98, -92, -85, -80, -71,
  102607. -75, -72, -76, -80, -84, -86, -89, -93,
  102608. -100, -107, -113, -999, -999, -999, -999, -999,
  102609. -999, -999, -999, -999, -999, -999, -999, -999,
  102610. -999, -999, -999, -999, -999, -999, -999, -999,
  102611. -999, -999, -999, -999, -999, -999, -999, -999},
  102612. {-999, -999, -999, -999, -999, -999, -999, -107,
  102613. -104, -101, -97, -92, -88, -84, -80, -64,
  102614. -66, -63, -64, -66, -69, -73, -77, -83,
  102615. -83, -86, -91, -98, -104, -111, -999, -999,
  102616. -999, -999, -999, -999, -999, -999, -999, -999,
  102617. -999, -999, -999, -999, -999, -999, -999, -999,
  102618. -999, -999, -999, -999, -999, -999, -999, -999},
  102619. {-999, -999, -999, -999, -999, -999, -999, -107,
  102620. -104, -101, -97, -92, -90, -84, -74, -57,
  102621. -58, -52, -55, -54, -50, -52, -50, -52,
  102622. -63, -62, -69, -76, -77, -78, -78, -79,
  102623. -82, -88, -94, -100, -106, -111, -999, -999,
  102624. -999, -999, -999, -999, -999, -999, -999, -999,
  102625. -999, -999, -999, -999, -999, -999, -999, -999},
  102626. {-999, -999, -999, -999, -999, -999, -106, -102,
  102627. -98, -95, -90, -85, -83, -78, -70, -50,
  102628. -50, -41, -44, -49, -47, -50, -50, -44,
  102629. -55, -46, -47, -48, -48, -54, -49, -49,
  102630. -58, -62, -71, -81, -87, -92, -97, -102,
  102631. -108, -114, -999, -999, -999, -999, -999, -999,
  102632. -999, -999, -999, -999, -999, -999, -999, -999},
  102633. {-999, -999, -999, -999, -999, -999, -106, -102,
  102634. -98, -95, -90, -85, -83, -78, -70, -45,
  102635. -43, -41, -47, -50, -51, -50, -49, -45,
  102636. -47, -41, -44, -41, -39, -43, -38, -37,
  102637. -40, -41, -44, -50, -58, -65, -73, -79,
  102638. -85, -92, -97, -101, -105, -109, -113, -999,
  102639. -999, -999, -999, -999, -999, -999, -999, -999}},
  102640. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102641. -999, -999, -999, -107, -100, -95, -87, -81,
  102642. -85, -83, -88, -93, -100, -107, -114, -999,
  102643. -999, -999, -999, -999, -999, -999, -999, -999,
  102644. -999, -999, -999, -999, -999, -999, -999, -999,
  102645. -999, -999, -999, -999, -999, -999, -999, -999,
  102646. -999, -999, -999, -999, -999, -999, -999, -999},
  102647. {-999, -999, -999, -999, -999, -999, -999, -999,
  102648. -999, -999, -107, -101, -95, -88, -83, -76,
  102649. -73, -72, -79, -84, -90, -95, -100, -105,
  102650. -110, -115, -999, -999, -999, -999, -999, -999,
  102651. -999, -999, -999, -999, -999, -999, -999, -999,
  102652. -999, -999, -999, -999, -999, -999, -999, -999,
  102653. -999, -999, -999, -999, -999, -999, -999, -999},
  102654. {-999, -999, -999, -999, -999, -999, -999, -999,
  102655. -999, -999, -104, -98, -92, -87, -81, -70,
  102656. -65, -62, -67, -71, -74, -80, -85, -91,
  102657. -95, -99, -103, -108, -111, -114, -999, -999,
  102658. -999, -999, -999, -999, -999, -999, -999, -999,
  102659. -999, -999, -999, -999, -999, -999, -999, -999,
  102660. -999, -999, -999, -999, -999, -999, -999, -999},
  102661. {-999, -999, -999, -999, -999, -999, -999, -999,
  102662. -999, -999, -103, -97, -90, -85, -76, -60,
  102663. -56, -54, -60, -62, -61, -56, -63, -65,
  102664. -73, -74, -77, -75, -78, -81, -86, -87,
  102665. -88, -91, -94, -98, -103, -110, -999, -999,
  102666. -999, -999, -999, -999, -999, -999, -999, -999,
  102667. -999, -999, -999, -999, -999, -999, -999, -999},
  102668. {-999, -999, -999, -999, -999, -999, -999, -105,
  102669. -100, -97, -92, -86, -81, -79, -70, -57,
  102670. -51, -47, -51, -58, -60, -56, -53, -50,
  102671. -58, -52, -50, -50, -53, -55, -64, -69,
  102672. -71, -85, -82, -78, -81, -85, -95, -102,
  102673. -112, -999, -999, -999, -999, -999, -999, -999,
  102674. -999, -999, -999, -999, -999, -999, -999, -999},
  102675. {-999, -999, -999, -999, -999, -999, -999, -105,
  102676. -100, -97, -92, -85, -83, -79, -72, -49,
  102677. -40, -43, -43, -54, -56, -51, -50, -40,
  102678. -43, -38, -36, -35, -37, -38, -37, -44,
  102679. -54, -60, -57, -60, -70, -75, -84, -92,
  102680. -103, -112, -999, -999, -999, -999, -999, -999,
  102681. -999, -999, -999, -999, -999, -999, -999, -999}},
  102682. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102683. -999, -999, -999, -110, -102, -95, -89, -82,
  102684. -83, -84, -90, -92, -99, -107, -113, -999,
  102685. -999, -999, -999, -999, -999, -999, -999, -999,
  102686. -999, -999, -999, -999, -999, -999, -999, -999,
  102687. -999, -999, -999, -999, -999, -999, -999, -999,
  102688. -999, -999, -999, -999, -999, -999, -999, -999},
  102689. {-999, -999, -999, -999, -999, -999, -999, -999,
  102690. -999, -999, -107, -101, -95, -89, -83, -72,
  102691. -74, -78, -85, -88, -88, -90, -92, -98,
  102692. -105, -111, -999, -999, -999, -999, -999, -999,
  102693. -999, -999, -999, -999, -999, -999, -999, -999,
  102694. -999, -999, -999, -999, -999, -999, -999, -999,
  102695. -999, -999, -999, -999, -999, -999, -999, -999},
  102696. {-999, -999, -999, -999, -999, -999, -999, -999,
  102697. -999, -109, -103, -97, -93, -87, -81, -70,
  102698. -70, -67, -75, -73, -76, -79, -81, -83,
  102699. -88, -89, -97, -103, -110, -999, -999, -999,
  102700. -999, -999, -999, -999, -999, -999, -999, -999,
  102701. -999, -999, -999, -999, -999, -999, -999, -999,
  102702. -999, -999, -999, -999, -999, -999, -999, -999},
  102703. {-999, -999, -999, -999, -999, -999, -999, -999,
  102704. -999, -107, -100, -94, -88, -83, -75, -63,
  102705. -59, -59, -63, -66, -60, -62, -67, -67,
  102706. -77, -76, -81, -88, -86, -92, -96, -102,
  102707. -109, -116, -999, -999, -999, -999, -999, -999,
  102708. -999, -999, -999, -999, -999, -999, -999, -999,
  102709. -999, -999, -999, -999, -999, -999, -999, -999},
  102710. {-999, -999, -999, -999, -999, -999, -999, -999,
  102711. -999, -105, -98, -92, -86, -81, -73, -56,
  102712. -52, -47, -55, -60, -58, -52, -51, -45,
  102713. -49, -50, -53, -54, -61, -71, -70, -69,
  102714. -78, -79, -87, -90, -96, -104, -112, -999,
  102715. -999, -999, -999, -999, -999, -999, -999, -999,
  102716. -999, -999, -999, -999, -999, -999, -999, -999},
  102717. {-999, -999, -999, -999, -999, -999, -999, -999,
  102718. -999, -103, -96, -90, -86, -78, -70, -51,
  102719. -42, -47, -48, -55, -54, -54, -53, -42,
  102720. -35, -28, -33, -38, -37, -44, -47, -49,
  102721. -54, -63, -68, -78, -82, -89, -94, -99,
  102722. -104, -109, -114, -999, -999, -999, -999, -999,
  102723. -999, -999, -999, -999, -999, -999, -999, -999}},
  102724. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102725. -999, -999, -999, -999, -110, -100, -90, -79,
  102726. -85, -81, -82, -82, -89, -94, -99, -103,
  102727. -109, -115, -999, -999, -999, -999, -999, -999,
  102728. -999, -999, -999, -999, -999, -999, -999, -999,
  102729. -999, -999, -999, -999, -999, -999, -999, -999,
  102730. -999, -999, -999, -999, -999, -999, -999, -999},
  102731. {-999, -999, -999, -999, -999, -999, -999, -999,
  102732. -999, -999, -999, -999, -105, -97, -85, -72,
  102733. -74, -70, -70, -70, -76, -85, -91, -93,
  102734. -97, -103, -109, -115, -999, -999, -999, -999,
  102735. -999, -999, -999, -999, -999, -999, -999, -999,
  102736. -999, -999, -999, -999, -999, -999, -999, -999,
  102737. -999, -999, -999, -999, -999, -999, -999, -999},
  102738. {-999, -999, -999, -999, -999, -999, -999, -999,
  102739. -999, -999, -999, -999, -112, -93, -81, -68,
  102740. -62, -60, -60, -57, -63, -70, -77, -82,
  102741. -90, -93, -98, -104, -109, -113, -999, -999,
  102742. -999, -999, -999, -999, -999, -999, -999, -999,
  102743. -999, -999, -999, -999, -999, -999, -999, -999,
  102744. -999, -999, -999, -999, -999, -999, -999, -999},
  102745. {-999, -999, -999, -999, -999, -999, -999, -999,
  102746. -999, -999, -999, -113, -100, -93, -84, -63,
  102747. -58, -48, -53, -54, -52, -52, -57, -64,
  102748. -66, -76, -83, -81, -85, -85, -90, -95,
  102749. -98, -101, -103, -106, -108, -111, -999, -999,
  102750. -999, -999, -999, -999, -999, -999, -999, -999,
  102751. -999, -999, -999, -999, -999, -999, -999, -999},
  102752. {-999, -999, -999, -999, -999, -999, -999, -999,
  102753. -999, -999, -999, -105, -95, -86, -74, -53,
  102754. -50, -38, -43, -49, -43, -42, -39, -39,
  102755. -46, -52, -57, -56, -72, -69, -74, -81,
  102756. -87, -92, -94, -97, -99, -102, -105, -108,
  102757. -999, -999, -999, -999, -999, -999, -999, -999,
  102758. -999, -999, -999, -999, -999, -999, -999, -999},
  102759. {-999, -999, -999, -999, -999, -999, -999, -999,
  102760. -999, -999, -108, -99, -90, -76, -66, -45,
  102761. -43, -41, -44, -47, -43, -47, -40, -30,
  102762. -31, -31, -39, -33, -40, -41, -43, -53,
  102763. -59, -70, -73, -77, -79, -82, -84, -87,
  102764. -999, -999, -999, -999, -999, -999, -999, -999,
  102765. -999, -999, -999, -999, -999, -999, -999, -999}},
  102766. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102767. -999, -999, -999, -999, -999, -110, -91, -76,
  102768. -75, -85, -93, -98, -104, -110, -999, -999,
  102769. -999, -999, -999, -999, -999, -999, -999, -999,
  102770. -999, -999, -999, -999, -999, -999, -999, -999,
  102771. -999, -999, -999, -999, -999, -999, -999, -999,
  102772. -999, -999, -999, -999, -999, -999, -999, -999},
  102773. {-999, -999, -999, -999, -999, -999, -999, -999,
  102774. -999, -999, -999, -999, -999, -110, -91, -70,
  102775. -70, -75, -86, -89, -94, -98, -101, -106,
  102776. -110, -999, -999, -999, -999, -999, -999, -999,
  102777. -999, -999, -999, -999, -999, -999, -999, -999,
  102778. -999, -999, -999, -999, -999, -999, -999, -999,
  102779. -999, -999, -999, -999, -999, -999, -999, -999},
  102780. {-999, -999, -999, -999, -999, -999, -999, -999,
  102781. -999, -999, -999, -999, -110, -95, -80, -60,
  102782. -65, -64, -74, -83, -88, -91, -95, -99,
  102783. -103, -107, -110, -999, -999, -999, -999, -999,
  102784. -999, -999, -999, -999, -999, -999, -999, -999,
  102785. -999, -999, -999, -999, -999, -999, -999, -999,
  102786. -999, -999, -999, -999, -999, -999, -999, -999},
  102787. {-999, -999, -999, -999, -999, -999, -999, -999,
  102788. -999, -999, -999, -999, -110, -95, -80, -58,
  102789. -55, -49, -66, -68, -71, -78, -78, -80,
  102790. -88, -85, -89, -97, -100, -105, -110, -999,
  102791. -999, -999, -999, -999, -999, -999, -999, -999,
  102792. -999, -999, -999, -999, -999, -999, -999, -999,
  102793. -999, -999, -999, -999, -999, -999, -999, -999},
  102794. {-999, -999, -999, -999, -999, -999, -999, -999,
  102795. -999, -999, -999, -999, -110, -95, -80, -53,
  102796. -52, -41, -59, -59, -49, -58, -56, -63,
  102797. -86, -79, -90, -93, -98, -103, -107, -112,
  102798. -999, -999, -999, -999, -999, -999, -999, -999,
  102799. -999, -999, -999, -999, -999, -999, -999, -999,
  102800. -999, -999, -999, -999, -999, -999, -999, -999},
  102801. {-999, -999, -999, -999, -999, -999, -999, -999,
  102802. -999, -999, -999, -110, -97, -91, -73, -45,
  102803. -40, -33, -53, -61, -49, -54, -50, -50,
  102804. -60, -52, -67, -74, -81, -92, -96, -100,
  102805. -105, -110, -999, -999, -999, -999, -999, -999,
  102806. -999, -999, -999, -999, -999, -999, -999, -999,
  102807. -999, -999, -999, -999, -999, -999, -999, -999}},
  102808. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102809. -999, -999, -999, -113, -106, -99, -92, -77,
  102810. -80, -88, -97, -106, -115, -999, -999, -999,
  102811. -999, -999, -999, -999, -999, -999, -999, -999,
  102812. -999, -999, -999, -999, -999, -999, -999, -999,
  102813. -999, -999, -999, -999, -999, -999, -999, -999,
  102814. -999, -999, -999, -999, -999, -999, -999, -999},
  102815. {-999, -999, -999, -999, -999, -999, -999, -999,
  102816. -999, -999, -116, -109, -102, -95, -89, -74,
  102817. -72, -88, -87, -95, -102, -109, -116, -999,
  102818. -999, -999, -999, -999, -999, -999, -999, -999,
  102819. -999, -999, -999, -999, -999, -999, -999, -999,
  102820. -999, -999, -999, -999, -999, -999, -999, -999,
  102821. -999, -999, -999, -999, -999, -999, -999, -999},
  102822. {-999, -999, -999, -999, -999, -999, -999, -999,
  102823. -999, -999, -116, -109, -102, -95, -89, -75,
  102824. -66, -74, -77, -78, -86, -87, -90, -96,
  102825. -105, -115, -999, -999, -999, -999, -999, -999,
  102826. -999, -999, -999, -999, -999, -999, -999, -999,
  102827. -999, -999, -999, -999, -999, -999, -999, -999,
  102828. -999, -999, -999, -999, -999, -999, -999, -999},
  102829. {-999, -999, -999, -999, -999, -999, -999, -999,
  102830. -999, -999, -115, -108, -101, -94, -88, -66,
  102831. -56, -61, -70, -65, -78, -72, -83, -84,
  102832. -93, -98, -105, -110, -999, -999, -999, -999,
  102833. -999, -999, -999, -999, -999, -999, -999, -999,
  102834. -999, -999, -999, -999, -999, -999, -999, -999,
  102835. -999, -999, -999, -999, -999, -999, -999, -999},
  102836. {-999, -999, -999, -999, -999, -999, -999, -999,
  102837. -999, -999, -110, -105, -95, -89, -82, -57,
  102838. -52, -52, -59, -56, -59, -58, -69, -67,
  102839. -88, -82, -82, -89, -94, -100, -108, -999,
  102840. -999, -999, -999, -999, -999, -999, -999, -999,
  102841. -999, -999, -999, -999, -999, -999, -999, -999,
  102842. -999, -999, -999, -999, -999, -999, -999, -999},
  102843. {-999, -999, -999, -999, -999, -999, -999, -999,
  102844. -999, -110, -101, -96, -90, -83, -77, -54,
  102845. -43, -38, -50, -48, -52, -48, -42, -42,
  102846. -51, -52, -53, -59, -65, -71, -78, -85,
  102847. -95, -999, -999, -999, -999, -999, -999, -999,
  102848. -999, -999, -999, -999, -999, -999, -999, -999,
  102849. -999, -999, -999, -999, -999, -999, -999, -999}},
  102850. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102851. -999, -999, -999, -999, -120, -105, -86, -68,
  102852. -78, -79, -90, -100, -110, -999, -999, -999,
  102853. -999, -999, -999, -999, -999, -999, -999, -999,
  102854. -999, -999, -999, -999, -999, -999, -999, -999,
  102855. -999, -999, -999, -999, -999, -999, -999, -999,
  102856. -999, -999, -999, -999, -999, -999, -999, -999},
  102857. {-999, -999, -999, -999, -999, -999, -999, -999,
  102858. -999, -999, -999, -999, -120, -105, -86, -66,
  102859. -73, -77, -88, -96, -105, -115, -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, -999, -999, -999, -999,
  102863. -999, -999, -999, -999, -999, -999, -999, -999},
  102864. {-999, -999, -999, -999, -999, -999, -999, -999,
  102865. -999, -999, -999, -120, -105, -92, -80, -61,
  102866. -64, -68, -80, -87, -92, -100, -110, -999,
  102867. -999, -999, -999, -999, -999, -999, -999, -999,
  102868. -999, -999, -999, -999, -999, -999, -999, -999,
  102869. -999, -999, -999, -999, -999, -999, -999, -999,
  102870. -999, -999, -999, -999, -999, -999, -999, -999},
  102871. {-999, -999, -999, -999, -999, -999, -999, -999,
  102872. -999, -999, -999, -120, -104, -91, -79, -52,
  102873. -60, -54, -64, -69, -77, -80, -82, -84,
  102874. -85, -87, -88, -90, -999, -999, -999, -999,
  102875. -999, -999, -999, -999, -999, -999, -999, -999,
  102876. -999, -999, -999, -999, -999, -999, -999, -999,
  102877. -999, -999, -999, -999, -999, -999, -999, -999},
  102878. {-999, -999, -999, -999, -999, -999, -999, -999,
  102879. -999, -999, -999, -118, -100, -87, -77, -49,
  102880. -50, -44, -58, -61, -61, -67, -65, -62,
  102881. -62, -62, -65, -68, -999, -999, -999, -999,
  102882. -999, -999, -999, -999, -999, -999, -999, -999,
  102883. -999, -999, -999, -999, -999, -999, -999, -999,
  102884. -999, -999, -999, -999, -999, -999, -999, -999},
  102885. {-999, -999, -999, -999, -999, -999, -999, -999,
  102886. -999, -999, -999, -115, -98, -84, -62, -49,
  102887. -44, -38, -46, -49, -49, -46, -39, -37,
  102888. -39, -40, -42, -43, -999, -999, -999, -999,
  102889. -999, -999, -999, -999, -999, -999, -999, -999,
  102890. -999, -999, -999, -999, -999, -999, -999, -999,
  102891. -999, -999, -999, -999, -999, -999, -999, -999}},
  102892. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102893. -999, -999, -999, -999, -999, -110, -88, -74,
  102894. -77, -82, -82, -85, -90, -94, -99, -104,
  102895. -999, -999, -999, -999, -999, -999, -999, -999,
  102896. -999, -999, -999, -999, -999, -999, -999, -999,
  102897. -999, -999, -999, -999, -999, -999, -999, -999,
  102898. -999, -999, -999, -999, -999, -999, -999, -999},
  102899. {-999, -999, -999, -999, -999, -999, -999, -999,
  102900. -999, -999, -999, -999, -999, -110, -88, -66,
  102901. -70, -81, -80, -81, -84, -88, -91, -93,
  102902. -999, -999, -999, -999, -999, -999, -999, -999,
  102903. -999, -999, -999, -999, -999, -999, -999, -999,
  102904. -999, -999, -999, -999, -999, -999, -999, -999,
  102905. -999, -999, -999, -999, -999, -999, -999, -999},
  102906. {-999, -999, -999, -999, -999, -999, -999, -999,
  102907. -999, -999, -999, -999, -999, -110, -88, -61,
  102908. -63, -70, -71, -74, -77, -80, -83, -85,
  102909. -999, -999, -999, -999, -999, -999, -999, -999,
  102910. -999, -999, -999, -999, -999, -999, -999, -999,
  102911. -999, -999, -999, -999, -999, -999, -999, -999,
  102912. -999, -999, -999, -999, -999, -999, -999, -999},
  102913. {-999, -999, -999, -999, -999, -999, -999, -999,
  102914. -999, -999, -999, -999, -999, -110, -86, -62,
  102915. -63, -62, -62, -58, -52, -50, -50, -52,
  102916. -54, -999, -999, -999, -999, -999, -999, -999,
  102917. -999, -999, -999, -999, -999, -999, -999, -999,
  102918. -999, -999, -999, -999, -999, -999, -999, -999,
  102919. -999, -999, -999, -999, -999, -999, -999, -999},
  102920. {-999, -999, -999, -999, -999, -999, -999, -999,
  102921. -999, -999, -999, -999, -118, -108, -84, -53,
  102922. -50, -50, -50, -55, -47, -45, -40, -40,
  102923. -40, -999, -999, -999, -999, -999, -999, -999,
  102924. -999, -999, -999, -999, -999, -999, -999, -999,
  102925. -999, -999, -999, -999, -999, -999, -999, -999,
  102926. -999, -999, -999, -999, -999, -999, -999, -999},
  102927. {-999, -999, -999, -999, -999, -999, -999, -999,
  102928. -999, -999, -999, -999, -118, -100, -73, -43,
  102929. -37, -42, -43, -53, -38, -37, -35, -35,
  102930. -38, -999, -999, -999, -999, -999, -999, -999,
  102931. -999, -999, -999, -999, -999, -999, -999, -999,
  102932. -999, -999, -999, -999, -999, -999, -999, -999,
  102933. -999, -999, -999, -999, -999, -999, -999, -999}},
  102934. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102935. -999, -999, -999, -110, -100, -91, -84, -74,
  102936. -80, -80, -80, -80, -80, -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, -999, -999, -999, -999,
  102940. -999, -999, -999, -999, -999, -999, -999, -999},
  102941. {-999, -999, -999, -999, -999, -999, -999, -999,
  102942. -999, -999, -999, -110, -100, -91, -84, -74,
  102943. -68, -68, -68, -68, -68, -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, -999, -999, -999, -999, -999,
  102947. -999, -999, -999, -999, -999, -999, -999, -999},
  102948. {-999, -999, -999, -999, -999, -999, -999, -999,
  102949. -999, -999, -999, -110, -100, -86, -78, -70,
  102950. -60, -45, -30, -21, -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, -999, -999, -999, -999, -999,
  102954. -999, -999, -999, -999, -999, -999, -999, -999},
  102955. {-999, -999, -999, -999, -999, -999, -999, -999,
  102956. -999, -999, -999, -110, -100, -87, -78, -67,
  102957. -48, -38, -29, -21, -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, -999, -999, -999, -999, -999,
  102961. -999, -999, -999, -999, -999, -999, -999, -999},
  102962. {-999, -999, -999, -999, -999, -999, -999, -999,
  102963. -999, -999, -999, -110, -100, -86, -69, -56,
  102964. -45, -35, -33, -29, -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, -999, -999, -999, -999, -999,
  102968. -999, -999, -999, -999, -999, -999, -999, -999},
  102969. {-999, -999, -999, -999, -999, -999, -999, -999,
  102970. -999, -999, -999, -110, -100, -83, -71, -48,
  102971. -27, -38, -37, -34, -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, -999, -999, -999, -999, -999,
  102975. -999, -999, -999, -999, -999, -999, -999, -999}}
  102976. };
  102977. #endif
  102978. /*** End of inlined file: masking.h ***/
  102979. #define NEGINF -9999.f
  102980. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  102981. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  102982. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  102983. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102984. vorbis_info_psy_global *gi=&ci->psy_g_param;
  102985. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  102986. look->channels=vi->channels;
  102987. look->ampmax=-9999.;
  102988. look->gi=gi;
  102989. return(look);
  102990. }
  102991. void _vp_global_free(vorbis_look_psy_global *look){
  102992. if(look){
  102993. memset(look,0,sizeof(*look));
  102994. _ogg_free(look);
  102995. }
  102996. }
  102997. void _vi_gpsy_free(vorbis_info_psy_global *i){
  102998. if(i){
  102999. memset(i,0,sizeof(*i));
  103000. _ogg_free(i);
  103001. }
  103002. }
  103003. void _vi_psy_free(vorbis_info_psy *i){
  103004. if(i){
  103005. memset(i,0,sizeof(*i));
  103006. _ogg_free(i);
  103007. }
  103008. }
  103009. static void min_curve(float *c,
  103010. float *c2){
  103011. int i;
  103012. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103013. }
  103014. static void max_curve(float *c,
  103015. float *c2){
  103016. int i;
  103017. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103018. }
  103019. static void attenuate_curve(float *c,float att){
  103020. int i;
  103021. for(i=0;i<EHMER_MAX;i++)
  103022. c[i]+=att;
  103023. }
  103024. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103025. float center_boost, float center_decay_rate){
  103026. int i,j,k,m;
  103027. float ath[EHMER_MAX];
  103028. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103029. float athc[P_LEVELS][EHMER_MAX];
  103030. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103031. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103032. memset(workc,0,sizeof(workc));
  103033. for(i=0;i<P_BANDS;i++){
  103034. int ath_offset=i*4;
  103035. for(j=0;j<EHMER_MAX;j++){
  103036. float min=999.;
  103037. for(k=0;k<4;k++)
  103038. if(j+k+ath_offset<MAX_ATH){
  103039. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103040. }else{
  103041. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103042. }
  103043. ath[j]=min;
  103044. }
  103045. for(j=0;j<6;j++)
  103046. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103047. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103048. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103049. for(j=0;j<P_LEVELS;j++){
  103050. for(k=0;k<EHMER_MAX;k++){
  103051. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103052. if(adj<0. && center_boost>0)adj=0.;
  103053. if(adj>0. && center_boost<0)adj=0.;
  103054. workc[i][j][k]+=adj;
  103055. }
  103056. }
  103057. for(j=0;j<P_LEVELS;j++){
  103058. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103059. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103060. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103061. max_curve(athc[j],workc[i][j]);
  103062. }
  103063. for(j=1;j<P_LEVELS;j++){
  103064. min_curve(athc[j],athc[j-1]);
  103065. min_curve(workc[i][j],athc[j]);
  103066. }
  103067. }
  103068. for(i=0;i<P_BANDS;i++){
  103069. int hi_curve,lo_curve,bin;
  103070. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103071. bin=floor(fromOC(i*.5)/binHz);
  103072. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103073. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103074. if(lo_curve>i)lo_curve=i;
  103075. if(lo_curve<0)lo_curve=0;
  103076. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103077. for(m=0;m<P_LEVELS;m++){
  103078. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103079. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103080. for(k=lo_curve;k<=hi_curve;k++){
  103081. int l=0;
  103082. for(j=0;j<EHMER_MAX;j++){
  103083. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103084. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103085. if(lo_bin<0)lo_bin=0;
  103086. if(lo_bin>n)lo_bin=n;
  103087. if(lo_bin<l)l=lo_bin;
  103088. if(hi_bin<0)hi_bin=0;
  103089. if(hi_bin>n)hi_bin=n;
  103090. for(;l<hi_bin && l<n;l++)
  103091. if(brute_buffer[l]>workc[k][m][j])
  103092. brute_buffer[l]=workc[k][m][j];
  103093. }
  103094. for(;l<n;l++)
  103095. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103096. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103097. }
  103098. if(i+1<P_BANDS){
  103099. int l=0;
  103100. k=i+1;
  103101. for(j=0;j<EHMER_MAX;j++){
  103102. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103103. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103104. if(lo_bin<0)lo_bin=0;
  103105. if(lo_bin>n)lo_bin=n;
  103106. if(lo_bin<l)l=lo_bin;
  103107. if(hi_bin<0)hi_bin=0;
  103108. if(hi_bin>n)hi_bin=n;
  103109. for(;l<hi_bin && l<n;l++)
  103110. if(brute_buffer[l]>workc[k][m][j])
  103111. brute_buffer[l]=workc[k][m][j];
  103112. }
  103113. for(;l<n;l++)
  103114. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103115. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103116. }
  103117. for(j=0;j<EHMER_MAX;j++){
  103118. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103119. if(bin<0){
  103120. ret[i][m][j+2]=-999.;
  103121. }else{
  103122. if(bin>=n){
  103123. ret[i][m][j+2]=-999.;
  103124. }else{
  103125. ret[i][m][j+2]=brute_buffer[bin];
  103126. }
  103127. }
  103128. }
  103129. for(j=0;j<EHMER_OFFSET;j++)
  103130. if(ret[i][m][j+2]>-200.f)break;
  103131. ret[i][m][0]=j;
  103132. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103133. if(ret[i][m][j+2]>-200.f)
  103134. break;
  103135. ret[i][m][1]=j;
  103136. }
  103137. }
  103138. return(ret);
  103139. }
  103140. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103141. vorbis_info_psy_global *gi,int n,long rate){
  103142. long i,j,lo=-99,hi=1;
  103143. long maxoc;
  103144. memset(p,0,sizeof(*p));
  103145. p->eighth_octave_lines=gi->eighth_octave_lines;
  103146. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103147. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103148. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103149. p->total_octave_lines=maxoc-p->firstoc+1;
  103150. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103151. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103152. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103153. p->vi=vi;
  103154. p->n=n;
  103155. p->rate=rate;
  103156. p->m_val = 1.;
  103157. if(rate < 26000) p->m_val = 0;
  103158. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103159. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103160. for(i=0,j=0;i<MAX_ATH-1;i++){
  103161. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103162. float base=ATH[i];
  103163. if(j<endpos){
  103164. float delta=(ATH[i+1]-base)/(endpos-j);
  103165. for(;j<endpos && j<n;j++){
  103166. p->ath[j]=base+100.;
  103167. base+=delta;
  103168. }
  103169. }
  103170. }
  103171. for(i=0;i<n;i++){
  103172. float bark=toBARK(rate/(2*n)*i);
  103173. for(;lo+vi->noisewindowlomin<i &&
  103174. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103175. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103176. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103177. p->bark[i]=((lo-1)<<16)+(hi-1);
  103178. }
  103179. for(i=0;i<n;i++)
  103180. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103181. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103182. vi->tone_centerboost,vi->tone_decay);
  103183. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103184. for(i=0;i<P_NOISECURVES;i++)
  103185. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103186. for(i=0;i<n;i++){
  103187. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103188. int inthalfoc;
  103189. float del;
  103190. if(halfoc<0)halfoc=0;
  103191. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103192. inthalfoc=(int)halfoc;
  103193. del=halfoc-inthalfoc;
  103194. for(j=0;j<P_NOISECURVES;j++)
  103195. p->noiseoffset[j][i]=
  103196. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103197. p->vi->noiseoff[j][inthalfoc+1]*del;
  103198. }
  103199. #if 0
  103200. {
  103201. static int ls=0;
  103202. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103203. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103204. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103205. }
  103206. #endif
  103207. }
  103208. void _vp_psy_clear(vorbis_look_psy *p){
  103209. int i,j;
  103210. if(p){
  103211. if(p->ath)_ogg_free(p->ath);
  103212. if(p->octave)_ogg_free(p->octave);
  103213. if(p->bark)_ogg_free(p->bark);
  103214. if(p->tonecurves){
  103215. for(i=0;i<P_BANDS;i++){
  103216. for(j=0;j<P_LEVELS;j++){
  103217. _ogg_free(p->tonecurves[i][j]);
  103218. }
  103219. _ogg_free(p->tonecurves[i]);
  103220. }
  103221. _ogg_free(p->tonecurves);
  103222. }
  103223. if(p->noiseoffset){
  103224. for(i=0;i<P_NOISECURVES;i++){
  103225. _ogg_free(p->noiseoffset[i]);
  103226. }
  103227. _ogg_free(p->noiseoffset);
  103228. }
  103229. memset(p,0,sizeof(*p));
  103230. }
  103231. }
  103232. static void seed_curve(float *seed,
  103233. const float **curves,
  103234. float amp,
  103235. int oc, int n,
  103236. int linesper,float dBoffset){
  103237. int i,post1;
  103238. int seedptr;
  103239. const float *posts,*curve;
  103240. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103241. choice=max(choice,0);
  103242. choice=min(choice,P_LEVELS-1);
  103243. posts=curves[choice];
  103244. curve=posts+2;
  103245. post1=(int)posts[1];
  103246. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103247. for(i=posts[0];i<post1;i++){
  103248. if(seedptr>0){
  103249. float lin=amp+curve[i];
  103250. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103251. }
  103252. seedptr+=linesper;
  103253. if(seedptr>=n)break;
  103254. }
  103255. }
  103256. static void seed_loop(vorbis_look_psy *p,
  103257. const float ***curves,
  103258. const float *f,
  103259. const float *flr,
  103260. float *seed,
  103261. float specmax){
  103262. vorbis_info_psy *vi=p->vi;
  103263. long n=p->n,i;
  103264. float dBoffset=vi->max_curve_dB-specmax;
  103265. for(i=0;i<n;i++){
  103266. float max=f[i];
  103267. long oc=p->octave[i];
  103268. while(i+1<n && p->octave[i+1]==oc){
  103269. i++;
  103270. if(f[i]>max)max=f[i];
  103271. }
  103272. if(max+6.f>flr[i]){
  103273. oc=oc>>p->shiftoc;
  103274. if(oc>=P_BANDS)oc=P_BANDS-1;
  103275. if(oc<0)oc=0;
  103276. seed_curve(seed,
  103277. curves[oc],
  103278. max,
  103279. p->octave[i]-p->firstoc,
  103280. p->total_octave_lines,
  103281. p->eighth_octave_lines,
  103282. dBoffset);
  103283. }
  103284. }
  103285. }
  103286. static void seed_chase(float *seeds, int linesper, long n){
  103287. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103288. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103289. long stack=0;
  103290. long pos=0;
  103291. long i;
  103292. for(i=0;i<n;i++){
  103293. if(stack<2){
  103294. posstack[stack]=i;
  103295. ampstack[stack++]=seeds[i];
  103296. }else{
  103297. while(1){
  103298. if(seeds[i]<ampstack[stack-1]){
  103299. posstack[stack]=i;
  103300. ampstack[stack++]=seeds[i];
  103301. break;
  103302. }else{
  103303. if(i<posstack[stack-1]+linesper){
  103304. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103305. i<posstack[stack-2]+linesper){
  103306. stack--;
  103307. continue;
  103308. }
  103309. }
  103310. posstack[stack]=i;
  103311. ampstack[stack++]=seeds[i];
  103312. break;
  103313. }
  103314. }
  103315. }
  103316. }
  103317. for(i=0;i<stack;i++){
  103318. long endpos;
  103319. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103320. endpos=posstack[i+1];
  103321. }else{
  103322. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103323. discarded in short frames */
  103324. }
  103325. if(endpos>n)endpos=n;
  103326. for(;pos<endpos;pos++)
  103327. seeds[pos]=ampstack[i];
  103328. }
  103329. }
  103330. #include<stdio.h>
  103331. static void max_seeds(vorbis_look_psy *p,
  103332. float *seed,
  103333. float *flr){
  103334. long n=p->total_octave_lines;
  103335. int linesper=p->eighth_octave_lines;
  103336. long linpos=0;
  103337. long pos;
  103338. seed_chase(seed,linesper,n); /* for masking */
  103339. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103340. while(linpos+1<p->n){
  103341. float minV=seed[pos];
  103342. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103343. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103344. while(pos+1<=end){
  103345. pos++;
  103346. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103347. minV=seed[pos];
  103348. }
  103349. end=pos+p->firstoc;
  103350. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103351. if(flr[linpos]<minV)flr[linpos]=minV;
  103352. }
  103353. {
  103354. float minV=seed[p->total_octave_lines-1];
  103355. for(;linpos<p->n;linpos++)
  103356. if(flr[linpos]<minV)flr[linpos]=minV;
  103357. }
  103358. }
  103359. static void bark_noise_hybridmp(int n,const long *b,
  103360. const float *f,
  103361. float *noise,
  103362. const float offset,
  103363. const int fixed){
  103364. float *N=(float*) alloca(n*sizeof(*N));
  103365. float *X=(float*) alloca(n*sizeof(*N));
  103366. float *XX=(float*) alloca(n*sizeof(*N));
  103367. float *Y=(float*) alloca(n*sizeof(*N));
  103368. float *XY=(float*) alloca(n*sizeof(*N));
  103369. float tN, tX, tXX, tY, tXY;
  103370. int i;
  103371. int lo, hi;
  103372. float R, A, B, D;
  103373. float w, x, y;
  103374. tN = tX = tXX = tY = tXY = 0.f;
  103375. y = f[0] + offset;
  103376. if (y < 1.f) y = 1.f;
  103377. w = y * y * .5;
  103378. tN += w;
  103379. tX += w;
  103380. tY += w * y;
  103381. N[0] = tN;
  103382. X[0] = tX;
  103383. XX[0] = tXX;
  103384. Y[0] = tY;
  103385. XY[0] = tXY;
  103386. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103387. y = f[i] + offset;
  103388. if (y < 1.f) y = 1.f;
  103389. w = y * y;
  103390. tN += w;
  103391. tX += w * x;
  103392. tXX += w * x * x;
  103393. tY += w * y;
  103394. tXY += w * x * y;
  103395. N[i] = tN;
  103396. X[i] = tX;
  103397. XX[i] = tXX;
  103398. Y[i] = tY;
  103399. XY[i] = tXY;
  103400. }
  103401. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103402. lo = b[i] >> 16;
  103403. if( lo>=0 ) break;
  103404. hi = b[i] & 0xffff;
  103405. tN = N[hi] + N[-lo];
  103406. tX = X[hi] - X[-lo];
  103407. tXX = XX[hi] + XX[-lo];
  103408. tY = Y[hi] + Y[-lo];
  103409. tXY = XY[hi] - XY[-lo];
  103410. A = tY * tXX - tX * tXY;
  103411. B = tN * tXY - tX * tY;
  103412. D = tN * tXX - tX * tX;
  103413. R = (A + x * B) / D;
  103414. if (R < 0.f)
  103415. R = 0.f;
  103416. noise[i] = R - offset;
  103417. }
  103418. for ( ;; i++, x += 1.f) {
  103419. lo = b[i] >> 16;
  103420. hi = b[i] & 0xffff;
  103421. if(hi>=n)break;
  103422. tN = N[hi] - N[lo];
  103423. tX = X[hi] - X[lo];
  103424. tXX = XX[hi] - XX[lo];
  103425. tY = Y[hi] - Y[lo];
  103426. tXY = XY[hi] - XY[lo];
  103427. A = tY * tXX - tX * tXY;
  103428. B = tN * tXY - tX * tY;
  103429. D = tN * tXX - tX * tX;
  103430. R = (A + x * B) / D;
  103431. if (R < 0.f) R = 0.f;
  103432. noise[i] = R - offset;
  103433. }
  103434. for ( ; i < n; i++, x += 1.f) {
  103435. R = (A + x * B) / D;
  103436. if (R < 0.f) R = 0.f;
  103437. noise[i] = R - offset;
  103438. }
  103439. if (fixed <= 0) return;
  103440. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103441. hi = i + fixed / 2;
  103442. lo = hi - fixed;
  103443. if(lo>=0)break;
  103444. tN = N[hi] + N[-lo];
  103445. tX = X[hi] - X[-lo];
  103446. tXX = XX[hi] + XX[-lo];
  103447. tY = Y[hi] + Y[-lo];
  103448. tXY = XY[hi] - XY[-lo];
  103449. A = tY * tXX - tX * tXY;
  103450. B = tN * tXY - tX * tY;
  103451. D = tN * tXX - tX * tX;
  103452. R = (A + x * B) / D;
  103453. if (R - offset < noise[i]) noise[i] = R - offset;
  103454. }
  103455. for ( ;; i++, x += 1.f) {
  103456. hi = i + fixed / 2;
  103457. lo = hi - fixed;
  103458. if(hi>=n)break;
  103459. tN = N[hi] - N[lo];
  103460. tX = X[hi] - X[lo];
  103461. tXX = XX[hi] - XX[lo];
  103462. tY = Y[hi] - Y[lo];
  103463. tXY = XY[hi] - XY[lo];
  103464. A = tY * tXX - tX * tXY;
  103465. B = tN * tXY - tX * tY;
  103466. D = tN * tXX - tX * tX;
  103467. R = (A + x * B) / D;
  103468. if (R - offset < noise[i]) noise[i] = R - offset;
  103469. }
  103470. for ( ; i < n; i++, x += 1.f) {
  103471. R = (A + x * B) / D;
  103472. if (R - offset < noise[i]) noise[i] = R - offset;
  103473. }
  103474. }
  103475. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103476. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103477. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103478. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103479. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103480. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103481. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103482. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103483. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103484. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103485. 973377.F, 913981.F, 858210.F, 805842.F,
  103486. 756669.F, 710497.F, 667142.F, 626433.F,
  103487. 588208.F, 552316.F, 518613.F, 486967.F,
  103488. 457252.F, 429351.F, 403152.F, 378551.F,
  103489. 355452.F, 333762.F, 313396.F, 294273.F,
  103490. 276316.F, 259455.F, 243623.F, 228757.F,
  103491. 214798.F, 201691.F, 189384.F, 177828.F,
  103492. 166977.F, 156788.F, 147221.F, 138237.F,
  103493. 129802.F, 121881.F, 114444.F, 107461.F,
  103494. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103495. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103496. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103497. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103498. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103499. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103500. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103501. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103502. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103503. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103504. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103505. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103506. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103507. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103508. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103509. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103510. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103511. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103512. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103513. 842.910F, 791.475F, 743.179F, 697.830F,
  103514. 655.249F, 615.265F, 577.722F, 542.469F,
  103515. 509.367F, 478.286F, 449.101F, 421.696F,
  103516. 395.964F, 371.803F, 349.115F, 327.812F,
  103517. 307.809F, 289.026F, 271.390F, 254.830F,
  103518. 239.280F, 224.679F, 210.969F, 198.096F,
  103519. 186.008F, 174.658F, 164.000F, 153.993F,
  103520. 144.596F, 135.773F, 127.488F, 119.708F,
  103521. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103522. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103523. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103524. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103525. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103526. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103527. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103528. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103529. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103530. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103531. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103532. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103533. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103534. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103535. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103536. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103537. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103538. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103539. 1.20790F, 1.13419F, 1.06499F, 1.F
  103540. };
  103541. void _vp_remove_floor(vorbis_look_psy *p,
  103542. float *mdct,
  103543. int *codedflr,
  103544. float *residue,
  103545. int sliding_lowpass){
  103546. int i,n=p->n;
  103547. if(sliding_lowpass>n)sliding_lowpass=n;
  103548. for(i=0;i<sliding_lowpass;i++){
  103549. residue[i]=
  103550. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103551. }
  103552. for(;i<n;i++)
  103553. residue[i]=0.;
  103554. }
  103555. void _vp_noisemask(vorbis_look_psy *p,
  103556. float *logmdct,
  103557. float *logmask){
  103558. int i,n=p->n;
  103559. float *work=(float*) alloca(n*sizeof(*work));
  103560. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103561. 140.,-1);
  103562. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103563. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103564. p->vi->noisewindowfixed);
  103565. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103566. #if 0
  103567. {
  103568. static int seq=0;
  103569. float work2[n];
  103570. for(i=0;i<n;i++){
  103571. work2[i]=logmask[i]+work[i];
  103572. }
  103573. if(seq&1)
  103574. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103575. else
  103576. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103577. if(seq&1)
  103578. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103579. else
  103580. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103581. seq++;
  103582. }
  103583. #endif
  103584. for(i=0;i<n;i++){
  103585. int dB=logmask[i]+.5;
  103586. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103587. if(dB<0)dB=0;
  103588. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103589. }
  103590. }
  103591. void _vp_tonemask(vorbis_look_psy *p,
  103592. float *logfft,
  103593. float *logmask,
  103594. float global_specmax,
  103595. float local_specmax){
  103596. int i,n=p->n;
  103597. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103598. float att=local_specmax+p->vi->ath_adjatt;
  103599. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103600. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103601. for(i=0;i<n;i++)
  103602. logmask[i]=p->ath[i]+att;
  103603. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103604. max_seeds(p,seed,logmask);
  103605. }
  103606. void _vp_offset_and_mix(vorbis_look_psy *p,
  103607. float *noise,
  103608. float *tone,
  103609. int offset_select,
  103610. float *logmask,
  103611. float *mdct,
  103612. float *logmdct){
  103613. int i,n=p->n;
  103614. float de, coeffi, cx;/* AoTuV */
  103615. float toneatt=p->vi->tone_masteratt[offset_select];
  103616. cx = p->m_val;
  103617. for(i=0;i<n;i++){
  103618. float val= noise[i]+p->noiseoffset[offset_select][i];
  103619. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103620. logmask[i]=max(val,tone[i]+toneatt);
  103621. if(offset_select == 1) {
  103622. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103623. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103624. if(val > coeffi){
  103625. de = 1.0-((val-coeffi)*0.005*cx);
  103626. if(de < 0) de = 0.0001;
  103627. }else
  103628. de = 1.0-((val-coeffi)*0.0003*cx);
  103629. mdct[i] *= de;
  103630. }
  103631. }
  103632. }
  103633. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103634. vorbis_info *vi=vd->vi;
  103635. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103636. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103637. int n=ci->blocksizes[vd->W]/2;
  103638. float secs=(float)n/vi->rate;
  103639. amp+=secs*gi->ampmax_att_per_sec;
  103640. if(amp<-9999)amp=-9999;
  103641. return(amp);
  103642. }
  103643. static void couple_lossless(float A, float B,
  103644. float *qA, float *qB){
  103645. int test1=fabs(*qA)>fabs(*qB);
  103646. test1-= fabs(*qA)<fabs(*qB);
  103647. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103648. if(test1==1){
  103649. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103650. }else{
  103651. float temp=*qB;
  103652. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103653. *qA=temp;
  103654. }
  103655. if(*qB>fabs(*qA)*1.9999f){
  103656. *qB= -fabs(*qA)*2.f;
  103657. *qA= -*qA;
  103658. }
  103659. }
  103660. static float hypot_lookup[32]={
  103661. -0.009935, -0.011245, -0.012726, -0.014397,
  103662. -0.016282, -0.018407, -0.020800, -0.023494,
  103663. -0.026522, -0.029923, -0.033737, -0.038010,
  103664. -0.042787, -0.048121, -0.054064, -0.060671,
  103665. -0.068000, -0.076109, -0.085054, -0.094892,
  103666. -0.105675, -0.117451, -0.130260, -0.144134,
  103667. -0.159093, -0.175146, -0.192286, -0.210490,
  103668. -0.229718, -0.249913, -0.271001, -0.292893};
  103669. static void precomputed_couple_point(float premag,
  103670. int floorA,int floorB,
  103671. float *mag, float *ang){
  103672. int test=(floorA>floorB)-1;
  103673. int offset=31-abs(floorA-floorB);
  103674. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103675. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103676. *mag=premag*floormag;
  103677. *ang=0.f;
  103678. }
  103679. static float dipole_hypot(float a, float b){
  103680. if(a>0.){
  103681. if(b>0.)return sqrt(a*a+b*b);
  103682. if(a>-b)return sqrt(a*a-b*b);
  103683. return -sqrt(b*b-a*a);
  103684. }
  103685. if(b<0.)return -sqrt(a*a+b*b);
  103686. if(-a>b)return -sqrt(a*a-b*b);
  103687. return sqrt(b*b-a*a);
  103688. }
  103689. static float round_hypot(float a, float b){
  103690. if(a>0.){
  103691. if(b>0.)return sqrt(a*a+b*b);
  103692. if(a>-b)return sqrt(a*a+b*b);
  103693. return -sqrt(b*b+a*a);
  103694. }
  103695. if(b<0.)return -sqrt(a*a+b*b);
  103696. if(-a>b)return -sqrt(a*a+b*b);
  103697. return sqrt(b*b+a*a);
  103698. }
  103699. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103700. vorbis_info_psy_global *g,
  103701. vorbis_look_psy *p,
  103702. vorbis_info_mapping0 *vi,
  103703. float **mdct){
  103704. int i,j,n=p->n;
  103705. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103706. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103707. for(i=0;i<vi->coupling_steps;i++){
  103708. float *mdctM=mdct[vi->coupling_mag[i]];
  103709. float *mdctA=mdct[vi->coupling_ang[i]];
  103710. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103711. for(j=0;j<limit;j++)
  103712. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103713. for(;j<n;j++)
  103714. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103715. }
  103716. return(ret);
  103717. }
  103718. static int apsort(const void *a, const void *b){
  103719. float f1=fabs(**(float**)a);
  103720. float f2=fabs(**(float**)b);
  103721. return (f1<f2)-(f1>f2);
  103722. }
  103723. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103724. vorbis_look_psy *p,
  103725. vorbis_info_mapping0 *vi,
  103726. float **mags){
  103727. if(p->vi->normal_point_p){
  103728. int i,j,k,n=p->n;
  103729. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103730. int partition=p->vi->normal_partition;
  103731. float **work=(float**) alloca(sizeof(*work)*partition);
  103732. for(i=0;i<vi->coupling_steps;i++){
  103733. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103734. for(j=0;j<n;j+=partition){
  103735. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103736. qsort(work,partition,sizeof(*work),apsort);
  103737. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103738. }
  103739. }
  103740. return(ret);
  103741. }
  103742. return(NULL);
  103743. }
  103744. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103745. float *magnitudes,int *sortedindex){
  103746. int i,j,n=p->n;
  103747. vorbis_info_psy *vi=p->vi;
  103748. int partition=vi->normal_partition;
  103749. float **work=(float**) alloca(sizeof(*work)*partition);
  103750. int start=vi->normal_start;
  103751. for(j=start;j<n;j+=partition){
  103752. if(j+partition>n)partition=n-j;
  103753. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103754. qsort(work,partition,sizeof(*work),apsort);
  103755. for(i=0;i<partition;i++){
  103756. sortedindex[i+j-start]=work[i]-magnitudes;
  103757. }
  103758. }
  103759. }
  103760. void _vp_noise_normalize(vorbis_look_psy *p,
  103761. float *in,float *out,int *sortedindex){
  103762. int flag=0,i,j=0,n=p->n;
  103763. vorbis_info_psy *vi=p->vi;
  103764. int partition=vi->normal_partition;
  103765. int start=vi->normal_start;
  103766. if(start>n)start=n;
  103767. if(vi->normal_channel_p){
  103768. for(;j<start;j++)
  103769. out[j]=rint(in[j]);
  103770. for(;j+partition<=n;j+=partition){
  103771. float acc=0.;
  103772. int k;
  103773. for(i=j;i<j+partition;i++)
  103774. acc+=in[i]*in[i];
  103775. for(i=0;i<partition;i++){
  103776. k=sortedindex[i+j-start];
  103777. if(in[k]*in[k]>=.25f){
  103778. out[k]=rint(in[k]);
  103779. acc-=in[k]*in[k];
  103780. flag=1;
  103781. }else{
  103782. if(acc<vi->normal_thresh)break;
  103783. out[k]=unitnorm(in[k]);
  103784. acc-=1.;
  103785. }
  103786. }
  103787. for(;i<partition;i++){
  103788. k=sortedindex[i+j-start];
  103789. out[k]=0.;
  103790. }
  103791. }
  103792. }
  103793. for(;j<n;j++)
  103794. out[j]=rint(in[j]);
  103795. }
  103796. void _vp_couple(int blobno,
  103797. vorbis_info_psy_global *g,
  103798. vorbis_look_psy *p,
  103799. vorbis_info_mapping0 *vi,
  103800. float **res,
  103801. float **mag_memo,
  103802. int **mag_sort,
  103803. int **ifloor,
  103804. int *nonzero,
  103805. int sliding_lowpass){
  103806. int i,j,k,n=p->n;
  103807. for(i=0;i<vi->coupling_steps;i++){
  103808. if(nonzero[vi->coupling_mag[i]] ||
  103809. nonzero[vi->coupling_ang[i]]){
  103810. float *rM=res[vi->coupling_mag[i]];
  103811. float *rA=res[vi->coupling_ang[i]];
  103812. float *qM=rM+n;
  103813. float *qA=rA+n;
  103814. int *floorM=ifloor[vi->coupling_mag[i]];
  103815. int *floorA=ifloor[vi->coupling_ang[i]];
  103816. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103817. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103818. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103819. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103820. int pointlimit=limit;
  103821. nonzero[vi->coupling_mag[i]]=1;
  103822. nonzero[vi->coupling_ang[i]]=1;
  103823. if(n > 1000)
  103824. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103825. for(j=0;j<p->n;j+=partition){
  103826. float acc=0.f;
  103827. for(k=0;k<partition;k++){
  103828. int l=k+j;
  103829. if(l<sliding_lowpass){
  103830. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103831. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103832. precomputed_couple_point(mag_memo[i][l],
  103833. floorM[l],floorA[l],
  103834. qM+l,qA+l);
  103835. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103836. }else{
  103837. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103838. }
  103839. }else{
  103840. qM[l]=0.;
  103841. qA[l]=0.;
  103842. }
  103843. }
  103844. if(p->vi->normal_point_p){
  103845. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103846. int l=mag_sort[i][j+k];
  103847. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103848. qM[l]=unitnorm(qM[l]);
  103849. acc-=1.f;
  103850. }
  103851. }
  103852. }
  103853. }
  103854. }
  103855. }
  103856. }
  103857. void hf_reduction(vorbis_info_psy_global *g,
  103858. vorbis_look_psy *p,
  103859. vorbis_info_mapping0 *vi,
  103860. float **mdct){
  103861. int i,j,n=p->n, de=0.3*p->m_val;
  103862. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103863. for(i=0; i<vi->coupling_steps; i++){
  103864. for(j=limit; j<n; j++)
  103865. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103866. }
  103867. }
  103868. #endif
  103869. /*** End of inlined file: psy.c ***/
  103870. /*** Start of inlined file: registry.c ***/
  103871. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103872. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103873. // tasks..
  103874. #if JUCE_MSVC
  103875. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103876. #endif
  103877. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103878. #if JUCE_USE_OGGVORBIS
  103879. extern vorbis_func_floor floor0_exportbundle;
  103880. extern vorbis_func_floor floor1_exportbundle;
  103881. extern vorbis_func_residue residue0_exportbundle;
  103882. extern vorbis_func_residue residue1_exportbundle;
  103883. extern vorbis_func_residue residue2_exportbundle;
  103884. extern vorbis_func_mapping mapping0_exportbundle;
  103885. vorbis_func_floor *_floor_P[]={
  103886. &floor0_exportbundle,
  103887. &floor1_exportbundle,
  103888. };
  103889. vorbis_func_residue *_residue_P[]={
  103890. &residue0_exportbundle,
  103891. &residue1_exportbundle,
  103892. &residue2_exportbundle,
  103893. };
  103894. vorbis_func_mapping *_mapping_P[]={
  103895. &mapping0_exportbundle,
  103896. };
  103897. #endif
  103898. /*** End of inlined file: registry.c ***/
  103899. /*** Start of inlined file: res0.c ***/
  103900. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103901. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103902. // tasks..
  103903. #if JUCE_MSVC
  103904. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103905. #endif
  103906. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103907. #if JUCE_USE_OGGVORBIS
  103908. #include <stdlib.h>
  103909. #include <string.h>
  103910. #include <math.h>
  103911. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103912. #include <stdio.h>
  103913. #endif
  103914. typedef struct {
  103915. vorbis_info_residue0 *info;
  103916. int parts;
  103917. int stages;
  103918. codebook *fullbooks;
  103919. codebook *phrasebook;
  103920. codebook ***partbooks;
  103921. int partvals;
  103922. int **decodemap;
  103923. long postbits;
  103924. long phrasebits;
  103925. long frames;
  103926. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  103927. int train_seq;
  103928. long *training_data[8][64];
  103929. float training_max[8][64];
  103930. float training_min[8][64];
  103931. float tmin;
  103932. float tmax;
  103933. #endif
  103934. } vorbis_look_residue0;
  103935. void res0_free_info(vorbis_info_residue *i){
  103936. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  103937. if(info){
  103938. memset(info,0,sizeof(*info));
  103939. _ogg_free(info);
  103940. }
  103941. }
  103942. void res0_free_look(vorbis_look_residue *i){
  103943. int j;
  103944. if(i){
  103945. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  103946. #ifdef TRAIN_RES
  103947. {
  103948. int j,k,l;
  103949. for(j=0;j<look->parts;j++){
  103950. for(k=0;k<8;k++)
  103951. if(look->training_data[k][j]){
  103952. char buffer[80];
  103953. FILE *of;
  103954. codebook *statebook=look->partbooks[j][k];
  103955. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  103956. of=fopen(buffer,"a");
  103957. for(l=0;l<statebook->entries;l++)
  103958. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  103959. fclose(of);
  103960. _ogg_free(look->training_data[k][j]);
  103961. look->training_data[k][j]=NULL;
  103962. }
  103963. }
  103964. }
  103965. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  103966. #endif
  103967. for(j=0;j<look->parts;j++)
  103968. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  103969. _ogg_free(look->partbooks);
  103970. for(j=0;j<look->partvals;j++)
  103971. _ogg_free(look->decodemap[j]);
  103972. _ogg_free(look->decodemap);
  103973. memset(look,0,sizeof(*look));
  103974. _ogg_free(look);
  103975. }
  103976. }
  103977. static int icount(unsigned int v){
  103978. int ret=0;
  103979. while(v){
  103980. ret+=v&1;
  103981. v>>=1;
  103982. }
  103983. return(ret);
  103984. }
  103985. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  103986. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103987. int j,acc=0;
  103988. oggpack_write(opb,info->begin,24);
  103989. oggpack_write(opb,info->end,24);
  103990. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  103991. code with a partitioned book */
  103992. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  103993. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  103994. for(j=0;j<info->partitions;j++){
  103995. if(ilog(info->secondstages[j])>3){
  103996. oggpack_write(opb,info->secondstages[j],3);
  103997. oggpack_write(opb,1,1);
  103998. oggpack_write(opb,info->secondstages[j]>>3,5);
  103999. }else
  104000. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104001. acc+=icount(info->secondstages[j]);
  104002. }
  104003. for(j=0;j<acc;j++)
  104004. oggpack_write(opb,info->booklist[j],8);
  104005. }
  104006. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104007. int j,acc=0;
  104008. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104009. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104010. info->begin=oggpack_read(opb,24);
  104011. info->end=oggpack_read(opb,24);
  104012. info->grouping=oggpack_read(opb,24)+1;
  104013. info->partitions=oggpack_read(opb,6)+1;
  104014. info->groupbook=oggpack_read(opb,8);
  104015. for(j=0;j<info->partitions;j++){
  104016. int cascade=oggpack_read(opb,3);
  104017. if(oggpack_read(opb,1))
  104018. cascade|=(oggpack_read(opb,5)<<3);
  104019. info->secondstages[j]=cascade;
  104020. acc+=icount(cascade);
  104021. }
  104022. for(j=0;j<acc;j++)
  104023. info->booklist[j]=oggpack_read(opb,8);
  104024. if(info->groupbook>=ci->books)goto errout;
  104025. for(j=0;j<acc;j++)
  104026. if(info->booklist[j]>=ci->books)goto errout;
  104027. return(info);
  104028. errout:
  104029. res0_free_info(info);
  104030. return(NULL);
  104031. }
  104032. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104033. vorbis_info_residue *vr){
  104034. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104035. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104036. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104037. int j,k,acc=0;
  104038. int dim;
  104039. int maxstage=0;
  104040. look->info=info;
  104041. look->parts=info->partitions;
  104042. look->fullbooks=ci->fullbooks;
  104043. look->phrasebook=ci->fullbooks+info->groupbook;
  104044. dim=look->phrasebook->dim;
  104045. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104046. for(j=0;j<look->parts;j++){
  104047. int stages=ilog(info->secondstages[j]);
  104048. if(stages){
  104049. if(stages>maxstage)maxstage=stages;
  104050. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104051. for(k=0;k<stages;k++)
  104052. if(info->secondstages[j]&(1<<k)){
  104053. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104054. #ifdef TRAIN_RES
  104055. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104056. sizeof(***look->training_data));
  104057. #endif
  104058. }
  104059. }
  104060. }
  104061. look->partvals=rint(pow((float)look->parts,(float)dim));
  104062. look->stages=maxstage;
  104063. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104064. for(j=0;j<look->partvals;j++){
  104065. long val=j;
  104066. long mult=look->partvals/look->parts;
  104067. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104068. for(k=0;k<dim;k++){
  104069. long deco=val/mult;
  104070. val-=deco*mult;
  104071. mult/=look->parts;
  104072. look->decodemap[j][k]=deco;
  104073. }
  104074. }
  104075. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104076. {
  104077. static int train_seq=0;
  104078. look->train_seq=train_seq++;
  104079. }
  104080. #endif
  104081. return(look);
  104082. }
  104083. static int local_book_besterror(codebook *book,float *a){
  104084. int dim=book->dim,i,k,o;
  104085. int best=0;
  104086. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104087. for(k=0,o=dim;k<dim;++k){
  104088. float val=a[--o];
  104089. i=tt->threshvals>>1;
  104090. if(val<tt->quantthresh[i]){
  104091. if(val<tt->quantthresh[i-1]){
  104092. for(--i;i>0;--i)
  104093. if(val>=tt->quantthresh[i-1])
  104094. break;
  104095. }
  104096. }else{
  104097. for(++i;i<tt->threshvals-1;++i)
  104098. if(val<tt->quantthresh[i])break;
  104099. }
  104100. best=(best*tt->quantvals)+tt->quantmap[i];
  104101. }
  104102. if(book->c->lengthlist[best]<=0){
  104103. const static_codebook *c=book->c;
  104104. int i,j;
  104105. float bestf=0.f;
  104106. float *e=book->valuelist;
  104107. best=-1;
  104108. for(i=0;i<book->entries;i++){
  104109. if(c->lengthlist[i]>0){
  104110. float thisx=0.f;
  104111. for(j=0;j<dim;j++){
  104112. float val=(e[j]-a[j]);
  104113. thisx+=val*val;
  104114. }
  104115. if(best==-1 || thisx<bestf){
  104116. bestf=thisx;
  104117. best=i;
  104118. }
  104119. }
  104120. e+=dim;
  104121. }
  104122. }
  104123. {
  104124. float *ptr=book->valuelist+best*dim;
  104125. for(i=0;i<dim;i++)
  104126. *a++ -= *ptr++;
  104127. }
  104128. return(best);
  104129. }
  104130. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104131. codebook *book,long *acc){
  104132. int i,bits=0;
  104133. int dim=book->dim;
  104134. int step=n/dim;
  104135. for(i=0;i<step;i++){
  104136. int entry=local_book_besterror(book,vec+i*dim);
  104137. #ifdef TRAIN_RES
  104138. acc[entry]++;
  104139. #endif
  104140. bits+=vorbis_book_encode(book,entry,opb);
  104141. }
  104142. return(bits);
  104143. }
  104144. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104145. float **in,int ch){
  104146. long i,j,k;
  104147. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104148. vorbis_info_residue0 *info=look->info;
  104149. int samples_per_partition=info->grouping;
  104150. int possible_partitions=info->partitions;
  104151. int n=info->end-info->begin;
  104152. int partvals=n/samples_per_partition;
  104153. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104154. float scale=100./samples_per_partition;
  104155. for(i=0;i<ch;i++){
  104156. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104157. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104158. }
  104159. for(i=0;i<partvals;i++){
  104160. int offset=i*samples_per_partition+info->begin;
  104161. for(j=0;j<ch;j++){
  104162. float max=0.;
  104163. float ent=0.;
  104164. for(k=0;k<samples_per_partition;k++){
  104165. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104166. ent+=fabs(rint(in[j][offset+k]));
  104167. }
  104168. ent*=scale;
  104169. for(k=0;k<possible_partitions-1;k++)
  104170. if(max<=info->classmetric1[k] &&
  104171. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104172. break;
  104173. partword[j][i]=k;
  104174. }
  104175. }
  104176. #ifdef TRAIN_RESAUX
  104177. {
  104178. FILE *of;
  104179. char buffer[80];
  104180. for(i=0;i<ch;i++){
  104181. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104182. of=fopen(buffer,"a");
  104183. for(j=0;j<partvals;j++)
  104184. fprintf(of,"%ld, ",partword[i][j]);
  104185. fprintf(of,"\n");
  104186. fclose(of);
  104187. }
  104188. }
  104189. #endif
  104190. look->frames++;
  104191. return(partword);
  104192. }
  104193. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104194. int ch){
  104195. long i,j,k,l;
  104196. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104197. vorbis_info_residue0 *info=look->info;
  104198. int samples_per_partition=info->grouping;
  104199. int possible_partitions=info->partitions;
  104200. int n=info->end-info->begin;
  104201. int partvals=n/samples_per_partition;
  104202. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104203. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104204. FILE *of;
  104205. char buffer[80];
  104206. #endif
  104207. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104208. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104209. for(i=0,l=info->begin/ch;i<partvals;i++){
  104210. float magmax=0.f;
  104211. float angmax=0.f;
  104212. for(j=0;j<samples_per_partition;j+=ch){
  104213. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104214. for(k=1;k<ch;k++)
  104215. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104216. l++;
  104217. }
  104218. for(j=0;j<possible_partitions-1;j++)
  104219. if(magmax<=info->classmetric1[j] &&
  104220. angmax<=info->classmetric2[j])
  104221. break;
  104222. partword[0][i]=j;
  104223. }
  104224. #ifdef TRAIN_RESAUX
  104225. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104226. of=fopen(buffer,"a");
  104227. for(i=0;i<partvals;i++)
  104228. fprintf(of,"%ld, ",partword[0][i]);
  104229. fprintf(of,"\n");
  104230. fclose(of);
  104231. #endif
  104232. look->frames++;
  104233. return(partword);
  104234. }
  104235. static int _01forward(oggpack_buffer *opb,
  104236. vorbis_block *vb,vorbis_look_residue *vl,
  104237. float **in,int ch,
  104238. long **partword,
  104239. int (*encode)(oggpack_buffer *,float *,int,
  104240. codebook *,long *)){
  104241. long i,j,k,s;
  104242. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104243. vorbis_info_residue0 *info=look->info;
  104244. int samples_per_partition=info->grouping;
  104245. int possible_partitions=info->partitions;
  104246. int partitions_per_word=look->phrasebook->dim;
  104247. int n=info->end-info->begin;
  104248. int partvals=n/samples_per_partition;
  104249. long resbits[128];
  104250. long resvals[128];
  104251. #ifdef TRAIN_RES
  104252. for(i=0;i<ch;i++)
  104253. for(j=info->begin;j<info->end;j++){
  104254. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104255. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104256. }
  104257. #endif
  104258. memset(resbits,0,sizeof(resbits));
  104259. memset(resvals,0,sizeof(resvals));
  104260. for(s=0;s<look->stages;s++){
  104261. for(i=0;i<partvals;){
  104262. if(s==0){
  104263. for(j=0;j<ch;j++){
  104264. long val=partword[j][i];
  104265. for(k=1;k<partitions_per_word;k++){
  104266. val*=possible_partitions;
  104267. if(i+k<partvals)
  104268. val+=partword[j][i+k];
  104269. }
  104270. if(val<look->phrasebook->entries)
  104271. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104272. #if 0 /*def TRAIN_RES*/
  104273. else
  104274. fprintf(stderr,"!");
  104275. #endif
  104276. }
  104277. }
  104278. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104279. long offset=i*samples_per_partition+info->begin;
  104280. for(j=0;j<ch;j++){
  104281. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104282. if(info->secondstages[partword[j][i]]&(1<<s)){
  104283. codebook *statebook=look->partbooks[partword[j][i]][s];
  104284. if(statebook){
  104285. int ret;
  104286. long *accumulator=NULL;
  104287. #ifdef TRAIN_RES
  104288. accumulator=look->training_data[s][partword[j][i]];
  104289. {
  104290. int l;
  104291. float *samples=in[j]+offset;
  104292. for(l=0;l<samples_per_partition;l++){
  104293. if(samples[l]<look->training_min[s][partword[j][i]])
  104294. look->training_min[s][partword[j][i]]=samples[l];
  104295. if(samples[l]>look->training_max[s][partword[j][i]])
  104296. look->training_max[s][partword[j][i]]=samples[l];
  104297. }
  104298. }
  104299. #endif
  104300. ret=encode(opb,in[j]+offset,samples_per_partition,
  104301. statebook,accumulator);
  104302. look->postbits+=ret;
  104303. resbits[partword[j][i]]+=ret;
  104304. }
  104305. }
  104306. }
  104307. }
  104308. }
  104309. }
  104310. return(0);
  104311. }
  104312. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104313. float **in,int ch,
  104314. long (*decodepart)(codebook *, float *,
  104315. oggpack_buffer *,int)){
  104316. long i,j,k,l,s;
  104317. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104318. vorbis_info_residue0 *info=look->info;
  104319. int samples_per_partition=info->grouping;
  104320. int partitions_per_word=look->phrasebook->dim;
  104321. int n=info->end-info->begin;
  104322. int partvals=n/samples_per_partition;
  104323. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104324. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104325. for(j=0;j<ch;j++)
  104326. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104327. for(s=0;s<look->stages;s++){
  104328. for(i=0,l=0;i<partvals;l++){
  104329. if(s==0){
  104330. for(j=0;j<ch;j++){
  104331. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104332. if(temp==-1)goto eopbreak;
  104333. partword[j][l]=look->decodemap[temp];
  104334. if(partword[j][l]==NULL)goto errout;
  104335. }
  104336. }
  104337. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104338. for(j=0;j<ch;j++){
  104339. long offset=info->begin+i*samples_per_partition;
  104340. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104341. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104342. if(stagebook){
  104343. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104344. samples_per_partition)==-1)goto eopbreak;
  104345. }
  104346. }
  104347. }
  104348. }
  104349. }
  104350. errout:
  104351. eopbreak:
  104352. return(0);
  104353. }
  104354. #if 0
  104355. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104356. float **in,int *nonzero,int ch){
  104357. int i,used=0;
  104358. for(i=0;i<ch;i++)
  104359. if(nonzero[i])
  104360. in[used++]=in[i];
  104361. if(used)
  104362. return(_01class(vb,vl,in,used));
  104363. else
  104364. return(0);
  104365. }
  104366. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104367. float **in,float **out,int *nonzero,int ch,
  104368. long **partword){
  104369. int i,j,used=0,n=vb->pcmend/2;
  104370. for(i=0;i<ch;i++)
  104371. if(nonzero[i]){
  104372. if(out)
  104373. for(j=0;j<n;j++)
  104374. out[i][j]+=in[i][j];
  104375. in[used++]=in[i];
  104376. }
  104377. if(used){
  104378. int ret=_01forward(vb,vl,in,used,partword,
  104379. _interleaved_encodepart);
  104380. if(out){
  104381. used=0;
  104382. for(i=0;i<ch;i++)
  104383. if(nonzero[i]){
  104384. for(j=0;j<n;j++)
  104385. out[i][j]-=in[used][j];
  104386. used++;
  104387. }
  104388. }
  104389. return(ret);
  104390. }else{
  104391. return(0);
  104392. }
  104393. }
  104394. #endif
  104395. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104396. float **in,int *nonzero,int ch){
  104397. int i,used=0;
  104398. for(i=0;i<ch;i++)
  104399. if(nonzero[i])
  104400. in[used++]=in[i];
  104401. if(used)
  104402. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104403. else
  104404. return(0);
  104405. }
  104406. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104407. float **in,float **out,int *nonzero,int ch,
  104408. long **partword){
  104409. int i,j,used=0,n=vb->pcmend/2;
  104410. for(i=0;i<ch;i++)
  104411. if(nonzero[i]){
  104412. if(out)
  104413. for(j=0;j<n;j++)
  104414. out[i][j]+=in[i][j];
  104415. in[used++]=in[i];
  104416. }
  104417. if(used){
  104418. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104419. if(out){
  104420. used=0;
  104421. for(i=0;i<ch;i++)
  104422. if(nonzero[i]){
  104423. for(j=0;j<n;j++)
  104424. out[i][j]-=in[used][j];
  104425. used++;
  104426. }
  104427. }
  104428. return(ret);
  104429. }else{
  104430. return(0);
  104431. }
  104432. }
  104433. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104434. float **in,int *nonzero,int ch){
  104435. int i,used=0;
  104436. for(i=0;i<ch;i++)
  104437. if(nonzero[i])
  104438. in[used++]=in[i];
  104439. if(used)
  104440. return(_01class(vb,vl,in,used));
  104441. else
  104442. return(0);
  104443. }
  104444. int res1_inverse(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(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104452. else
  104453. return(0);
  104454. }
  104455. long **res2_class(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])used++;
  104460. if(used)
  104461. return(_2class(vb,vl,in,ch));
  104462. else
  104463. return(0);
  104464. }
  104465. int res2_forward(oggpack_buffer *opb,
  104466. vorbis_block *vb,vorbis_look_residue *vl,
  104467. float **in,float **out,int *nonzero,int ch,
  104468. long **partword){
  104469. long i,j,k,n=vb->pcmend/2,used=0;
  104470. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104471. for(i=0;i<ch;i++){
  104472. float *pcm=in[i];
  104473. if(nonzero[i])used++;
  104474. for(j=0,k=i;j<n;j++,k+=ch)
  104475. work[k]=pcm[j];
  104476. }
  104477. if(used){
  104478. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104479. if(out){
  104480. for(i=0;i<ch;i++){
  104481. float *pcm=in[i];
  104482. float *sofar=out[i];
  104483. for(j=0,k=i;j<n;j++,k+=ch)
  104484. sofar[j]+=pcm[j]-work[k];
  104485. }
  104486. }
  104487. return(ret);
  104488. }else{
  104489. return(0);
  104490. }
  104491. }
  104492. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104493. float **in,int *nonzero,int ch){
  104494. long i,k,l,s;
  104495. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104496. vorbis_info_residue0 *info=look->info;
  104497. int samples_per_partition=info->grouping;
  104498. int partitions_per_word=look->phrasebook->dim;
  104499. int n=info->end-info->begin;
  104500. int partvals=n/samples_per_partition;
  104501. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104502. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104503. for(i=0;i<ch;i++)if(nonzero[i])break;
  104504. if(i==ch)return(0); /* no nonzero vectors */
  104505. for(s=0;s<look->stages;s++){
  104506. for(i=0,l=0;i<partvals;l++){
  104507. if(s==0){
  104508. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104509. if(temp==-1)goto eopbreak;
  104510. partword[l]=look->decodemap[temp];
  104511. if(partword[l]==NULL)goto errout;
  104512. }
  104513. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104514. if(info->secondstages[partword[l][k]]&(1<<s)){
  104515. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104516. if(stagebook){
  104517. if(vorbis_book_decodevv_add(stagebook,in,
  104518. i*samples_per_partition+info->begin,ch,
  104519. &vb->opb,samples_per_partition)==-1)
  104520. goto eopbreak;
  104521. }
  104522. }
  104523. }
  104524. }
  104525. errout:
  104526. eopbreak:
  104527. return(0);
  104528. }
  104529. vorbis_func_residue residue0_exportbundle={
  104530. NULL,
  104531. &res0_unpack,
  104532. &res0_look,
  104533. &res0_free_info,
  104534. &res0_free_look,
  104535. NULL,
  104536. NULL,
  104537. &res0_inverse
  104538. };
  104539. vorbis_func_residue residue1_exportbundle={
  104540. &res0_pack,
  104541. &res0_unpack,
  104542. &res0_look,
  104543. &res0_free_info,
  104544. &res0_free_look,
  104545. &res1_class,
  104546. &res1_forward,
  104547. &res1_inverse
  104548. };
  104549. vorbis_func_residue residue2_exportbundle={
  104550. &res0_pack,
  104551. &res0_unpack,
  104552. &res0_look,
  104553. &res0_free_info,
  104554. &res0_free_look,
  104555. &res2_class,
  104556. &res2_forward,
  104557. &res2_inverse
  104558. };
  104559. #endif
  104560. /*** End of inlined file: res0.c ***/
  104561. /*** Start of inlined file: sharedbook.c ***/
  104562. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104563. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104564. // tasks..
  104565. #if JUCE_MSVC
  104566. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104567. #endif
  104568. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104569. #if JUCE_USE_OGGVORBIS
  104570. #include <stdlib.h>
  104571. #include <math.h>
  104572. #include <string.h>
  104573. int _ilog(unsigned int v){
  104574. int ret=0;
  104575. while(v){
  104576. ret++;
  104577. v>>=1;
  104578. }
  104579. return(ret);
  104580. }
  104581. #define VQ_FEXP 10
  104582. #define VQ_FMAN 21
  104583. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104584. long _float32_pack(float val){
  104585. int sign=0;
  104586. long exp;
  104587. long mant;
  104588. if(val<0){
  104589. sign=0x80000000;
  104590. val= -val;
  104591. }
  104592. exp= floor(log(val)/log(2.f));
  104593. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104594. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104595. return(sign|exp|mant);
  104596. }
  104597. float _float32_unpack(long val){
  104598. double mant=val&0x1fffff;
  104599. int sign=val&0x80000000;
  104600. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104601. if(sign)mant= -mant;
  104602. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104603. }
  104604. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104605. long i,j,count=0;
  104606. ogg_uint32_t marker[33];
  104607. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104608. memset(marker,0,sizeof(marker));
  104609. for(i=0;i<n;i++){
  104610. long length=l[i];
  104611. if(length>0){
  104612. ogg_uint32_t entry=marker[length];
  104613. if(length<32 && (entry>>length)){
  104614. _ogg_free(r);
  104615. return(NULL);
  104616. }
  104617. r[count++]=entry;
  104618. {
  104619. for(j=length;j>0;j--){
  104620. if(marker[j]&1){
  104621. if(j==1)
  104622. marker[1]++;
  104623. else
  104624. marker[j]=marker[j-1]<<1;
  104625. break; /* invariant says next upper marker would already
  104626. have been moved if it was on the same path */
  104627. }
  104628. marker[j]++;
  104629. }
  104630. }
  104631. for(j=length+1;j<33;j++)
  104632. if((marker[j]>>1) == entry){
  104633. entry=marker[j];
  104634. marker[j]=marker[j-1]<<1;
  104635. }else
  104636. break;
  104637. }else
  104638. if(sparsecount==0)count++;
  104639. }
  104640. for(i=0,count=0;i<n;i++){
  104641. ogg_uint32_t temp=0;
  104642. for(j=0;j<l[i];j++){
  104643. temp<<=1;
  104644. temp|=(r[count]>>j)&1;
  104645. }
  104646. if(sparsecount){
  104647. if(l[i])
  104648. r[count++]=temp;
  104649. }else
  104650. r[count++]=temp;
  104651. }
  104652. return(r);
  104653. }
  104654. long _book_maptype1_quantvals(const static_codebook *b){
  104655. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104656. while(1){
  104657. long acc=1;
  104658. long acc1=1;
  104659. int i;
  104660. for(i=0;i<b->dim;i++){
  104661. acc*=vals;
  104662. acc1*=vals+1;
  104663. }
  104664. if(acc<=b->entries && acc1>b->entries){
  104665. return(vals);
  104666. }else{
  104667. if(acc>b->entries){
  104668. vals--;
  104669. }else{
  104670. vals++;
  104671. }
  104672. }
  104673. }
  104674. }
  104675. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104676. long j,k,count=0;
  104677. if(b->maptype==1 || b->maptype==2){
  104678. int quantvals;
  104679. float mindel=_float32_unpack(b->q_min);
  104680. float delta=_float32_unpack(b->q_delta);
  104681. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104682. switch(b->maptype){
  104683. case 1:
  104684. quantvals=_book_maptype1_quantvals(b);
  104685. for(j=0;j<b->entries;j++){
  104686. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104687. float last=0.f;
  104688. int indexdiv=1;
  104689. for(k=0;k<b->dim;k++){
  104690. int index= (j/indexdiv)%quantvals;
  104691. float val=b->quantlist[index];
  104692. val=fabs(val)*delta+mindel+last;
  104693. if(b->q_sequencep)last=val;
  104694. if(sparsemap)
  104695. r[sparsemap[count]*b->dim+k]=val;
  104696. else
  104697. r[count*b->dim+k]=val;
  104698. indexdiv*=quantvals;
  104699. }
  104700. count++;
  104701. }
  104702. }
  104703. break;
  104704. case 2:
  104705. for(j=0;j<b->entries;j++){
  104706. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104707. float last=0.f;
  104708. for(k=0;k<b->dim;k++){
  104709. float val=b->quantlist[j*b->dim+k];
  104710. val=fabs(val)*delta+mindel+last;
  104711. if(b->q_sequencep)last=val;
  104712. if(sparsemap)
  104713. r[sparsemap[count]*b->dim+k]=val;
  104714. else
  104715. r[count*b->dim+k]=val;
  104716. }
  104717. count++;
  104718. }
  104719. }
  104720. break;
  104721. }
  104722. return(r);
  104723. }
  104724. return(NULL);
  104725. }
  104726. void vorbis_staticbook_clear(static_codebook *b){
  104727. if(b->allocedp){
  104728. if(b->quantlist)_ogg_free(b->quantlist);
  104729. if(b->lengthlist)_ogg_free(b->lengthlist);
  104730. if(b->nearest_tree){
  104731. _ogg_free(b->nearest_tree->ptr0);
  104732. _ogg_free(b->nearest_tree->ptr1);
  104733. _ogg_free(b->nearest_tree->p);
  104734. _ogg_free(b->nearest_tree->q);
  104735. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104736. _ogg_free(b->nearest_tree);
  104737. }
  104738. if(b->thresh_tree){
  104739. _ogg_free(b->thresh_tree->quantthresh);
  104740. _ogg_free(b->thresh_tree->quantmap);
  104741. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104742. _ogg_free(b->thresh_tree);
  104743. }
  104744. memset(b,0,sizeof(*b));
  104745. }
  104746. }
  104747. void vorbis_staticbook_destroy(static_codebook *b){
  104748. if(b->allocedp){
  104749. vorbis_staticbook_clear(b);
  104750. _ogg_free(b);
  104751. }
  104752. }
  104753. void vorbis_book_clear(codebook *b){
  104754. if(b->valuelist)_ogg_free(b->valuelist);
  104755. if(b->codelist)_ogg_free(b->codelist);
  104756. if(b->dec_index)_ogg_free(b->dec_index);
  104757. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104758. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104759. memset(b,0,sizeof(*b));
  104760. }
  104761. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104762. memset(c,0,sizeof(*c));
  104763. c->c=s;
  104764. c->entries=s->entries;
  104765. c->used_entries=s->entries;
  104766. c->dim=s->dim;
  104767. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104768. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104769. return(0);
  104770. }
  104771. static int sort32a(const void *a,const void *b){
  104772. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104773. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104774. }
  104775. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104776. int i,j,n=0,tabn;
  104777. int *sortindex;
  104778. memset(c,0,sizeof(*c));
  104779. for(i=0;i<s->entries;i++)
  104780. if(s->lengthlist[i]>0)
  104781. n++;
  104782. c->entries=s->entries;
  104783. c->used_entries=n;
  104784. c->dim=s->dim;
  104785. {
  104786. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104787. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104788. if(codes==NULL)goto err_out;
  104789. for(i=0;i<n;i++){
  104790. codes[i]=ogg_bitreverse(codes[i]);
  104791. codep[i]=codes+i;
  104792. }
  104793. qsort(codep,n,sizeof(*codep),sort32a);
  104794. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104795. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104796. for(i=0;i<n;i++){
  104797. int position=codep[i]-codes;
  104798. sortindex[position]=i;
  104799. }
  104800. for(i=0;i<n;i++)
  104801. c->codelist[sortindex[i]]=codes[i];
  104802. _ogg_free(codes);
  104803. }
  104804. c->valuelist=_book_unquantize(s,n,sortindex);
  104805. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104806. for(n=0,i=0;i<s->entries;i++)
  104807. if(s->lengthlist[i]>0)
  104808. c->dec_index[sortindex[n++]]=i;
  104809. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104810. for(n=0,i=0;i<s->entries;i++)
  104811. if(s->lengthlist[i]>0)
  104812. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104813. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104814. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104815. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104816. tabn=1<<c->dec_firsttablen;
  104817. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104818. c->dec_maxlength=0;
  104819. for(i=0;i<n;i++){
  104820. if(c->dec_maxlength<c->dec_codelengths[i])
  104821. c->dec_maxlength=c->dec_codelengths[i];
  104822. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104823. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104824. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104825. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104826. }
  104827. }
  104828. {
  104829. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104830. long lo=0,hi=0;
  104831. for(i=0;i<tabn;i++){
  104832. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104833. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104834. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104835. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104836. {
  104837. unsigned long loval=lo;
  104838. unsigned long hival=n-hi;
  104839. if(loval>0x7fff)loval=0x7fff;
  104840. if(hival>0x7fff)hival=0x7fff;
  104841. c->dec_firsttable[ogg_bitreverse(word)]=
  104842. 0x80000000UL | (loval<<15) | hival;
  104843. }
  104844. }
  104845. }
  104846. }
  104847. return(0);
  104848. err_out:
  104849. vorbis_book_clear(c);
  104850. return(-1);
  104851. }
  104852. static float _dist(int el,float *ref, float *b,int step){
  104853. int i;
  104854. float acc=0.f;
  104855. for(i=0;i<el;i++){
  104856. float val=(ref[i]-b[i*step]);
  104857. acc+=val*val;
  104858. }
  104859. return(acc);
  104860. }
  104861. int _best(codebook *book, float *a, int step){
  104862. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104863. #if 0
  104864. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104865. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104866. #endif
  104867. int dim=book->dim;
  104868. int k,o;
  104869. if(tt){
  104870. int index=0,i;
  104871. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104872. i=tt->threshvals>>1;
  104873. if(a[o]<tt->quantthresh[i]){
  104874. for(;i>0;i--)
  104875. if(a[o]>=tt->quantthresh[i-1])
  104876. break;
  104877. }else{
  104878. for(i++;i<tt->threshvals-1;i++)
  104879. if(a[o]<tt->quantthresh[i])break;
  104880. }
  104881. index=(index*tt->quantvals)+tt->quantmap[i];
  104882. }
  104883. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104884. use a decision tree after all
  104885. and fall through*/
  104886. return(index);
  104887. }
  104888. #if 0
  104889. if(pt){
  104890. const static_codebook *c=book->c;
  104891. int i,besti=-1;
  104892. float best=0.f;
  104893. int entry=0;
  104894. if(c->q_sequencep){
  104895. int pv;
  104896. long mul=1;
  104897. float qlast=0;
  104898. for(k=0,o=0;k<dim;k++,o+=step){
  104899. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104900. if(pv<0 || pv>=pt->mapentries)break;
  104901. entry+=pt->pigeonmap[pv]*mul;
  104902. mul*=pt->quantvals;
  104903. qlast+=pv*pt->del+pt->min;
  104904. }
  104905. }else{
  104906. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104907. int pv=(int)((a[o]-pt->min)/pt->del);
  104908. if(pv<0 || pv>=pt->mapentries)break;
  104909. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  104910. }
  104911. }
  104912. if(k==dim && pt->fitlength[entry]){
  104913. long *list=pt->fitlist+pt->fitmap[entry];
  104914. for(i=0;i<pt->fitlength[entry];i++){
  104915. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  104916. if(besti==-1 || this<best){
  104917. best=this;
  104918. besti=list[i];
  104919. }
  104920. }
  104921. return(besti);
  104922. }
  104923. }
  104924. if(nt){
  104925. while(1){
  104926. float c=0.f;
  104927. float *p=book->valuelist+nt->p[ptr];
  104928. float *q=book->valuelist+nt->q[ptr];
  104929. for(k=0,o=0;k<dim;k++,o+=step)
  104930. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  104931. if(c>0.f) /* in A */
  104932. ptr= -nt->ptr0[ptr];
  104933. else /* in B */
  104934. ptr= -nt->ptr1[ptr];
  104935. if(ptr<=0)break;
  104936. }
  104937. return(-ptr);
  104938. }
  104939. #endif
  104940. {
  104941. const static_codebook *c=book->c;
  104942. int i,besti=-1;
  104943. float best=0.f;
  104944. float *e=book->valuelist;
  104945. for(i=0;i<book->entries;i++){
  104946. if(c->lengthlist[i]>0){
  104947. float thisx=_dist(dim,e,a,step);
  104948. if(besti==-1 || thisx<best){
  104949. best=thisx;
  104950. besti=i;
  104951. }
  104952. }
  104953. e+=dim;
  104954. }
  104955. return(besti);
  104956. }
  104957. }
  104958. long vorbis_book_codeword(codebook *book,int entry){
  104959. if(book->c) /* only use with encode; decode optimizations are
  104960. allowed to break this */
  104961. return book->codelist[entry];
  104962. return -1;
  104963. }
  104964. long vorbis_book_codelen(codebook *book,int entry){
  104965. if(book->c) /* only use with encode; decode optimizations are
  104966. allowed to break this */
  104967. return book->c->lengthlist[entry];
  104968. return -1;
  104969. }
  104970. #ifdef _V_SELFTEST
  104971. #include <stdio.h>
  104972. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  104973. static long partial_quantlist1[]={0,7,2};
  104974. static_codebook test1={
  104975. 4,16,
  104976. NULL,
  104977. 0,
  104978. 0,0,0,0,
  104979. NULL,
  104980. NULL,NULL
  104981. };
  104982. static float *test1_result=NULL;
  104983. static_codebook test2={
  104984. 4,3,
  104985. NULL,
  104986. 2,
  104987. -533200896,1611661312,4,0,
  104988. full_quantlist1,
  104989. NULL,NULL
  104990. };
  104991. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  104992. static_codebook test3={
  104993. 4,3,
  104994. NULL,
  104995. 2,
  104996. -533200896,1611661312,4,1,
  104997. full_quantlist1,
  104998. NULL,NULL
  104999. };
  105000. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105001. static_codebook test4={
  105002. 3,27,
  105003. NULL,
  105004. 1,
  105005. -533200896,1611661312,4,0,
  105006. partial_quantlist1,
  105007. NULL,NULL
  105008. };
  105009. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105010. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105011. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105012. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105013. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105014. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105015. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105016. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105017. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105018. static_codebook test5={
  105019. 3,27,
  105020. NULL,
  105021. 1,
  105022. -533200896,1611661312,4,1,
  105023. partial_quantlist1,
  105024. NULL,NULL
  105025. };
  105026. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105027. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105028. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105029. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105030. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105031. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105032. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105033. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105034. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105035. void run_test(static_codebook *b,float *comp){
  105036. float *out=_book_unquantize(b,b->entries,NULL);
  105037. int i;
  105038. if(comp){
  105039. if(!out){
  105040. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105041. exit(1);
  105042. }
  105043. for(i=0;i<b->entries*b->dim;i++)
  105044. if(fabs(out[i]-comp[i])>.0001){
  105045. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105046. "position %d, %g != %g\n",i,out[i],comp[i]);
  105047. exit(1);
  105048. }
  105049. }else{
  105050. if(out){
  105051. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105052. " correct result should have been NULL\n");
  105053. exit(1);
  105054. }
  105055. }
  105056. }
  105057. int main(){
  105058. fprintf(stderr,"Dequant test 1... ");
  105059. run_test(&test1,test1_result);
  105060. fprintf(stderr,"OK\nDequant test 2... ");
  105061. run_test(&test2,test2_result);
  105062. fprintf(stderr,"OK\nDequant test 3... ");
  105063. run_test(&test3,test3_result);
  105064. fprintf(stderr,"OK\nDequant test 4... ");
  105065. run_test(&test4,test4_result);
  105066. fprintf(stderr,"OK\nDequant test 5... ");
  105067. run_test(&test5,test5_result);
  105068. fprintf(stderr,"OK\n\n");
  105069. return(0);
  105070. }
  105071. #endif
  105072. #endif
  105073. /*** End of inlined file: sharedbook.c ***/
  105074. /*** Start of inlined file: smallft.c ***/
  105075. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105076. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105077. // tasks..
  105078. #if JUCE_MSVC
  105079. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105080. #endif
  105081. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105082. #if JUCE_USE_OGGVORBIS
  105083. #include <stdlib.h>
  105084. #include <string.h>
  105085. #include <math.h>
  105086. static void drfti1(int n, float *wa, int *ifac){
  105087. static int ntryh[4] = { 4,2,3,5 };
  105088. static float tpi = 6.28318530717958648f;
  105089. float arg,argh,argld,fi;
  105090. int ntry=0,i,j=-1;
  105091. int k1, l1, l2, ib;
  105092. int ld, ii, ip, is, nq, nr;
  105093. int ido, ipm, nfm1;
  105094. int nl=n;
  105095. int nf=0;
  105096. L101:
  105097. j++;
  105098. if (j < 4)
  105099. ntry=ntryh[j];
  105100. else
  105101. ntry+=2;
  105102. L104:
  105103. nq=nl/ntry;
  105104. nr=nl-ntry*nq;
  105105. if (nr!=0) goto L101;
  105106. nf++;
  105107. ifac[nf+1]=ntry;
  105108. nl=nq;
  105109. if(ntry!=2)goto L107;
  105110. if(nf==1)goto L107;
  105111. for (i=1;i<nf;i++){
  105112. ib=nf-i+1;
  105113. ifac[ib+1]=ifac[ib];
  105114. }
  105115. ifac[2] = 2;
  105116. L107:
  105117. if(nl!=1)goto L104;
  105118. ifac[0]=n;
  105119. ifac[1]=nf;
  105120. argh=tpi/n;
  105121. is=0;
  105122. nfm1=nf-1;
  105123. l1=1;
  105124. if(nfm1==0)return;
  105125. for (k1=0;k1<nfm1;k1++){
  105126. ip=ifac[k1+2];
  105127. ld=0;
  105128. l2=l1*ip;
  105129. ido=n/l2;
  105130. ipm=ip-1;
  105131. for (j=0;j<ipm;j++){
  105132. ld+=l1;
  105133. i=is;
  105134. argld=(float)ld*argh;
  105135. fi=0.f;
  105136. for (ii=2;ii<ido;ii+=2){
  105137. fi+=1.f;
  105138. arg=fi*argld;
  105139. wa[i++]=cos(arg);
  105140. wa[i++]=sin(arg);
  105141. }
  105142. is+=ido;
  105143. }
  105144. l1=l2;
  105145. }
  105146. }
  105147. static void fdrffti(int n, float *wsave, int *ifac){
  105148. if (n == 1) return;
  105149. drfti1(n, wsave+n, ifac);
  105150. }
  105151. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105152. int i,k;
  105153. float ti2,tr2;
  105154. int t0,t1,t2,t3,t4,t5,t6;
  105155. t1=0;
  105156. t0=(t2=l1*ido);
  105157. t3=ido<<1;
  105158. for(k=0;k<l1;k++){
  105159. ch[t1<<1]=cc[t1]+cc[t2];
  105160. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105161. t1+=ido;
  105162. t2+=ido;
  105163. }
  105164. if(ido<2)return;
  105165. if(ido==2)goto L105;
  105166. t1=0;
  105167. t2=t0;
  105168. for(k=0;k<l1;k++){
  105169. t3=t2;
  105170. t4=(t1<<1)+(ido<<1);
  105171. t5=t1;
  105172. t6=t1+t1;
  105173. for(i=2;i<ido;i+=2){
  105174. t3+=2;
  105175. t4-=2;
  105176. t5+=2;
  105177. t6+=2;
  105178. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105179. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105180. ch[t6]=cc[t5]+ti2;
  105181. ch[t4]=ti2-cc[t5];
  105182. ch[t6-1]=cc[t5-1]+tr2;
  105183. ch[t4-1]=cc[t5-1]-tr2;
  105184. }
  105185. t1+=ido;
  105186. t2+=ido;
  105187. }
  105188. if(ido%2==1)return;
  105189. L105:
  105190. t3=(t2=(t1=ido)-1);
  105191. t2+=t0;
  105192. for(k=0;k<l1;k++){
  105193. ch[t1]=-cc[t2];
  105194. ch[t1-1]=cc[t3];
  105195. t1+=ido<<1;
  105196. t2+=ido;
  105197. t3+=ido;
  105198. }
  105199. }
  105200. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105201. float *wa2,float *wa3){
  105202. static float hsqt2 = .70710678118654752f;
  105203. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105204. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105205. t0=l1*ido;
  105206. t1=t0;
  105207. t4=t1<<1;
  105208. t2=t1+(t1<<1);
  105209. t3=0;
  105210. for(k=0;k<l1;k++){
  105211. tr1=cc[t1]+cc[t2];
  105212. tr2=cc[t3]+cc[t4];
  105213. ch[t5=t3<<2]=tr1+tr2;
  105214. ch[(ido<<2)+t5-1]=tr2-tr1;
  105215. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105216. ch[t5]=cc[t2]-cc[t1];
  105217. t1+=ido;
  105218. t2+=ido;
  105219. t3+=ido;
  105220. t4+=ido;
  105221. }
  105222. if(ido<2)return;
  105223. if(ido==2)goto L105;
  105224. t1=0;
  105225. for(k=0;k<l1;k++){
  105226. t2=t1;
  105227. t4=t1<<2;
  105228. t5=(t6=ido<<1)+t4;
  105229. for(i=2;i<ido;i+=2){
  105230. t3=(t2+=2);
  105231. t4+=2;
  105232. t5-=2;
  105233. t3+=t0;
  105234. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105235. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105236. t3+=t0;
  105237. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105238. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105239. t3+=t0;
  105240. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105241. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105242. tr1=cr2+cr4;
  105243. tr4=cr4-cr2;
  105244. ti1=ci2+ci4;
  105245. ti4=ci2-ci4;
  105246. ti2=cc[t2]+ci3;
  105247. ti3=cc[t2]-ci3;
  105248. tr2=cc[t2-1]+cr3;
  105249. tr3=cc[t2-1]-cr3;
  105250. ch[t4-1]=tr1+tr2;
  105251. ch[t4]=ti1+ti2;
  105252. ch[t5-1]=tr3-ti4;
  105253. ch[t5]=tr4-ti3;
  105254. ch[t4+t6-1]=ti4+tr3;
  105255. ch[t4+t6]=tr4+ti3;
  105256. ch[t5+t6-1]=tr2-tr1;
  105257. ch[t5+t6]=ti1-ti2;
  105258. }
  105259. t1+=ido;
  105260. }
  105261. if(ido&1)return;
  105262. L105:
  105263. t2=(t1=t0+ido-1)+(t0<<1);
  105264. t3=ido<<2;
  105265. t4=ido;
  105266. t5=ido<<1;
  105267. t6=ido;
  105268. for(k=0;k<l1;k++){
  105269. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105270. tr1=hsqt2*(cc[t1]-cc[t2]);
  105271. ch[t4-1]=tr1+cc[t6-1];
  105272. ch[t4+t5-1]=cc[t6-1]-tr1;
  105273. ch[t4]=ti1-cc[t1+t0];
  105274. ch[t4+t5]=ti1+cc[t1+t0];
  105275. t1+=ido;
  105276. t2+=ido;
  105277. t4+=t3;
  105278. t6+=ido;
  105279. }
  105280. }
  105281. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105282. float *c2,float *ch,float *ch2,float *wa){
  105283. static float tpi=6.283185307179586f;
  105284. int idij,ipph,i,j,k,l,ic,ik,is;
  105285. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105286. float dc2,ai1,ai2,ar1,ar2,ds2;
  105287. int nbd;
  105288. float dcp,arg,dsp,ar1h,ar2h;
  105289. int idp2,ipp2;
  105290. arg=tpi/(float)ip;
  105291. dcp=cos(arg);
  105292. dsp=sin(arg);
  105293. ipph=(ip+1)>>1;
  105294. ipp2=ip;
  105295. idp2=ido;
  105296. nbd=(ido-1)>>1;
  105297. t0=l1*ido;
  105298. t10=ip*ido;
  105299. if(ido==1)goto L119;
  105300. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105301. t1=0;
  105302. for(j=1;j<ip;j++){
  105303. t1+=t0;
  105304. t2=t1;
  105305. for(k=0;k<l1;k++){
  105306. ch[t2]=c1[t2];
  105307. t2+=ido;
  105308. }
  105309. }
  105310. is=-ido;
  105311. t1=0;
  105312. if(nbd>l1){
  105313. for(j=1;j<ip;j++){
  105314. t1+=t0;
  105315. is+=ido;
  105316. t2= -ido+t1;
  105317. for(k=0;k<l1;k++){
  105318. idij=is-1;
  105319. t2+=ido;
  105320. t3=t2;
  105321. for(i=2;i<ido;i+=2){
  105322. idij+=2;
  105323. t3+=2;
  105324. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105325. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105326. }
  105327. }
  105328. }
  105329. }else{
  105330. for(j=1;j<ip;j++){
  105331. is+=ido;
  105332. idij=is-1;
  105333. t1+=t0;
  105334. t2=t1;
  105335. for(i=2;i<ido;i+=2){
  105336. idij+=2;
  105337. t2+=2;
  105338. t3=t2;
  105339. for(k=0;k<l1;k++){
  105340. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105341. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105342. t3+=ido;
  105343. }
  105344. }
  105345. }
  105346. }
  105347. t1=0;
  105348. t2=ipp2*t0;
  105349. if(nbd<l1){
  105350. for(j=1;j<ipph;j++){
  105351. t1+=t0;
  105352. t2-=t0;
  105353. t3=t1;
  105354. t4=t2;
  105355. for(i=2;i<ido;i+=2){
  105356. t3+=2;
  105357. t4+=2;
  105358. t5=t3-ido;
  105359. t6=t4-ido;
  105360. for(k=0;k<l1;k++){
  105361. t5+=ido;
  105362. t6+=ido;
  105363. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105364. c1[t6-1]=ch[t5]-ch[t6];
  105365. c1[t5]=ch[t5]+ch[t6];
  105366. c1[t6]=ch[t6-1]-ch[t5-1];
  105367. }
  105368. }
  105369. }
  105370. }else{
  105371. for(j=1;j<ipph;j++){
  105372. t1+=t0;
  105373. t2-=t0;
  105374. t3=t1;
  105375. t4=t2;
  105376. for(k=0;k<l1;k++){
  105377. t5=t3;
  105378. t6=t4;
  105379. for(i=2;i<ido;i+=2){
  105380. t5+=2;
  105381. t6+=2;
  105382. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105383. c1[t6-1]=ch[t5]-ch[t6];
  105384. c1[t5]=ch[t5]+ch[t6];
  105385. c1[t6]=ch[t6-1]-ch[t5-1];
  105386. }
  105387. t3+=ido;
  105388. t4+=ido;
  105389. }
  105390. }
  105391. }
  105392. L119:
  105393. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105394. t1=0;
  105395. t2=ipp2*idl1;
  105396. for(j=1;j<ipph;j++){
  105397. t1+=t0;
  105398. t2-=t0;
  105399. t3=t1-ido;
  105400. t4=t2-ido;
  105401. for(k=0;k<l1;k++){
  105402. t3+=ido;
  105403. t4+=ido;
  105404. c1[t3]=ch[t3]+ch[t4];
  105405. c1[t4]=ch[t4]-ch[t3];
  105406. }
  105407. }
  105408. ar1=1.f;
  105409. ai1=0.f;
  105410. t1=0;
  105411. t2=ipp2*idl1;
  105412. t3=(ip-1)*idl1;
  105413. for(l=1;l<ipph;l++){
  105414. t1+=idl1;
  105415. t2-=idl1;
  105416. ar1h=dcp*ar1-dsp*ai1;
  105417. ai1=dcp*ai1+dsp*ar1;
  105418. ar1=ar1h;
  105419. t4=t1;
  105420. t5=t2;
  105421. t6=t3;
  105422. t7=idl1;
  105423. for(ik=0;ik<idl1;ik++){
  105424. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105425. ch2[t5++]=ai1*c2[t6++];
  105426. }
  105427. dc2=ar1;
  105428. ds2=ai1;
  105429. ar2=ar1;
  105430. ai2=ai1;
  105431. t4=idl1;
  105432. t5=(ipp2-1)*idl1;
  105433. for(j=2;j<ipph;j++){
  105434. t4+=idl1;
  105435. t5-=idl1;
  105436. ar2h=dc2*ar2-ds2*ai2;
  105437. ai2=dc2*ai2+ds2*ar2;
  105438. ar2=ar2h;
  105439. t6=t1;
  105440. t7=t2;
  105441. t8=t4;
  105442. t9=t5;
  105443. for(ik=0;ik<idl1;ik++){
  105444. ch2[t6++]+=ar2*c2[t8++];
  105445. ch2[t7++]+=ai2*c2[t9++];
  105446. }
  105447. }
  105448. }
  105449. t1=0;
  105450. for(j=1;j<ipph;j++){
  105451. t1+=idl1;
  105452. t2=t1;
  105453. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105454. }
  105455. if(ido<l1)goto L132;
  105456. t1=0;
  105457. t2=0;
  105458. for(k=0;k<l1;k++){
  105459. t3=t1;
  105460. t4=t2;
  105461. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105462. t1+=ido;
  105463. t2+=t10;
  105464. }
  105465. goto L135;
  105466. L132:
  105467. for(i=0;i<ido;i++){
  105468. t1=i;
  105469. t2=i;
  105470. for(k=0;k<l1;k++){
  105471. cc[t2]=ch[t1];
  105472. t1+=ido;
  105473. t2+=t10;
  105474. }
  105475. }
  105476. L135:
  105477. t1=0;
  105478. t2=ido<<1;
  105479. t3=0;
  105480. t4=ipp2*t0;
  105481. for(j=1;j<ipph;j++){
  105482. t1+=t2;
  105483. t3+=t0;
  105484. t4-=t0;
  105485. t5=t1;
  105486. t6=t3;
  105487. t7=t4;
  105488. for(k=0;k<l1;k++){
  105489. cc[t5-1]=ch[t6];
  105490. cc[t5]=ch[t7];
  105491. t5+=t10;
  105492. t6+=ido;
  105493. t7+=ido;
  105494. }
  105495. }
  105496. if(ido==1)return;
  105497. if(nbd<l1)goto L141;
  105498. t1=-ido;
  105499. t3=0;
  105500. t4=0;
  105501. t5=ipp2*t0;
  105502. for(j=1;j<ipph;j++){
  105503. t1+=t2;
  105504. t3+=t2;
  105505. t4+=t0;
  105506. t5-=t0;
  105507. t6=t1;
  105508. t7=t3;
  105509. t8=t4;
  105510. t9=t5;
  105511. for(k=0;k<l1;k++){
  105512. for(i=2;i<ido;i+=2){
  105513. ic=idp2-i;
  105514. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105515. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105516. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105517. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105518. }
  105519. t6+=t10;
  105520. t7+=t10;
  105521. t8+=ido;
  105522. t9+=ido;
  105523. }
  105524. }
  105525. return;
  105526. L141:
  105527. t1=-ido;
  105528. t3=0;
  105529. t4=0;
  105530. t5=ipp2*t0;
  105531. for(j=1;j<ipph;j++){
  105532. t1+=t2;
  105533. t3+=t2;
  105534. t4+=t0;
  105535. t5-=t0;
  105536. for(i=2;i<ido;i+=2){
  105537. t6=idp2+t1-i;
  105538. t7=i+t3;
  105539. t8=i+t4;
  105540. t9=i+t5;
  105541. for(k=0;k<l1;k++){
  105542. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105543. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105544. cc[t7]=ch[t8]+ch[t9];
  105545. cc[t6]=ch[t9]-ch[t8];
  105546. t6+=t10;
  105547. t7+=t10;
  105548. t8+=ido;
  105549. t9+=ido;
  105550. }
  105551. }
  105552. }
  105553. }
  105554. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105555. int i,k1,l1,l2;
  105556. int na,kh,nf;
  105557. int ip,iw,ido,idl1,ix2,ix3;
  105558. nf=ifac[1];
  105559. na=1;
  105560. l2=n;
  105561. iw=n;
  105562. for(k1=0;k1<nf;k1++){
  105563. kh=nf-k1;
  105564. ip=ifac[kh+1];
  105565. l1=l2/ip;
  105566. ido=n/l2;
  105567. idl1=ido*l1;
  105568. iw-=(ip-1)*ido;
  105569. na=1-na;
  105570. if(ip!=4)goto L102;
  105571. ix2=iw+ido;
  105572. ix3=ix2+ido;
  105573. if(na!=0)
  105574. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105575. else
  105576. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105577. goto L110;
  105578. L102:
  105579. if(ip!=2)goto L104;
  105580. if(na!=0)goto L103;
  105581. dradf2(ido,l1,c,ch,wa+iw-1);
  105582. goto L110;
  105583. L103:
  105584. dradf2(ido,l1,ch,c,wa+iw-1);
  105585. goto L110;
  105586. L104:
  105587. if(ido==1)na=1-na;
  105588. if(na!=0)goto L109;
  105589. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105590. na=1;
  105591. goto L110;
  105592. L109:
  105593. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105594. na=0;
  105595. L110:
  105596. l2=l1;
  105597. }
  105598. if(na==1)return;
  105599. for(i=0;i<n;i++)c[i]=ch[i];
  105600. }
  105601. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105602. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105603. float ti2,tr2;
  105604. t0=l1*ido;
  105605. t1=0;
  105606. t2=0;
  105607. t3=(ido<<1)-1;
  105608. for(k=0;k<l1;k++){
  105609. ch[t1]=cc[t2]+cc[t3+t2];
  105610. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105611. t2=(t1+=ido)<<1;
  105612. }
  105613. if(ido<2)return;
  105614. if(ido==2)goto L105;
  105615. t1=0;
  105616. t2=0;
  105617. for(k=0;k<l1;k++){
  105618. t3=t1;
  105619. t5=(t4=t2)+(ido<<1);
  105620. t6=t0+t1;
  105621. for(i=2;i<ido;i+=2){
  105622. t3+=2;
  105623. t4+=2;
  105624. t5-=2;
  105625. t6+=2;
  105626. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105627. tr2=cc[t4-1]-cc[t5-1];
  105628. ch[t3]=cc[t4]-cc[t5];
  105629. ti2=cc[t4]+cc[t5];
  105630. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105631. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105632. }
  105633. t2=(t1+=ido)<<1;
  105634. }
  105635. if(ido%2==1)return;
  105636. L105:
  105637. t1=ido-1;
  105638. t2=ido-1;
  105639. for(k=0;k<l1;k++){
  105640. ch[t1]=cc[t2]+cc[t2];
  105641. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105642. t1+=ido;
  105643. t2+=ido<<1;
  105644. }
  105645. }
  105646. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105647. float *wa2){
  105648. static float taur = -.5f;
  105649. static float taui = .8660254037844386f;
  105650. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105651. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105652. t0=l1*ido;
  105653. t1=0;
  105654. t2=t0<<1;
  105655. t3=ido<<1;
  105656. t4=ido+(ido<<1);
  105657. t5=0;
  105658. for(k=0;k<l1;k++){
  105659. tr2=cc[t3-1]+cc[t3-1];
  105660. cr2=cc[t5]+(taur*tr2);
  105661. ch[t1]=cc[t5]+tr2;
  105662. ci3=taui*(cc[t3]+cc[t3]);
  105663. ch[t1+t0]=cr2-ci3;
  105664. ch[t1+t2]=cr2+ci3;
  105665. t1+=ido;
  105666. t3+=t4;
  105667. t5+=t4;
  105668. }
  105669. if(ido==1)return;
  105670. t1=0;
  105671. t3=ido<<1;
  105672. for(k=0;k<l1;k++){
  105673. t7=t1+(t1<<1);
  105674. t6=(t5=t7+t3);
  105675. t8=t1;
  105676. t10=(t9=t1+t0)+t0;
  105677. for(i=2;i<ido;i+=2){
  105678. t5+=2;
  105679. t6-=2;
  105680. t7+=2;
  105681. t8+=2;
  105682. t9+=2;
  105683. t10+=2;
  105684. tr2=cc[t5-1]+cc[t6-1];
  105685. cr2=cc[t7-1]+(taur*tr2);
  105686. ch[t8-1]=cc[t7-1]+tr2;
  105687. ti2=cc[t5]-cc[t6];
  105688. ci2=cc[t7]+(taur*ti2);
  105689. ch[t8]=cc[t7]+ti2;
  105690. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105691. ci3=taui*(cc[t5]+cc[t6]);
  105692. dr2=cr2-ci3;
  105693. dr3=cr2+ci3;
  105694. di2=ci2+cr3;
  105695. di3=ci2-cr3;
  105696. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105697. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105698. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105699. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105700. }
  105701. t1+=ido;
  105702. }
  105703. }
  105704. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105705. float *wa2,float *wa3){
  105706. static float sqrt2=1.414213562373095f;
  105707. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105708. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105709. t0=l1*ido;
  105710. t1=0;
  105711. t2=ido<<2;
  105712. t3=0;
  105713. t6=ido<<1;
  105714. for(k=0;k<l1;k++){
  105715. t4=t3+t6;
  105716. t5=t1;
  105717. tr3=cc[t4-1]+cc[t4-1];
  105718. tr4=cc[t4]+cc[t4];
  105719. tr1=cc[t3]-cc[(t4+=t6)-1];
  105720. tr2=cc[t3]+cc[t4-1];
  105721. ch[t5]=tr2+tr3;
  105722. ch[t5+=t0]=tr1-tr4;
  105723. ch[t5+=t0]=tr2-tr3;
  105724. ch[t5+=t0]=tr1+tr4;
  105725. t1+=ido;
  105726. t3+=t2;
  105727. }
  105728. if(ido<2)return;
  105729. if(ido==2)goto L105;
  105730. t1=0;
  105731. for(k=0;k<l1;k++){
  105732. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105733. t7=t1;
  105734. for(i=2;i<ido;i+=2){
  105735. t2+=2;
  105736. t3+=2;
  105737. t4-=2;
  105738. t5-=2;
  105739. t7+=2;
  105740. ti1=cc[t2]+cc[t5];
  105741. ti2=cc[t2]-cc[t5];
  105742. ti3=cc[t3]-cc[t4];
  105743. tr4=cc[t3]+cc[t4];
  105744. tr1=cc[t2-1]-cc[t5-1];
  105745. tr2=cc[t2-1]+cc[t5-1];
  105746. ti4=cc[t3-1]-cc[t4-1];
  105747. tr3=cc[t3-1]+cc[t4-1];
  105748. ch[t7-1]=tr2+tr3;
  105749. cr3=tr2-tr3;
  105750. ch[t7]=ti2+ti3;
  105751. ci3=ti2-ti3;
  105752. cr2=tr1-tr4;
  105753. cr4=tr1+tr4;
  105754. ci2=ti1+ti4;
  105755. ci4=ti1-ti4;
  105756. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105757. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105758. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105759. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105760. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105761. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105762. }
  105763. t1+=ido;
  105764. }
  105765. if(ido%2 == 1)return;
  105766. L105:
  105767. t1=ido;
  105768. t2=ido<<2;
  105769. t3=ido-1;
  105770. t4=ido+(ido<<1);
  105771. for(k=0;k<l1;k++){
  105772. t5=t3;
  105773. ti1=cc[t1]+cc[t4];
  105774. ti2=cc[t4]-cc[t1];
  105775. tr1=cc[t1-1]-cc[t4-1];
  105776. tr2=cc[t1-1]+cc[t4-1];
  105777. ch[t5]=tr2+tr2;
  105778. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105779. ch[t5+=t0]=ti2+ti2;
  105780. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105781. t3+=ido;
  105782. t1+=t2;
  105783. t4+=t2;
  105784. }
  105785. }
  105786. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105787. float *c2,float *ch,float *ch2,float *wa){
  105788. static float tpi=6.283185307179586f;
  105789. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105790. t11,t12;
  105791. float dc2,ai1,ai2,ar1,ar2,ds2;
  105792. int nbd;
  105793. float dcp,arg,dsp,ar1h,ar2h;
  105794. int ipp2;
  105795. t10=ip*ido;
  105796. t0=l1*ido;
  105797. arg=tpi/(float)ip;
  105798. dcp=cos(arg);
  105799. dsp=sin(arg);
  105800. nbd=(ido-1)>>1;
  105801. ipp2=ip;
  105802. ipph=(ip+1)>>1;
  105803. if(ido<l1)goto L103;
  105804. t1=0;
  105805. t2=0;
  105806. for(k=0;k<l1;k++){
  105807. t3=t1;
  105808. t4=t2;
  105809. for(i=0;i<ido;i++){
  105810. ch[t3]=cc[t4];
  105811. t3++;
  105812. t4++;
  105813. }
  105814. t1+=ido;
  105815. t2+=t10;
  105816. }
  105817. goto L106;
  105818. L103:
  105819. t1=0;
  105820. for(i=0;i<ido;i++){
  105821. t2=t1;
  105822. t3=t1;
  105823. for(k=0;k<l1;k++){
  105824. ch[t2]=cc[t3];
  105825. t2+=ido;
  105826. t3+=t10;
  105827. }
  105828. t1++;
  105829. }
  105830. L106:
  105831. t1=0;
  105832. t2=ipp2*t0;
  105833. t7=(t5=ido<<1);
  105834. for(j=1;j<ipph;j++){
  105835. t1+=t0;
  105836. t2-=t0;
  105837. t3=t1;
  105838. t4=t2;
  105839. t6=t5;
  105840. for(k=0;k<l1;k++){
  105841. ch[t3]=cc[t6-1]+cc[t6-1];
  105842. ch[t4]=cc[t6]+cc[t6];
  105843. t3+=ido;
  105844. t4+=ido;
  105845. t6+=t10;
  105846. }
  105847. t5+=t7;
  105848. }
  105849. if (ido == 1)goto L116;
  105850. if(nbd<l1)goto L112;
  105851. t1=0;
  105852. t2=ipp2*t0;
  105853. t7=0;
  105854. for(j=1;j<ipph;j++){
  105855. t1+=t0;
  105856. t2-=t0;
  105857. t3=t1;
  105858. t4=t2;
  105859. t7+=(ido<<1);
  105860. t8=t7;
  105861. for(k=0;k<l1;k++){
  105862. t5=t3;
  105863. t6=t4;
  105864. t9=t8;
  105865. t11=t8;
  105866. for(i=2;i<ido;i+=2){
  105867. t5+=2;
  105868. t6+=2;
  105869. t9+=2;
  105870. t11-=2;
  105871. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105872. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105873. ch[t5]=cc[t9]-cc[t11];
  105874. ch[t6]=cc[t9]+cc[t11];
  105875. }
  105876. t3+=ido;
  105877. t4+=ido;
  105878. t8+=t10;
  105879. }
  105880. }
  105881. goto L116;
  105882. L112:
  105883. t1=0;
  105884. t2=ipp2*t0;
  105885. t7=0;
  105886. for(j=1;j<ipph;j++){
  105887. t1+=t0;
  105888. t2-=t0;
  105889. t3=t1;
  105890. t4=t2;
  105891. t7+=(ido<<1);
  105892. t8=t7;
  105893. t9=t7;
  105894. for(i=2;i<ido;i+=2){
  105895. t3+=2;
  105896. t4+=2;
  105897. t8+=2;
  105898. t9-=2;
  105899. t5=t3;
  105900. t6=t4;
  105901. t11=t8;
  105902. t12=t9;
  105903. for(k=0;k<l1;k++){
  105904. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105905. ch[t6-1]=cc[t11-1]-cc[t12-1];
  105906. ch[t5]=cc[t11]-cc[t12];
  105907. ch[t6]=cc[t11]+cc[t12];
  105908. t5+=ido;
  105909. t6+=ido;
  105910. t11+=t10;
  105911. t12+=t10;
  105912. }
  105913. }
  105914. }
  105915. L116:
  105916. ar1=1.f;
  105917. ai1=0.f;
  105918. t1=0;
  105919. t9=(t2=ipp2*idl1);
  105920. t3=(ip-1)*idl1;
  105921. for(l=1;l<ipph;l++){
  105922. t1+=idl1;
  105923. t2-=idl1;
  105924. ar1h=dcp*ar1-dsp*ai1;
  105925. ai1=dcp*ai1+dsp*ar1;
  105926. ar1=ar1h;
  105927. t4=t1;
  105928. t5=t2;
  105929. t6=0;
  105930. t7=idl1;
  105931. t8=t3;
  105932. for(ik=0;ik<idl1;ik++){
  105933. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  105934. c2[t5++]=ai1*ch2[t8++];
  105935. }
  105936. dc2=ar1;
  105937. ds2=ai1;
  105938. ar2=ar1;
  105939. ai2=ai1;
  105940. t6=idl1;
  105941. t7=t9-idl1;
  105942. for(j=2;j<ipph;j++){
  105943. t6+=idl1;
  105944. t7-=idl1;
  105945. ar2h=dc2*ar2-ds2*ai2;
  105946. ai2=dc2*ai2+ds2*ar2;
  105947. ar2=ar2h;
  105948. t4=t1;
  105949. t5=t2;
  105950. t11=t6;
  105951. t12=t7;
  105952. for(ik=0;ik<idl1;ik++){
  105953. c2[t4++]+=ar2*ch2[t11++];
  105954. c2[t5++]+=ai2*ch2[t12++];
  105955. }
  105956. }
  105957. }
  105958. t1=0;
  105959. for(j=1;j<ipph;j++){
  105960. t1+=idl1;
  105961. t2=t1;
  105962. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  105963. }
  105964. t1=0;
  105965. t2=ipp2*t0;
  105966. for(j=1;j<ipph;j++){
  105967. t1+=t0;
  105968. t2-=t0;
  105969. t3=t1;
  105970. t4=t2;
  105971. for(k=0;k<l1;k++){
  105972. ch[t3]=c1[t3]-c1[t4];
  105973. ch[t4]=c1[t3]+c1[t4];
  105974. t3+=ido;
  105975. t4+=ido;
  105976. }
  105977. }
  105978. if(ido==1)goto L132;
  105979. if(nbd<l1)goto L128;
  105980. t1=0;
  105981. t2=ipp2*t0;
  105982. for(j=1;j<ipph;j++){
  105983. t1+=t0;
  105984. t2-=t0;
  105985. t3=t1;
  105986. t4=t2;
  105987. for(k=0;k<l1;k++){
  105988. t5=t3;
  105989. t6=t4;
  105990. for(i=2;i<ido;i+=2){
  105991. t5+=2;
  105992. t6+=2;
  105993. ch[t5-1]=c1[t5-1]-c1[t6];
  105994. ch[t6-1]=c1[t5-1]+c1[t6];
  105995. ch[t5]=c1[t5]+c1[t6-1];
  105996. ch[t6]=c1[t5]-c1[t6-1];
  105997. }
  105998. t3+=ido;
  105999. t4+=ido;
  106000. }
  106001. }
  106002. goto L132;
  106003. L128:
  106004. t1=0;
  106005. t2=ipp2*t0;
  106006. for(j=1;j<ipph;j++){
  106007. t1+=t0;
  106008. t2-=t0;
  106009. t3=t1;
  106010. t4=t2;
  106011. for(i=2;i<ido;i+=2){
  106012. t3+=2;
  106013. t4+=2;
  106014. t5=t3;
  106015. t6=t4;
  106016. for(k=0;k<l1;k++){
  106017. ch[t5-1]=c1[t5-1]-c1[t6];
  106018. ch[t6-1]=c1[t5-1]+c1[t6];
  106019. ch[t5]=c1[t5]+c1[t6-1];
  106020. ch[t6]=c1[t5]-c1[t6-1];
  106021. t5+=ido;
  106022. t6+=ido;
  106023. }
  106024. }
  106025. }
  106026. L132:
  106027. if(ido==1)return;
  106028. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106029. t1=0;
  106030. for(j=1;j<ip;j++){
  106031. t2=(t1+=t0);
  106032. for(k=0;k<l1;k++){
  106033. c1[t2]=ch[t2];
  106034. t2+=ido;
  106035. }
  106036. }
  106037. if(nbd>l1)goto L139;
  106038. is= -ido-1;
  106039. t1=0;
  106040. for(j=1;j<ip;j++){
  106041. is+=ido;
  106042. t1+=t0;
  106043. idij=is;
  106044. t2=t1;
  106045. for(i=2;i<ido;i+=2){
  106046. t2+=2;
  106047. idij+=2;
  106048. t3=t2;
  106049. for(k=0;k<l1;k++){
  106050. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106051. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106052. t3+=ido;
  106053. }
  106054. }
  106055. }
  106056. return;
  106057. L139:
  106058. is= -ido-1;
  106059. t1=0;
  106060. for(j=1;j<ip;j++){
  106061. is+=ido;
  106062. t1+=t0;
  106063. t2=t1;
  106064. for(k=0;k<l1;k++){
  106065. idij=is;
  106066. t3=t2;
  106067. for(i=2;i<ido;i+=2){
  106068. idij+=2;
  106069. t3+=2;
  106070. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106071. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106072. }
  106073. t2+=ido;
  106074. }
  106075. }
  106076. }
  106077. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106078. int i,k1,l1,l2;
  106079. int na;
  106080. int nf,ip,iw,ix2,ix3,ido,idl1;
  106081. nf=ifac[1];
  106082. na=0;
  106083. l1=1;
  106084. iw=1;
  106085. for(k1=0;k1<nf;k1++){
  106086. ip=ifac[k1 + 2];
  106087. l2=ip*l1;
  106088. ido=n/l2;
  106089. idl1=ido*l1;
  106090. if(ip!=4)goto L103;
  106091. ix2=iw+ido;
  106092. ix3=ix2+ido;
  106093. if(na!=0)
  106094. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106095. else
  106096. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106097. na=1-na;
  106098. goto L115;
  106099. L103:
  106100. if(ip!=2)goto L106;
  106101. if(na!=0)
  106102. dradb2(ido,l1,ch,c,wa+iw-1);
  106103. else
  106104. dradb2(ido,l1,c,ch,wa+iw-1);
  106105. na=1-na;
  106106. goto L115;
  106107. L106:
  106108. if(ip!=3)goto L109;
  106109. ix2=iw+ido;
  106110. if(na!=0)
  106111. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106112. else
  106113. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106114. na=1-na;
  106115. goto L115;
  106116. L109:
  106117. if(na!=0)
  106118. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106119. else
  106120. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106121. if(ido==1)na=1-na;
  106122. L115:
  106123. l1=l2;
  106124. iw+=(ip-1)*ido;
  106125. }
  106126. if(na==0)return;
  106127. for(i=0;i<n;i++)c[i]=ch[i];
  106128. }
  106129. void drft_forward(drft_lookup *l,float *data){
  106130. if(l->n==1)return;
  106131. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106132. }
  106133. void drft_backward(drft_lookup *l,float *data){
  106134. if (l->n==1)return;
  106135. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106136. }
  106137. void drft_init(drft_lookup *l,int n){
  106138. l->n=n;
  106139. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106140. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106141. fdrffti(n, l->trigcache, l->splitcache);
  106142. }
  106143. void drft_clear(drft_lookup *l){
  106144. if(l){
  106145. if(l->trigcache)_ogg_free(l->trigcache);
  106146. if(l->splitcache)_ogg_free(l->splitcache);
  106147. memset(l,0,sizeof(*l));
  106148. }
  106149. }
  106150. #endif
  106151. /*** End of inlined file: smallft.c ***/
  106152. /*** Start of inlined file: synthesis.c ***/
  106153. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106154. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106155. // tasks..
  106156. #if JUCE_MSVC
  106157. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106158. #endif
  106159. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106160. #if JUCE_USE_OGGVORBIS
  106161. #include <stdio.h>
  106162. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106163. vorbis_dsp_state *vd=vb->vd;
  106164. private_state *b=(private_state*)vd->backend_state;
  106165. vorbis_info *vi=vd->vi;
  106166. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106167. oggpack_buffer *opb=&vb->opb;
  106168. int type,mode,i;
  106169. _vorbis_block_ripcord(vb);
  106170. oggpack_readinit(opb,op->packet,op->bytes);
  106171. if(oggpack_read(opb,1)!=0){
  106172. return(OV_ENOTAUDIO);
  106173. }
  106174. mode=oggpack_read(opb,b->modebits);
  106175. if(mode==-1)return(OV_EBADPACKET);
  106176. vb->mode=mode;
  106177. vb->W=ci->mode_param[mode]->blockflag;
  106178. if(vb->W){
  106179. vb->lW=oggpack_read(opb,1);
  106180. vb->nW=oggpack_read(opb,1);
  106181. if(vb->nW==-1) return(OV_EBADPACKET);
  106182. }else{
  106183. vb->lW=0;
  106184. vb->nW=0;
  106185. }
  106186. vb->granulepos=op->granulepos;
  106187. vb->sequence=op->packetno;
  106188. vb->eofflag=op->e_o_s;
  106189. vb->pcmend=ci->blocksizes[vb->W];
  106190. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106191. for(i=0;i<vi->channels;i++)
  106192. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106193. type=ci->map_type[ci->mode_param[mode]->mapping];
  106194. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106195. mapping]));
  106196. }
  106197. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106198. vorbis_dsp_state *vd=vb->vd;
  106199. private_state *b=(private_state*)vd->backend_state;
  106200. vorbis_info *vi=vd->vi;
  106201. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106202. oggpack_buffer *opb=&vb->opb;
  106203. int mode;
  106204. _vorbis_block_ripcord(vb);
  106205. oggpack_readinit(opb,op->packet,op->bytes);
  106206. if(oggpack_read(opb,1)!=0){
  106207. return(OV_ENOTAUDIO);
  106208. }
  106209. mode=oggpack_read(opb,b->modebits);
  106210. if(mode==-1)return(OV_EBADPACKET);
  106211. vb->mode=mode;
  106212. vb->W=ci->mode_param[mode]->blockflag;
  106213. if(vb->W){
  106214. vb->lW=oggpack_read(opb,1);
  106215. vb->nW=oggpack_read(opb,1);
  106216. if(vb->nW==-1) return(OV_EBADPACKET);
  106217. }else{
  106218. vb->lW=0;
  106219. vb->nW=0;
  106220. }
  106221. vb->granulepos=op->granulepos;
  106222. vb->sequence=op->packetno;
  106223. vb->eofflag=op->e_o_s;
  106224. vb->pcmend=0;
  106225. vb->pcm=NULL;
  106226. return(0);
  106227. }
  106228. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106229. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106230. oggpack_buffer opb;
  106231. int mode;
  106232. oggpack_readinit(&opb,op->packet,op->bytes);
  106233. if(oggpack_read(&opb,1)!=0){
  106234. return(OV_ENOTAUDIO);
  106235. }
  106236. {
  106237. int modebits=0;
  106238. int v=ci->modes;
  106239. while(v>1){
  106240. modebits++;
  106241. v>>=1;
  106242. }
  106243. mode=oggpack_read(&opb,modebits);
  106244. }
  106245. if(mode==-1)return(OV_EBADPACKET);
  106246. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106247. }
  106248. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106249. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106250. if(ci->blocksizes[0]<=64 && flag)return -1;
  106251. ci->halfrate_flag=(flag?1:0);
  106252. return 0;
  106253. }
  106254. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106255. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106256. return ci->halfrate_flag;
  106257. }
  106258. #endif
  106259. /*** End of inlined file: synthesis.c ***/
  106260. /*** Start of inlined file: vorbisenc.c ***/
  106261. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106262. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106263. // tasks..
  106264. #if JUCE_MSVC
  106265. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106266. #endif
  106267. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106268. #if JUCE_USE_OGGVORBIS
  106269. #include <stdlib.h>
  106270. #include <string.h>
  106271. #include <math.h>
  106272. typedef struct {
  106273. static_codebook *books[12][3];
  106274. } static_bookblock;
  106275. typedef struct {
  106276. int res_type;
  106277. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106278. vorbis_info_residue0 *res;
  106279. static_codebook *book_aux;
  106280. static_codebook *book_aux_managed;
  106281. static_bookblock *books_base;
  106282. static_bookblock *books_base_managed;
  106283. } vorbis_residue_template;
  106284. typedef struct {
  106285. vorbis_info_mapping0 *map;
  106286. vorbis_residue_template *res;
  106287. } vorbis_mapping_template;
  106288. typedef struct vp_adjblock{
  106289. int block[P_BANDS];
  106290. } vp_adjblock;
  106291. typedef struct {
  106292. int data[NOISE_COMPAND_LEVELS];
  106293. } compandblock;
  106294. typedef struct {
  106295. int att[P_NOISECURVES];
  106296. float boost;
  106297. float decay;
  106298. } att3;
  106299. typedef struct { int data[P_NOISECURVES]; } adj3;
  106300. typedef struct {
  106301. int pre[PACKETBLOBS];
  106302. int post[PACKETBLOBS];
  106303. float kHz[PACKETBLOBS];
  106304. float lowpasskHz[PACKETBLOBS];
  106305. } adj_stereo;
  106306. typedef struct {
  106307. int lo;
  106308. int hi;
  106309. int fixed;
  106310. } noiseguard;
  106311. typedef struct {
  106312. int data[P_NOISECURVES][17];
  106313. } noise3;
  106314. typedef struct {
  106315. int mappings;
  106316. double *rate_mapping;
  106317. double *quality_mapping;
  106318. int coupling_restriction;
  106319. long samplerate_min_restriction;
  106320. long samplerate_max_restriction;
  106321. int *blocksize_short;
  106322. int *blocksize_long;
  106323. att3 *psy_tone_masteratt;
  106324. int *psy_tone_0dB;
  106325. int *psy_tone_dBsuppress;
  106326. vp_adjblock *psy_tone_adj_impulse;
  106327. vp_adjblock *psy_tone_adj_long;
  106328. vp_adjblock *psy_tone_adj_other;
  106329. noiseguard *psy_noiseguards;
  106330. noise3 *psy_noise_bias_impulse;
  106331. noise3 *psy_noise_bias_padding;
  106332. noise3 *psy_noise_bias_trans;
  106333. noise3 *psy_noise_bias_long;
  106334. int *psy_noise_dBsuppress;
  106335. compandblock *psy_noise_compand;
  106336. double *psy_noise_compand_short_mapping;
  106337. double *psy_noise_compand_long_mapping;
  106338. int *psy_noise_normal_start[2];
  106339. int *psy_noise_normal_partition[2];
  106340. double *psy_noise_normal_thresh;
  106341. int *psy_ath_float;
  106342. int *psy_ath_abs;
  106343. double *psy_lowpass;
  106344. vorbis_info_psy_global *global_params;
  106345. double *global_mapping;
  106346. adj_stereo *stereo_modes;
  106347. static_codebook ***floor_books;
  106348. vorbis_info_floor1 *floor_params;
  106349. int *floor_short_mapping;
  106350. int *floor_long_mapping;
  106351. vorbis_mapping_template *maps;
  106352. } ve_setup_data_template;
  106353. static vorbis_info_mode _mode_template[2]={
  106354. {0,0,0,0},
  106355. {1,0,0,1}
  106356. };
  106357. static vorbis_info_mapping0 _map_nominal[2]={
  106358. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106359. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106360. };
  106361. /*** Start of inlined file: setup_44.h ***/
  106362. /*** Start of inlined file: floor_all.h ***/
  106363. /*** Start of inlined file: floor_books.h ***/
  106364. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106365. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106366. };
  106367. static static_codebook _huff_book_line_256x7_0sub1 = {
  106368. 1, 9,
  106369. _huff_lengthlist_line_256x7_0sub1,
  106370. 0, 0, 0, 0, 0,
  106371. NULL,
  106372. NULL,
  106373. NULL,
  106374. NULL,
  106375. 0
  106376. };
  106377. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106379. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106380. };
  106381. static static_codebook _huff_book_line_256x7_0sub2 = {
  106382. 1, 25,
  106383. _huff_lengthlist_line_256x7_0sub2,
  106384. 0, 0, 0, 0, 0,
  106385. NULL,
  106386. NULL,
  106387. NULL,
  106388. NULL,
  106389. 0
  106390. };
  106391. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106394. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106395. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106396. };
  106397. static static_codebook _huff_book_line_256x7_0sub3 = {
  106398. 1, 64,
  106399. _huff_lengthlist_line_256x7_0sub3,
  106400. 0, 0, 0, 0, 0,
  106401. NULL,
  106402. NULL,
  106403. NULL,
  106404. NULL,
  106405. 0
  106406. };
  106407. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106408. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106409. };
  106410. static static_codebook _huff_book_line_256x7_1sub1 = {
  106411. 1, 9,
  106412. _huff_lengthlist_line_256x7_1sub1,
  106413. 0, 0, 0, 0, 0,
  106414. NULL,
  106415. NULL,
  106416. NULL,
  106417. NULL,
  106418. 0
  106419. };
  106420. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106422. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106423. };
  106424. static static_codebook _huff_book_line_256x7_1sub2 = {
  106425. 1, 25,
  106426. _huff_lengthlist_line_256x7_1sub2,
  106427. 0, 0, 0, 0, 0,
  106428. NULL,
  106429. NULL,
  106430. NULL,
  106431. NULL,
  106432. 0
  106433. };
  106434. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106437. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106438. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106439. };
  106440. static static_codebook _huff_book_line_256x7_1sub3 = {
  106441. 1, 64,
  106442. _huff_lengthlist_line_256x7_1sub3,
  106443. 0, 0, 0, 0, 0,
  106444. NULL,
  106445. NULL,
  106446. NULL,
  106447. NULL,
  106448. 0
  106449. };
  106450. static long _huff_lengthlist_line_256x7_class0[] = {
  106451. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106452. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106453. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106454. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106455. };
  106456. static static_codebook _huff_book_line_256x7_class0 = {
  106457. 1, 64,
  106458. _huff_lengthlist_line_256x7_class0,
  106459. 0, 0, 0, 0, 0,
  106460. NULL,
  106461. NULL,
  106462. NULL,
  106463. NULL,
  106464. 0
  106465. };
  106466. static long _huff_lengthlist_line_256x7_class1[] = {
  106467. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106468. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106469. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106470. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106471. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106472. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106473. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106474. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106475. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106476. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106477. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106478. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106479. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106480. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106481. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106482. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106483. };
  106484. static static_codebook _huff_book_line_256x7_class1 = {
  106485. 1, 256,
  106486. _huff_lengthlist_line_256x7_class1,
  106487. 0, 0, 0, 0, 0,
  106488. NULL,
  106489. NULL,
  106490. NULL,
  106491. NULL,
  106492. 0
  106493. };
  106494. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106495. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106496. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106497. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106498. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106499. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106500. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106501. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106502. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106503. };
  106504. static static_codebook _huff_book_line_512x17_0sub0 = {
  106505. 1, 128,
  106506. _huff_lengthlist_line_512x17_0sub0,
  106507. 0, 0, 0, 0, 0,
  106508. NULL,
  106509. NULL,
  106510. NULL,
  106511. NULL,
  106512. 0
  106513. };
  106514. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106515. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106516. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106517. };
  106518. static static_codebook _huff_book_line_512x17_1sub0 = {
  106519. 1, 32,
  106520. _huff_lengthlist_line_512x17_1sub0,
  106521. 0, 0, 0, 0, 0,
  106522. NULL,
  106523. NULL,
  106524. NULL,
  106525. NULL,
  106526. 0
  106527. };
  106528. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106531. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106532. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106533. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106534. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106535. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106536. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106537. };
  106538. static static_codebook _huff_book_line_512x17_1sub1 = {
  106539. 1, 128,
  106540. _huff_lengthlist_line_512x17_1sub1,
  106541. 0, 0, 0, 0, 0,
  106542. NULL,
  106543. NULL,
  106544. NULL,
  106545. NULL,
  106546. 0
  106547. };
  106548. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106549. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106550. 5, 3,
  106551. };
  106552. static static_codebook _huff_book_line_512x17_2sub1 = {
  106553. 1, 18,
  106554. _huff_lengthlist_line_512x17_2sub1,
  106555. 0, 0, 0, 0, 0,
  106556. NULL,
  106557. NULL,
  106558. NULL,
  106559. NULL,
  106560. 0
  106561. };
  106562. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106564. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106565. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106566. 9, 8,
  106567. };
  106568. static static_codebook _huff_book_line_512x17_2sub2 = {
  106569. 1, 50,
  106570. _huff_lengthlist_line_512x17_2sub2,
  106571. 0, 0, 0, 0, 0,
  106572. NULL,
  106573. NULL,
  106574. NULL,
  106575. NULL,
  106576. 0
  106577. };
  106578. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106582. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106583. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106584. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106585. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106586. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106587. };
  106588. static static_codebook _huff_book_line_512x17_2sub3 = {
  106589. 1, 128,
  106590. _huff_lengthlist_line_512x17_2sub3,
  106591. 0, 0, 0, 0, 0,
  106592. NULL,
  106593. NULL,
  106594. NULL,
  106595. NULL,
  106596. 0
  106597. };
  106598. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106599. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106600. 5, 5,
  106601. };
  106602. static static_codebook _huff_book_line_512x17_3sub1 = {
  106603. 1, 18,
  106604. _huff_lengthlist_line_512x17_3sub1,
  106605. 0, 0, 0, 0, 0,
  106606. NULL,
  106607. NULL,
  106608. NULL,
  106609. NULL,
  106610. 0
  106611. };
  106612. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106614. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106615. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106616. 11,14,
  106617. };
  106618. static static_codebook _huff_book_line_512x17_3sub2 = {
  106619. 1, 50,
  106620. _huff_lengthlist_line_512x17_3sub2,
  106621. 0, 0, 0, 0, 0,
  106622. NULL,
  106623. NULL,
  106624. NULL,
  106625. NULL,
  106626. 0
  106627. };
  106628. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106632. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106633. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106634. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106635. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106636. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106637. };
  106638. static static_codebook _huff_book_line_512x17_3sub3 = {
  106639. 1, 128,
  106640. _huff_lengthlist_line_512x17_3sub3,
  106641. 0, 0, 0, 0, 0,
  106642. NULL,
  106643. NULL,
  106644. NULL,
  106645. NULL,
  106646. 0
  106647. };
  106648. static long _huff_lengthlist_line_512x17_class1[] = {
  106649. 1, 2, 3, 6, 5, 4, 7, 7,
  106650. };
  106651. static static_codebook _huff_book_line_512x17_class1 = {
  106652. 1, 8,
  106653. _huff_lengthlist_line_512x17_class1,
  106654. 0, 0, 0, 0, 0,
  106655. NULL,
  106656. NULL,
  106657. NULL,
  106658. NULL,
  106659. 0
  106660. };
  106661. static long _huff_lengthlist_line_512x17_class2[] = {
  106662. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106663. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106664. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106665. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106666. };
  106667. static static_codebook _huff_book_line_512x17_class2 = {
  106668. 1, 64,
  106669. _huff_lengthlist_line_512x17_class2,
  106670. 0, 0, 0, 0, 0,
  106671. NULL,
  106672. NULL,
  106673. NULL,
  106674. NULL,
  106675. 0
  106676. };
  106677. static long _huff_lengthlist_line_512x17_class3[] = {
  106678. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106679. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106680. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106681. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106682. };
  106683. static static_codebook _huff_book_line_512x17_class3 = {
  106684. 1, 64,
  106685. _huff_lengthlist_line_512x17_class3,
  106686. 0, 0, 0, 0, 0,
  106687. NULL,
  106688. NULL,
  106689. NULL,
  106690. NULL,
  106691. 0
  106692. };
  106693. static long _huff_lengthlist_line_128x4_class0[] = {
  106694. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106695. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106696. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106697. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106698. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106699. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106700. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106701. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106702. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106703. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106704. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106705. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106706. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106707. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106708. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106709. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106710. };
  106711. static static_codebook _huff_book_line_128x4_class0 = {
  106712. 1, 256,
  106713. _huff_lengthlist_line_128x4_class0,
  106714. 0, 0, 0, 0, 0,
  106715. NULL,
  106716. NULL,
  106717. NULL,
  106718. NULL,
  106719. 0
  106720. };
  106721. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106722. 2, 2, 2, 2,
  106723. };
  106724. static static_codebook _huff_book_line_128x4_0sub0 = {
  106725. 1, 4,
  106726. _huff_lengthlist_line_128x4_0sub0,
  106727. 0, 0, 0, 0, 0,
  106728. NULL,
  106729. NULL,
  106730. NULL,
  106731. NULL,
  106732. 0
  106733. };
  106734. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106735. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106736. };
  106737. static static_codebook _huff_book_line_128x4_0sub1 = {
  106738. 1, 10,
  106739. _huff_lengthlist_line_128x4_0sub1,
  106740. 0, 0, 0, 0, 0,
  106741. NULL,
  106742. NULL,
  106743. NULL,
  106744. NULL,
  106745. 0
  106746. };
  106747. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106749. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106750. };
  106751. static static_codebook _huff_book_line_128x4_0sub2 = {
  106752. 1, 25,
  106753. _huff_lengthlist_line_128x4_0sub2,
  106754. 0, 0, 0, 0, 0,
  106755. NULL,
  106756. NULL,
  106757. NULL,
  106758. NULL,
  106759. 0
  106760. };
  106761. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106764. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106765. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106766. };
  106767. static static_codebook _huff_book_line_128x4_0sub3 = {
  106768. 1, 64,
  106769. _huff_lengthlist_line_128x4_0sub3,
  106770. 0, 0, 0, 0, 0,
  106771. NULL,
  106772. NULL,
  106773. NULL,
  106774. NULL,
  106775. 0
  106776. };
  106777. static long _huff_lengthlist_line_256x4_class0[] = {
  106778. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106779. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106780. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106781. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106782. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106783. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106784. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106785. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106786. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106787. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106788. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106789. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106790. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106791. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106792. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106793. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106794. };
  106795. static static_codebook _huff_book_line_256x4_class0 = {
  106796. 1, 256,
  106797. _huff_lengthlist_line_256x4_class0,
  106798. 0, 0, 0, 0, 0,
  106799. NULL,
  106800. NULL,
  106801. NULL,
  106802. NULL,
  106803. 0
  106804. };
  106805. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106806. 2, 2, 2, 2,
  106807. };
  106808. static static_codebook _huff_book_line_256x4_0sub0 = {
  106809. 1, 4,
  106810. _huff_lengthlist_line_256x4_0sub0,
  106811. 0, 0, 0, 0, 0,
  106812. NULL,
  106813. NULL,
  106814. NULL,
  106815. NULL,
  106816. 0
  106817. };
  106818. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106819. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106820. };
  106821. static static_codebook _huff_book_line_256x4_0sub1 = {
  106822. 1, 10,
  106823. _huff_lengthlist_line_256x4_0sub1,
  106824. 0, 0, 0, 0, 0,
  106825. NULL,
  106826. NULL,
  106827. NULL,
  106828. NULL,
  106829. 0
  106830. };
  106831. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106833. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106834. };
  106835. static static_codebook _huff_book_line_256x4_0sub2 = {
  106836. 1, 25,
  106837. _huff_lengthlist_line_256x4_0sub2,
  106838. 0, 0, 0, 0, 0,
  106839. NULL,
  106840. NULL,
  106841. NULL,
  106842. NULL,
  106843. 0
  106844. };
  106845. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106848. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106849. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106850. };
  106851. static static_codebook _huff_book_line_256x4_0sub3 = {
  106852. 1, 64,
  106853. _huff_lengthlist_line_256x4_0sub3,
  106854. 0, 0, 0, 0, 0,
  106855. NULL,
  106856. NULL,
  106857. NULL,
  106858. NULL,
  106859. 0
  106860. };
  106861. static long _huff_lengthlist_line_128x7_class0[] = {
  106862. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106863. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106864. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106865. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106866. };
  106867. static static_codebook _huff_book_line_128x7_class0 = {
  106868. 1, 64,
  106869. _huff_lengthlist_line_128x7_class0,
  106870. 0, 0, 0, 0, 0,
  106871. NULL,
  106872. NULL,
  106873. NULL,
  106874. NULL,
  106875. 0
  106876. };
  106877. static long _huff_lengthlist_line_128x7_class1[] = {
  106878. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106879. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106880. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106881. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106882. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106883. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106884. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106885. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106886. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106887. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106888. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106889. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106890. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106891. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106892. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106893. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106894. };
  106895. static static_codebook _huff_book_line_128x7_class1 = {
  106896. 1, 256,
  106897. _huff_lengthlist_line_128x7_class1,
  106898. 0, 0, 0, 0, 0,
  106899. NULL,
  106900. NULL,
  106901. NULL,
  106902. NULL,
  106903. 0
  106904. };
  106905. static long _huff_lengthlist_line_128x7_0sub1[] = {
  106906. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  106907. };
  106908. static static_codebook _huff_book_line_128x7_0sub1 = {
  106909. 1, 9,
  106910. _huff_lengthlist_line_128x7_0sub1,
  106911. 0, 0, 0, 0, 0,
  106912. NULL,
  106913. NULL,
  106914. NULL,
  106915. NULL,
  106916. 0
  106917. };
  106918. static long _huff_lengthlist_line_128x7_0sub2[] = {
  106919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  106920. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  106921. };
  106922. static static_codebook _huff_book_line_128x7_0sub2 = {
  106923. 1, 25,
  106924. _huff_lengthlist_line_128x7_0sub2,
  106925. 0, 0, 0, 0, 0,
  106926. NULL,
  106927. NULL,
  106928. NULL,
  106929. NULL,
  106930. 0
  106931. };
  106932. static long _huff_lengthlist_line_128x7_0sub3[] = {
  106933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  106935. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106936. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  106937. };
  106938. static static_codebook _huff_book_line_128x7_0sub3 = {
  106939. 1, 64,
  106940. _huff_lengthlist_line_128x7_0sub3,
  106941. 0, 0, 0, 0, 0,
  106942. NULL,
  106943. NULL,
  106944. NULL,
  106945. NULL,
  106946. 0
  106947. };
  106948. static long _huff_lengthlist_line_128x7_1sub1[] = {
  106949. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  106950. };
  106951. static static_codebook _huff_book_line_128x7_1sub1 = {
  106952. 1, 9,
  106953. _huff_lengthlist_line_128x7_1sub1,
  106954. 0, 0, 0, 0, 0,
  106955. NULL,
  106956. NULL,
  106957. NULL,
  106958. NULL,
  106959. 0
  106960. };
  106961. static long _huff_lengthlist_line_128x7_1sub2[] = {
  106962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  106963. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  106964. };
  106965. static static_codebook _huff_book_line_128x7_1sub2 = {
  106966. 1, 25,
  106967. _huff_lengthlist_line_128x7_1sub2,
  106968. 0, 0, 0, 0, 0,
  106969. NULL,
  106970. NULL,
  106971. NULL,
  106972. NULL,
  106973. 0
  106974. };
  106975. static long _huff_lengthlist_line_128x7_1sub3[] = {
  106976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  106978. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  106979. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  106980. };
  106981. static static_codebook _huff_book_line_128x7_1sub3 = {
  106982. 1, 64,
  106983. _huff_lengthlist_line_128x7_1sub3,
  106984. 0, 0, 0, 0, 0,
  106985. NULL,
  106986. NULL,
  106987. NULL,
  106988. NULL,
  106989. 0
  106990. };
  106991. static long _huff_lengthlist_line_128x11_class1[] = {
  106992. 1, 6, 3, 7, 2, 4, 5, 7,
  106993. };
  106994. static static_codebook _huff_book_line_128x11_class1 = {
  106995. 1, 8,
  106996. _huff_lengthlist_line_128x11_class1,
  106997. 0, 0, 0, 0, 0,
  106998. NULL,
  106999. NULL,
  107000. NULL,
  107001. NULL,
  107002. 0
  107003. };
  107004. static long _huff_lengthlist_line_128x11_class2[] = {
  107005. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107006. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107007. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107008. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107009. };
  107010. static static_codebook _huff_book_line_128x11_class2 = {
  107011. 1, 64,
  107012. _huff_lengthlist_line_128x11_class2,
  107013. 0, 0, 0, 0, 0,
  107014. NULL,
  107015. NULL,
  107016. NULL,
  107017. NULL,
  107018. 0
  107019. };
  107020. static long _huff_lengthlist_line_128x11_class3[] = {
  107021. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107022. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107023. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107024. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107025. };
  107026. static static_codebook _huff_book_line_128x11_class3 = {
  107027. 1, 64,
  107028. _huff_lengthlist_line_128x11_class3,
  107029. 0, 0, 0, 0, 0,
  107030. NULL,
  107031. NULL,
  107032. NULL,
  107033. NULL,
  107034. 0
  107035. };
  107036. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107037. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107038. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107039. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107040. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107041. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107042. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107043. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107044. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107045. };
  107046. static static_codebook _huff_book_line_128x11_0sub0 = {
  107047. 1, 128,
  107048. _huff_lengthlist_line_128x11_0sub0,
  107049. 0, 0, 0, 0, 0,
  107050. NULL,
  107051. NULL,
  107052. NULL,
  107053. NULL,
  107054. 0
  107055. };
  107056. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107057. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107058. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107059. };
  107060. static static_codebook _huff_book_line_128x11_1sub0 = {
  107061. 1, 32,
  107062. _huff_lengthlist_line_128x11_1sub0,
  107063. 0, 0, 0, 0, 0,
  107064. NULL,
  107065. NULL,
  107066. NULL,
  107067. NULL,
  107068. 0
  107069. };
  107070. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107073. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107074. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107075. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107076. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107077. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107078. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107079. };
  107080. static static_codebook _huff_book_line_128x11_1sub1 = {
  107081. 1, 128,
  107082. _huff_lengthlist_line_128x11_1sub1,
  107083. 0, 0, 0, 0, 0,
  107084. NULL,
  107085. NULL,
  107086. NULL,
  107087. NULL,
  107088. 0
  107089. };
  107090. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107091. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107092. 5, 5,
  107093. };
  107094. static static_codebook _huff_book_line_128x11_2sub1 = {
  107095. 1, 18,
  107096. _huff_lengthlist_line_128x11_2sub1,
  107097. 0, 0, 0, 0, 0,
  107098. NULL,
  107099. NULL,
  107100. NULL,
  107101. NULL,
  107102. 0
  107103. };
  107104. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107106. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107107. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107108. 8,11,
  107109. };
  107110. static static_codebook _huff_book_line_128x11_2sub2 = {
  107111. 1, 50,
  107112. _huff_lengthlist_line_128x11_2sub2,
  107113. 0, 0, 0, 0, 0,
  107114. NULL,
  107115. NULL,
  107116. NULL,
  107117. NULL,
  107118. 0
  107119. };
  107120. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107124. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107125. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107126. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107127. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107128. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107129. };
  107130. static static_codebook _huff_book_line_128x11_2sub3 = {
  107131. 1, 128,
  107132. _huff_lengthlist_line_128x11_2sub3,
  107133. 0, 0, 0, 0, 0,
  107134. NULL,
  107135. NULL,
  107136. NULL,
  107137. NULL,
  107138. 0
  107139. };
  107140. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107141. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107142. 5, 4,
  107143. };
  107144. static static_codebook _huff_book_line_128x11_3sub1 = {
  107145. 1, 18,
  107146. _huff_lengthlist_line_128x11_3sub1,
  107147. 0, 0, 0, 0, 0,
  107148. NULL,
  107149. NULL,
  107150. NULL,
  107151. NULL,
  107152. 0
  107153. };
  107154. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107156. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107157. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107158. 12, 6,
  107159. };
  107160. static static_codebook _huff_book_line_128x11_3sub2 = {
  107161. 1, 50,
  107162. _huff_lengthlist_line_128x11_3sub2,
  107163. 0, 0, 0, 0, 0,
  107164. NULL,
  107165. NULL,
  107166. NULL,
  107167. NULL,
  107168. 0
  107169. };
  107170. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107174. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107175. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107176. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107177. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107178. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107179. };
  107180. static static_codebook _huff_book_line_128x11_3sub3 = {
  107181. 1, 128,
  107182. _huff_lengthlist_line_128x11_3sub3,
  107183. 0, 0, 0, 0, 0,
  107184. NULL,
  107185. NULL,
  107186. NULL,
  107187. NULL,
  107188. 0
  107189. };
  107190. static long _huff_lengthlist_line_128x17_class1[] = {
  107191. 1, 3, 4, 7, 2, 5, 6, 7,
  107192. };
  107193. static static_codebook _huff_book_line_128x17_class1 = {
  107194. 1, 8,
  107195. _huff_lengthlist_line_128x17_class1,
  107196. 0, 0, 0, 0, 0,
  107197. NULL,
  107198. NULL,
  107199. NULL,
  107200. NULL,
  107201. 0
  107202. };
  107203. static long _huff_lengthlist_line_128x17_class2[] = {
  107204. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107205. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107206. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107207. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107208. };
  107209. static static_codebook _huff_book_line_128x17_class2 = {
  107210. 1, 64,
  107211. _huff_lengthlist_line_128x17_class2,
  107212. 0, 0, 0, 0, 0,
  107213. NULL,
  107214. NULL,
  107215. NULL,
  107216. NULL,
  107217. 0
  107218. };
  107219. static long _huff_lengthlist_line_128x17_class3[] = {
  107220. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107221. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107222. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107223. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107224. };
  107225. static static_codebook _huff_book_line_128x17_class3 = {
  107226. 1, 64,
  107227. _huff_lengthlist_line_128x17_class3,
  107228. 0, 0, 0, 0, 0,
  107229. NULL,
  107230. NULL,
  107231. NULL,
  107232. NULL,
  107233. 0
  107234. };
  107235. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107236. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107237. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107238. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107239. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107240. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107241. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107242. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107243. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107244. };
  107245. static static_codebook _huff_book_line_128x17_0sub0 = {
  107246. 1, 128,
  107247. _huff_lengthlist_line_128x17_0sub0,
  107248. 0, 0, 0, 0, 0,
  107249. NULL,
  107250. NULL,
  107251. NULL,
  107252. NULL,
  107253. 0
  107254. };
  107255. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107256. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107257. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107258. };
  107259. static static_codebook _huff_book_line_128x17_1sub0 = {
  107260. 1, 32,
  107261. _huff_lengthlist_line_128x17_1sub0,
  107262. 0, 0, 0, 0, 0,
  107263. NULL,
  107264. NULL,
  107265. NULL,
  107266. NULL,
  107267. 0
  107268. };
  107269. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107272. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107273. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107274. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107275. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107276. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107277. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107278. };
  107279. static static_codebook _huff_book_line_128x17_1sub1 = {
  107280. 1, 128,
  107281. _huff_lengthlist_line_128x17_1sub1,
  107282. 0, 0, 0, 0, 0,
  107283. NULL,
  107284. NULL,
  107285. NULL,
  107286. NULL,
  107287. 0
  107288. };
  107289. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107290. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107291. 9, 4,
  107292. };
  107293. static static_codebook _huff_book_line_128x17_2sub1 = {
  107294. 1, 18,
  107295. _huff_lengthlist_line_128x17_2sub1,
  107296. 0, 0, 0, 0, 0,
  107297. NULL,
  107298. NULL,
  107299. NULL,
  107300. NULL,
  107301. 0
  107302. };
  107303. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107305. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107306. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107307. 13,13,
  107308. };
  107309. static static_codebook _huff_book_line_128x17_2sub2 = {
  107310. 1, 50,
  107311. _huff_lengthlist_line_128x17_2sub2,
  107312. 0, 0, 0, 0, 0,
  107313. NULL,
  107314. NULL,
  107315. NULL,
  107316. NULL,
  107317. 0
  107318. };
  107319. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107323. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107324. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107325. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107326. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107327. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107328. };
  107329. static static_codebook _huff_book_line_128x17_2sub3 = {
  107330. 1, 128,
  107331. _huff_lengthlist_line_128x17_2sub3,
  107332. 0, 0, 0, 0, 0,
  107333. NULL,
  107334. NULL,
  107335. NULL,
  107336. NULL,
  107337. 0
  107338. };
  107339. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107340. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107341. 6, 4,
  107342. };
  107343. static static_codebook _huff_book_line_128x17_3sub1 = {
  107344. 1, 18,
  107345. _huff_lengthlist_line_128x17_3sub1,
  107346. 0, 0, 0, 0, 0,
  107347. NULL,
  107348. NULL,
  107349. NULL,
  107350. NULL,
  107351. 0
  107352. };
  107353. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107355. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107356. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107357. 10, 8,
  107358. };
  107359. static static_codebook _huff_book_line_128x17_3sub2 = {
  107360. 1, 50,
  107361. _huff_lengthlist_line_128x17_3sub2,
  107362. 0, 0, 0, 0, 0,
  107363. NULL,
  107364. NULL,
  107365. NULL,
  107366. NULL,
  107367. 0
  107368. };
  107369. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107373. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107374. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107375. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107376. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107377. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107378. };
  107379. static static_codebook _huff_book_line_128x17_3sub3 = {
  107380. 1, 128,
  107381. _huff_lengthlist_line_128x17_3sub3,
  107382. 0, 0, 0, 0, 0,
  107383. NULL,
  107384. NULL,
  107385. NULL,
  107386. NULL,
  107387. 0
  107388. };
  107389. static long _huff_lengthlist_line_1024x27_class1[] = {
  107390. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107391. };
  107392. static static_codebook _huff_book_line_1024x27_class1 = {
  107393. 1, 16,
  107394. _huff_lengthlist_line_1024x27_class1,
  107395. 0, 0, 0, 0, 0,
  107396. NULL,
  107397. NULL,
  107398. NULL,
  107399. NULL,
  107400. 0
  107401. };
  107402. static long _huff_lengthlist_line_1024x27_class2[] = {
  107403. 1, 4, 2, 6, 3, 7, 5, 7,
  107404. };
  107405. static static_codebook _huff_book_line_1024x27_class2 = {
  107406. 1, 8,
  107407. _huff_lengthlist_line_1024x27_class2,
  107408. 0, 0, 0, 0, 0,
  107409. NULL,
  107410. NULL,
  107411. NULL,
  107412. NULL,
  107413. 0
  107414. };
  107415. static long _huff_lengthlist_line_1024x27_class3[] = {
  107416. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107417. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107418. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107419. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107420. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107421. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107422. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107423. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107424. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107425. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107426. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107427. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107428. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107429. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107430. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107431. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107432. };
  107433. static static_codebook _huff_book_line_1024x27_class3 = {
  107434. 1, 256,
  107435. _huff_lengthlist_line_1024x27_class3,
  107436. 0, 0, 0, 0, 0,
  107437. NULL,
  107438. NULL,
  107439. NULL,
  107440. NULL,
  107441. 0
  107442. };
  107443. static long _huff_lengthlist_line_1024x27_class4[] = {
  107444. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107445. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107446. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107447. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107448. };
  107449. static static_codebook _huff_book_line_1024x27_class4 = {
  107450. 1, 64,
  107451. _huff_lengthlist_line_1024x27_class4,
  107452. 0, 0, 0, 0, 0,
  107453. NULL,
  107454. NULL,
  107455. NULL,
  107456. NULL,
  107457. 0
  107458. };
  107459. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107460. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107461. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107462. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107463. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107464. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107465. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107466. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107467. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107468. };
  107469. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107470. 1, 128,
  107471. _huff_lengthlist_line_1024x27_0sub0,
  107472. 0, 0, 0, 0, 0,
  107473. NULL,
  107474. NULL,
  107475. NULL,
  107476. NULL,
  107477. 0
  107478. };
  107479. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107480. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107481. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107482. };
  107483. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107484. 1, 32,
  107485. _huff_lengthlist_line_1024x27_1sub0,
  107486. 0, 0, 0, 0, 0,
  107487. NULL,
  107488. NULL,
  107489. NULL,
  107490. NULL,
  107491. 0
  107492. };
  107493. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107496. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107497. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107498. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107499. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107500. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107501. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107502. };
  107503. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107504. 1, 128,
  107505. _huff_lengthlist_line_1024x27_1sub1,
  107506. 0, 0, 0, 0, 0,
  107507. NULL,
  107508. NULL,
  107509. NULL,
  107510. NULL,
  107511. 0
  107512. };
  107513. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107514. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107515. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107516. };
  107517. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107518. 1, 32,
  107519. _huff_lengthlist_line_1024x27_2sub0,
  107520. 0, 0, 0, 0, 0,
  107521. NULL,
  107522. NULL,
  107523. NULL,
  107524. NULL,
  107525. 0
  107526. };
  107527. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107530. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107531. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107532. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107533. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107534. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107535. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107536. };
  107537. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107538. 1, 128,
  107539. _huff_lengthlist_line_1024x27_2sub1,
  107540. 0, 0, 0, 0, 0,
  107541. NULL,
  107542. NULL,
  107543. NULL,
  107544. NULL,
  107545. 0
  107546. };
  107547. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107548. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107549. 5, 5,
  107550. };
  107551. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107552. 1, 18,
  107553. _huff_lengthlist_line_1024x27_3sub1,
  107554. 0, 0, 0, 0, 0,
  107555. NULL,
  107556. NULL,
  107557. NULL,
  107558. NULL,
  107559. 0
  107560. };
  107561. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107563. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107564. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107565. 9,11,
  107566. };
  107567. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107568. 1, 50,
  107569. _huff_lengthlist_line_1024x27_3sub2,
  107570. 0, 0, 0, 0, 0,
  107571. NULL,
  107572. NULL,
  107573. NULL,
  107574. NULL,
  107575. 0
  107576. };
  107577. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107581. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107582. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107583. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107584. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107585. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107586. };
  107587. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107588. 1, 128,
  107589. _huff_lengthlist_line_1024x27_3sub3,
  107590. 0, 0, 0, 0, 0,
  107591. NULL,
  107592. NULL,
  107593. NULL,
  107594. NULL,
  107595. 0
  107596. };
  107597. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107598. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107599. 5, 4,
  107600. };
  107601. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107602. 1, 18,
  107603. _huff_lengthlist_line_1024x27_4sub1,
  107604. 0, 0, 0, 0, 0,
  107605. NULL,
  107606. NULL,
  107607. NULL,
  107608. NULL,
  107609. 0
  107610. };
  107611. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107613. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107614. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107615. 9,12,
  107616. };
  107617. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107618. 1, 50,
  107619. _huff_lengthlist_line_1024x27_4sub2,
  107620. 0, 0, 0, 0, 0,
  107621. NULL,
  107622. NULL,
  107623. NULL,
  107624. NULL,
  107625. 0
  107626. };
  107627. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107631. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107632. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107633. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107634. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107635. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107636. };
  107637. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107638. 1, 128,
  107639. _huff_lengthlist_line_1024x27_4sub3,
  107640. 0, 0, 0, 0, 0,
  107641. NULL,
  107642. NULL,
  107643. NULL,
  107644. NULL,
  107645. 0
  107646. };
  107647. static long _huff_lengthlist_line_2048x27_class1[] = {
  107648. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107649. };
  107650. static static_codebook _huff_book_line_2048x27_class1 = {
  107651. 1, 16,
  107652. _huff_lengthlist_line_2048x27_class1,
  107653. 0, 0, 0, 0, 0,
  107654. NULL,
  107655. NULL,
  107656. NULL,
  107657. NULL,
  107658. 0
  107659. };
  107660. static long _huff_lengthlist_line_2048x27_class2[] = {
  107661. 1, 2, 3, 6, 4, 7, 5, 7,
  107662. };
  107663. static static_codebook _huff_book_line_2048x27_class2 = {
  107664. 1, 8,
  107665. _huff_lengthlist_line_2048x27_class2,
  107666. 0, 0, 0, 0, 0,
  107667. NULL,
  107668. NULL,
  107669. NULL,
  107670. NULL,
  107671. 0
  107672. };
  107673. static long _huff_lengthlist_line_2048x27_class3[] = {
  107674. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107675. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107676. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107677. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107678. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107679. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107680. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107681. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107682. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107683. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107684. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107685. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107686. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107687. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107688. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107689. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107690. };
  107691. static static_codebook _huff_book_line_2048x27_class3 = {
  107692. 1, 256,
  107693. _huff_lengthlist_line_2048x27_class3,
  107694. 0, 0, 0, 0, 0,
  107695. NULL,
  107696. NULL,
  107697. NULL,
  107698. NULL,
  107699. 0
  107700. };
  107701. static long _huff_lengthlist_line_2048x27_class4[] = {
  107702. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107703. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107704. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107705. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107706. };
  107707. static static_codebook _huff_book_line_2048x27_class4 = {
  107708. 1, 64,
  107709. _huff_lengthlist_line_2048x27_class4,
  107710. 0, 0, 0, 0, 0,
  107711. NULL,
  107712. NULL,
  107713. NULL,
  107714. NULL,
  107715. 0
  107716. };
  107717. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107718. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107719. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107720. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107721. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107722. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107723. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107724. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107725. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107726. };
  107727. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107728. 1, 128,
  107729. _huff_lengthlist_line_2048x27_0sub0,
  107730. 0, 0, 0, 0, 0,
  107731. NULL,
  107732. NULL,
  107733. NULL,
  107734. NULL,
  107735. 0
  107736. };
  107737. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107738. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107739. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107740. };
  107741. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107742. 1, 32,
  107743. _huff_lengthlist_line_2048x27_1sub0,
  107744. 0, 0, 0, 0, 0,
  107745. NULL,
  107746. NULL,
  107747. NULL,
  107748. NULL,
  107749. 0
  107750. };
  107751. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107754. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107755. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107756. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107757. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107758. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107759. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107760. };
  107761. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107762. 1, 128,
  107763. _huff_lengthlist_line_2048x27_1sub1,
  107764. 0, 0, 0, 0, 0,
  107765. NULL,
  107766. NULL,
  107767. NULL,
  107768. NULL,
  107769. 0
  107770. };
  107771. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107772. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107773. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107774. };
  107775. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107776. 1, 32,
  107777. _huff_lengthlist_line_2048x27_2sub0,
  107778. 0, 0, 0, 0, 0,
  107779. NULL,
  107780. NULL,
  107781. NULL,
  107782. NULL,
  107783. 0
  107784. };
  107785. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107788. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107789. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107790. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107791. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107792. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107793. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107794. };
  107795. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107796. 1, 128,
  107797. _huff_lengthlist_line_2048x27_2sub1,
  107798. 0, 0, 0, 0, 0,
  107799. NULL,
  107800. NULL,
  107801. NULL,
  107802. NULL,
  107803. 0
  107804. };
  107805. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107806. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107807. 5, 5,
  107808. };
  107809. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107810. 1, 18,
  107811. _huff_lengthlist_line_2048x27_3sub1,
  107812. 0, 0, 0, 0, 0,
  107813. NULL,
  107814. NULL,
  107815. NULL,
  107816. NULL,
  107817. 0
  107818. };
  107819. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107821. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107822. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107823. 10,12,
  107824. };
  107825. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107826. 1, 50,
  107827. _huff_lengthlist_line_2048x27_3sub2,
  107828. 0, 0, 0, 0, 0,
  107829. NULL,
  107830. NULL,
  107831. NULL,
  107832. NULL,
  107833. 0
  107834. };
  107835. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107839. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107840. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107841. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107842. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107843. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107844. };
  107845. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107846. 1, 128,
  107847. _huff_lengthlist_line_2048x27_3sub3,
  107848. 0, 0, 0, 0, 0,
  107849. NULL,
  107850. NULL,
  107851. NULL,
  107852. NULL,
  107853. 0
  107854. };
  107855. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107856. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107857. 4, 5,
  107858. };
  107859. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107860. 1, 18,
  107861. _huff_lengthlist_line_2048x27_4sub1,
  107862. 0, 0, 0, 0, 0,
  107863. NULL,
  107864. NULL,
  107865. NULL,
  107866. NULL,
  107867. 0
  107868. };
  107869. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107871. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107872. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107873. 10,10,
  107874. };
  107875. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107876. 1, 50,
  107877. _huff_lengthlist_line_2048x27_4sub2,
  107878. 0, 0, 0, 0, 0,
  107879. NULL,
  107880. NULL,
  107881. NULL,
  107882. NULL,
  107883. 0
  107884. };
  107885. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107889. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107890. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107891. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107892. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107893. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107894. };
  107895. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107896. 1, 128,
  107897. _huff_lengthlist_line_2048x27_4sub3,
  107898. 0, 0, 0, 0, 0,
  107899. NULL,
  107900. NULL,
  107901. NULL,
  107902. NULL,
  107903. 0
  107904. };
  107905. static long _huff_lengthlist_line_256x4low_class0[] = {
  107906. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  107907. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  107908. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  107909. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  107910. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  107911. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  107912. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  107913. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  107914. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  107915. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  107916. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  107917. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  107918. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  107919. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  107920. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  107921. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  107922. };
  107923. static static_codebook _huff_book_line_256x4low_class0 = {
  107924. 1, 256,
  107925. _huff_lengthlist_line_256x4low_class0,
  107926. 0, 0, 0, 0, 0,
  107927. NULL,
  107928. NULL,
  107929. NULL,
  107930. NULL,
  107931. 0
  107932. };
  107933. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  107934. 1, 3, 2, 3,
  107935. };
  107936. static static_codebook _huff_book_line_256x4low_0sub0 = {
  107937. 1, 4,
  107938. _huff_lengthlist_line_256x4low_0sub0,
  107939. 0, 0, 0, 0, 0,
  107940. NULL,
  107941. NULL,
  107942. NULL,
  107943. NULL,
  107944. 0
  107945. };
  107946. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  107947. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  107948. };
  107949. static static_codebook _huff_book_line_256x4low_0sub1 = {
  107950. 1, 10,
  107951. _huff_lengthlist_line_256x4low_0sub1,
  107952. 0, 0, 0, 0, 0,
  107953. NULL,
  107954. NULL,
  107955. NULL,
  107956. NULL,
  107957. 0
  107958. };
  107959. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  107960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  107961. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  107962. };
  107963. static static_codebook _huff_book_line_256x4low_0sub2 = {
  107964. 1, 25,
  107965. _huff_lengthlist_line_256x4low_0sub2,
  107966. 0, 0, 0, 0, 0,
  107967. NULL,
  107968. NULL,
  107969. NULL,
  107970. NULL,
  107971. 0
  107972. };
  107973. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  107974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  107976. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  107977. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  107978. };
  107979. static static_codebook _huff_book_line_256x4low_0sub3 = {
  107980. 1, 64,
  107981. _huff_lengthlist_line_256x4low_0sub3,
  107982. 0, 0, 0, 0, 0,
  107983. NULL,
  107984. NULL,
  107985. NULL,
  107986. NULL,
  107987. 0
  107988. };
  107989. /*** End of inlined file: floor_books.h ***/
  107990. static static_codebook *_floor_128x4_books[]={
  107991. &_huff_book_line_128x4_class0,
  107992. &_huff_book_line_128x4_0sub0,
  107993. &_huff_book_line_128x4_0sub1,
  107994. &_huff_book_line_128x4_0sub2,
  107995. &_huff_book_line_128x4_0sub3,
  107996. };
  107997. static static_codebook *_floor_256x4_books[]={
  107998. &_huff_book_line_256x4_class0,
  107999. &_huff_book_line_256x4_0sub0,
  108000. &_huff_book_line_256x4_0sub1,
  108001. &_huff_book_line_256x4_0sub2,
  108002. &_huff_book_line_256x4_0sub3,
  108003. };
  108004. static static_codebook *_floor_128x7_books[]={
  108005. &_huff_book_line_128x7_class0,
  108006. &_huff_book_line_128x7_class1,
  108007. &_huff_book_line_128x7_0sub1,
  108008. &_huff_book_line_128x7_0sub2,
  108009. &_huff_book_line_128x7_0sub3,
  108010. &_huff_book_line_128x7_1sub1,
  108011. &_huff_book_line_128x7_1sub2,
  108012. &_huff_book_line_128x7_1sub3,
  108013. };
  108014. static static_codebook *_floor_256x7_books[]={
  108015. &_huff_book_line_256x7_class0,
  108016. &_huff_book_line_256x7_class1,
  108017. &_huff_book_line_256x7_0sub1,
  108018. &_huff_book_line_256x7_0sub2,
  108019. &_huff_book_line_256x7_0sub3,
  108020. &_huff_book_line_256x7_1sub1,
  108021. &_huff_book_line_256x7_1sub2,
  108022. &_huff_book_line_256x7_1sub3,
  108023. };
  108024. static static_codebook *_floor_128x11_books[]={
  108025. &_huff_book_line_128x11_class1,
  108026. &_huff_book_line_128x11_class2,
  108027. &_huff_book_line_128x11_class3,
  108028. &_huff_book_line_128x11_0sub0,
  108029. &_huff_book_line_128x11_1sub0,
  108030. &_huff_book_line_128x11_1sub1,
  108031. &_huff_book_line_128x11_2sub1,
  108032. &_huff_book_line_128x11_2sub2,
  108033. &_huff_book_line_128x11_2sub3,
  108034. &_huff_book_line_128x11_3sub1,
  108035. &_huff_book_line_128x11_3sub2,
  108036. &_huff_book_line_128x11_3sub3,
  108037. };
  108038. static static_codebook *_floor_128x17_books[]={
  108039. &_huff_book_line_128x17_class1,
  108040. &_huff_book_line_128x17_class2,
  108041. &_huff_book_line_128x17_class3,
  108042. &_huff_book_line_128x17_0sub0,
  108043. &_huff_book_line_128x17_1sub0,
  108044. &_huff_book_line_128x17_1sub1,
  108045. &_huff_book_line_128x17_2sub1,
  108046. &_huff_book_line_128x17_2sub2,
  108047. &_huff_book_line_128x17_2sub3,
  108048. &_huff_book_line_128x17_3sub1,
  108049. &_huff_book_line_128x17_3sub2,
  108050. &_huff_book_line_128x17_3sub3,
  108051. };
  108052. static static_codebook *_floor_256x4low_books[]={
  108053. &_huff_book_line_256x4low_class0,
  108054. &_huff_book_line_256x4low_0sub0,
  108055. &_huff_book_line_256x4low_0sub1,
  108056. &_huff_book_line_256x4low_0sub2,
  108057. &_huff_book_line_256x4low_0sub3,
  108058. };
  108059. static static_codebook *_floor_1024x27_books[]={
  108060. &_huff_book_line_1024x27_class1,
  108061. &_huff_book_line_1024x27_class2,
  108062. &_huff_book_line_1024x27_class3,
  108063. &_huff_book_line_1024x27_class4,
  108064. &_huff_book_line_1024x27_0sub0,
  108065. &_huff_book_line_1024x27_1sub0,
  108066. &_huff_book_line_1024x27_1sub1,
  108067. &_huff_book_line_1024x27_2sub0,
  108068. &_huff_book_line_1024x27_2sub1,
  108069. &_huff_book_line_1024x27_3sub1,
  108070. &_huff_book_line_1024x27_3sub2,
  108071. &_huff_book_line_1024x27_3sub3,
  108072. &_huff_book_line_1024x27_4sub1,
  108073. &_huff_book_line_1024x27_4sub2,
  108074. &_huff_book_line_1024x27_4sub3,
  108075. };
  108076. static static_codebook *_floor_2048x27_books[]={
  108077. &_huff_book_line_2048x27_class1,
  108078. &_huff_book_line_2048x27_class2,
  108079. &_huff_book_line_2048x27_class3,
  108080. &_huff_book_line_2048x27_class4,
  108081. &_huff_book_line_2048x27_0sub0,
  108082. &_huff_book_line_2048x27_1sub0,
  108083. &_huff_book_line_2048x27_1sub1,
  108084. &_huff_book_line_2048x27_2sub0,
  108085. &_huff_book_line_2048x27_2sub1,
  108086. &_huff_book_line_2048x27_3sub1,
  108087. &_huff_book_line_2048x27_3sub2,
  108088. &_huff_book_line_2048x27_3sub3,
  108089. &_huff_book_line_2048x27_4sub1,
  108090. &_huff_book_line_2048x27_4sub2,
  108091. &_huff_book_line_2048x27_4sub3,
  108092. };
  108093. static static_codebook *_floor_512x17_books[]={
  108094. &_huff_book_line_512x17_class1,
  108095. &_huff_book_line_512x17_class2,
  108096. &_huff_book_line_512x17_class3,
  108097. &_huff_book_line_512x17_0sub0,
  108098. &_huff_book_line_512x17_1sub0,
  108099. &_huff_book_line_512x17_1sub1,
  108100. &_huff_book_line_512x17_2sub1,
  108101. &_huff_book_line_512x17_2sub2,
  108102. &_huff_book_line_512x17_2sub3,
  108103. &_huff_book_line_512x17_3sub1,
  108104. &_huff_book_line_512x17_3sub2,
  108105. &_huff_book_line_512x17_3sub3,
  108106. };
  108107. static static_codebook **_floor_books[10]={
  108108. _floor_128x4_books,
  108109. _floor_256x4_books,
  108110. _floor_128x7_books,
  108111. _floor_256x7_books,
  108112. _floor_128x11_books,
  108113. _floor_128x17_books,
  108114. _floor_256x4low_books,
  108115. _floor_1024x27_books,
  108116. _floor_2048x27_books,
  108117. _floor_512x17_books,
  108118. };
  108119. static vorbis_info_floor1 _floor[10]={
  108120. {
  108121. 1,{0},{4},{2},{0},
  108122. {{1,2,3,4}},
  108123. 4,{0,128, 33,8,16,70},
  108124. 60,30,500, 1.,18., -1
  108125. },
  108126. {
  108127. 1,{0},{4},{2},{0},
  108128. {{1,2,3,4}},
  108129. 4,{0,256, 66,16,32,140},
  108130. 60,30,500, 1.,18., -1
  108131. },
  108132. {
  108133. 2,{0,1},{3,4},{2,2},{0,1},
  108134. {{-1,2,3,4},{-1,5,6,7}},
  108135. 4,{0,128, 14,4,58, 2,8,28,90},
  108136. 60,30,500, 1.,18., -1
  108137. },
  108138. {
  108139. 2,{0,1},{3,4},{2,2},{0,1},
  108140. {{-1,2,3,4},{-1,5,6,7}},
  108141. 4,{0,256, 28,8,116, 4,16,56,180},
  108142. 60,30,500, 1.,18., -1
  108143. },
  108144. {
  108145. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108146. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108147. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108148. 60,30,500, 1,18., -1
  108149. },
  108150. {
  108151. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108152. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108153. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108154. 60,30,500, 1,18., -1
  108155. },
  108156. {
  108157. 1,{0},{4},{2},{0},
  108158. {{1,2,3,4}},
  108159. 4,{0,256, 66,16,32,140},
  108160. 60,30,500, 1.,18., -1
  108161. },
  108162. {
  108163. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108164. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108165. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108166. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108167. 60,30,500, 3,18., -1 /* lowpass */
  108168. },
  108169. {
  108170. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108171. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108172. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108173. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108174. 60,30,500, 3,18., -1 /* lowpass */
  108175. },
  108176. {
  108177. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108178. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108179. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108180. 7,23,39, 55,79,110, 156,232,360},
  108181. 60,30,500, 1,18., -1 /* lowpass! */
  108182. },
  108183. };
  108184. /*** End of inlined file: floor_all.h ***/
  108185. /*** Start of inlined file: residue_44.h ***/
  108186. /*** Start of inlined file: res_books_stereo.h ***/
  108187. static long _vq_quantlist__16c0_s_p1_0[] = {
  108188. 1,
  108189. 0,
  108190. 2,
  108191. };
  108192. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108193. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108194. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108198. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108199. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108203. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108204. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108239. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108244. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  108249. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108284. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108285. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108290. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108295. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108501. 0, 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,
  108604. };
  108605. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108606. -0.5, 0.5,
  108607. };
  108608. static long _vq_quantmap__16c0_s_p1_0[] = {
  108609. 1, 0, 2,
  108610. };
  108611. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108612. _vq_quantthresh__16c0_s_p1_0,
  108613. _vq_quantmap__16c0_s_p1_0,
  108614. 3,
  108615. 3
  108616. };
  108617. static static_codebook _16c0_s_p1_0 = {
  108618. 8, 6561,
  108619. _vq_lengthlist__16c0_s_p1_0,
  108620. 1, -535822336, 1611661312, 2, 0,
  108621. _vq_quantlist__16c0_s_p1_0,
  108622. NULL,
  108623. &_vq_auxt__16c0_s_p1_0,
  108624. NULL,
  108625. 0
  108626. };
  108627. static long _vq_quantlist__16c0_s_p2_0[] = {
  108628. 2,
  108629. 1,
  108630. 3,
  108631. 0,
  108632. 4,
  108633. };
  108634. static long _vq_lengthlist__16c0_s_p2_0[] = {
  108635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  108675. };
  108676. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108677. -1.5, -0.5, 0.5, 1.5,
  108678. };
  108679. static long _vq_quantmap__16c0_s_p2_0[] = {
  108680. 3, 1, 0, 2, 4,
  108681. };
  108682. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108683. _vq_quantthresh__16c0_s_p2_0,
  108684. _vq_quantmap__16c0_s_p2_0,
  108685. 5,
  108686. 5
  108687. };
  108688. static static_codebook _16c0_s_p2_0 = {
  108689. 4, 625,
  108690. _vq_lengthlist__16c0_s_p2_0,
  108691. 1, -533725184, 1611661312, 3, 0,
  108692. _vq_quantlist__16c0_s_p2_0,
  108693. NULL,
  108694. &_vq_auxt__16c0_s_p2_0,
  108695. NULL,
  108696. 0
  108697. };
  108698. static long _vq_quantlist__16c0_s_p3_0[] = {
  108699. 2,
  108700. 1,
  108701. 3,
  108702. 0,
  108703. 4,
  108704. };
  108705. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108706. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108709. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108712. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  108713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  108746. };
  108747. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108748. -1.5, -0.5, 0.5, 1.5,
  108749. };
  108750. static long _vq_quantmap__16c0_s_p3_0[] = {
  108751. 3, 1, 0, 2, 4,
  108752. };
  108753. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108754. _vq_quantthresh__16c0_s_p3_0,
  108755. _vq_quantmap__16c0_s_p3_0,
  108756. 5,
  108757. 5
  108758. };
  108759. static static_codebook _16c0_s_p3_0 = {
  108760. 4, 625,
  108761. _vq_lengthlist__16c0_s_p3_0,
  108762. 1, -533725184, 1611661312, 3, 0,
  108763. _vq_quantlist__16c0_s_p3_0,
  108764. NULL,
  108765. &_vq_auxt__16c0_s_p3_0,
  108766. NULL,
  108767. 0
  108768. };
  108769. static long _vq_quantlist__16c0_s_p4_0[] = {
  108770. 4,
  108771. 3,
  108772. 5,
  108773. 2,
  108774. 6,
  108775. 1,
  108776. 7,
  108777. 0,
  108778. 8,
  108779. };
  108780. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108781. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108782. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108783. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108784. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108785. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108786. 0,
  108787. };
  108788. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108789. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108790. };
  108791. static long _vq_quantmap__16c0_s_p4_0[] = {
  108792. 7, 5, 3, 1, 0, 2, 4, 6,
  108793. 8,
  108794. };
  108795. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108796. _vq_quantthresh__16c0_s_p4_0,
  108797. _vq_quantmap__16c0_s_p4_0,
  108798. 9,
  108799. 9
  108800. };
  108801. static static_codebook _16c0_s_p4_0 = {
  108802. 2, 81,
  108803. _vq_lengthlist__16c0_s_p4_0,
  108804. 1, -531628032, 1611661312, 4, 0,
  108805. _vq_quantlist__16c0_s_p4_0,
  108806. NULL,
  108807. &_vq_auxt__16c0_s_p4_0,
  108808. NULL,
  108809. 0
  108810. };
  108811. static long _vq_quantlist__16c0_s_p5_0[] = {
  108812. 4,
  108813. 3,
  108814. 5,
  108815. 2,
  108816. 6,
  108817. 1,
  108818. 7,
  108819. 0,
  108820. 8,
  108821. };
  108822. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108823. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108824. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108825. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108826. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108827. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108828. 10,
  108829. };
  108830. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108831. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108832. };
  108833. static long _vq_quantmap__16c0_s_p5_0[] = {
  108834. 7, 5, 3, 1, 0, 2, 4, 6,
  108835. 8,
  108836. };
  108837. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108838. _vq_quantthresh__16c0_s_p5_0,
  108839. _vq_quantmap__16c0_s_p5_0,
  108840. 9,
  108841. 9
  108842. };
  108843. static static_codebook _16c0_s_p5_0 = {
  108844. 2, 81,
  108845. _vq_lengthlist__16c0_s_p5_0,
  108846. 1, -531628032, 1611661312, 4, 0,
  108847. _vq_quantlist__16c0_s_p5_0,
  108848. NULL,
  108849. &_vq_auxt__16c0_s_p5_0,
  108850. NULL,
  108851. 0
  108852. };
  108853. static long _vq_quantlist__16c0_s_p6_0[] = {
  108854. 8,
  108855. 7,
  108856. 9,
  108857. 6,
  108858. 10,
  108859. 5,
  108860. 11,
  108861. 4,
  108862. 12,
  108863. 3,
  108864. 13,
  108865. 2,
  108866. 14,
  108867. 1,
  108868. 15,
  108869. 0,
  108870. 16,
  108871. };
  108872. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108873. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108874. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108875. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108876. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108877. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108878. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108879. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108880. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108881. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108882. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108883. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108884. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108885. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108886. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108887. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108888. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108889. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108890. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108891. 14,
  108892. };
  108893. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108894. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108895. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108896. };
  108897. static long _vq_quantmap__16c0_s_p6_0[] = {
  108898. 15, 13, 11, 9, 7, 5, 3, 1,
  108899. 0, 2, 4, 6, 8, 10, 12, 14,
  108900. 16,
  108901. };
  108902. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108903. _vq_quantthresh__16c0_s_p6_0,
  108904. _vq_quantmap__16c0_s_p6_0,
  108905. 17,
  108906. 17
  108907. };
  108908. static static_codebook _16c0_s_p6_0 = {
  108909. 2, 289,
  108910. _vq_lengthlist__16c0_s_p6_0,
  108911. 1, -529530880, 1611661312, 5, 0,
  108912. _vq_quantlist__16c0_s_p6_0,
  108913. NULL,
  108914. &_vq_auxt__16c0_s_p6_0,
  108915. NULL,
  108916. 0
  108917. };
  108918. static long _vq_quantlist__16c0_s_p7_0[] = {
  108919. 1,
  108920. 0,
  108921. 2,
  108922. };
  108923. static long _vq_lengthlist__16c0_s_p7_0[] = {
  108924. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  108925. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  108926. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  108927. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  108928. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  108929. 13,
  108930. };
  108931. static float _vq_quantthresh__16c0_s_p7_0[] = {
  108932. -5.5, 5.5,
  108933. };
  108934. static long _vq_quantmap__16c0_s_p7_0[] = {
  108935. 1, 0, 2,
  108936. };
  108937. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  108938. _vq_quantthresh__16c0_s_p7_0,
  108939. _vq_quantmap__16c0_s_p7_0,
  108940. 3,
  108941. 3
  108942. };
  108943. static static_codebook _16c0_s_p7_0 = {
  108944. 4, 81,
  108945. _vq_lengthlist__16c0_s_p7_0,
  108946. 1, -529137664, 1618345984, 2, 0,
  108947. _vq_quantlist__16c0_s_p7_0,
  108948. NULL,
  108949. &_vq_auxt__16c0_s_p7_0,
  108950. NULL,
  108951. 0
  108952. };
  108953. static long _vq_quantlist__16c0_s_p7_1[] = {
  108954. 5,
  108955. 4,
  108956. 6,
  108957. 3,
  108958. 7,
  108959. 2,
  108960. 8,
  108961. 1,
  108962. 9,
  108963. 0,
  108964. 10,
  108965. };
  108966. static long _vq_lengthlist__16c0_s_p7_1[] = {
  108967. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  108968. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  108969. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  108970. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  108971. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  108972. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  108973. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  108974. 11,11,11, 9, 9, 9, 9,10,10,
  108975. };
  108976. static float _vq_quantthresh__16c0_s_p7_1[] = {
  108977. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  108978. 3.5, 4.5,
  108979. };
  108980. static long _vq_quantmap__16c0_s_p7_1[] = {
  108981. 9, 7, 5, 3, 1, 0, 2, 4,
  108982. 6, 8, 10,
  108983. };
  108984. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  108985. _vq_quantthresh__16c0_s_p7_1,
  108986. _vq_quantmap__16c0_s_p7_1,
  108987. 11,
  108988. 11
  108989. };
  108990. static static_codebook _16c0_s_p7_1 = {
  108991. 2, 121,
  108992. _vq_lengthlist__16c0_s_p7_1,
  108993. 1, -531365888, 1611661312, 4, 0,
  108994. _vq_quantlist__16c0_s_p7_1,
  108995. NULL,
  108996. &_vq_auxt__16c0_s_p7_1,
  108997. NULL,
  108998. 0
  108999. };
  109000. static long _vq_quantlist__16c0_s_p8_0[] = {
  109001. 6,
  109002. 5,
  109003. 7,
  109004. 4,
  109005. 8,
  109006. 3,
  109007. 9,
  109008. 2,
  109009. 10,
  109010. 1,
  109011. 11,
  109012. 0,
  109013. 12,
  109014. };
  109015. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109016. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109017. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109018. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109019. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109020. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109021. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109022. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109023. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109024. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109025. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109026. 0,12,13,13,12,13,14,14,14,
  109027. };
  109028. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109029. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109030. 12.5, 17.5, 22.5, 27.5,
  109031. };
  109032. static long _vq_quantmap__16c0_s_p8_0[] = {
  109033. 11, 9, 7, 5, 3, 1, 0, 2,
  109034. 4, 6, 8, 10, 12,
  109035. };
  109036. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109037. _vq_quantthresh__16c0_s_p8_0,
  109038. _vq_quantmap__16c0_s_p8_0,
  109039. 13,
  109040. 13
  109041. };
  109042. static static_codebook _16c0_s_p8_0 = {
  109043. 2, 169,
  109044. _vq_lengthlist__16c0_s_p8_0,
  109045. 1, -526516224, 1616117760, 4, 0,
  109046. _vq_quantlist__16c0_s_p8_0,
  109047. NULL,
  109048. &_vq_auxt__16c0_s_p8_0,
  109049. NULL,
  109050. 0
  109051. };
  109052. static long _vq_quantlist__16c0_s_p8_1[] = {
  109053. 2,
  109054. 1,
  109055. 3,
  109056. 0,
  109057. 4,
  109058. };
  109059. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109060. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109061. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109062. };
  109063. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109064. -1.5, -0.5, 0.5, 1.5,
  109065. };
  109066. static long _vq_quantmap__16c0_s_p8_1[] = {
  109067. 3, 1, 0, 2, 4,
  109068. };
  109069. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109070. _vq_quantthresh__16c0_s_p8_1,
  109071. _vq_quantmap__16c0_s_p8_1,
  109072. 5,
  109073. 5
  109074. };
  109075. static static_codebook _16c0_s_p8_1 = {
  109076. 2, 25,
  109077. _vq_lengthlist__16c0_s_p8_1,
  109078. 1, -533725184, 1611661312, 3, 0,
  109079. _vq_quantlist__16c0_s_p8_1,
  109080. NULL,
  109081. &_vq_auxt__16c0_s_p8_1,
  109082. NULL,
  109083. 0
  109084. };
  109085. static long _vq_quantlist__16c0_s_p9_0[] = {
  109086. 1,
  109087. 0,
  109088. 2,
  109089. };
  109090. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109091. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109092. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109093. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109094. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109095. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109096. 7,
  109097. };
  109098. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109099. -157.5, 157.5,
  109100. };
  109101. static long _vq_quantmap__16c0_s_p9_0[] = {
  109102. 1, 0, 2,
  109103. };
  109104. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109105. _vq_quantthresh__16c0_s_p9_0,
  109106. _vq_quantmap__16c0_s_p9_0,
  109107. 3,
  109108. 3
  109109. };
  109110. static static_codebook _16c0_s_p9_0 = {
  109111. 4, 81,
  109112. _vq_lengthlist__16c0_s_p9_0,
  109113. 1, -518803456, 1628680192, 2, 0,
  109114. _vq_quantlist__16c0_s_p9_0,
  109115. NULL,
  109116. &_vq_auxt__16c0_s_p9_0,
  109117. NULL,
  109118. 0
  109119. };
  109120. static long _vq_quantlist__16c0_s_p9_1[] = {
  109121. 7,
  109122. 6,
  109123. 8,
  109124. 5,
  109125. 9,
  109126. 4,
  109127. 10,
  109128. 3,
  109129. 11,
  109130. 2,
  109131. 12,
  109132. 1,
  109133. 13,
  109134. 0,
  109135. 14,
  109136. };
  109137. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109138. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109139. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109140. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109141. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109142. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109143. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109144. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109145. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109146. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109147. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109148. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109149. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109150. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109151. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109152. 10,
  109153. };
  109154. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109155. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109156. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109157. };
  109158. static long _vq_quantmap__16c0_s_p9_1[] = {
  109159. 13, 11, 9, 7, 5, 3, 1, 0,
  109160. 2, 4, 6, 8, 10, 12, 14,
  109161. };
  109162. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109163. _vq_quantthresh__16c0_s_p9_1,
  109164. _vq_quantmap__16c0_s_p9_1,
  109165. 15,
  109166. 15
  109167. };
  109168. static static_codebook _16c0_s_p9_1 = {
  109169. 2, 225,
  109170. _vq_lengthlist__16c0_s_p9_1,
  109171. 1, -520986624, 1620377600, 4, 0,
  109172. _vq_quantlist__16c0_s_p9_1,
  109173. NULL,
  109174. &_vq_auxt__16c0_s_p9_1,
  109175. NULL,
  109176. 0
  109177. };
  109178. static long _vq_quantlist__16c0_s_p9_2[] = {
  109179. 10,
  109180. 9,
  109181. 11,
  109182. 8,
  109183. 12,
  109184. 7,
  109185. 13,
  109186. 6,
  109187. 14,
  109188. 5,
  109189. 15,
  109190. 4,
  109191. 16,
  109192. 3,
  109193. 17,
  109194. 2,
  109195. 18,
  109196. 1,
  109197. 19,
  109198. 0,
  109199. 20,
  109200. };
  109201. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109202. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109203. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109204. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109205. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109206. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109207. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109208. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109209. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109210. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109211. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109212. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109213. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109214. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109215. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109216. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109217. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109218. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109219. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109220. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109221. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109222. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109223. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109224. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109225. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109226. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109227. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109228. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109229. 10,11,10,10,11, 9,10,10,10,
  109230. };
  109231. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109232. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109233. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109234. 6.5, 7.5, 8.5, 9.5,
  109235. };
  109236. static long _vq_quantmap__16c0_s_p9_2[] = {
  109237. 19, 17, 15, 13, 11, 9, 7, 5,
  109238. 3, 1, 0, 2, 4, 6, 8, 10,
  109239. 12, 14, 16, 18, 20,
  109240. };
  109241. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109242. _vq_quantthresh__16c0_s_p9_2,
  109243. _vq_quantmap__16c0_s_p9_2,
  109244. 21,
  109245. 21
  109246. };
  109247. static static_codebook _16c0_s_p9_2 = {
  109248. 2, 441,
  109249. _vq_lengthlist__16c0_s_p9_2,
  109250. 1, -529268736, 1611661312, 5, 0,
  109251. _vq_quantlist__16c0_s_p9_2,
  109252. NULL,
  109253. &_vq_auxt__16c0_s_p9_2,
  109254. NULL,
  109255. 0
  109256. };
  109257. static long _huff_lengthlist__16c0_s_single[] = {
  109258. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109259. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109260. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109261. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109262. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109263. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109264. 16,16,18,18,
  109265. };
  109266. static static_codebook _huff_book__16c0_s_single = {
  109267. 2, 100,
  109268. _huff_lengthlist__16c0_s_single,
  109269. 0, 0, 0, 0, 0,
  109270. NULL,
  109271. NULL,
  109272. NULL,
  109273. NULL,
  109274. 0
  109275. };
  109276. static long _huff_lengthlist__16c1_s_long[] = {
  109277. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109278. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109279. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109280. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109281. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109282. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109283. 12,11,11,13,
  109284. };
  109285. static static_codebook _huff_book__16c1_s_long = {
  109286. 2, 100,
  109287. _huff_lengthlist__16c1_s_long,
  109288. 0, 0, 0, 0, 0,
  109289. NULL,
  109290. NULL,
  109291. NULL,
  109292. NULL,
  109293. 0
  109294. };
  109295. static long _vq_quantlist__16c1_s_p1_0[] = {
  109296. 1,
  109297. 0,
  109298. 2,
  109299. };
  109300. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109301. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109302. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109306. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109307. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109311. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109312. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109347. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109352. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  109357. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109392. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109393. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109398. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109403. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109609. 0, 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,
  109712. };
  109713. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109714. -0.5, 0.5,
  109715. };
  109716. static long _vq_quantmap__16c1_s_p1_0[] = {
  109717. 1, 0, 2,
  109718. };
  109719. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109720. _vq_quantthresh__16c1_s_p1_0,
  109721. _vq_quantmap__16c1_s_p1_0,
  109722. 3,
  109723. 3
  109724. };
  109725. static static_codebook _16c1_s_p1_0 = {
  109726. 8, 6561,
  109727. _vq_lengthlist__16c1_s_p1_0,
  109728. 1, -535822336, 1611661312, 2, 0,
  109729. _vq_quantlist__16c1_s_p1_0,
  109730. NULL,
  109731. &_vq_auxt__16c1_s_p1_0,
  109732. NULL,
  109733. 0
  109734. };
  109735. static long _vq_quantlist__16c1_s_p2_0[] = {
  109736. 2,
  109737. 1,
  109738. 3,
  109739. 0,
  109740. 4,
  109741. };
  109742. static long _vq_lengthlist__16c1_s_p2_0[] = {
  109743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  109783. };
  109784. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109785. -1.5, -0.5, 0.5, 1.5,
  109786. };
  109787. static long _vq_quantmap__16c1_s_p2_0[] = {
  109788. 3, 1, 0, 2, 4,
  109789. };
  109790. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109791. _vq_quantthresh__16c1_s_p2_0,
  109792. _vq_quantmap__16c1_s_p2_0,
  109793. 5,
  109794. 5
  109795. };
  109796. static static_codebook _16c1_s_p2_0 = {
  109797. 4, 625,
  109798. _vq_lengthlist__16c1_s_p2_0,
  109799. 1, -533725184, 1611661312, 3, 0,
  109800. _vq_quantlist__16c1_s_p2_0,
  109801. NULL,
  109802. &_vq_auxt__16c1_s_p2_0,
  109803. NULL,
  109804. 0
  109805. };
  109806. static long _vq_quantlist__16c1_s_p3_0[] = {
  109807. 2,
  109808. 1,
  109809. 3,
  109810. 0,
  109811. 4,
  109812. };
  109813. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109814. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109817. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109820. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  109854. };
  109855. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109856. -1.5, -0.5, 0.5, 1.5,
  109857. };
  109858. static long _vq_quantmap__16c1_s_p3_0[] = {
  109859. 3, 1, 0, 2, 4,
  109860. };
  109861. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109862. _vq_quantthresh__16c1_s_p3_0,
  109863. _vq_quantmap__16c1_s_p3_0,
  109864. 5,
  109865. 5
  109866. };
  109867. static static_codebook _16c1_s_p3_0 = {
  109868. 4, 625,
  109869. _vq_lengthlist__16c1_s_p3_0,
  109870. 1, -533725184, 1611661312, 3, 0,
  109871. _vq_quantlist__16c1_s_p3_0,
  109872. NULL,
  109873. &_vq_auxt__16c1_s_p3_0,
  109874. NULL,
  109875. 0
  109876. };
  109877. static long _vq_quantlist__16c1_s_p4_0[] = {
  109878. 4,
  109879. 3,
  109880. 5,
  109881. 2,
  109882. 6,
  109883. 1,
  109884. 7,
  109885. 0,
  109886. 8,
  109887. };
  109888. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109889. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109890. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109891. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109892. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109893. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109894. 0,
  109895. };
  109896. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109897. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109898. };
  109899. static long _vq_quantmap__16c1_s_p4_0[] = {
  109900. 7, 5, 3, 1, 0, 2, 4, 6,
  109901. 8,
  109902. };
  109903. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109904. _vq_quantthresh__16c1_s_p4_0,
  109905. _vq_quantmap__16c1_s_p4_0,
  109906. 9,
  109907. 9
  109908. };
  109909. static static_codebook _16c1_s_p4_0 = {
  109910. 2, 81,
  109911. _vq_lengthlist__16c1_s_p4_0,
  109912. 1, -531628032, 1611661312, 4, 0,
  109913. _vq_quantlist__16c1_s_p4_0,
  109914. NULL,
  109915. &_vq_auxt__16c1_s_p4_0,
  109916. NULL,
  109917. 0
  109918. };
  109919. static long _vq_quantlist__16c1_s_p5_0[] = {
  109920. 4,
  109921. 3,
  109922. 5,
  109923. 2,
  109924. 6,
  109925. 1,
  109926. 7,
  109927. 0,
  109928. 8,
  109929. };
  109930. static long _vq_lengthlist__16c1_s_p5_0[] = {
  109931. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109932. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  109933. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  109934. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  109935. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109936. 10,
  109937. };
  109938. static float _vq_quantthresh__16c1_s_p5_0[] = {
  109939. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109940. };
  109941. static long _vq_quantmap__16c1_s_p5_0[] = {
  109942. 7, 5, 3, 1, 0, 2, 4, 6,
  109943. 8,
  109944. };
  109945. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  109946. _vq_quantthresh__16c1_s_p5_0,
  109947. _vq_quantmap__16c1_s_p5_0,
  109948. 9,
  109949. 9
  109950. };
  109951. static static_codebook _16c1_s_p5_0 = {
  109952. 2, 81,
  109953. _vq_lengthlist__16c1_s_p5_0,
  109954. 1, -531628032, 1611661312, 4, 0,
  109955. _vq_quantlist__16c1_s_p5_0,
  109956. NULL,
  109957. &_vq_auxt__16c1_s_p5_0,
  109958. NULL,
  109959. 0
  109960. };
  109961. static long _vq_quantlist__16c1_s_p6_0[] = {
  109962. 8,
  109963. 7,
  109964. 9,
  109965. 6,
  109966. 10,
  109967. 5,
  109968. 11,
  109969. 4,
  109970. 12,
  109971. 3,
  109972. 13,
  109973. 2,
  109974. 14,
  109975. 1,
  109976. 15,
  109977. 0,
  109978. 16,
  109979. };
  109980. static long _vq_lengthlist__16c1_s_p6_0[] = {
  109981. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  109982. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  109983. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  109984. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  109985. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  109986. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109987. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109988. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109989. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  109990. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109991. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  109992. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  109993. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  109994. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  109995. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  109996. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  109997. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  109998. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  109999. 14,
  110000. };
  110001. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110002. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110003. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110004. };
  110005. static long _vq_quantmap__16c1_s_p6_0[] = {
  110006. 15, 13, 11, 9, 7, 5, 3, 1,
  110007. 0, 2, 4, 6, 8, 10, 12, 14,
  110008. 16,
  110009. };
  110010. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110011. _vq_quantthresh__16c1_s_p6_0,
  110012. _vq_quantmap__16c1_s_p6_0,
  110013. 17,
  110014. 17
  110015. };
  110016. static static_codebook _16c1_s_p6_0 = {
  110017. 2, 289,
  110018. _vq_lengthlist__16c1_s_p6_0,
  110019. 1, -529530880, 1611661312, 5, 0,
  110020. _vq_quantlist__16c1_s_p6_0,
  110021. NULL,
  110022. &_vq_auxt__16c1_s_p6_0,
  110023. NULL,
  110024. 0
  110025. };
  110026. static long _vq_quantlist__16c1_s_p7_0[] = {
  110027. 1,
  110028. 0,
  110029. 2,
  110030. };
  110031. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110032. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110033. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110034. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110035. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110036. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110037. 11,
  110038. };
  110039. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110040. -5.5, 5.5,
  110041. };
  110042. static long _vq_quantmap__16c1_s_p7_0[] = {
  110043. 1, 0, 2,
  110044. };
  110045. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110046. _vq_quantthresh__16c1_s_p7_0,
  110047. _vq_quantmap__16c1_s_p7_0,
  110048. 3,
  110049. 3
  110050. };
  110051. static static_codebook _16c1_s_p7_0 = {
  110052. 4, 81,
  110053. _vq_lengthlist__16c1_s_p7_0,
  110054. 1, -529137664, 1618345984, 2, 0,
  110055. _vq_quantlist__16c1_s_p7_0,
  110056. NULL,
  110057. &_vq_auxt__16c1_s_p7_0,
  110058. NULL,
  110059. 0
  110060. };
  110061. static long _vq_quantlist__16c1_s_p7_1[] = {
  110062. 5,
  110063. 4,
  110064. 6,
  110065. 3,
  110066. 7,
  110067. 2,
  110068. 8,
  110069. 1,
  110070. 9,
  110071. 0,
  110072. 10,
  110073. };
  110074. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110075. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110076. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110077. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110078. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110079. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110080. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110081. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110082. 10,10,10, 8, 8, 8, 8, 9, 9,
  110083. };
  110084. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110085. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110086. 3.5, 4.5,
  110087. };
  110088. static long _vq_quantmap__16c1_s_p7_1[] = {
  110089. 9, 7, 5, 3, 1, 0, 2, 4,
  110090. 6, 8, 10,
  110091. };
  110092. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110093. _vq_quantthresh__16c1_s_p7_1,
  110094. _vq_quantmap__16c1_s_p7_1,
  110095. 11,
  110096. 11
  110097. };
  110098. static static_codebook _16c1_s_p7_1 = {
  110099. 2, 121,
  110100. _vq_lengthlist__16c1_s_p7_1,
  110101. 1, -531365888, 1611661312, 4, 0,
  110102. _vq_quantlist__16c1_s_p7_1,
  110103. NULL,
  110104. &_vq_auxt__16c1_s_p7_1,
  110105. NULL,
  110106. 0
  110107. };
  110108. static long _vq_quantlist__16c1_s_p8_0[] = {
  110109. 6,
  110110. 5,
  110111. 7,
  110112. 4,
  110113. 8,
  110114. 3,
  110115. 9,
  110116. 2,
  110117. 10,
  110118. 1,
  110119. 11,
  110120. 0,
  110121. 12,
  110122. };
  110123. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110124. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110125. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110126. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110127. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110128. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110129. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110130. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110131. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110132. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110133. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110134. 0,12,12,12,12,13,13,14,15,
  110135. };
  110136. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110137. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110138. 12.5, 17.5, 22.5, 27.5,
  110139. };
  110140. static long _vq_quantmap__16c1_s_p8_0[] = {
  110141. 11, 9, 7, 5, 3, 1, 0, 2,
  110142. 4, 6, 8, 10, 12,
  110143. };
  110144. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110145. _vq_quantthresh__16c1_s_p8_0,
  110146. _vq_quantmap__16c1_s_p8_0,
  110147. 13,
  110148. 13
  110149. };
  110150. static static_codebook _16c1_s_p8_0 = {
  110151. 2, 169,
  110152. _vq_lengthlist__16c1_s_p8_0,
  110153. 1, -526516224, 1616117760, 4, 0,
  110154. _vq_quantlist__16c1_s_p8_0,
  110155. NULL,
  110156. &_vq_auxt__16c1_s_p8_0,
  110157. NULL,
  110158. 0
  110159. };
  110160. static long _vq_quantlist__16c1_s_p8_1[] = {
  110161. 2,
  110162. 1,
  110163. 3,
  110164. 0,
  110165. 4,
  110166. };
  110167. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110168. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110169. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110170. };
  110171. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110172. -1.5, -0.5, 0.5, 1.5,
  110173. };
  110174. static long _vq_quantmap__16c1_s_p8_1[] = {
  110175. 3, 1, 0, 2, 4,
  110176. };
  110177. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110178. _vq_quantthresh__16c1_s_p8_1,
  110179. _vq_quantmap__16c1_s_p8_1,
  110180. 5,
  110181. 5
  110182. };
  110183. static static_codebook _16c1_s_p8_1 = {
  110184. 2, 25,
  110185. _vq_lengthlist__16c1_s_p8_1,
  110186. 1, -533725184, 1611661312, 3, 0,
  110187. _vq_quantlist__16c1_s_p8_1,
  110188. NULL,
  110189. &_vq_auxt__16c1_s_p8_1,
  110190. NULL,
  110191. 0
  110192. };
  110193. static long _vq_quantlist__16c1_s_p9_0[] = {
  110194. 6,
  110195. 5,
  110196. 7,
  110197. 4,
  110198. 8,
  110199. 3,
  110200. 9,
  110201. 2,
  110202. 10,
  110203. 1,
  110204. 11,
  110205. 0,
  110206. 12,
  110207. };
  110208. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110209. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110210. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110211. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110212. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110213. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110214. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110215. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110216. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110217. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110218. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110219. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110220. };
  110221. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110222. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110223. 787.5, 1102.5, 1417.5, 1732.5,
  110224. };
  110225. static long _vq_quantmap__16c1_s_p9_0[] = {
  110226. 11, 9, 7, 5, 3, 1, 0, 2,
  110227. 4, 6, 8, 10, 12,
  110228. };
  110229. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110230. _vq_quantthresh__16c1_s_p9_0,
  110231. _vq_quantmap__16c1_s_p9_0,
  110232. 13,
  110233. 13
  110234. };
  110235. static static_codebook _16c1_s_p9_0 = {
  110236. 2, 169,
  110237. _vq_lengthlist__16c1_s_p9_0,
  110238. 1, -513964032, 1628680192, 4, 0,
  110239. _vq_quantlist__16c1_s_p9_0,
  110240. NULL,
  110241. &_vq_auxt__16c1_s_p9_0,
  110242. NULL,
  110243. 0
  110244. };
  110245. static long _vq_quantlist__16c1_s_p9_1[] = {
  110246. 7,
  110247. 6,
  110248. 8,
  110249. 5,
  110250. 9,
  110251. 4,
  110252. 10,
  110253. 3,
  110254. 11,
  110255. 2,
  110256. 12,
  110257. 1,
  110258. 13,
  110259. 0,
  110260. 14,
  110261. };
  110262. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110263. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110264. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110265. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110266. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110267. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110268. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110269. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110270. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110271. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110272. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110273. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110274. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110275. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110276. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110277. 13,
  110278. };
  110279. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110280. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110281. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110282. };
  110283. static long _vq_quantmap__16c1_s_p9_1[] = {
  110284. 13, 11, 9, 7, 5, 3, 1, 0,
  110285. 2, 4, 6, 8, 10, 12, 14,
  110286. };
  110287. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110288. _vq_quantthresh__16c1_s_p9_1,
  110289. _vq_quantmap__16c1_s_p9_1,
  110290. 15,
  110291. 15
  110292. };
  110293. static static_codebook _16c1_s_p9_1 = {
  110294. 2, 225,
  110295. _vq_lengthlist__16c1_s_p9_1,
  110296. 1, -520986624, 1620377600, 4, 0,
  110297. _vq_quantlist__16c1_s_p9_1,
  110298. NULL,
  110299. &_vq_auxt__16c1_s_p9_1,
  110300. NULL,
  110301. 0
  110302. };
  110303. static long _vq_quantlist__16c1_s_p9_2[] = {
  110304. 10,
  110305. 9,
  110306. 11,
  110307. 8,
  110308. 12,
  110309. 7,
  110310. 13,
  110311. 6,
  110312. 14,
  110313. 5,
  110314. 15,
  110315. 4,
  110316. 16,
  110317. 3,
  110318. 17,
  110319. 2,
  110320. 18,
  110321. 1,
  110322. 19,
  110323. 0,
  110324. 20,
  110325. };
  110326. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110327. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110328. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110329. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110330. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110331. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110332. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110333. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110334. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110335. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110336. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110337. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110338. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110339. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110340. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110341. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110342. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110343. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110344. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110345. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110346. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110347. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110348. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110349. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110350. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110351. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110352. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110353. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110354. 11,11,11,11,12,11,11,12,11,
  110355. };
  110356. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110357. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110358. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110359. 6.5, 7.5, 8.5, 9.5,
  110360. };
  110361. static long _vq_quantmap__16c1_s_p9_2[] = {
  110362. 19, 17, 15, 13, 11, 9, 7, 5,
  110363. 3, 1, 0, 2, 4, 6, 8, 10,
  110364. 12, 14, 16, 18, 20,
  110365. };
  110366. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110367. _vq_quantthresh__16c1_s_p9_2,
  110368. _vq_quantmap__16c1_s_p9_2,
  110369. 21,
  110370. 21
  110371. };
  110372. static static_codebook _16c1_s_p9_2 = {
  110373. 2, 441,
  110374. _vq_lengthlist__16c1_s_p9_2,
  110375. 1, -529268736, 1611661312, 5, 0,
  110376. _vq_quantlist__16c1_s_p9_2,
  110377. NULL,
  110378. &_vq_auxt__16c1_s_p9_2,
  110379. NULL,
  110380. 0
  110381. };
  110382. static long _huff_lengthlist__16c1_s_short[] = {
  110383. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110384. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110385. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110386. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110387. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110388. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110389. 9, 9,10,13,
  110390. };
  110391. static static_codebook _huff_book__16c1_s_short = {
  110392. 2, 100,
  110393. _huff_lengthlist__16c1_s_short,
  110394. 0, 0, 0, 0, 0,
  110395. NULL,
  110396. NULL,
  110397. NULL,
  110398. NULL,
  110399. 0
  110400. };
  110401. static long _huff_lengthlist__16c2_s_long[] = {
  110402. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110403. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110404. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110405. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110406. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110407. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110408. 14,14,16,18,
  110409. };
  110410. static static_codebook _huff_book__16c2_s_long = {
  110411. 2, 100,
  110412. _huff_lengthlist__16c2_s_long,
  110413. 0, 0, 0, 0, 0,
  110414. NULL,
  110415. NULL,
  110416. NULL,
  110417. NULL,
  110418. 0
  110419. };
  110420. static long _vq_quantlist__16c2_s_p1_0[] = {
  110421. 1,
  110422. 0,
  110423. 2,
  110424. };
  110425. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110426. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110427. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110431. 0,
  110432. };
  110433. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110434. -0.5, 0.5,
  110435. };
  110436. static long _vq_quantmap__16c2_s_p1_0[] = {
  110437. 1, 0, 2,
  110438. };
  110439. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110440. _vq_quantthresh__16c2_s_p1_0,
  110441. _vq_quantmap__16c2_s_p1_0,
  110442. 3,
  110443. 3
  110444. };
  110445. static static_codebook _16c2_s_p1_0 = {
  110446. 4, 81,
  110447. _vq_lengthlist__16c2_s_p1_0,
  110448. 1, -535822336, 1611661312, 2, 0,
  110449. _vq_quantlist__16c2_s_p1_0,
  110450. NULL,
  110451. &_vq_auxt__16c2_s_p1_0,
  110452. NULL,
  110453. 0
  110454. };
  110455. static long _vq_quantlist__16c2_s_p2_0[] = {
  110456. 2,
  110457. 1,
  110458. 3,
  110459. 0,
  110460. 4,
  110461. };
  110462. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110463. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110464. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110465. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110466. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110467. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110468. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110469. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110470. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110475. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110476. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110477. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110478. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110484. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110485. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110486. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110492. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110493. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110494. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110499. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110500. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110501. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110502. 13,
  110503. };
  110504. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110505. -1.5, -0.5, 0.5, 1.5,
  110506. };
  110507. static long _vq_quantmap__16c2_s_p2_0[] = {
  110508. 3, 1, 0, 2, 4,
  110509. };
  110510. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110511. _vq_quantthresh__16c2_s_p2_0,
  110512. _vq_quantmap__16c2_s_p2_0,
  110513. 5,
  110514. 5
  110515. };
  110516. static static_codebook _16c2_s_p2_0 = {
  110517. 4, 625,
  110518. _vq_lengthlist__16c2_s_p2_0,
  110519. 1, -533725184, 1611661312, 3, 0,
  110520. _vq_quantlist__16c2_s_p2_0,
  110521. NULL,
  110522. &_vq_auxt__16c2_s_p2_0,
  110523. NULL,
  110524. 0
  110525. };
  110526. static long _vq_quantlist__16c2_s_p3_0[] = {
  110527. 4,
  110528. 3,
  110529. 5,
  110530. 2,
  110531. 6,
  110532. 1,
  110533. 7,
  110534. 0,
  110535. 8,
  110536. };
  110537. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110538. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110539. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110540. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110541. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110543. 0,
  110544. };
  110545. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110546. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110547. };
  110548. static long _vq_quantmap__16c2_s_p3_0[] = {
  110549. 7, 5, 3, 1, 0, 2, 4, 6,
  110550. 8,
  110551. };
  110552. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110553. _vq_quantthresh__16c2_s_p3_0,
  110554. _vq_quantmap__16c2_s_p3_0,
  110555. 9,
  110556. 9
  110557. };
  110558. static static_codebook _16c2_s_p3_0 = {
  110559. 2, 81,
  110560. _vq_lengthlist__16c2_s_p3_0,
  110561. 1, -531628032, 1611661312, 4, 0,
  110562. _vq_quantlist__16c2_s_p3_0,
  110563. NULL,
  110564. &_vq_auxt__16c2_s_p3_0,
  110565. NULL,
  110566. 0
  110567. };
  110568. static long _vq_quantlist__16c2_s_p4_0[] = {
  110569. 8,
  110570. 7,
  110571. 9,
  110572. 6,
  110573. 10,
  110574. 5,
  110575. 11,
  110576. 4,
  110577. 12,
  110578. 3,
  110579. 13,
  110580. 2,
  110581. 14,
  110582. 1,
  110583. 15,
  110584. 0,
  110585. 16,
  110586. };
  110587. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110588. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110589. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110590. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110591. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110592. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110593. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110594. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110595. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110596. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110597. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110606. 0,
  110607. };
  110608. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110609. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110610. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110611. };
  110612. static long _vq_quantmap__16c2_s_p4_0[] = {
  110613. 15, 13, 11, 9, 7, 5, 3, 1,
  110614. 0, 2, 4, 6, 8, 10, 12, 14,
  110615. 16,
  110616. };
  110617. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110618. _vq_quantthresh__16c2_s_p4_0,
  110619. _vq_quantmap__16c2_s_p4_0,
  110620. 17,
  110621. 17
  110622. };
  110623. static static_codebook _16c2_s_p4_0 = {
  110624. 2, 289,
  110625. _vq_lengthlist__16c2_s_p4_0,
  110626. 1, -529530880, 1611661312, 5, 0,
  110627. _vq_quantlist__16c2_s_p4_0,
  110628. NULL,
  110629. &_vq_auxt__16c2_s_p4_0,
  110630. NULL,
  110631. 0
  110632. };
  110633. static long _vq_quantlist__16c2_s_p5_0[] = {
  110634. 1,
  110635. 0,
  110636. 2,
  110637. };
  110638. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110639. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110640. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110641. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110642. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110643. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110644. 12,
  110645. };
  110646. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110647. -5.5, 5.5,
  110648. };
  110649. static long _vq_quantmap__16c2_s_p5_0[] = {
  110650. 1, 0, 2,
  110651. };
  110652. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110653. _vq_quantthresh__16c2_s_p5_0,
  110654. _vq_quantmap__16c2_s_p5_0,
  110655. 3,
  110656. 3
  110657. };
  110658. static static_codebook _16c2_s_p5_0 = {
  110659. 4, 81,
  110660. _vq_lengthlist__16c2_s_p5_0,
  110661. 1, -529137664, 1618345984, 2, 0,
  110662. _vq_quantlist__16c2_s_p5_0,
  110663. NULL,
  110664. &_vq_auxt__16c2_s_p5_0,
  110665. NULL,
  110666. 0
  110667. };
  110668. static long _vq_quantlist__16c2_s_p5_1[] = {
  110669. 5,
  110670. 4,
  110671. 6,
  110672. 3,
  110673. 7,
  110674. 2,
  110675. 8,
  110676. 1,
  110677. 9,
  110678. 0,
  110679. 10,
  110680. };
  110681. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110682. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110683. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110684. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110685. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110686. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110687. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110688. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110689. 11,11,11, 7, 7, 8, 8, 8, 8,
  110690. };
  110691. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110692. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110693. 3.5, 4.5,
  110694. };
  110695. static long _vq_quantmap__16c2_s_p5_1[] = {
  110696. 9, 7, 5, 3, 1, 0, 2, 4,
  110697. 6, 8, 10,
  110698. };
  110699. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110700. _vq_quantthresh__16c2_s_p5_1,
  110701. _vq_quantmap__16c2_s_p5_1,
  110702. 11,
  110703. 11
  110704. };
  110705. static static_codebook _16c2_s_p5_1 = {
  110706. 2, 121,
  110707. _vq_lengthlist__16c2_s_p5_1,
  110708. 1, -531365888, 1611661312, 4, 0,
  110709. _vq_quantlist__16c2_s_p5_1,
  110710. NULL,
  110711. &_vq_auxt__16c2_s_p5_1,
  110712. NULL,
  110713. 0
  110714. };
  110715. static long _vq_quantlist__16c2_s_p6_0[] = {
  110716. 6,
  110717. 5,
  110718. 7,
  110719. 4,
  110720. 8,
  110721. 3,
  110722. 9,
  110723. 2,
  110724. 10,
  110725. 1,
  110726. 11,
  110727. 0,
  110728. 12,
  110729. };
  110730. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110731. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110732. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110733. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110734. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110735. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110736. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110741. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110742. };
  110743. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110744. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110745. 12.5, 17.5, 22.5, 27.5,
  110746. };
  110747. static long _vq_quantmap__16c2_s_p6_0[] = {
  110748. 11, 9, 7, 5, 3, 1, 0, 2,
  110749. 4, 6, 8, 10, 12,
  110750. };
  110751. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110752. _vq_quantthresh__16c2_s_p6_0,
  110753. _vq_quantmap__16c2_s_p6_0,
  110754. 13,
  110755. 13
  110756. };
  110757. static static_codebook _16c2_s_p6_0 = {
  110758. 2, 169,
  110759. _vq_lengthlist__16c2_s_p6_0,
  110760. 1, -526516224, 1616117760, 4, 0,
  110761. _vq_quantlist__16c2_s_p6_0,
  110762. NULL,
  110763. &_vq_auxt__16c2_s_p6_0,
  110764. NULL,
  110765. 0
  110766. };
  110767. static long _vq_quantlist__16c2_s_p6_1[] = {
  110768. 2,
  110769. 1,
  110770. 3,
  110771. 0,
  110772. 4,
  110773. };
  110774. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110775. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110776. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110777. };
  110778. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110779. -1.5, -0.5, 0.5, 1.5,
  110780. };
  110781. static long _vq_quantmap__16c2_s_p6_1[] = {
  110782. 3, 1, 0, 2, 4,
  110783. };
  110784. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110785. _vq_quantthresh__16c2_s_p6_1,
  110786. _vq_quantmap__16c2_s_p6_1,
  110787. 5,
  110788. 5
  110789. };
  110790. static static_codebook _16c2_s_p6_1 = {
  110791. 2, 25,
  110792. _vq_lengthlist__16c2_s_p6_1,
  110793. 1, -533725184, 1611661312, 3, 0,
  110794. _vq_quantlist__16c2_s_p6_1,
  110795. NULL,
  110796. &_vq_auxt__16c2_s_p6_1,
  110797. NULL,
  110798. 0
  110799. };
  110800. static long _vq_quantlist__16c2_s_p7_0[] = {
  110801. 6,
  110802. 5,
  110803. 7,
  110804. 4,
  110805. 8,
  110806. 3,
  110807. 9,
  110808. 2,
  110809. 10,
  110810. 1,
  110811. 11,
  110812. 0,
  110813. 12,
  110814. };
  110815. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110816. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110817. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110818. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110819. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110820. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110821. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110822. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110823. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110824. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110825. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110826. 18,13,14,13,13,14,13,15,14,
  110827. };
  110828. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110829. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110830. 27.5, 38.5, 49.5, 60.5,
  110831. };
  110832. static long _vq_quantmap__16c2_s_p7_0[] = {
  110833. 11, 9, 7, 5, 3, 1, 0, 2,
  110834. 4, 6, 8, 10, 12,
  110835. };
  110836. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110837. _vq_quantthresh__16c2_s_p7_0,
  110838. _vq_quantmap__16c2_s_p7_0,
  110839. 13,
  110840. 13
  110841. };
  110842. static static_codebook _16c2_s_p7_0 = {
  110843. 2, 169,
  110844. _vq_lengthlist__16c2_s_p7_0,
  110845. 1, -523206656, 1618345984, 4, 0,
  110846. _vq_quantlist__16c2_s_p7_0,
  110847. NULL,
  110848. &_vq_auxt__16c2_s_p7_0,
  110849. NULL,
  110850. 0
  110851. };
  110852. static long _vq_quantlist__16c2_s_p7_1[] = {
  110853. 5,
  110854. 4,
  110855. 6,
  110856. 3,
  110857. 7,
  110858. 2,
  110859. 8,
  110860. 1,
  110861. 9,
  110862. 0,
  110863. 10,
  110864. };
  110865. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110866. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110867. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110868. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110869. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110870. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110871. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110872. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110873. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110874. };
  110875. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110876. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110877. 3.5, 4.5,
  110878. };
  110879. static long _vq_quantmap__16c2_s_p7_1[] = {
  110880. 9, 7, 5, 3, 1, 0, 2, 4,
  110881. 6, 8, 10,
  110882. };
  110883. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110884. _vq_quantthresh__16c2_s_p7_1,
  110885. _vq_quantmap__16c2_s_p7_1,
  110886. 11,
  110887. 11
  110888. };
  110889. static static_codebook _16c2_s_p7_1 = {
  110890. 2, 121,
  110891. _vq_lengthlist__16c2_s_p7_1,
  110892. 1, -531365888, 1611661312, 4, 0,
  110893. _vq_quantlist__16c2_s_p7_1,
  110894. NULL,
  110895. &_vq_auxt__16c2_s_p7_1,
  110896. NULL,
  110897. 0
  110898. };
  110899. static long _vq_quantlist__16c2_s_p8_0[] = {
  110900. 7,
  110901. 6,
  110902. 8,
  110903. 5,
  110904. 9,
  110905. 4,
  110906. 10,
  110907. 3,
  110908. 11,
  110909. 2,
  110910. 12,
  110911. 1,
  110912. 13,
  110913. 0,
  110914. 14,
  110915. };
  110916. static long _vq_lengthlist__16c2_s_p8_0[] = {
  110917. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  110918. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  110919. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  110920. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  110921. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  110922. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  110923. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  110924. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  110925. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  110926. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  110927. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  110928. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  110929. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  110930. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  110931. 13,
  110932. };
  110933. static float _vq_quantthresh__16c2_s_p8_0[] = {
  110934. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110935. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110936. };
  110937. static long _vq_quantmap__16c2_s_p8_0[] = {
  110938. 13, 11, 9, 7, 5, 3, 1, 0,
  110939. 2, 4, 6, 8, 10, 12, 14,
  110940. };
  110941. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  110942. _vq_quantthresh__16c2_s_p8_0,
  110943. _vq_quantmap__16c2_s_p8_0,
  110944. 15,
  110945. 15
  110946. };
  110947. static static_codebook _16c2_s_p8_0 = {
  110948. 2, 225,
  110949. _vq_lengthlist__16c2_s_p8_0,
  110950. 1, -520986624, 1620377600, 4, 0,
  110951. _vq_quantlist__16c2_s_p8_0,
  110952. NULL,
  110953. &_vq_auxt__16c2_s_p8_0,
  110954. NULL,
  110955. 0
  110956. };
  110957. static long _vq_quantlist__16c2_s_p8_1[] = {
  110958. 10,
  110959. 9,
  110960. 11,
  110961. 8,
  110962. 12,
  110963. 7,
  110964. 13,
  110965. 6,
  110966. 14,
  110967. 5,
  110968. 15,
  110969. 4,
  110970. 16,
  110971. 3,
  110972. 17,
  110973. 2,
  110974. 18,
  110975. 1,
  110976. 19,
  110977. 0,
  110978. 20,
  110979. };
  110980. static long _vq_lengthlist__16c2_s_p8_1[] = {
  110981. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  110982. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  110983. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  110984. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  110985. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  110986. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  110987. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  110988. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  110989. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  110990. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  110991. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  110992. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  110993. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  110994. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  110995. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  110996. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  110997. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  110998. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  110999. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111000. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111001. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111002. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111003. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111004. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111005. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111006. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111007. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111008. 10,11,10,10,10,10,10,10,10,
  111009. };
  111010. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111011. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111012. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111013. 6.5, 7.5, 8.5, 9.5,
  111014. };
  111015. static long _vq_quantmap__16c2_s_p8_1[] = {
  111016. 19, 17, 15, 13, 11, 9, 7, 5,
  111017. 3, 1, 0, 2, 4, 6, 8, 10,
  111018. 12, 14, 16, 18, 20,
  111019. };
  111020. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111021. _vq_quantthresh__16c2_s_p8_1,
  111022. _vq_quantmap__16c2_s_p8_1,
  111023. 21,
  111024. 21
  111025. };
  111026. static static_codebook _16c2_s_p8_1 = {
  111027. 2, 441,
  111028. _vq_lengthlist__16c2_s_p8_1,
  111029. 1, -529268736, 1611661312, 5, 0,
  111030. _vq_quantlist__16c2_s_p8_1,
  111031. NULL,
  111032. &_vq_auxt__16c2_s_p8_1,
  111033. NULL,
  111034. 0
  111035. };
  111036. static long _vq_quantlist__16c2_s_p9_0[] = {
  111037. 6,
  111038. 5,
  111039. 7,
  111040. 4,
  111041. 8,
  111042. 3,
  111043. 9,
  111044. 2,
  111045. 10,
  111046. 1,
  111047. 11,
  111048. 0,
  111049. 12,
  111050. };
  111051. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111052. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111053. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111054. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111055. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111056. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111057. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111058. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111059. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111060. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111061. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111062. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111063. };
  111064. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111065. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111066. 2327.5, 3258.5, 4189.5, 5120.5,
  111067. };
  111068. static long _vq_quantmap__16c2_s_p9_0[] = {
  111069. 11, 9, 7, 5, 3, 1, 0, 2,
  111070. 4, 6, 8, 10, 12,
  111071. };
  111072. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111073. _vq_quantthresh__16c2_s_p9_0,
  111074. _vq_quantmap__16c2_s_p9_0,
  111075. 13,
  111076. 13
  111077. };
  111078. static static_codebook _16c2_s_p9_0 = {
  111079. 2, 169,
  111080. _vq_lengthlist__16c2_s_p9_0,
  111081. 1, -510275072, 1631393792, 4, 0,
  111082. _vq_quantlist__16c2_s_p9_0,
  111083. NULL,
  111084. &_vq_auxt__16c2_s_p9_0,
  111085. NULL,
  111086. 0
  111087. };
  111088. static long _vq_quantlist__16c2_s_p9_1[] = {
  111089. 8,
  111090. 7,
  111091. 9,
  111092. 6,
  111093. 10,
  111094. 5,
  111095. 11,
  111096. 4,
  111097. 12,
  111098. 3,
  111099. 13,
  111100. 2,
  111101. 14,
  111102. 1,
  111103. 15,
  111104. 0,
  111105. 16,
  111106. };
  111107. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111108. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111109. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111110. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111111. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111112. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111113. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111114. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111115. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111116. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111117. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111118. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111119. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111120. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111121. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111122. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111123. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111124. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111125. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111126. 10,
  111127. };
  111128. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111129. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111130. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111131. };
  111132. static long _vq_quantmap__16c2_s_p9_1[] = {
  111133. 15, 13, 11, 9, 7, 5, 3, 1,
  111134. 0, 2, 4, 6, 8, 10, 12, 14,
  111135. 16,
  111136. };
  111137. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111138. _vq_quantthresh__16c2_s_p9_1,
  111139. _vq_quantmap__16c2_s_p9_1,
  111140. 17,
  111141. 17
  111142. };
  111143. static static_codebook _16c2_s_p9_1 = {
  111144. 2, 289,
  111145. _vq_lengthlist__16c2_s_p9_1,
  111146. 1, -518488064, 1622704128, 5, 0,
  111147. _vq_quantlist__16c2_s_p9_1,
  111148. NULL,
  111149. &_vq_auxt__16c2_s_p9_1,
  111150. NULL,
  111151. 0
  111152. };
  111153. static long _vq_quantlist__16c2_s_p9_2[] = {
  111154. 13,
  111155. 12,
  111156. 14,
  111157. 11,
  111158. 15,
  111159. 10,
  111160. 16,
  111161. 9,
  111162. 17,
  111163. 8,
  111164. 18,
  111165. 7,
  111166. 19,
  111167. 6,
  111168. 20,
  111169. 5,
  111170. 21,
  111171. 4,
  111172. 22,
  111173. 3,
  111174. 23,
  111175. 2,
  111176. 24,
  111177. 1,
  111178. 25,
  111179. 0,
  111180. 26,
  111181. };
  111182. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111183. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111184. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111185. };
  111186. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111187. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111188. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111189. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111190. 11.5, 12.5,
  111191. };
  111192. static long _vq_quantmap__16c2_s_p9_2[] = {
  111193. 25, 23, 21, 19, 17, 15, 13, 11,
  111194. 9, 7, 5, 3, 1, 0, 2, 4,
  111195. 6, 8, 10, 12, 14, 16, 18, 20,
  111196. 22, 24, 26,
  111197. };
  111198. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111199. _vq_quantthresh__16c2_s_p9_2,
  111200. _vq_quantmap__16c2_s_p9_2,
  111201. 27,
  111202. 27
  111203. };
  111204. static static_codebook _16c2_s_p9_2 = {
  111205. 1, 27,
  111206. _vq_lengthlist__16c2_s_p9_2,
  111207. 1, -528875520, 1611661312, 5, 0,
  111208. _vq_quantlist__16c2_s_p9_2,
  111209. NULL,
  111210. &_vq_auxt__16c2_s_p9_2,
  111211. NULL,
  111212. 0
  111213. };
  111214. static long _huff_lengthlist__16c2_s_short[] = {
  111215. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111216. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111217. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111218. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111219. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111220. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111221. 15,12,14,14,
  111222. };
  111223. static static_codebook _huff_book__16c2_s_short = {
  111224. 2, 100,
  111225. _huff_lengthlist__16c2_s_short,
  111226. 0, 0, 0, 0, 0,
  111227. NULL,
  111228. NULL,
  111229. NULL,
  111230. NULL,
  111231. 0
  111232. };
  111233. static long _vq_quantlist__8c0_s_p1_0[] = {
  111234. 1,
  111235. 0,
  111236. 2,
  111237. };
  111238. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111239. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111240. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111244. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111245. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111249. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111250. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111285. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111290. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  111295. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111330. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111331. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111336. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111341. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111547. 0, 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,
  111650. };
  111651. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111652. -0.5, 0.5,
  111653. };
  111654. static long _vq_quantmap__8c0_s_p1_0[] = {
  111655. 1, 0, 2,
  111656. };
  111657. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111658. _vq_quantthresh__8c0_s_p1_0,
  111659. _vq_quantmap__8c0_s_p1_0,
  111660. 3,
  111661. 3
  111662. };
  111663. static static_codebook _8c0_s_p1_0 = {
  111664. 8, 6561,
  111665. _vq_lengthlist__8c0_s_p1_0,
  111666. 1, -535822336, 1611661312, 2, 0,
  111667. _vq_quantlist__8c0_s_p1_0,
  111668. NULL,
  111669. &_vq_auxt__8c0_s_p1_0,
  111670. NULL,
  111671. 0
  111672. };
  111673. static long _vq_quantlist__8c0_s_p2_0[] = {
  111674. 2,
  111675. 1,
  111676. 3,
  111677. 0,
  111678. 4,
  111679. };
  111680. static long _vq_lengthlist__8c0_s_p2_0[] = {
  111681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  111721. };
  111722. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111723. -1.5, -0.5, 0.5, 1.5,
  111724. };
  111725. static long _vq_quantmap__8c0_s_p2_0[] = {
  111726. 3, 1, 0, 2, 4,
  111727. };
  111728. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111729. _vq_quantthresh__8c0_s_p2_0,
  111730. _vq_quantmap__8c0_s_p2_0,
  111731. 5,
  111732. 5
  111733. };
  111734. static static_codebook _8c0_s_p2_0 = {
  111735. 4, 625,
  111736. _vq_lengthlist__8c0_s_p2_0,
  111737. 1, -533725184, 1611661312, 3, 0,
  111738. _vq_quantlist__8c0_s_p2_0,
  111739. NULL,
  111740. &_vq_auxt__8c0_s_p2_0,
  111741. NULL,
  111742. 0
  111743. };
  111744. static long _vq_quantlist__8c0_s_p3_0[] = {
  111745. 2,
  111746. 1,
  111747. 3,
  111748. 0,
  111749. 4,
  111750. };
  111751. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111752. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111755. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111758. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  111759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  111792. };
  111793. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111794. -1.5, -0.5, 0.5, 1.5,
  111795. };
  111796. static long _vq_quantmap__8c0_s_p3_0[] = {
  111797. 3, 1, 0, 2, 4,
  111798. };
  111799. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111800. _vq_quantthresh__8c0_s_p3_0,
  111801. _vq_quantmap__8c0_s_p3_0,
  111802. 5,
  111803. 5
  111804. };
  111805. static static_codebook _8c0_s_p3_0 = {
  111806. 4, 625,
  111807. _vq_lengthlist__8c0_s_p3_0,
  111808. 1, -533725184, 1611661312, 3, 0,
  111809. _vq_quantlist__8c0_s_p3_0,
  111810. NULL,
  111811. &_vq_auxt__8c0_s_p3_0,
  111812. NULL,
  111813. 0
  111814. };
  111815. static long _vq_quantlist__8c0_s_p4_0[] = {
  111816. 4,
  111817. 3,
  111818. 5,
  111819. 2,
  111820. 6,
  111821. 1,
  111822. 7,
  111823. 0,
  111824. 8,
  111825. };
  111826. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111827. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111828. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111829. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111830. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111831. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111832. 0,
  111833. };
  111834. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111835. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111836. };
  111837. static long _vq_quantmap__8c0_s_p4_0[] = {
  111838. 7, 5, 3, 1, 0, 2, 4, 6,
  111839. 8,
  111840. };
  111841. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111842. _vq_quantthresh__8c0_s_p4_0,
  111843. _vq_quantmap__8c0_s_p4_0,
  111844. 9,
  111845. 9
  111846. };
  111847. static static_codebook _8c0_s_p4_0 = {
  111848. 2, 81,
  111849. _vq_lengthlist__8c0_s_p4_0,
  111850. 1, -531628032, 1611661312, 4, 0,
  111851. _vq_quantlist__8c0_s_p4_0,
  111852. NULL,
  111853. &_vq_auxt__8c0_s_p4_0,
  111854. NULL,
  111855. 0
  111856. };
  111857. static long _vq_quantlist__8c0_s_p5_0[] = {
  111858. 4,
  111859. 3,
  111860. 5,
  111861. 2,
  111862. 6,
  111863. 1,
  111864. 7,
  111865. 0,
  111866. 8,
  111867. };
  111868. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111869. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111870. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111871. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111872. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111873. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111874. 10,
  111875. };
  111876. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111877. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111878. };
  111879. static long _vq_quantmap__8c0_s_p5_0[] = {
  111880. 7, 5, 3, 1, 0, 2, 4, 6,
  111881. 8,
  111882. };
  111883. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111884. _vq_quantthresh__8c0_s_p5_0,
  111885. _vq_quantmap__8c0_s_p5_0,
  111886. 9,
  111887. 9
  111888. };
  111889. static static_codebook _8c0_s_p5_0 = {
  111890. 2, 81,
  111891. _vq_lengthlist__8c0_s_p5_0,
  111892. 1, -531628032, 1611661312, 4, 0,
  111893. _vq_quantlist__8c0_s_p5_0,
  111894. NULL,
  111895. &_vq_auxt__8c0_s_p5_0,
  111896. NULL,
  111897. 0
  111898. };
  111899. static long _vq_quantlist__8c0_s_p6_0[] = {
  111900. 8,
  111901. 7,
  111902. 9,
  111903. 6,
  111904. 10,
  111905. 5,
  111906. 11,
  111907. 4,
  111908. 12,
  111909. 3,
  111910. 13,
  111911. 2,
  111912. 14,
  111913. 1,
  111914. 15,
  111915. 0,
  111916. 16,
  111917. };
  111918. static long _vq_lengthlist__8c0_s_p6_0[] = {
  111919. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  111920. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  111921. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  111922. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  111923. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  111924. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  111925. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  111926. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  111927. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  111928. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  111929. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  111930. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  111931. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  111932. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  111933. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  111934. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  111935. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  111936. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  111937. 14,
  111938. };
  111939. static float _vq_quantthresh__8c0_s_p6_0[] = {
  111940. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111941. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111942. };
  111943. static long _vq_quantmap__8c0_s_p6_0[] = {
  111944. 15, 13, 11, 9, 7, 5, 3, 1,
  111945. 0, 2, 4, 6, 8, 10, 12, 14,
  111946. 16,
  111947. };
  111948. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  111949. _vq_quantthresh__8c0_s_p6_0,
  111950. _vq_quantmap__8c0_s_p6_0,
  111951. 17,
  111952. 17
  111953. };
  111954. static static_codebook _8c0_s_p6_0 = {
  111955. 2, 289,
  111956. _vq_lengthlist__8c0_s_p6_0,
  111957. 1, -529530880, 1611661312, 5, 0,
  111958. _vq_quantlist__8c0_s_p6_0,
  111959. NULL,
  111960. &_vq_auxt__8c0_s_p6_0,
  111961. NULL,
  111962. 0
  111963. };
  111964. static long _vq_quantlist__8c0_s_p7_0[] = {
  111965. 1,
  111966. 0,
  111967. 2,
  111968. };
  111969. static long _vq_lengthlist__8c0_s_p7_0[] = {
  111970. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  111971. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  111972. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  111973. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  111974. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  111975. 10,
  111976. };
  111977. static float _vq_quantthresh__8c0_s_p7_0[] = {
  111978. -5.5, 5.5,
  111979. };
  111980. static long _vq_quantmap__8c0_s_p7_0[] = {
  111981. 1, 0, 2,
  111982. };
  111983. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  111984. _vq_quantthresh__8c0_s_p7_0,
  111985. _vq_quantmap__8c0_s_p7_0,
  111986. 3,
  111987. 3
  111988. };
  111989. static static_codebook _8c0_s_p7_0 = {
  111990. 4, 81,
  111991. _vq_lengthlist__8c0_s_p7_0,
  111992. 1, -529137664, 1618345984, 2, 0,
  111993. _vq_quantlist__8c0_s_p7_0,
  111994. NULL,
  111995. &_vq_auxt__8c0_s_p7_0,
  111996. NULL,
  111997. 0
  111998. };
  111999. static long _vq_quantlist__8c0_s_p7_1[] = {
  112000. 5,
  112001. 4,
  112002. 6,
  112003. 3,
  112004. 7,
  112005. 2,
  112006. 8,
  112007. 1,
  112008. 9,
  112009. 0,
  112010. 10,
  112011. };
  112012. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112013. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112014. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112015. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112016. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112017. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112018. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112019. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112020. 10,10,10, 9, 9, 9,10,10,10,
  112021. };
  112022. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112023. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112024. 3.5, 4.5,
  112025. };
  112026. static long _vq_quantmap__8c0_s_p7_1[] = {
  112027. 9, 7, 5, 3, 1, 0, 2, 4,
  112028. 6, 8, 10,
  112029. };
  112030. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112031. _vq_quantthresh__8c0_s_p7_1,
  112032. _vq_quantmap__8c0_s_p7_1,
  112033. 11,
  112034. 11
  112035. };
  112036. static static_codebook _8c0_s_p7_1 = {
  112037. 2, 121,
  112038. _vq_lengthlist__8c0_s_p7_1,
  112039. 1, -531365888, 1611661312, 4, 0,
  112040. _vq_quantlist__8c0_s_p7_1,
  112041. NULL,
  112042. &_vq_auxt__8c0_s_p7_1,
  112043. NULL,
  112044. 0
  112045. };
  112046. static long _vq_quantlist__8c0_s_p8_0[] = {
  112047. 6,
  112048. 5,
  112049. 7,
  112050. 4,
  112051. 8,
  112052. 3,
  112053. 9,
  112054. 2,
  112055. 10,
  112056. 1,
  112057. 11,
  112058. 0,
  112059. 12,
  112060. };
  112061. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112062. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112063. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112064. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112065. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112066. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112067. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112068. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112069. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112070. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112071. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112072. 0, 0,13,13,11,13,13,11,12,
  112073. };
  112074. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112075. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112076. 12.5, 17.5, 22.5, 27.5,
  112077. };
  112078. static long _vq_quantmap__8c0_s_p8_0[] = {
  112079. 11, 9, 7, 5, 3, 1, 0, 2,
  112080. 4, 6, 8, 10, 12,
  112081. };
  112082. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112083. _vq_quantthresh__8c0_s_p8_0,
  112084. _vq_quantmap__8c0_s_p8_0,
  112085. 13,
  112086. 13
  112087. };
  112088. static static_codebook _8c0_s_p8_0 = {
  112089. 2, 169,
  112090. _vq_lengthlist__8c0_s_p8_0,
  112091. 1, -526516224, 1616117760, 4, 0,
  112092. _vq_quantlist__8c0_s_p8_0,
  112093. NULL,
  112094. &_vq_auxt__8c0_s_p8_0,
  112095. NULL,
  112096. 0
  112097. };
  112098. static long _vq_quantlist__8c0_s_p8_1[] = {
  112099. 2,
  112100. 1,
  112101. 3,
  112102. 0,
  112103. 4,
  112104. };
  112105. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112106. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112107. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112108. };
  112109. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112110. -1.5, -0.5, 0.5, 1.5,
  112111. };
  112112. static long _vq_quantmap__8c0_s_p8_1[] = {
  112113. 3, 1, 0, 2, 4,
  112114. };
  112115. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112116. _vq_quantthresh__8c0_s_p8_1,
  112117. _vq_quantmap__8c0_s_p8_1,
  112118. 5,
  112119. 5
  112120. };
  112121. static static_codebook _8c0_s_p8_1 = {
  112122. 2, 25,
  112123. _vq_lengthlist__8c0_s_p8_1,
  112124. 1, -533725184, 1611661312, 3, 0,
  112125. _vq_quantlist__8c0_s_p8_1,
  112126. NULL,
  112127. &_vq_auxt__8c0_s_p8_1,
  112128. NULL,
  112129. 0
  112130. };
  112131. static long _vq_quantlist__8c0_s_p9_0[] = {
  112132. 1,
  112133. 0,
  112134. 2,
  112135. };
  112136. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112137. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112138. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112139. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112140. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112141. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112142. 7,
  112143. };
  112144. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112145. -157.5, 157.5,
  112146. };
  112147. static long _vq_quantmap__8c0_s_p9_0[] = {
  112148. 1, 0, 2,
  112149. };
  112150. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112151. _vq_quantthresh__8c0_s_p9_0,
  112152. _vq_quantmap__8c0_s_p9_0,
  112153. 3,
  112154. 3
  112155. };
  112156. static static_codebook _8c0_s_p9_0 = {
  112157. 4, 81,
  112158. _vq_lengthlist__8c0_s_p9_0,
  112159. 1, -518803456, 1628680192, 2, 0,
  112160. _vq_quantlist__8c0_s_p9_0,
  112161. NULL,
  112162. &_vq_auxt__8c0_s_p9_0,
  112163. NULL,
  112164. 0
  112165. };
  112166. static long _vq_quantlist__8c0_s_p9_1[] = {
  112167. 7,
  112168. 6,
  112169. 8,
  112170. 5,
  112171. 9,
  112172. 4,
  112173. 10,
  112174. 3,
  112175. 11,
  112176. 2,
  112177. 12,
  112178. 1,
  112179. 13,
  112180. 0,
  112181. 14,
  112182. };
  112183. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112184. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112185. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112186. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112187. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112188. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112189. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112190. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112191. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112192. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112193. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112194. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112195. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112196. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112197. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112198. 11,
  112199. };
  112200. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112201. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112202. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112203. };
  112204. static long _vq_quantmap__8c0_s_p9_1[] = {
  112205. 13, 11, 9, 7, 5, 3, 1, 0,
  112206. 2, 4, 6, 8, 10, 12, 14,
  112207. };
  112208. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112209. _vq_quantthresh__8c0_s_p9_1,
  112210. _vq_quantmap__8c0_s_p9_1,
  112211. 15,
  112212. 15
  112213. };
  112214. static static_codebook _8c0_s_p9_1 = {
  112215. 2, 225,
  112216. _vq_lengthlist__8c0_s_p9_1,
  112217. 1, -520986624, 1620377600, 4, 0,
  112218. _vq_quantlist__8c0_s_p9_1,
  112219. NULL,
  112220. &_vq_auxt__8c0_s_p9_1,
  112221. NULL,
  112222. 0
  112223. };
  112224. static long _vq_quantlist__8c0_s_p9_2[] = {
  112225. 10,
  112226. 9,
  112227. 11,
  112228. 8,
  112229. 12,
  112230. 7,
  112231. 13,
  112232. 6,
  112233. 14,
  112234. 5,
  112235. 15,
  112236. 4,
  112237. 16,
  112238. 3,
  112239. 17,
  112240. 2,
  112241. 18,
  112242. 1,
  112243. 19,
  112244. 0,
  112245. 20,
  112246. };
  112247. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112248. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112249. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112250. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112251. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112252. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112253. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112254. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112255. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112256. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112257. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112258. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112259. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112260. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112261. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112262. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112263. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112264. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112265. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112266. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112267. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112268. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112269. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112270. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112271. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112272. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112273. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112274. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112275. 10,11, 9,11,10, 9,10, 9,10,
  112276. };
  112277. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112278. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112279. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112280. 6.5, 7.5, 8.5, 9.5,
  112281. };
  112282. static long _vq_quantmap__8c0_s_p9_2[] = {
  112283. 19, 17, 15, 13, 11, 9, 7, 5,
  112284. 3, 1, 0, 2, 4, 6, 8, 10,
  112285. 12, 14, 16, 18, 20,
  112286. };
  112287. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112288. _vq_quantthresh__8c0_s_p9_2,
  112289. _vq_quantmap__8c0_s_p9_2,
  112290. 21,
  112291. 21
  112292. };
  112293. static static_codebook _8c0_s_p9_2 = {
  112294. 2, 441,
  112295. _vq_lengthlist__8c0_s_p9_2,
  112296. 1, -529268736, 1611661312, 5, 0,
  112297. _vq_quantlist__8c0_s_p9_2,
  112298. NULL,
  112299. &_vq_auxt__8c0_s_p9_2,
  112300. NULL,
  112301. 0
  112302. };
  112303. static long _huff_lengthlist__8c0_s_single[] = {
  112304. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112305. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112306. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112307. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112308. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112309. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112310. 17,16,17,17,
  112311. };
  112312. static static_codebook _huff_book__8c0_s_single = {
  112313. 2, 100,
  112314. _huff_lengthlist__8c0_s_single,
  112315. 0, 0, 0, 0, 0,
  112316. NULL,
  112317. NULL,
  112318. NULL,
  112319. NULL,
  112320. 0
  112321. };
  112322. static long _vq_quantlist__8c1_s_p1_0[] = {
  112323. 1,
  112324. 0,
  112325. 2,
  112326. };
  112327. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112328. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112329. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112333. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112334. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112338. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112339. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112374. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112379. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  112384. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112419. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112420. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112425. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112430. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112636. 0, 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,
  112739. };
  112740. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112741. -0.5, 0.5,
  112742. };
  112743. static long _vq_quantmap__8c1_s_p1_0[] = {
  112744. 1, 0, 2,
  112745. };
  112746. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112747. _vq_quantthresh__8c1_s_p1_0,
  112748. _vq_quantmap__8c1_s_p1_0,
  112749. 3,
  112750. 3
  112751. };
  112752. static static_codebook _8c1_s_p1_0 = {
  112753. 8, 6561,
  112754. _vq_lengthlist__8c1_s_p1_0,
  112755. 1, -535822336, 1611661312, 2, 0,
  112756. _vq_quantlist__8c1_s_p1_0,
  112757. NULL,
  112758. &_vq_auxt__8c1_s_p1_0,
  112759. NULL,
  112760. 0
  112761. };
  112762. static long _vq_quantlist__8c1_s_p2_0[] = {
  112763. 2,
  112764. 1,
  112765. 3,
  112766. 0,
  112767. 4,
  112768. };
  112769. static long _vq_lengthlist__8c1_s_p2_0[] = {
  112770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  112810. };
  112811. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112812. -1.5, -0.5, 0.5, 1.5,
  112813. };
  112814. static long _vq_quantmap__8c1_s_p2_0[] = {
  112815. 3, 1, 0, 2, 4,
  112816. };
  112817. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112818. _vq_quantthresh__8c1_s_p2_0,
  112819. _vq_quantmap__8c1_s_p2_0,
  112820. 5,
  112821. 5
  112822. };
  112823. static static_codebook _8c1_s_p2_0 = {
  112824. 4, 625,
  112825. _vq_lengthlist__8c1_s_p2_0,
  112826. 1, -533725184, 1611661312, 3, 0,
  112827. _vq_quantlist__8c1_s_p2_0,
  112828. NULL,
  112829. &_vq_auxt__8c1_s_p2_0,
  112830. NULL,
  112831. 0
  112832. };
  112833. static long _vq_quantlist__8c1_s_p3_0[] = {
  112834. 2,
  112835. 1,
  112836. 3,
  112837. 0,
  112838. 4,
  112839. };
  112840. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112841. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112844. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112847. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  112881. };
  112882. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112883. -1.5, -0.5, 0.5, 1.5,
  112884. };
  112885. static long _vq_quantmap__8c1_s_p3_0[] = {
  112886. 3, 1, 0, 2, 4,
  112887. };
  112888. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112889. _vq_quantthresh__8c1_s_p3_0,
  112890. _vq_quantmap__8c1_s_p3_0,
  112891. 5,
  112892. 5
  112893. };
  112894. static static_codebook _8c1_s_p3_0 = {
  112895. 4, 625,
  112896. _vq_lengthlist__8c1_s_p3_0,
  112897. 1, -533725184, 1611661312, 3, 0,
  112898. _vq_quantlist__8c1_s_p3_0,
  112899. NULL,
  112900. &_vq_auxt__8c1_s_p3_0,
  112901. NULL,
  112902. 0
  112903. };
  112904. static long _vq_quantlist__8c1_s_p4_0[] = {
  112905. 4,
  112906. 3,
  112907. 5,
  112908. 2,
  112909. 6,
  112910. 1,
  112911. 7,
  112912. 0,
  112913. 8,
  112914. };
  112915. static long _vq_lengthlist__8c1_s_p4_0[] = {
  112916. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112917. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112918. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112919. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112920. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112921. 0,
  112922. };
  112923. static float _vq_quantthresh__8c1_s_p4_0[] = {
  112924. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112925. };
  112926. static long _vq_quantmap__8c1_s_p4_0[] = {
  112927. 7, 5, 3, 1, 0, 2, 4, 6,
  112928. 8,
  112929. };
  112930. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  112931. _vq_quantthresh__8c1_s_p4_0,
  112932. _vq_quantmap__8c1_s_p4_0,
  112933. 9,
  112934. 9
  112935. };
  112936. static static_codebook _8c1_s_p4_0 = {
  112937. 2, 81,
  112938. _vq_lengthlist__8c1_s_p4_0,
  112939. 1, -531628032, 1611661312, 4, 0,
  112940. _vq_quantlist__8c1_s_p4_0,
  112941. NULL,
  112942. &_vq_auxt__8c1_s_p4_0,
  112943. NULL,
  112944. 0
  112945. };
  112946. static long _vq_quantlist__8c1_s_p5_0[] = {
  112947. 4,
  112948. 3,
  112949. 5,
  112950. 2,
  112951. 6,
  112952. 1,
  112953. 7,
  112954. 0,
  112955. 8,
  112956. };
  112957. static long _vq_lengthlist__8c1_s_p5_0[] = {
  112958. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  112959. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  112960. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  112961. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  112962. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112963. 10,
  112964. };
  112965. static float _vq_quantthresh__8c1_s_p5_0[] = {
  112966. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112967. };
  112968. static long _vq_quantmap__8c1_s_p5_0[] = {
  112969. 7, 5, 3, 1, 0, 2, 4, 6,
  112970. 8,
  112971. };
  112972. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  112973. _vq_quantthresh__8c1_s_p5_0,
  112974. _vq_quantmap__8c1_s_p5_0,
  112975. 9,
  112976. 9
  112977. };
  112978. static static_codebook _8c1_s_p5_0 = {
  112979. 2, 81,
  112980. _vq_lengthlist__8c1_s_p5_0,
  112981. 1, -531628032, 1611661312, 4, 0,
  112982. _vq_quantlist__8c1_s_p5_0,
  112983. NULL,
  112984. &_vq_auxt__8c1_s_p5_0,
  112985. NULL,
  112986. 0
  112987. };
  112988. static long _vq_quantlist__8c1_s_p6_0[] = {
  112989. 8,
  112990. 7,
  112991. 9,
  112992. 6,
  112993. 10,
  112994. 5,
  112995. 11,
  112996. 4,
  112997. 12,
  112998. 3,
  112999. 13,
  113000. 2,
  113001. 14,
  113002. 1,
  113003. 15,
  113004. 0,
  113005. 16,
  113006. };
  113007. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113008. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113009. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113010. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113011. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113012. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113013. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113014. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113015. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113016. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113017. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113018. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113019. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113020. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113021. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113022. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113023. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113024. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113025. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113026. 14,
  113027. };
  113028. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113029. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113030. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113031. };
  113032. static long _vq_quantmap__8c1_s_p6_0[] = {
  113033. 15, 13, 11, 9, 7, 5, 3, 1,
  113034. 0, 2, 4, 6, 8, 10, 12, 14,
  113035. 16,
  113036. };
  113037. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113038. _vq_quantthresh__8c1_s_p6_0,
  113039. _vq_quantmap__8c1_s_p6_0,
  113040. 17,
  113041. 17
  113042. };
  113043. static static_codebook _8c1_s_p6_0 = {
  113044. 2, 289,
  113045. _vq_lengthlist__8c1_s_p6_0,
  113046. 1, -529530880, 1611661312, 5, 0,
  113047. _vq_quantlist__8c1_s_p6_0,
  113048. NULL,
  113049. &_vq_auxt__8c1_s_p6_0,
  113050. NULL,
  113051. 0
  113052. };
  113053. static long _vq_quantlist__8c1_s_p7_0[] = {
  113054. 1,
  113055. 0,
  113056. 2,
  113057. };
  113058. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113059. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113060. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113061. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113062. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113063. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113064. 9,
  113065. };
  113066. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113067. -5.5, 5.5,
  113068. };
  113069. static long _vq_quantmap__8c1_s_p7_0[] = {
  113070. 1, 0, 2,
  113071. };
  113072. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113073. _vq_quantthresh__8c1_s_p7_0,
  113074. _vq_quantmap__8c1_s_p7_0,
  113075. 3,
  113076. 3
  113077. };
  113078. static static_codebook _8c1_s_p7_0 = {
  113079. 4, 81,
  113080. _vq_lengthlist__8c1_s_p7_0,
  113081. 1, -529137664, 1618345984, 2, 0,
  113082. _vq_quantlist__8c1_s_p7_0,
  113083. NULL,
  113084. &_vq_auxt__8c1_s_p7_0,
  113085. NULL,
  113086. 0
  113087. };
  113088. static long _vq_quantlist__8c1_s_p7_1[] = {
  113089. 5,
  113090. 4,
  113091. 6,
  113092. 3,
  113093. 7,
  113094. 2,
  113095. 8,
  113096. 1,
  113097. 9,
  113098. 0,
  113099. 10,
  113100. };
  113101. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113102. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113103. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113104. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113105. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113106. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113107. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113108. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113109. 10,10,10, 8, 8, 8, 8, 8, 8,
  113110. };
  113111. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113112. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113113. 3.5, 4.5,
  113114. };
  113115. static long _vq_quantmap__8c1_s_p7_1[] = {
  113116. 9, 7, 5, 3, 1, 0, 2, 4,
  113117. 6, 8, 10,
  113118. };
  113119. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113120. _vq_quantthresh__8c1_s_p7_1,
  113121. _vq_quantmap__8c1_s_p7_1,
  113122. 11,
  113123. 11
  113124. };
  113125. static static_codebook _8c1_s_p7_1 = {
  113126. 2, 121,
  113127. _vq_lengthlist__8c1_s_p7_1,
  113128. 1, -531365888, 1611661312, 4, 0,
  113129. _vq_quantlist__8c1_s_p7_1,
  113130. NULL,
  113131. &_vq_auxt__8c1_s_p7_1,
  113132. NULL,
  113133. 0
  113134. };
  113135. static long _vq_quantlist__8c1_s_p8_0[] = {
  113136. 6,
  113137. 5,
  113138. 7,
  113139. 4,
  113140. 8,
  113141. 3,
  113142. 9,
  113143. 2,
  113144. 10,
  113145. 1,
  113146. 11,
  113147. 0,
  113148. 12,
  113149. };
  113150. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113151. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113152. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113153. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113154. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113155. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113156. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113157. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113158. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113159. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113160. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113161. 0,12,12,11,10,12,11,13,12,
  113162. };
  113163. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113164. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113165. 12.5, 17.5, 22.5, 27.5,
  113166. };
  113167. static long _vq_quantmap__8c1_s_p8_0[] = {
  113168. 11, 9, 7, 5, 3, 1, 0, 2,
  113169. 4, 6, 8, 10, 12,
  113170. };
  113171. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113172. _vq_quantthresh__8c1_s_p8_0,
  113173. _vq_quantmap__8c1_s_p8_0,
  113174. 13,
  113175. 13
  113176. };
  113177. static static_codebook _8c1_s_p8_0 = {
  113178. 2, 169,
  113179. _vq_lengthlist__8c1_s_p8_0,
  113180. 1, -526516224, 1616117760, 4, 0,
  113181. _vq_quantlist__8c1_s_p8_0,
  113182. NULL,
  113183. &_vq_auxt__8c1_s_p8_0,
  113184. NULL,
  113185. 0
  113186. };
  113187. static long _vq_quantlist__8c1_s_p8_1[] = {
  113188. 2,
  113189. 1,
  113190. 3,
  113191. 0,
  113192. 4,
  113193. };
  113194. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113195. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113196. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113197. };
  113198. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113199. -1.5, -0.5, 0.5, 1.5,
  113200. };
  113201. static long _vq_quantmap__8c1_s_p8_1[] = {
  113202. 3, 1, 0, 2, 4,
  113203. };
  113204. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113205. _vq_quantthresh__8c1_s_p8_1,
  113206. _vq_quantmap__8c1_s_p8_1,
  113207. 5,
  113208. 5
  113209. };
  113210. static static_codebook _8c1_s_p8_1 = {
  113211. 2, 25,
  113212. _vq_lengthlist__8c1_s_p8_1,
  113213. 1, -533725184, 1611661312, 3, 0,
  113214. _vq_quantlist__8c1_s_p8_1,
  113215. NULL,
  113216. &_vq_auxt__8c1_s_p8_1,
  113217. NULL,
  113218. 0
  113219. };
  113220. static long _vq_quantlist__8c1_s_p9_0[] = {
  113221. 6,
  113222. 5,
  113223. 7,
  113224. 4,
  113225. 8,
  113226. 3,
  113227. 9,
  113228. 2,
  113229. 10,
  113230. 1,
  113231. 11,
  113232. 0,
  113233. 12,
  113234. };
  113235. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113236. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113237. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113238. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113239. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113240. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113241. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113242. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113243. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113244. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113245. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113246. 10,10,10,10,10, 9, 9, 9, 9,
  113247. };
  113248. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113249. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113250. 787.5, 1102.5, 1417.5, 1732.5,
  113251. };
  113252. static long _vq_quantmap__8c1_s_p9_0[] = {
  113253. 11, 9, 7, 5, 3, 1, 0, 2,
  113254. 4, 6, 8, 10, 12,
  113255. };
  113256. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113257. _vq_quantthresh__8c1_s_p9_0,
  113258. _vq_quantmap__8c1_s_p9_0,
  113259. 13,
  113260. 13
  113261. };
  113262. static static_codebook _8c1_s_p9_0 = {
  113263. 2, 169,
  113264. _vq_lengthlist__8c1_s_p9_0,
  113265. 1, -513964032, 1628680192, 4, 0,
  113266. _vq_quantlist__8c1_s_p9_0,
  113267. NULL,
  113268. &_vq_auxt__8c1_s_p9_0,
  113269. NULL,
  113270. 0
  113271. };
  113272. static long _vq_quantlist__8c1_s_p9_1[] = {
  113273. 7,
  113274. 6,
  113275. 8,
  113276. 5,
  113277. 9,
  113278. 4,
  113279. 10,
  113280. 3,
  113281. 11,
  113282. 2,
  113283. 12,
  113284. 1,
  113285. 13,
  113286. 0,
  113287. 14,
  113288. };
  113289. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113290. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113291. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113292. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113293. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113294. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113295. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113296. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113297. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113298. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113299. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113300. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113301. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113302. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113303. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113304. 15,
  113305. };
  113306. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113307. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113308. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113309. };
  113310. static long _vq_quantmap__8c1_s_p9_1[] = {
  113311. 13, 11, 9, 7, 5, 3, 1, 0,
  113312. 2, 4, 6, 8, 10, 12, 14,
  113313. };
  113314. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113315. _vq_quantthresh__8c1_s_p9_1,
  113316. _vq_quantmap__8c1_s_p9_1,
  113317. 15,
  113318. 15
  113319. };
  113320. static static_codebook _8c1_s_p9_1 = {
  113321. 2, 225,
  113322. _vq_lengthlist__8c1_s_p9_1,
  113323. 1, -520986624, 1620377600, 4, 0,
  113324. _vq_quantlist__8c1_s_p9_1,
  113325. NULL,
  113326. &_vq_auxt__8c1_s_p9_1,
  113327. NULL,
  113328. 0
  113329. };
  113330. static long _vq_quantlist__8c1_s_p9_2[] = {
  113331. 10,
  113332. 9,
  113333. 11,
  113334. 8,
  113335. 12,
  113336. 7,
  113337. 13,
  113338. 6,
  113339. 14,
  113340. 5,
  113341. 15,
  113342. 4,
  113343. 16,
  113344. 3,
  113345. 17,
  113346. 2,
  113347. 18,
  113348. 1,
  113349. 19,
  113350. 0,
  113351. 20,
  113352. };
  113353. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113354. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113355. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113356. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113357. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113358. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113359. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113360. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113361. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113362. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113363. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113364. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113365. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113366. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113367. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113368. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113369. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113370. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113371. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113372. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113373. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113374. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113375. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113376. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113377. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113378. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113379. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113380. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113381. 10,10,10,10,10,10,10,10,10,
  113382. };
  113383. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113384. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113385. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113386. 6.5, 7.5, 8.5, 9.5,
  113387. };
  113388. static long _vq_quantmap__8c1_s_p9_2[] = {
  113389. 19, 17, 15, 13, 11, 9, 7, 5,
  113390. 3, 1, 0, 2, 4, 6, 8, 10,
  113391. 12, 14, 16, 18, 20,
  113392. };
  113393. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113394. _vq_quantthresh__8c1_s_p9_2,
  113395. _vq_quantmap__8c1_s_p9_2,
  113396. 21,
  113397. 21
  113398. };
  113399. static static_codebook _8c1_s_p9_2 = {
  113400. 2, 441,
  113401. _vq_lengthlist__8c1_s_p9_2,
  113402. 1, -529268736, 1611661312, 5, 0,
  113403. _vq_quantlist__8c1_s_p9_2,
  113404. NULL,
  113405. &_vq_auxt__8c1_s_p9_2,
  113406. NULL,
  113407. 0
  113408. };
  113409. static long _huff_lengthlist__8c1_s_single[] = {
  113410. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113411. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113412. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113413. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113414. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113415. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113416. 9, 7, 7, 8,
  113417. };
  113418. static static_codebook _huff_book__8c1_s_single = {
  113419. 2, 100,
  113420. _huff_lengthlist__8c1_s_single,
  113421. 0, 0, 0, 0, 0,
  113422. NULL,
  113423. NULL,
  113424. NULL,
  113425. NULL,
  113426. 0
  113427. };
  113428. static long _huff_lengthlist__44c2_s_long[] = {
  113429. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113430. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113431. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113432. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113433. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113434. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113435. 10, 8, 8, 9,
  113436. };
  113437. static static_codebook _huff_book__44c2_s_long = {
  113438. 2, 100,
  113439. _huff_lengthlist__44c2_s_long,
  113440. 0, 0, 0, 0, 0,
  113441. NULL,
  113442. NULL,
  113443. NULL,
  113444. NULL,
  113445. 0
  113446. };
  113447. static long _vq_quantlist__44c2_s_p1_0[] = {
  113448. 1,
  113449. 0,
  113450. 2,
  113451. };
  113452. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113453. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113454. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113458. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113459. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113463. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113464. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113499. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  113504. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  113509. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113544. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113545. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113550. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113555. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113761. 0, 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,
  113864. };
  113865. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113866. -0.5, 0.5,
  113867. };
  113868. static long _vq_quantmap__44c2_s_p1_0[] = {
  113869. 1, 0, 2,
  113870. };
  113871. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113872. _vq_quantthresh__44c2_s_p1_0,
  113873. _vq_quantmap__44c2_s_p1_0,
  113874. 3,
  113875. 3
  113876. };
  113877. static static_codebook _44c2_s_p1_0 = {
  113878. 8, 6561,
  113879. _vq_lengthlist__44c2_s_p1_0,
  113880. 1, -535822336, 1611661312, 2, 0,
  113881. _vq_quantlist__44c2_s_p1_0,
  113882. NULL,
  113883. &_vq_auxt__44c2_s_p1_0,
  113884. NULL,
  113885. 0
  113886. };
  113887. static long _vq_quantlist__44c2_s_p2_0[] = {
  113888. 2,
  113889. 1,
  113890. 3,
  113891. 0,
  113892. 4,
  113893. };
  113894. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113895. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113896. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113897. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113898. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113899. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113904. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113905. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  113906. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  113907. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113910. 0, 0, 0, 0, 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, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  113913. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  113914. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  113915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113918. 0, 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. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  113921. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  113922. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  113923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113934. 0,
  113935. };
  113936. static float _vq_quantthresh__44c2_s_p2_0[] = {
  113937. -1.5, -0.5, 0.5, 1.5,
  113938. };
  113939. static long _vq_quantmap__44c2_s_p2_0[] = {
  113940. 3, 1, 0, 2, 4,
  113941. };
  113942. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  113943. _vq_quantthresh__44c2_s_p2_0,
  113944. _vq_quantmap__44c2_s_p2_0,
  113945. 5,
  113946. 5
  113947. };
  113948. static static_codebook _44c2_s_p2_0 = {
  113949. 4, 625,
  113950. _vq_lengthlist__44c2_s_p2_0,
  113951. 1, -533725184, 1611661312, 3, 0,
  113952. _vq_quantlist__44c2_s_p2_0,
  113953. NULL,
  113954. &_vq_auxt__44c2_s_p2_0,
  113955. NULL,
  113956. 0
  113957. };
  113958. static long _vq_quantlist__44c2_s_p3_0[] = {
  113959. 2,
  113960. 1,
  113961. 3,
  113962. 0,
  113963. 4,
  113964. };
  113965. static long _vq_lengthlist__44c2_s_p3_0[] = {
  113966. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113969. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  113971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113972. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  114006. };
  114007. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114008. -1.5, -0.5, 0.5, 1.5,
  114009. };
  114010. static long _vq_quantmap__44c2_s_p3_0[] = {
  114011. 3, 1, 0, 2, 4,
  114012. };
  114013. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114014. _vq_quantthresh__44c2_s_p3_0,
  114015. _vq_quantmap__44c2_s_p3_0,
  114016. 5,
  114017. 5
  114018. };
  114019. static static_codebook _44c2_s_p3_0 = {
  114020. 4, 625,
  114021. _vq_lengthlist__44c2_s_p3_0,
  114022. 1, -533725184, 1611661312, 3, 0,
  114023. _vq_quantlist__44c2_s_p3_0,
  114024. NULL,
  114025. &_vq_auxt__44c2_s_p3_0,
  114026. NULL,
  114027. 0
  114028. };
  114029. static long _vq_quantlist__44c2_s_p4_0[] = {
  114030. 4,
  114031. 3,
  114032. 5,
  114033. 2,
  114034. 6,
  114035. 1,
  114036. 7,
  114037. 0,
  114038. 8,
  114039. };
  114040. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114041. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114042. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114043. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114044. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114045. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114046. 0,
  114047. };
  114048. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114049. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114050. };
  114051. static long _vq_quantmap__44c2_s_p4_0[] = {
  114052. 7, 5, 3, 1, 0, 2, 4, 6,
  114053. 8,
  114054. };
  114055. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114056. _vq_quantthresh__44c2_s_p4_0,
  114057. _vq_quantmap__44c2_s_p4_0,
  114058. 9,
  114059. 9
  114060. };
  114061. static static_codebook _44c2_s_p4_0 = {
  114062. 2, 81,
  114063. _vq_lengthlist__44c2_s_p4_0,
  114064. 1, -531628032, 1611661312, 4, 0,
  114065. _vq_quantlist__44c2_s_p4_0,
  114066. NULL,
  114067. &_vq_auxt__44c2_s_p4_0,
  114068. NULL,
  114069. 0
  114070. };
  114071. static long _vq_quantlist__44c2_s_p5_0[] = {
  114072. 4,
  114073. 3,
  114074. 5,
  114075. 2,
  114076. 6,
  114077. 1,
  114078. 7,
  114079. 0,
  114080. 8,
  114081. };
  114082. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114083. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114084. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114085. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114086. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114087. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114088. 11,
  114089. };
  114090. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114091. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114092. };
  114093. static long _vq_quantmap__44c2_s_p5_0[] = {
  114094. 7, 5, 3, 1, 0, 2, 4, 6,
  114095. 8,
  114096. };
  114097. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114098. _vq_quantthresh__44c2_s_p5_0,
  114099. _vq_quantmap__44c2_s_p5_0,
  114100. 9,
  114101. 9
  114102. };
  114103. static static_codebook _44c2_s_p5_0 = {
  114104. 2, 81,
  114105. _vq_lengthlist__44c2_s_p5_0,
  114106. 1, -531628032, 1611661312, 4, 0,
  114107. _vq_quantlist__44c2_s_p5_0,
  114108. NULL,
  114109. &_vq_auxt__44c2_s_p5_0,
  114110. NULL,
  114111. 0
  114112. };
  114113. static long _vq_quantlist__44c2_s_p6_0[] = {
  114114. 8,
  114115. 7,
  114116. 9,
  114117. 6,
  114118. 10,
  114119. 5,
  114120. 11,
  114121. 4,
  114122. 12,
  114123. 3,
  114124. 13,
  114125. 2,
  114126. 14,
  114127. 1,
  114128. 15,
  114129. 0,
  114130. 16,
  114131. };
  114132. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114133. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114134. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114135. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114136. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114137. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114138. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114139. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114140. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114141. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114142. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114143. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114144. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114145. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114146. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114147. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114148. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114149. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114150. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114151. 14,
  114152. };
  114153. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114154. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114155. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114156. };
  114157. static long _vq_quantmap__44c2_s_p6_0[] = {
  114158. 15, 13, 11, 9, 7, 5, 3, 1,
  114159. 0, 2, 4, 6, 8, 10, 12, 14,
  114160. 16,
  114161. };
  114162. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114163. _vq_quantthresh__44c2_s_p6_0,
  114164. _vq_quantmap__44c2_s_p6_0,
  114165. 17,
  114166. 17
  114167. };
  114168. static static_codebook _44c2_s_p6_0 = {
  114169. 2, 289,
  114170. _vq_lengthlist__44c2_s_p6_0,
  114171. 1, -529530880, 1611661312, 5, 0,
  114172. _vq_quantlist__44c2_s_p6_0,
  114173. NULL,
  114174. &_vq_auxt__44c2_s_p6_0,
  114175. NULL,
  114176. 0
  114177. };
  114178. static long _vq_quantlist__44c2_s_p7_0[] = {
  114179. 1,
  114180. 0,
  114181. 2,
  114182. };
  114183. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114184. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114185. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114186. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114187. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114188. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114189. 11,
  114190. };
  114191. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114192. -5.5, 5.5,
  114193. };
  114194. static long _vq_quantmap__44c2_s_p7_0[] = {
  114195. 1, 0, 2,
  114196. };
  114197. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114198. _vq_quantthresh__44c2_s_p7_0,
  114199. _vq_quantmap__44c2_s_p7_0,
  114200. 3,
  114201. 3
  114202. };
  114203. static static_codebook _44c2_s_p7_0 = {
  114204. 4, 81,
  114205. _vq_lengthlist__44c2_s_p7_0,
  114206. 1, -529137664, 1618345984, 2, 0,
  114207. _vq_quantlist__44c2_s_p7_0,
  114208. NULL,
  114209. &_vq_auxt__44c2_s_p7_0,
  114210. NULL,
  114211. 0
  114212. };
  114213. static long _vq_quantlist__44c2_s_p7_1[] = {
  114214. 5,
  114215. 4,
  114216. 6,
  114217. 3,
  114218. 7,
  114219. 2,
  114220. 8,
  114221. 1,
  114222. 9,
  114223. 0,
  114224. 10,
  114225. };
  114226. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114227. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114228. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114229. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114230. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114231. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114232. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114233. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114234. 10,10,10, 8, 8, 8, 8, 8, 8,
  114235. };
  114236. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114237. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114238. 3.5, 4.5,
  114239. };
  114240. static long _vq_quantmap__44c2_s_p7_1[] = {
  114241. 9, 7, 5, 3, 1, 0, 2, 4,
  114242. 6, 8, 10,
  114243. };
  114244. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114245. _vq_quantthresh__44c2_s_p7_1,
  114246. _vq_quantmap__44c2_s_p7_1,
  114247. 11,
  114248. 11
  114249. };
  114250. static static_codebook _44c2_s_p7_1 = {
  114251. 2, 121,
  114252. _vq_lengthlist__44c2_s_p7_1,
  114253. 1, -531365888, 1611661312, 4, 0,
  114254. _vq_quantlist__44c2_s_p7_1,
  114255. NULL,
  114256. &_vq_auxt__44c2_s_p7_1,
  114257. NULL,
  114258. 0
  114259. };
  114260. static long _vq_quantlist__44c2_s_p8_0[] = {
  114261. 6,
  114262. 5,
  114263. 7,
  114264. 4,
  114265. 8,
  114266. 3,
  114267. 9,
  114268. 2,
  114269. 10,
  114270. 1,
  114271. 11,
  114272. 0,
  114273. 12,
  114274. };
  114275. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114276. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114277. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114278. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114279. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114280. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114281. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114282. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114283. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114284. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114285. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114286. 0,12,12,12,12,13,12,14,14,
  114287. };
  114288. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114289. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114290. 12.5, 17.5, 22.5, 27.5,
  114291. };
  114292. static long _vq_quantmap__44c2_s_p8_0[] = {
  114293. 11, 9, 7, 5, 3, 1, 0, 2,
  114294. 4, 6, 8, 10, 12,
  114295. };
  114296. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114297. _vq_quantthresh__44c2_s_p8_0,
  114298. _vq_quantmap__44c2_s_p8_0,
  114299. 13,
  114300. 13
  114301. };
  114302. static static_codebook _44c2_s_p8_0 = {
  114303. 2, 169,
  114304. _vq_lengthlist__44c2_s_p8_0,
  114305. 1, -526516224, 1616117760, 4, 0,
  114306. _vq_quantlist__44c2_s_p8_0,
  114307. NULL,
  114308. &_vq_auxt__44c2_s_p8_0,
  114309. NULL,
  114310. 0
  114311. };
  114312. static long _vq_quantlist__44c2_s_p8_1[] = {
  114313. 2,
  114314. 1,
  114315. 3,
  114316. 0,
  114317. 4,
  114318. };
  114319. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114320. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114321. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114322. };
  114323. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114324. -1.5, -0.5, 0.5, 1.5,
  114325. };
  114326. static long _vq_quantmap__44c2_s_p8_1[] = {
  114327. 3, 1, 0, 2, 4,
  114328. };
  114329. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114330. _vq_quantthresh__44c2_s_p8_1,
  114331. _vq_quantmap__44c2_s_p8_1,
  114332. 5,
  114333. 5
  114334. };
  114335. static static_codebook _44c2_s_p8_1 = {
  114336. 2, 25,
  114337. _vq_lengthlist__44c2_s_p8_1,
  114338. 1, -533725184, 1611661312, 3, 0,
  114339. _vq_quantlist__44c2_s_p8_1,
  114340. NULL,
  114341. &_vq_auxt__44c2_s_p8_1,
  114342. NULL,
  114343. 0
  114344. };
  114345. static long _vq_quantlist__44c2_s_p9_0[] = {
  114346. 6,
  114347. 5,
  114348. 7,
  114349. 4,
  114350. 8,
  114351. 3,
  114352. 9,
  114353. 2,
  114354. 10,
  114355. 1,
  114356. 11,
  114357. 0,
  114358. 12,
  114359. };
  114360. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114361. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114362. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114363. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114364. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114365. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114366. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114367. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114368. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114369. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114370. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114371. 11,11,11,11,11,11,11,11,11,
  114372. };
  114373. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114374. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114375. 552.5, 773.5, 994.5, 1215.5,
  114376. };
  114377. static long _vq_quantmap__44c2_s_p9_0[] = {
  114378. 11, 9, 7, 5, 3, 1, 0, 2,
  114379. 4, 6, 8, 10, 12,
  114380. };
  114381. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114382. _vq_quantthresh__44c2_s_p9_0,
  114383. _vq_quantmap__44c2_s_p9_0,
  114384. 13,
  114385. 13
  114386. };
  114387. static static_codebook _44c2_s_p9_0 = {
  114388. 2, 169,
  114389. _vq_lengthlist__44c2_s_p9_0,
  114390. 1, -514541568, 1627103232, 4, 0,
  114391. _vq_quantlist__44c2_s_p9_0,
  114392. NULL,
  114393. &_vq_auxt__44c2_s_p9_0,
  114394. NULL,
  114395. 0
  114396. };
  114397. static long _vq_quantlist__44c2_s_p9_1[] = {
  114398. 6,
  114399. 5,
  114400. 7,
  114401. 4,
  114402. 8,
  114403. 3,
  114404. 9,
  114405. 2,
  114406. 10,
  114407. 1,
  114408. 11,
  114409. 0,
  114410. 12,
  114411. };
  114412. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114413. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114414. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114415. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114416. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114417. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114418. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114419. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114420. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114421. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114422. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114423. 17,13,12,12,10,13,11,14,14,
  114424. };
  114425. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114426. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114427. 42.5, 59.5, 76.5, 93.5,
  114428. };
  114429. static long _vq_quantmap__44c2_s_p9_1[] = {
  114430. 11, 9, 7, 5, 3, 1, 0, 2,
  114431. 4, 6, 8, 10, 12,
  114432. };
  114433. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114434. _vq_quantthresh__44c2_s_p9_1,
  114435. _vq_quantmap__44c2_s_p9_1,
  114436. 13,
  114437. 13
  114438. };
  114439. static static_codebook _44c2_s_p9_1 = {
  114440. 2, 169,
  114441. _vq_lengthlist__44c2_s_p9_1,
  114442. 1, -522616832, 1620115456, 4, 0,
  114443. _vq_quantlist__44c2_s_p9_1,
  114444. NULL,
  114445. &_vq_auxt__44c2_s_p9_1,
  114446. NULL,
  114447. 0
  114448. };
  114449. static long _vq_quantlist__44c2_s_p9_2[] = {
  114450. 8,
  114451. 7,
  114452. 9,
  114453. 6,
  114454. 10,
  114455. 5,
  114456. 11,
  114457. 4,
  114458. 12,
  114459. 3,
  114460. 13,
  114461. 2,
  114462. 14,
  114463. 1,
  114464. 15,
  114465. 0,
  114466. 16,
  114467. };
  114468. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114469. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114470. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114471. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114472. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114473. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114474. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114475. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114476. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114477. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114478. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114479. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114480. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114481. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114482. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114483. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114484. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114485. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114486. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114487. 10,
  114488. };
  114489. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114490. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114491. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114492. };
  114493. static long _vq_quantmap__44c2_s_p9_2[] = {
  114494. 15, 13, 11, 9, 7, 5, 3, 1,
  114495. 0, 2, 4, 6, 8, 10, 12, 14,
  114496. 16,
  114497. };
  114498. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114499. _vq_quantthresh__44c2_s_p9_2,
  114500. _vq_quantmap__44c2_s_p9_2,
  114501. 17,
  114502. 17
  114503. };
  114504. static static_codebook _44c2_s_p9_2 = {
  114505. 2, 289,
  114506. _vq_lengthlist__44c2_s_p9_2,
  114507. 1, -529530880, 1611661312, 5, 0,
  114508. _vq_quantlist__44c2_s_p9_2,
  114509. NULL,
  114510. &_vq_auxt__44c2_s_p9_2,
  114511. NULL,
  114512. 0
  114513. };
  114514. static long _huff_lengthlist__44c2_s_short[] = {
  114515. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114516. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114517. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114518. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114519. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114520. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114521. 6, 8, 9,12,
  114522. };
  114523. static static_codebook _huff_book__44c2_s_short = {
  114524. 2, 100,
  114525. _huff_lengthlist__44c2_s_short,
  114526. 0, 0, 0, 0, 0,
  114527. NULL,
  114528. NULL,
  114529. NULL,
  114530. NULL,
  114531. 0
  114532. };
  114533. static long _huff_lengthlist__44c3_s_long[] = {
  114534. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114535. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114536. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114537. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114538. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114539. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114540. 9, 8, 8, 8,
  114541. };
  114542. static static_codebook _huff_book__44c3_s_long = {
  114543. 2, 100,
  114544. _huff_lengthlist__44c3_s_long,
  114545. 0, 0, 0, 0, 0,
  114546. NULL,
  114547. NULL,
  114548. NULL,
  114549. NULL,
  114550. 0
  114551. };
  114552. static long _vq_quantlist__44c3_s_p1_0[] = {
  114553. 1,
  114554. 0,
  114555. 2,
  114556. };
  114557. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114558. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114559. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114563. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114564. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114568. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114569. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114604. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114609. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114614. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114649. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114650. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114655. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114660. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  114661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114866. 0, 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,
  114969. };
  114970. static float _vq_quantthresh__44c3_s_p1_0[] = {
  114971. -0.5, 0.5,
  114972. };
  114973. static long _vq_quantmap__44c3_s_p1_0[] = {
  114974. 1, 0, 2,
  114975. };
  114976. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  114977. _vq_quantthresh__44c3_s_p1_0,
  114978. _vq_quantmap__44c3_s_p1_0,
  114979. 3,
  114980. 3
  114981. };
  114982. static static_codebook _44c3_s_p1_0 = {
  114983. 8, 6561,
  114984. _vq_lengthlist__44c3_s_p1_0,
  114985. 1, -535822336, 1611661312, 2, 0,
  114986. _vq_quantlist__44c3_s_p1_0,
  114987. NULL,
  114988. &_vq_auxt__44c3_s_p1_0,
  114989. NULL,
  114990. 0
  114991. };
  114992. static long _vq_quantlist__44c3_s_p2_0[] = {
  114993. 2,
  114994. 1,
  114995. 3,
  114996. 0,
  114997. 4,
  114998. };
  114999. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115000. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115001. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115002. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115003. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115004. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115009. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115010. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115011. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115012. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115015. 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115018. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115019. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115023. 0, 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. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115026. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115027. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115039. 0,
  115040. };
  115041. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115042. -1.5, -0.5, 0.5, 1.5,
  115043. };
  115044. static long _vq_quantmap__44c3_s_p2_0[] = {
  115045. 3, 1, 0, 2, 4,
  115046. };
  115047. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115048. _vq_quantthresh__44c3_s_p2_0,
  115049. _vq_quantmap__44c3_s_p2_0,
  115050. 5,
  115051. 5
  115052. };
  115053. static static_codebook _44c3_s_p2_0 = {
  115054. 4, 625,
  115055. _vq_lengthlist__44c3_s_p2_0,
  115056. 1, -533725184, 1611661312, 3, 0,
  115057. _vq_quantlist__44c3_s_p2_0,
  115058. NULL,
  115059. &_vq_auxt__44c3_s_p2_0,
  115060. NULL,
  115061. 0
  115062. };
  115063. static long _vq_quantlist__44c3_s_p3_0[] = {
  115064. 2,
  115065. 1,
  115066. 3,
  115067. 0,
  115068. 4,
  115069. };
  115070. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115071. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115074. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115077. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  115111. };
  115112. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115113. -1.5, -0.5, 0.5, 1.5,
  115114. };
  115115. static long _vq_quantmap__44c3_s_p3_0[] = {
  115116. 3, 1, 0, 2, 4,
  115117. };
  115118. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115119. _vq_quantthresh__44c3_s_p3_0,
  115120. _vq_quantmap__44c3_s_p3_0,
  115121. 5,
  115122. 5
  115123. };
  115124. static static_codebook _44c3_s_p3_0 = {
  115125. 4, 625,
  115126. _vq_lengthlist__44c3_s_p3_0,
  115127. 1, -533725184, 1611661312, 3, 0,
  115128. _vq_quantlist__44c3_s_p3_0,
  115129. NULL,
  115130. &_vq_auxt__44c3_s_p3_0,
  115131. NULL,
  115132. 0
  115133. };
  115134. static long _vq_quantlist__44c3_s_p4_0[] = {
  115135. 4,
  115136. 3,
  115137. 5,
  115138. 2,
  115139. 6,
  115140. 1,
  115141. 7,
  115142. 0,
  115143. 8,
  115144. };
  115145. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115146. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115147. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115148. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115149. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115150. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115151. 0,
  115152. };
  115153. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115154. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115155. };
  115156. static long _vq_quantmap__44c3_s_p4_0[] = {
  115157. 7, 5, 3, 1, 0, 2, 4, 6,
  115158. 8,
  115159. };
  115160. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115161. _vq_quantthresh__44c3_s_p4_0,
  115162. _vq_quantmap__44c3_s_p4_0,
  115163. 9,
  115164. 9
  115165. };
  115166. static static_codebook _44c3_s_p4_0 = {
  115167. 2, 81,
  115168. _vq_lengthlist__44c3_s_p4_0,
  115169. 1, -531628032, 1611661312, 4, 0,
  115170. _vq_quantlist__44c3_s_p4_0,
  115171. NULL,
  115172. &_vq_auxt__44c3_s_p4_0,
  115173. NULL,
  115174. 0
  115175. };
  115176. static long _vq_quantlist__44c3_s_p5_0[] = {
  115177. 4,
  115178. 3,
  115179. 5,
  115180. 2,
  115181. 6,
  115182. 1,
  115183. 7,
  115184. 0,
  115185. 8,
  115186. };
  115187. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115188. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115189. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115190. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115191. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115192. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115193. 11,
  115194. };
  115195. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115196. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115197. };
  115198. static long _vq_quantmap__44c3_s_p5_0[] = {
  115199. 7, 5, 3, 1, 0, 2, 4, 6,
  115200. 8,
  115201. };
  115202. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115203. _vq_quantthresh__44c3_s_p5_0,
  115204. _vq_quantmap__44c3_s_p5_0,
  115205. 9,
  115206. 9
  115207. };
  115208. static static_codebook _44c3_s_p5_0 = {
  115209. 2, 81,
  115210. _vq_lengthlist__44c3_s_p5_0,
  115211. 1, -531628032, 1611661312, 4, 0,
  115212. _vq_quantlist__44c3_s_p5_0,
  115213. NULL,
  115214. &_vq_auxt__44c3_s_p5_0,
  115215. NULL,
  115216. 0
  115217. };
  115218. static long _vq_quantlist__44c3_s_p6_0[] = {
  115219. 8,
  115220. 7,
  115221. 9,
  115222. 6,
  115223. 10,
  115224. 5,
  115225. 11,
  115226. 4,
  115227. 12,
  115228. 3,
  115229. 13,
  115230. 2,
  115231. 14,
  115232. 1,
  115233. 15,
  115234. 0,
  115235. 16,
  115236. };
  115237. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115238. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115239. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115240. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115241. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115242. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115243. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115244. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115245. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115246. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115247. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115248. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115249. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115250. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115251. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115252. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115253. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115254. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115255. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115256. 13,
  115257. };
  115258. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115259. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115260. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115261. };
  115262. static long _vq_quantmap__44c3_s_p6_0[] = {
  115263. 15, 13, 11, 9, 7, 5, 3, 1,
  115264. 0, 2, 4, 6, 8, 10, 12, 14,
  115265. 16,
  115266. };
  115267. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115268. _vq_quantthresh__44c3_s_p6_0,
  115269. _vq_quantmap__44c3_s_p6_0,
  115270. 17,
  115271. 17
  115272. };
  115273. static static_codebook _44c3_s_p6_0 = {
  115274. 2, 289,
  115275. _vq_lengthlist__44c3_s_p6_0,
  115276. 1, -529530880, 1611661312, 5, 0,
  115277. _vq_quantlist__44c3_s_p6_0,
  115278. NULL,
  115279. &_vq_auxt__44c3_s_p6_0,
  115280. NULL,
  115281. 0
  115282. };
  115283. static long _vq_quantlist__44c3_s_p7_0[] = {
  115284. 1,
  115285. 0,
  115286. 2,
  115287. };
  115288. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115289. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115290. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115291. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115292. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115293. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115294. 10,
  115295. };
  115296. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115297. -5.5, 5.5,
  115298. };
  115299. static long _vq_quantmap__44c3_s_p7_0[] = {
  115300. 1, 0, 2,
  115301. };
  115302. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115303. _vq_quantthresh__44c3_s_p7_0,
  115304. _vq_quantmap__44c3_s_p7_0,
  115305. 3,
  115306. 3
  115307. };
  115308. static static_codebook _44c3_s_p7_0 = {
  115309. 4, 81,
  115310. _vq_lengthlist__44c3_s_p7_0,
  115311. 1, -529137664, 1618345984, 2, 0,
  115312. _vq_quantlist__44c3_s_p7_0,
  115313. NULL,
  115314. &_vq_auxt__44c3_s_p7_0,
  115315. NULL,
  115316. 0
  115317. };
  115318. static long _vq_quantlist__44c3_s_p7_1[] = {
  115319. 5,
  115320. 4,
  115321. 6,
  115322. 3,
  115323. 7,
  115324. 2,
  115325. 8,
  115326. 1,
  115327. 9,
  115328. 0,
  115329. 10,
  115330. };
  115331. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115332. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115333. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115334. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115335. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115336. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115337. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115338. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115339. 10,10,10, 8, 8, 8, 8, 8, 8,
  115340. };
  115341. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115342. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115343. 3.5, 4.5,
  115344. };
  115345. static long _vq_quantmap__44c3_s_p7_1[] = {
  115346. 9, 7, 5, 3, 1, 0, 2, 4,
  115347. 6, 8, 10,
  115348. };
  115349. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115350. _vq_quantthresh__44c3_s_p7_1,
  115351. _vq_quantmap__44c3_s_p7_1,
  115352. 11,
  115353. 11
  115354. };
  115355. static static_codebook _44c3_s_p7_1 = {
  115356. 2, 121,
  115357. _vq_lengthlist__44c3_s_p7_1,
  115358. 1, -531365888, 1611661312, 4, 0,
  115359. _vq_quantlist__44c3_s_p7_1,
  115360. NULL,
  115361. &_vq_auxt__44c3_s_p7_1,
  115362. NULL,
  115363. 0
  115364. };
  115365. static long _vq_quantlist__44c3_s_p8_0[] = {
  115366. 6,
  115367. 5,
  115368. 7,
  115369. 4,
  115370. 8,
  115371. 3,
  115372. 9,
  115373. 2,
  115374. 10,
  115375. 1,
  115376. 11,
  115377. 0,
  115378. 12,
  115379. };
  115380. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115381. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115382. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115383. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115384. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115385. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115386. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115387. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115388. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115389. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115390. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115391. 0,13,13,12,12,13,12,14,13,
  115392. };
  115393. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115394. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115395. 12.5, 17.5, 22.5, 27.5,
  115396. };
  115397. static long _vq_quantmap__44c3_s_p8_0[] = {
  115398. 11, 9, 7, 5, 3, 1, 0, 2,
  115399. 4, 6, 8, 10, 12,
  115400. };
  115401. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115402. _vq_quantthresh__44c3_s_p8_0,
  115403. _vq_quantmap__44c3_s_p8_0,
  115404. 13,
  115405. 13
  115406. };
  115407. static static_codebook _44c3_s_p8_0 = {
  115408. 2, 169,
  115409. _vq_lengthlist__44c3_s_p8_0,
  115410. 1, -526516224, 1616117760, 4, 0,
  115411. _vq_quantlist__44c3_s_p8_0,
  115412. NULL,
  115413. &_vq_auxt__44c3_s_p8_0,
  115414. NULL,
  115415. 0
  115416. };
  115417. static long _vq_quantlist__44c3_s_p8_1[] = {
  115418. 2,
  115419. 1,
  115420. 3,
  115421. 0,
  115422. 4,
  115423. };
  115424. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115425. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115426. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115427. };
  115428. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115429. -1.5, -0.5, 0.5, 1.5,
  115430. };
  115431. static long _vq_quantmap__44c3_s_p8_1[] = {
  115432. 3, 1, 0, 2, 4,
  115433. };
  115434. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115435. _vq_quantthresh__44c3_s_p8_1,
  115436. _vq_quantmap__44c3_s_p8_1,
  115437. 5,
  115438. 5
  115439. };
  115440. static static_codebook _44c3_s_p8_1 = {
  115441. 2, 25,
  115442. _vq_lengthlist__44c3_s_p8_1,
  115443. 1, -533725184, 1611661312, 3, 0,
  115444. _vq_quantlist__44c3_s_p8_1,
  115445. NULL,
  115446. &_vq_auxt__44c3_s_p8_1,
  115447. NULL,
  115448. 0
  115449. };
  115450. static long _vq_quantlist__44c3_s_p9_0[] = {
  115451. 6,
  115452. 5,
  115453. 7,
  115454. 4,
  115455. 8,
  115456. 3,
  115457. 9,
  115458. 2,
  115459. 10,
  115460. 1,
  115461. 11,
  115462. 0,
  115463. 12,
  115464. };
  115465. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115466. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115467. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115468. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115469. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115470. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115471. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115472. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115473. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115474. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115475. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115476. 11,11,11,11,11,11,11,11,11,
  115477. };
  115478. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115479. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115480. 637.5, 892.5, 1147.5, 1402.5,
  115481. };
  115482. static long _vq_quantmap__44c3_s_p9_0[] = {
  115483. 11, 9, 7, 5, 3, 1, 0, 2,
  115484. 4, 6, 8, 10, 12,
  115485. };
  115486. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115487. _vq_quantthresh__44c3_s_p9_0,
  115488. _vq_quantmap__44c3_s_p9_0,
  115489. 13,
  115490. 13
  115491. };
  115492. static static_codebook _44c3_s_p9_0 = {
  115493. 2, 169,
  115494. _vq_lengthlist__44c3_s_p9_0,
  115495. 1, -514332672, 1627381760, 4, 0,
  115496. _vq_quantlist__44c3_s_p9_0,
  115497. NULL,
  115498. &_vq_auxt__44c3_s_p9_0,
  115499. NULL,
  115500. 0
  115501. };
  115502. static long _vq_quantlist__44c3_s_p9_1[] = {
  115503. 7,
  115504. 6,
  115505. 8,
  115506. 5,
  115507. 9,
  115508. 4,
  115509. 10,
  115510. 3,
  115511. 11,
  115512. 2,
  115513. 12,
  115514. 1,
  115515. 13,
  115516. 0,
  115517. 14,
  115518. };
  115519. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115520. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115521. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115522. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115523. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115524. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115525. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115526. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115527. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115528. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115529. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115530. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115531. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115532. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115533. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115534. 15,
  115535. };
  115536. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115537. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115538. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115539. };
  115540. static long _vq_quantmap__44c3_s_p9_1[] = {
  115541. 13, 11, 9, 7, 5, 3, 1, 0,
  115542. 2, 4, 6, 8, 10, 12, 14,
  115543. };
  115544. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115545. _vq_quantthresh__44c3_s_p9_1,
  115546. _vq_quantmap__44c3_s_p9_1,
  115547. 15,
  115548. 15
  115549. };
  115550. static static_codebook _44c3_s_p9_1 = {
  115551. 2, 225,
  115552. _vq_lengthlist__44c3_s_p9_1,
  115553. 1, -522338304, 1620115456, 4, 0,
  115554. _vq_quantlist__44c3_s_p9_1,
  115555. NULL,
  115556. &_vq_auxt__44c3_s_p9_1,
  115557. NULL,
  115558. 0
  115559. };
  115560. static long _vq_quantlist__44c3_s_p9_2[] = {
  115561. 8,
  115562. 7,
  115563. 9,
  115564. 6,
  115565. 10,
  115566. 5,
  115567. 11,
  115568. 4,
  115569. 12,
  115570. 3,
  115571. 13,
  115572. 2,
  115573. 14,
  115574. 1,
  115575. 15,
  115576. 0,
  115577. 16,
  115578. };
  115579. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115580. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115581. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115582. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115583. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115584. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115585. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115586. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115587. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115588. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115589. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115590. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115591. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115592. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115593. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115594. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115595. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115596. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115597. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115598. 10,
  115599. };
  115600. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115601. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115602. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115603. };
  115604. static long _vq_quantmap__44c3_s_p9_2[] = {
  115605. 15, 13, 11, 9, 7, 5, 3, 1,
  115606. 0, 2, 4, 6, 8, 10, 12, 14,
  115607. 16,
  115608. };
  115609. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115610. _vq_quantthresh__44c3_s_p9_2,
  115611. _vq_quantmap__44c3_s_p9_2,
  115612. 17,
  115613. 17
  115614. };
  115615. static static_codebook _44c3_s_p9_2 = {
  115616. 2, 289,
  115617. _vq_lengthlist__44c3_s_p9_2,
  115618. 1, -529530880, 1611661312, 5, 0,
  115619. _vq_quantlist__44c3_s_p9_2,
  115620. NULL,
  115621. &_vq_auxt__44c3_s_p9_2,
  115622. NULL,
  115623. 0
  115624. };
  115625. static long _huff_lengthlist__44c3_s_short[] = {
  115626. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115627. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115628. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115629. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115630. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115631. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115632. 6, 8, 9,11,
  115633. };
  115634. static static_codebook _huff_book__44c3_s_short = {
  115635. 2, 100,
  115636. _huff_lengthlist__44c3_s_short,
  115637. 0, 0, 0, 0, 0,
  115638. NULL,
  115639. NULL,
  115640. NULL,
  115641. NULL,
  115642. 0
  115643. };
  115644. static long _huff_lengthlist__44c4_s_long[] = {
  115645. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115646. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115647. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115648. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115649. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115650. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115651. 9, 8, 7, 7,
  115652. };
  115653. static static_codebook _huff_book__44c4_s_long = {
  115654. 2, 100,
  115655. _huff_lengthlist__44c4_s_long,
  115656. 0, 0, 0, 0, 0,
  115657. NULL,
  115658. NULL,
  115659. NULL,
  115660. NULL,
  115661. 0
  115662. };
  115663. static long _vq_quantlist__44c4_s_p1_0[] = {
  115664. 1,
  115665. 0,
  115666. 2,
  115667. };
  115668. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115669. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115670. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115674. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115675. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115679. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115680. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115715. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115720. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115725. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115760. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115761. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115766. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115771. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115977. 0, 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,
  116080. };
  116081. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116082. -0.5, 0.5,
  116083. };
  116084. static long _vq_quantmap__44c4_s_p1_0[] = {
  116085. 1, 0, 2,
  116086. };
  116087. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116088. _vq_quantthresh__44c4_s_p1_0,
  116089. _vq_quantmap__44c4_s_p1_0,
  116090. 3,
  116091. 3
  116092. };
  116093. static static_codebook _44c4_s_p1_0 = {
  116094. 8, 6561,
  116095. _vq_lengthlist__44c4_s_p1_0,
  116096. 1, -535822336, 1611661312, 2, 0,
  116097. _vq_quantlist__44c4_s_p1_0,
  116098. NULL,
  116099. &_vq_auxt__44c4_s_p1_0,
  116100. NULL,
  116101. 0
  116102. };
  116103. static long _vq_quantlist__44c4_s_p2_0[] = {
  116104. 2,
  116105. 1,
  116106. 3,
  116107. 0,
  116108. 4,
  116109. };
  116110. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116111. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116112. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116113. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116114. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116115. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116120. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116121. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116122. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116123. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116126. 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116129. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116130. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116134. 0, 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. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116137. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116138. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116150. 0,
  116151. };
  116152. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116153. -1.5, -0.5, 0.5, 1.5,
  116154. };
  116155. static long _vq_quantmap__44c4_s_p2_0[] = {
  116156. 3, 1, 0, 2, 4,
  116157. };
  116158. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116159. _vq_quantthresh__44c4_s_p2_0,
  116160. _vq_quantmap__44c4_s_p2_0,
  116161. 5,
  116162. 5
  116163. };
  116164. static static_codebook _44c4_s_p2_0 = {
  116165. 4, 625,
  116166. _vq_lengthlist__44c4_s_p2_0,
  116167. 1, -533725184, 1611661312, 3, 0,
  116168. _vq_quantlist__44c4_s_p2_0,
  116169. NULL,
  116170. &_vq_auxt__44c4_s_p2_0,
  116171. NULL,
  116172. 0
  116173. };
  116174. static long _vq_quantlist__44c4_s_p3_0[] = {
  116175. 2,
  116176. 1,
  116177. 3,
  116178. 0,
  116179. 4,
  116180. };
  116181. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116182. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116185. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116188. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  116222. };
  116223. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116224. -1.5, -0.5, 0.5, 1.5,
  116225. };
  116226. static long _vq_quantmap__44c4_s_p3_0[] = {
  116227. 3, 1, 0, 2, 4,
  116228. };
  116229. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116230. _vq_quantthresh__44c4_s_p3_0,
  116231. _vq_quantmap__44c4_s_p3_0,
  116232. 5,
  116233. 5
  116234. };
  116235. static static_codebook _44c4_s_p3_0 = {
  116236. 4, 625,
  116237. _vq_lengthlist__44c4_s_p3_0,
  116238. 1, -533725184, 1611661312, 3, 0,
  116239. _vq_quantlist__44c4_s_p3_0,
  116240. NULL,
  116241. &_vq_auxt__44c4_s_p3_0,
  116242. NULL,
  116243. 0
  116244. };
  116245. static long _vq_quantlist__44c4_s_p4_0[] = {
  116246. 4,
  116247. 3,
  116248. 5,
  116249. 2,
  116250. 6,
  116251. 1,
  116252. 7,
  116253. 0,
  116254. 8,
  116255. };
  116256. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116257. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116258. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116259. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116260. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116261. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116262. 0,
  116263. };
  116264. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116265. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116266. };
  116267. static long _vq_quantmap__44c4_s_p4_0[] = {
  116268. 7, 5, 3, 1, 0, 2, 4, 6,
  116269. 8,
  116270. };
  116271. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116272. _vq_quantthresh__44c4_s_p4_0,
  116273. _vq_quantmap__44c4_s_p4_0,
  116274. 9,
  116275. 9
  116276. };
  116277. static static_codebook _44c4_s_p4_0 = {
  116278. 2, 81,
  116279. _vq_lengthlist__44c4_s_p4_0,
  116280. 1, -531628032, 1611661312, 4, 0,
  116281. _vq_quantlist__44c4_s_p4_0,
  116282. NULL,
  116283. &_vq_auxt__44c4_s_p4_0,
  116284. NULL,
  116285. 0
  116286. };
  116287. static long _vq_quantlist__44c4_s_p5_0[] = {
  116288. 4,
  116289. 3,
  116290. 5,
  116291. 2,
  116292. 6,
  116293. 1,
  116294. 7,
  116295. 0,
  116296. 8,
  116297. };
  116298. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116299. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116300. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116301. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116302. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116303. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116304. 10,
  116305. };
  116306. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116307. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116308. };
  116309. static long _vq_quantmap__44c4_s_p5_0[] = {
  116310. 7, 5, 3, 1, 0, 2, 4, 6,
  116311. 8,
  116312. };
  116313. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116314. _vq_quantthresh__44c4_s_p5_0,
  116315. _vq_quantmap__44c4_s_p5_0,
  116316. 9,
  116317. 9
  116318. };
  116319. static static_codebook _44c4_s_p5_0 = {
  116320. 2, 81,
  116321. _vq_lengthlist__44c4_s_p5_0,
  116322. 1, -531628032, 1611661312, 4, 0,
  116323. _vq_quantlist__44c4_s_p5_0,
  116324. NULL,
  116325. &_vq_auxt__44c4_s_p5_0,
  116326. NULL,
  116327. 0
  116328. };
  116329. static long _vq_quantlist__44c4_s_p6_0[] = {
  116330. 8,
  116331. 7,
  116332. 9,
  116333. 6,
  116334. 10,
  116335. 5,
  116336. 11,
  116337. 4,
  116338. 12,
  116339. 3,
  116340. 13,
  116341. 2,
  116342. 14,
  116343. 1,
  116344. 15,
  116345. 0,
  116346. 16,
  116347. };
  116348. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116349. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116350. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116351. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116352. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116353. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116354. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116355. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116356. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116357. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116358. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116359. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116360. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116361. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116362. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116363. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116364. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116365. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116366. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116367. 13,
  116368. };
  116369. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116370. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116371. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116372. };
  116373. static long _vq_quantmap__44c4_s_p6_0[] = {
  116374. 15, 13, 11, 9, 7, 5, 3, 1,
  116375. 0, 2, 4, 6, 8, 10, 12, 14,
  116376. 16,
  116377. };
  116378. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116379. _vq_quantthresh__44c4_s_p6_0,
  116380. _vq_quantmap__44c4_s_p6_0,
  116381. 17,
  116382. 17
  116383. };
  116384. static static_codebook _44c4_s_p6_0 = {
  116385. 2, 289,
  116386. _vq_lengthlist__44c4_s_p6_0,
  116387. 1, -529530880, 1611661312, 5, 0,
  116388. _vq_quantlist__44c4_s_p6_0,
  116389. NULL,
  116390. &_vq_auxt__44c4_s_p6_0,
  116391. NULL,
  116392. 0
  116393. };
  116394. static long _vq_quantlist__44c4_s_p7_0[] = {
  116395. 1,
  116396. 0,
  116397. 2,
  116398. };
  116399. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116400. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116401. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116402. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116403. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116404. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116405. 10,
  116406. };
  116407. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116408. -5.5, 5.5,
  116409. };
  116410. static long _vq_quantmap__44c4_s_p7_0[] = {
  116411. 1, 0, 2,
  116412. };
  116413. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116414. _vq_quantthresh__44c4_s_p7_0,
  116415. _vq_quantmap__44c4_s_p7_0,
  116416. 3,
  116417. 3
  116418. };
  116419. static static_codebook _44c4_s_p7_0 = {
  116420. 4, 81,
  116421. _vq_lengthlist__44c4_s_p7_0,
  116422. 1, -529137664, 1618345984, 2, 0,
  116423. _vq_quantlist__44c4_s_p7_0,
  116424. NULL,
  116425. &_vq_auxt__44c4_s_p7_0,
  116426. NULL,
  116427. 0
  116428. };
  116429. static long _vq_quantlist__44c4_s_p7_1[] = {
  116430. 5,
  116431. 4,
  116432. 6,
  116433. 3,
  116434. 7,
  116435. 2,
  116436. 8,
  116437. 1,
  116438. 9,
  116439. 0,
  116440. 10,
  116441. };
  116442. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116443. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116444. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116445. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116446. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116447. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116448. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116449. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116450. 10,10,10, 8, 8, 8, 8, 9, 9,
  116451. };
  116452. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116453. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116454. 3.5, 4.5,
  116455. };
  116456. static long _vq_quantmap__44c4_s_p7_1[] = {
  116457. 9, 7, 5, 3, 1, 0, 2, 4,
  116458. 6, 8, 10,
  116459. };
  116460. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116461. _vq_quantthresh__44c4_s_p7_1,
  116462. _vq_quantmap__44c4_s_p7_1,
  116463. 11,
  116464. 11
  116465. };
  116466. static static_codebook _44c4_s_p7_1 = {
  116467. 2, 121,
  116468. _vq_lengthlist__44c4_s_p7_1,
  116469. 1, -531365888, 1611661312, 4, 0,
  116470. _vq_quantlist__44c4_s_p7_1,
  116471. NULL,
  116472. &_vq_auxt__44c4_s_p7_1,
  116473. NULL,
  116474. 0
  116475. };
  116476. static long _vq_quantlist__44c4_s_p8_0[] = {
  116477. 6,
  116478. 5,
  116479. 7,
  116480. 4,
  116481. 8,
  116482. 3,
  116483. 9,
  116484. 2,
  116485. 10,
  116486. 1,
  116487. 11,
  116488. 0,
  116489. 12,
  116490. };
  116491. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116492. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116493. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116494. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116495. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116496. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116497. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116498. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116499. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116500. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116501. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116502. 0,13,12,12,12,12,12,13,13,
  116503. };
  116504. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116505. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116506. 12.5, 17.5, 22.5, 27.5,
  116507. };
  116508. static long _vq_quantmap__44c4_s_p8_0[] = {
  116509. 11, 9, 7, 5, 3, 1, 0, 2,
  116510. 4, 6, 8, 10, 12,
  116511. };
  116512. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116513. _vq_quantthresh__44c4_s_p8_0,
  116514. _vq_quantmap__44c4_s_p8_0,
  116515. 13,
  116516. 13
  116517. };
  116518. static static_codebook _44c4_s_p8_0 = {
  116519. 2, 169,
  116520. _vq_lengthlist__44c4_s_p8_0,
  116521. 1, -526516224, 1616117760, 4, 0,
  116522. _vq_quantlist__44c4_s_p8_0,
  116523. NULL,
  116524. &_vq_auxt__44c4_s_p8_0,
  116525. NULL,
  116526. 0
  116527. };
  116528. static long _vq_quantlist__44c4_s_p8_1[] = {
  116529. 2,
  116530. 1,
  116531. 3,
  116532. 0,
  116533. 4,
  116534. };
  116535. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116536. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116537. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116538. };
  116539. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116540. -1.5, -0.5, 0.5, 1.5,
  116541. };
  116542. static long _vq_quantmap__44c4_s_p8_1[] = {
  116543. 3, 1, 0, 2, 4,
  116544. };
  116545. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116546. _vq_quantthresh__44c4_s_p8_1,
  116547. _vq_quantmap__44c4_s_p8_1,
  116548. 5,
  116549. 5
  116550. };
  116551. static static_codebook _44c4_s_p8_1 = {
  116552. 2, 25,
  116553. _vq_lengthlist__44c4_s_p8_1,
  116554. 1, -533725184, 1611661312, 3, 0,
  116555. _vq_quantlist__44c4_s_p8_1,
  116556. NULL,
  116557. &_vq_auxt__44c4_s_p8_1,
  116558. NULL,
  116559. 0
  116560. };
  116561. static long _vq_quantlist__44c4_s_p9_0[] = {
  116562. 6,
  116563. 5,
  116564. 7,
  116565. 4,
  116566. 8,
  116567. 3,
  116568. 9,
  116569. 2,
  116570. 10,
  116571. 1,
  116572. 11,
  116573. 0,
  116574. 12,
  116575. };
  116576. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116577. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116578. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116579. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116580. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116581. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116582. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116583. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116584. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116585. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116586. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116587. 12,12,12,12,12,12,12,12,12,
  116588. };
  116589. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116590. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116591. 787.5, 1102.5, 1417.5, 1732.5,
  116592. };
  116593. static long _vq_quantmap__44c4_s_p9_0[] = {
  116594. 11, 9, 7, 5, 3, 1, 0, 2,
  116595. 4, 6, 8, 10, 12,
  116596. };
  116597. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116598. _vq_quantthresh__44c4_s_p9_0,
  116599. _vq_quantmap__44c4_s_p9_0,
  116600. 13,
  116601. 13
  116602. };
  116603. static static_codebook _44c4_s_p9_0 = {
  116604. 2, 169,
  116605. _vq_lengthlist__44c4_s_p9_0,
  116606. 1, -513964032, 1628680192, 4, 0,
  116607. _vq_quantlist__44c4_s_p9_0,
  116608. NULL,
  116609. &_vq_auxt__44c4_s_p9_0,
  116610. NULL,
  116611. 0
  116612. };
  116613. static long _vq_quantlist__44c4_s_p9_1[] = {
  116614. 7,
  116615. 6,
  116616. 8,
  116617. 5,
  116618. 9,
  116619. 4,
  116620. 10,
  116621. 3,
  116622. 11,
  116623. 2,
  116624. 12,
  116625. 1,
  116626. 13,
  116627. 0,
  116628. 14,
  116629. };
  116630. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116631. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116632. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116633. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116634. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116635. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116636. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116637. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116638. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116639. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116640. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116641. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116642. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116643. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116644. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116645. 15,
  116646. };
  116647. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116648. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116649. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116650. };
  116651. static long _vq_quantmap__44c4_s_p9_1[] = {
  116652. 13, 11, 9, 7, 5, 3, 1, 0,
  116653. 2, 4, 6, 8, 10, 12, 14,
  116654. };
  116655. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116656. _vq_quantthresh__44c4_s_p9_1,
  116657. _vq_quantmap__44c4_s_p9_1,
  116658. 15,
  116659. 15
  116660. };
  116661. static static_codebook _44c4_s_p9_1 = {
  116662. 2, 225,
  116663. _vq_lengthlist__44c4_s_p9_1,
  116664. 1, -520986624, 1620377600, 4, 0,
  116665. _vq_quantlist__44c4_s_p9_1,
  116666. NULL,
  116667. &_vq_auxt__44c4_s_p9_1,
  116668. NULL,
  116669. 0
  116670. };
  116671. static long _vq_quantlist__44c4_s_p9_2[] = {
  116672. 10,
  116673. 9,
  116674. 11,
  116675. 8,
  116676. 12,
  116677. 7,
  116678. 13,
  116679. 6,
  116680. 14,
  116681. 5,
  116682. 15,
  116683. 4,
  116684. 16,
  116685. 3,
  116686. 17,
  116687. 2,
  116688. 18,
  116689. 1,
  116690. 19,
  116691. 0,
  116692. 20,
  116693. };
  116694. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116695. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116696. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116697. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116698. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116699. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116700. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116701. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116702. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116703. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116704. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116705. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116706. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116707. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116708. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116709. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116710. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116711. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116712. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116713. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116714. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116715. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116716. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116717. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116718. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116719. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116720. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116721. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116722. 10,10,10,10,10,10,10,10,10,
  116723. };
  116724. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116725. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116726. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116727. 6.5, 7.5, 8.5, 9.5,
  116728. };
  116729. static long _vq_quantmap__44c4_s_p9_2[] = {
  116730. 19, 17, 15, 13, 11, 9, 7, 5,
  116731. 3, 1, 0, 2, 4, 6, 8, 10,
  116732. 12, 14, 16, 18, 20,
  116733. };
  116734. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116735. _vq_quantthresh__44c4_s_p9_2,
  116736. _vq_quantmap__44c4_s_p9_2,
  116737. 21,
  116738. 21
  116739. };
  116740. static static_codebook _44c4_s_p9_2 = {
  116741. 2, 441,
  116742. _vq_lengthlist__44c4_s_p9_2,
  116743. 1, -529268736, 1611661312, 5, 0,
  116744. _vq_quantlist__44c4_s_p9_2,
  116745. NULL,
  116746. &_vq_auxt__44c4_s_p9_2,
  116747. NULL,
  116748. 0
  116749. };
  116750. static long _huff_lengthlist__44c4_s_short[] = {
  116751. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116752. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116753. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116754. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116755. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116756. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116757. 7, 9,12,17,
  116758. };
  116759. static static_codebook _huff_book__44c4_s_short = {
  116760. 2, 100,
  116761. _huff_lengthlist__44c4_s_short,
  116762. 0, 0, 0, 0, 0,
  116763. NULL,
  116764. NULL,
  116765. NULL,
  116766. NULL,
  116767. 0
  116768. };
  116769. static long _huff_lengthlist__44c5_s_long[] = {
  116770. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116771. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116772. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116773. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116774. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116775. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116776. 9, 8, 7, 7,
  116777. };
  116778. static static_codebook _huff_book__44c5_s_long = {
  116779. 2, 100,
  116780. _huff_lengthlist__44c5_s_long,
  116781. 0, 0, 0, 0, 0,
  116782. NULL,
  116783. NULL,
  116784. NULL,
  116785. NULL,
  116786. 0
  116787. };
  116788. static long _vq_quantlist__44c5_s_p1_0[] = {
  116789. 1,
  116790. 0,
  116791. 2,
  116792. };
  116793. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116794. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116795. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116799. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116800. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116804. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116805. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116840. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  116845. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  116850. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  116851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116885. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116886. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116891. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116896. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  116897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117102. 0, 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,
  117205. };
  117206. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117207. -0.5, 0.5,
  117208. };
  117209. static long _vq_quantmap__44c5_s_p1_0[] = {
  117210. 1, 0, 2,
  117211. };
  117212. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117213. _vq_quantthresh__44c5_s_p1_0,
  117214. _vq_quantmap__44c5_s_p1_0,
  117215. 3,
  117216. 3
  117217. };
  117218. static static_codebook _44c5_s_p1_0 = {
  117219. 8, 6561,
  117220. _vq_lengthlist__44c5_s_p1_0,
  117221. 1, -535822336, 1611661312, 2, 0,
  117222. _vq_quantlist__44c5_s_p1_0,
  117223. NULL,
  117224. &_vq_auxt__44c5_s_p1_0,
  117225. NULL,
  117226. 0
  117227. };
  117228. static long _vq_quantlist__44c5_s_p2_0[] = {
  117229. 2,
  117230. 1,
  117231. 3,
  117232. 0,
  117233. 4,
  117234. };
  117235. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117236. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117237. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117238. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117239. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117240. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117245. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117246. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117247. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117248. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117251. 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117254. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117255. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117259. 0, 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. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117262. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117263. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117275. 0,
  117276. };
  117277. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117278. -1.5, -0.5, 0.5, 1.5,
  117279. };
  117280. static long _vq_quantmap__44c5_s_p2_0[] = {
  117281. 3, 1, 0, 2, 4,
  117282. };
  117283. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117284. _vq_quantthresh__44c5_s_p2_0,
  117285. _vq_quantmap__44c5_s_p2_0,
  117286. 5,
  117287. 5
  117288. };
  117289. static static_codebook _44c5_s_p2_0 = {
  117290. 4, 625,
  117291. _vq_lengthlist__44c5_s_p2_0,
  117292. 1, -533725184, 1611661312, 3, 0,
  117293. _vq_quantlist__44c5_s_p2_0,
  117294. NULL,
  117295. &_vq_auxt__44c5_s_p2_0,
  117296. NULL,
  117297. 0
  117298. };
  117299. static long _vq_quantlist__44c5_s_p3_0[] = {
  117300. 2,
  117301. 1,
  117302. 3,
  117303. 0,
  117304. 4,
  117305. };
  117306. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117307. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117310. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117313. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  117347. };
  117348. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117349. -1.5, -0.5, 0.5, 1.5,
  117350. };
  117351. static long _vq_quantmap__44c5_s_p3_0[] = {
  117352. 3, 1, 0, 2, 4,
  117353. };
  117354. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117355. _vq_quantthresh__44c5_s_p3_0,
  117356. _vq_quantmap__44c5_s_p3_0,
  117357. 5,
  117358. 5
  117359. };
  117360. static static_codebook _44c5_s_p3_0 = {
  117361. 4, 625,
  117362. _vq_lengthlist__44c5_s_p3_0,
  117363. 1, -533725184, 1611661312, 3, 0,
  117364. _vq_quantlist__44c5_s_p3_0,
  117365. NULL,
  117366. &_vq_auxt__44c5_s_p3_0,
  117367. NULL,
  117368. 0
  117369. };
  117370. static long _vq_quantlist__44c5_s_p4_0[] = {
  117371. 4,
  117372. 3,
  117373. 5,
  117374. 2,
  117375. 6,
  117376. 1,
  117377. 7,
  117378. 0,
  117379. 8,
  117380. };
  117381. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117382. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117383. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117384. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117385. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117386. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117387. 0,
  117388. };
  117389. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117390. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117391. };
  117392. static long _vq_quantmap__44c5_s_p4_0[] = {
  117393. 7, 5, 3, 1, 0, 2, 4, 6,
  117394. 8,
  117395. };
  117396. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117397. _vq_quantthresh__44c5_s_p4_0,
  117398. _vq_quantmap__44c5_s_p4_0,
  117399. 9,
  117400. 9
  117401. };
  117402. static static_codebook _44c5_s_p4_0 = {
  117403. 2, 81,
  117404. _vq_lengthlist__44c5_s_p4_0,
  117405. 1, -531628032, 1611661312, 4, 0,
  117406. _vq_quantlist__44c5_s_p4_0,
  117407. NULL,
  117408. &_vq_auxt__44c5_s_p4_0,
  117409. NULL,
  117410. 0
  117411. };
  117412. static long _vq_quantlist__44c5_s_p5_0[] = {
  117413. 4,
  117414. 3,
  117415. 5,
  117416. 2,
  117417. 6,
  117418. 1,
  117419. 7,
  117420. 0,
  117421. 8,
  117422. };
  117423. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117424. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117425. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117426. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117427. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117428. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117429. 10,
  117430. };
  117431. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117432. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117433. };
  117434. static long _vq_quantmap__44c5_s_p5_0[] = {
  117435. 7, 5, 3, 1, 0, 2, 4, 6,
  117436. 8,
  117437. };
  117438. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117439. _vq_quantthresh__44c5_s_p5_0,
  117440. _vq_quantmap__44c5_s_p5_0,
  117441. 9,
  117442. 9
  117443. };
  117444. static static_codebook _44c5_s_p5_0 = {
  117445. 2, 81,
  117446. _vq_lengthlist__44c5_s_p5_0,
  117447. 1, -531628032, 1611661312, 4, 0,
  117448. _vq_quantlist__44c5_s_p5_0,
  117449. NULL,
  117450. &_vq_auxt__44c5_s_p5_0,
  117451. NULL,
  117452. 0
  117453. };
  117454. static long _vq_quantlist__44c5_s_p6_0[] = {
  117455. 8,
  117456. 7,
  117457. 9,
  117458. 6,
  117459. 10,
  117460. 5,
  117461. 11,
  117462. 4,
  117463. 12,
  117464. 3,
  117465. 13,
  117466. 2,
  117467. 14,
  117468. 1,
  117469. 15,
  117470. 0,
  117471. 16,
  117472. };
  117473. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117474. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117475. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117476. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117477. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117478. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117479. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117480. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117481. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117482. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117483. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117484. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117485. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117486. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117487. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117488. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117489. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117490. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117491. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117492. 13,
  117493. };
  117494. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117495. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117496. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117497. };
  117498. static long _vq_quantmap__44c5_s_p6_0[] = {
  117499. 15, 13, 11, 9, 7, 5, 3, 1,
  117500. 0, 2, 4, 6, 8, 10, 12, 14,
  117501. 16,
  117502. };
  117503. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117504. _vq_quantthresh__44c5_s_p6_0,
  117505. _vq_quantmap__44c5_s_p6_0,
  117506. 17,
  117507. 17
  117508. };
  117509. static static_codebook _44c5_s_p6_0 = {
  117510. 2, 289,
  117511. _vq_lengthlist__44c5_s_p6_0,
  117512. 1, -529530880, 1611661312, 5, 0,
  117513. _vq_quantlist__44c5_s_p6_0,
  117514. NULL,
  117515. &_vq_auxt__44c5_s_p6_0,
  117516. NULL,
  117517. 0
  117518. };
  117519. static long _vq_quantlist__44c5_s_p7_0[] = {
  117520. 1,
  117521. 0,
  117522. 2,
  117523. };
  117524. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117525. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117526. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117527. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117528. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117529. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117530. 10,
  117531. };
  117532. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117533. -5.5, 5.5,
  117534. };
  117535. static long _vq_quantmap__44c5_s_p7_0[] = {
  117536. 1, 0, 2,
  117537. };
  117538. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117539. _vq_quantthresh__44c5_s_p7_0,
  117540. _vq_quantmap__44c5_s_p7_0,
  117541. 3,
  117542. 3
  117543. };
  117544. static static_codebook _44c5_s_p7_0 = {
  117545. 4, 81,
  117546. _vq_lengthlist__44c5_s_p7_0,
  117547. 1, -529137664, 1618345984, 2, 0,
  117548. _vq_quantlist__44c5_s_p7_0,
  117549. NULL,
  117550. &_vq_auxt__44c5_s_p7_0,
  117551. NULL,
  117552. 0
  117553. };
  117554. static long _vq_quantlist__44c5_s_p7_1[] = {
  117555. 5,
  117556. 4,
  117557. 6,
  117558. 3,
  117559. 7,
  117560. 2,
  117561. 8,
  117562. 1,
  117563. 9,
  117564. 0,
  117565. 10,
  117566. };
  117567. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117568. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117569. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117570. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117571. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117572. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117573. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117574. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117575. 10,10,10, 8, 8, 8, 8, 8, 8,
  117576. };
  117577. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117578. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117579. 3.5, 4.5,
  117580. };
  117581. static long _vq_quantmap__44c5_s_p7_1[] = {
  117582. 9, 7, 5, 3, 1, 0, 2, 4,
  117583. 6, 8, 10,
  117584. };
  117585. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117586. _vq_quantthresh__44c5_s_p7_1,
  117587. _vq_quantmap__44c5_s_p7_1,
  117588. 11,
  117589. 11
  117590. };
  117591. static static_codebook _44c5_s_p7_1 = {
  117592. 2, 121,
  117593. _vq_lengthlist__44c5_s_p7_1,
  117594. 1, -531365888, 1611661312, 4, 0,
  117595. _vq_quantlist__44c5_s_p7_1,
  117596. NULL,
  117597. &_vq_auxt__44c5_s_p7_1,
  117598. NULL,
  117599. 0
  117600. };
  117601. static long _vq_quantlist__44c5_s_p8_0[] = {
  117602. 6,
  117603. 5,
  117604. 7,
  117605. 4,
  117606. 8,
  117607. 3,
  117608. 9,
  117609. 2,
  117610. 10,
  117611. 1,
  117612. 11,
  117613. 0,
  117614. 12,
  117615. };
  117616. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117617. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117618. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117619. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117620. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117621. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117622. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117623. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117624. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117625. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117626. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117627. 0,12,12,12,12,12,12,13,13,
  117628. };
  117629. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117630. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117631. 12.5, 17.5, 22.5, 27.5,
  117632. };
  117633. static long _vq_quantmap__44c5_s_p8_0[] = {
  117634. 11, 9, 7, 5, 3, 1, 0, 2,
  117635. 4, 6, 8, 10, 12,
  117636. };
  117637. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117638. _vq_quantthresh__44c5_s_p8_0,
  117639. _vq_quantmap__44c5_s_p8_0,
  117640. 13,
  117641. 13
  117642. };
  117643. static static_codebook _44c5_s_p8_0 = {
  117644. 2, 169,
  117645. _vq_lengthlist__44c5_s_p8_0,
  117646. 1, -526516224, 1616117760, 4, 0,
  117647. _vq_quantlist__44c5_s_p8_0,
  117648. NULL,
  117649. &_vq_auxt__44c5_s_p8_0,
  117650. NULL,
  117651. 0
  117652. };
  117653. static long _vq_quantlist__44c5_s_p8_1[] = {
  117654. 2,
  117655. 1,
  117656. 3,
  117657. 0,
  117658. 4,
  117659. };
  117660. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117661. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117662. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117663. };
  117664. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117665. -1.5, -0.5, 0.5, 1.5,
  117666. };
  117667. static long _vq_quantmap__44c5_s_p8_1[] = {
  117668. 3, 1, 0, 2, 4,
  117669. };
  117670. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117671. _vq_quantthresh__44c5_s_p8_1,
  117672. _vq_quantmap__44c5_s_p8_1,
  117673. 5,
  117674. 5
  117675. };
  117676. static static_codebook _44c5_s_p8_1 = {
  117677. 2, 25,
  117678. _vq_lengthlist__44c5_s_p8_1,
  117679. 1, -533725184, 1611661312, 3, 0,
  117680. _vq_quantlist__44c5_s_p8_1,
  117681. NULL,
  117682. &_vq_auxt__44c5_s_p8_1,
  117683. NULL,
  117684. 0
  117685. };
  117686. static long _vq_quantlist__44c5_s_p9_0[] = {
  117687. 7,
  117688. 6,
  117689. 8,
  117690. 5,
  117691. 9,
  117692. 4,
  117693. 10,
  117694. 3,
  117695. 11,
  117696. 2,
  117697. 12,
  117698. 1,
  117699. 13,
  117700. 0,
  117701. 14,
  117702. };
  117703. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117704. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117705. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117706. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117707. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117708. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117709. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117710. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117711. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117712. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117713. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117714. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117715. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117716. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117717. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117718. 12,
  117719. };
  117720. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117721. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117722. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117723. };
  117724. static long _vq_quantmap__44c5_s_p9_0[] = {
  117725. 13, 11, 9, 7, 5, 3, 1, 0,
  117726. 2, 4, 6, 8, 10, 12, 14,
  117727. };
  117728. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117729. _vq_quantthresh__44c5_s_p9_0,
  117730. _vq_quantmap__44c5_s_p9_0,
  117731. 15,
  117732. 15
  117733. };
  117734. static static_codebook _44c5_s_p9_0 = {
  117735. 2, 225,
  117736. _vq_lengthlist__44c5_s_p9_0,
  117737. 1, -512522752, 1628852224, 4, 0,
  117738. _vq_quantlist__44c5_s_p9_0,
  117739. NULL,
  117740. &_vq_auxt__44c5_s_p9_0,
  117741. NULL,
  117742. 0
  117743. };
  117744. static long _vq_quantlist__44c5_s_p9_1[] = {
  117745. 8,
  117746. 7,
  117747. 9,
  117748. 6,
  117749. 10,
  117750. 5,
  117751. 11,
  117752. 4,
  117753. 12,
  117754. 3,
  117755. 13,
  117756. 2,
  117757. 14,
  117758. 1,
  117759. 15,
  117760. 0,
  117761. 16,
  117762. };
  117763. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117764. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117765. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117766. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117767. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117768. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117769. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117770. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117771. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117772. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117773. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117774. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117775. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117776. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117777. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117778. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117779. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117780. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117781. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117782. 15,
  117783. };
  117784. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117785. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117786. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117787. };
  117788. static long _vq_quantmap__44c5_s_p9_1[] = {
  117789. 15, 13, 11, 9, 7, 5, 3, 1,
  117790. 0, 2, 4, 6, 8, 10, 12, 14,
  117791. 16,
  117792. };
  117793. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117794. _vq_quantthresh__44c5_s_p9_1,
  117795. _vq_quantmap__44c5_s_p9_1,
  117796. 17,
  117797. 17
  117798. };
  117799. static static_codebook _44c5_s_p9_1 = {
  117800. 2, 289,
  117801. _vq_lengthlist__44c5_s_p9_1,
  117802. 1, -520814592, 1620377600, 5, 0,
  117803. _vq_quantlist__44c5_s_p9_1,
  117804. NULL,
  117805. &_vq_auxt__44c5_s_p9_1,
  117806. NULL,
  117807. 0
  117808. };
  117809. static long _vq_quantlist__44c5_s_p9_2[] = {
  117810. 10,
  117811. 9,
  117812. 11,
  117813. 8,
  117814. 12,
  117815. 7,
  117816. 13,
  117817. 6,
  117818. 14,
  117819. 5,
  117820. 15,
  117821. 4,
  117822. 16,
  117823. 3,
  117824. 17,
  117825. 2,
  117826. 18,
  117827. 1,
  117828. 19,
  117829. 0,
  117830. 20,
  117831. };
  117832. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117833. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117834. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117835. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117836. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117837. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117838. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117839. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117840. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117841. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117842. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117843. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117844. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117845. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117846. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117847. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117848. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117849. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117850. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117851. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117852. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117853. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117854. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117855. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117856. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117857. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117858. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117859. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117860. 10,10,10,10,10,10,10,10,10,
  117861. };
  117862. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117863. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117864. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117865. 6.5, 7.5, 8.5, 9.5,
  117866. };
  117867. static long _vq_quantmap__44c5_s_p9_2[] = {
  117868. 19, 17, 15, 13, 11, 9, 7, 5,
  117869. 3, 1, 0, 2, 4, 6, 8, 10,
  117870. 12, 14, 16, 18, 20,
  117871. };
  117872. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117873. _vq_quantthresh__44c5_s_p9_2,
  117874. _vq_quantmap__44c5_s_p9_2,
  117875. 21,
  117876. 21
  117877. };
  117878. static static_codebook _44c5_s_p9_2 = {
  117879. 2, 441,
  117880. _vq_lengthlist__44c5_s_p9_2,
  117881. 1, -529268736, 1611661312, 5, 0,
  117882. _vq_quantlist__44c5_s_p9_2,
  117883. NULL,
  117884. &_vq_auxt__44c5_s_p9_2,
  117885. NULL,
  117886. 0
  117887. };
  117888. static long _huff_lengthlist__44c5_s_short[] = {
  117889. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117890. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117891. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117892. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117893. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117894. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117895. 6, 8,11,16,
  117896. };
  117897. static static_codebook _huff_book__44c5_s_short = {
  117898. 2, 100,
  117899. _huff_lengthlist__44c5_s_short,
  117900. 0, 0, 0, 0, 0,
  117901. NULL,
  117902. NULL,
  117903. NULL,
  117904. NULL,
  117905. 0
  117906. };
  117907. static long _huff_lengthlist__44c6_s_long[] = {
  117908. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  117909. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  117910. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  117911. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  117912. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  117913. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  117914. 11,10,10,12,
  117915. };
  117916. static static_codebook _huff_book__44c6_s_long = {
  117917. 2, 100,
  117918. _huff_lengthlist__44c6_s_long,
  117919. 0, 0, 0, 0, 0,
  117920. NULL,
  117921. NULL,
  117922. NULL,
  117923. NULL,
  117924. 0
  117925. };
  117926. static long _vq_quantlist__44c6_s_p1_0[] = {
  117927. 1,
  117928. 0,
  117929. 2,
  117930. };
  117931. static long _vq_lengthlist__44c6_s_p1_0[] = {
  117932. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  117933. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  117934. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  117935. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  117936. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  117937. 8,
  117938. };
  117939. static float _vq_quantthresh__44c6_s_p1_0[] = {
  117940. -0.5, 0.5,
  117941. };
  117942. static long _vq_quantmap__44c6_s_p1_0[] = {
  117943. 1, 0, 2,
  117944. };
  117945. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  117946. _vq_quantthresh__44c6_s_p1_0,
  117947. _vq_quantmap__44c6_s_p1_0,
  117948. 3,
  117949. 3
  117950. };
  117951. static static_codebook _44c6_s_p1_0 = {
  117952. 4, 81,
  117953. _vq_lengthlist__44c6_s_p1_0,
  117954. 1, -535822336, 1611661312, 2, 0,
  117955. _vq_quantlist__44c6_s_p1_0,
  117956. NULL,
  117957. &_vq_auxt__44c6_s_p1_0,
  117958. NULL,
  117959. 0
  117960. };
  117961. static long _vq_quantlist__44c6_s_p2_0[] = {
  117962. 2,
  117963. 1,
  117964. 3,
  117965. 0,
  117966. 4,
  117967. };
  117968. static long _vq_lengthlist__44c6_s_p2_0[] = {
  117969. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  117970. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  117971. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  117972. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  117973. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  117974. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  117975. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  117976. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  117977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117978. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  117979. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  117980. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  117981. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  117982. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  117983. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  117984. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  117985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117986. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  117987. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  117988. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  117989. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  117990. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  117991. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  117992. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117994. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  117995. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  117996. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  117997. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  117998. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  117999. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118000. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118005. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118006. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118007. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118008. 13,
  118009. };
  118010. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118011. -1.5, -0.5, 0.5, 1.5,
  118012. };
  118013. static long _vq_quantmap__44c6_s_p2_0[] = {
  118014. 3, 1, 0, 2, 4,
  118015. };
  118016. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118017. _vq_quantthresh__44c6_s_p2_0,
  118018. _vq_quantmap__44c6_s_p2_0,
  118019. 5,
  118020. 5
  118021. };
  118022. static static_codebook _44c6_s_p2_0 = {
  118023. 4, 625,
  118024. _vq_lengthlist__44c6_s_p2_0,
  118025. 1, -533725184, 1611661312, 3, 0,
  118026. _vq_quantlist__44c6_s_p2_0,
  118027. NULL,
  118028. &_vq_auxt__44c6_s_p2_0,
  118029. NULL,
  118030. 0
  118031. };
  118032. static long _vq_quantlist__44c6_s_p3_0[] = {
  118033. 4,
  118034. 3,
  118035. 5,
  118036. 2,
  118037. 6,
  118038. 1,
  118039. 7,
  118040. 0,
  118041. 8,
  118042. };
  118043. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118044. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118045. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118046. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118047. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118049. 0,
  118050. };
  118051. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118052. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118053. };
  118054. static long _vq_quantmap__44c6_s_p3_0[] = {
  118055. 7, 5, 3, 1, 0, 2, 4, 6,
  118056. 8,
  118057. };
  118058. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118059. _vq_quantthresh__44c6_s_p3_0,
  118060. _vq_quantmap__44c6_s_p3_0,
  118061. 9,
  118062. 9
  118063. };
  118064. static static_codebook _44c6_s_p3_0 = {
  118065. 2, 81,
  118066. _vq_lengthlist__44c6_s_p3_0,
  118067. 1, -531628032, 1611661312, 4, 0,
  118068. _vq_quantlist__44c6_s_p3_0,
  118069. NULL,
  118070. &_vq_auxt__44c6_s_p3_0,
  118071. NULL,
  118072. 0
  118073. };
  118074. static long _vq_quantlist__44c6_s_p4_0[] = {
  118075. 8,
  118076. 7,
  118077. 9,
  118078. 6,
  118079. 10,
  118080. 5,
  118081. 11,
  118082. 4,
  118083. 12,
  118084. 3,
  118085. 13,
  118086. 2,
  118087. 14,
  118088. 1,
  118089. 15,
  118090. 0,
  118091. 16,
  118092. };
  118093. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118094. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118095. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118096. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118097. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118098. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118099. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118100. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118101. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118102. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118103. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118112. 0,
  118113. };
  118114. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118115. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118116. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118117. };
  118118. static long _vq_quantmap__44c6_s_p4_0[] = {
  118119. 15, 13, 11, 9, 7, 5, 3, 1,
  118120. 0, 2, 4, 6, 8, 10, 12, 14,
  118121. 16,
  118122. };
  118123. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118124. _vq_quantthresh__44c6_s_p4_0,
  118125. _vq_quantmap__44c6_s_p4_0,
  118126. 17,
  118127. 17
  118128. };
  118129. static static_codebook _44c6_s_p4_0 = {
  118130. 2, 289,
  118131. _vq_lengthlist__44c6_s_p4_0,
  118132. 1, -529530880, 1611661312, 5, 0,
  118133. _vq_quantlist__44c6_s_p4_0,
  118134. NULL,
  118135. &_vq_auxt__44c6_s_p4_0,
  118136. NULL,
  118137. 0
  118138. };
  118139. static long _vq_quantlist__44c6_s_p5_0[] = {
  118140. 1,
  118141. 0,
  118142. 2,
  118143. };
  118144. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118145. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118146. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118147. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118148. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118149. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118150. 12,
  118151. };
  118152. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118153. -5.5, 5.5,
  118154. };
  118155. static long _vq_quantmap__44c6_s_p5_0[] = {
  118156. 1, 0, 2,
  118157. };
  118158. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118159. _vq_quantthresh__44c6_s_p5_0,
  118160. _vq_quantmap__44c6_s_p5_0,
  118161. 3,
  118162. 3
  118163. };
  118164. static static_codebook _44c6_s_p5_0 = {
  118165. 4, 81,
  118166. _vq_lengthlist__44c6_s_p5_0,
  118167. 1, -529137664, 1618345984, 2, 0,
  118168. _vq_quantlist__44c6_s_p5_0,
  118169. NULL,
  118170. &_vq_auxt__44c6_s_p5_0,
  118171. NULL,
  118172. 0
  118173. };
  118174. static long _vq_quantlist__44c6_s_p5_1[] = {
  118175. 5,
  118176. 4,
  118177. 6,
  118178. 3,
  118179. 7,
  118180. 2,
  118181. 8,
  118182. 1,
  118183. 9,
  118184. 0,
  118185. 10,
  118186. };
  118187. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118188. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118189. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118190. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118191. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118192. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118193. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118194. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118195. 11,10,10, 7, 7, 8, 8, 8, 8,
  118196. };
  118197. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118198. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118199. 3.5, 4.5,
  118200. };
  118201. static long _vq_quantmap__44c6_s_p5_1[] = {
  118202. 9, 7, 5, 3, 1, 0, 2, 4,
  118203. 6, 8, 10,
  118204. };
  118205. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118206. _vq_quantthresh__44c6_s_p5_1,
  118207. _vq_quantmap__44c6_s_p5_1,
  118208. 11,
  118209. 11
  118210. };
  118211. static static_codebook _44c6_s_p5_1 = {
  118212. 2, 121,
  118213. _vq_lengthlist__44c6_s_p5_1,
  118214. 1, -531365888, 1611661312, 4, 0,
  118215. _vq_quantlist__44c6_s_p5_1,
  118216. NULL,
  118217. &_vq_auxt__44c6_s_p5_1,
  118218. NULL,
  118219. 0
  118220. };
  118221. static long _vq_quantlist__44c6_s_p6_0[] = {
  118222. 6,
  118223. 5,
  118224. 7,
  118225. 4,
  118226. 8,
  118227. 3,
  118228. 9,
  118229. 2,
  118230. 10,
  118231. 1,
  118232. 11,
  118233. 0,
  118234. 12,
  118235. };
  118236. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118237. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118238. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118239. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118240. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118241. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118242. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118247. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118248. };
  118249. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118250. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118251. 12.5, 17.5, 22.5, 27.5,
  118252. };
  118253. static long _vq_quantmap__44c6_s_p6_0[] = {
  118254. 11, 9, 7, 5, 3, 1, 0, 2,
  118255. 4, 6, 8, 10, 12,
  118256. };
  118257. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118258. _vq_quantthresh__44c6_s_p6_0,
  118259. _vq_quantmap__44c6_s_p6_0,
  118260. 13,
  118261. 13
  118262. };
  118263. static static_codebook _44c6_s_p6_0 = {
  118264. 2, 169,
  118265. _vq_lengthlist__44c6_s_p6_0,
  118266. 1, -526516224, 1616117760, 4, 0,
  118267. _vq_quantlist__44c6_s_p6_0,
  118268. NULL,
  118269. &_vq_auxt__44c6_s_p6_0,
  118270. NULL,
  118271. 0
  118272. };
  118273. static long _vq_quantlist__44c6_s_p6_1[] = {
  118274. 2,
  118275. 1,
  118276. 3,
  118277. 0,
  118278. 4,
  118279. };
  118280. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118281. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118282. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118283. };
  118284. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118285. -1.5, -0.5, 0.5, 1.5,
  118286. };
  118287. static long _vq_quantmap__44c6_s_p6_1[] = {
  118288. 3, 1, 0, 2, 4,
  118289. };
  118290. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118291. _vq_quantthresh__44c6_s_p6_1,
  118292. _vq_quantmap__44c6_s_p6_1,
  118293. 5,
  118294. 5
  118295. };
  118296. static static_codebook _44c6_s_p6_1 = {
  118297. 2, 25,
  118298. _vq_lengthlist__44c6_s_p6_1,
  118299. 1, -533725184, 1611661312, 3, 0,
  118300. _vq_quantlist__44c6_s_p6_1,
  118301. NULL,
  118302. &_vq_auxt__44c6_s_p6_1,
  118303. NULL,
  118304. 0
  118305. };
  118306. static long _vq_quantlist__44c6_s_p7_0[] = {
  118307. 6,
  118308. 5,
  118309. 7,
  118310. 4,
  118311. 8,
  118312. 3,
  118313. 9,
  118314. 2,
  118315. 10,
  118316. 1,
  118317. 11,
  118318. 0,
  118319. 12,
  118320. };
  118321. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118322. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118323. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118324. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118325. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118326. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118327. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118328. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118329. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118330. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118331. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118332. 20,13,13,13,13,13,13,14,14,
  118333. };
  118334. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118335. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118336. 27.5, 38.5, 49.5, 60.5,
  118337. };
  118338. static long _vq_quantmap__44c6_s_p7_0[] = {
  118339. 11, 9, 7, 5, 3, 1, 0, 2,
  118340. 4, 6, 8, 10, 12,
  118341. };
  118342. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118343. _vq_quantthresh__44c6_s_p7_0,
  118344. _vq_quantmap__44c6_s_p7_0,
  118345. 13,
  118346. 13
  118347. };
  118348. static static_codebook _44c6_s_p7_0 = {
  118349. 2, 169,
  118350. _vq_lengthlist__44c6_s_p7_0,
  118351. 1, -523206656, 1618345984, 4, 0,
  118352. _vq_quantlist__44c6_s_p7_0,
  118353. NULL,
  118354. &_vq_auxt__44c6_s_p7_0,
  118355. NULL,
  118356. 0
  118357. };
  118358. static long _vq_quantlist__44c6_s_p7_1[] = {
  118359. 5,
  118360. 4,
  118361. 6,
  118362. 3,
  118363. 7,
  118364. 2,
  118365. 8,
  118366. 1,
  118367. 9,
  118368. 0,
  118369. 10,
  118370. };
  118371. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118372. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118373. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118374. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118375. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118376. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118377. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118378. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118379. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118380. };
  118381. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118382. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118383. 3.5, 4.5,
  118384. };
  118385. static long _vq_quantmap__44c6_s_p7_1[] = {
  118386. 9, 7, 5, 3, 1, 0, 2, 4,
  118387. 6, 8, 10,
  118388. };
  118389. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118390. _vq_quantthresh__44c6_s_p7_1,
  118391. _vq_quantmap__44c6_s_p7_1,
  118392. 11,
  118393. 11
  118394. };
  118395. static static_codebook _44c6_s_p7_1 = {
  118396. 2, 121,
  118397. _vq_lengthlist__44c6_s_p7_1,
  118398. 1, -531365888, 1611661312, 4, 0,
  118399. _vq_quantlist__44c6_s_p7_1,
  118400. NULL,
  118401. &_vq_auxt__44c6_s_p7_1,
  118402. NULL,
  118403. 0
  118404. };
  118405. static long _vq_quantlist__44c6_s_p8_0[] = {
  118406. 7,
  118407. 6,
  118408. 8,
  118409. 5,
  118410. 9,
  118411. 4,
  118412. 10,
  118413. 3,
  118414. 11,
  118415. 2,
  118416. 12,
  118417. 1,
  118418. 13,
  118419. 0,
  118420. 14,
  118421. };
  118422. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118423. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118424. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118425. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118426. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118427. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118428. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118429. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118430. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118431. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118432. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118433. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118434. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118435. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118436. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118437. 14,
  118438. };
  118439. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118440. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118441. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118442. };
  118443. static long _vq_quantmap__44c6_s_p8_0[] = {
  118444. 13, 11, 9, 7, 5, 3, 1, 0,
  118445. 2, 4, 6, 8, 10, 12, 14,
  118446. };
  118447. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118448. _vq_quantthresh__44c6_s_p8_0,
  118449. _vq_quantmap__44c6_s_p8_0,
  118450. 15,
  118451. 15
  118452. };
  118453. static static_codebook _44c6_s_p8_0 = {
  118454. 2, 225,
  118455. _vq_lengthlist__44c6_s_p8_0,
  118456. 1, -520986624, 1620377600, 4, 0,
  118457. _vq_quantlist__44c6_s_p8_0,
  118458. NULL,
  118459. &_vq_auxt__44c6_s_p8_0,
  118460. NULL,
  118461. 0
  118462. };
  118463. static long _vq_quantlist__44c6_s_p8_1[] = {
  118464. 10,
  118465. 9,
  118466. 11,
  118467. 8,
  118468. 12,
  118469. 7,
  118470. 13,
  118471. 6,
  118472. 14,
  118473. 5,
  118474. 15,
  118475. 4,
  118476. 16,
  118477. 3,
  118478. 17,
  118479. 2,
  118480. 18,
  118481. 1,
  118482. 19,
  118483. 0,
  118484. 20,
  118485. };
  118486. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118487. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118488. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118489. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118490. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118491. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118492. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118493. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118494. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118495. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118496. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118497. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118498. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118499. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118500. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118501. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118502. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118503. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118504. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118505. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118506. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118507. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118508. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118509. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118510. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118511. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118512. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118513. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118514. 10,10,10,10,10,10,10,10,10,
  118515. };
  118516. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118517. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118518. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118519. 6.5, 7.5, 8.5, 9.5,
  118520. };
  118521. static long _vq_quantmap__44c6_s_p8_1[] = {
  118522. 19, 17, 15, 13, 11, 9, 7, 5,
  118523. 3, 1, 0, 2, 4, 6, 8, 10,
  118524. 12, 14, 16, 18, 20,
  118525. };
  118526. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118527. _vq_quantthresh__44c6_s_p8_1,
  118528. _vq_quantmap__44c6_s_p8_1,
  118529. 21,
  118530. 21
  118531. };
  118532. static static_codebook _44c6_s_p8_1 = {
  118533. 2, 441,
  118534. _vq_lengthlist__44c6_s_p8_1,
  118535. 1, -529268736, 1611661312, 5, 0,
  118536. _vq_quantlist__44c6_s_p8_1,
  118537. NULL,
  118538. &_vq_auxt__44c6_s_p8_1,
  118539. NULL,
  118540. 0
  118541. };
  118542. static long _vq_quantlist__44c6_s_p9_0[] = {
  118543. 6,
  118544. 5,
  118545. 7,
  118546. 4,
  118547. 8,
  118548. 3,
  118549. 9,
  118550. 2,
  118551. 10,
  118552. 1,
  118553. 11,
  118554. 0,
  118555. 12,
  118556. };
  118557. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118558. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118559. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118560. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118561. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118562. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118563. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118564. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118565. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118566. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118567. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118568. 10,10,10,10,10,10,10,10,10,
  118569. };
  118570. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118571. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118572. 1592.5, 2229.5, 2866.5, 3503.5,
  118573. };
  118574. static long _vq_quantmap__44c6_s_p9_0[] = {
  118575. 11, 9, 7, 5, 3, 1, 0, 2,
  118576. 4, 6, 8, 10, 12,
  118577. };
  118578. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118579. _vq_quantthresh__44c6_s_p9_0,
  118580. _vq_quantmap__44c6_s_p9_0,
  118581. 13,
  118582. 13
  118583. };
  118584. static static_codebook _44c6_s_p9_0 = {
  118585. 2, 169,
  118586. _vq_lengthlist__44c6_s_p9_0,
  118587. 1, -511845376, 1630791680, 4, 0,
  118588. _vq_quantlist__44c6_s_p9_0,
  118589. NULL,
  118590. &_vq_auxt__44c6_s_p9_0,
  118591. NULL,
  118592. 0
  118593. };
  118594. static long _vq_quantlist__44c6_s_p9_1[] = {
  118595. 6,
  118596. 5,
  118597. 7,
  118598. 4,
  118599. 8,
  118600. 3,
  118601. 9,
  118602. 2,
  118603. 10,
  118604. 1,
  118605. 11,
  118606. 0,
  118607. 12,
  118608. };
  118609. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118610. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118611. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118612. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118613. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118614. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118615. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118616. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118617. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118618. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118619. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118620. 15,12,10,11,11,13,11,12,13,
  118621. };
  118622. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118623. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118624. 122.5, 171.5, 220.5, 269.5,
  118625. };
  118626. static long _vq_quantmap__44c6_s_p9_1[] = {
  118627. 11, 9, 7, 5, 3, 1, 0, 2,
  118628. 4, 6, 8, 10, 12,
  118629. };
  118630. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118631. _vq_quantthresh__44c6_s_p9_1,
  118632. _vq_quantmap__44c6_s_p9_1,
  118633. 13,
  118634. 13
  118635. };
  118636. static static_codebook _44c6_s_p9_1 = {
  118637. 2, 169,
  118638. _vq_lengthlist__44c6_s_p9_1,
  118639. 1, -518889472, 1622704128, 4, 0,
  118640. _vq_quantlist__44c6_s_p9_1,
  118641. NULL,
  118642. &_vq_auxt__44c6_s_p9_1,
  118643. NULL,
  118644. 0
  118645. };
  118646. static long _vq_quantlist__44c6_s_p9_2[] = {
  118647. 24,
  118648. 23,
  118649. 25,
  118650. 22,
  118651. 26,
  118652. 21,
  118653. 27,
  118654. 20,
  118655. 28,
  118656. 19,
  118657. 29,
  118658. 18,
  118659. 30,
  118660. 17,
  118661. 31,
  118662. 16,
  118663. 32,
  118664. 15,
  118665. 33,
  118666. 14,
  118667. 34,
  118668. 13,
  118669. 35,
  118670. 12,
  118671. 36,
  118672. 11,
  118673. 37,
  118674. 10,
  118675. 38,
  118676. 9,
  118677. 39,
  118678. 8,
  118679. 40,
  118680. 7,
  118681. 41,
  118682. 6,
  118683. 42,
  118684. 5,
  118685. 43,
  118686. 4,
  118687. 44,
  118688. 3,
  118689. 45,
  118690. 2,
  118691. 46,
  118692. 1,
  118693. 47,
  118694. 0,
  118695. 48,
  118696. };
  118697. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118698. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118699. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118700. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118701. 7,
  118702. };
  118703. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118704. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118705. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118706. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118707. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118708. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118709. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118710. };
  118711. static long _vq_quantmap__44c6_s_p9_2[] = {
  118712. 47, 45, 43, 41, 39, 37, 35, 33,
  118713. 31, 29, 27, 25, 23, 21, 19, 17,
  118714. 15, 13, 11, 9, 7, 5, 3, 1,
  118715. 0, 2, 4, 6, 8, 10, 12, 14,
  118716. 16, 18, 20, 22, 24, 26, 28, 30,
  118717. 32, 34, 36, 38, 40, 42, 44, 46,
  118718. 48,
  118719. };
  118720. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118721. _vq_quantthresh__44c6_s_p9_2,
  118722. _vq_quantmap__44c6_s_p9_2,
  118723. 49,
  118724. 49
  118725. };
  118726. static static_codebook _44c6_s_p9_2 = {
  118727. 1, 49,
  118728. _vq_lengthlist__44c6_s_p9_2,
  118729. 1, -526909440, 1611661312, 6, 0,
  118730. _vq_quantlist__44c6_s_p9_2,
  118731. NULL,
  118732. &_vq_auxt__44c6_s_p9_2,
  118733. NULL,
  118734. 0
  118735. };
  118736. static long _huff_lengthlist__44c6_s_short[] = {
  118737. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118738. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118739. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118740. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118741. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118742. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118743. 9,10,17,18,
  118744. };
  118745. static static_codebook _huff_book__44c6_s_short = {
  118746. 2, 100,
  118747. _huff_lengthlist__44c6_s_short,
  118748. 0, 0, 0, 0, 0,
  118749. NULL,
  118750. NULL,
  118751. NULL,
  118752. NULL,
  118753. 0
  118754. };
  118755. static long _huff_lengthlist__44c7_s_long[] = {
  118756. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118757. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118758. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118759. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118760. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118761. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118762. 11,10,10,12,
  118763. };
  118764. static static_codebook _huff_book__44c7_s_long = {
  118765. 2, 100,
  118766. _huff_lengthlist__44c7_s_long,
  118767. 0, 0, 0, 0, 0,
  118768. NULL,
  118769. NULL,
  118770. NULL,
  118771. NULL,
  118772. 0
  118773. };
  118774. static long _vq_quantlist__44c7_s_p1_0[] = {
  118775. 1,
  118776. 0,
  118777. 2,
  118778. };
  118779. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118780. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118781. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118782. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118783. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118784. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118785. 8,
  118786. };
  118787. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118788. -0.5, 0.5,
  118789. };
  118790. static long _vq_quantmap__44c7_s_p1_0[] = {
  118791. 1, 0, 2,
  118792. };
  118793. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118794. _vq_quantthresh__44c7_s_p1_0,
  118795. _vq_quantmap__44c7_s_p1_0,
  118796. 3,
  118797. 3
  118798. };
  118799. static static_codebook _44c7_s_p1_0 = {
  118800. 4, 81,
  118801. _vq_lengthlist__44c7_s_p1_0,
  118802. 1, -535822336, 1611661312, 2, 0,
  118803. _vq_quantlist__44c7_s_p1_0,
  118804. NULL,
  118805. &_vq_auxt__44c7_s_p1_0,
  118806. NULL,
  118807. 0
  118808. };
  118809. static long _vq_quantlist__44c7_s_p2_0[] = {
  118810. 2,
  118811. 1,
  118812. 3,
  118813. 0,
  118814. 4,
  118815. };
  118816. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118817. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118818. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118819. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118820. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118821. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118822. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118823. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118824. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118826. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118827. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118828. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118829. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118830. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118831. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118832. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118834. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118835. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118836. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118837. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118838. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118839. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118840. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118842. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118843. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118844. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118845. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118846. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118847. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118848. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118853. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118854. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118855. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118856. 13,
  118857. };
  118858. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118859. -1.5, -0.5, 0.5, 1.5,
  118860. };
  118861. static long _vq_quantmap__44c7_s_p2_0[] = {
  118862. 3, 1, 0, 2, 4,
  118863. };
  118864. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118865. _vq_quantthresh__44c7_s_p2_0,
  118866. _vq_quantmap__44c7_s_p2_0,
  118867. 5,
  118868. 5
  118869. };
  118870. static static_codebook _44c7_s_p2_0 = {
  118871. 4, 625,
  118872. _vq_lengthlist__44c7_s_p2_0,
  118873. 1, -533725184, 1611661312, 3, 0,
  118874. _vq_quantlist__44c7_s_p2_0,
  118875. NULL,
  118876. &_vq_auxt__44c7_s_p2_0,
  118877. NULL,
  118878. 0
  118879. };
  118880. static long _vq_quantlist__44c7_s_p3_0[] = {
  118881. 4,
  118882. 3,
  118883. 5,
  118884. 2,
  118885. 6,
  118886. 1,
  118887. 7,
  118888. 0,
  118889. 8,
  118890. };
  118891. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118892. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118893. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118894. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118895. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118897. 0,
  118898. };
  118899. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118900. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118901. };
  118902. static long _vq_quantmap__44c7_s_p3_0[] = {
  118903. 7, 5, 3, 1, 0, 2, 4, 6,
  118904. 8,
  118905. };
  118906. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  118907. _vq_quantthresh__44c7_s_p3_0,
  118908. _vq_quantmap__44c7_s_p3_0,
  118909. 9,
  118910. 9
  118911. };
  118912. static static_codebook _44c7_s_p3_0 = {
  118913. 2, 81,
  118914. _vq_lengthlist__44c7_s_p3_0,
  118915. 1, -531628032, 1611661312, 4, 0,
  118916. _vq_quantlist__44c7_s_p3_0,
  118917. NULL,
  118918. &_vq_auxt__44c7_s_p3_0,
  118919. NULL,
  118920. 0
  118921. };
  118922. static long _vq_quantlist__44c7_s_p4_0[] = {
  118923. 8,
  118924. 7,
  118925. 9,
  118926. 6,
  118927. 10,
  118928. 5,
  118929. 11,
  118930. 4,
  118931. 12,
  118932. 3,
  118933. 13,
  118934. 2,
  118935. 14,
  118936. 1,
  118937. 15,
  118938. 0,
  118939. 16,
  118940. };
  118941. static long _vq_lengthlist__44c7_s_p4_0[] = {
  118942. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  118943. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  118944. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  118945. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  118946. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  118947. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  118948. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  118949. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118950. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  118951. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  118952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118960. 0,
  118961. };
  118962. static float _vq_quantthresh__44c7_s_p4_0[] = {
  118963. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118964. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118965. };
  118966. static long _vq_quantmap__44c7_s_p4_0[] = {
  118967. 15, 13, 11, 9, 7, 5, 3, 1,
  118968. 0, 2, 4, 6, 8, 10, 12, 14,
  118969. 16,
  118970. };
  118971. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  118972. _vq_quantthresh__44c7_s_p4_0,
  118973. _vq_quantmap__44c7_s_p4_0,
  118974. 17,
  118975. 17
  118976. };
  118977. static static_codebook _44c7_s_p4_0 = {
  118978. 2, 289,
  118979. _vq_lengthlist__44c7_s_p4_0,
  118980. 1, -529530880, 1611661312, 5, 0,
  118981. _vq_quantlist__44c7_s_p4_0,
  118982. NULL,
  118983. &_vq_auxt__44c7_s_p4_0,
  118984. NULL,
  118985. 0
  118986. };
  118987. static long _vq_quantlist__44c7_s_p5_0[] = {
  118988. 1,
  118989. 0,
  118990. 2,
  118991. };
  118992. static long _vq_lengthlist__44c7_s_p5_0[] = {
  118993. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  118994. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  118995. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  118996. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118997. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  118998. 12,
  118999. };
  119000. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119001. -5.5, 5.5,
  119002. };
  119003. static long _vq_quantmap__44c7_s_p5_0[] = {
  119004. 1, 0, 2,
  119005. };
  119006. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119007. _vq_quantthresh__44c7_s_p5_0,
  119008. _vq_quantmap__44c7_s_p5_0,
  119009. 3,
  119010. 3
  119011. };
  119012. static static_codebook _44c7_s_p5_0 = {
  119013. 4, 81,
  119014. _vq_lengthlist__44c7_s_p5_0,
  119015. 1, -529137664, 1618345984, 2, 0,
  119016. _vq_quantlist__44c7_s_p5_0,
  119017. NULL,
  119018. &_vq_auxt__44c7_s_p5_0,
  119019. NULL,
  119020. 0
  119021. };
  119022. static long _vq_quantlist__44c7_s_p5_1[] = {
  119023. 5,
  119024. 4,
  119025. 6,
  119026. 3,
  119027. 7,
  119028. 2,
  119029. 8,
  119030. 1,
  119031. 9,
  119032. 0,
  119033. 10,
  119034. };
  119035. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119036. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119037. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119038. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119039. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119040. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119041. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119042. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119043. 11,11,11, 7, 7, 8, 8, 8, 8,
  119044. };
  119045. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119046. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119047. 3.5, 4.5,
  119048. };
  119049. static long _vq_quantmap__44c7_s_p5_1[] = {
  119050. 9, 7, 5, 3, 1, 0, 2, 4,
  119051. 6, 8, 10,
  119052. };
  119053. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119054. _vq_quantthresh__44c7_s_p5_1,
  119055. _vq_quantmap__44c7_s_p5_1,
  119056. 11,
  119057. 11
  119058. };
  119059. static static_codebook _44c7_s_p5_1 = {
  119060. 2, 121,
  119061. _vq_lengthlist__44c7_s_p5_1,
  119062. 1, -531365888, 1611661312, 4, 0,
  119063. _vq_quantlist__44c7_s_p5_1,
  119064. NULL,
  119065. &_vq_auxt__44c7_s_p5_1,
  119066. NULL,
  119067. 0
  119068. };
  119069. static long _vq_quantlist__44c7_s_p6_0[] = {
  119070. 6,
  119071. 5,
  119072. 7,
  119073. 4,
  119074. 8,
  119075. 3,
  119076. 9,
  119077. 2,
  119078. 10,
  119079. 1,
  119080. 11,
  119081. 0,
  119082. 12,
  119083. };
  119084. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119085. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119086. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119087. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119088. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119089. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119090. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119095. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119096. };
  119097. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119098. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119099. 12.5, 17.5, 22.5, 27.5,
  119100. };
  119101. static long _vq_quantmap__44c7_s_p6_0[] = {
  119102. 11, 9, 7, 5, 3, 1, 0, 2,
  119103. 4, 6, 8, 10, 12,
  119104. };
  119105. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119106. _vq_quantthresh__44c7_s_p6_0,
  119107. _vq_quantmap__44c7_s_p6_0,
  119108. 13,
  119109. 13
  119110. };
  119111. static static_codebook _44c7_s_p6_0 = {
  119112. 2, 169,
  119113. _vq_lengthlist__44c7_s_p6_0,
  119114. 1, -526516224, 1616117760, 4, 0,
  119115. _vq_quantlist__44c7_s_p6_0,
  119116. NULL,
  119117. &_vq_auxt__44c7_s_p6_0,
  119118. NULL,
  119119. 0
  119120. };
  119121. static long _vq_quantlist__44c7_s_p6_1[] = {
  119122. 2,
  119123. 1,
  119124. 3,
  119125. 0,
  119126. 4,
  119127. };
  119128. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119129. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119130. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119131. };
  119132. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119133. -1.5, -0.5, 0.5, 1.5,
  119134. };
  119135. static long _vq_quantmap__44c7_s_p6_1[] = {
  119136. 3, 1, 0, 2, 4,
  119137. };
  119138. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119139. _vq_quantthresh__44c7_s_p6_1,
  119140. _vq_quantmap__44c7_s_p6_1,
  119141. 5,
  119142. 5
  119143. };
  119144. static static_codebook _44c7_s_p6_1 = {
  119145. 2, 25,
  119146. _vq_lengthlist__44c7_s_p6_1,
  119147. 1, -533725184, 1611661312, 3, 0,
  119148. _vq_quantlist__44c7_s_p6_1,
  119149. NULL,
  119150. &_vq_auxt__44c7_s_p6_1,
  119151. NULL,
  119152. 0
  119153. };
  119154. static long _vq_quantlist__44c7_s_p7_0[] = {
  119155. 6,
  119156. 5,
  119157. 7,
  119158. 4,
  119159. 8,
  119160. 3,
  119161. 9,
  119162. 2,
  119163. 10,
  119164. 1,
  119165. 11,
  119166. 0,
  119167. 12,
  119168. };
  119169. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119170. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119171. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119172. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119173. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119174. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119175. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119176. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119177. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119178. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119179. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119180. 19,13,13,13,13,14,14,15,15,
  119181. };
  119182. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119183. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119184. 27.5, 38.5, 49.5, 60.5,
  119185. };
  119186. static long _vq_quantmap__44c7_s_p7_0[] = {
  119187. 11, 9, 7, 5, 3, 1, 0, 2,
  119188. 4, 6, 8, 10, 12,
  119189. };
  119190. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119191. _vq_quantthresh__44c7_s_p7_0,
  119192. _vq_quantmap__44c7_s_p7_0,
  119193. 13,
  119194. 13
  119195. };
  119196. static static_codebook _44c7_s_p7_0 = {
  119197. 2, 169,
  119198. _vq_lengthlist__44c7_s_p7_0,
  119199. 1, -523206656, 1618345984, 4, 0,
  119200. _vq_quantlist__44c7_s_p7_0,
  119201. NULL,
  119202. &_vq_auxt__44c7_s_p7_0,
  119203. NULL,
  119204. 0
  119205. };
  119206. static long _vq_quantlist__44c7_s_p7_1[] = {
  119207. 5,
  119208. 4,
  119209. 6,
  119210. 3,
  119211. 7,
  119212. 2,
  119213. 8,
  119214. 1,
  119215. 9,
  119216. 0,
  119217. 10,
  119218. };
  119219. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119220. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119221. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119222. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119223. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119224. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119225. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119226. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119227. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119228. };
  119229. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119230. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119231. 3.5, 4.5,
  119232. };
  119233. static long _vq_quantmap__44c7_s_p7_1[] = {
  119234. 9, 7, 5, 3, 1, 0, 2, 4,
  119235. 6, 8, 10,
  119236. };
  119237. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119238. _vq_quantthresh__44c7_s_p7_1,
  119239. _vq_quantmap__44c7_s_p7_1,
  119240. 11,
  119241. 11
  119242. };
  119243. static static_codebook _44c7_s_p7_1 = {
  119244. 2, 121,
  119245. _vq_lengthlist__44c7_s_p7_1,
  119246. 1, -531365888, 1611661312, 4, 0,
  119247. _vq_quantlist__44c7_s_p7_1,
  119248. NULL,
  119249. &_vq_auxt__44c7_s_p7_1,
  119250. NULL,
  119251. 0
  119252. };
  119253. static long _vq_quantlist__44c7_s_p8_0[] = {
  119254. 7,
  119255. 6,
  119256. 8,
  119257. 5,
  119258. 9,
  119259. 4,
  119260. 10,
  119261. 3,
  119262. 11,
  119263. 2,
  119264. 12,
  119265. 1,
  119266. 13,
  119267. 0,
  119268. 14,
  119269. };
  119270. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119271. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119272. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119273. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119274. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119275. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119276. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119277. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119278. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119279. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119280. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119281. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119282. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119283. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119284. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119285. 14,
  119286. };
  119287. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119288. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119289. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119290. };
  119291. static long _vq_quantmap__44c7_s_p8_0[] = {
  119292. 13, 11, 9, 7, 5, 3, 1, 0,
  119293. 2, 4, 6, 8, 10, 12, 14,
  119294. };
  119295. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119296. _vq_quantthresh__44c7_s_p8_0,
  119297. _vq_quantmap__44c7_s_p8_0,
  119298. 15,
  119299. 15
  119300. };
  119301. static static_codebook _44c7_s_p8_0 = {
  119302. 2, 225,
  119303. _vq_lengthlist__44c7_s_p8_0,
  119304. 1, -520986624, 1620377600, 4, 0,
  119305. _vq_quantlist__44c7_s_p8_0,
  119306. NULL,
  119307. &_vq_auxt__44c7_s_p8_0,
  119308. NULL,
  119309. 0
  119310. };
  119311. static long _vq_quantlist__44c7_s_p8_1[] = {
  119312. 10,
  119313. 9,
  119314. 11,
  119315. 8,
  119316. 12,
  119317. 7,
  119318. 13,
  119319. 6,
  119320. 14,
  119321. 5,
  119322. 15,
  119323. 4,
  119324. 16,
  119325. 3,
  119326. 17,
  119327. 2,
  119328. 18,
  119329. 1,
  119330. 19,
  119331. 0,
  119332. 20,
  119333. };
  119334. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119335. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119336. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119337. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119338. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119339. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119340. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119341. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119342. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119343. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119344. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119345. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119346. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119347. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119348. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119349. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119350. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119351. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119352. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119353. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119354. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119355. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119356. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119357. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119358. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119359. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119360. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119361. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119362. 10,10,10,10,10,10,10,10,10,
  119363. };
  119364. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119365. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119366. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119367. 6.5, 7.5, 8.5, 9.5,
  119368. };
  119369. static long _vq_quantmap__44c7_s_p8_1[] = {
  119370. 19, 17, 15, 13, 11, 9, 7, 5,
  119371. 3, 1, 0, 2, 4, 6, 8, 10,
  119372. 12, 14, 16, 18, 20,
  119373. };
  119374. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119375. _vq_quantthresh__44c7_s_p8_1,
  119376. _vq_quantmap__44c7_s_p8_1,
  119377. 21,
  119378. 21
  119379. };
  119380. static static_codebook _44c7_s_p8_1 = {
  119381. 2, 441,
  119382. _vq_lengthlist__44c7_s_p8_1,
  119383. 1, -529268736, 1611661312, 5, 0,
  119384. _vq_quantlist__44c7_s_p8_1,
  119385. NULL,
  119386. &_vq_auxt__44c7_s_p8_1,
  119387. NULL,
  119388. 0
  119389. };
  119390. static long _vq_quantlist__44c7_s_p9_0[] = {
  119391. 6,
  119392. 5,
  119393. 7,
  119394. 4,
  119395. 8,
  119396. 3,
  119397. 9,
  119398. 2,
  119399. 10,
  119400. 1,
  119401. 11,
  119402. 0,
  119403. 12,
  119404. };
  119405. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119406. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119407. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119408. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119409. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119410. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119411. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119412. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119413. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119414. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119415. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119416. 11,11,11,11,11,11,11,11,11,
  119417. };
  119418. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119419. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119420. 1592.5, 2229.5, 2866.5, 3503.5,
  119421. };
  119422. static long _vq_quantmap__44c7_s_p9_0[] = {
  119423. 11, 9, 7, 5, 3, 1, 0, 2,
  119424. 4, 6, 8, 10, 12,
  119425. };
  119426. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119427. _vq_quantthresh__44c7_s_p9_0,
  119428. _vq_quantmap__44c7_s_p9_0,
  119429. 13,
  119430. 13
  119431. };
  119432. static static_codebook _44c7_s_p9_0 = {
  119433. 2, 169,
  119434. _vq_lengthlist__44c7_s_p9_0,
  119435. 1, -511845376, 1630791680, 4, 0,
  119436. _vq_quantlist__44c7_s_p9_0,
  119437. NULL,
  119438. &_vq_auxt__44c7_s_p9_0,
  119439. NULL,
  119440. 0
  119441. };
  119442. static long _vq_quantlist__44c7_s_p9_1[] = {
  119443. 6,
  119444. 5,
  119445. 7,
  119446. 4,
  119447. 8,
  119448. 3,
  119449. 9,
  119450. 2,
  119451. 10,
  119452. 1,
  119453. 11,
  119454. 0,
  119455. 12,
  119456. };
  119457. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119458. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119459. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119460. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119461. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119462. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119463. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119464. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119465. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119466. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119467. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119468. 15,11,11,10,10,12,12,12,12,
  119469. };
  119470. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119471. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119472. 122.5, 171.5, 220.5, 269.5,
  119473. };
  119474. static long _vq_quantmap__44c7_s_p9_1[] = {
  119475. 11, 9, 7, 5, 3, 1, 0, 2,
  119476. 4, 6, 8, 10, 12,
  119477. };
  119478. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119479. _vq_quantthresh__44c7_s_p9_1,
  119480. _vq_quantmap__44c7_s_p9_1,
  119481. 13,
  119482. 13
  119483. };
  119484. static static_codebook _44c7_s_p9_1 = {
  119485. 2, 169,
  119486. _vq_lengthlist__44c7_s_p9_1,
  119487. 1, -518889472, 1622704128, 4, 0,
  119488. _vq_quantlist__44c7_s_p9_1,
  119489. NULL,
  119490. &_vq_auxt__44c7_s_p9_1,
  119491. NULL,
  119492. 0
  119493. };
  119494. static long _vq_quantlist__44c7_s_p9_2[] = {
  119495. 24,
  119496. 23,
  119497. 25,
  119498. 22,
  119499. 26,
  119500. 21,
  119501. 27,
  119502. 20,
  119503. 28,
  119504. 19,
  119505. 29,
  119506. 18,
  119507. 30,
  119508. 17,
  119509. 31,
  119510. 16,
  119511. 32,
  119512. 15,
  119513. 33,
  119514. 14,
  119515. 34,
  119516. 13,
  119517. 35,
  119518. 12,
  119519. 36,
  119520. 11,
  119521. 37,
  119522. 10,
  119523. 38,
  119524. 9,
  119525. 39,
  119526. 8,
  119527. 40,
  119528. 7,
  119529. 41,
  119530. 6,
  119531. 42,
  119532. 5,
  119533. 43,
  119534. 4,
  119535. 44,
  119536. 3,
  119537. 45,
  119538. 2,
  119539. 46,
  119540. 1,
  119541. 47,
  119542. 0,
  119543. 48,
  119544. };
  119545. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119546. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119547. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119548. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119549. 7,
  119550. };
  119551. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119552. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119553. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119554. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119555. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119556. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119557. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119558. };
  119559. static long _vq_quantmap__44c7_s_p9_2[] = {
  119560. 47, 45, 43, 41, 39, 37, 35, 33,
  119561. 31, 29, 27, 25, 23, 21, 19, 17,
  119562. 15, 13, 11, 9, 7, 5, 3, 1,
  119563. 0, 2, 4, 6, 8, 10, 12, 14,
  119564. 16, 18, 20, 22, 24, 26, 28, 30,
  119565. 32, 34, 36, 38, 40, 42, 44, 46,
  119566. 48,
  119567. };
  119568. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119569. _vq_quantthresh__44c7_s_p9_2,
  119570. _vq_quantmap__44c7_s_p9_2,
  119571. 49,
  119572. 49
  119573. };
  119574. static static_codebook _44c7_s_p9_2 = {
  119575. 1, 49,
  119576. _vq_lengthlist__44c7_s_p9_2,
  119577. 1, -526909440, 1611661312, 6, 0,
  119578. _vq_quantlist__44c7_s_p9_2,
  119579. NULL,
  119580. &_vq_auxt__44c7_s_p9_2,
  119581. NULL,
  119582. 0
  119583. };
  119584. static long _huff_lengthlist__44c7_s_short[] = {
  119585. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119586. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119587. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119588. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119589. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119590. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119591. 10, 9,11,14,
  119592. };
  119593. static static_codebook _huff_book__44c7_s_short = {
  119594. 2, 100,
  119595. _huff_lengthlist__44c7_s_short,
  119596. 0, 0, 0, 0, 0,
  119597. NULL,
  119598. NULL,
  119599. NULL,
  119600. NULL,
  119601. 0
  119602. };
  119603. static long _huff_lengthlist__44c8_s_long[] = {
  119604. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119605. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119606. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119607. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119608. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119609. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119610. 11, 9, 9,10,
  119611. };
  119612. static static_codebook _huff_book__44c8_s_long = {
  119613. 2, 100,
  119614. _huff_lengthlist__44c8_s_long,
  119615. 0, 0, 0, 0, 0,
  119616. NULL,
  119617. NULL,
  119618. NULL,
  119619. NULL,
  119620. 0
  119621. };
  119622. static long _vq_quantlist__44c8_s_p1_0[] = {
  119623. 1,
  119624. 0,
  119625. 2,
  119626. };
  119627. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119628. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119629. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119630. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119631. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119632. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119633. 8,
  119634. };
  119635. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119636. -0.5, 0.5,
  119637. };
  119638. static long _vq_quantmap__44c8_s_p1_0[] = {
  119639. 1, 0, 2,
  119640. };
  119641. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119642. _vq_quantthresh__44c8_s_p1_0,
  119643. _vq_quantmap__44c8_s_p1_0,
  119644. 3,
  119645. 3
  119646. };
  119647. static static_codebook _44c8_s_p1_0 = {
  119648. 4, 81,
  119649. _vq_lengthlist__44c8_s_p1_0,
  119650. 1, -535822336, 1611661312, 2, 0,
  119651. _vq_quantlist__44c8_s_p1_0,
  119652. NULL,
  119653. &_vq_auxt__44c8_s_p1_0,
  119654. NULL,
  119655. 0
  119656. };
  119657. static long _vq_quantlist__44c8_s_p2_0[] = {
  119658. 2,
  119659. 1,
  119660. 3,
  119661. 0,
  119662. 4,
  119663. };
  119664. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119665. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119666. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119667. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119668. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119669. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119670. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119671. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119672. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119674. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119675. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119676. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119677. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119678. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119679. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119680. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119682. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119683. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119684. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119685. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119686. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119687. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119688. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119690. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119691. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119692. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119693. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119694. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119695. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119696. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119701. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119702. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119703. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119704. 13,
  119705. };
  119706. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119707. -1.5, -0.5, 0.5, 1.5,
  119708. };
  119709. static long _vq_quantmap__44c8_s_p2_0[] = {
  119710. 3, 1, 0, 2, 4,
  119711. };
  119712. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119713. _vq_quantthresh__44c8_s_p2_0,
  119714. _vq_quantmap__44c8_s_p2_0,
  119715. 5,
  119716. 5
  119717. };
  119718. static static_codebook _44c8_s_p2_0 = {
  119719. 4, 625,
  119720. _vq_lengthlist__44c8_s_p2_0,
  119721. 1, -533725184, 1611661312, 3, 0,
  119722. _vq_quantlist__44c8_s_p2_0,
  119723. NULL,
  119724. &_vq_auxt__44c8_s_p2_0,
  119725. NULL,
  119726. 0
  119727. };
  119728. static long _vq_quantlist__44c8_s_p3_0[] = {
  119729. 4,
  119730. 3,
  119731. 5,
  119732. 2,
  119733. 6,
  119734. 1,
  119735. 7,
  119736. 0,
  119737. 8,
  119738. };
  119739. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119740. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119741. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119742. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119743. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119745. 0,
  119746. };
  119747. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119748. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119749. };
  119750. static long _vq_quantmap__44c8_s_p3_0[] = {
  119751. 7, 5, 3, 1, 0, 2, 4, 6,
  119752. 8,
  119753. };
  119754. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119755. _vq_quantthresh__44c8_s_p3_0,
  119756. _vq_quantmap__44c8_s_p3_0,
  119757. 9,
  119758. 9
  119759. };
  119760. static static_codebook _44c8_s_p3_0 = {
  119761. 2, 81,
  119762. _vq_lengthlist__44c8_s_p3_0,
  119763. 1, -531628032, 1611661312, 4, 0,
  119764. _vq_quantlist__44c8_s_p3_0,
  119765. NULL,
  119766. &_vq_auxt__44c8_s_p3_0,
  119767. NULL,
  119768. 0
  119769. };
  119770. static long _vq_quantlist__44c8_s_p4_0[] = {
  119771. 8,
  119772. 7,
  119773. 9,
  119774. 6,
  119775. 10,
  119776. 5,
  119777. 11,
  119778. 4,
  119779. 12,
  119780. 3,
  119781. 13,
  119782. 2,
  119783. 14,
  119784. 1,
  119785. 15,
  119786. 0,
  119787. 16,
  119788. };
  119789. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119790. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119791. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119792. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119793. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119794. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119795. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119796. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119797. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119798. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119799. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119808. 0,
  119809. };
  119810. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119811. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119812. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119813. };
  119814. static long _vq_quantmap__44c8_s_p4_0[] = {
  119815. 15, 13, 11, 9, 7, 5, 3, 1,
  119816. 0, 2, 4, 6, 8, 10, 12, 14,
  119817. 16,
  119818. };
  119819. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119820. _vq_quantthresh__44c8_s_p4_0,
  119821. _vq_quantmap__44c8_s_p4_0,
  119822. 17,
  119823. 17
  119824. };
  119825. static static_codebook _44c8_s_p4_0 = {
  119826. 2, 289,
  119827. _vq_lengthlist__44c8_s_p4_0,
  119828. 1, -529530880, 1611661312, 5, 0,
  119829. _vq_quantlist__44c8_s_p4_0,
  119830. NULL,
  119831. &_vq_auxt__44c8_s_p4_0,
  119832. NULL,
  119833. 0
  119834. };
  119835. static long _vq_quantlist__44c8_s_p5_0[] = {
  119836. 1,
  119837. 0,
  119838. 2,
  119839. };
  119840. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119841. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119842. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119843. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119844. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119845. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119846. 12,
  119847. };
  119848. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119849. -5.5, 5.5,
  119850. };
  119851. static long _vq_quantmap__44c8_s_p5_0[] = {
  119852. 1, 0, 2,
  119853. };
  119854. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119855. _vq_quantthresh__44c8_s_p5_0,
  119856. _vq_quantmap__44c8_s_p5_0,
  119857. 3,
  119858. 3
  119859. };
  119860. static static_codebook _44c8_s_p5_0 = {
  119861. 4, 81,
  119862. _vq_lengthlist__44c8_s_p5_0,
  119863. 1, -529137664, 1618345984, 2, 0,
  119864. _vq_quantlist__44c8_s_p5_0,
  119865. NULL,
  119866. &_vq_auxt__44c8_s_p5_0,
  119867. NULL,
  119868. 0
  119869. };
  119870. static long _vq_quantlist__44c8_s_p5_1[] = {
  119871. 5,
  119872. 4,
  119873. 6,
  119874. 3,
  119875. 7,
  119876. 2,
  119877. 8,
  119878. 1,
  119879. 9,
  119880. 0,
  119881. 10,
  119882. };
  119883. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119884. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119885. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119886. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119887. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119888. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119889. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119890. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119891. 11,11,11, 7, 7, 7, 7, 8, 8,
  119892. };
  119893. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119894. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119895. 3.5, 4.5,
  119896. };
  119897. static long _vq_quantmap__44c8_s_p5_1[] = {
  119898. 9, 7, 5, 3, 1, 0, 2, 4,
  119899. 6, 8, 10,
  119900. };
  119901. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119902. _vq_quantthresh__44c8_s_p5_1,
  119903. _vq_quantmap__44c8_s_p5_1,
  119904. 11,
  119905. 11
  119906. };
  119907. static static_codebook _44c8_s_p5_1 = {
  119908. 2, 121,
  119909. _vq_lengthlist__44c8_s_p5_1,
  119910. 1, -531365888, 1611661312, 4, 0,
  119911. _vq_quantlist__44c8_s_p5_1,
  119912. NULL,
  119913. &_vq_auxt__44c8_s_p5_1,
  119914. NULL,
  119915. 0
  119916. };
  119917. static long _vq_quantlist__44c8_s_p6_0[] = {
  119918. 6,
  119919. 5,
  119920. 7,
  119921. 4,
  119922. 8,
  119923. 3,
  119924. 9,
  119925. 2,
  119926. 10,
  119927. 1,
  119928. 11,
  119929. 0,
  119930. 12,
  119931. };
  119932. static long _vq_lengthlist__44c8_s_p6_0[] = {
  119933. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  119934. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  119935. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  119936. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  119937. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  119938. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  119939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119943. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119944. };
  119945. static float _vq_quantthresh__44c8_s_p6_0[] = {
  119946. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119947. 12.5, 17.5, 22.5, 27.5,
  119948. };
  119949. static long _vq_quantmap__44c8_s_p6_0[] = {
  119950. 11, 9, 7, 5, 3, 1, 0, 2,
  119951. 4, 6, 8, 10, 12,
  119952. };
  119953. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  119954. _vq_quantthresh__44c8_s_p6_0,
  119955. _vq_quantmap__44c8_s_p6_0,
  119956. 13,
  119957. 13
  119958. };
  119959. static static_codebook _44c8_s_p6_0 = {
  119960. 2, 169,
  119961. _vq_lengthlist__44c8_s_p6_0,
  119962. 1, -526516224, 1616117760, 4, 0,
  119963. _vq_quantlist__44c8_s_p6_0,
  119964. NULL,
  119965. &_vq_auxt__44c8_s_p6_0,
  119966. NULL,
  119967. 0
  119968. };
  119969. static long _vq_quantlist__44c8_s_p6_1[] = {
  119970. 2,
  119971. 1,
  119972. 3,
  119973. 0,
  119974. 4,
  119975. };
  119976. static long _vq_lengthlist__44c8_s_p6_1[] = {
  119977. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119978. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119979. };
  119980. static float _vq_quantthresh__44c8_s_p6_1[] = {
  119981. -1.5, -0.5, 0.5, 1.5,
  119982. };
  119983. static long _vq_quantmap__44c8_s_p6_1[] = {
  119984. 3, 1, 0, 2, 4,
  119985. };
  119986. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  119987. _vq_quantthresh__44c8_s_p6_1,
  119988. _vq_quantmap__44c8_s_p6_1,
  119989. 5,
  119990. 5
  119991. };
  119992. static static_codebook _44c8_s_p6_1 = {
  119993. 2, 25,
  119994. _vq_lengthlist__44c8_s_p6_1,
  119995. 1, -533725184, 1611661312, 3, 0,
  119996. _vq_quantlist__44c8_s_p6_1,
  119997. NULL,
  119998. &_vq_auxt__44c8_s_p6_1,
  119999. NULL,
  120000. 0
  120001. };
  120002. static long _vq_quantlist__44c8_s_p7_0[] = {
  120003. 6,
  120004. 5,
  120005. 7,
  120006. 4,
  120007. 8,
  120008. 3,
  120009. 9,
  120010. 2,
  120011. 10,
  120012. 1,
  120013. 11,
  120014. 0,
  120015. 12,
  120016. };
  120017. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120018. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120019. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120020. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120021. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120022. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120023. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120024. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120025. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120026. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120027. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120028. 20,13,13,13,13,14,13,15,15,
  120029. };
  120030. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120031. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120032. 27.5, 38.5, 49.5, 60.5,
  120033. };
  120034. static long _vq_quantmap__44c8_s_p7_0[] = {
  120035. 11, 9, 7, 5, 3, 1, 0, 2,
  120036. 4, 6, 8, 10, 12,
  120037. };
  120038. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120039. _vq_quantthresh__44c8_s_p7_0,
  120040. _vq_quantmap__44c8_s_p7_0,
  120041. 13,
  120042. 13
  120043. };
  120044. static static_codebook _44c8_s_p7_0 = {
  120045. 2, 169,
  120046. _vq_lengthlist__44c8_s_p7_0,
  120047. 1, -523206656, 1618345984, 4, 0,
  120048. _vq_quantlist__44c8_s_p7_0,
  120049. NULL,
  120050. &_vq_auxt__44c8_s_p7_0,
  120051. NULL,
  120052. 0
  120053. };
  120054. static long _vq_quantlist__44c8_s_p7_1[] = {
  120055. 5,
  120056. 4,
  120057. 6,
  120058. 3,
  120059. 7,
  120060. 2,
  120061. 8,
  120062. 1,
  120063. 9,
  120064. 0,
  120065. 10,
  120066. };
  120067. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120068. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120069. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120070. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120071. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120072. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120073. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120074. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120075. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120076. };
  120077. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120078. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120079. 3.5, 4.5,
  120080. };
  120081. static long _vq_quantmap__44c8_s_p7_1[] = {
  120082. 9, 7, 5, 3, 1, 0, 2, 4,
  120083. 6, 8, 10,
  120084. };
  120085. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120086. _vq_quantthresh__44c8_s_p7_1,
  120087. _vq_quantmap__44c8_s_p7_1,
  120088. 11,
  120089. 11
  120090. };
  120091. static static_codebook _44c8_s_p7_1 = {
  120092. 2, 121,
  120093. _vq_lengthlist__44c8_s_p7_1,
  120094. 1, -531365888, 1611661312, 4, 0,
  120095. _vq_quantlist__44c8_s_p7_1,
  120096. NULL,
  120097. &_vq_auxt__44c8_s_p7_1,
  120098. NULL,
  120099. 0
  120100. };
  120101. static long _vq_quantlist__44c8_s_p8_0[] = {
  120102. 7,
  120103. 6,
  120104. 8,
  120105. 5,
  120106. 9,
  120107. 4,
  120108. 10,
  120109. 3,
  120110. 11,
  120111. 2,
  120112. 12,
  120113. 1,
  120114. 13,
  120115. 0,
  120116. 14,
  120117. };
  120118. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120119. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120120. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120121. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120122. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120123. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120124. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120125. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120126. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120127. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120128. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120129. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120130. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120131. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120132. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120133. 15,
  120134. };
  120135. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120136. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120137. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120138. };
  120139. static long _vq_quantmap__44c8_s_p8_0[] = {
  120140. 13, 11, 9, 7, 5, 3, 1, 0,
  120141. 2, 4, 6, 8, 10, 12, 14,
  120142. };
  120143. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120144. _vq_quantthresh__44c8_s_p8_0,
  120145. _vq_quantmap__44c8_s_p8_0,
  120146. 15,
  120147. 15
  120148. };
  120149. static static_codebook _44c8_s_p8_0 = {
  120150. 2, 225,
  120151. _vq_lengthlist__44c8_s_p8_0,
  120152. 1, -520986624, 1620377600, 4, 0,
  120153. _vq_quantlist__44c8_s_p8_0,
  120154. NULL,
  120155. &_vq_auxt__44c8_s_p8_0,
  120156. NULL,
  120157. 0
  120158. };
  120159. static long _vq_quantlist__44c8_s_p8_1[] = {
  120160. 10,
  120161. 9,
  120162. 11,
  120163. 8,
  120164. 12,
  120165. 7,
  120166. 13,
  120167. 6,
  120168. 14,
  120169. 5,
  120170. 15,
  120171. 4,
  120172. 16,
  120173. 3,
  120174. 17,
  120175. 2,
  120176. 18,
  120177. 1,
  120178. 19,
  120179. 0,
  120180. 20,
  120181. };
  120182. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120183. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120184. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120185. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120186. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120187. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120188. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120189. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120190. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120191. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120192. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120193. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120194. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120195. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120196. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120197. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120198. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120199. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120200. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120201. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120202. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120203. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120204. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120205. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120206. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120207. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120208. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120209. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120210. 10, 9, 9,10,10, 9,10, 9, 9,
  120211. };
  120212. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120213. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120214. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120215. 6.5, 7.5, 8.5, 9.5,
  120216. };
  120217. static long _vq_quantmap__44c8_s_p8_1[] = {
  120218. 19, 17, 15, 13, 11, 9, 7, 5,
  120219. 3, 1, 0, 2, 4, 6, 8, 10,
  120220. 12, 14, 16, 18, 20,
  120221. };
  120222. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120223. _vq_quantthresh__44c8_s_p8_1,
  120224. _vq_quantmap__44c8_s_p8_1,
  120225. 21,
  120226. 21
  120227. };
  120228. static static_codebook _44c8_s_p8_1 = {
  120229. 2, 441,
  120230. _vq_lengthlist__44c8_s_p8_1,
  120231. 1, -529268736, 1611661312, 5, 0,
  120232. _vq_quantlist__44c8_s_p8_1,
  120233. NULL,
  120234. &_vq_auxt__44c8_s_p8_1,
  120235. NULL,
  120236. 0
  120237. };
  120238. static long _vq_quantlist__44c8_s_p9_0[] = {
  120239. 8,
  120240. 7,
  120241. 9,
  120242. 6,
  120243. 10,
  120244. 5,
  120245. 11,
  120246. 4,
  120247. 12,
  120248. 3,
  120249. 13,
  120250. 2,
  120251. 14,
  120252. 1,
  120253. 15,
  120254. 0,
  120255. 16,
  120256. };
  120257. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120258. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120259. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120260. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120262. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120264. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120265. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120266. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120267. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120268. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120269. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120270. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120271. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120272. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120273. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120274. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120275. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120276. 10,
  120277. };
  120278. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120279. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120280. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120281. };
  120282. static long _vq_quantmap__44c8_s_p9_0[] = {
  120283. 15, 13, 11, 9, 7, 5, 3, 1,
  120284. 0, 2, 4, 6, 8, 10, 12, 14,
  120285. 16,
  120286. };
  120287. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120288. _vq_quantthresh__44c8_s_p9_0,
  120289. _vq_quantmap__44c8_s_p9_0,
  120290. 17,
  120291. 17
  120292. };
  120293. static static_codebook _44c8_s_p9_0 = {
  120294. 2, 289,
  120295. _vq_lengthlist__44c8_s_p9_0,
  120296. 1, -509798400, 1631393792, 5, 0,
  120297. _vq_quantlist__44c8_s_p9_0,
  120298. NULL,
  120299. &_vq_auxt__44c8_s_p9_0,
  120300. NULL,
  120301. 0
  120302. };
  120303. static long _vq_quantlist__44c8_s_p9_1[] = {
  120304. 9,
  120305. 8,
  120306. 10,
  120307. 7,
  120308. 11,
  120309. 6,
  120310. 12,
  120311. 5,
  120312. 13,
  120313. 4,
  120314. 14,
  120315. 3,
  120316. 15,
  120317. 2,
  120318. 16,
  120319. 1,
  120320. 17,
  120321. 0,
  120322. 18,
  120323. };
  120324. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120325. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120326. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120327. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120328. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120329. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120330. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120331. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120332. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120333. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120334. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120335. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120336. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120337. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120338. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120339. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120340. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120341. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120342. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120343. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120344. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120345. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120346. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120347. 14,13,13,14,14,15,14,15,14,
  120348. };
  120349. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120350. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120351. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120352. 367.5, 416.5,
  120353. };
  120354. static long _vq_quantmap__44c8_s_p9_1[] = {
  120355. 17, 15, 13, 11, 9, 7, 5, 3,
  120356. 1, 0, 2, 4, 6, 8, 10, 12,
  120357. 14, 16, 18,
  120358. };
  120359. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120360. _vq_quantthresh__44c8_s_p9_1,
  120361. _vq_quantmap__44c8_s_p9_1,
  120362. 19,
  120363. 19
  120364. };
  120365. static static_codebook _44c8_s_p9_1 = {
  120366. 2, 361,
  120367. _vq_lengthlist__44c8_s_p9_1,
  120368. 1, -518287360, 1622704128, 5, 0,
  120369. _vq_quantlist__44c8_s_p9_1,
  120370. NULL,
  120371. &_vq_auxt__44c8_s_p9_1,
  120372. NULL,
  120373. 0
  120374. };
  120375. static long _vq_quantlist__44c8_s_p9_2[] = {
  120376. 24,
  120377. 23,
  120378. 25,
  120379. 22,
  120380. 26,
  120381. 21,
  120382. 27,
  120383. 20,
  120384. 28,
  120385. 19,
  120386. 29,
  120387. 18,
  120388. 30,
  120389. 17,
  120390. 31,
  120391. 16,
  120392. 32,
  120393. 15,
  120394. 33,
  120395. 14,
  120396. 34,
  120397. 13,
  120398. 35,
  120399. 12,
  120400. 36,
  120401. 11,
  120402. 37,
  120403. 10,
  120404. 38,
  120405. 9,
  120406. 39,
  120407. 8,
  120408. 40,
  120409. 7,
  120410. 41,
  120411. 6,
  120412. 42,
  120413. 5,
  120414. 43,
  120415. 4,
  120416. 44,
  120417. 3,
  120418. 45,
  120419. 2,
  120420. 46,
  120421. 1,
  120422. 47,
  120423. 0,
  120424. 48,
  120425. };
  120426. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120427. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120428. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120429. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120430. 7,
  120431. };
  120432. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120433. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120434. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120435. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120436. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120437. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120438. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120439. };
  120440. static long _vq_quantmap__44c8_s_p9_2[] = {
  120441. 47, 45, 43, 41, 39, 37, 35, 33,
  120442. 31, 29, 27, 25, 23, 21, 19, 17,
  120443. 15, 13, 11, 9, 7, 5, 3, 1,
  120444. 0, 2, 4, 6, 8, 10, 12, 14,
  120445. 16, 18, 20, 22, 24, 26, 28, 30,
  120446. 32, 34, 36, 38, 40, 42, 44, 46,
  120447. 48,
  120448. };
  120449. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120450. _vq_quantthresh__44c8_s_p9_2,
  120451. _vq_quantmap__44c8_s_p9_2,
  120452. 49,
  120453. 49
  120454. };
  120455. static static_codebook _44c8_s_p9_2 = {
  120456. 1, 49,
  120457. _vq_lengthlist__44c8_s_p9_2,
  120458. 1, -526909440, 1611661312, 6, 0,
  120459. _vq_quantlist__44c8_s_p9_2,
  120460. NULL,
  120461. &_vq_auxt__44c8_s_p9_2,
  120462. NULL,
  120463. 0
  120464. };
  120465. static long _huff_lengthlist__44c8_s_short[] = {
  120466. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120467. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120468. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120469. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120470. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120471. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120472. 10, 9,11,14,
  120473. };
  120474. static static_codebook _huff_book__44c8_s_short = {
  120475. 2, 100,
  120476. _huff_lengthlist__44c8_s_short,
  120477. 0, 0, 0, 0, 0,
  120478. NULL,
  120479. NULL,
  120480. NULL,
  120481. NULL,
  120482. 0
  120483. };
  120484. static long _huff_lengthlist__44c9_s_long[] = {
  120485. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120486. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120487. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120488. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120489. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120490. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120491. 10, 9, 8, 9,
  120492. };
  120493. static static_codebook _huff_book__44c9_s_long = {
  120494. 2, 100,
  120495. _huff_lengthlist__44c9_s_long,
  120496. 0, 0, 0, 0, 0,
  120497. NULL,
  120498. NULL,
  120499. NULL,
  120500. NULL,
  120501. 0
  120502. };
  120503. static long _vq_quantlist__44c9_s_p1_0[] = {
  120504. 1,
  120505. 0,
  120506. 2,
  120507. };
  120508. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120509. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120510. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120511. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120512. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120513. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120514. 7,
  120515. };
  120516. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120517. -0.5, 0.5,
  120518. };
  120519. static long _vq_quantmap__44c9_s_p1_0[] = {
  120520. 1, 0, 2,
  120521. };
  120522. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120523. _vq_quantthresh__44c9_s_p1_0,
  120524. _vq_quantmap__44c9_s_p1_0,
  120525. 3,
  120526. 3
  120527. };
  120528. static static_codebook _44c9_s_p1_0 = {
  120529. 4, 81,
  120530. _vq_lengthlist__44c9_s_p1_0,
  120531. 1, -535822336, 1611661312, 2, 0,
  120532. _vq_quantlist__44c9_s_p1_0,
  120533. NULL,
  120534. &_vq_auxt__44c9_s_p1_0,
  120535. NULL,
  120536. 0
  120537. };
  120538. static long _vq_quantlist__44c9_s_p2_0[] = {
  120539. 2,
  120540. 1,
  120541. 3,
  120542. 0,
  120543. 4,
  120544. };
  120545. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120546. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120547. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120548. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120549. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120550. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120551. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120552. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120553. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120555. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120556. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120557. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120558. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120559. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120560. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120561. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120563. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120564. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120565. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120566. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120567. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120568. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120569. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120571. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120572. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120573. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120574. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120575. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120576. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120577. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120582. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120583. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120584. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120585. 12,
  120586. };
  120587. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120588. -1.5, -0.5, 0.5, 1.5,
  120589. };
  120590. static long _vq_quantmap__44c9_s_p2_0[] = {
  120591. 3, 1, 0, 2, 4,
  120592. };
  120593. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120594. _vq_quantthresh__44c9_s_p2_0,
  120595. _vq_quantmap__44c9_s_p2_0,
  120596. 5,
  120597. 5
  120598. };
  120599. static static_codebook _44c9_s_p2_0 = {
  120600. 4, 625,
  120601. _vq_lengthlist__44c9_s_p2_0,
  120602. 1, -533725184, 1611661312, 3, 0,
  120603. _vq_quantlist__44c9_s_p2_0,
  120604. NULL,
  120605. &_vq_auxt__44c9_s_p2_0,
  120606. NULL,
  120607. 0
  120608. };
  120609. static long _vq_quantlist__44c9_s_p3_0[] = {
  120610. 4,
  120611. 3,
  120612. 5,
  120613. 2,
  120614. 6,
  120615. 1,
  120616. 7,
  120617. 0,
  120618. 8,
  120619. };
  120620. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120621. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120622. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120623. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120624. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120626. 0,
  120627. };
  120628. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120629. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120630. };
  120631. static long _vq_quantmap__44c9_s_p3_0[] = {
  120632. 7, 5, 3, 1, 0, 2, 4, 6,
  120633. 8,
  120634. };
  120635. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120636. _vq_quantthresh__44c9_s_p3_0,
  120637. _vq_quantmap__44c9_s_p3_0,
  120638. 9,
  120639. 9
  120640. };
  120641. static static_codebook _44c9_s_p3_0 = {
  120642. 2, 81,
  120643. _vq_lengthlist__44c9_s_p3_0,
  120644. 1, -531628032, 1611661312, 4, 0,
  120645. _vq_quantlist__44c9_s_p3_0,
  120646. NULL,
  120647. &_vq_auxt__44c9_s_p3_0,
  120648. NULL,
  120649. 0
  120650. };
  120651. static long _vq_quantlist__44c9_s_p4_0[] = {
  120652. 8,
  120653. 7,
  120654. 9,
  120655. 6,
  120656. 10,
  120657. 5,
  120658. 11,
  120659. 4,
  120660. 12,
  120661. 3,
  120662. 13,
  120663. 2,
  120664. 14,
  120665. 1,
  120666. 15,
  120667. 0,
  120668. 16,
  120669. };
  120670. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120671. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120672. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120673. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120674. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120675. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120676. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120677. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120678. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120679. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120680. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120689. 0,
  120690. };
  120691. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120692. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120693. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120694. };
  120695. static long _vq_quantmap__44c9_s_p4_0[] = {
  120696. 15, 13, 11, 9, 7, 5, 3, 1,
  120697. 0, 2, 4, 6, 8, 10, 12, 14,
  120698. 16,
  120699. };
  120700. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120701. _vq_quantthresh__44c9_s_p4_0,
  120702. _vq_quantmap__44c9_s_p4_0,
  120703. 17,
  120704. 17
  120705. };
  120706. static static_codebook _44c9_s_p4_0 = {
  120707. 2, 289,
  120708. _vq_lengthlist__44c9_s_p4_0,
  120709. 1, -529530880, 1611661312, 5, 0,
  120710. _vq_quantlist__44c9_s_p4_0,
  120711. NULL,
  120712. &_vq_auxt__44c9_s_p4_0,
  120713. NULL,
  120714. 0
  120715. };
  120716. static long _vq_quantlist__44c9_s_p5_0[] = {
  120717. 1,
  120718. 0,
  120719. 2,
  120720. };
  120721. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120722. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120723. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120724. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120725. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120726. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120727. 12,
  120728. };
  120729. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120730. -5.5, 5.5,
  120731. };
  120732. static long _vq_quantmap__44c9_s_p5_0[] = {
  120733. 1, 0, 2,
  120734. };
  120735. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120736. _vq_quantthresh__44c9_s_p5_0,
  120737. _vq_quantmap__44c9_s_p5_0,
  120738. 3,
  120739. 3
  120740. };
  120741. static static_codebook _44c9_s_p5_0 = {
  120742. 4, 81,
  120743. _vq_lengthlist__44c9_s_p5_0,
  120744. 1, -529137664, 1618345984, 2, 0,
  120745. _vq_quantlist__44c9_s_p5_0,
  120746. NULL,
  120747. &_vq_auxt__44c9_s_p5_0,
  120748. NULL,
  120749. 0
  120750. };
  120751. static long _vq_quantlist__44c9_s_p5_1[] = {
  120752. 5,
  120753. 4,
  120754. 6,
  120755. 3,
  120756. 7,
  120757. 2,
  120758. 8,
  120759. 1,
  120760. 9,
  120761. 0,
  120762. 10,
  120763. };
  120764. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120765. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120766. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120767. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120768. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120769. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120770. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120771. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120772. 11,11,11, 7, 7, 7, 7, 7, 7,
  120773. };
  120774. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120775. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120776. 3.5, 4.5,
  120777. };
  120778. static long _vq_quantmap__44c9_s_p5_1[] = {
  120779. 9, 7, 5, 3, 1, 0, 2, 4,
  120780. 6, 8, 10,
  120781. };
  120782. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120783. _vq_quantthresh__44c9_s_p5_1,
  120784. _vq_quantmap__44c9_s_p5_1,
  120785. 11,
  120786. 11
  120787. };
  120788. static static_codebook _44c9_s_p5_1 = {
  120789. 2, 121,
  120790. _vq_lengthlist__44c9_s_p5_1,
  120791. 1, -531365888, 1611661312, 4, 0,
  120792. _vq_quantlist__44c9_s_p5_1,
  120793. NULL,
  120794. &_vq_auxt__44c9_s_p5_1,
  120795. NULL,
  120796. 0
  120797. };
  120798. static long _vq_quantlist__44c9_s_p6_0[] = {
  120799. 6,
  120800. 5,
  120801. 7,
  120802. 4,
  120803. 8,
  120804. 3,
  120805. 9,
  120806. 2,
  120807. 10,
  120808. 1,
  120809. 11,
  120810. 0,
  120811. 12,
  120812. };
  120813. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120814. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120815. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120816. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120817. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120818. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120819. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120824. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120825. };
  120826. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120827. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120828. 12.5, 17.5, 22.5, 27.5,
  120829. };
  120830. static long _vq_quantmap__44c9_s_p6_0[] = {
  120831. 11, 9, 7, 5, 3, 1, 0, 2,
  120832. 4, 6, 8, 10, 12,
  120833. };
  120834. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120835. _vq_quantthresh__44c9_s_p6_0,
  120836. _vq_quantmap__44c9_s_p6_0,
  120837. 13,
  120838. 13
  120839. };
  120840. static static_codebook _44c9_s_p6_0 = {
  120841. 2, 169,
  120842. _vq_lengthlist__44c9_s_p6_0,
  120843. 1, -526516224, 1616117760, 4, 0,
  120844. _vq_quantlist__44c9_s_p6_0,
  120845. NULL,
  120846. &_vq_auxt__44c9_s_p6_0,
  120847. NULL,
  120848. 0
  120849. };
  120850. static long _vq_quantlist__44c9_s_p6_1[] = {
  120851. 2,
  120852. 1,
  120853. 3,
  120854. 0,
  120855. 4,
  120856. };
  120857. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120858. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120859. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120860. };
  120861. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120862. -1.5, -0.5, 0.5, 1.5,
  120863. };
  120864. static long _vq_quantmap__44c9_s_p6_1[] = {
  120865. 3, 1, 0, 2, 4,
  120866. };
  120867. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120868. _vq_quantthresh__44c9_s_p6_1,
  120869. _vq_quantmap__44c9_s_p6_1,
  120870. 5,
  120871. 5
  120872. };
  120873. static static_codebook _44c9_s_p6_1 = {
  120874. 2, 25,
  120875. _vq_lengthlist__44c9_s_p6_1,
  120876. 1, -533725184, 1611661312, 3, 0,
  120877. _vq_quantlist__44c9_s_p6_1,
  120878. NULL,
  120879. &_vq_auxt__44c9_s_p6_1,
  120880. NULL,
  120881. 0
  120882. };
  120883. static long _vq_quantlist__44c9_s_p7_0[] = {
  120884. 6,
  120885. 5,
  120886. 7,
  120887. 4,
  120888. 8,
  120889. 3,
  120890. 9,
  120891. 2,
  120892. 10,
  120893. 1,
  120894. 11,
  120895. 0,
  120896. 12,
  120897. };
  120898. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120899. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120900. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120901. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120902. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120903. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120904. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120905. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  120906. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  120907. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  120908. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  120909. 19,12,12,12,12,13,13,14,14,
  120910. };
  120911. static float _vq_quantthresh__44c9_s_p7_0[] = {
  120912. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120913. 27.5, 38.5, 49.5, 60.5,
  120914. };
  120915. static long _vq_quantmap__44c9_s_p7_0[] = {
  120916. 11, 9, 7, 5, 3, 1, 0, 2,
  120917. 4, 6, 8, 10, 12,
  120918. };
  120919. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  120920. _vq_quantthresh__44c9_s_p7_0,
  120921. _vq_quantmap__44c9_s_p7_0,
  120922. 13,
  120923. 13
  120924. };
  120925. static static_codebook _44c9_s_p7_0 = {
  120926. 2, 169,
  120927. _vq_lengthlist__44c9_s_p7_0,
  120928. 1, -523206656, 1618345984, 4, 0,
  120929. _vq_quantlist__44c9_s_p7_0,
  120930. NULL,
  120931. &_vq_auxt__44c9_s_p7_0,
  120932. NULL,
  120933. 0
  120934. };
  120935. static long _vq_quantlist__44c9_s_p7_1[] = {
  120936. 5,
  120937. 4,
  120938. 6,
  120939. 3,
  120940. 7,
  120941. 2,
  120942. 8,
  120943. 1,
  120944. 9,
  120945. 0,
  120946. 10,
  120947. };
  120948. static long _vq_lengthlist__44c9_s_p7_1[] = {
  120949. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  120950. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120951. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  120952. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120953. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120954. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120955. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120956. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120957. };
  120958. static float _vq_quantthresh__44c9_s_p7_1[] = {
  120959. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120960. 3.5, 4.5,
  120961. };
  120962. static long _vq_quantmap__44c9_s_p7_1[] = {
  120963. 9, 7, 5, 3, 1, 0, 2, 4,
  120964. 6, 8, 10,
  120965. };
  120966. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  120967. _vq_quantthresh__44c9_s_p7_1,
  120968. _vq_quantmap__44c9_s_p7_1,
  120969. 11,
  120970. 11
  120971. };
  120972. static static_codebook _44c9_s_p7_1 = {
  120973. 2, 121,
  120974. _vq_lengthlist__44c9_s_p7_1,
  120975. 1, -531365888, 1611661312, 4, 0,
  120976. _vq_quantlist__44c9_s_p7_1,
  120977. NULL,
  120978. &_vq_auxt__44c9_s_p7_1,
  120979. NULL,
  120980. 0
  120981. };
  120982. static long _vq_quantlist__44c9_s_p8_0[] = {
  120983. 7,
  120984. 6,
  120985. 8,
  120986. 5,
  120987. 9,
  120988. 4,
  120989. 10,
  120990. 3,
  120991. 11,
  120992. 2,
  120993. 12,
  120994. 1,
  120995. 13,
  120996. 0,
  120997. 14,
  120998. };
  120999. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121000. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121001. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121002. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121003. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121004. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121005. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121006. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121007. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121008. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121009. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121010. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121011. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121012. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121013. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121014. 14,
  121015. };
  121016. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121017. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121018. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121019. };
  121020. static long _vq_quantmap__44c9_s_p8_0[] = {
  121021. 13, 11, 9, 7, 5, 3, 1, 0,
  121022. 2, 4, 6, 8, 10, 12, 14,
  121023. };
  121024. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121025. _vq_quantthresh__44c9_s_p8_0,
  121026. _vq_quantmap__44c9_s_p8_0,
  121027. 15,
  121028. 15
  121029. };
  121030. static static_codebook _44c9_s_p8_0 = {
  121031. 2, 225,
  121032. _vq_lengthlist__44c9_s_p8_0,
  121033. 1, -520986624, 1620377600, 4, 0,
  121034. _vq_quantlist__44c9_s_p8_0,
  121035. NULL,
  121036. &_vq_auxt__44c9_s_p8_0,
  121037. NULL,
  121038. 0
  121039. };
  121040. static long _vq_quantlist__44c9_s_p8_1[] = {
  121041. 10,
  121042. 9,
  121043. 11,
  121044. 8,
  121045. 12,
  121046. 7,
  121047. 13,
  121048. 6,
  121049. 14,
  121050. 5,
  121051. 15,
  121052. 4,
  121053. 16,
  121054. 3,
  121055. 17,
  121056. 2,
  121057. 18,
  121058. 1,
  121059. 19,
  121060. 0,
  121061. 20,
  121062. };
  121063. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121064. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121065. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121066. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121067. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121068. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121069. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121070. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121071. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121072. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121073. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121074. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121075. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121076. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121077. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121078. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121079. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121080. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121081. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121082. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121083. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121084. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121085. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121086. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121087. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121088. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121089. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121090. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121091. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121092. };
  121093. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121094. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121095. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121096. 6.5, 7.5, 8.5, 9.5,
  121097. };
  121098. static long _vq_quantmap__44c9_s_p8_1[] = {
  121099. 19, 17, 15, 13, 11, 9, 7, 5,
  121100. 3, 1, 0, 2, 4, 6, 8, 10,
  121101. 12, 14, 16, 18, 20,
  121102. };
  121103. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121104. _vq_quantthresh__44c9_s_p8_1,
  121105. _vq_quantmap__44c9_s_p8_1,
  121106. 21,
  121107. 21
  121108. };
  121109. static static_codebook _44c9_s_p8_1 = {
  121110. 2, 441,
  121111. _vq_lengthlist__44c9_s_p8_1,
  121112. 1, -529268736, 1611661312, 5, 0,
  121113. _vq_quantlist__44c9_s_p8_1,
  121114. NULL,
  121115. &_vq_auxt__44c9_s_p8_1,
  121116. NULL,
  121117. 0
  121118. };
  121119. static long _vq_quantlist__44c9_s_p9_0[] = {
  121120. 9,
  121121. 8,
  121122. 10,
  121123. 7,
  121124. 11,
  121125. 6,
  121126. 12,
  121127. 5,
  121128. 13,
  121129. 4,
  121130. 14,
  121131. 3,
  121132. 15,
  121133. 2,
  121134. 16,
  121135. 1,
  121136. 17,
  121137. 0,
  121138. 18,
  121139. };
  121140. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121141. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121142. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121143. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121144. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121145. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121146. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121147. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121148. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121149. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121150. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121151. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121152. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121153. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121154. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121155. 12,12,12,12,12,12,12,12,12,12,12,12,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,11,11,11,11,11,11,
  121158. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121159. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121160. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121161. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121162. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121163. 11,11,11,11,11,11,11,11,11,
  121164. };
  121165. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121166. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121167. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121168. 6982.5, 7913.5,
  121169. };
  121170. static long _vq_quantmap__44c9_s_p9_0[] = {
  121171. 17, 15, 13, 11, 9, 7, 5, 3,
  121172. 1, 0, 2, 4, 6, 8, 10, 12,
  121173. 14, 16, 18,
  121174. };
  121175. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121176. _vq_quantthresh__44c9_s_p9_0,
  121177. _vq_quantmap__44c9_s_p9_0,
  121178. 19,
  121179. 19
  121180. };
  121181. static static_codebook _44c9_s_p9_0 = {
  121182. 2, 361,
  121183. _vq_lengthlist__44c9_s_p9_0,
  121184. 1, -508535424, 1631393792, 5, 0,
  121185. _vq_quantlist__44c9_s_p9_0,
  121186. NULL,
  121187. &_vq_auxt__44c9_s_p9_0,
  121188. NULL,
  121189. 0
  121190. };
  121191. static long _vq_quantlist__44c9_s_p9_1[] = {
  121192. 9,
  121193. 8,
  121194. 10,
  121195. 7,
  121196. 11,
  121197. 6,
  121198. 12,
  121199. 5,
  121200. 13,
  121201. 4,
  121202. 14,
  121203. 3,
  121204. 15,
  121205. 2,
  121206. 16,
  121207. 1,
  121208. 17,
  121209. 0,
  121210. 18,
  121211. };
  121212. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121213. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121214. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121215. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121216. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121217. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121218. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121219. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121220. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121221. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121222. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121223. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121224. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121225. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121226. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121227. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121228. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121229. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121230. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121231. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121232. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121233. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121234. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121235. 13,13,13,14,13,14,15,15,15,
  121236. };
  121237. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121238. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121239. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121240. 367.5, 416.5,
  121241. };
  121242. static long _vq_quantmap__44c9_s_p9_1[] = {
  121243. 17, 15, 13, 11, 9, 7, 5, 3,
  121244. 1, 0, 2, 4, 6, 8, 10, 12,
  121245. 14, 16, 18,
  121246. };
  121247. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121248. _vq_quantthresh__44c9_s_p9_1,
  121249. _vq_quantmap__44c9_s_p9_1,
  121250. 19,
  121251. 19
  121252. };
  121253. static static_codebook _44c9_s_p9_1 = {
  121254. 2, 361,
  121255. _vq_lengthlist__44c9_s_p9_1,
  121256. 1, -518287360, 1622704128, 5, 0,
  121257. _vq_quantlist__44c9_s_p9_1,
  121258. NULL,
  121259. &_vq_auxt__44c9_s_p9_1,
  121260. NULL,
  121261. 0
  121262. };
  121263. static long _vq_quantlist__44c9_s_p9_2[] = {
  121264. 24,
  121265. 23,
  121266. 25,
  121267. 22,
  121268. 26,
  121269. 21,
  121270. 27,
  121271. 20,
  121272. 28,
  121273. 19,
  121274. 29,
  121275. 18,
  121276. 30,
  121277. 17,
  121278. 31,
  121279. 16,
  121280. 32,
  121281. 15,
  121282. 33,
  121283. 14,
  121284. 34,
  121285. 13,
  121286. 35,
  121287. 12,
  121288. 36,
  121289. 11,
  121290. 37,
  121291. 10,
  121292. 38,
  121293. 9,
  121294. 39,
  121295. 8,
  121296. 40,
  121297. 7,
  121298. 41,
  121299. 6,
  121300. 42,
  121301. 5,
  121302. 43,
  121303. 4,
  121304. 44,
  121305. 3,
  121306. 45,
  121307. 2,
  121308. 46,
  121309. 1,
  121310. 47,
  121311. 0,
  121312. 48,
  121313. };
  121314. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121315. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121316. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121317. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121318. 7,
  121319. };
  121320. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121321. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121322. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121323. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121324. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121325. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121326. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121327. };
  121328. static long _vq_quantmap__44c9_s_p9_2[] = {
  121329. 47, 45, 43, 41, 39, 37, 35, 33,
  121330. 31, 29, 27, 25, 23, 21, 19, 17,
  121331. 15, 13, 11, 9, 7, 5, 3, 1,
  121332. 0, 2, 4, 6, 8, 10, 12, 14,
  121333. 16, 18, 20, 22, 24, 26, 28, 30,
  121334. 32, 34, 36, 38, 40, 42, 44, 46,
  121335. 48,
  121336. };
  121337. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121338. _vq_quantthresh__44c9_s_p9_2,
  121339. _vq_quantmap__44c9_s_p9_2,
  121340. 49,
  121341. 49
  121342. };
  121343. static static_codebook _44c9_s_p9_2 = {
  121344. 1, 49,
  121345. _vq_lengthlist__44c9_s_p9_2,
  121346. 1, -526909440, 1611661312, 6, 0,
  121347. _vq_quantlist__44c9_s_p9_2,
  121348. NULL,
  121349. &_vq_auxt__44c9_s_p9_2,
  121350. NULL,
  121351. 0
  121352. };
  121353. static long _huff_lengthlist__44c9_s_short[] = {
  121354. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121355. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121356. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121357. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121358. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121359. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121360. 9, 8,10,13,
  121361. };
  121362. static static_codebook _huff_book__44c9_s_short = {
  121363. 2, 100,
  121364. _huff_lengthlist__44c9_s_short,
  121365. 0, 0, 0, 0, 0,
  121366. NULL,
  121367. NULL,
  121368. NULL,
  121369. NULL,
  121370. 0
  121371. };
  121372. static long _huff_lengthlist__44c0_s_long[] = {
  121373. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121374. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121375. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121376. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121377. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121378. 12,
  121379. };
  121380. static static_codebook _huff_book__44c0_s_long = {
  121381. 2, 81,
  121382. _huff_lengthlist__44c0_s_long,
  121383. 0, 0, 0, 0, 0,
  121384. NULL,
  121385. NULL,
  121386. NULL,
  121387. NULL,
  121388. 0
  121389. };
  121390. static long _vq_quantlist__44c0_s_p1_0[] = {
  121391. 1,
  121392. 0,
  121393. 2,
  121394. };
  121395. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121396. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121397. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121401. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121402. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121406. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121407. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121442. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121447. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  121452. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121487. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121488. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121493. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121498. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121704. 0, 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,
  121807. };
  121808. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121809. -0.5, 0.5,
  121810. };
  121811. static long _vq_quantmap__44c0_s_p1_0[] = {
  121812. 1, 0, 2,
  121813. };
  121814. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121815. _vq_quantthresh__44c0_s_p1_0,
  121816. _vq_quantmap__44c0_s_p1_0,
  121817. 3,
  121818. 3
  121819. };
  121820. static static_codebook _44c0_s_p1_0 = {
  121821. 8, 6561,
  121822. _vq_lengthlist__44c0_s_p1_0,
  121823. 1, -535822336, 1611661312, 2, 0,
  121824. _vq_quantlist__44c0_s_p1_0,
  121825. NULL,
  121826. &_vq_auxt__44c0_s_p1_0,
  121827. NULL,
  121828. 0
  121829. };
  121830. static long _vq_quantlist__44c0_s_p2_0[] = {
  121831. 2,
  121832. 1,
  121833. 3,
  121834. 0,
  121835. 4,
  121836. };
  121837. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121838. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121841. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121844. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  121845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  121878. };
  121879. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121880. -1.5, -0.5, 0.5, 1.5,
  121881. };
  121882. static long _vq_quantmap__44c0_s_p2_0[] = {
  121883. 3, 1, 0, 2, 4,
  121884. };
  121885. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121886. _vq_quantthresh__44c0_s_p2_0,
  121887. _vq_quantmap__44c0_s_p2_0,
  121888. 5,
  121889. 5
  121890. };
  121891. static static_codebook _44c0_s_p2_0 = {
  121892. 4, 625,
  121893. _vq_lengthlist__44c0_s_p2_0,
  121894. 1, -533725184, 1611661312, 3, 0,
  121895. _vq_quantlist__44c0_s_p2_0,
  121896. NULL,
  121897. &_vq_auxt__44c0_s_p2_0,
  121898. NULL,
  121899. 0
  121900. };
  121901. static long _vq_quantlist__44c0_s_p3_0[] = {
  121902. 4,
  121903. 3,
  121904. 5,
  121905. 2,
  121906. 6,
  121907. 1,
  121908. 7,
  121909. 0,
  121910. 8,
  121911. };
  121912. static long _vq_lengthlist__44c0_s_p3_0[] = {
  121913. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  121914. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  121915. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  121916. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  121917. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121918. 0,
  121919. };
  121920. static float _vq_quantthresh__44c0_s_p3_0[] = {
  121921. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121922. };
  121923. static long _vq_quantmap__44c0_s_p3_0[] = {
  121924. 7, 5, 3, 1, 0, 2, 4, 6,
  121925. 8,
  121926. };
  121927. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  121928. _vq_quantthresh__44c0_s_p3_0,
  121929. _vq_quantmap__44c0_s_p3_0,
  121930. 9,
  121931. 9
  121932. };
  121933. static static_codebook _44c0_s_p3_0 = {
  121934. 2, 81,
  121935. _vq_lengthlist__44c0_s_p3_0,
  121936. 1, -531628032, 1611661312, 4, 0,
  121937. _vq_quantlist__44c0_s_p3_0,
  121938. NULL,
  121939. &_vq_auxt__44c0_s_p3_0,
  121940. NULL,
  121941. 0
  121942. };
  121943. static long _vq_quantlist__44c0_s_p4_0[] = {
  121944. 4,
  121945. 3,
  121946. 5,
  121947. 2,
  121948. 6,
  121949. 1,
  121950. 7,
  121951. 0,
  121952. 8,
  121953. };
  121954. static long _vq_lengthlist__44c0_s_p4_0[] = {
  121955. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  121956. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  121957. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  121958. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  121959. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  121960. 10,
  121961. };
  121962. static float _vq_quantthresh__44c0_s_p4_0[] = {
  121963. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121964. };
  121965. static long _vq_quantmap__44c0_s_p4_0[] = {
  121966. 7, 5, 3, 1, 0, 2, 4, 6,
  121967. 8,
  121968. };
  121969. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  121970. _vq_quantthresh__44c0_s_p4_0,
  121971. _vq_quantmap__44c0_s_p4_0,
  121972. 9,
  121973. 9
  121974. };
  121975. static static_codebook _44c0_s_p4_0 = {
  121976. 2, 81,
  121977. _vq_lengthlist__44c0_s_p4_0,
  121978. 1, -531628032, 1611661312, 4, 0,
  121979. _vq_quantlist__44c0_s_p4_0,
  121980. NULL,
  121981. &_vq_auxt__44c0_s_p4_0,
  121982. NULL,
  121983. 0
  121984. };
  121985. static long _vq_quantlist__44c0_s_p5_0[] = {
  121986. 8,
  121987. 7,
  121988. 9,
  121989. 6,
  121990. 10,
  121991. 5,
  121992. 11,
  121993. 4,
  121994. 12,
  121995. 3,
  121996. 13,
  121997. 2,
  121998. 14,
  121999. 1,
  122000. 15,
  122001. 0,
  122002. 16,
  122003. };
  122004. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122005. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122006. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122007. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122008. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122009. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122010. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122011. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122012. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122013. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122014. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122015. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122016. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122017. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122018. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122019. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122020. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122021. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122022. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122023. 14,
  122024. };
  122025. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122026. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122027. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122028. };
  122029. static long _vq_quantmap__44c0_s_p5_0[] = {
  122030. 15, 13, 11, 9, 7, 5, 3, 1,
  122031. 0, 2, 4, 6, 8, 10, 12, 14,
  122032. 16,
  122033. };
  122034. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122035. _vq_quantthresh__44c0_s_p5_0,
  122036. _vq_quantmap__44c0_s_p5_0,
  122037. 17,
  122038. 17
  122039. };
  122040. static static_codebook _44c0_s_p5_0 = {
  122041. 2, 289,
  122042. _vq_lengthlist__44c0_s_p5_0,
  122043. 1, -529530880, 1611661312, 5, 0,
  122044. _vq_quantlist__44c0_s_p5_0,
  122045. NULL,
  122046. &_vq_auxt__44c0_s_p5_0,
  122047. NULL,
  122048. 0
  122049. };
  122050. static long _vq_quantlist__44c0_s_p6_0[] = {
  122051. 1,
  122052. 0,
  122053. 2,
  122054. };
  122055. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122056. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122057. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122058. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122059. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122060. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122061. 10,
  122062. };
  122063. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122064. -5.5, 5.5,
  122065. };
  122066. static long _vq_quantmap__44c0_s_p6_0[] = {
  122067. 1, 0, 2,
  122068. };
  122069. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122070. _vq_quantthresh__44c0_s_p6_0,
  122071. _vq_quantmap__44c0_s_p6_0,
  122072. 3,
  122073. 3
  122074. };
  122075. static static_codebook _44c0_s_p6_0 = {
  122076. 4, 81,
  122077. _vq_lengthlist__44c0_s_p6_0,
  122078. 1, -529137664, 1618345984, 2, 0,
  122079. _vq_quantlist__44c0_s_p6_0,
  122080. NULL,
  122081. &_vq_auxt__44c0_s_p6_0,
  122082. NULL,
  122083. 0
  122084. };
  122085. static long _vq_quantlist__44c0_s_p6_1[] = {
  122086. 5,
  122087. 4,
  122088. 6,
  122089. 3,
  122090. 7,
  122091. 2,
  122092. 8,
  122093. 1,
  122094. 9,
  122095. 0,
  122096. 10,
  122097. };
  122098. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122099. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122100. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122101. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122102. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122103. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122104. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122105. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122106. 10,10,10, 8, 8, 8, 8, 8, 8,
  122107. };
  122108. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122109. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122110. 3.5, 4.5,
  122111. };
  122112. static long _vq_quantmap__44c0_s_p6_1[] = {
  122113. 9, 7, 5, 3, 1, 0, 2, 4,
  122114. 6, 8, 10,
  122115. };
  122116. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122117. _vq_quantthresh__44c0_s_p6_1,
  122118. _vq_quantmap__44c0_s_p6_1,
  122119. 11,
  122120. 11
  122121. };
  122122. static static_codebook _44c0_s_p6_1 = {
  122123. 2, 121,
  122124. _vq_lengthlist__44c0_s_p6_1,
  122125. 1, -531365888, 1611661312, 4, 0,
  122126. _vq_quantlist__44c0_s_p6_1,
  122127. NULL,
  122128. &_vq_auxt__44c0_s_p6_1,
  122129. NULL,
  122130. 0
  122131. };
  122132. static long _vq_quantlist__44c0_s_p7_0[] = {
  122133. 6,
  122134. 5,
  122135. 7,
  122136. 4,
  122137. 8,
  122138. 3,
  122139. 9,
  122140. 2,
  122141. 10,
  122142. 1,
  122143. 11,
  122144. 0,
  122145. 12,
  122146. };
  122147. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122148. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122149. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122150. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122151. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122152. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122153. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122154. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122155. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122156. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122157. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122158. 0,12,12,11,11,12,12,13,13,
  122159. };
  122160. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122161. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122162. 12.5, 17.5, 22.5, 27.5,
  122163. };
  122164. static long _vq_quantmap__44c0_s_p7_0[] = {
  122165. 11, 9, 7, 5, 3, 1, 0, 2,
  122166. 4, 6, 8, 10, 12,
  122167. };
  122168. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122169. _vq_quantthresh__44c0_s_p7_0,
  122170. _vq_quantmap__44c0_s_p7_0,
  122171. 13,
  122172. 13
  122173. };
  122174. static static_codebook _44c0_s_p7_0 = {
  122175. 2, 169,
  122176. _vq_lengthlist__44c0_s_p7_0,
  122177. 1, -526516224, 1616117760, 4, 0,
  122178. _vq_quantlist__44c0_s_p7_0,
  122179. NULL,
  122180. &_vq_auxt__44c0_s_p7_0,
  122181. NULL,
  122182. 0
  122183. };
  122184. static long _vq_quantlist__44c0_s_p7_1[] = {
  122185. 2,
  122186. 1,
  122187. 3,
  122188. 0,
  122189. 4,
  122190. };
  122191. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122192. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122193. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122194. };
  122195. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122196. -1.5, -0.5, 0.5, 1.5,
  122197. };
  122198. static long _vq_quantmap__44c0_s_p7_1[] = {
  122199. 3, 1, 0, 2, 4,
  122200. };
  122201. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122202. _vq_quantthresh__44c0_s_p7_1,
  122203. _vq_quantmap__44c0_s_p7_1,
  122204. 5,
  122205. 5
  122206. };
  122207. static static_codebook _44c0_s_p7_1 = {
  122208. 2, 25,
  122209. _vq_lengthlist__44c0_s_p7_1,
  122210. 1, -533725184, 1611661312, 3, 0,
  122211. _vq_quantlist__44c0_s_p7_1,
  122212. NULL,
  122213. &_vq_auxt__44c0_s_p7_1,
  122214. NULL,
  122215. 0
  122216. };
  122217. static long _vq_quantlist__44c0_s_p8_0[] = {
  122218. 2,
  122219. 1,
  122220. 3,
  122221. 0,
  122222. 4,
  122223. };
  122224. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122225. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122226. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122227. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122228. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122229. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122230. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122231. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122232. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122233. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122234. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122235. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122236. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122237. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122238. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122239. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122240. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122241. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122242. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122243. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122244. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122245. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122246. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122247. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122248. 11,11,11,11,11,11,11,11,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,11,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,
  122265. };
  122266. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122267. -331.5, -110.5, 110.5, 331.5,
  122268. };
  122269. static long _vq_quantmap__44c0_s_p8_0[] = {
  122270. 3, 1, 0, 2, 4,
  122271. };
  122272. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122273. _vq_quantthresh__44c0_s_p8_0,
  122274. _vq_quantmap__44c0_s_p8_0,
  122275. 5,
  122276. 5
  122277. };
  122278. static static_codebook _44c0_s_p8_0 = {
  122279. 4, 625,
  122280. _vq_lengthlist__44c0_s_p8_0,
  122281. 1, -518283264, 1627103232, 3, 0,
  122282. _vq_quantlist__44c0_s_p8_0,
  122283. NULL,
  122284. &_vq_auxt__44c0_s_p8_0,
  122285. NULL,
  122286. 0
  122287. };
  122288. static long _vq_quantlist__44c0_s_p8_1[] = {
  122289. 6,
  122290. 5,
  122291. 7,
  122292. 4,
  122293. 8,
  122294. 3,
  122295. 9,
  122296. 2,
  122297. 10,
  122298. 1,
  122299. 11,
  122300. 0,
  122301. 12,
  122302. };
  122303. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122304. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122305. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122306. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122307. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122308. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122309. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122310. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122311. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122312. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122313. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122314. 16,13,13,12,12,14,14,15,13,
  122315. };
  122316. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122317. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122318. 42.5, 59.5, 76.5, 93.5,
  122319. };
  122320. static long _vq_quantmap__44c0_s_p8_1[] = {
  122321. 11, 9, 7, 5, 3, 1, 0, 2,
  122322. 4, 6, 8, 10, 12,
  122323. };
  122324. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122325. _vq_quantthresh__44c0_s_p8_1,
  122326. _vq_quantmap__44c0_s_p8_1,
  122327. 13,
  122328. 13
  122329. };
  122330. static static_codebook _44c0_s_p8_1 = {
  122331. 2, 169,
  122332. _vq_lengthlist__44c0_s_p8_1,
  122333. 1, -522616832, 1620115456, 4, 0,
  122334. _vq_quantlist__44c0_s_p8_1,
  122335. NULL,
  122336. &_vq_auxt__44c0_s_p8_1,
  122337. NULL,
  122338. 0
  122339. };
  122340. static long _vq_quantlist__44c0_s_p8_2[] = {
  122341. 8,
  122342. 7,
  122343. 9,
  122344. 6,
  122345. 10,
  122346. 5,
  122347. 11,
  122348. 4,
  122349. 12,
  122350. 3,
  122351. 13,
  122352. 2,
  122353. 14,
  122354. 1,
  122355. 15,
  122356. 0,
  122357. 16,
  122358. };
  122359. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122360. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122361. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122362. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122363. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122364. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122365. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122366. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122367. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122368. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122369. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122370. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122371. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122372. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122373. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122374. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122375. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122376. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122377. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122378. 10,
  122379. };
  122380. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122381. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122382. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122383. };
  122384. static long _vq_quantmap__44c0_s_p8_2[] = {
  122385. 15, 13, 11, 9, 7, 5, 3, 1,
  122386. 0, 2, 4, 6, 8, 10, 12, 14,
  122387. 16,
  122388. };
  122389. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122390. _vq_quantthresh__44c0_s_p8_2,
  122391. _vq_quantmap__44c0_s_p8_2,
  122392. 17,
  122393. 17
  122394. };
  122395. static static_codebook _44c0_s_p8_2 = {
  122396. 2, 289,
  122397. _vq_lengthlist__44c0_s_p8_2,
  122398. 1, -529530880, 1611661312, 5, 0,
  122399. _vq_quantlist__44c0_s_p8_2,
  122400. NULL,
  122401. &_vq_auxt__44c0_s_p8_2,
  122402. NULL,
  122403. 0
  122404. };
  122405. static long _huff_lengthlist__44c0_s_short[] = {
  122406. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122407. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122408. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122409. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122410. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122411. 12,
  122412. };
  122413. static static_codebook _huff_book__44c0_s_short = {
  122414. 2, 81,
  122415. _huff_lengthlist__44c0_s_short,
  122416. 0, 0, 0, 0, 0,
  122417. NULL,
  122418. NULL,
  122419. NULL,
  122420. NULL,
  122421. 0
  122422. };
  122423. static long _huff_lengthlist__44c0_sm_long[] = {
  122424. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122425. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122426. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122427. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122428. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122429. 13,
  122430. };
  122431. static static_codebook _huff_book__44c0_sm_long = {
  122432. 2, 81,
  122433. _huff_lengthlist__44c0_sm_long,
  122434. 0, 0, 0, 0, 0,
  122435. NULL,
  122436. NULL,
  122437. NULL,
  122438. NULL,
  122439. 0
  122440. };
  122441. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122442. 1,
  122443. 0,
  122444. 2,
  122445. };
  122446. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122447. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122448. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122452. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122453. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122457. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122458. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122493. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  122498. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  122503. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122538. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122539. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122544. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122549. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  122550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122755. 0, 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,
  122858. };
  122859. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122860. -0.5, 0.5,
  122861. };
  122862. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122863. 1, 0, 2,
  122864. };
  122865. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122866. _vq_quantthresh__44c0_sm_p1_0,
  122867. _vq_quantmap__44c0_sm_p1_0,
  122868. 3,
  122869. 3
  122870. };
  122871. static static_codebook _44c0_sm_p1_0 = {
  122872. 8, 6561,
  122873. _vq_lengthlist__44c0_sm_p1_0,
  122874. 1, -535822336, 1611661312, 2, 0,
  122875. _vq_quantlist__44c0_sm_p1_0,
  122876. NULL,
  122877. &_vq_auxt__44c0_sm_p1_0,
  122878. NULL,
  122879. 0
  122880. };
  122881. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122882. 2,
  122883. 1,
  122884. 3,
  122885. 0,
  122886. 4,
  122887. };
  122888. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122889. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122892. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122895. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  122929. };
  122930. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  122931. -1.5, -0.5, 0.5, 1.5,
  122932. };
  122933. static long _vq_quantmap__44c0_sm_p2_0[] = {
  122934. 3, 1, 0, 2, 4,
  122935. };
  122936. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  122937. _vq_quantthresh__44c0_sm_p2_0,
  122938. _vq_quantmap__44c0_sm_p2_0,
  122939. 5,
  122940. 5
  122941. };
  122942. static static_codebook _44c0_sm_p2_0 = {
  122943. 4, 625,
  122944. _vq_lengthlist__44c0_sm_p2_0,
  122945. 1, -533725184, 1611661312, 3, 0,
  122946. _vq_quantlist__44c0_sm_p2_0,
  122947. NULL,
  122948. &_vq_auxt__44c0_sm_p2_0,
  122949. NULL,
  122950. 0
  122951. };
  122952. static long _vq_quantlist__44c0_sm_p3_0[] = {
  122953. 4,
  122954. 3,
  122955. 5,
  122956. 2,
  122957. 6,
  122958. 1,
  122959. 7,
  122960. 0,
  122961. 8,
  122962. };
  122963. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  122964. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  122965. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  122966. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  122967. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  122968. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122969. 0,
  122970. };
  122971. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  122972. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122973. };
  122974. static long _vq_quantmap__44c0_sm_p3_0[] = {
  122975. 7, 5, 3, 1, 0, 2, 4, 6,
  122976. 8,
  122977. };
  122978. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  122979. _vq_quantthresh__44c0_sm_p3_0,
  122980. _vq_quantmap__44c0_sm_p3_0,
  122981. 9,
  122982. 9
  122983. };
  122984. static static_codebook _44c0_sm_p3_0 = {
  122985. 2, 81,
  122986. _vq_lengthlist__44c0_sm_p3_0,
  122987. 1, -531628032, 1611661312, 4, 0,
  122988. _vq_quantlist__44c0_sm_p3_0,
  122989. NULL,
  122990. &_vq_auxt__44c0_sm_p3_0,
  122991. NULL,
  122992. 0
  122993. };
  122994. static long _vq_quantlist__44c0_sm_p4_0[] = {
  122995. 4,
  122996. 3,
  122997. 5,
  122998. 2,
  122999. 6,
  123000. 1,
  123001. 7,
  123002. 0,
  123003. 8,
  123004. };
  123005. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123006. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123007. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123008. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123009. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123010. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123011. 11,
  123012. };
  123013. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123014. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123015. };
  123016. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123017. 7, 5, 3, 1, 0, 2, 4, 6,
  123018. 8,
  123019. };
  123020. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123021. _vq_quantthresh__44c0_sm_p4_0,
  123022. _vq_quantmap__44c0_sm_p4_0,
  123023. 9,
  123024. 9
  123025. };
  123026. static static_codebook _44c0_sm_p4_0 = {
  123027. 2, 81,
  123028. _vq_lengthlist__44c0_sm_p4_0,
  123029. 1, -531628032, 1611661312, 4, 0,
  123030. _vq_quantlist__44c0_sm_p4_0,
  123031. NULL,
  123032. &_vq_auxt__44c0_sm_p4_0,
  123033. NULL,
  123034. 0
  123035. };
  123036. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123037. 8,
  123038. 7,
  123039. 9,
  123040. 6,
  123041. 10,
  123042. 5,
  123043. 11,
  123044. 4,
  123045. 12,
  123046. 3,
  123047. 13,
  123048. 2,
  123049. 14,
  123050. 1,
  123051. 15,
  123052. 0,
  123053. 16,
  123054. };
  123055. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123056. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123057. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123058. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123059. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123060. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123061. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123062. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123063. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123064. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123065. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123066. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123067. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123068. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123069. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123070. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123071. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123072. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123073. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123074. 14,
  123075. };
  123076. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123077. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123078. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123079. };
  123080. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123081. 15, 13, 11, 9, 7, 5, 3, 1,
  123082. 0, 2, 4, 6, 8, 10, 12, 14,
  123083. 16,
  123084. };
  123085. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123086. _vq_quantthresh__44c0_sm_p5_0,
  123087. _vq_quantmap__44c0_sm_p5_0,
  123088. 17,
  123089. 17
  123090. };
  123091. static static_codebook _44c0_sm_p5_0 = {
  123092. 2, 289,
  123093. _vq_lengthlist__44c0_sm_p5_0,
  123094. 1, -529530880, 1611661312, 5, 0,
  123095. _vq_quantlist__44c0_sm_p5_0,
  123096. NULL,
  123097. &_vq_auxt__44c0_sm_p5_0,
  123098. NULL,
  123099. 0
  123100. };
  123101. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123102. 1,
  123103. 0,
  123104. 2,
  123105. };
  123106. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123107. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123108. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123109. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123110. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123111. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123112. 11,
  123113. };
  123114. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123115. -5.5, 5.5,
  123116. };
  123117. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123118. 1, 0, 2,
  123119. };
  123120. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123121. _vq_quantthresh__44c0_sm_p6_0,
  123122. _vq_quantmap__44c0_sm_p6_0,
  123123. 3,
  123124. 3
  123125. };
  123126. static static_codebook _44c0_sm_p6_0 = {
  123127. 4, 81,
  123128. _vq_lengthlist__44c0_sm_p6_0,
  123129. 1, -529137664, 1618345984, 2, 0,
  123130. _vq_quantlist__44c0_sm_p6_0,
  123131. NULL,
  123132. &_vq_auxt__44c0_sm_p6_0,
  123133. NULL,
  123134. 0
  123135. };
  123136. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123137. 5,
  123138. 4,
  123139. 6,
  123140. 3,
  123141. 7,
  123142. 2,
  123143. 8,
  123144. 1,
  123145. 9,
  123146. 0,
  123147. 10,
  123148. };
  123149. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123150. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123151. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123152. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123153. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123154. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123155. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123156. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123157. 10,10,10, 8, 8, 8, 8, 8, 8,
  123158. };
  123159. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123160. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123161. 3.5, 4.5,
  123162. };
  123163. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123164. 9, 7, 5, 3, 1, 0, 2, 4,
  123165. 6, 8, 10,
  123166. };
  123167. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123168. _vq_quantthresh__44c0_sm_p6_1,
  123169. _vq_quantmap__44c0_sm_p6_1,
  123170. 11,
  123171. 11
  123172. };
  123173. static static_codebook _44c0_sm_p6_1 = {
  123174. 2, 121,
  123175. _vq_lengthlist__44c0_sm_p6_1,
  123176. 1, -531365888, 1611661312, 4, 0,
  123177. _vq_quantlist__44c0_sm_p6_1,
  123178. NULL,
  123179. &_vq_auxt__44c0_sm_p6_1,
  123180. NULL,
  123181. 0
  123182. };
  123183. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123184. 6,
  123185. 5,
  123186. 7,
  123187. 4,
  123188. 8,
  123189. 3,
  123190. 9,
  123191. 2,
  123192. 10,
  123193. 1,
  123194. 11,
  123195. 0,
  123196. 12,
  123197. };
  123198. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123199. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123200. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123201. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123202. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123203. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123204. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123205. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123206. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123207. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123208. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123209. 0,12,12,11,11,13,12,14,14,
  123210. };
  123211. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123212. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123213. 12.5, 17.5, 22.5, 27.5,
  123214. };
  123215. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123216. 11, 9, 7, 5, 3, 1, 0, 2,
  123217. 4, 6, 8, 10, 12,
  123218. };
  123219. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123220. _vq_quantthresh__44c0_sm_p7_0,
  123221. _vq_quantmap__44c0_sm_p7_0,
  123222. 13,
  123223. 13
  123224. };
  123225. static static_codebook _44c0_sm_p7_0 = {
  123226. 2, 169,
  123227. _vq_lengthlist__44c0_sm_p7_0,
  123228. 1, -526516224, 1616117760, 4, 0,
  123229. _vq_quantlist__44c0_sm_p7_0,
  123230. NULL,
  123231. &_vq_auxt__44c0_sm_p7_0,
  123232. NULL,
  123233. 0
  123234. };
  123235. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123236. 2,
  123237. 1,
  123238. 3,
  123239. 0,
  123240. 4,
  123241. };
  123242. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123243. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123244. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123245. };
  123246. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123247. -1.5, -0.5, 0.5, 1.5,
  123248. };
  123249. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123250. 3, 1, 0, 2, 4,
  123251. };
  123252. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123253. _vq_quantthresh__44c0_sm_p7_1,
  123254. _vq_quantmap__44c0_sm_p7_1,
  123255. 5,
  123256. 5
  123257. };
  123258. static static_codebook _44c0_sm_p7_1 = {
  123259. 2, 25,
  123260. _vq_lengthlist__44c0_sm_p7_1,
  123261. 1, -533725184, 1611661312, 3, 0,
  123262. _vq_quantlist__44c0_sm_p7_1,
  123263. NULL,
  123264. &_vq_auxt__44c0_sm_p7_1,
  123265. NULL,
  123266. 0
  123267. };
  123268. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123269. 4,
  123270. 3,
  123271. 5,
  123272. 2,
  123273. 6,
  123274. 1,
  123275. 7,
  123276. 0,
  123277. 8,
  123278. };
  123279. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123280. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123281. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123282. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123283. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123284. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123285. 12,
  123286. };
  123287. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123288. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123289. };
  123290. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123291. 7, 5, 3, 1, 0, 2, 4, 6,
  123292. 8,
  123293. };
  123294. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123295. _vq_quantthresh__44c0_sm_p8_0,
  123296. _vq_quantmap__44c0_sm_p8_0,
  123297. 9,
  123298. 9
  123299. };
  123300. static static_codebook _44c0_sm_p8_0 = {
  123301. 2, 81,
  123302. _vq_lengthlist__44c0_sm_p8_0,
  123303. 1, -516186112, 1627103232, 4, 0,
  123304. _vq_quantlist__44c0_sm_p8_0,
  123305. NULL,
  123306. &_vq_auxt__44c0_sm_p8_0,
  123307. NULL,
  123308. 0
  123309. };
  123310. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123311. 6,
  123312. 5,
  123313. 7,
  123314. 4,
  123315. 8,
  123316. 3,
  123317. 9,
  123318. 2,
  123319. 10,
  123320. 1,
  123321. 11,
  123322. 0,
  123323. 12,
  123324. };
  123325. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123326. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123327. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123328. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123329. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123330. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123331. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123332. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123333. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123334. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123335. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123336. 20,13,13,12,12,16,13,15,13,
  123337. };
  123338. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123339. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123340. 42.5, 59.5, 76.5, 93.5,
  123341. };
  123342. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123343. 11, 9, 7, 5, 3, 1, 0, 2,
  123344. 4, 6, 8, 10, 12,
  123345. };
  123346. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123347. _vq_quantthresh__44c0_sm_p8_1,
  123348. _vq_quantmap__44c0_sm_p8_1,
  123349. 13,
  123350. 13
  123351. };
  123352. static static_codebook _44c0_sm_p8_1 = {
  123353. 2, 169,
  123354. _vq_lengthlist__44c0_sm_p8_1,
  123355. 1, -522616832, 1620115456, 4, 0,
  123356. _vq_quantlist__44c0_sm_p8_1,
  123357. NULL,
  123358. &_vq_auxt__44c0_sm_p8_1,
  123359. NULL,
  123360. 0
  123361. };
  123362. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123363. 8,
  123364. 7,
  123365. 9,
  123366. 6,
  123367. 10,
  123368. 5,
  123369. 11,
  123370. 4,
  123371. 12,
  123372. 3,
  123373. 13,
  123374. 2,
  123375. 14,
  123376. 1,
  123377. 15,
  123378. 0,
  123379. 16,
  123380. };
  123381. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123382. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123383. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123384. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123385. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123386. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123387. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123388. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123389. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123390. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123391. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123392. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123393. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123394. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123395. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123396. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123397. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123398. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123399. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123400. 9,
  123401. };
  123402. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123403. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123404. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123405. };
  123406. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123407. 15, 13, 11, 9, 7, 5, 3, 1,
  123408. 0, 2, 4, 6, 8, 10, 12, 14,
  123409. 16,
  123410. };
  123411. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123412. _vq_quantthresh__44c0_sm_p8_2,
  123413. _vq_quantmap__44c0_sm_p8_2,
  123414. 17,
  123415. 17
  123416. };
  123417. static static_codebook _44c0_sm_p8_2 = {
  123418. 2, 289,
  123419. _vq_lengthlist__44c0_sm_p8_2,
  123420. 1, -529530880, 1611661312, 5, 0,
  123421. _vq_quantlist__44c0_sm_p8_2,
  123422. NULL,
  123423. &_vq_auxt__44c0_sm_p8_2,
  123424. NULL,
  123425. 0
  123426. };
  123427. static long _huff_lengthlist__44c0_sm_short[] = {
  123428. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123429. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123430. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123431. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123432. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123433. 12,
  123434. };
  123435. static static_codebook _huff_book__44c0_sm_short = {
  123436. 2, 81,
  123437. _huff_lengthlist__44c0_sm_short,
  123438. 0, 0, 0, 0, 0,
  123439. NULL,
  123440. NULL,
  123441. NULL,
  123442. NULL,
  123443. 0
  123444. };
  123445. static long _huff_lengthlist__44c1_s_long[] = {
  123446. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123447. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123448. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123449. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123450. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123451. 11,
  123452. };
  123453. static static_codebook _huff_book__44c1_s_long = {
  123454. 2, 81,
  123455. _huff_lengthlist__44c1_s_long,
  123456. 0, 0, 0, 0, 0,
  123457. NULL,
  123458. NULL,
  123459. NULL,
  123460. NULL,
  123461. 0
  123462. };
  123463. static long _vq_quantlist__44c1_s_p1_0[] = {
  123464. 1,
  123465. 0,
  123466. 2,
  123467. };
  123468. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123469. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123470. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123474. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123475. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123479. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123480. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123515. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  123520. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  123525. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123560. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123561. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123566. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123571. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123777. 0, 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,
  123880. };
  123881. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123882. -0.5, 0.5,
  123883. };
  123884. static long _vq_quantmap__44c1_s_p1_0[] = {
  123885. 1, 0, 2,
  123886. };
  123887. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123888. _vq_quantthresh__44c1_s_p1_0,
  123889. _vq_quantmap__44c1_s_p1_0,
  123890. 3,
  123891. 3
  123892. };
  123893. static static_codebook _44c1_s_p1_0 = {
  123894. 8, 6561,
  123895. _vq_lengthlist__44c1_s_p1_0,
  123896. 1, -535822336, 1611661312, 2, 0,
  123897. _vq_quantlist__44c1_s_p1_0,
  123898. NULL,
  123899. &_vq_auxt__44c1_s_p1_0,
  123900. NULL,
  123901. 0
  123902. };
  123903. static long _vq_quantlist__44c1_s_p2_0[] = {
  123904. 2,
  123905. 1,
  123906. 3,
  123907. 0,
  123908. 4,
  123909. };
  123910. static long _vq_lengthlist__44c1_s_p2_0[] = {
  123911. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  123913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123914. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  123916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123917. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  123951. };
  123952. static float _vq_quantthresh__44c1_s_p2_0[] = {
  123953. -1.5, -0.5, 0.5, 1.5,
  123954. };
  123955. static long _vq_quantmap__44c1_s_p2_0[] = {
  123956. 3, 1, 0, 2, 4,
  123957. };
  123958. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  123959. _vq_quantthresh__44c1_s_p2_0,
  123960. _vq_quantmap__44c1_s_p2_0,
  123961. 5,
  123962. 5
  123963. };
  123964. static static_codebook _44c1_s_p2_0 = {
  123965. 4, 625,
  123966. _vq_lengthlist__44c1_s_p2_0,
  123967. 1, -533725184, 1611661312, 3, 0,
  123968. _vq_quantlist__44c1_s_p2_0,
  123969. NULL,
  123970. &_vq_auxt__44c1_s_p2_0,
  123971. NULL,
  123972. 0
  123973. };
  123974. static long _vq_quantlist__44c1_s_p3_0[] = {
  123975. 4,
  123976. 3,
  123977. 5,
  123978. 2,
  123979. 6,
  123980. 1,
  123981. 7,
  123982. 0,
  123983. 8,
  123984. };
  123985. static long _vq_lengthlist__44c1_s_p3_0[] = {
  123986. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  123987. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  123988. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  123989. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  123990. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123991. 0,
  123992. };
  123993. static float _vq_quantthresh__44c1_s_p3_0[] = {
  123994. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123995. };
  123996. static long _vq_quantmap__44c1_s_p3_0[] = {
  123997. 7, 5, 3, 1, 0, 2, 4, 6,
  123998. 8,
  123999. };
  124000. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124001. _vq_quantthresh__44c1_s_p3_0,
  124002. _vq_quantmap__44c1_s_p3_0,
  124003. 9,
  124004. 9
  124005. };
  124006. static static_codebook _44c1_s_p3_0 = {
  124007. 2, 81,
  124008. _vq_lengthlist__44c1_s_p3_0,
  124009. 1, -531628032, 1611661312, 4, 0,
  124010. _vq_quantlist__44c1_s_p3_0,
  124011. NULL,
  124012. &_vq_auxt__44c1_s_p3_0,
  124013. NULL,
  124014. 0
  124015. };
  124016. static long _vq_quantlist__44c1_s_p4_0[] = {
  124017. 4,
  124018. 3,
  124019. 5,
  124020. 2,
  124021. 6,
  124022. 1,
  124023. 7,
  124024. 0,
  124025. 8,
  124026. };
  124027. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124028. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124029. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124030. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124031. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124032. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124033. 11,
  124034. };
  124035. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124036. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124037. };
  124038. static long _vq_quantmap__44c1_s_p4_0[] = {
  124039. 7, 5, 3, 1, 0, 2, 4, 6,
  124040. 8,
  124041. };
  124042. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124043. _vq_quantthresh__44c1_s_p4_0,
  124044. _vq_quantmap__44c1_s_p4_0,
  124045. 9,
  124046. 9
  124047. };
  124048. static static_codebook _44c1_s_p4_0 = {
  124049. 2, 81,
  124050. _vq_lengthlist__44c1_s_p4_0,
  124051. 1, -531628032, 1611661312, 4, 0,
  124052. _vq_quantlist__44c1_s_p4_0,
  124053. NULL,
  124054. &_vq_auxt__44c1_s_p4_0,
  124055. NULL,
  124056. 0
  124057. };
  124058. static long _vq_quantlist__44c1_s_p5_0[] = {
  124059. 8,
  124060. 7,
  124061. 9,
  124062. 6,
  124063. 10,
  124064. 5,
  124065. 11,
  124066. 4,
  124067. 12,
  124068. 3,
  124069. 13,
  124070. 2,
  124071. 14,
  124072. 1,
  124073. 15,
  124074. 0,
  124075. 16,
  124076. };
  124077. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124078. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124079. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124080. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124081. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124082. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124083. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124084. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124085. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124086. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124087. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124088. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124089. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124090. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124091. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124092. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124093. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124094. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124095. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124096. 14,
  124097. };
  124098. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124099. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124100. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124101. };
  124102. static long _vq_quantmap__44c1_s_p5_0[] = {
  124103. 15, 13, 11, 9, 7, 5, 3, 1,
  124104. 0, 2, 4, 6, 8, 10, 12, 14,
  124105. 16,
  124106. };
  124107. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124108. _vq_quantthresh__44c1_s_p5_0,
  124109. _vq_quantmap__44c1_s_p5_0,
  124110. 17,
  124111. 17
  124112. };
  124113. static static_codebook _44c1_s_p5_0 = {
  124114. 2, 289,
  124115. _vq_lengthlist__44c1_s_p5_0,
  124116. 1, -529530880, 1611661312, 5, 0,
  124117. _vq_quantlist__44c1_s_p5_0,
  124118. NULL,
  124119. &_vq_auxt__44c1_s_p5_0,
  124120. NULL,
  124121. 0
  124122. };
  124123. static long _vq_quantlist__44c1_s_p6_0[] = {
  124124. 1,
  124125. 0,
  124126. 2,
  124127. };
  124128. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124129. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124130. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124131. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124132. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124133. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124134. 11,
  124135. };
  124136. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124137. -5.5, 5.5,
  124138. };
  124139. static long _vq_quantmap__44c1_s_p6_0[] = {
  124140. 1, 0, 2,
  124141. };
  124142. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124143. _vq_quantthresh__44c1_s_p6_0,
  124144. _vq_quantmap__44c1_s_p6_0,
  124145. 3,
  124146. 3
  124147. };
  124148. static static_codebook _44c1_s_p6_0 = {
  124149. 4, 81,
  124150. _vq_lengthlist__44c1_s_p6_0,
  124151. 1, -529137664, 1618345984, 2, 0,
  124152. _vq_quantlist__44c1_s_p6_0,
  124153. NULL,
  124154. &_vq_auxt__44c1_s_p6_0,
  124155. NULL,
  124156. 0
  124157. };
  124158. static long _vq_quantlist__44c1_s_p6_1[] = {
  124159. 5,
  124160. 4,
  124161. 6,
  124162. 3,
  124163. 7,
  124164. 2,
  124165. 8,
  124166. 1,
  124167. 9,
  124168. 0,
  124169. 10,
  124170. };
  124171. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124172. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124173. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124174. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124175. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124176. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124177. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124178. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124179. 10,10,10, 8, 8, 8, 8, 8, 8,
  124180. };
  124181. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124182. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124183. 3.5, 4.5,
  124184. };
  124185. static long _vq_quantmap__44c1_s_p6_1[] = {
  124186. 9, 7, 5, 3, 1, 0, 2, 4,
  124187. 6, 8, 10,
  124188. };
  124189. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124190. _vq_quantthresh__44c1_s_p6_1,
  124191. _vq_quantmap__44c1_s_p6_1,
  124192. 11,
  124193. 11
  124194. };
  124195. static static_codebook _44c1_s_p6_1 = {
  124196. 2, 121,
  124197. _vq_lengthlist__44c1_s_p6_1,
  124198. 1, -531365888, 1611661312, 4, 0,
  124199. _vq_quantlist__44c1_s_p6_1,
  124200. NULL,
  124201. &_vq_auxt__44c1_s_p6_1,
  124202. NULL,
  124203. 0
  124204. };
  124205. static long _vq_quantlist__44c1_s_p7_0[] = {
  124206. 6,
  124207. 5,
  124208. 7,
  124209. 4,
  124210. 8,
  124211. 3,
  124212. 9,
  124213. 2,
  124214. 10,
  124215. 1,
  124216. 11,
  124217. 0,
  124218. 12,
  124219. };
  124220. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124221. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124222. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124223. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124224. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124225. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124226. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124227. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124228. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124229. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124230. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124231. 0,12,11,11,11,13,10,14,13,
  124232. };
  124233. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124234. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124235. 12.5, 17.5, 22.5, 27.5,
  124236. };
  124237. static long _vq_quantmap__44c1_s_p7_0[] = {
  124238. 11, 9, 7, 5, 3, 1, 0, 2,
  124239. 4, 6, 8, 10, 12,
  124240. };
  124241. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124242. _vq_quantthresh__44c1_s_p7_0,
  124243. _vq_quantmap__44c1_s_p7_0,
  124244. 13,
  124245. 13
  124246. };
  124247. static static_codebook _44c1_s_p7_0 = {
  124248. 2, 169,
  124249. _vq_lengthlist__44c1_s_p7_0,
  124250. 1, -526516224, 1616117760, 4, 0,
  124251. _vq_quantlist__44c1_s_p7_0,
  124252. NULL,
  124253. &_vq_auxt__44c1_s_p7_0,
  124254. NULL,
  124255. 0
  124256. };
  124257. static long _vq_quantlist__44c1_s_p7_1[] = {
  124258. 2,
  124259. 1,
  124260. 3,
  124261. 0,
  124262. 4,
  124263. };
  124264. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124265. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124266. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124267. };
  124268. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124269. -1.5, -0.5, 0.5, 1.5,
  124270. };
  124271. static long _vq_quantmap__44c1_s_p7_1[] = {
  124272. 3, 1, 0, 2, 4,
  124273. };
  124274. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124275. _vq_quantthresh__44c1_s_p7_1,
  124276. _vq_quantmap__44c1_s_p7_1,
  124277. 5,
  124278. 5
  124279. };
  124280. static static_codebook _44c1_s_p7_1 = {
  124281. 2, 25,
  124282. _vq_lengthlist__44c1_s_p7_1,
  124283. 1, -533725184, 1611661312, 3, 0,
  124284. _vq_quantlist__44c1_s_p7_1,
  124285. NULL,
  124286. &_vq_auxt__44c1_s_p7_1,
  124287. NULL,
  124288. 0
  124289. };
  124290. static long _vq_quantlist__44c1_s_p8_0[] = {
  124291. 6,
  124292. 5,
  124293. 7,
  124294. 4,
  124295. 8,
  124296. 3,
  124297. 9,
  124298. 2,
  124299. 10,
  124300. 1,
  124301. 11,
  124302. 0,
  124303. 12,
  124304. };
  124305. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124306. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124307. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124308. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124309. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124310. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124311. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124312. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124313. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124314. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124315. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124316. 10,10,10,10,10,10,10,10,10,
  124317. };
  124318. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124319. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124320. 552.5, 773.5, 994.5, 1215.5,
  124321. };
  124322. static long _vq_quantmap__44c1_s_p8_0[] = {
  124323. 11, 9, 7, 5, 3, 1, 0, 2,
  124324. 4, 6, 8, 10, 12,
  124325. };
  124326. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124327. _vq_quantthresh__44c1_s_p8_0,
  124328. _vq_quantmap__44c1_s_p8_0,
  124329. 13,
  124330. 13
  124331. };
  124332. static static_codebook _44c1_s_p8_0 = {
  124333. 2, 169,
  124334. _vq_lengthlist__44c1_s_p8_0,
  124335. 1, -514541568, 1627103232, 4, 0,
  124336. _vq_quantlist__44c1_s_p8_0,
  124337. NULL,
  124338. &_vq_auxt__44c1_s_p8_0,
  124339. NULL,
  124340. 0
  124341. };
  124342. static long _vq_quantlist__44c1_s_p8_1[] = {
  124343. 6,
  124344. 5,
  124345. 7,
  124346. 4,
  124347. 8,
  124348. 3,
  124349. 9,
  124350. 2,
  124351. 10,
  124352. 1,
  124353. 11,
  124354. 0,
  124355. 12,
  124356. };
  124357. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124358. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124359. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124360. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124361. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124362. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124363. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124364. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124365. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124366. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124367. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124368. 16,13,12,12,11,14,12,15,13,
  124369. };
  124370. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124371. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124372. 42.5, 59.5, 76.5, 93.5,
  124373. };
  124374. static long _vq_quantmap__44c1_s_p8_1[] = {
  124375. 11, 9, 7, 5, 3, 1, 0, 2,
  124376. 4, 6, 8, 10, 12,
  124377. };
  124378. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124379. _vq_quantthresh__44c1_s_p8_1,
  124380. _vq_quantmap__44c1_s_p8_1,
  124381. 13,
  124382. 13
  124383. };
  124384. static static_codebook _44c1_s_p8_1 = {
  124385. 2, 169,
  124386. _vq_lengthlist__44c1_s_p8_1,
  124387. 1, -522616832, 1620115456, 4, 0,
  124388. _vq_quantlist__44c1_s_p8_1,
  124389. NULL,
  124390. &_vq_auxt__44c1_s_p8_1,
  124391. NULL,
  124392. 0
  124393. };
  124394. static long _vq_quantlist__44c1_s_p8_2[] = {
  124395. 8,
  124396. 7,
  124397. 9,
  124398. 6,
  124399. 10,
  124400. 5,
  124401. 11,
  124402. 4,
  124403. 12,
  124404. 3,
  124405. 13,
  124406. 2,
  124407. 14,
  124408. 1,
  124409. 15,
  124410. 0,
  124411. 16,
  124412. };
  124413. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124414. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124415. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124416. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124417. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124418. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124419. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124420. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124421. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124422. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124423. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124424. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124425. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124426. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124427. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124428. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124429. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124430. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124431. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124432. 9,
  124433. };
  124434. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124435. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124436. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124437. };
  124438. static long _vq_quantmap__44c1_s_p8_2[] = {
  124439. 15, 13, 11, 9, 7, 5, 3, 1,
  124440. 0, 2, 4, 6, 8, 10, 12, 14,
  124441. 16,
  124442. };
  124443. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124444. _vq_quantthresh__44c1_s_p8_2,
  124445. _vq_quantmap__44c1_s_p8_2,
  124446. 17,
  124447. 17
  124448. };
  124449. static static_codebook _44c1_s_p8_2 = {
  124450. 2, 289,
  124451. _vq_lengthlist__44c1_s_p8_2,
  124452. 1, -529530880, 1611661312, 5, 0,
  124453. _vq_quantlist__44c1_s_p8_2,
  124454. NULL,
  124455. &_vq_auxt__44c1_s_p8_2,
  124456. NULL,
  124457. 0
  124458. };
  124459. static long _huff_lengthlist__44c1_s_short[] = {
  124460. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124461. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124462. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124463. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124464. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124465. 11,
  124466. };
  124467. static static_codebook _huff_book__44c1_s_short = {
  124468. 2, 81,
  124469. _huff_lengthlist__44c1_s_short,
  124470. 0, 0, 0, 0, 0,
  124471. NULL,
  124472. NULL,
  124473. NULL,
  124474. NULL,
  124475. 0
  124476. };
  124477. static long _huff_lengthlist__44c1_sm_long[] = {
  124478. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124479. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124480. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124481. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124482. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124483. 11,
  124484. };
  124485. static static_codebook _huff_book__44c1_sm_long = {
  124486. 2, 81,
  124487. _huff_lengthlist__44c1_sm_long,
  124488. 0, 0, 0, 0, 0,
  124489. NULL,
  124490. NULL,
  124491. NULL,
  124492. NULL,
  124493. 0
  124494. };
  124495. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124496. 1,
  124497. 0,
  124498. 2,
  124499. };
  124500. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124501. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124502. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124506. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124507. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124511. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124512. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124547. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  124552. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  124557. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124592. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124593. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124598. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124603. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  124604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124809. 0, 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,
  124912. };
  124913. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  124914. -0.5, 0.5,
  124915. };
  124916. static long _vq_quantmap__44c1_sm_p1_0[] = {
  124917. 1, 0, 2,
  124918. };
  124919. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  124920. _vq_quantthresh__44c1_sm_p1_0,
  124921. _vq_quantmap__44c1_sm_p1_0,
  124922. 3,
  124923. 3
  124924. };
  124925. static static_codebook _44c1_sm_p1_0 = {
  124926. 8, 6561,
  124927. _vq_lengthlist__44c1_sm_p1_0,
  124928. 1, -535822336, 1611661312, 2, 0,
  124929. _vq_quantlist__44c1_sm_p1_0,
  124930. NULL,
  124931. &_vq_auxt__44c1_sm_p1_0,
  124932. NULL,
  124933. 0
  124934. };
  124935. static long _vq_quantlist__44c1_sm_p2_0[] = {
  124936. 2,
  124937. 1,
  124938. 3,
  124939. 0,
  124940. 4,
  124941. };
  124942. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  124943. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124946. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  124948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124949. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  124983. };
  124984. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  124985. -1.5, -0.5, 0.5, 1.5,
  124986. };
  124987. static long _vq_quantmap__44c1_sm_p2_0[] = {
  124988. 3, 1, 0, 2, 4,
  124989. };
  124990. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  124991. _vq_quantthresh__44c1_sm_p2_0,
  124992. _vq_quantmap__44c1_sm_p2_0,
  124993. 5,
  124994. 5
  124995. };
  124996. static static_codebook _44c1_sm_p2_0 = {
  124997. 4, 625,
  124998. _vq_lengthlist__44c1_sm_p2_0,
  124999. 1, -533725184, 1611661312, 3, 0,
  125000. _vq_quantlist__44c1_sm_p2_0,
  125001. NULL,
  125002. &_vq_auxt__44c1_sm_p2_0,
  125003. NULL,
  125004. 0
  125005. };
  125006. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125007. 4,
  125008. 3,
  125009. 5,
  125010. 2,
  125011. 6,
  125012. 1,
  125013. 7,
  125014. 0,
  125015. 8,
  125016. };
  125017. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125018. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125019. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125020. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125021. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125022. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125023. 0,
  125024. };
  125025. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125026. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125027. };
  125028. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125029. 7, 5, 3, 1, 0, 2, 4, 6,
  125030. 8,
  125031. };
  125032. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125033. _vq_quantthresh__44c1_sm_p3_0,
  125034. _vq_quantmap__44c1_sm_p3_0,
  125035. 9,
  125036. 9
  125037. };
  125038. static static_codebook _44c1_sm_p3_0 = {
  125039. 2, 81,
  125040. _vq_lengthlist__44c1_sm_p3_0,
  125041. 1, -531628032, 1611661312, 4, 0,
  125042. _vq_quantlist__44c1_sm_p3_0,
  125043. NULL,
  125044. &_vq_auxt__44c1_sm_p3_0,
  125045. NULL,
  125046. 0
  125047. };
  125048. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125049. 4,
  125050. 3,
  125051. 5,
  125052. 2,
  125053. 6,
  125054. 1,
  125055. 7,
  125056. 0,
  125057. 8,
  125058. };
  125059. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125060. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125061. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125062. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125063. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125064. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125065. 11,
  125066. };
  125067. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125068. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125069. };
  125070. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125071. 7, 5, 3, 1, 0, 2, 4, 6,
  125072. 8,
  125073. };
  125074. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125075. _vq_quantthresh__44c1_sm_p4_0,
  125076. _vq_quantmap__44c1_sm_p4_0,
  125077. 9,
  125078. 9
  125079. };
  125080. static static_codebook _44c1_sm_p4_0 = {
  125081. 2, 81,
  125082. _vq_lengthlist__44c1_sm_p4_0,
  125083. 1, -531628032, 1611661312, 4, 0,
  125084. _vq_quantlist__44c1_sm_p4_0,
  125085. NULL,
  125086. &_vq_auxt__44c1_sm_p4_0,
  125087. NULL,
  125088. 0
  125089. };
  125090. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125091. 8,
  125092. 7,
  125093. 9,
  125094. 6,
  125095. 10,
  125096. 5,
  125097. 11,
  125098. 4,
  125099. 12,
  125100. 3,
  125101. 13,
  125102. 2,
  125103. 14,
  125104. 1,
  125105. 15,
  125106. 0,
  125107. 16,
  125108. };
  125109. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125110. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125111. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125112. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125113. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125114. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125115. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125116. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125117. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125118. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125119. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125120. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125121. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125122. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125123. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125124. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125125. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125126. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125127. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125128. 14,
  125129. };
  125130. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125131. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125132. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125133. };
  125134. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125135. 15, 13, 11, 9, 7, 5, 3, 1,
  125136. 0, 2, 4, 6, 8, 10, 12, 14,
  125137. 16,
  125138. };
  125139. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125140. _vq_quantthresh__44c1_sm_p5_0,
  125141. _vq_quantmap__44c1_sm_p5_0,
  125142. 17,
  125143. 17
  125144. };
  125145. static static_codebook _44c1_sm_p5_0 = {
  125146. 2, 289,
  125147. _vq_lengthlist__44c1_sm_p5_0,
  125148. 1, -529530880, 1611661312, 5, 0,
  125149. _vq_quantlist__44c1_sm_p5_0,
  125150. NULL,
  125151. &_vq_auxt__44c1_sm_p5_0,
  125152. NULL,
  125153. 0
  125154. };
  125155. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125156. 1,
  125157. 0,
  125158. 2,
  125159. };
  125160. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125161. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125162. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125163. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125164. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125165. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125166. 11,
  125167. };
  125168. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125169. -5.5, 5.5,
  125170. };
  125171. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125172. 1, 0, 2,
  125173. };
  125174. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125175. _vq_quantthresh__44c1_sm_p6_0,
  125176. _vq_quantmap__44c1_sm_p6_0,
  125177. 3,
  125178. 3
  125179. };
  125180. static static_codebook _44c1_sm_p6_0 = {
  125181. 4, 81,
  125182. _vq_lengthlist__44c1_sm_p6_0,
  125183. 1, -529137664, 1618345984, 2, 0,
  125184. _vq_quantlist__44c1_sm_p6_0,
  125185. NULL,
  125186. &_vq_auxt__44c1_sm_p6_0,
  125187. NULL,
  125188. 0
  125189. };
  125190. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125191. 5,
  125192. 4,
  125193. 6,
  125194. 3,
  125195. 7,
  125196. 2,
  125197. 8,
  125198. 1,
  125199. 9,
  125200. 0,
  125201. 10,
  125202. };
  125203. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125204. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125205. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125206. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125207. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125208. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125209. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125210. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125211. 10,10,10, 8, 8, 8, 8, 8, 8,
  125212. };
  125213. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125214. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125215. 3.5, 4.5,
  125216. };
  125217. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125218. 9, 7, 5, 3, 1, 0, 2, 4,
  125219. 6, 8, 10,
  125220. };
  125221. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125222. _vq_quantthresh__44c1_sm_p6_1,
  125223. _vq_quantmap__44c1_sm_p6_1,
  125224. 11,
  125225. 11
  125226. };
  125227. static static_codebook _44c1_sm_p6_1 = {
  125228. 2, 121,
  125229. _vq_lengthlist__44c1_sm_p6_1,
  125230. 1, -531365888, 1611661312, 4, 0,
  125231. _vq_quantlist__44c1_sm_p6_1,
  125232. NULL,
  125233. &_vq_auxt__44c1_sm_p6_1,
  125234. NULL,
  125235. 0
  125236. };
  125237. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125238. 6,
  125239. 5,
  125240. 7,
  125241. 4,
  125242. 8,
  125243. 3,
  125244. 9,
  125245. 2,
  125246. 10,
  125247. 1,
  125248. 11,
  125249. 0,
  125250. 12,
  125251. };
  125252. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125253. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125254. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125255. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125256. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125257. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125258. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125259. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125260. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125261. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125262. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125263. 0,12,12,11,11,13,12,14,13,
  125264. };
  125265. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125266. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125267. 12.5, 17.5, 22.5, 27.5,
  125268. };
  125269. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125270. 11, 9, 7, 5, 3, 1, 0, 2,
  125271. 4, 6, 8, 10, 12,
  125272. };
  125273. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125274. _vq_quantthresh__44c1_sm_p7_0,
  125275. _vq_quantmap__44c1_sm_p7_0,
  125276. 13,
  125277. 13
  125278. };
  125279. static static_codebook _44c1_sm_p7_0 = {
  125280. 2, 169,
  125281. _vq_lengthlist__44c1_sm_p7_0,
  125282. 1, -526516224, 1616117760, 4, 0,
  125283. _vq_quantlist__44c1_sm_p7_0,
  125284. NULL,
  125285. &_vq_auxt__44c1_sm_p7_0,
  125286. NULL,
  125287. 0
  125288. };
  125289. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125290. 2,
  125291. 1,
  125292. 3,
  125293. 0,
  125294. 4,
  125295. };
  125296. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125297. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125298. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125299. };
  125300. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125301. -1.5, -0.5, 0.5, 1.5,
  125302. };
  125303. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125304. 3, 1, 0, 2, 4,
  125305. };
  125306. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125307. _vq_quantthresh__44c1_sm_p7_1,
  125308. _vq_quantmap__44c1_sm_p7_1,
  125309. 5,
  125310. 5
  125311. };
  125312. static static_codebook _44c1_sm_p7_1 = {
  125313. 2, 25,
  125314. _vq_lengthlist__44c1_sm_p7_1,
  125315. 1, -533725184, 1611661312, 3, 0,
  125316. _vq_quantlist__44c1_sm_p7_1,
  125317. NULL,
  125318. &_vq_auxt__44c1_sm_p7_1,
  125319. NULL,
  125320. 0
  125321. };
  125322. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125323. 6,
  125324. 5,
  125325. 7,
  125326. 4,
  125327. 8,
  125328. 3,
  125329. 9,
  125330. 2,
  125331. 10,
  125332. 1,
  125333. 11,
  125334. 0,
  125335. 12,
  125336. };
  125337. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125338. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125339. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125340. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125341. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125342. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125343. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125344. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125345. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125346. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125347. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125348. 13,13,13,13,13,13,13,13,13,
  125349. };
  125350. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125351. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125352. 552.5, 773.5, 994.5, 1215.5,
  125353. };
  125354. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125355. 11, 9, 7, 5, 3, 1, 0, 2,
  125356. 4, 6, 8, 10, 12,
  125357. };
  125358. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125359. _vq_quantthresh__44c1_sm_p8_0,
  125360. _vq_quantmap__44c1_sm_p8_0,
  125361. 13,
  125362. 13
  125363. };
  125364. static static_codebook _44c1_sm_p8_0 = {
  125365. 2, 169,
  125366. _vq_lengthlist__44c1_sm_p8_0,
  125367. 1, -514541568, 1627103232, 4, 0,
  125368. _vq_quantlist__44c1_sm_p8_0,
  125369. NULL,
  125370. &_vq_auxt__44c1_sm_p8_0,
  125371. NULL,
  125372. 0
  125373. };
  125374. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125375. 6,
  125376. 5,
  125377. 7,
  125378. 4,
  125379. 8,
  125380. 3,
  125381. 9,
  125382. 2,
  125383. 10,
  125384. 1,
  125385. 11,
  125386. 0,
  125387. 12,
  125388. };
  125389. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125390. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125391. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125392. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125393. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125394. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125395. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125396. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125397. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125398. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125399. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125400. 20,13,12,12,12,14,12,14,13,
  125401. };
  125402. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125403. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125404. 42.5, 59.5, 76.5, 93.5,
  125405. };
  125406. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125407. 11, 9, 7, 5, 3, 1, 0, 2,
  125408. 4, 6, 8, 10, 12,
  125409. };
  125410. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125411. _vq_quantthresh__44c1_sm_p8_1,
  125412. _vq_quantmap__44c1_sm_p8_1,
  125413. 13,
  125414. 13
  125415. };
  125416. static static_codebook _44c1_sm_p8_1 = {
  125417. 2, 169,
  125418. _vq_lengthlist__44c1_sm_p8_1,
  125419. 1, -522616832, 1620115456, 4, 0,
  125420. _vq_quantlist__44c1_sm_p8_1,
  125421. NULL,
  125422. &_vq_auxt__44c1_sm_p8_1,
  125423. NULL,
  125424. 0
  125425. };
  125426. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125427. 8,
  125428. 7,
  125429. 9,
  125430. 6,
  125431. 10,
  125432. 5,
  125433. 11,
  125434. 4,
  125435. 12,
  125436. 3,
  125437. 13,
  125438. 2,
  125439. 14,
  125440. 1,
  125441. 15,
  125442. 0,
  125443. 16,
  125444. };
  125445. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125446. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125447. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125448. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125449. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125450. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125451. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125452. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125453. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125454. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125455. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125456. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125457. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125458. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125459. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125460. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125461. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125462. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125463. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125464. 9,
  125465. };
  125466. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125467. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125468. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125469. };
  125470. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125471. 15, 13, 11, 9, 7, 5, 3, 1,
  125472. 0, 2, 4, 6, 8, 10, 12, 14,
  125473. 16,
  125474. };
  125475. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125476. _vq_quantthresh__44c1_sm_p8_2,
  125477. _vq_quantmap__44c1_sm_p8_2,
  125478. 17,
  125479. 17
  125480. };
  125481. static static_codebook _44c1_sm_p8_2 = {
  125482. 2, 289,
  125483. _vq_lengthlist__44c1_sm_p8_2,
  125484. 1, -529530880, 1611661312, 5, 0,
  125485. _vq_quantlist__44c1_sm_p8_2,
  125486. NULL,
  125487. &_vq_auxt__44c1_sm_p8_2,
  125488. NULL,
  125489. 0
  125490. };
  125491. static long _huff_lengthlist__44c1_sm_short[] = {
  125492. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125493. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125494. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125495. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125496. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125497. 11,
  125498. };
  125499. static static_codebook _huff_book__44c1_sm_short = {
  125500. 2, 81,
  125501. _huff_lengthlist__44c1_sm_short,
  125502. 0, 0, 0, 0, 0,
  125503. NULL,
  125504. NULL,
  125505. NULL,
  125506. NULL,
  125507. 0
  125508. };
  125509. static long _huff_lengthlist__44cn1_s_long[] = {
  125510. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125511. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125512. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125513. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125514. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125515. 20,
  125516. };
  125517. static static_codebook _huff_book__44cn1_s_long = {
  125518. 2, 81,
  125519. _huff_lengthlist__44cn1_s_long,
  125520. 0, 0, 0, 0, 0,
  125521. NULL,
  125522. NULL,
  125523. NULL,
  125524. NULL,
  125525. 0
  125526. };
  125527. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125528. 1,
  125529. 0,
  125530. 2,
  125531. };
  125532. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125533. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125534. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125538. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125539. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125543. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125544. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  125579. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  125584. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  125589. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  125590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125624. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125625. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125630. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125635. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  125636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125841. 0, 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,
  125944. };
  125945. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  125946. -0.5, 0.5,
  125947. };
  125948. static long _vq_quantmap__44cn1_s_p1_0[] = {
  125949. 1, 0, 2,
  125950. };
  125951. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  125952. _vq_quantthresh__44cn1_s_p1_0,
  125953. _vq_quantmap__44cn1_s_p1_0,
  125954. 3,
  125955. 3
  125956. };
  125957. static static_codebook _44cn1_s_p1_0 = {
  125958. 8, 6561,
  125959. _vq_lengthlist__44cn1_s_p1_0,
  125960. 1, -535822336, 1611661312, 2, 0,
  125961. _vq_quantlist__44cn1_s_p1_0,
  125962. NULL,
  125963. &_vq_auxt__44cn1_s_p1_0,
  125964. NULL,
  125965. 0
  125966. };
  125967. static long _vq_quantlist__44cn1_s_p2_0[] = {
  125968. 2,
  125969. 1,
  125970. 3,
  125971. 0,
  125972. 4,
  125973. };
  125974. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  125975. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  125977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125978. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  125980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125981. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  126015. };
  126016. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126017. -1.5, -0.5, 0.5, 1.5,
  126018. };
  126019. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126020. 3, 1, 0, 2, 4,
  126021. };
  126022. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126023. _vq_quantthresh__44cn1_s_p2_0,
  126024. _vq_quantmap__44cn1_s_p2_0,
  126025. 5,
  126026. 5
  126027. };
  126028. static static_codebook _44cn1_s_p2_0 = {
  126029. 4, 625,
  126030. _vq_lengthlist__44cn1_s_p2_0,
  126031. 1, -533725184, 1611661312, 3, 0,
  126032. _vq_quantlist__44cn1_s_p2_0,
  126033. NULL,
  126034. &_vq_auxt__44cn1_s_p2_0,
  126035. NULL,
  126036. 0
  126037. };
  126038. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126039. 4,
  126040. 3,
  126041. 5,
  126042. 2,
  126043. 6,
  126044. 1,
  126045. 7,
  126046. 0,
  126047. 8,
  126048. };
  126049. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126050. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126051. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126052. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126053. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126054. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126055. 0,
  126056. };
  126057. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126058. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126059. };
  126060. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126061. 7, 5, 3, 1, 0, 2, 4, 6,
  126062. 8,
  126063. };
  126064. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126065. _vq_quantthresh__44cn1_s_p3_0,
  126066. _vq_quantmap__44cn1_s_p3_0,
  126067. 9,
  126068. 9
  126069. };
  126070. static static_codebook _44cn1_s_p3_0 = {
  126071. 2, 81,
  126072. _vq_lengthlist__44cn1_s_p3_0,
  126073. 1, -531628032, 1611661312, 4, 0,
  126074. _vq_quantlist__44cn1_s_p3_0,
  126075. NULL,
  126076. &_vq_auxt__44cn1_s_p3_0,
  126077. NULL,
  126078. 0
  126079. };
  126080. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126081. 4,
  126082. 3,
  126083. 5,
  126084. 2,
  126085. 6,
  126086. 1,
  126087. 7,
  126088. 0,
  126089. 8,
  126090. };
  126091. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126092. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126093. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126094. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126095. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126096. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126097. 11,
  126098. };
  126099. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126100. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126101. };
  126102. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126103. 7, 5, 3, 1, 0, 2, 4, 6,
  126104. 8,
  126105. };
  126106. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126107. _vq_quantthresh__44cn1_s_p4_0,
  126108. _vq_quantmap__44cn1_s_p4_0,
  126109. 9,
  126110. 9
  126111. };
  126112. static static_codebook _44cn1_s_p4_0 = {
  126113. 2, 81,
  126114. _vq_lengthlist__44cn1_s_p4_0,
  126115. 1, -531628032, 1611661312, 4, 0,
  126116. _vq_quantlist__44cn1_s_p4_0,
  126117. NULL,
  126118. &_vq_auxt__44cn1_s_p4_0,
  126119. NULL,
  126120. 0
  126121. };
  126122. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126123. 8,
  126124. 7,
  126125. 9,
  126126. 6,
  126127. 10,
  126128. 5,
  126129. 11,
  126130. 4,
  126131. 12,
  126132. 3,
  126133. 13,
  126134. 2,
  126135. 14,
  126136. 1,
  126137. 15,
  126138. 0,
  126139. 16,
  126140. };
  126141. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126142. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126143. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126144. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126145. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126146. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126147. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126148. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126149. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126150. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126151. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126152. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126153. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126154. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126155. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126156. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126157. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126158. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126159. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126160. 14,
  126161. };
  126162. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126163. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126164. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126165. };
  126166. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126167. 15, 13, 11, 9, 7, 5, 3, 1,
  126168. 0, 2, 4, 6, 8, 10, 12, 14,
  126169. 16,
  126170. };
  126171. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126172. _vq_quantthresh__44cn1_s_p5_0,
  126173. _vq_quantmap__44cn1_s_p5_0,
  126174. 17,
  126175. 17
  126176. };
  126177. static static_codebook _44cn1_s_p5_0 = {
  126178. 2, 289,
  126179. _vq_lengthlist__44cn1_s_p5_0,
  126180. 1, -529530880, 1611661312, 5, 0,
  126181. _vq_quantlist__44cn1_s_p5_0,
  126182. NULL,
  126183. &_vq_auxt__44cn1_s_p5_0,
  126184. NULL,
  126185. 0
  126186. };
  126187. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126188. 1,
  126189. 0,
  126190. 2,
  126191. };
  126192. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126193. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126194. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126195. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126196. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126197. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126198. 10,
  126199. };
  126200. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126201. -5.5, 5.5,
  126202. };
  126203. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126204. 1, 0, 2,
  126205. };
  126206. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126207. _vq_quantthresh__44cn1_s_p6_0,
  126208. _vq_quantmap__44cn1_s_p6_0,
  126209. 3,
  126210. 3
  126211. };
  126212. static static_codebook _44cn1_s_p6_0 = {
  126213. 4, 81,
  126214. _vq_lengthlist__44cn1_s_p6_0,
  126215. 1, -529137664, 1618345984, 2, 0,
  126216. _vq_quantlist__44cn1_s_p6_0,
  126217. NULL,
  126218. &_vq_auxt__44cn1_s_p6_0,
  126219. NULL,
  126220. 0
  126221. };
  126222. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126223. 5,
  126224. 4,
  126225. 6,
  126226. 3,
  126227. 7,
  126228. 2,
  126229. 8,
  126230. 1,
  126231. 9,
  126232. 0,
  126233. 10,
  126234. };
  126235. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126236. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126237. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126238. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126239. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126240. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126241. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126242. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126243. 10,10,10, 9, 9, 9, 9, 9, 9,
  126244. };
  126245. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126246. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126247. 3.5, 4.5,
  126248. };
  126249. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126250. 9, 7, 5, 3, 1, 0, 2, 4,
  126251. 6, 8, 10,
  126252. };
  126253. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126254. _vq_quantthresh__44cn1_s_p6_1,
  126255. _vq_quantmap__44cn1_s_p6_1,
  126256. 11,
  126257. 11
  126258. };
  126259. static static_codebook _44cn1_s_p6_1 = {
  126260. 2, 121,
  126261. _vq_lengthlist__44cn1_s_p6_1,
  126262. 1, -531365888, 1611661312, 4, 0,
  126263. _vq_quantlist__44cn1_s_p6_1,
  126264. NULL,
  126265. &_vq_auxt__44cn1_s_p6_1,
  126266. NULL,
  126267. 0
  126268. };
  126269. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126270. 6,
  126271. 5,
  126272. 7,
  126273. 4,
  126274. 8,
  126275. 3,
  126276. 9,
  126277. 2,
  126278. 10,
  126279. 1,
  126280. 11,
  126281. 0,
  126282. 12,
  126283. };
  126284. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126285. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126286. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126287. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126288. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126289. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126290. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126291. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126292. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126293. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126294. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126295. 0,13,13,12,12,13,13,13,14,
  126296. };
  126297. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126298. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126299. 12.5, 17.5, 22.5, 27.5,
  126300. };
  126301. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126302. 11, 9, 7, 5, 3, 1, 0, 2,
  126303. 4, 6, 8, 10, 12,
  126304. };
  126305. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126306. _vq_quantthresh__44cn1_s_p7_0,
  126307. _vq_quantmap__44cn1_s_p7_0,
  126308. 13,
  126309. 13
  126310. };
  126311. static static_codebook _44cn1_s_p7_0 = {
  126312. 2, 169,
  126313. _vq_lengthlist__44cn1_s_p7_0,
  126314. 1, -526516224, 1616117760, 4, 0,
  126315. _vq_quantlist__44cn1_s_p7_0,
  126316. NULL,
  126317. &_vq_auxt__44cn1_s_p7_0,
  126318. NULL,
  126319. 0
  126320. };
  126321. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126322. 2,
  126323. 1,
  126324. 3,
  126325. 0,
  126326. 4,
  126327. };
  126328. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126329. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126330. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126331. };
  126332. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126333. -1.5, -0.5, 0.5, 1.5,
  126334. };
  126335. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126336. 3, 1, 0, 2, 4,
  126337. };
  126338. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126339. _vq_quantthresh__44cn1_s_p7_1,
  126340. _vq_quantmap__44cn1_s_p7_1,
  126341. 5,
  126342. 5
  126343. };
  126344. static static_codebook _44cn1_s_p7_1 = {
  126345. 2, 25,
  126346. _vq_lengthlist__44cn1_s_p7_1,
  126347. 1, -533725184, 1611661312, 3, 0,
  126348. _vq_quantlist__44cn1_s_p7_1,
  126349. NULL,
  126350. &_vq_auxt__44cn1_s_p7_1,
  126351. NULL,
  126352. 0
  126353. };
  126354. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126355. 2,
  126356. 1,
  126357. 3,
  126358. 0,
  126359. 4,
  126360. };
  126361. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126362. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126363. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126364. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126365. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126366. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126367. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126368. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126369. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126370. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126371. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126372. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126373. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126374. 11,11,11,11,11,11,11,11,11,11,11,11,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,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126377. 11,11,11,11,11,11,11,11,11,11, 8,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,11,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,11,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,11,
  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,11,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,12,12,12,12,12,12,12,12,12,
  126396. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126397. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126398. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126399. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126400. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126401. 12,
  126402. };
  126403. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126404. -331.5, -110.5, 110.5, 331.5,
  126405. };
  126406. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126407. 3, 1, 0, 2, 4,
  126408. };
  126409. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126410. _vq_quantthresh__44cn1_s_p8_0,
  126411. _vq_quantmap__44cn1_s_p8_0,
  126412. 5,
  126413. 5
  126414. };
  126415. static static_codebook _44cn1_s_p8_0 = {
  126416. 4, 625,
  126417. _vq_lengthlist__44cn1_s_p8_0,
  126418. 1, -518283264, 1627103232, 3, 0,
  126419. _vq_quantlist__44cn1_s_p8_0,
  126420. NULL,
  126421. &_vq_auxt__44cn1_s_p8_0,
  126422. NULL,
  126423. 0
  126424. };
  126425. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126426. 6,
  126427. 5,
  126428. 7,
  126429. 4,
  126430. 8,
  126431. 3,
  126432. 9,
  126433. 2,
  126434. 10,
  126435. 1,
  126436. 11,
  126437. 0,
  126438. 12,
  126439. };
  126440. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126441. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126442. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126443. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126444. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126445. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126446. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126447. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126448. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126449. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126450. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126451. 15,12,12,11,11,14,12,13,14,
  126452. };
  126453. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126454. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126455. 42.5, 59.5, 76.5, 93.5,
  126456. };
  126457. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126458. 11, 9, 7, 5, 3, 1, 0, 2,
  126459. 4, 6, 8, 10, 12,
  126460. };
  126461. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126462. _vq_quantthresh__44cn1_s_p8_1,
  126463. _vq_quantmap__44cn1_s_p8_1,
  126464. 13,
  126465. 13
  126466. };
  126467. static static_codebook _44cn1_s_p8_1 = {
  126468. 2, 169,
  126469. _vq_lengthlist__44cn1_s_p8_1,
  126470. 1, -522616832, 1620115456, 4, 0,
  126471. _vq_quantlist__44cn1_s_p8_1,
  126472. NULL,
  126473. &_vq_auxt__44cn1_s_p8_1,
  126474. NULL,
  126475. 0
  126476. };
  126477. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126478. 8,
  126479. 7,
  126480. 9,
  126481. 6,
  126482. 10,
  126483. 5,
  126484. 11,
  126485. 4,
  126486. 12,
  126487. 3,
  126488. 13,
  126489. 2,
  126490. 14,
  126491. 1,
  126492. 15,
  126493. 0,
  126494. 16,
  126495. };
  126496. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126497. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126498. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126499. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126500. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126501. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126502. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126503. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126504. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126505. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126506. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126507. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126508. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126509. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126510. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126511. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126512. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126513. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126514. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126515. 9,
  126516. };
  126517. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126518. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126519. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126520. };
  126521. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126522. 15, 13, 11, 9, 7, 5, 3, 1,
  126523. 0, 2, 4, 6, 8, 10, 12, 14,
  126524. 16,
  126525. };
  126526. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126527. _vq_quantthresh__44cn1_s_p8_2,
  126528. _vq_quantmap__44cn1_s_p8_2,
  126529. 17,
  126530. 17
  126531. };
  126532. static static_codebook _44cn1_s_p8_2 = {
  126533. 2, 289,
  126534. _vq_lengthlist__44cn1_s_p8_2,
  126535. 1, -529530880, 1611661312, 5, 0,
  126536. _vq_quantlist__44cn1_s_p8_2,
  126537. NULL,
  126538. &_vq_auxt__44cn1_s_p8_2,
  126539. NULL,
  126540. 0
  126541. };
  126542. static long _huff_lengthlist__44cn1_s_short[] = {
  126543. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126544. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126545. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126546. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126547. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126548. 10,
  126549. };
  126550. static static_codebook _huff_book__44cn1_s_short = {
  126551. 2, 81,
  126552. _huff_lengthlist__44cn1_s_short,
  126553. 0, 0, 0, 0, 0,
  126554. NULL,
  126555. NULL,
  126556. NULL,
  126557. NULL,
  126558. 0
  126559. };
  126560. static long _huff_lengthlist__44cn1_sm_long[] = {
  126561. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126562. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126563. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126564. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126565. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126566. 17,
  126567. };
  126568. static static_codebook _huff_book__44cn1_sm_long = {
  126569. 2, 81,
  126570. _huff_lengthlist__44cn1_sm_long,
  126571. 0, 0, 0, 0, 0,
  126572. NULL,
  126573. NULL,
  126574. NULL,
  126575. NULL,
  126576. 0
  126577. };
  126578. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126579. 1,
  126580. 0,
  126581. 2,
  126582. };
  126583. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126584. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126585. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126589. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126590. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126594. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126595. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126630. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  126635. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  126640. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  126641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126675. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126676. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126681. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126686. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  126687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126892. 0, 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,
  126995. };
  126996. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  126997. -0.5, 0.5,
  126998. };
  126999. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127000. 1, 0, 2,
  127001. };
  127002. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127003. _vq_quantthresh__44cn1_sm_p1_0,
  127004. _vq_quantmap__44cn1_sm_p1_0,
  127005. 3,
  127006. 3
  127007. };
  127008. static static_codebook _44cn1_sm_p1_0 = {
  127009. 8, 6561,
  127010. _vq_lengthlist__44cn1_sm_p1_0,
  127011. 1, -535822336, 1611661312, 2, 0,
  127012. _vq_quantlist__44cn1_sm_p1_0,
  127013. NULL,
  127014. &_vq_auxt__44cn1_sm_p1_0,
  127015. NULL,
  127016. 0
  127017. };
  127018. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127019. 2,
  127020. 1,
  127021. 3,
  127022. 0,
  127023. 4,
  127024. };
  127025. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127026. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127029. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127032. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  127066. };
  127067. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127068. -1.5, -0.5, 0.5, 1.5,
  127069. };
  127070. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127071. 3, 1, 0, 2, 4,
  127072. };
  127073. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127074. _vq_quantthresh__44cn1_sm_p2_0,
  127075. _vq_quantmap__44cn1_sm_p2_0,
  127076. 5,
  127077. 5
  127078. };
  127079. static static_codebook _44cn1_sm_p2_0 = {
  127080. 4, 625,
  127081. _vq_lengthlist__44cn1_sm_p2_0,
  127082. 1, -533725184, 1611661312, 3, 0,
  127083. _vq_quantlist__44cn1_sm_p2_0,
  127084. NULL,
  127085. &_vq_auxt__44cn1_sm_p2_0,
  127086. NULL,
  127087. 0
  127088. };
  127089. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127090. 4,
  127091. 3,
  127092. 5,
  127093. 2,
  127094. 6,
  127095. 1,
  127096. 7,
  127097. 0,
  127098. 8,
  127099. };
  127100. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127101. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127102. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127103. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127104. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127105. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127106. 0,
  127107. };
  127108. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127109. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127110. };
  127111. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127112. 7, 5, 3, 1, 0, 2, 4, 6,
  127113. 8,
  127114. };
  127115. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127116. _vq_quantthresh__44cn1_sm_p3_0,
  127117. _vq_quantmap__44cn1_sm_p3_0,
  127118. 9,
  127119. 9
  127120. };
  127121. static static_codebook _44cn1_sm_p3_0 = {
  127122. 2, 81,
  127123. _vq_lengthlist__44cn1_sm_p3_0,
  127124. 1, -531628032, 1611661312, 4, 0,
  127125. _vq_quantlist__44cn1_sm_p3_0,
  127126. NULL,
  127127. &_vq_auxt__44cn1_sm_p3_0,
  127128. NULL,
  127129. 0
  127130. };
  127131. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127132. 4,
  127133. 3,
  127134. 5,
  127135. 2,
  127136. 6,
  127137. 1,
  127138. 7,
  127139. 0,
  127140. 8,
  127141. };
  127142. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127143. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127144. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127145. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127146. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127147. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127148. 11,
  127149. };
  127150. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127151. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127152. };
  127153. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127154. 7, 5, 3, 1, 0, 2, 4, 6,
  127155. 8,
  127156. };
  127157. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127158. _vq_quantthresh__44cn1_sm_p4_0,
  127159. _vq_quantmap__44cn1_sm_p4_0,
  127160. 9,
  127161. 9
  127162. };
  127163. static static_codebook _44cn1_sm_p4_0 = {
  127164. 2, 81,
  127165. _vq_lengthlist__44cn1_sm_p4_0,
  127166. 1, -531628032, 1611661312, 4, 0,
  127167. _vq_quantlist__44cn1_sm_p4_0,
  127168. NULL,
  127169. &_vq_auxt__44cn1_sm_p4_0,
  127170. NULL,
  127171. 0
  127172. };
  127173. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127174. 8,
  127175. 7,
  127176. 9,
  127177. 6,
  127178. 10,
  127179. 5,
  127180. 11,
  127181. 4,
  127182. 12,
  127183. 3,
  127184. 13,
  127185. 2,
  127186. 14,
  127187. 1,
  127188. 15,
  127189. 0,
  127190. 16,
  127191. };
  127192. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127193. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127194. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127195. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127196. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127197. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127198. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127199. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127200. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127201. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127202. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127203. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127204. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127205. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127206. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127207. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127208. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127209. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127210. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127211. 14,
  127212. };
  127213. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127214. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127215. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127216. };
  127217. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127218. 15, 13, 11, 9, 7, 5, 3, 1,
  127219. 0, 2, 4, 6, 8, 10, 12, 14,
  127220. 16,
  127221. };
  127222. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127223. _vq_quantthresh__44cn1_sm_p5_0,
  127224. _vq_quantmap__44cn1_sm_p5_0,
  127225. 17,
  127226. 17
  127227. };
  127228. static static_codebook _44cn1_sm_p5_0 = {
  127229. 2, 289,
  127230. _vq_lengthlist__44cn1_sm_p5_0,
  127231. 1, -529530880, 1611661312, 5, 0,
  127232. _vq_quantlist__44cn1_sm_p5_0,
  127233. NULL,
  127234. &_vq_auxt__44cn1_sm_p5_0,
  127235. NULL,
  127236. 0
  127237. };
  127238. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127239. 1,
  127240. 0,
  127241. 2,
  127242. };
  127243. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127244. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127245. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127246. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127247. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127248. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127249. 10,
  127250. };
  127251. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127252. -5.5, 5.5,
  127253. };
  127254. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127255. 1, 0, 2,
  127256. };
  127257. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127258. _vq_quantthresh__44cn1_sm_p6_0,
  127259. _vq_quantmap__44cn1_sm_p6_0,
  127260. 3,
  127261. 3
  127262. };
  127263. static static_codebook _44cn1_sm_p6_0 = {
  127264. 4, 81,
  127265. _vq_lengthlist__44cn1_sm_p6_0,
  127266. 1, -529137664, 1618345984, 2, 0,
  127267. _vq_quantlist__44cn1_sm_p6_0,
  127268. NULL,
  127269. &_vq_auxt__44cn1_sm_p6_0,
  127270. NULL,
  127271. 0
  127272. };
  127273. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127274. 5,
  127275. 4,
  127276. 6,
  127277. 3,
  127278. 7,
  127279. 2,
  127280. 8,
  127281. 1,
  127282. 9,
  127283. 0,
  127284. 10,
  127285. };
  127286. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127287. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127288. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127289. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127290. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127291. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127292. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127293. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127294. 10,10,10, 8, 9, 8, 8, 9, 8,
  127295. };
  127296. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127297. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127298. 3.5, 4.5,
  127299. };
  127300. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127301. 9, 7, 5, 3, 1, 0, 2, 4,
  127302. 6, 8, 10,
  127303. };
  127304. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127305. _vq_quantthresh__44cn1_sm_p6_1,
  127306. _vq_quantmap__44cn1_sm_p6_1,
  127307. 11,
  127308. 11
  127309. };
  127310. static static_codebook _44cn1_sm_p6_1 = {
  127311. 2, 121,
  127312. _vq_lengthlist__44cn1_sm_p6_1,
  127313. 1, -531365888, 1611661312, 4, 0,
  127314. _vq_quantlist__44cn1_sm_p6_1,
  127315. NULL,
  127316. &_vq_auxt__44cn1_sm_p6_1,
  127317. NULL,
  127318. 0
  127319. };
  127320. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127321. 6,
  127322. 5,
  127323. 7,
  127324. 4,
  127325. 8,
  127326. 3,
  127327. 9,
  127328. 2,
  127329. 10,
  127330. 1,
  127331. 11,
  127332. 0,
  127333. 12,
  127334. };
  127335. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127336. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127337. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127338. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127339. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127340. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127341. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127342. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127343. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127344. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127345. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127346. 0,13,12,12,12,13,13,13,14,
  127347. };
  127348. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127349. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127350. 12.5, 17.5, 22.5, 27.5,
  127351. };
  127352. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127353. 11, 9, 7, 5, 3, 1, 0, 2,
  127354. 4, 6, 8, 10, 12,
  127355. };
  127356. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127357. _vq_quantthresh__44cn1_sm_p7_0,
  127358. _vq_quantmap__44cn1_sm_p7_0,
  127359. 13,
  127360. 13
  127361. };
  127362. static static_codebook _44cn1_sm_p7_0 = {
  127363. 2, 169,
  127364. _vq_lengthlist__44cn1_sm_p7_0,
  127365. 1, -526516224, 1616117760, 4, 0,
  127366. _vq_quantlist__44cn1_sm_p7_0,
  127367. NULL,
  127368. &_vq_auxt__44cn1_sm_p7_0,
  127369. NULL,
  127370. 0
  127371. };
  127372. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127373. 2,
  127374. 1,
  127375. 3,
  127376. 0,
  127377. 4,
  127378. };
  127379. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127380. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127381. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127382. };
  127383. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127384. -1.5, -0.5, 0.5, 1.5,
  127385. };
  127386. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127387. 3, 1, 0, 2, 4,
  127388. };
  127389. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127390. _vq_quantthresh__44cn1_sm_p7_1,
  127391. _vq_quantmap__44cn1_sm_p7_1,
  127392. 5,
  127393. 5
  127394. };
  127395. static static_codebook _44cn1_sm_p7_1 = {
  127396. 2, 25,
  127397. _vq_lengthlist__44cn1_sm_p7_1,
  127398. 1, -533725184, 1611661312, 3, 0,
  127399. _vq_quantlist__44cn1_sm_p7_1,
  127400. NULL,
  127401. &_vq_auxt__44cn1_sm_p7_1,
  127402. NULL,
  127403. 0
  127404. };
  127405. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127406. 4,
  127407. 3,
  127408. 5,
  127409. 2,
  127410. 6,
  127411. 1,
  127412. 7,
  127413. 0,
  127414. 8,
  127415. };
  127416. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127417. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127418. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127419. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127420. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127421. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127422. 14,
  127423. };
  127424. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127425. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127426. };
  127427. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127428. 7, 5, 3, 1, 0, 2, 4, 6,
  127429. 8,
  127430. };
  127431. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127432. _vq_quantthresh__44cn1_sm_p8_0,
  127433. _vq_quantmap__44cn1_sm_p8_0,
  127434. 9,
  127435. 9
  127436. };
  127437. static static_codebook _44cn1_sm_p8_0 = {
  127438. 2, 81,
  127439. _vq_lengthlist__44cn1_sm_p8_0,
  127440. 1, -516186112, 1627103232, 4, 0,
  127441. _vq_quantlist__44cn1_sm_p8_0,
  127442. NULL,
  127443. &_vq_auxt__44cn1_sm_p8_0,
  127444. NULL,
  127445. 0
  127446. };
  127447. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127448. 6,
  127449. 5,
  127450. 7,
  127451. 4,
  127452. 8,
  127453. 3,
  127454. 9,
  127455. 2,
  127456. 10,
  127457. 1,
  127458. 11,
  127459. 0,
  127460. 12,
  127461. };
  127462. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127463. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127464. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127465. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127466. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127467. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127468. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127469. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127470. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127471. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127472. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127473. 17,12,12,11,10,13,11,13,13,
  127474. };
  127475. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127476. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127477. 42.5, 59.5, 76.5, 93.5,
  127478. };
  127479. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127480. 11, 9, 7, 5, 3, 1, 0, 2,
  127481. 4, 6, 8, 10, 12,
  127482. };
  127483. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127484. _vq_quantthresh__44cn1_sm_p8_1,
  127485. _vq_quantmap__44cn1_sm_p8_1,
  127486. 13,
  127487. 13
  127488. };
  127489. static static_codebook _44cn1_sm_p8_1 = {
  127490. 2, 169,
  127491. _vq_lengthlist__44cn1_sm_p8_1,
  127492. 1, -522616832, 1620115456, 4, 0,
  127493. _vq_quantlist__44cn1_sm_p8_1,
  127494. NULL,
  127495. &_vq_auxt__44cn1_sm_p8_1,
  127496. NULL,
  127497. 0
  127498. };
  127499. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127500. 8,
  127501. 7,
  127502. 9,
  127503. 6,
  127504. 10,
  127505. 5,
  127506. 11,
  127507. 4,
  127508. 12,
  127509. 3,
  127510. 13,
  127511. 2,
  127512. 14,
  127513. 1,
  127514. 15,
  127515. 0,
  127516. 16,
  127517. };
  127518. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127519. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127520. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127521. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127522. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127523. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127524. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127525. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127526. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127527. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127528. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127529. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127530. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127531. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127532. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127533. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127534. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127535. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127536. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127537. 9,
  127538. };
  127539. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127540. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127541. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127542. };
  127543. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127544. 15, 13, 11, 9, 7, 5, 3, 1,
  127545. 0, 2, 4, 6, 8, 10, 12, 14,
  127546. 16,
  127547. };
  127548. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127549. _vq_quantthresh__44cn1_sm_p8_2,
  127550. _vq_quantmap__44cn1_sm_p8_2,
  127551. 17,
  127552. 17
  127553. };
  127554. static static_codebook _44cn1_sm_p8_2 = {
  127555. 2, 289,
  127556. _vq_lengthlist__44cn1_sm_p8_2,
  127557. 1, -529530880, 1611661312, 5, 0,
  127558. _vq_quantlist__44cn1_sm_p8_2,
  127559. NULL,
  127560. &_vq_auxt__44cn1_sm_p8_2,
  127561. NULL,
  127562. 0
  127563. };
  127564. static long _huff_lengthlist__44cn1_sm_short[] = {
  127565. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127566. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127567. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127568. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127569. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127570. 9,
  127571. };
  127572. static static_codebook _huff_book__44cn1_sm_short = {
  127573. 2, 81,
  127574. _huff_lengthlist__44cn1_sm_short,
  127575. 0, 0, 0, 0, 0,
  127576. NULL,
  127577. NULL,
  127578. NULL,
  127579. NULL,
  127580. 0
  127581. };
  127582. /*** End of inlined file: res_books_stereo.h ***/
  127583. static vorbis_info_residue0 _residue_44_low={
  127584. 0,-1, -1, 9,-1,
  127585. {0},
  127586. {-1},
  127587. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127588. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127589. };
  127590. static vorbis_info_residue0 _residue_44_mid={
  127591. 0,-1, -1, 10,-1,
  127592. {0},
  127593. {-1},
  127594. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127595. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127596. };
  127597. static vorbis_info_residue0 _residue_44_high={
  127598. 0,-1, -1, 10,-1,
  127599. {0},
  127600. {-1},
  127601. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127602. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127603. };
  127604. static static_bookblock _resbook_44s_n1={
  127605. {
  127606. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127607. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127608. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127609. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127610. }
  127611. };
  127612. static static_bookblock _resbook_44sm_n1={
  127613. {
  127614. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127615. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127616. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127617. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127618. }
  127619. };
  127620. static static_bookblock _resbook_44s_0={
  127621. {
  127622. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127623. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127624. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127625. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127626. }
  127627. };
  127628. static static_bookblock _resbook_44sm_0={
  127629. {
  127630. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127631. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127632. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127633. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127634. }
  127635. };
  127636. static static_bookblock _resbook_44s_1={
  127637. {
  127638. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127639. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127640. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127641. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127642. }
  127643. };
  127644. static static_bookblock _resbook_44sm_1={
  127645. {
  127646. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127647. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127648. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127649. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127650. }
  127651. };
  127652. static static_bookblock _resbook_44s_2={
  127653. {
  127654. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127655. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127656. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127657. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127658. }
  127659. };
  127660. static static_bookblock _resbook_44s_3={
  127661. {
  127662. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127663. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127664. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127665. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127666. }
  127667. };
  127668. static static_bookblock _resbook_44s_4={
  127669. {
  127670. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127671. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127672. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127673. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127674. }
  127675. };
  127676. static static_bookblock _resbook_44s_5={
  127677. {
  127678. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127679. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127680. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127681. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127682. }
  127683. };
  127684. static static_bookblock _resbook_44s_6={
  127685. {
  127686. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127687. {0,0,&_44c6_s_p4_0},
  127688. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127689. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127690. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127691. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127692. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127693. }
  127694. };
  127695. static static_bookblock _resbook_44s_7={
  127696. {
  127697. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127698. {0,0,&_44c7_s_p4_0},
  127699. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127700. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127701. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127702. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127703. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127704. }
  127705. };
  127706. static static_bookblock _resbook_44s_8={
  127707. {
  127708. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127709. {0,0,&_44c8_s_p4_0},
  127710. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127711. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127712. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127713. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127714. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127715. }
  127716. };
  127717. static static_bookblock _resbook_44s_9={
  127718. {
  127719. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127720. {0,0,&_44c9_s_p4_0},
  127721. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127722. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127723. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127724. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127725. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127726. }
  127727. };
  127728. static vorbis_residue_template _res_44s_n1[]={
  127729. {2,0, &_residue_44_low,
  127730. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127731. &_resbook_44s_n1,&_resbook_44sm_n1},
  127732. {2,0, &_residue_44_low,
  127733. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127734. &_resbook_44s_n1,&_resbook_44sm_n1}
  127735. };
  127736. static vorbis_residue_template _res_44s_0[]={
  127737. {2,0, &_residue_44_low,
  127738. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127739. &_resbook_44s_0,&_resbook_44sm_0},
  127740. {2,0, &_residue_44_low,
  127741. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127742. &_resbook_44s_0,&_resbook_44sm_0}
  127743. };
  127744. static vorbis_residue_template _res_44s_1[]={
  127745. {2,0, &_residue_44_low,
  127746. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127747. &_resbook_44s_1,&_resbook_44sm_1},
  127748. {2,0, &_residue_44_low,
  127749. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127750. &_resbook_44s_1,&_resbook_44sm_1}
  127751. };
  127752. static vorbis_residue_template _res_44s_2[]={
  127753. {2,0, &_residue_44_mid,
  127754. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127755. &_resbook_44s_2,&_resbook_44s_2},
  127756. {2,0, &_residue_44_mid,
  127757. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127758. &_resbook_44s_2,&_resbook_44s_2}
  127759. };
  127760. static vorbis_residue_template _res_44s_3[]={
  127761. {2,0, &_residue_44_mid,
  127762. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127763. &_resbook_44s_3,&_resbook_44s_3},
  127764. {2,0, &_residue_44_mid,
  127765. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127766. &_resbook_44s_3,&_resbook_44s_3}
  127767. };
  127768. static vorbis_residue_template _res_44s_4[]={
  127769. {2,0, &_residue_44_mid,
  127770. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127771. &_resbook_44s_4,&_resbook_44s_4},
  127772. {2,0, &_residue_44_mid,
  127773. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127774. &_resbook_44s_4,&_resbook_44s_4}
  127775. };
  127776. static vorbis_residue_template _res_44s_5[]={
  127777. {2,0, &_residue_44_mid,
  127778. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127779. &_resbook_44s_5,&_resbook_44s_5},
  127780. {2,0, &_residue_44_mid,
  127781. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127782. &_resbook_44s_5,&_resbook_44s_5}
  127783. };
  127784. static vorbis_residue_template _res_44s_6[]={
  127785. {2,0, &_residue_44_high,
  127786. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127787. &_resbook_44s_6,&_resbook_44s_6},
  127788. {2,0, &_residue_44_high,
  127789. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127790. &_resbook_44s_6,&_resbook_44s_6}
  127791. };
  127792. static vorbis_residue_template _res_44s_7[]={
  127793. {2,0, &_residue_44_high,
  127794. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127795. &_resbook_44s_7,&_resbook_44s_7},
  127796. {2,0, &_residue_44_high,
  127797. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127798. &_resbook_44s_7,&_resbook_44s_7}
  127799. };
  127800. static vorbis_residue_template _res_44s_8[]={
  127801. {2,0, &_residue_44_high,
  127802. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127803. &_resbook_44s_8,&_resbook_44s_8},
  127804. {2,0, &_residue_44_high,
  127805. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127806. &_resbook_44s_8,&_resbook_44s_8}
  127807. };
  127808. static vorbis_residue_template _res_44s_9[]={
  127809. {2,0, &_residue_44_high,
  127810. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127811. &_resbook_44s_9,&_resbook_44s_9},
  127812. {2,0, &_residue_44_high,
  127813. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127814. &_resbook_44s_9,&_resbook_44s_9}
  127815. };
  127816. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127817. { _map_nominal, _res_44s_n1 }, /* -1 */
  127818. { _map_nominal, _res_44s_0 }, /* 0 */
  127819. { _map_nominal, _res_44s_1 }, /* 1 */
  127820. { _map_nominal, _res_44s_2 }, /* 2 */
  127821. { _map_nominal, _res_44s_3 }, /* 3 */
  127822. { _map_nominal, _res_44s_4 }, /* 4 */
  127823. { _map_nominal, _res_44s_5 }, /* 5 */
  127824. { _map_nominal, _res_44s_6 }, /* 6 */
  127825. { _map_nominal, _res_44s_7 }, /* 7 */
  127826. { _map_nominal, _res_44s_8 }, /* 8 */
  127827. { _map_nominal, _res_44s_9 }, /* 9 */
  127828. };
  127829. /*** End of inlined file: residue_44.h ***/
  127830. /*** Start of inlined file: psych_44.h ***/
  127831. static vorbis_info_psy_global _psy_global_44[5]={
  127832. {8, /* lines per eighth octave */
  127833. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127834. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127835. -6.f,
  127836. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127837. },
  127838. {8, /* lines per eighth octave */
  127839. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127840. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127841. -6.f,
  127842. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127843. },
  127844. {8, /* lines per eighth octave */
  127845. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127846. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127847. -6.f,
  127848. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127849. },
  127850. {8, /* lines per eighth octave */
  127851. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127852. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127853. -6.f,
  127854. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127855. },
  127856. {8, /* lines per eighth octave */
  127857. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127858. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127859. -6.f,
  127860. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127861. },
  127862. };
  127863. static compandblock _psy_compand_44[6]={
  127864. {{
  127865. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127866. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127867. 16,17,18,19,20,21,22, 23, /* 23dB */
  127868. 24,25,26,27,28,29,30, 31, /* 31dB */
  127869. 32,33,34,35,36,37,38, 39, /* 39dB */
  127870. }},
  127871. {{
  127872. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127873. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127874. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127875. 15,16,17,17,17,18,18, 19, /* 31dB */
  127876. 19,19,20,21,22,23,24, 25, /* 39dB */
  127877. }},
  127878. {{
  127879. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127880. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127881. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127882. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127883. 11,12,13,14,15,16,17, 18, /* 39dB */
  127884. }},
  127885. {{
  127886. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127887. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127888. 16,17,18,19,20,21,22, 23, /* 23dB */
  127889. 24,25,26,27,28,29,30, 31, /* 31dB */
  127890. 32,33,34,35,36,37,38, 39, /* 39dB */
  127891. }},
  127892. {{
  127893. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127894. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127895. 13,14,14,14,15,15,15, 15, /* 23dB */
  127896. 16,16,17,17,17,18,18, 19, /* 31dB */
  127897. 19,19,20,21,22,23,24, 25, /* 39dB */
  127898. }},
  127899. {{
  127900. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127901. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127902. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127903. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127904. 11,12,13,14,15,16,17, 18, /* 39dB */
  127905. }}
  127906. };
  127907. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  127908. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  127909. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  127910. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  127911. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  127912. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  127913. /* 4 */
  127914. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127915. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127916. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127917. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127918. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127919. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127920. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127921. };
  127922. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  127923. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  127924. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  127925. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  127926. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  127927. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  127928. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127929. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127930. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127931. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127932. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127933. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127934. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127935. };
  127936. static noise3 _psy_noisebias_trans[12]={
  127937. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127938. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127939. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127940. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127941. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  127942. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127943. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127944. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127945. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127946. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127947. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127948. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  127949. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127950. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127951. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127952. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127953. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127954. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127955. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127956. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127957. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  127958. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127959. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127960. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127961. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127962. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  127963. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127964. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  127965. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  127966. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127967. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127968. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  127969. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  127970. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  127971. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  127972. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127973. };
  127974. static noise3 _psy_noisebias_long[12]={
  127975. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  127976. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  127977. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127978. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  127979. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  127980. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127981. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127982. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127983. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127984. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127985. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127986. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127987. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127988. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127989. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  127990. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127991. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127992. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  127993. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127994. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127995. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  127996. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127997. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127998. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  127999. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128000. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128001. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128002. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128003. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128004. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128005. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128006. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128007. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128008. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128009. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128010. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128011. };
  128012. static noise3 _psy_noisebias_impulse[12]={
  128013. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128014. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128015. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128016. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128017. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128018. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128019. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128020. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128021. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128022. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128023. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128024. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128025. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128026. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128027. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128028. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128029. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128030. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128031. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128032. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128033. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128034. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128035. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128036. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128037. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128038. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128039. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128040. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128041. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128042. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128043. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128044. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128045. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128046. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128047. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128048. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128049. };
  128050. static noise3 _psy_noisebias_padding[12]={
  128051. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128052. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128053. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128054. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128055. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128056. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128057. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128058. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128059. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128060. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128061. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128062. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128063. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128064. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128065. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128066. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128067. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128068. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128069. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128070. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128071. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128072. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128073. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128074. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128075. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128076. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128077. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128078. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128079. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128080. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128081. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128082. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128083. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128084. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128085. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128086. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128087. };
  128088. static noiseguard _psy_noiseguards_44[4]={
  128089. {3,3,15},
  128090. {3,3,15},
  128091. {10,10,100},
  128092. {10,10,100},
  128093. };
  128094. static int _psy_tone_suppress[12]={
  128095. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128096. };
  128097. static int _psy_tone_0dB[12]={
  128098. 90,90,95,95,95,95,105,105,105,105,105,105,
  128099. };
  128100. static int _psy_noise_suppress[12]={
  128101. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128102. };
  128103. static vorbis_info_psy _psy_info_template={
  128104. -1,
  128105. -140.,-140.,
  128106. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128107. 1, -0.f, .5f, .5f, 0,0,0,
  128108. {{-1},{-1},{-1}},{-1},105.f,
  128109. 0,0,-1,-1,0.,
  128110. };
  128111. static int _psy_ath_floater[12]={
  128112. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128113. };
  128114. static int _psy_ath_abs[12]={
  128115. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128116. };
  128117. static adj_stereo _psy_stereo_modes_44[12]={
  128118. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128119. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128120. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128121. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128122. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128123. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128124. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128125. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128126. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128127. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128128. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128129. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128130. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128131. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128132. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128133. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128134. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128135. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128136. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128137. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128138. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128139. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128140. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128141. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128142. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128143. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128144. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128145. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128146. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128147. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128148. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128149. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128150. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128151. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128152. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128153. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128154. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128155. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128156. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128157. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128158. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128159. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128160. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128161. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128162. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128163. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128164. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128165. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128166. };
  128167. static att3 _psy_tone_masteratt_44[12]={
  128168. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128169. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128170. /* 1 */
  128171. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128172. /* 2 */
  128173. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128174. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128175. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128176. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128177. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128178. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128179. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128180. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128181. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128182. };
  128183. static double _psy_lowpass_44[12]={
  128184. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128185. };
  128186. static int _noise_start_short_44[11]={
  128187. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128188. };
  128189. static int _noise_start_long_44[11]={
  128190. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128191. };
  128192. static int _noise_part_short_44[11]={
  128193. 8,8,8,8,8,8,8,8,8,8,8
  128194. };
  128195. static int _noise_part_long_44[11]={
  128196. 32,32,32,32,32,32,32,32,32,32,32
  128197. };
  128198. static double _noise_thresh_44[11]={
  128199. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128200. };
  128201. static double _noise_thresh_5only[2]={
  128202. .5,.5,
  128203. };
  128204. /*** End of inlined file: psych_44.h ***/
  128205. static double rate_mapping_44_stereo[12]={
  128206. 22500.,32000.,40000.,48000.,56000.,64000.,
  128207. 80000.,96000.,112000.,128000.,160000.,250001.
  128208. };
  128209. static double quality_mapping_44[12]={
  128210. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128211. };
  128212. static int blocksize_short_44[11]={
  128213. 512,256,256,256,256,256,256,256,256,256,256
  128214. };
  128215. static int blocksize_long_44[11]={
  128216. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128217. };
  128218. static double _psy_compand_short_mapping[12]={
  128219. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128220. };
  128221. static double _psy_compand_long_mapping[12]={
  128222. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128223. };
  128224. static double _global_mapping_44[12]={
  128225. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128226. };
  128227. static int _floor_short_mapping_44[11]={
  128228. 1,0,0,2,2,4,5,5,5,5,5
  128229. };
  128230. static int _floor_long_mapping_44[11]={
  128231. 8,7,7,7,7,7,7,7,7,7,7
  128232. };
  128233. ve_setup_data_template ve_setup_44_stereo={
  128234. 11,
  128235. rate_mapping_44_stereo,
  128236. quality_mapping_44,
  128237. 2,
  128238. 40000,
  128239. 50000,
  128240. blocksize_short_44,
  128241. blocksize_long_44,
  128242. _psy_tone_masteratt_44,
  128243. _psy_tone_0dB,
  128244. _psy_tone_suppress,
  128245. _vp_tonemask_adj_otherblock,
  128246. _vp_tonemask_adj_longblock,
  128247. _vp_tonemask_adj_otherblock,
  128248. _psy_noiseguards_44,
  128249. _psy_noisebias_impulse,
  128250. _psy_noisebias_padding,
  128251. _psy_noisebias_trans,
  128252. _psy_noisebias_long,
  128253. _psy_noise_suppress,
  128254. _psy_compand_44,
  128255. _psy_compand_short_mapping,
  128256. _psy_compand_long_mapping,
  128257. {_noise_start_short_44,_noise_start_long_44},
  128258. {_noise_part_short_44,_noise_part_long_44},
  128259. _noise_thresh_44,
  128260. _psy_ath_floater,
  128261. _psy_ath_abs,
  128262. _psy_lowpass_44,
  128263. _psy_global_44,
  128264. _global_mapping_44,
  128265. _psy_stereo_modes_44,
  128266. _floor_books,
  128267. _floor,
  128268. _floor_short_mapping_44,
  128269. _floor_long_mapping_44,
  128270. _mapres_template_44_stereo
  128271. };
  128272. /*** End of inlined file: setup_44.h ***/
  128273. /*** Start of inlined file: setup_44u.h ***/
  128274. /*** Start of inlined file: residue_44u.h ***/
  128275. /*** Start of inlined file: res_books_uncoupled.h ***/
  128276. static long _vq_quantlist__16u0__p1_0[] = {
  128277. 1,
  128278. 0,
  128279. 2,
  128280. };
  128281. static long _vq_lengthlist__16u0__p1_0[] = {
  128282. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128283. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128284. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128285. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128286. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128287. 12,
  128288. };
  128289. static float _vq_quantthresh__16u0__p1_0[] = {
  128290. -0.5, 0.5,
  128291. };
  128292. static long _vq_quantmap__16u0__p1_0[] = {
  128293. 1, 0, 2,
  128294. };
  128295. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128296. _vq_quantthresh__16u0__p1_0,
  128297. _vq_quantmap__16u0__p1_0,
  128298. 3,
  128299. 3
  128300. };
  128301. static static_codebook _16u0__p1_0 = {
  128302. 4, 81,
  128303. _vq_lengthlist__16u0__p1_0,
  128304. 1, -535822336, 1611661312, 2, 0,
  128305. _vq_quantlist__16u0__p1_0,
  128306. NULL,
  128307. &_vq_auxt__16u0__p1_0,
  128308. NULL,
  128309. 0
  128310. };
  128311. static long _vq_quantlist__16u0__p2_0[] = {
  128312. 1,
  128313. 0,
  128314. 2,
  128315. };
  128316. static long _vq_lengthlist__16u0__p2_0[] = {
  128317. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128318. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128319. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128320. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128321. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128322. 8,
  128323. };
  128324. static float _vq_quantthresh__16u0__p2_0[] = {
  128325. -0.5, 0.5,
  128326. };
  128327. static long _vq_quantmap__16u0__p2_0[] = {
  128328. 1, 0, 2,
  128329. };
  128330. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128331. _vq_quantthresh__16u0__p2_0,
  128332. _vq_quantmap__16u0__p2_0,
  128333. 3,
  128334. 3
  128335. };
  128336. static static_codebook _16u0__p2_0 = {
  128337. 4, 81,
  128338. _vq_lengthlist__16u0__p2_0,
  128339. 1, -535822336, 1611661312, 2, 0,
  128340. _vq_quantlist__16u0__p2_0,
  128341. NULL,
  128342. &_vq_auxt__16u0__p2_0,
  128343. NULL,
  128344. 0
  128345. };
  128346. static long _vq_quantlist__16u0__p3_0[] = {
  128347. 2,
  128348. 1,
  128349. 3,
  128350. 0,
  128351. 4,
  128352. };
  128353. static long _vq_lengthlist__16u0__p3_0[] = {
  128354. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128355. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128356. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128357. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128358. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128359. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128360. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128361. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128362. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128363. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128364. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128365. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128366. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128367. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128368. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128369. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128370. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128371. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128372. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128373. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128374. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128375. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128376. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128377. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128378. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128379. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128380. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128381. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128382. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128383. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128384. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128385. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128386. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128387. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128388. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128389. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128390. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128391. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128392. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128393. 18,
  128394. };
  128395. static float _vq_quantthresh__16u0__p3_0[] = {
  128396. -1.5, -0.5, 0.5, 1.5,
  128397. };
  128398. static long _vq_quantmap__16u0__p3_0[] = {
  128399. 3, 1, 0, 2, 4,
  128400. };
  128401. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128402. _vq_quantthresh__16u0__p3_0,
  128403. _vq_quantmap__16u0__p3_0,
  128404. 5,
  128405. 5
  128406. };
  128407. static static_codebook _16u0__p3_0 = {
  128408. 4, 625,
  128409. _vq_lengthlist__16u0__p3_0,
  128410. 1, -533725184, 1611661312, 3, 0,
  128411. _vq_quantlist__16u0__p3_0,
  128412. NULL,
  128413. &_vq_auxt__16u0__p3_0,
  128414. NULL,
  128415. 0
  128416. };
  128417. static long _vq_quantlist__16u0__p4_0[] = {
  128418. 2,
  128419. 1,
  128420. 3,
  128421. 0,
  128422. 4,
  128423. };
  128424. static long _vq_lengthlist__16u0__p4_0[] = {
  128425. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128426. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128427. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128428. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128429. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128430. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128431. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128432. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128433. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128434. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128435. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128436. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128437. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128438. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128439. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128440. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128441. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128442. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128443. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128444. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128445. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128446. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128447. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128448. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128449. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128450. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128451. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128452. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128453. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128454. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128455. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128456. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128457. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128458. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128459. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128460. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128461. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128462. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128463. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128464. 11,
  128465. };
  128466. static float _vq_quantthresh__16u0__p4_0[] = {
  128467. -1.5, -0.5, 0.5, 1.5,
  128468. };
  128469. static long _vq_quantmap__16u0__p4_0[] = {
  128470. 3, 1, 0, 2, 4,
  128471. };
  128472. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128473. _vq_quantthresh__16u0__p4_0,
  128474. _vq_quantmap__16u0__p4_0,
  128475. 5,
  128476. 5
  128477. };
  128478. static static_codebook _16u0__p4_0 = {
  128479. 4, 625,
  128480. _vq_lengthlist__16u0__p4_0,
  128481. 1, -533725184, 1611661312, 3, 0,
  128482. _vq_quantlist__16u0__p4_0,
  128483. NULL,
  128484. &_vq_auxt__16u0__p4_0,
  128485. NULL,
  128486. 0
  128487. };
  128488. static long _vq_quantlist__16u0__p5_0[] = {
  128489. 4,
  128490. 3,
  128491. 5,
  128492. 2,
  128493. 6,
  128494. 1,
  128495. 7,
  128496. 0,
  128497. 8,
  128498. };
  128499. static long _vq_lengthlist__16u0__p5_0[] = {
  128500. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128501. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128502. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128503. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128504. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128505. 12,
  128506. };
  128507. static float _vq_quantthresh__16u0__p5_0[] = {
  128508. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128509. };
  128510. static long _vq_quantmap__16u0__p5_0[] = {
  128511. 7, 5, 3, 1, 0, 2, 4, 6,
  128512. 8,
  128513. };
  128514. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128515. _vq_quantthresh__16u0__p5_0,
  128516. _vq_quantmap__16u0__p5_0,
  128517. 9,
  128518. 9
  128519. };
  128520. static static_codebook _16u0__p5_0 = {
  128521. 2, 81,
  128522. _vq_lengthlist__16u0__p5_0,
  128523. 1, -531628032, 1611661312, 4, 0,
  128524. _vq_quantlist__16u0__p5_0,
  128525. NULL,
  128526. &_vq_auxt__16u0__p5_0,
  128527. NULL,
  128528. 0
  128529. };
  128530. static long _vq_quantlist__16u0__p6_0[] = {
  128531. 6,
  128532. 5,
  128533. 7,
  128534. 4,
  128535. 8,
  128536. 3,
  128537. 9,
  128538. 2,
  128539. 10,
  128540. 1,
  128541. 11,
  128542. 0,
  128543. 12,
  128544. };
  128545. static long _vq_lengthlist__16u0__p6_0[] = {
  128546. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128547. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128548. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128549. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128550. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128551. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128552. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128553. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128554. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128555. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128556. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128557. };
  128558. static float _vq_quantthresh__16u0__p6_0[] = {
  128559. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128560. 12.5, 17.5, 22.5, 27.5,
  128561. };
  128562. static long _vq_quantmap__16u0__p6_0[] = {
  128563. 11, 9, 7, 5, 3, 1, 0, 2,
  128564. 4, 6, 8, 10, 12,
  128565. };
  128566. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128567. _vq_quantthresh__16u0__p6_0,
  128568. _vq_quantmap__16u0__p6_0,
  128569. 13,
  128570. 13
  128571. };
  128572. static static_codebook _16u0__p6_0 = {
  128573. 2, 169,
  128574. _vq_lengthlist__16u0__p6_0,
  128575. 1, -526516224, 1616117760, 4, 0,
  128576. _vq_quantlist__16u0__p6_0,
  128577. NULL,
  128578. &_vq_auxt__16u0__p6_0,
  128579. NULL,
  128580. 0
  128581. };
  128582. static long _vq_quantlist__16u0__p6_1[] = {
  128583. 2,
  128584. 1,
  128585. 3,
  128586. 0,
  128587. 4,
  128588. };
  128589. static long _vq_lengthlist__16u0__p6_1[] = {
  128590. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128591. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128592. };
  128593. static float _vq_quantthresh__16u0__p6_1[] = {
  128594. -1.5, -0.5, 0.5, 1.5,
  128595. };
  128596. static long _vq_quantmap__16u0__p6_1[] = {
  128597. 3, 1, 0, 2, 4,
  128598. };
  128599. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128600. _vq_quantthresh__16u0__p6_1,
  128601. _vq_quantmap__16u0__p6_1,
  128602. 5,
  128603. 5
  128604. };
  128605. static static_codebook _16u0__p6_1 = {
  128606. 2, 25,
  128607. _vq_lengthlist__16u0__p6_1,
  128608. 1, -533725184, 1611661312, 3, 0,
  128609. _vq_quantlist__16u0__p6_1,
  128610. NULL,
  128611. &_vq_auxt__16u0__p6_1,
  128612. NULL,
  128613. 0
  128614. };
  128615. static long _vq_quantlist__16u0__p7_0[] = {
  128616. 1,
  128617. 0,
  128618. 2,
  128619. };
  128620. static long _vq_lengthlist__16u0__p7_0[] = {
  128621. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128622. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128623. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128624. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128625. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128626. 7,
  128627. };
  128628. static float _vq_quantthresh__16u0__p7_0[] = {
  128629. -157.5, 157.5,
  128630. };
  128631. static long _vq_quantmap__16u0__p7_0[] = {
  128632. 1, 0, 2,
  128633. };
  128634. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128635. _vq_quantthresh__16u0__p7_0,
  128636. _vq_quantmap__16u0__p7_0,
  128637. 3,
  128638. 3
  128639. };
  128640. static static_codebook _16u0__p7_0 = {
  128641. 4, 81,
  128642. _vq_lengthlist__16u0__p7_0,
  128643. 1, -518803456, 1628680192, 2, 0,
  128644. _vq_quantlist__16u0__p7_0,
  128645. NULL,
  128646. &_vq_auxt__16u0__p7_0,
  128647. NULL,
  128648. 0
  128649. };
  128650. static long _vq_quantlist__16u0__p7_1[] = {
  128651. 7,
  128652. 6,
  128653. 8,
  128654. 5,
  128655. 9,
  128656. 4,
  128657. 10,
  128658. 3,
  128659. 11,
  128660. 2,
  128661. 12,
  128662. 1,
  128663. 13,
  128664. 0,
  128665. 14,
  128666. };
  128667. static long _vq_lengthlist__16u0__p7_1[] = {
  128668. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128669. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128670. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128671. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128672. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128673. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128674. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128675. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128676. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128677. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128678. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128679. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128680. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128681. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128682. 10,
  128683. };
  128684. static float _vq_quantthresh__16u0__p7_1[] = {
  128685. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128686. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128687. };
  128688. static long _vq_quantmap__16u0__p7_1[] = {
  128689. 13, 11, 9, 7, 5, 3, 1, 0,
  128690. 2, 4, 6, 8, 10, 12, 14,
  128691. };
  128692. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128693. _vq_quantthresh__16u0__p7_1,
  128694. _vq_quantmap__16u0__p7_1,
  128695. 15,
  128696. 15
  128697. };
  128698. static static_codebook _16u0__p7_1 = {
  128699. 2, 225,
  128700. _vq_lengthlist__16u0__p7_1,
  128701. 1, -520986624, 1620377600, 4, 0,
  128702. _vq_quantlist__16u0__p7_1,
  128703. NULL,
  128704. &_vq_auxt__16u0__p7_1,
  128705. NULL,
  128706. 0
  128707. };
  128708. static long _vq_quantlist__16u0__p7_2[] = {
  128709. 10,
  128710. 9,
  128711. 11,
  128712. 8,
  128713. 12,
  128714. 7,
  128715. 13,
  128716. 6,
  128717. 14,
  128718. 5,
  128719. 15,
  128720. 4,
  128721. 16,
  128722. 3,
  128723. 17,
  128724. 2,
  128725. 18,
  128726. 1,
  128727. 19,
  128728. 0,
  128729. 20,
  128730. };
  128731. static long _vq_lengthlist__16u0__p7_2[] = {
  128732. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128733. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128734. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128735. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128736. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128737. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128738. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128739. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128740. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128741. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128742. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128743. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128744. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128745. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128746. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128747. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128748. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128749. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128750. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128751. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128752. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128753. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128754. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128755. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128756. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128757. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128758. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128759. 10,10,12,11,10,11,11,11,10,
  128760. };
  128761. static float _vq_quantthresh__16u0__p7_2[] = {
  128762. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128763. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128764. 6.5, 7.5, 8.5, 9.5,
  128765. };
  128766. static long _vq_quantmap__16u0__p7_2[] = {
  128767. 19, 17, 15, 13, 11, 9, 7, 5,
  128768. 3, 1, 0, 2, 4, 6, 8, 10,
  128769. 12, 14, 16, 18, 20,
  128770. };
  128771. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128772. _vq_quantthresh__16u0__p7_2,
  128773. _vq_quantmap__16u0__p7_2,
  128774. 21,
  128775. 21
  128776. };
  128777. static static_codebook _16u0__p7_2 = {
  128778. 2, 441,
  128779. _vq_lengthlist__16u0__p7_2,
  128780. 1, -529268736, 1611661312, 5, 0,
  128781. _vq_quantlist__16u0__p7_2,
  128782. NULL,
  128783. &_vq_auxt__16u0__p7_2,
  128784. NULL,
  128785. 0
  128786. };
  128787. static long _huff_lengthlist__16u0__single[] = {
  128788. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128789. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128790. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128791. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128792. };
  128793. static static_codebook _huff_book__16u0__single = {
  128794. 2, 64,
  128795. _huff_lengthlist__16u0__single,
  128796. 0, 0, 0, 0, 0,
  128797. NULL,
  128798. NULL,
  128799. NULL,
  128800. NULL,
  128801. 0
  128802. };
  128803. static long _huff_lengthlist__16u1__long[] = {
  128804. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128805. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128806. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128807. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128808. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128809. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128810. 16,13,16,18,
  128811. };
  128812. static static_codebook _huff_book__16u1__long = {
  128813. 2, 100,
  128814. _huff_lengthlist__16u1__long,
  128815. 0, 0, 0, 0, 0,
  128816. NULL,
  128817. NULL,
  128818. NULL,
  128819. NULL,
  128820. 0
  128821. };
  128822. static long _vq_quantlist__16u1__p1_0[] = {
  128823. 1,
  128824. 0,
  128825. 2,
  128826. };
  128827. static long _vq_lengthlist__16u1__p1_0[] = {
  128828. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128829. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128830. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128831. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128832. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128833. 11,
  128834. };
  128835. static float _vq_quantthresh__16u1__p1_0[] = {
  128836. -0.5, 0.5,
  128837. };
  128838. static long _vq_quantmap__16u1__p1_0[] = {
  128839. 1, 0, 2,
  128840. };
  128841. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128842. _vq_quantthresh__16u1__p1_0,
  128843. _vq_quantmap__16u1__p1_0,
  128844. 3,
  128845. 3
  128846. };
  128847. static static_codebook _16u1__p1_0 = {
  128848. 4, 81,
  128849. _vq_lengthlist__16u1__p1_0,
  128850. 1, -535822336, 1611661312, 2, 0,
  128851. _vq_quantlist__16u1__p1_0,
  128852. NULL,
  128853. &_vq_auxt__16u1__p1_0,
  128854. NULL,
  128855. 0
  128856. };
  128857. static long _vq_quantlist__16u1__p2_0[] = {
  128858. 1,
  128859. 0,
  128860. 2,
  128861. };
  128862. static long _vq_lengthlist__16u1__p2_0[] = {
  128863. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128864. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128865. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128866. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128867. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128868. 8,
  128869. };
  128870. static float _vq_quantthresh__16u1__p2_0[] = {
  128871. -0.5, 0.5,
  128872. };
  128873. static long _vq_quantmap__16u1__p2_0[] = {
  128874. 1, 0, 2,
  128875. };
  128876. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128877. _vq_quantthresh__16u1__p2_0,
  128878. _vq_quantmap__16u1__p2_0,
  128879. 3,
  128880. 3
  128881. };
  128882. static static_codebook _16u1__p2_0 = {
  128883. 4, 81,
  128884. _vq_lengthlist__16u1__p2_0,
  128885. 1, -535822336, 1611661312, 2, 0,
  128886. _vq_quantlist__16u1__p2_0,
  128887. NULL,
  128888. &_vq_auxt__16u1__p2_0,
  128889. NULL,
  128890. 0
  128891. };
  128892. static long _vq_quantlist__16u1__p3_0[] = {
  128893. 2,
  128894. 1,
  128895. 3,
  128896. 0,
  128897. 4,
  128898. };
  128899. static long _vq_lengthlist__16u1__p3_0[] = {
  128900. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128901. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128902. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128903. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128904. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128905. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  128906. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  128907. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  128908. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  128909. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  128910. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  128911. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  128912. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  128913. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  128914. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  128915. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  128916. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  128917. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  128918. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  128919. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  128920. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  128921. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  128922. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  128923. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  128924. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  128925. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  128926. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  128927. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  128928. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  128929. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  128930. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  128931. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  128932. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  128933. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  128934. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  128935. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  128936. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  128937. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  128938. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  128939. 16,
  128940. };
  128941. static float _vq_quantthresh__16u1__p3_0[] = {
  128942. -1.5, -0.5, 0.5, 1.5,
  128943. };
  128944. static long _vq_quantmap__16u1__p3_0[] = {
  128945. 3, 1, 0, 2, 4,
  128946. };
  128947. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  128948. _vq_quantthresh__16u1__p3_0,
  128949. _vq_quantmap__16u1__p3_0,
  128950. 5,
  128951. 5
  128952. };
  128953. static static_codebook _16u1__p3_0 = {
  128954. 4, 625,
  128955. _vq_lengthlist__16u1__p3_0,
  128956. 1, -533725184, 1611661312, 3, 0,
  128957. _vq_quantlist__16u1__p3_0,
  128958. NULL,
  128959. &_vq_auxt__16u1__p3_0,
  128960. NULL,
  128961. 0
  128962. };
  128963. static long _vq_quantlist__16u1__p4_0[] = {
  128964. 2,
  128965. 1,
  128966. 3,
  128967. 0,
  128968. 4,
  128969. };
  128970. static long _vq_lengthlist__16u1__p4_0[] = {
  128971. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  128972. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  128973. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  128974. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  128975. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  128976. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  128977. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  128978. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  128979. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  128980. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  128981. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  128982. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  128983. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  128984. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  128985. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  128986. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  128987. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  128988. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  128989. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  128990. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  128991. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  128992. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  128993. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  128994. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  128995. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  128996. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  128997. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  128998. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  128999. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129000. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129001. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129002. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129003. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129004. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129005. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129006. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129007. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129008. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129009. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129010. 11,
  129011. };
  129012. static float _vq_quantthresh__16u1__p4_0[] = {
  129013. -1.5, -0.5, 0.5, 1.5,
  129014. };
  129015. static long _vq_quantmap__16u1__p4_0[] = {
  129016. 3, 1, 0, 2, 4,
  129017. };
  129018. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129019. _vq_quantthresh__16u1__p4_0,
  129020. _vq_quantmap__16u1__p4_0,
  129021. 5,
  129022. 5
  129023. };
  129024. static static_codebook _16u1__p4_0 = {
  129025. 4, 625,
  129026. _vq_lengthlist__16u1__p4_0,
  129027. 1, -533725184, 1611661312, 3, 0,
  129028. _vq_quantlist__16u1__p4_0,
  129029. NULL,
  129030. &_vq_auxt__16u1__p4_0,
  129031. NULL,
  129032. 0
  129033. };
  129034. static long _vq_quantlist__16u1__p5_0[] = {
  129035. 4,
  129036. 3,
  129037. 5,
  129038. 2,
  129039. 6,
  129040. 1,
  129041. 7,
  129042. 0,
  129043. 8,
  129044. };
  129045. static long _vq_lengthlist__16u1__p5_0[] = {
  129046. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129047. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129048. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129049. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129050. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129051. 13,
  129052. };
  129053. static float _vq_quantthresh__16u1__p5_0[] = {
  129054. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129055. };
  129056. static long _vq_quantmap__16u1__p5_0[] = {
  129057. 7, 5, 3, 1, 0, 2, 4, 6,
  129058. 8,
  129059. };
  129060. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129061. _vq_quantthresh__16u1__p5_0,
  129062. _vq_quantmap__16u1__p5_0,
  129063. 9,
  129064. 9
  129065. };
  129066. static static_codebook _16u1__p5_0 = {
  129067. 2, 81,
  129068. _vq_lengthlist__16u1__p5_0,
  129069. 1, -531628032, 1611661312, 4, 0,
  129070. _vq_quantlist__16u1__p5_0,
  129071. NULL,
  129072. &_vq_auxt__16u1__p5_0,
  129073. NULL,
  129074. 0
  129075. };
  129076. static long _vq_quantlist__16u1__p6_0[] = {
  129077. 4,
  129078. 3,
  129079. 5,
  129080. 2,
  129081. 6,
  129082. 1,
  129083. 7,
  129084. 0,
  129085. 8,
  129086. };
  129087. static long _vq_lengthlist__16u1__p6_0[] = {
  129088. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129089. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129090. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129091. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129092. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129093. 11,
  129094. };
  129095. static float _vq_quantthresh__16u1__p6_0[] = {
  129096. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129097. };
  129098. static long _vq_quantmap__16u1__p6_0[] = {
  129099. 7, 5, 3, 1, 0, 2, 4, 6,
  129100. 8,
  129101. };
  129102. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129103. _vq_quantthresh__16u1__p6_0,
  129104. _vq_quantmap__16u1__p6_0,
  129105. 9,
  129106. 9
  129107. };
  129108. static static_codebook _16u1__p6_0 = {
  129109. 2, 81,
  129110. _vq_lengthlist__16u1__p6_0,
  129111. 1, -531628032, 1611661312, 4, 0,
  129112. _vq_quantlist__16u1__p6_0,
  129113. NULL,
  129114. &_vq_auxt__16u1__p6_0,
  129115. NULL,
  129116. 0
  129117. };
  129118. static long _vq_quantlist__16u1__p7_0[] = {
  129119. 1,
  129120. 0,
  129121. 2,
  129122. };
  129123. static long _vq_lengthlist__16u1__p7_0[] = {
  129124. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129125. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129126. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129127. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129128. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129129. 13,
  129130. };
  129131. static float _vq_quantthresh__16u1__p7_0[] = {
  129132. -5.5, 5.5,
  129133. };
  129134. static long _vq_quantmap__16u1__p7_0[] = {
  129135. 1, 0, 2,
  129136. };
  129137. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129138. _vq_quantthresh__16u1__p7_0,
  129139. _vq_quantmap__16u1__p7_0,
  129140. 3,
  129141. 3
  129142. };
  129143. static static_codebook _16u1__p7_0 = {
  129144. 4, 81,
  129145. _vq_lengthlist__16u1__p7_0,
  129146. 1, -529137664, 1618345984, 2, 0,
  129147. _vq_quantlist__16u1__p7_0,
  129148. NULL,
  129149. &_vq_auxt__16u1__p7_0,
  129150. NULL,
  129151. 0
  129152. };
  129153. static long _vq_quantlist__16u1__p7_1[] = {
  129154. 5,
  129155. 4,
  129156. 6,
  129157. 3,
  129158. 7,
  129159. 2,
  129160. 8,
  129161. 1,
  129162. 9,
  129163. 0,
  129164. 10,
  129165. };
  129166. static long _vq_lengthlist__16u1__p7_1[] = {
  129167. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129168. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129169. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129170. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129171. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129172. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129173. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129174. 8, 9, 9,10,10,10,10,10,10,
  129175. };
  129176. static float _vq_quantthresh__16u1__p7_1[] = {
  129177. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129178. 3.5, 4.5,
  129179. };
  129180. static long _vq_quantmap__16u1__p7_1[] = {
  129181. 9, 7, 5, 3, 1, 0, 2, 4,
  129182. 6, 8, 10,
  129183. };
  129184. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129185. _vq_quantthresh__16u1__p7_1,
  129186. _vq_quantmap__16u1__p7_1,
  129187. 11,
  129188. 11
  129189. };
  129190. static static_codebook _16u1__p7_1 = {
  129191. 2, 121,
  129192. _vq_lengthlist__16u1__p7_1,
  129193. 1, -531365888, 1611661312, 4, 0,
  129194. _vq_quantlist__16u1__p7_1,
  129195. NULL,
  129196. &_vq_auxt__16u1__p7_1,
  129197. NULL,
  129198. 0
  129199. };
  129200. static long _vq_quantlist__16u1__p8_0[] = {
  129201. 5,
  129202. 4,
  129203. 6,
  129204. 3,
  129205. 7,
  129206. 2,
  129207. 8,
  129208. 1,
  129209. 9,
  129210. 0,
  129211. 10,
  129212. };
  129213. static long _vq_lengthlist__16u1__p8_0[] = {
  129214. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129215. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129216. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129217. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129218. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129219. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129220. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129221. 13,14,14,15,15,16,16,15,16,
  129222. };
  129223. static float _vq_quantthresh__16u1__p8_0[] = {
  129224. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129225. 38.5, 49.5,
  129226. };
  129227. static long _vq_quantmap__16u1__p8_0[] = {
  129228. 9, 7, 5, 3, 1, 0, 2, 4,
  129229. 6, 8, 10,
  129230. };
  129231. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129232. _vq_quantthresh__16u1__p8_0,
  129233. _vq_quantmap__16u1__p8_0,
  129234. 11,
  129235. 11
  129236. };
  129237. static static_codebook _16u1__p8_0 = {
  129238. 2, 121,
  129239. _vq_lengthlist__16u1__p8_0,
  129240. 1, -524582912, 1618345984, 4, 0,
  129241. _vq_quantlist__16u1__p8_0,
  129242. NULL,
  129243. &_vq_auxt__16u1__p8_0,
  129244. NULL,
  129245. 0
  129246. };
  129247. static long _vq_quantlist__16u1__p8_1[] = {
  129248. 5,
  129249. 4,
  129250. 6,
  129251. 3,
  129252. 7,
  129253. 2,
  129254. 8,
  129255. 1,
  129256. 9,
  129257. 0,
  129258. 10,
  129259. };
  129260. static long _vq_lengthlist__16u1__p8_1[] = {
  129261. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129262. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129263. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129264. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129265. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129266. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129267. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129268. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129269. };
  129270. static float _vq_quantthresh__16u1__p8_1[] = {
  129271. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129272. 3.5, 4.5,
  129273. };
  129274. static long _vq_quantmap__16u1__p8_1[] = {
  129275. 9, 7, 5, 3, 1, 0, 2, 4,
  129276. 6, 8, 10,
  129277. };
  129278. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129279. _vq_quantthresh__16u1__p8_1,
  129280. _vq_quantmap__16u1__p8_1,
  129281. 11,
  129282. 11
  129283. };
  129284. static static_codebook _16u1__p8_1 = {
  129285. 2, 121,
  129286. _vq_lengthlist__16u1__p8_1,
  129287. 1, -531365888, 1611661312, 4, 0,
  129288. _vq_quantlist__16u1__p8_1,
  129289. NULL,
  129290. &_vq_auxt__16u1__p8_1,
  129291. NULL,
  129292. 0
  129293. };
  129294. static long _vq_quantlist__16u1__p9_0[] = {
  129295. 7,
  129296. 6,
  129297. 8,
  129298. 5,
  129299. 9,
  129300. 4,
  129301. 10,
  129302. 3,
  129303. 11,
  129304. 2,
  129305. 12,
  129306. 1,
  129307. 13,
  129308. 0,
  129309. 14,
  129310. };
  129311. static long _vq_lengthlist__16u1__p9_0[] = {
  129312. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129313. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129314. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129315. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129316. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129317. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129318. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129319. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129320. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129321. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129322. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129323. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129324. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129325. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129326. 8,
  129327. };
  129328. static float _vq_quantthresh__16u1__p9_0[] = {
  129329. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129330. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129331. };
  129332. static long _vq_quantmap__16u1__p9_0[] = {
  129333. 13, 11, 9, 7, 5, 3, 1, 0,
  129334. 2, 4, 6, 8, 10, 12, 14,
  129335. };
  129336. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129337. _vq_quantthresh__16u1__p9_0,
  129338. _vq_quantmap__16u1__p9_0,
  129339. 15,
  129340. 15
  129341. };
  129342. static static_codebook _16u1__p9_0 = {
  129343. 2, 225,
  129344. _vq_lengthlist__16u1__p9_0,
  129345. 1, -514071552, 1627381760, 4, 0,
  129346. _vq_quantlist__16u1__p9_0,
  129347. NULL,
  129348. &_vq_auxt__16u1__p9_0,
  129349. NULL,
  129350. 0
  129351. };
  129352. static long _vq_quantlist__16u1__p9_1[] = {
  129353. 7,
  129354. 6,
  129355. 8,
  129356. 5,
  129357. 9,
  129358. 4,
  129359. 10,
  129360. 3,
  129361. 11,
  129362. 2,
  129363. 12,
  129364. 1,
  129365. 13,
  129366. 0,
  129367. 14,
  129368. };
  129369. static long _vq_lengthlist__16u1__p9_1[] = {
  129370. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129371. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129372. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129373. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129374. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129375. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129376. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129377. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129378. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129379. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129380. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129381. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129382. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129383. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129384. 9,
  129385. };
  129386. static float _vq_quantthresh__16u1__p9_1[] = {
  129387. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129388. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129389. };
  129390. static long _vq_quantmap__16u1__p9_1[] = {
  129391. 13, 11, 9, 7, 5, 3, 1, 0,
  129392. 2, 4, 6, 8, 10, 12, 14,
  129393. };
  129394. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129395. _vq_quantthresh__16u1__p9_1,
  129396. _vq_quantmap__16u1__p9_1,
  129397. 15,
  129398. 15
  129399. };
  129400. static static_codebook _16u1__p9_1 = {
  129401. 2, 225,
  129402. _vq_lengthlist__16u1__p9_1,
  129403. 1, -522338304, 1620115456, 4, 0,
  129404. _vq_quantlist__16u1__p9_1,
  129405. NULL,
  129406. &_vq_auxt__16u1__p9_1,
  129407. NULL,
  129408. 0
  129409. };
  129410. static long _vq_quantlist__16u1__p9_2[] = {
  129411. 8,
  129412. 7,
  129413. 9,
  129414. 6,
  129415. 10,
  129416. 5,
  129417. 11,
  129418. 4,
  129419. 12,
  129420. 3,
  129421. 13,
  129422. 2,
  129423. 14,
  129424. 1,
  129425. 15,
  129426. 0,
  129427. 16,
  129428. };
  129429. static long _vq_lengthlist__16u1__p9_2[] = {
  129430. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129431. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129432. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129433. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129434. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129435. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129436. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129437. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129438. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129439. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129440. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129441. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129442. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129443. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129444. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129445. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129446. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129447. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129448. 10,
  129449. };
  129450. static float _vq_quantthresh__16u1__p9_2[] = {
  129451. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129452. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129453. };
  129454. static long _vq_quantmap__16u1__p9_2[] = {
  129455. 15, 13, 11, 9, 7, 5, 3, 1,
  129456. 0, 2, 4, 6, 8, 10, 12, 14,
  129457. 16,
  129458. };
  129459. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129460. _vq_quantthresh__16u1__p9_2,
  129461. _vq_quantmap__16u1__p9_2,
  129462. 17,
  129463. 17
  129464. };
  129465. static static_codebook _16u1__p9_2 = {
  129466. 2, 289,
  129467. _vq_lengthlist__16u1__p9_2,
  129468. 1, -529530880, 1611661312, 5, 0,
  129469. _vq_quantlist__16u1__p9_2,
  129470. NULL,
  129471. &_vq_auxt__16u1__p9_2,
  129472. NULL,
  129473. 0
  129474. };
  129475. static long _huff_lengthlist__16u1__short[] = {
  129476. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129477. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129478. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129479. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129480. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129481. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129482. 16,16,16,16,
  129483. };
  129484. static static_codebook _huff_book__16u1__short = {
  129485. 2, 100,
  129486. _huff_lengthlist__16u1__short,
  129487. 0, 0, 0, 0, 0,
  129488. NULL,
  129489. NULL,
  129490. NULL,
  129491. NULL,
  129492. 0
  129493. };
  129494. static long _huff_lengthlist__16u2__long[] = {
  129495. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129496. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129497. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129498. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129499. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129500. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129501. 13,14,18,18,
  129502. };
  129503. static static_codebook _huff_book__16u2__long = {
  129504. 2, 100,
  129505. _huff_lengthlist__16u2__long,
  129506. 0, 0, 0, 0, 0,
  129507. NULL,
  129508. NULL,
  129509. NULL,
  129510. NULL,
  129511. 0
  129512. };
  129513. static long _huff_lengthlist__16u2__short[] = {
  129514. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129515. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129516. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129517. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129518. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129519. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129520. 16,16,16,16,
  129521. };
  129522. static static_codebook _huff_book__16u2__short = {
  129523. 2, 100,
  129524. _huff_lengthlist__16u2__short,
  129525. 0, 0, 0, 0, 0,
  129526. NULL,
  129527. NULL,
  129528. NULL,
  129529. NULL,
  129530. 0
  129531. };
  129532. static long _vq_quantlist__16u2_p1_0[] = {
  129533. 1,
  129534. 0,
  129535. 2,
  129536. };
  129537. static long _vq_lengthlist__16u2_p1_0[] = {
  129538. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129539. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129540. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129541. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129542. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129543. 10,
  129544. };
  129545. static float _vq_quantthresh__16u2_p1_0[] = {
  129546. -0.5, 0.5,
  129547. };
  129548. static long _vq_quantmap__16u2_p1_0[] = {
  129549. 1, 0, 2,
  129550. };
  129551. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129552. _vq_quantthresh__16u2_p1_0,
  129553. _vq_quantmap__16u2_p1_0,
  129554. 3,
  129555. 3
  129556. };
  129557. static static_codebook _16u2_p1_0 = {
  129558. 4, 81,
  129559. _vq_lengthlist__16u2_p1_0,
  129560. 1, -535822336, 1611661312, 2, 0,
  129561. _vq_quantlist__16u2_p1_0,
  129562. NULL,
  129563. &_vq_auxt__16u2_p1_0,
  129564. NULL,
  129565. 0
  129566. };
  129567. static long _vq_quantlist__16u2_p2_0[] = {
  129568. 2,
  129569. 1,
  129570. 3,
  129571. 0,
  129572. 4,
  129573. };
  129574. static long _vq_lengthlist__16u2_p2_0[] = {
  129575. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129576. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129577. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129578. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129579. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129580. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129581. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129582. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129583. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129584. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129585. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129586. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129587. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129588. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129589. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129590. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129591. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129592. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129593. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129594. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129595. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129596. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129597. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129598. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129599. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129600. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129601. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129602. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129603. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129604. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129605. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129606. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129607. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129608. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129609. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129610. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129611. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129612. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129613. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129614. 13,
  129615. };
  129616. static float _vq_quantthresh__16u2_p2_0[] = {
  129617. -1.5, -0.5, 0.5, 1.5,
  129618. };
  129619. static long _vq_quantmap__16u2_p2_0[] = {
  129620. 3, 1, 0, 2, 4,
  129621. };
  129622. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129623. _vq_quantthresh__16u2_p2_0,
  129624. _vq_quantmap__16u2_p2_0,
  129625. 5,
  129626. 5
  129627. };
  129628. static static_codebook _16u2_p2_0 = {
  129629. 4, 625,
  129630. _vq_lengthlist__16u2_p2_0,
  129631. 1, -533725184, 1611661312, 3, 0,
  129632. _vq_quantlist__16u2_p2_0,
  129633. NULL,
  129634. &_vq_auxt__16u2_p2_0,
  129635. NULL,
  129636. 0
  129637. };
  129638. static long _vq_quantlist__16u2_p3_0[] = {
  129639. 4,
  129640. 3,
  129641. 5,
  129642. 2,
  129643. 6,
  129644. 1,
  129645. 7,
  129646. 0,
  129647. 8,
  129648. };
  129649. static long _vq_lengthlist__16u2_p3_0[] = {
  129650. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129651. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129652. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129653. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129654. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129655. 11,
  129656. };
  129657. static float _vq_quantthresh__16u2_p3_0[] = {
  129658. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129659. };
  129660. static long _vq_quantmap__16u2_p3_0[] = {
  129661. 7, 5, 3, 1, 0, 2, 4, 6,
  129662. 8,
  129663. };
  129664. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129665. _vq_quantthresh__16u2_p3_0,
  129666. _vq_quantmap__16u2_p3_0,
  129667. 9,
  129668. 9
  129669. };
  129670. static static_codebook _16u2_p3_0 = {
  129671. 2, 81,
  129672. _vq_lengthlist__16u2_p3_0,
  129673. 1, -531628032, 1611661312, 4, 0,
  129674. _vq_quantlist__16u2_p3_0,
  129675. NULL,
  129676. &_vq_auxt__16u2_p3_0,
  129677. NULL,
  129678. 0
  129679. };
  129680. static long _vq_quantlist__16u2_p4_0[] = {
  129681. 8,
  129682. 7,
  129683. 9,
  129684. 6,
  129685. 10,
  129686. 5,
  129687. 11,
  129688. 4,
  129689. 12,
  129690. 3,
  129691. 13,
  129692. 2,
  129693. 14,
  129694. 1,
  129695. 15,
  129696. 0,
  129697. 16,
  129698. };
  129699. static long _vq_lengthlist__16u2_p4_0[] = {
  129700. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129701. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129702. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129703. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129704. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129705. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129706. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129707. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129708. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129709. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129710. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129711. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129712. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129713. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129714. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129715. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129716. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129717. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129718. 14,
  129719. };
  129720. static float _vq_quantthresh__16u2_p4_0[] = {
  129721. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129722. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129723. };
  129724. static long _vq_quantmap__16u2_p4_0[] = {
  129725. 15, 13, 11, 9, 7, 5, 3, 1,
  129726. 0, 2, 4, 6, 8, 10, 12, 14,
  129727. 16,
  129728. };
  129729. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129730. _vq_quantthresh__16u2_p4_0,
  129731. _vq_quantmap__16u2_p4_0,
  129732. 17,
  129733. 17
  129734. };
  129735. static static_codebook _16u2_p4_0 = {
  129736. 2, 289,
  129737. _vq_lengthlist__16u2_p4_0,
  129738. 1, -529530880, 1611661312, 5, 0,
  129739. _vq_quantlist__16u2_p4_0,
  129740. NULL,
  129741. &_vq_auxt__16u2_p4_0,
  129742. NULL,
  129743. 0
  129744. };
  129745. static long _vq_quantlist__16u2_p5_0[] = {
  129746. 1,
  129747. 0,
  129748. 2,
  129749. };
  129750. static long _vq_lengthlist__16u2_p5_0[] = {
  129751. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129752. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129753. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129754. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129755. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129756. 10,
  129757. };
  129758. static float _vq_quantthresh__16u2_p5_0[] = {
  129759. -5.5, 5.5,
  129760. };
  129761. static long _vq_quantmap__16u2_p5_0[] = {
  129762. 1, 0, 2,
  129763. };
  129764. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129765. _vq_quantthresh__16u2_p5_0,
  129766. _vq_quantmap__16u2_p5_0,
  129767. 3,
  129768. 3
  129769. };
  129770. static static_codebook _16u2_p5_0 = {
  129771. 4, 81,
  129772. _vq_lengthlist__16u2_p5_0,
  129773. 1, -529137664, 1618345984, 2, 0,
  129774. _vq_quantlist__16u2_p5_0,
  129775. NULL,
  129776. &_vq_auxt__16u2_p5_0,
  129777. NULL,
  129778. 0
  129779. };
  129780. static long _vq_quantlist__16u2_p5_1[] = {
  129781. 5,
  129782. 4,
  129783. 6,
  129784. 3,
  129785. 7,
  129786. 2,
  129787. 8,
  129788. 1,
  129789. 9,
  129790. 0,
  129791. 10,
  129792. };
  129793. static long _vq_lengthlist__16u2_p5_1[] = {
  129794. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129795. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129796. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129797. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129798. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129799. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129800. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129801. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129802. };
  129803. static float _vq_quantthresh__16u2_p5_1[] = {
  129804. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129805. 3.5, 4.5,
  129806. };
  129807. static long _vq_quantmap__16u2_p5_1[] = {
  129808. 9, 7, 5, 3, 1, 0, 2, 4,
  129809. 6, 8, 10,
  129810. };
  129811. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129812. _vq_quantthresh__16u2_p5_1,
  129813. _vq_quantmap__16u2_p5_1,
  129814. 11,
  129815. 11
  129816. };
  129817. static static_codebook _16u2_p5_1 = {
  129818. 2, 121,
  129819. _vq_lengthlist__16u2_p5_1,
  129820. 1, -531365888, 1611661312, 4, 0,
  129821. _vq_quantlist__16u2_p5_1,
  129822. NULL,
  129823. &_vq_auxt__16u2_p5_1,
  129824. NULL,
  129825. 0
  129826. };
  129827. static long _vq_quantlist__16u2_p6_0[] = {
  129828. 6,
  129829. 5,
  129830. 7,
  129831. 4,
  129832. 8,
  129833. 3,
  129834. 9,
  129835. 2,
  129836. 10,
  129837. 1,
  129838. 11,
  129839. 0,
  129840. 12,
  129841. };
  129842. static long _vq_lengthlist__16u2_p6_0[] = {
  129843. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129844. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129845. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129846. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129847. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129848. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129849. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129850. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129851. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129852. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129853. 12,13,13,14,14,14,14,15,15,
  129854. };
  129855. static float _vq_quantthresh__16u2_p6_0[] = {
  129856. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129857. 12.5, 17.5, 22.5, 27.5,
  129858. };
  129859. static long _vq_quantmap__16u2_p6_0[] = {
  129860. 11, 9, 7, 5, 3, 1, 0, 2,
  129861. 4, 6, 8, 10, 12,
  129862. };
  129863. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129864. _vq_quantthresh__16u2_p6_0,
  129865. _vq_quantmap__16u2_p6_0,
  129866. 13,
  129867. 13
  129868. };
  129869. static static_codebook _16u2_p6_0 = {
  129870. 2, 169,
  129871. _vq_lengthlist__16u2_p6_0,
  129872. 1, -526516224, 1616117760, 4, 0,
  129873. _vq_quantlist__16u2_p6_0,
  129874. NULL,
  129875. &_vq_auxt__16u2_p6_0,
  129876. NULL,
  129877. 0
  129878. };
  129879. static long _vq_quantlist__16u2_p6_1[] = {
  129880. 2,
  129881. 1,
  129882. 3,
  129883. 0,
  129884. 4,
  129885. };
  129886. static long _vq_lengthlist__16u2_p6_1[] = {
  129887. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129888. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129889. };
  129890. static float _vq_quantthresh__16u2_p6_1[] = {
  129891. -1.5, -0.5, 0.5, 1.5,
  129892. };
  129893. static long _vq_quantmap__16u2_p6_1[] = {
  129894. 3, 1, 0, 2, 4,
  129895. };
  129896. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129897. _vq_quantthresh__16u2_p6_1,
  129898. _vq_quantmap__16u2_p6_1,
  129899. 5,
  129900. 5
  129901. };
  129902. static static_codebook _16u2_p6_1 = {
  129903. 2, 25,
  129904. _vq_lengthlist__16u2_p6_1,
  129905. 1, -533725184, 1611661312, 3, 0,
  129906. _vq_quantlist__16u2_p6_1,
  129907. NULL,
  129908. &_vq_auxt__16u2_p6_1,
  129909. NULL,
  129910. 0
  129911. };
  129912. static long _vq_quantlist__16u2_p7_0[] = {
  129913. 6,
  129914. 5,
  129915. 7,
  129916. 4,
  129917. 8,
  129918. 3,
  129919. 9,
  129920. 2,
  129921. 10,
  129922. 1,
  129923. 11,
  129924. 0,
  129925. 12,
  129926. };
  129927. static long _vq_lengthlist__16u2_p7_0[] = {
  129928. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  129929. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  129930. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  129931. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  129932. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  129933. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  129934. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  129935. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  129936. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  129937. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  129938. 12,13,13,13,14,14,14,15,14,
  129939. };
  129940. static float _vq_quantthresh__16u2_p7_0[] = {
  129941. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  129942. 27.5, 38.5, 49.5, 60.5,
  129943. };
  129944. static long _vq_quantmap__16u2_p7_0[] = {
  129945. 11, 9, 7, 5, 3, 1, 0, 2,
  129946. 4, 6, 8, 10, 12,
  129947. };
  129948. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  129949. _vq_quantthresh__16u2_p7_0,
  129950. _vq_quantmap__16u2_p7_0,
  129951. 13,
  129952. 13
  129953. };
  129954. static static_codebook _16u2_p7_0 = {
  129955. 2, 169,
  129956. _vq_lengthlist__16u2_p7_0,
  129957. 1, -523206656, 1618345984, 4, 0,
  129958. _vq_quantlist__16u2_p7_0,
  129959. NULL,
  129960. &_vq_auxt__16u2_p7_0,
  129961. NULL,
  129962. 0
  129963. };
  129964. static long _vq_quantlist__16u2_p7_1[] = {
  129965. 5,
  129966. 4,
  129967. 6,
  129968. 3,
  129969. 7,
  129970. 2,
  129971. 8,
  129972. 1,
  129973. 9,
  129974. 0,
  129975. 10,
  129976. };
  129977. static long _vq_lengthlist__16u2_p7_1[] = {
  129978. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  129979. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  129980. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  129981. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  129982. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  129983. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  129984. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  129985. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129986. };
  129987. static float _vq_quantthresh__16u2_p7_1[] = {
  129988. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129989. 3.5, 4.5,
  129990. };
  129991. static long _vq_quantmap__16u2_p7_1[] = {
  129992. 9, 7, 5, 3, 1, 0, 2, 4,
  129993. 6, 8, 10,
  129994. };
  129995. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  129996. _vq_quantthresh__16u2_p7_1,
  129997. _vq_quantmap__16u2_p7_1,
  129998. 11,
  129999. 11
  130000. };
  130001. static static_codebook _16u2_p7_1 = {
  130002. 2, 121,
  130003. _vq_lengthlist__16u2_p7_1,
  130004. 1, -531365888, 1611661312, 4, 0,
  130005. _vq_quantlist__16u2_p7_1,
  130006. NULL,
  130007. &_vq_auxt__16u2_p7_1,
  130008. NULL,
  130009. 0
  130010. };
  130011. static long _vq_quantlist__16u2_p8_0[] = {
  130012. 7,
  130013. 6,
  130014. 8,
  130015. 5,
  130016. 9,
  130017. 4,
  130018. 10,
  130019. 3,
  130020. 11,
  130021. 2,
  130022. 12,
  130023. 1,
  130024. 13,
  130025. 0,
  130026. 14,
  130027. };
  130028. static long _vq_lengthlist__16u2_p8_0[] = {
  130029. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130030. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130031. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130032. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130033. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130034. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130035. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130036. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130037. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130038. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130039. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130040. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130041. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130042. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130043. 14,
  130044. };
  130045. static float _vq_quantthresh__16u2_p8_0[] = {
  130046. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130047. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130048. };
  130049. static long _vq_quantmap__16u2_p8_0[] = {
  130050. 13, 11, 9, 7, 5, 3, 1, 0,
  130051. 2, 4, 6, 8, 10, 12, 14,
  130052. };
  130053. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130054. _vq_quantthresh__16u2_p8_0,
  130055. _vq_quantmap__16u2_p8_0,
  130056. 15,
  130057. 15
  130058. };
  130059. static static_codebook _16u2_p8_0 = {
  130060. 2, 225,
  130061. _vq_lengthlist__16u2_p8_0,
  130062. 1, -520986624, 1620377600, 4, 0,
  130063. _vq_quantlist__16u2_p8_0,
  130064. NULL,
  130065. &_vq_auxt__16u2_p8_0,
  130066. NULL,
  130067. 0
  130068. };
  130069. static long _vq_quantlist__16u2_p8_1[] = {
  130070. 10,
  130071. 9,
  130072. 11,
  130073. 8,
  130074. 12,
  130075. 7,
  130076. 13,
  130077. 6,
  130078. 14,
  130079. 5,
  130080. 15,
  130081. 4,
  130082. 16,
  130083. 3,
  130084. 17,
  130085. 2,
  130086. 18,
  130087. 1,
  130088. 19,
  130089. 0,
  130090. 20,
  130091. };
  130092. static long _vq_lengthlist__16u2_p8_1[] = {
  130093. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130094. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130095. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130096. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130097. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130098. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130099. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130100. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130101. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130102. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130103. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130104. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130105. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130106. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130107. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130108. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130109. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130110. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130111. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130112. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130113. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130114. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130115. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130116. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130117. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130118. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130119. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130120. 11,11,10,11,11,11,10,11,11,
  130121. };
  130122. static float _vq_quantthresh__16u2_p8_1[] = {
  130123. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130124. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130125. 6.5, 7.5, 8.5, 9.5,
  130126. };
  130127. static long _vq_quantmap__16u2_p8_1[] = {
  130128. 19, 17, 15, 13, 11, 9, 7, 5,
  130129. 3, 1, 0, 2, 4, 6, 8, 10,
  130130. 12, 14, 16, 18, 20,
  130131. };
  130132. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130133. _vq_quantthresh__16u2_p8_1,
  130134. _vq_quantmap__16u2_p8_1,
  130135. 21,
  130136. 21
  130137. };
  130138. static static_codebook _16u2_p8_1 = {
  130139. 2, 441,
  130140. _vq_lengthlist__16u2_p8_1,
  130141. 1, -529268736, 1611661312, 5, 0,
  130142. _vq_quantlist__16u2_p8_1,
  130143. NULL,
  130144. &_vq_auxt__16u2_p8_1,
  130145. NULL,
  130146. 0
  130147. };
  130148. static long _vq_quantlist__16u2_p9_0[] = {
  130149. 5586,
  130150. 4655,
  130151. 6517,
  130152. 3724,
  130153. 7448,
  130154. 2793,
  130155. 8379,
  130156. 1862,
  130157. 9310,
  130158. 931,
  130159. 10241,
  130160. 0,
  130161. 11172,
  130162. 5521,
  130163. 5651,
  130164. };
  130165. static long _vq_lengthlist__16u2_p9_0[] = {
  130166. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130167. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130168. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130169. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130170. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130171. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130172. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130173. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130174. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130175. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130176. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130177. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130178. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130179. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130180. 5,
  130181. };
  130182. static float _vq_quantthresh__16u2_p9_0[] = {
  130183. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130184. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130185. };
  130186. static long _vq_quantmap__16u2_p9_0[] = {
  130187. 11, 9, 7, 5, 3, 1, 13, 0,
  130188. 14, 2, 4, 6, 8, 10, 12,
  130189. };
  130190. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130191. _vq_quantthresh__16u2_p9_0,
  130192. _vq_quantmap__16u2_p9_0,
  130193. 15,
  130194. 15
  130195. };
  130196. static static_codebook _16u2_p9_0 = {
  130197. 2, 225,
  130198. _vq_lengthlist__16u2_p9_0,
  130199. 1, -510275072, 1611661312, 14, 0,
  130200. _vq_quantlist__16u2_p9_0,
  130201. NULL,
  130202. &_vq_auxt__16u2_p9_0,
  130203. NULL,
  130204. 0
  130205. };
  130206. static long _vq_quantlist__16u2_p9_1[] = {
  130207. 392,
  130208. 343,
  130209. 441,
  130210. 294,
  130211. 490,
  130212. 245,
  130213. 539,
  130214. 196,
  130215. 588,
  130216. 147,
  130217. 637,
  130218. 98,
  130219. 686,
  130220. 49,
  130221. 735,
  130222. 0,
  130223. 784,
  130224. 388,
  130225. 396,
  130226. };
  130227. static long _vq_lengthlist__16u2_p9_1[] = {
  130228. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130229. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130230. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130231. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130232. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130233. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130234. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130235. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130236. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130237. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130238. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130239. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130240. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130241. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130242. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130243. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130244. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130245. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130246. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130247. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130248. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130249. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130250. 11,11,11,11,11,11,11, 5, 4,
  130251. };
  130252. static float _vq_quantthresh__16u2_p9_1[] = {
  130253. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130254. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130255. 318.5, 367.5,
  130256. };
  130257. static long _vq_quantmap__16u2_p9_1[] = {
  130258. 15, 13, 11, 9, 7, 5, 3, 1,
  130259. 17, 0, 18, 2, 4, 6, 8, 10,
  130260. 12, 14, 16,
  130261. };
  130262. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130263. _vq_quantthresh__16u2_p9_1,
  130264. _vq_quantmap__16u2_p9_1,
  130265. 19,
  130266. 19
  130267. };
  130268. static static_codebook _16u2_p9_1 = {
  130269. 2, 361,
  130270. _vq_lengthlist__16u2_p9_1,
  130271. 1, -518488064, 1611661312, 10, 0,
  130272. _vq_quantlist__16u2_p9_1,
  130273. NULL,
  130274. &_vq_auxt__16u2_p9_1,
  130275. NULL,
  130276. 0
  130277. };
  130278. static long _vq_quantlist__16u2_p9_2[] = {
  130279. 24,
  130280. 23,
  130281. 25,
  130282. 22,
  130283. 26,
  130284. 21,
  130285. 27,
  130286. 20,
  130287. 28,
  130288. 19,
  130289. 29,
  130290. 18,
  130291. 30,
  130292. 17,
  130293. 31,
  130294. 16,
  130295. 32,
  130296. 15,
  130297. 33,
  130298. 14,
  130299. 34,
  130300. 13,
  130301. 35,
  130302. 12,
  130303. 36,
  130304. 11,
  130305. 37,
  130306. 10,
  130307. 38,
  130308. 9,
  130309. 39,
  130310. 8,
  130311. 40,
  130312. 7,
  130313. 41,
  130314. 6,
  130315. 42,
  130316. 5,
  130317. 43,
  130318. 4,
  130319. 44,
  130320. 3,
  130321. 45,
  130322. 2,
  130323. 46,
  130324. 1,
  130325. 47,
  130326. 0,
  130327. 48,
  130328. };
  130329. static long _vq_lengthlist__16u2_p9_2[] = {
  130330. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130331. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130332. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130333. 11,
  130334. };
  130335. static float _vq_quantthresh__16u2_p9_2[] = {
  130336. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130337. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130338. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130339. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130340. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130341. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130342. };
  130343. static long _vq_quantmap__16u2_p9_2[] = {
  130344. 47, 45, 43, 41, 39, 37, 35, 33,
  130345. 31, 29, 27, 25, 23, 21, 19, 17,
  130346. 15, 13, 11, 9, 7, 5, 3, 1,
  130347. 0, 2, 4, 6, 8, 10, 12, 14,
  130348. 16, 18, 20, 22, 24, 26, 28, 30,
  130349. 32, 34, 36, 38, 40, 42, 44, 46,
  130350. 48,
  130351. };
  130352. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130353. _vq_quantthresh__16u2_p9_2,
  130354. _vq_quantmap__16u2_p9_2,
  130355. 49,
  130356. 49
  130357. };
  130358. static static_codebook _16u2_p9_2 = {
  130359. 1, 49,
  130360. _vq_lengthlist__16u2_p9_2,
  130361. 1, -526909440, 1611661312, 6, 0,
  130362. _vq_quantlist__16u2_p9_2,
  130363. NULL,
  130364. &_vq_auxt__16u2_p9_2,
  130365. NULL,
  130366. 0
  130367. };
  130368. static long _vq_quantlist__8u0__p1_0[] = {
  130369. 1,
  130370. 0,
  130371. 2,
  130372. };
  130373. static long _vq_lengthlist__8u0__p1_0[] = {
  130374. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130375. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130376. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130377. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130378. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130379. 11,
  130380. };
  130381. static float _vq_quantthresh__8u0__p1_0[] = {
  130382. -0.5, 0.5,
  130383. };
  130384. static long _vq_quantmap__8u0__p1_0[] = {
  130385. 1, 0, 2,
  130386. };
  130387. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130388. _vq_quantthresh__8u0__p1_0,
  130389. _vq_quantmap__8u0__p1_0,
  130390. 3,
  130391. 3
  130392. };
  130393. static static_codebook _8u0__p1_0 = {
  130394. 4, 81,
  130395. _vq_lengthlist__8u0__p1_0,
  130396. 1, -535822336, 1611661312, 2, 0,
  130397. _vq_quantlist__8u0__p1_0,
  130398. NULL,
  130399. &_vq_auxt__8u0__p1_0,
  130400. NULL,
  130401. 0
  130402. };
  130403. static long _vq_quantlist__8u0__p2_0[] = {
  130404. 1,
  130405. 0,
  130406. 2,
  130407. };
  130408. static long _vq_lengthlist__8u0__p2_0[] = {
  130409. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130410. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130411. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130412. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130413. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130414. 8,
  130415. };
  130416. static float _vq_quantthresh__8u0__p2_0[] = {
  130417. -0.5, 0.5,
  130418. };
  130419. static long _vq_quantmap__8u0__p2_0[] = {
  130420. 1, 0, 2,
  130421. };
  130422. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130423. _vq_quantthresh__8u0__p2_0,
  130424. _vq_quantmap__8u0__p2_0,
  130425. 3,
  130426. 3
  130427. };
  130428. static static_codebook _8u0__p2_0 = {
  130429. 4, 81,
  130430. _vq_lengthlist__8u0__p2_0,
  130431. 1, -535822336, 1611661312, 2, 0,
  130432. _vq_quantlist__8u0__p2_0,
  130433. NULL,
  130434. &_vq_auxt__8u0__p2_0,
  130435. NULL,
  130436. 0
  130437. };
  130438. static long _vq_quantlist__8u0__p3_0[] = {
  130439. 2,
  130440. 1,
  130441. 3,
  130442. 0,
  130443. 4,
  130444. };
  130445. static long _vq_lengthlist__8u0__p3_0[] = {
  130446. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130447. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130448. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130449. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130450. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130451. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130452. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130453. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130454. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130455. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130456. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130457. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130458. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130459. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130460. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130461. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130462. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130463. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130464. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130465. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130466. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130467. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130468. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130469. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130470. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130471. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130472. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130473. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130474. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130475. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130476. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130477. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130478. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130479. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130480. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130481. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130482. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130483. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130484. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130485. 16,
  130486. };
  130487. static float _vq_quantthresh__8u0__p3_0[] = {
  130488. -1.5, -0.5, 0.5, 1.5,
  130489. };
  130490. static long _vq_quantmap__8u0__p3_0[] = {
  130491. 3, 1, 0, 2, 4,
  130492. };
  130493. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130494. _vq_quantthresh__8u0__p3_0,
  130495. _vq_quantmap__8u0__p3_0,
  130496. 5,
  130497. 5
  130498. };
  130499. static static_codebook _8u0__p3_0 = {
  130500. 4, 625,
  130501. _vq_lengthlist__8u0__p3_0,
  130502. 1, -533725184, 1611661312, 3, 0,
  130503. _vq_quantlist__8u0__p3_0,
  130504. NULL,
  130505. &_vq_auxt__8u0__p3_0,
  130506. NULL,
  130507. 0
  130508. };
  130509. static long _vq_quantlist__8u0__p4_0[] = {
  130510. 2,
  130511. 1,
  130512. 3,
  130513. 0,
  130514. 4,
  130515. };
  130516. static long _vq_lengthlist__8u0__p4_0[] = {
  130517. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130518. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130519. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130520. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130521. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130522. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130523. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130524. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130525. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130526. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130527. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130528. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130529. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130530. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130531. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130532. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130533. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130534. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130535. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130536. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130537. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130538. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130539. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130540. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130541. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130542. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130543. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130544. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130545. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130546. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130547. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130548. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130549. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130550. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130551. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130552. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130553. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130554. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130555. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130556. 12,
  130557. };
  130558. static float _vq_quantthresh__8u0__p4_0[] = {
  130559. -1.5, -0.5, 0.5, 1.5,
  130560. };
  130561. static long _vq_quantmap__8u0__p4_0[] = {
  130562. 3, 1, 0, 2, 4,
  130563. };
  130564. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130565. _vq_quantthresh__8u0__p4_0,
  130566. _vq_quantmap__8u0__p4_0,
  130567. 5,
  130568. 5
  130569. };
  130570. static static_codebook _8u0__p4_0 = {
  130571. 4, 625,
  130572. _vq_lengthlist__8u0__p4_0,
  130573. 1, -533725184, 1611661312, 3, 0,
  130574. _vq_quantlist__8u0__p4_0,
  130575. NULL,
  130576. &_vq_auxt__8u0__p4_0,
  130577. NULL,
  130578. 0
  130579. };
  130580. static long _vq_quantlist__8u0__p5_0[] = {
  130581. 4,
  130582. 3,
  130583. 5,
  130584. 2,
  130585. 6,
  130586. 1,
  130587. 7,
  130588. 0,
  130589. 8,
  130590. };
  130591. static long _vq_lengthlist__8u0__p5_0[] = {
  130592. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130593. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130594. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130595. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130596. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130597. 12,
  130598. };
  130599. static float _vq_quantthresh__8u0__p5_0[] = {
  130600. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130601. };
  130602. static long _vq_quantmap__8u0__p5_0[] = {
  130603. 7, 5, 3, 1, 0, 2, 4, 6,
  130604. 8,
  130605. };
  130606. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130607. _vq_quantthresh__8u0__p5_0,
  130608. _vq_quantmap__8u0__p5_0,
  130609. 9,
  130610. 9
  130611. };
  130612. static static_codebook _8u0__p5_0 = {
  130613. 2, 81,
  130614. _vq_lengthlist__8u0__p5_0,
  130615. 1, -531628032, 1611661312, 4, 0,
  130616. _vq_quantlist__8u0__p5_0,
  130617. NULL,
  130618. &_vq_auxt__8u0__p5_0,
  130619. NULL,
  130620. 0
  130621. };
  130622. static long _vq_quantlist__8u0__p6_0[] = {
  130623. 6,
  130624. 5,
  130625. 7,
  130626. 4,
  130627. 8,
  130628. 3,
  130629. 9,
  130630. 2,
  130631. 10,
  130632. 1,
  130633. 11,
  130634. 0,
  130635. 12,
  130636. };
  130637. static long _vq_lengthlist__8u0__p6_0[] = {
  130638. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130639. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130640. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130641. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130642. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130643. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130644. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130645. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130646. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130647. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130648. 16, 0,15, 0,17, 0, 0, 0, 0,
  130649. };
  130650. static float _vq_quantthresh__8u0__p6_0[] = {
  130651. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130652. 12.5, 17.5, 22.5, 27.5,
  130653. };
  130654. static long _vq_quantmap__8u0__p6_0[] = {
  130655. 11, 9, 7, 5, 3, 1, 0, 2,
  130656. 4, 6, 8, 10, 12,
  130657. };
  130658. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130659. _vq_quantthresh__8u0__p6_0,
  130660. _vq_quantmap__8u0__p6_0,
  130661. 13,
  130662. 13
  130663. };
  130664. static static_codebook _8u0__p6_0 = {
  130665. 2, 169,
  130666. _vq_lengthlist__8u0__p6_0,
  130667. 1, -526516224, 1616117760, 4, 0,
  130668. _vq_quantlist__8u0__p6_0,
  130669. NULL,
  130670. &_vq_auxt__8u0__p6_0,
  130671. NULL,
  130672. 0
  130673. };
  130674. static long _vq_quantlist__8u0__p6_1[] = {
  130675. 2,
  130676. 1,
  130677. 3,
  130678. 0,
  130679. 4,
  130680. };
  130681. static long _vq_lengthlist__8u0__p6_1[] = {
  130682. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130683. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130684. };
  130685. static float _vq_quantthresh__8u0__p6_1[] = {
  130686. -1.5, -0.5, 0.5, 1.5,
  130687. };
  130688. static long _vq_quantmap__8u0__p6_1[] = {
  130689. 3, 1, 0, 2, 4,
  130690. };
  130691. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130692. _vq_quantthresh__8u0__p6_1,
  130693. _vq_quantmap__8u0__p6_1,
  130694. 5,
  130695. 5
  130696. };
  130697. static static_codebook _8u0__p6_1 = {
  130698. 2, 25,
  130699. _vq_lengthlist__8u0__p6_1,
  130700. 1, -533725184, 1611661312, 3, 0,
  130701. _vq_quantlist__8u0__p6_1,
  130702. NULL,
  130703. &_vq_auxt__8u0__p6_1,
  130704. NULL,
  130705. 0
  130706. };
  130707. static long _vq_quantlist__8u0__p7_0[] = {
  130708. 1,
  130709. 0,
  130710. 2,
  130711. };
  130712. static long _vq_lengthlist__8u0__p7_0[] = {
  130713. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130714. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130715. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130716. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130717. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130718. 7,
  130719. };
  130720. static float _vq_quantthresh__8u0__p7_0[] = {
  130721. -157.5, 157.5,
  130722. };
  130723. static long _vq_quantmap__8u0__p7_0[] = {
  130724. 1, 0, 2,
  130725. };
  130726. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130727. _vq_quantthresh__8u0__p7_0,
  130728. _vq_quantmap__8u0__p7_0,
  130729. 3,
  130730. 3
  130731. };
  130732. static static_codebook _8u0__p7_0 = {
  130733. 4, 81,
  130734. _vq_lengthlist__8u0__p7_0,
  130735. 1, -518803456, 1628680192, 2, 0,
  130736. _vq_quantlist__8u0__p7_0,
  130737. NULL,
  130738. &_vq_auxt__8u0__p7_0,
  130739. NULL,
  130740. 0
  130741. };
  130742. static long _vq_quantlist__8u0__p7_1[] = {
  130743. 7,
  130744. 6,
  130745. 8,
  130746. 5,
  130747. 9,
  130748. 4,
  130749. 10,
  130750. 3,
  130751. 11,
  130752. 2,
  130753. 12,
  130754. 1,
  130755. 13,
  130756. 0,
  130757. 14,
  130758. };
  130759. static long _vq_lengthlist__8u0__p7_1[] = {
  130760. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130761. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130762. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130763. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130764. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130765. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130766. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130767. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130768. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130769. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130770. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130771. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130772. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130773. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130774. 10,
  130775. };
  130776. static float _vq_quantthresh__8u0__p7_1[] = {
  130777. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130778. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130779. };
  130780. static long _vq_quantmap__8u0__p7_1[] = {
  130781. 13, 11, 9, 7, 5, 3, 1, 0,
  130782. 2, 4, 6, 8, 10, 12, 14,
  130783. };
  130784. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130785. _vq_quantthresh__8u0__p7_1,
  130786. _vq_quantmap__8u0__p7_1,
  130787. 15,
  130788. 15
  130789. };
  130790. static static_codebook _8u0__p7_1 = {
  130791. 2, 225,
  130792. _vq_lengthlist__8u0__p7_1,
  130793. 1, -520986624, 1620377600, 4, 0,
  130794. _vq_quantlist__8u0__p7_1,
  130795. NULL,
  130796. &_vq_auxt__8u0__p7_1,
  130797. NULL,
  130798. 0
  130799. };
  130800. static long _vq_quantlist__8u0__p7_2[] = {
  130801. 10,
  130802. 9,
  130803. 11,
  130804. 8,
  130805. 12,
  130806. 7,
  130807. 13,
  130808. 6,
  130809. 14,
  130810. 5,
  130811. 15,
  130812. 4,
  130813. 16,
  130814. 3,
  130815. 17,
  130816. 2,
  130817. 18,
  130818. 1,
  130819. 19,
  130820. 0,
  130821. 20,
  130822. };
  130823. static long _vq_lengthlist__8u0__p7_2[] = {
  130824. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130825. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130826. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130827. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130828. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130829. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130830. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130831. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130832. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130833. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130834. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130835. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130836. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130837. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130838. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130839. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130840. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130841. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130842. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130843. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130844. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130845. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130846. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130847. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130848. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130849. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130850. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130851. 11,12,11,11,11,10,10,11,11,
  130852. };
  130853. static float _vq_quantthresh__8u0__p7_2[] = {
  130854. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130855. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130856. 6.5, 7.5, 8.5, 9.5,
  130857. };
  130858. static long _vq_quantmap__8u0__p7_2[] = {
  130859. 19, 17, 15, 13, 11, 9, 7, 5,
  130860. 3, 1, 0, 2, 4, 6, 8, 10,
  130861. 12, 14, 16, 18, 20,
  130862. };
  130863. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130864. _vq_quantthresh__8u0__p7_2,
  130865. _vq_quantmap__8u0__p7_2,
  130866. 21,
  130867. 21
  130868. };
  130869. static static_codebook _8u0__p7_2 = {
  130870. 2, 441,
  130871. _vq_lengthlist__8u0__p7_2,
  130872. 1, -529268736, 1611661312, 5, 0,
  130873. _vq_quantlist__8u0__p7_2,
  130874. NULL,
  130875. &_vq_auxt__8u0__p7_2,
  130876. NULL,
  130877. 0
  130878. };
  130879. static long _huff_lengthlist__8u0__single[] = {
  130880. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130881. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130882. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130883. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130884. };
  130885. static static_codebook _huff_book__8u0__single = {
  130886. 2, 64,
  130887. _huff_lengthlist__8u0__single,
  130888. 0, 0, 0, 0, 0,
  130889. NULL,
  130890. NULL,
  130891. NULL,
  130892. NULL,
  130893. 0
  130894. };
  130895. static long _vq_quantlist__8u1__p1_0[] = {
  130896. 1,
  130897. 0,
  130898. 2,
  130899. };
  130900. static long _vq_lengthlist__8u1__p1_0[] = {
  130901. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130902. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130903. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130904. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130905. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  130906. 10,
  130907. };
  130908. static float _vq_quantthresh__8u1__p1_0[] = {
  130909. -0.5, 0.5,
  130910. };
  130911. static long _vq_quantmap__8u1__p1_0[] = {
  130912. 1, 0, 2,
  130913. };
  130914. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  130915. _vq_quantthresh__8u1__p1_0,
  130916. _vq_quantmap__8u1__p1_0,
  130917. 3,
  130918. 3
  130919. };
  130920. static static_codebook _8u1__p1_0 = {
  130921. 4, 81,
  130922. _vq_lengthlist__8u1__p1_0,
  130923. 1, -535822336, 1611661312, 2, 0,
  130924. _vq_quantlist__8u1__p1_0,
  130925. NULL,
  130926. &_vq_auxt__8u1__p1_0,
  130927. NULL,
  130928. 0
  130929. };
  130930. static long _vq_quantlist__8u1__p2_0[] = {
  130931. 1,
  130932. 0,
  130933. 2,
  130934. };
  130935. static long _vq_lengthlist__8u1__p2_0[] = {
  130936. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  130937. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  130938. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  130939. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  130940. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  130941. 7,
  130942. };
  130943. static float _vq_quantthresh__8u1__p2_0[] = {
  130944. -0.5, 0.5,
  130945. };
  130946. static long _vq_quantmap__8u1__p2_0[] = {
  130947. 1, 0, 2,
  130948. };
  130949. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  130950. _vq_quantthresh__8u1__p2_0,
  130951. _vq_quantmap__8u1__p2_0,
  130952. 3,
  130953. 3
  130954. };
  130955. static static_codebook _8u1__p2_0 = {
  130956. 4, 81,
  130957. _vq_lengthlist__8u1__p2_0,
  130958. 1, -535822336, 1611661312, 2, 0,
  130959. _vq_quantlist__8u1__p2_0,
  130960. NULL,
  130961. &_vq_auxt__8u1__p2_0,
  130962. NULL,
  130963. 0
  130964. };
  130965. static long _vq_quantlist__8u1__p3_0[] = {
  130966. 2,
  130967. 1,
  130968. 3,
  130969. 0,
  130970. 4,
  130971. };
  130972. static long _vq_lengthlist__8u1__p3_0[] = {
  130973. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130974. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130975. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  130976. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  130977. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  130978. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  130979. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  130980. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  130981. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  130982. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  130983. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  130984. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  130985. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  130986. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  130987. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  130988. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  130989. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  130990. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  130991. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  130992. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  130993. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  130994. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  130995. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  130996. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  130997. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  130998. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  130999. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131000. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131001. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131002. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131003. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131004. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131005. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131006. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131007. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131008. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131009. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131010. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131011. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131012. 16,
  131013. };
  131014. static float _vq_quantthresh__8u1__p3_0[] = {
  131015. -1.5, -0.5, 0.5, 1.5,
  131016. };
  131017. static long _vq_quantmap__8u1__p3_0[] = {
  131018. 3, 1, 0, 2, 4,
  131019. };
  131020. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131021. _vq_quantthresh__8u1__p3_0,
  131022. _vq_quantmap__8u1__p3_0,
  131023. 5,
  131024. 5
  131025. };
  131026. static static_codebook _8u1__p3_0 = {
  131027. 4, 625,
  131028. _vq_lengthlist__8u1__p3_0,
  131029. 1, -533725184, 1611661312, 3, 0,
  131030. _vq_quantlist__8u1__p3_0,
  131031. NULL,
  131032. &_vq_auxt__8u1__p3_0,
  131033. NULL,
  131034. 0
  131035. };
  131036. static long _vq_quantlist__8u1__p4_0[] = {
  131037. 2,
  131038. 1,
  131039. 3,
  131040. 0,
  131041. 4,
  131042. };
  131043. static long _vq_lengthlist__8u1__p4_0[] = {
  131044. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131045. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131046. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131047. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131048. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131049. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131050. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131051. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131052. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131053. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131054. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131055. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131056. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131057. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131058. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131059. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131060. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131061. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131062. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131063. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131064. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131065. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131066. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131067. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131068. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131069. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131070. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131071. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131072. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131073. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131074. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131075. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131076. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131077. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131078. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131079. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131080. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131081. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131082. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131083. 10,
  131084. };
  131085. static float _vq_quantthresh__8u1__p4_0[] = {
  131086. -1.5, -0.5, 0.5, 1.5,
  131087. };
  131088. static long _vq_quantmap__8u1__p4_0[] = {
  131089. 3, 1, 0, 2, 4,
  131090. };
  131091. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131092. _vq_quantthresh__8u1__p4_0,
  131093. _vq_quantmap__8u1__p4_0,
  131094. 5,
  131095. 5
  131096. };
  131097. static static_codebook _8u1__p4_0 = {
  131098. 4, 625,
  131099. _vq_lengthlist__8u1__p4_0,
  131100. 1, -533725184, 1611661312, 3, 0,
  131101. _vq_quantlist__8u1__p4_0,
  131102. NULL,
  131103. &_vq_auxt__8u1__p4_0,
  131104. NULL,
  131105. 0
  131106. };
  131107. static long _vq_quantlist__8u1__p5_0[] = {
  131108. 4,
  131109. 3,
  131110. 5,
  131111. 2,
  131112. 6,
  131113. 1,
  131114. 7,
  131115. 0,
  131116. 8,
  131117. };
  131118. static long _vq_lengthlist__8u1__p5_0[] = {
  131119. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131120. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131121. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131122. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131123. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131124. 13,
  131125. };
  131126. static float _vq_quantthresh__8u1__p5_0[] = {
  131127. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131128. };
  131129. static long _vq_quantmap__8u1__p5_0[] = {
  131130. 7, 5, 3, 1, 0, 2, 4, 6,
  131131. 8,
  131132. };
  131133. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131134. _vq_quantthresh__8u1__p5_0,
  131135. _vq_quantmap__8u1__p5_0,
  131136. 9,
  131137. 9
  131138. };
  131139. static static_codebook _8u1__p5_0 = {
  131140. 2, 81,
  131141. _vq_lengthlist__8u1__p5_0,
  131142. 1, -531628032, 1611661312, 4, 0,
  131143. _vq_quantlist__8u1__p5_0,
  131144. NULL,
  131145. &_vq_auxt__8u1__p5_0,
  131146. NULL,
  131147. 0
  131148. };
  131149. static long _vq_quantlist__8u1__p6_0[] = {
  131150. 4,
  131151. 3,
  131152. 5,
  131153. 2,
  131154. 6,
  131155. 1,
  131156. 7,
  131157. 0,
  131158. 8,
  131159. };
  131160. static long _vq_lengthlist__8u1__p6_0[] = {
  131161. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131162. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131163. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131164. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131165. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131166. 10,
  131167. };
  131168. static float _vq_quantthresh__8u1__p6_0[] = {
  131169. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131170. };
  131171. static long _vq_quantmap__8u1__p6_0[] = {
  131172. 7, 5, 3, 1, 0, 2, 4, 6,
  131173. 8,
  131174. };
  131175. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131176. _vq_quantthresh__8u1__p6_0,
  131177. _vq_quantmap__8u1__p6_0,
  131178. 9,
  131179. 9
  131180. };
  131181. static static_codebook _8u1__p6_0 = {
  131182. 2, 81,
  131183. _vq_lengthlist__8u1__p6_0,
  131184. 1, -531628032, 1611661312, 4, 0,
  131185. _vq_quantlist__8u1__p6_0,
  131186. NULL,
  131187. &_vq_auxt__8u1__p6_0,
  131188. NULL,
  131189. 0
  131190. };
  131191. static long _vq_quantlist__8u1__p7_0[] = {
  131192. 1,
  131193. 0,
  131194. 2,
  131195. };
  131196. static long _vq_lengthlist__8u1__p7_0[] = {
  131197. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131198. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131199. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131200. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131201. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131202. 11,
  131203. };
  131204. static float _vq_quantthresh__8u1__p7_0[] = {
  131205. -5.5, 5.5,
  131206. };
  131207. static long _vq_quantmap__8u1__p7_0[] = {
  131208. 1, 0, 2,
  131209. };
  131210. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131211. _vq_quantthresh__8u1__p7_0,
  131212. _vq_quantmap__8u1__p7_0,
  131213. 3,
  131214. 3
  131215. };
  131216. static static_codebook _8u1__p7_0 = {
  131217. 4, 81,
  131218. _vq_lengthlist__8u1__p7_0,
  131219. 1, -529137664, 1618345984, 2, 0,
  131220. _vq_quantlist__8u1__p7_0,
  131221. NULL,
  131222. &_vq_auxt__8u1__p7_0,
  131223. NULL,
  131224. 0
  131225. };
  131226. static long _vq_quantlist__8u1__p7_1[] = {
  131227. 5,
  131228. 4,
  131229. 6,
  131230. 3,
  131231. 7,
  131232. 2,
  131233. 8,
  131234. 1,
  131235. 9,
  131236. 0,
  131237. 10,
  131238. };
  131239. static long _vq_lengthlist__8u1__p7_1[] = {
  131240. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131241. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131242. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131243. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131244. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131245. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131246. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131247. 9, 9, 9, 9, 9,10,10,10,10,
  131248. };
  131249. static float _vq_quantthresh__8u1__p7_1[] = {
  131250. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131251. 3.5, 4.5,
  131252. };
  131253. static long _vq_quantmap__8u1__p7_1[] = {
  131254. 9, 7, 5, 3, 1, 0, 2, 4,
  131255. 6, 8, 10,
  131256. };
  131257. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131258. _vq_quantthresh__8u1__p7_1,
  131259. _vq_quantmap__8u1__p7_1,
  131260. 11,
  131261. 11
  131262. };
  131263. static static_codebook _8u1__p7_1 = {
  131264. 2, 121,
  131265. _vq_lengthlist__8u1__p7_1,
  131266. 1, -531365888, 1611661312, 4, 0,
  131267. _vq_quantlist__8u1__p7_1,
  131268. NULL,
  131269. &_vq_auxt__8u1__p7_1,
  131270. NULL,
  131271. 0
  131272. };
  131273. static long _vq_quantlist__8u1__p8_0[] = {
  131274. 5,
  131275. 4,
  131276. 6,
  131277. 3,
  131278. 7,
  131279. 2,
  131280. 8,
  131281. 1,
  131282. 9,
  131283. 0,
  131284. 10,
  131285. };
  131286. static long _vq_lengthlist__8u1__p8_0[] = {
  131287. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131288. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131289. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131290. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131291. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131292. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131293. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131294. 12,13,13,14,14,15,15,15,15,
  131295. };
  131296. static float _vq_quantthresh__8u1__p8_0[] = {
  131297. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131298. 38.5, 49.5,
  131299. };
  131300. static long _vq_quantmap__8u1__p8_0[] = {
  131301. 9, 7, 5, 3, 1, 0, 2, 4,
  131302. 6, 8, 10,
  131303. };
  131304. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131305. _vq_quantthresh__8u1__p8_0,
  131306. _vq_quantmap__8u1__p8_0,
  131307. 11,
  131308. 11
  131309. };
  131310. static static_codebook _8u1__p8_0 = {
  131311. 2, 121,
  131312. _vq_lengthlist__8u1__p8_0,
  131313. 1, -524582912, 1618345984, 4, 0,
  131314. _vq_quantlist__8u1__p8_0,
  131315. NULL,
  131316. &_vq_auxt__8u1__p8_0,
  131317. NULL,
  131318. 0
  131319. };
  131320. static long _vq_quantlist__8u1__p8_1[] = {
  131321. 5,
  131322. 4,
  131323. 6,
  131324. 3,
  131325. 7,
  131326. 2,
  131327. 8,
  131328. 1,
  131329. 9,
  131330. 0,
  131331. 10,
  131332. };
  131333. static long _vq_lengthlist__8u1__p8_1[] = {
  131334. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131335. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131336. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131337. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131338. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131339. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131340. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131341. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131342. };
  131343. static float _vq_quantthresh__8u1__p8_1[] = {
  131344. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131345. 3.5, 4.5,
  131346. };
  131347. static long _vq_quantmap__8u1__p8_1[] = {
  131348. 9, 7, 5, 3, 1, 0, 2, 4,
  131349. 6, 8, 10,
  131350. };
  131351. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131352. _vq_quantthresh__8u1__p8_1,
  131353. _vq_quantmap__8u1__p8_1,
  131354. 11,
  131355. 11
  131356. };
  131357. static static_codebook _8u1__p8_1 = {
  131358. 2, 121,
  131359. _vq_lengthlist__8u1__p8_1,
  131360. 1, -531365888, 1611661312, 4, 0,
  131361. _vq_quantlist__8u1__p8_1,
  131362. NULL,
  131363. &_vq_auxt__8u1__p8_1,
  131364. NULL,
  131365. 0
  131366. };
  131367. static long _vq_quantlist__8u1__p9_0[] = {
  131368. 7,
  131369. 6,
  131370. 8,
  131371. 5,
  131372. 9,
  131373. 4,
  131374. 10,
  131375. 3,
  131376. 11,
  131377. 2,
  131378. 12,
  131379. 1,
  131380. 13,
  131381. 0,
  131382. 14,
  131383. };
  131384. static long _vq_lengthlist__8u1__p9_0[] = {
  131385. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131386. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131387. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131388. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131389. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131390. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131391. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131392. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131393. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131394. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131395. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131396. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131397. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131398. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131399. 10,
  131400. };
  131401. static float _vq_quantthresh__8u1__p9_0[] = {
  131402. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131403. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131404. };
  131405. static long _vq_quantmap__8u1__p9_0[] = {
  131406. 13, 11, 9, 7, 5, 3, 1, 0,
  131407. 2, 4, 6, 8, 10, 12, 14,
  131408. };
  131409. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131410. _vq_quantthresh__8u1__p9_0,
  131411. _vq_quantmap__8u1__p9_0,
  131412. 15,
  131413. 15
  131414. };
  131415. static static_codebook _8u1__p9_0 = {
  131416. 2, 225,
  131417. _vq_lengthlist__8u1__p9_0,
  131418. 1, -514071552, 1627381760, 4, 0,
  131419. _vq_quantlist__8u1__p9_0,
  131420. NULL,
  131421. &_vq_auxt__8u1__p9_0,
  131422. NULL,
  131423. 0
  131424. };
  131425. static long _vq_quantlist__8u1__p9_1[] = {
  131426. 7,
  131427. 6,
  131428. 8,
  131429. 5,
  131430. 9,
  131431. 4,
  131432. 10,
  131433. 3,
  131434. 11,
  131435. 2,
  131436. 12,
  131437. 1,
  131438. 13,
  131439. 0,
  131440. 14,
  131441. };
  131442. static long _vq_lengthlist__8u1__p9_1[] = {
  131443. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131444. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131445. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131446. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131447. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131448. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131449. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131450. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131451. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131452. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131453. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131454. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131455. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131456. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131457. 13,
  131458. };
  131459. static float _vq_quantthresh__8u1__p9_1[] = {
  131460. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131461. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131462. };
  131463. static long _vq_quantmap__8u1__p9_1[] = {
  131464. 13, 11, 9, 7, 5, 3, 1, 0,
  131465. 2, 4, 6, 8, 10, 12, 14,
  131466. };
  131467. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131468. _vq_quantthresh__8u1__p9_1,
  131469. _vq_quantmap__8u1__p9_1,
  131470. 15,
  131471. 15
  131472. };
  131473. static static_codebook _8u1__p9_1 = {
  131474. 2, 225,
  131475. _vq_lengthlist__8u1__p9_1,
  131476. 1, -522338304, 1620115456, 4, 0,
  131477. _vq_quantlist__8u1__p9_1,
  131478. NULL,
  131479. &_vq_auxt__8u1__p9_1,
  131480. NULL,
  131481. 0
  131482. };
  131483. static long _vq_quantlist__8u1__p9_2[] = {
  131484. 8,
  131485. 7,
  131486. 9,
  131487. 6,
  131488. 10,
  131489. 5,
  131490. 11,
  131491. 4,
  131492. 12,
  131493. 3,
  131494. 13,
  131495. 2,
  131496. 14,
  131497. 1,
  131498. 15,
  131499. 0,
  131500. 16,
  131501. };
  131502. static long _vq_lengthlist__8u1__p9_2[] = {
  131503. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131504. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131505. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131506. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131507. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131508. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131509. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131510. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131511. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131512. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131513. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131514. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131515. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131516. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131517. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131518. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131519. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131520. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131521. 10,
  131522. };
  131523. static float _vq_quantthresh__8u1__p9_2[] = {
  131524. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131525. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131526. };
  131527. static long _vq_quantmap__8u1__p9_2[] = {
  131528. 15, 13, 11, 9, 7, 5, 3, 1,
  131529. 0, 2, 4, 6, 8, 10, 12, 14,
  131530. 16,
  131531. };
  131532. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131533. _vq_quantthresh__8u1__p9_2,
  131534. _vq_quantmap__8u1__p9_2,
  131535. 17,
  131536. 17
  131537. };
  131538. static static_codebook _8u1__p9_2 = {
  131539. 2, 289,
  131540. _vq_lengthlist__8u1__p9_2,
  131541. 1, -529530880, 1611661312, 5, 0,
  131542. _vq_quantlist__8u1__p9_2,
  131543. NULL,
  131544. &_vq_auxt__8u1__p9_2,
  131545. NULL,
  131546. 0
  131547. };
  131548. static long _huff_lengthlist__8u1__single[] = {
  131549. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131550. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131551. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131552. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131553. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131554. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131555. 13, 8, 8,15,
  131556. };
  131557. static static_codebook _huff_book__8u1__single = {
  131558. 2, 100,
  131559. _huff_lengthlist__8u1__single,
  131560. 0, 0, 0, 0, 0,
  131561. NULL,
  131562. NULL,
  131563. NULL,
  131564. NULL,
  131565. 0
  131566. };
  131567. static long _huff_lengthlist__44u0__long[] = {
  131568. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131569. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131570. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131571. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131572. };
  131573. static static_codebook _huff_book__44u0__long = {
  131574. 2, 64,
  131575. _huff_lengthlist__44u0__long,
  131576. 0, 0, 0, 0, 0,
  131577. NULL,
  131578. NULL,
  131579. NULL,
  131580. NULL,
  131581. 0
  131582. };
  131583. static long _vq_quantlist__44u0__p1_0[] = {
  131584. 1,
  131585. 0,
  131586. 2,
  131587. };
  131588. static long _vq_lengthlist__44u0__p1_0[] = {
  131589. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131590. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131591. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131592. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131593. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131594. 13,
  131595. };
  131596. static float _vq_quantthresh__44u0__p1_0[] = {
  131597. -0.5, 0.5,
  131598. };
  131599. static long _vq_quantmap__44u0__p1_0[] = {
  131600. 1, 0, 2,
  131601. };
  131602. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131603. _vq_quantthresh__44u0__p1_0,
  131604. _vq_quantmap__44u0__p1_0,
  131605. 3,
  131606. 3
  131607. };
  131608. static static_codebook _44u0__p1_0 = {
  131609. 4, 81,
  131610. _vq_lengthlist__44u0__p1_0,
  131611. 1, -535822336, 1611661312, 2, 0,
  131612. _vq_quantlist__44u0__p1_0,
  131613. NULL,
  131614. &_vq_auxt__44u0__p1_0,
  131615. NULL,
  131616. 0
  131617. };
  131618. static long _vq_quantlist__44u0__p2_0[] = {
  131619. 1,
  131620. 0,
  131621. 2,
  131622. };
  131623. static long _vq_lengthlist__44u0__p2_0[] = {
  131624. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131625. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131626. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131627. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131628. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131629. 9,
  131630. };
  131631. static float _vq_quantthresh__44u0__p2_0[] = {
  131632. -0.5, 0.5,
  131633. };
  131634. static long _vq_quantmap__44u0__p2_0[] = {
  131635. 1, 0, 2,
  131636. };
  131637. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131638. _vq_quantthresh__44u0__p2_0,
  131639. _vq_quantmap__44u0__p2_0,
  131640. 3,
  131641. 3
  131642. };
  131643. static static_codebook _44u0__p2_0 = {
  131644. 4, 81,
  131645. _vq_lengthlist__44u0__p2_0,
  131646. 1, -535822336, 1611661312, 2, 0,
  131647. _vq_quantlist__44u0__p2_0,
  131648. NULL,
  131649. &_vq_auxt__44u0__p2_0,
  131650. NULL,
  131651. 0
  131652. };
  131653. static long _vq_quantlist__44u0__p3_0[] = {
  131654. 2,
  131655. 1,
  131656. 3,
  131657. 0,
  131658. 4,
  131659. };
  131660. static long _vq_lengthlist__44u0__p3_0[] = {
  131661. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131662. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131663. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131664. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131665. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131666. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131667. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131668. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131669. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131670. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131671. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131672. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131673. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131674. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131675. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131676. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131677. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131678. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131679. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131680. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131681. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131682. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131683. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131684. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131685. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131686. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131687. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131688. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131689. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131690. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131691. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131692. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131693. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131694. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131695. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131696. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131697. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131698. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131699. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131700. 19,
  131701. };
  131702. static float _vq_quantthresh__44u0__p3_0[] = {
  131703. -1.5, -0.5, 0.5, 1.5,
  131704. };
  131705. static long _vq_quantmap__44u0__p3_0[] = {
  131706. 3, 1, 0, 2, 4,
  131707. };
  131708. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131709. _vq_quantthresh__44u0__p3_0,
  131710. _vq_quantmap__44u0__p3_0,
  131711. 5,
  131712. 5
  131713. };
  131714. static static_codebook _44u0__p3_0 = {
  131715. 4, 625,
  131716. _vq_lengthlist__44u0__p3_0,
  131717. 1, -533725184, 1611661312, 3, 0,
  131718. _vq_quantlist__44u0__p3_0,
  131719. NULL,
  131720. &_vq_auxt__44u0__p3_0,
  131721. NULL,
  131722. 0
  131723. };
  131724. static long _vq_quantlist__44u0__p4_0[] = {
  131725. 2,
  131726. 1,
  131727. 3,
  131728. 0,
  131729. 4,
  131730. };
  131731. static long _vq_lengthlist__44u0__p4_0[] = {
  131732. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131733. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131734. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131735. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131736. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131737. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131738. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131739. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131740. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131741. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131742. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131743. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131744. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131745. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131746. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131747. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131748. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131749. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131750. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131751. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131752. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131753. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131754. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131755. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131756. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131757. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131758. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131759. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131760. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131761. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131762. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131763. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131764. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131765. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131766. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131767. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131768. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131769. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131770. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131771. 12,
  131772. };
  131773. static float _vq_quantthresh__44u0__p4_0[] = {
  131774. -1.5, -0.5, 0.5, 1.5,
  131775. };
  131776. static long _vq_quantmap__44u0__p4_0[] = {
  131777. 3, 1, 0, 2, 4,
  131778. };
  131779. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131780. _vq_quantthresh__44u0__p4_0,
  131781. _vq_quantmap__44u0__p4_0,
  131782. 5,
  131783. 5
  131784. };
  131785. static static_codebook _44u0__p4_0 = {
  131786. 4, 625,
  131787. _vq_lengthlist__44u0__p4_0,
  131788. 1, -533725184, 1611661312, 3, 0,
  131789. _vq_quantlist__44u0__p4_0,
  131790. NULL,
  131791. &_vq_auxt__44u0__p4_0,
  131792. NULL,
  131793. 0
  131794. };
  131795. static long _vq_quantlist__44u0__p5_0[] = {
  131796. 4,
  131797. 3,
  131798. 5,
  131799. 2,
  131800. 6,
  131801. 1,
  131802. 7,
  131803. 0,
  131804. 8,
  131805. };
  131806. static long _vq_lengthlist__44u0__p5_0[] = {
  131807. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131808. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131809. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131810. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131811. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131812. 12,
  131813. };
  131814. static float _vq_quantthresh__44u0__p5_0[] = {
  131815. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131816. };
  131817. static long _vq_quantmap__44u0__p5_0[] = {
  131818. 7, 5, 3, 1, 0, 2, 4, 6,
  131819. 8,
  131820. };
  131821. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131822. _vq_quantthresh__44u0__p5_0,
  131823. _vq_quantmap__44u0__p5_0,
  131824. 9,
  131825. 9
  131826. };
  131827. static static_codebook _44u0__p5_0 = {
  131828. 2, 81,
  131829. _vq_lengthlist__44u0__p5_0,
  131830. 1, -531628032, 1611661312, 4, 0,
  131831. _vq_quantlist__44u0__p5_0,
  131832. NULL,
  131833. &_vq_auxt__44u0__p5_0,
  131834. NULL,
  131835. 0
  131836. };
  131837. static long _vq_quantlist__44u0__p6_0[] = {
  131838. 6,
  131839. 5,
  131840. 7,
  131841. 4,
  131842. 8,
  131843. 3,
  131844. 9,
  131845. 2,
  131846. 10,
  131847. 1,
  131848. 11,
  131849. 0,
  131850. 12,
  131851. };
  131852. static long _vq_lengthlist__44u0__p6_0[] = {
  131853. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131854. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131855. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131856. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131857. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131858. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131859. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131860. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131861. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131862. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131863. 15,17,16,17,18,17,17,18, 0,
  131864. };
  131865. static float _vq_quantthresh__44u0__p6_0[] = {
  131866. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131867. 12.5, 17.5, 22.5, 27.5,
  131868. };
  131869. static long _vq_quantmap__44u0__p6_0[] = {
  131870. 11, 9, 7, 5, 3, 1, 0, 2,
  131871. 4, 6, 8, 10, 12,
  131872. };
  131873. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131874. _vq_quantthresh__44u0__p6_0,
  131875. _vq_quantmap__44u0__p6_0,
  131876. 13,
  131877. 13
  131878. };
  131879. static static_codebook _44u0__p6_0 = {
  131880. 2, 169,
  131881. _vq_lengthlist__44u0__p6_0,
  131882. 1, -526516224, 1616117760, 4, 0,
  131883. _vq_quantlist__44u0__p6_0,
  131884. NULL,
  131885. &_vq_auxt__44u0__p6_0,
  131886. NULL,
  131887. 0
  131888. };
  131889. static long _vq_quantlist__44u0__p6_1[] = {
  131890. 2,
  131891. 1,
  131892. 3,
  131893. 0,
  131894. 4,
  131895. };
  131896. static long _vq_lengthlist__44u0__p6_1[] = {
  131897. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131898. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131899. };
  131900. static float _vq_quantthresh__44u0__p6_1[] = {
  131901. -1.5, -0.5, 0.5, 1.5,
  131902. };
  131903. static long _vq_quantmap__44u0__p6_1[] = {
  131904. 3, 1, 0, 2, 4,
  131905. };
  131906. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  131907. _vq_quantthresh__44u0__p6_1,
  131908. _vq_quantmap__44u0__p6_1,
  131909. 5,
  131910. 5
  131911. };
  131912. static static_codebook _44u0__p6_1 = {
  131913. 2, 25,
  131914. _vq_lengthlist__44u0__p6_1,
  131915. 1, -533725184, 1611661312, 3, 0,
  131916. _vq_quantlist__44u0__p6_1,
  131917. NULL,
  131918. &_vq_auxt__44u0__p6_1,
  131919. NULL,
  131920. 0
  131921. };
  131922. static long _vq_quantlist__44u0__p7_0[] = {
  131923. 2,
  131924. 1,
  131925. 3,
  131926. 0,
  131927. 4,
  131928. };
  131929. static long _vq_lengthlist__44u0__p7_0[] = {
  131930. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  131931. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131932. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131933. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131934. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131935. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131936. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131937. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  131938. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131939. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131940. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131941. 11,11,11,11,11,11,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,11,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,11,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,10,10,10,10,10,10,10,10,10,10,
  131961. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131962. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131963. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131964. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131965. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131966. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131967. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131968. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131969. 10,
  131970. };
  131971. static float _vq_quantthresh__44u0__p7_0[] = {
  131972. -253.5, -84.5, 84.5, 253.5,
  131973. };
  131974. static long _vq_quantmap__44u0__p7_0[] = {
  131975. 3, 1, 0, 2, 4,
  131976. };
  131977. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  131978. _vq_quantthresh__44u0__p7_0,
  131979. _vq_quantmap__44u0__p7_0,
  131980. 5,
  131981. 5
  131982. };
  131983. static static_codebook _44u0__p7_0 = {
  131984. 4, 625,
  131985. _vq_lengthlist__44u0__p7_0,
  131986. 1, -518709248, 1626677248, 3, 0,
  131987. _vq_quantlist__44u0__p7_0,
  131988. NULL,
  131989. &_vq_auxt__44u0__p7_0,
  131990. NULL,
  131991. 0
  131992. };
  131993. static long _vq_quantlist__44u0__p7_1[] = {
  131994. 6,
  131995. 5,
  131996. 7,
  131997. 4,
  131998. 8,
  131999. 3,
  132000. 9,
  132001. 2,
  132002. 10,
  132003. 1,
  132004. 11,
  132005. 0,
  132006. 12,
  132007. };
  132008. static long _vq_lengthlist__44u0__p7_1[] = {
  132009. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132010. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132011. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132012. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132013. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132014. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132015. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132016. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132017. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132018. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132019. 15,15,15,15,15,15,15,15,15,
  132020. };
  132021. static float _vq_quantthresh__44u0__p7_1[] = {
  132022. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132023. 32.5, 45.5, 58.5, 71.5,
  132024. };
  132025. static long _vq_quantmap__44u0__p7_1[] = {
  132026. 11, 9, 7, 5, 3, 1, 0, 2,
  132027. 4, 6, 8, 10, 12,
  132028. };
  132029. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132030. _vq_quantthresh__44u0__p7_1,
  132031. _vq_quantmap__44u0__p7_1,
  132032. 13,
  132033. 13
  132034. };
  132035. static static_codebook _44u0__p7_1 = {
  132036. 2, 169,
  132037. _vq_lengthlist__44u0__p7_1,
  132038. 1, -523010048, 1618608128, 4, 0,
  132039. _vq_quantlist__44u0__p7_1,
  132040. NULL,
  132041. &_vq_auxt__44u0__p7_1,
  132042. NULL,
  132043. 0
  132044. };
  132045. static long _vq_quantlist__44u0__p7_2[] = {
  132046. 6,
  132047. 5,
  132048. 7,
  132049. 4,
  132050. 8,
  132051. 3,
  132052. 9,
  132053. 2,
  132054. 10,
  132055. 1,
  132056. 11,
  132057. 0,
  132058. 12,
  132059. };
  132060. static long _vq_lengthlist__44u0__p7_2[] = {
  132061. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132062. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132063. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132064. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132065. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132066. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132067. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132068. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132069. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132070. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132071. 9, 9, 9,10, 9, 9,10,10, 9,
  132072. };
  132073. static float _vq_quantthresh__44u0__p7_2[] = {
  132074. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132075. 2.5, 3.5, 4.5, 5.5,
  132076. };
  132077. static long _vq_quantmap__44u0__p7_2[] = {
  132078. 11, 9, 7, 5, 3, 1, 0, 2,
  132079. 4, 6, 8, 10, 12,
  132080. };
  132081. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132082. _vq_quantthresh__44u0__p7_2,
  132083. _vq_quantmap__44u0__p7_2,
  132084. 13,
  132085. 13
  132086. };
  132087. static static_codebook _44u0__p7_2 = {
  132088. 2, 169,
  132089. _vq_lengthlist__44u0__p7_2,
  132090. 1, -531103744, 1611661312, 4, 0,
  132091. _vq_quantlist__44u0__p7_2,
  132092. NULL,
  132093. &_vq_auxt__44u0__p7_2,
  132094. NULL,
  132095. 0
  132096. };
  132097. static long _huff_lengthlist__44u0__short[] = {
  132098. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132099. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132100. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132101. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132102. };
  132103. static static_codebook _huff_book__44u0__short = {
  132104. 2, 64,
  132105. _huff_lengthlist__44u0__short,
  132106. 0, 0, 0, 0, 0,
  132107. NULL,
  132108. NULL,
  132109. NULL,
  132110. NULL,
  132111. 0
  132112. };
  132113. static long _huff_lengthlist__44u1__long[] = {
  132114. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132115. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132116. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132117. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132118. };
  132119. static static_codebook _huff_book__44u1__long = {
  132120. 2, 64,
  132121. _huff_lengthlist__44u1__long,
  132122. 0, 0, 0, 0, 0,
  132123. NULL,
  132124. NULL,
  132125. NULL,
  132126. NULL,
  132127. 0
  132128. };
  132129. static long _vq_quantlist__44u1__p1_0[] = {
  132130. 1,
  132131. 0,
  132132. 2,
  132133. };
  132134. static long _vq_lengthlist__44u1__p1_0[] = {
  132135. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132136. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132137. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132138. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132139. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132140. 13,
  132141. };
  132142. static float _vq_quantthresh__44u1__p1_0[] = {
  132143. -0.5, 0.5,
  132144. };
  132145. static long _vq_quantmap__44u1__p1_0[] = {
  132146. 1, 0, 2,
  132147. };
  132148. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132149. _vq_quantthresh__44u1__p1_0,
  132150. _vq_quantmap__44u1__p1_0,
  132151. 3,
  132152. 3
  132153. };
  132154. static static_codebook _44u1__p1_0 = {
  132155. 4, 81,
  132156. _vq_lengthlist__44u1__p1_0,
  132157. 1, -535822336, 1611661312, 2, 0,
  132158. _vq_quantlist__44u1__p1_0,
  132159. NULL,
  132160. &_vq_auxt__44u1__p1_0,
  132161. NULL,
  132162. 0
  132163. };
  132164. static long _vq_quantlist__44u1__p2_0[] = {
  132165. 1,
  132166. 0,
  132167. 2,
  132168. };
  132169. static long _vq_lengthlist__44u1__p2_0[] = {
  132170. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132171. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132172. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132173. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132174. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132175. 9,
  132176. };
  132177. static float _vq_quantthresh__44u1__p2_0[] = {
  132178. -0.5, 0.5,
  132179. };
  132180. static long _vq_quantmap__44u1__p2_0[] = {
  132181. 1, 0, 2,
  132182. };
  132183. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132184. _vq_quantthresh__44u1__p2_0,
  132185. _vq_quantmap__44u1__p2_0,
  132186. 3,
  132187. 3
  132188. };
  132189. static static_codebook _44u1__p2_0 = {
  132190. 4, 81,
  132191. _vq_lengthlist__44u1__p2_0,
  132192. 1, -535822336, 1611661312, 2, 0,
  132193. _vq_quantlist__44u1__p2_0,
  132194. NULL,
  132195. &_vq_auxt__44u1__p2_0,
  132196. NULL,
  132197. 0
  132198. };
  132199. static long _vq_quantlist__44u1__p3_0[] = {
  132200. 2,
  132201. 1,
  132202. 3,
  132203. 0,
  132204. 4,
  132205. };
  132206. static long _vq_lengthlist__44u1__p3_0[] = {
  132207. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132208. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132209. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132210. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132211. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132212. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132213. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132214. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132215. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132216. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132217. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132218. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132219. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132220. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132221. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132222. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132223. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132224. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132225. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132226. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132227. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132228. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132229. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132230. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132231. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132232. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132233. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132234. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132235. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132236. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132237. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132238. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132239. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132240. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132241. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132242. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132243. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132244. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132245. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132246. 19,
  132247. };
  132248. static float _vq_quantthresh__44u1__p3_0[] = {
  132249. -1.5, -0.5, 0.5, 1.5,
  132250. };
  132251. static long _vq_quantmap__44u1__p3_0[] = {
  132252. 3, 1, 0, 2, 4,
  132253. };
  132254. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132255. _vq_quantthresh__44u1__p3_0,
  132256. _vq_quantmap__44u1__p3_0,
  132257. 5,
  132258. 5
  132259. };
  132260. static static_codebook _44u1__p3_0 = {
  132261. 4, 625,
  132262. _vq_lengthlist__44u1__p3_0,
  132263. 1, -533725184, 1611661312, 3, 0,
  132264. _vq_quantlist__44u1__p3_0,
  132265. NULL,
  132266. &_vq_auxt__44u1__p3_0,
  132267. NULL,
  132268. 0
  132269. };
  132270. static long _vq_quantlist__44u1__p4_0[] = {
  132271. 2,
  132272. 1,
  132273. 3,
  132274. 0,
  132275. 4,
  132276. };
  132277. static long _vq_lengthlist__44u1__p4_0[] = {
  132278. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132279. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132280. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132281. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132282. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132283. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132284. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132285. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132286. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132287. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132288. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132289. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132290. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132291. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132292. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132293. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132294. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132295. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132296. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132297. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132298. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132299. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132300. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132301. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132302. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132303. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132304. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132305. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132306. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132307. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132308. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132309. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132310. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132311. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132312. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132313. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132314. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132315. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132316. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132317. 12,
  132318. };
  132319. static float _vq_quantthresh__44u1__p4_0[] = {
  132320. -1.5, -0.5, 0.5, 1.5,
  132321. };
  132322. static long _vq_quantmap__44u1__p4_0[] = {
  132323. 3, 1, 0, 2, 4,
  132324. };
  132325. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132326. _vq_quantthresh__44u1__p4_0,
  132327. _vq_quantmap__44u1__p4_0,
  132328. 5,
  132329. 5
  132330. };
  132331. static static_codebook _44u1__p4_0 = {
  132332. 4, 625,
  132333. _vq_lengthlist__44u1__p4_0,
  132334. 1, -533725184, 1611661312, 3, 0,
  132335. _vq_quantlist__44u1__p4_0,
  132336. NULL,
  132337. &_vq_auxt__44u1__p4_0,
  132338. NULL,
  132339. 0
  132340. };
  132341. static long _vq_quantlist__44u1__p5_0[] = {
  132342. 4,
  132343. 3,
  132344. 5,
  132345. 2,
  132346. 6,
  132347. 1,
  132348. 7,
  132349. 0,
  132350. 8,
  132351. };
  132352. static long _vq_lengthlist__44u1__p5_0[] = {
  132353. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132354. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132355. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132356. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132357. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132358. 12,
  132359. };
  132360. static float _vq_quantthresh__44u1__p5_0[] = {
  132361. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132362. };
  132363. static long _vq_quantmap__44u1__p5_0[] = {
  132364. 7, 5, 3, 1, 0, 2, 4, 6,
  132365. 8,
  132366. };
  132367. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132368. _vq_quantthresh__44u1__p5_0,
  132369. _vq_quantmap__44u1__p5_0,
  132370. 9,
  132371. 9
  132372. };
  132373. static static_codebook _44u1__p5_0 = {
  132374. 2, 81,
  132375. _vq_lengthlist__44u1__p5_0,
  132376. 1, -531628032, 1611661312, 4, 0,
  132377. _vq_quantlist__44u1__p5_0,
  132378. NULL,
  132379. &_vq_auxt__44u1__p5_0,
  132380. NULL,
  132381. 0
  132382. };
  132383. static long _vq_quantlist__44u1__p6_0[] = {
  132384. 6,
  132385. 5,
  132386. 7,
  132387. 4,
  132388. 8,
  132389. 3,
  132390. 9,
  132391. 2,
  132392. 10,
  132393. 1,
  132394. 11,
  132395. 0,
  132396. 12,
  132397. };
  132398. static long _vq_lengthlist__44u1__p6_0[] = {
  132399. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132400. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132401. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132402. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132403. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132404. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132405. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132406. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132407. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132408. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132409. 15,17,16,17,18,17,17,18, 0,
  132410. };
  132411. static float _vq_quantthresh__44u1__p6_0[] = {
  132412. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132413. 12.5, 17.5, 22.5, 27.5,
  132414. };
  132415. static long _vq_quantmap__44u1__p6_0[] = {
  132416. 11, 9, 7, 5, 3, 1, 0, 2,
  132417. 4, 6, 8, 10, 12,
  132418. };
  132419. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132420. _vq_quantthresh__44u1__p6_0,
  132421. _vq_quantmap__44u1__p6_0,
  132422. 13,
  132423. 13
  132424. };
  132425. static static_codebook _44u1__p6_0 = {
  132426. 2, 169,
  132427. _vq_lengthlist__44u1__p6_0,
  132428. 1, -526516224, 1616117760, 4, 0,
  132429. _vq_quantlist__44u1__p6_0,
  132430. NULL,
  132431. &_vq_auxt__44u1__p6_0,
  132432. NULL,
  132433. 0
  132434. };
  132435. static long _vq_quantlist__44u1__p6_1[] = {
  132436. 2,
  132437. 1,
  132438. 3,
  132439. 0,
  132440. 4,
  132441. };
  132442. static long _vq_lengthlist__44u1__p6_1[] = {
  132443. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132444. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132445. };
  132446. static float _vq_quantthresh__44u1__p6_1[] = {
  132447. -1.5, -0.5, 0.5, 1.5,
  132448. };
  132449. static long _vq_quantmap__44u1__p6_1[] = {
  132450. 3, 1, 0, 2, 4,
  132451. };
  132452. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132453. _vq_quantthresh__44u1__p6_1,
  132454. _vq_quantmap__44u1__p6_1,
  132455. 5,
  132456. 5
  132457. };
  132458. static static_codebook _44u1__p6_1 = {
  132459. 2, 25,
  132460. _vq_lengthlist__44u1__p6_1,
  132461. 1, -533725184, 1611661312, 3, 0,
  132462. _vq_quantlist__44u1__p6_1,
  132463. NULL,
  132464. &_vq_auxt__44u1__p6_1,
  132465. NULL,
  132466. 0
  132467. };
  132468. static long _vq_quantlist__44u1__p7_0[] = {
  132469. 3,
  132470. 2,
  132471. 4,
  132472. 1,
  132473. 5,
  132474. 0,
  132475. 6,
  132476. };
  132477. static long _vq_lengthlist__44u1__p7_0[] = {
  132478. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132479. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132480. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132481. 8,
  132482. };
  132483. static float _vq_quantthresh__44u1__p7_0[] = {
  132484. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132485. };
  132486. static long _vq_quantmap__44u1__p7_0[] = {
  132487. 5, 3, 1, 0, 2, 4, 6,
  132488. };
  132489. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132490. _vq_quantthresh__44u1__p7_0,
  132491. _vq_quantmap__44u1__p7_0,
  132492. 7,
  132493. 7
  132494. };
  132495. static static_codebook _44u1__p7_0 = {
  132496. 2, 49,
  132497. _vq_lengthlist__44u1__p7_0,
  132498. 1, -518017024, 1626677248, 3, 0,
  132499. _vq_quantlist__44u1__p7_0,
  132500. NULL,
  132501. &_vq_auxt__44u1__p7_0,
  132502. NULL,
  132503. 0
  132504. };
  132505. static long _vq_quantlist__44u1__p7_1[] = {
  132506. 6,
  132507. 5,
  132508. 7,
  132509. 4,
  132510. 8,
  132511. 3,
  132512. 9,
  132513. 2,
  132514. 10,
  132515. 1,
  132516. 11,
  132517. 0,
  132518. 12,
  132519. };
  132520. static long _vq_lengthlist__44u1__p7_1[] = {
  132521. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132522. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132523. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132524. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132525. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132526. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132527. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132528. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132529. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132530. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132531. 15,15,15,15,15,15,15,15,15,
  132532. };
  132533. static float _vq_quantthresh__44u1__p7_1[] = {
  132534. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132535. 32.5, 45.5, 58.5, 71.5,
  132536. };
  132537. static long _vq_quantmap__44u1__p7_1[] = {
  132538. 11, 9, 7, 5, 3, 1, 0, 2,
  132539. 4, 6, 8, 10, 12,
  132540. };
  132541. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132542. _vq_quantthresh__44u1__p7_1,
  132543. _vq_quantmap__44u1__p7_1,
  132544. 13,
  132545. 13
  132546. };
  132547. static static_codebook _44u1__p7_1 = {
  132548. 2, 169,
  132549. _vq_lengthlist__44u1__p7_1,
  132550. 1, -523010048, 1618608128, 4, 0,
  132551. _vq_quantlist__44u1__p7_1,
  132552. NULL,
  132553. &_vq_auxt__44u1__p7_1,
  132554. NULL,
  132555. 0
  132556. };
  132557. static long _vq_quantlist__44u1__p7_2[] = {
  132558. 6,
  132559. 5,
  132560. 7,
  132561. 4,
  132562. 8,
  132563. 3,
  132564. 9,
  132565. 2,
  132566. 10,
  132567. 1,
  132568. 11,
  132569. 0,
  132570. 12,
  132571. };
  132572. static long _vq_lengthlist__44u1__p7_2[] = {
  132573. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132574. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132575. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132576. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132577. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132578. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132579. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132580. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132581. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132582. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132583. 9, 9, 9,10, 9, 9,10,10, 9,
  132584. };
  132585. static float _vq_quantthresh__44u1__p7_2[] = {
  132586. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132587. 2.5, 3.5, 4.5, 5.5,
  132588. };
  132589. static long _vq_quantmap__44u1__p7_2[] = {
  132590. 11, 9, 7, 5, 3, 1, 0, 2,
  132591. 4, 6, 8, 10, 12,
  132592. };
  132593. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132594. _vq_quantthresh__44u1__p7_2,
  132595. _vq_quantmap__44u1__p7_2,
  132596. 13,
  132597. 13
  132598. };
  132599. static static_codebook _44u1__p7_2 = {
  132600. 2, 169,
  132601. _vq_lengthlist__44u1__p7_2,
  132602. 1, -531103744, 1611661312, 4, 0,
  132603. _vq_quantlist__44u1__p7_2,
  132604. NULL,
  132605. &_vq_auxt__44u1__p7_2,
  132606. NULL,
  132607. 0
  132608. };
  132609. static long _huff_lengthlist__44u1__short[] = {
  132610. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132611. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132612. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132613. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132614. };
  132615. static static_codebook _huff_book__44u1__short = {
  132616. 2, 64,
  132617. _huff_lengthlist__44u1__short,
  132618. 0, 0, 0, 0, 0,
  132619. NULL,
  132620. NULL,
  132621. NULL,
  132622. NULL,
  132623. 0
  132624. };
  132625. static long _huff_lengthlist__44u2__long[] = {
  132626. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132627. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132628. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132629. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132630. };
  132631. static static_codebook _huff_book__44u2__long = {
  132632. 2, 64,
  132633. _huff_lengthlist__44u2__long,
  132634. 0, 0, 0, 0, 0,
  132635. NULL,
  132636. NULL,
  132637. NULL,
  132638. NULL,
  132639. 0
  132640. };
  132641. static long _vq_quantlist__44u2__p1_0[] = {
  132642. 1,
  132643. 0,
  132644. 2,
  132645. };
  132646. static long _vq_lengthlist__44u2__p1_0[] = {
  132647. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132648. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132649. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132650. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132651. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132652. 13,
  132653. };
  132654. static float _vq_quantthresh__44u2__p1_0[] = {
  132655. -0.5, 0.5,
  132656. };
  132657. static long _vq_quantmap__44u2__p1_0[] = {
  132658. 1, 0, 2,
  132659. };
  132660. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132661. _vq_quantthresh__44u2__p1_0,
  132662. _vq_quantmap__44u2__p1_0,
  132663. 3,
  132664. 3
  132665. };
  132666. static static_codebook _44u2__p1_0 = {
  132667. 4, 81,
  132668. _vq_lengthlist__44u2__p1_0,
  132669. 1, -535822336, 1611661312, 2, 0,
  132670. _vq_quantlist__44u2__p1_0,
  132671. NULL,
  132672. &_vq_auxt__44u2__p1_0,
  132673. NULL,
  132674. 0
  132675. };
  132676. static long _vq_quantlist__44u2__p2_0[] = {
  132677. 1,
  132678. 0,
  132679. 2,
  132680. };
  132681. static long _vq_lengthlist__44u2__p2_0[] = {
  132682. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132683. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132684. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132685. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132686. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132687. 9,
  132688. };
  132689. static float _vq_quantthresh__44u2__p2_0[] = {
  132690. -0.5, 0.5,
  132691. };
  132692. static long _vq_quantmap__44u2__p2_0[] = {
  132693. 1, 0, 2,
  132694. };
  132695. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132696. _vq_quantthresh__44u2__p2_0,
  132697. _vq_quantmap__44u2__p2_0,
  132698. 3,
  132699. 3
  132700. };
  132701. static static_codebook _44u2__p2_0 = {
  132702. 4, 81,
  132703. _vq_lengthlist__44u2__p2_0,
  132704. 1, -535822336, 1611661312, 2, 0,
  132705. _vq_quantlist__44u2__p2_0,
  132706. NULL,
  132707. &_vq_auxt__44u2__p2_0,
  132708. NULL,
  132709. 0
  132710. };
  132711. static long _vq_quantlist__44u2__p3_0[] = {
  132712. 2,
  132713. 1,
  132714. 3,
  132715. 0,
  132716. 4,
  132717. };
  132718. static long _vq_lengthlist__44u2__p3_0[] = {
  132719. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132720. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132721. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132722. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132723. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132724. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132725. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132726. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132727. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132728. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132729. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132730. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132731. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132732. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132733. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132734. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132735. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132736. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132737. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132738. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132739. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132740. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132741. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132742. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132743. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132744. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132745. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132746. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132747. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132748. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132749. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132750. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132751. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132752. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132753. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132754. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132755. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132756. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132757. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132758. 0,
  132759. };
  132760. static float _vq_quantthresh__44u2__p3_0[] = {
  132761. -1.5, -0.5, 0.5, 1.5,
  132762. };
  132763. static long _vq_quantmap__44u2__p3_0[] = {
  132764. 3, 1, 0, 2, 4,
  132765. };
  132766. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132767. _vq_quantthresh__44u2__p3_0,
  132768. _vq_quantmap__44u2__p3_0,
  132769. 5,
  132770. 5
  132771. };
  132772. static static_codebook _44u2__p3_0 = {
  132773. 4, 625,
  132774. _vq_lengthlist__44u2__p3_0,
  132775. 1, -533725184, 1611661312, 3, 0,
  132776. _vq_quantlist__44u2__p3_0,
  132777. NULL,
  132778. &_vq_auxt__44u2__p3_0,
  132779. NULL,
  132780. 0
  132781. };
  132782. static long _vq_quantlist__44u2__p4_0[] = {
  132783. 2,
  132784. 1,
  132785. 3,
  132786. 0,
  132787. 4,
  132788. };
  132789. static long _vq_lengthlist__44u2__p4_0[] = {
  132790. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132791. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132792. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132793. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132794. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132795. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132796. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132797. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132798. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132799. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132800. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132801. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132802. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132803. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132804. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132805. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132806. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132807. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132808. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132809. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132810. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132811. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132812. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132813. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132814. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132815. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132816. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132817. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132818. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132819. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132820. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132821. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132822. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132823. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132824. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132825. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132826. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132827. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132828. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132829. 13,
  132830. };
  132831. static float _vq_quantthresh__44u2__p4_0[] = {
  132832. -1.5, -0.5, 0.5, 1.5,
  132833. };
  132834. static long _vq_quantmap__44u2__p4_0[] = {
  132835. 3, 1, 0, 2, 4,
  132836. };
  132837. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132838. _vq_quantthresh__44u2__p4_0,
  132839. _vq_quantmap__44u2__p4_0,
  132840. 5,
  132841. 5
  132842. };
  132843. static static_codebook _44u2__p4_0 = {
  132844. 4, 625,
  132845. _vq_lengthlist__44u2__p4_0,
  132846. 1, -533725184, 1611661312, 3, 0,
  132847. _vq_quantlist__44u2__p4_0,
  132848. NULL,
  132849. &_vq_auxt__44u2__p4_0,
  132850. NULL,
  132851. 0
  132852. };
  132853. static long _vq_quantlist__44u2__p5_0[] = {
  132854. 4,
  132855. 3,
  132856. 5,
  132857. 2,
  132858. 6,
  132859. 1,
  132860. 7,
  132861. 0,
  132862. 8,
  132863. };
  132864. static long _vq_lengthlist__44u2__p5_0[] = {
  132865. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132866. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132867. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132868. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132869. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132870. 13,
  132871. };
  132872. static float _vq_quantthresh__44u2__p5_0[] = {
  132873. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132874. };
  132875. static long _vq_quantmap__44u2__p5_0[] = {
  132876. 7, 5, 3, 1, 0, 2, 4, 6,
  132877. 8,
  132878. };
  132879. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132880. _vq_quantthresh__44u2__p5_0,
  132881. _vq_quantmap__44u2__p5_0,
  132882. 9,
  132883. 9
  132884. };
  132885. static static_codebook _44u2__p5_0 = {
  132886. 2, 81,
  132887. _vq_lengthlist__44u2__p5_0,
  132888. 1, -531628032, 1611661312, 4, 0,
  132889. _vq_quantlist__44u2__p5_0,
  132890. NULL,
  132891. &_vq_auxt__44u2__p5_0,
  132892. NULL,
  132893. 0
  132894. };
  132895. static long _vq_quantlist__44u2__p6_0[] = {
  132896. 6,
  132897. 5,
  132898. 7,
  132899. 4,
  132900. 8,
  132901. 3,
  132902. 9,
  132903. 2,
  132904. 10,
  132905. 1,
  132906. 11,
  132907. 0,
  132908. 12,
  132909. };
  132910. static long _vq_lengthlist__44u2__p6_0[] = {
  132911. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  132912. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  132913. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  132914. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  132915. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  132916. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  132917. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  132918. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  132919. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  132920. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  132921. 15,17,17,16,18,17,18, 0, 0,
  132922. };
  132923. static float _vq_quantthresh__44u2__p6_0[] = {
  132924. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132925. 12.5, 17.5, 22.5, 27.5,
  132926. };
  132927. static long _vq_quantmap__44u2__p6_0[] = {
  132928. 11, 9, 7, 5, 3, 1, 0, 2,
  132929. 4, 6, 8, 10, 12,
  132930. };
  132931. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  132932. _vq_quantthresh__44u2__p6_0,
  132933. _vq_quantmap__44u2__p6_0,
  132934. 13,
  132935. 13
  132936. };
  132937. static static_codebook _44u2__p6_0 = {
  132938. 2, 169,
  132939. _vq_lengthlist__44u2__p6_0,
  132940. 1, -526516224, 1616117760, 4, 0,
  132941. _vq_quantlist__44u2__p6_0,
  132942. NULL,
  132943. &_vq_auxt__44u2__p6_0,
  132944. NULL,
  132945. 0
  132946. };
  132947. static long _vq_quantlist__44u2__p6_1[] = {
  132948. 2,
  132949. 1,
  132950. 3,
  132951. 0,
  132952. 4,
  132953. };
  132954. static long _vq_lengthlist__44u2__p6_1[] = {
  132955. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  132956. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  132957. };
  132958. static float _vq_quantthresh__44u2__p6_1[] = {
  132959. -1.5, -0.5, 0.5, 1.5,
  132960. };
  132961. static long _vq_quantmap__44u2__p6_1[] = {
  132962. 3, 1, 0, 2, 4,
  132963. };
  132964. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  132965. _vq_quantthresh__44u2__p6_1,
  132966. _vq_quantmap__44u2__p6_1,
  132967. 5,
  132968. 5
  132969. };
  132970. static static_codebook _44u2__p6_1 = {
  132971. 2, 25,
  132972. _vq_lengthlist__44u2__p6_1,
  132973. 1, -533725184, 1611661312, 3, 0,
  132974. _vq_quantlist__44u2__p6_1,
  132975. NULL,
  132976. &_vq_auxt__44u2__p6_1,
  132977. NULL,
  132978. 0
  132979. };
  132980. static long _vq_quantlist__44u2__p7_0[] = {
  132981. 4,
  132982. 3,
  132983. 5,
  132984. 2,
  132985. 6,
  132986. 1,
  132987. 7,
  132988. 0,
  132989. 8,
  132990. };
  132991. static long _vq_lengthlist__44u2__p7_0[] = {
  132992. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  132993. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  132994. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132995. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132996. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132997. 11,
  132998. };
  132999. static float _vq_quantthresh__44u2__p7_0[] = {
  133000. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133001. };
  133002. static long _vq_quantmap__44u2__p7_0[] = {
  133003. 7, 5, 3, 1, 0, 2, 4, 6,
  133004. 8,
  133005. };
  133006. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133007. _vq_quantthresh__44u2__p7_0,
  133008. _vq_quantmap__44u2__p7_0,
  133009. 9,
  133010. 9
  133011. };
  133012. static static_codebook _44u2__p7_0 = {
  133013. 2, 81,
  133014. _vq_lengthlist__44u2__p7_0,
  133015. 1, -516612096, 1626677248, 4, 0,
  133016. _vq_quantlist__44u2__p7_0,
  133017. NULL,
  133018. &_vq_auxt__44u2__p7_0,
  133019. NULL,
  133020. 0
  133021. };
  133022. static long _vq_quantlist__44u2__p7_1[] = {
  133023. 6,
  133024. 5,
  133025. 7,
  133026. 4,
  133027. 8,
  133028. 3,
  133029. 9,
  133030. 2,
  133031. 10,
  133032. 1,
  133033. 11,
  133034. 0,
  133035. 12,
  133036. };
  133037. static long _vq_lengthlist__44u2__p7_1[] = {
  133038. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133039. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133040. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133041. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133042. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133043. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133044. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133045. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133046. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133047. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133048. 14,14,14,17,15,17,17,17,17,
  133049. };
  133050. static float _vq_quantthresh__44u2__p7_1[] = {
  133051. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133052. 32.5, 45.5, 58.5, 71.5,
  133053. };
  133054. static long _vq_quantmap__44u2__p7_1[] = {
  133055. 11, 9, 7, 5, 3, 1, 0, 2,
  133056. 4, 6, 8, 10, 12,
  133057. };
  133058. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133059. _vq_quantthresh__44u2__p7_1,
  133060. _vq_quantmap__44u2__p7_1,
  133061. 13,
  133062. 13
  133063. };
  133064. static static_codebook _44u2__p7_1 = {
  133065. 2, 169,
  133066. _vq_lengthlist__44u2__p7_1,
  133067. 1, -523010048, 1618608128, 4, 0,
  133068. _vq_quantlist__44u2__p7_1,
  133069. NULL,
  133070. &_vq_auxt__44u2__p7_1,
  133071. NULL,
  133072. 0
  133073. };
  133074. static long _vq_quantlist__44u2__p7_2[] = {
  133075. 6,
  133076. 5,
  133077. 7,
  133078. 4,
  133079. 8,
  133080. 3,
  133081. 9,
  133082. 2,
  133083. 10,
  133084. 1,
  133085. 11,
  133086. 0,
  133087. 12,
  133088. };
  133089. static long _vq_lengthlist__44u2__p7_2[] = {
  133090. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133091. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133092. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133093. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133094. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133095. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133096. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133097. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133098. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133099. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133100. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133101. };
  133102. static float _vq_quantthresh__44u2__p7_2[] = {
  133103. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133104. 2.5, 3.5, 4.5, 5.5,
  133105. };
  133106. static long _vq_quantmap__44u2__p7_2[] = {
  133107. 11, 9, 7, 5, 3, 1, 0, 2,
  133108. 4, 6, 8, 10, 12,
  133109. };
  133110. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133111. _vq_quantthresh__44u2__p7_2,
  133112. _vq_quantmap__44u2__p7_2,
  133113. 13,
  133114. 13
  133115. };
  133116. static static_codebook _44u2__p7_2 = {
  133117. 2, 169,
  133118. _vq_lengthlist__44u2__p7_2,
  133119. 1, -531103744, 1611661312, 4, 0,
  133120. _vq_quantlist__44u2__p7_2,
  133121. NULL,
  133122. &_vq_auxt__44u2__p7_2,
  133123. NULL,
  133124. 0
  133125. };
  133126. static long _huff_lengthlist__44u2__short[] = {
  133127. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133128. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133129. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133130. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133131. };
  133132. static static_codebook _huff_book__44u2__short = {
  133133. 2, 64,
  133134. _huff_lengthlist__44u2__short,
  133135. 0, 0, 0, 0, 0,
  133136. NULL,
  133137. NULL,
  133138. NULL,
  133139. NULL,
  133140. 0
  133141. };
  133142. static long _huff_lengthlist__44u3__long[] = {
  133143. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133144. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133145. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133146. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133147. };
  133148. static static_codebook _huff_book__44u3__long = {
  133149. 2, 64,
  133150. _huff_lengthlist__44u3__long,
  133151. 0, 0, 0, 0, 0,
  133152. NULL,
  133153. NULL,
  133154. NULL,
  133155. NULL,
  133156. 0
  133157. };
  133158. static long _vq_quantlist__44u3__p1_0[] = {
  133159. 1,
  133160. 0,
  133161. 2,
  133162. };
  133163. static long _vq_lengthlist__44u3__p1_0[] = {
  133164. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133165. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133166. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133167. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133168. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133169. 13,
  133170. };
  133171. static float _vq_quantthresh__44u3__p1_0[] = {
  133172. -0.5, 0.5,
  133173. };
  133174. static long _vq_quantmap__44u3__p1_0[] = {
  133175. 1, 0, 2,
  133176. };
  133177. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133178. _vq_quantthresh__44u3__p1_0,
  133179. _vq_quantmap__44u3__p1_0,
  133180. 3,
  133181. 3
  133182. };
  133183. static static_codebook _44u3__p1_0 = {
  133184. 4, 81,
  133185. _vq_lengthlist__44u3__p1_0,
  133186. 1, -535822336, 1611661312, 2, 0,
  133187. _vq_quantlist__44u3__p1_0,
  133188. NULL,
  133189. &_vq_auxt__44u3__p1_0,
  133190. NULL,
  133191. 0
  133192. };
  133193. static long _vq_quantlist__44u3__p2_0[] = {
  133194. 1,
  133195. 0,
  133196. 2,
  133197. };
  133198. static long _vq_lengthlist__44u3__p2_0[] = {
  133199. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133200. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133201. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133202. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133203. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133204. 9,
  133205. };
  133206. static float _vq_quantthresh__44u3__p2_0[] = {
  133207. -0.5, 0.5,
  133208. };
  133209. static long _vq_quantmap__44u3__p2_0[] = {
  133210. 1, 0, 2,
  133211. };
  133212. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133213. _vq_quantthresh__44u3__p2_0,
  133214. _vq_quantmap__44u3__p2_0,
  133215. 3,
  133216. 3
  133217. };
  133218. static static_codebook _44u3__p2_0 = {
  133219. 4, 81,
  133220. _vq_lengthlist__44u3__p2_0,
  133221. 1, -535822336, 1611661312, 2, 0,
  133222. _vq_quantlist__44u3__p2_0,
  133223. NULL,
  133224. &_vq_auxt__44u3__p2_0,
  133225. NULL,
  133226. 0
  133227. };
  133228. static long _vq_quantlist__44u3__p3_0[] = {
  133229. 2,
  133230. 1,
  133231. 3,
  133232. 0,
  133233. 4,
  133234. };
  133235. static long _vq_lengthlist__44u3__p3_0[] = {
  133236. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133237. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133238. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133239. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133240. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133241. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133242. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133243. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133244. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133245. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133246. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133247. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133248. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133249. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133250. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133251. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133252. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133253. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133254. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133255. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133256. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133257. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133258. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133259. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133260. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133261. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133262. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133263. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133264. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133265. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133266. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133267. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133268. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133269. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133270. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133271. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133272. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133273. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133274. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133275. 0,
  133276. };
  133277. static float _vq_quantthresh__44u3__p3_0[] = {
  133278. -1.5, -0.5, 0.5, 1.5,
  133279. };
  133280. static long _vq_quantmap__44u3__p3_0[] = {
  133281. 3, 1, 0, 2, 4,
  133282. };
  133283. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133284. _vq_quantthresh__44u3__p3_0,
  133285. _vq_quantmap__44u3__p3_0,
  133286. 5,
  133287. 5
  133288. };
  133289. static static_codebook _44u3__p3_0 = {
  133290. 4, 625,
  133291. _vq_lengthlist__44u3__p3_0,
  133292. 1, -533725184, 1611661312, 3, 0,
  133293. _vq_quantlist__44u3__p3_0,
  133294. NULL,
  133295. &_vq_auxt__44u3__p3_0,
  133296. NULL,
  133297. 0
  133298. };
  133299. static long _vq_quantlist__44u3__p4_0[] = {
  133300. 2,
  133301. 1,
  133302. 3,
  133303. 0,
  133304. 4,
  133305. };
  133306. static long _vq_lengthlist__44u3__p4_0[] = {
  133307. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133308. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133309. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133310. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133311. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133312. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133313. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133314. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133315. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133316. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133317. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133318. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133319. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133320. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133321. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133322. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133323. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133324. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133325. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133326. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133327. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133328. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133329. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133330. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133331. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133332. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133333. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133334. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133335. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133336. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133337. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133338. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133339. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133340. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133341. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133342. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133343. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133344. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133345. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133346. 13,
  133347. };
  133348. static float _vq_quantthresh__44u3__p4_0[] = {
  133349. -1.5, -0.5, 0.5, 1.5,
  133350. };
  133351. static long _vq_quantmap__44u3__p4_0[] = {
  133352. 3, 1, 0, 2, 4,
  133353. };
  133354. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133355. _vq_quantthresh__44u3__p4_0,
  133356. _vq_quantmap__44u3__p4_0,
  133357. 5,
  133358. 5
  133359. };
  133360. static static_codebook _44u3__p4_0 = {
  133361. 4, 625,
  133362. _vq_lengthlist__44u3__p4_0,
  133363. 1, -533725184, 1611661312, 3, 0,
  133364. _vq_quantlist__44u3__p4_0,
  133365. NULL,
  133366. &_vq_auxt__44u3__p4_0,
  133367. NULL,
  133368. 0
  133369. };
  133370. static long _vq_quantlist__44u3__p5_0[] = {
  133371. 4,
  133372. 3,
  133373. 5,
  133374. 2,
  133375. 6,
  133376. 1,
  133377. 7,
  133378. 0,
  133379. 8,
  133380. };
  133381. static long _vq_lengthlist__44u3__p5_0[] = {
  133382. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133383. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133384. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133385. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133386. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133387. 12,
  133388. };
  133389. static float _vq_quantthresh__44u3__p5_0[] = {
  133390. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133391. };
  133392. static long _vq_quantmap__44u3__p5_0[] = {
  133393. 7, 5, 3, 1, 0, 2, 4, 6,
  133394. 8,
  133395. };
  133396. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133397. _vq_quantthresh__44u3__p5_0,
  133398. _vq_quantmap__44u3__p5_0,
  133399. 9,
  133400. 9
  133401. };
  133402. static static_codebook _44u3__p5_0 = {
  133403. 2, 81,
  133404. _vq_lengthlist__44u3__p5_0,
  133405. 1, -531628032, 1611661312, 4, 0,
  133406. _vq_quantlist__44u3__p5_0,
  133407. NULL,
  133408. &_vq_auxt__44u3__p5_0,
  133409. NULL,
  133410. 0
  133411. };
  133412. static long _vq_quantlist__44u3__p6_0[] = {
  133413. 6,
  133414. 5,
  133415. 7,
  133416. 4,
  133417. 8,
  133418. 3,
  133419. 9,
  133420. 2,
  133421. 10,
  133422. 1,
  133423. 11,
  133424. 0,
  133425. 12,
  133426. };
  133427. static long _vq_lengthlist__44u3__p6_0[] = {
  133428. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133429. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133430. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133431. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133432. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133433. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133434. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133435. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133436. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133437. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133438. 15,16,16,16,17,18,16,20,18,
  133439. };
  133440. static float _vq_quantthresh__44u3__p6_0[] = {
  133441. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133442. 12.5, 17.5, 22.5, 27.5,
  133443. };
  133444. static long _vq_quantmap__44u3__p6_0[] = {
  133445. 11, 9, 7, 5, 3, 1, 0, 2,
  133446. 4, 6, 8, 10, 12,
  133447. };
  133448. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133449. _vq_quantthresh__44u3__p6_0,
  133450. _vq_quantmap__44u3__p6_0,
  133451. 13,
  133452. 13
  133453. };
  133454. static static_codebook _44u3__p6_0 = {
  133455. 2, 169,
  133456. _vq_lengthlist__44u3__p6_0,
  133457. 1, -526516224, 1616117760, 4, 0,
  133458. _vq_quantlist__44u3__p6_0,
  133459. NULL,
  133460. &_vq_auxt__44u3__p6_0,
  133461. NULL,
  133462. 0
  133463. };
  133464. static long _vq_quantlist__44u3__p6_1[] = {
  133465. 2,
  133466. 1,
  133467. 3,
  133468. 0,
  133469. 4,
  133470. };
  133471. static long _vq_lengthlist__44u3__p6_1[] = {
  133472. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133473. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133474. };
  133475. static float _vq_quantthresh__44u3__p6_1[] = {
  133476. -1.5, -0.5, 0.5, 1.5,
  133477. };
  133478. static long _vq_quantmap__44u3__p6_1[] = {
  133479. 3, 1, 0, 2, 4,
  133480. };
  133481. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133482. _vq_quantthresh__44u3__p6_1,
  133483. _vq_quantmap__44u3__p6_1,
  133484. 5,
  133485. 5
  133486. };
  133487. static static_codebook _44u3__p6_1 = {
  133488. 2, 25,
  133489. _vq_lengthlist__44u3__p6_1,
  133490. 1, -533725184, 1611661312, 3, 0,
  133491. _vq_quantlist__44u3__p6_1,
  133492. NULL,
  133493. &_vq_auxt__44u3__p6_1,
  133494. NULL,
  133495. 0
  133496. };
  133497. static long _vq_quantlist__44u3__p7_0[] = {
  133498. 4,
  133499. 3,
  133500. 5,
  133501. 2,
  133502. 6,
  133503. 1,
  133504. 7,
  133505. 0,
  133506. 8,
  133507. };
  133508. static long _vq_lengthlist__44u3__p7_0[] = {
  133509. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133510. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133511. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133512. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133513. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133514. 9,
  133515. };
  133516. static float _vq_quantthresh__44u3__p7_0[] = {
  133517. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133518. };
  133519. static long _vq_quantmap__44u3__p7_0[] = {
  133520. 7, 5, 3, 1, 0, 2, 4, 6,
  133521. 8,
  133522. };
  133523. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133524. _vq_quantthresh__44u3__p7_0,
  133525. _vq_quantmap__44u3__p7_0,
  133526. 9,
  133527. 9
  133528. };
  133529. static static_codebook _44u3__p7_0 = {
  133530. 2, 81,
  133531. _vq_lengthlist__44u3__p7_0,
  133532. 1, -515907584, 1627381760, 4, 0,
  133533. _vq_quantlist__44u3__p7_0,
  133534. NULL,
  133535. &_vq_auxt__44u3__p7_0,
  133536. NULL,
  133537. 0
  133538. };
  133539. static long _vq_quantlist__44u3__p7_1[] = {
  133540. 7,
  133541. 6,
  133542. 8,
  133543. 5,
  133544. 9,
  133545. 4,
  133546. 10,
  133547. 3,
  133548. 11,
  133549. 2,
  133550. 12,
  133551. 1,
  133552. 13,
  133553. 0,
  133554. 14,
  133555. };
  133556. static long _vq_lengthlist__44u3__p7_1[] = {
  133557. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133558. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133559. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133560. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133561. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133562. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133563. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133564. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133565. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133566. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133567. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133568. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133569. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133570. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133571. 17,
  133572. };
  133573. static float _vq_quantthresh__44u3__p7_1[] = {
  133574. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133575. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133576. };
  133577. static long _vq_quantmap__44u3__p7_1[] = {
  133578. 13, 11, 9, 7, 5, 3, 1, 0,
  133579. 2, 4, 6, 8, 10, 12, 14,
  133580. };
  133581. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133582. _vq_quantthresh__44u3__p7_1,
  133583. _vq_quantmap__44u3__p7_1,
  133584. 15,
  133585. 15
  133586. };
  133587. static static_codebook _44u3__p7_1 = {
  133588. 2, 225,
  133589. _vq_lengthlist__44u3__p7_1,
  133590. 1, -522338304, 1620115456, 4, 0,
  133591. _vq_quantlist__44u3__p7_1,
  133592. NULL,
  133593. &_vq_auxt__44u3__p7_1,
  133594. NULL,
  133595. 0
  133596. };
  133597. static long _vq_quantlist__44u3__p7_2[] = {
  133598. 8,
  133599. 7,
  133600. 9,
  133601. 6,
  133602. 10,
  133603. 5,
  133604. 11,
  133605. 4,
  133606. 12,
  133607. 3,
  133608. 13,
  133609. 2,
  133610. 14,
  133611. 1,
  133612. 15,
  133613. 0,
  133614. 16,
  133615. };
  133616. static long _vq_lengthlist__44u3__p7_2[] = {
  133617. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133618. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133619. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133620. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133621. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133622. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133623. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133624. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133625. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133626. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133627. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133628. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133629. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133630. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133631. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133632. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133633. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133634. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133635. 11,
  133636. };
  133637. static float _vq_quantthresh__44u3__p7_2[] = {
  133638. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133639. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133640. };
  133641. static long _vq_quantmap__44u3__p7_2[] = {
  133642. 15, 13, 11, 9, 7, 5, 3, 1,
  133643. 0, 2, 4, 6, 8, 10, 12, 14,
  133644. 16,
  133645. };
  133646. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133647. _vq_quantthresh__44u3__p7_2,
  133648. _vq_quantmap__44u3__p7_2,
  133649. 17,
  133650. 17
  133651. };
  133652. static static_codebook _44u3__p7_2 = {
  133653. 2, 289,
  133654. _vq_lengthlist__44u3__p7_2,
  133655. 1, -529530880, 1611661312, 5, 0,
  133656. _vq_quantlist__44u3__p7_2,
  133657. NULL,
  133658. &_vq_auxt__44u3__p7_2,
  133659. NULL,
  133660. 0
  133661. };
  133662. static long _huff_lengthlist__44u3__short[] = {
  133663. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133664. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133665. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133666. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133667. };
  133668. static static_codebook _huff_book__44u3__short = {
  133669. 2, 64,
  133670. _huff_lengthlist__44u3__short,
  133671. 0, 0, 0, 0, 0,
  133672. NULL,
  133673. NULL,
  133674. NULL,
  133675. NULL,
  133676. 0
  133677. };
  133678. static long _huff_lengthlist__44u4__long[] = {
  133679. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133680. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133681. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133682. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133683. };
  133684. static static_codebook _huff_book__44u4__long = {
  133685. 2, 64,
  133686. _huff_lengthlist__44u4__long,
  133687. 0, 0, 0, 0, 0,
  133688. NULL,
  133689. NULL,
  133690. NULL,
  133691. NULL,
  133692. 0
  133693. };
  133694. static long _vq_quantlist__44u4__p1_0[] = {
  133695. 1,
  133696. 0,
  133697. 2,
  133698. };
  133699. static long _vq_lengthlist__44u4__p1_0[] = {
  133700. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133701. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133702. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133703. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133704. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133705. 13,
  133706. };
  133707. static float _vq_quantthresh__44u4__p1_0[] = {
  133708. -0.5, 0.5,
  133709. };
  133710. static long _vq_quantmap__44u4__p1_0[] = {
  133711. 1, 0, 2,
  133712. };
  133713. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133714. _vq_quantthresh__44u4__p1_0,
  133715. _vq_quantmap__44u4__p1_0,
  133716. 3,
  133717. 3
  133718. };
  133719. static static_codebook _44u4__p1_0 = {
  133720. 4, 81,
  133721. _vq_lengthlist__44u4__p1_0,
  133722. 1, -535822336, 1611661312, 2, 0,
  133723. _vq_quantlist__44u4__p1_0,
  133724. NULL,
  133725. &_vq_auxt__44u4__p1_0,
  133726. NULL,
  133727. 0
  133728. };
  133729. static long _vq_quantlist__44u4__p2_0[] = {
  133730. 1,
  133731. 0,
  133732. 2,
  133733. };
  133734. static long _vq_lengthlist__44u4__p2_0[] = {
  133735. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133736. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133737. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133738. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133739. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133740. 9,
  133741. };
  133742. static float _vq_quantthresh__44u4__p2_0[] = {
  133743. -0.5, 0.5,
  133744. };
  133745. static long _vq_quantmap__44u4__p2_0[] = {
  133746. 1, 0, 2,
  133747. };
  133748. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133749. _vq_quantthresh__44u4__p2_0,
  133750. _vq_quantmap__44u4__p2_0,
  133751. 3,
  133752. 3
  133753. };
  133754. static static_codebook _44u4__p2_0 = {
  133755. 4, 81,
  133756. _vq_lengthlist__44u4__p2_0,
  133757. 1, -535822336, 1611661312, 2, 0,
  133758. _vq_quantlist__44u4__p2_0,
  133759. NULL,
  133760. &_vq_auxt__44u4__p2_0,
  133761. NULL,
  133762. 0
  133763. };
  133764. static long _vq_quantlist__44u4__p3_0[] = {
  133765. 2,
  133766. 1,
  133767. 3,
  133768. 0,
  133769. 4,
  133770. };
  133771. static long _vq_lengthlist__44u4__p3_0[] = {
  133772. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133773. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133774. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133775. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133776. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133777. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133778. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133779. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133780. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133781. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133782. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133783. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133784. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133785. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133786. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133787. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133788. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133789. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133790. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133791. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133792. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133793. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133794. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133795. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133796. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133797. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133798. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133799. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133800. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133801. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133802. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133803. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133804. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133805. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133806. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133807. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133808. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133809. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133810. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133811. 0,
  133812. };
  133813. static float _vq_quantthresh__44u4__p3_0[] = {
  133814. -1.5, -0.5, 0.5, 1.5,
  133815. };
  133816. static long _vq_quantmap__44u4__p3_0[] = {
  133817. 3, 1, 0, 2, 4,
  133818. };
  133819. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133820. _vq_quantthresh__44u4__p3_0,
  133821. _vq_quantmap__44u4__p3_0,
  133822. 5,
  133823. 5
  133824. };
  133825. static static_codebook _44u4__p3_0 = {
  133826. 4, 625,
  133827. _vq_lengthlist__44u4__p3_0,
  133828. 1, -533725184, 1611661312, 3, 0,
  133829. _vq_quantlist__44u4__p3_0,
  133830. NULL,
  133831. &_vq_auxt__44u4__p3_0,
  133832. NULL,
  133833. 0
  133834. };
  133835. static long _vq_quantlist__44u4__p4_0[] = {
  133836. 2,
  133837. 1,
  133838. 3,
  133839. 0,
  133840. 4,
  133841. };
  133842. static long _vq_lengthlist__44u4__p4_0[] = {
  133843. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133844. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133845. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133846. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133847. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133848. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133849. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133850. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133851. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133852. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133853. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133854. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133855. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133856. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133857. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133858. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133859. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133860. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133861. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133862. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133863. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133864. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133865. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133866. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133867. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133868. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133869. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133870. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133871. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133872. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133873. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133874. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133875. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133876. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133877. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133878. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133879. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133880. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133881. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133882. 13,
  133883. };
  133884. static float _vq_quantthresh__44u4__p4_0[] = {
  133885. -1.5, -0.5, 0.5, 1.5,
  133886. };
  133887. static long _vq_quantmap__44u4__p4_0[] = {
  133888. 3, 1, 0, 2, 4,
  133889. };
  133890. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133891. _vq_quantthresh__44u4__p4_0,
  133892. _vq_quantmap__44u4__p4_0,
  133893. 5,
  133894. 5
  133895. };
  133896. static static_codebook _44u4__p4_0 = {
  133897. 4, 625,
  133898. _vq_lengthlist__44u4__p4_0,
  133899. 1, -533725184, 1611661312, 3, 0,
  133900. _vq_quantlist__44u4__p4_0,
  133901. NULL,
  133902. &_vq_auxt__44u4__p4_0,
  133903. NULL,
  133904. 0
  133905. };
  133906. static long _vq_quantlist__44u4__p5_0[] = {
  133907. 4,
  133908. 3,
  133909. 5,
  133910. 2,
  133911. 6,
  133912. 1,
  133913. 7,
  133914. 0,
  133915. 8,
  133916. };
  133917. static long _vq_lengthlist__44u4__p5_0[] = {
  133918. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133919. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133920. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  133921. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133922. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  133923. 12,
  133924. };
  133925. static float _vq_quantthresh__44u4__p5_0[] = {
  133926. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133927. };
  133928. static long _vq_quantmap__44u4__p5_0[] = {
  133929. 7, 5, 3, 1, 0, 2, 4, 6,
  133930. 8,
  133931. };
  133932. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  133933. _vq_quantthresh__44u4__p5_0,
  133934. _vq_quantmap__44u4__p5_0,
  133935. 9,
  133936. 9
  133937. };
  133938. static static_codebook _44u4__p5_0 = {
  133939. 2, 81,
  133940. _vq_lengthlist__44u4__p5_0,
  133941. 1, -531628032, 1611661312, 4, 0,
  133942. _vq_quantlist__44u4__p5_0,
  133943. NULL,
  133944. &_vq_auxt__44u4__p5_0,
  133945. NULL,
  133946. 0
  133947. };
  133948. static long _vq_quantlist__44u4__p6_0[] = {
  133949. 6,
  133950. 5,
  133951. 7,
  133952. 4,
  133953. 8,
  133954. 3,
  133955. 9,
  133956. 2,
  133957. 10,
  133958. 1,
  133959. 11,
  133960. 0,
  133961. 12,
  133962. };
  133963. static long _vq_lengthlist__44u4__p6_0[] = {
  133964. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  133965. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133966. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133967. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133968. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  133969. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  133970. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  133971. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  133972. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  133973. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  133974. 16,16,16,17,17,18,17,20,21,
  133975. };
  133976. static float _vq_quantthresh__44u4__p6_0[] = {
  133977. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133978. 12.5, 17.5, 22.5, 27.5,
  133979. };
  133980. static long _vq_quantmap__44u4__p6_0[] = {
  133981. 11, 9, 7, 5, 3, 1, 0, 2,
  133982. 4, 6, 8, 10, 12,
  133983. };
  133984. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  133985. _vq_quantthresh__44u4__p6_0,
  133986. _vq_quantmap__44u4__p6_0,
  133987. 13,
  133988. 13
  133989. };
  133990. static static_codebook _44u4__p6_0 = {
  133991. 2, 169,
  133992. _vq_lengthlist__44u4__p6_0,
  133993. 1, -526516224, 1616117760, 4, 0,
  133994. _vq_quantlist__44u4__p6_0,
  133995. NULL,
  133996. &_vq_auxt__44u4__p6_0,
  133997. NULL,
  133998. 0
  133999. };
  134000. static long _vq_quantlist__44u4__p6_1[] = {
  134001. 2,
  134002. 1,
  134003. 3,
  134004. 0,
  134005. 4,
  134006. };
  134007. static long _vq_lengthlist__44u4__p6_1[] = {
  134008. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134009. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134010. };
  134011. static float _vq_quantthresh__44u4__p6_1[] = {
  134012. -1.5, -0.5, 0.5, 1.5,
  134013. };
  134014. static long _vq_quantmap__44u4__p6_1[] = {
  134015. 3, 1, 0, 2, 4,
  134016. };
  134017. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134018. _vq_quantthresh__44u4__p6_1,
  134019. _vq_quantmap__44u4__p6_1,
  134020. 5,
  134021. 5
  134022. };
  134023. static static_codebook _44u4__p6_1 = {
  134024. 2, 25,
  134025. _vq_lengthlist__44u4__p6_1,
  134026. 1, -533725184, 1611661312, 3, 0,
  134027. _vq_quantlist__44u4__p6_1,
  134028. NULL,
  134029. &_vq_auxt__44u4__p6_1,
  134030. NULL,
  134031. 0
  134032. };
  134033. static long _vq_quantlist__44u4__p7_0[] = {
  134034. 6,
  134035. 5,
  134036. 7,
  134037. 4,
  134038. 8,
  134039. 3,
  134040. 9,
  134041. 2,
  134042. 10,
  134043. 1,
  134044. 11,
  134045. 0,
  134046. 12,
  134047. };
  134048. static long _vq_lengthlist__44u4__p7_0[] = {
  134049. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134050. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134051. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134052. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134053. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134054. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134055. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134056. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134057. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134058. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134059. 11,11,11,11,11,11,11,11,11,
  134060. };
  134061. static float _vq_quantthresh__44u4__p7_0[] = {
  134062. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134063. 637.5, 892.5, 1147.5, 1402.5,
  134064. };
  134065. static long _vq_quantmap__44u4__p7_0[] = {
  134066. 11, 9, 7, 5, 3, 1, 0, 2,
  134067. 4, 6, 8, 10, 12,
  134068. };
  134069. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134070. _vq_quantthresh__44u4__p7_0,
  134071. _vq_quantmap__44u4__p7_0,
  134072. 13,
  134073. 13
  134074. };
  134075. static static_codebook _44u4__p7_0 = {
  134076. 2, 169,
  134077. _vq_lengthlist__44u4__p7_0,
  134078. 1, -514332672, 1627381760, 4, 0,
  134079. _vq_quantlist__44u4__p7_0,
  134080. NULL,
  134081. &_vq_auxt__44u4__p7_0,
  134082. NULL,
  134083. 0
  134084. };
  134085. static long _vq_quantlist__44u4__p7_1[] = {
  134086. 7,
  134087. 6,
  134088. 8,
  134089. 5,
  134090. 9,
  134091. 4,
  134092. 10,
  134093. 3,
  134094. 11,
  134095. 2,
  134096. 12,
  134097. 1,
  134098. 13,
  134099. 0,
  134100. 14,
  134101. };
  134102. static long _vq_lengthlist__44u4__p7_1[] = {
  134103. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134104. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134105. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134106. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134107. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134108. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134109. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134110. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134111. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134112. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134113. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134114. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134115. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134116. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134117. 16,
  134118. };
  134119. static float _vq_quantthresh__44u4__p7_1[] = {
  134120. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134121. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134122. };
  134123. static long _vq_quantmap__44u4__p7_1[] = {
  134124. 13, 11, 9, 7, 5, 3, 1, 0,
  134125. 2, 4, 6, 8, 10, 12, 14,
  134126. };
  134127. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134128. _vq_quantthresh__44u4__p7_1,
  134129. _vq_quantmap__44u4__p7_1,
  134130. 15,
  134131. 15
  134132. };
  134133. static static_codebook _44u4__p7_1 = {
  134134. 2, 225,
  134135. _vq_lengthlist__44u4__p7_1,
  134136. 1, -522338304, 1620115456, 4, 0,
  134137. _vq_quantlist__44u4__p7_1,
  134138. NULL,
  134139. &_vq_auxt__44u4__p7_1,
  134140. NULL,
  134141. 0
  134142. };
  134143. static long _vq_quantlist__44u4__p7_2[] = {
  134144. 8,
  134145. 7,
  134146. 9,
  134147. 6,
  134148. 10,
  134149. 5,
  134150. 11,
  134151. 4,
  134152. 12,
  134153. 3,
  134154. 13,
  134155. 2,
  134156. 14,
  134157. 1,
  134158. 15,
  134159. 0,
  134160. 16,
  134161. };
  134162. static long _vq_lengthlist__44u4__p7_2[] = {
  134163. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134164. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134165. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134166. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134167. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134168. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134169. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134170. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134171. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134172. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134173. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134174. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134175. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134176. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134177. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134178. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134179. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134180. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134181. 10,
  134182. };
  134183. static float _vq_quantthresh__44u4__p7_2[] = {
  134184. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134185. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134186. };
  134187. static long _vq_quantmap__44u4__p7_2[] = {
  134188. 15, 13, 11, 9, 7, 5, 3, 1,
  134189. 0, 2, 4, 6, 8, 10, 12, 14,
  134190. 16,
  134191. };
  134192. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134193. _vq_quantthresh__44u4__p7_2,
  134194. _vq_quantmap__44u4__p7_2,
  134195. 17,
  134196. 17
  134197. };
  134198. static static_codebook _44u4__p7_2 = {
  134199. 2, 289,
  134200. _vq_lengthlist__44u4__p7_2,
  134201. 1, -529530880, 1611661312, 5, 0,
  134202. _vq_quantlist__44u4__p7_2,
  134203. NULL,
  134204. &_vq_auxt__44u4__p7_2,
  134205. NULL,
  134206. 0
  134207. };
  134208. static long _huff_lengthlist__44u4__short[] = {
  134209. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134210. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134211. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134212. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134213. };
  134214. static static_codebook _huff_book__44u4__short = {
  134215. 2, 64,
  134216. _huff_lengthlist__44u4__short,
  134217. 0, 0, 0, 0, 0,
  134218. NULL,
  134219. NULL,
  134220. NULL,
  134221. NULL,
  134222. 0
  134223. };
  134224. static long _huff_lengthlist__44u5__long[] = {
  134225. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134226. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134227. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134228. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134229. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134230. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134231. 14, 8, 7, 8,
  134232. };
  134233. static static_codebook _huff_book__44u5__long = {
  134234. 2, 100,
  134235. _huff_lengthlist__44u5__long,
  134236. 0, 0, 0, 0, 0,
  134237. NULL,
  134238. NULL,
  134239. NULL,
  134240. NULL,
  134241. 0
  134242. };
  134243. static long _vq_quantlist__44u5__p1_0[] = {
  134244. 1,
  134245. 0,
  134246. 2,
  134247. };
  134248. static long _vq_lengthlist__44u5__p1_0[] = {
  134249. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134250. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134251. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134252. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134253. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134254. 12,
  134255. };
  134256. static float _vq_quantthresh__44u5__p1_0[] = {
  134257. -0.5, 0.5,
  134258. };
  134259. static long _vq_quantmap__44u5__p1_0[] = {
  134260. 1, 0, 2,
  134261. };
  134262. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134263. _vq_quantthresh__44u5__p1_0,
  134264. _vq_quantmap__44u5__p1_0,
  134265. 3,
  134266. 3
  134267. };
  134268. static static_codebook _44u5__p1_0 = {
  134269. 4, 81,
  134270. _vq_lengthlist__44u5__p1_0,
  134271. 1, -535822336, 1611661312, 2, 0,
  134272. _vq_quantlist__44u5__p1_0,
  134273. NULL,
  134274. &_vq_auxt__44u5__p1_0,
  134275. NULL,
  134276. 0
  134277. };
  134278. static long _vq_quantlist__44u5__p2_0[] = {
  134279. 1,
  134280. 0,
  134281. 2,
  134282. };
  134283. static long _vq_lengthlist__44u5__p2_0[] = {
  134284. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134285. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134286. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134287. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134288. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134289. 9,
  134290. };
  134291. static float _vq_quantthresh__44u5__p2_0[] = {
  134292. -0.5, 0.5,
  134293. };
  134294. static long _vq_quantmap__44u5__p2_0[] = {
  134295. 1, 0, 2,
  134296. };
  134297. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134298. _vq_quantthresh__44u5__p2_0,
  134299. _vq_quantmap__44u5__p2_0,
  134300. 3,
  134301. 3
  134302. };
  134303. static static_codebook _44u5__p2_0 = {
  134304. 4, 81,
  134305. _vq_lengthlist__44u5__p2_0,
  134306. 1, -535822336, 1611661312, 2, 0,
  134307. _vq_quantlist__44u5__p2_0,
  134308. NULL,
  134309. &_vq_auxt__44u5__p2_0,
  134310. NULL,
  134311. 0
  134312. };
  134313. static long _vq_quantlist__44u5__p3_0[] = {
  134314. 2,
  134315. 1,
  134316. 3,
  134317. 0,
  134318. 4,
  134319. };
  134320. static long _vq_lengthlist__44u5__p3_0[] = {
  134321. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134322. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134323. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134324. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134325. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134326. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134327. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134328. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134329. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134330. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134331. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134332. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134333. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134334. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134335. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134336. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134337. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134338. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134339. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134340. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134341. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134342. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134343. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134344. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134345. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134346. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134347. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134348. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134349. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134350. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134351. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134352. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134353. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134354. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134355. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134356. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134357. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134358. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134359. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134360. 0,
  134361. };
  134362. static float _vq_quantthresh__44u5__p3_0[] = {
  134363. -1.5, -0.5, 0.5, 1.5,
  134364. };
  134365. static long _vq_quantmap__44u5__p3_0[] = {
  134366. 3, 1, 0, 2, 4,
  134367. };
  134368. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134369. _vq_quantthresh__44u5__p3_0,
  134370. _vq_quantmap__44u5__p3_0,
  134371. 5,
  134372. 5
  134373. };
  134374. static static_codebook _44u5__p3_0 = {
  134375. 4, 625,
  134376. _vq_lengthlist__44u5__p3_0,
  134377. 1, -533725184, 1611661312, 3, 0,
  134378. _vq_quantlist__44u5__p3_0,
  134379. NULL,
  134380. &_vq_auxt__44u5__p3_0,
  134381. NULL,
  134382. 0
  134383. };
  134384. static long _vq_quantlist__44u5__p4_0[] = {
  134385. 2,
  134386. 1,
  134387. 3,
  134388. 0,
  134389. 4,
  134390. };
  134391. static long _vq_lengthlist__44u5__p4_0[] = {
  134392. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134393. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134394. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134395. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134396. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134397. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134398. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134399. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134400. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134401. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134402. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134403. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134404. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134405. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134406. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134407. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134408. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134409. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134410. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134411. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134412. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134413. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134414. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134415. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134416. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134417. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134418. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134419. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134420. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134421. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134422. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134423. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134424. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134425. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134426. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134427. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134428. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134429. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134430. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134431. 12,
  134432. };
  134433. static float _vq_quantthresh__44u5__p4_0[] = {
  134434. -1.5, -0.5, 0.5, 1.5,
  134435. };
  134436. static long _vq_quantmap__44u5__p4_0[] = {
  134437. 3, 1, 0, 2, 4,
  134438. };
  134439. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134440. _vq_quantthresh__44u5__p4_0,
  134441. _vq_quantmap__44u5__p4_0,
  134442. 5,
  134443. 5
  134444. };
  134445. static static_codebook _44u5__p4_0 = {
  134446. 4, 625,
  134447. _vq_lengthlist__44u5__p4_0,
  134448. 1, -533725184, 1611661312, 3, 0,
  134449. _vq_quantlist__44u5__p4_0,
  134450. NULL,
  134451. &_vq_auxt__44u5__p4_0,
  134452. NULL,
  134453. 0
  134454. };
  134455. static long _vq_quantlist__44u5__p5_0[] = {
  134456. 4,
  134457. 3,
  134458. 5,
  134459. 2,
  134460. 6,
  134461. 1,
  134462. 7,
  134463. 0,
  134464. 8,
  134465. };
  134466. static long _vq_lengthlist__44u5__p5_0[] = {
  134467. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134468. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134469. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134470. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134471. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134472. 14,
  134473. };
  134474. static float _vq_quantthresh__44u5__p5_0[] = {
  134475. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134476. };
  134477. static long _vq_quantmap__44u5__p5_0[] = {
  134478. 7, 5, 3, 1, 0, 2, 4, 6,
  134479. 8,
  134480. };
  134481. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134482. _vq_quantthresh__44u5__p5_0,
  134483. _vq_quantmap__44u5__p5_0,
  134484. 9,
  134485. 9
  134486. };
  134487. static static_codebook _44u5__p5_0 = {
  134488. 2, 81,
  134489. _vq_lengthlist__44u5__p5_0,
  134490. 1, -531628032, 1611661312, 4, 0,
  134491. _vq_quantlist__44u5__p5_0,
  134492. NULL,
  134493. &_vq_auxt__44u5__p5_0,
  134494. NULL,
  134495. 0
  134496. };
  134497. static long _vq_quantlist__44u5__p6_0[] = {
  134498. 4,
  134499. 3,
  134500. 5,
  134501. 2,
  134502. 6,
  134503. 1,
  134504. 7,
  134505. 0,
  134506. 8,
  134507. };
  134508. static long _vq_lengthlist__44u5__p6_0[] = {
  134509. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134510. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134511. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134512. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134513. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134514. 11,
  134515. };
  134516. static float _vq_quantthresh__44u5__p6_0[] = {
  134517. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134518. };
  134519. static long _vq_quantmap__44u5__p6_0[] = {
  134520. 7, 5, 3, 1, 0, 2, 4, 6,
  134521. 8,
  134522. };
  134523. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134524. _vq_quantthresh__44u5__p6_0,
  134525. _vq_quantmap__44u5__p6_0,
  134526. 9,
  134527. 9
  134528. };
  134529. static static_codebook _44u5__p6_0 = {
  134530. 2, 81,
  134531. _vq_lengthlist__44u5__p6_0,
  134532. 1, -531628032, 1611661312, 4, 0,
  134533. _vq_quantlist__44u5__p6_0,
  134534. NULL,
  134535. &_vq_auxt__44u5__p6_0,
  134536. NULL,
  134537. 0
  134538. };
  134539. static long _vq_quantlist__44u5__p7_0[] = {
  134540. 1,
  134541. 0,
  134542. 2,
  134543. };
  134544. static long _vq_lengthlist__44u5__p7_0[] = {
  134545. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134546. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134547. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134548. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134549. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134550. 12,
  134551. };
  134552. static float _vq_quantthresh__44u5__p7_0[] = {
  134553. -5.5, 5.5,
  134554. };
  134555. static long _vq_quantmap__44u5__p7_0[] = {
  134556. 1, 0, 2,
  134557. };
  134558. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134559. _vq_quantthresh__44u5__p7_0,
  134560. _vq_quantmap__44u5__p7_0,
  134561. 3,
  134562. 3
  134563. };
  134564. static static_codebook _44u5__p7_0 = {
  134565. 4, 81,
  134566. _vq_lengthlist__44u5__p7_0,
  134567. 1, -529137664, 1618345984, 2, 0,
  134568. _vq_quantlist__44u5__p7_0,
  134569. NULL,
  134570. &_vq_auxt__44u5__p7_0,
  134571. NULL,
  134572. 0
  134573. };
  134574. static long _vq_quantlist__44u5__p7_1[] = {
  134575. 5,
  134576. 4,
  134577. 6,
  134578. 3,
  134579. 7,
  134580. 2,
  134581. 8,
  134582. 1,
  134583. 9,
  134584. 0,
  134585. 10,
  134586. };
  134587. static long _vq_lengthlist__44u5__p7_1[] = {
  134588. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134589. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134590. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134591. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134592. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134593. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134594. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134595. 9, 9, 9, 9, 9,10,10,10,10,
  134596. };
  134597. static float _vq_quantthresh__44u5__p7_1[] = {
  134598. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134599. 3.5, 4.5,
  134600. };
  134601. static long _vq_quantmap__44u5__p7_1[] = {
  134602. 9, 7, 5, 3, 1, 0, 2, 4,
  134603. 6, 8, 10,
  134604. };
  134605. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134606. _vq_quantthresh__44u5__p7_1,
  134607. _vq_quantmap__44u5__p7_1,
  134608. 11,
  134609. 11
  134610. };
  134611. static static_codebook _44u5__p7_1 = {
  134612. 2, 121,
  134613. _vq_lengthlist__44u5__p7_1,
  134614. 1, -531365888, 1611661312, 4, 0,
  134615. _vq_quantlist__44u5__p7_1,
  134616. NULL,
  134617. &_vq_auxt__44u5__p7_1,
  134618. NULL,
  134619. 0
  134620. };
  134621. static long _vq_quantlist__44u5__p8_0[] = {
  134622. 5,
  134623. 4,
  134624. 6,
  134625. 3,
  134626. 7,
  134627. 2,
  134628. 8,
  134629. 1,
  134630. 9,
  134631. 0,
  134632. 10,
  134633. };
  134634. static long _vq_lengthlist__44u5__p8_0[] = {
  134635. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134636. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134637. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134638. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134639. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134640. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134641. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134642. 12,13,13,14,14,14,14,15,15,
  134643. };
  134644. static float _vq_quantthresh__44u5__p8_0[] = {
  134645. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134646. 38.5, 49.5,
  134647. };
  134648. static long _vq_quantmap__44u5__p8_0[] = {
  134649. 9, 7, 5, 3, 1, 0, 2, 4,
  134650. 6, 8, 10,
  134651. };
  134652. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134653. _vq_quantthresh__44u5__p8_0,
  134654. _vq_quantmap__44u5__p8_0,
  134655. 11,
  134656. 11
  134657. };
  134658. static static_codebook _44u5__p8_0 = {
  134659. 2, 121,
  134660. _vq_lengthlist__44u5__p8_0,
  134661. 1, -524582912, 1618345984, 4, 0,
  134662. _vq_quantlist__44u5__p8_0,
  134663. NULL,
  134664. &_vq_auxt__44u5__p8_0,
  134665. NULL,
  134666. 0
  134667. };
  134668. static long _vq_quantlist__44u5__p8_1[] = {
  134669. 5,
  134670. 4,
  134671. 6,
  134672. 3,
  134673. 7,
  134674. 2,
  134675. 8,
  134676. 1,
  134677. 9,
  134678. 0,
  134679. 10,
  134680. };
  134681. static long _vq_lengthlist__44u5__p8_1[] = {
  134682. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134683. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134684. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134685. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134686. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134687. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134688. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134689. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134690. };
  134691. static float _vq_quantthresh__44u5__p8_1[] = {
  134692. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134693. 3.5, 4.5,
  134694. };
  134695. static long _vq_quantmap__44u5__p8_1[] = {
  134696. 9, 7, 5, 3, 1, 0, 2, 4,
  134697. 6, 8, 10,
  134698. };
  134699. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134700. _vq_quantthresh__44u5__p8_1,
  134701. _vq_quantmap__44u5__p8_1,
  134702. 11,
  134703. 11
  134704. };
  134705. static static_codebook _44u5__p8_1 = {
  134706. 2, 121,
  134707. _vq_lengthlist__44u5__p8_1,
  134708. 1, -531365888, 1611661312, 4, 0,
  134709. _vq_quantlist__44u5__p8_1,
  134710. NULL,
  134711. &_vq_auxt__44u5__p8_1,
  134712. NULL,
  134713. 0
  134714. };
  134715. static long _vq_quantlist__44u5__p9_0[] = {
  134716. 6,
  134717. 5,
  134718. 7,
  134719. 4,
  134720. 8,
  134721. 3,
  134722. 9,
  134723. 2,
  134724. 10,
  134725. 1,
  134726. 11,
  134727. 0,
  134728. 12,
  134729. };
  134730. static long _vq_lengthlist__44u5__p9_0[] = {
  134731. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134732. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134733. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134734. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134735. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134736. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134737. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134738. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134739. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134740. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134741. 12,12,12,12,12,12,12,12,12,
  134742. };
  134743. static float _vq_quantthresh__44u5__p9_0[] = {
  134744. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134745. 637.5, 892.5, 1147.5, 1402.5,
  134746. };
  134747. static long _vq_quantmap__44u5__p9_0[] = {
  134748. 11, 9, 7, 5, 3, 1, 0, 2,
  134749. 4, 6, 8, 10, 12,
  134750. };
  134751. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134752. _vq_quantthresh__44u5__p9_0,
  134753. _vq_quantmap__44u5__p9_0,
  134754. 13,
  134755. 13
  134756. };
  134757. static static_codebook _44u5__p9_0 = {
  134758. 2, 169,
  134759. _vq_lengthlist__44u5__p9_0,
  134760. 1, -514332672, 1627381760, 4, 0,
  134761. _vq_quantlist__44u5__p9_0,
  134762. NULL,
  134763. &_vq_auxt__44u5__p9_0,
  134764. NULL,
  134765. 0
  134766. };
  134767. static long _vq_quantlist__44u5__p9_1[] = {
  134768. 7,
  134769. 6,
  134770. 8,
  134771. 5,
  134772. 9,
  134773. 4,
  134774. 10,
  134775. 3,
  134776. 11,
  134777. 2,
  134778. 12,
  134779. 1,
  134780. 13,
  134781. 0,
  134782. 14,
  134783. };
  134784. static long _vq_lengthlist__44u5__p9_1[] = {
  134785. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134786. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134787. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134788. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134789. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134790. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134791. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134792. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134793. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134794. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134795. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134796. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134797. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134798. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134799. 14,
  134800. };
  134801. static float _vq_quantthresh__44u5__p9_1[] = {
  134802. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134803. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134804. };
  134805. static long _vq_quantmap__44u5__p9_1[] = {
  134806. 13, 11, 9, 7, 5, 3, 1, 0,
  134807. 2, 4, 6, 8, 10, 12, 14,
  134808. };
  134809. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134810. _vq_quantthresh__44u5__p9_1,
  134811. _vq_quantmap__44u5__p9_1,
  134812. 15,
  134813. 15
  134814. };
  134815. static static_codebook _44u5__p9_1 = {
  134816. 2, 225,
  134817. _vq_lengthlist__44u5__p9_1,
  134818. 1, -522338304, 1620115456, 4, 0,
  134819. _vq_quantlist__44u5__p9_1,
  134820. NULL,
  134821. &_vq_auxt__44u5__p9_1,
  134822. NULL,
  134823. 0
  134824. };
  134825. static long _vq_quantlist__44u5__p9_2[] = {
  134826. 8,
  134827. 7,
  134828. 9,
  134829. 6,
  134830. 10,
  134831. 5,
  134832. 11,
  134833. 4,
  134834. 12,
  134835. 3,
  134836. 13,
  134837. 2,
  134838. 14,
  134839. 1,
  134840. 15,
  134841. 0,
  134842. 16,
  134843. };
  134844. static long _vq_lengthlist__44u5__p9_2[] = {
  134845. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134846. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134847. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134848. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134849. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134850. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134851. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134852. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134853. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134854. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134855. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134856. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134857. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134858. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134859. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134860. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134861. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134862. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134863. 10,
  134864. };
  134865. static float _vq_quantthresh__44u5__p9_2[] = {
  134866. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134867. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134868. };
  134869. static long _vq_quantmap__44u5__p9_2[] = {
  134870. 15, 13, 11, 9, 7, 5, 3, 1,
  134871. 0, 2, 4, 6, 8, 10, 12, 14,
  134872. 16,
  134873. };
  134874. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134875. _vq_quantthresh__44u5__p9_2,
  134876. _vq_quantmap__44u5__p9_2,
  134877. 17,
  134878. 17
  134879. };
  134880. static static_codebook _44u5__p9_2 = {
  134881. 2, 289,
  134882. _vq_lengthlist__44u5__p9_2,
  134883. 1, -529530880, 1611661312, 5, 0,
  134884. _vq_quantlist__44u5__p9_2,
  134885. NULL,
  134886. &_vq_auxt__44u5__p9_2,
  134887. NULL,
  134888. 0
  134889. };
  134890. static long _huff_lengthlist__44u5__short[] = {
  134891. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134892. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134893. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134894. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134895. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134896. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134897. 6, 8,15,17,
  134898. };
  134899. static static_codebook _huff_book__44u5__short = {
  134900. 2, 100,
  134901. _huff_lengthlist__44u5__short,
  134902. 0, 0, 0, 0, 0,
  134903. NULL,
  134904. NULL,
  134905. NULL,
  134906. NULL,
  134907. 0
  134908. };
  134909. static long _huff_lengthlist__44u6__long[] = {
  134910. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  134911. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  134912. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  134913. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  134914. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  134915. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  134916. 13, 8, 7, 7,
  134917. };
  134918. static static_codebook _huff_book__44u6__long = {
  134919. 2, 100,
  134920. _huff_lengthlist__44u6__long,
  134921. 0, 0, 0, 0, 0,
  134922. NULL,
  134923. NULL,
  134924. NULL,
  134925. NULL,
  134926. 0
  134927. };
  134928. static long _vq_quantlist__44u6__p1_0[] = {
  134929. 1,
  134930. 0,
  134931. 2,
  134932. };
  134933. static long _vq_lengthlist__44u6__p1_0[] = {
  134934. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134935. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134936. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134937. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  134938. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134939. 12,
  134940. };
  134941. static float _vq_quantthresh__44u6__p1_0[] = {
  134942. -0.5, 0.5,
  134943. };
  134944. static long _vq_quantmap__44u6__p1_0[] = {
  134945. 1, 0, 2,
  134946. };
  134947. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  134948. _vq_quantthresh__44u6__p1_0,
  134949. _vq_quantmap__44u6__p1_0,
  134950. 3,
  134951. 3
  134952. };
  134953. static static_codebook _44u6__p1_0 = {
  134954. 4, 81,
  134955. _vq_lengthlist__44u6__p1_0,
  134956. 1, -535822336, 1611661312, 2, 0,
  134957. _vq_quantlist__44u6__p1_0,
  134958. NULL,
  134959. &_vq_auxt__44u6__p1_0,
  134960. NULL,
  134961. 0
  134962. };
  134963. static long _vq_quantlist__44u6__p2_0[] = {
  134964. 1,
  134965. 0,
  134966. 2,
  134967. };
  134968. static long _vq_lengthlist__44u6__p2_0[] = {
  134969. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134970. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134971. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  134972. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134973. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134974. 9,
  134975. };
  134976. static float _vq_quantthresh__44u6__p2_0[] = {
  134977. -0.5, 0.5,
  134978. };
  134979. static long _vq_quantmap__44u6__p2_0[] = {
  134980. 1, 0, 2,
  134981. };
  134982. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  134983. _vq_quantthresh__44u6__p2_0,
  134984. _vq_quantmap__44u6__p2_0,
  134985. 3,
  134986. 3
  134987. };
  134988. static static_codebook _44u6__p2_0 = {
  134989. 4, 81,
  134990. _vq_lengthlist__44u6__p2_0,
  134991. 1, -535822336, 1611661312, 2, 0,
  134992. _vq_quantlist__44u6__p2_0,
  134993. NULL,
  134994. &_vq_auxt__44u6__p2_0,
  134995. NULL,
  134996. 0
  134997. };
  134998. static long _vq_quantlist__44u6__p3_0[] = {
  134999. 2,
  135000. 1,
  135001. 3,
  135002. 0,
  135003. 4,
  135004. };
  135005. static long _vq_lengthlist__44u6__p3_0[] = {
  135006. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135007. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135008. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135009. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135010. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135011. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135012. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135013. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135014. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135015. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135016. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135017. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135018. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135019. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135020. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135021. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135022. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135023. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135024. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135025. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135026. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135027. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135028. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135029. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135030. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135031. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135032. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135033. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135034. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135035. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135036. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135037. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135038. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135039. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135040. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135041. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135042. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135043. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135044. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135045. 19,
  135046. };
  135047. static float _vq_quantthresh__44u6__p3_0[] = {
  135048. -1.5, -0.5, 0.5, 1.5,
  135049. };
  135050. static long _vq_quantmap__44u6__p3_0[] = {
  135051. 3, 1, 0, 2, 4,
  135052. };
  135053. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135054. _vq_quantthresh__44u6__p3_0,
  135055. _vq_quantmap__44u6__p3_0,
  135056. 5,
  135057. 5
  135058. };
  135059. static static_codebook _44u6__p3_0 = {
  135060. 4, 625,
  135061. _vq_lengthlist__44u6__p3_0,
  135062. 1, -533725184, 1611661312, 3, 0,
  135063. _vq_quantlist__44u6__p3_0,
  135064. NULL,
  135065. &_vq_auxt__44u6__p3_0,
  135066. NULL,
  135067. 0
  135068. };
  135069. static long _vq_quantlist__44u6__p4_0[] = {
  135070. 2,
  135071. 1,
  135072. 3,
  135073. 0,
  135074. 4,
  135075. };
  135076. static long _vq_lengthlist__44u6__p4_0[] = {
  135077. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135078. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135079. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135080. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135081. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135082. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135083. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135084. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135085. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135086. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135087. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135088. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135089. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135090. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135091. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135092. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135093. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135094. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135095. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135096. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135097. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135098. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135099. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135100. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135101. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135102. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135103. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135104. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135105. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135106. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135107. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135108. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135109. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135110. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135111. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135112. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135113. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135114. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135115. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135116. 13,
  135117. };
  135118. static float _vq_quantthresh__44u6__p4_0[] = {
  135119. -1.5, -0.5, 0.5, 1.5,
  135120. };
  135121. static long _vq_quantmap__44u6__p4_0[] = {
  135122. 3, 1, 0, 2, 4,
  135123. };
  135124. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135125. _vq_quantthresh__44u6__p4_0,
  135126. _vq_quantmap__44u6__p4_0,
  135127. 5,
  135128. 5
  135129. };
  135130. static static_codebook _44u6__p4_0 = {
  135131. 4, 625,
  135132. _vq_lengthlist__44u6__p4_0,
  135133. 1, -533725184, 1611661312, 3, 0,
  135134. _vq_quantlist__44u6__p4_0,
  135135. NULL,
  135136. &_vq_auxt__44u6__p4_0,
  135137. NULL,
  135138. 0
  135139. };
  135140. static long _vq_quantlist__44u6__p5_0[] = {
  135141. 4,
  135142. 3,
  135143. 5,
  135144. 2,
  135145. 6,
  135146. 1,
  135147. 7,
  135148. 0,
  135149. 8,
  135150. };
  135151. static long _vq_lengthlist__44u6__p5_0[] = {
  135152. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135153. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135154. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135155. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135156. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135157. 14,
  135158. };
  135159. static float _vq_quantthresh__44u6__p5_0[] = {
  135160. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135161. };
  135162. static long _vq_quantmap__44u6__p5_0[] = {
  135163. 7, 5, 3, 1, 0, 2, 4, 6,
  135164. 8,
  135165. };
  135166. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135167. _vq_quantthresh__44u6__p5_0,
  135168. _vq_quantmap__44u6__p5_0,
  135169. 9,
  135170. 9
  135171. };
  135172. static static_codebook _44u6__p5_0 = {
  135173. 2, 81,
  135174. _vq_lengthlist__44u6__p5_0,
  135175. 1, -531628032, 1611661312, 4, 0,
  135176. _vq_quantlist__44u6__p5_0,
  135177. NULL,
  135178. &_vq_auxt__44u6__p5_0,
  135179. NULL,
  135180. 0
  135181. };
  135182. static long _vq_quantlist__44u6__p6_0[] = {
  135183. 4,
  135184. 3,
  135185. 5,
  135186. 2,
  135187. 6,
  135188. 1,
  135189. 7,
  135190. 0,
  135191. 8,
  135192. };
  135193. static long _vq_lengthlist__44u6__p6_0[] = {
  135194. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135195. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135196. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135197. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135198. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135199. 12,
  135200. };
  135201. static float _vq_quantthresh__44u6__p6_0[] = {
  135202. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135203. };
  135204. static long _vq_quantmap__44u6__p6_0[] = {
  135205. 7, 5, 3, 1, 0, 2, 4, 6,
  135206. 8,
  135207. };
  135208. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135209. _vq_quantthresh__44u6__p6_0,
  135210. _vq_quantmap__44u6__p6_0,
  135211. 9,
  135212. 9
  135213. };
  135214. static static_codebook _44u6__p6_0 = {
  135215. 2, 81,
  135216. _vq_lengthlist__44u6__p6_0,
  135217. 1, -531628032, 1611661312, 4, 0,
  135218. _vq_quantlist__44u6__p6_0,
  135219. NULL,
  135220. &_vq_auxt__44u6__p6_0,
  135221. NULL,
  135222. 0
  135223. };
  135224. static long _vq_quantlist__44u6__p7_0[] = {
  135225. 1,
  135226. 0,
  135227. 2,
  135228. };
  135229. static long _vq_lengthlist__44u6__p7_0[] = {
  135230. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135231. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135232. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135233. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135234. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135235. 10,
  135236. };
  135237. static float _vq_quantthresh__44u6__p7_0[] = {
  135238. -5.5, 5.5,
  135239. };
  135240. static long _vq_quantmap__44u6__p7_0[] = {
  135241. 1, 0, 2,
  135242. };
  135243. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135244. _vq_quantthresh__44u6__p7_0,
  135245. _vq_quantmap__44u6__p7_0,
  135246. 3,
  135247. 3
  135248. };
  135249. static static_codebook _44u6__p7_0 = {
  135250. 4, 81,
  135251. _vq_lengthlist__44u6__p7_0,
  135252. 1, -529137664, 1618345984, 2, 0,
  135253. _vq_quantlist__44u6__p7_0,
  135254. NULL,
  135255. &_vq_auxt__44u6__p7_0,
  135256. NULL,
  135257. 0
  135258. };
  135259. static long _vq_quantlist__44u6__p7_1[] = {
  135260. 5,
  135261. 4,
  135262. 6,
  135263. 3,
  135264. 7,
  135265. 2,
  135266. 8,
  135267. 1,
  135268. 9,
  135269. 0,
  135270. 10,
  135271. };
  135272. static long _vq_lengthlist__44u6__p7_1[] = {
  135273. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135274. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135275. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135276. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135277. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135278. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135279. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135280. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135281. };
  135282. static float _vq_quantthresh__44u6__p7_1[] = {
  135283. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135284. 3.5, 4.5,
  135285. };
  135286. static long _vq_quantmap__44u6__p7_1[] = {
  135287. 9, 7, 5, 3, 1, 0, 2, 4,
  135288. 6, 8, 10,
  135289. };
  135290. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135291. _vq_quantthresh__44u6__p7_1,
  135292. _vq_quantmap__44u6__p7_1,
  135293. 11,
  135294. 11
  135295. };
  135296. static static_codebook _44u6__p7_1 = {
  135297. 2, 121,
  135298. _vq_lengthlist__44u6__p7_1,
  135299. 1, -531365888, 1611661312, 4, 0,
  135300. _vq_quantlist__44u6__p7_1,
  135301. NULL,
  135302. &_vq_auxt__44u6__p7_1,
  135303. NULL,
  135304. 0
  135305. };
  135306. static long _vq_quantlist__44u6__p8_0[] = {
  135307. 5,
  135308. 4,
  135309. 6,
  135310. 3,
  135311. 7,
  135312. 2,
  135313. 8,
  135314. 1,
  135315. 9,
  135316. 0,
  135317. 10,
  135318. };
  135319. static long _vq_lengthlist__44u6__p8_0[] = {
  135320. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135321. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135322. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135323. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135324. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135325. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135326. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135327. 12,13,13,14,14,14,15,15,15,
  135328. };
  135329. static float _vq_quantthresh__44u6__p8_0[] = {
  135330. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135331. 38.5, 49.5,
  135332. };
  135333. static long _vq_quantmap__44u6__p8_0[] = {
  135334. 9, 7, 5, 3, 1, 0, 2, 4,
  135335. 6, 8, 10,
  135336. };
  135337. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135338. _vq_quantthresh__44u6__p8_0,
  135339. _vq_quantmap__44u6__p8_0,
  135340. 11,
  135341. 11
  135342. };
  135343. static static_codebook _44u6__p8_0 = {
  135344. 2, 121,
  135345. _vq_lengthlist__44u6__p8_0,
  135346. 1, -524582912, 1618345984, 4, 0,
  135347. _vq_quantlist__44u6__p8_0,
  135348. NULL,
  135349. &_vq_auxt__44u6__p8_0,
  135350. NULL,
  135351. 0
  135352. };
  135353. static long _vq_quantlist__44u6__p8_1[] = {
  135354. 5,
  135355. 4,
  135356. 6,
  135357. 3,
  135358. 7,
  135359. 2,
  135360. 8,
  135361. 1,
  135362. 9,
  135363. 0,
  135364. 10,
  135365. };
  135366. static long _vq_lengthlist__44u6__p8_1[] = {
  135367. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135368. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135369. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135370. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135371. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135372. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135373. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135374. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135375. };
  135376. static float _vq_quantthresh__44u6__p8_1[] = {
  135377. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135378. 3.5, 4.5,
  135379. };
  135380. static long _vq_quantmap__44u6__p8_1[] = {
  135381. 9, 7, 5, 3, 1, 0, 2, 4,
  135382. 6, 8, 10,
  135383. };
  135384. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135385. _vq_quantthresh__44u6__p8_1,
  135386. _vq_quantmap__44u6__p8_1,
  135387. 11,
  135388. 11
  135389. };
  135390. static static_codebook _44u6__p8_1 = {
  135391. 2, 121,
  135392. _vq_lengthlist__44u6__p8_1,
  135393. 1, -531365888, 1611661312, 4, 0,
  135394. _vq_quantlist__44u6__p8_1,
  135395. NULL,
  135396. &_vq_auxt__44u6__p8_1,
  135397. NULL,
  135398. 0
  135399. };
  135400. static long _vq_quantlist__44u6__p9_0[] = {
  135401. 7,
  135402. 6,
  135403. 8,
  135404. 5,
  135405. 9,
  135406. 4,
  135407. 10,
  135408. 3,
  135409. 11,
  135410. 2,
  135411. 12,
  135412. 1,
  135413. 13,
  135414. 0,
  135415. 14,
  135416. };
  135417. static long _vq_lengthlist__44u6__p9_0[] = {
  135418. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135419. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135420. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135421. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135422. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135423. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135424. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135425. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135426. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135427. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135428. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135429. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135430. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135431. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135432. 14,
  135433. };
  135434. static float _vq_quantthresh__44u6__p9_0[] = {
  135435. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135436. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135437. };
  135438. static long _vq_quantmap__44u6__p9_0[] = {
  135439. 13, 11, 9, 7, 5, 3, 1, 0,
  135440. 2, 4, 6, 8, 10, 12, 14,
  135441. };
  135442. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135443. _vq_quantthresh__44u6__p9_0,
  135444. _vq_quantmap__44u6__p9_0,
  135445. 15,
  135446. 15
  135447. };
  135448. static static_codebook _44u6__p9_0 = {
  135449. 2, 225,
  135450. _vq_lengthlist__44u6__p9_0,
  135451. 1, -514071552, 1627381760, 4, 0,
  135452. _vq_quantlist__44u6__p9_0,
  135453. NULL,
  135454. &_vq_auxt__44u6__p9_0,
  135455. NULL,
  135456. 0
  135457. };
  135458. static long _vq_quantlist__44u6__p9_1[] = {
  135459. 7,
  135460. 6,
  135461. 8,
  135462. 5,
  135463. 9,
  135464. 4,
  135465. 10,
  135466. 3,
  135467. 11,
  135468. 2,
  135469. 12,
  135470. 1,
  135471. 13,
  135472. 0,
  135473. 14,
  135474. };
  135475. static long _vq_lengthlist__44u6__p9_1[] = {
  135476. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135477. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135478. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135479. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135480. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135481. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135482. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135483. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135484. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135485. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135486. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135487. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135488. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135489. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135490. 13,
  135491. };
  135492. static float _vq_quantthresh__44u6__p9_1[] = {
  135493. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135494. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135495. };
  135496. static long _vq_quantmap__44u6__p9_1[] = {
  135497. 13, 11, 9, 7, 5, 3, 1, 0,
  135498. 2, 4, 6, 8, 10, 12, 14,
  135499. };
  135500. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135501. _vq_quantthresh__44u6__p9_1,
  135502. _vq_quantmap__44u6__p9_1,
  135503. 15,
  135504. 15
  135505. };
  135506. static static_codebook _44u6__p9_1 = {
  135507. 2, 225,
  135508. _vq_lengthlist__44u6__p9_1,
  135509. 1, -522338304, 1620115456, 4, 0,
  135510. _vq_quantlist__44u6__p9_1,
  135511. NULL,
  135512. &_vq_auxt__44u6__p9_1,
  135513. NULL,
  135514. 0
  135515. };
  135516. static long _vq_quantlist__44u6__p9_2[] = {
  135517. 8,
  135518. 7,
  135519. 9,
  135520. 6,
  135521. 10,
  135522. 5,
  135523. 11,
  135524. 4,
  135525. 12,
  135526. 3,
  135527. 13,
  135528. 2,
  135529. 14,
  135530. 1,
  135531. 15,
  135532. 0,
  135533. 16,
  135534. };
  135535. static long _vq_lengthlist__44u6__p9_2[] = {
  135536. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135537. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135538. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135539. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135540. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135541. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135542. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135543. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135544. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135545. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135546. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135547. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135548. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135549. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135550. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135551. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135552. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135553. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135554. 10,
  135555. };
  135556. static float _vq_quantthresh__44u6__p9_2[] = {
  135557. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135558. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135559. };
  135560. static long _vq_quantmap__44u6__p9_2[] = {
  135561. 15, 13, 11, 9, 7, 5, 3, 1,
  135562. 0, 2, 4, 6, 8, 10, 12, 14,
  135563. 16,
  135564. };
  135565. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135566. _vq_quantthresh__44u6__p9_2,
  135567. _vq_quantmap__44u6__p9_2,
  135568. 17,
  135569. 17
  135570. };
  135571. static static_codebook _44u6__p9_2 = {
  135572. 2, 289,
  135573. _vq_lengthlist__44u6__p9_2,
  135574. 1, -529530880, 1611661312, 5, 0,
  135575. _vq_quantlist__44u6__p9_2,
  135576. NULL,
  135577. &_vq_auxt__44u6__p9_2,
  135578. NULL,
  135579. 0
  135580. };
  135581. static long _huff_lengthlist__44u6__short[] = {
  135582. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135583. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135584. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135585. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135586. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135587. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135588. 7, 6, 9,16,
  135589. };
  135590. static static_codebook _huff_book__44u6__short = {
  135591. 2, 100,
  135592. _huff_lengthlist__44u6__short,
  135593. 0, 0, 0, 0, 0,
  135594. NULL,
  135595. NULL,
  135596. NULL,
  135597. NULL,
  135598. 0
  135599. };
  135600. static long _huff_lengthlist__44u7__long[] = {
  135601. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135602. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135603. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135604. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135605. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135606. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135607. 12, 8, 6, 7,
  135608. };
  135609. static static_codebook _huff_book__44u7__long = {
  135610. 2, 100,
  135611. _huff_lengthlist__44u7__long,
  135612. 0, 0, 0, 0, 0,
  135613. NULL,
  135614. NULL,
  135615. NULL,
  135616. NULL,
  135617. 0
  135618. };
  135619. static long _vq_quantlist__44u7__p1_0[] = {
  135620. 1,
  135621. 0,
  135622. 2,
  135623. };
  135624. static long _vq_lengthlist__44u7__p1_0[] = {
  135625. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135626. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135627. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135628. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135629. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135630. 12,
  135631. };
  135632. static float _vq_quantthresh__44u7__p1_0[] = {
  135633. -0.5, 0.5,
  135634. };
  135635. static long _vq_quantmap__44u7__p1_0[] = {
  135636. 1, 0, 2,
  135637. };
  135638. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135639. _vq_quantthresh__44u7__p1_0,
  135640. _vq_quantmap__44u7__p1_0,
  135641. 3,
  135642. 3
  135643. };
  135644. static static_codebook _44u7__p1_0 = {
  135645. 4, 81,
  135646. _vq_lengthlist__44u7__p1_0,
  135647. 1, -535822336, 1611661312, 2, 0,
  135648. _vq_quantlist__44u7__p1_0,
  135649. NULL,
  135650. &_vq_auxt__44u7__p1_0,
  135651. NULL,
  135652. 0
  135653. };
  135654. static long _vq_quantlist__44u7__p2_0[] = {
  135655. 1,
  135656. 0,
  135657. 2,
  135658. };
  135659. static long _vq_lengthlist__44u7__p2_0[] = {
  135660. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135661. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135662. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135663. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135664. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135665. 9,
  135666. };
  135667. static float _vq_quantthresh__44u7__p2_0[] = {
  135668. -0.5, 0.5,
  135669. };
  135670. static long _vq_quantmap__44u7__p2_0[] = {
  135671. 1, 0, 2,
  135672. };
  135673. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135674. _vq_quantthresh__44u7__p2_0,
  135675. _vq_quantmap__44u7__p2_0,
  135676. 3,
  135677. 3
  135678. };
  135679. static static_codebook _44u7__p2_0 = {
  135680. 4, 81,
  135681. _vq_lengthlist__44u7__p2_0,
  135682. 1, -535822336, 1611661312, 2, 0,
  135683. _vq_quantlist__44u7__p2_0,
  135684. NULL,
  135685. &_vq_auxt__44u7__p2_0,
  135686. NULL,
  135687. 0
  135688. };
  135689. static long _vq_quantlist__44u7__p3_0[] = {
  135690. 2,
  135691. 1,
  135692. 3,
  135693. 0,
  135694. 4,
  135695. };
  135696. static long _vq_lengthlist__44u7__p3_0[] = {
  135697. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135698. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135699. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135700. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135701. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135702. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135703. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135704. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135705. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135706. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135707. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135708. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135709. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135710. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135711. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135712. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135713. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135714. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135715. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135716. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135717. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135718. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135719. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135720. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135721. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135722. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135723. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135724. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135725. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135726. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135727. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135728. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135729. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135730. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135731. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135732. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135733. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135734. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135735. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135736. 0,
  135737. };
  135738. static float _vq_quantthresh__44u7__p3_0[] = {
  135739. -1.5, -0.5, 0.5, 1.5,
  135740. };
  135741. static long _vq_quantmap__44u7__p3_0[] = {
  135742. 3, 1, 0, 2, 4,
  135743. };
  135744. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135745. _vq_quantthresh__44u7__p3_0,
  135746. _vq_quantmap__44u7__p3_0,
  135747. 5,
  135748. 5
  135749. };
  135750. static static_codebook _44u7__p3_0 = {
  135751. 4, 625,
  135752. _vq_lengthlist__44u7__p3_0,
  135753. 1, -533725184, 1611661312, 3, 0,
  135754. _vq_quantlist__44u7__p3_0,
  135755. NULL,
  135756. &_vq_auxt__44u7__p3_0,
  135757. NULL,
  135758. 0
  135759. };
  135760. static long _vq_quantlist__44u7__p4_0[] = {
  135761. 2,
  135762. 1,
  135763. 3,
  135764. 0,
  135765. 4,
  135766. };
  135767. static long _vq_lengthlist__44u7__p4_0[] = {
  135768. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135769. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135770. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135771. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135772. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135773. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135774. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135775. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135776. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135777. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135778. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135779. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135780. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135781. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135782. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135783. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135784. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135785. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135786. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135787. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135788. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135789. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135790. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135791. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135792. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135793. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135794. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135795. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135796. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135797. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135798. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135799. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135800. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135801. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135802. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135803. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135804. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135805. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135806. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135807. 14,
  135808. };
  135809. static float _vq_quantthresh__44u7__p4_0[] = {
  135810. -1.5, -0.5, 0.5, 1.5,
  135811. };
  135812. static long _vq_quantmap__44u7__p4_0[] = {
  135813. 3, 1, 0, 2, 4,
  135814. };
  135815. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135816. _vq_quantthresh__44u7__p4_0,
  135817. _vq_quantmap__44u7__p4_0,
  135818. 5,
  135819. 5
  135820. };
  135821. static static_codebook _44u7__p4_0 = {
  135822. 4, 625,
  135823. _vq_lengthlist__44u7__p4_0,
  135824. 1, -533725184, 1611661312, 3, 0,
  135825. _vq_quantlist__44u7__p4_0,
  135826. NULL,
  135827. &_vq_auxt__44u7__p4_0,
  135828. NULL,
  135829. 0
  135830. };
  135831. static long _vq_quantlist__44u7__p5_0[] = {
  135832. 4,
  135833. 3,
  135834. 5,
  135835. 2,
  135836. 6,
  135837. 1,
  135838. 7,
  135839. 0,
  135840. 8,
  135841. };
  135842. static long _vq_lengthlist__44u7__p5_0[] = {
  135843. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135844. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135845. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135846. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135847. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135848. 14,
  135849. };
  135850. static float _vq_quantthresh__44u7__p5_0[] = {
  135851. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135852. };
  135853. static long _vq_quantmap__44u7__p5_0[] = {
  135854. 7, 5, 3, 1, 0, 2, 4, 6,
  135855. 8,
  135856. };
  135857. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135858. _vq_quantthresh__44u7__p5_0,
  135859. _vq_quantmap__44u7__p5_0,
  135860. 9,
  135861. 9
  135862. };
  135863. static static_codebook _44u7__p5_0 = {
  135864. 2, 81,
  135865. _vq_lengthlist__44u7__p5_0,
  135866. 1, -531628032, 1611661312, 4, 0,
  135867. _vq_quantlist__44u7__p5_0,
  135868. NULL,
  135869. &_vq_auxt__44u7__p5_0,
  135870. NULL,
  135871. 0
  135872. };
  135873. static long _vq_quantlist__44u7__p6_0[] = {
  135874. 4,
  135875. 3,
  135876. 5,
  135877. 2,
  135878. 6,
  135879. 1,
  135880. 7,
  135881. 0,
  135882. 8,
  135883. };
  135884. static long _vq_lengthlist__44u7__p6_0[] = {
  135885. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135886. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135887. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135888. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135889. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135890. 12,
  135891. };
  135892. static float _vq_quantthresh__44u7__p6_0[] = {
  135893. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135894. };
  135895. static long _vq_quantmap__44u7__p6_0[] = {
  135896. 7, 5, 3, 1, 0, 2, 4, 6,
  135897. 8,
  135898. };
  135899. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135900. _vq_quantthresh__44u7__p6_0,
  135901. _vq_quantmap__44u7__p6_0,
  135902. 9,
  135903. 9
  135904. };
  135905. static static_codebook _44u7__p6_0 = {
  135906. 2, 81,
  135907. _vq_lengthlist__44u7__p6_0,
  135908. 1, -531628032, 1611661312, 4, 0,
  135909. _vq_quantlist__44u7__p6_0,
  135910. NULL,
  135911. &_vq_auxt__44u7__p6_0,
  135912. NULL,
  135913. 0
  135914. };
  135915. static long _vq_quantlist__44u7__p7_0[] = {
  135916. 1,
  135917. 0,
  135918. 2,
  135919. };
  135920. static long _vq_lengthlist__44u7__p7_0[] = {
  135921. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  135922. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  135923. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  135924. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  135925. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  135926. 10,
  135927. };
  135928. static float _vq_quantthresh__44u7__p7_0[] = {
  135929. -5.5, 5.5,
  135930. };
  135931. static long _vq_quantmap__44u7__p7_0[] = {
  135932. 1, 0, 2,
  135933. };
  135934. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  135935. _vq_quantthresh__44u7__p7_0,
  135936. _vq_quantmap__44u7__p7_0,
  135937. 3,
  135938. 3
  135939. };
  135940. static static_codebook _44u7__p7_0 = {
  135941. 4, 81,
  135942. _vq_lengthlist__44u7__p7_0,
  135943. 1, -529137664, 1618345984, 2, 0,
  135944. _vq_quantlist__44u7__p7_0,
  135945. NULL,
  135946. &_vq_auxt__44u7__p7_0,
  135947. NULL,
  135948. 0
  135949. };
  135950. static long _vq_quantlist__44u7__p7_1[] = {
  135951. 5,
  135952. 4,
  135953. 6,
  135954. 3,
  135955. 7,
  135956. 2,
  135957. 8,
  135958. 1,
  135959. 9,
  135960. 0,
  135961. 10,
  135962. };
  135963. static long _vq_lengthlist__44u7__p7_1[] = {
  135964. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  135965. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  135966. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  135967. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  135968. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  135969. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135970. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  135971. 8, 9, 9, 9, 9, 9,10,10,10,
  135972. };
  135973. static float _vq_quantthresh__44u7__p7_1[] = {
  135974. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135975. 3.5, 4.5,
  135976. };
  135977. static long _vq_quantmap__44u7__p7_1[] = {
  135978. 9, 7, 5, 3, 1, 0, 2, 4,
  135979. 6, 8, 10,
  135980. };
  135981. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  135982. _vq_quantthresh__44u7__p7_1,
  135983. _vq_quantmap__44u7__p7_1,
  135984. 11,
  135985. 11
  135986. };
  135987. static static_codebook _44u7__p7_1 = {
  135988. 2, 121,
  135989. _vq_lengthlist__44u7__p7_1,
  135990. 1, -531365888, 1611661312, 4, 0,
  135991. _vq_quantlist__44u7__p7_1,
  135992. NULL,
  135993. &_vq_auxt__44u7__p7_1,
  135994. NULL,
  135995. 0
  135996. };
  135997. static long _vq_quantlist__44u7__p8_0[] = {
  135998. 5,
  135999. 4,
  136000. 6,
  136001. 3,
  136002. 7,
  136003. 2,
  136004. 8,
  136005. 1,
  136006. 9,
  136007. 0,
  136008. 10,
  136009. };
  136010. static long _vq_lengthlist__44u7__p8_0[] = {
  136011. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136012. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136013. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136014. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136015. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136016. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136017. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136018. 12,13,13,14,14,15,15,15,16,
  136019. };
  136020. static float _vq_quantthresh__44u7__p8_0[] = {
  136021. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136022. 38.5, 49.5,
  136023. };
  136024. static long _vq_quantmap__44u7__p8_0[] = {
  136025. 9, 7, 5, 3, 1, 0, 2, 4,
  136026. 6, 8, 10,
  136027. };
  136028. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136029. _vq_quantthresh__44u7__p8_0,
  136030. _vq_quantmap__44u7__p8_0,
  136031. 11,
  136032. 11
  136033. };
  136034. static static_codebook _44u7__p8_0 = {
  136035. 2, 121,
  136036. _vq_lengthlist__44u7__p8_0,
  136037. 1, -524582912, 1618345984, 4, 0,
  136038. _vq_quantlist__44u7__p8_0,
  136039. NULL,
  136040. &_vq_auxt__44u7__p8_0,
  136041. NULL,
  136042. 0
  136043. };
  136044. static long _vq_quantlist__44u7__p8_1[] = {
  136045. 5,
  136046. 4,
  136047. 6,
  136048. 3,
  136049. 7,
  136050. 2,
  136051. 8,
  136052. 1,
  136053. 9,
  136054. 0,
  136055. 10,
  136056. };
  136057. static long _vq_lengthlist__44u7__p8_1[] = {
  136058. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136059. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136060. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136061. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136062. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136063. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136064. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136065. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136066. };
  136067. static float _vq_quantthresh__44u7__p8_1[] = {
  136068. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136069. 3.5, 4.5,
  136070. };
  136071. static long _vq_quantmap__44u7__p8_1[] = {
  136072. 9, 7, 5, 3, 1, 0, 2, 4,
  136073. 6, 8, 10,
  136074. };
  136075. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136076. _vq_quantthresh__44u7__p8_1,
  136077. _vq_quantmap__44u7__p8_1,
  136078. 11,
  136079. 11
  136080. };
  136081. static static_codebook _44u7__p8_1 = {
  136082. 2, 121,
  136083. _vq_lengthlist__44u7__p8_1,
  136084. 1, -531365888, 1611661312, 4, 0,
  136085. _vq_quantlist__44u7__p8_1,
  136086. NULL,
  136087. &_vq_auxt__44u7__p8_1,
  136088. NULL,
  136089. 0
  136090. };
  136091. static long _vq_quantlist__44u7__p9_0[] = {
  136092. 5,
  136093. 4,
  136094. 6,
  136095. 3,
  136096. 7,
  136097. 2,
  136098. 8,
  136099. 1,
  136100. 9,
  136101. 0,
  136102. 10,
  136103. };
  136104. static long _vq_lengthlist__44u7__p9_0[] = {
  136105. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136106. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136107. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136108. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136109. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136110. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136111. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136112. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136113. };
  136114. static float _vq_quantthresh__44u7__p9_0[] = {
  136115. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136116. 2229.5, 2866.5,
  136117. };
  136118. static long _vq_quantmap__44u7__p9_0[] = {
  136119. 9, 7, 5, 3, 1, 0, 2, 4,
  136120. 6, 8, 10,
  136121. };
  136122. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136123. _vq_quantthresh__44u7__p9_0,
  136124. _vq_quantmap__44u7__p9_0,
  136125. 11,
  136126. 11
  136127. };
  136128. static static_codebook _44u7__p9_0 = {
  136129. 2, 121,
  136130. _vq_lengthlist__44u7__p9_0,
  136131. 1, -512171520, 1630791680, 4, 0,
  136132. _vq_quantlist__44u7__p9_0,
  136133. NULL,
  136134. &_vq_auxt__44u7__p9_0,
  136135. NULL,
  136136. 0
  136137. };
  136138. static long _vq_quantlist__44u7__p9_1[] = {
  136139. 6,
  136140. 5,
  136141. 7,
  136142. 4,
  136143. 8,
  136144. 3,
  136145. 9,
  136146. 2,
  136147. 10,
  136148. 1,
  136149. 11,
  136150. 0,
  136151. 12,
  136152. };
  136153. static long _vq_lengthlist__44u7__p9_1[] = {
  136154. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136155. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136156. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136157. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136158. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136159. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136160. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136161. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136162. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136163. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136164. 15,15,15,15,17,17,16,17,16,
  136165. };
  136166. static float _vq_quantthresh__44u7__p9_1[] = {
  136167. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136168. 122.5, 171.5, 220.5, 269.5,
  136169. };
  136170. static long _vq_quantmap__44u7__p9_1[] = {
  136171. 11, 9, 7, 5, 3, 1, 0, 2,
  136172. 4, 6, 8, 10, 12,
  136173. };
  136174. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136175. _vq_quantthresh__44u7__p9_1,
  136176. _vq_quantmap__44u7__p9_1,
  136177. 13,
  136178. 13
  136179. };
  136180. static static_codebook _44u7__p9_1 = {
  136181. 2, 169,
  136182. _vq_lengthlist__44u7__p9_1,
  136183. 1, -518889472, 1622704128, 4, 0,
  136184. _vq_quantlist__44u7__p9_1,
  136185. NULL,
  136186. &_vq_auxt__44u7__p9_1,
  136187. NULL,
  136188. 0
  136189. };
  136190. static long _vq_quantlist__44u7__p9_2[] = {
  136191. 24,
  136192. 23,
  136193. 25,
  136194. 22,
  136195. 26,
  136196. 21,
  136197. 27,
  136198. 20,
  136199. 28,
  136200. 19,
  136201. 29,
  136202. 18,
  136203. 30,
  136204. 17,
  136205. 31,
  136206. 16,
  136207. 32,
  136208. 15,
  136209. 33,
  136210. 14,
  136211. 34,
  136212. 13,
  136213. 35,
  136214. 12,
  136215. 36,
  136216. 11,
  136217. 37,
  136218. 10,
  136219. 38,
  136220. 9,
  136221. 39,
  136222. 8,
  136223. 40,
  136224. 7,
  136225. 41,
  136226. 6,
  136227. 42,
  136228. 5,
  136229. 43,
  136230. 4,
  136231. 44,
  136232. 3,
  136233. 45,
  136234. 2,
  136235. 46,
  136236. 1,
  136237. 47,
  136238. 0,
  136239. 48,
  136240. };
  136241. static long _vq_lengthlist__44u7__p9_2[] = {
  136242. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136243. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136244. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136245. 8,
  136246. };
  136247. static float _vq_quantthresh__44u7__p9_2[] = {
  136248. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136249. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136250. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136251. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136252. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136253. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136254. };
  136255. static long _vq_quantmap__44u7__p9_2[] = {
  136256. 47, 45, 43, 41, 39, 37, 35, 33,
  136257. 31, 29, 27, 25, 23, 21, 19, 17,
  136258. 15, 13, 11, 9, 7, 5, 3, 1,
  136259. 0, 2, 4, 6, 8, 10, 12, 14,
  136260. 16, 18, 20, 22, 24, 26, 28, 30,
  136261. 32, 34, 36, 38, 40, 42, 44, 46,
  136262. 48,
  136263. };
  136264. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136265. _vq_quantthresh__44u7__p9_2,
  136266. _vq_quantmap__44u7__p9_2,
  136267. 49,
  136268. 49
  136269. };
  136270. static static_codebook _44u7__p9_2 = {
  136271. 1, 49,
  136272. _vq_lengthlist__44u7__p9_2,
  136273. 1, -526909440, 1611661312, 6, 0,
  136274. _vq_quantlist__44u7__p9_2,
  136275. NULL,
  136276. &_vq_auxt__44u7__p9_2,
  136277. NULL,
  136278. 0
  136279. };
  136280. static long _huff_lengthlist__44u7__short[] = {
  136281. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136282. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136283. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136284. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136285. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136286. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136287. 6, 8, 5, 9,
  136288. };
  136289. static static_codebook _huff_book__44u7__short = {
  136290. 2, 100,
  136291. _huff_lengthlist__44u7__short,
  136292. 0, 0, 0, 0, 0,
  136293. NULL,
  136294. NULL,
  136295. NULL,
  136296. NULL,
  136297. 0
  136298. };
  136299. static long _huff_lengthlist__44u8__long[] = {
  136300. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136301. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136302. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136303. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136304. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136305. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136306. 10, 8, 8, 9,
  136307. };
  136308. static static_codebook _huff_book__44u8__long = {
  136309. 2, 100,
  136310. _huff_lengthlist__44u8__long,
  136311. 0, 0, 0, 0, 0,
  136312. NULL,
  136313. NULL,
  136314. NULL,
  136315. NULL,
  136316. 0
  136317. };
  136318. static long _huff_lengthlist__44u8__short[] = {
  136319. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136320. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136321. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136322. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136323. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136324. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136325. 10,10,15,17,
  136326. };
  136327. static static_codebook _huff_book__44u8__short = {
  136328. 2, 100,
  136329. _huff_lengthlist__44u8__short,
  136330. 0, 0, 0, 0, 0,
  136331. NULL,
  136332. NULL,
  136333. NULL,
  136334. NULL,
  136335. 0
  136336. };
  136337. static long _vq_quantlist__44u8_p1_0[] = {
  136338. 1,
  136339. 0,
  136340. 2,
  136341. };
  136342. static long _vq_lengthlist__44u8_p1_0[] = {
  136343. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136344. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136345. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136346. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136347. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136348. 10,
  136349. };
  136350. static float _vq_quantthresh__44u8_p1_0[] = {
  136351. -0.5, 0.5,
  136352. };
  136353. static long _vq_quantmap__44u8_p1_0[] = {
  136354. 1, 0, 2,
  136355. };
  136356. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136357. _vq_quantthresh__44u8_p1_0,
  136358. _vq_quantmap__44u8_p1_0,
  136359. 3,
  136360. 3
  136361. };
  136362. static static_codebook _44u8_p1_0 = {
  136363. 4, 81,
  136364. _vq_lengthlist__44u8_p1_0,
  136365. 1, -535822336, 1611661312, 2, 0,
  136366. _vq_quantlist__44u8_p1_0,
  136367. NULL,
  136368. &_vq_auxt__44u8_p1_0,
  136369. NULL,
  136370. 0
  136371. };
  136372. static long _vq_quantlist__44u8_p2_0[] = {
  136373. 2,
  136374. 1,
  136375. 3,
  136376. 0,
  136377. 4,
  136378. };
  136379. static long _vq_lengthlist__44u8_p2_0[] = {
  136380. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136381. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136382. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136383. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136384. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136385. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136386. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136387. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136388. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136389. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136390. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136391. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136392. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136393. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136394. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136395. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136396. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136397. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136398. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136399. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136400. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136401. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136402. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136403. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136404. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136405. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136406. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136407. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136408. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136409. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136410. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136411. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136412. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136413. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136414. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136415. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136416. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136417. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136418. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136419. 14,
  136420. };
  136421. static float _vq_quantthresh__44u8_p2_0[] = {
  136422. -1.5, -0.5, 0.5, 1.5,
  136423. };
  136424. static long _vq_quantmap__44u8_p2_0[] = {
  136425. 3, 1, 0, 2, 4,
  136426. };
  136427. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136428. _vq_quantthresh__44u8_p2_0,
  136429. _vq_quantmap__44u8_p2_0,
  136430. 5,
  136431. 5
  136432. };
  136433. static static_codebook _44u8_p2_0 = {
  136434. 4, 625,
  136435. _vq_lengthlist__44u8_p2_0,
  136436. 1, -533725184, 1611661312, 3, 0,
  136437. _vq_quantlist__44u8_p2_0,
  136438. NULL,
  136439. &_vq_auxt__44u8_p2_0,
  136440. NULL,
  136441. 0
  136442. };
  136443. static long _vq_quantlist__44u8_p3_0[] = {
  136444. 4,
  136445. 3,
  136446. 5,
  136447. 2,
  136448. 6,
  136449. 1,
  136450. 7,
  136451. 0,
  136452. 8,
  136453. };
  136454. static long _vq_lengthlist__44u8_p3_0[] = {
  136455. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136456. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136457. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136458. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136459. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136460. 12,
  136461. };
  136462. static float _vq_quantthresh__44u8_p3_0[] = {
  136463. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136464. };
  136465. static long _vq_quantmap__44u8_p3_0[] = {
  136466. 7, 5, 3, 1, 0, 2, 4, 6,
  136467. 8,
  136468. };
  136469. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136470. _vq_quantthresh__44u8_p3_0,
  136471. _vq_quantmap__44u8_p3_0,
  136472. 9,
  136473. 9
  136474. };
  136475. static static_codebook _44u8_p3_0 = {
  136476. 2, 81,
  136477. _vq_lengthlist__44u8_p3_0,
  136478. 1, -531628032, 1611661312, 4, 0,
  136479. _vq_quantlist__44u8_p3_0,
  136480. NULL,
  136481. &_vq_auxt__44u8_p3_0,
  136482. NULL,
  136483. 0
  136484. };
  136485. static long _vq_quantlist__44u8_p4_0[] = {
  136486. 8,
  136487. 7,
  136488. 9,
  136489. 6,
  136490. 10,
  136491. 5,
  136492. 11,
  136493. 4,
  136494. 12,
  136495. 3,
  136496. 13,
  136497. 2,
  136498. 14,
  136499. 1,
  136500. 15,
  136501. 0,
  136502. 16,
  136503. };
  136504. static long _vq_lengthlist__44u8_p4_0[] = {
  136505. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136506. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136507. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136508. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136509. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136510. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136511. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136512. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136513. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136514. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136515. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136516. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136517. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136518. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136519. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136520. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136521. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136522. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136523. 14,
  136524. };
  136525. static float _vq_quantthresh__44u8_p4_0[] = {
  136526. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136527. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136528. };
  136529. static long _vq_quantmap__44u8_p4_0[] = {
  136530. 15, 13, 11, 9, 7, 5, 3, 1,
  136531. 0, 2, 4, 6, 8, 10, 12, 14,
  136532. 16,
  136533. };
  136534. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136535. _vq_quantthresh__44u8_p4_0,
  136536. _vq_quantmap__44u8_p4_0,
  136537. 17,
  136538. 17
  136539. };
  136540. static static_codebook _44u8_p4_0 = {
  136541. 2, 289,
  136542. _vq_lengthlist__44u8_p4_0,
  136543. 1, -529530880, 1611661312, 5, 0,
  136544. _vq_quantlist__44u8_p4_0,
  136545. NULL,
  136546. &_vq_auxt__44u8_p4_0,
  136547. NULL,
  136548. 0
  136549. };
  136550. static long _vq_quantlist__44u8_p5_0[] = {
  136551. 1,
  136552. 0,
  136553. 2,
  136554. };
  136555. static long _vq_lengthlist__44u8_p5_0[] = {
  136556. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136557. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136558. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136559. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136560. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136561. 10,
  136562. };
  136563. static float _vq_quantthresh__44u8_p5_0[] = {
  136564. -5.5, 5.5,
  136565. };
  136566. static long _vq_quantmap__44u8_p5_0[] = {
  136567. 1, 0, 2,
  136568. };
  136569. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136570. _vq_quantthresh__44u8_p5_0,
  136571. _vq_quantmap__44u8_p5_0,
  136572. 3,
  136573. 3
  136574. };
  136575. static static_codebook _44u8_p5_0 = {
  136576. 4, 81,
  136577. _vq_lengthlist__44u8_p5_0,
  136578. 1, -529137664, 1618345984, 2, 0,
  136579. _vq_quantlist__44u8_p5_0,
  136580. NULL,
  136581. &_vq_auxt__44u8_p5_0,
  136582. NULL,
  136583. 0
  136584. };
  136585. static long _vq_quantlist__44u8_p5_1[] = {
  136586. 5,
  136587. 4,
  136588. 6,
  136589. 3,
  136590. 7,
  136591. 2,
  136592. 8,
  136593. 1,
  136594. 9,
  136595. 0,
  136596. 10,
  136597. };
  136598. static long _vq_lengthlist__44u8_p5_1[] = {
  136599. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136600. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136601. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136602. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136603. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136604. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136605. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136606. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136607. };
  136608. static float _vq_quantthresh__44u8_p5_1[] = {
  136609. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136610. 3.5, 4.5,
  136611. };
  136612. static long _vq_quantmap__44u8_p5_1[] = {
  136613. 9, 7, 5, 3, 1, 0, 2, 4,
  136614. 6, 8, 10,
  136615. };
  136616. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136617. _vq_quantthresh__44u8_p5_1,
  136618. _vq_quantmap__44u8_p5_1,
  136619. 11,
  136620. 11
  136621. };
  136622. static static_codebook _44u8_p5_1 = {
  136623. 2, 121,
  136624. _vq_lengthlist__44u8_p5_1,
  136625. 1, -531365888, 1611661312, 4, 0,
  136626. _vq_quantlist__44u8_p5_1,
  136627. NULL,
  136628. &_vq_auxt__44u8_p5_1,
  136629. NULL,
  136630. 0
  136631. };
  136632. static long _vq_quantlist__44u8_p6_0[] = {
  136633. 6,
  136634. 5,
  136635. 7,
  136636. 4,
  136637. 8,
  136638. 3,
  136639. 9,
  136640. 2,
  136641. 10,
  136642. 1,
  136643. 11,
  136644. 0,
  136645. 12,
  136646. };
  136647. static long _vq_lengthlist__44u8_p6_0[] = {
  136648. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136649. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136650. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136651. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136652. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136653. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136654. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136655. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136656. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136657. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136658. 11,11,11,11,11,12,11,12,12,
  136659. };
  136660. static float _vq_quantthresh__44u8_p6_0[] = {
  136661. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136662. 12.5, 17.5, 22.5, 27.5,
  136663. };
  136664. static long _vq_quantmap__44u8_p6_0[] = {
  136665. 11, 9, 7, 5, 3, 1, 0, 2,
  136666. 4, 6, 8, 10, 12,
  136667. };
  136668. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136669. _vq_quantthresh__44u8_p6_0,
  136670. _vq_quantmap__44u8_p6_0,
  136671. 13,
  136672. 13
  136673. };
  136674. static static_codebook _44u8_p6_0 = {
  136675. 2, 169,
  136676. _vq_lengthlist__44u8_p6_0,
  136677. 1, -526516224, 1616117760, 4, 0,
  136678. _vq_quantlist__44u8_p6_0,
  136679. NULL,
  136680. &_vq_auxt__44u8_p6_0,
  136681. NULL,
  136682. 0
  136683. };
  136684. static long _vq_quantlist__44u8_p6_1[] = {
  136685. 2,
  136686. 1,
  136687. 3,
  136688. 0,
  136689. 4,
  136690. };
  136691. static long _vq_lengthlist__44u8_p6_1[] = {
  136692. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136693. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136694. };
  136695. static float _vq_quantthresh__44u8_p6_1[] = {
  136696. -1.5, -0.5, 0.5, 1.5,
  136697. };
  136698. static long _vq_quantmap__44u8_p6_1[] = {
  136699. 3, 1, 0, 2, 4,
  136700. };
  136701. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136702. _vq_quantthresh__44u8_p6_1,
  136703. _vq_quantmap__44u8_p6_1,
  136704. 5,
  136705. 5
  136706. };
  136707. static static_codebook _44u8_p6_1 = {
  136708. 2, 25,
  136709. _vq_lengthlist__44u8_p6_1,
  136710. 1, -533725184, 1611661312, 3, 0,
  136711. _vq_quantlist__44u8_p6_1,
  136712. NULL,
  136713. &_vq_auxt__44u8_p6_1,
  136714. NULL,
  136715. 0
  136716. };
  136717. static long _vq_quantlist__44u8_p7_0[] = {
  136718. 6,
  136719. 5,
  136720. 7,
  136721. 4,
  136722. 8,
  136723. 3,
  136724. 9,
  136725. 2,
  136726. 10,
  136727. 1,
  136728. 11,
  136729. 0,
  136730. 12,
  136731. };
  136732. static long _vq_lengthlist__44u8_p7_0[] = {
  136733. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136734. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136735. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136736. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136737. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136738. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136739. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136740. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136741. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136742. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136743. 13,13,14,14,14,15,15,15,16,
  136744. };
  136745. static float _vq_quantthresh__44u8_p7_0[] = {
  136746. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136747. 27.5, 38.5, 49.5, 60.5,
  136748. };
  136749. static long _vq_quantmap__44u8_p7_0[] = {
  136750. 11, 9, 7, 5, 3, 1, 0, 2,
  136751. 4, 6, 8, 10, 12,
  136752. };
  136753. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136754. _vq_quantthresh__44u8_p7_0,
  136755. _vq_quantmap__44u8_p7_0,
  136756. 13,
  136757. 13
  136758. };
  136759. static static_codebook _44u8_p7_0 = {
  136760. 2, 169,
  136761. _vq_lengthlist__44u8_p7_0,
  136762. 1, -523206656, 1618345984, 4, 0,
  136763. _vq_quantlist__44u8_p7_0,
  136764. NULL,
  136765. &_vq_auxt__44u8_p7_0,
  136766. NULL,
  136767. 0
  136768. };
  136769. static long _vq_quantlist__44u8_p7_1[] = {
  136770. 5,
  136771. 4,
  136772. 6,
  136773. 3,
  136774. 7,
  136775. 2,
  136776. 8,
  136777. 1,
  136778. 9,
  136779. 0,
  136780. 10,
  136781. };
  136782. static long _vq_lengthlist__44u8_p7_1[] = {
  136783. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136784. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136785. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136786. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136787. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136788. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136789. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136790. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136791. };
  136792. static float _vq_quantthresh__44u8_p7_1[] = {
  136793. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136794. 3.5, 4.5,
  136795. };
  136796. static long _vq_quantmap__44u8_p7_1[] = {
  136797. 9, 7, 5, 3, 1, 0, 2, 4,
  136798. 6, 8, 10,
  136799. };
  136800. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136801. _vq_quantthresh__44u8_p7_1,
  136802. _vq_quantmap__44u8_p7_1,
  136803. 11,
  136804. 11
  136805. };
  136806. static static_codebook _44u8_p7_1 = {
  136807. 2, 121,
  136808. _vq_lengthlist__44u8_p7_1,
  136809. 1, -531365888, 1611661312, 4, 0,
  136810. _vq_quantlist__44u8_p7_1,
  136811. NULL,
  136812. &_vq_auxt__44u8_p7_1,
  136813. NULL,
  136814. 0
  136815. };
  136816. static long _vq_quantlist__44u8_p8_0[] = {
  136817. 7,
  136818. 6,
  136819. 8,
  136820. 5,
  136821. 9,
  136822. 4,
  136823. 10,
  136824. 3,
  136825. 11,
  136826. 2,
  136827. 12,
  136828. 1,
  136829. 13,
  136830. 0,
  136831. 14,
  136832. };
  136833. static long _vq_lengthlist__44u8_p8_0[] = {
  136834. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136835. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136836. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136837. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136838. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136839. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136840. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136841. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136842. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136843. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136844. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136845. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136846. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136847. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136848. 17,
  136849. };
  136850. static float _vq_quantthresh__44u8_p8_0[] = {
  136851. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136852. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136853. };
  136854. static long _vq_quantmap__44u8_p8_0[] = {
  136855. 13, 11, 9, 7, 5, 3, 1, 0,
  136856. 2, 4, 6, 8, 10, 12, 14,
  136857. };
  136858. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136859. _vq_quantthresh__44u8_p8_0,
  136860. _vq_quantmap__44u8_p8_0,
  136861. 15,
  136862. 15
  136863. };
  136864. static static_codebook _44u8_p8_0 = {
  136865. 2, 225,
  136866. _vq_lengthlist__44u8_p8_0,
  136867. 1, -520986624, 1620377600, 4, 0,
  136868. _vq_quantlist__44u8_p8_0,
  136869. NULL,
  136870. &_vq_auxt__44u8_p8_0,
  136871. NULL,
  136872. 0
  136873. };
  136874. static long _vq_quantlist__44u8_p8_1[] = {
  136875. 10,
  136876. 9,
  136877. 11,
  136878. 8,
  136879. 12,
  136880. 7,
  136881. 13,
  136882. 6,
  136883. 14,
  136884. 5,
  136885. 15,
  136886. 4,
  136887. 16,
  136888. 3,
  136889. 17,
  136890. 2,
  136891. 18,
  136892. 1,
  136893. 19,
  136894. 0,
  136895. 20,
  136896. };
  136897. static long _vq_lengthlist__44u8_p8_1[] = {
  136898. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136899. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136900. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136901. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136902. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136903. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136904. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136905. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  136906. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136907. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136908. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  136909. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  136910. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136911. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136912. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136913. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  136914. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  136915. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  136916. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  136917. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  136918. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136919. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136920. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136921. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  136922. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  136923. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136924. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  136925. 10,10,10,10,10,10,10,10,10,
  136926. };
  136927. static float _vq_quantthresh__44u8_p8_1[] = {
  136928. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  136929. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  136930. 6.5, 7.5, 8.5, 9.5,
  136931. };
  136932. static long _vq_quantmap__44u8_p8_1[] = {
  136933. 19, 17, 15, 13, 11, 9, 7, 5,
  136934. 3, 1, 0, 2, 4, 6, 8, 10,
  136935. 12, 14, 16, 18, 20,
  136936. };
  136937. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  136938. _vq_quantthresh__44u8_p8_1,
  136939. _vq_quantmap__44u8_p8_1,
  136940. 21,
  136941. 21
  136942. };
  136943. static static_codebook _44u8_p8_1 = {
  136944. 2, 441,
  136945. _vq_lengthlist__44u8_p8_1,
  136946. 1, -529268736, 1611661312, 5, 0,
  136947. _vq_quantlist__44u8_p8_1,
  136948. NULL,
  136949. &_vq_auxt__44u8_p8_1,
  136950. NULL,
  136951. 0
  136952. };
  136953. static long _vq_quantlist__44u8_p9_0[] = {
  136954. 4,
  136955. 3,
  136956. 5,
  136957. 2,
  136958. 6,
  136959. 1,
  136960. 7,
  136961. 0,
  136962. 8,
  136963. };
  136964. static long _vq_lengthlist__44u8_p9_0[] = {
  136965. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  136966. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136967. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136968. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136969. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136970. 8,
  136971. };
  136972. static float _vq_quantthresh__44u8_p9_0[] = {
  136973. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  136974. };
  136975. static long _vq_quantmap__44u8_p9_0[] = {
  136976. 7, 5, 3, 1, 0, 2, 4, 6,
  136977. 8,
  136978. };
  136979. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  136980. _vq_quantthresh__44u8_p9_0,
  136981. _vq_quantmap__44u8_p9_0,
  136982. 9,
  136983. 9
  136984. };
  136985. static static_codebook _44u8_p9_0 = {
  136986. 2, 81,
  136987. _vq_lengthlist__44u8_p9_0,
  136988. 1, -511895552, 1631393792, 4, 0,
  136989. _vq_quantlist__44u8_p9_0,
  136990. NULL,
  136991. &_vq_auxt__44u8_p9_0,
  136992. NULL,
  136993. 0
  136994. };
  136995. static long _vq_quantlist__44u8_p9_1[] = {
  136996. 9,
  136997. 8,
  136998. 10,
  136999. 7,
  137000. 11,
  137001. 6,
  137002. 12,
  137003. 5,
  137004. 13,
  137005. 4,
  137006. 14,
  137007. 3,
  137008. 15,
  137009. 2,
  137010. 16,
  137011. 1,
  137012. 17,
  137013. 0,
  137014. 18,
  137015. };
  137016. static long _vq_lengthlist__44u8_p9_1[] = {
  137017. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137018. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137019. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137020. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137021. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137022. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137023. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137024. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137025. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137026. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137027. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137028. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137029. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137030. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137031. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137032. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137033. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137034. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137035. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137036. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137037. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137038. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137039. 16,15,16,16,16,16,16,16,16,
  137040. };
  137041. static float _vq_quantthresh__44u8_p9_1[] = {
  137042. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137043. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137044. 367.5, 416.5,
  137045. };
  137046. static long _vq_quantmap__44u8_p9_1[] = {
  137047. 17, 15, 13, 11, 9, 7, 5, 3,
  137048. 1, 0, 2, 4, 6, 8, 10, 12,
  137049. 14, 16, 18,
  137050. };
  137051. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137052. _vq_quantthresh__44u8_p9_1,
  137053. _vq_quantmap__44u8_p9_1,
  137054. 19,
  137055. 19
  137056. };
  137057. static static_codebook _44u8_p9_1 = {
  137058. 2, 361,
  137059. _vq_lengthlist__44u8_p9_1,
  137060. 1, -518287360, 1622704128, 5, 0,
  137061. _vq_quantlist__44u8_p9_1,
  137062. NULL,
  137063. &_vq_auxt__44u8_p9_1,
  137064. NULL,
  137065. 0
  137066. };
  137067. static long _vq_quantlist__44u8_p9_2[] = {
  137068. 24,
  137069. 23,
  137070. 25,
  137071. 22,
  137072. 26,
  137073. 21,
  137074. 27,
  137075. 20,
  137076. 28,
  137077. 19,
  137078. 29,
  137079. 18,
  137080. 30,
  137081. 17,
  137082. 31,
  137083. 16,
  137084. 32,
  137085. 15,
  137086. 33,
  137087. 14,
  137088. 34,
  137089. 13,
  137090. 35,
  137091. 12,
  137092. 36,
  137093. 11,
  137094. 37,
  137095. 10,
  137096. 38,
  137097. 9,
  137098. 39,
  137099. 8,
  137100. 40,
  137101. 7,
  137102. 41,
  137103. 6,
  137104. 42,
  137105. 5,
  137106. 43,
  137107. 4,
  137108. 44,
  137109. 3,
  137110. 45,
  137111. 2,
  137112. 46,
  137113. 1,
  137114. 47,
  137115. 0,
  137116. 48,
  137117. };
  137118. static long _vq_lengthlist__44u8_p9_2[] = {
  137119. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137120. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137121. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137122. 7,
  137123. };
  137124. static float _vq_quantthresh__44u8_p9_2[] = {
  137125. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137126. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137127. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137128. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137129. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137130. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137131. };
  137132. static long _vq_quantmap__44u8_p9_2[] = {
  137133. 47, 45, 43, 41, 39, 37, 35, 33,
  137134. 31, 29, 27, 25, 23, 21, 19, 17,
  137135. 15, 13, 11, 9, 7, 5, 3, 1,
  137136. 0, 2, 4, 6, 8, 10, 12, 14,
  137137. 16, 18, 20, 22, 24, 26, 28, 30,
  137138. 32, 34, 36, 38, 40, 42, 44, 46,
  137139. 48,
  137140. };
  137141. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137142. _vq_quantthresh__44u8_p9_2,
  137143. _vq_quantmap__44u8_p9_2,
  137144. 49,
  137145. 49
  137146. };
  137147. static static_codebook _44u8_p9_2 = {
  137148. 1, 49,
  137149. _vq_lengthlist__44u8_p9_2,
  137150. 1, -526909440, 1611661312, 6, 0,
  137151. _vq_quantlist__44u8_p9_2,
  137152. NULL,
  137153. &_vq_auxt__44u8_p9_2,
  137154. NULL,
  137155. 0
  137156. };
  137157. static long _huff_lengthlist__44u9__long[] = {
  137158. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137159. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137160. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137161. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137162. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137163. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137164. 10, 8, 8, 9,
  137165. };
  137166. static static_codebook _huff_book__44u9__long = {
  137167. 2, 100,
  137168. _huff_lengthlist__44u9__long,
  137169. 0, 0, 0, 0, 0,
  137170. NULL,
  137171. NULL,
  137172. NULL,
  137173. NULL,
  137174. 0
  137175. };
  137176. static long _huff_lengthlist__44u9__short[] = {
  137177. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137178. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137179. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137180. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137181. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137182. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137183. 9, 9,12,15,
  137184. };
  137185. static static_codebook _huff_book__44u9__short = {
  137186. 2, 100,
  137187. _huff_lengthlist__44u9__short,
  137188. 0, 0, 0, 0, 0,
  137189. NULL,
  137190. NULL,
  137191. NULL,
  137192. NULL,
  137193. 0
  137194. };
  137195. static long _vq_quantlist__44u9_p1_0[] = {
  137196. 1,
  137197. 0,
  137198. 2,
  137199. };
  137200. static long _vq_lengthlist__44u9_p1_0[] = {
  137201. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137202. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137203. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137204. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137205. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137206. 10,
  137207. };
  137208. static float _vq_quantthresh__44u9_p1_0[] = {
  137209. -0.5, 0.5,
  137210. };
  137211. static long _vq_quantmap__44u9_p1_0[] = {
  137212. 1, 0, 2,
  137213. };
  137214. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137215. _vq_quantthresh__44u9_p1_0,
  137216. _vq_quantmap__44u9_p1_0,
  137217. 3,
  137218. 3
  137219. };
  137220. static static_codebook _44u9_p1_0 = {
  137221. 4, 81,
  137222. _vq_lengthlist__44u9_p1_0,
  137223. 1, -535822336, 1611661312, 2, 0,
  137224. _vq_quantlist__44u9_p1_0,
  137225. NULL,
  137226. &_vq_auxt__44u9_p1_0,
  137227. NULL,
  137228. 0
  137229. };
  137230. static long _vq_quantlist__44u9_p2_0[] = {
  137231. 2,
  137232. 1,
  137233. 3,
  137234. 0,
  137235. 4,
  137236. };
  137237. static long _vq_lengthlist__44u9_p2_0[] = {
  137238. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137239. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137240. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137241. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137242. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137243. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137244. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137245. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137246. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137247. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137248. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137249. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137250. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137251. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137252. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137253. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137254. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137255. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137256. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137257. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137258. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137259. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137260. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137261. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137262. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137263. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137264. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137265. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137266. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137267. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137268. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137269. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137270. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137271. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137272. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137273. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137274. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137275. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137276. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137277. 14,
  137278. };
  137279. static float _vq_quantthresh__44u9_p2_0[] = {
  137280. -1.5, -0.5, 0.5, 1.5,
  137281. };
  137282. static long _vq_quantmap__44u9_p2_0[] = {
  137283. 3, 1, 0, 2, 4,
  137284. };
  137285. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137286. _vq_quantthresh__44u9_p2_0,
  137287. _vq_quantmap__44u9_p2_0,
  137288. 5,
  137289. 5
  137290. };
  137291. static static_codebook _44u9_p2_0 = {
  137292. 4, 625,
  137293. _vq_lengthlist__44u9_p2_0,
  137294. 1, -533725184, 1611661312, 3, 0,
  137295. _vq_quantlist__44u9_p2_0,
  137296. NULL,
  137297. &_vq_auxt__44u9_p2_0,
  137298. NULL,
  137299. 0
  137300. };
  137301. static long _vq_quantlist__44u9_p3_0[] = {
  137302. 4,
  137303. 3,
  137304. 5,
  137305. 2,
  137306. 6,
  137307. 1,
  137308. 7,
  137309. 0,
  137310. 8,
  137311. };
  137312. static long _vq_lengthlist__44u9_p3_0[] = {
  137313. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137314. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137315. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137316. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137317. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137318. 11,
  137319. };
  137320. static float _vq_quantthresh__44u9_p3_0[] = {
  137321. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137322. };
  137323. static long _vq_quantmap__44u9_p3_0[] = {
  137324. 7, 5, 3, 1, 0, 2, 4, 6,
  137325. 8,
  137326. };
  137327. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137328. _vq_quantthresh__44u9_p3_0,
  137329. _vq_quantmap__44u9_p3_0,
  137330. 9,
  137331. 9
  137332. };
  137333. static static_codebook _44u9_p3_0 = {
  137334. 2, 81,
  137335. _vq_lengthlist__44u9_p3_0,
  137336. 1, -531628032, 1611661312, 4, 0,
  137337. _vq_quantlist__44u9_p3_0,
  137338. NULL,
  137339. &_vq_auxt__44u9_p3_0,
  137340. NULL,
  137341. 0
  137342. };
  137343. static long _vq_quantlist__44u9_p4_0[] = {
  137344. 8,
  137345. 7,
  137346. 9,
  137347. 6,
  137348. 10,
  137349. 5,
  137350. 11,
  137351. 4,
  137352. 12,
  137353. 3,
  137354. 13,
  137355. 2,
  137356. 14,
  137357. 1,
  137358. 15,
  137359. 0,
  137360. 16,
  137361. };
  137362. static long _vq_lengthlist__44u9_p4_0[] = {
  137363. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137364. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137365. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137366. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137367. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137368. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137369. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137370. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137371. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137372. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137373. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137374. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137375. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137376. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137377. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137378. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137379. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137380. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137381. 14,
  137382. };
  137383. static float _vq_quantthresh__44u9_p4_0[] = {
  137384. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137385. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137386. };
  137387. static long _vq_quantmap__44u9_p4_0[] = {
  137388. 15, 13, 11, 9, 7, 5, 3, 1,
  137389. 0, 2, 4, 6, 8, 10, 12, 14,
  137390. 16,
  137391. };
  137392. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137393. _vq_quantthresh__44u9_p4_0,
  137394. _vq_quantmap__44u9_p4_0,
  137395. 17,
  137396. 17
  137397. };
  137398. static static_codebook _44u9_p4_0 = {
  137399. 2, 289,
  137400. _vq_lengthlist__44u9_p4_0,
  137401. 1, -529530880, 1611661312, 5, 0,
  137402. _vq_quantlist__44u9_p4_0,
  137403. NULL,
  137404. &_vq_auxt__44u9_p4_0,
  137405. NULL,
  137406. 0
  137407. };
  137408. static long _vq_quantlist__44u9_p5_0[] = {
  137409. 1,
  137410. 0,
  137411. 2,
  137412. };
  137413. static long _vq_lengthlist__44u9_p5_0[] = {
  137414. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137415. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137416. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137417. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137418. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137419. 10,
  137420. };
  137421. static float _vq_quantthresh__44u9_p5_0[] = {
  137422. -5.5, 5.5,
  137423. };
  137424. static long _vq_quantmap__44u9_p5_0[] = {
  137425. 1, 0, 2,
  137426. };
  137427. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137428. _vq_quantthresh__44u9_p5_0,
  137429. _vq_quantmap__44u9_p5_0,
  137430. 3,
  137431. 3
  137432. };
  137433. static static_codebook _44u9_p5_0 = {
  137434. 4, 81,
  137435. _vq_lengthlist__44u9_p5_0,
  137436. 1, -529137664, 1618345984, 2, 0,
  137437. _vq_quantlist__44u9_p5_0,
  137438. NULL,
  137439. &_vq_auxt__44u9_p5_0,
  137440. NULL,
  137441. 0
  137442. };
  137443. static long _vq_quantlist__44u9_p5_1[] = {
  137444. 5,
  137445. 4,
  137446. 6,
  137447. 3,
  137448. 7,
  137449. 2,
  137450. 8,
  137451. 1,
  137452. 9,
  137453. 0,
  137454. 10,
  137455. };
  137456. static long _vq_lengthlist__44u9_p5_1[] = {
  137457. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137458. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137459. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137460. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137461. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137462. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137463. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137464. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137465. };
  137466. static float _vq_quantthresh__44u9_p5_1[] = {
  137467. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137468. 3.5, 4.5,
  137469. };
  137470. static long _vq_quantmap__44u9_p5_1[] = {
  137471. 9, 7, 5, 3, 1, 0, 2, 4,
  137472. 6, 8, 10,
  137473. };
  137474. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137475. _vq_quantthresh__44u9_p5_1,
  137476. _vq_quantmap__44u9_p5_1,
  137477. 11,
  137478. 11
  137479. };
  137480. static static_codebook _44u9_p5_1 = {
  137481. 2, 121,
  137482. _vq_lengthlist__44u9_p5_1,
  137483. 1, -531365888, 1611661312, 4, 0,
  137484. _vq_quantlist__44u9_p5_1,
  137485. NULL,
  137486. &_vq_auxt__44u9_p5_1,
  137487. NULL,
  137488. 0
  137489. };
  137490. static long _vq_quantlist__44u9_p6_0[] = {
  137491. 6,
  137492. 5,
  137493. 7,
  137494. 4,
  137495. 8,
  137496. 3,
  137497. 9,
  137498. 2,
  137499. 10,
  137500. 1,
  137501. 11,
  137502. 0,
  137503. 12,
  137504. };
  137505. static long _vq_lengthlist__44u9_p6_0[] = {
  137506. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137507. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137508. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137509. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137510. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137511. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137512. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137513. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137514. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137515. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137516. 10,11,11,11,11,12,11,12,12,
  137517. };
  137518. static float _vq_quantthresh__44u9_p6_0[] = {
  137519. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137520. 12.5, 17.5, 22.5, 27.5,
  137521. };
  137522. static long _vq_quantmap__44u9_p6_0[] = {
  137523. 11, 9, 7, 5, 3, 1, 0, 2,
  137524. 4, 6, 8, 10, 12,
  137525. };
  137526. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137527. _vq_quantthresh__44u9_p6_0,
  137528. _vq_quantmap__44u9_p6_0,
  137529. 13,
  137530. 13
  137531. };
  137532. static static_codebook _44u9_p6_0 = {
  137533. 2, 169,
  137534. _vq_lengthlist__44u9_p6_0,
  137535. 1, -526516224, 1616117760, 4, 0,
  137536. _vq_quantlist__44u9_p6_0,
  137537. NULL,
  137538. &_vq_auxt__44u9_p6_0,
  137539. NULL,
  137540. 0
  137541. };
  137542. static long _vq_quantlist__44u9_p6_1[] = {
  137543. 2,
  137544. 1,
  137545. 3,
  137546. 0,
  137547. 4,
  137548. };
  137549. static long _vq_lengthlist__44u9_p6_1[] = {
  137550. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137551. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137552. };
  137553. static float _vq_quantthresh__44u9_p6_1[] = {
  137554. -1.5, -0.5, 0.5, 1.5,
  137555. };
  137556. static long _vq_quantmap__44u9_p6_1[] = {
  137557. 3, 1, 0, 2, 4,
  137558. };
  137559. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137560. _vq_quantthresh__44u9_p6_1,
  137561. _vq_quantmap__44u9_p6_1,
  137562. 5,
  137563. 5
  137564. };
  137565. static static_codebook _44u9_p6_1 = {
  137566. 2, 25,
  137567. _vq_lengthlist__44u9_p6_1,
  137568. 1, -533725184, 1611661312, 3, 0,
  137569. _vq_quantlist__44u9_p6_1,
  137570. NULL,
  137571. &_vq_auxt__44u9_p6_1,
  137572. NULL,
  137573. 0
  137574. };
  137575. static long _vq_quantlist__44u9_p7_0[] = {
  137576. 6,
  137577. 5,
  137578. 7,
  137579. 4,
  137580. 8,
  137581. 3,
  137582. 9,
  137583. 2,
  137584. 10,
  137585. 1,
  137586. 11,
  137587. 0,
  137588. 12,
  137589. };
  137590. static long _vq_lengthlist__44u9_p7_0[] = {
  137591. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137592. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137593. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137594. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137595. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137596. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137597. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137598. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137599. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137600. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137601. 12,13,13,14,14,14,15,15,15,
  137602. };
  137603. static float _vq_quantthresh__44u9_p7_0[] = {
  137604. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137605. 27.5, 38.5, 49.5, 60.5,
  137606. };
  137607. static long _vq_quantmap__44u9_p7_0[] = {
  137608. 11, 9, 7, 5, 3, 1, 0, 2,
  137609. 4, 6, 8, 10, 12,
  137610. };
  137611. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137612. _vq_quantthresh__44u9_p7_0,
  137613. _vq_quantmap__44u9_p7_0,
  137614. 13,
  137615. 13
  137616. };
  137617. static static_codebook _44u9_p7_0 = {
  137618. 2, 169,
  137619. _vq_lengthlist__44u9_p7_0,
  137620. 1, -523206656, 1618345984, 4, 0,
  137621. _vq_quantlist__44u9_p7_0,
  137622. NULL,
  137623. &_vq_auxt__44u9_p7_0,
  137624. NULL,
  137625. 0
  137626. };
  137627. static long _vq_quantlist__44u9_p7_1[] = {
  137628. 5,
  137629. 4,
  137630. 6,
  137631. 3,
  137632. 7,
  137633. 2,
  137634. 8,
  137635. 1,
  137636. 9,
  137637. 0,
  137638. 10,
  137639. };
  137640. static long _vq_lengthlist__44u9_p7_1[] = {
  137641. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137642. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137643. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137644. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137645. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137646. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137647. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137648. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137649. };
  137650. static float _vq_quantthresh__44u9_p7_1[] = {
  137651. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137652. 3.5, 4.5,
  137653. };
  137654. static long _vq_quantmap__44u9_p7_1[] = {
  137655. 9, 7, 5, 3, 1, 0, 2, 4,
  137656. 6, 8, 10,
  137657. };
  137658. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137659. _vq_quantthresh__44u9_p7_1,
  137660. _vq_quantmap__44u9_p7_1,
  137661. 11,
  137662. 11
  137663. };
  137664. static static_codebook _44u9_p7_1 = {
  137665. 2, 121,
  137666. _vq_lengthlist__44u9_p7_1,
  137667. 1, -531365888, 1611661312, 4, 0,
  137668. _vq_quantlist__44u9_p7_1,
  137669. NULL,
  137670. &_vq_auxt__44u9_p7_1,
  137671. NULL,
  137672. 0
  137673. };
  137674. static long _vq_quantlist__44u9_p8_0[] = {
  137675. 7,
  137676. 6,
  137677. 8,
  137678. 5,
  137679. 9,
  137680. 4,
  137681. 10,
  137682. 3,
  137683. 11,
  137684. 2,
  137685. 12,
  137686. 1,
  137687. 13,
  137688. 0,
  137689. 14,
  137690. };
  137691. static long _vq_lengthlist__44u9_p8_0[] = {
  137692. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137693. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137694. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137695. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137696. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137697. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137698. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137699. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137700. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137701. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137702. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137703. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137704. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137705. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137706. 15,
  137707. };
  137708. static float _vq_quantthresh__44u9_p8_0[] = {
  137709. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137710. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137711. };
  137712. static long _vq_quantmap__44u9_p8_0[] = {
  137713. 13, 11, 9, 7, 5, 3, 1, 0,
  137714. 2, 4, 6, 8, 10, 12, 14,
  137715. };
  137716. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137717. _vq_quantthresh__44u9_p8_0,
  137718. _vq_quantmap__44u9_p8_0,
  137719. 15,
  137720. 15
  137721. };
  137722. static static_codebook _44u9_p8_0 = {
  137723. 2, 225,
  137724. _vq_lengthlist__44u9_p8_0,
  137725. 1, -520986624, 1620377600, 4, 0,
  137726. _vq_quantlist__44u9_p8_0,
  137727. NULL,
  137728. &_vq_auxt__44u9_p8_0,
  137729. NULL,
  137730. 0
  137731. };
  137732. static long _vq_quantlist__44u9_p8_1[] = {
  137733. 10,
  137734. 9,
  137735. 11,
  137736. 8,
  137737. 12,
  137738. 7,
  137739. 13,
  137740. 6,
  137741. 14,
  137742. 5,
  137743. 15,
  137744. 4,
  137745. 16,
  137746. 3,
  137747. 17,
  137748. 2,
  137749. 18,
  137750. 1,
  137751. 19,
  137752. 0,
  137753. 20,
  137754. };
  137755. static long _vq_lengthlist__44u9_p8_1[] = {
  137756. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137757. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137758. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137759. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137760. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137761. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137762. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137763. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137764. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137765. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137766. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137767. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137768. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137769. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137770. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137771. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137772. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137773. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137774. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137775. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137776. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137777. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137778. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137779. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137780. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137781. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137782. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137783. 10,10,10,10,10,10,10,10,10,
  137784. };
  137785. static float _vq_quantthresh__44u9_p8_1[] = {
  137786. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137787. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137788. 6.5, 7.5, 8.5, 9.5,
  137789. };
  137790. static long _vq_quantmap__44u9_p8_1[] = {
  137791. 19, 17, 15, 13, 11, 9, 7, 5,
  137792. 3, 1, 0, 2, 4, 6, 8, 10,
  137793. 12, 14, 16, 18, 20,
  137794. };
  137795. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137796. _vq_quantthresh__44u9_p8_1,
  137797. _vq_quantmap__44u9_p8_1,
  137798. 21,
  137799. 21
  137800. };
  137801. static static_codebook _44u9_p8_1 = {
  137802. 2, 441,
  137803. _vq_lengthlist__44u9_p8_1,
  137804. 1, -529268736, 1611661312, 5, 0,
  137805. _vq_quantlist__44u9_p8_1,
  137806. NULL,
  137807. &_vq_auxt__44u9_p8_1,
  137808. NULL,
  137809. 0
  137810. };
  137811. static long _vq_quantlist__44u9_p9_0[] = {
  137812. 7,
  137813. 6,
  137814. 8,
  137815. 5,
  137816. 9,
  137817. 4,
  137818. 10,
  137819. 3,
  137820. 11,
  137821. 2,
  137822. 12,
  137823. 1,
  137824. 13,
  137825. 0,
  137826. 14,
  137827. };
  137828. static long _vq_lengthlist__44u9_p9_0[] = {
  137829. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137830. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137831. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137832. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137833. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137834. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137835. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137836. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137837. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137838. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137839. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137840. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137841. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137842. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137843. 10,
  137844. };
  137845. static float _vq_quantthresh__44u9_p9_0[] = {
  137846. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137847. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137848. };
  137849. static long _vq_quantmap__44u9_p9_0[] = {
  137850. 13, 11, 9, 7, 5, 3, 1, 0,
  137851. 2, 4, 6, 8, 10, 12, 14,
  137852. };
  137853. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137854. _vq_quantthresh__44u9_p9_0,
  137855. _vq_quantmap__44u9_p9_0,
  137856. 15,
  137857. 15
  137858. };
  137859. static static_codebook _44u9_p9_0 = {
  137860. 2, 225,
  137861. _vq_lengthlist__44u9_p9_0,
  137862. 1, -510036736, 1631393792, 4, 0,
  137863. _vq_quantlist__44u9_p9_0,
  137864. NULL,
  137865. &_vq_auxt__44u9_p9_0,
  137866. NULL,
  137867. 0
  137868. };
  137869. static long _vq_quantlist__44u9_p9_1[] = {
  137870. 9,
  137871. 8,
  137872. 10,
  137873. 7,
  137874. 11,
  137875. 6,
  137876. 12,
  137877. 5,
  137878. 13,
  137879. 4,
  137880. 14,
  137881. 3,
  137882. 15,
  137883. 2,
  137884. 16,
  137885. 1,
  137886. 17,
  137887. 0,
  137888. 18,
  137889. };
  137890. static long _vq_lengthlist__44u9_p9_1[] = {
  137891. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137892. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137893. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137894. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137895. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137896. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137897. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137898. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137899. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137900. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137901. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137902. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137903. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137904. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137905. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  137906. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  137907. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  137908. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  137909. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  137910. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  137911. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  137912. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  137913. 17,17,15,17,15,17,16,16,17,
  137914. };
  137915. static float _vq_quantthresh__44u9_p9_1[] = {
  137916. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137917. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137918. 367.5, 416.5,
  137919. };
  137920. static long _vq_quantmap__44u9_p9_1[] = {
  137921. 17, 15, 13, 11, 9, 7, 5, 3,
  137922. 1, 0, 2, 4, 6, 8, 10, 12,
  137923. 14, 16, 18,
  137924. };
  137925. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  137926. _vq_quantthresh__44u9_p9_1,
  137927. _vq_quantmap__44u9_p9_1,
  137928. 19,
  137929. 19
  137930. };
  137931. static static_codebook _44u9_p9_1 = {
  137932. 2, 361,
  137933. _vq_lengthlist__44u9_p9_1,
  137934. 1, -518287360, 1622704128, 5, 0,
  137935. _vq_quantlist__44u9_p9_1,
  137936. NULL,
  137937. &_vq_auxt__44u9_p9_1,
  137938. NULL,
  137939. 0
  137940. };
  137941. static long _vq_quantlist__44u9_p9_2[] = {
  137942. 24,
  137943. 23,
  137944. 25,
  137945. 22,
  137946. 26,
  137947. 21,
  137948. 27,
  137949. 20,
  137950. 28,
  137951. 19,
  137952. 29,
  137953. 18,
  137954. 30,
  137955. 17,
  137956. 31,
  137957. 16,
  137958. 32,
  137959. 15,
  137960. 33,
  137961. 14,
  137962. 34,
  137963. 13,
  137964. 35,
  137965. 12,
  137966. 36,
  137967. 11,
  137968. 37,
  137969. 10,
  137970. 38,
  137971. 9,
  137972. 39,
  137973. 8,
  137974. 40,
  137975. 7,
  137976. 41,
  137977. 6,
  137978. 42,
  137979. 5,
  137980. 43,
  137981. 4,
  137982. 44,
  137983. 3,
  137984. 45,
  137985. 2,
  137986. 46,
  137987. 1,
  137988. 47,
  137989. 0,
  137990. 48,
  137991. };
  137992. static long _vq_lengthlist__44u9_p9_2[] = {
  137993. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  137994. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137995. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137996. 7,
  137997. };
  137998. static float _vq_quantthresh__44u9_p9_2[] = {
  137999. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138000. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138001. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138002. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138003. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138004. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138005. };
  138006. static long _vq_quantmap__44u9_p9_2[] = {
  138007. 47, 45, 43, 41, 39, 37, 35, 33,
  138008. 31, 29, 27, 25, 23, 21, 19, 17,
  138009. 15, 13, 11, 9, 7, 5, 3, 1,
  138010. 0, 2, 4, 6, 8, 10, 12, 14,
  138011. 16, 18, 20, 22, 24, 26, 28, 30,
  138012. 32, 34, 36, 38, 40, 42, 44, 46,
  138013. 48,
  138014. };
  138015. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138016. _vq_quantthresh__44u9_p9_2,
  138017. _vq_quantmap__44u9_p9_2,
  138018. 49,
  138019. 49
  138020. };
  138021. static static_codebook _44u9_p9_2 = {
  138022. 1, 49,
  138023. _vq_lengthlist__44u9_p9_2,
  138024. 1, -526909440, 1611661312, 6, 0,
  138025. _vq_quantlist__44u9_p9_2,
  138026. NULL,
  138027. &_vq_auxt__44u9_p9_2,
  138028. NULL,
  138029. 0
  138030. };
  138031. static long _huff_lengthlist__44un1__long[] = {
  138032. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138033. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138034. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138035. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138036. };
  138037. static static_codebook _huff_book__44un1__long = {
  138038. 2, 64,
  138039. _huff_lengthlist__44un1__long,
  138040. 0, 0, 0, 0, 0,
  138041. NULL,
  138042. NULL,
  138043. NULL,
  138044. NULL,
  138045. 0
  138046. };
  138047. static long _vq_quantlist__44un1__p1_0[] = {
  138048. 1,
  138049. 0,
  138050. 2,
  138051. };
  138052. static long _vq_lengthlist__44un1__p1_0[] = {
  138053. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138054. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138055. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138056. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138057. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138058. 12,
  138059. };
  138060. static float _vq_quantthresh__44un1__p1_0[] = {
  138061. -0.5, 0.5,
  138062. };
  138063. static long _vq_quantmap__44un1__p1_0[] = {
  138064. 1, 0, 2,
  138065. };
  138066. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138067. _vq_quantthresh__44un1__p1_0,
  138068. _vq_quantmap__44un1__p1_0,
  138069. 3,
  138070. 3
  138071. };
  138072. static static_codebook _44un1__p1_0 = {
  138073. 4, 81,
  138074. _vq_lengthlist__44un1__p1_0,
  138075. 1, -535822336, 1611661312, 2, 0,
  138076. _vq_quantlist__44un1__p1_0,
  138077. NULL,
  138078. &_vq_auxt__44un1__p1_0,
  138079. NULL,
  138080. 0
  138081. };
  138082. static long _vq_quantlist__44un1__p2_0[] = {
  138083. 1,
  138084. 0,
  138085. 2,
  138086. };
  138087. static long _vq_lengthlist__44un1__p2_0[] = {
  138088. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138089. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138090. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138091. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138092. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138093. 8,
  138094. };
  138095. static float _vq_quantthresh__44un1__p2_0[] = {
  138096. -0.5, 0.5,
  138097. };
  138098. static long _vq_quantmap__44un1__p2_0[] = {
  138099. 1, 0, 2,
  138100. };
  138101. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138102. _vq_quantthresh__44un1__p2_0,
  138103. _vq_quantmap__44un1__p2_0,
  138104. 3,
  138105. 3
  138106. };
  138107. static static_codebook _44un1__p2_0 = {
  138108. 4, 81,
  138109. _vq_lengthlist__44un1__p2_0,
  138110. 1, -535822336, 1611661312, 2, 0,
  138111. _vq_quantlist__44un1__p2_0,
  138112. NULL,
  138113. &_vq_auxt__44un1__p2_0,
  138114. NULL,
  138115. 0
  138116. };
  138117. static long _vq_quantlist__44un1__p3_0[] = {
  138118. 2,
  138119. 1,
  138120. 3,
  138121. 0,
  138122. 4,
  138123. };
  138124. static long _vq_lengthlist__44un1__p3_0[] = {
  138125. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138126. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138127. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138128. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138129. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138130. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138131. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138132. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138133. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138134. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138135. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138136. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138137. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138138. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138139. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138140. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138141. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138142. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138143. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138144. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138145. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138146. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138147. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138148. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138149. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138150. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138151. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138152. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138153. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138154. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138155. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138156. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138157. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138158. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138159. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138160. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138161. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138162. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138163. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138164. 17,
  138165. };
  138166. static float _vq_quantthresh__44un1__p3_0[] = {
  138167. -1.5, -0.5, 0.5, 1.5,
  138168. };
  138169. static long _vq_quantmap__44un1__p3_0[] = {
  138170. 3, 1, 0, 2, 4,
  138171. };
  138172. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138173. _vq_quantthresh__44un1__p3_0,
  138174. _vq_quantmap__44un1__p3_0,
  138175. 5,
  138176. 5
  138177. };
  138178. static static_codebook _44un1__p3_0 = {
  138179. 4, 625,
  138180. _vq_lengthlist__44un1__p3_0,
  138181. 1, -533725184, 1611661312, 3, 0,
  138182. _vq_quantlist__44un1__p3_0,
  138183. NULL,
  138184. &_vq_auxt__44un1__p3_0,
  138185. NULL,
  138186. 0
  138187. };
  138188. static long _vq_quantlist__44un1__p4_0[] = {
  138189. 2,
  138190. 1,
  138191. 3,
  138192. 0,
  138193. 4,
  138194. };
  138195. static long _vq_lengthlist__44un1__p4_0[] = {
  138196. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138197. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138198. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138199. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138200. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138201. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138202. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138203. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138204. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138205. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138206. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138207. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138208. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138209. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138210. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138211. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138212. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138213. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138214. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138215. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138216. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138217. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138218. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138219. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138220. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138221. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138222. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138223. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138224. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138225. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138226. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138227. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138228. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138229. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138230. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138231. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138232. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138233. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138234. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138235. 12,
  138236. };
  138237. static float _vq_quantthresh__44un1__p4_0[] = {
  138238. -1.5, -0.5, 0.5, 1.5,
  138239. };
  138240. static long _vq_quantmap__44un1__p4_0[] = {
  138241. 3, 1, 0, 2, 4,
  138242. };
  138243. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138244. _vq_quantthresh__44un1__p4_0,
  138245. _vq_quantmap__44un1__p4_0,
  138246. 5,
  138247. 5
  138248. };
  138249. static static_codebook _44un1__p4_0 = {
  138250. 4, 625,
  138251. _vq_lengthlist__44un1__p4_0,
  138252. 1, -533725184, 1611661312, 3, 0,
  138253. _vq_quantlist__44un1__p4_0,
  138254. NULL,
  138255. &_vq_auxt__44un1__p4_0,
  138256. NULL,
  138257. 0
  138258. };
  138259. static long _vq_quantlist__44un1__p5_0[] = {
  138260. 4,
  138261. 3,
  138262. 5,
  138263. 2,
  138264. 6,
  138265. 1,
  138266. 7,
  138267. 0,
  138268. 8,
  138269. };
  138270. static long _vq_lengthlist__44un1__p5_0[] = {
  138271. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138272. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138273. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138274. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138275. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138276. 12,
  138277. };
  138278. static float _vq_quantthresh__44un1__p5_0[] = {
  138279. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138280. };
  138281. static long _vq_quantmap__44un1__p5_0[] = {
  138282. 7, 5, 3, 1, 0, 2, 4, 6,
  138283. 8,
  138284. };
  138285. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138286. _vq_quantthresh__44un1__p5_0,
  138287. _vq_quantmap__44un1__p5_0,
  138288. 9,
  138289. 9
  138290. };
  138291. static static_codebook _44un1__p5_0 = {
  138292. 2, 81,
  138293. _vq_lengthlist__44un1__p5_0,
  138294. 1, -531628032, 1611661312, 4, 0,
  138295. _vq_quantlist__44un1__p5_0,
  138296. NULL,
  138297. &_vq_auxt__44un1__p5_0,
  138298. NULL,
  138299. 0
  138300. };
  138301. static long _vq_quantlist__44un1__p6_0[] = {
  138302. 6,
  138303. 5,
  138304. 7,
  138305. 4,
  138306. 8,
  138307. 3,
  138308. 9,
  138309. 2,
  138310. 10,
  138311. 1,
  138312. 11,
  138313. 0,
  138314. 12,
  138315. };
  138316. static long _vq_lengthlist__44un1__p6_0[] = {
  138317. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138318. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138319. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138320. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138321. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138322. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138323. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138324. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138325. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138326. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138327. 16, 0,15,18,18, 0,16, 0, 0,
  138328. };
  138329. static float _vq_quantthresh__44un1__p6_0[] = {
  138330. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138331. 12.5, 17.5, 22.5, 27.5,
  138332. };
  138333. static long _vq_quantmap__44un1__p6_0[] = {
  138334. 11, 9, 7, 5, 3, 1, 0, 2,
  138335. 4, 6, 8, 10, 12,
  138336. };
  138337. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138338. _vq_quantthresh__44un1__p6_0,
  138339. _vq_quantmap__44un1__p6_0,
  138340. 13,
  138341. 13
  138342. };
  138343. static static_codebook _44un1__p6_0 = {
  138344. 2, 169,
  138345. _vq_lengthlist__44un1__p6_0,
  138346. 1, -526516224, 1616117760, 4, 0,
  138347. _vq_quantlist__44un1__p6_0,
  138348. NULL,
  138349. &_vq_auxt__44un1__p6_0,
  138350. NULL,
  138351. 0
  138352. };
  138353. static long _vq_quantlist__44un1__p6_1[] = {
  138354. 2,
  138355. 1,
  138356. 3,
  138357. 0,
  138358. 4,
  138359. };
  138360. static long _vq_lengthlist__44un1__p6_1[] = {
  138361. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138362. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138363. };
  138364. static float _vq_quantthresh__44un1__p6_1[] = {
  138365. -1.5, -0.5, 0.5, 1.5,
  138366. };
  138367. static long _vq_quantmap__44un1__p6_1[] = {
  138368. 3, 1, 0, 2, 4,
  138369. };
  138370. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138371. _vq_quantthresh__44un1__p6_1,
  138372. _vq_quantmap__44un1__p6_1,
  138373. 5,
  138374. 5
  138375. };
  138376. static static_codebook _44un1__p6_1 = {
  138377. 2, 25,
  138378. _vq_lengthlist__44un1__p6_1,
  138379. 1, -533725184, 1611661312, 3, 0,
  138380. _vq_quantlist__44un1__p6_1,
  138381. NULL,
  138382. &_vq_auxt__44un1__p6_1,
  138383. NULL,
  138384. 0
  138385. };
  138386. static long _vq_quantlist__44un1__p7_0[] = {
  138387. 2,
  138388. 1,
  138389. 3,
  138390. 0,
  138391. 4,
  138392. };
  138393. static long _vq_lengthlist__44un1__p7_0[] = {
  138394. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138395. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138396. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138397. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138398. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138399. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138400. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138401. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138402. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138403. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138404. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138405. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138406. 11,11,11,11,11,11,11,11,11,11,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,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138409. 11,11,11,11,11,11,11,11,11,11, 7,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,10,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,11,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,11,
  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,11,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,11,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. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138431. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138432. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138433. 10,
  138434. };
  138435. static float _vq_quantthresh__44un1__p7_0[] = {
  138436. -253.5, -84.5, 84.5, 253.5,
  138437. };
  138438. static long _vq_quantmap__44un1__p7_0[] = {
  138439. 3, 1, 0, 2, 4,
  138440. };
  138441. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138442. _vq_quantthresh__44un1__p7_0,
  138443. _vq_quantmap__44un1__p7_0,
  138444. 5,
  138445. 5
  138446. };
  138447. static static_codebook _44un1__p7_0 = {
  138448. 4, 625,
  138449. _vq_lengthlist__44un1__p7_0,
  138450. 1, -518709248, 1626677248, 3, 0,
  138451. _vq_quantlist__44un1__p7_0,
  138452. NULL,
  138453. &_vq_auxt__44un1__p7_0,
  138454. NULL,
  138455. 0
  138456. };
  138457. static long _vq_quantlist__44un1__p7_1[] = {
  138458. 6,
  138459. 5,
  138460. 7,
  138461. 4,
  138462. 8,
  138463. 3,
  138464. 9,
  138465. 2,
  138466. 10,
  138467. 1,
  138468. 11,
  138469. 0,
  138470. 12,
  138471. };
  138472. static long _vq_lengthlist__44un1__p7_1[] = {
  138473. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138474. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138475. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138476. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138477. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138478. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138479. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138480. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138481. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138482. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138483. 12,13,13,12,13,13,14,14,14,
  138484. };
  138485. static float _vq_quantthresh__44un1__p7_1[] = {
  138486. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138487. 32.5, 45.5, 58.5, 71.5,
  138488. };
  138489. static long _vq_quantmap__44un1__p7_1[] = {
  138490. 11, 9, 7, 5, 3, 1, 0, 2,
  138491. 4, 6, 8, 10, 12,
  138492. };
  138493. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138494. _vq_quantthresh__44un1__p7_1,
  138495. _vq_quantmap__44un1__p7_1,
  138496. 13,
  138497. 13
  138498. };
  138499. static static_codebook _44un1__p7_1 = {
  138500. 2, 169,
  138501. _vq_lengthlist__44un1__p7_1,
  138502. 1, -523010048, 1618608128, 4, 0,
  138503. _vq_quantlist__44un1__p7_1,
  138504. NULL,
  138505. &_vq_auxt__44un1__p7_1,
  138506. NULL,
  138507. 0
  138508. };
  138509. static long _vq_quantlist__44un1__p7_2[] = {
  138510. 6,
  138511. 5,
  138512. 7,
  138513. 4,
  138514. 8,
  138515. 3,
  138516. 9,
  138517. 2,
  138518. 10,
  138519. 1,
  138520. 11,
  138521. 0,
  138522. 12,
  138523. };
  138524. static long _vq_lengthlist__44un1__p7_2[] = {
  138525. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138526. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138527. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138528. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138529. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138530. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138531. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138532. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138533. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138534. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138535. 9, 9, 9,10,10,10,10,10,10,
  138536. };
  138537. static float _vq_quantthresh__44un1__p7_2[] = {
  138538. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138539. 2.5, 3.5, 4.5, 5.5,
  138540. };
  138541. static long _vq_quantmap__44un1__p7_2[] = {
  138542. 11, 9, 7, 5, 3, 1, 0, 2,
  138543. 4, 6, 8, 10, 12,
  138544. };
  138545. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138546. _vq_quantthresh__44un1__p7_2,
  138547. _vq_quantmap__44un1__p7_2,
  138548. 13,
  138549. 13
  138550. };
  138551. static static_codebook _44un1__p7_2 = {
  138552. 2, 169,
  138553. _vq_lengthlist__44un1__p7_2,
  138554. 1, -531103744, 1611661312, 4, 0,
  138555. _vq_quantlist__44un1__p7_2,
  138556. NULL,
  138557. &_vq_auxt__44un1__p7_2,
  138558. NULL,
  138559. 0
  138560. };
  138561. static long _huff_lengthlist__44un1__short[] = {
  138562. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138563. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138564. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138565. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138566. };
  138567. static static_codebook _huff_book__44un1__short = {
  138568. 2, 64,
  138569. _huff_lengthlist__44un1__short,
  138570. 0, 0, 0, 0, 0,
  138571. NULL,
  138572. NULL,
  138573. NULL,
  138574. NULL,
  138575. 0
  138576. };
  138577. /*** End of inlined file: res_books_uncoupled.h ***/
  138578. static vorbis_info_residue0 _residue_44_low_un={
  138579. 0,-1, -1, 8,-1,
  138580. {0},
  138581. {-1},
  138582. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138583. { -1, 25, -1, 45, -1, -1, -1}
  138584. };
  138585. static vorbis_info_residue0 _residue_44_mid_un={
  138586. 0,-1, -1, 10,-1,
  138587. {0},
  138588. {-1},
  138589. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138590. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138591. };
  138592. static vorbis_info_residue0 _residue_44_hi_un={
  138593. 0,-1, -1, 10,-1,
  138594. {0},
  138595. {-1},
  138596. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138597. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138598. };
  138599. static vorbis_info_mapping0 _map_nominal_u[2]={
  138600. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138601. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138602. };
  138603. static static_bookblock _resbook_44u_n1={
  138604. {
  138605. {0},
  138606. {0,0,&_44un1__p1_0},
  138607. {0,0,&_44un1__p2_0},
  138608. {0,0,&_44un1__p3_0},
  138609. {0,0,&_44un1__p4_0},
  138610. {0,0,&_44un1__p5_0},
  138611. {&_44un1__p6_0,&_44un1__p6_1},
  138612. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138613. }
  138614. };
  138615. static static_bookblock _resbook_44u_0={
  138616. {
  138617. {0},
  138618. {0,0,&_44u0__p1_0},
  138619. {0,0,&_44u0__p2_0},
  138620. {0,0,&_44u0__p3_0},
  138621. {0,0,&_44u0__p4_0},
  138622. {0,0,&_44u0__p5_0},
  138623. {&_44u0__p6_0,&_44u0__p6_1},
  138624. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138625. }
  138626. };
  138627. static static_bookblock _resbook_44u_1={
  138628. {
  138629. {0},
  138630. {0,0,&_44u1__p1_0},
  138631. {0,0,&_44u1__p2_0},
  138632. {0,0,&_44u1__p3_0},
  138633. {0,0,&_44u1__p4_0},
  138634. {0,0,&_44u1__p5_0},
  138635. {&_44u1__p6_0,&_44u1__p6_1},
  138636. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138637. }
  138638. };
  138639. static static_bookblock _resbook_44u_2={
  138640. {
  138641. {0},
  138642. {0,0,&_44u2__p1_0},
  138643. {0,0,&_44u2__p2_0},
  138644. {0,0,&_44u2__p3_0},
  138645. {0,0,&_44u2__p4_0},
  138646. {0,0,&_44u2__p5_0},
  138647. {&_44u2__p6_0,&_44u2__p6_1},
  138648. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138649. }
  138650. };
  138651. static static_bookblock _resbook_44u_3={
  138652. {
  138653. {0},
  138654. {0,0,&_44u3__p1_0},
  138655. {0,0,&_44u3__p2_0},
  138656. {0,0,&_44u3__p3_0},
  138657. {0,0,&_44u3__p4_0},
  138658. {0,0,&_44u3__p5_0},
  138659. {&_44u3__p6_0,&_44u3__p6_1},
  138660. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138661. }
  138662. };
  138663. static static_bookblock _resbook_44u_4={
  138664. {
  138665. {0},
  138666. {0,0,&_44u4__p1_0},
  138667. {0,0,&_44u4__p2_0},
  138668. {0,0,&_44u4__p3_0},
  138669. {0,0,&_44u4__p4_0},
  138670. {0,0,&_44u4__p5_0},
  138671. {&_44u4__p6_0,&_44u4__p6_1},
  138672. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138673. }
  138674. };
  138675. static static_bookblock _resbook_44u_5={
  138676. {
  138677. {0},
  138678. {0,0,&_44u5__p1_0},
  138679. {0,0,&_44u5__p2_0},
  138680. {0,0,&_44u5__p3_0},
  138681. {0,0,&_44u5__p4_0},
  138682. {0,0,&_44u5__p5_0},
  138683. {0,0,&_44u5__p6_0},
  138684. {&_44u5__p7_0,&_44u5__p7_1},
  138685. {&_44u5__p8_0,&_44u5__p8_1},
  138686. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138687. }
  138688. };
  138689. static static_bookblock _resbook_44u_6={
  138690. {
  138691. {0},
  138692. {0,0,&_44u6__p1_0},
  138693. {0,0,&_44u6__p2_0},
  138694. {0,0,&_44u6__p3_0},
  138695. {0,0,&_44u6__p4_0},
  138696. {0,0,&_44u6__p5_0},
  138697. {0,0,&_44u6__p6_0},
  138698. {&_44u6__p7_0,&_44u6__p7_1},
  138699. {&_44u6__p8_0,&_44u6__p8_1},
  138700. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138701. }
  138702. };
  138703. static static_bookblock _resbook_44u_7={
  138704. {
  138705. {0},
  138706. {0,0,&_44u7__p1_0},
  138707. {0,0,&_44u7__p2_0},
  138708. {0,0,&_44u7__p3_0},
  138709. {0,0,&_44u7__p4_0},
  138710. {0,0,&_44u7__p5_0},
  138711. {0,0,&_44u7__p6_0},
  138712. {&_44u7__p7_0,&_44u7__p7_1},
  138713. {&_44u7__p8_0,&_44u7__p8_1},
  138714. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138715. }
  138716. };
  138717. static static_bookblock _resbook_44u_8={
  138718. {
  138719. {0},
  138720. {0,0,&_44u8_p1_0},
  138721. {0,0,&_44u8_p2_0},
  138722. {0,0,&_44u8_p3_0},
  138723. {0,0,&_44u8_p4_0},
  138724. {&_44u8_p5_0,&_44u8_p5_1},
  138725. {&_44u8_p6_0,&_44u8_p6_1},
  138726. {&_44u8_p7_0,&_44u8_p7_1},
  138727. {&_44u8_p8_0,&_44u8_p8_1},
  138728. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138729. }
  138730. };
  138731. static static_bookblock _resbook_44u_9={
  138732. {
  138733. {0},
  138734. {0,0,&_44u9_p1_0},
  138735. {0,0,&_44u9_p2_0},
  138736. {0,0,&_44u9_p3_0},
  138737. {0,0,&_44u9_p4_0},
  138738. {&_44u9_p5_0,&_44u9_p5_1},
  138739. {&_44u9_p6_0,&_44u9_p6_1},
  138740. {&_44u9_p7_0,&_44u9_p7_1},
  138741. {&_44u9_p8_0,&_44u9_p8_1},
  138742. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138743. }
  138744. };
  138745. static vorbis_residue_template _res_44u_n1[]={
  138746. {1,0, &_residue_44_low_un,
  138747. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138748. &_resbook_44u_n1,&_resbook_44u_n1},
  138749. {1,0, &_residue_44_low_un,
  138750. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138751. &_resbook_44u_n1,&_resbook_44u_n1}
  138752. };
  138753. static vorbis_residue_template _res_44u_0[]={
  138754. {1,0, &_residue_44_low_un,
  138755. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138756. &_resbook_44u_0,&_resbook_44u_0},
  138757. {1,0, &_residue_44_low_un,
  138758. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138759. &_resbook_44u_0,&_resbook_44u_0}
  138760. };
  138761. static vorbis_residue_template _res_44u_1[]={
  138762. {1,0, &_residue_44_low_un,
  138763. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138764. &_resbook_44u_1,&_resbook_44u_1},
  138765. {1,0, &_residue_44_low_un,
  138766. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138767. &_resbook_44u_1,&_resbook_44u_1}
  138768. };
  138769. static vorbis_residue_template _res_44u_2[]={
  138770. {1,0, &_residue_44_low_un,
  138771. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138772. &_resbook_44u_2,&_resbook_44u_2},
  138773. {1,0, &_residue_44_low_un,
  138774. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138775. &_resbook_44u_2,&_resbook_44u_2}
  138776. };
  138777. static vorbis_residue_template _res_44u_3[]={
  138778. {1,0, &_residue_44_low_un,
  138779. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138780. &_resbook_44u_3,&_resbook_44u_3},
  138781. {1,0, &_residue_44_low_un,
  138782. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138783. &_resbook_44u_3,&_resbook_44u_3}
  138784. };
  138785. static vorbis_residue_template _res_44u_4[]={
  138786. {1,0, &_residue_44_low_un,
  138787. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138788. &_resbook_44u_4,&_resbook_44u_4},
  138789. {1,0, &_residue_44_low_un,
  138790. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138791. &_resbook_44u_4,&_resbook_44u_4}
  138792. };
  138793. static vorbis_residue_template _res_44u_5[]={
  138794. {1,0, &_residue_44_mid_un,
  138795. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138796. &_resbook_44u_5,&_resbook_44u_5},
  138797. {1,0, &_residue_44_mid_un,
  138798. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138799. &_resbook_44u_5,&_resbook_44u_5}
  138800. };
  138801. static vorbis_residue_template _res_44u_6[]={
  138802. {1,0, &_residue_44_mid_un,
  138803. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138804. &_resbook_44u_6,&_resbook_44u_6},
  138805. {1,0, &_residue_44_mid_un,
  138806. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138807. &_resbook_44u_6,&_resbook_44u_6}
  138808. };
  138809. static vorbis_residue_template _res_44u_7[]={
  138810. {1,0, &_residue_44_mid_un,
  138811. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138812. &_resbook_44u_7,&_resbook_44u_7},
  138813. {1,0, &_residue_44_mid_un,
  138814. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138815. &_resbook_44u_7,&_resbook_44u_7}
  138816. };
  138817. static vorbis_residue_template _res_44u_8[]={
  138818. {1,0, &_residue_44_hi_un,
  138819. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138820. &_resbook_44u_8,&_resbook_44u_8},
  138821. {1,0, &_residue_44_hi_un,
  138822. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138823. &_resbook_44u_8,&_resbook_44u_8}
  138824. };
  138825. static vorbis_residue_template _res_44u_9[]={
  138826. {1,0, &_residue_44_hi_un,
  138827. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138828. &_resbook_44u_9,&_resbook_44u_9},
  138829. {1,0, &_residue_44_hi_un,
  138830. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138831. &_resbook_44u_9,&_resbook_44u_9}
  138832. };
  138833. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138834. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138835. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138836. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138837. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138838. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138839. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138840. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138841. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138842. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138843. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138844. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138845. };
  138846. /*** End of inlined file: residue_44u.h ***/
  138847. static double rate_mapping_44_un[12]={
  138848. 32000.,48000.,60000.,70000.,80000.,86000.,
  138849. 96000.,110000.,120000.,140000.,160000.,240001.
  138850. };
  138851. ve_setup_data_template ve_setup_44_uncoupled={
  138852. 11,
  138853. rate_mapping_44_un,
  138854. quality_mapping_44,
  138855. -1,
  138856. 40000,
  138857. 50000,
  138858. blocksize_short_44,
  138859. blocksize_long_44,
  138860. _psy_tone_masteratt_44,
  138861. _psy_tone_0dB,
  138862. _psy_tone_suppress,
  138863. _vp_tonemask_adj_otherblock,
  138864. _vp_tonemask_adj_longblock,
  138865. _vp_tonemask_adj_otherblock,
  138866. _psy_noiseguards_44,
  138867. _psy_noisebias_impulse,
  138868. _psy_noisebias_padding,
  138869. _psy_noisebias_trans,
  138870. _psy_noisebias_long,
  138871. _psy_noise_suppress,
  138872. _psy_compand_44,
  138873. _psy_compand_short_mapping,
  138874. _psy_compand_long_mapping,
  138875. {_noise_start_short_44,_noise_start_long_44},
  138876. {_noise_part_short_44,_noise_part_long_44},
  138877. _noise_thresh_44,
  138878. _psy_ath_floater,
  138879. _psy_ath_abs,
  138880. _psy_lowpass_44,
  138881. _psy_global_44,
  138882. _global_mapping_44,
  138883. NULL,
  138884. _floor_books,
  138885. _floor,
  138886. _floor_short_mapping_44,
  138887. _floor_long_mapping_44,
  138888. _mapres_template_44_uncoupled
  138889. };
  138890. /*** End of inlined file: setup_44u.h ***/
  138891. /*** Start of inlined file: setup_32.h ***/
  138892. static double rate_mapping_32[12]={
  138893. 18000.,28000.,35000.,45000.,56000.,60000.,
  138894. 75000.,90000.,100000.,115000.,150000.,190000.,
  138895. };
  138896. static double rate_mapping_32_un[12]={
  138897. 30000.,42000.,52000.,64000.,72000.,78000.,
  138898. 86000.,92000.,110000.,120000.,140000.,190000.,
  138899. };
  138900. static double _psy_lowpass_32[12]={
  138901. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138902. };
  138903. ve_setup_data_template ve_setup_32_stereo={
  138904. 11,
  138905. rate_mapping_32,
  138906. quality_mapping_44,
  138907. 2,
  138908. 26000,
  138909. 40000,
  138910. blocksize_short_44,
  138911. blocksize_long_44,
  138912. _psy_tone_masteratt_44,
  138913. _psy_tone_0dB,
  138914. _psy_tone_suppress,
  138915. _vp_tonemask_adj_otherblock,
  138916. _vp_tonemask_adj_longblock,
  138917. _vp_tonemask_adj_otherblock,
  138918. _psy_noiseguards_44,
  138919. _psy_noisebias_impulse,
  138920. _psy_noisebias_padding,
  138921. _psy_noisebias_trans,
  138922. _psy_noisebias_long,
  138923. _psy_noise_suppress,
  138924. _psy_compand_44,
  138925. _psy_compand_short_mapping,
  138926. _psy_compand_long_mapping,
  138927. {_noise_start_short_44,_noise_start_long_44},
  138928. {_noise_part_short_44,_noise_part_long_44},
  138929. _noise_thresh_44,
  138930. _psy_ath_floater,
  138931. _psy_ath_abs,
  138932. _psy_lowpass_32,
  138933. _psy_global_44,
  138934. _global_mapping_44,
  138935. _psy_stereo_modes_44,
  138936. _floor_books,
  138937. _floor,
  138938. _floor_short_mapping_44,
  138939. _floor_long_mapping_44,
  138940. _mapres_template_44_stereo
  138941. };
  138942. ve_setup_data_template ve_setup_32_uncoupled={
  138943. 11,
  138944. rate_mapping_32_un,
  138945. quality_mapping_44,
  138946. -1,
  138947. 26000,
  138948. 40000,
  138949. blocksize_short_44,
  138950. blocksize_long_44,
  138951. _psy_tone_masteratt_44,
  138952. _psy_tone_0dB,
  138953. _psy_tone_suppress,
  138954. _vp_tonemask_adj_otherblock,
  138955. _vp_tonemask_adj_longblock,
  138956. _vp_tonemask_adj_otherblock,
  138957. _psy_noiseguards_44,
  138958. _psy_noisebias_impulse,
  138959. _psy_noisebias_padding,
  138960. _psy_noisebias_trans,
  138961. _psy_noisebias_long,
  138962. _psy_noise_suppress,
  138963. _psy_compand_44,
  138964. _psy_compand_short_mapping,
  138965. _psy_compand_long_mapping,
  138966. {_noise_start_short_44,_noise_start_long_44},
  138967. {_noise_part_short_44,_noise_part_long_44},
  138968. _noise_thresh_44,
  138969. _psy_ath_floater,
  138970. _psy_ath_abs,
  138971. _psy_lowpass_32,
  138972. _psy_global_44,
  138973. _global_mapping_44,
  138974. NULL,
  138975. _floor_books,
  138976. _floor,
  138977. _floor_short_mapping_44,
  138978. _floor_long_mapping_44,
  138979. _mapres_template_44_uncoupled
  138980. };
  138981. /*** End of inlined file: setup_32.h ***/
  138982. /*** Start of inlined file: setup_8.h ***/
  138983. /*** Start of inlined file: psych_8.h ***/
  138984. static att3 _psy_tone_masteratt_8[3]={
  138985. {{ 32, 25, 12}, 0, 0}, /* 0 */
  138986. {{ 30, 25, 12}, 0, 0}, /* 0 */
  138987. {{ 20, 0, -14}, 0, 0}, /* 0 */
  138988. };
  138989. static vp_adjblock _vp_tonemask_adj_8[3]={
  138990. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138991. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138992. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  138993. };
  138994. static noise3 _psy_noisebias_8[3]={
  138995. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138996. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  138997. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138998. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138999. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139000. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139001. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139002. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139003. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139004. };
  139005. static adj_stereo _psy_stereo_modes_8[3]={
  139006. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139007. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139008. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139009. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139010. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139011. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139012. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139013. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139014. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139015. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139016. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139017. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139018. };
  139019. static noiseguard _psy_noiseguards_8[2]={
  139020. {10,10,-1},
  139021. {10,10,-1},
  139022. };
  139023. static compandblock _psy_compand_8[2]={
  139024. {{
  139025. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139026. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139027. 12,12,13,13,14,14,15, 15, /* 23dB */
  139028. 16,16,17,17,17,18,18, 19, /* 31dB */
  139029. 19,19,20,21,22,23,24, 25, /* 39dB */
  139030. }},
  139031. {{
  139032. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139033. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139034. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139035. 9,10,11,12,13,14,15, 16, /* 31dB */
  139036. 17,18,19,20,21,22,23, 24, /* 39dB */
  139037. }},
  139038. };
  139039. static double _psy_lowpass_8[3]={3.,4.,4.};
  139040. static int _noise_start_8[2]={
  139041. 64,64,
  139042. };
  139043. static int _noise_part_8[2]={
  139044. 8,8,
  139045. };
  139046. static int _psy_ath_floater_8[3]={
  139047. -100,-100,-105,
  139048. };
  139049. static int _psy_ath_abs_8[3]={
  139050. -130,-130,-140,
  139051. };
  139052. /*** End of inlined file: psych_8.h ***/
  139053. /*** Start of inlined file: residue_8.h ***/
  139054. static static_bookblock _resbook_8s_0={
  139055. {
  139056. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139057. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139058. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139059. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139060. }
  139061. };
  139062. static static_bookblock _resbook_8s_1={
  139063. {
  139064. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139065. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139066. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139067. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139068. }
  139069. };
  139070. static vorbis_residue_template _res_8s_0[]={
  139071. {2,0, &_residue_44_mid,
  139072. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139073. &_resbook_8s_0,&_resbook_8s_0},
  139074. };
  139075. static vorbis_residue_template _res_8s_1[]={
  139076. {2,0, &_residue_44_mid,
  139077. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139078. &_resbook_8s_1,&_resbook_8s_1},
  139079. };
  139080. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139081. { _map_nominal, _res_8s_0 }, /* 0 */
  139082. { _map_nominal, _res_8s_1 }, /* 1 */
  139083. };
  139084. static static_bookblock _resbook_8u_0={
  139085. {
  139086. {0},
  139087. {0,0,&_8u0__p1_0},
  139088. {0,0,&_8u0__p2_0},
  139089. {0,0,&_8u0__p3_0},
  139090. {0,0,&_8u0__p4_0},
  139091. {0,0,&_8u0__p5_0},
  139092. {&_8u0__p6_0,&_8u0__p6_1},
  139093. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139094. }
  139095. };
  139096. static static_bookblock _resbook_8u_1={
  139097. {
  139098. {0},
  139099. {0,0,&_8u1__p1_0},
  139100. {0,0,&_8u1__p2_0},
  139101. {0,0,&_8u1__p3_0},
  139102. {0,0,&_8u1__p4_0},
  139103. {0,0,&_8u1__p5_0},
  139104. {0,0,&_8u1__p6_0},
  139105. {&_8u1__p7_0,&_8u1__p7_1},
  139106. {&_8u1__p8_0,&_8u1__p8_1},
  139107. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139108. }
  139109. };
  139110. static vorbis_residue_template _res_8u_0[]={
  139111. {1,0, &_residue_44_low_un,
  139112. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139113. &_resbook_8u_0,&_resbook_8u_0},
  139114. };
  139115. static vorbis_residue_template _res_8u_1[]={
  139116. {1,0, &_residue_44_mid_un,
  139117. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139118. &_resbook_8u_1,&_resbook_8u_1},
  139119. };
  139120. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139121. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139122. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139123. };
  139124. /*** End of inlined file: residue_8.h ***/
  139125. static int blocksize_8[2]={
  139126. 512,512
  139127. };
  139128. static int _floor_mapping_8[2]={
  139129. 6,6,
  139130. };
  139131. static double rate_mapping_8[3]={
  139132. 6000.,9000.,32000.,
  139133. };
  139134. static double rate_mapping_8_uncoupled[3]={
  139135. 8000.,14000.,42000.,
  139136. };
  139137. static double quality_mapping_8[3]={
  139138. -.1,.0,1.
  139139. };
  139140. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139141. static double _global_mapping_8[3]={ 1., 2., 3. };
  139142. ve_setup_data_template ve_setup_8_stereo={
  139143. 2,
  139144. rate_mapping_8,
  139145. quality_mapping_8,
  139146. 2,
  139147. 8000,
  139148. 9000,
  139149. blocksize_8,
  139150. blocksize_8,
  139151. _psy_tone_masteratt_8,
  139152. _psy_tone_0dB,
  139153. _psy_tone_suppress,
  139154. _vp_tonemask_adj_8,
  139155. NULL,
  139156. _vp_tonemask_adj_8,
  139157. _psy_noiseguards_8,
  139158. _psy_noisebias_8,
  139159. _psy_noisebias_8,
  139160. NULL,
  139161. NULL,
  139162. _psy_noise_suppress,
  139163. _psy_compand_8,
  139164. _psy_compand_8_mapping,
  139165. NULL,
  139166. {_noise_start_8,_noise_start_8},
  139167. {_noise_part_8,_noise_part_8},
  139168. _noise_thresh_5only,
  139169. _psy_ath_floater_8,
  139170. _psy_ath_abs_8,
  139171. _psy_lowpass_8,
  139172. _psy_global_44,
  139173. _global_mapping_8,
  139174. _psy_stereo_modes_8,
  139175. _floor_books,
  139176. _floor,
  139177. _floor_mapping_8,
  139178. NULL,
  139179. _mapres_template_8_stereo
  139180. };
  139181. ve_setup_data_template ve_setup_8_uncoupled={
  139182. 2,
  139183. rate_mapping_8_uncoupled,
  139184. quality_mapping_8,
  139185. -1,
  139186. 8000,
  139187. 9000,
  139188. blocksize_8,
  139189. blocksize_8,
  139190. _psy_tone_masteratt_8,
  139191. _psy_tone_0dB,
  139192. _psy_tone_suppress,
  139193. _vp_tonemask_adj_8,
  139194. NULL,
  139195. _vp_tonemask_adj_8,
  139196. _psy_noiseguards_8,
  139197. _psy_noisebias_8,
  139198. _psy_noisebias_8,
  139199. NULL,
  139200. NULL,
  139201. _psy_noise_suppress,
  139202. _psy_compand_8,
  139203. _psy_compand_8_mapping,
  139204. NULL,
  139205. {_noise_start_8,_noise_start_8},
  139206. {_noise_part_8,_noise_part_8},
  139207. _noise_thresh_5only,
  139208. _psy_ath_floater_8,
  139209. _psy_ath_abs_8,
  139210. _psy_lowpass_8,
  139211. _psy_global_44,
  139212. _global_mapping_8,
  139213. _psy_stereo_modes_8,
  139214. _floor_books,
  139215. _floor,
  139216. _floor_mapping_8,
  139217. NULL,
  139218. _mapres_template_8_uncoupled
  139219. };
  139220. /*** End of inlined file: setup_8.h ***/
  139221. /*** Start of inlined file: setup_11.h ***/
  139222. /*** Start of inlined file: psych_11.h ***/
  139223. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139224. static att3 _psy_tone_masteratt_11[3]={
  139225. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139226. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139227. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139228. };
  139229. static vp_adjblock _vp_tonemask_adj_11[3]={
  139230. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139231. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139232. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139233. };
  139234. static noise3 _psy_noisebias_11[3]={
  139235. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139236. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139237. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139238. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139239. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139240. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139241. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139242. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139243. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139244. };
  139245. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139246. /*** End of inlined file: psych_11.h ***/
  139247. static int blocksize_11[2]={
  139248. 512,512
  139249. };
  139250. static int _floor_mapping_11[2]={
  139251. 6,6,
  139252. };
  139253. static double rate_mapping_11[3]={
  139254. 8000.,13000.,44000.,
  139255. };
  139256. static double rate_mapping_11_uncoupled[3]={
  139257. 12000.,20000.,50000.,
  139258. };
  139259. static double quality_mapping_11[3]={
  139260. -.1,.0,1.
  139261. };
  139262. ve_setup_data_template ve_setup_11_stereo={
  139263. 2,
  139264. rate_mapping_11,
  139265. quality_mapping_11,
  139266. 2,
  139267. 9000,
  139268. 15000,
  139269. blocksize_11,
  139270. blocksize_11,
  139271. _psy_tone_masteratt_11,
  139272. _psy_tone_0dB,
  139273. _psy_tone_suppress,
  139274. _vp_tonemask_adj_11,
  139275. NULL,
  139276. _vp_tonemask_adj_11,
  139277. _psy_noiseguards_8,
  139278. _psy_noisebias_11,
  139279. _psy_noisebias_11,
  139280. NULL,
  139281. NULL,
  139282. _psy_noise_suppress,
  139283. _psy_compand_8,
  139284. _psy_compand_8_mapping,
  139285. NULL,
  139286. {_noise_start_8,_noise_start_8},
  139287. {_noise_part_8,_noise_part_8},
  139288. _noise_thresh_11,
  139289. _psy_ath_floater_8,
  139290. _psy_ath_abs_8,
  139291. _psy_lowpass_11,
  139292. _psy_global_44,
  139293. _global_mapping_8,
  139294. _psy_stereo_modes_8,
  139295. _floor_books,
  139296. _floor,
  139297. _floor_mapping_11,
  139298. NULL,
  139299. _mapres_template_8_stereo
  139300. };
  139301. ve_setup_data_template ve_setup_11_uncoupled={
  139302. 2,
  139303. rate_mapping_11_uncoupled,
  139304. quality_mapping_11,
  139305. -1,
  139306. 9000,
  139307. 15000,
  139308. blocksize_11,
  139309. blocksize_11,
  139310. _psy_tone_masteratt_11,
  139311. _psy_tone_0dB,
  139312. _psy_tone_suppress,
  139313. _vp_tonemask_adj_11,
  139314. NULL,
  139315. _vp_tonemask_adj_11,
  139316. _psy_noiseguards_8,
  139317. _psy_noisebias_11,
  139318. _psy_noisebias_11,
  139319. NULL,
  139320. NULL,
  139321. _psy_noise_suppress,
  139322. _psy_compand_8,
  139323. _psy_compand_8_mapping,
  139324. NULL,
  139325. {_noise_start_8,_noise_start_8},
  139326. {_noise_part_8,_noise_part_8},
  139327. _noise_thresh_11,
  139328. _psy_ath_floater_8,
  139329. _psy_ath_abs_8,
  139330. _psy_lowpass_11,
  139331. _psy_global_44,
  139332. _global_mapping_8,
  139333. _psy_stereo_modes_8,
  139334. _floor_books,
  139335. _floor,
  139336. _floor_mapping_11,
  139337. NULL,
  139338. _mapres_template_8_uncoupled
  139339. };
  139340. /*** End of inlined file: setup_11.h ***/
  139341. /*** Start of inlined file: setup_16.h ***/
  139342. /*** Start of inlined file: psych_16.h ***/
  139343. static adj_stereo _psy_stereo_modes_16[4]={
  139344. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139345. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139346. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139347. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139348. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139349. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139350. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139351. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139352. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139353. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139354. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139355. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139356. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139357. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139358. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139359. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139360. };
  139361. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139362. static att3 _psy_tone_masteratt_16[4]={
  139363. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139364. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139365. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139366. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139367. };
  139368. static vp_adjblock _vp_tonemask_adj_16[4]={
  139369. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139370. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139371. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139372. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139373. };
  139374. static noise3 _psy_noisebias_16_short[4]={
  139375. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139376. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139377. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139378. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139379. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139380. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139381. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139382. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139383. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139384. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139385. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139386. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139387. };
  139388. static noise3 _psy_noisebias_16_impulse[4]={
  139389. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139390. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139391. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139392. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139393. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139394. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139395. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139396. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139397. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139398. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139399. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139400. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139401. };
  139402. static noise3 _psy_noisebias_16[4]={
  139403. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139404. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139405. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139406. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139407. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139408. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139409. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139410. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139411. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139412. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139413. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139414. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139415. };
  139416. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139417. static int _noise_start_16[3]={ 256,256,9999 };
  139418. static int _noise_part_16[4]={ 8,8,8,8 };
  139419. static int _psy_ath_floater_16[4]={
  139420. -100,-100,-100,-105,
  139421. };
  139422. static int _psy_ath_abs_16[4]={
  139423. -130,-130,-130,-140,
  139424. };
  139425. /*** End of inlined file: psych_16.h ***/
  139426. /*** Start of inlined file: residue_16.h ***/
  139427. static static_bookblock _resbook_16s_0={
  139428. {
  139429. {0},
  139430. {0,0,&_16c0_s_p1_0},
  139431. {0,0,&_16c0_s_p2_0},
  139432. {0,0,&_16c0_s_p3_0},
  139433. {0,0,&_16c0_s_p4_0},
  139434. {0,0,&_16c0_s_p5_0},
  139435. {0,0,&_16c0_s_p6_0},
  139436. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139437. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139438. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139439. }
  139440. };
  139441. static static_bookblock _resbook_16s_1={
  139442. {
  139443. {0},
  139444. {0,0,&_16c1_s_p1_0},
  139445. {0,0,&_16c1_s_p2_0},
  139446. {0,0,&_16c1_s_p3_0},
  139447. {0,0,&_16c1_s_p4_0},
  139448. {0,0,&_16c1_s_p5_0},
  139449. {0,0,&_16c1_s_p6_0},
  139450. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139451. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139452. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139453. }
  139454. };
  139455. static static_bookblock _resbook_16s_2={
  139456. {
  139457. {0},
  139458. {0,0,&_16c2_s_p1_0},
  139459. {0,0,&_16c2_s_p2_0},
  139460. {0,0,&_16c2_s_p3_0},
  139461. {0,0,&_16c2_s_p4_0},
  139462. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139463. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139464. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139465. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139466. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139467. }
  139468. };
  139469. static vorbis_residue_template _res_16s_0[]={
  139470. {2,0, &_residue_44_mid,
  139471. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139472. &_resbook_16s_0,&_resbook_16s_0},
  139473. };
  139474. static vorbis_residue_template _res_16s_1[]={
  139475. {2,0, &_residue_44_mid,
  139476. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139477. &_resbook_16s_1,&_resbook_16s_1},
  139478. {2,0, &_residue_44_mid,
  139479. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139480. &_resbook_16s_1,&_resbook_16s_1}
  139481. };
  139482. static vorbis_residue_template _res_16s_2[]={
  139483. {2,0, &_residue_44_high,
  139484. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139485. &_resbook_16s_2,&_resbook_16s_2},
  139486. {2,0, &_residue_44_high,
  139487. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139488. &_resbook_16s_2,&_resbook_16s_2}
  139489. };
  139490. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139491. { _map_nominal, _res_16s_0 }, /* 0 */
  139492. { _map_nominal, _res_16s_1 }, /* 1 */
  139493. { _map_nominal, _res_16s_2 }, /* 2 */
  139494. };
  139495. static static_bookblock _resbook_16u_0={
  139496. {
  139497. {0},
  139498. {0,0,&_16u0__p1_0},
  139499. {0,0,&_16u0__p2_0},
  139500. {0,0,&_16u0__p3_0},
  139501. {0,0,&_16u0__p4_0},
  139502. {0,0,&_16u0__p5_0},
  139503. {&_16u0__p6_0,&_16u0__p6_1},
  139504. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139505. }
  139506. };
  139507. static static_bookblock _resbook_16u_1={
  139508. {
  139509. {0},
  139510. {0,0,&_16u1__p1_0},
  139511. {0,0,&_16u1__p2_0},
  139512. {0,0,&_16u1__p3_0},
  139513. {0,0,&_16u1__p4_0},
  139514. {0,0,&_16u1__p5_0},
  139515. {0,0,&_16u1__p6_0},
  139516. {&_16u1__p7_0,&_16u1__p7_1},
  139517. {&_16u1__p8_0,&_16u1__p8_1},
  139518. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139519. }
  139520. };
  139521. static static_bookblock _resbook_16u_2={
  139522. {
  139523. {0},
  139524. {0,0,&_16u2_p1_0},
  139525. {0,0,&_16u2_p2_0},
  139526. {0,0,&_16u2_p3_0},
  139527. {0,0,&_16u2_p4_0},
  139528. {&_16u2_p5_0,&_16u2_p5_1},
  139529. {&_16u2_p6_0,&_16u2_p6_1},
  139530. {&_16u2_p7_0,&_16u2_p7_1},
  139531. {&_16u2_p8_0,&_16u2_p8_1},
  139532. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139533. }
  139534. };
  139535. static vorbis_residue_template _res_16u_0[]={
  139536. {1,0, &_residue_44_low_un,
  139537. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139538. &_resbook_16u_0,&_resbook_16u_0},
  139539. };
  139540. static vorbis_residue_template _res_16u_1[]={
  139541. {1,0, &_residue_44_mid_un,
  139542. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139543. &_resbook_16u_1,&_resbook_16u_1},
  139544. {1,0, &_residue_44_mid_un,
  139545. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139546. &_resbook_16u_1,&_resbook_16u_1}
  139547. };
  139548. static vorbis_residue_template _res_16u_2[]={
  139549. {1,0, &_residue_44_hi_un,
  139550. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139551. &_resbook_16u_2,&_resbook_16u_2},
  139552. {1,0, &_residue_44_hi_un,
  139553. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139554. &_resbook_16u_2,&_resbook_16u_2}
  139555. };
  139556. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139557. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139558. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139559. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139560. };
  139561. /*** End of inlined file: residue_16.h ***/
  139562. static int blocksize_16_short[3]={
  139563. 1024,512,512
  139564. };
  139565. static int blocksize_16_long[3]={
  139566. 1024,1024,1024
  139567. };
  139568. static int _floor_mapping_16_short[3]={
  139569. 9,3,3
  139570. };
  139571. static int _floor_mapping_16[3]={
  139572. 9,9,9
  139573. };
  139574. static double rate_mapping_16[4]={
  139575. 12000.,20000.,44000.,86000.
  139576. };
  139577. static double rate_mapping_16_uncoupled[4]={
  139578. 16000.,28000.,64000.,100000.
  139579. };
  139580. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139581. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139582. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139583. ve_setup_data_template ve_setup_16_stereo={
  139584. 3,
  139585. rate_mapping_16,
  139586. quality_mapping_16,
  139587. 2,
  139588. 15000,
  139589. 19000,
  139590. blocksize_16_short,
  139591. blocksize_16_long,
  139592. _psy_tone_masteratt_16,
  139593. _psy_tone_0dB,
  139594. _psy_tone_suppress,
  139595. _vp_tonemask_adj_16,
  139596. _vp_tonemask_adj_16,
  139597. _vp_tonemask_adj_16,
  139598. _psy_noiseguards_8,
  139599. _psy_noisebias_16_impulse,
  139600. _psy_noisebias_16_short,
  139601. _psy_noisebias_16_short,
  139602. _psy_noisebias_16,
  139603. _psy_noise_suppress,
  139604. _psy_compand_8,
  139605. _psy_compand_16_mapping,
  139606. _psy_compand_16_mapping,
  139607. {_noise_start_16,_noise_start_16},
  139608. { _noise_part_16, _noise_part_16},
  139609. _noise_thresh_16,
  139610. _psy_ath_floater_16,
  139611. _psy_ath_abs_16,
  139612. _psy_lowpass_16,
  139613. _psy_global_44,
  139614. _global_mapping_16,
  139615. _psy_stereo_modes_16,
  139616. _floor_books,
  139617. _floor,
  139618. _floor_mapping_16_short,
  139619. _floor_mapping_16,
  139620. _mapres_template_16_stereo
  139621. };
  139622. ve_setup_data_template ve_setup_16_uncoupled={
  139623. 3,
  139624. rate_mapping_16_uncoupled,
  139625. quality_mapping_16,
  139626. -1,
  139627. 15000,
  139628. 19000,
  139629. blocksize_16_short,
  139630. blocksize_16_long,
  139631. _psy_tone_masteratt_16,
  139632. _psy_tone_0dB,
  139633. _psy_tone_suppress,
  139634. _vp_tonemask_adj_16,
  139635. _vp_tonemask_adj_16,
  139636. _vp_tonemask_adj_16,
  139637. _psy_noiseguards_8,
  139638. _psy_noisebias_16_impulse,
  139639. _psy_noisebias_16_short,
  139640. _psy_noisebias_16_short,
  139641. _psy_noisebias_16,
  139642. _psy_noise_suppress,
  139643. _psy_compand_8,
  139644. _psy_compand_16_mapping,
  139645. _psy_compand_16_mapping,
  139646. {_noise_start_16,_noise_start_16},
  139647. { _noise_part_16, _noise_part_16},
  139648. _noise_thresh_16,
  139649. _psy_ath_floater_16,
  139650. _psy_ath_abs_16,
  139651. _psy_lowpass_16,
  139652. _psy_global_44,
  139653. _global_mapping_16,
  139654. _psy_stereo_modes_16,
  139655. _floor_books,
  139656. _floor,
  139657. _floor_mapping_16_short,
  139658. _floor_mapping_16,
  139659. _mapres_template_16_uncoupled
  139660. };
  139661. /*** End of inlined file: setup_16.h ***/
  139662. /*** Start of inlined file: setup_22.h ***/
  139663. static double rate_mapping_22[4]={
  139664. 15000.,20000.,44000.,86000.
  139665. };
  139666. static double rate_mapping_22_uncoupled[4]={
  139667. 16000.,28000.,50000.,90000.
  139668. };
  139669. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139670. ve_setup_data_template ve_setup_22_stereo={
  139671. 3,
  139672. rate_mapping_22,
  139673. quality_mapping_16,
  139674. 2,
  139675. 19000,
  139676. 26000,
  139677. blocksize_16_short,
  139678. blocksize_16_long,
  139679. _psy_tone_masteratt_16,
  139680. _psy_tone_0dB,
  139681. _psy_tone_suppress,
  139682. _vp_tonemask_adj_16,
  139683. _vp_tonemask_adj_16,
  139684. _vp_tonemask_adj_16,
  139685. _psy_noiseguards_8,
  139686. _psy_noisebias_16_impulse,
  139687. _psy_noisebias_16_short,
  139688. _psy_noisebias_16_short,
  139689. _psy_noisebias_16,
  139690. _psy_noise_suppress,
  139691. _psy_compand_8,
  139692. _psy_compand_8_mapping,
  139693. _psy_compand_8_mapping,
  139694. {_noise_start_16,_noise_start_16},
  139695. { _noise_part_16, _noise_part_16},
  139696. _noise_thresh_16,
  139697. _psy_ath_floater_16,
  139698. _psy_ath_abs_16,
  139699. _psy_lowpass_22,
  139700. _psy_global_44,
  139701. _global_mapping_16,
  139702. _psy_stereo_modes_16,
  139703. _floor_books,
  139704. _floor,
  139705. _floor_mapping_16_short,
  139706. _floor_mapping_16,
  139707. _mapres_template_16_stereo
  139708. };
  139709. ve_setup_data_template ve_setup_22_uncoupled={
  139710. 3,
  139711. rate_mapping_22_uncoupled,
  139712. quality_mapping_16,
  139713. -1,
  139714. 19000,
  139715. 26000,
  139716. blocksize_16_short,
  139717. blocksize_16_long,
  139718. _psy_tone_masteratt_16,
  139719. _psy_tone_0dB,
  139720. _psy_tone_suppress,
  139721. _vp_tonemask_adj_16,
  139722. _vp_tonemask_adj_16,
  139723. _vp_tonemask_adj_16,
  139724. _psy_noiseguards_8,
  139725. _psy_noisebias_16_impulse,
  139726. _psy_noisebias_16_short,
  139727. _psy_noisebias_16_short,
  139728. _psy_noisebias_16,
  139729. _psy_noise_suppress,
  139730. _psy_compand_8,
  139731. _psy_compand_8_mapping,
  139732. _psy_compand_8_mapping,
  139733. {_noise_start_16,_noise_start_16},
  139734. { _noise_part_16, _noise_part_16},
  139735. _noise_thresh_16,
  139736. _psy_ath_floater_16,
  139737. _psy_ath_abs_16,
  139738. _psy_lowpass_22,
  139739. _psy_global_44,
  139740. _global_mapping_16,
  139741. _psy_stereo_modes_16,
  139742. _floor_books,
  139743. _floor,
  139744. _floor_mapping_16_short,
  139745. _floor_mapping_16,
  139746. _mapres_template_16_uncoupled
  139747. };
  139748. /*** End of inlined file: setup_22.h ***/
  139749. /*** Start of inlined file: setup_X.h ***/
  139750. static double rate_mapping_X[12]={
  139751. -1.,-1.,-1.,-1.,-1.,-1.,
  139752. -1.,-1.,-1.,-1.,-1.,-1.
  139753. };
  139754. ve_setup_data_template ve_setup_X_stereo={
  139755. 11,
  139756. rate_mapping_X,
  139757. quality_mapping_44,
  139758. 2,
  139759. 50000,
  139760. 200000,
  139761. blocksize_short_44,
  139762. blocksize_long_44,
  139763. _psy_tone_masteratt_44,
  139764. _psy_tone_0dB,
  139765. _psy_tone_suppress,
  139766. _vp_tonemask_adj_otherblock,
  139767. _vp_tonemask_adj_longblock,
  139768. _vp_tonemask_adj_otherblock,
  139769. _psy_noiseguards_44,
  139770. _psy_noisebias_impulse,
  139771. _psy_noisebias_padding,
  139772. _psy_noisebias_trans,
  139773. _psy_noisebias_long,
  139774. _psy_noise_suppress,
  139775. _psy_compand_44,
  139776. _psy_compand_short_mapping,
  139777. _psy_compand_long_mapping,
  139778. {_noise_start_short_44,_noise_start_long_44},
  139779. {_noise_part_short_44,_noise_part_long_44},
  139780. _noise_thresh_44,
  139781. _psy_ath_floater,
  139782. _psy_ath_abs,
  139783. _psy_lowpass_44,
  139784. _psy_global_44,
  139785. _global_mapping_44,
  139786. _psy_stereo_modes_44,
  139787. _floor_books,
  139788. _floor,
  139789. _floor_short_mapping_44,
  139790. _floor_long_mapping_44,
  139791. _mapres_template_44_stereo
  139792. };
  139793. ve_setup_data_template ve_setup_X_uncoupled={
  139794. 11,
  139795. rate_mapping_X,
  139796. quality_mapping_44,
  139797. -1,
  139798. 50000,
  139799. 200000,
  139800. blocksize_short_44,
  139801. blocksize_long_44,
  139802. _psy_tone_masteratt_44,
  139803. _psy_tone_0dB,
  139804. _psy_tone_suppress,
  139805. _vp_tonemask_adj_otherblock,
  139806. _vp_tonemask_adj_longblock,
  139807. _vp_tonemask_adj_otherblock,
  139808. _psy_noiseguards_44,
  139809. _psy_noisebias_impulse,
  139810. _psy_noisebias_padding,
  139811. _psy_noisebias_trans,
  139812. _psy_noisebias_long,
  139813. _psy_noise_suppress,
  139814. _psy_compand_44,
  139815. _psy_compand_short_mapping,
  139816. _psy_compand_long_mapping,
  139817. {_noise_start_short_44,_noise_start_long_44},
  139818. {_noise_part_short_44,_noise_part_long_44},
  139819. _noise_thresh_44,
  139820. _psy_ath_floater,
  139821. _psy_ath_abs,
  139822. _psy_lowpass_44,
  139823. _psy_global_44,
  139824. _global_mapping_44,
  139825. NULL,
  139826. _floor_books,
  139827. _floor,
  139828. _floor_short_mapping_44,
  139829. _floor_long_mapping_44,
  139830. _mapres_template_44_uncoupled
  139831. };
  139832. ve_setup_data_template ve_setup_XX_stereo={
  139833. 2,
  139834. rate_mapping_X,
  139835. quality_mapping_8,
  139836. 2,
  139837. 0,
  139838. 8000,
  139839. blocksize_8,
  139840. blocksize_8,
  139841. _psy_tone_masteratt_8,
  139842. _psy_tone_0dB,
  139843. _psy_tone_suppress,
  139844. _vp_tonemask_adj_8,
  139845. NULL,
  139846. _vp_tonemask_adj_8,
  139847. _psy_noiseguards_8,
  139848. _psy_noisebias_8,
  139849. _psy_noisebias_8,
  139850. NULL,
  139851. NULL,
  139852. _psy_noise_suppress,
  139853. _psy_compand_8,
  139854. _psy_compand_8_mapping,
  139855. NULL,
  139856. {_noise_start_8,_noise_start_8},
  139857. {_noise_part_8,_noise_part_8},
  139858. _noise_thresh_5only,
  139859. _psy_ath_floater_8,
  139860. _psy_ath_abs_8,
  139861. _psy_lowpass_8,
  139862. _psy_global_44,
  139863. _global_mapping_8,
  139864. _psy_stereo_modes_8,
  139865. _floor_books,
  139866. _floor,
  139867. _floor_mapping_8,
  139868. NULL,
  139869. _mapres_template_8_stereo
  139870. };
  139871. ve_setup_data_template ve_setup_XX_uncoupled={
  139872. 2,
  139873. rate_mapping_X,
  139874. quality_mapping_8,
  139875. -1,
  139876. 0,
  139877. 8000,
  139878. blocksize_8,
  139879. blocksize_8,
  139880. _psy_tone_masteratt_8,
  139881. _psy_tone_0dB,
  139882. _psy_tone_suppress,
  139883. _vp_tonemask_adj_8,
  139884. NULL,
  139885. _vp_tonemask_adj_8,
  139886. _psy_noiseguards_8,
  139887. _psy_noisebias_8,
  139888. _psy_noisebias_8,
  139889. NULL,
  139890. NULL,
  139891. _psy_noise_suppress,
  139892. _psy_compand_8,
  139893. _psy_compand_8_mapping,
  139894. NULL,
  139895. {_noise_start_8,_noise_start_8},
  139896. {_noise_part_8,_noise_part_8},
  139897. _noise_thresh_5only,
  139898. _psy_ath_floater_8,
  139899. _psy_ath_abs_8,
  139900. _psy_lowpass_8,
  139901. _psy_global_44,
  139902. _global_mapping_8,
  139903. _psy_stereo_modes_8,
  139904. _floor_books,
  139905. _floor,
  139906. _floor_mapping_8,
  139907. NULL,
  139908. _mapres_template_8_uncoupled
  139909. };
  139910. /*** End of inlined file: setup_X.h ***/
  139911. static ve_setup_data_template *setup_list[]={
  139912. &ve_setup_44_stereo,
  139913. &ve_setup_44_uncoupled,
  139914. &ve_setup_32_stereo,
  139915. &ve_setup_32_uncoupled,
  139916. &ve_setup_22_stereo,
  139917. &ve_setup_22_uncoupled,
  139918. &ve_setup_16_stereo,
  139919. &ve_setup_16_uncoupled,
  139920. &ve_setup_11_stereo,
  139921. &ve_setup_11_uncoupled,
  139922. &ve_setup_8_stereo,
  139923. &ve_setup_8_uncoupled,
  139924. &ve_setup_X_stereo,
  139925. &ve_setup_X_uncoupled,
  139926. &ve_setup_XX_stereo,
  139927. &ve_setup_XX_uncoupled,
  139928. 0
  139929. };
  139930. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  139931. if(vi && vi->codec_setup){
  139932. vi->version=0;
  139933. vi->channels=ch;
  139934. vi->rate=rate;
  139935. return(0);
  139936. }
  139937. return(OV_EINVAL);
  139938. }
  139939. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  139940. static_codebook ***books,
  139941. vorbis_info_floor1 *in,
  139942. int *x){
  139943. int i,k,is=s;
  139944. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  139945. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139946. memcpy(f,in+x[is],sizeof(*f));
  139947. f->n=ci->blocksizes[block]>>1;
  139948. {
  139949. int partitions=f->partitions;
  139950. int maxclass=-1;
  139951. int maxbook=-1;
  139952. for(i=0;i<partitions;i++)
  139953. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  139954. for(i=0;i<=maxclass;i++){
  139955. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  139956. f->class_book[i]+=ci->books;
  139957. for(k=0;k<(1<<f->class_subs[i]);k++){
  139958. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  139959. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  139960. }
  139961. }
  139962. for(i=0;i<=maxbook;i++)
  139963. ci->book_param[ci->books++]=books[x[is]][i];
  139964. }
  139965. ci->floor_type[ci->floors]=1;
  139966. ci->floor_param[ci->floors]=f;
  139967. ci->floors++;
  139968. return;
  139969. }
  139970. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  139971. vorbis_info_psy_global *in,
  139972. double *x){
  139973. int i,is=s;
  139974. double ds=s-is;
  139975. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139976. vorbis_info_psy_global *g=&ci->psy_g_param;
  139977. memcpy(g,in+(int)x[is],sizeof(*g));
  139978. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139979. is=(int)ds;
  139980. ds-=is;
  139981. if(ds==0 && is>0){
  139982. is--;
  139983. ds=1.;
  139984. }
  139985. for(i=0;i<4;i++){
  139986. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  139987. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  139988. }
  139989. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  139990. return;
  139991. }
  139992. static void vorbis_encode_global_stereo(vorbis_info *vi,
  139993. highlevel_encode_setup *hi,
  139994. adj_stereo *p){
  139995. float s=hi->stereo_point_setting;
  139996. int i,is=s;
  139997. double ds=s-is;
  139998. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139999. vorbis_info_psy_global *g=&ci->psy_g_param;
  140000. if(p){
  140001. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140002. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140003. if(hi->managed){
  140004. for(i=0;i<PACKETBLOBS;i++){
  140005. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140006. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140007. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140008. g->coupling_pkHz[i]=kHz;
  140009. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140010. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140011. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140012. }
  140013. }else{
  140014. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140015. for(i=0;i<PACKETBLOBS;i++){
  140016. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140017. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140018. g->coupling_pkHz[i]=kHz;
  140019. }
  140020. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140021. for(i=0;i<PACKETBLOBS;i++){
  140022. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140023. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140024. }
  140025. }
  140026. }else{
  140027. for(i=0;i<PACKETBLOBS;i++){
  140028. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140029. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140030. }
  140031. }
  140032. return;
  140033. }
  140034. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140035. int *nn_start,
  140036. int *nn_partition,
  140037. double *nn_thresh,
  140038. int block){
  140039. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140040. vorbis_info_psy *p=ci->psy_param[block];
  140041. highlevel_encode_setup *hi=&ci->hi;
  140042. int is=s;
  140043. if(block>=ci->psys)
  140044. ci->psys=block+1;
  140045. if(!p){
  140046. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140047. ci->psy_param[block]=p;
  140048. }
  140049. memcpy(p,&_psy_info_template,sizeof(*p));
  140050. p->blockflag=block>>1;
  140051. if(hi->noise_normalize_p){
  140052. p->normal_channel_p=1;
  140053. p->normal_point_p=1;
  140054. p->normal_start=nn_start[is];
  140055. p->normal_partition=nn_partition[is];
  140056. p->normal_thresh=nn_thresh[is];
  140057. }
  140058. return;
  140059. }
  140060. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140061. att3 *att,
  140062. int *max,
  140063. vp_adjblock *in){
  140064. int i,is=s;
  140065. double ds=s-is;
  140066. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140067. vorbis_info_psy *p=ci->psy_param[block];
  140068. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140069. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140070. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140071. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140072. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140073. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140074. for(i=0;i<P_BANDS;i++)
  140075. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140076. return;
  140077. }
  140078. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140079. compandblock *in, double *x){
  140080. int i,is=s;
  140081. double ds=s-is;
  140082. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140083. vorbis_info_psy *p=ci->psy_param[block];
  140084. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140085. is=(int)ds;
  140086. ds-=is;
  140087. if(ds==0 && is>0){
  140088. is--;
  140089. ds=1.;
  140090. }
  140091. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140092. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140093. return;
  140094. }
  140095. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140096. int *suppress){
  140097. int is=s;
  140098. double ds=s-is;
  140099. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140100. vorbis_info_psy *p=ci->psy_param[block];
  140101. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140102. return;
  140103. }
  140104. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140105. int *suppress,
  140106. noise3 *in,
  140107. noiseguard *guard,
  140108. double userbias){
  140109. int i,is=s,j;
  140110. double ds=s-is;
  140111. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140112. vorbis_info_psy *p=ci->psy_param[block];
  140113. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140114. p->noisewindowlomin=guard[block].lo;
  140115. p->noisewindowhimin=guard[block].hi;
  140116. p->noisewindowfixed=guard[block].fixed;
  140117. for(j=0;j<P_NOISECURVES;j++)
  140118. for(i=0;i<P_BANDS;i++)
  140119. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140120. for(j=0;j<P_NOISECURVES;j++){
  140121. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140122. for(i=0;i<P_BANDS;i++){
  140123. p->noiseoff[j][i]+=userbias;
  140124. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140125. }
  140126. }
  140127. return;
  140128. }
  140129. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140130. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140131. vorbis_info_psy *p=ci->psy_param[block];
  140132. p->ath_adjatt=ci->hi.ath_floating_dB;
  140133. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140134. return;
  140135. }
  140136. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140137. int i;
  140138. for(i=0;i<ci->books;i++)
  140139. if(ci->book_param[i]==book)return(i);
  140140. return(ci->books++);
  140141. }
  140142. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140143. int *shortb,int *longb){
  140144. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140145. int is=s;
  140146. int blockshort=shortb[is];
  140147. int blocklong=longb[is];
  140148. ci->blocksizes[0]=blockshort;
  140149. ci->blocksizes[1]=blocklong;
  140150. }
  140151. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140152. int number, int block,
  140153. vorbis_residue_template *res){
  140154. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140155. int i,n;
  140156. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140157. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140158. memcpy(r,res->res,sizeof(*r));
  140159. if(ci->residues<=number)ci->residues=number+1;
  140160. switch(ci->blocksizes[block]){
  140161. case 64:case 128:case 256:
  140162. r->grouping=16;
  140163. break;
  140164. default:
  140165. r->grouping=32;
  140166. break;
  140167. }
  140168. ci->residue_type[number]=res->res_type;
  140169. n=r->end=ci->blocksizes[block]>>1;
  140170. if(res->res_type==2)
  140171. n=r->end*=vi->channels;
  140172. {
  140173. int booklist=0,k;
  140174. if(ci->hi.managed){
  140175. for(i=0;i<r->partitions;i++)
  140176. for(k=0;k<3;k++)
  140177. if(res->books_base_managed->books[i][k])
  140178. r->secondstages[i]|=(1<<k);
  140179. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140180. ci->book_param[r->groupbook]=res->book_aux_managed;
  140181. for(i=0;i<r->partitions;i++){
  140182. for(k=0;k<3;k++){
  140183. if(res->books_base_managed->books[i][k]){
  140184. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140185. r->booklist[booklist++]=bookid;
  140186. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140187. }
  140188. }
  140189. }
  140190. }else{
  140191. for(i=0;i<r->partitions;i++)
  140192. for(k=0;k<3;k++)
  140193. if(res->books_base->books[i][k])
  140194. r->secondstages[i]|=(1<<k);
  140195. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140196. ci->book_param[r->groupbook]=res->book_aux;
  140197. for(i=0;i<r->partitions;i++){
  140198. for(k=0;k<3;k++){
  140199. if(res->books_base->books[i][k]){
  140200. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140201. r->booklist[booklist++]=bookid;
  140202. ci->book_param[bookid]=res->books_base->books[i][k];
  140203. }
  140204. }
  140205. }
  140206. }
  140207. }
  140208. {
  140209. double freq=ci->hi.lowpass_kHz*1000.;
  140210. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140211. double nyq=vi->rate/2.;
  140212. long blocksize=ci->blocksizes[block]>>1;
  140213. if(freq>nyq)freq=nyq;
  140214. f->n=freq/nyq*blocksize;
  140215. if(res->limit_type){
  140216. if(ci->hi.managed)
  140217. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140218. else
  140219. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140220. if(freq>nyq)freq=nyq;
  140221. }
  140222. if(ci->residue_type[block]==2)
  140223. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140224. r->grouping;
  140225. else
  140226. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140227. r->grouping;
  140228. }
  140229. }
  140230. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140231. vorbis_mapping_template *maps){
  140232. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140233. int i,j,is=s,modes=2;
  140234. vorbis_info_mapping0 *map=maps[is].map;
  140235. vorbis_info_mode *mode=_mode_template;
  140236. vorbis_residue_template *res=maps[is].res;
  140237. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140238. for(i=0;i<modes;i++){
  140239. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140240. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140241. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140242. if(i>=ci->modes)ci->modes=i+1;
  140243. ci->map_type[i]=0;
  140244. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140245. if(i>=ci->maps)ci->maps=i+1;
  140246. for(j=0;j<map[i].submaps;j++)
  140247. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140248. ,res+map[i].residuesubmap[j]);
  140249. }
  140250. }
  140251. static double setting_to_approx_bitrate(vorbis_info *vi){
  140252. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140253. highlevel_encode_setup *hi=&ci->hi;
  140254. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140255. int is=hi->base_setting;
  140256. double ds=hi->base_setting-is;
  140257. int ch=vi->channels;
  140258. double *r=setup->rate_mapping;
  140259. if(r==NULL)
  140260. return(-1);
  140261. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140262. }
  140263. static void get_setup_template(vorbis_info *vi,
  140264. long ch,long srate,
  140265. double req,int q_or_bitrate){
  140266. int i=0,j;
  140267. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140268. highlevel_encode_setup *hi=&ci->hi;
  140269. if(q_or_bitrate)req/=ch;
  140270. while(setup_list[i]){
  140271. if(setup_list[i]->coupling_restriction==-1 ||
  140272. setup_list[i]->coupling_restriction==ch){
  140273. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140274. srate<=setup_list[i]->samplerate_max_restriction){
  140275. int mappings=setup_list[i]->mappings;
  140276. double *map=(q_or_bitrate?
  140277. setup_list[i]->rate_mapping:
  140278. setup_list[i]->quality_mapping);
  140279. if(req<map[0]){++i;continue;}
  140280. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140281. for(j=0;j<mappings;j++)
  140282. if(req>=map[j] && req<map[j+1])break;
  140283. hi->setup=setup_list[i];
  140284. if(j==mappings)
  140285. hi->base_setting=j-.001;
  140286. else{
  140287. float low=map[j];
  140288. float high=map[j+1];
  140289. float del=(req-low)/(high-low);
  140290. hi->base_setting=j+del;
  140291. }
  140292. return;
  140293. }
  140294. }
  140295. i++;
  140296. }
  140297. hi->setup=NULL;
  140298. }
  140299. int vorbis_encode_setup_init(vorbis_info *vi){
  140300. int i0=0,singleblock=0;
  140301. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140302. ve_setup_data_template *setup=NULL;
  140303. highlevel_encode_setup *hi=&ci->hi;
  140304. if(ci==NULL)return(OV_EINVAL);
  140305. if(!hi->impulse_block_p)i0=1;
  140306. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140307. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140308. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140309. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140310. setup=(ve_setup_data_template *)hi->setup;
  140311. if(setup==NULL)return(OV_EINVAL);
  140312. hi->set_in_stone=1;
  140313. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140314. setup->blocksize_short,
  140315. setup->blocksize_long);
  140316. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140317. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140318. setup->floor_books,
  140319. setup->floor_params,
  140320. setup->floor_short_mapping);
  140321. if(!singleblock)
  140322. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140323. setup->floor_books,
  140324. setup->floor_params,
  140325. setup->floor_long_mapping);
  140326. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140327. setup->global_params,
  140328. setup->global_mapping);
  140329. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140330. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140331. setup->psy_noise_normal_start[0],
  140332. setup->psy_noise_normal_partition[0],
  140333. setup->psy_noise_normal_thresh,
  140334. 0);
  140335. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140336. setup->psy_noise_normal_start[0],
  140337. setup->psy_noise_normal_partition[0],
  140338. setup->psy_noise_normal_thresh,
  140339. 1);
  140340. if(!singleblock){
  140341. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140342. setup->psy_noise_normal_start[1],
  140343. setup->psy_noise_normal_partition[1],
  140344. setup->psy_noise_normal_thresh,
  140345. 2);
  140346. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140347. setup->psy_noise_normal_start[1],
  140348. setup->psy_noise_normal_partition[1],
  140349. setup->psy_noise_normal_thresh,
  140350. 3);
  140351. }
  140352. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140353. setup->psy_tone_masteratt,
  140354. setup->psy_tone_0dB,
  140355. setup->psy_tone_adj_impulse);
  140356. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140357. setup->psy_tone_masteratt,
  140358. setup->psy_tone_0dB,
  140359. setup->psy_tone_adj_other);
  140360. if(!singleblock){
  140361. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140362. setup->psy_tone_masteratt,
  140363. setup->psy_tone_0dB,
  140364. setup->psy_tone_adj_other);
  140365. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140366. setup->psy_tone_masteratt,
  140367. setup->psy_tone_0dB,
  140368. setup->psy_tone_adj_long);
  140369. }
  140370. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140371. setup->psy_noise_compand,
  140372. setup->psy_noise_compand_short_mapping);
  140373. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140374. setup->psy_noise_compand,
  140375. setup->psy_noise_compand_short_mapping);
  140376. if(!singleblock){
  140377. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140378. setup->psy_noise_compand,
  140379. setup->psy_noise_compand_long_mapping);
  140380. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140381. setup->psy_noise_compand,
  140382. setup->psy_noise_compand_long_mapping);
  140383. }
  140384. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140385. setup->psy_tone_dBsuppress);
  140386. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140387. setup->psy_tone_dBsuppress);
  140388. if(!singleblock){
  140389. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140390. setup->psy_tone_dBsuppress);
  140391. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140392. setup->psy_tone_dBsuppress);
  140393. }
  140394. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140395. setup->psy_noise_dBsuppress,
  140396. setup->psy_noise_bias_impulse,
  140397. setup->psy_noiseguards,
  140398. (i0==0?hi->impulse_noisetune:0.));
  140399. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140400. setup->psy_noise_dBsuppress,
  140401. setup->psy_noise_bias_padding,
  140402. setup->psy_noiseguards,0.);
  140403. if(!singleblock){
  140404. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140405. setup->psy_noise_dBsuppress,
  140406. setup->psy_noise_bias_trans,
  140407. setup->psy_noiseguards,0.);
  140408. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140409. setup->psy_noise_dBsuppress,
  140410. setup->psy_noise_bias_long,
  140411. setup->psy_noiseguards,0.);
  140412. }
  140413. vorbis_encode_ath_setup(vi,0);
  140414. vorbis_encode_ath_setup(vi,1);
  140415. if(!singleblock){
  140416. vorbis_encode_ath_setup(vi,2);
  140417. vorbis_encode_ath_setup(vi,3);
  140418. }
  140419. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140420. if(hi->bitrate_av>0)
  140421. vi->bitrate_nominal=hi->bitrate_av;
  140422. else{
  140423. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140424. }
  140425. vi->bitrate_lower=hi->bitrate_min;
  140426. vi->bitrate_upper=hi->bitrate_max;
  140427. if(hi->bitrate_av)
  140428. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140429. else
  140430. vi->bitrate_window=0.;
  140431. if(hi->managed){
  140432. ci->bi.avg_rate=hi->bitrate_av;
  140433. ci->bi.min_rate=hi->bitrate_min;
  140434. ci->bi.max_rate=hi->bitrate_max;
  140435. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140436. ci->bi.reservoir_bias=
  140437. hi->bitrate_reservoir_bias;
  140438. ci->bi.slew_damp=hi->bitrate_av_damp;
  140439. }
  140440. return(0);
  140441. }
  140442. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140443. long channels,
  140444. long rate){
  140445. int ret=0,i,is;
  140446. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140447. highlevel_encode_setup *hi=&ci->hi;
  140448. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140449. double ds;
  140450. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140451. if(ret)return(ret);
  140452. is=hi->base_setting;
  140453. ds=hi->base_setting-is;
  140454. hi->short_setting=hi->base_setting;
  140455. hi->long_setting=hi->base_setting;
  140456. hi->managed=0;
  140457. hi->impulse_block_p=1;
  140458. hi->noise_normalize_p=1;
  140459. hi->stereo_point_setting=hi->base_setting;
  140460. hi->lowpass_kHz=
  140461. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140462. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140463. setup->psy_ath_float[is+1]*ds;
  140464. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140465. setup->psy_ath_abs[is+1]*ds;
  140466. hi->amplitude_track_dBpersec=-6.;
  140467. hi->trigger_setting=hi->base_setting;
  140468. for(i=0;i<4;i++){
  140469. hi->block[i].tone_mask_setting=hi->base_setting;
  140470. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140471. hi->block[i].noise_bias_setting=hi->base_setting;
  140472. hi->block[i].noise_compand_setting=hi->base_setting;
  140473. }
  140474. return(ret);
  140475. }
  140476. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140477. long channels,
  140478. long rate,
  140479. float quality){
  140480. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140481. highlevel_encode_setup *hi=&ci->hi;
  140482. quality+=.0000001;
  140483. if(quality>=1.)quality=.9999;
  140484. get_setup_template(vi,channels,rate,quality,0);
  140485. if(!hi->setup)return OV_EIMPL;
  140486. return vorbis_encode_setup_setting(vi,channels,rate);
  140487. }
  140488. int vorbis_encode_init_vbr(vorbis_info *vi,
  140489. long channels,
  140490. long rate,
  140491. float base_quality /* 0. to 1. */
  140492. ){
  140493. int ret=0;
  140494. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140495. if(ret){
  140496. vorbis_info_clear(vi);
  140497. return ret;
  140498. }
  140499. ret=vorbis_encode_setup_init(vi);
  140500. if(ret)
  140501. vorbis_info_clear(vi);
  140502. return(ret);
  140503. }
  140504. int vorbis_encode_setup_managed(vorbis_info *vi,
  140505. long channels,
  140506. long rate,
  140507. long max_bitrate,
  140508. long nominal_bitrate,
  140509. long min_bitrate){
  140510. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140511. highlevel_encode_setup *hi=&ci->hi;
  140512. double tnominal=nominal_bitrate;
  140513. int ret=0;
  140514. if(nominal_bitrate<=0.){
  140515. if(max_bitrate>0.){
  140516. if(min_bitrate>0.)
  140517. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140518. else
  140519. nominal_bitrate=max_bitrate*.875;
  140520. }else{
  140521. if(min_bitrate>0.){
  140522. nominal_bitrate=min_bitrate;
  140523. }else{
  140524. return(OV_EINVAL);
  140525. }
  140526. }
  140527. }
  140528. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140529. if(!hi->setup)return OV_EIMPL;
  140530. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140531. if(ret){
  140532. vorbis_info_clear(vi);
  140533. return ret;
  140534. }
  140535. hi->managed=1;
  140536. hi->bitrate_min=min_bitrate;
  140537. hi->bitrate_max=max_bitrate;
  140538. hi->bitrate_av=tnominal;
  140539. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140540. hi->bitrate_reservoir=nominal_bitrate*2;
  140541. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140542. return(ret);
  140543. }
  140544. int vorbis_encode_init(vorbis_info *vi,
  140545. long channels,
  140546. long rate,
  140547. long max_bitrate,
  140548. long nominal_bitrate,
  140549. long min_bitrate){
  140550. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140551. max_bitrate,
  140552. nominal_bitrate,
  140553. min_bitrate);
  140554. if(ret){
  140555. vorbis_info_clear(vi);
  140556. return(ret);
  140557. }
  140558. ret=vorbis_encode_setup_init(vi);
  140559. if(ret)
  140560. vorbis_info_clear(vi);
  140561. return(ret);
  140562. }
  140563. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140564. if(vi){
  140565. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140566. highlevel_encode_setup *hi=&ci->hi;
  140567. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140568. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140569. switch(number){
  140570. case OV_ECTL_RATEMANAGE_GET:
  140571. {
  140572. struct ovectl_ratemanage_arg *ai=
  140573. (struct ovectl_ratemanage_arg *)arg;
  140574. ai->management_active=hi->managed;
  140575. ai->bitrate_hard_window=ai->bitrate_av_window=
  140576. (double)hi->bitrate_reservoir/vi->rate;
  140577. ai->bitrate_av_window_center=1.;
  140578. ai->bitrate_hard_min=hi->bitrate_min;
  140579. ai->bitrate_hard_max=hi->bitrate_max;
  140580. ai->bitrate_av_lo=hi->bitrate_av;
  140581. ai->bitrate_av_hi=hi->bitrate_av;
  140582. }
  140583. return(0);
  140584. case OV_ECTL_RATEMANAGE_SET:
  140585. {
  140586. struct ovectl_ratemanage_arg *ai=
  140587. (struct ovectl_ratemanage_arg *)arg;
  140588. if(ai==NULL){
  140589. hi->managed=0;
  140590. }else{
  140591. hi->managed=ai->management_active;
  140592. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140593. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140594. }
  140595. }
  140596. return 0;
  140597. case OV_ECTL_RATEMANAGE_AVG:
  140598. {
  140599. struct ovectl_ratemanage_arg *ai=
  140600. (struct ovectl_ratemanage_arg *)arg;
  140601. if(ai==NULL){
  140602. hi->bitrate_av=0;
  140603. }else{
  140604. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140605. }
  140606. }
  140607. return(0);
  140608. case OV_ECTL_RATEMANAGE_HARD:
  140609. {
  140610. struct ovectl_ratemanage_arg *ai=
  140611. (struct ovectl_ratemanage_arg *)arg;
  140612. if(ai==NULL){
  140613. hi->bitrate_min=0;
  140614. hi->bitrate_max=0;
  140615. }else{
  140616. hi->bitrate_min=ai->bitrate_hard_min;
  140617. hi->bitrate_max=ai->bitrate_hard_max;
  140618. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140619. (hi->bitrate_max+hi->bitrate_min)*.5;
  140620. }
  140621. if(hi->bitrate_reservoir<128.)
  140622. hi->bitrate_reservoir=128.;
  140623. }
  140624. return(0);
  140625. case OV_ECTL_RATEMANAGE2_GET:
  140626. {
  140627. struct ovectl_ratemanage2_arg *ai=
  140628. (struct ovectl_ratemanage2_arg *)arg;
  140629. if(ai==NULL)return OV_EINVAL;
  140630. ai->management_active=hi->managed;
  140631. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140632. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140633. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140634. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140635. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140636. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140637. }
  140638. return (0);
  140639. case OV_ECTL_RATEMANAGE2_SET:
  140640. {
  140641. struct ovectl_ratemanage2_arg *ai=
  140642. (struct ovectl_ratemanage2_arg *)arg;
  140643. if(ai==NULL){
  140644. hi->managed=0;
  140645. }else{
  140646. if(ai->bitrate_limit_min_kbps>0 &&
  140647. ai->bitrate_average_kbps>0 &&
  140648. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140649. return OV_EINVAL;
  140650. if(ai->bitrate_limit_max_kbps>0 &&
  140651. ai->bitrate_average_kbps>0 &&
  140652. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140653. return OV_EINVAL;
  140654. if(ai->bitrate_limit_min_kbps>0 &&
  140655. ai->bitrate_limit_max_kbps>0 &&
  140656. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140657. return OV_EINVAL;
  140658. if(ai->bitrate_average_damping <= 0.)
  140659. return OV_EINVAL;
  140660. if(ai->bitrate_limit_reservoir_bits < 0)
  140661. return OV_EINVAL;
  140662. if(ai->bitrate_limit_reservoir_bias < 0.)
  140663. return OV_EINVAL;
  140664. if(ai->bitrate_limit_reservoir_bias > 1.)
  140665. return OV_EINVAL;
  140666. hi->managed=ai->management_active;
  140667. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140668. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140669. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140670. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140671. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140672. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140673. }
  140674. }
  140675. return 0;
  140676. case OV_ECTL_LOWPASS_GET:
  140677. {
  140678. double *farg=(double *)arg;
  140679. *farg=hi->lowpass_kHz;
  140680. }
  140681. return(0);
  140682. case OV_ECTL_LOWPASS_SET:
  140683. {
  140684. double *farg=(double *)arg;
  140685. hi->lowpass_kHz=*farg;
  140686. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140687. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140688. }
  140689. return(0);
  140690. case OV_ECTL_IBLOCK_GET:
  140691. {
  140692. double *farg=(double *)arg;
  140693. *farg=hi->impulse_noisetune;
  140694. }
  140695. return(0);
  140696. case OV_ECTL_IBLOCK_SET:
  140697. {
  140698. double *farg=(double *)arg;
  140699. hi->impulse_noisetune=*farg;
  140700. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140701. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140702. }
  140703. return(0);
  140704. }
  140705. return(OV_EIMPL);
  140706. }
  140707. return(OV_EINVAL);
  140708. }
  140709. #endif
  140710. /*** End of inlined file: vorbisenc.c ***/
  140711. /*** Start of inlined file: vorbisfile.c ***/
  140712. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140713. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140714. // tasks..
  140715. #if JUCE_MSVC
  140716. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140717. #endif
  140718. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140719. #if JUCE_USE_OGGVORBIS
  140720. #include <stdlib.h>
  140721. #include <stdio.h>
  140722. #include <errno.h>
  140723. #include <string.h>
  140724. #include <math.h>
  140725. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140726. over 8k gets what they deserve */
  140727. static long _get_data(OggVorbis_File *vf){
  140728. errno=0;
  140729. if(vf->datasource){
  140730. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140731. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140732. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140733. if(bytes==0 && errno)return(-1);
  140734. return(bytes);
  140735. }else
  140736. return(0);
  140737. }
  140738. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140739. if(vf->datasource){
  140740. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140741. vf->offset=offset;
  140742. ogg_sync_reset(&vf->oy);
  140743. }else{
  140744. return;
  140745. }
  140746. }
  140747. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140748. ogg_int64_t boundary){
  140749. if(boundary>0)boundary+=vf->offset;
  140750. while(1){
  140751. long more;
  140752. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140753. more=ogg_sync_pageseek(&vf->oy,og);
  140754. if(more<0){
  140755. vf->offset-=more;
  140756. }else{
  140757. if(more==0){
  140758. if(!boundary)return(OV_FALSE);
  140759. {
  140760. long ret=_get_data(vf);
  140761. if(ret==0)return(OV_EOF);
  140762. if(ret<0)return(OV_EREAD);
  140763. }
  140764. }else{
  140765. ogg_int64_t ret=vf->offset;
  140766. vf->offset+=more;
  140767. return(ret);
  140768. }
  140769. }
  140770. }
  140771. }
  140772. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140773. ogg_int64_t begin=vf->offset;
  140774. ogg_int64_t end=begin;
  140775. ogg_int64_t ret;
  140776. ogg_int64_t offset=-1;
  140777. while(offset==-1){
  140778. begin-=CHUNKSIZE;
  140779. if(begin<0)
  140780. begin=0;
  140781. _seek_helper(vf,begin);
  140782. while(vf->offset<end){
  140783. ret=_get_next_page(vf,og,end-vf->offset);
  140784. if(ret==OV_EREAD)return(OV_EREAD);
  140785. if(ret<0){
  140786. break;
  140787. }else{
  140788. offset=ret;
  140789. }
  140790. }
  140791. }
  140792. _seek_helper(vf,offset);
  140793. ret=_get_next_page(vf,og,CHUNKSIZE);
  140794. if(ret<0)
  140795. return(OV_EFAULT);
  140796. return(offset);
  140797. }
  140798. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140799. ogg_int64_t begin,
  140800. ogg_int64_t searched,
  140801. ogg_int64_t end,
  140802. long currentno,
  140803. long m){
  140804. ogg_int64_t endsearched=end;
  140805. ogg_int64_t next=end;
  140806. ogg_page og;
  140807. ogg_int64_t ret;
  140808. while(searched<endsearched){
  140809. ogg_int64_t bisect;
  140810. if(endsearched-searched<CHUNKSIZE){
  140811. bisect=searched;
  140812. }else{
  140813. bisect=(searched+endsearched)/2;
  140814. }
  140815. _seek_helper(vf,bisect);
  140816. ret=_get_next_page(vf,&og,-1);
  140817. if(ret==OV_EREAD)return(OV_EREAD);
  140818. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140819. endsearched=bisect;
  140820. if(ret>=0)next=ret;
  140821. }else{
  140822. searched=ret+og.header_len+og.body_len;
  140823. }
  140824. }
  140825. _seek_helper(vf,next);
  140826. ret=_get_next_page(vf,&og,-1);
  140827. if(ret==OV_EREAD)return(OV_EREAD);
  140828. if(searched>=end || ret<0){
  140829. vf->links=m+1;
  140830. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140831. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140832. vf->offsets[m+1]=searched;
  140833. }else{
  140834. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140835. end,ogg_page_serialno(&og),m+1);
  140836. if(ret==OV_EREAD)return(OV_EREAD);
  140837. }
  140838. vf->offsets[m]=begin;
  140839. vf->serialnos[m]=currentno;
  140840. return(0);
  140841. }
  140842. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140843. long *serialno,ogg_page *og_ptr){
  140844. ogg_page og;
  140845. ogg_packet op;
  140846. int i,ret;
  140847. if(!og_ptr){
  140848. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140849. if(llret==OV_EREAD)return(OV_EREAD);
  140850. if(llret<0)return OV_ENOTVORBIS;
  140851. og_ptr=&og;
  140852. }
  140853. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140854. if(serialno)*serialno=vf->os.serialno;
  140855. vf->ready_state=STREAMSET;
  140856. vorbis_info_init(vi);
  140857. vorbis_comment_init(vc);
  140858. i=0;
  140859. while(i<3){
  140860. ogg_stream_pagein(&vf->os,og_ptr);
  140861. while(i<3){
  140862. int result=ogg_stream_packetout(&vf->os,&op);
  140863. if(result==0)break;
  140864. if(result==-1){
  140865. ret=OV_EBADHEADER;
  140866. goto bail_header;
  140867. }
  140868. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140869. goto bail_header;
  140870. }
  140871. i++;
  140872. }
  140873. if(i<3)
  140874. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140875. ret=OV_EBADHEADER;
  140876. goto bail_header;
  140877. }
  140878. }
  140879. return 0;
  140880. bail_header:
  140881. vorbis_info_clear(vi);
  140882. vorbis_comment_clear(vc);
  140883. vf->ready_state=OPENED;
  140884. return ret;
  140885. }
  140886. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140887. ogg_page og;
  140888. int i;
  140889. ogg_int64_t ret;
  140890. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140891. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140892. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140893. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140894. for(i=0;i<vf->links;i++){
  140895. if(i==0){
  140896. vf->dataoffsets[i]=dataoffset;
  140897. _seek_helper(vf,dataoffset);
  140898. }else{
  140899. _seek_helper(vf,vf->offsets[i]);
  140900. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140901. vf->dataoffsets[i]=-1;
  140902. }else{
  140903. vf->dataoffsets[i]=vf->offset;
  140904. }
  140905. }
  140906. if(vf->dataoffsets[i]!=-1){
  140907. ogg_int64_t accumulated=0;
  140908. long lastblock=-1;
  140909. int result;
  140910. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  140911. while(1){
  140912. ogg_packet op;
  140913. ret=_get_next_page(vf,&og,-1);
  140914. if(ret<0)
  140915. break;
  140916. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  140917. break;
  140918. ogg_stream_pagein(&vf->os,&og);
  140919. while((result=ogg_stream_packetout(&vf->os,&op))){
  140920. if(result>0){ /* ignore holes */
  140921. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  140922. if(lastblock!=-1)
  140923. accumulated+=(lastblock+thisblock)>>2;
  140924. lastblock=thisblock;
  140925. }
  140926. }
  140927. if(ogg_page_granulepos(&og)!=-1){
  140928. accumulated= ogg_page_granulepos(&og)-accumulated;
  140929. break;
  140930. }
  140931. }
  140932. if(accumulated<0)accumulated=0;
  140933. vf->pcmlengths[i*2]=accumulated;
  140934. }
  140935. {
  140936. ogg_int64_t end=vf->offsets[i+1];
  140937. _seek_helper(vf,end);
  140938. while(1){
  140939. ret=_get_prev_page(vf,&og);
  140940. if(ret<0){
  140941. vorbis_info_clear(vf->vi+i);
  140942. vorbis_comment_clear(vf->vc+i);
  140943. break;
  140944. }
  140945. if(ogg_page_granulepos(&og)!=-1){
  140946. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  140947. break;
  140948. }
  140949. vf->offset=ret;
  140950. }
  140951. }
  140952. }
  140953. }
  140954. static int _make_decode_ready(OggVorbis_File *vf){
  140955. if(vf->ready_state>STREAMSET)return 0;
  140956. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  140957. if(vf->seekable){
  140958. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  140959. return OV_EBADLINK;
  140960. }else{
  140961. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  140962. return OV_EBADLINK;
  140963. }
  140964. vorbis_block_init(&vf->vd,&vf->vb);
  140965. vf->ready_state=INITSET;
  140966. vf->bittrack=0.f;
  140967. vf->samptrack=0.f;
  140968. return 0;
  140969. }
  140970. static int _open_seekable2(OggVorbis_File *vf){
  140971. long serialno=vf->current_serialno;
  140972. ogg_int64_t dataoffset=vf->offset, end;
  140973. ogg_page og;
  140974. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  140975. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  140976. end=_get_prev_page(vf,&og);
  140977. if(end<0)return(end);
  140978. if(ogg_page_serialno(&og)!=serialno){
  140979. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  140980. }else{
  140981. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  140982. }
  140983. _prefetch_all_headers(vf,dataoffset);
  140984. return(ov_raw_seek(vf,0));
  140985. }
  140986. static void _decode_clear(OggVorbis_File *vf){
  140987. vorbis_dsp_clear(&vf->vd);
  140988. vorbis_block_clear(&vf->vb);
  140989. vf->ready_state=OPENED;
  140990. }
  140991. static int _fetch_and_process_packet(OggVorbis_File *vf,
  140992. ogg_packet *op_in,
  140993. int readp,
  140994. int spanp){
  140995. ogg_page og;
  140996. while(1){
  140997. if(vf->ready_state==INITSET){
  140998. while(1) {
  140999. ogg_packet op;
  141000. ogg_packet *op_ptr=(op_in?op_in:&op);
  141001. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141002. ogg_int64_t granulepos;
  141003. op_in=NULL;
  141004. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141005. if(result>0){
  141006. granulepos=op_ptr->granulepos;
  141007. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141008. header handling. The
  141009. header packets aren't
  141010. audio, so if/when we
  141011. submit them,
  141012. vorbis_synthesis will
  141013. reject them */
  141014. {
  141015. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141016. if(oldsamples)return(OV_EFAULT);
  141017. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141018. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141019. vf->bittrack+=op_ptr->bytes*8;
  141020. }
  141021. if(granulepos!=-1 && !op_ptr->e_o_s){
  141022. int link=(vf->seekable?vf->current_link:0);
  141023. int i,samples;
  141024. if(vf->seekable && link>0)
  141025. granulepos-=vf->pcmlengths[link*2];
  141026. if(granulepos<0)granulepos=0; /* actually, this
  141027. shouldn't be possible
  141028. here unless the stream
  141029. is very broken */
  141030. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141031. granulepos-=samples;
  141032. for(i=0;i<link;i++)
  141033. granulepos+=vf->pcmlengths[i*2+1];
  141034. vf->pcm_offset=granulepos;
  141035. }
  141036. return(1);
  141037. }
  141038. }
  141039. else
  141040. break;
  141041. }
  141042. }
  141043. if(vf->ready_state>=OPENED){
  141044. ogg_int64_t ret;
  141045. if(!readp)return(0);
  141046. if((ret=_get_next_page(vf,&og,-1))<0){
  141047. return(OV_EOF); /* eof.
  141048. leave unitialized */
  141049. }
  141050. vf->bittrack+=og.header_len*8;
  141051. if(vf->ready_state==INITSET){
  141052. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141053. if(!spanp)
  141054. return(OV_EOF);
  141055. _decode_clear(vf);
  141056. if(!vf->seekable){
  141057. vorbis_info_clear(vf->vi);
  141058. vorbis_comment_clear(vf->vc);
  141059. }
  141060. }
  141061. }
  141062. }
  141063. if(vf->ready_state!=INITSET){
  141064. int link;
  141065. if(vf->ready_state<STREAMSET){
  141066. if(vf->seekable){
  141067. vf->current_serialno=ogg_page_serialno(&og);
  141068. for(link=0;link<vf->links;link++)
  141069. if(vf->serialnos[link]==vf->current_serialno)break;
  141070. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141071. stream. error out,
  141072. leave machine
  141073. uninitialized */
  141074. vf->current_link=link;
  141075. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141076. vf->ready_state=STREAMSET;
  141077. }else{
  141078. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141079. if(ret)return(ret);
  141080. vf->current_link++;
  141081. link=0;
  141082. }
  141083. }
  141084. {
  141085. int ret=_make_decode_ready(vf);
  141086. if(ret<0)return ret;
  141087. }
  141088. }
  141089. ogg_stream_pagein(&vf->os,&og);
  141090. }
  141091. }
  141092. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141093. if(f==NULL)return(-1);
  141094. return fseek(f,off,whence);
  141095. }
  141096. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141097. long ibytes, ov_callbacks callbacks){
  141098. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141099. int ret;
  141100. memset(vf,0,sizeof(*vf));
  141101. vf->datasource=f;
  141102. vf->callbacks = callbacks;
  141103. ogg_sync_init(&vf->oy);
  141104. if(initial){
  141105. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141106. memcpy(buffer,initial,ibytes);
  141107. ogg_sync_wrote(&vf->oy,ibytes);
  141108. }
  141109. if(offsettest!=-1)vf->seekable=1;
  141110. vf->links=1;
  141111. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141112. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141113. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141114. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141115. vf->datasource=NULL;
  141116. ov_clear(vf);
  141117. }else
  141118. vf->ready_state=PARTOPEN;
  141119. return(ret);
  141120. }
  141121. static int _ov_open2(OggVorbis_File *vf){
  141122. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141123. vf->ready_state=OPENED;
  141124. if(vf->seekable){
  141125. int ret=_open_seekable2(vf);
  141126. if(ret){
  141127. vf->datasource=NULL;
  141128. ov_clear(vf);
  141129. }
  141130. return(ret);
  141131. }else
  141132. vf->ready_state=STREAMSET;
  141133. return 0;
  141134. }
  141135. int ov_clear(OggVorbis_File *vf){
  141136. if(vf){
  141137. vorbis_block_clear(&vf->vb);
  141138. vorbis_dsp_clear(&vf->vd);
  141139. ogg_stream_clear(&vf->os);
  141140. if(vf->vi && vf->links){
  141141. int i;
  141142. for(i=0;i<vf->links;i++){
  141143. vorbis_info_clear(vf->vi+i);
  141144. vorbis_comment_clear(vf->vc+i);
  141145. }
  141146. _ogg_free(vf->vi);
  141147. _ogg_free(vf->vc);
  141148. }
  141149. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141150. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141151. if(vf->serialnos)_ogg_free(vf->serialnos);
  141152. if(vf->offsets)_ogg_free(vf->offsets);
  141153. ogg_sync_clear(&vf->oy);
  141154. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141155. memset(vf,0,sizeof(*vf));
  141156. }
  141157. #ifdef DEBUG_LEAKS
  141158. _VDBG_dump();
  141159. #endif
  141160. return(0);
  141161. }
  141162. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141163. ov_callbacks callbacks){
  141164. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141165. if(ret)return ret;
  141166. return _ov_open2(vf);
  141167. }
  141168. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141169. ov_callbacks callbacks = {
  141170. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141171. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141172. (int (*)(void *)) fclose,
  141173. (long (*)(void *)) ftell
  141174. };
  141175. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141176. }
  141177. int ov_halfrate(OggVorbis_File *vf,int flag){
  141178. int i;
  141179. if(vf->vi==NULL)return OV_EINVAL;
  141180. if(!vf->seekable)return OV_EINVAL;
  141181. if(vf->ready_state>=STREAMSET)
  141182. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141183. will be able to swap this on the fly, but
  141184. for now dumping the decode machine is needed
  141185. to reinit the MDCT lookups. 1.1 libvorbis
  141186. is planned to be able to switch on the fly */
  141187. for(i=0;i<vf->links;i++){
  141188. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141189. ov_halfrate(vf,0);
  141190. return OV_EINVAL;
  141191. }
  141192. }
  141193. return 0;
  141194. }
  141195. int ov_halfrate_p(OggVorbis_File *vf){
  141196. if(vf->vi==NULL)return OV_EINVAL;
  141197. return vorbis_synthesis_halfrate_p(vf->vi);
  141198. }
  141199. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141200. ov_callbacks callbacks)
  141201. {
  141202. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141203. }
  141204. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141205. ov_callbacks callbacks = {
  141206. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141207. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141208. (int (*)(void *)) fclose,
  141209. (long (*)(void *)) ftell
  141210. };
  141211. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141212. }
  141213. int ov_test_open(OggVorbis_File *vf){
  141214. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141215. return _ov_open2(vf);
  141216. }
  141217. long ov_streams(OggVorbis_File *vf){
  141218. return vf->links;
  141219. }
  141220. long ov_seekable(OggVorbis_File *vf){
  141221. return vf->seekable;
  141222. }
  141223. long ov_bitrate(OggVorbis_File *vf,int i){
  141224. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141225. if(i>=vf->links)return(OV_EINVAL);
  141226. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141227. if(i<0){
  141228. ogg_int64_t bits=0;
  141229. int i;
  141230. float br;
  141231. for(i=0;i<vf->links;i++)
  141232. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141233. br = bits/ov_time_total(vf,-1);
  141234. return(rint(br));
  141235. }else{
  141236. if(vf->seekable){
  141237. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141238. }else{
  141239. if(vf->vi[i].bitrate_nominal>0){
  141240. return vf->vi[i].bitrate_nominal;
  141241. }else{
  141242. if(vf->vi[i].bitrate_upper>0){
  141243. if(vf->vi[i].bitrate_lower>0){
  141244. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141245. }else{
  141246. return vf->vi[i].bitrate_upper;
  141247. }
  141248. }
  141249. return(OV_FALSE);
  141250. }
  141251. }
  141252. }
  141253. }
  141254. long ov_bitrate_instant(OggVorbis_File *vf){
  141255. int link=(vf->seekable?vf->current_link:0);
  141256. long ret;
  141257. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141258. if(vf->samptrack==0)return(OV_FALSE);
  141259. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141260. vf->bittrack=0.f;
  141261. vf->samptrack=0.f;
  141262. return(ret);
  141263. }
  141264. long ov_serialnumber(OggVorbis_File *vf,int i){
  141265. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141266. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141267. if(i<0){
  141268. return(vf->current_serialno);
  141269. }else{
  141270. return(vf->serialnos[i]);
  141271. }
  141272. }
  141273. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141274. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141275. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141276. if(i<0){
  141277. ogg_int64_t acc=0;
  141278. int i;
  141279. for(i=0;i<vf->links;i++)
  141280. acc+=ov_raw_total(vf,i);
  141281. return(acc);
  141282. }else{
  141283. return(vf->offsets[i+1]-vf->offsets[i]);
  141284. }
  141285. }
  141286. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141287. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141288. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141289. if(i<0){
  141290. ogg_int64_t acc=0;
  141291. int i;
  141292. for(i=0;i<vf->links;i++)
  141293. acc+=ov_pcm_total(vf,i);
  141294. return(acc);
  141295. }else{
  141296. return(vf->pcmlengths[i*2+1]);
  141297. }
  141298. }
  141299. double ov_time_total(OggVorbis_File *vf,int i){
  141300. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141301. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141302. if(i<0){
  141303. double acc=0;
  141304. int i;
  141305. for(i=0;i<vf->links;i++)
  141306. acc+=ov_time_total(vf,i);
  141307. return(acc);
  141308. }else{
  141309. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141310. }
  141311. }
  141312. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141313. ogg_stream_state work_os;
  141314. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141315. if(!vf->seekable)
  141316. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141317. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141318. vf->pcm_offset=-1;
  141319. ogg_stream_reset_serialno(&vf->os,
  141320. vf->current_serialno); /* must set serialno */
  141321. vorbis_synthesis_restart(&vf->vd);
  141322. _seek_helper(vf,pos);
  141323. {
  141324. ogg_page og;
  141325. ogg_packet op;
  141326. int lastblock=0;
  141327. int accblock=0;
  141328. int thisblock;
  141329. int eosflag;
  141330. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141331. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141332. return from not necessarily
  141333. starting from the beginning */
  141334. while(1){
  141335. if(vf->ready_state>=STREAMSET){
  141336. int result=ogg_stream_packetout(&work_os,&op);
  141337. if(result>0){
  141338. if(vf->vi[vf->current_link].codec_setup){
  141339. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141340. if(thisblock<0){
  141341. ogg_stream_packetout(&vf->os,NULL);
  141342. thisblock=0;
  141343. }else{
  141344. if(eosflag)
  141345. ogg_stream_packetout(&vf->os,NULL);
  141346. else
  141347. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141348. }
  141349. if(op.granulepos!=-1){
  141350. int i,link=vf->current_link;
  141351. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141352. if(granulepos<0)granulepos=0;
  141353. for(i=0;i<link;i++)
  141354. granulepos+=vf->pcmlengths[i*2+1];
  141355. vf->pcm_offset=granulepos-accblock;
  141356. break;
  141357. }
  141358. lastblock=thisblock;
  141359. continue;
  141360. }else
  141361. ogg_stream_packetout(&vf->os,NULL);
  141362. }
  141363. }
  141364. if(!lastblock){
  141365. if(_get_next_page(vf,&og,-1)<0){
  141366. vf->pcm_offset=ov_pcm_total(vf,-1);
  141367. break;
  141368. }
  141369. }else{
  141370. vf->pcm_offset=-1;
  141371. break;
  141372. }
  141373. if(vf->ready_state>=STREAMSET)
  141374. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141375. _decode_clear(vf); /* clear out stream state */
  141376. ogg_stream_clear(&work_os);
  141377. }
  141378. if(vf->ready_state<STREAMSET){
  141379. int link;
  141380. vf->current_serialno=ogg_page_serialno(&og);
  141381. for(link=0;link<vf->links;link++)
  141382. if(vf->serialnos[link]==vf->current_serialno)break;
  141383. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141384. error out, leave
  141385. machine uninitialized */
  141386. vf->current_link=link;
  141387. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141388. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141389. vf->ready_state=STREAMSET;
  141390. }
  141391. ogg_stream_pagein(&vf->os,&og);
  141392. ogg_stream_pagein(&work_os,&og);
  141393. eosflag=ogg_page_eos(&og);
  141394. }
  141395. }
  141396. ogg_stream_clear(&work_os);
  141397. vf->bittrack=0.f;
  141398. vf->samptrack=0.f;
  141399. return(0);
  141400. seek_error:
  141401. vf->pcm_offset=-1;
  141402. ogg_stream_clear(&work_os);
  141403. _decode_clear(vf);
  141404. return OV_EBADLINK;
  141405. }
  141406. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141407. int link=-1;
  141408. ogg_int64_t result=0;
  141409. ogg_int64_t total=ov_pcm_total(vf,-1);
  141410. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141411. if(!vf->seekable)return(OV_ENOSEEK);
  141412. if(pos<0 || pos>total)return(OV_EINVAL);
  141413. for(link=vf->links-1;link>=0;link--){
  141414. total-=vf->pcmlengths[link*2+1];
  141415. if(pos>=total)break;
  141416. }
  141417. {
  141418. ogg_int64_t end=vf->offsets[link+1];
  141419. ogg_int64_t begin=vf->offsets[link];
  141420. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141421. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141422. ogg_int64_t target=pos-total+begintime;
  141423. ogg_int64_t best=begin;
  141424. ogg_page og;
  141425. while(begin<end){
  141426. ogg_int64_t bisect;
  141427. if(end-begin<CHUNKSIZE){
  141428. bisect=begin;
  141429. }else{
  141430. bisect=begin +
  141431. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141432. if(bisect<=begin)
  141433. bisect=begin+1;
  141434. }
  141435. _seek_helper(vf,bisect);
  141436. while(begin<end){
  141437. result=_get_next_page(vf,&og,end-vf->offset);
  141438. if(result==OV_EREAD) goto seek_error;
  141439. if(result<0){
  141440. if(bisect<=begin+1)
  141441. end=begin; /* found it */
  141442. else{
  141443. if(bisect==0) goto seek_error;
  141444. bisect-=CHUNKSIZE;
  141445. if(bisect<=begin)bisect=begin+1;
  141446. _seek_helper(vf,bisect);
  141447. }
  141448. }else{
  141449. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141450. if(granulepos==-1)continue;
  141451. if(granulepos<target){
  141452. best=result; /* raw offset of packet with granulepos */
  141453. begin=vf->offset; /* raw offset of next page */
  141454. begintime=granulepos;
  141455. if(target-begintime>44100)break;
  141456. bisect=begin; /* *not* begin + 1 */
  141457. }else{
  141458. if(bisect<=begin+1)
  141459. end=begin; /* found it */
  141460. else{
  141461. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141462. end=result;
  141463. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141464. if(bisect<=begin)bisect=begin+1;
  141465. _seek_helper(vf,bisect);
  141466. }else{
  141467. end=result;
  141468. endtime=granulepos;
  141469. break;
  141470. }
  141471. }
  141472. }
  141473. }
  141474. }
  141475. }
  141476. {
  141477. ogg_page og;
  141478. ogg_packet op;
  141479. _seek_helper(vf,best);
  141480. vf->pcm_offset=-1;
  141481. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141482. if(link!=vf->current_link){
  141483. _decode_clear(vf);
  141484. vf->current_link=link;
  141485. vf->current_serialno=ogg_page_serialno(&og);
  141486. vf->ready_state=STREAMSET;
  141487. }else{
  141488. vorbis_synthesis_restart(&vf->vd);
  141489. }
  141490. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141491. ogg_stream_pagein(&vf->os,&og);
  141492. while(1){
  141493. result=ogg_stream_packetpeek(&vf->os,&op);
  141494. if(result==0){
  141495. _seek_helper(vf,best);
  141496. while(1){
  141497. result=_get_prev_page(vf,&og);
  141498. if(result<0) goto seek_error;
  141499. if(ogg_page_granulepos(&og)>-1 ||
  141500. !ogg_page_continued(&og)){
  141501. return ov_raw_seek(vf,result);
  141502. }
  141503. vf->offset=result;
  141504. }
  141505. }
  141506. if(result<0){
  141507. result = OV_EBADPACKET;
  141508. goto seek_error;
  141509. }
  141510. if(op.granulepos!=-1){
  141511. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141512. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141513. vf->pcm_offset+=total;
  141514. break;
  141515. }else
  141516. result=ogg_stream_packetout(&vf->os,NULL);
  141517. }
  141518. }
  141519. }
  141520. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141521. result=OV_EFAULT;
  141522. goto seek_error;
  141523. }
  141524. vf->bittrack=0.f;
  141525. vf->samptrack=0.f;
  141526. return(0);
  141527. seek_error:
  141528. vf->pcm_offset=-1;
  141529. _decode_clear(vf);
  141530. return (int)result;
  141531. }
  141532. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141533. int thisblock,lastblock=0;
  141534. int ret=ov_pcm_seek_page(vf,pos);
  141535. if(ret<0)return(ret);
  141536. if((ret=_make_decode_ready(vf)))return ret;
  141537. while(1){
  141538. ogg_packet op;
  141539. ogg_page og;
  141540. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141541. if(ret>0){
  141542. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141543. if(thisblock<0){
  141544. ogg_stream_packetout(&vf->os,NULL);
  141545. continue; /* non audio packet */
  141546. }
  141547. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141548. if(vf->pcm_offset+((thisblock+
  141549. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141550. ogg_stream_packetout(&vf->os,NULL);
  141551. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141552. only tracking, no
  141553. pcm_decode */
  141554. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141555. if(op.granulepos>-1){
  141556. int i;
  141557. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141558. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141559. for(i=0;i<vf->current_link;i++)
  141560. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141561. }
  141562. lastblock=thisblock;
  141563. }else{
  141564. if(ret<0 && ret!=OV_HOLE)break;
  141565. if(_get_next_page(vf,&og,-1)<0)break;
  141566. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141567. if(vf->ready_state<STREAMSET){
  141568. int link;
  141569. vf->current_serialno=ogg_page_serialno(&og);
  141570. for(link=0;link<vf->links;link++)
  141571. if(vf->serialnos[link]==vf->current_serialno)break;
  141572. if(link==vf->links)return(OV_EBADLINK);
  141573. vf->current_link=link;
  141574. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141575. vf->ready_state=STREAMSET;
  141576. ret=_make_decode_ready(vf);
  141577. if(ret)return ret;
  141578. lastblock=0;
  141579. }
  141580. ogg_stream_pagein(&vf->os,&og);
  141581. }
  141582. }
  141583. vf->bittrack=0.f;
  141584. vf->samptrack=0.f;
  141585. while(vf->pcm_offset<pos){
  141586. ogg_int64_t target=pos-vf->pcm_offset;
  141587. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141588. if(samples>target)samples=target;
  141589. vorbis_synthesis_read(&vf->vd,samples);
  141590. vf->pcm_offset+=samples;
  141591. if(samples<target)
  141592. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141593. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141594. }
  141595. return 0;
  141596. }
  141597. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141598. int link=-1;
  141599. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141600. double time_total=ov_time_total(vf,-1);
  141601. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141602. if(!vf->seekable)return(OV_ENOSEEK);
  141603. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141604. for(link=vf->links-1;link>=0;link--){
  141605. pcm_total-=vf->pcmlengths[link*2+1];
  141606. time_total-=ov_time_total(vf,link);
  141607. if(seconds>=time_total)break;
  141608. }
  141609. {
  141610. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141611. return(ov_pcm_seek(vf,target));
  141612. }
  141613. }
  141614. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141615. int link=-1;
  141616. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141617. double time_total=ov_time_total(vf,-1);
  141618. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141619. if(!vf->seekable)return(OV_ENOSEEK);
  141620. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141621. for(link=vf->links-1;link>=0;link--){
  141622. pcm_total-=vf->pcmlengths[link*2+1];
  141623. time_total-=ov_time_total(vf,link);
  141624. if(seconds>=time_total)break;
  141625. }
  141626. {
  141627. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141628. return(ov_pcm_seek_page(vf,target));
  141629. }
  141630. }
  141631. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141632. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141633. return(vf->offset);
  141634. }
  141635. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141636. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141637. return(vf->pcm_offset);
  141638. }
  141639. double ov_time_tell(OggVorbis_File *vf){
  141640. int link=0;
  141641. ogg_int64_t pcm_total=0;
  141642. double time_total=0.f;
  141643. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141644. if(vf->seekable){
  141645. pcm_total=ov_pcm_total(vf,-1);
  141646. time_total=ov_time_total(vf,-1);
  141647. for(link=vf->links-1;link>=0;link--){
  141648. pcm_total-=vf->pcmlengths[link*2+1];
  141649. time_total-=ov_time_total(vf,link);
  141650. if(vf->pcm_offset>=pcm_total)break;
  141651. }
  141652. }
  141653. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141654. }
  141655. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141656. if(vf->seekable){
  141657. if(link<0)
  141658. if(vf->ready_state>=STREAMSET)
  141659. return vf->vi+vf->current_link;
  141660. else
  141661. return vf->vi;
  141662. else
  141663. if(link>=vf->links)
  141664. return NULL;
  141665. else
  141666. return vf->vi+link;
  141667. }else{
  141668. return vf->vi;
  141669. }
  141670. }
  141671. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141672. if(vf->seekable){
  141673. if(link<0)
  141674. if(vf->ready_state>=STREAMSET)
  141675. return vf->vc+vf->current_link;
  141676. else
  141677. return vf->vc;
  141678. else
  141679. if(link>=vf->links)
  141680. return NULL;
  141681. else
  141682. return vf->vc+link;
  141683. }else{
  141684. return vf->vc;
  141685. }
  141686. }
  141687. static int host_is_big_endian() {
  141688. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141689. unsigned char *bytewise = (unsigned char *)&pattern;
  141690. if (bytewise[0] == 0xfe) return 1;
  141691. return 0;
  141692. }
  141693. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141694. int bigendianp,int word,int sgned,int *bitstream){
  141695. int i,j;
  141696. int host_endian = host_is_big_endian();
  141697. float **pcm;
  141698. long samples;
  141699. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141700. while(1){
  141701. if(vf->ready_state==INITSET){
  141702. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141703. if(samples)break;
  141704. }
  141705. {
  141706. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141707. if(ret==OV_EOF)
  141708. return(0);
  141709. if(ret<=0)
  141710. return(ret);
  141711. }
  141712. }
  141713. if(samples>0){
  141714. long channels=ov_info(vf,-1)->channels;
  141715. long bytespersample=word * channels;
  141716. vorbis_fpu_control fpu;
  141717. (void) fpu; // (to avoid a warning about it being unused)
  141718. if(samples>length/bytespersample)samples=length/bytespersample;
  141719. if(samples <= 0)
  141720. return OV_EINVAL;
  141721. {
  141722. int val;
  141723. if(word==1){
  141724. int off=(sgned?0:128);
  141725. vorbis_fpu_setround(&fpu);
  141726. for(j=0;j<samples;j++)
  141727. for(i=0;i<channels;i++){
  141728. val=vorbis_ftoi(pcm[i][j]*128.f);
  141729. if(val>127)val=127;
  141730. else if(val<-128)val=-128;
  141731. *buffer++=val+off;
  141732. }
  141733. vorbis_fpu_restore(fpu);
  141734. }else{
  141735. int off=(sgned?0:32768);
  141736. if(host_endian==bigendianp){
  141737. if(sgned){
  141738. vorbis_fpu_setround(&fpu);
  141739. for(i=0;i<channels;i++) { /* It's faster in this order */
  141740. float *src=pcm[i];
  141741. short *dest=((short *)buffer)+i;
  141742. for(j=0;j<samples;j++) {
  141743. val=vorbis_ftoi(src[j]*32768.f);
  141744. if(val>32767)val=32767;
  141745. else if(val<-32768)val=-32768;
  141746. *dest=val;
  141747. dest+=channels;
  141748. }
  141749. }
  141750. vorbis_fpu_restore(fpu);
  141751. }else{
  141752. vorbis_fpu_setround(&fpu);
  141753. for(i=0;i<channels;i++) {
  141754. float *src=pcm[i];
  141755. short *dest=((short *)buffer)+i;
  141756. for(j=0;j<samples;j++) {
  141757. val=vorbis_ftoi(src[j]*32768.f);
  141758. if(val>32767)val=32767;
  141759. else if(val<-32768)val=-32768;
  141760. *dest=val+off;
  141761. dest+=channels;
  141762. }
  141763. }
  141764. vorbis_fpu_restore(fpu);
  141765. }
  141766. }else if(bigendianp){
  141767. vorbis_fpu_setround(&fpu);
  141768. for(j=0;j<samples;j++)
  141769. for(i=0;i<channels;i++){
  141770. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141771. if(val>32767)val=32767;
  141772. else if(val<-32768)val=-32768;
  141773. val+=off;
  141774. *buffer++=(val>>8);
  141775. *buffer++=(val&0xff);
  141776. }
  141777. vorbis_fpu_restore(fpu);
  141778. }else{
  141779. int val;
  141780. vorbis_fpu_setround(&fpu);
  141781. for(j=0;j<samples;j++)
  141782. for(i=0;i<channels;i++){
  141783. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141784. if(val>32767)val=32767;
  141785. else if(val<-32768)val=-32768;
  141786. val+=off;
  141787. *buffer++=(val&0xff);
  141788. *buffer++=(val>>8);
  141789. }
  141790. vorbis_fpu_restore(fpu);
  141791. }
  141792. }
  141793. }
  141794. vorbis_synthesis_read(&vf->vd,samples);
  141795. vf->pcm_offset+=samples;
  141796. if(bitstream)*bitstream=vf->current_link;
  141797. return(samples*bytespersample);
  141798. }else{
  141799. return(samples);
  141800. }
  141801. }
  141802. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141803. int *bitstream){
  141804. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141805. while(1){
  141806. if(vf->ready_state==INITSET){
  141807. float **pcm;
  141808. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141809. if(samples){
  141810. if(pcm_channels)*pcm_channels=pcm;
  141811. if(samples>length)samples=length;
  141812. vorbis_synthesis_read(&vf->vd,samples);
  141813. vf->pcm_offset+=samples;
  141814. if(bitstream)*bitstream=vf->current_link;
  141815. return samples;
  141816. }
  141817. }
  141818. {
  141819. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141820. if(ret==OV_EOF)return(0);
  141821. if(ret<=0)return(ret);
  141822. }
  141823. }
  141824. }
  141825. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141826. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141827. ogg_int64_t off);
  141828. static void _ov_splice(float **pcm,float **lappcm,
  141829. int n1, int n2,
  141830. int ch1, int ch2,
  141831. float *w1, float *w2){
  141832. int i,j;
  141833. float *w=w1;
  141834. int n=n1;
  141835. if(n1>n2){
  141836. n=n2;
  141837. w=w2;
  141838. }
  141839. for(j=0;j<ch1 && j<ch2;j++){
  141840. float *s=lappcm[j];
  141841. float *d=pcm[j];
  141842. for(i=0;i<n;i++){
  141843. float wd=w[i]*w[i];
  141844. float ws=1.-wd;
  141845. d[i]=d[i]*wd + s[i]*ws;
  141846. }
  141847. }
  141848. for(;j<ch2;j++){
  141849. float *d=pcm[j];
  141850. for(i=0;i<n;i++){
  141851. float wd=w[i]*w[i];
  141852. d[i]=d[i]*wd;
  141853. }
  141854. }
  141855. }
  141856. static int _ov_initset(OggVorbis_File *vf){
  141857. while(1){
  141858. if(vf->ready_state==INITSET)break;
  141859. {
  141860. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141861. if(ret<0 && ret!=OV_HOLE)return(ret);
  141862. }
  141863. }
  141864. return 0;
  141865. }
  141866. static int _ov_initprime(OggVorbis_File *vf){
  141867. vorbis_dsp_state *vd=&vf->vd;
  141868. while(1){
  141869. if(vf->ready_state==INITSET)
  141870. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141871. {
  141872. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141873. if(ret<0 && ret!=OV_HOLE)return(ret);
  141874. }
  141875. }
  141876. return 0;
  141877. }
  141878. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141879. float **lappcm,int lapsize){
  141880. int lapcount=0,i;
  141881. float **pcm;
  141882. while(lapcount<lapsize){
  141883. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141884. if(samples){
  141885. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141886. for(i=0;i<vi->channels;i++)
  141887. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141888. lapcount+=samples;
  141889. vorbis_synthesis_read(vd,samples);
  141890. }else{
  141891. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141892. if(ret==OV_EOF)break;
  141893. }
  141894. }
  141895. if(lapcount<lapsize){
  141896. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141897. if(samples==0){
  141898. for(i=0;i<vi->channels;i++)
  141899. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141900. lapcount=lapsize;
  141901. }else{
  141902. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141903. for(i=0;i<vi->channels;i++)
  141904. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141905. lapcount+=samples;
  141906. }
  141907. }
  141908. }
  141909. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  141910. vorbis_info *vi1,*vi2;
  141911. float **lappcm;
  141912. float **pcm;
  141913. float *w1,*w2;
  141914. int n1,n2,i,ret,hs1,hs2;
  141915. if(vf1==vf2)return(0); /* degenerate case */
  141916. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  141917. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  141918. ret=_ov_initset(vf1);
  141919. if(ret)return(ret);
  141920. ret=_ov_initprime(vf2);
  141921. if(ret)return(ret);
  141922. vi1=ov_info(vf1,-1);
  141923. vi2=ov_info(vf2,-1);
  141924. hs1=ov_halfrate_p(vf1);
  141925. hs2=ov_halfrate_p(vf2);
  141926. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  141927. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  141928. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  141929. w1=vorbis_window(&vf1->vd,0);
  141930. w2=vorbis_window(&vf2->vd,0);
  141931. for(i=0;i<vi1->channels;i++)
  141932. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141933. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  141934. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  141935. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  141936. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  141937. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  141938. return(0);
  141939. }
  141940. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  141941. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  141942. vorbis_info *vi;
  141943. float **lappcm;
  141944. float **pcm;
  141945. float *w1,*w2;
  141946. int n1,n2,ch1,ch2,hs;
  141947. int i,ret;
  141948. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141949. ret=_ov_initset(vf);
  141950. if(ret)return(ret);
  141951. vi=ov_info(vf,-1);
  141952. hs=ov_halfrate_p(vf);
  141953. ch1=vi->channels;
  141954. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141955. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141956. persistent; even if the decode state
  141957. from this link gets dumped, this
  141958. window array continues to exist */
  141959. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141960. for(i=0;i<ch1;i++)
  141961. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141962. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141963. ret=localseek(vf,pos);
  141964. if(ret)return ret;
  141965. ret=_ov_initprime(vf);
  141966. if(ret)return(ret);
  141967. vi=ov_info(vf,-1);
  141968. ch2=vi->channels;
  141969. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141970. w2=vorbis_window(&vf->vd,0);
  141971. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141972. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141973. return(0);
  141974. }
  141975. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141976. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  141977. }
  141978. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141979. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  141980. }
  141981. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141982. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  141983. }
  141984. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  141985. int (*localseek)(OggVorbis_File *,double)){
  141986. vorbis_info *vi;
  141987. float **lappcm;
  141988. float **pcm;
  141989. float *w1,*w2;
  141990. int n1,n2,ch1,ch2,hs;
  141991. int i,ret;
  141992. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141993. ret=_ov_initset(vf);
  141994. if(ret)return(ret);
  141995. vi=ov_info(vf,-1);
  141996. hs=ov_halfrate_p(vf);
  141997. ch1=vi->channels;
  141998. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141999. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142000. persistent; even if the decode state
  142001. from this link gets dumped, this
  142002. window array continues to exist */
  142003. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142004. for(i=0;i<ch1;i++)
  142005. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142006. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142007. ret=localseek(vf,pos);
  142008. if(ret)return ret;
  142009. ret=_ov_initprime(vf);
  142010. if(ret)return(ret);
  142011. vi=ov_info(vf,-1);
  142012. ch2=vi->channels;
  142013. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142014. w2=vorbis_window(&vf->vd,0);
  142015. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142016. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142017. return(0);
  142018. }
  142019. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142020. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142021. }
  142022. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142023. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142024. }
  142025. #endif
  142026. /*** End of inlined file: vorbisfile.c ***/
  142027. /*** Start of inlined file: window.c ***/
  142028. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142029. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142030. // tasks..
  142031. #if JUCE_MSVC
  142032. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142033. #endif
  142034. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142035. #if JUCE_USE_OGGVORBIS
  142036. #include <stdlib.h>
  142037. #include <math.h>
  142038. static float vwin64[32] = {
  142039. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142040. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142041. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142042. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142043. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142044. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142045. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142046. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142047. };
  142048. static float vwin128[64] = {
  142049. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142050. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142051. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142052. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142053. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142054. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142055. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142056. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142057. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142058. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142059. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142060. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142061. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142062. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142063. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142064. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142065. };
  142066. static float vwin256[128] = {
  142067. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142068. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142069. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142070. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142071. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142072. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142073. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142074. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142075. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142076. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142077. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142078. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142079. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142080. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142081. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142082. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142083. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142084. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142085. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142086. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142087. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142088. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142089. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142090. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142091. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142092. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142093. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142094. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142095. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142096. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142097. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142098. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142099. };
  142100. static float vwin512[256] = {
  142101. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142102. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142103. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142104. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142105. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142106. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142107. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142108. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142109. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142110. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142111. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142112. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142113. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142114. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142115. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142116. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142117. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142118. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142119. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142120. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142121. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142122. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142123. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142124. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142125. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142126. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142127. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142128. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142129. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142130. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142131. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142132. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142133. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142134. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142135. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142136. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142137. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142138. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142139. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142140. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142141. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142142. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142143. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142144. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142145. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142146. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142147. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142148. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142149. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142150. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142151. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142152. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142153. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142154. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142155. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142156. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142157. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142158. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142159. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142160. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142161. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142162. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142163. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142164. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142165. };
  142166. static float vwin1024[512] = {
  142167. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142168. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142169. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142170. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142171. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142172. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142173. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142174. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142175. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142176. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142177. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142178. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142179. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142180. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142181. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142182. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142183. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142184. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142185. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142186. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142187. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142188. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142189. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142190. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142191. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142192. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142193. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142194. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142195. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142196. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142197. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142198. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142199. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142200. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142201. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142202. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142203. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142204. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142205. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142206. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142207. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142208. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142209. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142210. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142211. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142212. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142213. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142214. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142215. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142216. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142217. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142218. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142219. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142220. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142221. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142222. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142223. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142224. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142225. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142226. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142227. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142228. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142229. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142230. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142231. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142232. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142233. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142234. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142235. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142236. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142237. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142238. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142239. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142240. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142241. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142242. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142243. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142244. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142245. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142246. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142247. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142248. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142249. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142250. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142251. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142252. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142253. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142254. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142255. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142256. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142257. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142258. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142259. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142260. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142261. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142262. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142263. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142264. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142265. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142266. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142267. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142268. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142269. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142270. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142271. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142272. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142273. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142274. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142275. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142276. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142277. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142278. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142279. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142280. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142281. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142282. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142283. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142284. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142285. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142286. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142287. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142288. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142289. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142290. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142291. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142292. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142293. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142294. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142295. };
  142296. static float vwin2048[1024] = {
  142297. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142298. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142299. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142300. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142301. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142302. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142303. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142304. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142305. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142306. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142307. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142308. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142309. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142310. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142311. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142312. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142313. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142314. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142315. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142316. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142317. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142318. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142319. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142320. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142321. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142322. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142323. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142324. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142325. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142326. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142327. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142328. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142329. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142330. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142331. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142332. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142333. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142334. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142335. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142336. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142337. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142338. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142339. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142340. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142341. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142342. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142343. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142344. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142345. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142346. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142347. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142348. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142349. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142350. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142351. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142352. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142353. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142354. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142355. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142356. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142357. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142358. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142359. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142360. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142361. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142362. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142363. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142364. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142365. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142366. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142367. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142368. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142369. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142370. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142371. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142372. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142373. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142374. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142375. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142376. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142377. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142378. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142379. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142380. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142381. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142382. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142383. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142384. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142385. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142386. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142387. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142388. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142389. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142390. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142391. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142392. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142393. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142394. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142395. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142396. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142397. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142398. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142399. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142400. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142401. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142402. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142403. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142404. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142405. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142406. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142407. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142408. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142409. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142410. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142411. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142412. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142413. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142414. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142415. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142416. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142417. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142418. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142419. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142420. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142421. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142422. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142423. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142424. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142425. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142426. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142427. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142428. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142429. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142430. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142431. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142432. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142433. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142434. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142435. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142436. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142437. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142438. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142439. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142440. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142441. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142442. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142443. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142444. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142445. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142446. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142447. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142448. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142449. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142450. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142451. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142452. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142453. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142454. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142455. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142456. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142457. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142458. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142459. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142460. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142461. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142462. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142463. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142464. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142465. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142466. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142467. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142468. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142469. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142470. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142471. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142472. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142473. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142474. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142475. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142476. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142477. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142478. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142479. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142480. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142481. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142482. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142483. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142484. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142485. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142486. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142487. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142488. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142489. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142490. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142491. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142492. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142493. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142494. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142495. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142496. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142497. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142498. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142499. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142500. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142501. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142502. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142503. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142504. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142505. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142506. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142507. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142508. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142509. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142510. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142511. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142512. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142513. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142514. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142515. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142516. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142517. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142518. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142519. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142520. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142521. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142522. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142523. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142524. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142525. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142526. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142527. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142528. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142529. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142530. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142531. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142532. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142533. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142534. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142535. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142536. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142537. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142538. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142539. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142540. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142541. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142542. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142543. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142544. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142545. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142546. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142547. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142548. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142549. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142550. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142551. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142552. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142553. };
  142554. static float vwin4096[2048] = {
  142555. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142556. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142557. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142558. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142559. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142560. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142561. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142562. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142563. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142564. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142565. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142566. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142567. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142568. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142569. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142570. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142571. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142572. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142573. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142574. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142575. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142576. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142577. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142578. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142579. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142580. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142581. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142582. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142583. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142584. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142585. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142586. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142587. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142588. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142589. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142590. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142591. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142592. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142593. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142594. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142595. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142596. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142597. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142598. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142599. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142600. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142601. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142602. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142603. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142604. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142605. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142606. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142607. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142608. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142609. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142610. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142611. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142612. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142613. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142614. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142615. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142616. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142617. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142618. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142619. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142620. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142621. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142622. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142623. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142624. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142625. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142626. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142627. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142628. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142629. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142630. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142631. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142632. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142633. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142634. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142635. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142636. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142637. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142638. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142639. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142640. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142641. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142642. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142643. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142644. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142645. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142646. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142647. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142648. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142649. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142650. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142651. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142652. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142653. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142654. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142655. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142656. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142657. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142658. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142659. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142660. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142661. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142662. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142663. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142664. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142665. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142666. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142667. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142668. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142669. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142670. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142671. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142672. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142673. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142674. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142675. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142676. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142677. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142678. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142679. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142680. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142681. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142682. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142683. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142684. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142685. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142686. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142687. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142688. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142689. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142690. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142691. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142692. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142693. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142694. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142695. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142696. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142697. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142698. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142699. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142700. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142701. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142702. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142703. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142704. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142705. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142706. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142707. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142708. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142709. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142710. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142711. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142712. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142713. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142714. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142715. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142716. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142717. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142718. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142719. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142720. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142721. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142722. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142723. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142724. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142725. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142726. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142727. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142728. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142729. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142730. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142731. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142732. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142733. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142734. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142735. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142736. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142737. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142738. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142739. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142740. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142741. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142742. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142743. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142744. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142745. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142746. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142747. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142748. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142749. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142750. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142751. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142752. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142753. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142754. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142755. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142756. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142757. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142758. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142759. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142760. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142761. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142762. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142763. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142764. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142765. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142766. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142767. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142768. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142769. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142770. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142771. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142772. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142773. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142774. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142775. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142776. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142777. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142778. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142779. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142780. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142781. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142782. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142783. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142784. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142785. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142786. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142787. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142788. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142789. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142790. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142791. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142792. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142793. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142794. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142795. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142796. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142797. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142798. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142799. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142800. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142801. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142802. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142803. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142804. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142805. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142806. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142807. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142808. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142809. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142810. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142811. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142812. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142813. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142814. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142815. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142816. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142817. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142818. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142819. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142820. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142821. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142822. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142823. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142824. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142825. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142826. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142827. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142828. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142829. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142830. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142831. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142832. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142833. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142834. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142835. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142836. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142837. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142838. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142839. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142840. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142841. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142842. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142843. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142844. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142845. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142846. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142847. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142848. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142849. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142850. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142851. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142852. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142853. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142854. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142855. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142856. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142857. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142858. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142859. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142860. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142861. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142862. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142863. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142864. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142865. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142866. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142867. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142868. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142869. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142870. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142871. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142872. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142873. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142874. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142875. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142876. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142877. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142878. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142879. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142880. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142881. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142882. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142883. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142884. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142885. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142886. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142887. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142888. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142889. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142890. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142891. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142892. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142893. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142894. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142895. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142896. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142897. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142898. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142899. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142900. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142901. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142902. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142903. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142904. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142905. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  142906. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  142907. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  142908. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  142909. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  142910. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  142911. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  142912. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  142913. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  142914. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  142915. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  142916. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  142917. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  142918. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  142919. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  142920. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  142921. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  142922. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  142923. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  142924. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  142925. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  142926. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  142927. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  142928. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  142929. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  142930. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  142931. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  142932. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  142933. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  142934. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  142935. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  142936. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  142937. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  142938. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  142939. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  142940. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  142941. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  142942. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  142943. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  142944. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  142945. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  142946. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  142947. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  142948. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  142949. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  142950. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  142951. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  142952. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  142953. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  142954. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  142955. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  142956. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  142957. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  142958. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  142959. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  142960. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  142961. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  142962. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  142963. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  142964. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  142965. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  142966. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  142967. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  142968. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  142969. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  142970. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  142971. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  142972. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  142973. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  142974. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  142975. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  142976. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  142977. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  142978. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  142979. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  142980. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  142981. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  142982. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  142983. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  142984. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  142985. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  142986. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  142987. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  142988. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  142989. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  142990. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  142991. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  142992. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  142993. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  142994. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  142995. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  142996. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  142997. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  142998. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  142999. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143000. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143001. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143002. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143003. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143004. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143005. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143006. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143007. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143008. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143009. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143010. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143011. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143012. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143013. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143014. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143015. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143016. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143017. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143018. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143019. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143020. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143021. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143022. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143023. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143024. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143025. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143026. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143027. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143028. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143029. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143030. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143031. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143032. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143033. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143034. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143035. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143036. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143037. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143038. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143039. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143040. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143041. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143042. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143043. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143044. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143045. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143046. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143047. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143048. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143049. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143050. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143051. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143052. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143053. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143054. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143055. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143056. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143057. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143058. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143059. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143060. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143061. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143062. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143063. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143064. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143065. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143066. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143067. };
  143068. static float vwin8192[4096] = {
  143069. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143070. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143071. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143072. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143073. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143074. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143075. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143076. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143077. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143078. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143079. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143080. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143081. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143082. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143083. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143084. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143085. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143086. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143087. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143088. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143089. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143090. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143091. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143092. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143093. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143094. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143095. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143096. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143097. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143098. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143099. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143100. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143101. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143102. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143103. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143104. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143105. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143106. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143107. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143108. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143109. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143110. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143111. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143112. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143113. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143114. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143115. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143116. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143117. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143118. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143119. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143120. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143121. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143122. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143123. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143124. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143125. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143126. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143127. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143128. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143129. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143130. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143131. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143132. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143133. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143134. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143135. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143136. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143137. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143138. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143139. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143140. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143141. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143142. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143143. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143144. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143145. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143146. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143147. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143148. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143149. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143150. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143151. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143152. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143153. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143154. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143155. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143156. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143157. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143158. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143159. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143160. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143161. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143162. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143163. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143164. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143165. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143166. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143167. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143168. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143169. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143170. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143171. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143172. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143173. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143174. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143175. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143176. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143177. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143178. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143179. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143180. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143181. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143182. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143183. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143184. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143185. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143186. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143187. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143188. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143189. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143190. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143191. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143192. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143193. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143194. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143195. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143196. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143197. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143198. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143199. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143200. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143201. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143202. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143203. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143204. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143205. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143206. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143207. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143208. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143209. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143210. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143211. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143212. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143213. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143214. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143215. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143216. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143217. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143218. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143219. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143220. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143221. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143222. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143223. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143224. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143225. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143226. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143227. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143228. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143229. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143230. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143231. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143232. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143233. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143234. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143235. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143236. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143237. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143238. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143239. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143240. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143241. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143242. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143243. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143244. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143245. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143246. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143247. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143248. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143249. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143250. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143251. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143252. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143253. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143254. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143255. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143256. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143257. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143258. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143259. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143260. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143261. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143262. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143263. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143264. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143265. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143266. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143267. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143268. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143269. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143270. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143271. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143272. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143273. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143274. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143275. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143276. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143277. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143278. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143279. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143280. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143281. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143282. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143283. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143284. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143285. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143286. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143287. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143288. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143289. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143290. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143291. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143292. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143293. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143294. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143295. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143296. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143297. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143298. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143299. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143300. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143301. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143302. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143303. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143304. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143305. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143306. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143307. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143308. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143309. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143310. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143311. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143312. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143313. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143314. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143315. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143316. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143317. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143318. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143319. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143320. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143321. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143322. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143323. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143324. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143325. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143326. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143327. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143328. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143329. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143330. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143331. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143332. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143333. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143334. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143335. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143336. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143337. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143338. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143339. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143340. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143341. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143342. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143343. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143344. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143345. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143346. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143347. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143348. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143349. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143350. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143351. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143352. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143353. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143354. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143355. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143356. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143357. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143358. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143359. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143360. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143361. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143362. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143363. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143364. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143365. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143366. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143367. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143368. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143369. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143370. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143371. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143372. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143373. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143374. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143375. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143376. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143377. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143378. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143379. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143380. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143381. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143382. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143383. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143384. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143385. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143386. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143387. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143388. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143389. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143390. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143391. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143392. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143393. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143394. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143395. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143396. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143397. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143398. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143399. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143400. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143401. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143402. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143403. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143404. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143405. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143406. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143407. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143408. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143409. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143410. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143411. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143412. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143413. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143414. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143415. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143416. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143417. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143418. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143419. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143420. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143421. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143422. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143423. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143424. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143425. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143426. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143427. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143428. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143429. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143430. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143431. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143432. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143433. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143434. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143435. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143436. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143437. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143438. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143439. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143440. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143441. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143442. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143443. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143444. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143445. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143446. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143447. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143448. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143449. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143450. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143451. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143452. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143453. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143454. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143455. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143456. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143457. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143458. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143459. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143460. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143461. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143462. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143463. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143464. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143465. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143466. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143467. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143468. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143469. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143470. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143471. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143472. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143473. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143474. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143475. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143476. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143477. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143478. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143479. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143480. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143481. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143482. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143483. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143484. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143485. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143486. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143487. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143488. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143489. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143490. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143491. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143492. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143493. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143494. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143495. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143496. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143497. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143498. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143499. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143500. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143501. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143502. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143503. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143504. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143505. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143506. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143507. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143508. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143509. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143510. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143511. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143512. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143513. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143514. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143515. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143516. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143517. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143518. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143519. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143520. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143521. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143522. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143523. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143524. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143525. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143526. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143527. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143528. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143529. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143530. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143531. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143532. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143533. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143534. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143535. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143536. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143537. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143538. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143539. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143540. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143541. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143542. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143543. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143544. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143545. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143546. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143547. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143548. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143549. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143550. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143551. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143552. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143553. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143554. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143555. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143556. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143557. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143558. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143559. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143560. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143561. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143562. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143563. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143564. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143565. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143566. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143567. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143568. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143569. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143570. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143571. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143572. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143573. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143574. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143575. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143576. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143577. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143578. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143579. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143580. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143581. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143582. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143583. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143584. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143585. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143586. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143587. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143588. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143589. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143590. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143591. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143592. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143593. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143594. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143595. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143596. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143597. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143598. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143599. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143600. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143601. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143602. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143603. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143604. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143605. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143606. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143607. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143608. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143609. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143610. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143611. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143612. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143613. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143614. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143615. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143616. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143617. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143618. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143619. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143620. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143621. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143622. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143623. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143624. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143625. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143626. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143627. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143628. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143629. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143630. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143631. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143632. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143633. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143634. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143635. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143636. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143637. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143638. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143639. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143640. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143641. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143642. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143643. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143644. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143645. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143646. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143647. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143648. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143649. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143650. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143651. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143652. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143653. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143654. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143655. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143656. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143657. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143658. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143659. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143660. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143661. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143662. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143663. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143664. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143665. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143666. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143667. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143668. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143669. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143670. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143671. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143672. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143673. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143674. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143675. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143676. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143677. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143678. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143679. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143680. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143681. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143682. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143683. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143684. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143685. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143686. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143687. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143688. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143689. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143690. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143691. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143692. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143693. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143694. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143695. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143696. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143697. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143698. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143699. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143700. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143701. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143702. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143703. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143704. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143705. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143706. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143707. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143708. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143709. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143710. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143711. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143712. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143713. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143714. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143715. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143716. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143717. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143718. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143719. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143720. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143721. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143722. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143723. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143724. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143725. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143726. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143727. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143728. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143729. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143730. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143731. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143732. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143733. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143734. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143735. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143736. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143737. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143738. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143739. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143740. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143741. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143742. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143743. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143744. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143745. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143746. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143747. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143748. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143749. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143750. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143751. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143752. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143753. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143754. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143755. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143756. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143757. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143758. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143759. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143760. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143761. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143762. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143763. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143764. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143765. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143766. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143767. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143768. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143769. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143770. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143771. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143772. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143773. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143774. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143775. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143776. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143777. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143778. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143779. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143780. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143781. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143782. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143783. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143784. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143785. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143786. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143787. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143788. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143789. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143790. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143791. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143792. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143793. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143794. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143795. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143796. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143797. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143798. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143799. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143800. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143801. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143802. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143803. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143804. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143805. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143806. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143807. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143808. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143809. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143810. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143811. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143812. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143813. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143814. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143815. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143816. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143817. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143818. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143819. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143820. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143821. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143822. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143823. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143824. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143825. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143826. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143827. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143828. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143829. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143830. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143831. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143832. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143833. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143834. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143835. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143836. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143837. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143838. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143839. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143840. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143841. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143842. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143843. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143844. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143845. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143846. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143847. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143848. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143849. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143850. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143851. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143852. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143853. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143854. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143855. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143856. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143857. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143858. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143859. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143860. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143861. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143862. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143863. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143864. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143865. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143866. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143867. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143868. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143869. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143870. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143871. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143872. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143873. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143874. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143875. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143876. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143877. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143878. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143879. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143880. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143881. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143882. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143883. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143884. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143885. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143886. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143887. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143888. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143889. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143890. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143891. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143892. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143893. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143894. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143895. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143896. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143897. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143898. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143899. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143900. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143901. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143902. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143903. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143904. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143905. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  143906. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  143907. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  143908. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  143909. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  143910. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  143911. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  143912. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  143913. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  143914. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  143915. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  143916. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  143917. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  143918. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  143919. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  143920. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  143921. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  143922. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  143923. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  143924. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  143925. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  143926. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  143927. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  143928. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  143929. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  143930. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  143931. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  143932. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  143933. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  143934. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  143935. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  143936. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  143937. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  143938. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  143939. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  143940. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  143941. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  143942. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  143943. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  143944. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  143945. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  143946. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  143947. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  143948. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  143949. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  143950. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  143951. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  143952. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  143953. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  143954. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  143955. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  143956. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  143957. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  143958. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  143959. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  143960. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  143961. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  143962. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  143963. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  143964. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  143965. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  143966. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  143967. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  143968. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  143969. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  143970. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  143971. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  143972. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  143973. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  143974. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  143975. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  143976. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  143977. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  143978. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  143979. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  143980. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  143981. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  143982. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  143983. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  143984. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  143985. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  143986. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  143987. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  143988. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  143989. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  143990. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  143991. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  143992. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  143993. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  143994. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  143995. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  143996. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  143997. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  143998. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  143999. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144000. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144001. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144002. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144003. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144004. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144005. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144006. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144007. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144008. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144009. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144010. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144011. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144012. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144013. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144014. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144015. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144016. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144017. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144018. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144019. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144020. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144021. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144022. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144023. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144024. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144025. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144026. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144027. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144028. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144029. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144030. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144031. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144032. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144033. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144034. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144035. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144036. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144037. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144038. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144039. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144040. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144041. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144042. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144043. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144044. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144045. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144046. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144047. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144048. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144049. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144050. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144051. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144052. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144053. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144054. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144055. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144056. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144057. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144058. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144059. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144060. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144061. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144062. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144063. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144064. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144065. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144066. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144067. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144068. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144069. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144070. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144071. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144072. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144073. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144074. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144075. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144076. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144077. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144078. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144079. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144080. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144081. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144082. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144083. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144084. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144085. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144086. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144087. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144088. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144089. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144090. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144091. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144092. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144093. };
  144094. static float *vwin[8] = {
  144095. vwin64,
  144096. vwin128,
  144097. vwin256,
  144098. vwin512,
  144099. vwin1024,
  144100. vwin2048,
  144101. vwin4096,
  144102. vwin8192,
  144103. };
  144104. float *_vorbis_window_get(int n){
  144105. return vwin[n];
  144106. }
  144107. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144108. int lW,int W,int nW){
  144109. lW=(W?lW:0);
  144110. nW=(W?nW:0);
  144111. {
  144112. float *windowLW=vwin[winno[lW]];
  144113. float *windowNW=vwin[winno[nW]];
  144114. long n=blocksizes[W];
  144115. long ln=blocksizes[lW];
  144116. long rn=blocksizes[nW];
  144117. long leftbegin=n/4-ln/4;
  144118. long leftend=leftbegin+ln/2;
  144119. long rightbegin=n/2+n/4-rn/4;
  144120. long rightend=rightbegin+rn/2;
  144121. int i,p;
  144122. for(i=0;i<leftbegin;i++)
  144123. d[i]=0.f;
  144124. for(p=0;i<leftend;i++,p++)
  144125. d[i]*=windowLW[p];
  144126. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144127. d[i]*=windowNW[p];
  144128. for(;i<n;i++)
  144129. d[i]=0.f;
  144130. }
  144131. }
  144132. #endif
  144133. /*** End of inlined file: window.c ***/
  144134. #else
  144135. #include <vorbis/vorbisenc.h>
  144136. #include <vorbis/codec.h>
  144137. #include <vorbis/vorbisfile.h>
  144138. #endif
  144139. }
  144140. #undef max
  144141. #undef min
  144142. BEGIN_JUCE_NAMESPACE
  144143. static const char* const oggFormatName = "Ogg-Vorbis file";
  144144. static const juce_wchar* const oggExtensions[] = { T(".ogg"), 0 };
  144145. class OggReader : public AudioFormatReader
  144146. {
  144147. OggVorbisNamespace::OggVorbis_File ovFile;
  144148. OggVorbisNamespace::ov_callbacks callbacks;
  144149. AudioSampleBuffer reservoir;
  144150. int reservoirStart, samplesInReservoir;
  144151. public:
  144152. OggReader (InputStream* const inp)
  144153. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144154. reservoir (2, 4096),
  144155. reservoirStart (0),
  144156. samplesInReservoir (0)
  144157. {
  144158. using namespace OggVorbisNamespace;
  144159. sampleRate = 0;
  144160. usesFloatingPointData = true;
  144161. callbacks.read_func = &oggReadCallback;
  144162. callbacks.seek_func = &oggSeekCallback;
  144163. callbacks.close_func = &oggCloseCallback;
  144164. callbacks.tell_func = &oggTellCallback;
  144165. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144166. if (err == 0)
  144167. {
  144168. vorbis_info* info = ov_info (&ovFile, -1);
  144169. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144170. numChannels = info->channels;
  144171. bitsPerSample = 16;
  144172. sampleRate = info->rate;
  144173. reservoir.setSize (numChannels,
  144174. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144175. }
  144176. }
  144177. ~OggReader()
  144178. {
  144179. OggVorbisNamespace::ov_clear (&ovFile);
  144180. }
  144181. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144182. int64 startSampleInFile, int numSamples)
  144183. {
  144184. while (numSamples > 0)
  144185. {
  144186. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144187. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144188. {
  144189. // got a few samples overlapping, so use them before seeking..
  144190. const int numToUse = jmin (numSamples, numAvailable);
  144191. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144192. if (destSamples[i] != 0)
  144193. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144194. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144195. sizeof (float) * numToUse);
  144196. startSampleInFile += numToUse;
  144197. numSamples -= numToUse;
  144198. startOffsetInDestBuffer += numToUse;
  144199. if (numSamples == 0)
  144200. break;
  144201. }
  144202. if (startSampleInFile < reservoirStart
  144203. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144204. {
  144205. // buffer miss, so refill the reservoir
  144206. int bitStream = 0;
  144207. reservoirStart = jmax (0, (int) startSampleInFile);
  144208. samplesInReservoir = reservoir.getNumSamples();
  144209. if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
  144210. OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
  144211. int offset = 0;
  144212. int numToRead = samplesInReservoir;
  144213. while (numToRead > 0)
  144214. {
  144215. float** dataIn = 0;
  144216. const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144217. if (samps <= 0)
  144218. break;
  144219. jassert (samps <= numToRead);
  144220. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144221. {
  144222. memcpy (reservoir.getSampleData (i, offset),
  144223. dataIn[i],
  144224. sizeof (float) * samps);
  144225. }
  144226. numToRead -= samps;
  144227. offset += samps;
  144228. }
  144229. if (numToRead > 0)
  144230. reservoir.clear (offset, numToRead);
  144231. }
  144232. }
  144233. if (numSamples > 0)
  144234. {
  144235. for (int i = numDestChannels; --i >= 0;)
  144236. if (destSamples[i] != 0)
  144237. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144238. sizeof (int) * numSamples);
  144239. }
  144240. return true;
  144241. }
  144242. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144243. {
  144244. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144245. }
  144246. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144247. {
  144248. InputStream* const in = (InputStream*) datasource;
  144249. if (whence == SEEK_CUR)
  144250. offset += in->getPosition();
  144251. else if (whence == SEEK_END)
  144252. offset += in->getTotalLength();
  144253. in->setPosition (offset);
  144254. return 0;
  144255. }
  144256. static int oggCloseCallback (void*)
  144257. {
  144258. return 0;
  144259. }
  144260. static long oggTellCallback (void* datasource)
  144261. {
  144262. return (long) ((InputStream*) datasource)->getPosition();
  144263. }
  144264. juce_UseDebuggingNewOperator
  144265. };
  144266. class OggWriter : public AudioFormatWriter
  144267. {
  144268. OggVorbisNamespace::ogg_stream_state os;
  144269. OggVorbisNamespace::ogg_page og;
  144270. OggVorbisNamespace::ogg_packet op;
  144271. OggVorbisNamespace::vorbis_info vi;
  144272. OggVorbisNamespace::vorbis_comment vc;
  144273. OggVorbisNamespace::vorbis_dsp_state vd;
  144274. OggVorbisNamespace::vorbis_block vb;
  144275. public:
  144276. bool ok;
  144277. OggWriter (OutputStream* const out,
  144278. const double sampleRate,
  144279. const int numChannels,
  144280. const int bitsPerSample,
  144281. const int qualityIndex)
  144282. : AudioFormatWriter (out, TRANS (oggFormatName),
  144283. sampleRate,
  144284. numChannels,
  144285. bitsPerSample)
  144286. {
  144287. using namespace OggVorbisNamespace;
  144288. ok = false;
  144289. vorbis_info_init (&vi);
  144290. if (vorbis_encode_init_vbr (&vi,
  144291. numChannels,
  144292. (int) sampleRate,
  144293. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144294. {
  144295. vorbis_comment_init (&vc);
  144296. if (JUCEApplication::getInstance() != 0)
  144297. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144298. vorbis_analysis_init (&vd, &vi);
  144299. vorbis_block_init (&vd, &vb);
  144300. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144301. ogg_packet header;
  144302. ogg_packet header_comm;
  144303. ogg_packet header_code;
  144304. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144305. ogg_stream_packetin (&os, &header);
  144306. ogg_stream_packetin (&os, &header_comm);
  144307. ogg_stream_packetin (&os, &header_code);
  144308. for (;;)
  144309. {
  144310. if (ogg_stream_flush (&os, &og) == 0)
  144311. break;
  144312. output->write (og.header, og.header_len);
  144313. output->write (og.body, og.body_len);
  144314. }
  144315. ok = true;
  144316. }
  144317. }
  144318. ~OggWriter()
  144319. {
  144320. using namespace OggVorbisNamespace;
  144321. if (ok)
  144322. {
  144323. // write a zero-length packet to show ogg that we're finished..
  144324. write (0, 0);
  144325. ogg_stream_clear (&os);
  144326. vorbis_block_clear (&vb);
  144327. vorbis_dsp_clear (&vd);
  144328. vorbis_comment_clear (&vc);
  144329. vorbis_info_clear (&vi);
  144330. output->flush();
  144331. }
  144332. else
  144333. {
  144334. vorbis_info_clear (&vi);
  144335. output = 0; // to stop the base class deleting this, as it needs to be returned
  144336. // to the caller of createWriter()
  144337. }
  144338. }
  144339. bool write (const int** samplesToWrite, int numSamples)
  144340. {
  144341. using namespace OggVorbisNamespace;
  144342. if (! ok)
  144343. return false;
  144344. if (numSamples > 0)
  144345. {
  144346. const double gain = 1.0 / 0x80000000u;
  144347. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144348. for (int i = numChannels; --i >= 0;)
  144349. {
  144350. float* const dst = vorbisBuffer[i];
  144351. const int* const src = samplesToWrite [i];
  144352. if (src != 0 && dst != 0)
  144353. {
  144354. for (int j = 0; j < numSamples; ++j)
  144355. dst[j] = (float) (src[j] * gain);
  144356. }
  144357. }
  144358. }
  144359. vorbis_analysis_wrote (&vd, numSamples);
  144360. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144361. {
  144362. vorbis_analysis (&vb, 0);
  144363. vorbis_bitrate_addblock (&vb);
  144364. while (vorbis_bitrate_flushpacket (&vd, &op))
  144365. {
  144366. ogg_stream_packetin (&os, &op);
  144367. for (;;)
  144368. {
  144369. if (ogg_stream_pageout (&os, &og) == 0)
  144370. break;
  144371. output->write (og.header, og.header_len);
  144372. output->write (og.body, og.body_len);
  144373. if (ogg_page_eos (&og))
  144374. break;
  144375. }
  144376. }
  144377. }
  144378. return true;
  144379. }
  144380. juce_UseDebuggingNewOperator
  144381. };
  144382. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144383. : AudioFormat (TRANS (oggFormatName), (const juce_wchar**) oggExtensions)
  144384. {
  144385. }
  144386. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144387. {
  144388. }
  144389. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144390. {
  144391. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144392. return Array <int> (rates);
  144393. }
  144394. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144395. {
  144396. Array <int> depths;
  144397. depths.add (32);
  144398. return depths;
  144399. }
  144400. bool OggVorbisAudioFormat::canDoStereo()
  144401. {
  144402. return true;
  144403. }
  144404. bool OggVorbisAudioFormat::canDoMono()
  144405. {
  144406. return true;
  144407. }
  144408. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144409. const bool deleteStreamIfOpeningFails)
  144410. {
  144411. ScopedPointer <OggReader> r (new OggReader (in));
  144412. if (r->sampleRate != 0)
  144413. return r.release();
  144414. if (! deleteStreamIfOpeningFails)
  144415. r->input = 0;
  144416. return 0;
  144417. }
  144418. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144419. double sampleRate,
  144420. unsigned int numChannels,
  144421. int bitsPerSample,
  144422. const StringPairArray& /*metadataValues*/,
  144423. int qualityOptionIndex)
  144424. {
  144425. ScopedPointer <OggWriter> w (new OggWriter (out,
  144426. sampleRate,
  144427. numChannels,
  144428. bitsPerSample,
  144429. qualityOptionIndex));
  144430. return w->ok ? w.release() : 0;
  144431. }
  144432. bool OggVorbisAudioFormat::isCompressed()
  144433. {
  144434. return true;
  144435. }
  144436. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144437. {
  144438. StringArray s;
  144439. s.add ("Low Quality");
  144440. s.add ("Medium Quality");
  144441. s.add ("High Quality");
  144442. return s;
  144443. }
  144444. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144445. {
  144446. FileInputStream* const in = source.createInputStream();
  144447. if (in != 0)
  144448. {
  144449. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144450. if (r != 0)
  144451. {
  144452. const int64 numSamps = r->lengthInSamples;
  144453. r = 0;
  144454. const int64 fileNumSamps = source.getSize() / 4;
  144455. const double ratio = numSamps / (double) fileNumSamps;
  144456. if (ratio > 12.0)
  144457. return 0;
  144458. else if (ratio > 6.0)
  144459. return 1;
  144460. else
  144461. return 2;
  144462. }
  144463. }
  144464. return 1;
  144465. }
  144466. END_JUCE_NAMESPACE
  144467. #endif
  144468. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144469. #endif
  144470. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144471. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144472. #if JUCE_MSVC
  144473. #pragma warning (push)
  144474. #endif
  144475. namespace jpeglibNamespace
  144476. {
  144477. #if JUCE_INCLUDE_JPEGLIB_CODE
  144478. #if JUCE_MINGW
  144479. typedef unsigned char boolean;
  144480. #endif
  144481. extern "C"
  144482. {
  144483. #define JPEG_INTERNALS
  144484. #undef FAR
  144485. /*** Start of inlined file: jpeglib.h ***/
  144486. #ifndef JPEGLIB_H
  144487. #define JPEGLIB_H
  144488. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144489. /*** Start of inlined file: jconfig.h ***/
  144490. // disable all the warnings under MSVC
  144491. #ifdef _MSC_VER
  144492. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144493. #endif
  144494. #ifdef __BORLANDC__
  144495. #pragma warn -8057
  144496. #pragma warn -8019
  144497. #pragma warn -8004
  144498. #pragma warn -8008
  144499. #endif
  144500. #define HAVE_PROTOTYPES
  144501. #define HAVE_UNSIGNED_CHAR
  144502. #define HAVE_UNSIGNED_SHORT
  144503. #undef CHAR_IS_UNSIGNED
  144504. #define HAVE_STDDEF_H
  144505. #define HAVE_STDLIB_H
  144506. #undef NEED_BSD_STRINGS
  144507. #undef NEED_SYS_TYPES_H
  144508. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144509. #undef NEED_SHORT_EXTERNAL_NAMES
  144510. #undef INCOMPLETE_TYPES_BROKEN
  144511. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144512. typedef unsigned char boolean;
  144513. #endif
  144514. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144515. #ifdef JPEG_INTERNALS
  144516. #undef RIGHT_SHIFT_IS_UNSIGNED
  144517. #endif /* JPEG_INTERNALS */
  144518. #ifdef JPEG_CJPEG_DJPEG
  144519. #define BMP_SUPPORTED /* BMP image file format */
  144520. #define GIF_SUPPORTED /* GIF image file format */
  144521. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144522. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144523. #define TARGA_SUPPORTED /* Targa image file format */
  144524. #define TWO_FILE_COMMANDLINE /* optional */
  144525. #define USE_SETMODE /* Microsoft has setmode() */
  144526. #undef NEED_SIGNAL_CATCHER
  144527. #undef DONT_USE_B_MODE
  144528. #undef PROGRESS_REPORT /* optional */
  144529. #endif /* JPEG_CJPEG_DJPEG */
  144530. /*** End of inlined file: jconfig.h ***/
  144531. /* widely used configuration options */
  144532. #endif
  144533. /*** Start of inlined file: jmorecfg.h ***/
  144534. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144535. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144536. #if BITS_IN_JSAMPLE == 8
  144537. #ifdef HAVE_UNSIGNED_CHAR
  144538. typedef unsigned char JSAMPLE;
  144539. #define GETJSAMPLE(value) ((int) (value))
  144540. #else /* not HAVE_UNSIGNED_CHAR */
  144541. typedef char JSAMPLE;
  144542. #ifdef CHAR_IS_UNSIGNED
  144543. #define GETJSAMPLE(value) ((int) (value))
  144544. #else
  144545. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144546. #endif /* CHAR_IS_UNSIGNED */
  144547. #endif /* HAVE_UNSIGNED_CHAR */
  144548. #define MAXJSAMPLE 255
  144549. #define CENTERJSAMPLE 128
  144550. #endif /* BITS_IN_JSAMPLE == 8 */
  144551. #if BITS_IN_JSAMPLE == 12
  144552. typedef short JSAMPLE;
  144553. #define GETJSAMPLE(value) ((int) (value))
  144554. #define MAXJSAMPLE 4095
  144555. #define CENTERJSAMPLE 2048
  144556. #endif /* BITS_IN_JSAMPLE == 12 */
  144557. typedef short JCOEF;
  144558. #ifdef HAVE_UNSIGNED_CHAR
  144559. typedef unsigned char JOCTET;
  144560. #define GETJOCTET(value) (value)
  144561. #else /* not HAVE_UNSIGNED_CHAR */
  144562. typedef char JOCTET;
  144563. #ifdef CHAR_IS_UNSIGNED
  144564. #define GETJOCTET(value) (value)
  144565. #else
  144566. #define GETJOCTET(value) ((value) & 0xFF)
  144567. #endif /* CHAR_IS_UNSIGNED */
  144568. #endif /* HAVE_UNSIGNED_CHAR */
  144569. #ifdef HAVE_UNSIGNED_CHAR
  144570. typedef unsigned char UINT8;
  144571. #else /* not HAVE_UNSIGNED_CHAR */
  144572. #ifdef CHAR_IS_UNSIGNED
  144573. typedef char UINT8;
  144574. #else /* not CHAR_IS_UNSIGNED */
  144575. typedef short UINT8;
  144576. #endif /* CHAR_IS_UNSIGNED */
  144577. #endif /* HAVE_UNSIGNED_CHAR */
  144578. #ifdef HAVE_UNSIGNED_SHORT
  144579. typedef unsigned short UINT16;
  144580. #else /* not HAVE_UNSIGNED_SHORT */
  144581. typedef unsigned int UINT16;
  144582. #endif /* HAVE_UNSIGNED_SHORT */
  144583. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144584. typedef short INT16;
  144585. #endif
  144586. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144587. typedef long INT32;
  144588. #endif
  144589. typedef unsigned int JDIMENSION;
  144590. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144591. #define METHODDEF(type) static type
  144592. #define LOCAL(type) static type
  144593. #define GLOBAL(type) type
  144594. #define EXTERN(type) extern type
  144595. #ifdef HAVE_PROTOTYPES
  144596. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144597. #else
  144598. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144599. #endif
  144600. #ifdef NEED_FAR_POINTERS
  144601. #define FAR far
  144602. #else
  144603. #define FAR
  144604. #endif
  144605. #ifndef HAVE_BOOLEAN
  144606. typedef int boolean;
  144607. #endif
  144608. #ifndef FALSE /* in case these macros already exist */
  144609. #define FALSE 0 /* values of boolean */
  144610. #endif
  144611. #ifndef TRUE
  144612. #define TRUE 1
  144613. #endif
  144614. #ifdef JPEG_INTERNALS
  144615. #define JPEG_INTERNAL_OPTIONS
  144616. #endif
  144617. #ifdef JPEG_INTERNAL_OPTIONS
  144618. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144619. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144620. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144621. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144622. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144623. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144624. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144625. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144626. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144627. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144628. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144629. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144630. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144631. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144632. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144633. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144634. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144635. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144636. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144637. #define RGB_GREEN 1 /* Offset of Green */
  144638. #define RGB_BLUE 2 /* Offset of Blue */
  144639. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144640. #ifndef INLINE
  144641. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144642. #define INLINE __inline__
  144643. #endif
  144644. #ifndef INLINE
  144645. #define INLINE /* default is to define it as empty */
  144646. #endif
  144647. #endif
  144648. #ifndef MULTIPLIER
  144649. #define MULTIPLIER int /* type for fastest integer multiply */
  144650. #endif
  144651. #ifndef FAST_FLOAT
  144652. #ifdef HAVE_PROTOTYPES
  144653. #define FAST_FLOAT float
  144654. #else
  144655. #define FAST_FLOAT double
  144656. #endif
  144657. #endif
  144658. #endif /* JPEG_INTERNAL_OPTIONS */
  144659. /*** End of inlined file: jmorecfg.h ***/
  144660. /* seldom changed options */
  144661. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144662. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144663. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144664. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144665. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144666. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144667. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144668. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144669. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144670. #ifndef D_MAX_BLOCKS_IN_MCU
  144671. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144672. #endif
  144673. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144674. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144675. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144676. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144677. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144678. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144679. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144680. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144681. typedef struct {
  144682. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144683. boolean sent_table; /* TRUE when table has been output */
  144684. } JQUANT_TBL;
  144685. typedef struct {
  144686. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144687. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144688. boolean sent_table; /* TRUE when table has been output */
  144689. } JHUFF_TBL;
  144690. typedef struct {
  144691. int component_id; /* identifier for this component (0..255) */
  144692. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144693. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144694. int v_samp_factor; /* vertical sampling factor (1..4) */
  144695. int quant_tbl_no; /* quantization table selector (0..3) */
  144696. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144697. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144698. JDIMENSION width_in_blocks;
  144699. JDIMENSION height_in_blocks;
  144700. int DCT_scaled_size;
  144701. JDIMENSION downsampled_width; /* actual width in samples */
  144702. JDIMENSION downsampled_height; /* actual height in samples */
  144703. boolean component_needed; /* do we need the value of this component? */
  144704. int MCU_width; /* number of blocks per MCU, horizontally */
  144705. int MCU_height; /* number of blocks per MCU, vertically */
  144706. int MCU_blocks; /* MCU_width * MCU_height */
  144707. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144708. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144709. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144710. JQUANT_TBL * quant_table;
  144711. void * dct_table;
  144712. } jpeg_component_info;
  144713. typedef struct {
  144714. int comps_in_scan; /* number of components encoded in this scan */
  144715. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144716. int Ss, Se; /* progressive JPEG spectral selection parms */
  144717. int Ah, Al; /* progressive JPEG successive approx. parms */
  144718. } jpeg_scan_info;
  144719. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144720. struct jpeg_marker_struct {
  144721. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144722. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144723. unsigned int original_length; /* # bytes of data in the file */
  144724. unsigned int data_length; /* # bytes of data saved at data[] */
  144725. JOCTET FAR * data; /* the data contained in the marker */
  144726. };
  144727. typedef enum {
  144728. JCS_UNKNOWN, /* error/unspecified */
  144729. JCS_GRAYSCALE, /* monochrome */
  144730. JCS_RGB, /* red/green/blue */
  144731. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144732. JCS_CMYK, /* C/M/Y/K */
  144733. JCS_YCCK /* Y/Cb/Cr/K */
  144734. } J_COLOR_SPACE;
  144735. typedef enum {
  144736. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144737. JDCT_IFAST, /* faster, less accurate integer method */
  144738. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144739. } J_DCT_METHOD;
  144740. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144741. #define JDCT_DEFAULT JDCT_ISLOW
  144742. #endif
  144743. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144744. #define JDCT_FASTEST JDCT_IFAST
  144745. #endif
  144746. typedef enum {
  144747. JDITHER_NONE, /* no dithering */
  144748. JDITHER_ORDERED, /* simple ordered dither */
  144749. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144750. } J_DITHER_MODE;
  144751. #define jpeg_common_fields \
  144752. struct jpeg_error_mgr * err; /* Error handler module */\
  144753. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144754. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144755. void * client_data; /* Available for use by application */\
  144756. boolean is_decompressor; /* So common code can tell which is which */\
  144757. int global_state /* For checking call sequence validity */
  144758. struct jpeg_common_struct {
  144759. jpeg_common_fields; /* Fields common to both master struct types */
  144760. };
  144761. typedef struct jpeg_common_struct * j_common_ptr;
  144762. typedef struct jpeg_compress_struct * j_compress_ptr;
  144763. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144764. struct jpeg_compress_struct {
  144765. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144766. struct jpeg_destination_mgr * dest;
  144767. JDIMENSION image_width; /* input image width */
  144768. JDIMENSION image_height; /* input image height */
  144769. int input_components; /* # of color components in input image */
  144770. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144771. double input_gamma; /* image gamma of input image */
  144772. int data_precision; /* bits of precision in image data */
  144773. int num_components; /* # of color components in JPEG image */
  144774. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144775. jpeg_component_info * comp_info;
  144776. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144777. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144778. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144779. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144780. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144781. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144782. int num_scans; /* # of entries in scan_info array */
  144783. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144784. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144785. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144786. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144787. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144788. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144789. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144790. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144791. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144792. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144793. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144794. UINT8 JFIF_minor_version;
  144795. UINT8 density_unit; /* JFIF code for pixel size units */
  144796. UINT16 X_density; /* Horizontal pixel density */
  144797. UINT16 Y_density; /* Vertical pixel density */
  144798. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144799. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144800. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144801. int max_h_samp_factor; /* largest h_samp_factor */
  144802. int max_v_samp_factor; /* largest v_samp_factor */
  144803. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144804. int comps_in_scan; /* # of JPEG components in this scan */
  144805. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144806. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144807. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144808. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144809. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144810. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144811. struct jpeg_comp_master * master;
  144812. struct jpeg_c_main_controller * main;
  144813. struct jpeg_c_prep_controller * prep;
  144814. struct jpeg_c_coef_controller * coef;
  144815. struct jpeg_marker_writer * marker;
  144816. struct jpeg_color_converter * cconvert;
  144817. struct jpeg_downsampler * downsample;
  144818. struct jpeg_forward_dct * fdct;
  144819. struct jpeg_entropy_encoder * entropy;
  144820. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144821. int script_space_size;
  144822. };
  144823. struct jpeg_decompress_struct {
  144824. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144825. struct jpeg_source_mgr * src;
  144826. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144827. JDIMENSION image_height; /* nominal image height */
  144828. int num_components; /* # of color components in JPEG image */
  144829. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144830. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144831. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144832. double output_gamma; /* image gamma wanted in output */
  144833. boolean buffered_image; /* TRUE=multiple output passes */
  144834. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144835. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144836. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144837. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144838. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144839. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144840. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144841. int desired_number_of_colors; /* max # colors to use in created colormap */
  144842. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144843. boolean enable_external_quant;/* enable future use of external colormap */
  144844. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144845. JDIMENSION output_width; /* scaled image width */
  144846. JDIMENSION output_height; /* scaled image height */
  144847. int out_color_components; /* # of color components in out_color_space */
  144848. int output_components; /* # of color components returned */
  144849. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144850. int actual_number_of_colors; /* number of entries in use */
  144851. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144852. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144853. int input_scan_number; /* Number of SOS markers seen so far */
  144854. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144855. int output_scan_number; /* Nominal scan number being displayed */
  144856. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144857. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144858. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144859. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144860. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144861. int data_precision; /* bits of precision in image data */
  144862. jpeg_component_info * comp_info;
  144863. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144864. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144865. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144866. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144867. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144868. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144869. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144870. UINT8 JFIF_major_version; /* JFIF version number */
  144871. UINT8 JFIF_minor_version;
  144872. UINT8 density_unit; /* JFIF code for pixel size units */
  144873. UINT16 X_density; /* Horizontal pixel density */
  144874. UINT16 Y_density; /* Vertical pixel density */
  144875. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144876. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144877. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144878. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144879. int max_h_samp_factor; /* largest h_samp_factor */
  144880. int max_v_samp_factor; /* largest v_samp_factor */
  144881. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144882. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144883. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144884. int comps_in_scan; /* # of JPEG components in this scan */
  144885. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144886. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144887. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144888. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144889. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144890. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144891. int unread_marker;
  144892. struct jpeg_decomp_master * master;
  144893. struct jpeg_d_main_controller * main;
  144894. struct jpeg_d_coef_controller * coef;
  144895. struct jpeg_d_post_controller * post;
  144896. struct jpeg_input_controller * inputctl;
  144897. struct jpeg_marker_reader * marker;
  144898. struct jpeg_entropy_decoder * entropy;
  144899. struct jpeg_inverse_dct * idct;
  144900. struct jpeg_upsampler * upsample;
  144901. struct jpeg_color_deconverter * cconvert;
  144902. struct jpeg_color_quantizer * cquantize;
  144903. };
  144904. struct jpeg_error_mgr {
  144905. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144906. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144907. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144908. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144909. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144910. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  144911. int msg_code;
  144912. #define JMSG_STR_PARM_MAX 80
  144913. union {
  144914. int i[8];
  144915. char s[JMSG_STR_PARM_MAX];
  144916. } msg_parm;
  144917. int trace_level; /* max msg_level that will be displayed */
  144918. long num_warnings; /* number of corrupt-data warnings */
  144919. const char * const * jpeg_message_table; /* Library errors */
  144920. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  144921. const char * const * addon_message_table; /* Non-library errors */
  144922. int first_addon_message; /* code for first string in addon table */
  144923. int last_addon_message; /* code for last string in addon table */
  144924. };
  144925. struct jpeg_progress_mgr {
  144926. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  144927. long pass_counter; /* work units completed in this pass */
  144928. long pass_limit; /* total number of work units in this pass */
  144929. int completed_passes; /* passes completed so far */
  144930. int total_passes; /* total number of passes expected */
  144931. };
  144932. struct jpeg_destination_mgr {
  144933. JOCTET * next_output_byte; /* => next byte to write in buffer */
  144934. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  144935. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  144936. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  144937. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  144938. };
  144939. struct jpeg_source_mgr {
  144940. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  144941. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  144942. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  144943. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  144944. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  144945. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  144946. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  144947. };
  144948. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  144949. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  144950. #define JPOOL_NUMPOOLS 2
  144951. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  144952. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  144953. struct jpeg_memory_mgr {
  144954. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  144955. size_t sizeofobject));
  144956. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  144957. size_t sizeofobject));
  144958. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  144959. JDIMENSION samplesperrow,
  144960. JDIMENSION numrows));
  144961. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  144962. JDIMENSION blocksperrow,
  144963. JDIMENSION numrows));
  144964. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  144965. int pool_id,
  144966. boolean pre_zero,
  144967. JDIMENSION samplesperrow,
  144968. JDIMENSION numrows,
  144969. JDIMENSION maxaccess));
  144970. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  144971. int pool_id,
  144972. boolean pre_zero,
  144973. JDIMENSION blocksperrow,
  144974. JDIMENSION numrows,
  144975. JDIMENSION maxaccess));
  144976. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  144977. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  144978. jvirt_sarray_ptr ptr,
  144979. JDIMENSION start_row,
  144980. JDIMENSION num_rows,
  144981. boolean writable));
  144982. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  144983. jvirt_barray_ptr ptr,
  144984. JDIMENSION start_row,
  144985. JDIMENSION num_rows,
  144986. boolean writable));
  144987. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  144988. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  144989. long max_memory_to_use;
  144990. long max_alloc_chunk;
  144991. };
  144992. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  144993. #ifdef HAVE_PROTOTYPES
  144994. #define JPP(arglist) arglist
  144995. #else
  144996. #define JPP(arglist) ()
  144997. #endif
  144998. #ifdef NEED_SHORT_EXTERNAL_NAMES
  144999. #define jpeg_std_error jStdError
  145000. #define jpeg_CreateCompress jCreaCompress
  145001. #define jpeg_CreateDecompress jCreaDecompress
  145002. #define jpeg_destroy_compress jDestCompress
  145003. #define jpeg_destroy_decompress jDestDecompress
  145004. #define jpeg_stdio_dest jStdDest
  145005. #define jpeg_stdio_src jStdSrc
  145006. #define jpeg_set_defaults jSetDefaults
  145007. #define jpeg_set_colorspace jSetColorspace
  145008. #define jpeg_default_colorspace jDefColorspace
  145009. #define jpeg_set_quality jSetQuality
  145010. #define jpeg_set_linear_quality jSetLQuality
  145011. #define jpeg_add_quant_table jAddQuantTable
  145012. #define jpeg_quality_scaling jQualityScaling
  145013. #define jpeg_simple_progression jSimProgress
  145014. #define jpeg_suppress_tables jSuppressTables
  145015. #define jpeg_alloc_quant_table jAlcQTable
  145016. #define jpeg_alloc_huff_table jAlcHTable
  145017. #define jpeg_start_compress jStrtCompress
  145018. #define jpeg_write_scanlines jWrtScanlines
  145019. #define jpeg_finish_compress jFinCompress
  145020. #define jpeg_write_raw_data jWrtRawData
  145021. #define jpeg_write_marker jWrtMarker
  145022. #define jpeg_write_m_header jWrtMHeader
  145023. #define jpeg_write_m_byte jWrtMByte
  145024. #define jpeg_write_tables jWrtTables
  145025. #define jpeg_read_header jReadHeader
  145026. #define jpeg_start_decompress jStrtDecompress
  145027. #define jpeg_read_scanlines jReadScanlines
  145028. #define jpeg_finish_decompress jFinDecompress
  145029. #define jpeg_read_raw_data jReadRawData
  145030. #define jpeg_has_multiple_scans jHasMultScn
  145031. #define jpeg_start_output jStrtOutput
  145032. #define jpeg_finish_output jFinOutput
  145033. #define jpeg_input_complete jInComplete
  145034. #define jpeg_new_colormap jNewCMap
  145035. #define jpeg_consume_input jConsumeInput
  145036. #define jpeg_calc_output_dimensions jCalcDimensions
  145037. #define jpeg_save_markers jSaveMarkers
  145038. #define jpeg_set_marker_processor jSetMarker
  145039. #define jpeg_read_coefficients jReadCoefs
  145040. #define jpeg_write_coefficients jWrtCoefs
  145041. #define jpeg_copy_critical_parameters jCopyCrit
  145042. #define jpeg_abort_compress jAbrtCompress
  145043. #define jpeg_abort_decompress jAbrtDecompress
  145044. #define jpeg_abort jAbort
  145045. #define jpeg_destroy jDestroy
  145046. #define jpeg_resync_to_restart jResyncRestart
  145047. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145048. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145049. JPP((struct jpeg_error_mgr * err));
  145050. #define jpeg_create_compress(cinfo) \
  145051. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145052. (size_t) sizeof(struct jpeg_compress_struct))
  145053. #define jpeg_create_decompress(cinfo) \
  145054. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145055. (size_t) sizeof(struct jpeg_decompress_struct))
  145056. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145057. int version, size_t structsize));
  145058. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145059. int version, size_t structsize));
  145060. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145061. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145062. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145063. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145064. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145065. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145066. J_COLOR_SPACE colorspace));
  145067. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145068. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145069. boolean force_baseline));
  145070. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145071. int scale_factor,
  145072. boolean force_baseline));
  145073. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145074. const unsigned int *basic_table,
  145075. int scale_factor,
  145076. boolean force_baseline));
  145077. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145078. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145079. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145080. boolean suppress));
  145081. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145082. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145083. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145084. boolean write_all_tables));
  145085. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145086. JSAMPARRAY scanlines,
  145087. JDIMENSION num_lines));
  145088. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145089. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145090. JSAMPIMAGE data,
  145091. JDIMENSION num_lines));
  145092. EXTERN(void) jpeg_write_marker
  145093. JPP((j_compress_ptr cinfo, int marker,
  145094. const JOCTET * dataptr, unsigned int datalen));
  145095. EXTERN(void) jpeg_write_m_header
  145096. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145097. EXTERN(void) jpeg_write_m_byte
  145098. JPP((j_compress_ptr cinfo, int val));
  145099. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145100. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145101. boolean require_image));
  145102. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145103. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145104. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145105. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145106. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145107. JSAMPARRAY scanlines,
  145108. JDIMENSION max_lines));
  145109. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145110. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145111. JSAMPIMAGE data,
  145112. JDIMENSION max_lines));
  145113. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145114. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145115. int scan_number));
  145116. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145117. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145118. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145119. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145120. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145121. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145122. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145123. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145124. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145125. EXTERN(void) jpeg_save_markers
  145126. JPP((j_decompress_ptr cinfo, int marker_code,
  145127. unsigned int length_limit));
  145128. EXTERN(void) jpeg_set_marker_processor
  145129. JPP((j_decompress_ptr cinfo, int marker_code,
  145130. jpeg_marker_parser_method routine));
  145131. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145132. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145133. jvirt_barray_ptr * coef_arrays));
  145134. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145135. j_compress_ptr dstinfo));
  145136. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145137. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145138. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145139. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145140. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145141. int desired));
  145142. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145143. #define JPEG_EOI 0xD9 /* EOI marker code */
  145144. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145145. #define JPEG_COM 0xFE /* COM marker code */
  145146. #ifdef INCOMPLETE_TYPES_BROKEN
  145147. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145148. struct jvirt_sarray_control { long dummy; };
  145149. struct jvirt_barray_control { long dummy; };
  145150. struct jpeg_comp_master { long dummy; };
  145151. struct jpeg_c_main_controller { long dummy; };
  145152. struct jpeg_c_prep_controller { long dummy; };
  145153. struct jpeg_c_coef_controller { long dummy; };
  145154. struct jpeg_marker_writer { long dummy; };
  145155. struct jpeg_color_converter { long dummy; };
  145156. struct jpeg_downsampler { long dummy; };
  145157. struct jpeg_forward_dct { long dummy; };
  145158. struct jpeg_entropy_encoder { long dummy; };
  145159. struct jpeg_decomp_master { long dummy; };
  145160. struct jpeg_d_main_controller { long dummy; };
  145161. struct jpeg_d_coef_controller { long dummy; };
  145162. struct jpeg_d_post_controller { long dummy; };
  145163. struct jpeg_input_controller { long dummy; };
  145164. struct jpeg_marker_reader { long dummy; };
  145165. struct jpeg_entropy_decoder { long dummy; };
  145166. struct jpeg_inverse_dct { long dummy; };
  145167. struct jpeg_upsampler { long dummy; };
  145168. struct jpeg_color_deconverter { long dummy; };
  145169. struct jpeg_color_quantizer { long dummy; };
  145170. #endif /* JPEG_INTERNALS */
  145171. #endif /* INCOMPLETE_TYPES_BROKEN */
  145172. #ifdef JPEG_INTERNALS
  145173. /*** Start of inlined file: jpegint.h ***/
  145174. typedef enum { /* Operating modes for buffer controllers */
  145175. JBUF_PASS_THRU, /* Plain stripwise operation */
  145176. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145177. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145178. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145179. } J_BUF_MODE;
  145180. #define CSTATE_START 100 /* after create_compress */
  145181. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145182. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145183. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145184. #define DSTATE_START 200 /* after create_decompress */
  145185. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145186. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145187. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145188. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145189. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145190. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145191. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145192. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145193. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145194. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145195. struct jpeg_comp_master {
  145196. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145197. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145198. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145199. boolean call_pass_startup; /* True if pass_startup must be called */
  145200. boolean is_last_pass; /* True during last pass */
  145201. };
  145202. struct jpeg_c_main_controller {
  145203. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145204. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145205. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145206. JDIMENSION in_rows_avail));
  145207. };
  145208. struct jpeg_c_prep_controller {
  145209. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145210. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145211. JSAMPARRAY input_buf,
  145212. JDIMENSION *in_row_ctr,
  145213. JDIMENSION in_rows_avail,
  145214. JSAMPIMAGE output_buf,
  145215. JDIMENSION *out_row_group_ctr,
  145216. JDIMENSION out_row_groups_avail));
  145217. };
  145218. struct jpeg_c_coef_controller {
  145219. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145220. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145221. JSAMPIMAGE input_buf));
  145222. };
  145223. struct jpeg_color_converter {
  145224. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145225. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145226. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145227. JDIMENSION output_row, int num_rows));
  145228. };
  145229. struct jpeg_downsampler {
  145230. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145231. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145232. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145233. JSAMPIMAGE output_buf,
  145234. JDIMENSION out_row_group_index));
  145235. boolean need_context_rows; /* TRUE if need rows above & below */
  145236. };
  145237. struct jpeg_forward_dct {
  145238. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145239. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145240. jpeg_component_info * compptr,
  145241. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145242. JDIMENSION start_row, JDIMENSION start_col,
  145243. JDIMENSION num_blocks));
  145244. };
  145245. struct jpeg_entropy_encoder {
  145246. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145247. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145248. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145249. };
  145250. struct jpeg_marker_writer {
  145251. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145252. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145253. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145254. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145255. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145256. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145257. unsigned int datalen));
  145258. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145259. };
  145260. struct jpeg_decomp_master {
  145261. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145262. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145263. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145264. };
  145265. struct jpeg_input_controller {
  145266. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145267. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145268. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145269. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145270. boolean has_multiple_scans; /* True if file has multiple scans */
  145271. boolean eoi_reached; /* True when EOI has been consumed */
  145272. };
  145273. struct jpeg_d_main_controller {
  145274. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145275. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145276. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145277. JDIMENSION out_rows_avail));
  145278. };
  145279. struct jpeg_d_coef_controller {
  145280. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145281. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145282. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145283. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145284. JSAMPIMAGE output_buf));
  145285. jvirt_barray_ptr *coef_arrays;
  145286. };
  145287. struct jpeg_d_post_controller {
  145288. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145289. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145290. JSAMPIMAGE input_buf,
  145291. JDIMENSION *in_row_group_ctr,
  145292. JDIMENSION in_row_groups_avail,
  145293. JSAMPARRAY output_buf,
  145294. JDIMENSION *out_row_ctr,
  145295. JDIMENSION out_rows_avail));
  145296. };
  145297. struct jpeg_marker_reader {
  145298. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145299. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145300. jpeg_marker_parser_method read_restart_marker;
  145301. boolean saw_SOI; /* found SOI? */
  145302. boolean saw_SOF; /* found SOF? */
  145303. int next_restart_num; /* next restart number expected (0-7) */
  145304. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145305. };
  145306. struct jpeg_entropy_decoder {
  145307. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145308. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145309. JBLOCKROW *MCU_data));
  145310. boolean insufficient_data; /* set TRUE after emitting warning */
  145311. };
  145312. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145313. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145314. JCOEFPTR coef_block,
  145315. JSAMPARRAY output_buf, JDIMENSION output_col));
  145316. struct jpeg_inverse_dct {
  145317. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145318. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145319. };
  145320. struct jpeg_upsampler {
  145321. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145322. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145323. JSAMPIMAGE input_buf,
  145324. JDIMENSION *in_row_group_ctr,
  145325. JDIMENSION in_row_groups_avail,
  145326. JSAMPARRAY output_buf,
  145327. JDIMENSION *out_row_ctr,
  145328. JDIMENSION out_rows_avail));
  145329. boolean need_context_rows; /* TRUE if need rows above & below */
  145330. };
  145331. struct jpeg_color_deconverter {
  145332. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145333. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145334. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145335. JSAMPARRAY output_buf, int num_rows));
  145336. };
  145337. struct jpeg_color_quantizer {
  145338. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145339. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145340. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145341. int num_rows));
  145342. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145343. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145344. };
  145345. #undef MAX
  145346. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145347. #undef MIN
  145348. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145349. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145350. #define SHIFT_TEMPS INT32 shift_temp;
  145351. #define RIGHT_SHIFT(x,shft) \
  145352. ((shift_temp = (x)) < 0 ? \
  145353. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145354. (shift_temp >> (shft)))
  145355. #else
  145356. #define SHIFT_TEMPS
  145357. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145358. #endif
  145359. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145360. #define jinit_compress_master jICompress
  145361. #define jinit_c_master_control jICMaster
  145362. #define jinit_c_main_controller jICMainC
  145363. #define jinit_c_prep_controller jICPrepC
  145364. #define jinit_c_coef_controller jICCoefC
  145365. #define jinit_color_converter jICColor
  145366. #define jinit_downsampler jIDownsampler
  145367. #define jinit_forward_dct jIFDCT
  145368. #define jinit_huff_encoder jIHEncoder
  145369. #define jinit_phuff_encoder jIPHEncoder
  145370. #define jinit_marker_writer jIMWriter
  145371. #define jinit_master_decompress jIDMaster
  145372. #define jinit_d_main_controller jIDMainC
  145373. #define jinit_d_coef_controller jIDCoefC
  145374. #define jinit_d_post_controller jIDPostC
  145375. #define jinit_input_controller jIInCtlr
  145376. #define jinit_marker_reader jIMReader
  145377. #define jinit_huff_decoder jIHDecoder
  145378. #define jinit_phuff_decoder jIPHDecoder
  145379. #define jinit_inverse_dct jIIDCT
  145380. #define jinit_upsampler jIUpsampler
  145381. #define jinit_color_deconverter jIDColor
  145382. #define jinit_1pass_quantizer jI1Quant
  145383. #define jinit_2pass_quantizer jI2Quant
  145384. #define jinit_merged_upsampler jIMUpsampler
  145385. #define jinit_memory_mgr jIMemMgr
  145386. #define jdiv_round_up jDivRound
  145387. #define jround_up jRound
  145388. #define jcopy_sample_rows jCopySamples
  145389. #define jcopy_block_row jCopyBlocks
  145390. #define jzero_far jZeroFar
  145391. #define jpeg_zigzag_order jZIGTable
  145392. #define jpeg_natural_order jZAGTable
  145393. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145394. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145395. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145396. boolean transcode_only));
  145397. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145398. boolean need_full_buffer));
  145399. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145400. boolean need_full_buffer));
  145401. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145402. boolean need_full_buffer));
  145403. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145404. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145405. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145406. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145407. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145408. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145409. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145410. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145411. boolean need_full_buffer));
  145412. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145413. boolean need_full_buffer));
  145414. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145415. boolean need_full_buffer));
  145416. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145417. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145418. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145419. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145420. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145421. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145422. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145423. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145424. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145425. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145426. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145427. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145428. EXTERN(long) jround_up JPP((long a, long b));
  145429. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145430. JSAMPARRAY output_array, int dest_row,
  145431. int num_rows, JDIMENSION num_cols));
  145432. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145433. JDIMENSION num_blocks));
  145434. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145435. #if 0 /* This table is not actually needed in v6a */
  145436. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145437. #endif
  145438. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145439. #ifdef INCOMPLETE_TYPES_BROKEN
  145440. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145441. struct jvirt_sarray_control { long dummy; };
  145442. struct jvirt_barray_control { long dummy; };
  145443. #endif
  145444. #endif /* INCOMPLETE_TYPES_BROKEN */
  145445. /*** End of inlined file: jpegint.h ***/
  145446. /* fetch private declarations */
  145447. /*** Start of inlined file: jerror.h ***/
  145448. #ifndef JMESSAGE
  145449. #ifndef JERROR_H
  145450. #define JMAKE_ENUM_LIST
  145451. #else
  145452. #define JMESSAGE(code,string)
  145453. #endif /* JERROR_H */
  145454. #endif /* JMESSAGE */
  145455. #ifdef JMAKE_ENUM_LIST
  145456. typedef enum {
  145457. #define JMESSAGE(code,string) code ,
  145458. #endif /* JMAKE_ENUM_LIST */
  145459. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145460. JMESSAGE(JERR_ARITH_NOTIMPL,
  145461. "Sorry, there are legal restrictions on arithmetic coding")
  145462. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145463. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145464. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145465. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145466. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145467. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145468. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145469. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145470. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145471. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145472. JMESSAGE(JERR_BAD_LIB_VERSION,
  145473. "Wrong JPEG library version: library is %d, caller expects %d")
  145474. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145475. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145476. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145477. JMESSAGE(JERR_BAD_PROGRESSION,
  145478. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145479. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145480. "Invalid progressive parameters at scan script entry %d")
  145481. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145482. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145483. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145484. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145485. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145486. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145487. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145488. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145489. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145490. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145491. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145492. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145493. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145494. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145495. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145496. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145497. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145498. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145499. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145500. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145501. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145502. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145503. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145504. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145505. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145506. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145507. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145508. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145509. "Cannot transcode due to multiple use of quantization table %d")
  145510. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145511. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145512. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145513. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145514. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145515. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145516. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145517. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145518. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145519. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145520. JMESSAGE(JERR_QUANT_COMPONENTS,
  145521. "Cannot quantize more than %d color components")
  145522. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145523. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145524. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145525. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145526. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145527. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145528. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145529. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145530. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145531. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145532. JMESSAGE(JERR_TFILE_WRITE,
  145533. "Write failed on temporary file --- out of disk space?")
  145534. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145535. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145536. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145537. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145538. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145539. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145540. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145541. JMESSAGE(JMSG_VERSION, JVERSION)
  145542. JMESSAGE(JTRC_16BIT_TABLES,
  145543. "Caution: quantization tables are too coarse for baseline JPEG")
  145544. JMESSAGE(JTRC_ADOBE,
  145545. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145546. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145547. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145548. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145549. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145550. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145551. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145552. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145553. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145554. JMESSAGE(JTRC_EOI, "End Of Image")
  145555. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145556. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145557. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145558. "Warning: thumbnail image size does not match data length %u")
  145559. JMESSAGE(JTRC_JFIF_EXTENSION,
  145560. "JFIF extension marker: type 0x%02x, length %u")
  145561. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145562. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145563. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145564. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145565. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145566. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145567. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145568. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145569. JMESSAGE(JTRC_RST, "RST%d")
  145570. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145571. "Smoothing not supported with nonstandard sampling ratios")
  145572. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145573. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145574. JMESSAGE(JTRC_SOI, "Start of Image")
  145575. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145576. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145577. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145578. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145579. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145580. JMESSAGE(JTRC_THUMB_JPEG,
  145581. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145582. JMESSAGE(JTRC_THUMB_PALETTE,
  145583. "JFIF extension marker: palette thumbnail image, length %u")
  145584. JMESSAGE(JTRC_THUMB_RGB,
  145585. "JFIF extension marker: RGB thumbnail image, length %u")
  145586. JMESSAGE(JTRC_UNKNOWN_IDS,
  145587. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145588. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145589. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145590. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145591. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145592. "Inconsistent progression sequence for component %d coefficient %d")
  145593. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145594. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145595. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145596. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145597. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145598. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145599. JMESSAGE(JWRN_MUST_RESYNC,
  145600. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145601. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145602. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145603. #ifdef JMAKE_ENUM_LIST
  145604. JMSG_LASTMSGCODE
  145605. } J_MESSAGE_CODE;
  145606. #undef JMAKE_ENUM_LIST
  145607. #endif /* JMAKE_ENUM_LIST */
  145608. #undef JMESSAGE
  145609. #ifndef JERROR_H
  145610. #define JERROR_H
  145611. #define ERREXIT(cinfo,code) \
  145612. ((cinfo)->err->msg_code = (code), \
  145613. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145614. #define ERREXIT1(cinfo,code,p1) \
  145615. ((cinfo)->err->msg_code = (code), \
  145616. (cinfo)->err->msg_parm.i[0] = (p1), \
  145617. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145618. #define ERREXIT2(cinfo,code,p1,p2) \
  145619. ((cinfo)->err->msg_code = (code), \
  145620. (cinfo)->err->msg_parm.i[0] = (p1), \
  145621. (cinfo)->err->msg_parm.i[1] = (p2), \
  145622. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145623. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145624. ((cinfo)->err->msg_code = (code), \
  145625. (cinfo)->err->msg_parm.i[0] = (p1), \
  145626. (cinfo)->err->msg_parm.i[1] = (p2), \
  145627. (cinfo)->err->msg_parm.i[2] = (p3), \
  145628. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145629. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  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->msg_parm.i[2] = (p3), \
  145634. (cinfo)->err->msg_parm.i[3] = (p4), \
  145635. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145636. #define ERREXITS(cinfo,code,str) \
  145637. ((cinfo)->err->msg_code = (code), \
  145638. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145639. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145640. #define MAKESTMT(stuff) do { stuff } while (0)
  145641. #define WARNMS(cinfo,code) \
  145642. ((cinfo)->err->msg_code = (code), \
  145643. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145644. #define WARNMS1(cinfo,code,p1) \
  145645. ((cinfo)->err->msg_code = (code), \
  145646. (cinfo)->err->msg_parm.i[0] = (p1), \
  145647. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145648. #define WARNMS2(cinfo,code,p1,p2) \
  145649. ((cinfo)->err->msg_code = (code), \
  145650. (cinfo)->err->msg_parm.i[0] = (p1), \
  145651. (cinfo)->err->msg_parm.i[1] = (p2), \
  145652. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145653. #define TRACEMS(cinfo,lvl,code) \
  145654. ((cinfo)->err->msg_code = (code), \
  145655. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145656. #define TRACEMS1(cinfo,lvl,code,p1) \
  145657. ((cinfo)->err->msg_code = (code), \
  145658. (cinfo)->err->msg_parm.i[0] = (p1), \
  145659. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145660. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145661. ((cinfo)->err->msg_code = (code), \
  145662. (cinfo)->err->msg_parm.i[0] = (p1), \
  145663. (cinfo)->err->msg_parm.i[1] = (p2), \
  145664. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145665. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145666. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145667. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145668. (cinfo)->err->msg_code = (code); \
  145669. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145670. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145671. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145672. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145673. (cinfo)->err->msg_code = (code); \
  145674. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145675. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145676. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145677. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145678. _mp[4] = (p5); \
  145679. (cinfo)->err->msg_code = (code); \
  145680. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145681. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145682. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145683. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145684. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145685. (cinfo)->err->msg_code = (code); \
  145686. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145687. #define TRACEMSS(cinfo,lvl,code,str) \
  145688. ((cinfo)->err->msg_code = (code), \
  145689. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145690. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145691. #endif /* JERROR_H */
  145692. /*** End of inlined file: jerror.h ***/
  145693. /* fetch error codes too */
  145694. #endif
  145695. #endif /* JPEGLIB_H */
  145696. /*** End of inlined file: jpeglib.h ***/
  145697. /*** Start of inlined file: jcapimin.c ***/
  145698. #define JPEG_INTERNALS
  145699. /*** Start of inlined file: jinclude.h ***/
  145700. #ifndef __jinclude_h__
  145701. #define __jinclude_h__
  145702. /*** Start of inlined file: jconfig.h ***/
  145703. // disable all the warnings under MSVC
  145704. #ifdef _MSC_VER
  145705. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145706. #endif
  145707. #ifdef __BORLANDC__
  145708. #pragma warn -8057
  145709. #pragma warn -8019
  145710. #pragma warn -8004
  145711. #pragma warn -8008
  145712. #endif
  145713. #define HAVE_PROTOTYPES
  145714. #define HAVE_UNSIGNED_CHAR
  145715. #define HAVE_UNSIGNED_SHORT
  145716. #undef CHAR_IS_UNSIGNED
  145717. #define HAVE_STDDEF_H
  145718. #define HAVE_STDLIB_H
  145719. #undef NEED_BSD_STRINGS
  145720. #undef NEED_SYS_TYPES_H
  145721. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145722. #undef NEED_SHORT_EXTERNAL_NAMES
  145723. #undef INCOMPLETE_TYPES_BROKEN
  145724. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145725. typedef unsigned char boolean;
  145726. #endif
  145727. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145728. #ifdef JPEG_INTERNALS
  145729. #undef RIGHT_SHIFT_IS_UNSIGNED
  145730. #endif /* JPEG_INTERNALS */
  145731. #ifdef JPEG_CJPEG_DJPEG
  145732. #define BMP_SUPPORTED /* BMP image file format */
  145733. #define GIF_SUPPORTED /* GIF image file format */
  145734. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145735. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145736. #define TARGA_SUPPORTED /* Targa image file format */
  145737. #define TWO_FILE_COMMANDLINE /* optional */
  145738. #define USE_SETMODE /* Microsoft has setmode() */
  145739. #undef NEED_SIGNAL_CATCHER
  145740. #undef DONT_USE_B_MODE
  145741. #undef PROGRESS_REPORT /* optional */
  145742. #endif /* JPEG_CJPEG_DJPEG */
  145743. /*** End of inlined file: jconfig.h ***/
  145744. /* auto configuration options */
  145745. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145746. #ifdef HAVE_STDDEF_H
  145747. #include <stddef.h>
  145748. #endif
  145749. #ifdef HAVE_STDLIB_H
  145750. #include <stdlib.h>
  145751. #endif
  145752. #ifdef NEED_SYS_TYPES_H
  145753. #include <sys/types.h>
  145754. #endif
  145755. #include <stdio.h>
  145756. #ifdef NEED_BSD_STRINGS
  145757. #include <strings.h>
  145758. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145759. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145760. #else /* not BSD, assume ANSI/SysV string lib */
  145761. #include <string.h>
  145762. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145763. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145764. #endif
  145765. #define SIZEOF(object) ((size_t) sizeof(object))
  145766. #define JFREAD(file,buf,sizeofbuf) \
  145767. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145768. #define JFWRITE(file,buf,sizeofbuf) \
  145769. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145770. typedef enum { /* JPEG marker codes */
  145771. M_SOF0 = 0xc0,
  145772. M_SOF1 = 0xc1,
  145773. M_SOF2 = 0xc2,
  145774. M_SOF3 = 0xc3,
  145775. M_SOF5 = 0xc5,
  145776. M_SOF6 = 0xc6,
  145777. M_SOF7 = 0xc7,
  145778. M_JPG = 0xc8,
  145779. M_SOF9 = 0xc9,
  145780. M_SOF10 = 0xca,
  145781. M_SOF11 = 0xcb,
  145782. M_SOF13 = 0xcd,
  145783. M_SOF14 = 0xce,
  145784. M_SOF15 = 0xcf,
  145785. M_DHT = 0xc4,
  145786. M_DAC = 0xcc,
  145787. M_RST0 = 0xd0,
  145788. M_RST1 = 0xd1,
  145789. M_RST2 = 0xd2,
  145790. M_RST3 = 0xd3,
  145791. M_RST4 = 0xd4,
  145792. M_RST5 = 0xd5,
  145793. M_RST6 = 0xd6,
  145794. M_RST7 = 0xd7,
  145795. M_SOI = 0xd8,
  145796. M_EOI = 0xd9,
  145797. M_SOS = 0xda,
  145798. M_DQT = 0xdb,
  145799. M_DNL = 0xdc,
  145800. M_DRI = 0xdd,
  145801. M_DHP = 0xde,
  145802. M_EXP = 0xdf,
  145803. M_APP0 = 0xe0,
  145804. M_APP1 = 0xe1,
  145805. M_APP2 = 0xe2,
  145806. M_APP3 = 0xe3,
  145807. M_APP4 = 0xe4,
  145808. M_APP5 = 0xe5,
  145809. M_APP6 = 0xe6,
  145810. M_APP7 = 0xe7,
  145811. M_APP8 = 0xe8,
  145812. M_APP9 = 0xe9,
  145813. M_APP10 = 0xea,
  145814. M_APP11 = 0xeb,
  145815. M_APP12 = 0xec,
  145816. M_APP13 = 0xed,
  145817. M_APP14 = 0xee,
  145818. M_APP15 = 0xef,
  145819. M_JPG0 = 0xf0,
  145820. M_JPG13 = 0xfd,
  145821. M_COM = 0xfe,
  145822. M_TEM = 0x01,
  145823. M_ERROR = 0x100
  145824. } JPEG_MARKER;
  145825. #ifdef AVOID_TABLES
  145826. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145827. #else
  145828. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145829. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145830. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145831. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145832. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145833. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145834. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145835. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145836. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145837. #endif /* AVOID_TABLES */
  145838. #endif
  145839. /*** End of inlined file: jinclude.h ***/
  145840. GLOBAL(void)
  145841. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145842. {
  145843. int i;
  145844. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145845. if (version != JPEG_LIB_VERSION)
  145846. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145847. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145848. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145849. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145850. {
  145851. struct jpeg_error_mgr * err = cinfo->err;
  145852. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145853. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145854. cinfo->err = err;
  145855. cinfo->client_data = client_data;
  145856. }
  145857. cinfo->is_decompressor = FALSE;
  145858. jinit_memory_mgr((j_common_ptr) cinfo);
  145859. cinfo->progress = NULL;
  145860. cinfo->dest = NULL;
  145861. cinfo->comp_info = NULL;
  145862. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145863. cinfo->quant_tbl_ptrs[i] = NULL;
  145864. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145865. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145866. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145867. }
  145868. cinfo->script_space = NULL;
  145869. cinfo->input_gamma = 1.0; /* in case application forgets */
  145870. cinfo->global_state = CSTATE_START;
  145871. }
  145872. GLOBAL(void)
  145873. jpeg_destroy_compress (j_compress_ptr cinfo)
  145874. {
  145875. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145876. }
  145877. GLOBAL(void)
  145878. jpeg_abort_compress (j_compress_ptr cinfo)
  145879. {
  145880. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145881. }
  145882. GLOBAL(void)
  145883. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145884. {
  145885. int i;
  145886. JQUANT_TBL * qtbl;
  145887. JHUFF_TBL * htbl;
  145888. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145889. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145890. qtbl->sent_table = suppress;
  145891. }
  145892. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145893. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145894. htbl->sent_table = suppress;
  145895. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145896. htbl->sent_table = suppress;
  145897. }
  145898. }
  145899. GLOBAL(void)
  145900. jpeg_finish_compress (j_compress_ptr cinfo)
  145901. {
  145902. JDIMENSION iMCU_row;
  145903. if (cinfo->global_state == CSTATE_SCANNING ||
  145904. cinfo->global_state == CSTATE_RAW_OK) {
  145905. if (cinfo->next_scanline < cinfo->image_height)
  145906. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145907. (*cinfo->master->finish_pass) (cinfo);
  145908. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145909. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145910. while (! cinfo->master->is_last_pass) {
  145911. (*cinfo->master->prepare_for_pass) (cinfo);
  145912. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  145913. if (cinfo->progress != NULL) {
  145914. cinfo->progress->pass_counter = (long) iMCU_row;
  145915. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  145916. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145917. }
  145918. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  145919. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  145920. }
  145921. (*cinfo->master->finish_pass) (cinfo);
  145922. }
  145923. (*cinfo->marker->write_file_trailer) (cinfo);
  145924. (*cinfo->dest->term_destination) (cinfo);
  145925. jpeg_abort((j_common_ptr) cinfo);
  145926. }
  145927. GLOBAL(void)
  145928. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  145929. const JOCTET *dataptr, unsigned int datalen)
  145930. {
  145931. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  145932. if (cinfo->next_scanline != 0 ||
  145933. (cinfo->global_state != CSTATE_SCANNING &&
  145934. cinfo->global_state != CSTATE_RAW_OK &&
  145935. cinfo->global_state != CSTATE_WRCOEFS))
  145936. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145937. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145938. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  145939. while (datalen--) {
  145940. (*write_marker_byte) (cinfo, *dataptr);
  145941. dataptr++;
  145942. }
  145943. }
  145944. GLOBAL(void)
  145945. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  145946. {
  145947. if (cinfo->next_scanline != 0 ||
  145948. (cinfo->global_state != CSTATE_SCANNING &&
  145949. cinfo->global_state != CSTATE_RAW_OK &&
  145950. cinfo->global_state != CSTATE_WRCOEFS))
  145951. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145952. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145953. }
  145954. GLOBAL(void)
  145955. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  145956. {
  145957. (*cinfo->marker->write_marker_byte) (cinfo, val);
  145958. }
  145959. GLOBAL(void)
  145960. jpeg_write_tables (j_compress_ptr cinfo)
  145961. {
  145962. if (cinfo->global_state != CSTATE_START)
  145963. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145964. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145965. (*cinfo->dest->init_destination) (cinfo);
  145966. jinit_marker_writer(cinfo);
  145967. (*cinfo->marker->write_tables_only) (cinfo);
  145968. (*cinfo->dest->term_destination) (cinfo);
  145969. }
  145970. /*** End of inlined file: jcapimin.c ***/
  145971. /*** Start of inlined file: jcapistd.c ***/
  145972. #define JPEG_INTERNALS
  145973. GLOBAL(void)
  145974. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  145975. {
  145976. if (cinfo->global_state != CSTATE_START)
  145977. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145978. if (write_all_tables)
  145979. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  145980. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145981. (*cinfo->dest->init_destination) (cinfo);
  145982. jinit_compress_master(cinfo);
  145983. (*cinfo->master->prepare_for_pass) (cinfo);
  145984. cinfo->next_scanline = 0;
  145985. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  145986. }
  145987. GLOBAL(JDIMENSION)
  145988. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  145989. JDIMENSION num_lines)
  145990. {
  145991. JDIMENSION row_ctr, rows_left;
  145992. if (cinfo->global_state != CSTATE_SCANNING)
  145993. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145994. if (cinfo->next_scanline >= cinfo->image_height)
  145995. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145996. if (cinfo->progress != NULL) {
  145997. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145998. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145999. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146000. }
  146001. if (cinfo->master->call_pass_startup)
  146002. (*cinfo->master->pass_startup) (cinfo);
  146003. rows_left = cinfo->image_height - cinfo->next_scanline;
  146004. if (num_lines > rows_left)
  146005. num_lines = rows_left;
  146006. row_ctr = 0;
  146007. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146008. cinfo->next_scanline += row_ctr;
  146009. return row_ctr;
  146010. }
  146011. GLOBAL(JDIMENSION)
  146012. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146013. JDIMENSION num_lines)
  146014. {
  146015. JDIMENSION lines_per_iMCU_row;
  146016. if (cinfo->global_state != CSTATE_RAW_OK)
  146017. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146018. if (cinfo->next_scanline >= cinfo->image_height) {
  146019. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146020. return 0;
  146021. }
  146022. if (cinfo->progress != NULL) {
  146023. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146024. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146025. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146026. }
  146027. if (cinfo->master->call_pass_startup)
  146028. (*cinfo->master->pass_startup) (cinfo);
  146029. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146030. if (num_lines < lines_per_iMCU_row)
  146031. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146032. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146033. return 0;
  146034. }
  146035. cinfo->next_scanline += lines_per_iMCU_row;
  146036. return lines_per_iMCU_row;
  146037. }
  146038. /*** End of inlined file: jcapistd.c ***/
  146039. /*** Start of inlined file: jccoefct.c ***/
  146040. #define JPEG_INTERNALS
  146041. #ifdef ENTROPY_OPT_SUPPORTED
  146042. #define FULL_COEF_BUFFER_SUPPORTED
  146043. #else
  146044. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146045. #define FULL_COEF_BUFFER_SUPPORTED
  146046. #endif
  146047. #endif
  146048. typedef struct {
  146049. struct jpeg_c_coef_controller pub; /* public fields */
  146050. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146051. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146052. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146053. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146054. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146055. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146056. } my_coef_controller;
  146057. typedef my_coef_controller * my_coef_ptr;
  146058. METHODDEF(boolean) compress_data
  146059. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146060. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146061. METHODDEF(boolean) compress_first_pass
  146062. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146063. METHODDEF(boolean) compress_output
  146064. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146065. #endif
  146066. LOCAL(void)
  146067. start_iMCU_row (j_compress_ptr cinfo)
  146068. {
  146069. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146070. if (cinfo->comps_in_scan > 1) {
  146071. coef->MCU_rows_per_iMCU_row = 1;
  146072. } else {
  146073. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146074. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146075. else
  146076. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146077. }
  146078. coef->mcu_ctr = 0;
  146079. coef->MCU_vert_offset = 0;
  146080. }
  146081. METHODDEF(void)
  146082. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146083. {
  146084. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146085. coef->iMCU_row_num = 0;
  146086. start_iMCU_row(cinfo);
  146087. switch (pass_mode) {
  146088. case JBUF_PASS_THRU:
  146089. if (coef->whole_image[0] != NULL)
  146090. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146091. coef->pub.compress_data = compress_data;
  146092. break;
  146093. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146094. case JBUF_SAVE_AND_PASS:
  146095. if (coef->whole_image[0] == NULL)
  146096. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146097. coef->pub.compress_data = compress_first_pass;
  146098. break;
  146099. case JBUF_CRANK_DEST:
  146100. if (coef->whole_image[0] == NULL)
  146101. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146102. coef->pub.compress_data = compress_output;
  146103. break;
  146104. #endif
  146105. default:
  146106. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146107. break;
  146108. }
  146109. }
  146110. METHODDEF(boolean)
  146111. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146112. {
  146113. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146114. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146115. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146116. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146117. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146118. JDIMENSION ypos, xpos;
  146119. jpeg_component_info *compptr;
  146120. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146121. yoffset++) {
  146122. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146123. MCU_col_num++) {
  146124. blkn = 0;
  146125. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146126. compptr = cinfo->cur_comp_info[ci];
  146127. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146128. : compptr->last_col_width;
  146129. xpos = MCU_col_num * compptr->MCU_sample_width;
  146130. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146131. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146132. if (coef->iMCU_row_num < last_iMCU_row ||
  146133. yoffset+yindex < compptr->last_row_height) {
  146134. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146135. input_buf[compptr->component_index],
  146136. coef->MCU_buffer[blkn],
  146137. ypos, xpos, (JDIMENSION) blockcnt);
  146138. if (blockcnt < compptr->MCU_width) {
  146139. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146140. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146141. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146142. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146143. }
  146144. }
  146145. } else {
  146146. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146147. compptr->MCU_width * SIZEOF(JBLOCK));
  146148. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146149. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146150. }
  146151. }
  146152. blkn += compptr->MCU_width;
  146153. ypos += DCTSIZE;
  146154. }
  146155. }
  146156. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146157. coef->MCU_vert_offset = yoffset;
  146158. coef->mcu_ctr = MCU_col_num;
  146159. return FALSE;
  146160. }
  146161. }
  146162. coef->mcu_ctr = 0;
  146163. }
  146164. coef->iMCU_row_num++;
  146165. start_iMCU_row(cinfo);
  146166. return TRUE;
  146167. }
  146168. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146169. METHODDEF(boolean)
  146170. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146171. {
  146172. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146173. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146174. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146175. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146176. JCOEF lastDC;
  146177. jpeg_component_info *compptr;
  146178. JBLOCKARRAY buffer;
  146179. JBLOCKROW thisblockrow, lastblockrow;
  146180. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146181. ci++, compptr++) {
  146182. buffer = (*cinfo->mem->access_virt_barray)
  146183. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146184. coef->iMCU_row_num * compptr->v_samp_factor,
  146185. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146186. if (coef->iMCU_row_num < last_iMCU_row)
  146187. block_rows = compptr->v_samp_factor;
  146188. else {
  146189. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146190. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146191. }
  146192. blocks_across = compptr->width_in_blocks;
  146193. h_samp_factor = compptr->h_samp_factor;
  146194. ndummy = (int) (blocks_across % h_samp_factor);
  146195. if (ndummy > 0)
  146196. ndummy = h_samp_factor - ndummy;
  146197. for (block_row = 0; block_row < block_rows; block_row++) {
  146198. thisblockrow = buffer[block_row];
  146199. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146200. input_buf[ci], thisblockrow,
  146201. (JDIMENSION) (block_row * DCTSIZE),
  146202. (JDIMENSION) 0, blocks_across);
  146203. if (ndummy > 0) {
  146204. thisblockrow += blocks_across; /* => first dummy block */
  146205. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146206. lastDC = thisblockrow[-1][0];
  146207. for (bi = 0; bi < ndummy; bi++) {
  146208. thisblockrow[bi][0] = lastDC;
  146209. }
  146210. }
  146211. }
  146212. if (coef->iMCU_row_num == last_iMCU_row) {
  146213. blocks_across += ndummy; /* include lower right corner */
  146214. MCUs_across = blocks_across / h_samp_factor;
  146215. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146216. block_row++) {
  146217. thisblockrow = buffer[block_row];
  146218. lastblockrow = buffer[block_row-1];
  146219. jzero_far((void FAR *) thisblockrow,
  146220. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146221. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146222. lastDC = lastblockrow[h_samp_factor-1][0];
  146223. for (bi = 0; bi < h_samp_factor; bi++) {
  146224. thisblockrow[bi][0] = lastDC;
  146225. }
  146226. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146227. lastblockrow += h_samp_factor;
  146228. }
  146229. }
  146230. }
  146231. }
  146232. return compress_output(cinfo, input_buf);
  146233. }
  146234. METHODDEF(boolean)
  146235. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146236. {
  146237. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146238. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146239. int blkn, ci, xindex, yindex, yoffset;
  146240. JDIMENSION start_col;
  146241. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146242. JBLOCKROW buffer_ptr;
  146243. jpeg_component_info *compptr;
  146244. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146245. compptr = cinfo->cur_comp_info[ci];
  146246. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146247. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146248. coef->iMCU_row_num * compptr->v_samp_factor,
  146249. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146250. }
  146251. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146252. yoffset++) {
  146253. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146254. MCU_col_num++) {
  146255. blkn = 0; /* index of current DCT block within MCU */
  146256. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146257. compptr = cinfo->cur_comp_info[ci];
  146258. start_col = MCU_col_num * compptr->MCU_width;
  146259. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146260. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146261. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146262. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146263. }
  146264. }
  146265. }
  146266. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146267. coef->MCU_vert_offset = yoffset;
  146268. coef->mcu_ctr = MCU_col_num;
  146269. return FALSE;
  146270. }
  146271. }
  146272. coef->mcu_ctr = 0;
  146273. }
  146274. coef->iMCU_row_num++;
  146275. start_iMCU_row(cinfo);
  146276. return TRUE;
  146277. }
  146278. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146279. GLOBAL(void)
  146280. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146281. {
  146282. my_coef_ptr coef;
  146283. coef = (my_coef_ptr)
  146284. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146285. SIZEOF(my_coef_controller));
  146286. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146287. coef->pub.start_pass = start_pass_coef;
  146288. if (need_full_buffer) {
  146289. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146290. int ci;
  146291. jpeg_component_info *compptr;
  146292. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146293. ci++, compptr++) {
  146294. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146295. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146296. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146297. (long) compptr->h_samp_factor),
  146298. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146299. (long) compptr->v_samp_factor),
  146300. (JDIMENSION) compptr->v_samp_factor);
  146301. }
  146302. #else
  146303. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146304. #endif
  146305. } else {
  146306. JBLOCKROW buffer;
  146307. int i;
  146308. buffer = (JBLOCKROW)
  146309. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146310. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146311. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146312. coef->MCU_buffer[i] = buffer + i;
  146313. }
  146314. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146315. }
  146316. }
  146317. /*** End of inlined file: jccoefct.c ***/
  146318. /*** Start of inlined file: jccolor.c ***/
  146319. #define JPEG_INTERNALS
  146320. typedef struct {
  146321. struct jpeg_color_converter pub; /* public fields */
  146322. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146323. } my_color_converter;
  146324. typedef my_color_converter * my_cconvert_ptr;
  146325. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146326. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146327. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146328. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146329. #define R_Y_OFF 0 /* offset to R => Y section */
  146330. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146331. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146332. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146333. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146334. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146335. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146336. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146337. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146338. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146339. METHODDEF(void)
  146340. rgb_ycc_start (j_compress_ptr cinfo)
  146341. {
  146342. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146343. INT32 * rgb_ycc_tab;
  146344. INT32 i;
  146345. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146346. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146347. (TABLE_SIZE * SIZEOF(INT32)));
  146348. for (i = 0; i <= MAXJSAMPLE; i++) {
  146349. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146350. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146351. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146352. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146353. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146354. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146355. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146356. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146357. }
  146358. }
  146359. METHODDEF(void)
  146360. rgb_ycc_convert (j_compress_ptr cinfo,
  146361. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146362. JDIMENSION output_row, int num_rows)
  146363. {
  146364. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146365. register int r, g, b;
  146366. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146367. register JSAMPROW inptr;
  146368. register JSAMPROW outptr0, outptr1, outptr2;
  146369. register JDIMENSION col;
  146370. JDIMENSION num_cols = cinfo->image_width;
  146371. while (--num_rows >= 0) {
  146372. inptr = *input_buf++;
  146373. outptr0 = output_buf[0][output_row];
  146374. outptr1 = output_buf[1][output_row];
  146375. outptr2 = output_buf[2][output_row];
  146376. output_row++;
  146377. for (col = 0; col < num_cols; col++) {
  146378. r = GETJSAMPLE(inptr[RGB_RED]);
  146379. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146380. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146381. inptr += RGB_PIXELSIZE;
  146382. outptr0[col] = (JSAMPLE)
  146383. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146384. >> SCALEBITS);
  146385. outptr1[col] = (JSAMPLE)
  146386. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146387. >> SCALEBITS);
  146388. outptr2[col] = (JSAMPLE)
  146389. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146390. >> SCALEBITS);
  146391. }
  146392. }
  146393. }
  146394. METHODDEF(void)
  146395. rgb_gray_convert (j_compress_ptr cinfo,
  146396. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146397. JDIMENSION output_row, int num_rows)
  146398. {
  146399. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146400. register int r, g, b;
  146401. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146402. register JSAMPROW inptr;
  146403. register JSAMPROW outptr;
  146404. register JDIMENSION col;
  146405. JDIMENSION num_cols = cinfo->image_width;
  146406. while (--num_rows >= 0) {
  146407. inptr = *input_buf++;
  146408. outptr = output_buf[0][output_row];
  146409. output_row++;
  146410. for (col = 0; col < num_cols; col++) {
  146411. r = GETJSAMPLE(inptr[RGB_RED]);
  146412. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146413. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146414. inptr += RGB_PIXELSIZE;
  146415. outptr[col] = (JSAMPLE)
  146416. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146417. >> SCALEBITS);
  146418. }
  146419. }
  146420. }
  146421. METHODDEF(void)
  146422. cmyk_ycck_convert (j_compress_ptr cinfo,
  146423. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146424. JDIMENSION output_row, int num_rows)
  146425. {
  146426. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146427. register int r, g, b;
  146428. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146429. register JSAMPROW inptr;
  146430. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146431. register JDIMENSION col;
  146432. JDIMENSION num_cols = cinfo->image_width;
  146433. while (--num_rows >= 0) {
  146434. inptr = *input_buf++;
  146435. outptr0 = output_buf[0][output_row];
  146436. outptr1 = output_buf[1][output_row];
  146437. outptr2 = output_buf[2][output_row];
  146438. outptr3 = output_buf[3][output_row];
  146439. output_row++;
  146440. for (col = 0; col < num_cols; col++) {
  146441. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146442. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146443. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146444. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146445. inptr += 4;
  146446. outptr0[col] = (JSAMPLE)
  146447. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146448. >> SCALEBITS);
  146449. outptr1[col] = (JSAMPLE)
  146450. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146451. >> SCALEBITS);
  146452. outptr2[col] = (JSAMPLE)
  146453. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146454. >> SCALEBITS);
  146455. }
  146456. }
  146457. }
  146458. METHODDEF(void)
  146459. grayscale_convert (j_compress_ptr cinfo,
  146460. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146461. JDIMENSION output_row, int num_rows)
  146462. {
  146463. register JSAMPROW inptr;
  146464. register JSAMPROW outptr;
  146465. register JDIMENSION col;
  146466. JDIMENSION num_cols = cinfo->image_width;
  146467. int instride = cinfo->input_components;
  146468. while (--num_rows >= 0) {
  146469. inptr = *input_buf++;
  146470. outptr = output_buf[0][output_row];
  146471. output_row++;
  146472. for (col = 0; col < num_cols; col++) {
  146473. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146474. inptr += instride;
  146475. }
  146476. }
  146477. }
  146478. METHODDEF(void)
  146479. null_convert (j_compress_ptr cinfo,
  146480. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146481. JDIMENSION output_row, int num_rows)
  146482. {
  146483. register JSAMPROW inptr;
  146484. register JSAMPROW outptr;
  146485. register JDIMENSION col;
  146486. register int ci;
  146487. int nc = cinfo->num_components;
  146488. JDIMENSION num_cols = cinfo->image_width;
  146489. while (--num_rows >= 0) {
  146490. for (ci = 0; ci < nc; ci++) {
  146491. inptr = *input_buf;
  146492. outptr = output_buf[ci][output_row];
  146493. for (col = 0; col < num_cols; col++) {
  146494. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146495. inptr += nc;
  146496. }
  146497. }
  146498. input_buf++;
  146499. output_row++;
  146500. }
  146501. }
  146502. METHODDEF(void)
  146503. null_method (j_compress_ptr cinfo)
  146504. {
  146505. }
  146506. GLOBAL(void)
  146507. jinit_color_converter (j_compress_ptr cinfo)
  146508. {
  146509. my_cconvert_ptr cconvert;
  146510. cconvert = (my_cconvert_ptr)
  146511. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146512. SIZEOF(my_color_converter));
  146513. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146514. cconvert->pub.start_pass = null_method;
  146515. switch (cinfo->in_color_space) {
  146516. case JCS_GRAYSCALE:
  146517. if (cinfo->input_components != 1)
  146518. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146519. break;
  146520. case JCS_RGB:
  146521. #if RGB_PIXELSIZE != 3
  146522. if (cinfo->input_components != RGB_PIXELSIZE)
  146523. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146524. break;
  146525. #endif /* else share code with YCbCr */
  146526. case JCS_YCbCr:
  146527. if (cinfo->input_components != 3)
  146528. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146529. break;
  146530. case JCS_CMYK:
  146531. case JCS_YCCK:
  146532. if (cinfo->input_components != 4)
  146533. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146534. break;
  146535. default: /* JCS_UNKNOWN can be anything */
  146536. if (cinfo->input_components < 1)
  146537. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146538. break;
  146539. }
  146540. switch (cinfo->jpeg_color_space) {
  146541. case JCS_GRAYSCALE:
  146542. if (cinfo->num_components != 1)
  146543. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146544. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146545. cconvert->pub.color_convert = grayscale_convert;
  146546. else if (cinfo->in_color_space == JCS_RGB) {
  146547. cconvert->pub.start_pass = rgb_ycc_start;
  146548. cconvert->pub.color_convert = rgb_gray_convert;
  146549. } else if (cinfo->in_color_space == JCS_YCbCr)
  146550. cconvert->pub.color_convert = grayscale_convert;
  146551. else
  146552. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146553. break;
  146554. case JCS_RGB:
  146555. if (cinfo->num_components != 3)
  146556. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146557. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146558. cconvert->pub.color_convert = null_convert;
  146559. else
  146560. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146561. break;
  146562. case JCS_YCbCr:
  146563. if (cinfo->num_components != 3)
  146564. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146565. if (cinfo->in_color_space == JCS_RGB) {
  146566. cconvert->pub.start_pass = rgb_ycc_start;
  146567. cconvert->pub.color_convert = rgb_ycc_convert;
  146568. } else if (cinfo->in_color_space == JCS_YCbCr)
  146569. cconvert->pub.color_convert = null_convert;
  146570. else
  146571. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146572. break;
  146573. case JCS_CMYK:
  146574. if (cinfo->num_components != 4)
  146575. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146576. if (cinfo->in_color_space == JCS_CMYK)
  146577. cconvert->pub.color_convert = null_convert;
  146578. else
  146579. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146580. break;
  146581. case JCS_YCCK:
  146582. if (cinfo->num_components != 4)
  146583. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146584. if (cinfo->in_color_space == JCS_CMYK) {
  146585. cconvert->pub.start_pass = rgb_ycc_start;
  146586. cconvert->pub.color_convert = cmyk_ycck_convert;
  146587. } else if (cinfo->in_color_space == JCS_YCCK)
  146588. cconvert->pub.color_convert = null_convert;
  146589. else
  146590. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146591. break;
  146592. default: /* allow null conversion of JCS_UNKNOWN */
  146593. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146594. cinfo->num_components != cinfo->input_components)
  146595. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146596. cconvert->pub.color_convert = null_convert;
  146597. break;
  146598. }
  146599. }
  146600. /*** End of inlined file: jccolor.c ***/
  146601. #undef FIX
  146602. /*** Start of inlined file: jcdctmgr.c ***/
  146603. #define JPEG_INTERNALS
  146604. /*** Start of inlined file: jdct.h ***/
  146605. #ifndef __jdct_h__
  146606. #define __jdct_h__
  146607. #if BITS_IN_JSAMPLE == 8
  146608. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146609. #else
  146610. typedef INT32 DCTELEM; /* must have 32 bits */
  146611. #endif
  146612. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146613. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146614. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146615. #if BITS_IN_JSAMPLE == 8
  146616. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146617. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146618. #else
  146619. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146620. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146621. #endif
  146622. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146623. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146624. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146625. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146626. #define jpeg_fdct_islow jFDislow
  146627. #define jpeg_fdct_ifast jFDifast
  146628. #define jpeg_fdct_float jFDfloat
  146629. #define jpeg_idct_islow jRDislow
  146630. #define jpeg_idct_ifast jRDifast
  146631. #define jpeg_idct_float jRDfloat
  146632. #define jpeg_idct_4x4 jRD4x4
  146633. #define jpeg_idct_2x2 jRD2x2
  146634. #define jpeg_idct_1x1 jRD1x1
  146635. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146636. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146637. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146638. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146639. EXTERN(void) jpeg_idct_islow
  146640. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146641. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146642. EXTERN(void) jpeg_idct_ifast
  146643. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146644. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146645. EXTERN(void) jpeg_idct_float
  146646. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146647. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146648. EXTERN(void) jpeg_idct_4x4
  146649. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146650. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146651. EXTERN(void) jpeg_idct_2x2
  146652. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146653. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146654. EXTERN(void) jpeg_idct_1x1
  146655. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146656. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146657. #define ONE ((INT32) 1)
  146658. #define CONST_SCALE (ONE << CONST_BITS)
  146659. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146660. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146661. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146662. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146663. #endif
  146664. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146665. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146666. #endif
  146667. #ifndef MULTIPLY16C16 /* default definition */
  146668. #define MULTIPLY16C16(var,const) ((var) * (const))
  146669. #endif
  146670. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146671. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146672. #endif
  146673. #ifndef MULTIPLY16V16 /* default definition */
  146674. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146675. #endif
  146676. #endif
  146677. /*** End of inlined file: jdct.h ***/
  146678. /* Private declarations for DCT subsystem */
  146679. typedef struct {
  146680. struct jpeg_forward_dct pub; /* public fields */
  146681. forward_DCT_method_ptr do_dct;
  146682. DCTELEM * divisors[NUM_QUANT_TBLS];
  146683. #ifdef DCT_FLOAT_SUPPORTED
  146684. float_DCT_method_ptr do_float_dct;
  146685. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146686. #endif
  146687. } my_fdct_controller;
  146688. typedef my_fdct_controller * my_fdct_ptr;
  146689. METHODDEF(void)
  146690. start_pass_fdctmgr (j_compress_ptr cinfo)
  146691. {
  146692. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146693. int ci, qtblno, i;
  146694. jpeg_component_info *compptr;
  146695. JQUANT_TBL * qtbl;
  146696. DCTELEM * dtbl;
  146697. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146698. ci++, compptr++) {
  146699. qtblno = compptr->quant_tbl_no;
  146700. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146701. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146702. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146703. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146704. switch (cinfo->dct_method) {
  146705. #ifdef DCT_ISLOW_SUPPORTED
  146706. case JDCT_ISLOW:
  146707. if (fdct->divisors[qtblno] == NULL) {
  146708. fdct->divisors[qtblno] = (DCTELEM *)
  146709. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146710. DCTSIZE2 * SIZEOF(DCTELEM));
  146711. }
  146712. dtbl = fdct->divisors[qtblno];
  146713. for (i = 0; i < DCTSIZE2; i++) {
  146714. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146715. }
  146716. break;
  146717. #endif
  146718. #ifdef DCT_IFAST_SUPPORTED
  146719. case JDCT_IFAST:
  146720. {
  146721. #define CONST_BITS 14
  146722. static const INT16 aanscales[DCTSIZE2] = {
  146723. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146724. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146725. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146726. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146727. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146728. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146729. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146730. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146731. };
  146732. SHIFT_TEMPS
  146733. if (fdct->divisors[qtblno] == NULL) {
  146734. fdct->divisors[qtblno] = (DCTELEM *)
  146735. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146736. DCTSIZE2 * SIZEOF(DCTELEM));
  146737. }
  146738. dtbl = fdct->divisors[qtblno];
  146739. for (i = 0; i < DCTSIZE2; i++) {
  146740. dtbl[i] = (DCTELEM)
  146741. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146742. (INT32) aanscales[i]),
  146743. CONST_BITS-3);
  146744. }
  146745. }
  146746. break;
  146747. #endif
  146748. #ifdef DCT_FLOAT_SUPPORTED
  146749. case JDCT_FLOAT:
  146750. {
  146751. FAST_FLOAT * fdtbl;
  146752. int row, col;
  146753. static const double aanscalefactor[DCTSIZE] = {
  146754. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146755. 1.0, 0.785694958, 0.541196100, 0.275899379
  146756. };
  146757. if (fdct->float_divisors[qtblno] == NULL) {
  146758. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146759. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146760. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146761. }
  146762. fdtbl = fdct->float_divisors[qtblno];
  146763. i = 0;
  146764. for (row = 0; row < DCTSIZE; row++) {
  146765. for (col = 0; col < DCTSIZE; col++) {
  146766. fdtbl[i] = (FAST_FLOAT)
  146767. (1.0 / (((double) qtbl->quantval[i] *
  146768. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146769. i++;
  146770. }
  146771. }
  146772. }
  146773. break;
  146774. #endif
  146775. default:
  146776. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146777. break;
  146778. }
  146779. }
  146780. }
  146781. METHODDEF(void)
  146782. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146783. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146784. JDIMENSION start_row, JDIMENSION start_col,
  146785. JDIMENSION num_blocks)
  146786. {
  146787. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146788. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146789. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146790. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146791. JDIMENSION bi;
  146792. sample_data += start_row; /* fold in the vertical offset once */
  146793. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146794. { register DCTELEM *workspaceptr;
  146795. register JSAMPROW elemptr;
  146796. register int elemr;
  146797. workspaceptr = workspace;
  146798. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146799. elemptr = sample_data[elemr] + start_col;
  146800. #if DCTSIZE == 8 /* unroll the inner loop */
  146801. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146802. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146803. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146804. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146805. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146806. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146807. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146808. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146809. #else
  146810. { register int elemc;
  146811. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146812. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146813. }
  146814. }
  146815. #endif
  146816. }
  146817. }
  146818. (*do_dct) (workspace);
  146819. { register DCTELEM temp, qval;
  146820. register int i;
  146821. register JCOEFPTR output_ptr = coef_blocks[bi];
  146822. for (i = 0; i < DCTSIZE2; i++) {
  146823. qval = divisors[i];
  146824. temp = workspace[i];
  146825. #ifdef FAST_DIVIDE
  146826. #define DIVIDE_BY(a,b) a /= b
  146827. #else
  146828. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146829. #endif
  146830. if (temp < 0) {
  146831. temp = -temp;
  146832. temp += qval>>1; /* for rounding */
  146833. DIVIDE_BY(temp, qval);
  146834. temp = -temp;
  146835. } else {
  146836. temp += qval>>1; /* for rounding */
  146837. DIVIDE_BY(temp, qval);
  146838. }
  146839. output_ptr[i] = (JCOEF) temp;
  146840. }
  146841. }
  146842. }
  146843. }
  146844. #ifdef DCT_FLOAT_SUPPORTED
  146845. METHODDEF(void)
  146846. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146847. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146848. JDIMENSION start_row, JDIMENSION start_col,
  146849. JDIMENSION num_blocks)
  146850. {
  146851. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146852. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146853. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146854. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146855. JDIMENSION bi;
  146856. sample_data += start_row; /* fold in the vertical offset once */
  146857. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146858. { register FAST_FLOAT *workspaceptr;
  146859. register JSAMPROW elemptr;
  146860. register int elemr;
  146861. workspaceptr = workspace;
  146862. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146863. elemptr = sample_data[elemr] + start_col;
  146864. #if DCTSIZE == 8 /* unroll the inner loop */
  146865. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146866. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146867. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146868. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146869. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146870. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146871. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146872. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146873. #else
  146874. { register int elemc;
  146875. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146876. *workspaceptr++ = (FAST_FLOAT)
  146877. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146878. }
  146879. }
  146880. #endif
  146881. }
  146882. }
  146883. (*do_dct) (workspace);
  146884. { register FAST_FLOAT temp;
  146885. register int i;
  146886. register JCOEFPTR output_ptr = coef_blocks[bi];
  146887. for (i = 0; i < DCTSIZE2; i++) {
  146888. temp = workspace[i] * divisors[i];
  146889. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146890. }
  146891. }
  146892. }
  146893. }
  146894. #endif /* DCT_FLOAT_SUPPORTED */
  146895. GLOBAL(void)
  146896. jinit_forward_dct (j_compress_ptr cinfo)
  146897. {
  146898. my_fdct_ptr fdct;
  146899. int i;
  146900. fdct = (my_fdct_ptr)
  146901. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146902. SIZEOF(my_fdct_controller));
  146903. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146904. fdct->pub.start_pass = start_pass_fdctmgr;
  146905. switch (cinfo->dct_method) {
  146906. #ifdef DCT_ISLOW_SUPPORTED
  146907. case JDCT_ISLOW:
  146908. fdct->pub.forward_DCT = forward_DCT;
  146909. fdct->do_dct = jpeg_fdct_islow;
  146910. break;
  146911. #endif
  146912. #ifdef DCT_IFAST_SUPPORTED
  146913. case JDCT_IFAST:
  146914. fdct->pub.forward_DCT = forward_DCT;
  146915. fdct->do_dct = jpeg_fdct_ifast;
  146916. break;
  146917. #endif
  146918. #ifdef DCT_FLOAT_SUPPORTED
  146919. case JDCT_FLOAT:
  146920. fdct->pub.forward_DCT = forward_DCT_float;
  146921. fdct->do_float_dct = jpeg_fdct_float;
  146922. break;
  146923. #endif
  146924. default:
  146925. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146926. break;
  146927. }
  146928. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146929. fdct->divisors[i] = NULL;
  146930. #ifdef DCT_FLOAT_SUPPORTED
  146931. fdct->float_divisors[i] = NULL;
  146932. #endif
  146933. }
  146934. }
  146935. /*** End of inlined file: jcdctmgr.c ***/
  146936. #undef CONST_BITS
  146937. /*** Start of inlined file: jchuff.c ***/
  146938. #define JPEG_INTERNALS
  146939. /*** Start of inlined file: jchuff.h ***/
  146940. #ifndef _jchuff_h_
  146941. #define _jchuff_h_
  146942. #if BITS_IN_JSAMPLE == 8
  146943. #define MAX_COEF_BITS 10
  146944. #else
  146945. #define MAX_COEF_BITS 14
  146946. #endif
  146947. typedef struct {
  146948. unsigned int ehufco[256]; /* code for each symbol */
  146949. char ehufsi[256]; /* length of code for each symbol */
  146950. } c_derived_tbl;
  146951. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146952. #define jpeg_make_c_derived_tbl jMkCDerived
  146953. #define jpeg_gen_optimal_table jGenOptTbl
  146954. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146955. EXTERN(void) jpeg_make_c_derived_tbl
  146956. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  146957. c_derived_tbl ** pdtbl));
  146958. EXTERN(void) jpeg_gen_optimal_table
  146959. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  146960. #endif
  146961. /*** End of inlined file: jchuff.h ***/
  146962. /* Declarations shared with jcphuff.c */
  146963. typedef struct {
  146964. INT32 put_buffer; /* current bit-accumulation buffer */
  146965. int put_bits; /* # of bits now in it */
  146966. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  146967. } savable_state;
  146968. #ifndef NO_STRUCT_ASSIGN
  146969. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  146970. #else
  146971. #if MAX_COMPS_IN_SCAN == 4
  146972. #define ASSIGN_STATE(dest,src) \
  146973. ((dest).put_buffer = (src).put_buffer, \
  146974. (dest).put_bits = (src).put_bits, \
  146975. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  146976. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  146977. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  146978. (dest).last_dc_val[3] = (src).last_dc_val[3])
  146979. #endif
  146980. #endif
  146981. typedef struct {
  146982. struct jpeg_entropy_encoder pub; /* public fields */
  146983. savable_state saved; /* Bit buffer & DC state at start of MCU */
  146984. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  146985. int next_restart_num; /* next restart number to write (0-7) */
  146986. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  146987. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  146988. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  146989. long * dc_count_ptrs[NUM_HUFF_TBLS];
  146990. long * ac_count_ptrs[NUM_HUFF_TBLS];
  146991. #endif
  146992. } huff_entropy_encoder;
  146993. typedef huff_entropy_encoder * huff_entropy_ptr;
  146994. typedef struct {
  146995. JOCTET * next_output_byte; /* => next byte to write in buffer */
  146996. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  146997. savable_state cur; /* Current bit buffer & DC state */
  146998. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  146999. } working_state;
  147000. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147001. JBLOCKROW *MCU_data));
  147002. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147003. #ifdef ENTROPY_OPT_SUPPORTED
  147004. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147005. JBLOCKROW *MCU_data));
  147006. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147007. #endif
  147008. METHODDEF(void)
  147009. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147010. {
  147011. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147012. int ci, dctbl, actbl;
  147013. jpeg_component_info * compptr;
  147014. if (gather_statistics) {
  147015. #ifdef ENTROPY_OPT_SUPPORTED
  147016. entropy->pub.encode_mcu = encode_mcu_gather;
  147017. entropy->pub.finish_pass = finish_pass_gather;
  147018. #else
  147019. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147020. #endif
  147021. } else {
  147022. entropy->pub.encode_mcu = encode_mcu_huff;
  147023. entropy->pub.finish_pass = finish_pass_huff;
  147024. }
  147025. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147026. compptr = cinfo->cur_comp_info[ci];
  147027. dctbl = compptr->dc_tbl_no;
  147028. actbl = compptr->ac_tbl_no;
  147029. if (gather_statistics) {
  147030. #ifdef ENTROPY_OPT_SUPPORTED
  147031. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147032. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147033. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147034. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147035. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147036. entropy->dc_count_ptrs[dctbl] = (long *)
  147037. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147038. 257 * SIZEOF(long));
  147039. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147040. if (entropy->ac_count_ptrs[actbl] == NULL)
  147041. entropy->ac_count_ptrs[actbl] = (long *)
  147042. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147043. 257 * SIZEOF(long));
  147044. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147045. #endif
  147046. } else {
  147047. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147048. & entropy->dc_derived_tbls[dctbl]);
  147049. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147050. & entropy->ac_derived_tbls[actbl]);
  147051. }
  147052. entropy->saved.last_dc_val[ci] = 0;
  147053. }
  147054. entropy->saved.put_buffer = 0;
  147055. entropy->saved.put_bits = 0;
  147056. entropy->restarts_to_go = cinfo->restart_interval;
  147057. entropy->next_restart_num = 0;
  147058. }
  147059. GLOBAL(void)
  147060. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147061. c_derived_tbl ** pdtbl)
  147062. {
  147063. JHUFF_TBL *htbl;
  147064. c_derived_tbl *dtbl;
  147065. int p, i, l, lastp, si, maxsymbol;
  147066. char huffsize[257];
  147067. unsigned int huffcode[257];
  147068. unsigned int code;
  147069. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147070. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147071. htbl =
  147072. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147073. if (htbl == NULL)
  147074. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147075. if (*pdtbl == NULL)
  147076. *pdtbl = (c_derived_tbl *)
  147077. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147078. SIZEOF(c_derived_tbl));
  147079. dtbl = *pdtbl;
  147080. p = 0;
  147081. for (l = 1; l <= 16; l++) {
  147082. i = (int) htbl->bits[l];
  147083. if (i < 0 || p + i > 256) /* protect against table overrun */
  147084. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147085. while (i--)
  147086. huffsize[p++] = (char) l;
  147087. }
  147088. huffsize[p] = 0;
  147089. lastp = p;
  147090. code = 0;
  147091. si = huffsize[0];
  147092. p = 0;
  147093. while (huffsize[p]) {
  147094. while (((int) huffsize[p]) == si) {
  147095. huffcode[p++] = code;
  147096. code++;
  147097. }
  147098. if (((INT32) code) >= (((INT32) 1) << si))
  147099. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147100. code <<= 1;
  147101. si++;
  147102. }
  147103. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147104. maxsymbol = isDC ? 15 : 255;
  147105. for (p = 0; p < lastp; p++) {
  147106. i = htbl->huffval[p];
  147107. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147108. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147109. dtbl->ehufco[i] = huffcode[p];
  147110. dtbl->ehufsi[i] = huffsize[p];
  147111. }
  147112. }
  147113. #define emit_byte(state,val,action) \
  147114. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147115. if (--(state)->free_in_buffer == 0) \
  147116. if (! dump_buffer(state)) \
  147117. { action; } }
  147118. LOCAL(boolean)
  147119. dump_buffer (working_state * state)
  147120. {
  147121. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147122. if (! (*dest->empty_output_buffer) (state->cinfo))
  147123. return FALSE;
  147124. state->next_output_byte = dest->next_output_byte;
  147125. state->free_in_buffer = dest->free_in_buffer;
  147126. return TRUE;
  147127. }
  147128. INLINE
  147129. LOCAL(boolean)
  147130. emit_bits (working_state * state, unsigned int code, int size)
  147131. {
  147132. register INT32 put_buffer = (INT32) code;
  147133. register int put_bits = state->cur.put_bits;
  147134. if (size == 0)
  147135. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147136. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147137. put_bits += size; /* new number of bits in buffer */
  147138. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147139. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147140. while (put_bits >= 8) {
  147141. int c = (int) ((put_buffer >> 16) & 0xFF);
  147142. emit_byte(state, c, return FALSE);
  147143. if (c == 0xFF) { /* need to stuff a zero byte? */
  147144. emit_byte(state, 0, return FALSE);
  147145. }
  147146. put_buffer <<= 8;
  147147. put_bits -= 8;
  147148. }
  147149. state->cur.put_buffer = put_buffer; /* update state variables */
  147150. state->cur.put_bits = put_bits;
  147151. return TRUE;
  147152. }
  147153. LOCAL(boolean)
  147154. flush_bits (working_state * state)
  147155. {
  147156. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147157. return FALSE;
  147158. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147159. state->cur.put_bits = 0;
  147160. return TRUE;
  147161. }
  147162. LOCAL(boolean)
  147163. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147164. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147165. {
  147166. register int temp, temp2;
  147167. register int nbits;
  147168. register int k, r, i;
  147169. temp = temp2 = block[0] - last_dc_val;
  147170. if (temp < 0) {
  147171. temp = -temp; /* temp is abs value of input */
  147172. temp2--;
  147173. }
  147174. nbits = 0;
  147175. while (temp) {
  147176. nbits++;
  147177. temp >>= 1;
  147178. }
  147179. if (nbits > MAX_COEF_BITS+1)
  147180. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147181. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147182. return FALSE;
  147183. if (nbits) /* emit_bits rejects calls with size 0 */
  147184. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147185. return FALSE;
  147186. r = 0; /* r = run length of zeros */
  147187. for (k = 1; k < DCTSIZE2; k++) {
  147188. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147189. r++;
  147190. } else {
  147191. while (r > 15) {
  147192. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147193. return FALSE;
  147194. r -= 16;
  147195. }
  147196. temp2 = temp;
  147197. if (temp < 0) {
  147198. temp = -temp; /* temp is abs value of input */
  147199. temp2--;
  147200. }
  147201. nbits = 1; /* there must be at least one 1 bit */
  147202. while ((temp >>= 1))
  147203. nbits++;
  147204. if (nbits > MAX_COEF_BITS)
  147205. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147206. i = (r << 4) + nbits;
  147207. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147208. return FALSE;
  147209. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147210. return FALSE;
  147211. r = 0;
  147212. }
  147213. }
  147214. if (r > 0)
  147215. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147216. return FALSE;
  147217. return TRUE;
  147218. }
  147219. LOCAL(boolean)
  147220. emit_restart (working_state * state, int restart_num)
  147221. {
  147222. int ci;
  147223. if (! flush_bits(state))
  147224. return FALSE;
  147225. emit_byte(state, 0xFF, return FALSE);
  147226. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147227. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147228. state->cur.last_dc_val[ci] = 0;
  147229. return TRUE;
  147230. }
  147231. METHODDEF(boolean)
  147232. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147233. {
  147234. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147235. working_state state;
  147236. int blkn, ci;
  147237. jpeg_component_info * compptr;
  147238. state.next_output_byte = cinfo->dest->next_output_byte;
  147239. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147240. ASSIGN_STATE(state.cur, entropy->saved);
  147241. state.cinfo = cinfo;
  147242. if (cinfo->restart_interval) {
  147243. if (entropy->restarts_to_go == 0)
  147244. if (! emit_restart(&state, entropy->next_restart_num))
  147245. return FALSE;
  147246. }
  147247. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147248. ci = cinfo->MCU_membership[blkn];
  147249. compptr = cinfo->cur_comp_info[ci];
  147250. if (! encode_one_block(&state,
  147251. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147252. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147253. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147254. return FALSE;
  147255. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147256. }
  147257. cinfo->dest->next_output_byte = state.next_output_byte;
  147258. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147259. ASSIGN_STATE(entropy->saved, state.cur);
  147260. if (cinfo->restart_interval) {
  147261. if (entropy->restarts_to_go == 0) {
  147262. entropy->restarts_to_go = cinfo->restart_interval;
  147263. entropy->next_restart_num++;
  147264. entropy->next_restart_num &= 7;
  147265. }
  147266. entropy->restarts_to_go--;
  147267. }
  147268. return TRUE;
  147269. }
  147270. METHODDEF(void)
  147271. finish_pass_huff (j_compress_ptr cinfo)
  147272. {
  147273. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147274. working_state state;
  147275. state.next_output_byte = cinfo->dest->next_output_byte;
  147276. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147277. ASSIGN_STATE(state.cur, entropy->saved);
  147278. state.cinfo = cinfo;
  147279. if (! flush_bits(&state))
  147280. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147281. cinfo->dest->next_output_byte = state.next_output_byte;
  147282. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147283. ASSIGN_STATE(entropy->saved, state.cur);
  147284. }
  147285. #ifdef ENTROPY_OPT_SUPPORTED
  147286. LOCAL(void)
  147287. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147288. long dc_counts[], long ac_counts[])
  147289. {
  147290. register int temp;
  147291. register int nbits;
  147292. register int k, r;
  147293. temp = block[0] - last_dc_val;
  147294. if (temp < 0)
  147295. temp = -temp;
  147296. nbits = 0;
  147297. while (temp) {
  147298. nbits++;
  147299. temp >>= 1;
  147300. }
  147301. if (nbits > MAX_COEF_BITS+1)
  147302. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147303. dc_counts[nbits]++;
  147304. r = 0; /* r = run length of zeros */
  147305. for (k = 1; k < DCTSIZE2; k++) {
  147306. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147307. r++;
  147308. } else {
  147309. while (r > 15) {
  147310. ac_counts[0xF0]++;
  147311. r -= 16;
  147312. }
  147313. if (temp < 0)
  147314. temp = -temp;
  147315. nbits = 1; /* there must be at least one 1 bit */
  147316. while ((temp >>= 1))
  147317. nbits++;
  147318. if (nbits > MAX_COEF_BITS)
  147319. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147320. ac_counts[(r << 4) + nbits]++;
  147321. r = 0;
  147322. }
  147323. }
  147324. if (r > 0)
  147325. ac_counts[0]++;
  147326. }
  147327. METHODDEF(boolean)
  147328. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147329. {
  147330. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147331. int blkn, ci;
  147332. jpeg_component_info * compptr;
  147333. if (cinfo->restart_interval) {
  147334. if (entropy->restarts_to_go == 0) {
  147335. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147336. entropy->saved.last_dc_val[ci] = 0;
  147337. entropy->restarts_to_go = cinfo->restart_interval;
  147338. }
  147339. entropy->restarts_to_go--;
  147340. }
  147341. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147342. ci = cinfo->MCU_membership[blkn];
  147343. compptr = cinfo->cur_comp_info[ci];
  147344. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147345. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147346. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147347. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147348. }
  147349. return TRUE;
  147350. }
  147351. GLOBAL(void)
  147352. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147353. {
  147354. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147355. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147356. int codesize[257]; /* codesize[k] = code length of symbol k */
  147357. int others[257]; /* next symbol in current branch of tree */
  147358. int c1, c2;
  147359. int p, i, j;
  147360. long v;
  147361. MEMZERO(bits, SIZEOF(bits));
  147362. MEMZERO(codesize, SIZEOF(codesize));
  147363. for (i = 0; i < 257; i++)
  147364. others[i] = -1; /* init links to empty */
  147365. freq[256] = 1; /* make sure 256 has a nonzero count */
  147366. for (;;) {
  147367. c1 = -1;
  147368. v = 1000000000L;
  147369. for (i = 0; i <= 256; i++) {
  147370. if (freq[i] && freq[i] <= v) {
  147371. v = freq[i];
  147372. c1 = i;
  147373. }
  147374. }
  147375. c2 = -1;
  147376. v = 1000000000L;
  147377. for (i = 0; i <= 256; i++) {
  147378. if (freq[i] && freq[i] <= v && i != c1) {
  147379. v = freq[i];
  147380. c2 = i;
  147381. }
  147382. }
  147383. if (c2 < 0)
  147384. break;
  147385. freq[c1] += freq[c2];
  147386. freq[c2] = 0;
  147387. codesize[c1]++;
  147388. while (others[c1] >= 0) {
  147389. c1 = others[c1];
  147390. codesize[c1]++;
  147391. }
  147392. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147393. codesize[c2]++;
  147394. while (others[c2] >= 0) {
  147395. c2 = others[c2];
  147396. codesize[c2]++;
  147397. }
  147398. }
  147399. for (i = 0; i <= 256; i++) {
  147400. if (codesize[i]) {
  147401. if (codesize[i] > MAX_CLEN)
  147402. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147403. bits[codesize[i]]++;
  147404. }
  147405. }
  147406. for (i = MAX_CLEN; i > 16; i--) {
  147407. while (bits[i] > 0) {
  147408. j = i - 2; /* find length of new prefix to be used */
  147409. while (bits[j] == 0)
  147410. j--;
  147411. bits[i] -= 2; /* remove two symbols */
  147412. bits[i-1]++; /* one goes in this length */
  147413. bits[j+1] += 2; /* two new symbols in this length */
  147414. bits[j]--; /* symbol of this length is now a prefix */
  147415. }
  147416. }
  147417. while (bits[i] == 0) /* find largest codelength still in use */
  147418. i--;
  147419. bits[i]--;
  147420. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147421. p = 0;
  147422. for (i = 1; i <= MAX_CLEN; i++) {
  147423. for (j = 0; j <= 255; j++) {
  147424. if (codesize[j] == i) {
  147425. htbl->huffval[p] = (UINT8) j;
  147426. p++;
  147427. }
  147428. }
  147429. }
  147430. htbl->sent_table = FALSE;
  147431. }
  147432. METHODDEF(void)
  147433. finish_pass_gather (j_compress_ptr cinfo)
  147434. {
  147435. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147436. int ci, dctbl, actbl;
  147437. jpeg_component_info * compptr;
  147438. JHUFF_TBL **htblptr;
  147439. boolean did_dc[NUM_HUFF_TBLS];
  147440. boolean did_ac[NUM_HUFF_TBLS];
  147441. MEMZERO(did_dc, SIZEOF(did_dc));
  147442. MEMZERO(did_ac, SIZEOF(did_ac));
  147443. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147444. compptr = cinfo->cur_comp_info[ci];
  147445. dctbl = compptr->dc_tbl_no;
  147446. actbl = compptr->ac_tbl_no;
  147447. if (! did_dc[dctbl]) {
  147448. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147449. if (*htblptr == NULL)
  147450. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147451. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147452. did_dc[dctbl] = TRUE;
  147453. }
  147454. if (! did_ac[actbl]) {
  147455. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147456. if (*htblptr == NULL)
  147457. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147458. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147459. did_ac[actbl] = TRUE;
  147460. }
  147461. }
  147462. }
  147463. #endif /* ENTROPY_OPT_SUPPORTED */
  147464. GLOBAL(void)
  147465. jinit_huff_encoder (j_compress_ptr cinfo)
  147466. {
  147467. huff_entropy_ptr entropy;
  147468. int i;
  147469. entropy = (huff_entropy_ptr)
  147470. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147471. SIZEOF(huff_entropy_encoder));
  147472. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147473. entropy->pub.start_pass = start_pass_huff;
  147474. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147475. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147476. #ifdef ENTROPY_OPT_SUPPORTED
  147477. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147478. #endif
  147479. }
  147480. }
  147481. /*** End of inlined file: jchuff.c ***/
  147482. #undef emit_byte
  147483. /*** Start of inlined file: jcinit.c ***/
  147484. #define JPEG_INTERNALS
  147485. GLOBAL(void)
  147486. jinit_compress_master (j_compress_ptr cinfo)
  147487. {
  147488. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147489. if (! cinfo->raw_data_in) {
  147490. jinit_color_converter(cinfo);
  147491. jinit_downsampler(cinfo);
  147492. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147493. }
  147494. jinit_forward_dct(cinfo);
  147495. if (cinfo->arith_code) {
  147496. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147497. } else {
  147498. if (cinfo->progressive_mode) {
  147499. #ifdef C_PROGRESSIVE_SUPPORTED
  147500. jinit_phuff_encoder(cinfo);
  147501. #else
  147502. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147503. #endif
  147504. } else
  147505. jinit_huff_encoder(cinfo);
  147506. }
  147507. jinit_c_coef_controller(cinfo,
  147508. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147509. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147510. jinit_marker_writer(cinfo);
  147511. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147512. (*cinfo->marker->write_file_header) (cinfo);
  147513. }
  147514. /*** End of inlined file: jcinit.c ***/
  147515. /*** Start of inlined file: jcmainct.c ***/
  147516. #define JPEG_INTERNALS
  147517. #undef FULL_MAIN_BUFFER_SUPPORTED
  147518. typedef struct {
  147519. struct jpeg_c_main_controller pub; /* public fields */
  147520. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147521. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147522. boolean suspended; /* remember if we suspended output */
  147523. J_BUF_MODE pass_mode; /* current operating mode */
  147524. JSAMPARRAY buffer[MAX_COMPONENTS];
  147525. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147526. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147527. #endif
  147528. } my_main_controller;
  147529. typedef my_main_controller * my_main_ptr;
  147530. METHODDEF(void) process_data_simple_main
  147531. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147532. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147533. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147534. METHODDEF(void) process_data_buffer_main
  147535. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147536. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147537. #endif
  147538. METHODDEF(void)
  147539. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147540. {
  147541. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147542. if (cinfo->raw_data_in)
  147543. return;
  147544. main_->cur_iMCU_row = 0; /* initialize counters */
  147545. main_->rowgroup_ctr = 0;
  147546. main_->suspended = FALSE;
  147547. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147548. switch (pass_mode) {
  147549. case JBUF_PASS_THRU:
  147550. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147551. if (main_->whole_image[0] != NULL)
  147552. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147553. #endif
  147554. main_->pub.process_data = process_data_simple_main;
  147555. break;
  147556. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147557. case JBUF_SAVE_SOURCE:
  147558. case JBUF_CRANK_DEST:
  147559. case JBUF_SAVE_AND_PASS:
  147560. if (main_->whole_image[0] == NULL)
  147561. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147562. main_->pub.process_data = process_data_buffer_main;
  147563. break;
  147564. #endif
  147565. default:
  147566. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147567. break;
  147568. }
  147569. }
  147570. METHODDEF(void)
  147571. process_data_simple_main (j_compress_ptr cinfo,
  147572. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147573. JDIMENSION in_rows_avail)
  147574. {
  147575. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147576. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147577. if (main_->rowgroup_ctr < DCTSIZE)
  147578. (*cinfo->prep->pre_process_data) (cinfo,
  147579. input_buf, in_row_ctr, in_rows_avail,
  147580. main_->buffer, &main_->rowgroup_ctr,
  147581. (JDIMENSION) DCTSIZE);
  147582. if (main_->rowgroup_ctr != DCTSIZE)
  147583. return;
  147584. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147585. if (! main_->suspended) {
  147586. (*in_row_ctr)--;
  147587. main_->suspended = TRUE;
  147588. }
  147589. return;
  147590. }
  147591. if (main_->suspended) {
  147592. (*in_row_ctr)++;
  147593. main_->suspended = FALSE;
  147594. }
  147595. main_->rowgroup_ctr = 0;
  147596. main_->cur_iMCU_row++;
  147597. }
  147598. }
  147599. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147600. METHODDEF(void)
  147601. process_data_buffer_main (j_compress_ptr cinfo,
  147602. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147603. JDIMENSION in_rows_avail)
  147604. {
  147605. my_main_ptr main = (my_main_ptr) cinfo->main;
  147606. int ci;
  147607. jpeg_component_info *compptr;
  147608. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147609. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147610. if (main->rowgroup_ctr == 0) {
  147611. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147612. ci++, compptr++) {
  147613. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147614. ((j_common_ptr) cinfo, main->whole_image[ci],
  147615. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147616. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147617. }
  147618. if (! writing) {
  147619. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147620. main->rowgroup_ctr = DCTSIZE;
  147621. }
  147622. }
  147623. if (writing) {
  147624. (*cinfo->prep->pre_process_data) (cinfo,
  147625. input_buf, in_row_ctr, in_rows_avail,
  147626. main->buffer, &main->rowgroup_ctr,
  147627. (JDIMENSION) DCTSIZE);
  147628. if (main->rowgroup_ctr < DCTSIZE)
  147629. return;
  147630. }
  147631. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147632. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147633. if (! main->suspended) {
  147634. (*in_row_ctr)--;
  147635. main->suspended = TRUE;
  147636. }
  147637. return;
  147638. }
  147639. if (main->suspended) {
  147640. (*in_row_ctr)++;
  147641. main->suspended = FALSE;
  147642. }
  147643. }
  147644. main->rowgroup_ctr = 0;
  147645. main->cur_iMCU_row++;
  147646. }
  147647. }
  147648. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147649. GLOBAL(void)
  147650. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147651. {
  147652. my_main_ptr main_;
  147653. int ci;
  147654. jpeg_component_info *compptr;
  147655. main_ = (my_main_ptr)
  147656. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147657. SIZEOF(my_main_controller));
  147658. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147659. main_->pub.start_pass = start_pass_main;
  147660. if (cinfo->raw_data_in)
  147661. return;
  147662. if (need_full_buffer) {
  147663. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147664. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147665. ci++, compptr++) {
  147666. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147667. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147668. compptr->width_in_blocks * DCTSIZE,
  147669. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147670. (long) compptr->v_samp_factor) * DCTSIZE,
  147671. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147672. }
  147673. #else
  147674. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147675. #endif
  147676. } else {
  147677. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147678. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147679. #endif
  147680. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147681. ci++, compptr++) {
  147682. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147683. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147684. compptr->width_in_blocks * DCTSIZE,
  147685. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147686. }
  147687. }
  147688. }
  147689. /*** End of inlined file: jcmainct.c ***/
  147690. /*** Start of inlined file: jcmarker.c ***/
  147691. #define JPEG_INTERNALS
  147692. typedef struct {
  147693. struct jpeg_marker_writer pub; /* public fields */
  147694. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147695. } my_marker_writer;
  147696. typedef my_marker_writer * my_marker_ptr;
  147697. LOCAL(void)
  147698. emit_byte (j_compress_ptr cinfo, int val)
  147699. {
  147700. struct jpeg_destination_mgr * dest = cinfo->dest;
  147701. *(dest->next_output_byte)++ = (JOCTET) val;
  147702. if (--dest->free_in_buffer == 0) {
  147703. if (! (*dest->empty_output_buffer) (cinfo))
  147704. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147705. }
  147706. }
  147707. LOCAL(void)
  147708. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147709. {
  147710. emit_byte(cinfo, 0xFF);
  147711. emit_byte(cinfo, (int) mark);
  147712. }
  147713. LOCAL(void)
  147714. emit_2bytes (j_compress_ptr cinfo, int value)
  147715. {
  147716. emit_byte(cinfo, (value >> 8) & 0xFF);
  147717. emit_byte(cinfo, value & 0xFF);
  147718. }
  147719. LOCAL(int)
  147720. emit_dqt (j_compress_ptr cinfo, int index)
  147721. {
  147722. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147723. int prec;
  147724. int i;
  147725. if (qtbl == NULL)
  147726. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147727. prec = 0;
  147728. for (i = 0; i < DCTSIZE2; i++) {
  147729. if (qtbl->quantval[i] > 255)
  147730. prec = 1;
  147731. }
  147732. if (! qtbl->sent_table) {
  147733. emit_marker(cinfo, M_DQT);
  147734. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147735. emit_byte(cinfo, index + (prec<<4));
  147736. for (i = 0; i < DCTSIZE2; i++) {
  147737. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147738. if (prec)
  147739. emit_byte(cinfo, (int) (qval >> 8));
  147740. emit_byte(cinfo, (int) (qval & 0xFF));
  147741. }
  147742. qtbl->sent_table = TRUE;
  147743. }
  147744. return prec;
  147745. }
  147746. LOCAL(void)
  147747. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147748. {
  147749. JHUFF_TBL * htbl;
  147750. int length, i;
  147751. if (is_ac) {
  147752. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147753. index += 0x10; /* output index has AC bit set */
  147754. } else {
  147755. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147756. }
  147757. if (htbl == NULL)
  147758. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147759. if (! htbl->sent_table) {
  147760. emit_marker(cinfo, M_DHT);
  147761. length = 0;
  147762. for (i = 1; i <= 16; i++)
  147763. length += htbl->bits[i];
  147764. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147765. emit_byte(cinfo, index);
  147766. for (i = 1; i <= 16; i++)
  147767. emit_byte(cinfo, htbl->bits[i]);
  147768. for (i = 0; i < length; i++)
  147769. emit_byte(cinfo, htbl->huffval[i]);
  147770. htbl->sent_table = TRUE;
  147771. }
  147772. }
  147773. LOCAL(void)
  147774. emit_dac (j_compress_ptr cinfo)
  147775. {
  147776. #ifdef C_ARITH_CODING_SUPPORTED
  147777. char dc_in_use[NUM_ARITH_TBLS];
  147778. char ac_in_use[NUM_ARITH_TBLS];
  147779. int length, i;
  147780. jpeg_component_info *compptr;
  147781. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147782. dc_in_use[i] = ac_in_use[i] = 0;
  147783. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147784. compptr = cinfo->cur_comp_info[i];
  147785. dc_in_use[compptr->dc_tbl_no] = 1;
  147786. ac_in_use[compptr->ac_tbl_no] = 1;
  147787. }
  147788. length = 0;
  147789. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147790. length += dc_in_use[i] + ac_in_use[i];
  147791. emit_marker(cinfo, M_DAC);
  147792. emit_2bytes(cinfo, length*2 + 2);
  147793. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147794. if (dc_in_use[i]) {
  147795. emit_byte(cinfo, i);
  147796. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147797. }
  147798. if (ac_in_use[i]) {
  147799. emit_byte(cinfo, i + 0x10);
  147800. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147801. }
  147802. }
  147803. #endif /* C_ARITH_CODING_SUPPORTED */
  147804. }
  147805. LOCAL(void)
  147806. emit_dri (j_compress_ptr cinfo)
  147807. {
  147808. emit_marker(cinfo, M_DRI);
  147809. emit_2bytes(cinfo, 4); /* fixed length */
  147810. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147811. }
  147812. LOCAL(void)
  147813. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147814. {
  147815. int ci;
  147816. jpeg_component_info *compptr;
  147817. emit_marker(cinfo, code);
  147818. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147819. if ((long) cinfo->image_height > 65535L ||
  147820. (long) cinfo->image_width > 65535L)
  147821. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147822. emit_byte(cinfo, cinfo->data_precision);
  147823. emit_2bytes(cinfo, (int) cinfo->image_height);
  147824. emit_2bytes(cinfo, (int) cinfo->image_width);
  147825. emit_byte(cinfo, cinfo->num_components);
  147826. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147827. ci++, compptr++) {
  147828. emit_byte(cinfo, compptr->component_id);
  147829. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147830. emit_byte(cinfo, compptr->quant_tbl_no);
  147831. }
  147832. }
  147833. LOCAL(void)
  147834. emit_sos (j_compress_ptr cinfo)
  147835. {
  147836. int i, td, ta;
  147837. jpeg_component_info *compptr;
  147838. emit_marker(cinfo, M_SOS);
  147839. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147840. emit_byte(cinfo, cinfo->comps_in_scan);
  147841. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147842. compptr = cinfo->cur_comp_info[i];
  147843. emit_byte(cinfo, compptr->component_id);
  147844. td = compptr->dc_tbl_no;
  147845. ta = compptr->ac_tbl_no;
  147846. if (cinfo->progressive_mode) {
  147847. if (cinfo->Ss == 0) {
  147848. ta = 0; /* DC scan */
  147849. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147850. td = 0; /* no DC table either */
  147851. } else {
  147852. td = 0; /* AC scan */
  147853. }
  147854. }
  147855. emit_byte(cinfo, (td << 4) + ta);
  147856. }
  147857. emit_byte(cinfo, cinfo->Ss);
  147858. emit_byte(cinfo, cinfo->Se);
  147859. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147860. }
  147861. LOCAL(void)
  147862. emit_jfif_app0 (j_compress_ptr cinfo)
  147863. {
  147864. emit_marker(cinfo, M_APP0);
  147865. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147866. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147867. emit_byte(cinfo, 0x46);
  147868. emit_byte(cinfo, 0x49);
  147869. emit_byte(cinfo, 0x46);
  147870. emit_byte(cinfo, 0);
  147871. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147872. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147873. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147874. emit_2bytes(cinfo, (int) cinfo->X_density);
  147875. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147876. emit_byte(cinfo, 0); /* No thumbnail image */
  147877. emit_byte(cinfo, 0);
  147878. }
  147879. LOCAL(void)
  147880. emit_adobe_app14 (j_compress_ptr cinfo)
  147881. {
  147882. emit_marker(cinfo, M_APP14);
  147883. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147884. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147885. emit_byte(cinfo, 0x64);
  147886. emit_byte(cinfo, 0x6F);
  147887. emit_byte(cinfo, 0x62);
  147888. emit_byte(cinfo, 0x65);
  147889. emit_2bytes(cinfo, 100); /* Version */
  147890. emit_2bytes(cinfo, 0); /* Flags0 */
  147891. emit_2bytes(cinfo, 0); /* Flags1 */
  147892. switch (cinfo->jpeg_color_space) {
  147893. case JCS_YCbCr:
  147894. emit_byte(cinfo, 1); /* Color transform = 1 */
  147895. break;
  147896. case JCS_YCCK:
  147897. emit_byte(cinfo, 2); /* Color transform = 2 */
  147898. break;
  147899. default:
  147900. emit_byte(cinfo, 0); /* Color transform = 0 */
  147901. break;
  147902. }
  147903. }
  147904. METHODDEF(void)
  147905. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147906. {
  147907. if (datalen > (unsigned int) 65533) /* safety check */
  147908. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147909. emit_marker(cinfo, (JPEG_MARKER) marker);
  147910. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  147911. }
  147912. METHODDEF(void)
  147913. write_marker_byte (j_compress_ptr cinfo, int val)
  147914. {
  147915. emit_byte(cinfo, val);
  147916. }
  147917. METHODDEF(void)
  147918. write_file_header (j_compress_ptr cinfo)
  147919. {
  147920. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147921. emit_marker(cinfo, M_SOI); /* first the SOI */
  147922. marker->last_restart_interval = 0;
  147923. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  147924. emit_jfif_app0(cinfo);
  147925. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  147926. emit_adobe_app14(cinfo);
  147927. }
  147928. METHODDEF(void)
  147929. write_frame_header (j_compress_ptr cinfo)
  147930. {
  147931. int ci, prec;
  147932. boolean is_baseline;
  147933. jpeg_component_info *compptr;
  147934. prec = 0;
  147935. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147936. ci++, compptr++) {
  147937. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  147938. }
  147939. if (cinfo->arith_code || cinfo->progressive_mode ||
  147940. cinfo->data_precision != 8) {
  147941. is_baseline = FALSE;
  147942. } else {
  147943. is_baseline = TRUE;
  147944. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147945. ci++, compptr++) {
  147946. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  147947. is_baseline = FALSE;
  147948. }
  147949. if (prec && is_baseline) {
  147950. is_baseline = FALSE;
  147951. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  147952. }
  147953. }
  147954. if (cinfo->arith_code) {
  147955. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  147956. } else {
  147957. if (cinfo->progressive_mode)
  147958. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  147959. else if (is_baseline)
  147960. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  147961. else
  147962. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  147963. }
  147964. }
  147965. METHODDEF(void)
  147966. write_scan_header (j_compress_ptr cinfo)
  147967. {
  147968. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147969. int i;
  147970. jpeg_component_info *compptr;
  147971. if (cinfo->arith_code) {
  147972. emit_dac(cinfo);
  147973. } else {
  147974. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147975. compptr = cinfo->cur_comp_info[i];
  147976. if (cinfo->progressive_mode) {
  147977. if (cinfo->Ss == 0) {
  147978. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  147979. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147980. } else {
  147981. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147982. }
  147983. } else {
  147984. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147985. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147986. }
  147987. }
  147988. }
  147989. if (cinfo->restart_interval != marker->last_restart_interval) {
  147990. emit_dri(cinfo);
  147991. marker->last_restart_interval = cinfo->restart_interval;
  147992. }
  147993. emit_sos(cinfo);
  147994. }
  147995. METHODDEF(void)
  147996. write_file_trailer (j_compress_ptr cinfo)
  147997. {
  147998. emit_marker(cinfo, M_EOI);
  147999. }
  148000. METHODDEF(void)
  148001. write_tables_only (j_compress_ptr cinfo)
  148002. {
  148003. int i;
  148004. emit_marker(cinfo, M_SOI);
  148005. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148006. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148007. (void) emit_dqt(cinfo, i);
  148008. }
  148009. if (! cinfo->arith_code) {
  148010. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148011. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148012. emit_dht(cinfo, i, FALSE);
  148013. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148014. emit_dht(cinfo, i, TRUE);
  148015. }
  148016. }
  148017. emit_marker(cinfo, M_EOI);
  148018. }
  148019. GLOBAL(void)
  148020. jinit_marker_writer (j_compress_ptr cinfo)
  148021. {
  148022. my_marker_ptr marker;
  148023. marker = (my_marker_ptr)
  148024. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148025. SIZEOF(my_marker_writer));
  148026. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148027. marker->pub.write_file_header = write_file_header;
  148028. marker->pub.write_frame_header = write_frame_header;
  148029. marker->pub.write_scan_header = write_scan_header;
  148030. marker->pub.write_file_trailer = write_file_trailer;
  148031. marker->pub.write_tables_only = write_tables_only;
  148032. marker->pub.write_marker_header = write_marker_header;
  148033. marker->pub.write_marker_byte = write_marker_byte;
  148034. marker->last_restart_interval = 0;
  148035. }
  148036. /*** End of inlined file: jcmarker.c ***/
  148037. /*** Start of inlined file: jcmaster.c ***/
  148038. #define JPEG_INTERNALS
  148039. typedef enum {
  148040. main_pass, /* input data, also do first output step */
  148041. huff_opt_pass, /* Huffman code optimization pass */
  148042. output_pass /* data output pass */
  148043. } c_pass_type;
  148044. typedef struct {
  148045. struct jpeg_comp_master pub; /* public fields */
  148046. c_pass_type pass_type; /* the type of the current pass */
  148047. int pass_number; /* # of passes completed */
  148048. int total_passes; /* total # of passes needed */
  148049. int scan_number; /* current index in scan_info[] */
  148050. } my_comp_master;
  148051. typedef my_comp_master * my_master_ptr;
  148052. LOCAL(void)
  148053. initial_setup (j_compress_ptr cinfo)
  148054. {
  148055. int ci;
  148056. jpeg_component_info *compptr;
  148057. long samplesperrow;
  148058. JDIMENSION jd_samplesperrow;
  148059. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148060. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148061. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148062. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148063. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148064. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148065. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148066. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148067. if ((long) jd_samplesperrow != samplesperrow)
  148068. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148069. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148070. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148071. if (cinfo->num_components > MAX_COMPONENTS)
  148072. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148073. MAX_COMPONENTS);
  148074. cinfo->max_h_samp_factor = 1;
  148075. cinfo->max_v_samp_factor = 1;
  148076. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148077. ci++, compptr++) {
  148078. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148079. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148080. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148081. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148082. compptr->h_samp_factor);
  148083. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148084. compptr->v_samp_factor);
  148085. }
  148086. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148087. ci++, compptr++) {
  148088. compptr->component_index = ci;
  148089. compptr->DCT_scaled_size = DCTSIZE;
  148090. compptr->width_in_blocks = (JDIMENSION)
  148091. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148092. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148093. compptr->height_in_blocks = (JDIMENSION)
  148094. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148095. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148096. compptr->downsampled_width = (JDIMENSION)
  148097. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148098. (long) cinfo->max_h_samp_factor);
  148099. compptr->downsampled_height = (JDIMENSION)
  148100. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148101. (long) cinfo->max_v_samp_factor);
  148102. compptr->component_needed = TRUE;
  148103. }
  148104. cinfo->total_iMCU_rows = (JDIMENSION)
  148105. jdiv_round_up((long) cinfo->image_height,
  148106. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148107. }
  148108. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148109. LOCAL(void)
  148110. validate_script (j_compress_ptr cinfo)
  148111. {
  148112. const jpeg_scan_info * scanptr;
  148113. int scanno, ncomps, ci, coefi, thisi;
  148114. int Ss, Se, Ah, Al;
  148115. boolean component_sent[MAX_COMPONENTS];
  148116. #ifdef C_PROGRESSIVE_SUPPORTED
  148117. int * last_bitpos_ptr;
  148118. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148119. #endif
  148120. if (cinfo->num_scans <= 0)
  148121. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148122. scanptr = cinfo->scan_info;
  148123. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148124. #ifdef C_PROGRESSIVE_SUPPORTED
  148125. cinfo->progressive_mode = TRUE;
  148126. last_bitpos_ptr = & last_bitpos[0][0];
  148127. for (ci = 0; ci < cinfo->num_components; ci++)
  148128. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148129. *last_bitpos_ptr++ = -1;
  148130. #else
  148131. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148132. #endif
  148133. } else {
  148134. cinfo->progressive_mode = FALSE;
  148135. for (ci = 0; ci < cinfo->num_components; ci++)
  148136. component_sent[ci] = FALSE;
  148137. }
  148138. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148139. ncomps = scanptr->comps_in_scan;
  148140. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148141. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148142. for (ci = 0; ci < ncomps; ci++) {
  148143. thisi = scanptr->component_index[ci];
  148144. if (thisi < 0 || thisi >= cinfo->num_components)
  148145. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148146. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148147. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148148. }
  148149. Ss = scanptr->Ss;
  148150. Se = scanptr->Se;
  148151. Ah = scanptr->Ah;
  148152. Al = scanptr->Al;
  148153. if (cinfo->progressive_mode) {
  148154. #ifdef C_PROGRESSIVE_SUPPORTED
  148155. #if BITS_IN_JSAMPLE == 8
  148156. #define MAX_AH_AL 10
  148157. #else
  148158. #define MAX_AH_AL 13
  148159. #endif
  148160. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148161. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148162. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148163. if (Ss == 0) {
  148164. if (Se != 0) /* DC and AC together not OK */
  148165. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148166. } else {
  148167. if (ncomps != 1) /* AC scans must be for only one component */
  148168. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148169. }
  148170. for (ci = 0; ci < ncomps; ci++) {
  148171. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148172. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148173. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148174. for (coefi = Ss; coefi <= Se; coefi++) {
  148175. if (last_bitpos_ptr[coefi] < 0) {
  148176. if (Ah != 0)
  148177. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148178. } else {
  148179. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148180. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148181. }
  148182. last_bitpos_ptr[coefi] = Al;
  148183. }
  148184. }
  148185. #endif
  148186. } else {
  148187. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148188. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148189. for (ci = 0; ci < ncomps; ci++) {
  148190. thisi = scanptr->component_index[ci];
  148191. if (component_sent[thisi])
  148192. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148193. component_sent[thisi] = TRUE;
  148194. }
  148195. }
  148196. }
  148197. if (cinfo->progressive_mode) {
  148198. #ifdef C_PROGRESSIVE_SUPPORTED
  148199. for (ci = 0; ci < cinfo->num_components; ci++) {
  148200. if (last_bitpos[ci][0] < 0)
  148201. ERREXIT(cinfo, JERR_MISSING_DATA);
  148202. }
  148203. #endif
  148204. } else {
  148205. for (ci = 0; ci < cinfo->num_components; ci++) {
  148206. if (! component_sent[ci])
  148207. ERREXIT(cinfo, JERR_MISSING_DATA);
  148208. }
  148209. }
  148210. }
  148211. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148212. LOCAL(void)
  148213. select_scan_parameters (j_compress_ptr cinfo)
  148214. {
  148215. int ci;
  148216. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148217. if (cinfo->scan_info != NULL) {
  148218. my_master_ptr master = (my_master_ptr) cinfo->master;
  148219. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148220. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148221. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148222. cinfo->cur_comp_info[ci] =
  148223. &cinfo->comp_info[scanptr->component_index[ci]];
  148224. }
  148225. cinfo->Ss = scanptr->Ss;
  148226. cinfo->Se = scanptr->Se;
  148227. cinfo->Ah = scanptr->Ah;
  148228. cinfo->Al = scanptr->Al;
  148229. }
  148230. else
  148231. #endif
  148232. {
  148233. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148234. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148235. MAX_COMPS_IN_SCAN);
  148236. cinfo->comps_in_scan = cinfo->num_components;
  148237. for (ci = 0; ci < cinfo->num_components; ci++) {
  148238. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148239. }
  148240. cinfo->Ss = 0;
  148241. cinfo->Se = DCTSIZE2-1;
  148242. cinfo->Ah = 0;
  148243. cinfo->Al = 0;
  148244. }
  148245. }
  148246. LOCAL(void)
  148247. per_scan_setup (j_compress_ptr cinfo)
  148248. {
  148249. int ci, mcublks, tmp;
  148250. jpeg_component_info *compptr;
  148251. if (cinfo->comps_in_scan == 1) {
  148252. compptr = cinfo->cur_comp_info[0];
  148253. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148254. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148255. compptr->MCU_width = 1;
  148256. compptr->MCU_height = 1;
  148257. compptr->MCU_blocks = 1;
  148258. compptr->MCU_sample_width = DCTSIZE;
  148259. compptr->last_col_width = 1;
  148260. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148261. if (tmp == 0) tmp = compptr->v_samp_factor;
  148262. compptr->last_row_height = tmp;
  148263. cinfo->blocks_in_MCU = 1;
  148264. cinfo->MCU_membership[0] = 0;
  148265. } else {
  148266. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148267. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148268. MAX_COMPS_IN_SCAN);
  148269. cinfo->MCUs_per_row = (JDIMENSION)
  148270. jdiv_round_up((long) cinfo->image_width,
  148271. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148272. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148273. jdiv_round_up((long) cinfo->image_height,
  148274. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148275. cinfo->blocks_in_MCU = 0;
  148276. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148277. compptr = cinfo->cur_comp_info[ci];
  148278. compptr->MCU_width = compptr->h_samp_factor;
  148279. compptr->MCU_height = compptr->v_samp_factor;
  148280. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148281. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148282. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148283. if (tmp == 0) tmp = compptr->MCU_width;
  148284. compptr->last_col_width = tmp;
  148285. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148286. if (tmp == 0) tmp = compptr->MCU_height;
  148287. compptr->last_row_height = tmp;
  148288. mcublks = compptr->MCU_blocks;
  148289. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148290. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148291. while (mcublks-- > 0) {
  148292. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148293. }
  148294. }
  148295. }
  148296. if (cinfo->restart_in_rows > 0) {
  148297. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148298. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148299. }
  148300. }
  148301. METHODDEF(void)
  148302. prepare_for_pass (j_compress_ptr cinfo)
  148303. {
  148304. my_master_ptr master = (my_master_ptr) cinfo->master;
  148305. switch (master->pass_type) {
  148306. case main_pass:
  148307. select_scan_parameters(cinfo);
  148308. per_scan_setup(cinfo);
  148309. if (! cinfo->raw_data_in) {
  148310. (*cinfo->cconvert->start_pass) (cinfo);
  148311. (*cinfo->downsample->start_pass) (cinfo);
  148312. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148313. }
  148314. (*cinfo->fdct->start_pass) (cinfo);
  148315. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148316. (*cinfo->coef->start_pass) (cinfo,
  148317. (master->total_passes > 1 ?
  148318. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148319. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148320. if (cinfo->optimize_coding) {
  148321. master->pub.call_pass_startup = FALSE;
  148322. } else {
  148323. master->pub.call_pass_startup = TRUE;
  148324. }
  148325. break;
  148326. #ifdef ENTROPY_OPT_SUPPORTED
  148327. case huff_opt_pass:
  148328. select_scan_parameters(cinfo);
  148329. per_scan_setup(cinfo);
  148330. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148331. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148332. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148333. master->pub.call_pass_startup = FALSE;
  148334. break;
  148335. }
  148336. master->pass_type = output_pass;
  148337. master->pass_number++;
  148338. #endif
  148339. case output_pass:
  148340. if (! cinfo->optimize_coding) {
  148341. select_scan_parameters(cinfo);
  148342. per_scan_setup(cinfo);
  148343. }
  148344. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148345. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148346. if (master->scan_number == 0)
  148347. (*cinfo->marker->write_frame_header) (cinfo);
  148348. (*cinfo->marker->write_scan_header) (cinfo);
  148349. master->pub.call_pass_startup = FALSE;
  148350. break;
  148351. default:
  148352. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148353. }
  148354. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148355. if (cinfo->progress != NULL) {
  148356. cinfo->progress->completed_passes = master->pass_number;
  148357. cinfo->progress->total_passes = master->total_passes;
  148358. }
  148359. }
  148360. METHODDEF(void)
  148361. pass_startup (j_compress_ptr cinfo)
  148362. {
  148363. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148364. (*cinfo->marker->write_frame_header) (cinfo);
  148365. (*cinfo->marker->write_scan_header) (cinfo);
  148366. }
  148367. METHODDEF(void)
  148368. finish_pass_master (j_compress_ptr cinfo)
  148369. {
  148370. my_master_ptr master = (my_master_ptr) cinfo->master;
  148371. (*cinfo->entropy->finish_pass) (cinfo);
  148372. switch (master->pass_type) {
  148373. case main_pass:
  148374. master->pass_type = output_pass;
  148375. if (! cinfo->optimize_coding)
  148376. master->scan_number++;
  148377. break;
  148378. case huff_opt_pass:
  148379. master->pass_type = output_pass;
  148380. break;
  148381. case output_pass:
  148382. if (cinfo->optimize_coding)
  148383. master->pass_type = huff_opt_pass;
  148384. master->scan_number++;
  148385. break;
  148386. }
  148387. master->pass_number++;
  148388. }
  148389. GLOBAL(void)
  148390. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148391. {
  148392. my_master_ptr master;
  148393. master = (my_master_ptr)
  148394. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148395. SIZEOF(my_comp_master));
  148396. cinfo->master = (struct jpeg_comp_master *) master;
  148397. master->pub.prepare_for_pass = prepare_for_pass;
  148398. master->pub.pass_startup = pass_startup;
  148399. master->pub.finish_pass = finish_pass_master;
  148400. master->pub.is_last_pass = FALSE;
  148401. initial_setup(cinfo);
  148402. if (cinfo->scan_info != NULL) {
  148403. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148404. validate_script(cinfo);
  148405. #else
  148406. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148407. #endif
  148408. } else {
  148409. cinfo->progressive_mode = FALSE;
  148410. cinfo->num_scans = 1;
  148411. }
  148412. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148413. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148414. if (transcode_only) {
  148415. if (cinfo->optimize_coding)
  148416. master->pass_type = huff_opt_pass;
  148417. else
  148418. master->pass_type = output_pass;
  148419. } else {
  148420. master->pass_type = main_pass;
  148421. }
  148422. master->scan_number = 0;
  148423. master->pass_number = 0;
  148424. if (cinfo->optimize_coding)
  148425. master->total_passes = cinfo->num_scans * 2;
  148426. else
  148427. master->total_passes = cinfo->num_scans;
  148428. }
  148429. /*** End of inlined file: jcmaster.c ***/
  148430. /*** Start of inlined file: jcomapi.c ***/
  148431. #define JPEG_INTERNALS
  148432. GLOBAL(void)
  148433. jpeg_abort (j_common_ptr cinfo)
  148434. {
  148435. int pool;
  148436. if (cinfo->mem == NULL)
  148437. return;
  148438. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148439. (*cinfo->mem->free_pool) (cinfo, pool);
  148440. }
  148441. if (cinfo->is_decompressor) {
  148442. cinfo->global_state = DSTATE_START;
  148443. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148444. } else {
  148445. cinfo->global_state = CSTATE_START;
  148446. }
  148447. }
  148448. GLOBAL(void)
  148449. jpeg_destroy (j_common_ptr cinfo)
  148450. {
  148451. if (cinfo->mem != NULL)
  148452. (*cinfo->mem->self_destruct) (cinfo);
  148453. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148454. cinfo->global_state = 0; /* mark it destroyed */
  148455. }
  148456. GLOBAL(JQUANT_TBL *)
  148457. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148458. {
  148459. JQUANT_TBL *tbl;
  148460. tbl = (JQUANT_TBL *)
  148461. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148462. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148463. return tbl;
  148464. }
  148465. GLOBAL(JHUFF_TBL *)
  148466. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148467. {
  148468. JHUFF_TBL *tbl;
  148469. tbl = (JHUFF_TBL *)
  148470. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148471. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148472. return tbl;
  148473. }
  148474. /*** End of inlined file: jcomapi.c ***/
  148475. /*** Start of inlined file: jcparam.c ***/
  148476. #define JPEG_INTERNALS
  148477. GLOBAL(void)
  148478. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148479. const unsigned int *basic_table,
  148480. int scale_factor, boolean force_baseline)
  148481. {
  148482. JQUANT_TBL ** qtblptr;
  148483. int i;
  148484. long temp;
  148485. if (cinfo->global_state != CSTATE_START)
  148486. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148487. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148488. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148489. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148490. if (*qtblptr == NULL)
  148491. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148492. for (i = 0; i < DCTSIZE2; i++) {
  148493. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148494. if (temp <= 0L) temp = 1L;
  148495. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148496. if (force_baseline && temp > 255L)
  148497. temp = 255L; /* limit to baseline range if requested */
  148498. (*qtblptr)->quantval[i] = (UINT16) temp;
  148499. }
  148500. (*qtblptr)->sent_table = FALSE;
  148501. }
  148502. GLOBAL(void)
  148503. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148504. boolean force_baseline)
  148505. {
  148506. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148507. 16, 11, 10, 16, 24, 40, 51, 61,
  148508. 12, 12, 14, 19, 26, 58, 60, 55,
  148509. 14, 13, 16, 24, 40, 57, 69, 56,
  148510. 14, 17, 22, 29, 51, 87, 80, 62,
  148511. 18, 22, 37, 56, 68, 109, 103, 77,
  148512. 24, 35, 55, 64, 81, 104, 113, 92,
  148513. 49, 64, 78, 87, 103, 121, 120, 101,
  148514. 72, 92, 95, 98, 112, 100, 103, 99
  148515. };
  148516. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148517. 17, 18, 24, 47, 99, 99, 99, 99,
  148518. 18, 21, 26, 66, 99, 99, 99, 99,
  148519. 24, 26, 56, 99, 99, 99, 99, 99,
  148520. 47, 66, 99, 99, 99, 99, 99, 99,
  148521. 99, 99, 99, 99, 99, 99, 99, 99,
  148522. 99, 99, 99, 99, 99, 99, 99, 99,
  148523. 99, 99, 99, 99, 99, 99, 99, 99,
  148524. 99, 99, 99, 99, 99, 99, 99, 99
  148525. };
  148526. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148527. scale_factor, force_baseline);
  148528. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148529. scale_factor, force_baseline);
  148530. }
  148531. GLOBAL(int)
  148532. jpeg_quality_scaling (int quality)
  148533. {
  148534. if (quality <= 0) quality = 1;
  148535. if (quality > 100) quality = 100;
  148536. if (quality < 50)
  148537. quality = 5000 / quality;
  148538. else
  148539. quality = 200 - quality*2;
  148540. return quality;
  148541. }
  148542. GLOBAL(void)
  148543. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148544. {
  148545. quality = jpeg_quality_scaling(quality);
  148546. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148547. }
  148548. LOCAL(void)
  148549. add_huff_table (j_compress_ptr cinfo,
  148550. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148551. {
  148552. int nsymbols, len;
  148553. if (*htblptr == NULL)
  148554. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148555. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148556. nsymbols = 0;
  148557. for (len = 1; len <= 16; len++)
  148558. nsymbols += bits[len];
  148559. if (nsymbols < 1 || nsymbols > 256)
  148560. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148561. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148562. (*htblptr)->sent_table = FALSE;
  148563. }
  148564. LOCAL(void)
  148565. std_huff_tables (j_compress_ptr cinfo)
  148566. {
  148567. static const UINT8 bits_dc_luminance[17] =
  148568. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148569. static const UINT8 val_dc_luminance[] =
  148570. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148571. static const UINT8 bits_dc_chrominance[17] =
  148572. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148573. static const UINT8 val_dc_chrominance[] =
  148574. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148575. static const UINT8 bits_ac_luminance[17] =
  148576. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148577. static const UINT8 val_ac_luminance[] =
  148578. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148579. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148580. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148581. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148582. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148583. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148584. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148585. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148586. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148587. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148588. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148589. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148590. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148591. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148592. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148593. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148594. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148595. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148596. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148597. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148598. 0xf9, 0xfa };
  148599. static const UINT8 bits_ac_chrominance[17] =
  148600. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148601. static const UINT8 val_ac_chrominance[] =
  148602. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148603. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148604. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148605. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148606. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148607. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148608. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148609. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148610. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148611. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148612. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148613. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148614. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148615. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148616. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148617. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148618. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148619. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148620. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148621. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148622. 0xf9, 0xfa };
  148623. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148624. bits_dc_luminance, val_dc_luminance);
  148625. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148626. bits_ac_luminance, val_ac_luminance);
  148627. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148628. bits_dc_chrominance, val_dc_chrominance);
  148629. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148630. bits_ac_chrominance, val_ac_chrominance);
  148631. }
  148632. GLOBAL(void)
  148633. jpeg_set_defaults (j_compress_ptr cinfo)
  148634. {
  148635. int i;
  148636. if (cinfo->global_state != CSTATE_START)
  148637. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148638. if (cinfo->comp_info == NULL)
  148639. cinfo->comp_info = (jpeg_component_info *)
  148640. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148641. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148642. cinfo->data_precision = BITS_IN_JSAMPLE;
  148643. jpeg_set_quality(cinfo, 75, TRUE);
  148644. std_huff_tables(cinfo);
  148645. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148646. cinfo->arith_dc_L[i] = 0;
  148647. cinfo->arith_dc_U[i] = 1;
  148648. cinfo->arith_ac_K[i] = 5;
  148649. }
  148650. cinfo->scan_info = NULL;
  148651. cinfo->num_scans = 0;
  148652. cinfo->raw_data_in = FALSE;
  148653. cinfo->arith_code = FALSE;
  148654. cinfo->optimize_coding = FALSE;
  148655. if (cinfo->data_precision > 8)
  148656. cinfo->optimize_coding = TRUE;
  148657. cinfo->CCIR601_sampling = FALSE;
  148658. cinfo->smoothing_factor = 0;
  148659. cinfo->dct_method = JDCT_DEFAULT;
  148660. cinfo->restart_interval = 0;
  148661. cinfo->restart_in_rows = 0;
  148662. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148663. cinfo->JFIF_minor_version = 1;
  148664. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148665. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148666. cinfo->Y_density = 1;
  148667. jpeg_default_colorspace(cinfo);
  148668. }
  148669. GLOBAL(void)
  148670. jpeg_default_colorspace (j_compress_ptr cinfo)
  148671. {
  148672. switch (cinfo->in_color_space) {
  148673. case JCS_GRAYSCALE:
  148674. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148675. break;
  148676. case JCS_RGB:
  148677. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148678. break;
  148679. case JCS_YCbCr:
  148680. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148681. break;
  148682. case JCS_CMYK:
  148683. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148684. break;
  148685. case JCS_YCCK:
  148686. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148687. break;
  148688. case JCS_UNKNOWN:
  148689. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148690. break;
  148691. default:
  148692. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148693. }
  148694. }
  148695. GLOBAL(void)
  148696. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148697. {
  148698. jpeg_component_info * compptr;
  148699. int ci;
  148700. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148701. (compptr = &cinfo->comp_info[index], \
  148702. compptr->component_id = (id), \
  148703. compptr->h_samp_factor = (hsamp), \
  148704. compptr->v_samp_factor = (vsamp), \
  148705. compptr->quant_tbl_no = (quant), \
  148706. compptr->dc_tbl_no = (dctbl), \
  148707. compptr->ac_tbl_no = (actbl) )
  148708. if (cinfo->global_state != CSTATE_START)
  148709. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148710. cinfo->jpeg_color_space = colorspace;
  148711. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148712. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148713. switch (colorspace) {
  148714. case JCS_GRAYSCALE:
  148715. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148716. cinfo->num_components = 1;
  148717. SET_COMP(0, 1, 1,1, 0, 0,0);
  148718. break;
  148719. case JCS_RGB:
  148720. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148721. cinfo->num_components = 3;
  148722. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148723. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148724. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148725. break;
  148726. case JCS_YCbCr:
  148727. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148728. cinfo->num_components = 3;
  148729. SET_COMP(0, 1, 2,2, 0, 0,0);
  148730. SET_COMP(1, 2, 1,1, 1, 1,1);
  148731. SET_COMP(2, 3, 1,1, 1, 1,1);
  148732. break;
  148733. case JCS_CMYK:
  148734. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148735. cinfo->num_components = 4;
  148736. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148737. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148738. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148739. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148740. break;
  148741. case JCS_YCCK:
  148742. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148743. cinfo->num_components = 4;
  148744. SET_COMP(0, 1, 2,2, 0, 0,0);
  148745. SET_COMP(1, 2, 1,1, 1, 1,1);
  148746. SET_COMP(2, 3, 1,1, 1, 1,1);
  148747. SET_COMP(3, 4, 2,2, 0, 0,0);
  148748. break;
  148749. case JCS_UNKNOWN:
  148750. cinfo->num_components = cinfo->input_components;
  148751. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148752. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148753. MAX_COMPONENTS);
  148754. for (ci = 0; ci < cinfo->num_components; ci++) {
  148755. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148756. }
  148757. break;
  148758. default:
  148759. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148760. }
  148761. }
  148762. #ifdef C_PROGRESSIVE_SUPPORTED
  148763. LOCAL(jpeg_scan_info *)
  148764. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148765. int Ss, int Se, int Ah, int Al)
  148766. {
  148767. scanptr->comps_in_scan = 1;
  148768. scanptr->component_index[0] = ci;
  148769. scanptr->Ss = Ss;
  148770. scanptr->Se = Se;
  148771. scanptr->Ah = Ah;
  148772. scanptr->Al = Al;
  148773. scanptr++;
  148774. return scanptr;
  148775. }
  148776. LOCAL(jpeg_scan_info *)
  148777. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148778. int Ss, int Se, int Ah, int Al)
  148779. {
  148780. int ci;
  148781. for (ci = 0; ci < ncomps; ci++) {
  148782. scanptr->comps_in_scan = 1;
  148783. scanptr->component_index[0] = ci;
  148784. scanptr->Ss = Ss;
  148785. scanptr->Se = Se;
  148786. scanptr->Ah = Ah;
  148787. scanptr->Al = Al;
  148788. scanptr++;
  148789. }
  148790. return scanptr;
  148791. }
  148792. LOCAL(jpeg_scan_info *)
  148793. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148794. {
  148795. int ci;
  148796. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148797. scanptr->comps_in_scan = ncomps;
  148798. for (ci = 0; ci < ncomps; ci++)
  148799. scanptr->component_index[ci] = ci;
  148800. scanptr->Ss = scanptr->Se = 0;
  148801. scanptr->Ah = Ah;
  148802. scanptr->Al = Al;
  148803. scanptr++;
  148804. } else {
  148805. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148806. }
  148807. return scanptr;
  148808. }
  148809. GLOBAL(void)
  148810. jpeg_simple_progression (j_compress_ptr cinfo)
  148811. {
  148812. int ncomps = cinfo->num_components;
  148813. int nscans;
  148814. jpeg_scan_info * scanptr;
  148815. if (cinfo->global_state != CSTATE_START)
  148816. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148817. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148818. nscans = 10;
  148819. } else {
  148820. if (ncomps > MAX_COMPS_IN_SCAN)
  148821. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148822. else
  148823. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148824. }
  148825. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148826. cinfo->script_space_size = MAX(nscans, 10);
  148827. cinfo->script_space = (jpeg_scan_info *)
  148828. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148829. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148830. }
  148831. scanptr = cinfo->script_space;
  148832. cinfo->scan_info = scanptr;
  148833. cinfo->num_scans = nscans;
  148834. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148835. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148836. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148837. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148838. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148839. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148840. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148841. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148842. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148843. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148844. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148845. } else {
  148846. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148847. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148848. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148849. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148850. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148851. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148852. }
  148853. }
  148854. #endif /* C_PROGRESSIVE_SUPPORTED */
  148855. /*** End of inlined file: jcparam.c ***/
  148856. /*** Start of inlined file: jcphuff.c ***/
  148857. #define JPEG_INTERNALS
  148858. #ifdef C_PROGRESSIVE_SUPPORTED
  148859. typedef struct {
  148860. struct jpeg_entropy_encoder pub; /* public fields */
  148861. boolean gather_statistics;
  148862. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148863. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148864. INT32 put_buffer; /* current bit-accumulation buffer */
  148865. int put_bits; /* # of bits now in it */
  148866. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148867. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148868. int ac_tbl_no; /* the table number of the single component */
  148869. unsigned int EOBRUN; /* run length of EOBs */
  148870. unsigned int BE; /* # of buffered correction bits before MCU */
  148871. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148872. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148873. int next_restart_num; /* next restart number to write (0-7) */
  148874. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148875. long * count_ptrs[NUM_HUFF_TBLS];
  148876. } phuff_entropy_encoder;
  148877. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148878. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148879. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148880. #define ISHIFT_TEMPS int ishift_temp;
  148881. #define IRIGHT_SHIFT(x,shft) \
  148882. ((ishift_temp = (x)) < 0 ? \
  148883. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148884. (ishift_temp >> (shft)))
  148885. #else
  148886. #define ISHIFT_TEMPS
  148887. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148888. #endif
  148889. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148890. JBLOCKROW *MCU_data));
  148891. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148892. JBLOCKROW *MCU_data));
  148893. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148894. JBLOCKROW *MCU_data));
  148895. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148896. JBLOCKROW *MCU_data));
  148897. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148898. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148899. METHODDEF(void)
  148900. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148901. {
  148902. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148903. boolean is_DC_band;
  148904. int ci, tbl;
  148905. jpeg_component_info * compptr;
  148906. entropy->cinfo = cinfo;
  148907. entropy->gather_statistics = gather_statistics;
  148908. is_DC_band = (cinfo->Ss == 0);
  148909. if (cinfo->Ah == 0) {
  148910. if (is_DC_band)
  148911. entropy->pub.encode_mcu = encode_mcu_DC_first;
  148912. else
  148913. entropy->pub.encode_mcu = encode_mcu_AC_first;
  148914. } else {
  148915. if (is_DC_band)
  148916. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  148917. else {
  148918. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  148919. if (entropy->bit_buffer == NULL)
  148920. entropy->bit_buffer = (char *)
  148921. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148922. MAX_CORR_BITS * SIZEOF(char));
  148923. }
  148924. }
  148925. if (gather_statistics)
  148926. entropy->pub.finish_pass = finish_pass_gather_phuff;
  148927. else
  148928. entropy->pub.finish_pass = finish_pass_phuff;
  148929. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148930. compptr = cinfo->cur_comp_info[ci];
  148931. entropy->last_dc_val[ci] = 0;
  148932. if (is_DC_band) {
  148933. if (cinfo->Ah != 0) /* DC refinement needs no table */
  148934. continue;
  148935. tbl = compptr->dc_tbl_no;
  148936. } else {
  148937. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  148938. }
  148939. if (gather_statistics) {
  148940. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  148941. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  148942. if (entropy->count_ptrs[tbl] == NULL)
  148943. entropy->count_ptrs[tbl] = (long *)
  148944. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148945. 257 * SIZEOF(long));
  148946. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  148947. } else {
  148948. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  148949. & entropy->derived_tbls[tbl]);
  148950. }
  148951. }
  148952. entropy->EOBRUN = 0;
  148953. entropy->BE = 0;
  148954. entropy->put_buffer = 0;
  148955. entropy->put_bits = 0;
  148956. entropy->restarts_to_go = cinfo->restart_interval;
  148957. entropy->next_restart_num = 0;
  148958. }
  148959. #define emit_byte(entropy,val) \
  148960. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  148961. if (--(entropy)->free_in_buffer == 0) \
  148962. dump_buffer_p(entropy); }
  148963. LOCAL(void)
  148964. dump_buffer_p (phuff_entropy_ptr entropy)
  148965. {
  148966. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  148967. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  148968. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  148969. entropy->next_output_byte = dest->next_output_byte;
  148970. entropy->free_in_buffer = dest->free_in_buffer;
  148971. }
  148972. INLINE
  148973. LOCAL(void)
  148974. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  148975. {
  148976. register INT32 put_buffer = (INT32) code;
  148977. register int put_bits = entropy->put_bits;
  148978. if (size == 0)
  148979. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148980. if (entropy->gather_statistics)
  148981. return; /* do nothing if we're only getting stats */
  148982. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  148983. put_bits += size; /* new number of bits in buffer */
  148984. put_buffer <<= 24 - put_bits; /* align incoming bits */
  148985. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  148986. while (put_bits >= 8) {
  148987. int c = (int) ((put_buffer >> 16) & 0xFF);
  148988. emit_byte(entropy, c);
  148989. if (c == 0xFF) { /* need to stuff a zero byte? */
  148990. emit_byte(entropy, 0);
  148991. }
  148992. put_buffer <<= 8;
  148993. put_bits -= 8;
  148994. }
  148995. entropy->put_buffer = put_buffer; /* update variables */
  148996. entropy->put_bits = put_bits;
  148997. }
  148998. LOCAL(void)
  148999. flush_bits_p (phuff_entropy_ptr entropy)
  149000. {
  149001. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149002. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149003. entropy->put_bits = 0;
  149004. }
  149005. INLINE
  149006. LOCAL(void)
  149007. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149008. {
  149009. if (entropy->gather_statistics)
  149010. entropy->count_ptrs[tbl_no][symbol]++;
  149011. else {
  149012. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149013. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149014. }
  149015. }
  149016. LOCAL(void)
  149017. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149018. unsigned int nbits)
  149019. {
  149020. if (entropy->gather_statistics)
  149021. return; /* no real work */
  149022. while (nbits > 0) {
  149023. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149024. bufstart++;
  149025. nbits--;
  149026. }
  149027. }
  149028. LOCAL(void)
  149029. emit_eobrun (phuff_entropy_ptr entropy)
  149030. {
  149031. register int temp, nbits;
  149032. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149033. temp = entropy->EOBRUN;
  149034. nbits = 0;
  149035. while ((temp >>= 1))
  149036. nbits++;
  149037. if (nbits > 14)
  149038. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149039. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149040. if (nbits)
  149041. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149042. entropy->EOBRUN = 0;
  149043. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149044. entropy->BE = 0;
  149045. }
  149046. }
  149047. LOCAL(void)
  149048. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149049. {
  149050. int ci;
  149051. emit_eobrun(entropy);
  149052. if (! entropy->gather_statistics) {
  149053. flush_bits_p(entropy);
  149054. emit_byte(entropy, 0xFF);
  149055. emit_byte(entropy, JPEG_RST0 + restart_num);
  149056. }
  149057. if (entropy->cinfo->Ss == 0) {
  149058. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149059. entropy->last_dc_val[ci] = 0;
  149060. } else {
  149061. entropy->EOBRUN = 0;
  149062. entropy->BE = 0;
  149063. }
  149064. }
  149065. METHODDEF(boolean)
  149066. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149067. {
  149068. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149069. register int temp, temp2;
  149070. register int nbits;
  149071. int blkn, ci;
  149072. int Al = cinfo->Al;
  149073. JBLOCKROW block;
  149074. jpeg_component_info * compptr;
  149075. ISHIFT_TEMPS
  149076. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149077. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149078. if (cinfo->restart_interval)
  149079. if (entropy->restarts_to_go == 0)
  149080. emit_restart_p(entropy, entropy->next_restart_num);
  149081. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149082. block = MCU_data[blkn];
  149083. ci = cinfo->MCU_membership[blkn];
  149084. compptr = cinfo->cur_comp_info[ci];
  149085. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149086. temp = temp2 - entropy->last_dc_val[ci];
  149087. entropy->last_dc_val[ci] = temp2;
  149088. temp2 = temp;
  149089. if (temp < 0) {
  149090. temp = -temp; /* temp is abs value of input */
  149091. temp2--;
  149092. }
  149093. nbits = 0;
  149094. while (temp) {
  149095. nbits++;
  149096. temp >>= 1;
  149097. }
  149098. if (nbits > MAX_COEF_BITS+1)
  149099. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149100. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149101. if (nbits) /* emit_bits rejects calls with size 0 */
  149102. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149103. }
  149104. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149105. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149106. if (cinfo->restart_interval) {
  149107. if (entropy->restarts_to_go == 0) {
  149108. entropy->restarts_to_go = cinfo->restart_interval;
  149109. entropy->next_restart_num++;
  149110. entropy->next_restart_num &= 7;
  149111. }
  149112. entropy->restarts_to_go--;
  149113. }
  149114. return TRUE;
  149115. }
  149116. METHODDEF(boolean)
  149117. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149118. {
  149119. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149120. register int temp, temp2;
  149121. register int nbits;
  149122. register int r, k;
  149123. int Se = cinfo->Se;
  149124. int Al = cinfo->Al;
  149125. JBLOCKROW block;
  149126. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149127. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149128. if (cinfo->restart_interval)
  149129. if (entropy->restarts_to_go == 0)
  149130. emit_restart_p(entropy, entropy->next_restart_num);
  149131. block = MCU_data[0];
  149132. r = 0; /* r = run length of zeros */
  149133. for (k = cinfo->Ss; k <= Se; k++) {
  149134. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149135. r++;
  149136. continue;
  149137. }
  149138. if (temp < 0) {
  149139. temp = -temp; /* temp is abs value of input */
  149140. temp >>= Al; /* apply the point transform */
  149141. temp2 = ~temp;
  149142. } else {
  149143. temp >>= Al; /* apply the point transform */
  149144. temp2 = temp;
  149145. }
  149146. if (temp == 0) {
  149147. r++;
  149148. continue;
  149149. }
  149150. if (entropy->EOBRUN > 0)
  149151. emit_eobrun(entropy);
  149152. while (r > 15) {
  149153. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149154. r -= 16;
  149155. }
  149156. nbits = 1; /* there must be at least one 1 bit */
  149157. while ((temp >>= 1))
  149158. nbits++;
  149159. if (nbits > MAX_COEF_BITS)
  149160. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149161. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149162. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149163. r = 0; /* reset zero run length */
  149164. }
  149165. if (r > 0) { /* If there are trailing zeroes, */
  149166. entropy->EOBRUN++; /* count an EOB */
  149167. if (entropy->EOBRUN == 0x7FFF)
  149168. emit_eobrun(entropy); /* force it out to avoid overflow */
  149169. }
  149170. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149171. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149172. if (cinfo->restart_interval) {
  149173. if (entropy->restarts_to_go == 0) {
  149174. entropy->restarts_to_go = cinfo->restart_interval;
  149175. entropy->next_restart_num++;
  149176. entropy->next_restart_num &= 7;
  149177. }
  149178. entropy->restarts_to_go--;
  149179. }
  149180. return TRUE;
  149181. }
  149182. METHODDEF(boolean)
  149183. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149184. {
  149185. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149186. register int temp;
  149187. int blkn;
  149188. int Al = cinfo->Al;
  149189. JBLOCKROW block;
  149190. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149191. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149192. if (cinfo->restart_interval)
  149193. if (entropy->restarts_to_go == 0)
  149194. emit_restart_p(entropy, entropy->next_restart_num);
  149195. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149196. block = MCU_data[blkn];
  149197. temp = (*block)[0];
  149198. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149199. }
  149200. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149201. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149202. if (cinfo->restart_interval) {
  149203. if (entropy->restarts_to_go == 0) {
  149204. entropy->restarts_to_go = cinfo->restart_interval;
  149205. entropy->next_restart_num++;
  149206. entropy->next_restart_num &= 7;
  149207. }
  149208. entropy->restarts_to_go--;
  149209. }
  149210. return TRUE;
  149211. }
  149212. METHODDEF(boolean)
  149213. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149214. {
  149215. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149216. register int temp;
  149217. register int r, k;
  149218. int EOB;
  149219. char *BR_buffer;
  149220. unsigned int BR;
  149221. int Se = cinfo->Se;
  149222. int Al = cinfo->Al;
  149223. JBLOCKROW block;
  149224. int absvalues[DCTSIZE2];
  149225. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149226. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149227. if (cinfo->restart_interval)
  149228. if (entropy->restarts_to_go == 0)
  149229. emit_restart_p(entropy, entropy->next_restart_num);
  149230. block = MCU_data[0];
  149231. EOB = 0;
  149232. for (k = cinfo->Ss; k <= Se; k++) {
  149233. temp = (*block)[jpeg_natural_order[k]];
  149234. if (temp < 0)
  149235. temp = -temp; /* temp is abs value of input */
  149236. temp >>= Al; /* apply the point transform */
  149237. absvalues[k] = temp; /* save abs value for main pass */
  149238. if (temp == 1)
  149239. EOB = k; /* EOB = index of last newly-nonzero coef */
  149240. }
  149241. r = 0; /* r = run length of zeros */
  149242. BR = 0; /* BR = count of buffered bits added now */
  149243. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149244. for (k = cinfo->Ss; k <= Se; k++) {
  149245. if ((temp = absvalues[k]) == 0) {
  149246. r++;
  149247. continue;
  149248. }
  149249. while (r > 15 && k <= EOB) {
  149250. emit_eobrun(entropy);
  149251. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149252. r -= 16;
  149253. emit_buffered_bits(entropy, BR_buffer, BR);
  149254. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149255. BR = 0;
  149256. }
  149257. if (temp > 1) {
  149258. BR_buffer[BR++] = (char) (temp & 1);
  149259. continue;
  149260. }
  149261. emit_eobrun(entropy);
  149262. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149263. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149264. emit_bits_p(entropy, (unsigned int) temp, 1);
  149265. emit_buffered_bits(entropy, BR_buffer, BR);
  149266. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149267. BR = 0;
  149268. r = 0; /* reset zero run length */
  149269. }
  149270. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149271. entropy->EOBRUN++; /* count an EOB */
  149272. entropy->BE += BR; /* concat my correction bits to older ones */
  149273. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149274. emit_eobrun(entropy);
  149275. }
  149276. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149277. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149278. if (cinfo->restart_interval) {
  149279. if (entropy->restarts_to_go == 0) {
  149280. entropy->restarts_to_go = cinfo->restart_interval;
  149281. entropy->next_restart_num++;
  149282. entropy->next_restart_num &= 7;
  149283. }
  149284. entropy->restarts_to_go--;
  149285. }
  149286. return TRUE;
  149287. }
  149288. METHODDEF(void)
  149289. finish_pass_phuff (j_compress_ptr cinfo)
  149290. {
  149291. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149292. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149293. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149294. emit_eobrun(entropy);
  149295. flush_bits_p(entropy);
  149296. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149297. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149298. }
  149299. METHODDEF(void)
  149300. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149301. {
  149302. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149303. boolean is_DC_band;
  149304. int ci, tbl;
  149305. jpeg_component_info * compptr;
  149306. JHUFF_TBL **htblptr;
  149307. boolean did[NUM_HUFF_TBLS];
  149308. emit_eobrun(entropy);
  149309. is_DC_band = (cinfo->Ss == 0);
  149310. MEMZERO(did, SIZEOF(did));
  149311. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149312. compptr = cinfo->cur_comp_info[ci];
  149313. if (is_DC_band) {
  149314. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149315. continue;
  149316. tbl = compptr->dc_tbl_no;
  149317. } else {
  149318. tbl = compptr->ac_tbl_no;
  149319. }
  149320. if (! did[tbl]) {
  149321. if (is_DC_band)
  149322. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149323. else
  149324. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149325. if (*htblptr == NULL)
  149326. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149327. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149328. did[tbl] = TRUE;
  149329. }
  149330. }
  149331. }
  149332. GLOBAL(void)
  149333. jinit_phuff_encoder (j_compress_ptr cinfo)
  149334. {
  149335. phuff_entropy_ptr entropy;
  149336. int i;
  149337. entropy = (phuff_entropy_ptr)
  149338. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149339. SIZEOF(phuff_entropy_encoder));
  149340. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149341. entropy->pub.start_pass = start_pass_phuff;
  149342. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149343. entropy->derived_tbls[i] = NULL;
  149344. entropy->count_ptrs[i] = NULL;
  149345. }
  149346. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149347. }
  149348. #endif /* C_PROGRESSIVE_SUPPORTED */
  149349. /*** End of inlined file: jcphuff.c ***/
  149350. /*** Start of inlined file: jcprepct.c ***/
  149351. #define JPEG_INTERNALS
  149352. #ifdef INPUT_SMOOTHING_SUPPORTED
  149353. #define CONTEXT_ROWS_SUPPORTED
  149354. #endif
  149355. typedef struct {
  149356. struct jpeg_c_prep_controller pub; /* public fields */
  149357. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149358. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149359. int next_buf_row; /* index of next row to store in color_buf */
  149360. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149361. int this_row_group; /* starting row index of group to process */
  149362. int next_buf_stop; /* downsample when we reach this index */
  149363. #endif
  149364. } my_prep_controller;
  149365. typedef my_prep_controller * my_prep_ptr;
  149366. METHODDEF(void)
  149367. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149368. {
  149369. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149370. if (pass_mode != JBUF_PASS_THRU)
  149371. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149372. prep->rows_to_go = cinfo->image_height;
  149373. prep->next_buf_row = 0;
  149374. #ifdef CONTEXT_ROWS_SUPPORTED
  149375. prep->this_row_group = 0;
  149376. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149377. #endif
  149378. }
  149379. LOCAL(void)
  149380. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149381. int input_rows, int output_rows)
  149382. {
  149383. register int row;
  149384. for (row = input_rows; row < output_rows; row++) {
  149385. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149386. 1, num_cols);
  149387. }
  149388. }
  149389. METHODDEF(void)
  149390. pre_process_data (j_compress_ptr cinfo,
  149391. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149392. JDIMENSION in_rows_avail,
  149393. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149394. JDIMENSION out_row_groups_avail)
  149395. {
  149396. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149397. int numrows, ci;
  149398. JDIMENSION inrows;
  149399. jpeg_component_info * compptr;
  149400. while (*in_row_ctr < in_rows_avail &&
  149401. *out_row_group_ctr < out_row_groups_avail) {
  149402. inrows = in_rows_avail - *in_row_ctr;
  149403. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149404. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149405. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149406. prep->color_buf,
  149407. (JDIMENSION) prep->next_buf_row,
  149408. numrows);
  149409. *in_row_ctr += numrows;
  149410. prep->next_buf_row += numrows;
  149411. prep->rows_to_go -= numrows;
  149412. if (prep->rows_to_go == 0 &&
  149413. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149414. for (ci = 0; ci < cinfo->num_components; ci++) {
  149415. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149416. prep->next_buf_row, cinfo->max_v_samp_factor);
  149417. }
  149418. prep->next_buf_row = cinfo->max_v_samp_factor;
  149419. }
  149420. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149421. (*cinfo->downsample->downsample) (cinfo,
  149422. prep->color_buf, (JDIMENSION) 0,
  149423. output_buf, *out_row_group_ctr);
  149424. prep->next_buf_row = 0;
  149425. (*out_row_group_ctr)++;
  149426. }
  149427. if (prep->rows_to_go == 0 &&
  149428. *out_row_group_ctr < out_row_groups_avail) {
  149429. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149430. ci++, compptr++) {
  149431. expand_bottom_edge(output_buf[ci],
  149432. compptr->width_in_blocks * DCTSIZE,
  149433. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149434. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149435. }
  149436. *out_row_group_ctr = out_row_groups_avail;
  149437. break; /* can exit outer loop without test */
  149438. }
  149439. }
  149440. }
  149441. #ifdef CONTEXT_ROWS_SUPPORTED
  149442. METHODDEF(void)
  149443. pre_process_context (j_compress_ptr cinfo,
  149444. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149445. JDIMENSION in_rows_avail,
  149446. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149447. JDIMENSION out_row_groups_avail)
  149448. {
  149449. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149450. int numrows, ci;
  149451. int buf_height = cinfo->max_v_samp_factor * 3;
  149452. JDIMENSION inrows;
  149453. while (*out_row_group_ctr < out_row_groups_avail) {
  149454. if (*in_row_ctr < in_rows_avail) {
  149455. inrows = in_rows_avail - *in_row_ctr;
  149456. numrows = prep->next_buf_stop - prep->next_buf_row;
  149457. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149458. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149459. prep->color_buf,
  149460. (JDIMENSION) prep->next_buf_row,
  149461. numrows);
  149462. if (prep->rows_to_go == cinfo->image_height) {
  149463. for (ci = 0; ci < cinfo->num_components; ci++) {
  149464. int row;
  149465. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149466. jcopy_sample_rows(prep->color_buf[ci], 0,
  149467. prep->color_buf[ci], -row,
  149468. 1, cinfo->image_width);
  149469. }
  149470. }
  149471. }
  149472. *in_row_ctr += numrows;
  149473. prep->next_buf_row += numrows;
  149474. prep->rows_to_go -= numrows;
  149475. } else {
  149476. if (prep->rows_to_go != 0)
  149477. break;
  149478. if (prep->next_buf_row < prep->next_buf_stop) {
  149479. for (ci = 0; ci < cinfo->num_components; ci++) {
  149480. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149481. prep->next_buf_row, prep->next_buf_stop);
  149482. }
  149483. prep->next_buf_row = prep->next_buf_stop;
  149484. }
  149485. }
  149486. if (prep->next_buf_row == prep->next_buf_stop) {
  149487. (*cinfo->downsample->downsample) (cinfo,
  149488. prep->color_buf,
  149489. (JDIMENSION) prep->this_row_group,
  149490. output_buf, *out_row_group_ctr);
  149491. (*out_row_group_ctr)++;
  149492. prep->this_row_group += cinfo->max_v_samp_factor;
  149493. if (prep->this_row_group >= buf_height)
  149494. prep->this_row_group = 0;
  149495. if (prep->next_buf_row >= buf_height)
  149496. prep->next_buf_row = 0;
  149497. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149498. }
  149499. }
  149500. }
  149501. LOCAL(void)
  149502. create_context_buffer (j_compress_ptr cinfo)
  149503. {
  149504. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149505. int rgroup_height = cinfo->max_v_samp_factor;
  149506. int ci, i;
  149507. jpeg_component_info * compptr;
  149508. JSAMPARRAY true_buffer, fake_buffer;
  149509. fake_buffer = (JSAMPARRAY)
  149510. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149511. (cinfo->num_components * 5 * rgroup_height) *
  149512. SIZEOF(JSAMPROW));
  149513. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149514. ci++, compptr++) {
  149515. true_buffer = (*cinfo->mem->alloc_sarray)
  149516. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149517. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149518. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149519. (JDIMENSION) (3 * rgroup_height));
  149520. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149521. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149522. for (i = 0; i < rgroup_height; i++) {
  149523. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149524. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149525. }
  149526. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149527. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149528. }
  149529. }
  149530. #endif /* CONTEXT_ROWS_SUPPORTED */
  149531. GLOBAL(void)
  149532. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149533. {
  149534. my_prep_ptr prep;
  149535. int ci;
  149536. jpeg_component_info * compptr;
  149537. if (need_full_buffer) /* safety check */
  149538. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149539. prep = (my_prep_ptr)
  149540. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149541. SIZEOF(my_prep_controller));
  149542. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149543. prep->pub.start_pass = start_pass_prep;
  149544. if (cinfo->downsample->need_context_rows) {
  149545. #ifdef CONTEXT_ROWS_SUPPORTED
  149546. prep->pub.pre_process_data = pre_process_context;
  149547. create_context_buffer(cinfo);
  149548. #else
  149549. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149550. #endif
  149551. } else {
  149552. prep->pub.pre_process_data = pre_process_data;
  149553. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149554. ci++, compptr++) {
  149555. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149556. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149557. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149558. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149559. (JDIMENSION) cinfo->max_v_samp_factor);
  149560. }
  149561. }
  149562. }
  149563. /*** End of inlined file: jcprepct.c ***/
  149564. /*** Start of inlined file: jcsample.c ***/
  149565. #define JPEG_INTERNALS
  149566. typedef JMETHOD(void, downsample1_ptr,
  149567. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149568. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149569. typedef struct {
  149570. struct jpeg_downsampler pub; /* public fields */
  149571. downsample1_ptr methods[MAX_COMPONENTS];
  149572. } my_downsampler;
  149573. typedef my_downsampler * my_downsample_ptr;
  149574. METHODDEF(void)
  149575. start_pass_downsample (j_compress_ptr cinfo)
  149576. {
  149577. }
  149578. LOCAL(void)
  149579. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149580. JDIMENSION input_cols, JDIMENSION output_cols)
  149581. {
  149582. register JSAMPROW ptr;
  149583. register JSAMPLE pixval;
  149584. register int count;
  149585. int row;
  149586. int numcols = (int) (output_cols - input_cols);
  149587. if (numcols > 0) {
  149588. for (row = 0; row < num_rows; row++) {
  149589. ptr = image_data[row] + input_cols;
  149590. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149591. for (count = numcols; count > 0; count--)
  149592. *ptr++ = pixval;
  149593. }
  149594. }
  149595. }
  149596. METHODDEF(void)
  149597. sep_downsample (j_compress_ptr cinfo,
  149598. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149599. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149600. {
  149601. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149602. int ci;
  149603. jpeg_component_info * compptr;
  149604. JSAMPARRAY in_ptr, out_ptr;
  149605. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149606. ci++, compptr++) {
  149607. in_ptr = input_buf[ci] + in_row_index;
  149608. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149609. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149610. }
  149611. }
  149612. METHODDEF(void)
  149613. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149614. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149615. {
  149616. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149617. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149618. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149619. JSAMPROW inptr, outptr;
  149620. INT32 outvalue;
  149621. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149622. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149623. numpix = h_expand * v_expand;
  149624. numpix2 = numpix/2;
  149625. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149626. cinfo->image_width, output_cols * h_expand);
  149627. inrow = 0;
  149628. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149629. outptr = output_data[outrow];
  149630. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149631. outcol++, outcol_h += h_expand) {
  149632. outvalue = 0;
  149633. for (v = 0; v < v_expand; v++) {
  149634. inptr = input_data[inrow+v] + outcol_h;
  149635. for (h = 0; h < h_expand; h++) {
  149636. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149637. }
  149638. }
  149639. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149640. }
  149641. inrow += v_expand;
  149642. }
  149643. }
  149644. METHODDEF(void)
  149645. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149646. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149647. {
  149648. jcopy_sample_rows(input_data, 0, output_data, 0,
  149649. cinfo->max_v_samp_factor, cinfo->image_width);
  149650. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149651. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149652. }
  149653. METHODDEF(void)
  149654. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149655. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149656. {
  149657. int outrow;
  149658. JDIMENSION outcol;
  149659. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149660. register JSAMPROW inptr, outptr;
  149661. register int bias;
  149662. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149663. cinfo->image_width, output_cols * 2);
  149664. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149665. outptr = output_data[outrow];
  149666. inptr = input_data[outrow];
  149667. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149668. for (outcol = 0; outcol < output_cols; outcol++) {
  149669. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149670. + bias) >> 1);
  149671. bias ^= 1; /* 0=>1, 1=>0 */
  149672. inptr += 2;
  149673. }
  149674. }
  149675. }
  149676. METHODDEF(void)
  149677. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149678. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149679. {
  149680. int inrow, outrow;
  149681. JDIMENSION outcol;
  149682. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149683. register JSAMPROW inptr0, inptr1, outptr;
  149684. register int bias;
  149685. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149686. cinfo->image_width, output_cols * 2);
  149687. inrow = 0;
  149688. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149689. outptr = output_data[outrow];
  149690. inptr0 = input_data[inrow];
  149691. inptr1 = input_data[inrow+1];
  149692. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149693. for (outcol = 0; outcol < output_cols; outcol++) {
  149694. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149695. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149696. + bias) >> 2);
  149697. bias ^= 3; /* 1=>2, 2=>1 */
  149698. inptr0 += 2; inptr1 += 2;
  149699. }
  149700. inrow += 2;
  149701. }
  149702. }
  149703. #ifdef INPUT_SMOOTHING_SUPPORTED
  149704. METHODDEF(void)
  149705. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149706. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149707. {
  149708. int inrow, outrow;
  149709. JDIMENSION colctr;
  149710. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149711. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149712. INT32 membersum, neighsum, memberscale, neighscale;
  149713. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149714. cinfo->image_width, output_cols * 2);
  149715. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149716. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149717. inrow = 0;
  149718. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149719. outptr = output_data[outrow];
  149720. inptr0 = input_data[inrow];
  149721. inptr1 = input_data[inrow+1];
  149722. above_ptr = input_data[inrow-1];
  149723. below_ptr = input_data[inrow+2];
  149724. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149725. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149726. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149727. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149728. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149729. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149730. neighsum += neighsum;
  149731. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149732. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149733. membersum = membersum * memberscale + neighsum * neighscale;
  149734. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149735. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149736. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149737. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149738. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149739. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149740. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149741. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149742. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149743. neighsum += neighsum;
  149744. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149745. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149746. membersum = membersum * memberscale + neighsum * neighscale;
  149747. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149748. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149749. }
  149750. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149751. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149752. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149753. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149754. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149755. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149756. neighsum += neighsum;
  149757. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149758. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149759. membersum = membersum * memberscale + neighsum * neighscale;
  149760. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149761. inrow += 2;
  149762. }
  149763. }
  149764. METHODDEF(void)
  149765. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149766. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149767. {
  149768. int outrow;
  149769. JDIMENSION colctr;
  149770. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149771. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149772. INT32 membersum, neighsum, memberscale, neighscale;
  149773. int colsum, lastcolsum, nextcolsum;
  149774. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149775. cinfo->image_width, output_cols);
  149776. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149777. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149778. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149779. outptr = output_data[outrow];
  149780. inptr = input_data[outrow];
  149781. above_ptr = input_data[outrow-1];
  149782. below_ptr = input_data[outrow+1];
  149783. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149784. GETJSAMPLE(*inptr);
  149785. membersum = GETJSAMPLE(*inptr++);
  149786. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149787. GETJSAMPLE(*inptr);
  149788. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149789. membersum = membersum * memberscale + neighsum * neighscale;
  149790. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149791. lastcolsum = colsum; colsum = nextcolsum;
  149792. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149793. membersum = GETJSAMPLE(*inptr++);
  149794. above_ptr++; below_ptr++;
  149795. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149796. GETJSAMPLE(*inptr);
  149797. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149798. membersum = membersum * memberscale + neighsum * neighscale;
  149799. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149800. lastcolsum = colsum; colsum = nextcolsum;
  149801. }
  149802. membersum = GETJSAMPLE(*inptr);
  149803. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149804. membersum = membersum * memberscale + neighsum * neighscale;
  149805. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149806. }
  149807. }
  149808. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149809. GLOBAL(void)
  149810. jinit_downsampler (j_compress_ptr cinfo)
  149811. {
  149812. my_downsample_ptr downsample;
  149813. int ci;
  149814. jpeg_component_info * compptr;
  149815. boolean smoothok = TRUE;
  149816. downsample = (my_downsample_ptr)
  149817. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149818. SIZEOF(my_downsampler));
  149819. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149820. downsample->pub.start_pass = start_pass_downsample;
  149821. downsample->pub.downsample = sep_downsample;
  149822. downsample->pub.need_context_rows = FALSE;
  149823. if (cinfo->CCIR601_sampling)
  149824. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149825. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149826. ci++, compptr++) {
  149827. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149828. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149829. #ifdef INPUT_SMOOTHING_SUPPORTED
  149830. if (cinfo->smoothing_factor) {
  149831. downsample->methods[ci] = fullsize_smooth_downsample;
  149832. downsample->pub.need_context_rows = TRUE;
  149833. } else
  149834. #endif
  149835. downsample->methods[ci] = fullsize_downsample;
  149836. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149837. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149838. smoothok = FALSE;
  149839. downsample->methods[ci] = h2v1_downsample;
  149840. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149841. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149842. #ifdef INPUT_SMOOTHING_SUPPORTED
  149843. if (cinfo->smoothing_factor) {
  149844. downsample->methods[ci] = h2v2_smooth_downsample;
  149845. downsample->pub.need_context_rows = TRUE;
  149846. } else
  149847. #endif
  149848. downsample->methods[ci] = h2v2_downsample;
  149849. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149850. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149851. smoothok = FALSE;
  149852. downsample->methods[ci] = int_downsample;
  149853. } else
  149854. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149855. }
  149856. #ifdef INPUT_SMOOTHING_SUPPORTED
  149857. if (cinfo->smoothing_factor && !smoothok)
  149858. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149859. #endif
  149860. }
  149861. /*** End of inlined file: jcsample.c ***/
  149862. /*** Start of inlined file: jctrans.c ***/
  149863. #define JPEG_INTERNALS
  149864. LOCAL(void) transencode_master_selection
  149865. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149866. LOCAL(void) transencode_coef_controller
  149867. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149868. GLOBAL(void)
  149869. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149870. {
  149871. if (cinfo->global_state != CSTATE_START)
  149872. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149873. jpeg_suppress_tables(cinfo, FALSE);
  149874. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149875. (*cinfo->dest->init_destination) (cinfo);
  149876. transencode_master_selection(cinfo, coef_arrays);
  149877. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149878. cinfo->global_state = CSTATE_WRCOEFS;
  149879. }
  149880. GLOBAL(void)
  149881. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149882. j_compress_ptr dstinfo)
  149883. {
  149884. JQUANT_TBL ** qtblptr;
  149885. jpeg_component_info *incomp, *outcomp;
  149886. JQUANT_TBL *c_quant, *slot_quant;
  149887. int tblno, ci, coefi;
  149888. if (dstinfo->global_state != CSTATE_START)
  149889. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149890. dstinfo->image_width = srcinfo->image_width;
  149891. dstinfo->image_height = srcinfo->image_height;
  149892. dstinfo->input_components = srcinfo->num_components;
  149893. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149894. jpeg_set_defaults(dstinfo);
  149895. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149896. dstinfo->data_precision = srcinfo->data_precision;
  149897. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149898. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149899. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149900. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149901. if (*qtblptr == NULL)
  149902. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149903. MEMCOPY((*qtblptr)->quantval,
  149904. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149905. SIZEOF((*qtblptr)->quantval));
  149906. (*qtblptr)->sent_table = FALSE;
  149907. }
  149908. }
  149909. dstinfo->num_components = srcinfo->num_components;
  149910. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  149911. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  149912. MAX_COMPONENTS);
  149913. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  149914. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  149915. outcomp->component_id = incomp->component_id;
  149916. outcomp->h_samp_factor = incomp->h_samp_factor;
  149917. outcomp->v_samp_factor = incomp->v_samp_factor;
  149918. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  149919. tblno = outcomp->quant_tbl_no;
  149920. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  149921. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  149922. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  149923. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  149924. c_quant = incomp->quant_table;
  149925. if (c_quant != NULL) {
  149926. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  149927. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  149928. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  149929. }
  149930. }
  149931. }
  149932. if (srcinfo->saw_JFIF_marker) {
  149933. if (srcinfo->JFIF_major_version == 1) {
  149934. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  149935. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  149936. }
  149937. dstinfo->density_unit = srcinfo->density_unit;
  149938. dstinfo->X_density = srcinfo->X_density;
  149939. dstinfo->Y_density = srcinfo->Y_density;
  149940. }
  149941. }
  149942. LOCAL(void)
  149943. transencode_master_selection (j_compress_ptr cinfo,
  149944. jvirt_barray_ptr * coef_arrays)
  149945. {
  149946. cinfo->input_components = 1;
  149947. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  149948. if (cinfo->arith_code) {
  149949. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  149950. } else {
  149951. if (cinfo->progressive_mode) {
  149952. #ifdef C_PROGRESSIVE_SUPPORTED
  149953. jinit_phuff_encoder(cinfo);
  149954. #else
  149955. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149956. #endif
  149957. } else
  149958. jinit_huff_encoder(cinfo);
  149959. }
  149960. transencode_coef_controller(cinfo, coef_arrays);
  149961. jinit_marker_writer(cinfo);
  149962. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  149963. (*cinfo->marker->write_file_header) (cinfo);
  149964. }
  149965. typedef struct {
  149966. struct jpeg_c_coef_controller pub; /* public fields */
  149967. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  149968. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  149969. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  149970. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  149971. jvirt_barray_ptr * whole_image;
  149972. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  149973. } my_coef_controller2;
  149974. typedef my_coef_controller2 * my_coef_ptr2;
  149975. LOCAL(void)
  149976. start_iMCU_row2 (j_compress_ptr cinfo)
  149977. {
  149978. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149979. if (cinfo->comps_in_scan > 1) {
  149980. coef->MCU_rows_per_iMCU_row = 1;
  149981. } else {
  149982. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  149983. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  149984. else
  149985. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  149986. }
  149987. coef->mcu_ctr = 0;
  149988. coef->MCU_vert_offset = 0;
  149989. }
  149990. METHODDEF(void)
  149991. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149992. {
  149993. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149994. if (pass_mode != JBUF_CRANK_DEST)
  149995. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149996. coef->iMCU_row_num = 0;
  149997. start_iMCU_row2(cinfo);
  149998. }
  149999. METHODDEF(boolean)
  150000. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150001. {
  150002. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150003. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150004. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150005. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150006. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150007. JDIMENSION start_col;
  150008. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150009. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150010. JBLOCKROW buffer_ptr;
  150011. jpeg_component_info *compptr;
  150012. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150013. compptr = cinfo->cur_comp_info[ci];
  150014. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150015. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150016. coef->iMCU_row_num * compptr->v_samp_factor,
  150017. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150018. }
  150019. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150020. yoffset++) {
  150021. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150022. MCU_col_num++) {
  150023. blkn = 0; /* index of current DCT block within MCU */
  150024. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150025. compptr = cinfo->cur_comp_info[ci];
  150026. start_col = MCU_col_num * compptr->MCU_width;
  150027. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150028. : compptr->last_col_width;
  150029. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150030. if (coef->iMCU_row_num < last_iMCU_row ||
  150031. yindex+yoffset < compptr->last_row_height) {
  150032. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150033. for (xindex = 0; xindex < blockcnt; xindex++)
  150034. MCU_buffer[blkn++] = buffer_ptr++;
  150035. } else {
  150036. xindex = 0;
  150037. }
  150038. for (; xindex < compptr->MCU_width; xindex++) {
  150039. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150040. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150041. blkn++;
  150042. }
  150043. }
  150044. }
  150045. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150046. coef->MCU_vert_offset = yoffset;
  150047. coef->mcu_ctr = MCU_col_num;
  150048. return FALSE;
  150049. }
  150050. }
  150051. coef->mcu_ctr = 0;
  150052. }
  150053. coef->iMCU_row_num++;
  150054. start_iMCU_row2(cinfo);
  150055. return TRUE;
  150056. }
  150057. LOCAL(void)
  150058. transencode_coef_controller (j_compress_ptr cinfo,
  150059. jvirt_barray_ptr * coef_arrays)
  150060. {
  150061. my_coef_ptr2 coef;
  150062. JBLOCKROW buffer;
  150063. int i;
  150064. coef = (my_coef_ptr2)
  150065. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150066. SIZEOF(my_coef_controller2));
  150067. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150068. coef->pub.start_pass = start_pass_coef2;
  150069. coef->pub.compress_data = compress_output2;
  150070. coef->whole_image = coef_arrays;
  150071. buffer = (JBLOCKROW)
  150072. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150073. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150074. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150075. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150076. coef->dummy_buffer[i] = buffer + i;
  150077. }
  150078. }
  150079. /*** End of inlined file: jctrans.c ***/
  150080. /*** Start of inlined file: jdapistd.c ***/
  150081. #define JPEG_INTERNALS
  150082. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150083. GLOBAL(boolean)
  150084. jpeg_start_decompress (j_decompress_ptr cinfo)
  150085. {
  150086. if (cinfo->global_state == DSTATE_READY) {
  150087. jinit_master_decompress(cinfo);
  150088. if (cinfo->buffered_image) {
  150089. cinfo->global_state = DSTATE_BUFIMAGE;
  150090. return TRUE;
  150091. }
  150092. cinfo->global_state = DSTATE_PRELOAD;
  150093. }
  150094. if (cinfo->global_state == DSTATE_PRELOAD) {
  150095. if (cinfo->inputctl->has_multiple_scans) {
  150096. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150097. for (;;) {
  150098. int retcode;
  150099. if (cinfo->progress != NULL)
  150100. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150101. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150102. if (retcode == JPEG_SUSPENDED)
  150103. return FALSE;
  150104. if (retcode == JPEG_REACHED_EOI)
  150105. break;
  150106. if (cinfo->progress != NULL &&
  150107. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150108. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150109. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150110. }
  150111. }
  150112. }
  150113. #else
  150114. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150115. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150116. }
  150117. cinfo->output_scan_number = cinfo->input_scan_number;
  150118. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150119. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150120. return output_pass_setup(cinfo);
  150121. }
  150122. LOCAL(boolean)
  150123. output_pass_setup (j_decompress_ptr cinfo)
  150124. {
  150125. if (cinfo->global_state != DSTATE_PRESCAN) {
  150126. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150127. cinfo->output_scanline = 0;
  150128. cinfo->global_state = DSTATE_PRESCAN;
  150129. }
  150130. while (cinfo->master->is_dummy_pass) {
  150131. #ifdef QUANT_2PASS_SUPPORTED
  150132. while (cinfo->output_scanline < cinfo->output_height) {
  150133. JDIMENSION last_scanline;
  150134. if (cinfo->progress != NULL) {
  150135. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150136. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150137. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150138. }
  150139. last_scanline = cinfo->output_scanline;
  150140. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150141. &cinfo->output_scanline, (JDIMENSION) 0);
  150142. if (cinfo->output_scanline == last_scanline)
  150143. return FALSE; /* No progress made, must suspend */
  150144. }
  150145. (*cinfo->master->finish_output_pass) (cinfo);
  150146. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150147. cinfo->output_scanline = 0;
  150148. #else
  150149. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150150. #endif /* QUANT_2PASS_SUPPORTED */
  150151. }
  150152. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150153. return TRUE;
  150154. }
  150155. GLOBAL(JDIMENSION)
  150156. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150157. JDIMENSION max_lines)
  150158. {
  150159. JDIMENSION row_ctr;
  150160. if (cinfo->global_state != DSTATE_SCANNING)
  150161. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150162. if (cinfo->output_scanline >= cinfo->output_height) {
  150163. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150164. return 0;
  150165. }
  150166. if (cinfo->progress != NULL) {
  150167. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150168. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150169. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150170. }
  150171. row_ctr = 0;
  150172. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150173. cinfo->output_scanline += row_ctr;
  150174. return row_ctr;
  150175. }
  150176. GLOBAL(JDIMENSION)
  150177. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150178. JDIMENSION max_lines)
  150179. {
  150180. JDIMENSION lines_per_iMCU_row;
  150181. if (cinfo->global_state != DSTATE_RAW_OK)
  150182. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150183. if (cinfo->output_scanline >= cinfo->output_height) {
  150184. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150185. return 0;
  150186. }
  150187. if (cinfo->progress != NULL) {
  150188. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150189. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150190. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150191. }
  150192. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150193. if (max_lines < lines_per_iMCU_row)
  150194. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150195. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150196. return 0; /* suspension forced, can do nothing more */
  150197. cinfo->output_scanline += lines_per_iMCU_row;
  150198. return lines_per_iMCU_row;
  150199. }
  150200. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150201. GLOBAL(boolean)
  150202. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150203. {
  150204. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150205. cinfo->global_state != DSTATE_PRESCAN)
  150206. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150207. if (scan_number <= 0)
  150208. scan_number = 1;
  150209. if (cinfo->inputctl->eoi_reached &&
  150210. scan_number > cinfo->input_scan_number)
  150211. scan_number = cinfo->input_scan_number;
  150212. cinfo->output_scan_number = scan_number;
  150213. return output_pass_setup(cinfo);
  150214. }
  150215. GLOBAL(boolean)
  150216. jpeg_finish_output (j_decompress_ptr cinfo)
  150217. {
  150218. if ((cinfo->global_state == DSTATE_SCANNING ||
  150219. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150220. (*cinfo->master->finish_output_pass) (cinfo);
  150221. cinfo->global_state = DSTATE_BUFPOST;
  150222. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150223. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150224. }
  150225. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150226. ! cinfo->inputctl->eoi_reached) {
  150227. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150228. return FALSE; /* Suspend, come back later */
  150229. }
  150230. cinfo->global_state = DSTATE_BUFIMAGE;
  150231. return TRUE;
  150232. }
  150233. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150234. /*** End of inlined file: jdapistd.c ***/
  150235. /*** Start of inlined file: jdapimin.c ***/
  150236. #define JPEG_INTERNALS
  150237. GLOBAL(void)
  150238. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150239. {
  150240. int i;
  150241. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150242. if (version != JPEG_LIB_VERSION)
  150243. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150244. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150245. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150246. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150247. {
  150248. struct jpeg_error_mgr * err = cinfo->err;
  150249. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150250. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150251. cinfo->err = err;
  150252. cinfo->client_data = client_data;
  150253. }
  150254. cinfo->is_decompressor = TRUE;
  150255. jinit_memory_mgr((j_common_ptr) cinfo);
  150256. cinfo->progress = NULL;
  150257. cinfo->src = NULL;
  150258. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150259. cinfo->quant_tbl_ptrs[i] = NULL;
  150260. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150261. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150262. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150263. }
  150264. cinfo->marker_list = NULL;
  150265. jinit_marker_reader(cinfo);
  150266. jinit_input_controller(cinfo);
  150267. cinfo->global_state = DSTATE_START;
  150268. }
  150269. GLOBAL(void)
  150270. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150271. {
  150272. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150273. }
  150274. GLOBAL(void)
  150275. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150276. {
  150277. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150278. }
  150279. LOCAL(void)
  150280. default_decompress_parms (j_decompress_ptr cinfo)
  150281. {
  150282. switch (cinfo->num_components) {
  150283. case 1:
  150284. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150285. cinfo->out_color_space = JCS_GRAYSCALE;
  150286. break;
  150287. case 3:
  150288. if (cinfo->saw_JFIF_marker) {
  150289. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150290. } else if (cinfo->saw_Adobe_marker) {
  150291. switch (cinfo->Adobe_transform) {
  150292. case 0:
  150293. cinfo->jpeg_color_space = JCS_RGB;
  150294. break;
  150295. case 1:
  150296. cinfo->jpeg_color_space = JCS_YCbCr;
  150297. break;
  150298. default:
  150299. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150300. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150301. break;
  150302. }
  150303. } else {
  150304. int cid0 = cinfo->comp_info[0].component_id;
  150305. int cid1 = cinfo->comp_info[1].component_id;
  150306. int cid2 = cinfo->comp_info[2].component_id;
  150307. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150308. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150309. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150310. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150311. else {
  150312. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150313. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150314. }
  150315. }
  150316. cinfo->out_color_space = JCS_RGB;
  150317. break;
  150318. case 4:
  150319. if (cinfo->saw_Adobe_marker) {
  150320. switch (cinfo->Adobe_transform) {
  150321. case 0:
  150322. cinfo->jpeg_color_space = JCS_CMYK;
  150323. break;
  150324. case 2:
  150325. cinfo->jpeg_color_space = JCS_YCCK;
  150326. break;
  150327. default:
  150328. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150329. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150330. break;
  150331. }
  150332. } else {
  150333. cinfo->jpeg_color_space = JCS_CMYK;
  150334. }
  150335. cinfo->out_color_space = JCS_CMYK;
  150336. break;
  150337. default:
  150338. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150339. cinfo->out_color_space = JCS_UNKNOWN;
  150340. break;
  150341. }
  150342. cinfo->scale_num = 1; /* 1:1 scaling */
  150343. cinfo->scale_denom = 1;
  150344. cinfo->output_gamma = 1.0;
  150345. cinfo->buffered_image = FALSE;
  150346. cinfo->raw_data_out = FALSE;
  150347. cinfo->dct_method = JDCT_DEFAULT;
  150348. cinfo->do_fancy_upsampling = TRUE;
  150349. cinfo->do_block_smoothing = TRUE;
  150350. cinfo->quantize_colors = FALSE;
  150351. cinfo->dither_mode = JDITHER_FS;
  150352. #ifdef QUANT_2PASS_SUPPORTED
  150353. cinfo->two_pass_quantize = TRUE;
  150354. #else
  150355. cinfo->two_pass_quantize = FALSE;
  150356. #endif
  150357. cinfo->desired_number_of_colors = 256;
  150358. cinfo->colormap = NULL;
  150359. cinfo->enable_1pass_quant = FALSE;
  150360. cinfo->enable_external_quant = FALSE;
  150361. cinfo->enable_2pass_quant = FALSE;
  150362. }
  150363. GLOBAL(int)
  150364. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150365. {
  150366. int retcode;
  150367. if (cinfo->global_state != DSTATE_START &&
  150368. cinfo->global_state != DSTATE_INHEADER)
  150369. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150370. retcode = jpeg_consume_input(cinfo);
  150371. switch (retcode) {
  150372. case JPEG_REACHED_SOS:
  150373. retcode = JPEG_HEADER_OK;
  150374. break;
  150375. case JPEG_REACHED_EOI:
  150376. if (require_image) /* Complain if application wanted an image */
  150377. ERREXIT(cinfo, JERR_NO_IMAGE);
  150378. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150379. retcode = JPEG_HEADER_TABLES_ONLY;
  150380. break;
  150381. case JPEG_SUSPENDED:
  150382. break;
  150383. }
  150384. return retcode;
  150385. }
  150386. GLOBAL(int)
  150387. jpeg_consume_input (j_decompress_ptr cinfo)
  150388. {
  150389. int retcode = JPEG_SUSPENDED;
  150390. switch (cinfo->global_state) {
  150391. case DSTATE_START:
  150392. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150393. (*cinfo->src->init_source) (cinfo);
  150394. cinfo->global_state = DSTATE_INHEADER;
  150395. case DSTATE_INHEADER:
  150396. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150397. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150398. default_decompress_parms(cinfo);
  150399. cinfo->global_state = DSTATE_READY;
  150400. }
  150401. break;
  150402. case DSTATE_READY:
  150403. retcode = JPEG_REACHED_SOS;
  150404. break;
  150405. case DSTATE_PRELOAD:
  150406. case DSTATE_PRESCAN:
  150407. case DSTATE_SCANNING:
  150408. case DSTATE_RAW_OK:
  150409. case DSTATE_BUFIMAGE:
  150410. case DSTATE_BUFPOST:
  150411. case DSTATE_STOPPING:
  150412. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150413. break;
  150414. default:
  150415. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150416. }
  150417. return retcode;
  150418. }
  150419. GLOBAL(boolean)
  150420. jpeg_input_complete (j_decompress_ptr cinfo)
  150421. {
  150422. if (cinfo->global_state < DSTATE_START ||
  150423. cinfo->global_state > DSTATE_STOPPING)
  150424. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150425. return cinfo->inputctl->eoi_reached;
  150426. }
  150427. GLOBAL(boolean)
  150428. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150429. {
  150430. if (cinfo->global_state < DSTATE_READY ||
  150431. cinfo->global_state > DSTATE_STOPPING)
  150432. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150433. return cinfo->inputctl->has_multiple_scans;
  150434. }
  150435. GLOBAL(boolean)
  150436. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150437. {
  150438. if ((cinfo->global_state == DSTATE_SCANNING ||
  150439. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150440. if (cinfo->output_scanline < cinfo->output_height)
  150441. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150442. (*cinfo->master->finish_output_pass) (cinfo);
  150443. cinfo->global_state = DSTATE_STOPPING;
  150444. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150445. cinfo->global_state = DSTATE_STOPPING;
  150446. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150447. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150448. }
  150449. while (! cinfo->inputctl->eoi_reached) {
  150450. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150451. return FALSE; /* Suspend, come back later */
  150452. }
  150453. (*cinfo->src->term_source) (cinfo);
  150454. jpeg_abort((j_common_ptr) cinfo);
  150455. return TRUE;
  150456. }
  150457. /*** End of inlined file: jdapimin.c ***/
  150458. /*** Start of inlined file: jdatasrc.c ***/
  150459. /*** Start of inlined file: jerror.h ***/
  150460. #ifndef JMESSAGE
  150461. #ifndef JERROR_H
  150462. #define JMAKE_ENUM_LIST
  150463. #else
  150464. #define JMESSAGE(code,string)
  150465. #endif /* JERROR_H */
  150466. #endif /* JMESSAGE */
  150467. #ifdef JMAKE_ENUM_LIST
  150468. typedef enum {
  150469. #define JMESSAGE(code,string) code ,
  150470. #endif /* JMAKE_ENUM_LIST */
  150471. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150472. JMESSAGE(JERR_ARITH_NOTIMPL,
  150473. "Sorry, there are legal restrictions on arithmetic coding")
  150474. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150475. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150476. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150477. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150478. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150479. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150480. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150481. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150482. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150483. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150484. JMESSAGE(JERR_BAD_LIB_VERSION,
  150485. "Wrong JPEG library version: library is %d, caller expects %d")
  150486. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150487. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150488. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150489. JMESSAGE(JERR_BAD_PROGRESSION,
  150490. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150491. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150492. "Invalid progressive parameters at scan script entry %d")
  150493. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150494. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150495. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150496. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150497. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150498. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150499. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150500. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150501. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150502. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150503. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150504. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150505. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150506. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150507. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150508. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150509. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150510. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150511. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150512. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150513. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150514. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150515. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150516. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150517. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150518. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150519. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150520. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150521. "Cannot transcode due to multiple use of quantization table %d")
  150522. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150523. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150524. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150525. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150526. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150527. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150528. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150529. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150530. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150531. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150532. JMESSAGE(JERR_QUANT_COMPONENTS,
  150533. "Cannot quantize more than %d color components")
  150534. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150535. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150536. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150537. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150538. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150539. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150540. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150541. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150542. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150543. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150544. JMESSAGE(JERR_TFILE_WRITE,
  150545. "Write failed on temporary file --- out of disk space?")
  150546. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150547. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150548. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150549. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150550. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150551. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150552. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150553. JMESSAGE(JMSG_VERSION, JVERSION)
  150554. JMESSAGE(JTRC_16BIT_TABLES,
  150555. "Caution: quantization tables are too coarse for baseline JPEG")
  150556. JMESSAGE(JTRC_ADOBE,
  150557. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150558. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150559. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150560. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150561. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150562. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150563. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150564. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150565. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150566. JMESSAGE(JTRC_EOI, "End Of Image")
  150567. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150568. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150569. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150570. "Warning: thumbnail image size does not match data length %u")
  150571. JMESSAGE(JTRC_JFIF_EXTENSION,
  150572. "JFIF extension marker: type 0x%02x, length %u")
  150573. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150574. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150575. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150576. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150577. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150578. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150579. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150580. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150581. JMESSAGE(JTRC_RST, "RST%d")
  150582. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150583. "Smoothing not supported with nonstandard sampling ratios")
  150584. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150585. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150586. JMESSAGE(JTRC_SOI, "Start of Image")
  150587. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150588. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150589. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150590. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150591. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150592. JMESSAGE(JTRC_THUMB_JPEG,
  150593. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150594. JMESSAGE(JTRC_THUMB_PALETTE,
  150595. "JFIF extension marker: palette thumbnail image, length %u")
  150596. JMESSAGE(JTRC_THUMB_RGB,
  150597. "JFIF extension marker: RGB thumbnail image, length %u")
  150598. JMESSAGE(JTRC_UNKNOWN_IDS,
  150599. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150600. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150601. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150602. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150603. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150604. "Inconsistent progression sequence for component %d coefficient %d")
  150605. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150606. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150607. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150608. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150609. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150610. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150611. JMESSAGE(JWRN_MUST_RESYNC,
  150612. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150613. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150614. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150615. #ifdef JMAKE_ENUM_LIST
  150616. JMSG_LASTMSGCODE
  150617. } J_MESSAGE_CODE;
  150618. #undef JMAKE_ENUM_LIST
  150619. #endif /* JMAKE_ENUM_LIST */
  150620. #undef JMESSAGE
  150621. #ifndef JERROR_H
  150622. #define JERROR_H
  150623. #define ERREXIT(cinfo,code) \
  150624. ((cinfo)->err->msg_code = (code), \
  150625. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150626. #define ERREXIT1(cinfo,code,p1) \
  150627. ((cinfo)->err->msg_code = (code), \
  150628. (cinfo)->err->msg_parm.i[0] = (p1), \
  150629. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150630. #define ERREXIT2(cinfo,code,p1,p2) \
  150631. ((cinfo)->err->msg_code = (code), \
  150632. (cinfo)->err->msg_parm.i[0] = (p1), \
  150633. (cinfo)->err->msg_parm.i[1] = (p2), \
  150634. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150635. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150636. ((cinfo)->err->msg_code = (code), \
  150637. (cinfo)->err->msg_parm.i[0] = (p1), \
  150638. (cinfo)->err->msg_parm.i[1] = (p2), \
  150639. (cinfo)->err->msg_parm.i[2] = (p3), \
  150640. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150641. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  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->msg_parm.i[2] = (p3), \
  150646. (cinfo)->err->msg_parm.i[3] = (p4), \
  150647. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150648. #define ERREXITS(cinfo,code,str) \
  150649. ((cinfo)->err->msg_code = (code), \
  150650. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150651. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150652. #define MAKESTMT(stuff) do { stuff } while (0)
  150653. #define WARNMS(cinfo,code) \
  150654. ((cinfo)->err->msg_code = (code), \
  150655. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150656. #define WARNMS1(cinfo,code,p1) \
  150657. ((cinfo)->err->msg_code = (code), \
  150658. (cinfo)->err->msg_parm.i[0] = (p1), \
  150659. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150660. #define WARNMS2(cinfo,code,p1,p2) \
  150661. ((cinfo)->err->msg_code = (code), \
  150662. (cinfo)->err->msg_parm.i[0] = (p1), \
  150663. (cinfo)->err->msg_parm.i[1] = (p2), \
  150664. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150665. #define TRACEMS(cinfo,lvl,code) \
  150666. ((cinfo)->err->msg_code = (code), \
  150667. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150668. #define TRACEMS1(cinfo,lvl,code,p1) \
  150669. ((cinfo)->err->msg_code = (code), \
  150670. (cinfo)->err->msg_parm.i[0] = (p1), \
  150671. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150672. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150673. ((cinfo)->err->msg_code = (code), \
  150674. (cinfo)->err->msg_parm.i[0] = (p1), \
  150675. (cinfo)->err->msg_parm.i[1] = (p2), \
  150676. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150677. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150678. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150679. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150680. (cinfo)->err->msg_code = (code); \
  150681. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150682. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150683. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150684. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150685. (cinfo)->err->msg_code = (code); \
  150686. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150687. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150688. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150689. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150690. _mp[4] = (p5); \
  150691. (cinfo)->err->msg_code = (code); \
  150692. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150693. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150694. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150695. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150696. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150697. (cinfo)->err->msg_code = (code); \
  150698. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150699. #define TRACEMSS(cinfo,lvl,code,str) \
  150700. ((cinfo)->err->msg_code = (code), \
  150701. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150702. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150703. #endif /* JERROR_H */
  150704. /*** End of inlined file: jerror.h ***/
  150705. typedef struct {
  150706. struct jpeg_source_mgr pub; /* public fields */
  150707. FILE * infile; /* source stream */
  150708. JOCTET * buffer; /* start of buffer */
  150709. boolean start_of_file; /* have we gotten any data yet? */
  150710. } my_source_mgr;
  150711. typedef my_source_mgr * my_src_ptr;
  150712. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150713. METHODDEF(void)
  150714. init_source (j_decompress_ptr cinfo)
  150715. {
  150716. my_src_ptr src = (my_src_ptr) cinfo->src;
  150717. src->start_of_file = TRUE;
  150718. }
  150719. METHODDEF(boolean)
  150720. fill_input_buffer (j_decompress_ptr cinfo)
  150721. {
  150722. my_src_ptr src = (my_src_ptr) cinfo->src;
  150723. size_t nbytes;
  150724. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150725. if (nbytes <= 0) {
  150726. if (src->start_of_file) /* Treat empty input file as fatal error */
  150727. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150728. WARNMS(cinfo, JWRN_JPEG_EOF);
  150729. src->buffer[0] = (JOCTET) 0xFF;
  150730. src->buffer[1] = (JOCTET) JPEG_EOI;
  150731. nbytes = 2;
  150732. }
  150733. src->pub.next_input_byte = src->buffer;
  150734. src->pub.bytes_in_buffer = nbytes;
  150735. src->start_of_file = FALSE;
  150736. return TRUE;
  150737. }
  150738. METHODDEF(void)
  150739. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150740. {
  150741. my_src_ptr src = (my_src_ptr) cinfo->src;
  150742. if (num_bytes > 0) {
  150743. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150744. num_bytes -= (long) src->pub.bytes_in_buffer;
  150745. (void) fill_input_buffer(cinfo);
  150746. }
  150747. src->pub.next_input_byte += (size_t) num_bytes;
  150748. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150749. }
  150750. }
  150751. METHODDEF(void)
  150752. term_source (j_decompress_ptr cinfo)
  150753. {
  150754. }
  150755. GLOBAL(void)
  150756. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150757. {
  150758. my_src_ptr src;
  150759. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150760. cinfo->src = (struct jpeg_source_mgr *)
  150761. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150762. SIZEOF(my_source_mgr));
  150763. src = (my_src_ptr) cinfo->src;
  150764. src->buffer = (JOCTET *)
  150765. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150766. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150767. }
  150768. src = (my_src_ptr) cinfo->src;
  150769. src->pub.init_source = init_source;
  150770. src->pub.fill_input_buffer = fill_input_buffer;
  150771. src->pub.skip_input_data = skip_input_data;
  150772. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150773. src->pub.term_source = term_source;
  150774. src->infile = infile;
  150775. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150776. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150777. }
  150778. /*** End of inlined file: jdatasrc.c ***/
  150779. /*** Start of inlined file: jdcoefct.c ***/
  150780. #define JPEG_INTERNALS
  150781. #ifndef D_PROGRESSIVE_SUPPORTED
  150782. #undef BLOCK_SMOOTHING_SUPPORTED
  150783. #endif
  150784. typedef struct {
  150785. struct jpeg_d_coef_controller pub; /* public fields */
  150786. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150787. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150788. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150789. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150790. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150791. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150792. #endif
  150793. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150794. int * coef_bits_latch;
  150795. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150796. #endif
  150797. } my_coef_controller3;
  150798. typedef my_coef_controller3 * my_coef_ptr3;
  150799. METHODDEF(int) decompress_onepass
  150800. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150801. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150802. METHODDEF(int) decompress_data
  150803. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150804. #endif
  150805. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150806. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150807. METHODDEF(int) decompress_smooth_data
  150808. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150809. #endif
  150810. LOCAL(void)
  150811. start_iMCU_row3 (j_decompress_ptr cinfo)
  150812. {
  150813. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150814. if (cinfo->comps_in_scan > 1) {
  150815. coef->MCU_rows_per_iMCU_row = 1;
  150816. } else {
  150817. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150818. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150819. else
  150820. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150821. }
  150822. coef->MCU_ctr = 0;
  150823. coef->MCU_vert_offset = 0;
  150824. }
  150825. METHODDEF(void)
  150826. start_input_pass (j_decompress_ptr cinfo)
  150827. {
  150828. cinfo->input_iMCU_row = 0;
  150829. start_iMCU_row3(cinfo);
  150830. }
  150831. METHODDEF(void)
  150832. start_output_pass (j_decompress_ptr cinfo)
  150833. {
  150834. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150835. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150836. if (coef->pub.coef_arrays != NULL) {
  150837. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150838. coef->pub.decompress_data = decompress_smooth_data;
  150839. else
  150840. coef->pub.decompress_data = decompress_data;
  150841. }
  150842. #endif
  150843. cinfo->output_iMCU_row = 0;
  150844. }
  150845. METHODDEF(int)
  150846. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150847. {
  150848. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150849. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150850. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150851. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150852. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150853. JSAMPARRAY output_ptr;
  150854. JDIMENSION start_col, output_col;
  150855. jpeg_component_info *compptr;
  150856. inverse_DCT_method_ptr inverse_DCT;
  150857. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150858. yoffset++) {
  150859. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150860. MCU_col_num++) {
  150861. jzero_far((void FAR *) coef->MCU_buffer[0],
  150862. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150863. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150864. coef->MCU_vert_offset = yoffset;
  150865. coef->MCU_ctr = MCU_col_num;
  150866. return JPEG_SUSPENDED;
  150867. }
  150868. blkn = 0; /* index of current DCT block within MCU */
  150869. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150870. compptr = cinfo->cur_comp_info[ci];
  150871. if (! compptr->component_needed) {
  150872. blkn += compptr->MCU_blocks;
  150873. continue;
  150874. }
  150875. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150876. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150877. : compptr->last_col_width;
  150878. output_ptr = output_buf[compptr->component_index] +
  150879. yoffset * compptr->DCT_scaled_size;
  150880. start_col = MCU_col_num * compptr->MCU_sample_width;
  150881. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150882. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150883. yoffset+yindex < compptr->last_row_height) {
  150884. output_col = start_col;
  150885. for (xindex = 0; xindex < useful_width; xindex++) {
  150886. (*inverse_DCT) (cinfo, compptr,
  150887. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150888. output_ptr, output_col);
  150889. output_col += compptr->DCT_scaled_size;
  150890. }
  150891. }
  150892. blkn += compptr->MCU_width;
  150893. output_ptr += compptr->DCT_scaled_size;
  150894. }
  150895. }
  150896. }
  150897. coef->MCU_ctr = 0;
  150898. }
  150899. cinfo->output_iMCU_row++;
  150900. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150901. start_iMCU_row3(cinfo);
  150902. return JPEG_ROW_COMPLETED;
  150903. }
  150904. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150905. return JPEG_SCAN_COMPLETED;
  150906. }
  150907. METHODDEF(int)
  150908. dummy_consume_data (j_decompress_ptr cinfo)
  150909. {
  150910. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  150911. }
  150912. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150913. METHODDEF(int)
  150914. consume_data (j_decompress_ptr cinfo)
  150915. {
  150916. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150917. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150918. int blkn, ci, xindex, yindex, yoffset;
  150919. JDIMENSION start_col;
  150920. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150921. JBLOCKROW buffer_ptr;
  150922. jpeg_component_info *compptr;
  150923. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150924. compptr = cinfo->cur_comp_info[ci];
  150925. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150926. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150927. cinfo->input_iMCU_row * compptr->v_samp_factor,
  150928. (JDIMENSION) compptr->v_samp_factor, TRUE);
  150929. }
  150930. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150931. yoffset++) {
  150932. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150933. MCU_col_num++) {
  150934. blkn = 0; /* index of current DCT block within MCU */
  150935. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150936. compptr = cinfo->cur_comp_info[ci];
  150937. start_col = MCU_col_num * compptr->MCU_width;
  150938. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150939. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150940. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  150941. coef->MCU_buffer[blkn++] = buffer_ptr++;
  150942. }
  150943. }
  150944. }
  150945. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150946. coef->MCU_vert_offset = yoffset;
  150947. coef->MCU_ctr = MCU_col_num;
  150948. return JPEG_SUSPENDED;
  150949. }
  150950. }
  150951. coef->MCU_ctr = 0;
  150952. }
  150953. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150954. start_iMCU_row3(cinfo);
  150955. return JPEG_ROW_COMPLETED;
  150956. }
  150957. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150958. return JPEG_SCAN_COMPLETED;
  150959. }
  150960. METHODDEF(int)
  150961. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150962. {
  150963. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150964. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150965. JDIMENSION block_num;
  150966. int ci, block_row, block_rows;
  150967. JBLOCKARRAY buffer;
  150968. JBLOCKROW buffer_ptr;
  150969. JSAMPARRAY output_ptr;
  150970. JDIMENSION output_col;
  150971. jpeg_component_info *compptr;
  150972. inverse_DCT_method_ptr inverse_DCT;
  150973. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  150974. (cinfo->input_scan_number == cinfo->output_scan_number &&
  150975. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  150976. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150977. return JPEG_SUSPENDED;
  150978. }
  150979. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150980. ci++, compptr++) {
  150981. if (! compptr->component_needed)
  150982. continue;
  150983. buffer = (*cinfo->mem->access_virt_barray)
  150984. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150985. cinfo->output_iMCU_row * compptr->v_samp_factor,
  150986. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150987. if (cinfo->output_iMCU_row < last_iMCU_row)
  150988. block_rows = compptr->v_samp_factor;
  150989. else {
  150990. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  150991. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  150992. }
  150993. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  150994. output_ptr = output_buf[ci];
  150995. for (block_row = 0; block_row < block_rows; block_row++) {
  150996. buffer_ptr = buffer[block_row];
  150997. output_col = 0;
  150998. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  150999. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151000. output_ptr, output_col);
  151001. buffer_ptr++;
  151002. output_col += compptr->DCT_scaled_size;
  151003. }
  151004. output_ptr += compptr->DCT_scaled_size;
  151005. }
  151006. }
  151007. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151008. return JPEG_ROW_COMPLETED;
  151009. return JPEG_SCAN_COMPLETED;
  151010. }
  151011. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151012. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151013. #define Q01_POS 1
  151014. #define Q10_POS 8
  151015. #define Q20_POS 16
  151016. #define Q11_POS 9
  151017. #define Q02_POS 2
  151018. LOCAL(boolean)
  151019. smoothing_ok (j_decompress_ptr cinfo)
  151020. {
  151021. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151022. boolean smoothing_useful = FALSE;
  151023. int ci, coefi;
  151024. jpeg_component_info *compptr;
  151025. JQUANT_TBL * qtable;
  151026. int * coef_bits;
  151027. int * coef_bits_latch;
  151028. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151029. return FALSE;
  151030. if (coef->coef_bits_latch == NULL)
  151031. coef->coef_bits_latch = (int *)
  151032. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151033. cinfo->num_components *
  151034. (SAVED_COEFS * SIZEOF(int)));
  151035. coef_bits_latch = coef->coef_bits_latch;
  151036. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151037. ci++, compptr++) {
  151038. if ((qtable = compptr->quant_table) == NULL)
  151039. return FALSE;
  151040. if (qtable->quantval[0] == 0 ||
  151041. qtable->quantval[Q01_POS] == 0 ||
  151042. qtable->quantval[Q10_POS] == 0 ||
  151043. qtable->quantval[Q20_POS] == 0 ||
  151044. qtable->quantval[Q11_POS] == 0 ||
  151045. qtable->quantval[Q02_POS] == 0)
  151046. return FALSE;
  151047. coef_bits = cinfo->coef_bits[ci];
  151048. if (coef_bits[0] < 0)
  151049. return FALSE;
  151050. for (coefi = 1; coefi <= 5; coefi++) {
  151051. coef_bits_latch[coefi] = coef_bits[coefi];
  151052. if (coef_bits[coefi] != 0)
  151053. smoothing_useful = TRUE;
  151054. }
  151055. coef_bits_latch += SAVED_COEFS;
  151056. }
  151057. return smoothing_useful;
  151058. }
  151059. METHODDEF(int)
  151060. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151061. {
  151062. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151063. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151064. JDIMENSION block_num, last_block_column;
  151065. int ci, block_row, block_rows, access_rows;
  151066. JBLOCKARRAY buffer;
  151067. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151068. JSAMPARRAY output_ptr;
  151069. JDIMENSION output_col;
  151070. jpeg_component_info *compptr;
  151071. inverse_DCT_method_ptr inverse_DCT;
  151072. boolean first_row, last_row;
  151073. JBLOCK workspace;
  151074. int *coef_bits;
  151075. JQUANT_TBL *quanttbl;
  151076. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151077. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151078. int Al, pred;
  151079. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151080. ! cinfo->inputctl->eoi_reached) {
  151081. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151082. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151083. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151084. break;
  151085. }
  151086. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151087. return JPEG_SUSPENDED;
  151088. }
  151089. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151090. ci++, compptr++) {
  151091. if (! compptr->component_needed)
  151092. continue;
  151093. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151094. block_rows = compptr->v_samp_factor;
  151095. access_rows = block_rows * 2; /* this and next iMCU row */
  151096. last_row = FALSE;
  151097. } else {
  151098. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151099. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151100. access_rows = block_rows; /* this iMCU row only */
  151101. last_row = TRUE;
  151102. }
  151103. if (cinfo->output_iMCU_row > 0) {
  151104. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151105. buffer = (*cinfo->mem->access_virt_barray)
  151106. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151107. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151108. (JDIMENSION) access_rows, FALSE);
  151109. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151110. first_row = FALSE;
  151111. } else {
  151112. buffer = (*cinfo->mem->access_virt_barray)
  151113. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151114. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151115. first_row = TRUE;
  151116. }
  151117. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151118. quanttbl = compptr->quant_table;
  151119. Q00 = quanttbl->quantval[0];
  151120. Q01 = quanttbl->quantval[Q01_POS];
  151121. Q10 = quanttbl->quantval[Q10_POS];
  151122. Q20 = quanttbl->quantval[Q20_POS];
  151123. Q11 = quanttbl->quantval[Q11_POS];
  151124. Q02 = quanttbl->quantval[Q02_POS];
  151125. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151126. output_ptr = output_buf[ci];
  151127. for (block_row = 0; block_row < block_rows; block_row++) {
  151128. buffer_ptr = buffer[block_row];
  151129. if (first_row && block_row == 0)
  151130. prev_block_row = buffer_ptr;
  151131. else
  151132. prev_block_row = buffer[block_row-1];
  151133. if (last_row && block_row == block_rows-1)
  151134. next_block_row = buffer_ptr;
  151135. else
  151136. next_block_row = buffer[block_row+1];
  151137. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151138. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151139. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151140. output_col = 0;
  151141. last_block_column = compptr->width_in_blocks - 1;
  151142. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151143. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151144. if (block_num < last_block_column) {
  151145. DC3 = (int) prev_block_row[1][0];
  151146. DC6 = (int) buffer_ptr[1][0];
  151147. DC9 = (int) next_block_row[1][0];
  151148. }
  151149. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151150. num = 36 * Q00 * (DC4 - DC6);
  151151. if (num >= 0) {
  151152. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151153. if (Al > 0 && pred >= (1<<Al))
  151154. pred = (1<<Al)-1;
  151155. } else {
  151156. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151157. if (Al > 0 && pred >= (1<<Al))
  151158. pred = (1<<Al)-1;
  151159. pred = -pred;
  151160. }
  151161. workspace[1] = (JCOEF) pred;
  151162. }
  151163. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151164. num = 36 * Q00 * (DC2 - DC8);
  151165. if (num >= 0) {
  151166. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151167. if (Al > 0 && pred >= (1<<Al))
  151168. pred = (1<<Al)-1;
  151169. } else {
  151170. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151171. if (Al > 0 && pred >= (1<<Al))
  151172. pred = (1<<Al)-1;
  151173. pred = -pred;
  151174. }
  151175. workspace[8] = (JCOEF) pred;
  151176. }
  151177. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151178. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151179. if (num >= 0) {
  151180. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151181. if (Al > 0 && pred >= (1<<Al))
  151182. pred = (1<<Al)-1;
  151183. } else {
  151184. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151185. if (Al > 0 && pred >= (1<<Al))
  151186. pred = (1<<Al)-1;
  151187. pred = -pred;
  151188. }
  151189. workspace[16] = (JCOEF) pred;
  151190. }
  151191. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151192. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151193. if (num >= 0) {
  151194. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151195. if (Al > 0 && pred >= (1<<Al))
  151196. pred = (1<<Al)-1;
  151197. } else {
  151198. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151199. if (Al > 0 && pred >= (1<<Al))
  151200. pred = (1<<Al)-1;
  151201. pred = -pred;
  151202. }
  151203. workspace[9] = (JCOEF) pred;
  151204. }
  151205. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151206. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151207. if (num >= 0) {
  151208. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151209. if (Al > 0 && pred >= (1<<Al))
  151210. pred = (1<<Al)-1;
  151211. } else {
  151212. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151213. if (Al > 0 && pred >= (1<<Al))
  151214. pred = (1<<Al)-1;
  151215. pred = -pred;
  151216. }
  151217. workspace[2] = (JCOEF) pred;
  151218. }
  151219. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151220. output_ptr, output_col);
  151221. DC1 = DC2; DC2 = DC3;
  151222. DC4 = DC5; DC5 = DC6;
  151223. DC7 = DC8; DC8 = DC9;
  151224. buffer_ptr++, prev_block_row++, next_block_row++;
  151225. output_col += compptr->DCT_scaled_size;
  151226. }
  151227. output_ptr += compptr->DCT_scaled_size;
  151228. }
  151229. }
  151230. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151231. return JPEG_ROW_COMPLETED;
  151232. return JPEG_SCAN_COMPLETED;
  151233. }
  151234. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151235. GLOBAL(void)
  151236. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151237. {
  151238. my_coef_ptr3 coef;
  151239. coef = (my_coef_ptr3)
  151240. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151241. SIZEOF(my_coef_controller3));
  151242. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151243. coef->pub.start_input_pass = start_input_pass;
  151244. coef->pub.start_output_pass = start_output_pass;
  151245. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151246. coef->coef_bits_latch = NULL;
  151247. #endif
  151248. if (need_full_buffer) {
  151249. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151250. int ci, access_rows;
  151251. jpeg_component_info *compptr;
  151252. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151253. ci++, compptr++) {
  151254. access_rows = compptr->v_samp_factor;
  151255. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151256. if (cinfo->progressive_mode)
  151257. access_rows *= 3;
  151258. #endif
  151259. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151260. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151261. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151262. (long) compptr->h_samp_factor),
  151263. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151264. (long) compptr->v_samp_factor),
  151265. (JDIMENSION) access_rows);
  151266. }
  151267. coef->pub.consume_data = consume_data;
  151268. coef->pub.decompress_data = decompress_data;
  151269. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151270. #else
  151271. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151272. #endif
  151273. } else {
  151274. JBLOCKROW buffer;
  151275. int i;
  151276. buffer = (JBLOCKROW)
  151277. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151278. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151279. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151280. coef->MCU_buffer[i] = buffer + i;
  151281. }
  151282. coef->pub.consume_data = dummy_consume_data;
  151283. coef->pub.decompress_data = decompress_onepass;
  151284. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151285. }
  151286. }
  151287. /*** End of inlined file: jdcoefct.c ***/
  151288. #undef FIX
  151289. /*** Start of inlined file: jdcolor.c ***/
  151290. #define JPEG_INTERNALS
  151291. typedef struct {
  151292. struct jpeg_color_deconverter pub; /* public fields */
  151293. int * Cr_r_tab; /* => table for Cr to R conversion */
  151294. int * Cb_b_tab; /* => table for Cb to B conversion */
  151295. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151296. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151297. } my_color_deconverter2;
  151298. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151299. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151300. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151301. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151302. LOCAL(void)
  151303. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151304. {
  151305. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151306. int i;
  151307. INT32 x;
  151308. SHIFT_TEMPS
  151309. cconvert->Cr_r_tab = (int *)
  151310. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151311. (MAXJSAMPLE+1) * SIZEOF(int));
  151312. cconvert->Cb_b_tab = (int *)
  151313. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151314. (MAXJSAMPLE+1) * SIZEOF(int));
  151315. cconvert->Cr_g_tab = (INT32 *)
  151316. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151317. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151318. cconvert->Cb_g_tab = (INT32 *)
  151319. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151320. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151321. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151322. cconvert->Cr_r_tab[i] = (int)
  151323. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151324. cconvert->Cb_b_tab[i] = (int)
  151325. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151326. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151327. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151328. }
  151329. }
  151330. METHODDEF(void)
  151331. ycc_rgb_convert (j_decompress_ptr cinfo,
  151332. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151333. JSAMPARRAY output_buf, int num_rows)
  151334. {
  151335. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151336. register int y, cb, cr;
  151337. register JSAMPROW outptr;
  151338. register JSAMPROW inptr0, inptr1, inptr2;
  151339. register JDIMENSION col;
  151340. JDIMENSION num_cols = cinfo->output_width;
  151341. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151342. register int * Crrtab = cconvert->Cr_r_tab;
  151343. register int * Cbbtab = cconvert->Cb_b_tab;
  151344. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151345. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151346. SHIFT_TEMPS
  151347. while (--num_rows >= 0) {
  151348. inptr0 = input_buf[0][input_row];
  151349. inptr1 = input_buf[1][input_row];
  151350. inptr2 = input_buf[2][input_row];
  151351. input_row++;
  151352. outptr = *output_buf++;
  151353. for (col = 0; col < num_cols; col++) {
  151354. y = GETJSAMPLE(inptr0[col]);
  151355. cb = GETJSAMPLE(inptr1[col]);
  151356. cr = GETJSAMPLE(inptr2[col]);
  151357. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151358. outptr[RGB_GREEN] = range_limit[y +
  151359. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151360. SCALEBITS))];
  151361. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151362. outptr += RGB_PIXELSIZE;
  151363. }
  151364. }
  151365. }
  151366. METHODDEF(void)
  151367. null_convert2 (j_decompress_ptr cinfo,
  151368. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151369. JSAMPARRAY output_buf, int num_rows)
  151370. {
  151371. register JSAMPROW inptr, outptr;
  151372. register JDIMENSION count;
  151373. register int num_components = cinfo->num_components;
  151374. JDIMENSION num_cols = cinfo->output_width;
  151375. int ci;
  151376. while (--num_rows >= 0) {
  151377. for (ci = 0; ci < num_components; ci++) {
  151378. inptr = input_buf[ci][input_row];
  151379. outptr = output_buf[0] + ci;
  151380. for (count = num_cols; count > 0; count--) {
  151381. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151382. outptr += num_components;
  151383. }
  151384. }
  151385. input_row++;
  151386. output_buf++;
  151387. }
  151388. }
  151389. METHODDEF(void)
  151390. grayscale_convert2 (j_decompress_ptr cinfo,
  151391. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151392. JSAMPARRAY output_buf, int num_rows)
  151393. {
  151394. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151395. num_rows, cinfo->output_width);
  151396. }
  151397. METHODDEF(void)
  151398. gray_rgb_convert (j_decompress_ptr cinfo,
  151399. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151400. JSAMPARRAY output_buf, int num_rows)
  151401. {
  151402. register JSAMPROW inptr, outptr;
  151403. register JDIMENSION col;
  151404. JDIMENSION num_cols = cinfo->output_width;
  151405. while (--num_rows >= 0) {
  151406. inptr = input_buf[0][input_row++];
  151407. outptr = *output_buf++;
  151408. for (col = 0; col < num_cols; col++) {
  151409. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151410. outptr += RGB_PIXELSIZE;
  151411. }
  151412. }
  151413. }
  151414. METHODDEF(void)
  151415. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151416. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151417. JSAMPARRAY output_buf, int num_rows)
  151418. {
  151419. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151420. register int y, cb, cr;
  151421. register JSAMPROW outptr;
  151422. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151423. register JDIMENSION col;
  151424. JDIMENSION num_cols = cinfo->output_width;
  151425. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151426. register int * Crrtab = cconvert->Cr_r_tab;
  151427. register int * Cbbtab = cconvert->Cb_b_tab;
  151428. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151429. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151430. SHIFT_TEMPS
  151431. while (--num_rows >= 0) {
  151432. inptr0 = input_buf[0][input_row];
  151433. inptr1 = input_buf[1][input_row];
  151434. inptr2 = input_buf[2][input_row];
  151435. inptr3 = input_buf[3][input_row];
  151436. input_row++;
  151437. outptr = *output_buf++;
  151438. for (col = 0; col < num_cols; col++) {
  151439. y = GETJSAMPLE(inptr0[col]);
  151440. cb = GETJSAMPLE(inptr1[col]);
  151441. cr = GETJSAMPLE(inptr2[col]);
  151442. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151443. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151444. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151445. SCALEBITS)))];
  151446. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151447. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151448. outptr += 4;
  151449. }
  151450. }
  151451. }
  151452. METHODDEF(void)
  151453. start_pass_dcolor (j_decompress_ptr cinfo)
  151454. {
  151455. }
  151456. GLOBAL(void)
  151457. jinit_color_deconverter (j_decompress_ptr cinfo)
  151458. {
  151459. my_cconvert_ptr2 cconvert;
  151460. int ci;
  151461. cconvert = (my_cconvert_ptr2)
  151462. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151463. SIZEOF(my_color_deconverter2));
  151464. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151465. cconvert->pub.start_pass = start_pass_dcolor;
  151466. switch (cinfo->jpeg_color_space) {
  151467. case JCS_GRAYSCALE:
  151468. if (cinfo->num_components != 1)
  151469. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151470. break;
  151471. case JCS_RGB:
  151472. case JCS_YCbCr:
  151473. if (cinfo->num_components != 3)
  151474. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151475. break;
  151476. case JCS_CMYK:
  151477. case JCS_YCCK:
  151478. if (cinfo->num_components != 4)
  151479. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151480. break;
  151481. default: /* JCS_UNKNOWN can be anything */
  151482. if (cinfo->num_components < 1)
  151483. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151484. break;
  151485. }
  151486. switch (cinfo->out_color_space) {
  151487. case JCS_GRAYSCALE:
  151488. cinfo->out_color_components = 1;
  151489. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151490. cinfo->jpeg_color_space == JCS_YCbCr) {
  151491. cconvert->pub.color_convert = grayscale_convert2;
  151492. for (ci = 1; ci < cinfo->num_components; ci++)
  151493. cinfo->comp_info[ci].component_needed = FALSE;
  151494. } else
  151495. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151496. break;
  151497. case JCS_RGB:
  151498. cinfo->out_color_components = RGB_PIXELSIZE;
  151499. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151500. cconvert->pub.color_convert = ycc_rgb_convert;
  151501. build_ycc_rgb_table(cinfo);
  151502. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151503. cconvert->pub.color_convert = gray_rgb_convert;
  151504. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151505. cconvert->pub.color_convert = null_convert2;
  151506. } else
  151507. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151508. break;
  151509. case JCS_CMYK:
  151510. cinfo->out_color_components = 4;
  151511. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151512. cconvert->pub.color_convert = ycck_cmyk_convert;
  151513. build_ycc_rgb_table(cinfo);
  151514. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151515. cconvert->pub.color_convert = null_convert2;
  151516. } else
  151517. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151518. break;
  151519. default:
  151520. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151521. cinfo->out_color_components = cinfo->num_components;
  151522. cconvert->pub.color_convert = null_convert2;
  151523. } else /* unsupported non-null conversion */
  151524. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151525. break;
  151526. }
  151527. if (cinfo->quantize_colors)
  151528. cinfo->output_components = 1; /* single colormapped output component */
  151529. else
  151530. cinfo->output_components = cinfo->out_color_components;
  151531. }
  151532. /*** End of inlined file: jdcolor.c ***/
  151533. #undef FIX
  151534. /*** Start of inlined file: jddctmgr.c ***/
  151535. #define JPEG_INTERNALS
  151536. typedef struct {
  151537. struct jpeg_inverse_dct pub; /* public fields */
  151538. int cur_method[MAX_COMPONENTS];
  151539. } my_idct_controller;
  151540. typedef my_idct_controller * my_idct_ptr;
  151541. typedef union {
  151542. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151543. #ifdef DCT_IFAST_SUPPORTED
  151544. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151545. #endif
  151546. #ifdef DCT_FLOAT_SUPPORTED
  151547. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151548. #endif
  151549. } multiplier_table;
  151550. #ifdef DCT_ISLOW_SUPPORTED
  151551. #define PROVIDE_ISLOW_TABLES
  151552. #else
  151553. #ifdef IDCT_SCALING_SUPPORTED
  151554. #define PROVIDE_ISLOW_TABLES
  151555. #endif
  151556. #endif
  151557. METHODDEF(void)
  151558. start_pass (j_decompress_ptr cinfo)
  151559. {
  151560. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151561. int ci, i;
  151562. jpeg_component_info *compptr;
  151563. int method = 0;
  151564. inverse_DCT_method_ptr method_ptr = NULL;
  151565. JQUANT_TBL * qtbl;
  151566. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151567. ci++, compptr++) {
  151568. switch (compptr->DCT_scaled_size) {
  151569. #ifdef IDCT_SCALING_SUPPORTED
  151570. case 1:
  151571. method_ptr = jpeg_idct_1x1;
  151572. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151573. break;
  151574. case 2:
  151575. method_ptr = jpeg_idct_2x2;
  151576. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151577. break;
  151578. case 4:
  151579. method_ptr = jpeg_idct_4x4;
  151580. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151581. break;
  151582. #endif
  151583. case DCTSIZE:
  151584. switch (cinfo->dct_method) {
  151585. #ifdef DCT_ISLOW_SUPPORTED
  151586. case JDCT_ISLOW:
  151587. method_ptr = jpeg_idct_islow;
  151588. method = JDCT_ISLOW;
  151589. break;
  151590. #endif
  151591. #ifdef DCT_IFAST_SUPPORTED
  151592. case JDCT_IFAST:
  151593. method_ptr = jpeg_idct_ifast;
  151594. method = JDCT_IFAST;
  151595. break;
  151596. #endif
  151597. #ifdef DCT_FLOAT_SUPPORTED
  151598. case JDCT_FLOAT:
  151599. method_ptr = jpeg_idct_float;
  151600. method = JDCT_FLOAT;
  151601. break;
  151602. #endif
  151603. default:
  151604. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151605. break;
  151606. }
  151607. break;
  151608. default:
  151609. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151610. break;
  151611. }
  151612. idct->pub.inverse_DCT[ci] = method_ptr;
  151613. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151614. continue;
  151615. qtbl = compptr->quant_table;
  151616. if (qtbl == NULL) /* happens if no data yet for component */
  151617. continue;
  151618. idct->cur_method[ci] = method;
  151619. switch (method) {
  151620. #ifdef PROVIDE_ISLOW_TABLES
  151621. case JDCT_ISLOW:
  151622. {
  151623. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151624. for (i = 0; i < DCTSIZE2; i++) {
  151625. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151626. }
  151627. }
  151628. break;
  151629. #endif
  151630. #ifdef DCT_IFAST_SUPPORTED
  151631. case JDCT_IFAST:
  151632. {
  151633. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151634. #define CONST_BITS 14
  151635. static const INT16 aanscales[DCTSIZE2] = {
  151636. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151637. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151638. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151639. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151640. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151641. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151642. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151643. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151644. };
  151645. SHIFT_TEMPS
  151646. for (i = 0; i < DCTSIZE2; i++) {
  151647. ifmtbl[i] = (IFAST_MULT_TYPE)
  151648. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151649. (INT32) aanscales[i]),
  151650. CONST_BITS-IFAST_SCALE_BITS);
  151651. }
  151652. }
  151653. break;
  151654. #endif
  151655. #ifdef DCT_FLOAT_SUPPORTED
  151656. case JDCT_FLOAT:
  151657. {
  151658. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151659. int row, col;
  151660. static const double aanscalefactor[DCTSIZE] = {
  151661. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151662. 1.0, 0.785694958, 0.541196100, 0.275899379
  151663. };
  151664. i = 0;
  151665. for (row = 0; row < DCTSIZE; row++) {
  151666. for (col = 0; col < DCTSIZE; col++) {
  151667. fmtbl[i] = (FLOAT_MULT_TYPE)
  151668. ((double) qtbl->quantval[i] *
  151669. aanscalefactor[row] * aanscalefactor[col]);
  151670. i++;
  151671. }
  151672. }
  151673. }
  151674. break;
  151675. #endif
  151676. default:
  151677. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151678. break;
  151679. }
  151680. }
  151681. }
  151682. GLOBAL(void)
  151683. jinit_inverse_dct (j_decompress_ptr cinfo)
  151684. {
  151685. my_idct_ptr idct;
  151686. int ci;
  151687. jpeg_component_info *compptr;
  151688. idct = (my_idct_ptr)
  151689. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151690. SIZEOF(my_idct_controller));
  151691. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151692. idct->pub.start_pass = start_pass;
  151693. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151694. ci++, compptr++) {
  151695. compptr->dct_table =
  151696. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151697. SIZEOF(multiplier_table));
  151698. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151699. idct->cur_method[ci] = -1;
  151700. }
  151701. }
  151702. /*** End of inlined file: jddctmgr.c ***/
  151703. #undef CONST_BITS
  151704. #undef ASSIGN_STATE
  151705. /*** Start of inlined file: jdhuff.c ***/
  151706. #define JPEG_INTERNALS
  151707. /*** Start of inlined file: jdhuff.h ***/
  151708. #ifndef __jdhuff_h__
  151709. #define __jdhuff_h__
  151710. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151711. #define jpeg_make_d_derived_tbl jMkDDerived
  151712. #define jpeg_fill_bit_buffer jFilBitBuf
  151713. #define jpeg_huff_decode jHufDecode
  151714. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151715. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151716. typedef struct {
  151717. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151718. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151719. JHUFF_TBL *pub;
  151720. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151721. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151722. } d_derived_tbl;
  151723. EXTERN(void) jpeg_make_d_derived_tbl
  151724. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151725. d_derived_tbl ** pdtbl));
  151726. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151727. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151728. typedef struct { /* Bitreading state saved across MCUs */
  151729. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151730. int bits_left; /* # of unused bits in it */
  151731. } bitread_perm_state;
  151732. typedef struct { /* Bitreading working state within an MCU */
  151733. const JOCTET * next_input_byte; /* => next byte to read from source */
  151734. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151735. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151736. int bits_left; /* # of unused bits in it */
  151737. j_decompress_ptr cinfo; /* back link to decompress master record */
  151738. } bitread_working_state;
  151739. #define BITREAD_STATE_VARS \
  151740. register bit_buf_type get_buffer; \
  151741. register int bits_left; \
  151742. bitread_working_state br_state
  151743. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151744. br_state.cinfo = cinfop; \
  151745. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151746. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151747. get_buffer = permstate.get_buffer; \
  151748. bits_left = permstate.bits_left;
  151749. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151750. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151751. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151752. permstate.get_buffer = get_buffer; \
  151753. permstate.bits_left = bits_left
  151754. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151755. { if (bits_left < (nbits)) { \
  151756. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151757. { action; } \
  151758. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151759. #define GET_BITS(nbits) \
  151760. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151761. #define PEEK_BITS(nbits) \
  151762. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151763. #define DROP_BITS(nbits) \
  151764. (bits_left -= (nbits))
  151765. EXTERN(boolean) jpeg_fill_bit_buffer
  151766. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151767. register int bits_left, int nbits));
  151768. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151769. { register int nb, look; \
  151770. if (bits_left < HUFF_LOOKAHEAD) { \
  151771. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151772. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151773. if (bits_left < HUFF_LOOKAHEAD) { \
  151774. nb = 1; goto slowlabel; \
  151775. } \
  151776. } \
  151777. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151778. if ((nb = htbl->look_nbits[look]) != 0) { \
  151779. DROP_BITS(nb); \
  151780. result = htbl->look_sym[look]; \
  151781. } else { \
  151782. nb = HUFF_LOOKAHEAD+1; \
  151783. slowlabel: \
  151784. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151785. { failaction; } \
  151786. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151787. } \
  151788. }
  151789. EXTERN(int) jpeg_huff_decode
  151790. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151791. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151792. #endif
  151793. /*** End of inlined file: jdhuff.h ***/
  151794. /* Declarations shared with jdphuff.c */
  151795. typedef struct {
  151796. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151797. } savable_state2;
  151798. #ifndef NO_STRUCT_ASSIGN
  151799. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151800. #else
  151801. #if MAX_COMPS_IN_SCAN == 4
  151802. #define ASSIGN_STATE(dest,src) \
  151803. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151804. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151805. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151806. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151807. #endif
  151808. #endif
  151809. typedef struct {
  151810. struct jpeg_entropy_decoder pub; /* public fields */
  151811. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151812. savable_state2 saved; /* Other state at start of MCU */
  151813. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151814. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151815. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151816. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151817. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151818. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151819. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151820. } huff_entropy_decoder2;
  151821. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151822. METHODDEF(void)
  151823. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151824. {
  151825. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151826. int ci, blkn, dctbl, actbl;
  151827. jpeg_component_info * compptr;
  151828. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151829. cinfo->Ah != 0 || cinfo->Al != 0)
  151830. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151831. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151832. compptr = cinfo->cur_comp_info[ci];
  151833. dctbl = compptr->dc_tbl_no;
  151834. actbl = compptr->ac_tbl_no;
  151835. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151836. & entropy->dc_derived_tbls[dctbl]);
  151837. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151838. & entropy->ac_derived_tbls[actbl]);
  151839. entropy->saved.last_dc_val[ci] = 0;
  151840. }
  151841. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151842. ci = cinfo->MCU_membership[blkn];
  151843. compptr = cinfo->cur_comp_info[ci];
  151844. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151845. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151846. if (compptr->component_needed) {
  151847. entropy->dc_needed[blkn] = TRUE;
  151848. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151849. } else {
  151850. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151851. }
  151852. }
  151853. entropy->bitstate.bits_left = 0;
  151854. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151855. entropy->pub.insufficient_data = FALSE;
  151856. entropy->restarts_to_go = cinfo->restart_interval;
  151857. }
  151858. GLOBAL(void)
  151859. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151860. d_derived_tbl ** pdtbl)
  151861. {
  151862. JHUFF_TBL *htbl;
  151863. d_derived_tbl *dtbl;
  151864. int p, i, l, si, numsymbols;
  151865. int lookbits, ctr;
  151866. char huffsize[257];
  151867. unsigned int huffcode[257];
  151868. unsigned int code;
  151869. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151870. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151871. htbl =
  151872. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151873. if (htbl == NULL)
  151874. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151875. if (*pdtbl == NULL)
  151876. *pdtbl = (d_derived_tbl *)
  151877. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151878. SIZEOF(d_derived_tbl));
  151879. dtbl = *pdtbl;
  151880. dtbl->pub = htbl; /* fill in back link */
  151881. p = 0;
  151882. for (l = 1; l <= 16; l++) {
  151883. i = (int) htbl->bits[l];
  151884. if (i < 0 || p + i > 256) /* protect against table overrun */
  151885. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151886. while (i--)
  151887. huffsize[p++] = (char) l;
  151888. }
  151889. huffsize[p] = 0;
  151890. numsymbols = p;
  151891. code = 0;
  151892. si = huffsize[0];
  151893. p = 0;
  151894. while (huffsize[p]) {
  151895. while (((int) huffsize[p]) == si) {
  151896. huffcode[p++] = code;
  151897. code++;
  151898. }
  151899. if (((INT32) code) >= (((INT32) 1) << si))
  151900. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151901. code <<= 1;
  151902. si++;
  151903. }
  151904. p = 0;
  151905. for (l = 1; l <= 16; l++) {
  151906. if (htbl->bits[l]) {
  151907. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151908. p += htbl->bits[l];
  151909. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151910. } else {
  151911. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  151912. }
  151913. }
  151914. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  151915. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  151916. p = 0;
  151917. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  151918. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  151919. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  151920. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  151921. dtbl->look_nbits[lookbits] = l;
  151922. dtbl->look_sym[lookbits] = htbl->huffval[p];
  151923. lookbits++;
  151924. }
  151925. }
  151926. }
  151927. if (isDC) {
  151928. for (i = 0; i < numsymbols; i++) {
  151929. int sym = htbl->huffval[i];
  151930. if (sym < 0 || sym > 15)
  151931. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151932. }
  151933. }
  151934. }
  151935. #ifdef SLOW_SHIFT_32
  151936. #define MIN_GET_BITS 15 /* minimum allowable value */
  151937. #else
  151938. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  151939. #endif
  151940. GLOBAL(boolean)
  151941. jpeg_fill_bit_buffer (bitread_working_state * state,
  151942. register bit_buf_type get_buffer, register int bits_left,
  151943. int nbits)
  151944. {
  151945. register const JOCTET * next_input_byte = state->next_input_byte;
  151946. register size_t bytes_in_buffer = state->bytes_in_buffer;
  151947. j_decompress_ptr cinfo = state->cinfo;
  151948. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  151949. while (bits_left < MIN_GET_BITS) {
  151950. register int c;
  151951. if (bytes_in_buffer == 0) {
  151952. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151953. return FALSE;
  151954. next_input_byte = cinfo->src->next_input_byte;
  151955. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151956. }
  151957. bytes_in_buffer--;
  151958. c = GETJOCTET(*next_input_byte++);
  151959. if (c == 0xFF) {
  151960. do {
  151961. if (bytes_in_buffer == 0) {
  151962. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151963. return FALSE;
  151964. next_input_byte = cinfo->src->next_input_byte;
  151965. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151966. }
  151967. bytes_in_buffer--;
  151968. c = GETJOCTET(*next_input_byte++);
  151969. } while (c == 0xFF);
  151970. if (c == 0) {
  151971. c = 0xFF;
  151972. } else {
  151973. cinfo->unread_marker = c;
  151974. goto no_more_bytes;
  151975. }
  151976. }
  151977. get_buffer = (get_buffer << 8) | c;
  151978. bits_left += 8;
  151979. } /* end while */
  151980. } else {
  151981. no_more_bytes:
  151982. if (nbits > bits_left) {
  151983. if (! cinfo->entropy->insufficient_data) {
  151984. WARNMS(cinfo, JWRN_HIT_MARKER);
  151985. cinfo->entropy->insufficient_data = TRUE;
  151986. }
  151987. get_buffer <<= MIN_GET_BITS - bits_left;
  151988. bits_left = MIN_GET_BITS;
  151989. }
  151990. }
  151991. state->next_input_byte = next_input_byte;
  151992. state->bytes_in_buffer = bytes_in_buffer;
  151993. state->get_buffer = get_buffer;
  151994. state->bits_left = bits_left;
  151995. return TRUE;
  151996. }
  151997. GLOBAL(int)
  151998. jpeg_huff_decode (bitread_working_state * state,
  151999. register bit_buf_type get_buffer, register int bits_left,
  152000. d_derived_tbl * htbl, int min_bits)
  152001. {
  152002. register int l = min_bits;
  152003. register INT32 code;
  152004. CHECK_BIT_BUFFER(*state, l, return -1);
  152005. code = GET_BITS(l);
  152006. while (code > htbl->maxcode[l]) {
  152007. code <<= 1;
  152008. CHECK_BIT_BUFFER(*state, 1, return -1);
  152009. code |= GET_BITS(1);
  152010. l++;
  152011. }
  152012. state->get_buffer = get_buffer;
  152013. state->bits_left = bits_left;
  152014. if (l > 16) {
  152015. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152016. return 0; /* fake a zero as the safest result */
  152017. }
  152018. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152019. }
  152020. LOCAL(boolean)
  152021. process_restart (j_decompress_ptr cinfo)
  152022. {
  152023. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152024. int ci;
  152025. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152026. entropy->bitstate.bits_left = 0;
  152027. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152028. return FALSE;
  152029. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152030. entropy->saved.last_dc_val[ci] = 0;
  152031. entropy->restarts_to_go = cinfo->restart_interval;
  152032. if (cinfo->unread_marker == 0)
  152033. entropy->pub.insufficient_data = FALSE;
  152034. return TRUE;
  152035. }
  152036. METHODDEF(boolean)
  152037. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152038. {
  152039. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152040. int blkn;
  152041. BITREAD_STATE_VARS;
  152042. savable_state2 state;
  152043. if (cinfo->restart_interval) {
  152044. if (entropy->restarts_to_go == 0)
  152045. if (! process_restart(cinfo))
  152046. return FALSE;
  152047. }
  152048. if (! entropy->pub.insufficient_data) {
  152049. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152050. ASSIGN_STATE(state, entropy->saved);
  152051. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152052. JBLOCKROW block = MCU_data[blkn];
  152053. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152054. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152055. register int s, k, r;
  152056. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152057. if (s) {
  152058. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152059. r = GET_BITS(s);
  152060. s = HUFF_EXTEND(r, s);
  152061. }
  152062. if (entropy->dc_needed[blkn]) {
  152063. int ci = cinfo->MCU_membership[blkn];
  152064. s += state.last_dc_val[ci];
  152065. state.last_dc_val[ci] = s;
  152066. (*block)[0] = (JCOEF) s;
  152067. }
  152068. if (entropy->ac_needed[blkn]) {
  152069. for (k = 1; k < DCTSIZE2; k++) {
  152070. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152071. r = s >> 4;
  152072. s &= 15;
  152073. if (s) {
  152074. k += r;
  152075. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152076. r = GET_BITS(s);
  152077. s = HUFF_EXTEND(r, s);
  152078. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152079. } else {
  152080. if (r != 15)
  152081. break;
  152082. k += 15;
  152083. }
  152084. }
  152085. } else {
  152086. for (k = 1; k < DCTSIZE2; k++) {
  152087. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152088. r = s >> 4;
  152089. s &= 15;
  152090. if (s) {
  152091. k += r;
  152092. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152093. DROP_BITS(s);
  152094. } else {
  152095. if (r != 15)
  152096. break;
  152097. k += 15;
  152098. }
  152099. }
  152100. }
  152101. }
  152102. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152103. ASSIGN_STATE(entropy->saved, state);
  152104. }
  152105. entropy->restarts_to_go--;
  152106. return TRUE;
  152107. }
  152108. GLOBAL(void)
  152109. jinit_huff_decoder (j_decompress_ptr cinfo)
  152110. {
  152111. huff_entropy_ptr2 entropy;
  152112. int i;
  152113. entropy = (huff_entropy_ptr2)
  152114. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152115. SIZEOF(huff_entropy_decoder2));
  152116. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152117. entropy->pub.start_pass = start_pass_huff_decoder;
  152118. entropy->pub.decode_mcu = decode_mcu;
  152119. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152120. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152121. }
  152122. }
  152123. /*** End of inlined file: jdhuff.c ***/
  152124. /*** Start of inlined file: jdinput.c ***/
  152125. #define JPEG_INTERNALS
  152126. typedef struct {
  152127. struct jpeg_input_controller pub; /* public fields */
  152128. boolean inheaders; /* TRUE until first SOS is reached */
  152129. } my_input_controller;
  152130. typedef my_input_controller * my_inputctl_ptr;
  152131. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152132. LOCAL(void)
  152133. initial_setup2 (j_decompress_ptr cinfo)
  152134. {
  152135. int ci;
  152136. jpeg_component_info *compptr;
  152137. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152138. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152139. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152140. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152141. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152142. if (cinfo->num_components > MAX_COMPONENTS)
  152143. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152144. MAX_COMPONENTS);
  152145. cinfo->max_h_samp_factor = 1;
  152146. cinfo->max_v_samp_factor = 1;
  152147. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152148. ci++, compptr++) {
  152149. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152150. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152151. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152152. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152153. compptr->h_samp_factor);
  152154. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152155. compptr->v_samp_factor);
  152156. }
  152157. cinfo->min_DCT_scaled_size = DCTSIZE;
  152158. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152159. ci++, compptr++) {
  152160. compptr->DCT_scaled_size = DCTSIZE;
  152161. compptr->width_in_blocks = (JDIMENSION)
  152162. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152163. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152164. compptr->height_in_blocks = (JDIMENSION)
  152165. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152166. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152167. compptr->downsampled_width = (JDIMENSION)
  152168. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152169. (long) cinfo->max_h_samp_factor);
  152170. compptr->downsampled_height = (JDIMENSION)
  152171. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152172. (long) cinfo->max_v_samp_factor);
  152173. compptr->component_needed = TRUE;
  152174. compptr->quant_table = NULL;
  152175. }
  152176. cinfo->total_iMCU_rows = (JDIMENSION)
  152177. jdiv_round_up((long) cinfo->image_height,
  152178. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152179. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152180. cinfo->inputctl->has_multiple_scans = TRUE;
  152181. else
  152182. cinfo->inputctl->has_multiple_scans = FALSE;
  152183. }
  152184. LOCAL(void)
  152185. per_scan_setup2 (j_decompress_ptr cinfo)
  152186. {
  152187. int ci, mcublks, tmp;
  152188. jpeg_component_info *compptr;
  152189. if (cinfo->comps_in_scan == 1) {
  152190. compptr = cinfo->cur_comp_info[0];
  152191. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152192. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152193. compptr->MCU_width = 1;
  152194. compptr->MCU_height = 1;
  152195. compptr->MCU_blocks = 1;
  152196. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152197. compptr->last_col_width = 1;
  152198. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152199. if (tmp == 0) tmp = compptr->v_samp_factor;
  152200. compptr->last_row_height = tmp;
  152201. cinfo->blocks_in_MCU = 1;
  152202. cinfo->MCU_membership[0] = 0;
  152203. } else {
  152204. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152205. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152206. MAX_COMPS_IN_SCAN);
  152207. cinfo->MCUs_per_row = (JDIMENSION)
  152208. jdiv_round_up((long) cinfo->image_width,
  152209. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152210. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152211. jdiv_round_up((long) cinfo->image_height,
  152212. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152213. cinfo->blocks_in_MCU = 0;
  152214. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152215. compptr = cinfo->cur_comp_info[ci];
  152216. compptr->MCU_width = compptr->h_samp_factor;
  152217. compptr->MCU_height = compptr->v_samp_factor;
  152218. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152219. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152220. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152221. if (tmp == 0) tmp = compptr->MCU_width;
  152222. compptr->last_col_width = tmp;
  152223. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152224. if (tmp == 0) tmp = compptr->MCU_height;
  152225. compptr->last_row_height = tmp;
  152226. mcublks = compptr->MCU_blocks;
  152227. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152228. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152229. while (mcublks-- > 0) {
  152230. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152231. }
  152232. }
  152233. }
  152234. }
  152235. LOCAL(void)
  152236. latch_quant_tables (j_decompress_ptr cinfo)
  152237. {
  152238. int ci, qtblno;
  152239. jpeg_component_info *compptr;
  152240. JQUANT_TBL * qtbl;
  152241. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152242. compptr = cinfo->cur_comp_info[ci];
  152243. if (compptr->quant_table != NULL)
  152244. continue;
  152245. qtblno = compptr->quant_tbl_no;
  152246. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152247. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152248. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152249. qtbl = (JQUANT_TBL *)
  152250. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152251. SIZEOF(JQUANT_TBL));
  152252. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152253. compptr->quant_table = qtbl;
  152254. }
  152255. }
  152256. METHODDEF(void)
  152257. start_input_pass2 (j_decompress_ptr cinfo)
  152258. {
  152259. per_scan_setup2(cinfo);
  152260. latch_quant_tables(cinfo);
  152261. (*cinfo->entropy->start_pass) (cinfo);
  152262. (*cinfo->coef->start_input_pass) (cinfo);
  152263. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152264. }
  152265. METHODDEF(void)
  152266. finish_input_pass (j_decompress_ptr cinfo)
  152267. {
  152268. cinfo->inputctl->consume_input = consume_markers;
  152269. }
  152270. METHODDEF(int)
  152271. consume_markers (j_decompress_ptr cinfo)
  152272. {
  152273. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152274. int val;
  152275. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152276. return JPEG_REACHED_EOI;
  152277. val = (*cinfo->marker->read_markers) (cinfo);
  152278. switch (val) {
  152279. case JPEG_REACHED_SOS: /* Found SOS */
  152280. if (inputctl->inheaders) { /* 1st SOS */
  152281. initial_setup2(cinfo);
  152282. inputctl->inheaders = FALSE;
  152283. } else { /* 2nd or later SOS marker */
  152284. if (! inputctl->pub.has_multiple_scans)
  152285. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152286. start_input_pass2(cinfo);
  152287. }
  152288. break;
  152289. case JPEG_REACHED_EOI: /* Found EOI */
  152290. inputctl->pub.eoi_reached = TRUE;
  152291. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152292. if (cinfo->marker->saw_SOF)
  152293. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152294. } else {
  152295. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152296. cinfo->output_scan_number = cinfo->input_scan_number;
  152297. }
  152298. break;
  152299. case JPEG_SUSPENDED:
  152300. break;
  152301. }
  152302. return val;
  152303. }
  152304. METHODDEF(void)
  152305. reset_input_controller (j_decompress_ptr cinfo)
  152306. {
  152307. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152308. inputctl->pub.consume_input = consume_markers;
  152309. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152310. inputctl->pub.eoi_reached = FALSE;
  152311. inputctl->inheaders = TRUE;
  152312. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152313. (*cinfo->marker->reset_marker_reader) (cinfo);
  152314. cinfo->coef_bits = NULL;
  152315. }
  152316. GLOBAL(void)
  152317. jinit_input_controller (j_decompress_ptr cinfo)
  152318. {
  152319. my_inputctl_ptr inputctl;
  152320. inputctl = (my_inputctl_ptr)
  152321. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152322. SIZEOF(my_input_controller));
  152323. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152324. inputctl->pub.consume_input = consume_markers;
  152325. inputctl->pub.reset_input_controller = reset_input_controller;
  152326. inputctl->pub.start_input_pass = start_input_pass2;
  152327. inputctl->pub.finish_input_pass = finish_input_pass;
  152328. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152329. inputctl->pub.eoi_reached = FALSE;
  152330. inputctl->inheaders = TRUE;
  152331. }
  152332. /*** End of inlined file: jdinput.c ***/
  152333. /*** Start of inlined file: jdmainct.c ***/
  152334. #define JPEG_INTERNALS
  152335. typedef struct {
  152336. struct jpeg_d_main_controller pub; /* public fields */
  152337. JSAMPARRAY buffer[MAX_COMPONENTS];
  152338. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152339. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152340. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152341. int whichptr; /* indicates which pointer set is now in use */
  152342. int context_state; /* process_data state machine status */
  152343. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152344. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152345. } my_main_controller4;
  152346. typedef my_main_controller4 * my_main_ptr4;
  152347. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152348. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152349. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152350. METHODDEF(void) process_data_simple_main2
  152351. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152352. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152353. METHODDEF(void) process_data_context_main
  152354. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152355. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152356. #ifdef QUANT_2PASS_SUPPORTED
  152357. METHODDEF(void) process_data_crank_post
  152358. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152359. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152360. #endif
  152361. LOCAL(void)
  152362. alloc_funny_pointers (j_decompress_ptr cinfo)
  152363. {
  152364. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152365. int ci, rgroup;
  152366. int M = cinfo->min_DCT_scaled_size;
  152367. jpeg_component_info *compptr;
  152368. JSAMPARRAY xbuf;
  152369. main_->xbuffer[0] = (JSAMPIMAGE)
  152370. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152371. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152372. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152373. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152374. ci++, compptr++) {
  152375. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152376. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152377. xbuf = (JSAMPARRAY)
  152378. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152379. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152380. xbuf += rgroup; /* want one row group at negative offsets */
  152381. main_->xbuffer[0][ci] = xbuf;
  152382. xbuf += rgroup * (M + 4);
  152383. main_->xbuffer[1][ci] = xbuf;
  152384. }
  152385. }
  152386. LOCAL(void)
  152387. make_funny_pointers (j_decompress_ptr cinfo)
  152388. {
  152389. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152390. int ci, i, rgroup;
  152391. int M = cinfo->min_DCT_scaled_size;
  152392. jpeg_component_info *compptr;
  152393. JSAMPARRAY buf, xbuf0, xbuf1;
  152394. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152395. ci++, compptr++) {
  152396. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152397. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152398. xbuf0 = main_->xbuffer[0][ci];
  152399. xbuf1 = main_->xbuffer[1][ci];
  152400. buf = main_->buffer[ci];
  152401. for (i = 0; i < rgroup * (M + 2); i++) {
  152402. xbuf0[i] = xbuf1[i] = buf[i];
  152403. }
  152404. for (i = 0; i < rgroup * 2; i++) {
  152405. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152406. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152407. }
  152408. for (i = 0; i < rgroup; i++) {
  152409. xbuf0[i - rgroup] = xbuf0[0];
  152410. }
  152411. }
  152412. }
  152413. LOCAL(void)
  152414. set_wraparound_pointers (j_decompress_ptr cinfo)
  152415. {
  152416. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152417. int ci, i, rgroup;
  152418. int M = cinfo->min_DCT_scaled_size;
  152419. jpeg_component_info *compptr;
  152420. JSAMPARRAY xbuf0, xbuf1;
  152421. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152422. ci++, compptr++) {
  152423. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152424. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152425. xbuf0 = main_->xbuffer[0][ci];
  152426. xbuf1 = main_->xbuffer[1][ci];
  152427. for (i = 0; i < rgroup; i++) {
  152428. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152429. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152430. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152431. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152432. }
  152433. }
  152434. }
  152435. LOCAL(void)
  152436. set_bottom_pointers (j_decompress_ptr cinfo)
  152437. {
  152438. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152439. int ci, i, rgroup, iMCUheight, rows_left;
  152440. jpeg_component_info *compptr;
  152441. JSAMPARRAY xbuf;
  152442. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152443. ci++, compptr++) {
  152444. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152445. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152446. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152447. if (rows_left == 0) rows_left = iMCUheight;
  152448. if (ci == 0) {
  152449. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152450. }
  152451. xbuf = main_->xbuffer[main_->whichptr][ci];
  152452. for (i = 0; i < rgroup * 2; i++) {
  152453. xbuf[rows_left + i] = xbuf[rows_left-1];
  152454. }
  152455. }
  152456. }
  152457. METHODDEF(void)
  152458. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152459. {
  152460. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152461. switch (pass_mode) {
  152462. case JBUF_PASS_THRU:
  152463. if (cinfo->upsample->need_context_rows) {
  152464. main_->pub.process_data = process_data_context_main;
  152465. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152466. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152467. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152468. main_->iMCU_row_ctr = 0;
  152469. } else {
  152470. main_->pub.process_data = process_data_simple_main2;
  152471. }
  152472. main_->buffer_full = FALSE; /* Mark buffer empty */
  152473. main_->rowgroup_ctr = 0;
  152474. break;
  152475. #ifdef QUANT_2PASS_SUPPORTED
  152476. case JBUF_CRANK_DEST:
  152477. main_->pub.process_data = process_data_crank_post;
  152478. break;
  152479. #endif
  152480. default:
  152481. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152482. break;
  152483. }
  152484. }
  152485. METHODDEF(void)
  152486. process_data_simple_main2 (j_decompress_ptr cinfo,
  152487. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152488. JDIMENSION out_rows_avail)
  152489. {
  152490. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152491. JDIMENSION rowgroups_avail;
  152492. if (! main_->buffer_full) {
  152493. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152494. return; /* suspension forced, can do nothing more */
  152495. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152496. }
  152497. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152498. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152499. &main_->rowgroup_ctr, rowgroups_avail,
  152500. output_buf, out_row_ctr, out_rows_avail);
  152501. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152502. main_->buffer_full = FALSE;
  152503. main_->rowgroup_ctr = 0;
  152504. }
  152505. }
  152506. METHODDEF(void)
  152507. process_data_context_main (j_decompress_ptr cinfo,
  152508. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152509. JDIMENSION out_rows_avail)
  152510. {
  152511. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152512. if (! main_->buffer_full) {
  152513. if (! (*cinfo->coef->decompress_data) (cinfo,
  152514. main_->xbuffer[main_->whichptr]))
  152515. return; /* suspension forced, can do nothing more */
  152516. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152517. main_->iMCU_row_ctr++; /* count rows received */
  152518. }
  152519. switch (main_->context_state) {
  152520. case CTX_POSTPONED_ROW:
  152521. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152522. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152523. output_buf, out_row_ctr, out_rows_avail);
  152524. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152525. return; /* Need to suspend */
  152526. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152527. if (*out_row_ctr >= out_rows_avail)
  152528. return; /* Postprocessor exactly filled output buf */
  152529. case CTX_PREPARE_FOR_IMCU:
  152530. main_->rowgroup_ctr = 0;
  152531. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152532. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152533. set_bottom_pointers(cinfo);
  152534. main_->context_state = CTX_PROCESS_IMCU;
  152535. case CTX_PROCESS_IMCU:
  152536. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152537. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152538. output_buf, out_row_ctr, out_rows_avail);
  152539. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152540. return; /* Need to suspend */
  152541. if (main_->iMCU_row_ctr == 1)
  152542. set_wraparound_pointers(cinfo);
  152543. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152544. main_->buffer_full = FALSE;
  152545. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152546. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152547. main_->context_state = CTX_POSTPONED_ROW;
  152548. }
  152549. }
  152550. #ifdef QUANT_2PASS_SUPPORTED
  152551. METHODDEF(void)
  152552. process_data_crank_post (j_decompress_ptr cinfo,
  152553. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152554. JDIMENSION out_rows_avail)
  152555. {
  152556. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152557. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152558. output_buf, out_row_ctr, out_rows_avail);
  152559. }
  152560. #endif /* QUANT_2PASS_SUPPORTED */
  152561. GLOBAL(void)
  152562. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152563. {
  152564. my_main_ptr4 main_;
  152565. int ci, rgroup, ngroups;
  152566. jpeg_component_info *compptr;
  152567. main_ = (my_main_ptr4)
  152568. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152569. SIZEOF(my_main_controller4));
  152570. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152571. main_->pub.start_pass = start_pass_main2;
  152572. if (need_full_buffer) /* shouldn't happen */
  152573. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152574. if (cinfo->upsample->need_context_rows) {
  152575. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152576. ERREXIT(cinfo, JERR_NOTIMPL);
  152577. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152578. ngroups = cinfo->min_DCT_scaled_size + 2;
  152579. } else {
  152580. ngroups = cinfo->min_DCT_scaled_size;
  152581. }
  152582. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152583. ci++, compptr++) {
  152584. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152585. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152586. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152587. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152588. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152589. (JDIMENSION) (rgroup * ngroups));
  152590. }
  152591. }
  152592. /*** End of inlined file: jdmainct.c ***/
  152593. /*** Start of inlined file: jdmarker.c ***/
  152594. #define JPEG_INTERNALS
  152595. typedef struct {
  152596. struct jpeg_marker_reader pub; /* public fields */
  152597. jpeg_marker_parser_method process_COM;
  152598. jpeg_marker_parser_method process_APPn[16];
  152599. unsigned int length_limit_COM;
  152600. unsigned int length_limit_APPn[16];
  152601. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152602. unsigned int bytes_read; /* data bytes read so far in marker */
  152603. } my_marker_reader;
  152604. typedef my_marker_reader * my_marker_ptr2;
  152605. #define INPUT_VARS(cinfo) \
  152606. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152607. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152608. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152609. #define INPUT_SYNC(cinfo) \
  152610. ( datasrc->next_input_byte = next_input_byte, \
  152611. datasrc->bytes_in_buffer = bytes_in_buffer )
  152612. #define INPUT_RELOAD(cinfo) \
  152613. ( next_input_byte = datasrc->next_input_byte, \
  152614. bytes_in_buffer = datasrc->bytes_in_buffer )
  152615. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152616. if (bytes_in_buffer == 0) { \
  152617. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152618. { action; } \
  152619. INPUT_RELOAD(cinfo); \
  152620. }
  152621. #define INPUT_BYTE(cinfo,V,action) \
  152622. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152623. bytes_in_buffer--; \
  152624. V = GETJOCTET(*next_input_byte++); )
  152625. #define INPUT_2BYTES(cinfo,V,action) \
  152626. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152627. bytes_in_buffer--; \
  152628. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152629. MAKE_BYTE_AVAIL(cinfo,action); \
  152630. bytes_in_buffer--; \
  152631. V += GETJOCTET(*next_input_byte++); )
  152632. LOCAL(boolean)
  152633. get_soi (j_decompress_ptr cinfo)
  152634. {
  152635. int i;
  152636. TRACEMS(cinfo, 1, JTRC_SOI);
  152637. if (cinfo->marker->saw_SOI)
  152638. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152639. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152640. cinfo->arith_dc_L[i] = 0;
  152641. cinfo->arith_dc_U[i] = 1;
  152642. cinfo->arith_ac_K[i] = 5;
  152643. }
  152644. cinfo->restart_interval = 0;
  152645. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152646. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152647. cinfo->saw_JFIF_marker = FALSE;
  152648. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152649. cinfo->JFIF_minor_version = 1;
  152650. cinfo->density_unit = 0;
  152651. cinfo->X_density = 1;
  152652. cinfo->Y_density = 1;
  152653. cinfo->saw_Adobe_marker = FALSE;
  152654. cinfo->Adobe_transform = 0;
  152655. cinfo->marker->saw_SOI = TRUE;
  152656. return TRUE;
  152657. }
  152658. LOCAL(boolean)
  152659. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152660. {
  152661. INT32 length;
  152662. int c, ci;
  152663. jpeg_component_info * compptr;
  152664. INPUT_VARS(cinfo);
  152665. cinfo->progressive_mode = is_prog;
  152666. cinfo->arith_code = is_arith;
  152667. INPUT_2BYTES(cinfo, length, return FALSE);
  152668. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152669. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152670. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152671. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152672. length -= 8;
  152673. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152674. (int) cinfo->image_width, (int) cinfo->image_height,
  152675. cinfo->num_components);
  152676. if (cinfo->marker->saw_SOF)
  152677. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152678. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152679. || cinfo->num_components <= 0)
  152680. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152681. if (length != (cinfo->num_components * 3))
  152682. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152683. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152684. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152685. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152686. cinfo->num_components * SIZEOF(jpeg_component_info));
  152687. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152688. ci++, compptr++) {
  152689. compptr->component_index = ci;
  152690. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152691. INPUT_BYTE(cinfo, c, return FALSE);
  152692. compptr->h_samp_factor = (c >> 4) & 15;
  152693. compptr->v_samp_factor = (c ) & 15;
  152694. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152695. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152696. compptr->component_id, compptr->h_samp_factor,
  152697. compptr->v_samp_factor, compptr->quant_tbl_no);
  152698. }
  152699. cinfo->marker->saw_SOF = TRUE;
  152700. INPUT_SYNC(cinfo);
  152701. return TRUE;
  152702. }
  152703. LOCAL(boolean)
  152704. get_sos (j_decompress_ptr cinfo)
  152705. {
  152706. INT32 length;
  152707. int i, ci, n, c, cc;
  152708. jpeg_component_info * compptr;
  152709. INPUT_VARS(cinfo);
  152710. if (! cinfo->marker->saw_SOF)
  152711. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152712. INPUT_2BYTES(cinfo, length, return FALSE);
  152713. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152714. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152715. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152716. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152717. cinfo->comps_in_scan = n;
  152718. for (i = 0; i < n; i++) {
  152719. INPUT_BYTE(cinfo, cc, return FALSE);
  152720. INPUT_BYTE(cinfo, c, return FALSE);
  152721. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152722. ci++, compptr++) {
  152723. if (cc == compptr->component_id)
  152724. goto id_found;
  152725. }
  152726. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152727. id_found:
  152728. cinfo->cur_comp_info[i] = compptr;
  152729. compptr->dc_tbl_no = (c >> 4) & 15;
  152730. compptr->ac_tbl_no = (c ) & 15;
  152731. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152732. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152733. }
  152734. INPUT_BYTE(cinfo, c, return FALSE);
  152735. cinfo->Ss = c;
  152736. INPUT_BYTE(cinfo, c, return FALSE);
  152737. cinfo->Se = c;
  152738. INPUT_BYTE(cinfo, c, return FALSE);
  152739. cinfo->Ah = (c >> 4) & 15;
  152740. cinfo->Al = (c ) & 15;
  152741. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152742. cinfo->Ah, cinfo->Al);
  152743. cinfo->marker->next_restart_num = 0;
  152744. cinfo->input_scan_number++;
  152745. INPUT_SYNC(cinfo);
  152746. return TRUE;
  152747. }
  152748. #ifdef D_ARITH_CODING_SUPPORTED
  152749. LOCAL(boolean)
  152750. get_dac (j_decompress_ptr cinfo)
  152751. {
  152752. INT32 length;
  152753. int index, val;
  152754. INPUT_VARS(cinfo);
  152755. INPUT_2BYTES(cinfo, length, return FALSE);
  152756. length -= 2;
  152757. while (length > 0) {
  152758. INPUT_BYTE(cinfo, index, return FALSE);
  152759. INPUT_BYTE(cinfo, val, return FALSE);
  152760. length -= 2;
  152761. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152762. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152763. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152764. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152765. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152766. } else { /* define DC table */
  152767. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152768. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152769. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152770. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152771. }
  152772. }
  152773. if (length != 0)
  152774. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152775. INPUT_SYNC(cinfo);
  152776. return TRUE;
  152777. }
  152778. #else /* ! D_ARITH_CODING_SUPPORTED */
  152779. #define get_dac(cinfo) skip_variable(cinfo)
  152780. #endif /* D_ARITH_CODING_SUPPORTED */
  152781. LOCAL(boolean)
  152782. get_dht (j_decompress_ptr cinfo)
  152783. {
  152784. INT32 length;
  152785. UINT8 bits[17];
  152786. UINT8 huffval[256];
  152787. int i, index, count;
  152788. JHUFF_TBL **htblptr;
  152789. INPUT_VARS(cinfo);
  152790. INPUT_2BYTES(cinfo, length, return FALSE);
  152791. length -= 2;
  152792. while (length > 16) {
  152793. INPUT_BYTE(cinfo, index, return FALSE);
  152794. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152795. bits[0] = 0;
  152796. count = 0;
  152797. for (i = 1; i <= 16; i++) {
  152798. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152799. count += bits[i];
  152800. }
  152801. length -= 1 + 16;
  152802. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152803. bits[1], bits[2], bits[3], bits[4],
  152804. bits[5], bits[6], bits[7], bits[8]);
  152805. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152806. bits[9], bits[10], bits[11], bits[12],
  152807. bits[13], bits[14], bits[15], bits[16]);
  152808. if (count > 256 || ((INT32) count) > length)
  152809. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152810. for (i = 0; i < count; i++)
  152811. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152812. length -= count;
  152813. if (index & 0x10) { /* AC table definition */
  152814. index -= 0x10;
  152815. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152816. } else { /* DC table definition */
  152817. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152818. }
  152819. if (index < 0 || index >= NUM_HUFF_TBLS)
  152820. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152821. if (*htblptr == NULL)
  152822. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152823. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152824. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152825. }
  152826. if (length != 0)
  152827. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152828. INPUT_SYNC(cinfo);
  152829. return TRUE;
  152830. }
  152831. LOCAL(boolean)
  152832. get_dqt (j_decompress_ptr cinfo)
  152833. {
  152834. INT32 length;
  152835. int n, i, prec;
  152836. unsigned int tmp;
  152837. JQUANT_TBL *quant_ptr;
  152838. INPUT_VARS(cinfo);
  152839. INPUT_2BYTES(cinfo, length, return FALSE);
  152840. length -= 2;
  152841. while (length > 0) {
  152842. INPUT_BYTE(cinfo, n, return FALSE);
  152843. prec = n >> 4;
  152844. n &= 0x0F;
  152845. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152846. if (n >= NUM_QUANT_TBLS)
  152847. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152848. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152849. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152850. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152851. for (i = 0; i < DCTSIZE2; i++) {
  152852. if (prec)
  152853. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152854. else
  152855. INPUT_BYTE(cinfo, tmp, return FALSE);
  152856. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152857. }
  152858. if (cinfo->err->trace_level >= 2) {
  152859. for (i = 0; i < DCTSIZE2; i += 8) {
  152860. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152861. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152862. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152863. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152864. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152865. }
  152866. }
  152867. length -= DCTSIZE2+1;
  152868. if (prec) length -= DCTSIZE2;
  152869. }
  152870. if (length != 0)
  152871. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152872. INPUT_SYNC(cinfo);
  152873. return TRUE;
  152874. }
  152875. LOCAL(boolean)
  152876. get_dri (j_decompress_ptr cinfo)
  152877. {
  152878. INT32 length;
  152879. unsigned int tmp;
  152880. INPUT_VARS(cinfo);
  152881. INPUT_2BYTES(cinfo, length, return FALSE);
  152882. if (length != 4)
  152883. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152884. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152885. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152886. cinfo->restart_interval = tmp;
  152887. INPUT_SYNC(cinfo);
  152888. return TRUE;
  152889. }
  152890. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152891. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152892. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152893. LOCAL(void)
  152894. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152895. unsigned int datalen, INT32 remaining)
  152896. {
  152897. INT32 totallen = (INT32) datalen + remaining;
  152898. if (datalen >= APP0_DATA_LEN &&
  152899. GETJOCTET(data[0]) == 0x4A &&
  152900. GETJOCTET(data[1]) == 0x46 &&
  152901. GETJOCTET(data[2]) == 0x49 &&
  152902. GETJOCTET(data[3]) == 0x46 &&
  152903. GETJOCTET(data[4]) == 0) {
  152904. cinfo->saw_JFIF_marker = TRUE;
  152905. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152906. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152907. cinfo->density_unit = GETJOCTET(data[7]);
  152908. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152909. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152910. if (cinfo->JFIF_major_version != 1)
  152911. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  152912. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  152913. TRACEMS5(cinfo, 1, JTRC_JFIF,
  152914. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  152915. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  152916. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  152917. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  152918. GETJOCTET(data[12]), GETJOCTET(data[13]));
  152919. totallen -= APP0_DATA_LEN;
  152920. if (totallen !=
  152921. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  152922. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  152923. } else if (datalen >= 6 &&
  152924. GETJOCTET(data[0]) == 0x4A &&
  152925. GETJOCTET(data[1]) == 0x46 &&
  152926. GETJOCTET(data[2]) == 0x58 &&
  152927. GETJOCTET(data[3]) == 0x58 &&
  152928. GETJOCTET(data[4]) == 0) {
  152929. switch (GETJOCTET(data[5])) {
  152930. case 0x10:
  152931. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  152932. break;
  152933. case 0x11:
  152934. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  152935. break;
  152936. case 0x13:
  152937. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  152938. break;
  152939. default:
  152940. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  152941. GETJOCTET(data[5]), (int) totallen);
  152942. break;
  152943. }
  152944. } else {
  152945. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  152946. }
  152947. }
  152948. LOCAL(void)
  152949. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152950. unsigned int datalen, INT32 remaining)
  152951. {
  152952. unsigned int version, flags0, flags1, transform;
  152953. if (datalen >= APP14_DATA_LEN &&
  152954. GETJOCTET(data[0]) == 0x41 &&
  152955. GETJOCTET(data[1]) == 0x64 &&
  152956. GETJOCTET(data[2]) == 0x6F &&
  152957. GETJOCTET(data[3]) == 0x62 &&
  152958. GETJOCTET(data[4]) == 0x65) {
  152959. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  152960. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  152961. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  152962. transform = GETJOCTET(data[11]);
  152963. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  152964. cinfo->saw_Adobe_marker = TRUE;
  152965. cinfo->Adobe_transform = (UINT8) transform;
  152966. } else {
  152967. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  152968. }
  152969. }
  152970. METHODDEF(boolean)
  152971. get_interesting_appn (j_decompress_ptr cinfo)
  152972. {
  152973. INT32 length;
  152974. JOCTET b[APPN_DATA_LEN];
  152975. unsigned int i, numtoread;
  152976. INPUT_VARS(cinfo);
  152977. INPUT_2BYTES(cinfo, length, return FALSE);
  152978. length -= 2;
  152979. if (length >= APPN_DATA_LEN)
  152980. numtoread = APPN_DATA_LEN;
  152981. else if (length > 0)
  152982. numtoread = (unsigned int) length;
  152983. else
  152984. numtoread = 0;
  152985. for (i = 0; i < numtoread; i++)
  152986. INPUT_BYTE(cinfo, b[i], return FALSE);
  152987. length -= numtoread;
  152988. switch (cinfo->unread_marker) {
  152989. case M_APP0:
  152990. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  152991. break;
  152992. case M_APP14:
  152993. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  152994. break;
  152995. default:
  152996. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  152997. break;
  152998. }
  152999. INPUT_SYNC(cinfo);
  153000. if (length > 0)
  153001. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153002. return TRUE;
  153003. }
  153004. #ifdef SAVE_MARKERS_SUPPORTED
  153005. METHODDEF(boolean)
  153006. save_marker (j_decompress_ptr cinfo)
  153007. {
  153008. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153009. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153010. unsigned int bytes_read, data_length;
  153011. JOCTET FAR * data;
  153012. INT32 length = 0;
  153013. INPUT_VARS(cinfo);
  153014. if (cur_marker == NULL) {
  153015. INPUT_2BYTES(cinfo, length, return FALSE);
  153016. length -= 2;
  153017. if (length >= 0) { /* watch out for bogus length word */
  153018. unsigned int limit;
  153019. if (cinfo->unread_marker == (int) M_COM)
  153020. limit = marker->length_limit_COM;
  153021. else
  153022. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153023. if ((unsigned int) length < limit)
  153024. limit = (unsigned int) length;
  153025. cur_marker = (jpeg_saved_marker_ptr)
  153026. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153027. SIZEOF(struct jpeg_marker_struct) + limit);
  153028. cur_marker->next = NULL;
  153029. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153030. cur_marker->original_length = (unsigned int) length;
  153031. cur_marker->data_length = limit;
  153032. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153033. marker->cur_marker = cur_marker;
  153034. marker->bytes_read = 0;
  153035. bytes_read = 0;
  153036. data_length = limit;
  153037. } else {
  153038. bytes_read = data_length = 0;
  153039. data = NULL;
  153040. }
  153041. } else {
  153042. bytes_read = marker->bytes_read;
  153043. data_length = cur_marker->data_length;
  153044. data = cur_marker->data + bytes_read;
  153045. }
  153046. while (bytes_read < data_length) {
  153047. INPUT_SYNC(cinfo); /* move the restart point to here */
  153048. marker->bytes_read = bytes_read;
  153049. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153050. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153051. *data++ = *next_input_byte++;
  153052. bytes_in_buffer--;
  153053. bytes_read++;
  153054. }
  153055. }
  153056. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153057. if (cinfo->marker_list == NULL) {
  153058. cinfo->marker_list = cur_marker;
  153059. } else {
  153060. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153061. while (prev->next != NULL)
  153062. prev = prev->next;
  153063. prev->next = cur_marker;
  153064. }
  153065. data = cur_marker->data;
  153066. length = cur_marker->original_length - data_length;
  153067. }
  153068. marker->cur_marker = NULL;
  153069. switch (cinfo->unread_marker) {
  153070. case M_APP0:
  153071. examine_app0(cinfo, data, data_length, length);
  153072. break;
  153073. case M_APP14:
  153074. examine_app14(cinfo, data, data_length, length);
  153075. break;
  153076. default:
  153077. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153078. (int) (data_length + length));
  153079. break;
  153080. }
  153081. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153082. if (length > 0)
  153083. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153084. return TRUE;
  153085. }
  153086. #endif /* SAVE_MARKERS_SUPPORTED */
  153087. METHODDEF(boolean)
  153088. skip_variable (j_decompress_ptr cinfo)
  153089. {
  153090. INT32 length;
  153091. INPUT_VARS(cinfo);
  153092. INPUT_2BYTES(cinfo, length, return FALSE);
  153093. length -= 2;
  153094. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153095. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153096. if (length > 0)
  153097. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153098. return TRUE;
  153099. }
  153100. LOCAL(boolean)
  153101. next_marker (j_decompress_ptr cinfo)
  153102. {
  153103. int c;
  153104. INPUT_VARS(cinfo);
  153105. for (;;) {
  153106. INPUT_BYTE(cinfo, c, return FALSE);
  153107. while (c != 0xFF) {
  153108. cinfo->marker->discarded_bytes++;
  153109. INPUT_SYNC(cinfo);
  153110. INPUT_BYTE(cinfo, c, return FALSE);
  153111. }
  153112. do {
  153113. INPUT_BYTE(cinfo, c, return FALSE);
  153114. } while (c == 0xFF);
  153115. if (c != 0)
  153116. break; /* found a valid marker, exit loop */
  153117. cinfo->marker->discarded_bytes += 2;
  153118. INPUT_SYNC(cinfo);
  153119. }
  153120. if (cinfo->marker->discarded_bytes != 0) {
  153121. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153122. cinfo->marker->discarded_bytes = 0;
  153123. }
  153124. cinfo->unread_marker = c;
  153125. INPUT_SYNC(cinfo);
  153126. return TRUE;
  153127. }
  153128. LOCAL(boolean)
  153129. first_marker (j_decompress_ptr cinfo)
  153130. {
  153131. int c, c2;
  153132. INPUT_VARS(cinfo);
  153133. INPUT_BYTE(cinfo, c, return FALSE);
  153134. INPUT_BYTE(cinfo, c2, return FALSE);
  153135. if (c != 0xFF || c2 != (int) M_SOI)
  153136. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153137. cinfo->unread_marker = c2;
  153138. INPUT_SYNC(cinfo);
  153139. return TRUE;
  153140. }
  153141. METHODDEF(int)
  153142. read_markers (j_decompress_ptr cinfo)
  153143. {
  153144. for (;;) {
  153145. if (cinfo->unread_marker == 0) {
  153146. if (! cinfo->marker->saw_SOI) {
  153147. if (! first_marker(cinfo))
  153148. return JPEG_SUSPENDED;
  153149. } else {
  153150. if (! next_marker(cinfo))
  153151. return JPEG_SUSPENDED;
  153152. }
  153153. }
  153154. switch (cinfo->unread_marker) {
  153155. case M_SOI:
  153156. if (! get_soi(cinfo))
  153157. return JPEG_SUSPENDED;
  153158. break;
  153159. case M_SOF0: /* Baseline */
  153160. case M_SOF1: /* Extended sequential, Huffman */
  153161. if (! get_sof(cinfo, FALSE, FALSE))
  153162. return JPEG_SUSPENDED;
  153163. break;
  153164. case M_SOF2: /* Progressive, Huffman */
  153165. if (! get_sof(cinfo, TRUE, FALSE))
  153166. return JPEG_SUSPENDED;
  153167. break;
  153168. case M_SOF9: /* Extended sequential, arithmetic */
  153169. if (! get_sof(cinfo, FALSE, TRUE))
  153170. return JPEG_SUSPENDED;
  153171. break;
  153172. case M_SOF10: /* Progressive, arithmetic */
  153173. if (! get_sof(cinfo, TRUE, TRUE))
  153174. return JPEG_SUSPENDED;
  153175. break;
  153176. case M_SOF3: /* Lossless, Huffman */
  153177. case M_SOF5: /* Differential sequential, Huffman */
  153178. case M_SOF6: /* Differential progressive, Huffman */
  153179. case M_SOF7: /* Differential lossless, Huffman */
  153180. case M_JPG: /* Reserved for JPEG extensions */
  153181. case M_SOF11: /* Lossless, arithmetic */
  153182. case M_SOF13: /* Differential sequential, arithmetic */
  153183. case M_SOF14: /* Differential progressive, arithmetic */
  153184. case M_SOF15: /* Differential lossless, arithmetic */
  153185. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153186. break;
  153187. case M_SOS:
  153188. if (! get_sos(cinfo))
  153189. return JPEG_SUSPENDED;
  153190. cinfo->unread_marker = 0; /* processed the marker */
  153191. return JPEG_REACHED_SOS;
  153192. case M_EOI:
  153193. TRACEMS(cinfo, 1, JTRC_EOI);
  153194. cinfo->unread_marker = 0; /* processed the marker */
  153195. return JPEG_REACHED_EOI;
  153196. case M_DAC:
  153197. if (! get_dac(cinfo))
  153198. return JPEG_SUSPENDED;
  153199. break;
  153200. case M_DHT:
  153201. if (! get_dht(cinfo))
  153202. return JPEG_SUSPENDED;
  153203. break;
  153204. case M_DQT:
  153205. if (! get_dqt(cinfo))
  153206. return JPEG_SUSPENDED;
  153207. break;
  153208. case M_DRI:
  153209. if (! get_dri(cinfo))
  153210. return JPEG_SUSPENDED;
  153211. break;
  153212. case M_APP0:
  153213. case M_APP1:
  153214. case M_APP2:
  153215. case M_APP3:
  153216. case M_APP4:
  153217. case M_APP5:
  153218. case M_APP6:
  153219. case M_APP7:
  153220. case M_APP8:
  153221. case M_APP9:
  153222. case M_APP10:
  153223. case M_APP11:
  153224. case M_APP12:
  153225. case M_APP13:
  153226. case M_APP14:
  153227. case M_APP15:
  153228. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153229. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153230. return JPEG_SUSPENDED;
  153231. break;
  153232. case M_COM:
  153233. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153234. return JPEG_SUSPENDED;
  153235. break;
  153236. case M_RST0: /* these are all parameterless */
  153237. case M_RST1:
  153238. case M_RST2:
  153239. case M_RST3:
  153240. case M_RST4:
  153241. case M_RST5:
  153242. case M_RST6:
  153243. case M_RST7:
  153244. case M_TEM:
  153245. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153246. break;
  153247. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153248. if (! skip_variable(cinfo))
  153249. return JPEG_SUSPENDED;
  153250. break;
  153251. default: /* must be DHP, EXP, JPGn, or RESn */
  153252. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153253. break;
  153254. }
  153255. cinfo->unread_marker = 0;
  153256. } /* end loop */
  153257. }
  153258. METHODDEF(boolean)
  153259. read_restart_marker (j_decompress_ptr cinfo)
  153260. {
  153261. if (cinfo->unread_marker == 0) {
  153262. if (! next_marker(cinfo))
  153263. return FALSE;
  153264. }
  153265. if (cinfo->unread_marker ==
  153266. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153267. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153268. cinfo->unread_marker = 0;
  153269. } else {
  153270. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153271. cinfo->marker->next_restart_num))
  153272. return FALSE;
  153273. }
  153274. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153275. return TRUE;
  153276. }
  153277. GLOBAL(boolean)
  153278. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153279. {
  153280. int marker = cinfo->unread_marker;
  153281. int action = 1;
  153282. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153283. for (;;) {
  153284. if (marker < (int) M_SOF0)
  153285. action = 2; /* invalid marker */
  153286. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153287. action = 3; /* valid non-restart marker */
  153288. else {
  153289. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153290. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153291. action = 3; /* one of the next two expected restarts */
  153292. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153293. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153294. action = 2; /* a prior restart, so advance */
  153295. else
  153296. action = 1; /* desired restart or too far away */
  153297. }
  153298. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153299. switch (action) {
  153300. case 1:
  153301. cinfo->unread_marker = 0;
  153302. return TRUE;
  153303. case 2:
  153304. if (! next_marker(cinfo))
  153305. return FALSE;
  153306. marker = cinfo->unread_marker;
  153307. break;
  153308. case 3:
  153309. return TRUE;
  153310. }
  153311. } /* end loop */
  153312. }
  153313. METHODDEF(void)
  153314. reset_marker_reader (j_decompress_ptr cinfo)
  153315. {
  153316. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153317. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153318. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153319. cinfo->unread_marker = 0; /* no pending marker */
  153320. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153321. marker->pub.saw_SOF = FALSE;
  153322. marker->pub.discarded_bytes = 0;
  153323. marker->cur_marker = NULL;
  153324. }
  153325. GLOBAL(void)
  153326. jinit_marker_reader (j_decompress_ptr cinfo)
  153327. {
  153328. my_marker_ptr2 marker;
  153329. int i;
  153330. marker = (my_marker_ptr2)
  153331. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153332. SIZEOF(my_marker_reader));
  153333. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153334. marker->pub.reset_marker_reader = reset_marker_reader;
  153335. marker->pub.read_markers = read_markers;
  153336. marker->pub.read_restart_marker = read_restart_marker;
  153337. marker->process_COM = skip_variable;
  153338. marker->length_limit_COM = 0;
  153339. for (i = 0; i < 16; i++) {
  153340. marker->process_APPn[i] = skip_variable;
  153341. marker->length_limit_APPn[i] = 0;
  153342. }
  153343. marker->process_APPn[0] = get_interesting_appn;
  153344. marker->process_APPn[14] = get_interesting_appn;
  153345. reset_marker_reader(cinfo);
  153346. }
  153347. #ifdef SAVE_MARKERS_SUPPORTED
  153348. GLOBAL(void)
  153349. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153350. unsigned int length_limit)
  153351. {
  153352. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153353. long maxlength;
  153354. jpeg_marker_parser_method processor;
  153355. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153356. if (((long) length_limit) > maxlength)
  153357. length_limit = (unsigned int) maxlength;
  153358. if (length_limit) {
  153359. processor = save_marker;
  153360. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153361. length_limit = APP0_DATA_LEN;
  153362. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153363. length_limit = APP14_DATA_LEN;
  153364. } else {
  153365. processor = skip_variable;
  153366. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153367. processor = get_interesting_appn;
  153368. }
  153369. if (marker_code == (int) M_COM) {
  153370. marker->process_COM = processor;
  153371. marker->length_limit_COM = length_limit;
  153372. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153373. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153374. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153375. } else
  153376. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153377. }
  153378. #endif /* SAVE_MARKERS_SUPPORTED */
  153379. GLOBAL(void)
  153380. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153381. jpeg_marker_parser_method routine)
  153382. {
  153383. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153384. if (marker_code == (int) M_COM)
  153385. marker->process_COM = routine;
  153386. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153387. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153388. else
  153389. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153390. }
  153391. /*** End of inlined file: jdmarker.c ***/
  153392. /*** Start of inlined file: jdmaster.c ***/
  153393. #define JPEG_INTERNALS
  153394. typedef struct {
  153395. struct jpeg_decomp_master pub; /* public fields */
  153396. int pass_number; /* # of passes completed */
  153397. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153398. struct jpeg_color_quantizer * quantizer_1pass;
  153399. struct jpeg_color_quantizer * quantizer_2pass;
  153400. } my_decomp_master;
  153401. typedef my_decomp_master * my_master_ptr6;
  153402. LOCAL(boolean)
  153403. use_merged_upsample (j_decompress_ptr cinfo)
  153404. {
  153405. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153406. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153407. return FALSE;
  153408. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153409. cinfo->out_color_space != JCS_RGB ||
  153410. cinfo->out_color_components != RGB_PIXELSIZE)
  153411. return FALSE;
  153412. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153413. cinfo->comp_info[1].h_samp_factor != 1 ||
  153414. cinfo->comp_info[2].h_samp_factor != 1 ||
  153415. cinfo->comp_info[0].v_samp_factor > 2 ||
  153416. cinfo->comp_info[1].v_samp_factor != 1 ||
  153417. cinfo->comp_info[2].v_samp_factor != 1)
  153418. return FALSE;
  153419. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153420. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153421. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153422. return FALSE;
  153423. return TRUE; /* by golly, it'll work... */
  153424. #else
  153425. return FALSE;
  153426. #endif
  153427. }
  153428. GLOBAL(void)
  153429. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153430. {
  153431. #ifdef IDCT_SCALING_SUPPORTED
  153432. int ci;
  153433. jpeg_component_info *compptr;
  153434. #endif
  153435. if (cinfo->global_state != DSTATE_READY)
  153436. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153437. #ifdef IDCT_SCALING_SUPPORTED
  153438. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153439. cinfo->output_width = (JDIMENSION)
  153440. jdiv_round_up((long) cinfo->image_width, 8L);
  153441. cinfo->output_height = (JDIMENSION)
  153442. jdiv_round_up((long) cinfo->image_height, 8L);
  153443. cinfo->min_DCT_scaled_size = 1;
  153444. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153445. cinfo->output_width = (JDIMENSION)
  153446. jdiv_round_up((long) cinfo->image_width, 4L);
  153447. cinfo->output_height = (JDIMENSION)
  153448. jdiv_round_up((long) cinfo->image_height, 4L);
  153449. cinfo->min_DCT_scaled_size = 2;
  153450. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153451. cinfo->output_width = (JDIMENSION)
  153452. jdiv_round_up((long) cinfo->image_width, 2L);
  153453. cinfo->output_height = (JDIMENSION)
  153454. jdiv_round_up((long) cinfo->image_height, 2L);
  153455. cinfo->min_DCT_scaled_size = 4;
  153456. } else {
  153457. cinfo->output_width = cinfo->image_width;
  153458. cinfo->output_height = cinfo->image_height;
  153459. cinfo->min_DCT_scaled_size = DCTSIZE;
  153460. }
  153461. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153462. ci++, compptr++) {
  153463. int ssize = cinfo->min_DCT_scaled_size;
  153464. while (ssize < DCTSIZE &&
  153465. (compptr->h_samp_factor * ssize * 2 <=
  153466. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153467. (compptr->v_samp_factor * ssize * 2 <=
  153468. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153469. ssize = ssize * 2;
  153470. }
  153471. compptr->DCT_scaled_size = ssize;
  153472. }
  153473. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153474. ci++, compptr++) {
  153475. compptr->downsampled_width = (JDIMENSION)
  153476. jdiv_round_up((long) cinfo->image_width *
  153477. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153478. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153479. compptr->downsampled_height = (JDIMENSION)
  153480. jdiv_round_up((long) cinfo->image_height *
  153481. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153482. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153483. }
  153484. #else /* !IDCT_SCALING_SUPPORTED */
  153485. cinfo->output_width = cinfo->image_width;
  153486. cinfo->output_height = cinfo->image_height;
  153487. #endif /* IDCT_SCALING_SUPPORTED */
  153488. switch (cinfo->out_color_space) {
  153489. case JCS_GRAYSCALE:
  153490. cinfo->out_color_components = 1;
  153491. break;
  153492. case JCS_RGB:
  153493. #if RGB_PIXELSIZE != 3
  153494. cinfo->out_color_components = RGB_PIXELSIZE;
  153495. break;
  153496. #endif /* else share code with YCbCr */
  153497. case JCS_YCbCr:
  153498. cinfo->out_color_components = 3;
  153499. break;
  153500. case JCS_CMYK:
  153501. case JCS_YCCK:
  153502. cinfo->out_color_components = 4;
  153503. break;
  153504. default: /* else must be same colorspace as in file */
  153505. cinfo->out_color_components = cinfo->num_components;
  153506. break;
  153507. }
  153508. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153509. cinfo->out_color_components);
  153510. if (use_merged_upsample(cinfo))
  153511. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153512. else
  153513. cinfo->rec_outbuf_height = 1;
  153514. }
  153515. LOCAL(void)
  153516. prepare_range_limit_table (j_decompress_ptr cinfo)
  153517. {
  153518. JSAMPLE * table;
  153519. int i;
  153520. table = (JSAMPLE *)
  153521. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153522. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153523. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153524. cinfo->sample_range_limit = table;
  153525. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153526. for (i = 0; i <= MAXJSAMPLE; i++)
  153527. table[i] = (JSAMPLE) i;
  153528. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153529. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153530. table[i] = MAXJSAMPLE;
  153531. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153532. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153533. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153534. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153535. }
  153536. LOCAL(void)
  153537. master_selection (j_decompress_ptr cinfo)
  153538. {
  153539. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153540. boolean use_c_buffer;
  153541. long samplesperrow;
  153542. JDIMENSION jd_samplesperrow;
  153543. jpeg_calc_output_dimensions(cinfo);
  153544. prepare_range_limit_table(cinfo);
  153545. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153546. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153547. if ((long) jd_samplesperrow != samplesperrow)
  153548. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153549. master->pass_number = 0;
  153550. master->using_merged_upsample = use_merged_upsample(cinfo);
  153551. master->quantizer_1pass = NULL;
  153552. master->quantizer_2pass = NULL;
  153553. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153554. cinfo->enable_1pass_quant = FALSE;
  153555. cinfo->enable_external_quant = FALSE;
  153556. cinfo->enable_2pass_quant = FALSE;
  153557. }
  153558. if (cinfo->quantize_colors) {
  153559. if (cinfo->raw_data_out)
  153560. ERREXIT(cinfo, JERR_NOTIMPL);
  153561. if (cinfo->out_color_components != 3) {
  153562. cinfo->enable_1pass_quant = TRUE;
  153563. cinfo->enable_external_quant = FALSE;
  153564. cinfo->enable_2pass_quant = FALSE;
  153565. cinfo->colormap = NULL;
  153566. } else if (cinfo->colormap != NULL) {
  153567. cinfo->enable_external_quant = TRUE;
  153568. } else if (cinfo->two_pass_quantize) {
  153569. cinfo->enable_2pass_quant = TRUE;
  153570. } else {
  153571. cinfo->enable_1pass_quant = TRUE;
  153572. }
  153573. if (cinfo->enable_1pass_quant) {
  153574. #ifdef QUANT_1PASS_SUPPORTED
  153575. jinit_1pass_quantizer(cinfo);
  153576. master->quantizer_1pass = cinfo->cquantize;
  153577. #else
  153578. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153579. #endif
  153580. }
  153581. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153582. #ifdef QUANT_2PASS_SUPPORTED
  153583. jinit_2pass_quantizer(cinfo);
  153584. master->quantizer_2pass = cinfo->cquantize;
  153585. #else
  153586. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153587. #endif
  153588. }
  153589. }
  153590. if (! cinfo->raw_data_out) {
  153591. if (master->using_merged_upsample) {
  153592. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153593. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153594. #else
  153595. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153596. #endif
  153597. } else {
  153598. jinit_color_deconverter(cinfo);
  153599. jinit_upsampler(cinfo);
  153600. }
  153601. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153602. }
  153603. jinit_inverse_dct(cinfo);
  153604. if (cinfo->arith_code) {
  153605. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153606. } else {
  153607. if (cinfo->progressive_mode) {
  153608. #ifdef D_PROGRESSIVE_SUPPORTED
  153609. jinit_phuff_decoder(cinfo);
  153610. #else
  153611. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153612. #endif
  153613. } else
  153614. jinit_huff_decoder(cinfo);
  153615. }
  153616. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153617. jinit_d_coef_controller(cinfo, use_c_buffer);
  153618. if (! cinfo->raw_data_out)
  153619. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153620. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153621. (*cinfo->inputctl->start_input_pass) (cinfo);
  153622. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153623. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153624. cinfo->inputctl->has_multiple_scans) {
  153625. int nscans;
  153626. if (cinfo->progressive_mode) {
  153627. nscans = 2 + 3 * cinfo->num_components;
  153628. } else {
  153629. nscans = cinfo->num_components;
  153630. }
  153631. cinfo->progress->pass_counter = 0L;
  153632. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153633. cinfo->progress->completed_passes = 0;
  153634. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153635. master->pass_number++;
  153636. }
  153637. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153638. }
  153639. METHODDEF(void)
  153640. prepare_for_output_pass (j_decompress_ptr cinfo)
  153641. {
  153642. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153643. if (master->pub.is_dummy_pass) {
  153644. #ifdef QUANT_2PASS_SUPPORTED
  153645. master->pub.is_dummy_pass = FALSE;
  153646. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153647. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153648. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153649. #else
  153650. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153651. #endif /* QUANT_2PASS_SUPPORTED */
  153652. } else {
  153653. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153654. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153655. cinfo->cquantize = master->quantizer_2pass;
  153656. master->pub.is_dummy_pass = TRUE;
  153657. } else if (cinfo->enable_1pass_quant) {
  153658. cinfo->cquantize = master->quantizer_1pass;
  153659. } else {
  153660. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153661. }
  153662. }
  153663. (*cinfo->idct->start_pass) (cinfo);
  153664. (*cinfo->coef->start_output_pass) (cinfo);
  153665. if (! cinfo->raw_data_out) {
  153666. if (! master->using_merged_upsample)
  153667. (*cinfo->cconvert->start_pass) (cinfo);
  153668. (*cinfo->upsample->start_pass) (cinfo);
  153669. if (cinfo->quantize_colors)
  153670. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153671. (*cinfo->post->start_pass) (cinfo,
  153672. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153673. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153674. }
  153675. }
  153676. if (cinfo->progress != NULL) {
  153677. cinfo->progress->completed_passes = master->pass_number;
  153678. cinfo->progress->total_passes = master->pass_number +
  153679. (master->pub.is_dummy_pass ? 2 : 1);
  153680. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153681. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153682. }
  153683. }
  153684. }
  153685. METHODDEF(void)
  153686. finish_output_pass (j_decompress_ptr cinfo)
  153687. {
  153688. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153689. if (cinfo->quantize_colors)
  153690. (*cinfo->cquantize->finish_pass) (cinfo);
  153691. master->pass_number++;
  153692. }
  153693. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153694. GLOBAL(void)
  153695. jpeg_new_colormap (j_decompress_ptr cinfo)
  153696. {
  153697. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153698. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153699. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153700. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153701. cinfo->colormap != NULL) {
  153702. cinfo->cquantize = master->quantizer_2pass;
  153703. (*cinfo->cquantize->new_color_map) (cinfo);
  153704. master->pub.is_dummy_pass = FALSE; /* just in case */
  153705. } else
  153706. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153707. }
  153708. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153709. GLOBAL(void)
  153710. jinit_master_decompress (j_decompress_ptr cinfo)
  153711. {
  153712. my_master_ptr6 master;
  153713. master = (my_master_ptr6)
  153714. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153715. SIZEOF(my_decomp_master));
  153716. cinfo->master = (struct jpeg_decomp_master *) master;
  153717. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153718. master->pub.finish_output_pass = finish_output_pass;
  153719. master->pub.is_dummy_pass = FALSE;
  153720. master_selection(cinfo);
  153721. }
  153722. /*** End of inlined file: jdmaster.c ***/
  153723. #undef FIX
  153724. /*** Start of inlined file: jdmerge.c ***/
  153725. #define JPEG_INTERNALS
  153726. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153727. typedef struct {
  153728. struct jpeg_upsampler pub; /* public fields */
  153729. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153730. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153731. JSAMPARRAY output_buf));
  153732. int * Cr_r_tab; /* => table for Cr to R conversion */
  153733. int * Cb_b_tab; /* => table for Cb to B conversion */
  153734. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153735. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153736. JSAMPROW spare_row;
  153737. boolean spare_full; /* T if spare buffer is occupied */
  153738. JDIMENSION out_row_width; /* samples per output row */
  153739. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153740. } my_upsampler;
  153741. typedef my_upsampler * my_upsample_ptr;
  153742. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153743. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153744. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153745. LOCAL(void)
  153746. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153747. {
  153748. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153749. int i;
  153750. INT32 x;
  153751. SHIFT_TEMPS
  153752. upsample->Cr_r_tab = (int *)
  153753. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153754. (MAXJSAMPLE+1) * SIZEOF(int));
  153755. upsample->Cb_b_tab = (int *)
  153756. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153757. (MAXJSAMPLE+1) * SIZEOF(int));
  153758. upsample->Cr_g_tab = (INT32 *)
  153759. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153760. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153761. upsample->Cb_g_tab = (INT32 *)
  153762. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153763. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153764. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153765. upsample->Cr_r_tab[i] = (int)
  153766. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153767. upsample->Cb_b_tab[i] = (int)
  153768. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153769. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153770. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153771. }
  153772. }
  153773. METHODDEF(void)
  153774. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153775. {
  153776. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153777. upsample->spare_full = FALSE;
  153778. upsample->rows_to_go = cinfo->output_height;
  153779. }
  153780. METHODDEF(void)
  153781. merged_2v_upsample (j_decompress_ptr cinfo,
  153782. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153783. JDIMENSION in_row_groups_avail,
  153784. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153785. JDIMENSION out_rows_avail)
  153786. {
  153787. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153788. JSAMPROW work_ptrs[2];
  153789. JDIMENSION num_rows; /* number of rows returned to caller */
  153790. if (upsample->spare_full) {
  153791. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153792. 1, upsample->out_row_width);
  153793. num_rows = 1;
  153794. upsample->spare_full = FALSE;
  153795. } else {
  153796. num_rows = 2;
  153797. if (num_rows > upsample->rows_to_go)
  153798. num_rows = upsample->rows_to_go;
  153799. out_rows_avail -= *out_row_ctr;
  153800. if (num_rows > out_rows_avail)
  153801. num_rows = out_rows_avail;
  153802. work_ptrs[0] = output_buf[*out_row_ctr];
  153803. if (num_rows > 1) {
  153804. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153805. } else {
  153806. work_ptrs[1] = upsample->spare_row;
  153807. upsample->spare_full = TRUE;
  153808. }
  153809. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153810. }
  153811. *out_row_ctr += num_rows;
  153812. upsample->rows_to_go -= num_rows;
  153813. if (! upsample->spare_full)
  153814. (*in_row_group_ctr)++;
  153815. }
  153816. METHODDEF(void)
  153817. merged_1v_upsample (j_decompress_ptr cinfo,
  153818. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153819. JDIMENSION in_row_groups_avail,
  153820. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153821. JDIMENSION out_rows_avail)
  153822. {
  153823. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153824. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153825. output_buf + *out_row_ctr);
  153826. (*out_row_ctr)++;
  153827. (*in_row_group_ctr)++;
  153828. }
  153829. METHODDEF(void)
  153830. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153831. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153832. JSAMPARRAY output_buf)
  153833. {
  153834. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153835. register int y, cred, cgreen, cblue;
  153836. int cb, cr;
  153837. register JSAMPROW outptr;
  153838. JSAMPROW inptr0, inptr1, inptr2;
  153839. JDIMENSION col;
  153840. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153841. int * Crrtab = upsample->Cr_r_tab;
  153842. int * Cbbtab = upsample->Cb_b_tab;
  153843. INT32 * Crgtab = upsample->Cr_g_tab;
  153844. INT32 * Cbgtab = upsample->Cb_g_tab;
  153845. SHIFT_TEMPS
  153846. inptr0 = input_buf[0][in_row_group_ctr];
  153847. inptr1 = input_buf[1][in_row_group_ctr];
  153848. inptr2 = input_buf[2][in_row_group_ctr];
  153849. outptr = output_buf[0];
  153850. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153851. cb = GETJSAMPLE(*inptr1++);
  153852. cr = GETJSAMPLE(*inptr2++);
  153853. cred = Crrtab[cr];
  153854. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153855. cblue = Cbbtab[cb];
  153856. y = GETJSAMPLE(*inptr0++);
  153857. outptr[RGB_RED] = range_limit[y + cred];
  153858. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153859. outptr[RGB_BLUE] = range_limit[y + cblue];
  153860. outptr += RGB_PIXELSIZE;
  153861. y = GETJSAMPLE(*inptr0++);
  153862. outptr[RGB_RED] = range_limit[y + cred];
  153863. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153864. outptr[RGB_BLUE] = range_limit[y + cblue];
  153865. outptr += RGB_PIXELSIZE;
  153866. }
  153867. if (cinfo->output_width & 1) {
  153868. cb = GETJSAMPLE(*inptr1);
  153869. cr = GETJSAMPLE(*inptr2);
  153870. cred = Crrtab[cr];
  153871. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153872. cblue = Cbbtab[cb];
  153873. y = GETJSAMPLE(*inptr0);
  153874. outptr[RGB_RED] = range_limit[y + cred];
  153875. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153876. outptr[RGB_BLUE] = range_limit[y + cblue];
  153877. }
  153878. }
  153879. METHODDEF(void)
  153880. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153881. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153882. JSAMPARRAY output_buf)
  153883. {
  153884. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153885. register int y, cred, cgreen, cblue;
  153886. int cb, cr;
  153887. register JSAMPROW outptr0, outptr1;
  153888. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153889. JDIMENSION col;
  153890. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153891. int * Crrtab = upsample->Cr_r_tab;
  153892. int * Cbbtab = upsample->Cb_b_tab;
  153893. INT32 * Crgtab = upsample->Cr_g_tab;
  153894. INT32 * Cbgtab = upsample->Cb_g_tab;
  153895. SHIFT_TEMPS
  153896. inptr00 = input_buf[0][in_row_group_ctr*2];
  153897. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153898. inptr1 = input_buf[1][in_row_group_ctr];
  153899. inptr2 = input_buf[2][in_row_group_ctr];
  153900. outptr0 = output_buf[0];
  153901. outptr1 = output_buf[1];
  153902. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153903. cb = GETJSAMPLE(*inptr1++);
  153904. cr = GETJSAMPLE(*inptr2++);
  153905. cred = Crrtab[cr];
  153906. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153907. cblue = Cbbtab[cb];
  153908. y = GETJSAMPLE(*inptr00++);
  153909. outptr0[RGB_RED] = range_limit[y + cred];
  153910. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153911. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153912. outptr0 += RGB_PIXELSIZE;
  153913. y = GETJSAMPLE(*inptr00++);
  153914. outptr0[RGB_RED] = range_limit[y + cred];
  153915. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153916. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153917. outptr0 += RGB_PIXELSIZE;
  153918. y = GETJSAMPLE(*inptr01++);
  153919. outptr1[RGB_RED] = range_limit[y + cred];
  153920. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153921. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153922. outptr1 += RGB_PIXELSIZE;
  153923. y = GETJSAMPLE(*inptr01++);
  153924. outptr1[RGB_RED] = range_limit[y + cred];
  153925. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153926. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153927. outptr1 += RGB_PIXELSIZE;
  153928. }
  153929. if (cinfo->output_width & 1) {
  153930. cb = GETJSAMPLE(*inptr1);
  153931. cr = GETJSAMPLE(*inptr2);
  153932. cred = Crrtab[cr];
  153933. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153934. cblue = Cbbtab[cb];
  153935. y = GETJSAMPLE(*inptr00);
  153936. outptr0[RGB_RED] = range_limit[y + cred];
  153937. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153938. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153939. y = GETJSAMPLE(*inptr01);
  153940. outptr1[RGB_RED] = range_limit[y + cred];
  153941. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153942. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153943. }
  153944. }
  153945. GLOBAL(void)
  153946. jinit_merged_upsampler (j_decompress_ptr cinfo)
  153947. {
  153948. my_upsample_ptr upsample;
  153949. upsample = (my_upsample_ptr)
  153950. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153951. SIZEOF(my_upsampler));
  153952. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  153953. upsample->pub.start_pass = start_pass_merged_upsample;
  153954. upsample->pub.need_context_rows = FALSE;
  153955. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  153956. if (cinfo->max_v_samp_factor == 2) {
  153957. upsample->pub.upsample = merged_2v_upsample;
  153958. upsample->upmethod = h2v2_merged_upsample;
  153959. upsample->spare_row = (JSAMPROW)
  153960. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153961. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  153962. } else {
  153963. upsample->pub.upsample = merged_1v_upsample;
  153964. upsample->upmethod = h2v1_merged_upsample;
  153965. upsample->spare_row = NULL;
  153966. }
  153967. build_ycc_rgb_table2(cinfo);
  153968. }
  153969. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  153970. /*** End of inlined file: jdmerge.c ***/
  153971. #undef ASSIGN_STATE
  153972. /*** Start of inlined file: jdphuff.c ***/
  153973. #define JPEG_INTERNALS
  153974. #ifdef D_PROGRESSIVE_SUPPORTED
  153975. typedef struct {
  153976. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  153977. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  153978. } savable_state3;
  153979. #ifndef NO_STRUCT_ASSIGN
  153980. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  153981. #else
  153982. #if MAX_COMPS_IN_SCAN == 4
  153983. #define ASSIGN_STATE(dest,src) \
  153984. ((dest).EOBRUN = (src).EOBRUN, \
  153985. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  153986. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  153987. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  153988. (dest).last_dc_val[3] = (src).last_dc_val[3])
  153989. #endif
  153990. #endif
  153991. typedef struct {
  153992. struct jpeg_entropy_decoder pub; /* public fields */
  153993. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  153994. savable_state3 saved; /* Other state at start of MCU */
  153995. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  153996. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  153997. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  153998. } phuff_entropy_decoder;
  153999. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154000. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154001. JBLOCKROW *MCU_data));
  154002. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154003. JBLOCKROW *MCU_data));
  154004. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154005. JBLOCKROW *MCU_data));
  154006. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154007. JBLOCKROW *MCU_data));
  154008. METHODDEF(void)
  154009. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154010. {
  154011. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154012. boolean is_DC_band, bad;
  154013. int ci, coefi, tbl;
  154014. int *coef_bit_ptr;
  154015. jpeg_component_info * compptr;
  154016. is_DC_band = (cinfo->Ss == 0);
  154017. bad = FALSE;
  154018. if (is_DC_band) {
  154019. if (cinfo->Se != 0)
  154020. bad = TRUE;
  154021. } else {
  154022. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154023. bad = TRUE;
  154024. if (cinfo->comps_in_scan != 1)
  154025. bad = TRUE;
  154026. }
  154027. if (cinfo->Ah != 0) {
  154028. if (cinfo->Al != cinfo->Ah-1)
  154029. bad = TRUE;
  154030. }
  154031. if (cinfo->Al > 13) /* need not check for < 0 */
  154032. bad = TRUE;
  154033. if (bad)
  154034. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154035. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154036. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154037. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154038. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154039. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154040. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154041. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154042. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154043. if (cinfo->Ah != expected)
  154044. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154045. coef_bit_ptr[coefi] = cinfo->Al;
  154046. }
  154047. }
  154048. if (cinfo->Ah == 0) {
  154049. if (is_DC_band)
  154050. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154051. else
  154052. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154053. } else {
  154054. if (is_DC_band)
  154055. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154056. else
  154057. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154058. }
  154059. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154060. compptr = cinfo->cur_comp_info[ci];
  154061. if (is_DC_band) {
  154062. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154063. tbl = compptr->dc_tbl_no;
  154064. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154065. & entropy->derived_tbls[tbl]);
  154066. }
  154067. } else {
  154068. tbl = compptr->ac_tbl_no;
  154069. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154070. & entropy->derived_tbls[tbl]);
  154071. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154072. }
  154073. entropy->saved.last_dc_val[ci] = 0;
  154074. }
  154075. entropy->bitstate.bits_left = 0;
  154076. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154077. entropy->pub.insufficient_data = FALSE;
  154078. entropy->saved.EOBRUN = 0;
  154079. entropy->restarts_to_go = cinfo->restart_interval;
  154080. }
  154081. LOCAL(boolean)
  154082. process_restartp (j_decompress_ptr cinfo)
  154083. {
  154084. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154085. int ci;
  154086. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154087. entropy->bitstate.bits_left = 0;
  154088. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154089. return FALSE;
  154090. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154091. entropy->saved.last_dc_val[ci] = 0;
  154092. entropy->saved.EOBRUN = 0;
  154093. entropy->restarts_to_go = cinfo->restart_interval;
  154094. if (cinfo->unread_marker == 0)
  154095. entropy->pub.insufficient_data = FALSE;
  154096. return TRUE;
  154097. }
  154098. METHODDEF(boolean)
  154099. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154100. {
  154101. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154102. int Al = cinfo->Al;
  154103. register int s, r;
  154104. int blkn, ci;
  154105. JBLOCKROW block;
  154106. BITREAD_STATE_VARS;
  154107. savable_state3 state;
  154108. d_derived_tbl * tbl;
  154109. jpeg_component_info * compptr;
  154110. if (cinfo->restart_interval) {
  154111. if (entropy->restarts_to_go == 0)
  154112. if (! process_restartp(cinfo))
  154113. return FALSE;
  154114. }
  154115. if (! entropy->pub.insufficient_data) {
  154116. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154117. ASSIGN_STATE(state, entropy->saved);
  154118. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154119. block = MCU_data[blkn];
  154120. ci = cinfo->MCU_membership[blkn];
  154121. compptr = cinfo->cur_comp_info[ci];
  154122. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154123. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154124. if (s) {
  154125. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154126. r = GET_BITS(s);
  154127. s = HUFF_EXTEND(r, s);
  154128. }
  154129. s += state.last_dc_val[ci];
  154130. state.last_dc_val[ci] = s;
  154131. (*block)[0] = (JCOEF) (s << Al);
  154132. }
  154133. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154134. ASSIGN_STATE(entropy->saved, state);
  154135. }
  154136. entropy->restarts_to_go--;
  154137. return TRUE;
  154138. }
  154139. METHODDEF(boolean)
  154140. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154141. {
  154142. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154143. int Se = cinfo->Se;
  154144. int Al = cinfo->Al;
  154145. register int s, k, r;
  154146. unsigned int EOBRUN;
  154147. JBLOCKROW block;
  154148. BITREAD_STATE_VARS;
  154149. d_derived_tbl * tbl;
  154150. if (cinfo->restart_interval) {
  154151. if (entropy->restarts_to_go == 0)
  154152. if (! process_restartp(cinfo))
  154153. return FALSE;
  154154. }
  154155. if (! entropy->pub.insufficient_data) {
  154156. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154157. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154158. EOBRUN--; /* ...process it now (we do nothing) */
  154159. else {
  154160. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154161. block = MCU_data[0];
  154162. tbl = entropy->ac_derived_tbl;
  154163. for (k = cinfo->Ss; k <= Se; k++) {
  154164. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154165. r = s >> 4;
  154166. s &= 15;
  154167. if (s) {
  154168. k += r;
  154169. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154170. r = GET_BITS(s);
  154171. s = HUFF_EXTEND(r, s);
  154172. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154173. } else {
  154174. if (r == 15) { /* ZRL */
  154175. k += 15; /* skip 15 zeroes in band */
  154176. } else { /* EOBr, run length is 2^r + appended bits */
  154177. EOBRUN = 1 << r;
  154178. if (r) { /* EOBr, r > 0 */
  154179. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154180. r = GET_BITS(r);
  154181. EOBRUN += r;
  154182. }
  154183. EOBRUN--; /* this band is processed at this moment */
  154184. break; /* force end-of-band */
  154185. }
  154186. }
  154187. }
  154188. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154189. }
  154190. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154191. }
  154192. entropy->restarts_to_go--;
  154193. return TRUE;
  154194. }
  154195. METHODDEF(boolean)
  154196. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154197. {
  154198. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154199. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154200. int blkn;
  154201. JBLOCKROW block;
  154202. BITREAD_STATE_VARS;
  154203. if (cinfo->restart_interval) {
  154204. if (entropy->restarts_to_go == 0)
  154205. if (! process_restartp(cinfo))
  154206. return FALSE;
  154207. }
  154208. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154209. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154210. block = MCU_data[blkn];
  154211. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154212. if (GET_BITS(1))
  154213. (*block)[0] |= p1;
  154214. }
  154215. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154216. entropy->restarts_to_go--;
  154217. return TRUE;
  154218. }
  154219. METHODDEF(boolean)
  154220. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154221. {
  154222. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154223. int Se = cinfo->Se;
  154224. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154225. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154226. register int s, k, r;
  154227. unsigned int EOBRUN;
  154228. JBLOCKROW block;
  154229. JCOEFPTR thiscoef;
  154230. BITREAD_STATE_VARS;
  154231. d_derived_tbl * tbl;
  154232. int num_newnz;
  154233. int newnz_pos[DCTSIZE2];
  154234. if (cinfo->restart_interval) {
  154235. if (entropy->restarts_to_go == 0)
  154236. if (! process_restartp(cinfo))
  154237. return FALSE;
  154238. }
  154239. if (! entropy->pub.insufficient_data) {
  154240. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154241. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154242. block = MCU_data[0];
  154243. tbl = entropy->ac_derived_tbl;
  154244. num_newnz = 0;
  154245. k = cinfo->Ss;
  154246. if (EOBRUN == 0) {
  154247. for (; k <= Se; k++) {
  154248. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154249. r = s >> 4;
  154250. s &= 15;
  154251. if (s) {
  154252. if (s != 1) /* size of new coef should always be 1 */
  154253. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154254. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154255. if (GET_BITS(1))
  154256. s = p1; /* newly nonzero coef is positive */
  154257. else
  154258. s = m1; /* newly nonzero coef is negative */
  154259. } else {
  154260. if (r != 15) {
  154261. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154262. if (r) {
  154263. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154264. r = GET_BITS(r);
  154265. EOBRUN += r;
  154266. }
  154267. break; /* rest of block is handled by EOB logic */
  154268. }
  154269. }
  154270. do {
  154271. thiscoef = *block + jpeg_natural_order[k];
  154272. if (*thiscoef != 0) {
  154273. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154274. if (GET_BITS(1)) {
  154275. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154276. if (*thiscoef >= 0)
  154277. *thiscoef += p1;
  154278. else
  154279. *thiscoef += m1;
  154280. }
  154281. }
  154282. } else {
  154283. if (--r < 0)
  154284. break; /* reached target zero coefficient */
  154285. }
  154286. k++;
  154287. } while (k <= Se);
  154288. if (s) {
  154289. int pos = jpeg_natural_order[k];
  154290. (*block)[pos] = (JCOEF) s;
  154291. newnz_pos[num_newnz++] = pos;
  154292. }
  154293. }
  154294. }
  154295. if (EOBRUN > 0) {
  154296. for (; k <= Se; k++) {
  154297. thiscoef = *block + jpeg_natural_order[k];
  154298. if (*thiscoef != 0) {
  154299. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154300. if (GET_BITS(1)) {
  154301. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154302. if (*thiscoef >= 0)
  154303. *thiscoef += p1;
  154304. else
  154305. *thiscoef += m1;
  154306. }
  154307. }
  154308. }
  154309. }
  154310. EOBRUN--;
  154311. }
  154312. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154313. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154314. }
  154315. entropy->restarts_to_go--;
  154316. return TRUE;
  154317. undoit:
  154318. while (num_newnz > 0)
  154319. (*block)[newnz_pos[--num_newnz]] = 0;
  154320. return FALSE;
  154321. }
  154322. GLOBAL(void)
  154323. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154324. {
  154325. phuff_entropy_ptr2 entropy;
  154326. int *coef_bit_ptr;
  154327. int ci, i;
  154328. entropy = (phuff_entropy_ptr2)
  154329. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154330. SIZEOF(phuff_entropy_decoder));
  154331. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154332. entropy->pub.start_pass = start_pass_phuff_decoder;
  154333. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154334. entropy->derived_tbls[i] = NULL;
  154335. }
  154336. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154337. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154338. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154339. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154340. for (ci = 0; ci < cinfo->num_components; ci++)
  154341. for (i = 0; i < DCTSIZE2; i++)
  154342. *coef_bit_ptr++ = -1;
  154343. }
  154344. #endif /* D_PROGRESSIVE_SUPPORTED */
  154345. /*** End of inlined file: jdphuff.c ***/
  154346. /*** Start of inlined file: jdpostct.c ***/
  154347. #define JPEG_INTERNALS
  154348. typedef struct {
  154349. struct jpeg_d_post_controller pub; /* public fields */
  154350. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154351. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154352. JDIMENSION strip_height; /* buffer size in rows */
  154353. JDIMENSION starting_row; /* row # of first row in current strip */
  154354. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154355. } my_post_controller;
  154356. typedef my_post_controller * my_post_ptr;
  154357. METHODDEF(void) post_process_1pass
  154358. JPP((j_decompress_ptr cinfo,
  154359. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154360. JDIMENSION in_row_groups_avail,
  154361. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154362. JDIMENSION out_rows_avail));
  154363. #ifdef QUANT_2PASS_SUPPORTED
  154364. METHODDEF(void) post_process_prepass
  154365. JPP((j_decompress_ptr cinfo,
  154366. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154367. JDIMENSION in_row_groups_avail,
  154368. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154369. JDIMENSION out_rows_avail));
  154370. METHODDEF(void) post_process_2pass
  154371. JPP((j_decompress_ptr cinfo,
  154372. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154373. JDIMENSION in_row_groups_avail,
  154374. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154375. JDIMENSION out_rows_avail));
  154376. #endif
  154377. METHODDEF(void)
  154378. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154379. {
  154380. my_post_ptr post = (my_post_ptr) cinfo->post;
  154381. switch (pass_mode) {
  154382. case JBUF_PASS_THRU:
  154383. if (cinfo->quantize_colors) {
  154384. post->pub.post_process_data = post_process_1pass;
  154385. if (post->buffer == NULL) {
  154386. post->buffer = (*cinfo->mem->access_virt_sarray)
  154387. ((j_common_ptr) cinfo, post->whole_image,
  154388. (JDIMENSION) 0, post->strip_height, TRUE);
  154389. }
  154390. } else {
  154391. post->pub.post_process_data = cinfo->upsample->upsample;
  154392. }
  154393. break;
  154394. #ifdef QUANT_2PASS_SUPPORTED
  154395. case JBUF_SAVE_AND_PASS:
  154396. if (post->whole_image == NULL)
  154397. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154398. post->pub.post_process_data = post_process_prepass;
  154399. break;
  154400. case JBUF_CRANK_DEST:
  154401. if (post->whole_image == NULL)
  154402. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154403. post->pub.post_process_data = post_process_2pass;
  154404. break;
  154405. #endif /* QUANT_2PASS_SUPPORTED */
  154406. default:
  154407. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154408. break;
  154409. }
  154410. post->starting_row = post->next_row = 0;
  154411. }
  154412. METHODDEF(void)
  154413. post_process_1pass (j_decompress_ptr cinfo,
  154414. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154415. JDIMENSION in_row_groups_avail,
  154416. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154417. JDIMENSION out_rows_avail)
  154418. {
  154419. my_post_ptr post = (my_post_ptr) cinfo->post;
  154420. JDIMENSION num_rows, max_rows;
  154421. max_rows = out_rows_avail - *out_row_ctr;
  154422. if (max_rows > post->strip_height)
  154423. max_rows = post->strip_height;
  154424. num_rows = 0;
  154425. (*cinfo->upsample->upsample) (cinfo,
  154426. input_buf, in_row_group_ctr, in_row_groups_avail,
  154427. post->buffer, &num_rows, max_rows);
  154428. (*cinfo->cquantize->color_quantize) (cinfo,
  154429. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154430. *out_row_ctr += num_rows;
  154431. }
  154432. #ifdef QUANT_2PASS_SUPPORTED
  154433. METHODDEF(void)
  154434. post_process_prepass (j_decompress_ptr cinfo,
  154435. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154436. JDIMENSION in_row_groups_avail,
  154437. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154438. JDIMENSION out_rows_avail)
  154439. {
  154440. my_post_ptr post = (my_post_ptr) cinfo->post;
  154441. JDIMENSION old_next_row, num_rows;
  154442. if (post->next_row == 0) {
  154443. post->buffer = (*cinfo->mem->access_virt_sarray)
  154444. ((j_common_ptr) cinfo, post->whole_image,
  154445. post->starting_row, post->strip_height, TRUE);
  154446. }
  154447. old_next_row = post->next_row;
  154448. (*cinfo->upsample->upsample) (cinfo,
  154449. input_buf, in_row_group_ctr, in_row_groups_avail,
  154450. post->buffer, &post->next_row, post->strip_height);
  154451. if (post->next_row > old_next_row) {
  154452. num_rows = post->next_row - old_next_row;
  154453. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154454. (JSAMPARRAY) NULL, (int) num_rows);
  154455. *out_row_ctr += num_rows;
  154456. }
  154457. if (post->next_row >= post->strip_height) {
  154458. post->starting_row += post->strip_height;
  154459. post->next_row = 0;
  154460. }
  154461. }
  154462. METHODDEF(void)
  154463. post_process_2pass (j_decompress_ptr cinfo,
  154464. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154465. JDIMENSION in_row_groups_avail,
  154466. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154467. JDIMENSION out_rows_avail)
  154468. {
  154469. my_post_ptr post = (my_post_ptr) cinfo->post;
  154470. JDIMENSION num_rows, max_rows;
  154471. if (post->next_row == 0) {
  154472. post->buffer = (*cinfo->mem->access_virt_sarray)
  154473. ((j_common_ptr) cinfo, post->whole_image,
  154474. post->starting_row, post->strip_height, FALSE);
  154475. }
  154476. num_rows = post->strip_height - post->next_row; /* available in strip */
  154477. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154478. if (num_rows > max_rows)
  154479. num_rows = max_rows;
  154480. max_rows = cinfo->output_height - post->starting_row;
  154481. if (num_rows > max_rows)
  154482. num_rows = max_rows;
  154483. (*cinfo->cquantize->color_quantize) (cinfo,
  154484. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154485. (int) num_rows);
  154486. *out_row_ctr += num_rows;
  154487. post->next_row += num_rows;
  154488. if (post->next_row >= post->strip_height) {
  154489. post->starting_row += post->strip_height;
  154490. post->next_row = 0;
  154491. }
  154492. }
  154493. #endif /* QUANT_2PASS_SUPPORTED */
  154494. GLOBAL(void)
  154495. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154496. {
  154497. my_post_ptr post;
  154498. post = (my_post_ptr)
  154499. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154500. SIZEOF(my_post_controller));
  154501. cinfo->post = (struct jpeg_d_post_controller *) post;
  154502. post->pub.start_pass = start_pass_dpost;
  154503. post->whole_image = NULL; /* flag for no virtual arrays */
  154504. post->buffer = NULL; /* flag for no strip buffer */
  154505. if (cinfo->quantize_colors) {
  154506. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154507. if (need_full_buffer) {
  154508. #ifdef QUANT_2PASS_SUPPORTED
  154509. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154510. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154511. cinfo->output_width * cinfo->out_color_components,
  154512. (JDIMENSION) jround_up((long) cinfo->output_height,
  154513. (long) post->strip_height),
  154514. post->strip_height);
  154515. #else
  154516. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154517. #endif /* QUANT_2PASS_SUPPORTED */
  154518. } else {
  154519. post->buffer = (*cinfo->mem->alloc_sarray)
  154520. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154521. cinfo->output_width * cinfo->out_color_components,
  154522. post->strip_height);
  154523. }
  154524. }
  154525. }
  154526. /*** End of inlined file: jdpostct.c ***/
  154527. #undef FIX
  154528. /*** Start of inlined file: jdsample.c ***/
  154529. #define JPEG_INTERNALS
  154530. typedef JMETHOD(void, upsample1_ptr,
  154531. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154532. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154533. typedef struct {
  154534. struct jpeg_upsampler pub; /* public fields */
  154535. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154536. upsample1_ptr methods[MAX_COMPONENTS];
  154537. int next_row_out; /* counts rows emitted from color_buf */
  154538. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154539. int rowgroup_height[MAX_COMPONENTS];
  154540. UINT8 h_expand[MAX_COMPONENTS];
  154541. UINT8 v_expand[MAX_COMPONENTS];
  154542. } my_upsampler2;
  154543. typedef my_upsampler2 * my_upsample_ptr2;
  154544. METHODDEF(void)
  154545. start_pass_upsample (j_decompress_ptr cinfo)
  154546. {
  154547. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154548. upsample->next_row_out = cinfo->max_v_samp_factor;
  154549. upsample->rows_to_go = cinfo->output_height;
  154550. }
  154551. METHODDEF(void)
  154552. sep_upsample (j_decompress_ptr cinfo,
  154553. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154554. JDIMENSION in_row_groups_avail,
  154555. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154556. JDIMENSION out_rows_avail)
  154557. {
  154558. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154559. int ci;
  154560. jpeg_component_info * compptr;
  154561. JDIMENSION num_rows;
  154562. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154563. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154564. ci++, compptr++) {
  154565. (*upsample->methods[ci]) (cinfo, compptr,
  154566. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154567. upsample->color_buf + ci);
  154568. }
  154569. upsample->next_row_out = 0;
  154570. }
  154571. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154572. if (num_rows > upsample->rows_to_go)
  154573. num_rows = upsample->rows_to_go;
  154574. out_rows_avail -= *out_row_ctr;
  154575. if (num_rows > out_rows_avail)
  154576. num_rows = out_rows_avail;
  154577. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154578. (JDIMENSION) upsample->next_row_out,
  154579. output_buf + *out_row_ctr,
  154580. (int) num_rows);
  154581. *out_row_ctr += num_rows;
  154582. upsample->rows_to_go -= num_rows;
  154583. upsample->next_row_out += num_rows;
  154584. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154585. (*in_row_group_ctr)++;
  154586. }
  154587. METHODDEF(void)
  154588. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154589. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154590. {
  154591. *output_data_ptr = input_data;
  154592. }
  154593. METHODDEF(void)
  154594. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154595. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154596. {
  154597. *output_data_ptr = NULL; /* safety check */
  154598. }
  154599. METHODDEF(void)
  154600. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154601. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154602. {
  154603. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154604. JSAMPARRAY output_data = *output_data_ptr;
  154605. register JSAMPROW inptr, outptr;
  154606. register JSAMPLE invalue;
  154607. register int h;
  154608. JSAMPROW outend;
  154609. int h_expand, v_expand;
  154610. int inrow, outrow;
  154611. h_expand = upsample->h_expand[compptr->component_index];
  154612. v_expand = upsample->v_expand[compptr->component_index];
  154613. inrow = outrow = 0;
  154614. while (outrow < cinfo->max_v_samp_factor) {
  154615. inptr = input_data[inrow];
  154616. outptr = output_data[outrow];
  154617. outend = outptr + cinfo->output_width;
  154618. while (outptr < outend) {
  154619. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154620. for (h = h_expand; h > 0; h--) {
  154621. *outptr++ = invalue;
  154622. }
  154623. }
  154624. if (v_expand > 1) {
  154625. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154626. v_expand-1, cinfo->output_width);
  154627. }
  154628. inrow++;
  154629. outrow += v_expand;
  154630. }
  154631. }
  154632. METHODDEF(void)
  154633. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154634. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154635. {
  154636. JSAMPARRAY output_data = *output_data_ptr;
  154637. register JSAMPROW inptr, outptr;
  154638. register JSAMPLE invalue;
  154639. JSAMPROW outend;
  154640. int inrow;
  154641. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154642. inptr = input_data[inrow];
  154643. outptr = output_data[inrow];
  154644. outend = outptr + cinfo->output_width;
  154645. while (outptr < outend) {
  154646. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154647. *outptr++ = invalue;
  154648. *outptr++ = invalue;
  154649. }
  154650. }
  154651. }
  154652. METHODDEF(void)
  154653. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154654. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154655. {
  154656. JSAMPARRAY output_data = *output_data_ptr;
  154657. register JSAMPROW inptr, outptr;
  154658. register JSAMPLE invalue;
  154659. JSAMPROW outend;
  154660. int inrow, outrow;
  154661. inrow = outrow = 0;
  154662. while (outrow < cinfo->max_v_samp_factor) {
  154663. inptr = input_data[inrow];
  154664. outptr = output_data[outrow];
  154665. outend = outptr + cinfo->output_width;
  154666. while (outptr < outend) {
  154667. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154668. *outptr++ = invalue;
  154669. *outptr++ = invalue;
  154670. }
  154671. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154672. 1, cinfo->output_width);
  154673. inrow++;
  154674. outrow += 2;
  154675. }
  154676. }
  154677. METHODDEF(void)
  154678. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154679. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154680. {
  154681. JSAMPARRAY output_data = *output_data_ptr;
  154682. register JSAMPROW inptr, outptr;
  154683. register int invalue;
  154684. register JDIMENSION colctr;
  154685. int inrow;
  154686. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154687. inptr = input_data[inrow];
  154688. outptr = output_data[inrow];
  154689. invalue = GETJSAMPLE(*inptr++);
  154690. *outptr++ = (JSAMPLE) invalue;
  154691. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154692. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154693. invalue = GETJSAMPLE(*inptr++) * 3;
  154694. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154695. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154696. }
  154697. invalue = GETJSAMPLE(*inptr);
  154698. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154699. *outptr++ = (JSAMPLE) invalue;
  154700. }
  154701. }
  154702. METHODDEF(void)
  154703. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154704. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154705. {
  154706. JSAMPARRAY output_data = *output_data_ptr;
  154707. register JSAMPROW inptr0, inptr1, outptr;
  154708. #if BITS_IN_JSAMPLE == 8
  154709. register int thiscolsum, lastcolsum, nextcolsum;
  154710. #else
  154711. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154712. #endif
  154713. register JDIMENSION colctr;
  154714. int inrow, outrow, v;
  154715. inrow = outrow = 0;
  154716. while (outrow < cinfo->max_v_samp_factor) {
  154717. for (v = 0; v < 2; v++) {
  154718. inptr0 = input_data[inrow];
  154719. if (v == 0) /* next nearest is row above */
  154720. inptr1 = input_data[inrow-1];
  154721. else /* next nearest is row below */
  154722. inptr1 = input_data[inrow+1];
  154723. outptr = output_data[outrow++];
  154724. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154725. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154726. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154727. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154728. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154729. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154730. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154731. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154732. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154733. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154734. }
  154735. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154736. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154737. }
  154738. inrow++;
  154739. }
  154740. }
  154741. GLOBAL(void)
  154742. jinit_upsampler (j_decompress_ptr cinfo)
  154743. {
  154744. my_upsample_ptr2 upsample;
  154745. int ci;
  154746. jpeg_component_info * compptr;
  154747. boolean need_buffer, do_fancy;
  154748. int h_in_group, v_in_group, h_out_group, v_out_group;
  154749. upsample = (my_upsample_ptr2)
  154750. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154751. SIZEOF(my_upsampler2));
  154752. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154753. upsample->pub.start_pass = start_pass_upsample;
  154754. upsample->pub.upsample = sep_upsample;
  154755. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154756. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154757. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154758. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154759. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154760. ci++, compptr++) {
  154761. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154762. cinfo->min_DCT_scaled_size;
  154763. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154764. cinfo->min_DCT_scaled_size;
  154765. h_out_group = cinfo->max_h_samp_factor;
  154766. v_out_group = cinfo->max_v_samp_factor;
  154767. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154768. need_buffer = TRUE;
  154769. if (! compptr->component_needed) {
  154770. upsample->methods[ci] = noop_upsample;
  154771. need_buffer = FALSE;
  154772. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154773. upsample->methods[ci] = fullsize_upsample;
  154774. need_buffer = FALSE;
  154775. } else if (h_in_group * 2 == h_out_group &&
  154776. v_in_group == v_out_group) {
  154777. if (do_fancy && compptr->downsampled_width > 2)
  154778. upsample->methods[ci] = h2v1_fancy_upsample;
  154779. else
  154780. upsample->methods[ci] = h2v1_upsample;
  154781. } else if (h_in_group * 2 == h_out_group &&
  154782. v_in_group * 2 == v_out_group) {
  154783. if (do_fancy && compptr->downsampled_width > 2) {
  154784. upsample->methods[ci] = h2v2_fancy_upsample;
  154785. upsample->pub.need_context_rows = TRUE;
  154786. } else
  154787. upsample->methods[ci] = h2v2_upsample;
  154788. } else if ((h_out_group % h_in_group) == 0 &&
  154789. (v_out_group % v_in_group) == 0) {
  154790. upsample->methods[ci] = int_upsample;
  154791. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154792. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154793. } else
  154794. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154795. if (need_buffer) {
  154796. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154797. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154798. (JDIMENSION) jround_up((long) cinfo->output_width,
  154799. (long) cinfo->max_h_samp_factor),
  154800. (JDIMENSION) cinfo->max_v_samp_factor);
  154801. }
  154802. }
  154803. }
  154804. /*** End of inlined file: jdsample.c ***/
  154805. /*** Start of inlined file: jdtrans.c ***/
  154806. #define JPEG_INTERNALS
  154807. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154808. GLOBAL(jvirt_barray_ptr *)
  154809. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154810. {
  154811. if (cinfo->global_state == DSTATE_READY) {
  154812. transdecode_master_selection(cinfo);
  154813. cinfo->global_state = DSTATE_RDCOEFS;
  154814. }
  154815. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154816. for (;;) {
  154817. int retcode;
  154818. if (cinfo->progress != NULL)
  154819. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154820. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154821. if (retcode == JPEG_SUSPENDED)
  154822. return NULL;
  154823. if (retcode == JPEG_REACHED_EOI)
  154824. break;
  154825. if (cinfo->progress != NULL &&
  154826. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154827. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154828. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154829. }
  154830. }
  154831. }
  154832. cinfo->global_state = DSTATE_STOPPING;
  154833. }
  154834. if ((cinfo->global_state == DSTATE_STOPPING ||
  154835. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154836. return cinfo->coef->coef_arrays;
  154837. }
  154838. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154839. return NULL; /* keep compiler happy */
  154840. }
  154841. LOCAL(void)
  154842. transdecode_master_selection (j_decompress_ptr cinfo)
  154843. {
  154844. cinfo->buffered_image = TRUE;
  154845. if (cinfo->arith_code) {
  154846. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154847. } else {
  154848. if (cinfo->progressive_mode) {
  154849. #ifdef D_PROGRESSIVE_SUPPORTED
  154850. jinit_phuff_decoder(cinfo);
  154851. #else
  154852. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154853. #endif
  154854. } else
  154855. jinit_huff_decoder(cinfo);
  154856. }
  154857. jinit_d_coef_controller(cinfo, TRUE);
  154858. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154859. (*cinfo->inputctl->start_input_pass) (cinfo);
  154860. if (cinfo->progress != NULL) {
  154861. int nscans;
  154862. if (cinfo->progressive_mode) {
  154863. nscans = 2 + 3 * cinfo->num_components;
  154864. } else if (cinfo->inputctl->has_multiple_scans) {
  154865. nscans = cinfo->num_components;
  154866. } else {
  154867. nscans = 1;
  154868. }
  154869. cinfo->progress->pass_counter = 0L;
  154870. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154871. cinfo->progress->completed_passes = 0;
  154872. cinfo->progress->total_passes = 1;
  154873. }
  154874. }
  154875. /*** End of inlined file: jdtrans.c ***/
  154876. /*** Start of inlined file: jfdctflt.c ***/
  154877. #define JPEG_INTERNALS
  154878. #ifdef DCT_FLOAT_SUPPORTED
  154879. #if DCTSIZE != 8
  154880. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154881. #endif
  154882. GLOBAL(void)
  154883. jpeg_fdct_float (FAST_FLOAT * data)
  154884. {
  154885. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154886. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154887. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154888. FAST_FLOAT *dataptr;
  154889. int ctr;
  154890. dataptr = data;
  154891. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154892. tmp0 = dataptr[0] + dataptr[7];
  154893. tmp7 = dataptr[0] - dataptr[7];
  154894. tmp1 = dataptr[1] + dataptr[6];
  154895. tmp6 = dataptr[1] - dataptr[6];
  154896. tmp2 = dataptr[2] + dataptr[5];
  154897. tmp5 = dataptr[2] - dataptr[5];
  154898. tmp3 = dataptr[3] + dataptr[4];
  154899. tmp4 = dataptr[3] - dataptr[4];
  154900. tmp10 = tmp0 + tmp3; /* phase 2 */
  154901. tmp13 = tmp0 - tmp3;
  154902. tmp11 = tmp1 + tmp2;
  154903. tmp12 = tmp1 - tmp2;
  154904. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154905. dataptr[4] = tmp10 - tmp11;
  154906. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154907. dataptr[2] = tmp13 + z1; /* phase 5 */
  154908. dataptr[6] = tmp13 - z1;
  154909. tmp10 = tmp4 + tmp5; /* phase 2 */
  154910. tmp11 = tmp5 + tmp6;
  154911. tmp12 = tmp6 + tmp7;
  154912. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154913. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154914. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154915. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154916. z11 = tmp7 + z3; /* phase 5 */
  154917. z13 = tmp7 - z3;
  154918. dataptr[5] = z13 + z2; /* phase 6 */
  154919. dataptr[3] = z13 - z2;
  154920. dataptr[1] = z11 + z4;
  154921. dataptr[7] = z11 - z4;
  154922. dataptr += DCTSIZE; /* advance pointer to next row */
  154923. }
  154924. dataptr = data;
  154925. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154926. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154927. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154928. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154929. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154930. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154931. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154932. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154933. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154934. tmp10 = tmp0 + tmp3; /* phase 2 */
  154935. tmp13 = tmp0 - tmp3;
  154936. tmp11 = tmp1 + tmp2;
  154937. tmp12 = tmp1 - tmp2;
  154938. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154939. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154940. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154941. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154942. dataptr[DCTSIZE*6] = tmp13 - z1;
  154943. tmp10 = tmp4 + tmp5; /* phase 2 */
  154944. tmp11 = tmp5 + tmp6;
  154945. tmp12 = tmp6 + tmp7;
  154946. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154947. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154948. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154949. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154950. z11 = tmp7 + z3; /* phase 5 */
  154951. z13 = tmp7 - z3;
  154952. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  154953. dataptr[DCTSIZE*3] = z13 - z2;
  154954. dataptr[DCTSIZE*1] = z11 + z4;
  154955. dataptr[DCTSIZE*7] = z11 - z4;
  154956. dataptr++; /* advance pointer to next column */
  154957. }
  154958. }
  154959. #endif /* DCT_FLOAT_SUPPORTED */
  154960. /*** End of inlined file: jfdctflt.c ***/
  154961. /*** Start of inlined file: jfdctint.c ***/
  154962. #define JPEG_INTERNALS
  154963. #ifdef DCT_ISLOW_SUPPORTED
  154964. #if DCTSIZE != 8
  154965. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154966. #endif
  154967. #if BITS_IN_JSAMPLE == 8
  154968. #define CONST_BITS 13
  154969. #define PASS1_BITS 2
  154970. #else
  154971. #define CONST_BITS 13
  154972. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  154973. #endif
  154974. #if CONST_BITS == 13
  154975. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  154976. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  154977. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  154978. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  154979. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  154980. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  154981. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  154982. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  154983. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  154984. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  154985. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  154986. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  154987. #else
  154988. #define FIX_0_298631336 FIX(0.298631336)
  154989. #define FIX_0_390180644 FIX(0.390180644)
  154990. #define FIX_0_541196100 FIX(0.541196100)
  154991. #define FIX_0_765366865 FIX(0.765366865)
  154992. #define FIX_0_899976223 FIX(0.899976223)
  154993. #define FIX_1_175875602 FIX(1.175875602)
  154994. #define FIX_1_501321110 FIX(1.501321110)
  154995. #define FIX_1_847759065 FIX(1.847759065)
  154996. #define FIX_1_961570560 FIX(1.961570560)
  154997. #define FIX_2_053119869 FIX(2.053119869)
  154998. #define FIX_2_562915447 FIX(2.562915447)
  154999. #define FIX_3_072711026 FIX(3.072711026)
  155000. #endif
  155001. #if BITS_IN_JSAMPLE == 8
  155002. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155003. #else
  155004. #define MULTIPLY(var,const) ((var) * (const))
  155005. #endif
  155006. GLOBAL(void)
  155007. jpeg_fdct_islow (DCTELEM * data)
  155008. {
  155009. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155010. INT32 tmp10, tmp11, tmp12, tmp13;
  155011. INT32 z1, z2, z3, z4, z5;
  155012. DCTELEM *dataptr;
  155013. int ctr;
  155014. SHIFT_TEMPS
  155015. dataptr = data;
  155016. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155017. tmp0 = dataptr[0] + dataptr[7];
  155018. tmp7 = dataptr[0] - dataptr[7];
  155019. tmp1 = dataptr[1] + dataptr[6];
  155020. tmp6 = dataptr[1] - dataptr[6];
  155021. tmp2 = dataptr[2] + dataptr[5];
  155022. tmp5 = dataptr[2] - dataptr[5];
  155023. tmp3 = dataptr[3] + dataptr[4];
  155024. tmp4 = dataptr[3] - dataptr[4];
  155025. tmp10 = tmp0 + tmp3;
  155026. tmp13 = tmp0 - tmp3;
  155027. tmp11 = tmp1 + tmp2;
  155028. tmp12 = tmp1 - tmp2;
  155029. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155030. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155031. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155032. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155033. CONST_BITS-PASS1_BITS);
  155034. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155035. CONST_BITS-PASS1_BITS);
  155036. z1 = tmp4 + tmp7;
  155037. z2 = tmp5 + tmp6;
  155038. z3 = tmp4 + tmp6;
  155039. z4 = tmp5 + tmp7;
  155040. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155041. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155042. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155043. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155044. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155045. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155046. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155047. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155048. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155049. z3 += z5;
  155050. z4 += z5;
  155051. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155052. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155053. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155054. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155055. dataptr += DCTSIZE; /* advance pointer to next row */
  155056. }
  155057. dataptr = data;
  155058. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155059. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155060. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155061. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155062. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155063. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155064. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155065. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155066. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155067. tmp10 = tmp0 + tmp3;
  155068. tmp13 = tmp0 - tmp3;
  155069. tmp11 = tmp1 + tmp2;
  155070. tmp12 = tmp1 - tmp2;
  155071. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155072. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155073. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155074. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155075. CONST_BITS+PASS1_BITS);
  155076. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155077. CONST_BITS+PASS1_BITS);
  155078. z1 = tmp4 + tmp7;
  155079. z2 = tmp5 + tmp6;
  155080. z3 = tmp4 + tmp6;
  155081. z4 = tmp5 + tmp7;
  155082. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155083. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155084. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155085. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155086. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155087. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155088. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155089. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155090. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155091. z3 += z5;
  155092. z4 += z5;
  155093. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155094. CONST_BITS+PASS1_BITS);
  155095. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155096. CONST_BITS+PASS1_BITS);
  155097. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155098. CONST_BITS+PASS1_BITS);
  155099. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155100. CONST_BITS+PASS1_BITS);
  155101. dataptr++; /* advance pointer to next column */
  155102. }
  155103. }
  155104. #endif /* DCT_ISLOW_SUPPORTED */
  155105. /*** End of inlined file: jfdctint.c ***/
  155106. #undef CONST_BITS
  155107. #undef MULTIPLY
  155108. #undef FIX_0_541196100
  155109. /*** Start of inlined file: jfdctfst.c ***/
  155110. #define JPEG_INTERNALS
  155111. #ifdef DCT_IFAST_SUPPORTED
  155112. #if DCTSIZE != 8
  155113. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155114. #endif
  155115. #define CONST_BITS 8
  155116. #if CONST_BITS == 8
  155117. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155118. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155119. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155120. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155121. #else
  155122. #define FIX_0_382683433 FIX(0.382683433)
  155123. #define FIX_0_541196100 FIX(0.541196100)
  155124. #define FIX_0_707106781 FIX(0.707106781)
  155125. #define FIX_1_306562965 FIX(1.306562965)
  155126. #endif
  155127. #ifndef USE_ACCURATE_ROUNDING
  155128. #undef DESCALE
  155129. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155130. #endif
  155131. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155132. GLOBAL(void)
  155133. jpeg_fdct_ifast (DCTELEM * data)
  155134. {
  155135. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155136. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155137. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155138. DCTELEM *dataptr;
  155139. int ctr;
  155140. SHIFT_TEMPS
  155141. dataptr = data;
  155142. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155143. tmp0 = dataptr[0] + dataptr[7];
  155144. tmp7 = dataptr[0] - dataptr[7];
  155145. tmp1 = dataptr[1] + dataptr[6];
  155146. tmp6 = dataptr[1] - dataptr[6];
  155147. tmp2 = dataptr[2] + dataptr[5];
  155148. tmp5 = dataptr[2] - dataptr[5];
  155149. tmp3 = dataptr[3] + dataptr[4];
  155150. tmp4 = dataptr[3] - dataptr[4];
  155151. tmp10 = tmp0 + tmp3; /* phase 2 */
  155152. tmp13 = tmp0 - tmp3;
  155153. tmp11 = tmp1 + tmp2;
  155154. tmp12 = tmp1 - tmp2;
  155155. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155156. dataptr[4] = tmp10 - tmp11;
  155157. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155158. dataptr[2] = tmp13 + z1; /* phase 5 */
  155159. dataptr[6] = tmp13 - z1;
  155160. tmp10 = tmp4 + tmp5; /* phase 2 */
  155161. tmp11 = tmp5 + tmp6;
  155162. tmp12 = tmp6 + tmp7;
  155163. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155164. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155165. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155166. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155167. z11 = tmp7 + z3; /* phase 5 */
  155168. z13 = tmp7 - z3;
  155169. dataptr[5] = z13 + z2; /* phase 6 */
  155170. dataptr[3] = z13 - z2;
  155171. dataptr[1] = z11 + z4;
  155172. dataptr[7] = z11 - z4;
  155173. dataptr += DCTSIZE; /* advance pointer to next row */
  155174. }
  155175. dataptr = data;
  155176. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155177. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155178. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155179. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155180. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155181. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155182. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155183. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155184. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155185. tmp10 = tmp0 + tmp3; /* phase 2 */
  155186. tmp13 = tmp0 - tmp3;
  155187. tmp11 = tmp1 + tmp2;
  155188. tmp12 = tmp1 - tmp2;
  155189. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155190. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155191. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155192. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155193. dataptr[DCTSIZE*6] = tmp13 - z1;
  155194. tmp10 = tmp4 + tmp5; /* phase 2 */
  155195. tmp11 = tmp5 + tmp6;
  155196. tmp12 = tmp6 + tmp7;
  155197. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155198. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155199. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155200. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155201. z11 = tmp7 + z3; /* phase 5 */
  155202. z13 = tmp7 - z3;
  155203. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155204. dataptr[DCTSIZE*3] = z13 - z2;
  155205. dataptr[DCTSIZE*1] = z11 + z4;
  155206. dataptr[DCTSIZE*7] = z11 - z4;
  155207. dataptr++; /* advance pointer to next column */
  155208. }
  155209. }
  155210. #endif /* DCT_IFAST_SUPPORTED */
  155211. /*** End of inlined file: jfdctfst.c ***/
  155212. #undef FIX_0_541196100
  155213. /*** Start of inlined file: jidctflt.c ***/
  155214. #define JPEG_INTERNALS
  155215. #ifdef DCT_FLOAT_SUPPORTED
  155216. #if DCTSIZE != 8
  155217. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155218. #endif
  155219. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155220. GLOBAL(void)
  155221. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155222. JCOEFPTR coef_block,
  155223. JSAMPARRAY output_buf, JDIMENSION output_col)
  155224. {
  155225. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155226. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155227. FAST_FLOAT z5, z10, z11, z12, z13;
  155228. JCOEFPTR inptr;
  155229. FLOAT_MULT_TYPE * quantptr;
  155230. FAST_FLOAT * wsptr;
  155231. JSAMPROW outptr;
  155232. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155233. int ctr;
  155234. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155235. SHIFT_TEMPS
  155236. inptr = coef_block;
  155237. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155238. wsptr = workspace;
  155239. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155240. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155241. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155242. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155243. inptr[DCTSIZE*7] == 0) {
  155244. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155245. wsptr[DCTSIZE*0] = dcval;
  155246. wsptr[DCTSIZE*1] = dcval;
  155247. wsptr[DCTSIZE*2] = dcval;
  155248. wsptr[DCTSIZE*3] = dcval;
  155249. wsptr[DCTSIZE*4] = dcval;
  155250. wsptr[DCTSIZE*5] = dcval;
  155251. wsptr[DCTSIZE*6] = dcval;
  155252. wsptr[DCTSIZE*7] = dcval;
  155253. inptr++; /* advance pointers to next column */
  155254. quantptr++;
  155255. wsptr++;
  155256. continue;
  155257. }
  155258. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155259. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155260. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155261. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155262. tmp10 = tmp0 + tmp2; /* phase 3 */
  155263. tmp11 = tmp0 - tmp2;
  155264. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155265. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155266. tmp0 = tmp10 + tmp13; /* phase 2 */
  155267. tmp3 = tmp10 - tmp13;
  155268. tmp1 = tmp11 + tmp12;
  155269. tmp2 = tmp11 - tmp12;
  155270. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155271. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155272. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155273. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155274. z13 = tmp6 + tmp5; /* phase 6 */
  155275. z10 = tmp6 - tmp5;
  155276. z11 = tmp4 + tmp7;
  155277. z12 = tmp4 - tmp7;
  155278. tmp7 = z11 + z13; /* phase 5 */
  155279. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155280. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155281. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155282. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155283. tmp6 = tmp12 - tmp7; /* phase 2 */
  155284. tmp5 = tmp11 - tmp6;
  155285. tmp4 = tmp10 + tmp5;
  155286. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155287. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155288. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155289. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155290. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155291. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155292. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155293. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155294. inptr++; /* advance pointers to next column */
  155295. quantptr++;
  155296. wsptr++;
  155297. }
  155298. wsptr = workspace;
  155299. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155300. outptr = output_buf[ctr] + output_col;
  155301. tmp10 = wsptr[0] + wsptr[4];
  155302. tmp11 = wsptr[0] - wsptr[4];
  155303. tmp13 = wsptr[2] + wsptr[6];
  155304. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155305. tmp0 = tmp10 + tmp13;
  155306. tmp3 = tmp10 - tmp13;
  155307. tmp1 = tmp11 + tmp12;
  155308. tmp2 = tmp11 - tmp12;
  155309. z13 = wsptr[5] + wsptr[3];
  155310. z10 = wsptr[5] - wsptr[3];
  155311. z11 = wsptr[1] + wsptr[7];
  155312. z12 = wsptr[1] - wsptr[7];
  155313. tmp7 = z11 + z13;
  155314. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155315. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155316. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155317. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155318. tmp6 = tmp12 - tmp7;
  155319. tmp5 = tmp11 - tmp6;
  155320. tmp4 = tmp10 + tmp5;
  155321. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155322. & RANGE_MASK];
  155323. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155324. & RANGE_MASK];
  155325. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155326. & RANGE_MASK];
  155327. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155328. & RANGE_MASK];
  155329. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155330. & RANGE_MASK];
  155331. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155332. & RANGE_MASK];
  155333. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155334. & RANGE_MASK];
  155335. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155336. & RANGE_MASK];
  155337. wsptr += DCTSIZE; /* advance pointer to next row */
  155338. }
  155339. }
  155340. #endif /* DCT_FLOAT_SUPPORTED */
  155341. /*** End of inlined file: jidctflt.c ***/
  155342. #undef CONST_BITS
  155343. #undef FIX_1_847759065
  155344. #undef MULTIPLY
  155345. #undef DEQUANTIZE
  155346. #undef DESCALE
  155347. /*** Start of inlined file: jidctfst.c ***/
  155348. #define JPEG_INTERNALS
  155349. #ifdef DCT_IFAST_SUPPORTED
  155350. #if DCTSIZE != 8
  155351. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155352. #endif
  155353. #if BITS_IN_JSAMPLE == 8
  155354. #define CONST_BITS 8
  155355. #define PASS1_BITS 2
  155356. #else
  155357. #define CONST_BITS 8
  155358. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155359. #endif
  155360. #if CONST_BITS == 8
  155361. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155362. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155363. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155364. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155365. #else
  155366. #define FIX_1_082392200 FIX(1.082392200)
  155367. #define FIX_1_414213562 FIX(1.414213562)
  155368. #define FIX_1_847759065 FIX(1.847759065)
  155369. #define FIX_2_613125930 FIX(2.613125930)
  155370. #endif
  155371. #ifndef USE_ACCURATE_ROUNDING
  155372. #undef DESCALE
  155373. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155374. #endif
  155375. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155376. #if BITS_IN_JSAMPLE == 8
  155377. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155378. #else
  155379. #define DEQUANTIZE(coef,quantval) \
  155380. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155381. #endif
  155382. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155383. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155384. #if BITS_IN_JSAMPLE == 8
  155385. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155386. #else
  155387. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155388. #endif
  155389. #define IRIGHT_SHIFT(x,shft) \
  155390. ((ishift_temp = (x)) < 0 ? \
  155391. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155392. (ishift_temp >> (shft)))
  155393. #else
  155394. #define ISHIFT_TEMPS
  155395. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155396. #endif
  155397. #ifdef USE_ACCURATE_ROUNDING
  155398. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155399. #else
  155400. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155401. #endif
  155402. GLOBAL(void)
  155403. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155404. JCOEFPTR coef_block,
  155405. JSAMPARRAY output_buf, JDIMENSION output_col)
  155406. {
  155407. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155408. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155409. DCTELEM z5, z10, z11, z12, z13;
  155410. JCOEFPTR inptr;
  155411. IFAST_MULT_TYPE * quantptr;
  155412. int * wsptr;
  155413. JSAMPROW outptr;
  155414. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155415. int ctr;
  155416. int workspace[DCTSIZE2]; /* buffers data between passes */
  155417. SHIFT_TEMPS /* for DESCALE */
  155418. ISHIFT_TEMPS /* for IDESCALE */
  155419. inptr = coef_block;
  155420. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155421. wsptr = workspace;
  155422. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155423. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155424. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155425. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155426. inptr[DCTSIZE*7] == 0) {
  155427. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155428. wsptr[DCTSIZE*0] = dcval;
  155429. wsptr[DCTSIZE*1] = dcval;
  155430. wsptr[DCTSIZE*2] = dcval;
  155431. wsptr[DCTSIZE*3] = dcval;
  155432. wsptr[DCTSIZE*4] = dcval;
  155433. wsptr[DCTSIZE*5] = dcval;
  155434. wsptr[DCTSIZE*6] = dcval;
  155435. wsptr[DCTSIZE*7] = dcval;
  155436. inptr++; /* advance pointers to next column */
  155437. quantptr++;
  155438. wsptr++;
  155439. continue;
  155440. }
  155441. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155442. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155443. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155444. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155445. tmp10 = tmp0 + tmp2; /* phase 3 */
  155446. tmp11 = tmp0 - tmp2;
  155447. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155448. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155449. tmp0 = tmp10 + tmp13; /* phase 2 */
  155450. tmp3 = tmp10 - tmp13;
  155451. tmp1 = tmp11 + tmp12;
  155452. tmp2 = tmp11 - tmp12;
  155453. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155454. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155455. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155456. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155457. z13 = tmp6 + tmp5; /* phase 6 */
  155458. z10 = tmp6 - tmp5;
  155459. z11 = tmp4 + tmp7;
  155460. z12 = tmp4 - tmp7;
  155461. tmp7 = z11 + z13; /* phase 5 */
  155462. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155463. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155464. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155465. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155466. tmp6 = tmp12 - tmp7; /* phase 2 */
  155467. tmp5 = tmp11 - tmp6;
  155468. tmp4 = tmp10 + tmp5;
  155469. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155470. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155471. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155472. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155473. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155474. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155475. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155476. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155477. inptr++; /* advance pointers to next column */
  155478. quantptr++;
  155479. wsptr++;
  155480. }
  155481. wsptr = workspace;
  155482. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155483. outptr = output_buf[ctr] + output_col;
  155484. #ifndef NO_ZERO_ROW_TEST
  155485. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155486. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155487. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155488. & RANGE_MASK];
  155489. outptr[0] = dcval;
  155490. outptr[1] = dcval;
  155491. outptr[2] = dcval;
  155492. outptr[3] = dcval;
  155493. outptr[4] = dcval;
  155494. outptr[5] = dcval;
  155495. outptr[6] = dcval;
  155496. outptr[7] = dcval;
  155497. wsptr += DCTSIZE; /* advance pointer to next row */
  155498. continue;
  155499. }
  155500. #endif
  155501. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155502. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155503. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155504. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155505. - tmp13;
  155506. tmp0 = tmp10 + tmp13;
  155507. tmp3 = tmp10 - tmp13;
  155508. tmp1 = tmp11 + tmp12;
  155509. tmp2 = tmp11 - tmp12;
  155510. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155511. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155512. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155513. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155514. tmp7 = z11 + z13; /* phase 5 */
  155515. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155516. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155517. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155518. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155519. tmp6 = tmp12 - tmp7; /* phase 2 */
  155520. tmp5 = tmp11 - tmp6;
  155521. tmp4 = tmp10 + tmp5;
  155522. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155523. & RANGE_MASK];
  155524. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155525. & RANGE_MASK];
  155526. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155527. & RANGE_MASK];
  155528. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155529. & RANGE_MASK];
  155530. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155531. & RANGE_MASK];
  155532. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155533. & RANGE_MASK];
  155534. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155535. & RANGE_MASK];
  155536. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155537. & RANGE_MASK];
  155538. wsptr += DCTSIZE; /* advance pointer to next row */
  155539. }
  155540. }
  155541. #endif /* DCT_IFAST_SUPPORTED */
  155542. /*** End of inlined file: jidctfst.c ***/
  155543. #undef CONST_BITS
  155544. #undef FIX_1_847759065
  155545. #undef MULTIPLY
  155546. #undef DEQUANTIZE
  155547. /*** Start of inlined file: jidctint.c ***/
  155548. #define JPEG_INTERNALS
  155549. #ifdef DCT_ISLOW_SUPPORTED
  155550. #if DCTSIZE != 8
  155551. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155552. #endif
  155553. #if BITS_IN_JSAMPLE == 8
  155554. #define CONST_BITS 13
  155555. #define PASS1_BITS 2
  155556. #else
  155557. #define CONST_BITS 13
  155558. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155559. #endif
  155560. #if CONST_BITS == 13
  155561. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155562. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155563. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155564. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155565. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155566. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155567. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155568. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155569. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155570. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155571. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155572. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155573. #else
  155574. #define FIX_0_298631336 FIX(0.298631336)
  155575. #define FIX_0_390180644 FIX(0.390180644)
  155576. #define FIX_0_541196100 FIX(0.541196100)
  155577. #define FIX_0_765366865 FIX(0.765366865)
  155578. #define FIX_0_899976223 FIX(0.899976223)
  155579. #define FIX_1_175875602 FIX(1.175875602)
  155580. #define FIX_1_501321110 FIX(1.501321110)
  155581. #define FIX_1_847759065 FIX(1.847759065)
  155582. #define FIX_1_961570560 FIX(1.961570560)
  155583. #define FIX_2_053119869 FIX(2.053119869)
  155584. #define FIX_2_562915447 FIX(2.562915447)
  155585. #define FIX_3_072711026 FIX(3.072711026)
  155586. #endif
  155587. #if BITS_IN_JSAMPLE == 8
  155588. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155589. #else
  155590. #define MULTIPLY(var,const) ((var) * (const))
  155591. #endif
  155592. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155593. GLOBAL(void)
  155594. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155595. JCOEFPTR coef_block,
  155596. JSAMPARRAY output_buf, JDIMENSION output_col)
  155597. {
  155598. INT32 tmp0, tmp1, tmp2, tmp3;
  155599. INT32 tmp10, tmp11, tmp12, tmp13;
  155600. INT32 z1, z2, z3, z4, z5;
  155601. JCOEFPTR inptr;
  155602. ISLOW_MULT_TYPE * quantptr;
  155603. int * wsptr;
  155604. JSAMPROW outptr;
  155605. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155606. int ctr;
  155607. int workspace[DCTSIZE2]; /* buffers data between passes */
  155608. SHIFT_TEMPS
  155609. inptr = coef_block;
  155610. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155611. wsptr = workspace;
  155612. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155613. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155614. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155615. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155616. inptr[DCTSIZE*7] == 0) {
  155617. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155618. wsptr[DCTSIZE*0] = dcval;
  155619. wsptr[DCTSIZE*1] = dcval;
  155620. wsptr[DCTSIZE*2] = dcval;
  155621. wsptr[DCTSIZE*3] = dcval;
  155622. wsptr[DCTSIZE*4] = dcval;
  155623. wsptr[DCTSIZE*5] = dcval;
  155624. wsptr[DCTSIZE*6] = dcval;
  155625. wsptr[DCTSIZE*7] = dcval;
  155626. inptr++; /* advance pointers to next column */
  155627. quantptr++;
  155628. wsptr++;
  155629. continue;
  155630. }
  155631. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155632. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155633. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155634. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155635. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155636. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155637. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155638. tmp0 = (z2 + z3) << CONST_BITS;
  155639. tmp1 = (z2 - z3) << CONST_BITS;
  155640. tmp10 = tmp0 + tmp3;
  155641. tmp13 = tmp0 - tmp3;
  155642. tmp11 = tmp1 + tmp2;
  155643. tmp12 = tmp1 - tmp2;
  155644. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155645. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155646. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155647. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155648. z1 = tmp0 + tmp3;
  155649. z2 = tmp1 + tmp2;
  155650. z3 = tmp0 + tmp2;
  155651. z4 = tmp1 + tmp3;
  155652. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155653. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155654. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155655. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155656. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155657. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155658. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155659. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155660. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155661. z3 += z5;
  155662. z4 += z5;
  155663. tmp0 += z1 + z3;
  155664. tmp1 += z2 + z4;
  155665. tmp2 += z2 + z3;
  155666. tmp3 += z1 + z4;
  155667. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155668. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155669. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155670. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155671. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155672. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155673. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155674. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155675. inptr++; /* advance pointers to next column */
  155676. quantptr++;
  155677. wsptr++;
  155678. }
  155679. wsptr = workspace;
  155680. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155681. outptr = output_buf[ctr] + output_col;
  155682. #ifndef NO_ZERO_ROW_TEST
  155683. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155684. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155685. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155686. & RANGE_MASK];
  155687. outptr[0] = dcval;
  155688. outptr[1] = dcval;
  155689. outptr[2] = dcval;
  155690. outptr[3] = dcval;
  155691. outptr[4] = dcval;
  155692. outptr[5] = dcval;
  155693. outptr[6] = dcval;
  155694. outptr[7] = dcval;
  155695. wsptr += DCTSIZE; /* advance pointer to next row */
  155696. continue;
  155697. }
  155698. #endif
  155699. z2 = (INT32) wsptr[2];
  155700. z3 = (INT32) wsptr[6];
  155701. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155702. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155703. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155704. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155705. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155706. tmp10 = tmp0 + tmp3;
  155707. tmp13 = tmp0 - tmp3;
  155708. tmp11 = tmp1 + tmp2;
  155709. tmp12 = tmp1 - tmp2;
  155710. tmp0 = (INT32) wsptr[7];
  155711. tmp1 = (INT32) wsptr[5];
  155712. tmp2 = (INT32) wsptr[3];
  155713. tmp3 = (INT32) wsptr[1];
  155714. z1 = tmp0 + tmp3;
  155715. z2 = tmp1 + tmp2;
  155716. z3 = tmp0 + tmp2;
  155717. z4 = tmp1 + tmp3;
  155718. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155719. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155720. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155721. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155722. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155723. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155724. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155725. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155726. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155727. z3 += z5;
  155728. z4 += z5;
  155729. tmp0 += z1 + z3;
  155730. tmp1 += z2 + z4;
  155731. tmp2 += z2 + z3;
  155732. tmp3 += z1 + z4;
  155733. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155734. CONST_BITS+PASS1_BITS+3)
  155735. & RANGE_MASK];
  155736. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155737. CONST_BITS+PASS1_BITS+3)
  155738. & RANGE_MASK];
  155739. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155740. CONST_BITS+PASS1_BITS+3)
  155741. & RANGE_MASK];
  155742. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155743. CONST_BITS+PASS1_BITS+3)
  155744. & RANGE_MASK];
  155745. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155746. CONST_BITS+PASS1_BITS+3)
  155747. & RANGE_MASK];
  155748. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155749. CONST_BITS+PASS1_BITS+3)
  155750. & RANGE_MASK];
  155751. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155752. CONST_BITS+PASS1_BITS+3)
  155753. & RANGE_MASK];
  155754. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155755. CONST_BITS+PASS1_BITS+3)
  155756. & RANGE_MASK];
  155757. wsptr += DCTSIZE; /* advance pointer to next row */
  155758. }
  155759. }
  155760. #endif /* DCT_ISLOW_SUPPORTED */
  155761. /*** End of inlined file: jidctint.c ***/
  155762. /*** Start of inlined file: jidctred.c ***/
  155763. #define JPEG_INTERNALS
  155764. #ifdef IDCT_SCALING_SUPPORTED
  155765. #if DCTSIZE != 8
  155766. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155767. #endif
  155768. #if BITS_IN_JSAMPLE == 8
  155769. #define CONST_BITS 13
  155770. #define PASS1_BITS 2
  155771. #else
  155772. #define CONST_BITS 13
  155773. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155774. #endif
  155775. #if CONST_BITS == 13
  155776. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155777. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155778. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155779. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155780. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155781. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155782. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155783. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155784. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155785. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155786. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155787. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155788. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155789. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155790. #else
  155791. #define FIX_0_211164243 FIX(0.211164243)
  155792. #define FIX_0_509795579 FIX(0.509795579)
  155793. #define FIX_0_601344887 FIX(0.601344887)
  155794. #define FIX_0_720959822 FIX(0.720959822)
  155795. #define FIX_0_765366865 FIX(0.765366865)
  155796. #define FIX_0_850430095 FIX(0.850430095)
  155797. #define FIX_0_899976223 FIX(0.899976223)
  155798. #define FIX_1_061594337 FIX(1.061594337)
  155799. #define FIX_1_272758580 FIX(1.272758580)
  155800. #define FIX_1_451774981 FIX(1.451774981)
  155801. #define FIX_1_847759065 FIX(1.847759065)
  155802. #define FIX_2_172734803 FIX(2.172734803)
  155803. #define FIX_2_562915447 FIX(2.562915447)
  155804. #define FIX_3_624509785 FIX(3.624509785)
  155805. #endif
  155806. #if BITS_IN_JSAMPLE == 8
  155807. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155808. #else
  155809. #define MULTIPLY(var,const) ((var) * (const))
  155810. #endif
  155811. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155812. GLOBAL(void)
  155813. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155814. JCOEFPTR coef_block,
  155815. JSAMPARRAY output_buf, JDIMENSION output_col)
  155816. {
  155817. INT32 tmp0, tmp2, tmp10, tmp12;
  155818. INT32 z1, z2, z3, z4;
  155819. JCOEFPTR inptr;
  155820. ISLOW_MULT_TYPE * quantptr;
  155821. int * wsptr;
  155822. JSAMPROW outptr;
  155823. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155824. int ctr;
  155825. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155826. SHIFT_TEMPS
  155827. inptr = coef_block;
  155828. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155829. wsptr = workspace;
  155830. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155831. if (ctr == DCTSIZE-4)
  155832. continue;
  155833. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155834. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155835. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155836. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155837. wsptr[DCTSIZE*0] = dcval;
  155838. wsptr[DCTSIZE*1] = dcval;
  155839. wsptr[DCTSIZE*2] = dcval;
  155840. wsptr[DCTSIZE*3] = dcval;
  155841. continue;
  155842. }
  155843. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155844. tmp0 <<= (CONST_BITS+1);
  155845. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155846. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155847. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155848. tmp10 = tmp0 + tmp2;
  155849. tmp12 = tmp0 - tmp2;
  155850. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155851. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155852. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155853. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155854. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155855. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155856. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155857. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155858. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155859. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155860. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155861. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155862. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155863. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155864. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155865. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155866. }
  155867. wsptr = workspace;
  155868. for (ctr = 0; ctr < 4; ctr++) {
  155869. outptr = output_buf[ctr] + output_col;
  155870. #ifndef NO_ZERO_ROW_TEST
  155871. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155872. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155873. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155874. & RANGE_MASK];
  155875. outptr[0] = dcval;
  155876. outptr[1] = dcval;
  155877. outptr[2] = dcval;
  155878. outptr[3] = dcval;
  155879. wsptr += DCTSIZE; /* advance pointer to next row */
  155880. continue;
  155881. }
  155882. #endif
  155883. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155884. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155885. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155886. tmp10 = tmp0 + tmp2;
  155887. tmp12 = tmp0 - tmp2;
  155888. z1 = (INT32) wsptr[7];
  155889. z2 = (INT32) wsptr[5];
  155890. z3 = (INT32) wsptr[3];
  155891. z4 = (INT32) wsptr[1];
  155892. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155893. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155894. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155895. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155896. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155897. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155898. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155899. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155900. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155901. CONST_BITS+PASS1_BITS+3+1)
  155902. & RANGE_MASK];
  155903. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155904. CONST_BITS+PASS1_BITS+3+1)
  155905. & RANGE_MASK];
  155906. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155907. CONST_BITS+PASS1_BITS+3+1)
  155908. & RANGE_MASK];
  155909. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155910. CONST_BITS+PASS1_BITS+3+1)
  155911. & RANGE_MASK];
  155912. wsptr += DCTSIZE; /* advance pointer to next row */
  155913. }
  155914. }
  155915. GLOBAL(void)
  155916. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155917. JCOEFPTR coef_block,
  155918. JSAMPARRAY output_buf, JDIMENSION output_col)
  155919. {
  155920. INT32 tmp0, tmp10, z1;
  155921. JCOEFPTR inptr;
  155922. ISLOW_MULT_TYPE * quantptr;
  155923. int * wsptr;
  155924. JSAMPROW outptr;
  155925. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155926. int ctr;
  155927. int workspace[DCTSIZE*2]; /* buffers data between passes */
  155928. SHIFT_TEMPS
  155929. inptr = coef_block;
  155930. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155931. wsptr = workspace;
  155932. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155933. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  155934. continue;
  155935. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  155936. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  155937. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155938. wsptr[DCTSIZE*0] = dcval;
  155939. wsptr[DCTSIZE*1] = dcval;
  155940. continue;
  155941. }
  155942. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155943. tmp10 = z1 << (CONST_BITS+2);
  155944. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155945. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  155946. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155947. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  155948. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155949. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  155950. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155951. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155952. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  155953. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  155954. }
  155955. wsptr = workspace;
  155956. for (ctr = 0; ctr < 2; ctr++) {
  155957. outptr = output_buf[ctr] + output_col;
  155958. #ifndef NO_ZERO_ROW_TEST
  155959. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  155960. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155961. & RANGE_MASK];
  155962. outptr[0] = dcval;
  155963. outptr[1] = dcval;
  155964. wsptr += DCTSIZE; /* advance pointer to next row */
  155965. continue;
  155966. }
  155967. #endif
  155968. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  155969. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  155970. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  155971. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  155972. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155973. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  155974. CONST_BITS+PASS1_BITS+3+2)
  155975. & RANGE_MASK];
  155976. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  155977. CONST_BITS+PASS1_BITS+3+2)
  155978. & RANGE_MASK];
  155979. wsptr += DCTSIZE; /* advance pointer to next row */
  155980. }
  155981. }
  155982. GLOBAL(void)
  155983. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155984. JCOEFPTR coef_block,
  155985. JSAMPARRAY output_buf, JDIMENSION output_col)
  155986. {
  155987. int dcval;
  155988. ISLOW_MULT_TYPE * quantptr;
  155989. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155990. SHIFT_TEMPS
  155991. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155992. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  155993. dcval = (int) DESCALE((INT32) dcval, 3);
  155994. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  155995. }
  155996. #endif /* IDCT_SCALING_SUPPORTED */
  155997. /*** End of inlined file: jidctred.c ***/
  155998. /*** Start of inlined file: jmemmgr.c ***/
  155999. #define JPEG_INTERNALS
  156000. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156001. /*** Start of inlined file: jmemsys.h ***/
  156002. #ifndef __jmemsys_h__
  156003. #define __jmemsys_h__
  156004. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156005. #define jpeg_get_small jGetSmall
  156006. #define jpeg_free_small jFreeSmall
  156007. #define jpeg_get_large jGetLarge
  156008. #define jpeg_free_large jFreeLarge
  156009. #define jpeg_mem_available jMemAvail
  156010. #define jpeg_open_backing_store jOpenBackStore
  156011. #define jpeg_mem_init jMemInit
  156012. #define jpeg_mem_term jMemTerm
  156013. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156014. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156015. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156016. size_t sizeofobject));
  156017. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156018. size_t sizeofobject));
  156019. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156020. size_t sizeofobject));
  156021. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156022. #define MAX_ALLOC_CHUNK 1000000000L
  156023. #endif
  156024. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156025. long min_bytes_needed,
  156026. long max_bytes_needed,
  156027. long already_allocated));
  156028. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156029. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156030. typedef unsigned short XMSH; /* type of extended-memory handles */
  156031. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156032. typedef union {
  156033. short file_handle; /* DOS file handle if it's a temp file */
  156034. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156035. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156036. } handle_union;
  156037. #endif /* USE_MSDOS_MEMMGR */
  156038. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156039. #include <Files.h>
  156040. #endif /* USE_MAC_MEMMGR */
  156041. //typedef struct backing_store_struct * backing_store_ptr;
  156042. typedef struct backing_store_struct {
  156043. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156044. struct backing_store_struct *info,
  156045. void FAR * buffer_address,
  156046. long file_offset, long byte_count));
  156047. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156048. struct backing_store_struct *info,
  156049. void FAR * buffer_address,
  156050. long file_offset, long byte_count));
  156051. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156052. struct backing_store_struct *info));
  156053. #ifdef USE_MSDOS_MEMMGR
  156054. handle_union handle; /* reference to backing-store storage object */
  156055. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156056. #else
  156057. #ifdef USE_MAC_MEMMGR
  156058. short temp_file; /* file reference number to temp file */
  156059. FSSpec tempSpec; /* the FSSpec for the temp file */
  156060. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156061. #else
  156062. FILE * temp_file; /* stdio reference to temp file */
  156063. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156064. #endif
  156065. #endif
  156066. } backing_store_info;
  156067. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156068. struct backing_store_struct *info,
  156069. long total_bytes_needed));
  156070. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156071. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156072. #endif
  156073. /*** End of inlined file: jmemsys.h ***/
  156074. /* import the system-dependent declarations */
  156075. #ifndef NO_GETENV
  156076. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156077. extern char * getenv JPP((const char * name));
  156078. #endif
  156079. #endif
  156080. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156081. #define ALIGN_TYPE double
  156082. #endif
  156083. typedef union small_pool_struct * small_pool_ptr;
  156084. typedef union small_pool_struct {
  156085. struct {
  156086. small_pool_ptr next; /* next in list of pools */
  156087. size_t bytes_used; /* how many bytes already used within pool */
  156088. size_t bytes_left; /* bytes still available in this pool */
  156089. } hdr;
  156090. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156091. } small_pool_hdr;
  156092. typedef union large_pool_struct FAR * large_pool_ptr;
  156093. typedef union large_pool_struct {
  156094. struct {
  156095. large_pool_ptr next; /* next in list of pools */
  156096. size_t bytes_used; /* how many bytes already used within pool */
  156097. size_t bytes_left; /* bytes still available in this pool */
  156098. } hdr;
  156099. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156100. } large_pool_hdr;
  156101. typedef struct {
  156102. struct jpeg_memory_mgr pub; /* public fields */
  156103. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156104. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156105. jvirt_sarray_ptr virt_sarray_list;
  156106. jvirt_barray_ptr virt_barray_list;
  156107. long total_space_allocated;
  156108. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156109. } my_memory_mgr;
  156110. typedef my_memory_mgr * my_mem_ptr;
  156111. struct jvirt_sarray_control {
  156112. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156113. JDIMENSION rows_in_array; /* total virtual array height */
  156114. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156115. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156116. JDIMENSION rows_in_mem; /* height of memory buffer */
  156117. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156118. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156119. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156120. boolean pre_zero; /* pre-zero mode requested? */
  156121. boolean dirty; /* do current buffer contents need written? */
  156122. boolean b_s_open; /* is backing-store data valid? */
  156123. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156124. backing_store_info b_s_info; /* System-dependent control info */
  156125. };
  156126. struct jvirt_barray_control {
  156127. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156128. JDIMENSION rows_in_array; /* total virtual array height */
  156129. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156130. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156131. JDIMENSION rows_in_mem; /* height of memory buffer */
  156132. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156133. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156134. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156135. boolean pre_zero; /* pre-zero mode requested? */
  156136. boolean dirty; /* do current buffer contents need written? */
  156137. boolean b_s_open; /* is backing-store data valid? */
  156138. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156139. backing_store_info b_s_info; /* System-dependent control info */
  156140. };
  156141. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156142. LOCAL(void)
  156143. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156144. {
  156145. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156146. small_pool_ptr shdr_ptr;
  156147. large_pool_ptr lhdr_ptr;
  156148. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156149. pool_id, mem->total_space_allocated);
  156150. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156151. lhdr_ptr = lhdr_ptr->hdr.next) {
  156152. fprintf(stderr, " Large chunk used %ld\n",
  156153. (long) lhdr_ptr->hdr.bytes_used);
  156154. }
  156155. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156156. shdr_ptr = shdr_ptr->hdr.next) {
  156157. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156158. (long) shdr_ptr->hdr.bytes_used,
  156159. (long) shdr_ptr->hdr.bytes_left);
  156160. }
  156161. }
  156162. #endif /* MEM_STATS */
  156163. LOCAL(void)
  156164. out_of_memory (j_common_ptr cinfo, int which)
  156165. {
  156166. #ifdef MEM_STATS
  156167. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156168. #endif
  156169. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156170. }
  156171. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156172. {
  156173. 1600, /* first PERMANENT pool */
  156174. 16000 /* first IMAGE pool */
  156175. };
  156176. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156177. {
  156178. 0, /* additional PERMANENT pools */
  156179. 5000 /* additional IMAGE pools */
  156180. };
  156181. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156182. METHODDEF(void *)
  156183. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156184. {
  156185. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156186. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156187. char * data_ptr;
  156188. size_t odd_bytes, min_request, slop;
  156189. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156190. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156191. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156192. if (odd_bytes > 0)
  156193. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156194. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156195. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156196. prev_hdr_ptr = NULL;
  156197. hdr_ptr = mem->small_list[pool_id];
  156198. while (hdr_ptr != NULL) {
  156199. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156200. break; /* found pool with enough space */
  156201. prev_hdr_ptr = hdr_ptr;
  156202. hdr_ptr = hdr_ptr->hdr.next;
  156203. }
  156204. if (hdr_ptr == NULL) {
  156205. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156206. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156207. slop = first_pool_slop[pool_id];
  156208. else
  156209. slop = extra_pool_slop[pool_id];
  156210. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156211. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156212. for (;;) {
  156213. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156214. if (hdr_ptr != NULL)
  156215. break;
  156216. slop /= 2;
  156217. if (slop < MIN_SLOP) /* give up when it gets real small */
  156218. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156219. }
  156220. mem->total_space_allocated += min_request + slop;
  156221. hdr_ptr->hdr.next = NULL;
  156222. hdr_ptr->hdr.bytes_used = 0;
  156223. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156224. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156225. mem->small_list[pool_id] = hdr_ptr;
  156226. else
  156227. prev_hdr_ptr->hdr.next = hdr_ptr;
  156228. }
  156229. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156230. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156231. hdr_ptr->hdr.bytes_used += sizeofobject;
  156232. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156233. return (void *) data_ptr;
  156234. }
  156235. METHODDEF(void FAR *)
  156236. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156237. {
  156238. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156239. large_pool_ptr hdr_ptr;
  156240. size_t odd_bytes;
  156241. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156242. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156243. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156244. if (odd_bytes > 0)
  156245. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156246. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156247. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156248. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156249. SIZEOF(large_pool_hdr));
  156250. if (hdr_ptr == NULL)
  156251. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156252. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156253. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156254. hdr_ptr->hdr.bytes_used = sizeofobject;
  156255. hdr_ptr->hdr.bytes_left = 0;
  156256. mem->large_list[pool_id] = hdr_ptr;
  156257. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156258. }
  156259. METHODDEF(JSAMPARRAY)
  156260. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156261. JDIMENSION samplesperrow, JDIMENSION numrows)
  156262. {
  156263. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156264. JSAMPARRAY result;
  156265. JSAMPROW workspace;
  156266. JDIMENSION rowsperchunk, currow, i;
  156267. long ltemp;
  156268. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156269. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156270. if (ltemp <= 0)
  156271. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156272. if (ltemp < (long) numrows)
  156273. rowsperchunk = (JDIMENSION) ltemp;
  156274. else
  156275. rowsperchunk = numrows;
  156276. mem->last_rowsperchunk = rowsperchunk;
  156277. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156278. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156279. currow = 0;
  156280. while (currow < numrows) {
  156281. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156282. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156283. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156284. * SIZEOF(JSAMPLE)));
  156285. for (i = rowsperchunk; i > 0; i--) {
  156286. result[currow++] = workspace;
  156287. workspace += samplesperrow;
  156288. }
  156289. }
  156290. return result;
  156291. }
  156292. METHODDEF(JBLOCKARRAY)
  156293. alloc_barray (j_common_ptr cinfo, int pool_id,
  156294. JDIMENSION blocksperrow, JDIMENSION numrows)
  156295. {
  156296. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156297. JBLOCKARRAY result;
  156298. JBLOCKROW workspace;
  156299. JDIMENSION rowsperchunk, currow, i;
  156300. long ltemp;
  156301. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156302. ((long) blocksperrow * SIZEOF(JBLOCK));
  156303. if (ltemp <= 0)
  156304. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156305. if (ltemp < (long) numrows)
  156306. rowsperchunk = (JDIMENSION) ltemp;
  156307. else
  156308. rowsperchunk = numrows;
  156309. mem->last_rowsperchunk = rowsperchunk;
  156310. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156311. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156312. currow = 0;
  156313. while (currow < numrows) {
  156314. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156315. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156316. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156317. * SIZEOF(JBLOCK)));
  156318. for (i = rowsperchunk; i > 0; i--) {
  156319. result[currow++] = workspace;
  156320. workspace += blocksperrow;
  156321. }
  156322. }
  156323. return result;
  156324. }
  156325. METHODDEF(jvirt_sarray_ptr)
  156326. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156327. JDIMENSION samplesperrow, JDIMENSION numrows,
  156328. JDIMENSION maxaccess)
  156329. {
  156330. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156331. jvirt_sarray_ptr result;
  156332. if (pool_id != JPOOL_IMAGE)
  156333. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156334. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156335. SIZEOF(struct jvirt_sarray_control));
  156336. result->mem_buffer = NULL; /* marks array not yet realized */
  156337. result->rows_in_array = numrows;
  156338. result->samplesperrow = samplesperrow;
  156339. result->maxaccess = maxaccess;
  156340. result->pre_zero = pre_zero;
  156341. result->b_s_open = FALSE; /* no associated backing-store object */
  156342. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156343. mem->virt_sarray_list = result;
  156344. return result;
  156345. }
  156346. METHODDEF(jvirt_barray_ptr)
  156347. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156348. JDIMENSION blocksperrow, JDIMENSION numrows,
  156349. JDIMENSION maxaccess)
  156350. {
  156351. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156352. jvirt_barray_ptr result;
  156353. if (pool_id != JPOOL_IMAGE)
  156354. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156355. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156356. SIZEOF(struct jvirt_barray_control));
  156357. result->mem_buffer = NULL; /* marks array not yet realized */
  156358. result->rows_in_array = numrows;
  156359. result->blocksperrow = blocksperrow;
  156360. result->maxaccess = maxaccess;
  156361. result->pre_zero = pre_zero;
  156362. result->b_s_open = FALSE; /* no associated backing-store object */
  156363. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156364. mem->virt_barray_list = result;
  156365. return result;
  156366. }
  156367. METHODDEF(void)
  156368. realize_virt_arrays (j_common_ptr cinfo)
  156369. {
  156370. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156371. long space_per_minheight, maximum_space, avail_mem;
  156372. long minheights, max_minheights;
  156373. jvirt_sarray_ptr sptr;
  156374. jvirt_barray_ptr bptr;
  156375. space_per_minheight = 0;
  156376. maximum_space = 0;
  156377. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156378. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156379. space_per_minheight += (long) sptr->maxaccess *
  156380. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156381. maximum_space += (long) sptr->rows_in_array *
  156382. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156383. }
  156384. }
  156385. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156386. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156387. space_per_minheight += (long) bptr->maxaccess *
  156388. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156389. maximum_space += (long) bptr->rows_in_array *
  156390. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156391. }
  156392. }
  156393. if (space_per_minheight <= 0)
  156394. return; /* no unrealized arrays, no work */
  156395. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156396. mem->total_space_allocated);
  156397. if (avail_mem >= maximum_space)
  156398. max_minheights = 1000000000L;
  156399. else {
  156400. max_minheights = avail_mem / space_per_minheight;
  156401. if (max_minheights <= 0)
  156402. max_minheights = 1;
  156403. }
  156404. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156405. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156406. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156407. if (minheights <= max_minheights) {
  156408. sptr->rows_in_mem = sptr->rows_in_array;
  156409. } else {
  156410. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156411. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156412. (long) sptr->rows_in_array *
  156413. (long) sptr->samplesperrow *
  156414. (long) SIZEOF(JSAMPLE));
  156415. sptr->b_s_open = TRUE;
  156416. }
  156417. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156418. sptr->samplesperrow, sptr->rows_in_mem);
  156419. sptr->rowsperchunk = mem->last_rowsperchunk;
  156420. sptr->cur_start_row = 0;
  156421. sptr->first_undef_row = 0;
  156422. sptr->dirty = FALSE;
  156423. }
  156424. }
  156425. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156426. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156427. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156428. if (minheights <= max_minheights) {
  156429. bptr->rows_in_mem = bptr->rows_in_array;
  156430. } else {
  156431. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156432. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156433. (long) bptr->rows_in_array *
  156434. (long) bptr->blocksperrow *
  156435. (long) SIZEOF(JBLOCK));
  156436. bptr->b_s_open = TRUE;
  156437. }
  156438. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156439. bptr->blocksperrow, bptr->rows_in_mem);
  156440. bptr->rowsperchunk = mem->last_rowsperchunk;
  156441. bptr->cur_start_row = 0;
  156442. bptr->first_undef_row = 0;
  156443. bptr->dirty = FALSE;
  156444. }
  156445. }
  156446. }
  156447. LOCAL(void)
  156448. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156449. {
  156450. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156451. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156452. file_offset = ptr->cur_start_row * bytesperrow;
  156453. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156454. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156455. thisrow = (long) ptr->cur_start_row + i;
  156456. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156457. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156458. if (rows <= 0) /* this chunk might be past end of file! */
  156459. break;
  156460. byte_count = rows * bytesperrow;
  156461. if (writing)
  156462. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156463. (void FAR *) ptr->mem_buffer[i],
  156464. file_offset, byte_count);
  156465. else
  156466. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156467. (void FAR *) ptr->mem_buffer[i],
  156468. file_offset, byte_count);
  156469. file_offset += byte_count;
  156470. }
  156471. }
  156472. LOCAL(void)
  156473. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156474. {
  156475. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156476. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156477. file_offset = ptr->cur_start_row * bytesperrow;
  156478. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156479. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156480. thisrow = (long) ptr->cur_start_row + i;
  156481. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156482. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156483. if (rows <= 0) /* this chunk might be past end of file! */
  156484. break;
  156485. byte_count = rows * bytesperrow;
  156486. if (writing)
  156487. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156488. (void FAR *) ptr->mem_buffer[i],
  156489. file_offset, byte_count);
  156490. else
  156491. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156492. (void FAR *) ptr->mem_buffer[i],
  156493. file_offset, byte_count);
  156494. file_offset += byte_count;
  156495. }
  156496. }
  156497. METHODDEF(JSAMPARRAY)
  156498. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156499. JDIMENSION start_row, JDIMENSION num_rows,
  156500. boolean writable)
  156501. {
  156502. JDIMENSION end_row = start_row + num_rows;
  156503. JDIMENSION undef_row;
  156504. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156505. ptr->mem_buffer == NULL)
  156506. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156507. if (start_row < ptr->cur_start_row ||
  156508. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156509. if (! ptr->b_s_open)
  156510. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156511. if (ptr->dirty) {
  156512. do_sarray_io(cinfo, ptr, TRUE);
  156513. ptr->dirty = FALSE;
  156514. }
  156515. if (start_row > ptr->cur_start_row) {
  156516. ptr->cur_start_row = start_row;
  156517. } else {
  156518. long ltemp;
  156519. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156520. if (ltemp < 0)
  156521. ltemp = 0; /* don't fall off front end of file */
  156522. ptr->cur_start_row = (JDIMENSION) ltemp;
  156523. }
  156524. do_sarray_io(cinfo, ptr, FALSE);
  156525. }
  156526. if (ptr->first_undef_row < end_row) {
  156527. if (ptr->first_undef_row < start_row) {
  156528. if (writable) /* writer skipped over a section of array */
  156529. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156530. undef_row = start_row; /* but reader is allowed to read ahead */
  156531. } else {
  156532. undef_row = ptr->first_undef_row;
  156533. }
  156534. if (writable)
  156535. ptr->first_undef_row = end_row;
  156536. if (ptr->pre_zero) {
  156537. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156538. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156539. end_row -= ptr->cur_start_row;
  156540. while (undef_row < end_row) {
  156541. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156542. undef_row++;
  156543. }
  156544. } else {
  156545. if (! writable) /* reader looking at undefined data */
  156546. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156547. }
  156548. }
  156549. if (writable)
  156550. ptr->dirty = TRUE;
  156551. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156552. }
  156553. METHODDEF(JBLOCKARRAY)
  156554. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156555. JDIMENSION start_row, JDIMENSION num_rows,
  156556. boolean writable)
  156557. {
  156558. JDIMENSION end_row = start_row + num_rows;
  156559. JDIMENSION undef_row;
  156560. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156561. ptr->mem_buffer == NULL)
  156562. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156563. if (start_row < ptr->cur_start_row ||
  156564. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156565. if (! ptr->b_s_open)
  156566. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156567. if (ptr->dirty) {
  156568. do_barray_io(cinfo, ptr, TRUE);
  156569. ptr->dirty = FALSE;
  156570. }
  156571. if (start_row > ptr->cur_start_row) {
  156572. ptr->cur_start_row = start_row;
  156573. } else {
  156574. long ltemp;
  156575. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156576. if (ltemp < 0)
  156577. ltemp = 0; /* don't fall off front end of file */
  156578. ptr->cur_start_row = (JDIMENSION) ltemp;
  156579. }
  156580. do_barray_io(cinfo, ptr, FALSE);
  156581. }
  156582. if (ptr->first_undef_row < end_row) {
  156583. if (ptr->first_undef_row < start_row) {
  156584. if (writable) /* writer skipped over a section of array */
  156585. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156586. undef_row = start_row; /* but reader is allowed to read ahead */
  156587. } else {
  156588. undef_row = ptr->first_undef_row;
  156589. }
  156590. if (writable)
  156591. ptr->first_undef_row = end_row;
  156592. if (ptr->pre_zero) {
  156593. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156594. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156595. end_row -= ptr->cur_start_row;
  156596. while (undef_row < end_row) {
  156597. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156598. undef_row++;
  156599. }
  156600. } else {
  156601. if (! writable) /* reader looking at undefined data */
  156602. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156603. }
  156604. }
  156605. if (writable)
  156606. ptr->dirty = TRUE;
  156607. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156608. }
  156609. METHODDEF(void)
  156610. free_pool (j_common_ptr cinfo, int pool_id)
  156611. {
  156612. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156613. small_pool_ptr shdr_ptr;
  156614. large_pool_ptr lhdr_ptr;
  156615. size_t space_freed;
  156616. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156617. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156618. #ifdef MEM_STATS
  156619. if (cinfo->err->trace_level > 1)
  156620. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156621. #endif
  156622. if (pool_id == JPOOL_IMAGE) {
  156623. jvirt_sarray_ptr sptr;
  156624. jvirt_barray_ptr bptr;
  156625. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156626. if (sptr->b_s_open) { /* there may be no backing store */
  156627. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156628. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156629. }
  156630. }
  156631. mem->virt_sarray_list = NULL;
  156632. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156633. if (bptr->b_s_open) { /* there may be no backing store */
  156634. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156635. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156636. }
  156637. }
  156638. mem->virt_barray_list = NULL;
  156639. }
  156640. lhdr_ptr = mem->large_list[pool_id];
  156641. mem->large_list[pool_id] = NULL;
  156642. while (lhdr_ptr != NULL) {
  156643. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156644. space_freed = lhdr_ptr->hdr.bytes_used +
  156645. lhdr_ptr->hdr.bytes_left +
  156646. SIZEOF(large_pool_hdr);
  156647. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156648. mem->total_space_allocated -= space_freed;
  156649. lhdr_ptr = next_lhdr_ptr;
  156650. }
  156651. shdr_ptr = mem->small_list[pool_id];
  156652. mem->small_list[pool_id] = NULL;
  156653. while (shdr_ptr != NULL) {
  156654. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156655. space_freed = shdr_ptr->hdr.bytes_used +
  156656. shdr_ptr->hdr.bytes_left +
  156657. SIZEOF(small_pool_hdr);
  156658. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156659. mem->total_space_allocated -= space_freed;
  156660. shdr_ptr = next_shdr_ptr;
  156661. }
  156662. }
  156663. METHODDEF(void)
  156664. self_destruct (j_common_ptr cinfo)
  156665. {
  156666. int pool;
  156667. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156668. free_pool(cinfo, pool);
  156669. }
  156670. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156671. cinfo->mem = NULL; /* ensures I will be called only once */
  156672. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156673. }
  156674. GLOBAL(void)
  156675. jinit_memory_mgr (j_common_ptr cinfo)
  156676. {
  156677. my_mem_ptr mem;
  156678. long max_to_use;
  156679. int pool;
  156680. size_t test_mac;
  156681. cinfo->mem = NULL; /* for safety if init fails */
  156682. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156683. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156684. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156685. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156686. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156687. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156688. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156689. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156690. if (mem == NULL) {
  156691. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156692. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156693. }
  156694. mem->pub.alloc_small = alloc_small;
  156695. mem->pub.alloc_large = alloc_large;
  156696. mem->pub.alloc_sarray = alloc_sarray;
  156697. mem->pub.alloc_barray = alloc_barray;
  156698. mem->pub.request_virt_sarray = request_virt_sarray;
  156699. mem->pub.request_virt_barray = request_virt_barray;
  156700. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156701. mem->pub.access_virt_sarray = access_virt_sarray;
  156702. mem->pub.access_virt_barray = access_virt_barray;
  156703. mem->pub.free_pool = free_pool;
  156704. mem->pub.self_destruct = self_destruct;
  156705. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156706. mem->pub.max_memory_to_use = max_to_use;
  156707. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156708. mem->small_list[pool] = NULL;
  156709. mem->large_list[pool] = NULL;
  156710. }
  156711. mem->virt_sarray_list = NULL;
  156712. mem->virt_barray_list = NULL;
  156713. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156714. cinfo->mem = & mem->pub;
  156715. #ifndef NO_GETENV
  156716. { char * memenv;
  156717. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156718. char ch = 'x';
  156719. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156720. if (ch == 'm' || ch == 'M')
  156721. max_to_use *= 1000L;
  156722. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156723. }
  156724. }
  156725. }
  156726. #endif
  156727. }
  156728. /*** End of inlined file: jmemmgr.c ***/
  156729. /*** Start of inlined file: jmemnobs.c ***/
  156730. #define JPEG_INTERNALS
  156731. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156732. extern void * malloc JPP((size_t size));
  156733. extern void free JPP((void *ptr));
  156734. #endif
  156735. GLOBAL(void *)
  156736. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156737. {
  156738. return (void *) malloc(sizeofobject);
  156739. }
  156740. GLOBAL(void)
  156741. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156742. {
  156743. free(object);
  156744. }
  156745. GLOBAL(void FAR *)
  156746. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156747. {
  156748. return (void FAR *) malloc(sizeofobject);
  156749. }
  156750. GLOBAL(void)
  156751. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156752. {
  156753. free(object);
  156754. }
  156755. GLOBAL(long)
  156756. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156757. long max_bytes_needed, long already_allocated)
  156758. {
  156759. return max_bytes_needed;
  156760. }
  156761. GLOBAL(void)
  156762. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156763. long total_bytes_needed)
  156764. {
  156765. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156766. }
  156767. GLOBAL(long)
  156768. jpeg_mem_init (j_common_ptr cinfo)
  156769. {
  156770. return 0; /* just set max_memory_to_use to 0 */
  156771. }
  156772. GLOBAL(void)
  156773. jpeg_mem_term (j_common_ptr cinfo)
  156774. {
  156775. }
  156776. /*** End of inlined file: jmemnobs.c ***/
  156777. /*** Start of inlined file: jquant1.c ***/
  156778. #define JPEG_INTERNALS
  156779. #ifdef QUANT_1PASS_SUPPORTED
  156780. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156781. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156782. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156783. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156784. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156785. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156786. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156787. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156788. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156789. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156790. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156791. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156792. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156793. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156794. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156795. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156796. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156797. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156798. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156799. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156800. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156801. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156802. };
  156803. #if BITS_IN_JSAMPLE == 8
  156804. typedef INT16 FSERROR; /* 16 bits should be enough */
  156805. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156806. #else
  156807. typedef INT32 FSERROR; /* may need more than 16 bits */
  156808. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156809. #endif
  156810. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156811. #define MAX_Q_COMPS 4 /* max components I can handle */
  156812. typedef struct {
  156813. struct jpeg_color_quantizer pub; /* public fields */
  156814. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156815. int sv_actual; /* number of entries in use */
  156816. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156817. boolean is_padded; /* is the colorindex padded for odither? */
  156818. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156819. int row_index; /* cur row's vertical index in dither matrix */
  156820. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156821. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156822. boolean on_odd_row; /* flag to remember which row we are on */
  156823. } my_cquantizer;
  156824. typedef my_cquantizer * my_cquantize_ptr;
  156825. LOCAL(int)
  156826. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156827. {
  156828. int nc = cinfo->out_color_components; /* number of color components */
  156829. int max_colors = cinfo->desired_number_of_colors;
  156830. int total_colors, iroot, i, j;
  156831. boolean changed;
  156832. long temp;
  156833. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156834. iroot = 1;
  156835. do {
  156836. iroot++;
  156837. temp = iroot; /* set temp = iroot ** nc */
  156838. for (i = 1; i < nc; i++)
  156839. temp *= iroot;
  156840. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156841. iroot--; /* now iroot = floor(root) */
  156842. if (iroot < 2)
  156843. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156844. total_colors = 1;
  156845. for (i = 0; i < nc; i++) {
  156846. Ncolors[i] = iroot;
  156847. total_colors *= iroot;
  156848. }
  156849. do {
  156850. changed = FALSE;
  156851. for (i = 0; i < nc; i++) {
  156852. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156853. temp = total_colors / Ncolors[j];
  156854. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156855. if (temp > (long) max_colors)
  156856. break; /* won't fit, done with this pass */
  156857. Ncolors[j]++; /* OK, apply the increment */
  156858. total_colors = (int) temp;
  156859. changed = TRUE;
  156860. }
  156861. } while (changed);
  156862. return total_colors;
  156863. }
  156864. LOCAL(int)
  156865. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156866. {
  156867. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156868. }
  156869. LOCAL(int)
  156870. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156871. {
  156872. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156873. }
  156874. LOCAL(void)
  156875. create_colormap (j_decompress_ptr cinfo)
  156876. {
  156877. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156878. JSAMPARRAY colormap; /* Created colormap */
  156879. int total_colors; /* Number of distinct output colors */
  156880. int i,j,k, nci, blksize, blkdist, ptr, val;
  156881. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156882. if (cinfo->out_color_components == 3)
  156883. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156884. total_colors, cquantize->Ncolors[0],
  156885. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156886. else
  156887. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156888. colormap = (*cinfo->mem->alloc_sarray)
  156889. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156890. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156891. blkdist = total_colors;
  156892. for (i = 0; i < cinfo->out_color_components; i++) {
  156893. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156894. blksize = blkdist / nci;
  156895. for (j = 0; j < nci; j++) {
  156896. val = output_value(cinfo, i, j, nci-1);
  156897. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156898. for (k = 0; k < blksize; k++)
  156899. colormap[i][ptr+k] = (JSAMPLE) val;
  156900. }
  156901. }
  156902. blkdist = blksize; /* blksize of this color is blkdist of next */
  156903. }
  156904. cquantize->sv_colormap = colormap;
  156905. cquantize->sv_actual = total_colors;
  156906. }
  156907. LOCAL(void)
  156908. create_colorindex (j_decompress_ptr cinfo)
  156909. {
  156910. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156911. JSAMPROW indexptr;
  156912. int i,j,k, nci, blksize, val, pad;
  156913. if (cinfo->dither_mode == JDITHER_ORDERED) {
  156914. pad = MAXJSAMPLE*2;
  156915. cquantize->is_padded = TRUE;
  156916. } else {
  156917. pad = 0;
  156918. cquantize->is_padded = FALSE;
  156919. }
  156920. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  156921. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156922. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  156923. (JDIMENSION) cinfo->out_color_components);
  156924. blksize = cquantize->sv_actual;
  156925. for (i = 0; i < cinfo->out_color_components; i++) {
  156926. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156927. blksize = blksize / nci;
  156928. if (pad)
  156929. cquantize->colorindex[i] += MAXJSAMPLE;
  156930. indexptr = cquantize->colorindex[i];
  156931. val = 0;
  156932. k = largest_input_value(cinfo, i, 0, nci-1);
  156933. for (j = 0; j <= MAXJSAMPLE; j++) {
  156934. while (j > k) /* advance val if past boundary */
  156935. k = largest_input_value(cinfo, i, ++val, nci-1);
  156936. indexptr[j] = (JSAMPLE) (val * blksize);
  156937. }
  156938. if (pad)
  156939. for (j = 1; j <= MAXJSAMPLE; j++) {
  156940. indexptr[-j] = indexptr[0];
  156941. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  156942. }
  156943. }
  156944. }
  156945. LOCAL(ODITHER_MATRIX_PTR)
  156946. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  156947. {
  156948. ODITHER_MATRIX_PTR odither;
  156949. int j,k;
  156950. INT32 num,den;
  156951. odither = (ODITHER_MATRIX_PTR)
  156952. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156953. SIZEOF(ODITHER_MATRIX));
  156954. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  156955. for (j = 0; j < ODITHER_SIZE; j++) {
  156956. for (k = 0; k < ODITHER_SIZE; k++) {
  156957. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  156958. * MAXJSAMPLE;
  156959. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  156960. }
  156961. }
  156962. return odither;
  156963. }
  156964. LOCAL(void)
  156965. create_odither_tables (j_decompress_ptr cinfo)
  156966. {
  156967. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156968. ODITHER_MATRIX_PTR odither;
  156969. int i, j, nci;
  156970. for (i = 0; i < cinfo->out_color_components; i++) {
  156971. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156972. odither = NULL; /* search for matching prior component */
  156973. for (j = 0; j < i; j++) {
  156974. if (nci == cquantize->Ncolors[j]) {
  156975. odither = cquantize->odither[j];
  156976. break;
  156977. }
  156978. }
  156979. if (odither == NULL) /* need a new table? */
  156980. odither = make_odither_array(cinfo, nci);
  156981. cquantize->odither[i] = odither;
  156982. }
  156983. }
  156984. METHODDEF(void)
  156985. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156986. JSAMPARRAY output_buf, int num_rows)
  156987. {
  156988. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156989. JSAMPARRAY colorindex = cquantize->colorindex;
  156990. register int pixcode, ci;
  156991. register JSAMPROW ptrin, ptrout;
  156992. int row;
  156993. JDIMENSION col;
  156994. JDIMENSION width = cinfo->output_width;
  156995. register int nc = cinfo->out_color_components;
  156996. for (row = 0; row < num_rows; row++) {
  156997. ptrin = input_buf[row];
  156998. ptrout = output_buf[row];
  156999. for (col = width; col > 0; col--) {
  157000. pixcode = 0;
  157001. for (ci = 0; ci < nc; ci++) {
  157002. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157003. }
  157004. *ptrout++ = (JSAMPLE) pixcode;
  157005. }
  157006. }
  157007. }
  157008. METHODDEF(void)
  157009. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157010. JSAMPARRAY output_buf, int num_rows)
  157011. {
  157012. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157013. register int pixcode;
  157014. register JSAMPROW ptrin, ptrout;
  157015. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157016. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157017. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157018. int row;
  157019. JDIMENSION col;
  157020. JDIMENSION width = cinfo->output_width;
  157021. for (row = 0; row < num_rows; row++) {
  157022. ptrin = input_buf[row];
  157023. ptrout = output_buf[row];
  157024. for (col = width; col > 0; col--) {
  157025. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157026. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157027. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157028. *ptrout++ = (JSAMPLE) pixcode;
  157029. }
  157030. }
  157031. }
  157032. METHODDEF(void)
  157033. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157034. JSAMPARRAY output_buf, int num_rows)
  157035. {
  157036. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157037. register JSAMPROW input_ptr;
  157038. register JSAMPROW output_ptr;
  157039. JSAMPROW colorindex_ci;
  157040. int * dither; /* points to active row of dither matrix */
  157041. int row_index, col_index; /* current indexes into dither matrix */
  157042. int nc = cinfo->out_color_components;
  157043. int ci;
  157044. int row;
  157045. JDIMENSION col;
  157046. JDIMENSION width = cinfo->output_width;
  157047. for (row = 0; row < num_rows; row++) {
  157048. jzero_far((void FAR *) output_buf[row],
  157049. (size_t) (width * SIZEOF(JSAMPLE)));
  157050. row_index = cquantize->row_index;
  157051. for (ci = 0; ci < nc; ci++) {
  157052. input_ptr = input_buf[row] + ci;
  157053. output_ptr = output_buf[row];
  157054. colorindex_ci = cquantize->colorindex[ci];
  157055. dither = cquantize->odither[ci][row_index];
  157056. col_index = 0;
  157057. for (col = width; col > 0; col--) {
  157058. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157059. input_ptr += nc;
  157060. output_ptr++;
  157061. col_index = (col_index + 1) & ODITHER_MASK;
  157062. }
  157063. }
  157064. row_index = (row_index + 1) & ODITHER_MASK;
  157065. cquantize->row_index = row_index;
  157066. }
  157067. }
  157068. METHODDEF(void)
  157069. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157070. JSAMPARRAY output_buf, int num_rows)
  157071. {
  157072. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157073. register int pixcode;
  157074. register JSAMPROW input_ptr;
  157075. register JSAMPROW output_ptr;
  157076. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157077. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157078. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157079. int * dither0; /* points to active row of dither matrix */
  157080. int * dither1;
  157081. int * dither2;
  157082. int row_index, col_index; /* current indexes into dither matrix */
  157083. int row;
  157084. JDIMENSION col;
  157085. JDIMENSION width = cinfo->output_width;
  157086. for (row = 0; row < num_rows; row++) {
  157087. row_index = cquantize->row_index;
  157088. input_ptr = input_buf[row];
  157089. output_ptr = output_buf[row];
  157090. dither0 = cquantize->odither[0][row_index];
  157091. dither1 = cquantize->odither[1][row_index];
  157092. dither2 = cquantize->odither[2][row_index];
  157093. col_index = 0;
  157094. for (col = width; col > 0; col--) {
  157095. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157096. dither0[col_index]]);
  157097. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157098. dither1[col_index]]);
  157099. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157100. dither2[col_index]]);
  157101. *output_ptr++ = (JSAMPLE) pixcode;
  157102. col_index = (col_index + 1) & ODITHER_MASK;
  157103. }
  157104. row_index = (row_index + 1) & ODITHER_MASK;
  157105. cquantize->row_index = row_index;
  157106. }
  157107. }
  157108. METHODDEF(void)
  157109. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157110. JSAMPARRAY output_buf, int num_rows)
  157111. {
  157112. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157113. register LOCFSERROR cur; /* current error or pixel value */
  157114. LOCFSERROR belowerr; /* error for pixel below cur */
  157115. LOCFSERROR bpreverr; /* error for below/prev col */
  157116. LOCFSERROR bnexterr; /* error for below/next col */
  157117. LOCFSERROR delta;
  157118. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157119. register JSAMPROW input_ptr;
  157120. register JSAMPROW output_ptr;
  157121. JSAMPROW colorindex_ci;
  157122. JSAMPROW colormap_ci;
  157123. int pixcode;
  157124. int nc = cinfo->out_color_components;
  157125. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157126. int dirnc; /* dir * nc */
  157127. int ci;
  157128. int row;
  157129. JDIMENSION col;
  157130. JDIMENSION width = cinfo->output_width;
  157131. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157132. SHIFT_TEMPS
  157133. for (row = 0; row < num_rows; row++) {
  157134. jzero_far((void FAR *) output_buf[row],
  157135. (size_t) (width * SIZEOF(JSAMPLE)));
  157136. for (ci = 0; ci < nc; ci++) {
  157137. input_ptr = input_buf[row] + ci;
  157138. output_ptr = output_buf[row];
  157139. if (cquantize->on_odd_row) {
  157140. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157141. output_ptr += width-1;
  157142. dir = -1;
  157143. dirnc = -nc;
  157144. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157145. } else {
  157146. dir = 1;
  157147. dirnc = nc;
  157148. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157149. }
  157150. colorindex_ci = cquantize->colorindex[ci];
  157151. colormap_ci = cquantize->sv_colormap[ci];
  157152. cur = 0;
  157153. belowerr = bpreverr = 0;
  157154. for (col = width; col > 0; col--) {
  157155. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157156. cur += GETJSAMPLE(*input_ptr);
  157157. cur = GETJSAMPLE(range_limit[cur]);
  157158. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157159. *output_ptr += (JSAMPLE) pixcode;
  157160. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157161. bnexterr = cur;
  157162. delta = cur * 2;
  157163. cur += delta; /* form error * 3 */
  157164. errorptr[0] = (FSERROR) (bpreverr + cur);
  157165. cur += delta; /* form error * 5 */
  157166. bpreverr = belowerr + cur;
  157167. belowerr = bnexterr;
  157168. cur += delta; /* form error * 7 */
  157169. input_ptr += dirnc; /* advance input ptr to next column */
  157170. output_ptr += dir; /* advance output ptr to next column */
  157171. errorptr += dir; /* advance errorptr to current column */
  157172. }
  157173. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157174. }
  157175. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157176. }
  157177. }
  157178. LOCAL(void)
  157179. alloc_fs_workspace (j_decompress_ptr cinfo)
  157180. {
  157181. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157182. size_t arraysize;
  157183. int i;
  157184. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157185. for (i = 0; i < cinfo->out_color_components; i++) {
  157186. cquantize->fserrors[i] = (FSERRPTR)
  157187. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157188. }
  157189. }
  157190. METHODDEF(void)
  157191. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157192. {
  157193. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157194. size_t arraysize;
  157195. int i;
  157196. cinfo->colormap = cquantize->sv_colormap;
  157197. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157198. switch (cinfo->dither_mode) {
  157199. case JDITHER_NONE:
  157200. if (cinfo->out_color_components == 3)
  157201. cquantize->pub.color_quantize = color_quantize3;
  157202. else
  157203. cquantize->pub.color_quantize = color_quantize;
  157204. break;
  157205. case JDITHER_ORDERED:
  157206. if (cinfo->out_color_components == 3)
  157207. cquantize->pub.color_quantize = quantize3_ord_dither;
  157208. else
  157209. cquantize->pub.color_quantize = quantize_ord_dither;
  157210. cquantize->row_index = 0; /* initialize state for ordered dither */
  157211. if (! cquantize->is_padded)
  157212. create_colorindex(cinfo);
  157213. if (cquantize->odither[0] == NULL)
  157214. create_odither_tables(cinfo);
  157215. break;
  157216. case JDITHER_FS:
  157217. cquantize->pub.color_quantize = quantize_fs_dither;
  157218. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157219. if (cquantize->fserrors[0] == NULL)
  157220. alloc_fs_workspace(cinfo);
  157221. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157222. for (i = 0; i < cinfo->out_color_components; i++)
  157223. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157224. break;
  157225. default:
  157226. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157227. break;
  157228. }
  157229. }
  157230. METHODDEF(void)
  157231. finish_pass_1_quant (j_decompress_ptr cinfo)
  157232. {
  157233. }
  157234. METHODDEF(void)
  157235. new_color_map_1_quant (j_decompress_ptr cinfo)
  157236. {
  157237. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157238. }
  157239. GLOBAL(void)
  157240. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157241. {
  157242. my_cquantize_ptr cquantize;
  157243. cquantize = (my_cquantize_ptr)
  157244. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157245. SIZEOF(my_cquantizer));
  157246. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157247. cquantize->pub.start_pass = start_pass_1_quant;
  157248. cquantize->pub.finish_pass = finish_pass_1_quant;
  157249. cquantize->pub.new_color_map = new_color_map_1_quant;
  157250. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157251. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157252. if (cinfo->out_color_components > MAX_Q_COMPS)
  157253. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157254. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157255. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157256. create_colormap(cinfo);
  157257. create_colorindex(cinfo);
  157258. if (cinfo->dither_mode == JDITHER_FS)
  157259. alloc_fs_workspace(cinfo);
  157260. }
  157261. #endif /* QUANT_1PASS_SUPPORTED */
  157262. /*** End of inlined file: jquant1.c ***/
  157263. /*** Start of inlined file: jquant2.c ***/
  157264. #define JPEG_INTERNALS
  157265. #ifdef QUANT_2PASS_SUPPORTED
  157266. #define R_SCALE 2 /* scale R distances by this much */
  157267. #define G_SCALE 3 /* scale G distances by this much */
  157268. #define B_SCALE 1 /* and B by this much */
  157269. #if RGB_RED == 0
  157270. #define C0_SCALE R_SCALE
  157271. #endif
  157272. #if RGB_BLUE == 0
  157273. #define C0_SCALE B_SCALE
  157274. #endif
  157275. #if RGB_GREEN == 1
  157276. #define C1_SCALE G_SCALE
  157277. #endif
  157278. #if RGB_RED == 2
  157279. #define C2_SCALE R_SCALE
  157280. #endif
  157281. #if RGB_BLUE == 2
  157282. #define C2_SCALE B_SCALE
  157283. #endif
  157284. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157285. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157286. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157287. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157288. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157289. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157290. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157291. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157292. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157293. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157294. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157295. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157296. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157297. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157298. typedef hist2d * hist3d; /* type for top-level pointer */
  157299. #if BITS_IN_JSAMPLE == 8
  157300. typedef INT16 FSERROR; /* 16 bits should be enough */
  157301. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157302. #else
  157303. typedef INT32 FSERROR; /* may need more than 16 bits */
  157304. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157305. #endif
  157306. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157307. typedef struct {
  157308. struct jpeg_color_quantizer pub; /* public fields */
  157309. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157310. int desired; /* desired # of colors = size of colormap */
  157311. hist3d histogram; /* pointer to the histogram */
  157312. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157313. FSERRPTR fserrors; /* accumulated errors */
  157314. boolean on_odd_row; /* flag to remember which row we are on */
  157315. int * error_limiter; /* table for clamping the applied error */
  157316. } my_cquantizer2;
  157317. typedef my_cquantizer2 * my_cquantize_ptr2;
  157318. METHODDEF(void)
  157319. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157320. JSAMPARRAY output_buf, int num_rows)
  157321. {
  157322. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157323. register JSAMPROW ptr;
  157324. register histptr histp;
  157325. register hist3d histogram = cquantize->histogram;
  157326. int row;
  157327. JDIMENSION col;
  157328. JDIMENSION width = cinfo->output_width;
  157329. for (row = 0; row < num_rows; row++) {
  157330. ptr = input_buf[row];
  157331. for (col = width; col > 0; col--) {
  157332. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157333. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157334. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157335. if (++(*histp) <= 0)
  157336. (*histp)--;
  157337. ptr += 3;
  157338. }
  157339. }
  157340. }
  157341. typedef struct {
  157342. int c0min, c0max;
  157343. int c1min, c1max;
  157344. int c2min, c2max;
  157345. INT32 volume;
  157346. long colorcount;
  157347. } box;
  157348. typedef box * boxptr;
  157349. LOCAL(boxptr)
  157350. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157351. {
  157352. register boxptr boxp;
  157353. register int i;
  157354. register long maxc = 0;
  157355. boxptr which = NULL;
  157356. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157357. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157358. which = boxp;
  157359. maxc = boxp->colorcount;
  157360. }
  157361. }
  157362. return which;
  157363. }
  157364. LOCAL(boxptr)
  157365. find_biggest_volume (boxptr boxlist, int numboxes)
  157366. {
  157367. register boxptr boxp;
  157368. register int i;
  157369. register INT32 maxv = 0;
  157370. boxptr which = NULL;
  157371. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157372. if (boxp->volume > maxv) {
  157373. which = boxp;
  157374. maxv = boxp->volume;
  157375. }
  157376. }
  157377. return which;
  157378. }
  157379. LOCAL(void)
  157380. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157381. {
  157382. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157383. hist3d histogram = cquantize->histogram;
  157384. histptr histp;
  157385. int c0,c1,c2;
  157386. int c0min,c0max,c1min,c1max,c2min,c2max;
  157387. INT32 dist0,dist1,dist2;
  157388. long ccount;
  157389. c0min = boxp->c0min; c0max = boxp->c0max;
  157390. c1min = boxp->c1min; c1max = boxp->c1max;
  157391. c2min = boxp->c2min; c2max = boxp->c2max;
  157392. if (c0max > c0min)
  157393. for (c0 = c0min; c0 <= c0max; c0++)
  157394. for (c1 = c1min; c1 <= c1max; c1++) {
  157395. histp = & histogram[c0][c1][c2min];
  157396. for (c2 = c2min; c2 <= c2max; c2++)
  157397. if (*histp++ != 0) {
  157398. boxp->c0min = c0min = c0;
  157399. goto have_c0min;
  157400. }
  157401. }
  157402. have_c0min:
  157403. if (c0max > c0min)
  157404. for (c0 = c0max; c0 >= c0min; 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->c0max = c0max = c0;
  157410. goto have_c0max;
  157411. }
  157412. }
  157413. have_c0max:
  157414. if (c1max > c1min)
  157415. for (c1 = c1min; c1 <= c1max; c1++)
  157416. for (c0 = c0min; c0 <= c0max; c0++) {
  157417. histp = & histogram[c0][c1][c2min];
  157418. for (c2 = c2min; c2 <= c2max; c2++)
  157419. if (*histp++ != 0) {
  157420. boxp->c1min = c1min = c1;
  157421. goto have_c1min;
  157422. }
  157423. }
  157424. have_c1min:
  157425. if (c1max > c1min)
  157426. for (c1 = c1max; c1 >= c1min; 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->c1max = c1max = c1;
  157432. goto have_c1max;
  157433. }
  157434. }
  157435. have_c1max:
  157436. if (c2max > c2min)
  157437. for (c2 = c2min; c2 <= c2max; c2++)
  157438. for (c0 = c0min; c0 <= c0max; c0++) {
  157439. histp = & histogram[c0][c1min][c2];
  157440. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157441. if (*histp != 0) {
  157442. boxp->c2min = c2min = c2;
  157443. goto have_c2min;
  157444. }
  157445. }
  157446. have_c2min:
  157447. if (c2max > c2min)
  157448. for (c2 = c2max; c2 >= c2min; 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->c2max = c2max = c2;
  157454. goto have_c2max;
  157455. }
  157456. }
  157457. have_c2max:
  157458. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157459. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157460. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157461. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157462. ccount = 0;
  157463. for (c0 = c0min; c0 <= c0max; c0++)
  157464. for (c1 = c1min; c1 <= c1max; c1++) {
  157465. histp = & histogram[c0][c1][c2min];
  157466. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157467. if (*histp != 0) {
  157468. ccount++;
  157469. }
  157470. }
  157471. boxp->colorcount = ccount;
  157472. }
  157473. LOCAL(int)
  157474. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157475. int desired_colors)
  157476. {
  157477. int n,lb;
  157478. int c0,c1,c2,cmax;
  157479. register boxptr b1,b2;
  157480. while (numboxes < desired_colors) {
  157481. if (numboxes*2 <= desired_colors) {
  157482. b1 = find_biggest_color_pop(boxlist, numboxes);
  157483. } else {
  157484. b1 = find_biggest_volume(boxlist, numboxes);
  157485. }
  157486. if (b1 == NULL) /* no splittable boxes left! */
  157487. break;
  157488. b2 = &boxlist[numboxes]; /* where new box will go */
  157489. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157490. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157491. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157492. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157493. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157494. #if RGB_RED == 0
  157495. cmax = c1; n = 1;
  157496. if (c0 > cmax) { cmax = c0; n = 0; }
  157497. if (c2 > cmax) { n = 2; }
  157498. #else
  157499. cmax = c1; n = 1;
  157500. if (c2 > cmax) { cmax = c2; n = 2; }
  157501. if (c0 > cmax) { n = 0; }
  157502. #endif
  157503. switch (n) {
  157504. case 0:
  157505. lb = (b1->c0max + b1->c0min) / 2;
  157506. b1->c0max = lb;
  157507. b2->c0min = lb+1;
  157508. break;
  157509. case 1:
  157510. lb = (b1->c1max + b1->c1min) / 2;
  157511. b1->c1max = lb;
  157512. b2->c1min = lb+1;
  157513. break;
  157514. case 2:
  157515. lb = (b1->c2max + b1->c2min) / 2;
  157516. b1->c2max = lb;
  157517. b2->c2min = lb+1;
  157518. break;
  157519. }
  157520. update_box(cinfo, b1);
  157521. update_box(cinfo, b2);
  157522. numboxes++;
  157523. }
  157524. return numboxes;
  157525. }
  157526. LOCAL(void)
  157527. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157528. {
  157529. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157530. hist3d histogram = cquantize->histogram;
  157531. histptr histp;
  157532. int c0,c1,c2;
  157533. int c0min,c0max,c1min,c1max,c2min,c2max;
  157534. long count;
  157535. long total = 0;
  157536. long c0total = 0;
  157537. long c1total = 0;
  157538. long c2total = 0;
  157539. c0min = boxp->c0min; c0max = boxp->c0max;
  157540. c1min = boxp->c1min; c1max = boxp->c1max;
  157541. c2min = boxp->c2min; c2max = boxp->c2max;
  157542. for (c0 = c0min; c0 <= c0max; c0++)
  157543. for (c1 = c1min; c1 <= c1max; c1++) {
  157544. histp = & histogram[c0][c1][c2min];
  157545. for (c2 = c2min; c2 <= c2max; c2++) {
  157546. if ((count = *histp++) != 0) {
  157547. total += count;
  157548. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157549. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157550. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157551. }
  157552. }
  157553. }
  157554. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157555. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157556. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157557. }
  157558. LOCAL(void)
  157559. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157560. {
  157561. boxptr boxlist;
  157562. int numboxes;
  157563. int i;
  157564. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157565. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157566. numboxes = 1;
  157567. boxlist[0].c0min = 0;
  157568. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157569. boxlist[0].c1min = 0;
  157570. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157571. boxlist[0].c2min = 0;
  157572. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157573. update_box(cinfo, & boxlist[0]);
  157574. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157575. for (i = 0; i < numboxes; i++)
  157576. compute_color(cinfo, & boxlist[i], i);
  157577. cinfo->actual_number_of_colors = numboxes;
  157578. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157579. }
  157580. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157581. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157582. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157583. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157584. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157585. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157586. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157587. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157588. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157589. LOCAL(int)
  157590. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157591. JSAMPLE colorlist[])
  157592. {
  157593. int numcolors = cinfo->actual_number_of_colors;
  157594. int maxc0, maxc1, maxc2;
  157595. int centerc0, centerc1, centerc2;
  157596. int i, x, ncolors;
  157597. INT32 minmaxdist, min_dist, max_dist, tdist;
  157598. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157599. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157600. centerc0 = (minc0 + maxc0) >> 1;
  157601. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157602. centerc1 = (minc1 + maxc1) >> 1;
  157603. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157604. centerc2 = (minc2 + maxc2) >> 1;
  157605. minmaxdist = 0x7FFFFFFFL;
  157606. for (i = 0; i < numcolors; i++) {
  157607. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157608. if (x < minc0) {
  157609. tdist = (x - minc0) * C0_SCALE;
  157610. min_dist = tdist*tdist;
  157611. tdist = (x - maxc0) * C0_SCALE;
  157612. max_dist = tdist*tdist;
  157613. } else if (x > maxc0) {
  157614. tdist = (x - maxc0) * C0_SCALE;
  157615. min_dist = tdist*tdist;
  157616. tdist = (x - minc0) * C0_SCALE;
  157617. max_dist = tdist*tdist;
  157618. } else {
  157619. min_dist = 0;
  157620. if (x <= centerc0) {
  157621. tdist = (x - maxc0) * C0_SCALE;
  157622. max_dist = tdist*tdist;
  157623. } else {
  157624. tdist = (x - minc0) * C0_SCALE;
  157625. max_dist = tdist*tdist;
  157626. }
  157627. }
  157628. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157629. if (x < minc1) {
  157630. tdist = (x - minc1) * C1_SCALE;
  157631. min_dist += tdist*tdist;
  157632. tdist = (x - maxc1) * C1_SCALE;
  157633. max_dist += tdist*tdist;
  157634. } else if (x > maxc1) {
  157635. tdist = (x - maxc1) * C1_SCALE;
  157636. min_dist += tdist*tdist;
  157637. tdist = (x - minc1) * C1_SCALE;
  157638. max_dist += tdist*tdist;
  157639. } else {
  157640. if (x <= centerc1) {
  157641. tdist = (x - maxc1) * C1_SCALE;
  157642. max_dist += tdist*tdist;
  157643. } else {
  157644. tdist = (x - minc1) * C1_SCALE;
  157645. max_dist += tdist*tdist;
  157646. }
  157647. }
  157648. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157649. if (x < minc2) {
  157650. tdist = (x - minc2) * C2_SCALE;
  157651. min_dist += tdist*tdist;
  157652. tdist = (x - maxc2) * C2_SCALE;
  157653. max_dist += tdist*tdist;
  157654. } else if (x > maxc2) {
  157655. tdist = (x - maxc2) * C2_SCALE;
  157656. min_dist += tdist*tdist;
  157657. tdist = (x - minc2) * C2_SCALE;
  157658. max_dist += tdist*tdist;
  157659. } else {
  157660. if (x <= centerc2) {
  157661. tdist = (x - maxc2) * C2_SCALE;
  157662. max_dist += tdist*tdist;
  157663. } else {
  157664. tdist = (x - minc2) * C2_SCALE;
  157665. max_dist += tdist*tdist;
  157666. }
  157667. }
  157668. mindist[i] = min_dist; /* save away the results */
  157669. if (max_dist < minmaxdist)
  157670. minmaxdist = max_dist;
  157671. }
  157672. ncolors = 0;
  157673. for (i = 0; i < numcolors; i++) {
  157674. if (mindist[i] <= minmaxdist)
  157675. colorlist[ncolors++] = (JSAMPLE) i;
  157676. }
  157677. return ncolors;
  157678. }
  157679. LOCAL(void)
  157680. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157681. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157682. {
  157683. int ic0, ic1, ic2;
  157684. int i, icolor;
  157685. register INT32 * bptr; /* pointer into bestdist[] array */
  157686. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157687. INT32 dist0, dist1; /* initial distance values */
  157688. register INT32 dist2; /* current distance in inner loop */
  157689. INT32 xx0, xx1; /* distance increments */
  157690. register INT32 xx2;
  157691. INT32 inc0, inc1, inc2; /* initial values for increments */
  157692. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157693. bptr = bestdist;
  157694. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157695. *bptr++ = 0x7FFFFFFFL;
  157696. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157697. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157698. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157699. for (i = 0; i < numcolors; i++) {
  157700. icolor = GETJSAMPLE(colorlist[i]);
  157701. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157702. dist0 = inc0*inc0;
  157703. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157704. dist0 += inc1*inc1;
  157705. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157706. dist0 += inc2*inc2;
  157707. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157708. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157709. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157710. bptr = bestdist;
  157711. cptr = bestcolor;
  157712. xx0 = inc0;
  157713. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157714. dist1 = dist0;
  157715. xx1 = inc1;
  157716. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157717. dist2 = dist1;
  157718. xx2 = inc2;
  157719. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157720. if (dist2 < *bptr) {
  157721. *bptr = dist2;
  157722. *cptr = (JSAMPLE) icolor;
  157723. }
  157724. dist2 += xx2;
  157725. xx2 += 2 * STEP_C2 * STEP_C2;
  157726. bptr++;
  157727. cptr++;
  157728. }
  157729. dist1 += xx1;
  157730. xx1 += 2 * STEP_C1 * STEP_C1;
  157731. }
  157732. dist0 += xx0;
  157733. xx0 += 2 * STEP_C0 * STEP_C0;
  157734. }
  157735. }
  157736. }
  157737. LOCAL(void)
  157738. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157739. {
  157740. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157741. hist3d histogram = cquantize->histogram;
  157742. int minc0, minc1, minc2; /* lower left corner of update box */
  157743. int ic0, ic1, ic2;
  157744. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157745. register histptr cachep; /* pointer into main cache array */
  157746. JSAMPLE colorlist[MAXNUMCOLORS];
  157747. int numcolors; /* number of candidate colors */
  157748. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157749. c0 >>= BOX_C0_LOG;
  157750. c1 >>= BOX_C1_LOG;
  157751. c2 >>= BOX_C2_LOG;
  157752. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157753. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157754. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157755. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157756. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157757. bestcolor);
  157758. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157759. c1 <<= BOX_C1_LOG;
  157760. c2 <<= BOX_C2_LOG;
  157761. cptr = bestcolor;
  157762. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157763. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157764. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157765. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157766. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157767. }
  157768. }
  157769. }
  157770. }
  157771. METHODDEF(void)
  157772. pass2_no_dither (j_decompress_ptr cinfo,
  157773. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157774. {
  157775. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157776. hist3d histogram = cquantize->histogram;
  157777. register JSAMPROW inptr, outptr;
  157778. register histptr cachep;
  157779. register int c0, c1, c2;
  157780. int row;
  157781. JDIMENSION col;
  157782. JDIMENSION width = cinfo->output_width;
  157783. for (row = 0; row < num_rows; row++) {
  157784. inptr = input_buf[row];
  157785. outptr = output_buf[row];
  157786. for (col = width; col > 0; col--) {
  157787. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157788. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157789. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157790. cachep = & histogram[c0][c1][c2];
  157791. if (*cachep == 0)
  157792. fill_inverse_cmap(cinfo, c0,c1,c2);
  157793. *outptr++ = (JSAMPLE) (*cachep - 1);
  157794. }
  157795. }
  157796. }
  157797. METHODDEF(void)
  157798. pass2_fs_dither (j_decompress_ptr cinfo,
  157799. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157800. {
  157801. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157802. hist3d histogram = cquantize->histogram;
  157803. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157804. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157805. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157806. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157807. JSAMPROW inptr; /* => current input pixel */
  157808. JSAMPROW outptr; /* => current output pixel */
  157809. histptr cachep;
  157810. int dir; /* +1 or -1 depending on direction */
  157811. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157812. int row;
  157813. JDIMENSION col;
  157814. JDIMENSION width = cinfo->output_width;
  157815. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157816. int *error_limit = cquantize->error_limiter;
  157817. JSAMPROW colormap0 = cinfo->colormap[0];
  157818. JSAMPROW colormap1 = cinfo->colormap[1];
  157819. JSAMPROW colormap2 = cinfo->colormap[2];
  157820. SHIFT_TEMPS
  157821. for (row = 0; row < num_rows; row++) {
  157822. inptr = input_buf[row];
  157823. outptr = output_buf[row];
  157824. if (cquantize->on_odd_row) {
  157825. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157826. outptr += width-1;
  157827. dir = -1;
  157828. dir3 = -3;
  157829. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157830. cquantize->on_odd_row = FALSE; /* flip for next time */
  157831. } else {
  157832. dir = 1;
  157833. dir3 = 3;
  157834. errorptr = cquantize->fserrors; /* => entry before first real column */
  157835. cquantize->on_odd_row = TRUE; /* flip for next time */
  157836. }
  157837. cur0 = cur1 = cur2 = 0;
  157838. belowerr0 = belowerr1 = belowerr2 = 0;
  157839. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157840. for (col = width; col > 0; col--) {
  157841. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157842. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157843. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157844. cur0 = error_limit[cur0];
  157845. cur1 = error_limit[cur1];
  157846. cur2 = error_limit[cur2];
  157847. cur0 += GETJSAMPLE(inptr[0]);
  157848. cur1 += GETJSAMPLE(inptr[1]);
  157849. cur2 += GETJSAMPLE(inptr[2]);
  157850. cur0 = GETJSAMPLE(range_limit[cur0]);
  157851. cur1 = GETJSAMPLE(range_limit[cur1]);
  157852. cur2 = GETJSAMPLE(range_limit[cur2]);
  157853. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157854. if (*cachep == 0)
  157855. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157856. { register int pixcode = *cachep - 1;
  157857. *outptr = (JSAMPLE) pixcode;
  157858. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157859. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157860. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157861. }
  157862. { register LOCFSERROR bnexterr, delta;
  157863. bnexterr = cur0; /* Process component 0 */
  157864. delta = cur0 * 2;
  157865. cur0 += delta; /* form error * 3 */
  157866. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157867. cur0 += delta; /* form error * 5 */
  157868. bpreverr0 = belowerr0 + cur0;
  157869. belowerr0 = bnexterr;
  157870. cur0 += delta; /* form error * 7 */
  157871. bnexterr = cur1; /* Process component 1 */
  157872. delta = cur1 * 2;
  157873. cur1 += delta; /* form error * 3 */
  157874. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157875. cur1 += delta; /* form error * 5 */
  157876. bpreverr1 = belowerr1 + cur1;
  157877. belowerr1 = bnexterr;
  157878. cur1 += delta; /* form error * 7 */
  157879. bnexterr = cur2; /* Process component 2 */
  157880. delta = cur2 * 2;
  157881. cur2 += delta; /* form error * 3 */
  157882. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157883. cur2 += delta; /* form error * 5 */
  157884. bpreverr2 = belowerr2 + cur2;
  157885. belowerr2 = bnexterr;
  157886. cur2 += delta; /* form error * 7 */
  157887. }
  157888. inptr += dir3; /* Advance pixel pointers to next column */
  157889. outptr += dir;
  157890. errorptr += dir3; /* advance errorptr to current column */
  157891. }
  157892. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157893. errorptr[1] = (FSERROR) bpreverr1;
  157894. errorptr[2] = (FSERROR) bpreverr2;
  157895. }
  157896. }
  157897. LOCAL(void)
  157898. init_error_limit (j_decompress_ptr cinfo)
  157899. {
  157900. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157901. int * table;
  157902. int in, out;
  157903. table = (int *) (*cinfo->mem->alloc_small)
  157904. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157905. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157906. cquantize->error_limiter = table;
  157907. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157908. out = 0;
  157909. for (in = 0; in < STEPSIZE; in++, out++) {
  157910. table[in] = out; table[-in] = -out;
  157911. }
  157912. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  157913. table[in] = out; table[-in] = -out;
  157914. }
  157915. for (; in <= MAXJSAMPLE; in++) {
  157916. table[in] = out; table[-in] = -out;
  157917. }
  157918. #undef STEPSIZE
  157919. }
  157920. METHODDEF(void)
  157921. finish_pass1 (j_decompress_ptr cinfo)
  157922. {
  157923. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157924. cinfo->colormap = cquantize->sv_colormap;
  157925. select_colors(cinfo, cquantize->desired);
  157926. cquantize->needs_zeroed = TRUE;
  157927. }
  157928. METHODDEF(void)
  157929. finish_pass2 (j_decompress_ptr cinfo)
  157930. {
  157931. }
  157932. METHODDEF(void)
  157933. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157934. {
  157935. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157936. hist3d histogram = cquantize->histogram;
  157937. int i;
  157938. if (cinfo->dither_mode != JDITHER_NONE)
  157939. cinfo->dither_mode = JDITHER_FS;
  157940. if (is_pre_scan) {
  157941. cquantize->pub.color_quantize = prescan_quantize;
  157942. cquantize->pub.finish_pass = finish_pass1;
  157943. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  157944. } else {
  157945. if (cinfo->dither_mode == JDITHER_FS)
  157946. cquantize->pub.color_quantize = pass2_fs_dither;
  157947. else
  157948. cquantize->pub.color_quantize = pass2_no_dither;
  157949. cquantize->pub.finish_pass = finish_pass2;
  157950. i = cinfo->actual_number_of_colors;
  157951. if (i < 1)
  157952. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  157953. if (i > MAXNUMCOLORS)
  157954. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157955. if (cinfo->dither_mode == JDITHER_FS) {
  157956. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  157957. (3 * SIZEOF(FSERROR)));
  157958. if (cquantize->fserrors == NULL)
  157959. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157960. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157961. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  157962. if (cquantize->error_limiter == NULL)
  157963. init_error_limit(cinfo);
  157964. cquantize->on_odd_row = FALSE;
  157965. }
  157966. }
  157967. if (cquantize->needs_zeroed) {
  157968. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157969. jzero_far((void FAR *) histogram[i],
  157970. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157971. }
  157972. cquantize->needs_zeroed = FALSE;
  157973. }
  157974. }
  157975. METHODDEF(void)
  157976. new_color_map_2_quant (j_decompress_ptr cinfo)
  157977. {
  157978. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157979. cquantize->needs_zeroed = TRUE;
  157980. }
  157981. GLOBAL(void)
  157982. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  157983. {
  157984. my_cquantize_ptr2 cquantize;
  157985. int i;
  157986. cquantize = (my_cquantize_ptr2)
  157987. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157988. SIZEOF(my_cquantizer2));
  157989. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157990. cquantize->pub.start_pass = start_pass_2_quant;
  157991. cquantize->pub.new_color_map = new_color_map_2_quant;
  157992. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  157993. cquantize->error_limiter = NULL;
  157994. if (cinfo->out_color_components != 3)
  157995. ERREXIT(cinfo, JERR_NOTIMPL);
  157996. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  157997. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  157998. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157999. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158000. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158001. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158002. }
  158003. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158004. if (cinfo->enable_2pass_quant) {
  158005. int desired = cinfo->desired_number_of_colors;
  158006. if (desired < 8)
  158007. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158008. if (desired > MAXNUMCOLORS)
  158009. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158010. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158011. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158012. cquantize->desired = desired;
  158013. } else
  158014. cquantize->sv_colormap = NULL;
  158015. if (cinfo->dither_mode != JDITHER_NONE)
  158016. cinfo->dither_mode = JDITHER_FS;
  158017. if (cinfo->dither_mode == JDITHER_FS) {
  158018. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158019. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158020. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158021. init_error_limit(cinfo);
  158022. }
  158023. }
  158024. #endif /* QUANT_2PASS_SUPPORTED */
  158025. /*** End of inlined file: jquant2.c ***/
  158026. /*** Start of inlined file: jutils.c ***/
  158027. #define JPEG_INTERNALS
  158028. #if 0 /* This table is not actually needed in v6a */
  158029. const int jpeg_zigzag_order[DCTSIZE2] = {
  158030. 0, 1, 5, 6, 14, 15, 27, 28,
  158031. 2, 4, 7, 13, 16, 26, 29, 42,
  158032. 3, 8, 12, 17, 25, 30, 41, 43,
  158033. 9, 11, 18, 24, 31, 40, 44, 53,
  158034. 10, 19, 23, 32, 39, 45, 52, 54,
  158035. 20, 22, 33, 38, 46, 51, 55, 60,
  158036. 21, 34, 37, 47, 50, 56, 59, 61,
  158037. 35, 36, 48, 49, 57, 58, 62, 63
  158038. };
  158039. #endif
  158040. const int jpeg_natural_order[DCTSIZE2+16] = {
  158041. 0, 1, 8, 16, 9, 2, 3, 10,
  158042. 17, 24, 32, 25, 18, 11, 4, 5,
  158043. 12, 19, 26, 33, 40, 48, 41, 34,
  158044. 27, 20, 13, 6, 7, 14, 21, 28,
  158045. 35, 42, 49, 56, 57, 50, 43, 36,
  158046. 29, 22, 15, 23, 30, 37, 44, 51,
  158047. 58, 59, 52, 45, 38, 31, 39, 46,
  158048. 53, 60, 61, 54, 47, 55, 62, 63,
  158049. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158050. 63, 63, 63, 63, 63, 63, 63, 63
  158051. };
  158052. GLOBAL(long)
  158053. jdiv_round_up (long a, long b)
  158054. {
  158055. return (a + b - 1L) / b;
  158056. }
  158057. GLOBAL(long)
  158058. jround_up (long a, long b)
  158059. {
  158060. a += b - 1L;
  158061. return a - (a % b);
  158062. }
  158063. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158064. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158065. #define FMEMZERO(target,size) MEMZERO(target,size)
  158066. #else /* 80x86 case, define if we can */
  158067. #ifdef USE_FMEM
  158068. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158069. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158070. #endif
  158071. #endif
  158072. GLOBAL(void)
  158073. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158074. JSAMPARRAY output_array, int dest_row,
  158075. int num_rows, JDIMENSION num_cols)
  158076. {
  158077. register JSAMPROW inptr, outptr;
  158078. #ifdef FMEMCOPY
  158079. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158080. #else
  158081. register JDIMENSION count;
  158082. #endif
  158083. register int row;
  158084. input_array += source_row;
  158085. output_array += dest_row;
  158086. for (row = num_rows; row > 0; row--) {
  158087. inptr = *input_array++;
  158088. outptr = *output_array++;
  158089. #ifdef FMEMCOPY
  158090. FMEMCOPY(outptr, inptr, count);
  158091. #else
  158092. for (count = num_cols; count > 0; count--)
  158093. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158094. #endif
  158095. }
  158096. }
  158097. GLOBAL(void)
  158098. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158099. JDIMENSION num_blocks)
  158100. {
  158101. #ifdef FMEMCOPY
  158102. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158103. #else
  158104. register JCOEFPTR inptr, outptr;
  158105. register long count;
  158106. inptr = (JCOEFPTR) input_row;
  158107. outptr = (JCOEFPTR) output_row;
  158108. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158109. *outptr++ = *inptr++;
  158110. }
  158111. #endif
  158112. }
  158113. GLOBAL(void)
  158114. jzero_far (void FAR * target, size_t bytestozero)
  158115. {
  158116. #ifdef FMEMZERO
  158117. FMEMZERO(target, bytestozero);
  158118. #else
  158119. register char FAR * ptr = (char FAR *) target;
  158120. register size_t count;
  158121. for (count = bytestozero; count > 0; count--) {
  158122. *ptr++ = 0;
  158123. }
  158124. #endif
  158125. }
  158126. /*** End of inlined file: jutils.c ***/
  158127. /*** Start of inlined file: transupp.c ***/
  158128. #define JPEG_INTERNALS
  158129. /*** Start of inlined file: transupp.h ***/
  158130. #ifndef TRANSFORMS_SUPPORTED
  158131. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158132. #endif
  158133. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158134. #define jtransform_request_workspace jTrRequest
  158135. #define jtransform_adjust_parameters jTrAdjust
  158136. #define jtransform_execute_transformation jTrExec
  158137. #define jcopy_markers_setup jCMrkSetup
  158138. #define jcopy_markers_execute jCMrkExec
  158139. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158140. typedef enum {
  158141. JXFORM_NONE, /* no transformation */
  158142. JXFORM_FLIP_H, /* horizontal flip */
  158143. JXFORM_FLIP_V, /* vertical flip */
  158144. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158145. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158146. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158147. JXFORM_ROT_180, /* 180-degree rotation */
  158148. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158149. } JXFORM_CODE;
  158150. typedef struct {
  158151. JXFORM_CODE transform; /* image transform operator */
  158152. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158153. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158154. int num_components; /* # of components in workspace */
  158155. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158156. } jpeg_transform_info;
  158157. #if TRANSFORMS_SUPPORTED
  158158. EXTERN(void) jtransform_request_workspace
  158159. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158160. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158161. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158162. jvirt_barray_ptr *src_coef_arrays,
  158163. jpeg_transform_info *info));
  158164. EXTERN(void) jtransform_execute_transformation
  158165. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158166. jvirt_barray_ptr *src_coef_arrays,
  158167. jpeg_transform_info *info));
  158168. #endif /* TRANSFORMS_SUPPORTED */
  158169. typedef enum {
  158170. JCOPYOPT_NONE, /* copy no optional markers */
  158171. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158172. JCOPYOPT_ALL /* copy all optional markers */
  158173. } JCOPY_OPTION;
  158174. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158175. EXTERN(void) jcopy_markers_setup
  158176. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158177. EXTERN(void) jcopy_markers_execute
  158178. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158179. JCOPY_OPTION option));
  158180. /*** End of inlined file: transupp.h ***/
  158181. /* My own external interface */
  158182. #if TRANSFORMS_SUPPORTED
  158183. LOCAL(void)
  158184. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158185. jvirt_barray_ptr *src_coef_arrays)
  158186. {
  158187. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158188. int ci, k, offset_y;
  158189. JBLOCKARRAY buffer;
  158190. JCOEFPTR ptr1, ptr2;
  158191. JCOEF temp1, temp2;
  158192. jpeg_component_info *compptr;
  158193. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158194. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158195. compptr = dstinfo->comp_info + ci;
  158196. comp_width = MCU_cols * compptr->h_samp_factor;
  158197. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158198. blk_y += compptr->v_samp_factor) {
  158199. buffer = (*srcinfo->mem->access_virt_barray)
  158200. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158201. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158202. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158203. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158204. ptr1 = buffer[offset_y][blk_x];
  158205. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158206. for (k = 0; k < DCTSIZE2; k += 2) {
  158207. temp1 = *ptr1; /* swap even column */
  158208. temp2 = *ptr2;
  158209. *ptr1++ = temp2;
  158210. *ptr2++ = temp1;
  158211. temp1 = *ptr1; /* swap odd column with sign change */
  158212. temp2 = *ptr2;
  158213. *ptr1++ = -temp2;
  158214. *ptr2++ = -temp1;
  158215. }
  158216. }
  158217. }
  158218. }
  158219. }
  158220. }
  158221. LOCAL(void)
  158222. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158223. jvirt_barray_ptr *src_coef_arrays,
  158224. jvirt_barray_ptr *dst_coef_arrays)
  158225. {
  158226. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158227. int ci, i, j, offset_y;
  158228. JBLOCKARRAY src_buffer, dst_buffer;
  158229. JBLOCKROW src_row_ptr, dst_row_ptr;
  158230. JCOEFPTR src_ptr, dst_ptr;
  158231. jpeg_component_info *compptr;
  158232. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158233. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158234. compptr = dstinfo->comp_info + ci;
  158235. comp_height = MCU_rows * compptr->v_samp_factor;
  158236. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158237. dst_blk_y += compptr->v_samp_factor) {
  158238. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158239. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158240. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158241. if (dst_blk_y < comp_height) {
  158242. src_buffer = (*srcinfo->mem->access_virt_barray)
  158243. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158244. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158245. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158246. } else {
  158247. src_buffer = (*srcinfo->mem->access_virt_barray)
  158248. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158249. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158250. }
  158251. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158252. if (dst_blk_y < comp_height) {
  158253. dst_row_ptr = dst_buffer[offset_y];
  158254. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158255. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158256. dst_blk_x++) {
  158257. dst_ptr = dst_row_ptr[dst_blk_x];
  158258. src_ptr = src_row_ptr[dst_blk_x];
  158259. for (i = 0; i < DCTSIZE; i += 2) {
  158260. for (j = 0; j < DCTSIZE; j++)
  158261. *dst_ptr++ = *src_ptr++;
  158262. for (j = 0; j < DCTSIZE; j++)
  158263. *dst_ptr++ = - *src_ptr++;
  158264. }
  158265. }
  158266. } else {
  158267. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158268. compptr->width_in_blocks);
  158269. }
  158270. }
  158271. }
  158272. }
  158273. }
  158274. LOCAL(void)
  158275. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158276. jvirt_barray_ptr *src_coef_arrays,
  158277. jvirt_barray_ptr *dst_coef_arrays)
  158278. {
  158279. JDIMENSION dst_blk_x, dst_blk_y;
  158280. int ci, i, j, offset_x, offset_y;
  158281. JBLOCKARRAY src_buffer, dst_buffer;
  158282. JCOEFPTR src_ptr, dst_ptr;
  158283. jpeg_component_info *compptr;
  158284. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158285. compptr = dstinfo->comp_info + ci;
  158286. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158287. dst_blk_y += compptr->v_samp_factor) {
  158288. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158289. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158290. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158291. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158292. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158293. dst_blk_x += compptr->h_samp_factor) {
  158294. src_buffer = (*srcinfo->mem->access_virt_barray)
  158295. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158296. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158297. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158298. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158299. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158300. for (i = 0; i < DCTSIZE; i++)
  158301. for (j = 0; j < DCTSIZE; j++)
  158302. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158303. }
  158304. }
  158305. }
  158306. }
  158307. }
  158308. }
  158309. LOCAL(void)
  158310. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158311. jvirt_barray_ptr *src_coef_arrays,
  158312. jvirt_barray_ptr *dst_coef_arrays)
  158313. {
  158314. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158315. int ci, i, j, offset_x, offset_y;
  158316. JBLOCKARRAY src_buffer, dst_buffer;
  158317. JCOEFPTR src_ptr, dst_ptr;
  158318. jpeg_component_info *compptr;
  158319. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158320. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158321. compptr = dstinfo->comp_info + ci;
  158322. comp_width = MCU_cols * compptr->h_samp_factor;
  158323. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158324. dst_blk_y += compptr->v_samp_factor) {
  158325. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158326. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158327. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158328. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158329. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158330. dst_blk_x += compptr->h_samp_factor) {
  158331. src_buffer = (*srcinfo->mem->access_virt_barray)
  158332. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158333. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158334. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158335. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158336. if (dst_blk_x < comp_width) {
  158337. dst_ptr = dst_buffer[offset_y]
  158338. [comp_width - dst_blk_x - offset_x - 1];
  158339. for (i = 0; i < DCTSIZE; i++) {
  158340. for (j = 0; j < DCTSIZE; j++)
  158341. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158342. i++;
  158343. for (j = 0; j < DCTSIZE; j++)
  158344. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158345. }
  158346. } else {
  158347. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158348. for (i = 0; i < DCTSIZE; i++)
  158349. for (j = 0; j < DCTSIZE; j++)
  158350. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158351. }
  158352. }
  158353. }
  158354. }
  158355. }
  158356. }
  158357. }
  158358. LOCAL(void)
  158359. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158360. jvirt_barray_ptr *src_coef_arrays,
  158361. jvirt_barray_ptr *dst_coef_arrays)
  158362. {
  158363. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158364. int ci, i, j, offset_x, offset_y;
  158365. JBLOCKARRAY src_buffer, dst_buffer;
  158366. JCOEFPTR src_ptr, dst_ptr;
  158367. jpeg_component_info *compptr;
  158368. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158369. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158370. compptr = dstinfo->comp_info + ci;
  158371. comp_height = MCU_rows * compptr->v_samp_factor;
  158372. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158373. dst_blk_y += compptr->v_samp_factor) {
  158374. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158375. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158376. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158377. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158378. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158379. dst_blk_x += compptr->h_samp_factor) {
  158380. src_buffer = (*srcinfo->mem->access_virt_barray)
  158381. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158382. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158383. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158384. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158385. if (dst_blk_y < comp_height) {
  158386. src_ptr = src_buffer[offset_x]
  158387. [comp_height - dst_blk_y - offset_y - 1];
  158388. for (i = 0; i < DCTSIZE; i++) {
  158389. for (j = 0; j < DCTSIZE; j++) {
  158390. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158391. j++;
  158392. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158393. }
  158394. }
  158395. } else {
  158396. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158397. for (i = 0; i < DCTSIZE; i++)
  158398. for (j = 0; j < DCTSIZE; j++)
  158399. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158400. }
  158401. }
  158402. }
  158403. }
  158404. }
  158405. }
  158406. }
  158407. LOCAL(void)
  158408. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158409. jvirt_barray_ptr *src_coef_arrays,
  158410. jvirt_barray_ptr *dst_coef_arrays)
  158411. {
  158412. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158413. int ci, i, j, offset_y;
  158414. JBLOCKARRAY src_buffer, dst_buffer;
  158415. JBLOCKROW src_row_ptr, dst_row_ptr;
  158416. JCOEFPTR src_ptr, dst_ptr;
  158417. jpeg_component_info *compptr;
  158418. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158419. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158420. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158421. compptr = dstinfo->comp_info + ci;
  158422. comp_width = MCU_cols * compptr->h_samp_factor;
  158423. comp_height = MCU_rows * compptr->v_samp_factor;
  158424. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158425. dst_blk_y += compptr->v_samp_factor) {
  158426. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158427. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158428. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158429. if (dst_blk_y < comp_height) {
  158430. src_buffer = (*srcinfo->mem->access_virt_barray)
  158431. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158432. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158433. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158434. } else {
  158435. src_buffer = (*srcinfo->mem->access_virt_barray)
  158436. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158437. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158438. }
  158439. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158440. if (dst_blk_y < comp_height) {
  158441. dst_row_ptr = dst_buffer[offset_y];
  158442. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158443. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158444. dst_ptr = dst_row_ptr[dst_blk_x];
  158445. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158446. for (i = 0; i < DCTSIZE; i += 2) {
  158447. for (j = 0; j < DCTSIZE; j += 2) {
  158448. *dst_ptr++ = *src_ptr++;
  158449. *dst_ptr++ = - *src_ptr++;
  158450. }
  158451. for (j = 0; j < DCTSIZE; j += 2) {
  158452. *dst_ptr++ = - *src_ptr++;
  158453. *dst_ptr++ = *src_ptr++;
  158454. }
  158455. }
  158456. }
  158457. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158458. dst_ptr = dst_row_ptr[dst_blk_x];
  158459. src_ptr = src_row_ptr[dst_blk_x];
  158460. for (i = 0; i < DCTSIZE; i += 2) {
  158461. for (j = 0; j < DCTSIZE; j++)
  158462. *dst_ptr++ = *src_ptr++;
  158463. for (j = 0; j < DCTSIZE; j++)
  158464. *dst_ptr++ = - *src_ptr++;
  158465. }
  158466. }
  158467. } else {
  158468. dst_row_ptr = dst_buffer[offset_y];
  158469. src_row_ptr = src_buffer[offset_y];
  158470. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158471. dst_ptr = dst_row_ptr[dst_blk_x];
  158472. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158473. for (i = 0; i < DCTSIZE2; i += 2) {
  158474. *dst_ptr++ = *src_ptr++;
  158475. *dst_ptr++ = - *src_ptr++;
  158476. }
  158477. }
  158478. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158479. dst_ptr = dst_row_ptr[dst_blk_x];
  158480. src_ptr = src_row_ptr[dst_blk_x];
  158481. for (i = 0; i < DCTSIZE2; i++)
  158482. *dst_ptr++ = *src_ptr++;
  158483. }
  158484. }
  158485. }
  158486. }
  158487. }
  158488. }
  158489. LOCAL(void)
  158490. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158491. jvirt_barray_ptr *src_coef_arrays,
  158492. jvirt_barray_ptr *dst_coef_arrays)
  158493. {
  158494. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158495. int ci, i, j, offset_x, offset_y;
  158496. JBLOCKARRAY src_buffer, dst_buffer;
  158497. JCOEFPTR src_ptr, dst_ptr;
  158498. jpeg_component_info *compptr;
  158499. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158500. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158501. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158502. compptr = dstinfo->comp_info + ci;
  158503. comp_width = MCU_cols * compptr->h_samp_factor;
  158504. comp_height = MCU_rows * compptr->v_samp_factor;
  158505. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158506. dst_blk_y += compptr->v_samp_factor) {
  158507. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158508. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158509. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158510. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158511. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158512. dst_blk_x += compptr->h_samp_factor) {
  158513. src_buffer = (*srcinfo->mem->access_virt_barray)
  158514. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158515. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158516. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158517. if (dst_blk_y < comp_height) {
  158518. src_ptr = src_buffer[offset_x]
  158519. [comp_height - dst_blk_y - offset_y - 1];
  158520. if (dst_blk_x < comp_width) {
  158521. dst_ptr = dst_buffer[offset_y]
  158522. [comp_width - dst_blk_x - offset_x - 1];
  158523. for (i = 0; i < DCTSIZE; i++) {
  158524. for (j = 0; j < DCTSIZE; j++) {
  158525. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158526. j++;
  158527. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158528. }
  158529. i++;
  158530. for (j = 0; j < DCTSIZE; j++) {
  158531. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158532. j++;
  158533. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158534. }
  158535. }
  158536. } else {
  158537. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158538. for (i = 0; i < DCTSIZE; i++) {
  158539. for (j = 0; j < DCTSIZE; j++) {
  158540. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158541. j++;
  158542. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158543. }
  158544. }
  158545. }
  158546. } else {
  158547. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158548. if (dst_blk_x < comp_width) {
  158549. dst_ptr = dst_buffer[offset_y]
  158550. [comp_width - dst_blk_x - offset_x - 1];
  158551. for (i = 0; i < DCTSIZE; i++) {
  158552. for (j = 0; j < DCTSIZE; j++)
  158553. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158554. i++;
  158555. for (j = 0; j < DCTSIZE; j++)
  158556. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158557. }
  158558. } else {
  158559. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158560. for (i = 0; i < DCTSIZE; i++)
  158561. for (j = 0; j < DCTSIZE; j++)
  158562. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158563. }
  158564. }
  158565. }
  158566. }
  158567. }
  158568. }
  158569. }
  158570. }
  158571. GLOBAL(void)
  158572. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158573. jpeg_transform_info *info)
  158574. {
  158575. jvirt_barray_ptr *coef_arrays = NULL;
  158576. jpeg_component_info *compptr;
  158577. int ci;
  158578. if (info->force_grayscale &&
  158579. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158580. srcinfo->num_components == 3) {
  158581. info->num_components = 1;
  158582. } else {
  158583. info->num_components = srcinfo->num_components;
  158584. }
  158585. switch (info->transform) {
  158586. case JXFORM_NONE:
  158587. case JXFORM_FLIP_H:
  158588. break;
  158589. case JXFORM_FLIP_V:
  158590. case JXFORM_ROT_180:
  158591. coef_arrays = (jvirt_barray_ptr *)
  158592. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158593. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158594. for (ci = 0; ci < info->num_components; ci++) {
  158595. compptr = srcinfo->comp_info + ci;
  158596. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158597. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158598. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158599. (long) compptr->h_samp_factor),
  158600. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158601. (long) compptr->v_samp_factor),
  158602. (JDIMENSION) compptr->v_samp_factor);
  158603. }
  158604. break;
  158605. case JXFORM_TRANSPOSE:
  158606. case JXFORM_TRANSVERSE:
  158607. case JXFORM_ROT_90:
  158608. case JXFORM_ROT_270:
  158609. coef_arrays = (jvirt_barray_ptr *)
  158610. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158611. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158612. for (ci = 0; ci < info->num_components; ci++) {
  158613. compptr = srcinfo->comp_info + ci;
  158614. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158615. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158616. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158617. (long) compptr->v_samp_factor),
  158618. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158619. (long) compptr->h_samp_factor),
  158620. (JDIMENSION) compptr->h_samp_factor);
  158621. }
  158622. break;
  158623. }
  158624. info->workspace_coef_arrays = coef_arrays;
  158625. }
  158626. LOCAL(void)
  158627. transpose_critical_parameters (j_compress_ptr dstinfo)
  158628. {
  158629. int tblno, i, j, ci, itemp;
  158630. jpeg_component_info *compptr;
  158631. JQUANT_TBL *qtblptr;
  158632. JDIMENSION dtemp;
  158633. UINT16 qtemp;
  158634. dtemp = dstinfo->image_width;
  158635. dstinfo->image_width = dstinfo->image_height;
  158636. dstinfo->image_height = dtemp;
  158637. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158638. compptr = dstinfo->comp_info + ci;
  158639. itemp = compptr->h_samp_factor;
  158640. compptr->h_samp_factor = compptr->v_samp_factor;
  158641. compptr->v_samp_factor = itemp;
  158642. }
  158643. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158644. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158645. if (qtblptr != NULL) {
  158646. for (i = 0; i < DCTSIZE; i++) {
  158647. for (j = 0; j < i; j++) {
  158648. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158649. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158650. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158651. }
  158652. }
  158653. }
  158654. }
  158655. }
  158656. LOCAL(void)
  158657. trim_right_edge (j_compress_ptr dstinfo)
  158658. {
  158659. int ci, max_h_samp_factor;
  158660. JDIMENSION MCU_cols;
  158661. max_h_samp_factor = 1;
  158662. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158663. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158664. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158665. }
  158666. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158667. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158668. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158669. }
  158670. LOCAL(void)
  158671. trim_bottom_edge (j_compress_ptr dstinfo)
  158672. {
  158673. int ci, max_v_samp_factor;
  158674. JDIMENSION MCU_rows;
  158675. max_v_samp_factor = 1;
  158676. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158677. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158678. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158679. }
  158680. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158681. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158682. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158683. }
  158684. GLOBAL(jvirt_barray_ptr *)
  158685. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158686. j_compress_ptr dstinfo,
  158687. jvirt_barray_ptr *src_coef_arrays,
  158688. jpeg_transform_info *info)
  158689. {
  158690. if (info->force_grayscale) {
  158691. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158692. dstinfo->num_components == 3) ||
  158693. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158694. dstinfo->num_components == 1)) {
  158695. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158696. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158697. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158698. } else {
  158699. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158700. }
  158701. }
  158702. switch (info->transform) {
  158703. case JXFORM_NONE:
  158704. break;
  158705. case JXFORM_FLIP_H:
  158706. if (info->trim)
  158707. trim_right_edge(dstinfo);
  158708. break;
  158709. case JXFORM_FLIP_V:
  158710. if (info->trim)
  158711. trim_bottom_edge(dstinfo);
  158712. break;
  158713. case JXFORM_TRANSPOSE:
  158714. transpose_critical_parameters(dstinfo);
  158715. break;
  158716. case JXFORM_TRANSVERSE:
  158717. transpose_critical_parameters(dstinfo);
  158718. if (info->trim) {
  158719. trim_right_edge(dstinfo);
  158720. trim_bottom_edge(dstinfo);
  158721. }
  158722. break;
  158723. case JXFORM_ROT_90:
  158724. transpose_critical_parameters(dstinfo);
  158725. if (info->trim)
  158726. trim_right_edge(dstinfo);
  158727. break;
  158728. case JXFORM_ROT_180:
  158729. if (info->trim) {
  158730. trim_right_edge(dstinfo);
  158731. trim_bottom_edge(dstinfo);
  158732. }
  158733. break;
  158734. case JXFORM_ROT_270:
  158735. transpose_critical_parameters(dstinfo);
  158736. if (info->trim)
  158737. trim_bottom_edge(dstinfo);
  158738. break;
  158739. }
  158740. if (info->workspace_coef_arrays != NULL)
  158741. return info->workspace_coef_arrays;
  158742. return src_coef_arrays;
  158743. }
  158744. GLOBAL(void)
  158745. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158746. j_compress_ptr dstinfo,
  158747. jvirt_barray_ptr *src_coef_arrays,
  158748. jpeg_transform_info *info)
  158749. {
  158750. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158751. switch (info->transform) {
  158752. case JXFORM_NONE:
  158753. break;
  158754. case JXFORM_FLIP_H:
  158755. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158756. break;
  158757. case JXFORM_FLIP_V:
  158758. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158759. break;
  158760. case JXFORM_TRANSPOSE:
  158761. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158762. break;
  158763. case JXFORM_TRANSVERSE:
  158764. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158765. break;
  158766. case JXFORM_ROT_90:
  158767. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158768. break;
  158769. case JXFORM_ROT_180:
  158770. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158771. break;
  158772. case JXFORM_ROT_270:
  158773. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158774. break;
  158775. }
  158776. }
  158777. #endif /* TRANSFORMS_SUPPORTED */
  158778. GLOBAL(void)
  158779. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158780. {
  158781. #ifdef SAVE_MARKERS_SUPPORTED
  158782. int m;
  158783. if (option != JCOPYOPT_NONE) {
  158784. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158785. }
  158786. if (option == JCOPYOPT_ALL) {
  158787. for (m = 0; m < 16; m++)
  158788. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158789. }
  158790. #endif /* SAVE_MARKERS_SUPPORTED */
  158791. }
  158792. GLOBAL(void)
  158793. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158794. JCOPY_OPTION option)
  158795. {
  158796. jpeg_saved_marker_ptr marker;
  158797. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158798. if (dstinfo->write_JFIF_header &&
  158799. marker->marker == JPEG_APP0 &&
  158800. marker->data_length >= 5 &&
  158801. GETJOCTET(marker->data[0]) == 0x4A &&
  158802. GETJOCTET(marker->data[1]) == 0x46 &&
  158803. GETJOCTET(marker->data[2]) == 0x49 &&
  158804. GETJOCTET(marker->data[3]) == 0x46 &&
  158805. GETJOCTET(marker->data[4]) == 0)
  158806. continue; /* reject duplicate JFIF */
  158807. if (dstinfo->write_Adobe_marker &&
  158808. marker->marker == JPEG_APP0+14 &&
  158809. marker->data_length >= 5 &&
  158810. GETJOCTET(marker->data[0]) == 0x41 &&
  158811. GETJOCTET(marker->data[1]) == 0x64 &&
  158812. GETJOCTET(marker->data[2]) == 0x6F &&
  158813. GETJOCTET(marker->data[3]) == 0x62 &&
  158814. GETJOCTET(marker->data[4]) == 0x65)
  158815. continue; /* reject duplicate Adobe */
  158816. #ifdef NEED_FAR_POINTERS
  158817. {
  158818. unsigned int i;
  158819. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158820. for (i = 0; i < marker->data_length; i++)
  158821. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158822. }
  158823. #else
  158824. jpeg_write_marker(dstinfo, marker->marker,
  158825. marker->data, marker->data_length);
  158826. #endif
  158827. }
  158828. }
  158829. /*** End of inlined file: transupp.c ***/
  158830. }
  158831. #else
  158832. #define JPEG_INTERNALS
  158833. #undef FAR
  158834. #include <jpeglib.h>
  158835. #endif
  158836. }
  158837. #undef max
  158838. #undef min
  158839. #if JUCE_MSVC
  158840. #pragma warning (pop)
  158841. #endif
  158842. BEGIN_JUCE_NAMESPACE
  158843. namespace JPEGHelpers
  158844. {
  158845. using namespace jpeglibNamespace;
  158846. #if ! JUCE_MSVC
  158847. using jpeglibNamespace::boolean;
  158848. #endif
  158849. struct JPEGDecodingFailure {};
  158850. static void fatalErrorHandler (j_common_ptr)
  158851. {
  158852. throw JPEGDecodingFailure();
  158853. }
  158854. static void silentErrorCallback1 (j_common_ptr) {}
  158855. static void silentErrorCallback2 (j_common_ptr, int) {}
  158856. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158857. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158858. {
  158859. zerostruct (err);
  158860. err.error_exit = fatalErrorHandler;
  158861. err.emit_message = silentErrorCallback2;
  158862. err.output_message = silentErrorCallback1;
  158863. err.format_message = silentErrorCallback3;
  158864. err.reset_error_mgr = silentErrorCallback1;
  158865. }
  158866. static void dummyCallback1 (j_decompress_ptr)
  158867. {
  158868. }
  158869. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158870. {
  158871. decompStruct->src->next_input_byte += num;
  158872. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158873. decompStruct->src->bytes_in_buffer -= num;
  158874. }
  158875. static boolean jpegFill (j_decompress_ptr)
  158876. {
  158877. return 0;
  158878. }
  158879. static const int jpegBufferSize = 512;
  158880. struct JuceJpegDest : public jpeg_destination_mgr
  158881. {
  158882. OutputStream* output;
  158883. char* buffer;
  158884. };
  158885. static void jpegWriteInit (j_compress_ptr)
  158886. {
  158887. }
  158888. static void jpegWriteTerminate (j_compress_ptr cinfo)
  158889. {
  158890. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158891. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  158892. dest->output->write (dest->buffer, (int) numToWrite);
  158893. }
  158894. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  158895. {
  158896. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158897. const int numToWrite = jpegBufferSize;
  158898. dest->next_output_byte = (JOCTET*) dest->buffer;
  158899. dest->free_in_buffer = jpegBufferSize;
  158900. return dest->output->write (dest->buffer, numToWrite);
  158901. }
  158902. }
  158903. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158904. {
  158905. using namespace jpeglibNamespace;
  158906. using namespace JPEGHelpers;
  158907. MemoryBlock mb;
  158908. in.readIntoMemoryBlock (mb);
  158909. Image* image = 0;
  158910. if (mb.getSize() > 16)
  158911. {
  158912. struct jpeg_decompress_struct jpegDecompStruct;
  158913. struct jpeg_error_mgr jerr;
  158914. setupSilentErrorHandler (jerr);
  158915. jpegDecompStruct.err = &jerr;
  158916. jpeg_create_decompress (&jpegDecompStruct);
  158917. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158918. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158919. jpegDecompStruct.src->init_source = dummyCallback1;
  158920. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158921. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158922. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158923. jpegDecompStruct.src->term_source = dummyCallback1;
  158924. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  158925. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158926. try
  158927. {
  158928. jpeg_read_header (&jpegDecompStruct, TRUE);
  158929. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158930. const int width = jpegDecompStruct.output_width;
  158931. const int height = jpegDecompStruct.output_height;
  158932. jpegDecompStruct.out_color_space = JCS_RGB;
  158933. JSAMPARRAY buffer
  158934. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158935. JPOOL_IMAGE,
  158936. width * 3, 1);
  158937. if (jpeg_start_decompress (&jpegDecompStruct))
  158938. {
  158939. image = Image::createNativeImage (Image::RGB, width, height, false);
  158940. const bool hasAlphaChan = image->hasAlphaChannel();
  158941. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  158942. for (int y = 0; y < height; ++y)
  158943. {
  158944. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  158945. const uint8* src = *buffer;
  158946. uint8* dest = destData.getLinePointer (y);
  158947. if (hasAlphaChan)
  158948. {
  158949. for (int i = width; --i >= 0;)
  158950. {
  158951. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158952. ((PixelARGB*) dest)->premultiply();
  158953. dest += destData.pixelStride;
  158954. src += 3;
  158955. }
  158956. }
  158957. else
  158958. {
  158959. for (int i = width; --i >= 0;)
  158960. {
  158961. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158962. dest += destData.pixelStride;
  158963. src += 3;
  158964. }
  158965. }
  158966. }
  158967. jpeg_finish_decompress (&jpegDecompStruct);
  158968. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  158969. }
  158970. jpeg_destroy_decompress (&jpegDecompStruct);
  158971. }
  158972. catch (...)
  158973. {}
  158974. }
  158975. return image;
  158976. }
  158977. bool juce_writeJPEGImageToStream (const Image& image,
  158978. OutputStream& out,
  158979. float quality)
  158980. {
  158981. using namespace jpeglibNamespace;
  158982. using namespace JPEGHelpers;
  158983. if (image.hasAlphaChannel())
  158984. {
  158985. // this method could fill the background in white and still save the image..
  158986. jassertfalse
  158987. return true;
  158988. }
  158989. struct jpeg_compress_struct jpegCompStruct;
  158990. struct jpeg_error_mgr jerr;
  158991. setupSilentErrorHandler (jerr);
  158992. jpegCompStruct.err = &jerr;
  158993. jpeg_create_compress (&jpegCompStruct);
  158994. JuceJpegDest dest;
  158995. jpegCompStruct.dest = &dest;
  158996. dest.output = &out;
  158997. HeapBlock <char> tempBuffer (jpegBufferSize);
  158998. dest.buffer = (char*) tempBuffer;
  158999. dest.next_output_byte = (JOCTET*) dest.buffer;
  159000. dest.free_in_buffer = jpegBufferSize;
  159001. dest.init_destination = jpegWriteInit;
  159002. dest.empty_output_buffer = jpegWriteFlush;
  159003. dest.term_destination = jpegWriteTerminate;
  159004. jpegCompStruct.image_width = image.getWidth();
  159005. jpegCompStruct.image_height = image.getHeight();
  159006. jpegCompStruct.input_components = 3;
  159007. jpegCompStruct.in_color_space = JCS_RGB;
  159008. jpegCompStruct.write_JFIF_header = 1;
  159009. jpegCompStruct.X_density = 72;
  159010. jpegCompStruct.Y_density = 72;
  159011. jpeg_set_defaults (&jpegCompStruct);
  159012. jpegCompStruct.dct_method = JDCT_FLOAT;
  159013. jpegCompStruct.optimize_coding = 1;
  159014. //jpegCompStruct.smoothing_factor = 10;
  159015. if (quality < 0.0f)
  159016. quality = 0.85f;
  159017. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159018. jpeg_start_compress (&jpegCompStruct, TRUE);
  159019. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159020. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159021. JPOOL_IMAGE, strideBytes, 1);
  159022. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159023. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159024. {
  159025. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159026. uint8* dst = *buffer;
  159027. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159028. {
  159029. *dst++ = ((const PixelRGB*) src)->getRed();
  159030. *dst++ = ((const PixelRGB*) src)->getGreen();
  159031. *dst++ = ((const PixelRGB*) src)->getBlue();
  159032. src += srcData.pixelStride;
  159033. }
  159034. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159035. }
  159036. jpeg_finish_compress (&jpegCompStruct);
  159037. jpeg_destroy_compress (&jpegCompStruct);
  159038. out.flush();
  159039. return true;
  159040. }
  159041. END_JUCE_NAMESPACE
  159042. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159043. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159044. #ifdef _MSC_VER
  159045. #pragma warning (push)
  159046. #pragma warning (disable: 4390 4611)
  159047. #endif
  159048. namespace zlibNamespace
  159049. {
  159050. #if JUCE_INCLUDE_ZLIB_CODE
  159051. #undef OS_CODE
  159052. #undef fdopen
  159053. #undef OS_CODE
  159054. #else
  159055. #include <zlib.h>
  159056. #endif
  159057. }
  159058. namespace pnglibNamespace
  159059. {
  159060. using namespace zlibNamespace;
  159061. #if JUCE_INCLUDE_PNGLIB_CODE
  159062. #if _MSC_VER != 1310
  159063. using ::calloc; // (causes conflict in VS.NET 2003)
  159064. using ::malloc;
  159065. using ::free;
  159066. #endif
  159067. extern "C"
  159068. {
  159069. using ::abs;
  159070. #define PNG_INTERNAL
  159071. #define NO_DUMMY_DECL
  159072. #define PNG_SETJMP_NOT_SUPPORTED
  159073. /*** Start of inlined file: png.h ***/
  159074. #ifndef PNG_H
  159075. #define PNG_H
  159076. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159077. #define PNG_HEADER_VERSION_STRING \
  159078. " libpng version 1.2.21 - October 4, 2007\n"
  159079. #define PNG_LIBPNG_VER_SONUM 0
  159080. #define PNG_LIBPNG_VER_DLLNUM 13
  159081. #define PNG_LIBPNG_VER_MAJOR 1
  159082. #define PNG_LIBPNG_VER_MINOR 2
  159083. #define PNG_LIBPNG_VER_RELEASE 21
  159084. #define PNG_LIBPNG_VER_BUILD 0
  159085. #define PNG_LIBPNG_BUILD_ALPHA 1
  159086. #define PNG_LIBPNG_BUILD_BETA 2
  159087. #define PNG_LIBPNG_BUILD_RC 3
  159088. #define PNG_LIBPNG_BUILD_STABLE 4
  159089. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159090. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159091. PNG_LIBPNG_BUILD_STABLE only */
  159092. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159093. PNG_LIBPNG_BUILD_SPECIAL */
  159094. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159095. PNG_LIBPNG_BUILD_PRIVATE */
  159096. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159097. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159098. #ifndef PNG_VERSION_INFO_ONLY
  159099. #endif
  159100. /*** Start of inlined file: pngconf.h ***/
  159101. #ifndef PNGCONF_H
  159102. #define PNGCONF_H
  159103. #define PNG_1_2_X
  159104. // These are some Juce config settings that should remove any unnecessary code bloat..
  159105. #define PNG_NO_STDIO 1
  159106. #define PNG_DEBUG 0
  159107. #define PNG_NO_WARNINGS 1
  159108. #define PNG_NO_ERROR_TEXT 1
  159109. #define PNG_NO_ERROR_NUMBERS 1
  159110. #define PNG_NO_USER_MEM 1
  159111. #define PNG_NO_READ_iCCP 1
  159112. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159113. #define PNG_NO_READ_USER_CHUNKS 1
  159114. #define PNG_NO_READ_iTXt 1
  159115. #define PNG_NO_READ_sCAL 1
  159116. #define PNG_NO_READ_sPLT 1
  159117. #define png_error(a, b) png_err(a)
  159118. #define png_warning(a, b)
  159119. #define png_chunk_error(a, b) png_err(a)
  159120. #define png_chunk_warning(a, b)
  159121. #ifdef PNG_USER_CONFIG
  159122. # ifndef PNG_USER_PRIVATEBUILD
  159123. # define PNG_USER_PRIVATEBUILD
  159124. # endif
  159125. #include "pngusr.h"
  159126. #endif
  159127. #ifdef PNG_CONFIGURE_LIBPNG
  159128. #ifdef HAVE_CONFIG_H
  159129. #include "config.h"
  159130. #endif
  159131. #endif
  159132. #ifdef __STDC__
  159133. #ifdef SPECIALBUILD
  159134. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159135. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159136. #endif
  159137. #ifdef PRIVATEBUILD
  159138. # pragma message("PRIVATEBUILD is deprecated.\
  159139. Use PNG_USER_PRIVATEBUILD instead.")
  159140. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159141. #endif
  159142. #endif /* __STDC__ */
  159143. #ifndef PNG_VERSION_INFO_ONLY
  159144. # define PNG_WARN_UNINITIALIZED_ROW 1
  159145. #ifndef PNG_ZBUF_SIZE
  159146. # define PNG_ZBUF_SIZE 8192
  159147. #endif
  159148. #ifndef PNG_NO_READ_SUPPORTED
  159149. # define PNG_READ_SUPPORTED
  159150. #endif
  159151. #ifndef PNG_NO_WRITE_SUPPORTED
  159152. # define PNG_WRITE_SUPPORTED
  159153. #endif
  159154. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159155. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159156. # define PNG_MNG_FEATURES_SUPPORTED
  159157. # endif
  159158. #endif
  159159. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159160. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159161. # define PNG_FLOATING_POINT_SUPPORTED
  159162. # endif
  159163. #endif
  159164. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159165. # define PNG_MAX_MALLOC_64K
  159166. #endif
  159167. #if defined(__CYGWIN__)
  159168. # if defined(ALL_STATIC)
  159169. # if defined(PNG_BUILD_DLL)
  159170. # undef PNG_BUILD_DLL
  159171. # endif
  159172. # if defined(PNG_USE_DLL)
  159173. # undef PNG_USE_DLL
  159174. # endif
  159175. # if defined(PNG_DLL)
  159176. # undef PNG_DLL
  159177. # endif
  159178. # if !defined(PNG_STATIC)
  159179. # define PNG_STATIC
  159180. # endif
  159181. # else
  159182. # if defined (PNG_BUILD_DLL)
  159183. # if defined(PNG_STATIC)
  159184. # undef PNG_STATIC
  159185. # endif
  159186. # if defined(PNG_USE_DLL)
  159187. # undef PNG_USE_DLL
  159188. # endif
  159189. # if !defined(PNG_DLL)
  159190. # define PNG_DLL
  159191. # endif
  159192. # else
  159193. # if defined(PNG_STATIC)
  159194. # if defined(PNG_USE_DLL)
  159195. # undef PNG_USE_DLL
  159196. # endif
  159197. # if defined(PNG_DLL)
  159198. # undef PNG_DLL
  159199. # endif
  159200. # else
  159201. # if !defined(PNG_USE_DLL)
  159202. # define PNG_USE_DLL
  159203. # endif
  159204. # if !defined(PNG_DLL)
  159205. # define PNG_DLL
  159206. # endif
  159207. # endif
  159208. # endif
  159209. # endif
  159210. #endif
  159211. #if defined(_WIN32_WCE)
  159212. # include <windows.h>
  159213. # define PNG_NO_CONSOLE_IO
  159214. # ifdef PNG_DEBUG
  159215. # undef PNG_DEBUG
  159216. # endif
  159217. #endif
  159218. #ifdef PNG_BUILD_DLL
  159219. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159220. # ifndef PNG_NO_CONSOLE_IO
  159221. # define PNG_NO_CONSOLE_IO
  159222. # endif
  159223. # endif
  159224. #endif
  159225. # ifdef PNG_NO_STDIO
  159226. # ifndef PNG_NO_CONSOLE_IO
  159227. # define PNG_NO_CONSOLE_IO
  159228. # endif
  159229. # ifdef PNG_DEBUG
  159230. # if (PNG_DEBUG > 0)
  159231. # include <stdio.h>
  159232. # endif
  159233. # endif
  159234. # else
  159235. # if !defined(_WIN32_WCE)
  159236. # include <stdio.h>
  159237. # endif
  159238. # endif
  159239. #ifndef PNGARG
  159240. #ifdef OF /* zlib prototype munger */
  159241. # define PNGARG(arglist) OF(arglist)
  159242. #else
  159243. #ifdef _NO_PROTO
  159244. # define PNGARG(arglist) ()
  159245. # ifndef PNG_TYPECAST_NULL
  159246. # define PNG_TYPECAST_NULL
  159247. # endif
  159248. #else
  159249. # define PNGARG(arglist) arglist
  159250. #endif /* _NO_PROTO */
  159251. #endif /* OF */
  159252. #endif /* PNGARG */
  159253. #ifndef MACOS
  159254. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159255. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159256. # define MACOS
  159257. # endif
  159258. #endif
  159259. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159260. # include <sys/types.h>
  159261. #endif
  159262. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159263. # define PNG_SETJMP_SUPPORTED
  159264. #endif
  159265. #ifdef PNG_SETJMP_SUPPORTED
  159266. # ifdef __linux__
  159267. # ifdef _BSD_SOURCE
  159268. # define PNG_SAVE_BSD_SOURCE
  159269. # undef _BSD_SOURCE
  159270. # endif
  159271. # ifdef _SETJMP_H
  159272. __png.h__ already includes setjmp.h;
  159273. __dont__ include it again.;
  159274. # endif
  159275. # endif /* __linux__ */
  159276. # include <setjmp.h>
  159277. # ifdef __linux__
  159278. # ifdef PNG_SAVE_BSD_SOURCE
  159279. # define _BSD_SOURCE
  159280. # undef PNG_SAVE_BSD_SOURCE
  159281. # endif
  159282. # endif /* __linux__ */
  159283. #endif /* PNG_SETJMP_SUPPORTED */
  159284. #ifdef BSD
  159285. #if ! JUCE_MAC
  159286. # include <strings.h>
  159287. #endif
  159288. #else
  159289. # include <string.h>
  159290. #endif
  159291. #ifdef PNG_INTERNAL
  159292. #include <stdlib.h>
  159293. #define PNG_EXTERN
  159294. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159295. # if defined(MACOS)
  159296. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159297. # include <fp.h>
  159298. # endif
  159299. # else
  159300. # include <math.h>
  159301. # endif
  159302. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159303. # include <m68881.h>
  159304. # endif
  159305. #endif
  159306. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159307. # define PNG_ALWAYS_EXTERN
  159308. #endif
  159309. #if defined(__TURBOC__) && defined(__MSDOS__)
  159310. # include <mem.h>
  159311. # include <alloc.h>
  159312. #endif
  159313. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159314. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159315. # include <malloc.h>
  159316. #endif
  159317. #ifndef PNG_DITHER_RED_BITS
  159318. # define PNG_DITHER_RED_BITS 5
  159319. #endif
  159320. #ifndef PNG_DITHER_GREEN_BITS
  159321. # define PNG_DITHER_GREEN_BITS 5
  159322. #endif
  159323. #ifndef PNG_DITHER_BLUE_BITS
  159324. # define PNG_DITHER_BLUE_BITS 5
  159325. #endif
  159326. #ifndef PNG_MAX_GAMMA_8
  159327. # define PNG_MAX_GAMMA_8 11
  159328. #endif
  159329. #ifndef PNG_GAMMA_THRESHOLD
  159330. # define PNG_GAMMA_THRESHOLD 0.05
  159331. #endif
  159332. #endif /* PNG_INTERNAL */
  159333. #ifndef PNG_NO_CONST
  159334. # define PNG_CONST const
  159335. #else
  159336. # define PNG_CONST
  159337. #endif
  159338. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159339. # ifndef PNG_NO_iTXt_SUPPORTED
  159340. # define PNG_NO_iTXt_SUPPORTED
  159341. # endif
  159342. # ifndef PNG_NO_READ_iTXt
  159343. # define PNG_NO_READ_iTXt
  159344. # endif
  159345. # ifndef PNG_NO_WRITE_iTXt
  159346. # define PNG_NO_WRITE_iTXt
  159347. # endif
  159348. #endif
  159349. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159350. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159351. # define PNG_READ_iTXt
  159352. # endif
  159353. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159354. # define PNG_WRITE_iTXt
  159355. # endif
  159356. #endif
  159357. #ifdef PNG_LEGACY_SUPPORTED
  159358. # define PNG_NO_FREE_ME
  159359. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159360. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159361. # define PNG_NO_READ_USER_CHUNKS
  159362. # define PNG_NO_READ_iCCP
  159363. # define PNG_NO_WRITE_iCCP
  159364. # define PNG_NO_READ_iTXt
  159365. # define PNG_NO_WRITE_iTXt
  159366. # define PNG_NO_READ_sCAL
  159367. # define PNG_NO_WRITE_sCAL
  159368. # define PNG_NO_READ_sPLT
  159369. # define PNG_NO_WRITE_sPLT
  159370. # define PNG_NO_INFO_IMAGE
  159371. # define PNG_NO_READ_RGB_TO_GRAY
  159372. # define PNG_NO_READ_USER_TRANSFORM
  159373. # define PNG_NO_WRITE_USER_TRANSFORM
  159374. # define PNG_NO_USER_MEM
  159375. # define PNG_NO_READ_EMPTY_PLTE
  159376. # define PNG_NO_MNG_FEATURES
  159377. # define PNG_NO_FIXED_POINT_SUPPORTED
  159378. #endif
  159379. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159380. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159381. # define PNG_FIXED_POINT_SUPPORTED
  159382. #endif
  159383. #ifndef PNG_NO_FREE_ME
  159384. # define PNG_FREE_ME_SUPPORTED
  159385. #endif
  159386. #if defined(PNG_READ_SUPPORTED)
  159387. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159388. !defined(PNG_NO_READ_TRANSFORMS)
  159389. # define PNG_READ_TRANSFORMS_SUPPORTED
  159390. #endif
  159391. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159392. # ifndef PNG_NO_READ_EXPAND
  159393. # define PNG_READ_EXPAND_SUPPORTED
  159394. # endif
  159395. # ifndef PNG_NO_READ_SHIFT
  159396. # define PNG_READ_SHIFT_SUPPORTED
  159397. # endif
  159398. # ifndef PNG_NO_READ_PACK
  159399. # define PNG_READ_PACK_SUPPORTED
  159400. # endif
  159401. # ifndef PNG_NO_READ_BGR
  159402. # define PNG_READ_BGR_SUPPORTED
  159403. # endif
  159404. # ifndef PNG_NO_READ_SWAP
  159405. # define PNG_READ_SWAP_SUPPORTED
  159406. # endif
  159407. # ifndef PNG_NO_READ_PACKSWAP
  159408. # define PNG_READ_PACKSWAP_SUPPORTED
  159409. # endif
  159410. # ifndef PNG_NO_READ_INVERT
  159411. # define PNG_READ_INVERT_SUPPORTED
  159412. # endif
  159413. # ifndef PNG_NO_READ_DITHER
  159414. # define PNG_READ_DITHER_SUPPORTED
  159415. # endif
  159416. # ifndef PNG_NO_READ_BACKGROUND
  159417. # define PNG_READ_BACKGROUND_SUPPORTED
  159418. # endif
  159419. # ifndef PNG_NO_READ_16_TO_8
  159420. # define PNG_READ_16_TO_8_SUPPORTED
  159421. # endif
  159422. # ifndef PNG_NO_READ_FILLER
  159423. # define PNG_READ_FILLER_SUPPORTED
  159424. # endif
  159425. # ifndef PNG_NO_READ_GAMMA
  159426. # define PNG_READ_GAMMA_SUPPORTED
  159427. # endif
  159428. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159429. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159430. # endif
  159431. # ifndef PNG_NO_READ_SWAP_ALPHA
  159432. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159433. # endif
  159434. # ifndef PNG_NO_READ_INVERT_ALPHA
  159435. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159436. # endif
  159437. # ifndef PNG_NO_READ_STRIP_ALPHA
  159438. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159439. # endif
  159440. # ifndef PNG_NO_READ_USER_TRANSFORM
  159441. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159442. # endif
  159443. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159444. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159445. # endif
  159446. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159447. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159448. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159449. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159450. #endif /* about interlacing capability! You'll */
  159451. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159452. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159453. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159454. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159455. # endif
  159456. #endif
  159457. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159458. #ifndef PNG_NO_READ_EMPTY_PLTE
  159459. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159460. #endif
  159461. #endif
  159462. #endif /* PNG_READ_SUPPORTED */
  159463. #if defined(PNG_WRITE_SUPPORTED)
  159464. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159465. !defined(PNG_NO_WRITE_TRANSFORMS)
  159466. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159467. #endif
  159468. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159469. # ifndef PNG_NO_WRITE_SHIFT
  159470. # define PNG_WRITE_SHIFT_SUPPORTED
  159471. # endif
  159472. # ifndef PNG_NO_WRITE_PACK
  159473. # define PNG_WRITE_PACK_SUPPORTED
  159474. # endif
  159475. # ifndef PNG_NO_WRITE_BGR
  159476. # define PNG_WRITE_BGR_SUPPORTED
  159477. # endif
  159478. # ifndef PNG_NO_WRITE_SWAP
  159479. # define PNG_WRITE_SWAP_SUPPORTED
  159480. # endif
  159481. # ifndef PNG_NO_WRITE_PACKSWAP
  159482. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159483. # endif
  159484. # ifndef PNG_NO_WRITE_INVERT
  159485. # define PNG_WRITE_INVERT_SUPPORTED
  159486. # endif
  159487. # ifndef PNG_NO_WRITE_FILLER
  159488. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159489. # endif
  159490. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159491. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159492. # endif
  159493. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159494. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159495. # endif
  159496. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159497. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159498. # endif
  159499. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159500. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159501. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159502. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159503. encoders, but can cause trouble
  159504. if left undefined */
  159505. #endif
  159506. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159507. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159508. defined(PNG_FLOATING_POINT_SUPPORTED)
  159509. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159510. #endif
  159511. #ifndef PNG_NO_WRITE_FLUSH
  159512. # define PNG_WRITE_FLUSH_SUPPORTED
  159513. #endif
  159514. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159515. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159516. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159517. #endif
  159518. #endif
  159519. #endif /* PNG_WRITE_SUPPORTED */
  159520. #ifndef PNG_1_0_X
  159521. # ifndef PNG_NO_ERROR_NUMBERS
  159522. # define PNG_ERROR_NUMBERS_SUPPORTED
  159523. # endif
  159524. #endif /* PNG_1_0_X */
  159525. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159526. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159527. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159528. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159529. # endif
  159530. #endif
  159531. #ifndef PNG_NO_STDIO
  159532. # define PNG_TIME_RFC1123_SUPPORTED
  159533. #endif
  159534. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159535. # define PNG_EASY_ACCESS_SUPPORTED
  159536. #endif
  159537. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159538. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159539. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159540. # endif
  159541. #endif
  159542. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159543. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159544. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159545. # endif
  159546. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159547. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159548. # define PNG_NO_MMX_CODE
  159549. # endif
  159550. # endif
  159551. # if defined(__APPLE__)
  159552. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159553. # define PNG_NO_MMX_CODE
  159554. # endif
  159555. # endif
  159556. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159557. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159558. # define PNG_NO_MMX_CODE
  159559. # endif
  159560. # endif
  159561. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159562. # define PNG_MMX_CODE_SUPPORTED
  159563. # endif
  159564. #endif
  159565. #if !defined(PNG_1_0_X)
  159566. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159567. # define PNG_USER_MEM_SUPPORTED
  159568. #endif
  159569. #endif /* PNG_1_0_X */
  159570. #if !defined(PNG_1_0_X)
  159571. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159572. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159573. # define PNG_SET_USER_LIMITS_SUPPORTED
  159574. #endif
  159575. #endif
  159576. #endif /* PNG_1_0_X */
  159577. #ifndef PNG_USER_WIDTH_MAX
  159578. # define PNG_USER_WIDTH_MAX 1000000L
  159579. #endif
  159580. #ifndef PNG_USER_HEIGHT_MAX
  159581. # define PNG_USER_HEIGHT_MAX 1000000L
  159582. #endif
  159583. #if defined(PNG_READ_SUPPORTED) && \
  159584. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159585. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159586. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159587. #endif
  159588. #if defined(PNG_WRITE_SUPPORTED) && \
  159589. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159590. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159591. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159592. #endif
  159593. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159594. #ifdef PNG_NO_READ_TEXT
  159595. # define PNG_NO_READ_iTXt
  159596. # define PNG_NO_READ_tEXt
  159597. # define PNG_NO_READ_zTXt
  159598. #endif
  159599. #ifndef PNG_NO_READ_bKGD
  159600. # define PNG_READ_bKGD_SUPPORTED
  159601. # define PNG_bKGD_SUPPORTED
  159602. #endif
  159603. #ifndef PNG_NO_READ_cHRM
  159604. # define PNG_READ_cHRM_SUPPORTED
  159605. # define PNG_cHRM_SUPPORTED
  159606. #endif
  159607. #ifndef PNG_NO_READ_gAMA
  159608. # define PNG_READ_gAMA_SUPPORTED
  159609. # define PNG_gAMA_SUPPORTED
  159610. #endif
  159611. #ifndef PNG_NO_READ_hIST
  159612. # define PNG_READ_hIST_SUPPORTED
  159613. # define PNG_hIST_SUPPORTED
  159614. #endif
  159615. #ifndef PNG_NO_READ_iCCP
  159616. # define PNG_READ_iCCP_SUPPORTED
  159617. # define PNG_iCCP_SUPPORTED
  159618. #endif
  159619. #ifndef PNG_NO_READ_iTXt
  159620. # ifndef PNG_READ_iTXt_SUPPORTED
  159621. # define PNG_READ_iTXt_SUPPORTED
  159622. # endif
  159623. # ifndef PNG_iTXt_SUPPORTED
  159624. # define PNG_iTXt_SUPPORTED
  159625. # endif
  159626. #endif
  159627. #ifndef PNG_NO_READ_oFFs
  159628. # define PNG_READ_oFFs_SUPPORTED
  159629. # define PNG_oFFs_SUPPORTED
  159630. #endif
  159631. #ifndef PNG_NO_READ_pCAL
  159632. # define PNG_READ_pCAL_SUPPORTED
  159633. # define PNG_pCAL_SUPPORTED
  159634. #endif
  159635. #ifndef PNG_NO_READ_sCAL
  159636. # define PNG_READ_sCAL_SUPPORTED
  159637. # define PNG_sCAL_SUPPORTED
  159638. #endif
  159639. #ifndef PNG_NO_READ_pHYs
  159640. # define PNG_READ_pHYs_SUPPORTED
  159641. # define PNG_pHYs_SUPPORTED
  159642. #endif
  159643. #ifndef PNG_NO_READ_sBIT
  159644. # define PNG_READ_sBIT_SUPPORTED
  159645. # define PNG_sBIT_SUPPORTED
  159646. #endif
  159647. #ifndef PNG_NO_READ_sPLT
  159648. # define PNG_READ_sPLT_SUPPORTED
  159649. # define PNG_sPLT_SUPPORTED
  159650. #endif
  159651. #ifndef PNG_NO_READ_sRGB
  159652. # define PNG_READ_sRGB_SUPPORTED
  159653. # define PNG_sRGB_SUPPORTED
  159654. #endif
  159655. #ifndef PNG_NO_READ_tEXt
  159656. # define PNG_READ_tEXt_SUPPORTED
  159657. # define PNG_tEXt_SUPPORTED
  159658. #endif
  159659. #ifndef PNG_NO_READ_tIME
  159660. # define PNG_READ_tIME_SUPPORTED
  159661. # define PNG_tIME_SUPPORTED
  159662. #endif
  159663. #ifndef PNG_NO_READ_tRNS
  159664. # define PNG_READ_tRNS_SUPPORTED
  159665. # define PNG_tRNS_SUPPORTED
  159666. #endif
  159667. #ifndef PNG_NO_READ_zTXt
  159668. # define PNG_READ_zTXt_SUPPORTED
  159669. # define PNG_zTXt_SUPPORTED
  159670. #endif
  159671. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159672. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159673. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159674. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159675. # endif
  159676. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159677. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159678. # endif
  159679. #endif
  159680. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159681. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159682. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159683. # define PNG_USER_CHUNKS_SUPPORTED
  159684. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159685. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159686. # endif
  159687. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159688. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159689. # endif
  159690. #endif
  159691. #ifndef PNG_NO_READ_OPT_PLTE
  159692. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159693. #endif /* optional PLTE chunk in RGB and RGBA images */
  159694. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159695. defined(PNG_READ_zTXt_SUPPORTED)
  159696. # define PNG_READ_TEXT_SUPPORTED
  159697. # define PNG_TEXT_SUPPORTED
  159698. #endif
  159699. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159700. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159701. #ifdef PNG_NO_WRITE_TEXT
  159702. # define PNG_NO_WRITE_iTXt
  159703. # define PNG_NO_WRITE_tEXt
  159704. # define PNG_NO_WRITE_zTXt
  159705. #endif
  159706. #ifndef PNG_NO_WRITE_bKGD
  159707. # define PNG_WRITE_bKGD_SUPPORTED
  159708. # ifndef PNG_bKGD_SUPPORTED
  159709. # define PNG_bKGD_SUPPORTED
  159710. # endif
  159711. #endif
  159712. #ifndef PNG_NO_WRITE_cHRM
  159713. # define PNG_WRITE_cHRM_SUPPORTED
  159714. # ifndef PNG_cHRM_SUPPORTED
  159715. # define PNG_cHRM_SUPPORTED
  159716. # endif
  159717. #endif
  159718. #ifndef PNG_NO_WRITE_gAMA
  159719. # define PNG_WRITE_gAMA_SUPPORTED
  159720. # ifndef PNG_gAMA_SUPPORTED
  159721. # define PNG_gAMA_SUPPORTED
  159722. # endif
  159723. #endif
  159724. #ifndef PNG_NO_WRITE_hIST
  159725. # define PNG_WRITE_hIST_SUPPORTED
  159726. # ifndef PNG_hIST_SUPPORTED
  159727. # define PNG_hIST_SUPPORTED
  159728. # endif
  159729. #endif
  159730. #ifndef PNG_NO_WRITE_iCCP
  159731. # define PNG_WRITE_iCCP_SUPPORTED
  159732. # ifndef PNG_iCCP_SUPPORTED
  159733. # define PNG_iCCP_SUPPORTED
  159734. # endif
  159735. #endif
  159736. #ifndef PNG_NO_WRITE_iTXt
  159737. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159738. # define PNG_WRITE_iTXt_SUPPORTED
  159739. # endif
  159740. # ifndef PNG_iTXt_SUPPORTED
  159741. # define PNG_iTXt_SUPPORTED
  159742. # endif
  159743. #endif
  159744. #ifndef PNG_NO_WRITE_oFFs
  159745. # define PNG_WRITE_oFFs_SUPPORTED
  159746. # ifndef PNG_oFFs_SUPPORTED
  159747. # define PNG_oFFs_SUPPORTED
  159748. # endif
  159749. #endif
  159750. #ifndef PNG_NO_WRITE_pCAL
  159751. # define PNG_WRITE_pCAL_SUPPORTED
  159752. # ifndef PNG_pCAL_SUPPORTED
  159753. # define PNG_pCAL_SUPPORTED
  159754. # endif
  159755. #endif
  159756. #ifndef PNG_NO_WRITE_sCAL
  159757. # define PNG_WRITE_sCAL_SUPPORTED
  159758. # ifndef PNG_sCAL_SUPPORTED
  159759. # define PNG_sCAL_SUPPORTED
  159760. # endif
  159761. #endif
  159762. #ifndef PNG_NO_WRITE_pHYs
  159763. # define PNG_WRITE_pHYs_SUPPORTED
  159764. # ifndef PNG_pHYs_SUPPORTED
  159765. # define PNG_pHYs_SUPPORTED
  159766. # endif
  159767. #endif
  159768. #ifndef PNG_NO_WRITE_sBIT
  159769. # define PNG_WRITE_sBIT_SUPPORTED
  159770. # ifndef PNG_sBIT_SUPPORTED
  159771. # define PNG_sBIT_SUPPORTED
  159772. # endif
  159773. #endif
  159774. #ifndef PNG_NO_WRITE_sPLT
  159775. # define PNG_WRITE_sPLT_SUPPORTED
  159776. # ifndef PNG_sPLT_SUPPORTED
  159777. # define PNG_sPLT_SUPPORTED
  159778. # endif
  159779. #endif
  159780. #ifndef PNG_NO_WRITE_sRGB
  159781. # define PNG_WRITE_sRGB_SUPPORTED
  159782. # ifndef PNG_sRGB_SUPPORTED
  159783. # define PNG_sRGB_SUPPORTED
  159784. # endif
  159785. #endif
  159786. #ifndef PNG_NO_WRITE_tEXt
  159787. # define PNG_WRITE_tEXt_SUPPORTED
  159788. # ifndef PNG_tEXt_SUPPORTED
  159789. # define PNG_tEXt_SUPPORTED
  159790. # endif
  159791. #endif
  159792. #ifndef PNG_NO_WRITE_tIME
  159793. # define PNG_WRITE_tIME_SUPPORTED
  159794. # ifndef PNG_tIME_SUPPORTED
  159795. # define PNG_tIME_SUPPORTED
  159796. # endif
  159797. #endif
  159798. #ifndef PNG_NO_WRITE_tRNS
  159799. # define PNG_WRITE_tRNS_SUPPORTED
  159800. # ifndef PNG_tRNS_SUPPORTED
  159801. # define PNG_tRNS_SUPPORTED
  159802. # endif
  159803. #endif
  159804. #ifndef PNG_NO_WRITE_zTXt
  159805. # define PNG_WRITE_zTXt_SUPPORTED
  159806. # ifndef PNG_zTXt_SUPPORTED
  159807. # define PNG_zTXt_SUPPORTED
  159808. # endif
  159809. #endif
  159810. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159811. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159812. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159813. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159814. # endif
  159815. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159816. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159817. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159818. # endif
  159819. # endif
  159820. #endif
  159821. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159822. defined(PNG_WRITE_zTXt_SUPPORTED)
  159823. # define PNG_WRITE_TEXT_SUPPORTED
  159824. # ifndef PNG_TEXT_SUPPORTED
  159825. # define PNG_TEXT_SUPPORTED
  159826. # endif
  159827. #endif
  159828. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159829. #ifndef PNG_NO_INFO_IMAGE
  159830. # define PNG_INFO_IMAGE_SUPPORTED
  159831. #endif
  159832. #if defined(PNG_tIME_SUPPORTED)
  159833. # if !defined(_WIN32_WCE)
  159834. # include <time.h>
  159835. # endif
  159836. #endif
  159837. typedef unsigned long png_uint_32;
  159838. typedef long png_int_32;
  159839. typedef unsigned short png_uint_16;
  159840. typedef short png_int_16;
  159841. typedef unsigned char png_byte;
  159842. #ifdef PNG_SIZE_T
  159843. typedef PNG_SIZE_T png_size_t;
  159844. # define png_sizeof(x) png_convert_size(sizeof (x))
  159845. #else
  159846. typedef size_t png_size_t;
  159847. # define png_sizeof(x) sizeof (x)
  159848. #endif
  159849. #ifdef __BORLANDC__
  159850. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159851. # define LDATA 1
  159852. # else
  159853. # define LDATA 0
  159854. # endif
  159855. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159856. # define PNG_MAX_MALLOC_64K
  159857. # if (LDATA != 1)
  159858. # ifndef FAR
  159859. # define FAR __far
  159860. # endif
  159861. # define USE_FAR_KEYWORD
  159862. # endif /* LDATA != 1 */
  159863. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159864. #endif /* __BORLANDC__ */
  159865. #if defined(FAR)
  159866. # if defined(M_I86MM)
  159867. # define USE_FAR_KEYWORD
  159868. # define FARDATA FAR
  159869. # include <dos.h>
  159870. # endif
  159871. #endif
  159872. #ifndef FAR
  159873. # define FAR
  159874. #endif
  159875. #ifndef FARDATA
  159876. # define FARDATA
  159877. #endif
  159878. typedef png_int_32 png_fixed_point;
  159879. typedef void FAR * png_voidp;
  159880. typedef png_byte FAR * png_bytep;
  159881. typedef png_uint_32 FAR * png_uint_32p;
  159882. typedef png_int_32 FAR * png_int_32p;
  159883. typedef png_uint_16 FAR * png_uint_16p;
  159884. typedef png_int_16 FAR * png_int_16p;
  159885. typedef PNG_CONST char FAR * png_const_charp;
  159886. typedef char FAR * png_charp;
  159887. typedef png_fixed_point FAR * png_fixed_point_p;
  159888. #ifndef PNG_NO_STDIO
  159889. #if defined(_WIN32_WCE)
  159890. typedef HANDLE png_FILE_p;
  159891. #else
  159892. typedef FILE * png_FILE_p;
  159893. #endif
  159894. #endif
  159895. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159896. typedef double FAR * png_doublep;
  159897. #endif
  159898. typedef png_byte FAR * FAR * png_bytepp;
  159899. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159900. typedef png_int_32 FAR * FAR * png_int_32pp;
  159901. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159902. typedef png_int_16 FAR * FAR * png_int_16pp;
  159903. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159904. typedef char FAR * FAR * png_charpp;
  159905. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159906. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159907. typedef double FAR * FAR * png_doublepp;
  159908. #endif
  159909. typedef char FAR * FAR * FAR * png_charppp;
  159910. #if 0
  159911. typedef charf * png_zcharp;
  159912. typedef charf * FAR * png_zcharpp;
  159913. typedef z_stream FAR * png_zstreamp;
  159914. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159915. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159916. # define PNG_DLL
  159917. #endif
  159918. #if defined(__CYGWIN__)
  159919. # if !defined(PNG_STATIC)
  159920. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159921. # undef PNG_USE_GLOBAL_ARRAYS
  159922. # endif
  159923. # if !defined(PNG_USE_LOCAL_ARRAYS)
  159924. # define PNG_USE_LOCAL_ARRAYS
  159925. # endif
  159926. # else
  159927. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  159928. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159929. # undef PNG_USE_GLOBAL_ARRAYS
  159930. # endif
  159931. # endif
  159932. # endif
  159933. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159934. # define PNG_USE_LOCAL_ARRAYS
  159935. # endif
  159936. #endif
  159937. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159938. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  159939. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  159940. # define PNG_USE_LOCAL_ARRAYS
  159941. # else
  159942. # define PNG_USE_GLOBAL_ARRAYS
  159943. # endif
  159944. #endif
  159945. #if defined(__CYGWIN__)
  159946. # undef PNGAPI
  159947. # define PNGAPI __cdecl
  159948. # undef PNG_IMPEXP
  159949. # define PNG_IMPEXP
  159950. #endif
  159951. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  159952. # ifndef PNG_NO_MODULEDEF
  159953. # define PNG_NO_MODULEDEF
  159954. # endif
  159955. #endif
  159956. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  159957. # define PNG_IMPEXP
  159958. #endif
  159959. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  159960. (( defined(_Windows) || defined(_WINDOWS) || \
  159961. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  159962. # ifndef PNGAPI
  159963. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  159964. # define PNGAPI __cdecl
  159965. # else
  159966. # define PNGAPI _cdecl
  159967. # endif
  159968. # endif
  159969. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  159970. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  159971. # define PNG_IMPEXP
  159972. # endif
  159973. # if !defined(PNG_IMPEXP)
  159974. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159975. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  159976. # if defined(_MSC_VER) || defined(__BORLANDC__)
  159977. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  159978. # define PNG_EXPORT PNG_EXPORT_TYPE1
  159979. # else
  159980. # define PNG_EXPORT PNG_EXPORT_TYPE2
  159981. # if defined(PNG_BUILD_DLL)
  159982. # define PNG_IMPEXP __export
  159983. # else
  159984. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  159985. VC++ */
  159986. # endif /* Exists in Borland C++ for
  159987. C++ classes (== huge) */
  159988. # endif
  159989. # endif
  159990. # if !defined(PNG_IMPEXP)
  159991. # if defined(PNG_BUILD_DLL)
  159992. # define PNG_IMPEXP __declspec(dllexport)
  159993. # else
  159994. # define PNG_IMPEXP __declspec(dllimport)
  159995. # endif
  159996. # endif
  159997. # endif /* PNG_IMPEXP */
  159998. #else /* !(DLL || non-cygwin WINDOWS) */
  159999. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160000. # ifndef PNGAPI
  160001. # define PNGAPI _System
  160002. # endif
  160003. # else
  160004. # if 0 /* ... other platforms, with other meanings */
  160005. # endif
  160006. # endif
  160007. #endif
  160008. #ifndef PNGAPI
  160009. # define PNGAPI
  160010. #endif
  160011. #ifndef PNG_IMPEXP
  160012. # define PNG_IMPEXP
  160013. #endif
  160014. #ifdef PNG_BUILDSYMS
  160015. # ifndef PNG_EXPORT
  160016. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160017. # endif
  160018. # ifdef PNG_USE_GLOBAL_ARRAYS
  160019. # ifndef PNG_EXPORT_VAR
  160020. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160021. # endif
  160022. # endif
  160023. #endif
  160024. #ifndef PNG_EXPORT
  160025. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160026. #endif
  160027. #ifdef PNG_USE_GLOBAL_ARRAYS
  160028. # ifndef PNG_EXPORT_VAR
  160029. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160030. # endif
  160031. #endif
  160032. #ifndef PNG_ABORT
  160033. # define PNG_ABORT() abort()
  160034. #endif
  160035. #ifdef PNG_SETJMP_SUPPORTED
  160036. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160037. #else
  160038. # define png_jmpbuf(png_ptr) \
  160039. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160040. #endif
  160041. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160042. # define CHECK 1
  160043. # define NOCHECK 0
  160044. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160045. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160046. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160047. # define png_strcpy _fstrcpy
  160048. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160049. # define png_strlen _fstrlen
  160050. # define png_memcmp _fmemcmp /* SJT: added */
  160051. # define png_memcpy _fmemcpy
  160052. # define png_memset _fmemset
  160053. #else /* use the usual functions */
  160054. # define CVT_PTR(ptr) (ptr)
  160055. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160056. # ifndef PNG_NO_SNPRINTF
  160057. # ifdef _MSC_VER
  160058. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160059. # define png_snprintf2 _snprintf
  160060. # define png_snprintf6 _snprintf
  160061. # else
  160062. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160063. # define png_snprintf2 snprintf
  160064. # define png_snprintf6 snprintf
  160065. # endif
  160066. # else
  160067. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160068. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160069. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160070. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160071. # endif
  160072. # define png_strcpy strcpy
  160073. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160074. # define png_strlen strlen
  160075. # define png_memcmp memcmp /* SJT: added */
  160076. # define png_memcpy memcpy
  160077. # define png_memset memset
  160078. #endif
  160079. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160080. # undef PNG_ZBUF_SIZE
  160081. # define PNG_ZBUF_SIZE 65536L
  160082. #endif
  160083. #endif /* PNG_VERSION_INFO_ONLY */
  160084. #endif /* PNGCONF_H */
  160085. /*** End of inlined file: pngconf.h ***/
  160086. #ifdef _MSC_VER
  160087. #pragma warning (disable: 4996 4100)
  160088. #endif
  160089. #if defined(PNG_USER_PRIVATEBUILD)
  160090. # define PNG_LIBPNG_BUILD_TYPE \
  160091. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160092. #else
  160093. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160094. # define PNG_LIBPNG_BUILD_TYPE \
  160095. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160096. # else
  160097. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160098. # endif
  160099. #endif
  160100. #ifndef PNG_VERSION_INFO_ONLY
  160101. #ifdef __cplusplus
  160102. extern "C" {
  160103. #endif /* __cplusplus */
  160104. #ifndef PNG_NO_TYPECAST_NULL
  160105. #define int_p_NULL (int *)NULL
  160106. #define png_bytep_NULL (png_bytep)NULL
  160107. #define png_bytepp_NULL (png_bytepp)NULL
  160108. #define png_doublep_NULL (png_doublep)NULL
  160109. #define png_error_ptr_NULL (png_error_ptr)NULL
  160110. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160111. #define png_free_ptr_NULL (png_free_ptr)NULL
  160112. #define png_infopp_NULL (png_infopp)NULL
  160113. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160114. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160115. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160116. #define png_structp_NULL (png_structp)NULL
  160117. #define png_uint_16p_NULL (png_uint_16p)NULL
  160118. #define png_voidp_NULL (png_voidp)NULL
  160119. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160120. #else
  160121. #define int_p_NULL NULL
  160122. #define png_bytep_NULL NULL
  160123. #define png_bytepp_NULL NULL
  160124. #define png_doublep_NULL NULL
  160125. #define png_error_ptr_NULL NULL
  160126. #define png_flush_ptr_NULL NULL
  160127. #define png_free_ptr_NULL NULL
  160128. #define png_infopp_NULL NULL
  160129. #define png_malloc_ptr_NULL NULL
  160130. #define png_read_status_ptr_NULL NULL
  160131. #define png_rw_ptr_NULL NULL
  160132. #define png_structp_NULL NULL
  160133. #define png_uint_16p_NULL NULL
  160134. #define png_voidp_NULL NULL
  160135. #define png_write_status_ptr_NULL NULL
  160136. #endif
  160137. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160138. #ifdef PNG_USE_GLOBAL_ARRAYS
  160139. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160140. #else
  160141. #define png_libpng_ver png_get_header_ver(NULL)
  160142. #endif
  160143. #ifdef PNG_USE_GLOBAL_ARRAYS
  160144. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160145. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160146. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160147. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160148. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160149. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160150. #endif
  160151. #endif /* PNG_NO_EXTERN */
  160152. typedef struct png_color_struct
  160153. {
  160154. png_byte red;
  160155. png_byte green;
  160156. png_byte blue;
  160157. } png_color;
  160158. typedef png_color FAR * png_colorp;
  160159. typedef png_color FAR * FAR * png_colorpp;
  160160. typedef struct png_color_16_struct
  160161. {
  160162. png_byte index; /* used for palette files */
  160163. png_uint_16 red; /* for use in red green blue files */
  160164. png_uint_16 green;
  160165. png_uint_16 blue;
  160166. png_uint_16 gray; /* for use in grayscale files */
  160167. } png_color_16;
  160168. typedef png_color_16 FAR * png_color_16p;
  160169. typedef png_color_16 FAR * FAR * png_color_16pp;
  160170. typedef struct png_color_8_struct
  160171. {
  160172. png_byte red; /* for use in red green blue files */
  160173. png_byte green;
  160174. png_byte blue;
  160175. png_byte gray; /* for use in grayscale files */
  160176. png_byte alpha; /* for alpha channel files */
  160177. } png_color_8;
  160178. typedef png_color_8 FAR * png_color_8p;
  160179. typedef png_color_8 FAR * FAR * png_color_8pp;
  160180. typedef struct png_sPLT_entry_struct
  160181. {
  160182. png_uint_16 red;
  160183. png_uint_16 green;
  160184. png_uint_16 blue;
  160185. png_uint_16 alpha;
  160186. png_uint_16 frequency;
  160187. } png_sPLT_entry;
  160188. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160189. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160190. typedef struct png_sPLT_struct
  160191. {
  160192. png_charp name; /* palette name */
  160193. png_byte depth; /* depth of palette samples */
  160194. png_sPLT_entryp entries; /* palette entries */
  160195. png_int_32 nentries; /* number of palette entries */
  160196. } png_sPLT_t;
  160197. typedef png_sPLT_t FAR * png_sPLT_tp;
  160198. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160199. #ifdef PNG_TEXT_SUPPORTED
  160200. typedef struct png_text_struct
  160201. {
  160202. int compression; /* compression value:
  160203. -1: tEXt, none
  160204. 0: zTXt, deflate
  160205. 1: iTXt, none
  160206. 2: iTXt, deflate */
  160207. png_charp key; /* keyword, 1-79 character description of "text" */
  160208. png_charp text; /* comment, may be an empty string (ie "")
  160209. or a NULL pointer */
  160210. png_size_t text_length; /* length of the text string */
  160211. #ifdef PNG_iTXt_SUPPORTED
  160212. png_size_t itxt_length; /* length of the itxt string */
  160213. png_charp lang; /* language code, 0-79 characters
  160214. or a NULL pointer */
  160215. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160216. chars or a NULL pointer */
  160217. #endif
  160218. } png_text;
  160219. typedef png_text FAR * png_textp;
  160220. typedef png_text FAR * FAR * png_textpp;
  160221. #endif
  160222. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160223. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160224. #define PNG_TEXT_COMPRESSION_NONE -1
  160225. #define PNG_TEXT_COMPRESSION_zTXt 0
  160226. #define PNG_ITXT_COMPRESSION_NONE 1
  160227. #define PNG_ITXT_COMPRESSION_zTXt 2
  160228. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160229. typedef struct png_time_struct
  160230. {
  160231. png_uint_16 year; /* full year, as in, 1995 */
  160232. png_byte month; /* month of year, 1 - 12 */
  160233. png_byte day; /* day of month, 1 - 31 */
  160234. png_byte hour; /* hour of day, 0 - 23 */
  160235. png_byte minute; /* minute of hour, 0 - 59 */
  160236. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160237. } png_time;
  160238. typedef png_time FAR * png_timep;
  160239. typedef png_time FAR * FAR * png_timepp;
  160240. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160241. typedef struct png_unknown_chunk_t
  160242. {
  160243. png_byte name[5];
  160244. png_byte *data;
  160245. png_size_t size;
  160246. png_byte location; /* mode of operation at read time */
  160247. }
  160248. png_unknown_chunk;
  160249. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160250. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160251. #endif
  160252. typedef struct png_info_struct
  160253. {
  160254. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160255. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160256. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160257. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160258. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160259. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160260. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160261. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160262. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160263. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160264. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160265. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160266. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160267. png_byte pixel_depth; /* number of bits per pixel */
  160268. png_byte spare_byte; /* to align the data, and for future use */
  160269. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160270. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160271. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160272. #endif
  160273. #if defined(PNG_sRGB_SUPPORTED)
  160274. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160275. #endif
  160276. #if defined(PNG_TEXT_SUPPORTED)
  160277. int num_text; /* number of comments read/to write */
  160278. int max_text; /* current size of text array */
  160279. png_textp text; /* array of comments read/to write */
  160280. #endif /* PNG_TEXT_SUPPORTED */
  160281. #if defined(PNG_tIME_SUPPORTED)
  160282. png_time mod_time;
  160283. #endif
  160284. #if defined(PNG_sBIT_SUPPORTED)
  160285. png_color_8 sig_bit; /* significant bits in color channels */
  160286. #endif
  160287. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160288. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160289. png_bytep trans; /* transparent values for paletted image */
  160290. png_color_16 trans_values; /* transparent color for non-palette image */
  160291. #endif
  160292. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160293. png_color_16 background;
  160294. #endif
  160295. #if defined(PNG_oFFs_SUPPORTED)
  160296. png_int_32 x_offset; /* x offset on page */
  160297. png_int_32 y_offset; /* y offset on page */
  160298. png_byte offset_unit_type; /* offset units type */
  160299. #endif
  160300. #if defined(PNG_pHYs_SUPPORTED)
  160301. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160302. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160303. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160304. #endif
  160305. #if defined(PNG_hIST_SUPPORTED)
  160306. png_uint_16p hist;
  160307. #endif
  160308. #ifdef PNG_cHRM_SUPPORTED
  160309. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160310. float x_white;
  160311. float y_white;
  160312. float x_red;
  160313. float y_red;
  160314. float x_green;
  160315. float y_green;
  160316. float x_blue;
  160317. float y_blue;
  160318. #endif
  160319. #endif
  160320. #if defined(PNG_pCAL_SUPPORTED)
  160321. png_charp pcal_purpose; /* pCAL chunk description string */
  160322. png_int_32 pcal_X0; /* minimum value */
  160323. png_int_32 pcal_X1; /* maximum value */
  160324. png_charp pcal_units; /* Latin-1 string giving physical units */
  160325. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160326. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160327. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160328. #endif
  160329. #ifdef PNG_FREE_ME_SUPPORTED
  160330. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160331. #endif
  160332. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160333. png_unknown_chunkp unknown_chunks;
  160334. png_size_t unknown_chunks_num;
  160335. #endif
  160336. #if defined(PNG_iCCP_SUPPORTED)
  160337. png_charp iccp_name; /* profile name */
  160338. png_charp iccp_profile; /* International Color Consortium profile data */
  160339. png_uint_32 iccp_proflen; /* ICC profile data length */
  160340. png_byte iccp_compression; /* Always zero */
  160341. #endif
  160342. #if defined(PNG_sPLT_SUPPORTED)
  160343. png_sPLT_tp splt_palettes;
  160344. png_uint_32 splt_palettes_num;
  160345. #endif
  160346. #if defined(PNG_sCAL_SUPPORTED)
  160347. png_byte scal_unit; /* unit of physical scale */
  160348. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160349. double scal_pixel_width; /* width of one pixel */
  160350. double scal_pixel_height; /* height of one pixel */
  160351. #endif
  160352. #ifdef PNG_FIXED_POINT_SUPPORTED
  160353. png_charp scal_s_width; /* string containing height */
  160354. png_charp scal_s_height; /* string containing width */
  160355. #endif
  160356. #endif
  160357. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160358. png_bytepp row_pointers; /* the image bits */
  160359. #endif
  160360. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160361. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160362. #endif
  160363. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160364. png_fixed_point int_x_white;
  160365. png_fixed_point int_y_white;
  160366. png_fixed_point int_x_red;
  160367. png_fixed_point int_y_red;
  160368. png_fixed_point int_x_green;
  160369. png_fixed_point int_y_green;
  160370. png_fixed_point int_x_blue;
  160371. png_fixed_point int_y_blue;
  160372. #endif
  160373. } png_info;
  160374. typedef png_info FAR * png_infop;
  160375. typedef png_info FAR * FAR * png_infopp;
  160376. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160377. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160378. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160379. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160380. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160381. #endif
  160382. #define PNG_COLOR_MASK_PALETTE 1
  160383. #define PNG_COLOR_MASK_COLOR 2
  160384. #define PNG_COLOR_MASK_ALPHA 4
  160385. #define PNG_COLOR_TYPE_GRAY 0
  160386. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160387. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160388. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160389. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160390. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160391. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160392. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160393. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160394. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160395. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160396. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160397. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160398. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160399. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160400. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160401. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160402. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160403. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160404. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160405. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160406. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160407. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160408. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160409. #define PNG_SCALE_METER 1 /* meters per pixel */
  160410. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160411. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160412. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160413. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160414. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160415. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160416. #define PNG_sRGB_INTENT_RELATIVE 1
  160417. #define PNG_sRGB_INTENT_SATURATION 2
  160418. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160419. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160420. #define PNG_KEYWORD_MAX_LENGTH 79
  160421. #define PNG_MAX_PALETTE_LENGTH 256
  160422. #define PNG_INFO_gAMA 0x0001
  160423. #define PNG_INFO_sBIT 0x0002
  160424. #define PNG_INFO_cHRM 0x0004
  160425. #define PNG_INFO_PLTE 0x0008
  160426. #define PNG_INFO_tRNS 0x0010
  160427. #define PNG_INFO_bKGD 0x0020
  160428. #define PNG_INFO_hIST 0x0040
  160429. #define PNG_INFO_pHYs 0x0080
  160430. #define PNG_INFO_oFFs 0x0100
  160431. #define PNG_INFO_tIME 0x0200
  160432. #define PNG_INFO_pCAL 0x0400
  160433. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160434. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160435. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160436. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160437. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160438. typedef struct png_row_info_struct
  160439. {
  160440. png_uint_32 width; /* width of row */
  160441. png_uint_32 rowbytes; /* number of bytes in row */
  160442. png_byte color_type; /* color type of row */
  160443. png_byte bit_depth; /* bit depth of row */
  160444. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160445. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160446. } png_row_info;
  160447. typedef png_row_info FAR * png_row_infop;
  160448. typedef png_row_info FAR * FAR * png_row_infopp;
  160449. typedef struct png_struct_def png_struct;
  160450. typedef png_struct FAR * png_structp;
  160451. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160452. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160453. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160454. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160455. int));
  160456. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160457. int));
  160458. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160459. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160460. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160461. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160462. png_uint_32, int));
  160463. #endif
  160464. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160465. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160466. defined(PNG_LEGACY_SUPPORTED)
  160467. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160468. png_row_infop, png_bytep));
  160469. #endif
  160470. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160471. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160472. #endif
  160473. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160474. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160475. #endif
  160476. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160477. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160478. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160479. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160480. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160481. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160482. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160483. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160484. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160485. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160486. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160487. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160488. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160489. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160490. #define PNG_FLAG_MNG_FILTER_64 0x04
  160491. #define PNG_ALL_MNG_FEATURES 0x05
  160492. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160493. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160494. struct png_struct_def
  160495. {
  160496. #ifdef PNG_SETJMP_SUPPORTED
  160497. jmp_buf jmpbuf; /* used in png_error */
  160498. #endif
  160499. png_error_ptr error_fn; /* function for printing errors and aborting */
  160500. png_error_ptr warning_fn; /* function for printing warnings */
  160501. png_voidp error_ptr; /* user supplied struct for error functions */
  160502. png_rw_ptr write_data_fn; /* function for writing output data */
  160503. png_rw_ptr read_data_fn; /* function for reading input data */
  160504. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160505. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160506. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160507. #endif
  160508. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160509. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160510. #endif
  160511. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160512. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160513. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160514. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160515. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160516. png_byte user_transform_channels; /* channels in user transformed pixels */
  160517. #endif
  160518. #endif
  160519. png_uint_32 mode; /* tells us where we are in the PNG file */
  160520. png_uint_32 flags; /* flags indicating various things to libpng */
  160521. png_uint_32 transformations; /* which transformations to perform */
  160522. z_stream zstream; /* pointer to decompression structure (below) */
  160523. png_bytep zbuf; /* buffer for zlib */
  160524. png_size_t zbuf_size; /* size of zbuf */
  160525. int zlib_level; /* holds zlib compression level */
  160526. int zlib_method; /* holds zlib compression method */
  160527. int zlib_window_bits; /* holds zlib compression window bits */
  160528. int zlib_mem_level; /* holds zlib compression memory level */
  160529. int zlib_strategy; /* holds zlib compression strategy */
  160530. png_uint_32 width; /* width of image in pixels */
  160531. png_uint_32 height; /* height of image in pixels */
  160532. png_uint_32 num_rows; /* number of rows in current pass */
  160533. png_uint_32 usr_width; /* width of row at start of write */
  160534. png_uint_32 rowbytes; /* size of row in bytes */
  160535. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160536. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160537. png_uint_32 row_number; /* current row in interlace pass */
  160538. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160539. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160540. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160541. png_bytep up_row; /* buffer to save "up" row when filtering */
  160542. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160543. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160544. png_row_info row_info; /* used for transformation routines */
  160545. png_uint_32 idat_size; /* current IDAT size for read */
  160546. png_uint_32 crc; /* current chunk CRC value */
  160547. png_colorp palette; /* palette from the input file */
  160548. png_uint_16 num_palette; /* number of color entries in palette */
  160549. png_uint_16 num_trans; /* number of transparency values */
  160550. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160551. png_byte compression; /* file compression type (always 0) */
  160552. png_byte filter; /* file filter type (always 0) */
  160553. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160554. png_byte pass; /* current interlace pass (0 - 6) */
  160555. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160556. png_byte color_type; /* color type of file */
  160557. png_byte bit_depth; /* bit depth of file */
  160558. png_byte usr_bit_depth; /* bit depth of users row */
  160559. png_byte pixel_depth; /* number of bits per pixel */
  160560. png_byte channels; /* number of channels in file */
  160561. png_byte usr_channels; /* channels at start of write */
  160562. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160563. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160564. #ifdef PNG_LEGACY_SUPPORTED
  160565. png_byte filler; /* filler byte for pixel expansion */
  160566. #else
  160567. png_uint_16 filler; /* filler bytes for pixel expansion */
  160568. #endif
  160569. #endif
  160570. #if defined(PNG_bKGD_SUPPORTED)
  160571. png_byte background_gamma_type;
  160572. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160573. float background_gamma;
  160574. # endif
  160575. png_color_16 background; /* background color in screen gamma space */
  160576. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160577. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160578. #endif
  160579. #endif /* PNG_bKGD_SUPPORTED */
  160580. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160581. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160582. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160583. png_uint_32 flush_rows; /* number of rows written since last flush */
  160584. #endif
  160585. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160586. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160587. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160588. float gamma; /* file gamma value */
  160589. float screen_gamma; /* screen gamma value (display_exponent) */
  160590. #endif
  160591. #endif
  160592. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160593. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160594. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160595. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160596. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160597. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160598. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160599. #endif
  160600. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160601. png_color_8 sig_bit; /* significant bits in each available channel */
  160602. #endif
  160603. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160604. png_color_8 shift; /* shift for significant bit tranformation */
  160605. #endif
  160606. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160607. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160608. png_bytep trans; /* transparency values for paletted files */
  160609. png_color_16 trans_values; /* transparency values for non-paletted files */
  160610. #endif
  160611. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160612. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160613. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160614. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160615. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160616. png_progressive_end_ptr end_fn; /* called after image is complete */
  160617. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160618. png_bytep save_buffer; /* buffer for previously read data */
  160619. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160620. png_bytep current_buffer; /* buffer for recently used data */
  160621. png_uint_32 push_length; /* size of current input chunk */
  160622. png_uint_32 skip_length; /* bytes to skip in input data */
  160623. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160624. png_size_t save_buffer_max; /* total size of save_buffer */
  160625. png_size_t buffer_size; /* total amount of available input data */
  160626. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160627. int process_mode; /* what push library is currently doing */
  160628. int cur_palette; /* current push library palette index */
  160629. # if defined(PNG_TEXT_SUPPORTED)
  160630. png_size_t current_text_size; /* current size of text input data */
  160631. png_size_t current_text_left; /* how much text left to read in input */
  160632. png_charp current_text; /* current text chunk buffer */
  160633. png_charp current_text_ptr; /* current location in current_text */
  160634. # endif /* PNG_TEXT_SUPPORTED */
  160635. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160636. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160637. png_bytepp offset_table_ptr;
  160638. png_bytep offset_table;
  160639. png_uint_16 offset_table_number;
  160640. png_uint_16 offset_table_count;
  160641. png_uint_16 offset_table_count_free;
  160642. #endif
  160643. #if defined(PNG_READ_DITHER_SUPPORTED)
  160644. png_bytep palette_lookup; /* lookup table for dithering */
  160645. png_bytep dither_index; /* index translation for palette files */
  160646. #endif
  160647. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160648. png_uint_16p hist; /* histogram */
  160649. #endif
  160650. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160651. png_byte heuristic_method; /* heuristic for row filter selection */
  160652. png_byte num_prev_filters; /* number of weights for previous rows */
  160653. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160654. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160655. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160656. png_uint_16p filter_costs; /* relative filter calculation cost */
  160657. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160658. #endif
  160659. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160660. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160661. #endif
  160662. #ifdef PNG_FREE_ME_SUPPORTED
  160663. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160664. #endif
  160665. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160666. png_voidp user_chunk_ptr;
  160667. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160668. #endif
  160669. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160670. int num_chunk_list;
  160671. png_bytep chunk_list;
  160672. #endif
  160673. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160674. png_byte rgb_to_gray_status;
  160675. png_uint_16 rgb_to_gray_red_coeff;
  160676. png_uint_16 rgb_to_gray_green_coeff;
  160677. png_uint_16 rgb_to_gray_blue_coeff;
  160678. #endif
  160679. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160680. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160681. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160682. #ifdef PNG_1_0_X
  160683. png_byte mng_features_permitted;
  160684. #else
  160685. png_uint_32 mng_features_permitted;
  160686. #endif /* PNG_1_0_X */
  160687. #endif
  160688. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160689. png_fixed_point int_gamma;
  160690. #endif
  160691. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160692. png_byte filter_type;
  160693. #endif
  160694. #if defined(PNG_1_0_X)
  160695. png_uint_32 row_buf_size;
  160696. #endif
  160697. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160698. # if !defined(PNG_1_0_X)
  160699. # if defined(PNG_MMX_CODE_SUPPORTED)
  160700. png_byte mmx_bitdepth_threshold;
  160701. png_uint_32 mmx_rowbytes_threshold;
  160702. # endif
  160703. png_uint_32 asm_flags;
  160704. # endif
  160705. #endif
  160706. #ifdef PNG_USER_MEM_SUPPORTED
  160707. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160708. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160709. png_free_ptr free_fn; /* function for freeing memory */
  160710. #endif
  160711. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160712. #if defined(PNG_READ_DITHER_SUPPORTED)
  160713. png_bytep dither_sort; /* working sort array */
  160714. png_bytep index_to_palette; /* where the original index currently is */
  160715. png_bytep palette_to_index; /* which original index points to this */
  160716. #endif
  160717. png_byte compression_type;
  160718. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160719. png_uint_32 user_width_max;
  160720. png_uint_32 user_height_max;
  160721. #endif
  160722. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160723. png_unknown_chunk unknown_chunk;
  160724. #endif
  160725. };
  160726. typedef png_structp version_1_2_21;
  160727. typedef png_struct FAR * FAR * png_structpp;
  160728. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160729. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160730. int num_bytes));
  160731. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160732. png_size_t num_to_check));
  160733. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160734. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160735. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160736. png_error_ptr error_fn, png_error_ptr warn_fn));
  160737. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160738. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160739. png_error_ptr error_fn, png_error_ptr warn_fn));
  160740. #ifdef PNG_WRITE_SUPPORTED
  160741. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160742. PNGARG((png_structp png_ptr));
  160743. #endif
  160744. #ifdef PNG_WRITE_SUPPORTED
  160745. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160746. PNGARG((png_structp png_ptr, png_uint_32 size));
  160747. #endif
  160748. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160749. #ifdef PNG_USER_MEM_SUPPORTED
  160750. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160751. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160752. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160753. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160754. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160755. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160756. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160757. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160758. #endif
  160759. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160760. png_bytep chunk_name, png_bytep data, png_size_t length));
  160761. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160762. png_bytep chunk_name, png_uint_32 length));
  160763. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160764. png_bytep data, png_size_t length));
  160765. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160766. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160767. PNGARG((png_structp png_ptr));
  160768. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160769. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160770. #undef png_info_init
  160771. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160772. png_sizeof(png_info));
  160773. #endif
  160774. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160775. png_size_t png_info_struct_size));
  160776. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160777. png_infop info_ptr));
  160778. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160779. png_infop info_ptr));
  160780. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160781. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160782. png_infop info_ptr));
  160783. #endif
  160784. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160785. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160786. PNGARG((png_structp png_ptr, png_timep ptime));
  160787. #endif
  160788. #if !defined(_WIN32_WCE)
  160789. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160790. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160791. struct tm FAR * ttime));
  160792. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160793. time_t ttime));
  160794. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160795. #endif /* _WIN32_WCE */
  160796. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160797. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160798. #if !defined(PNG_1_0_X)
  160799. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160800. png_ptr));
  160801. #endif
  160802. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160803. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160804. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160805. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160806. #endif
  160807. #endif
  160808. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160809. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160810. #endif
  160811. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160812. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160813. #endif
  160814. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160815. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160816. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160817. int error_action, double red, double green ));
  160818. #endif
  160819. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160820. int error_action, png_fixed_point red, png_fixed_point green ));
  160821. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160822. png_ptr));
  160823. #endif
  160824. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160825. png_colorp palette));
  160826. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160827. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160828. #endif
  160829. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160830. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160831. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160832. #endif
  160833. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160834. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160835. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160836. #endif
  160837. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160838. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160839. png_uint_32 filler, int flags));
  160840. #define PNG_FILLER_BEFORE 0
  160841. #define PNG_FILLER_AFTER 1
  160842. #if !defined(PNG_1_0_X)
  160843. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160844. png_uint_32 filler, int flags));
  160845. #endif
  160846. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160847. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160848. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160849. #endif
  160850. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160851. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160852. #endif
  160853. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160854. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160855. #endif
  160856. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160857. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160858. png_color_8p true_bits));
  160859. #endif
  160860. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160861. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160862. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160863. #endif
  160864. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160865. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160866. #endif
  160867. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160868. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160869. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160870. png_color_16p background_color, int background_gamma_code,
  160871. int need_expand, double background_gamma));
  160872. #endif
  160873. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160874. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160875. #define PNG_BACKGROUND_GAMMA_FILE 2
  160876. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160877. #endif
  160878. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160879. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160880. #endif
  160881. #if defined(PNG_READ_DITHER_SUPPORTED)
  160882. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160883. png_colorp palette, int num_palette, int maximum_colors,
  160884. png_uint_16p histogram, int full_dither));
  160885. #endif
  160886. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160887. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160888. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160889. double screen_gamma, double default_file_gamma));
  160890. #endif
  160891. #endif
  160892. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160893. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160894. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160895. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160896. int empty_plte_permitted));
  160897. #endif
  160898. #endif
  160899. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160900. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160901. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160902. #endif
  160903. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160904. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160905. png_infop info_ptr));
  160906. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160907. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160908. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160909. #endif
  160910. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160911. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160912. png_bytep row,
  160913. png_bytep display_row));
  160914. #endif
  160915. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160916. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160917. png_bytepp image));
  160918. #endif
  160919. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  160920. png_bytep row));
  160921. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  160922. png_bytepp row, png_uint_32 num_rows));
  160923. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  160924. png_bytepp image));
  160925. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  160926. png_infop info_ptr));
  160927. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160928. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  160929. png_infop info_ptr));
  160930. #endif
  160931. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  160932. png_infopp info_ptr_ptr));
  160933. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  160934. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  160935. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  160936. png_infop end_info_ptr));
  160937. extern PNG_EXPORT(void,png_destroy_write_struct)
  160938. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  160939. extern void png_write_destroy PNGARG((png_structp png_ptr));
  160940. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  160941. int crit_action, int ancil_action));
  160942. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  160943. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  160944. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  160945. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  160946. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  160947. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  160948. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  160949. int filters));
  160950. #define PNG_NO_FILTERS 0x00
  160951. #define PNG_FILTER_NONE 0x08
  160952. #define PNG_FILTER_SUB 0x10
  160953. #define PNG_FILTER_UP 0x20
  160954. #define PNG_FILTER_AVG 0x40
  160955. #define PNG_FILTER_PAETH 0x80
  160956. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  160957. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  160958. #define PNG_FILTER_VALUE_NONE 0
  160959. #define PNG_FILTER_VALUE_SUB 1
  160960. #define PNG_FILTER_VALUE_UP 2
  160961. #define PNG_FILTER_VALUE_AVG 3
  160962. #define PNG_FILTER_VALUE_PAETH 4
  160963. #define PNG_FILTER_VALUE_LAST 5
  160964. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  160965. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160966. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  160967. int heuristic_method, int num_weights, png_doublep filter_weights,
  160968. png_doublep filter_costs));
  160969. #endif
  160970. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  160971. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  160972. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  160973. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  160974. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  160975. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  160976. int level));
  160977. extern PNG_EXPORT(void,png_set_compression_mem_level)
  160978. PNGARG((png_structp png_ptr, int mem_level));
  160979. extern PNG_EXPORT(void,png_set_compression_strategy)
  160980. PNGARG((png_structp png_ptr, int strategy));
  160981. extern PNG_EXPORT(void,png_set_compression_window_bits)
  160982. PNGARG((png_structp png_ptr, int window_bits));
  160983. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  160984. int method));
  160985. #if !defined(PNG_NO_STDIO)
  160986. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  160987. #endif
  160988. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  160989. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  160990. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  160991. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  160992. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  160993. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  160994. png_voidp io_ptr, png_rw_ptr read_data_fn));
  160995. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  160996. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  160997. png_read_status_ptr read_row_fn));
  160998. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  160999. png_write_status_ptr write_row_fn));
  161000. #ifdef PNG_USER_MEM_SUPPORTED
  161001. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161002. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161003. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161004. #endif
  161005. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161006. defined(PNG_LEGACY_SUPPORTED)
  161007. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161008. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161009. #endif
  161010. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161011. defined(PNG_LEGACY_SUPPORTED)
  161012. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161013. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161014. #endif
  161015. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161016. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161017. defined(PNG_LEGACY_SUPPORTED)
  161018. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161019. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161020. int user_transform_channels));
  161021. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161022. PNGARG((png_structp png_ptr));
  161023. #endif
  161024. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161025. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161026. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161027. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161028. png_ptr));
  161029. #endif
  161030. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161031. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161032. png_voidp progressive_ptr,
  161033. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161034. png_progressive_end_ptr end_fn));
  161035. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161036. PNGARG((png_structp png_ptr));
  161037. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161038. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161039. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161040. png_bytep old_row, png_bytep new_row));
  161041. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161042. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161043. png_uint_32 size));
  161044. #if defined(PNG_1_0_X)
  161045. # define png_malloc_warn png_malloc
  161046. #else
  161047. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161048. png_uint_32 size));
  161049. #endif
  161050. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161051. #if defined(PNG_1_0_X)
  161052. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161053. uInt size));
  161054. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161055. #endif
  161056. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161057. png_infop info_ptr, png_uint_32 free_me, int num));
  161058. #ifdef PNG_FREE_ME_SUPPORTED
  161059. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161060. png_infop info_ptr, int freer, png_uint_32 mask));
  161061. #endif
  161062. #define PNG_DESTROY_WILL_FREE_DATA 1
  161063. #define PNG_SET_WILL_FREE_DATA 1
  161064. #define PNG_USER_WILL_FREE_DATA 2
  161065. #define PNG_FREE_HIST 0x0008
  161066. #define PNG_FREE_ICCP 0x0010
  161067. #define PNG_FREE_SPLT 0x0020
  161068. #define PNG_FREE_ROWS 0x0040
  161069. #define PNG_FREE_PCAL 0x0080
  161070. #define PNG_FREE_SCAL 0x0100
  161071. #define PNG_FREE_UNKN 0x0200
  161072. #define PNG_FREE_LIST 0x0400
  161073. #define PNG_FREE_PLTE 0x1000
  161074. #define PNG_FREE_TRNS 0x2000
  161075. #define PNG_FREE_TEXT 0x4000
  161076. #define PNG_FREE_ALL 0x7fff
  161077. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161078. #ifdef PNG_USER_MEM_SUPPORTED
  161079. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161080. png_uint_32 size));
  161081. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161082. png_voidp ptr));
  161083. #endif
  161084. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161085. png_voidp s1, png_voidp s2, png_uint_32 size));
  161086. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161087. png_voidp s1, int value, png_uint_32 size));
  161088. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161089. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161090. int check));
  161091. #endif /* USE_FAR_KEYWORD */
  161092. #ifndef PNG_NO_ERROR_TEXT
  161093. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161094. png_const_charp error_message));
  161095. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161096. png_const_charp error_message));
  161097. #else
  161098. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161099. #endif
  161100. #ifndef PNG_NO_WARNINGS
  161101. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161102. png_const_charp warning_message));
  161103. #ifdef PNG_READ_SUPPORTED
  161104. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161105. png_const_charp warning_message));
  161106. #endif /* PNG_READ_SUPPORTED */
  161107. #endif /* PNG_NO_WARNINGS */
  161108. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161109. png_infop info_ptr, png_uint_32 flag));
  161110. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161111. png_infop info_ptr));
  161112. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161113. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161114. png_infop info_ptr));
  161115. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161116. png_infop info_ptr, png_bytepp row_pointers));
  161117. #endif
  161118. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161119. png_infop info_ptr));
  161120. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161121. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161122. png_ptr, png_infop info_ptr));
  161123. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161124. png_ptr, png_infop info_ptr));
  161125. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161126. png_ptr, png_infop info_ptr));
  161127. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161128. png_ptr, png_infop info_ptr));
  161129. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161130. png_ptr, png_infop info_ptr));
  161131. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161132. png_ptr, png_infop info_ptr));
  161133. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161134. png_ptr, png_infop info_ptr));
  161135. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161136. png_ptr, png_infop info_ptr));
  161137. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161138. png_ptr, png_infop info_ptr));
  161139. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161140. png_ptr, png_infop info_ptr));
  161141. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161142. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161143. png_ptr, png_infop info_ptr));
  161144. #endif
  161145. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161146. png_ptr, png_infop info_ptr));
  161147. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161148. png_ptr, png_infop info_ptr));
  161149. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161150. png_ptr, png_infop info_ptr));
  161151. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161152. png_ptr, png_infop info_ptr));
  161153. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161154. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161155. png_infop info_ptr));
  161156. #if defined(PNG_bKGD_SUPPORTED)
  161157. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161158. png_infop info_ptr, png_color_16p *background));
  161159. #endif
  161160. #if defined(PNG_bKGD_SUPPORTED)
  161161. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161162. png_infop info_ptr, png_color_16p background));
  161163. #endif
  161164. #if defined(PNG_cHRM_SUPPORTED)
  161165. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161166. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161167. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161168. double *red_y, double *green_x, double *green_y, double *blue_x,
  161169. double *blue_y));
  161170. #endif
  161171. #ifdef PNG_FIXED_POINT_SUPPORTED
  161172. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161173. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161174. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161175. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161176. *int_blue_x, png_fixed_point *int_blue_y));
  161177. #endif
  161178. #endif
  161179. #if defined(PNG_cHRM_SUPPORTED)
  161180. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161181. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161182. png_infop info_ptr, double white_x, double white_y, double red_x,
  161183. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161184. #endif
  161185. #ifdef PNG_FIXED_POINT_SUPPORTED
  161186. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161187. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161188. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161189. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161190. png_fixed_point int_blue_y));
  161191. #endif
  161192. #endif
  161193. #if defined(PNG_gAMA_SUPPORTED)
  161194. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161195. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161196. png_infop info_ptr, double *file_gamma));
  161197. #endif
  161198. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161199. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161200. #endif
  161201. #if defined(PNG_gAMA_SUPPORTED)
  161202. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161203. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161204. png_infop info_ptr, double file_gamma));
  161205. #endif
  161206. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161207. png_infop info_ptr, png_fixed_point int_file_gamma));
  161208. #endif
  161209. #if defined(PNG_hIST_SUPPORTED)
  161210. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161211. png_infop info_ptr, png_uint_16p *hist));
  161212. #endif
  161213. #if defined(PNG_hIST_SUPPORTED)
  161214. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161215. png_infop info_ptr, png_uint_16p hist));
  161216. #endif
  161217. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161218. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161219. int *bit_depth, int *color_type, int *interlace_method,
  161220. int *compression_method, int *filter_method));
  161221. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161222. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161223. int color_type, int interlace_method, int compression_method,
  161224. int filter_method));
  161225. #if defined(PNG_oFFs_SUPPORTED)
  161226. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161227. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161228. int *unit_type));
  161229. #endif
  161230. #if defined(PNG_oFFs_SUPPORTED)
  161231. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161232. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161233. int unit_type));
  161234. #endif
  161235. #if defined(PNG_pCAL_SUPPORTED)
  161236. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161237. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161238. int *type, int *nparams, png_charp *units, png_charpp *params));
  161239. #endif
  161240. #if defined(PNG_pCAL_SUPPORTED)
  161241. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161242. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161243. int type, int nparams, png_charp units, png_charpp params));
  161244. #endif
  161245. #if defined(PNG_pHYs_SUPPORTED)
  161246. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161247. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161248. #endif
  161249. #if defined(PNG_pHYs_SUPPORTED)
  161250. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161251. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161252. #endif
  161253. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161254. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161255. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161256. png_infop info_ptr, png_colorp palette, int num_palette));
  161257. #if defined(PNG_sBIT_SUPPORTED)
  161258. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161259. png_infop info_ptr, png_color_8p *sig_bit));
  161260. #endif
  161261. #if defined(PNG_sBIT_SUPPORTED)
  161262. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161263. png_infop info_ptr, png_color_8p sig_bit));
  161264. #endif
  161265. #if defined(PNG_sRGB_SUPPORTED)
  161266. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161267. png_infop info_ptr, int *intent));
  161268. #endif
  161269. #if defined(PNG_sRGB_SUPPORTED)
  161270. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161271. png_infop info_ptr, int intent));
  161272. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161273. png_infop info_ptr, int intent));
  161274. #endif
  161275. #if defined(PNG_iCCP_SUPPORTED)
  161276. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161277. png_infop info_ptr, png_charpp name, int *compression_type,
  161278. png_charpp profile, png_uint_32 *proflen));
  161279. #endif
  161280. #if defined(PNG_iCCP_SUPPORTED)
  161281. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161282. png_infop info_ptr, png_charp name, int compression_type,
  161283. png_charp profile, png_uint_32 proflen));
  161284. #endif
  161285. #if defined(PNG_sPLT_SUPPORTED)
  161286. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161287. png_infop info_ptr, png_sPLT_tpp entries));
  161288. #endif
  161289. #if defined(PNG_sPLT_SUPPORTED)
  161290. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161291. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161292. #endif
  161293. #if defined(PNG_TEXT_SUPPORTED)
  161294. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161295. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161296. #endif
  161297. #if defined(PNG_TEXT_SUPPORTED)
  161298. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161299. png_infop info_ptr, png_textp text_ptr, int num_text));
  161300. #endif
  161301. #if defined(PNG_tIME_SUPPORTED)
  161302. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161303. png_infop info_ptr, png_timep *mod_time));
  161304. #endif
  161305. #if defined(PNG_tIME_SUPPORTED)
  161306. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161307. png_infop info_ptr, png_timep mod_time));
  161308. #endif
  161309. #if defined(PNG_tRNS_SUPPORTED)
  161310. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161311. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161312. png_color_16p *trans_values));
  161313. #endif
  161314. #if defined(PNG_tRNS_SUPPORTED)
  161315. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161316. png_infop info_ptr, png_bytep trans, int num_trans,
  161317. png_color_16p trans_values));
  161318. #endif
  161319. #if defined(PNG_tRNS_SUPPORTED)
  161320. #endif
  161321. #if defined(PNG_sCAL_SUPPORTED)
  161322. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161323. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161324. png_infop info_ptr, int *unit, double *width, double *height));
  161325. #else
  161326. #ifdef PNG_FIXED_POINT_SUPPORTED
  161327. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161328. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161329. #endif
  161330. #endif
  161331. #endif /* PNG_sCAL_SUPPORTED */
  161332. #if defined(PNG_sCAL_SUPPORTED)
  161333. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161334. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161335. png_infop info_ptr, int unit, double width, double height));
  161336. #else
  161337. #ifdef PNG_FIXED_POINT_SUPPORTED
  161338. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161339. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161340. #endif
  161341. #endif
  161342. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161343. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161344. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161345. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161346. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161347. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161348. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161349. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161350. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161351. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161352. #endif
  161353. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161354. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161355. chunk_name));
  161356. #endif
  161357. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161358. png_infop info_ptr, int mask));
  161359. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161360. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161361. png_infop info_ptr,
  161362. int transforms,
  161363. png_voidp params));
  161364. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161365. png_infop info_ptr,
  161366. int transforms,
  161367. png_voidp params));
  161368. #endif
  161369. #ifdef PNG_DEBUG
  161370. #if (PNG_DEBUG > 0)
  161371. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161372. #include <crtdbg.h>
  161373. #if (PNG_DEBUG > 1)
  161374. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161375. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161376. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161377. #endif
  161378. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161379. #ifndef PNG_DEBUG_FILE
  161380. #define PNG_DEBUG_FILE stderr
  161381. #endif /* PNG_DEBUG_FILE */
  161382. #if (PNG_DEBUG > 1)
  161383. #define png_debug(l,m) \
  161384. { \
  161385. int num_tabs=l; \
  161386. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161387. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161388. }
  161389. #define png_debug1(l,m,p1) \
  161390. { \
  161391. int num_tabs=l; \
  161392. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161393. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161394. }
  161395. #define png_debug2(l,m,p1,p2) \
  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":""))),p1,p2); \
  161400. }
  161401. #endif /* (PNG_DEBUG > 1) */
  161402. #endif /* _MSC_VER */
  161403. #endif /* (PNG_DEBUG > 0) */
  161404. #endif /* PNG_DEBUG */
  161405. #ifndef png_debug
  161406. #define png_debug(l, m)
  161407. #endif
  161408. #ifndef png_debug1
  161409. #define png_debug1(l, m, p1)
  161410. #endif
  161411. #ifndef png_debug2
  161412. #define png_debug2(l, m, p1, p2)
  161413. #endif
  161414. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161415. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161416. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161417. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161418. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161419. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161420. png_ptr, png_uint_32 mng_features_permitted));
  161421. #endif
  161422. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161423. #define PNG_HANDLE_CHUNK_NEVER 1
  161424. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161425. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161426. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161427. #if defined(PNG_MMX_CODE_SUPPORTED)
  161428. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161429. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161430. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161431. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161432. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161433. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161434. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161435. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161436. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161437. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161438. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161439. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161440. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161441. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161442. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161443. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161444. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161445. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161446. | PNG_MMX_READ_FLAGS \
  161447. | PNG_MMX_WRITE_FLAGS )
  161448. #define PNG_SELECT_READ 1
  161449. #define PNG_SELECT_WRITE 2
  161450. #endif /* PNG_MMX_CODE_SUPPORTED */
  161451. #if !defined(PNG_1_0_X)
  161452. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161453. PNGARG((int flag_select, int *compilerID));
  161454. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161455. PNGARG((int flag_select));
  161456. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161457. PNGARG((png_structp png_ptr));
  161458. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161459. PNGARG((png_structp png_ptr));
  161460. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161461. PNGARG((png_structp png_ptr));
  161462. extern PNG_EXPORT(void,png_set_asm_flags)
  161463. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161464. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161465. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161466. png_uint_32 mmx_rowbytes_threshold));
  161467. #endif /* PNG_1_0_X */
  161468. #if !defined(PNG_1_0_X)
  161469. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161470. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161471. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161472. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161473. png_ptr, png_uint_32 strip_mode));
  161474. #endif
  161475. #endif /* PNG_1_0_X */
  161476. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161477. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161478. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161479. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161480. png_ptr));
  161481. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161482. png_ptr));
  161483. #endif
  161484. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161485. # define png_composite(composite, fg, alpha, bg) \
  161486. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161487. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161488. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161489. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161490. # define png_composite_16(composite, fg, alpha, bg) \
  161491. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161492. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161493. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161494. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161495. #else /* standard method using integer division */
  161496. # define png_composite(composite, fg, alpha, bg) \
  161497. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161498. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161499. (png_uint_16)127) / 255)
  161500. # define png_composite_16(composite, fg, alpha, bg) \
  161501. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161502. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161503. (png_uint_32)32767) / (png_uint_32)65535L)
  161504. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161505. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161506. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161507. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161508. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161509. #else
  161510. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161511. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161512. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161513. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161514. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161515. PNGARG((png_structp png_ptr, png_bytep buf));
  161516. extern PNG_EXPORT(void,png_save_uint_32)
  161517. PNGARG((png_bytep buf, png_uint_32 i));
  161518. extern PNG_EXPORT(void,png_save_int_32)
  161519. PNGARG((png_bytep buf, png_int_32 i));
  161520. extern PNG_EXPORT(void,png_save_uint_16)
  161521. PNGARG((png_bytep buf, unsigned int i));
  161522. #define PNG_HAVE_IHDR 0x01
  161523. #define PNG_HAVE_PLTE 0x02
  161524. #define PNG_HAVE_IDAT 0x04
  161525. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161526. #define PNG_HAVE_IEND 0x10
  161527. #if defined(PNG_INTERNAL)
  161528. #define PNG_HAVE_gAMA 0x20
  161529. #define PNG_HAVE_cHRM 0x40
  161530. #define PNG_HAVE_sRGB 0x80
  161531. #define PNG_HAVE_CHUNK_HEADER 0x100
  161532. #define PNG_WROTE_tIME 0x200
  161533. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161534. #define PNG_BACKGROUND_IS_GRAY 0x800
  161535. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161536. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161537. #define PNG_BGR 0x0001
  161538. #define PNG_INTERLACE 0x0002
  161539. #define PNG_PACK 0x0004
  161540. #define PNG_SHIFT 0x0008
  161541. #define PNG_SWAP_BYTES 0x0010
  161542. #define PNG_INVERT_MONO 0x0020
  161543. #define PNG_DITHER 0x0040
  161544. #define PNG_BACKGROUND 0x0080
  161545. #define PNG_BACKGROUND_EXPAND 0x0100
  161546. #define PNG_16_TO_8 0x0400
  161547. #define PNG_RGBA 0x0800
  161548. #define PNG_EXPAND 0x1000
  161549. #define PNG_GAMMA 0x2000
  161550. #define PNG_GRAY_TO_RGB 0x4000
  161551. #define PNG_FILLER 0x8000L
  161552. #define PNG_PACKSWAP 0x10000L
  161553. #define PNG_SWAP_ALPHA 0x20000L
  161554. #define PNG_STRIP_ALPHA 0x40000L
  161555. #define PNG_INVERT_ALPHA 0x80000L
  161556. #define PNG_USER_TRANSFORM 0x100000L
  161557. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161558. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161559. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161560. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161561. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161562. #define PNG_STRUCT_PNG 0x0001
  161563. #define PNG_STRUCT_INFO 0x0002
  161564. #define PNG_WEIGHT_SHIFT 8
  161565. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161566. #define PNG_COST_SHIFT 3
  161567. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161568. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161569. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161570. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161571. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161572. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161573. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161574. #define PNG_FLAG_ROW_INIT 0x0040
  161575. #define PNG_FLAG_FILLER_AFTER 0x0080
  161576. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161577. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161578. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161579. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161580. #define PNG_FLAG_FREE_PLTE 0x1000
  161581. #define PNG_FLAG_FREE_TRNS 0x2000
  161582. #define PNG_FLAG_FREE_HIST 0x4000
  161583. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161584. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161585. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161586. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161587. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161588. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161589. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161590. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161591. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161592. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161593. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161594. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161595. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161596. PNG_FLAG_CRC_CRITICAL_MASK)
  161597. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161598. abs((int)((c1).green) - (int)((c2).green)) + \
  161599. abs((int)((c1).blue) - (int)((c2).blue)))
  161600. #define PNG_ROWBYTES(pixel_bits, width) \
  161601. ((pixel_bits) >= 8 ? \
  161602. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161603. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161604. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161605. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161606. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161607. #ifdef PNG_USE_GLOBAL_ARRAYS
  161608. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161609. #else
  161610. #endif
  161611. #endif /* PNG_NO_EXTERN */
  161612. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161613. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161614. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161615. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161616. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161617. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161618. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161619. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161620. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161621. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161622. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161623. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161624. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161625. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161626. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161627. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161628. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161629. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161630. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161631. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161632. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161633. #ifdef PNG_USE_GLOBAL_ARRAYS
  161634. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161635. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161636. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161637. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161638. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161639. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161640. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161641. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161642. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161643. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161644. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161645. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161646. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161647. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161648. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161649. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161650. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161651. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161652. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161653. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161654. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161655. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161656. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161657. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161658. #undef png_read_init
  161659. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161660. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161661. #endif
  161662. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161663. png_const_charp user_png_ver, png_size_t png_struct_size));
  161664. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161665. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161666. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161667. png_info_size));
  161668. #endif
  161669. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161670. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161671. #undef png_write_init
  161672. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161673. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161674. #endif
  161675. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161676. png_const_charp user_png_ver, png_size_t png_struct_size));
  161677. extern PNG_EXPORT(void,png_write_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. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161681. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161682. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161683. malloc_fn, png_voidp mem_ptr));
  161684. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161685. png_free_ptr free_fn, png_voidp mem_ptr));
  161686. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161687. png_infop info_ptr));
  161688. #ifndef PNG_1_0_X
  161689. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161690. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161691. #ifdef PNG_SIZE_T
  161692. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161693. #endif
  161694. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161695. png_bytep data, png_size_t length));
  161696. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161697. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161698. png_bytep buffer, png_size_t length));
  161699. #endif
  161700. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161701. png_bytep data, png_size_t length));
  161702. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161703. #if !defined(PNG_NO_STDIO)
  161704. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161705. #endif
  161706. #endif
  161707. #else /* PNG_1_0_X */
  161708. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161709. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161710. png_bytep buffer, png_size_t length));
  161711. #endif
  161712. #endif /* PNG_1_0_X */
  161713. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161714. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161715. png_size_t length));
  161716. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161717. png_size_t length));
  161718. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161719. png_size_t length));
  161720. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161721. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161722. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161723. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161724. png_size_t prefix_length, png_size_t *data_length));
  161725. #endif
  161726. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161727. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161728. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161729. png_size_t length));
  161730. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161731. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161732. #endif
  161733. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161734. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161735. png_uint_32 height,
  161736. int bit_depth, int color_type, int compression_method, int filter_method,
  161737. int interlace_method));
  161738. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161739. png_uint_32 num_pal));
  161740. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161741. png_size_t length));
  161742. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161743. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161744. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161745. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161746. #endif
  161747. #ifdef PNG_FIXED_POINT_SUPPORTED
  161748. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161749. file_gamma));
  161750. #endif
  161751. #endif
  161752. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161753. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161754. int color_type));
  161755. #endif
  161756. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161757. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161758. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161759. double white_x, double white_y,
  161760. double red_x, double red_y, double green_x, double green_y,
  161761. double blue_x, double blue_y));
  161762. #endif
  161763. #ifdef PNG_FIXED_POINT_SUPPORTED
  161764. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161765. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161766. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161767. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161768. png_fixed_point int_blue_y));
  161769. #endif
  161770. #endif
  161771. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161772. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161773. int intent));
  161774. #endif
  161775. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161776. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161777. png_charp name, int compression_type,
  161778. png_charp profile, int proflen));
  161779. #endif
  161780. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161781. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161782. png_sPLT_tp palette));
  161783. #endif
  161784. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161785. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161786. png_color_16p values, int number, int color_type));
  161787. #endif
  161788. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161789. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161790. png_color_16p values, int color_type));
  161791. #endif
  161792. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161793. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161794. int num_hist));
  161795. #endif
  161796. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161797. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161798. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161799. png_charp key, png_charpp new_key));
  161800. #endif
  161801. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161802. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161803. png_charp text, png_size_t text_len));
  161804. #endif
  161805. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161806. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161807. png_charp text, png_size_t text_len, int compression));
  161808. #endif
  161809. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161810. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161811. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161812. png_charp text));
  161813. #endif
  161814. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161815. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161816. png_infop info_ptr, png_textp text_ptr, int num_text));
  161817. #endif
  161818. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161819. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161820. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161821. #endif
  161822. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161823. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161824. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161825. png_charp units, png_charpp params));
  161826. #endif
  161827. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161828. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161829. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161830. int unit_type));
  161831. #endif
  161832. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161833. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161834. png_timep mod_time));
  161835. #endif
  161836. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161837. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161838. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161839. int unit, double width, double height));
  161840. #else
  161841. #ifdef PNG_FIXED_POINT_SUPPORTED
  161842. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161843. int unit, png_charp width, png_charp height));
  161844. #endif
  161845. #endif
  161846. #endif
  161847. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161848. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161849. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161850. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161851. #endif
  161852. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161853. int mask));
  161854. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161855. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161856. #endif
  161857. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161858. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161859. png_bytep row, int pass));
  161860. #endif
  161861. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161862. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161863. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161864. png_row_infop row_info));
  161865. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161866. png_bytep filtered_row));
  161867. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161868. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161869. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161870. png_infop info_ptr));
  161871. #if defined(PNG_READ_FILLER_SUPPORTED)
  161872. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161873. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161874. #endif
  161875. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161876. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161877. png_bytep row));
  161878. #endif
  161879. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161880. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161881. png_bytep row));
  161882. #endif
  161883. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161884. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161885. png_bytep row));
  161886. #endif
  161887. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161888. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161889. png_bytep row));
  161890. #endif
  161891. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161892. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161893. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161894. png_bytep row, png_uint_32 flags));
  161895. #endif
  161896. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161897. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161898. #endif
  161899. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161900. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161901. #endif
  161902. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161903. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161904. row_info, png_bytep row));
  161905. #endif
  161906. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161907. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161908. png_bytep row));
  161909. #endif
  161910. #if defined(PNG_READ_PACK_SUPPORTED)
  161911. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161912. #endif
  161913. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161914. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161915. png_color_8p sig_bits));
  161916. #endif
  161917. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161918. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  161919. #endif
  161920. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161921. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  161922. #endif
  161923. #if defined(PNG_READ_DITHER_SUPPORTED)
  161924. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  161925. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  161926. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  161927. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  161928. png_colorp palette, int num_palette));
  161929. # endif
  161930. #endif
  161931. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161932. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  161933. #endif
  161934. #if defined(PNG_WRITE_PACK_SUPPORTED)
  161935. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  161936. png_bytep row, png_uint_32 bit_depth));
  161937. #endif
  161938. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  161939. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  161940. png_color_8p bit_depth));
  161941. #endif
  161942. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161943. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161944. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161945. png_color_16p trans_values, png_color_16p background,
  161946. png_color_16p background_1,
  161947. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  161948. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  161949. png_uint_16pp gamma_16_to_1, int gamma_shift));
  161950. #else
  161951. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161952. png_color_16p trans_values, png_color_16p background));
  161953. #endif
  161954. #endif
  161955. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161956. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  161957. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  161958. int gamma_shift));
  161959. #endif
  161960. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161961. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  161962. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  161963. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  161964. png_bytep row, png_color_16p trans_value));
  161965. #endif
  161966. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  161967. png_uint_32 length));
  161968. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  161969. png_uint_32 length));
  161970. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  161971. png_uint_32 length));
  161972. #if defined(PNG_READ_bKGD_SUPPORTED)
  161973. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  161974. png_uint_32 length));
  161975. #endif
  161976. #if defined(PNG_READ_cHRM_SUPPORTED)
  161977. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  161978. png_uint_32 length));
  161979. #endif
  161980. #if defined(PNG_READ_gAMA_SUPPORTED)
  161981. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  161982. png_uint_32 length));
  161983. #endif
  161984. #if defined(PNG_READ_hIST_SUPPORTED)
  161985. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  161986. png_uint_32 length));
  161987. #endif
  161988. #if defined(PNG_READ_iCCP_SUPPORTED)
  161989. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  161990. png_uint_32 length));
  161991. #endif /* PNG_READ_iCCP_SUPPORTED */
  161992. #if defined(PNG_READ_iTXt_SUPPORTED)
  161993. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161994. png_uint_32 length));
  161995. #endif
  161996. #if defined(PNG_READ_oFFs_SUPPORTED)
  161997. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161998. png_uint_32 length));
  161999. #endif
  162000. #if defined(PNG_READ_pCAL_SUPPORTED)
  162001. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162002. png_uint_32 length));
  162003. #endif
  162004. #if defined(PNG_READ_pHYs_SUPPORTED)
  162005. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162006. png_uint_32 length));
  162007. #endif
  162008. #if defined(PNG_READ_sBIT_SUPPORTED)
  162009. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162010. png_uint_32 length));
  162011. #endif
  162012. #if defined(PNG_READ_sCAL_SUPPORTED)
  162013. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162014. png_uint_32 length));
  162015. #endif
  162016. #if defined(PNG_READ_sPLT_SUPPORTED)
  162017. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162018. png_uint_32 length));
  162019. #endif /* PNG_READ_sPLT_SUPPORTED */
  162020. #if defined(PNG_READ_sRGB_SUPPORTED)
  162021. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162022. png_uint_32 length));
  162023. #endif
  162024. #if defined(PNG_READ_tEXt_SUPPORTED)
  162025. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162026. png_uint_32 length));
  162027. #endif
  162028. #if defined(PNG_READ_tIME_SUPPORTED)
  162029. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162030. png_uint_32 length));
  162031. #endif
  162032. #if defined(PNG_READ_tRNS_SUPPORTED)
  162033. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162034. png_uint_32 length));
  162035. #endif
  162036. #if defined(PNG_READ_zTXt_SUPPORTED)
  162037. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162038. png_uint_32 length));
  162039. #endif
  162040. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162041. png_infop info_ptr, png_uint_32 length));
  162042. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162043. png_bytep chunk_name));
  162044. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162045. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162046. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162047. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162048. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162049. png_infop info_ptr));
  162050. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162051. png_infop info_ptr));
  162052. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162053. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162054. png_uint_32 length));
  162055. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162056. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162057. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162058. png_bytep buffer, png_size_t buffer_length));
  162059. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162060. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162061. png_bytep buffer, png_size_t buffer_length));
  162062. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162063. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162064. png_infop info_ptr, png_uint_32 length));
  162065. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162066. png_infop info_ptr));
  162067. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162068. png_infop info_ptr));
  162069. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162070. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162071. png_infop info_ptr));
  162072. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162073. png_infop info_ptr));
  162074. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162075. #if defined(PNG_READ_tEXt_SUPPORTED)
  162076. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162077. png_infop info_ptr, png_uint_32 length));
  162078. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162079. png_infop info_ptr));
  162080. #endif
  162081. #if defined(PNG_READ_zTXt_SUPPORTED)
  162082. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162083. png_infop info_ptr, png_uint_32 length));
  162084. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162085. png_infop info_ptr));
  162086. #endif
  162087. #if defined(PNG_READ_iTXt_SUPPORTED)
  162088. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162089. png_infop info_ptr, png_uint_32 length));
  162090. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162091. png_infop info_ptr));
  162092. #endif
  162093. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162094. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162095. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162096. png_bytep row));
  162097. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162098. png_bytep row));
  162099. #endif
  162100. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162101. #if defined(PNG_MMX_CODE_SUPPORTED)
  162102. /* PRIVATE */
  162103. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162104. #endif
  162105. #endif
  162106. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162107. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162108. png_infop info_ptr));
  162109. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162110. png_infop info_ptr));
  162111. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162112. png_infop info_ptr));
  162113. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162114. png_infop info_ptr));
  162115. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162116. png_infop info_ptr));
  162117. #if defined(PNG_pHYs_SUPPORTED)
  162118. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162119. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162120. #endif /* PNG_pHYs_SUPPORTED */
  162121. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162122. #endif /* PNG_INTERNAL */
  162123. #ifdef __cplusplus
  162124. }
  162125. #endif
  162126. #endif /* PNG_VERSION_INFO_ONLY */
  162127. #endif /* PNG_H */
  162128. /*** End of inlined file: png.h ***/
  162129. #define PNG_NO_EXTERN
  162130. /*** Start of inlined file: png.c ***/
  162131. #define PNG_INTERNAL
  162132. #define PNG_NO_EXTERN
  162133. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162134. #ifdef PNG_USE_GLOBAL_ARRAYS
  162135. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162136. #ifdef PNG_READ_SUPPORTED
  162137. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162138. #endif /* PNG_READ_SUPPORTED */
  162139. PNG_IHDR;
  162140. PNG_IDAT;
  162141. PNG_IEND;
  162142. PNG_PLTE;
  162143. PNG_bKGD;
  162144. PNG_cHRM;
  162145. PNG_gAMA;
  162146. PNG_hIST;
  162147. PNG_iCCP;
  162148. PNG_iTXt;
  162149. PNG_oFFs;
  162150. PNG_pCAL;
  162151. PNG_sCAL;
  162152. PNG_pHYs;
  162153. PNG_sBIT;
  162154. PNG_sPLT;
  162155. PNG_sRGB;
  162156. PNG_tEXt;
  162157. PNG_tIME;
  162158. PNG_tRNS;
  162159. PNG_zTXt;
  162160. #ifdef PNG_READ_SUPPORTED
  162161. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162162. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162163. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162164. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162165. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162166. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162167. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162168. #endif /* PNG_READ_SUPPORTED */
  162169. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162170. #ifdef PNG_READ_SUPPORTED
  162171. void PNGAPI
  162172. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162173. {
  162174. if(png_ptr == NULL) return;
  162175. png_debug(1, "in png_set_sig_bytes\n");
  162176. if (num_bytes > 8)
  162177. png_error(png_ptr, "Too many bytes for PNG signature.");
  162178. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162179. }
  162180. int PNGAPI
  162181. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162182. {
  162183. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162184. if (num_to_check > 8)
  162185. num_to_check = 8;
  162186. else if (num_to_check < 1)
  162187. return (-1);
  162188. if (start > 7)
  162189. return (-1);
  162190. if (start + num_to_check > 8)
  162191. num_to_check = 8 - start;
  162192. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162193. }
  162194. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162195. int PNGAPI
  162196. png_check_sig(png_bytep sig, int num)
  162197. {
  162198. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162199. }
  162200. #endif
  162201. #endif /* PNG_READ_SUPPORTED */
  162202. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162203. #ifdef PNG_1_0_X
  162204. voidpf PNGAPI
  162205. #else
  162206. voidpf /* private */
  162207. #endif
  162208. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162209. {
  162210. png_voidp ptr;
  162211. png_structp p=(png_structp)png_ptr;
  162212. png_uint_32 save_flags=p->flags;
  162213. png_uint_32 num_bytes;
  162214. if(png_ptr == NULL) return (NULL);
  162215. if (items > PNG_UINT_32_MAX/size)
  162216. {
  162217. png_warning (p, "Potential overflow in png_zalloc()");
  162218. return (NULL);
  162219. }
  162220. num_bytes = (png_uint_32)items * size;
  162221. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162222. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162223. p->flags=save_flags;
  162224. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162225. if (ptr == NULL)
  162226. return ((voidpf)ptr);
  162227. if (num_bytes > (png_uint_32)0x8000L)
  162228. {
  162229. png_memset(ptr, 0, (png_size_t)0x8000L);
  162230. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162231. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162232. }
  162233. else
  162234. {
  162235. png_memset(ptr, 0, (png_size_t)num_bytes);
  162236. }
  162237. #endif
  162238. return ((voidpf)ptr);
  162239. }
  162240. #ifdef PNG_1_0_X
  162241. void PNGAPI
  162242. #else
  162243. void /* private */
  162244. #endif
  162245. png_zfree(voidpf png_ptr, voidpf ptr)
  162246. {
  162247. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162248. }
  162249. void /* PRIVATE */
  162250. png_reset_crc(png_structp png_ptr)
  162251. {
  162252. png_ptr->crc = crc32(0, Z_NULL, 0);
  162253. }
  162254. void /* PRIVATE */
  162255. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162256. {
  162257. int need_crc = 1;
  162258. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162259. {
  162260. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162261. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162262. need_crc = 0;
  162263. }
  162264. else /* critical */
  162265. {
  162266. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162267. need_crc = 0;
  162268. }
  162269. if (need_crc)
  162270. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162271. }
  162272. png_infop PNGAPI
  162273. png_create_info_struct(png_structp png_ptr)
  162274. {
  162275. png_infop info_ptr;
  162276. png_debug(1, "in png_create_info_struct\n");
  162277. if(png_ptr == NULL) return (NULL);
  162278. #ifdef PNG_USER_MEM_SUPPORTED
  162279. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162280. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162281. #else
  162282. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162283. #endif
  162284. if (info_ptr != NULL)
  162285. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162286. return (info_ptr);
  162287. }
  162288. void PNGAPI
  162289. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162290. {
  162291. png_infop info_ptr = NULL;
  162292. if(png_ptr == NULL) return;
  162293. png_debug(1, "in png_destroy_info_struct\n");
  162294. if (info_ptr_ptr != NULL)
  162295. info_ptr = *info_ptr_ptr;
  162296. if (info_ptr != NULL)
  162297. {
  162298. png_info_destroy(png_ptr, info_ptr);
  162299. #ifdef PNG_USER_MEM_SUPPORTED
  162300. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162301. png_ptr->mem_ptr);
  162302. #else
  162303. png_destroy_struct((png_voidp)info_ptr);
  162304. #endif
  162305. *info_ptr_ptr = NULL;
  162306. }
  162307. }
  162308. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162309. #undef png_info_init
  162310. void PNGAPI
  162311. png_info_init(png_infop info_ptr)
  162312. {
  162313. png_info_init_3(&info_ptr, 0);
  162314. }
  162315. #endif
  162316. void PNGAPI
  162317. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162318. {
  162319. png_infop info_ptr = *ptr_ptr;
  162320. if(info_ptr == NULL) return;
  162321. png_debug(1, "in png_info_init_3\n");
  162322. if(png_sizeof(png_info) > png_info_struct_size)
  162323. {
  162324. png_destroy_struct(info_ptr);
  162325. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162326. *ptr_ptr = info_ptr;
  162327. }
  162328. png_memset(info_ptr, 0, png_sizeof (png_info));
  162329. }
  162330. #ifdef PNG_FREE_ME_SUPPORTED
  162331. void PNGAPI
  162332. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162333. int freer, png_uint_32 mask)
  162334. {
  162335. png_debug(1, "in png_data_freer\n");
  162336. if (png_ptr == NULL || info_ptr == NULL)
  162337. return;
  162338. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162339. info_ptr->free_me |= mask;
  162340. else if(freer == PNG_USER_WILL_FREE_DATA)
  162341. info_ptr->free_me &= ~mask;
  162342. else
  162343. png_warning(png_ptr,
  162344. "Unknown freer parameter in png_data_freer.");
  162345. }
  162346. #endif
  162347. void PNGAPI
  162348. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162349. int num)
  162350. {
  162351. png_debug(1, "in png_free_data\n");
  162352. if (png_ptr == NULL || info_ptr == NULL)
  162353. return;
  162354. #if defined(PNG_TEXT_SUPPORTED)
  162355. #ifdef PNG_FREE_ME_SUPPORTED
  162356. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162357. #else
  162358. if (mask & PNG_FREE_TEXT)
  162359. #endif
  162360. {
  162361. if (num != -1)
  162362. {
  162363. if (info_ptr->text && info_ptr->text[num].key)
  162364. {
  162365. png_free(png_ptr, info_ptr->text[num].key);
  162366. info_ptr->text[num].key = NULL;
  162367. }
  162368. }
  162369. else
  162370. {
  162371. int i;
  162372. for (i = 0; i < info_ptr->num_text; i++)
  162373. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162374. png_free(png_ptr, info_ptr->text);
  162375. info_ptr->text = NULL;
  162376. info_ptr->num_text=0;
  162377. }
  162378. }
  162379. #endif
  162380. #if defined(PNG_tRNS_SUPPORTED)
  162381. #ifdef PNG_FREE_ME_SUPPORTED
  162382. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162383. #else
  162384. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162385. #endif
  162386. {
  162387. png_free(png_ptr, info_ptr->trans);
  162388. info_ptr->valid &= ~PNG_INFO_tRNS;
  162389. #ifndef PNG_FREE_ME_SUPPORTED
  162390. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162391. #endif
  162392. info_ptr->trans = NULL;
  162393. }
  162394. #endif
  162395. #if defined(PNG_sCAL_SUPPORTED)
  162396. #ifdef PNG_FREE_ME_SUPPORTED
  162397. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162398. #else
  162399. if (mask & PNG_FREE_SCAL)
  162400. #endif
  162401. {
  162402. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162403. png_free(png_ptr, info_ptr->scal_s_width);
  162404. png_free(png_ptr, info_ptr->scal_s_height);
  162405. info_ptr->scal_s_width = NULL;
  162406. info_ptr->scal_s_height = NULL;
  162407. #endif
  162408. info_ptr->valid &= ~PNG_INFO_sCAL;
  162409. }
  162410. #endif
  162411. #if defined(PNG_pCAL_SUPPORTED)
  162412. #ifdef PNG_FREE_ME_SUPPORTED
  162413. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162414. #else
  162415. if (mask & PNG_FREE_PCAL)
  162416. #endif
  162417. {
  162418. png_free(png_ptr, info_ptr->pcal_purpose);
  162419. png_free(png_ptr, info_ptr->pcal_units);
  162420. info_ptr->pcal_purpose = NULL;
  162421. info_ptr->pcal_units = NULL;
  162422. if (info_ptr->pcal_params != NULL)
  162423. {
  162424. int i;
  162425. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162426. {
  162427. png_free(png_ptr, info_ptr->pcal_params[i]);
  162428. info_ptr->pcal_params[i]=NULL;
  162429. }
  162430. png_free(png_ptr, info_ptr->pcal_params);
  162431. info_ptr->pcal_params = NULL;
  162432. }
  162433. info_ptr->valid &= ~PNG_INFO_pCAL;
  162434. }
  162435. #endif
  162436. #if defined(PNG_iCCP_SUPPORTED)
  162437. #ifdef PNG_FREE_ME_SUPPORTED
  162438. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162439. #else
  162440. if (mask & PNG_FREE_ICCP)
  162441. #endif
  162442. {
  162443. png_free(png_ptr, info_ptr->iccp_name);
  162444. png_free(png_ptr, info_ptr->iccp_profile);
  162445. info_ptr->iccp_name = NULL;
  162446. info_ptr->iccp_profile = NULL;
  162447. info_ptr->valid &= ~PNG_INFO_iCCP;
  162448. }
  162449. #endif
  162450. #if defined(PNG_sPLT_SUPPORTED)
  162451. #ifdef PNG_FREE_ME_SUPPORTED
  162452. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162453. #else
  162454. if (mask & PNG_FREE_SPLT)
  162455. #endif
  162456. {
  162457. if (num != -1)
  162458. {
  162459. if(info_ptr->splt_palettes)
  162460. {
  162461. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162462. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162463. info_ptr->splt_palettes[num].name = NULL;
  162464. info_ptr->splt_palettes[num].entries = NULL;
  162465. }
  162466. }
  162467. else
  162468. {
  162469. if(info_ptr->splt_palettes_num)
  162470. {
  162471. int i;
  162472. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162473. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162474. png_free(png_ptr, info_ptr->splt_palettes);
  162475. info_ptr->splt_palettes = NULL;
  162476. info_ptr->splt_palettes_num = 0;
  162477. }
  162478. info_ptr->valid &= ~PNG_INFO_sPLT;
  162479. }
  162480. }
  162481. #endif
  162482. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162483. if(png_ptr->unknown_chunk.data)
  162484. {
  162485. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162486. png_ptr->unknown_chunk.data = NULL;
  162487. }
  162488. #ifdef PNG_FREE_ME_SUPPORTED
  162489. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162490. #else
  162491. if (mask & PNG_FREE_UNKN)
  162492. #endif
  162493. {
  162494. if (num != -1)
  162495. {
  162496. if(info_ptr->unknown_chunks)
  162497. {
  162498. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162499. info_ptr->unknown_chunks[num].data = NULL;
  162500. }
  162501. }
  162502. else
  162503. {
  162504. int i;
  162505. if(info_ptr->unknown_chunks_num)
  162506. {
  162507. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162508. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162509. png_free(png_ptr, info_ptr->unknown_chunks);
  162510. info_ptr->unknown_chunks = NULL;
  162511. info_ptr->unknown_chunks_num = 0;
  162512. }
  162513. }
  162514. }
  162515. #endif
  162516. #if defined(PNG_hIST_SUPPORTED)
  162517. #ifdef PNG_FREE_ME_SUPPORTED
  162518. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162519. #else
  162520. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162521. #endif
  162522. {
  162523. png_free(png_ptr, info_ptr->hist);
  162524. info_ptr->hist = NULL;
  162525. info_ptr->valid &= ~PNG_INFO_hIST;
  162526. #ifndef PNG_FREE_ME_SUPPORTED
  162527. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162528. #endif
  162529. }
  162530. #endif
  162531. #ifdef PNG_FREE_ME_SUPPORTED
  162532. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162533. #else
  162534. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162535. #endif
  162536. {
  162537. png_zfree(png_ptr, info_ptr->palette);
  162538. info_ptr->palette = NULL;
  162539. info_ptr->valid &= ~PNG_INFO_PLTE;
  162540. #ifndef PNG_FREE_ME_SUPPORTED
  162541. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162542. #endif
  162543. info_ptr->num_palette = 0;
  162544. }
  162545. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162546. #ifdef PNG_FREE_ME_SUPPORTED
  162547. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162548. #else
  162549. if (mask & PNG_FREE_ROWS)
  162550. #endif
  162551. {
  162552. if(info_ptr->row_pointers)
  162553. {
  162554. int row;
  162555. for (row = 0; row < (int)info_ptr->height; row++)
  162556. {
  162557. png_free(png_ptr, info_ptr->row_pointers[row]);
  162558. info_ptr->row_pointers[row]=NULL;
  162559. }
  162560. png_free(png_ptr, info_ptr->row_pointers);
  162561. info_ptr->row_pointers=NULL;
  162562. }
  162563. info_ptr->valid &= ~PNG_INFO_IDAT;
  162564. }
  162565. #endif
  162566. #ifdef PNG_FREE_ME_SUPPORTED
  162567. if(num == -1)
  162568. info_ptr->free_me &= ~mask;
  162569. else
  162570. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162571. #endif
  162572. }
  162573. void /* PRIVATE */
  162574. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162575. {
  162576. png_debug(1, "in png_info_destroy\n");
  162577. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162578. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162579. if (png_ptr->num_chunk_list)
  162580. {
  162581. png_free(png_ptr, png_ptr->chunk_list);
  162582. png_ptr->chunk_list=NULL;
  162583. png_ptr->num_chunk_list=0;
  162584. }
  162585. #endif
  162586. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162587. }
  162588. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162589. png_voidp PNGAPI
  162590. png_get_io_ptr(png_structp png_ptr)
  162591. {
  162592. if(png_ptr == NULL) return (NULL);
  162593. return (png_ptr->io_ptr);
  162594. }
  162595. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162596. #if !defined(PNG_NO_STDIO)
  162597. void PNGAPI
  162598. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162599. {
  162600. png_debug(1, "in png_init_io\n");
  162601. if(png_ptr == NULL) return;
  162602. png_ptr->io_ptr = (png_voidp)fp;
  162603. }
  162604. #endif
  162605. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162606. png_charp PNGAPI
  162607. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162608. {
  162609. static PNG_CONST char short_months[12][4] =
  162610. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162611. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162612. if(png_ptr == NULL) return (NULL);
  162613. if (png_ptr->time_buffer == NULL)
  162614. {
  162615. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162616. png_sizeof(char)));
  162617. }
  162618. #if defined(_WIN32_WCE)
  162619. {
  162620. wchar_t time_buf[29];
  162621. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162622. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162623. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162624. ptime->second % 61);
  162625. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162626. NULL, NULL);
  162627. }
  162628. #else
  162629. #ifdef USE_FAR_KEYWORD
  162630. {
  162631. char near_time_buf[29];
  162632. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162633. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162634. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162635. ptime->second % 61);
  162636. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162637. 29*png_sizeof(char));
  162638. }
  162639. #else
  162640. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162641. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162642. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162643. ptime->second % 61);
  162644. #endif
  162645. #endif /* _WIN32_WCE */
  162646. return ((png_charp)png_ptr->time_buffer);
  162647. }
  162648. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162649. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162650. png_charp PNGAPI
  162651. png_get_copyright(png_structp png_ptr)
  162652. {
  162653. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162654. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162655. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162656. Copyright (c) 1996-1997 Andreas Dilger\n\
  162657. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162658. }
  162659. png_charp PNGAPI
  162660. png_get_libpng_ver(png_structp png_ptr)
  162661. {
  162662. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162663. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162664. }
  162665. png_charp PNGAPI
  162666. png_get_header_ver(png_structp png_ptr)
  162667. {
  162668. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162669. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162670. }
  162671. png_charp PNGAPI
  162672. png_get_header_version(png_structp png_ptr)
  162673. {
  162674. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162675. return ((png_charp) PNG_HEADER_VERSION_STRING
  162676. #ifndef PNG_READ_SUPPORTED
  162677. " (NO READ SUPPORT)"
  162678. #endif
  162679. "\n");
  162680. }
  162681. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162682. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162683. int PNGAPI
  162684. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162685. {
  162686. int i;
  162687. png_bytep p;
  162688. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162689. return 0;
  162690. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162691. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162692. if (!png_memcmp(chunk_name, p, 4))
  162693. return ((int)*(p+4));
  162694. return 0;
  162695. }
  162696. #endif
  162697. int PNGAPI
  162698. png_reset_zstream(png_structp png_ptr)
  162699. {
  162700. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162701. return (inflateReset(&png_ptr->zstream));
  162702. }
  162703. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162704. png_uint_32 PNGAPI
  162705. png_access_version_number(void)
  162706. {
  162707. return((png_uint_32) PNG_LIBPNG_VER);
  162708. }
  162709. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162710. #if !defined(PNG_1_0_X)
  162711. int PNGAPI
  162712. png_mmx_support(void)
  162713. {
  162714. return -1;
  162715. }
  162716. #endif /* PNG_1_0_X */
  162717. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162718. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162719. #ifdef PNG_SIZE_T
  162720. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162721. png_size_t PNGAPI
  162722. png_convert_size(size_t size)
  162723. {
  162724. if (size > (png_size_t)-1)
  162725. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162726. return ((png_size_t)size);
  162727. }
  162728. #endif /* PNG_SIZE_T */
  162729. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162730. /*** End of inlined file: png.c ***/
  162731. /*** Start of inlined file: pngerror.c ***/
  162732. #define PNG_INTERNAL
  162733. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162734. static void /* PRIVATE */
  162735. png_default_error PNGARG((png_structp png_ptr,
  162736. png_const_charp error_message));
  162737. #ifndef PNG_NO_WARNINGS
  162738. static void /* PRIVATE */
  162739. png_default_warning PNGARG((png_structp png_ptr,
  162740. png_const_charp warning_message));
  162741. #endif /* PNG_NO_WARNINGS */
  162742. #ifndef PNG_NO_ERROR_TEXT
  162743. void PNGAPI
  162744. png_error(png_structp png_ptr, png_const_charp error_message)
  162745. {
  162746. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162747. char msg[16];
  162748. if (png_ptr != NULL)
  162749. {
  162750. if (png_ptr->flags&
  162751. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162752. {
  162753. if (*error_message == '#')
  162754. {
  162755. int offset;
  162756. for (offset=1; offset<15; offset++)
  162757. if (*(error_message+offset) == ' ')
  162758. break;
  162759. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162760. {
  162761. int i;
  162762. for (i=0; i<offset-1; i++)
  162763. msg[i]=error_message[i+1];
  162764. msg[i]='\0';
  162765. error_message=msg;
  162766. }
  162767. else
  162768. error_message+=offset;
  162769. }
  162770. else
  162771. {
  162772. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162773. {
  162774. msg[0]='0';
  162775. msg[1]='\0';
  162776. error_message=msg;
  162777. }
  162778. }
  162779. }
  162780. }
  162781. #endif
  162782. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162783. (*(png_ptr->error_fn))(png_ptr, error_message);
  162784. png_default_error(png_ptr, error_message);
  162785. }
  162786. #else
  162787. void PNGAPI
  162788. png_err(png_structp png_ptr)
  162789. {
  162790. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162791. (*(png_ptr->error_fn))(png_ptr, '\0');
  162792. png_default_error(png_ptr, '\0');
  162793. }
  162794. #endif /* PNG_NO_ERROR_TEXT */
  162795. #ifndef PNG_NO_WARNINGS
  162796. void PNGAPI
  162797. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162798. {
  162799. int offset = 0;
  162800. if (png_ptr != NULL)
  162801. {
  162802. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162803. if (png_ptr->flags&
  162804. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162805. #endif
  162806. {
  162807. if (*warning_message == '#')
  162808. {
  162809. for (offset=1; offset<15; offset++)
  162810. if (*(warning_message+offset) == ' ')
  162811. break;
  162812. }
  162813. }
  162814. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162815. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162816. }
  162817. else
  162818. png_default_warning(png_ptr, warning_message+offset);
  162819. }
  162820. #endif /* PNG_NO_WARNINGS */
  162821. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162822. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162823. static void /* PRIVATE */
  162824. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162825. error_message)
  162826. {
  162827. int iout = 0, iin = 0;
  162828. while (iin < 4)
  162829. {
  162830. int c = png_ptr->chunk_name[iin++];
  162831. if (isnonalpha(c))
  162832. {
  162833. buffer[iout++] = '[';
  162834. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162835. buffer[iout++] = png_digit[c & 0x0f];
  162836. buffer[iout++] = ']';
  162837. }
  162838. else
  162839. {
  162840. buffer[iout++] = (png_byte)c;
  162841. }
  162842. }
  162843. if (error_message == NULL)
  162844. buffer[iout] = 0;
  162845. else
  162846. {
  162847. buffer[iout++] = ':';
  162848. buffer[iout++] = ' ';
  162849. png_strncpy(buffer+iout, error_message, 63);
  162850. buffer[iout+63] = 0;
  162851. }
  162852. }
  162853. #ifdef PNG_READ_SUPPORTED
  162854. void PNGAPI
  162855. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162856. {
  162857. char msg[18+64];
  162858. if (png_ptr == NULL)
  162859. png_error(png_ptr, error_message);
  162860. else
  162861. {
  162862. png_format_buffer(png_ptr, msg, error_message);
  162863. png_error(png_ptr, msg);
  162864. }
  162865. }
  162866. #endif /* PNG_READ_SUPPORTED */
  162867. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162868. #ifndef PNG_NO_WARNINGS
  162869. void PNGAPI
  162870. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162871. {
  162872. char msg[18+64];
  162873. if (png_ptr == NULL)
  162874. png_warning(png_ptr, warning_message);
  162875. else
  162876. {
  162877. png_format_buffer(png_ptr, msg, warning_message);
  162878. png_warning(png_ptr, msg);
  162879. }
  162880. }
  162881. #endif /* PNG_NO_WARNINGS */
  162882. static void /* PRIVATE */
  162883. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162884. {
  162885. #ifndef PNG_NO_CONSOLE_IO
  162886. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162887. if (*error_message == '#')
  162888. {
  162889. int offset;
  162890. char error_number[16];
  162891. for (offset=0; offset<15; offset++)
  162892. {
  162893. error_number[offset] = *(error_message+offset+1);
  162894. if (*(error_message+offset) == ' ')
  162895. break;
  162896. }
  162897. if((offset > 1) && (offset < 15))
  162898. {
  162899. error_number[offset-1]='\0';
  162900. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162901. error_message+offset);
  162902. }
  162903. else
  162904. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162905. }
  162906. else
  162907. #endif
  162908. fprintf(stderr, "libpng error: %s\n", error_message);
  162909. #endif
  162910. #ifdef PNG_SETJMP_SUPPORTED
  162911. if (png_ptr)
  162912. {
  162913. # ifdef USE_FAR_KEYWORD
  162914. {
  162915. jmp_buf jmpbuf;
  162916. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162917. longjmp(jmpbuf, 1);
  162918. }
  162919. # else
  162920. longjmp(png_ptr->jmpbuf, 1);
  162921. # endif
  162922. }
  162923. #else
  162924. PNG_ABORT();
  162925. #endif
  162926. #ifdef PNG_NO_CONSOLE_IO
  162927. error_message = error_message; /* make compiler happy */
  162928. #endif
  162929. }
  162930. #ifndef PNG_NO_WARNINGS
  162931. static void /* PRIVATE */
  162932. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  162933. {
  162934. #ifndef PNG_NO_CONSOLE_IO
  162935. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162936. if (*warning_message == '#')
  162937. {
  162938. int offset;
  162939. char warning_number[16];
  162940. for (offset=0; offset<15; offset++)
  162941. {
  162942. warning_number[offset]=*(warning_message+offset+1);
  162943. if (*(warning_message+offset) == ' ')
  162944. break;
  162945. }
  162946. if((offset > 1) && (offset < 15))
  162947. {
  162948. warning_number[offset-1]='\0';
  162949. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  162950. warning_message+offset);
  162951. }
  162952. else
  162953. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162954. }
  162955. else
  162956. # endif
  162957. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162958. #else
  162959. warning_message = warning_message; /* make compiler happy */
  162960. #endif
  162961. png_ptr = png_ptr; /* make compiler happy */
  162962. }
  162963. #endif /* PNG_NO_WARNINGS */
  162964. void PNGAPI
  162965. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  162966. png_error_ptr error_fn, png_error_ptr warning_fn)
  162967. {
  162968. if (png_ptr == NULL)
  162969. return;
  162970. png_ptr->error_ptr = error_ptr;
  162971. png_ptr->error_fn = error_fn;
  162972. png_ptr->warning_fn = warning_fn;
  162973. }
  162974. png_voidp PNGAPI
  162975. png_get_error_ptr(png_structp png_ptr)
  162976. {
  162977. if (png_ptr == NULL)
  162978. return NULL;
  162979. return ((png_voidp)png_ptr->error_ptr);
  162980. }
  162981. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162982. void PNGAPI
  162983. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  162984. {
  162985. if(png_ptr != NULL)
  162986. {
  162987. png_ptr->flags &=
  162988. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  162989. }
  162990. }
  162991. #endif
  162992. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  162993. /*** End of inlined file: pngerror.c ***/
  162994. /*** Start of inlined file: pngget.c ***/
  162995. #define PNG_INTERNAL
  162996. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162997. png_uint_32 PNGAPI
  162998. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  162999. {
  163000. if (png_ptr != NULL && info_ptr != NULL)
  163001. return(info_ptr->valid & flag);
  163002. else
  163003. return(0);
  163004. }
  163005. png_uint_32 PNGAPI
  163006. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163007. {
  163008. if (png_ptr != NULL && info_ptr != NULL)
  163009. return(info_ptr->rowbytes);
  163010. else
  163011. return(0);
  163012. }
  163013. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163014. png_bytepp PNGAPI
  163015. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163016. {
  163017. if (png_ptr != NULL && info_ptr != NULL)
  163018. return(info_ptr->row_pointers);
  163019. else
  163020. return(0);
  163021. }
  163022. #endif
  163023. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163024. png_uint_32 PNGAPI
  163025. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163026. {
  163027. if (png_ptr != NULL && info_ptr != NULL)
  163028. {
  163029. return info_ptr->width;
  163030. }
  163031. return (0);
  163032. }
  163033. png_uint_32 PNGAPI
  163034. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163035. {
  163036. if (png_ptr != NULL && info_ptr != NULL)
  163037. {
  163038. return info_ptr->height;
  163039. }
  163040. return (0);
  163041. }
  163042. png_byte PNGAPI
  163043. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163044. {
  163045. if (png_ptr != NULL && info_ptr != NULL)
  163046. {
  163047. return info_ptr->bit_depth;
  163048. }
  163049. return (0);
  163050. }
  163051. png_byte PNGAPI
  163052. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163053. {
  163054. if (png_ptr != NULL && info_ptr != NULL)
  163055. {
  163056. return info_ptr->color_type;
  163057. }
  163058. return (0);
  163059. }
  163060. png_byte PNGAPI
  163061. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163062. {
  163063. if (png_ptr != NULL && info_ptr != NULL)
  163064. {
  163065. return info_ptr->filter_type;
  163066. }
  163067. return (0);
  163068. }
  163069. png_byte PNGAPI
  163070. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163071. {
  163072. if (png_ptr != NULL && info_ptr != NULL)
  163073. {
  163074. return info_ptr->interlace_type;
  163075. }
  163076. return (0);
  163077. }
  163078. png_byte PNGAPI
  163079. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163080. {
  163081. if (png_ptr != NULL && info_ptr != NULL)
  163082. {
  163083. return info_ptr->compression_type;
  163084. }
  163085. return (0);
  163086. }
  163087. png_uint_32 PNGAPI
  163088. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163089. {
  163090. if (png_ptr != NULL && info_ptr != NULL)
  163091. #if defined(PNG_pHYs_SUPPORTED)
  163092. if (info_ptr->valid & PNG_INFO_pHYs)
  163093. {
  163094. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163095. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163096. return (0);
  163097. else return (info_ptr->x_pixels_per_unit);
  163098. }
  163099. #else
  163100. return (0);
  163101. #endif
  163102. return (0);
  163103. }
  163104. png_uint_32 PNGAPI
  163105. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163106. {
  163107. if (png_ptr != NULL && info_ptr != NULL)
  163108. #if defined(PNG_pHYs_SUPPORTED)
  163109. if (info_ptr->valid & PNG_INFO_pHYs)
  163110. {
  163111. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163112. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163113. return (0);
  163114. else return (info_ptr->y_pixels_per_unit);
  163115. }
  163116. #else
  163117. return (0);
  163118. #endif
  163119. return (0);
  163120. }
  163121. png_uint_32 PNGAPI
  163122. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163123. {
  163124. if (png_ptr != NULL && info_ptr != NULL)
  163125. #if defined(PNG_pHYs_SUPPORTED)
  163126. if (info_ptr->valid & PNG_INFO_pHYs)
  163127. {
  163128. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163129. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163130. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163131. return (0);
  163132. else return (info_ptr->x_pixels_per_unit);
  163133. }
  163134. #else
  163135. return (0);
  163136. #endif
  163137. return (0);
  163138. }
  163139. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163140. float PNGAPI
  163141. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163142. {
  163143. if (png_ptr != NULL && info_ptr != NULL)
  163144. #if defined(PNG_pHYs_SUPPORTED)
  163145. if (info_ptr->valid & PNG_INFO_pHYs)
  163146. {
  163147. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163148. if (info_ptr->x_pixels_per_unit == 0)
  163149. return ((float)0.0);
  163150. else
  163151. return ((float)((float)info_ptr->y_pixels_per_unit
  163152. /(float)info_ptr->x_pixels_per_unit));
  163153. }
  163154. #else
  163155. return (0.0);
  163156. #endif
  163157. return ((float)0.0);
  163158. }
  163159. #endif
  163160. png_int_32 PNGAPI
  163161. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163162. {
  163163. if (png_ptr != NULL && info_ptr != NULL)
  163164. #if defined(PNG_oFFs_SUPPORTED)
  163165. if (info_ptr->valid & PNG_INFO_oFFs)
  163166. {
  163167. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163168. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163169. return (0);
  163170. else return (info_ptr->x_offset);
  163171. }
  163172. #else
  163173. return (0);
  163174. #endif
  163175. return (0);
  163176. }
  163177. png_int_32 PNGAPI
  163178. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163179. {
  163180. if (png_ptr != NULL && info_ptr != NULL)
  163181. #if defined(PNG_oFFs_SUPPORTED)
  163182. if (info_ptr->valid & PNG_INFO_oFFs)
  163183. {
  163184. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163185. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163186. return (0);
  163187. else return (info_ptr->y_offset);
  163188. }
  163189. #else
  163190. return (0);
  163191. #endif
  163192. return (0);
  163193. }
  163194. png_int_32 PNGAPI
  163195. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163196. {
  163197. if (png_ptr != NULL && info_ptr != NULL)
  163198. #if defined(PNG_oFFs_SUPPORTED)
  163199. if (info_ptr->valid & PNG_INFO_oFFs)
  163200. {
  163201. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163202. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163203. return (0);
  163204. else return (info_ptr->x_offset);
  163205. }
  163206. #else
  163207. return (0);
  163208. #endif
  163209. return (0);
  163210. }
  163211. png_int_32 PNGAPI
  163212. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163213. {
  163214. if (png_ptr != NULL && info_ptr != NULL)
  163215. #if defined(PNG_oFFs_SUPPORTED)
  163216. if (info_ptr->valid & PNG_INFO_oFFs)
  163217. {
  163218. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163219. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163220. return (0);
  163221. else return (info_ptr->y_offset);
  163222. }
  163223. #else
  163224. return (0);
  163225. #endif
  163226. return (0);
  163227. }
  163228. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163229. png_uint_32 PNGAPI
  163230. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163231. {
  163232. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163233. *.0254 +.5));
  163234. }
  163235. png_uint_32 PNGAPI
  163236. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163237. {
  163238. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163239. *.0254 +.5));
  163240. }
  163241. png_uint_32 PNGAPI
  163242. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163243. {
  163244. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163245. *.0254 +.5));
  163246. }
  163247. float PNGAPI
  163248. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163249. {
  163250. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163251. *.00003937);
  163252. }
  163253. float PNGAPI
  163254. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163255. {
  163256. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163257. *.00003937);
  163258. }
  163259. #if defined(PNG_pHYs_SUPPORTED)
  163260. png_uint_32 PNGAPI
  163261. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163262. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163263. {
  163264. png_uint_32 retval = 0;
  163265. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163266. {
  163267. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163268. if (res_x != NULL)
  163269. {
  163270. *res_x = info_ptr->x_pixels_per_unit;
  163271. retval |= PNG_INFO_pHYs;
  163272. }
  163273. if (res_y != NULL)
  163274. {
  163275. *res_y = info_ptr->y_pixels_per_unit;
  163276. retval |= PNG_INFO_pHYs;
  163277. }
  163278. if (unit_type != NULL)
  163279. {
  163280. *unit_type = (int)info_ptr->phys_unit_type;
  163281. retval |= PNG_INFO_pHYs;
  163282. if(*unit_type == 1)
  163283. {
  163284. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163285. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163286. }
  163287. }
  163288. }
  163289. return (retval);
  163290. }
  163291. #endif /* PNG_pHYs_SUPPORTED */
  163292. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163293. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163294. png_byte PNGAPI
  163295. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163296. {
  163297. if (png_ptr != NULL && info_ptr != NULL)
  163298. return(info_ptr->channels);
  163299. else
  163300. return (0);
  163301. }
  163302. png_bytep PNGAPI
  163303. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163304. {
  163305. if (png_ptr != NULL && info_ptr != NULL)
  163306. return(info_ptr->signature);
  163307. else
  163308. return (NULL);
  163309. }
  163310. #if defined(PNG_bKGD_SUPPORTED)
  163311. png_uint_32 PNGAPI
  163312. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163313. png_color_16p *background)
  163314. {
  163315. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163316. && background != NULL)
  163317. {
  163318. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163319. *background = &(info_ptr->background);
  163320. return (PNG_INFO_bKGD);
  163321. }
  163322. return (0);
  163323. }
  163324. #endif
  163325. #if defined(PNG_cHRM_SUPPORTED)
  163326. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163327. png_uint_32 PNGAPI
  163328. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163329. double *white_x, double *white_y, double *red_x, double *red_y,
  163330. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163331. {
  163332. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163333. {
  163334. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163335. if (white_x != NULL)
  163336. *white_x = (double)info_ptr->x_white;
  163337. if (white_y != NULL)
  163338. *white_y = (double)info_ptr->y_white;
  163339. if (red_x != NULL)
  163340. *red_x = (double)info_ptr->x_red;
  163341. if (red_y != NULL)
  163342. *red_y = (double)info_ptr->y_red;
  163343. if (green_x != NULL)
  163344. *green_x = (double)info_ptr->x_green;
  163345. if (green_y != NULL)
  163346. *green_y = (double)info_ptr->y_green;
  163347. if (blue_x != NULL)
  163348. *blue_x = (double)info_ptr->x_blue;
  163349. if (blue_y != NULL)
  163350. *blue_y = (double)info_ptr->y_blue;
  163351. return (PNG_INFO_cHRM);
  163352. }
  163353. return (0);
  163354. }
  163355. #endif
  163356. #ifdef PNG_FIXED_POINT_SUPPORTED
  163357. png_uint_32 PNGAPI
  163358. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163359. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163360. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163361. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163362. {
  163363. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163364. {
  163365. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163366. if (white_x != NULL)
  163367. *white_x = info_ptr->int_x_white;
  163368. if (white_y != NULL)
  163369. *white_y = info_ptr->int_y_white;
  163370. if (red_x != NULL)
  163371. *red_x = info_ptr->int_x_red;
  163372. if (red_y != NULL)
  163373. *red_y = info_ptr->int_y_red;
  163374. if (green_x != NULL)
  163375. *green_x = info_ptr->int_x_green;
  163376. if (green_y != NULL)
  163377. *green_y = info_ptr->int_y_green;
  163378. if (blue_x != NULL)
  163379. *blue_x = info_ptr->int_x_blue;
  163380. if (blue_y != NULL)
  163381. *blue_y = info_ptr->int_y_blue;
  163382. return (PNG_INFO_cHRM);
  163383. }
  163384. return (0);
  163385. }
  163386. #endif
  163387. #endif
  163388. #if defined(PNG_gAMA_SUPPORTED)
  163389. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163390. png_uint_32 PNGAPI
  163391. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163392. {
  163393. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163394. && file_gamma != NULL)
  163395. {
  163396. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163397. *file_gamma = (double)info_ptr->gamma;
  163398. return (PNG_INFO_gAMA);
  163399. }
  163400. return (0);
  163401. }
  163402. #endif
  163403. #ifdef PNG_FIXED_POINT_SUPPORTED
  163404. png_uint_32 PNGAPI
  163405. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163406. png_fixed_point *int_file_gamma)
  163407. {
  163408. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163409. && int_file_gamma != NULL)
  163410. {
  163411. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163412. *int_file_gamma = info_ptr->int_gamma;
  163413. return (PNG_INFO_gAMA);
  163414. }
  163415. return (0);
  163416. }
  163417. #endif
  163418. #endif
  163419. #if defined(PNG_sRGB_SUPPORTED)
  163420. png_uint_32 PNGAPI
  163421. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163422. {
  163423. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163424. && file_srgb_intent != NULL)
  163425. {
  163426. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163427. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163428. return (PNG_INFO_sRGB);
  163429. }
  163430. return (0);
  163431. }
  163432. #endif
  163433. #if defined(PNG_iCCP_SUPPORTED)
  163434. png_uint_32 PNGAPI
  163435. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163436. png_charpp name, int *compression_type,
  163437. png_charpp profile, png_uint_32 *proflen)
  163438. {
  163439. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163440. && name != NULL && profile != NULL && proflen != NULL)
  163441. {
  163442. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163443. *name = info_ptr->iccp_name;
  163444. *profile = info_ptr->iccp_profile;
  163445. *proflen = (int)info_ptr->iccp_proflen;
  163446. *compression_type = (int)info_ptr->iccp_compression;
  163447. return (PNG_INFO_iCCP);
  163448. }
  163449. return (0);
  163450. }
  163451. #endif
  163452. #if defined(PNG_sPLT_SUPPORTED)
  163453. png_uint_32 PNGAPI
  163454. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163455. png_sPLT_tpp spalettes)
  163456. {
  163457. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163458. {
  163459. *spalettes = info_ptr->splt_palettes;
  163460. return ((png_uint_32)info_ptr->splt_palettes_num);
  163461. }
  163462. return (0);
  163463. }
  163464. #endif
  163465. #if defined(PNG_hIST_SUPPORTED)
  163466. png_uint_32 PNGAPI
  163467. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163468. {
  163469. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163470. && hist != NULL)
  163471. {
  163472. png_debug1(1, "in %s retrieval function\n", "hIST");
  163473. *hist = info_ptr->hist;
  163474. return (PNG_INFO_hIST);
  163475. }
  163476. return (0);
  163477. }
  163478. #endif
  163479. png_uint_32 PNGAPI
  163480. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163481. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163482. int *color_type, int *interlace_type, int *compression_type,
  163483. int *filter_type)
  163484. {
  163485. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163486. bit_depth != NULL && color_type != NULL)
  163487. {
  163488. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163489. *width = info_ptr->width;
  163490. *height = info_ptr->height;
  163491. *bit_depth = info_ptr->bit_depth;
  163492. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163493. png_error(png_ptr, "Invalid bit depth");
  163494. *color_type = info_ptr->color_type;
  163495. if (info_ptr->color_type > 6)
  163496. png_error(png_ptr, "Invalid color type");
  163497. if (compression_type != NULL)
  163498. *compression_type = info_ptr->compression_type;
  163499. if (filter_type != NULL)
  163500. *filter_type = info_ptr->filter_type;
  163501. if (interlace_type != NULL)
  163502. *interlace_type = info_ptr->interlace_type;
  163503. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163504. png_error(png_ptr, "Invalid image width");
  163505. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163506. png_error(png_ptr, "Invalid image height");
  163507. if (info_ptr->width > (PNG_UINT_32_MAX
  163508. >> 3) /* 8-byte RGBA pixels */
  163509. - 64 /* bigrowbuf hack */
  163510. - 1 /* filter byte */
  163511. - 7*8 /* rounding of width to multiple of 8 pixels */
  163512. - 8) /* extra max_pixel_depth pad */
  163513. {
  163514. png_warning(png_ptr,
  163515. "Width too large for libpng to process image data.");
  163516. }
  163517. return (1);
  163518. }
  163519. return (0);
  163520. }
  163521. #if defined(PNG_oFFs_SUPPORTED)
  163522. png_uint_32 PNGAPI
  163523. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163524. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163525. {
  163526. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163527. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163528. {
  163529. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163530. *offset_x = info_ptr->x_offset;
  163531. *offset_y = info_ptr->y_offset;
  163532. *unit_type = (int)info_ptr->offset_unit_type;
  163533. return (PNG_INFO_oFFs);
  163534. }
  163535. return (0);
  163536. }
  163537. #endif
  163538. #if defined(PNG_pCAL_SUPPORTED)
  163539. png_uint_32 PNGAPI
  163540. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163541. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163542. png_charp *units, png_charpp *params)
  163543. {
  163544. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163545. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163546. nparams != NULL && units != NULL && params != NULL)
  163547. {
  163548. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163549. *purpose = info_ptr->pcal_purpose;
  163550. *X0 = info_ptr->pcal_X0;
  163551. *X1 = info_ptr->pcal_X1;
  163552. *type = (int)info_ptr->pcal_type;
  163553. *nparams = (int)info_ptr->pcal_nparams;
  163554. *units = info_ptr->pcal_units;
  163555. *params = info_ptr->pcal_params;
  163556. return (PNG_INFO_pCAL);
  163557. }
  163558. return (0);
  163559. }
  163560. #endif
  163561. #if defined(PNG_sCAL_SUPPORTED)
  163562. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163563. png_uint_32 PNGAPI
  163564. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163565. int *unit, double *width, double *height)
  163566. {
  163567. if (png_ptr != NULL && info_ptr != NULL &&
  163568. (info_ptr->valid & PNG_INFO_sCAL))
  163569. {
  163570. *unit = info_ptr->scal_unit;
  163571. *width = info_ptr->scal_pixel_width;
  163572. *height = info_ptr->scal_pixel_height;
  163573. return (PNG_INFO_sCAL);
  163574. }
  163575. return(0);
  163576. }
  163577. #else
  163578. #ifdef PNG_FIXED_POINT_SUPPORTED
  163579. png_uint_32 PNGAPI
  163580. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163581. int *unit, png_charpp width, png_charpp height)
  163582. {
  163583. if (png_ptr != NULL && info_ptr != NULL &&
  163584. (info_ptr->valid & PNG_INFO_sCAL))
  163585. {
  163586. *unit = info_ptr->scal_unit;
  163587. *width = info_ptr->scal_s_width;
  163588. *height = info_ptr->scal_s_height;
  163589. return (PNG_INFO_sCAL);
  163590. }
  163591. return(0);
  163592. }
  163593. #endif
  163594. #endif
  163595. #endif
  163596. #if defined(PNG_pHYs_SUPPORTED)
  163597. png_uint_32 PNGAPI
  163598. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163599. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163600. {
  163601. png_uint_32 retval = 0;
  163602. if (png_ptr != NULL && info_ptr != NULL &&
  163603. (info_ptr->valid & PNG_INFO_pHYs))
  163604. {
  163605. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163606. if (res_x != NULL)
  163607. {
  163608. *res_x = info_ptr->x_pixels_per_unit;
  163609. retval |= PNG_INFO_pHYs;
  163610. }
  163611. if (res_y != NULL)
  163612. {
  163613. *res_y = info_ptr->y_pixels_per_unit;
  163614. retval |= PNG_INFO_pHYs;
  163615. }
  163616. if (unit_type != NULL)
  163617. {
  163618. *unit_type = (int)info_ptr->phys_unit_type;
  163619. retval |= PNG_INFO_pHYs;
  163620. }
  163621. }
  163622. return (retval);
  163623. }
  163624. #endif
  163625. png_uint_32 PNGAPI
  163626. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163627. int *num_palette)
  163628. {
  163629. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163630. && palette != NULL)
  163631. {
  163632. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163633. *palette = info_ptr->palette;
  163634. *num_palette = info_ptr->num_palette;
  163635. png_debug1(3, "num_palette = %d\n", *num_palette);
  163636. return (PNG_INFO_PLTE);
  163637. }
  163638. return (0);
  163639. }
  163640. #if defined(PNG_sBIT_SUPPORTED)
  163641. png_uint_32 PNGAPI
  163642. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163643. {
  163644. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163645. && sig_bit != NULL)
  163646. {
  163647. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163648. *sig_bit = &(info_ptr->sig_bit);
  163649. return (PNG_INFO_sBIT);
  163650. }
  163651. return (0);
  163652. }
  163653. #endif
  163654. #if defined(PNG_TEXT_SUPPORTED)
  163655. png_uint_32 PNGAPI
  163656. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163657. int *num_text)
  163658. {
  163659. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163660. {
  163661. png_debug1(1, "in %s retrieval function\n",
  163662. (png_ptr->chunk_name[0] == '\0' ? "text"
  163663. : (png_const_charp)png_ptr->chunk_name));
  163664. if (text_ptr != NULL)
  163665. *text_ptr = info_ptr->text;
  163666. if (num_text != NULL)
  163667. *num_text = info_ptr->num_text;
  163668. return ((png_uint_32)info_ptr->num_text);
  163669. }
  163670. if (num_text != NULL)
  163671. *num_text = 0;
  163672. return(0);
  163673. }
  163674. #endif
  163675. #if defined(PNG_tIME_SUPPORTED)
  163676. png_uint_32 PNGAPI
  163677. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163678. {
  163679. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163680. && mod_time != NULL)
  163681. {
  163682. png_debug1(1, "in %s retrieval function\n", "tIME");
  163683. *mod_time = &(info_ptr->mod_time);
  163684. return (PNG_INFO_tIME);
  163685. }
  163686. return (0);
  163687. }
  163688. #endif
  163689. #if defined(PNG_tRNS_SUPPORTED)
  163690. png_uint_32 PNGAPI
  163691. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163692. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163693. {
  163694. png_uint_32 retval = 0;
  163695. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163696. {
  163697. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163698. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163699. {
  163700. if (trans != NULL)
  163701. {
  163702. *trans = info_ptr->trans;
  163703. retval |= PNG_INFO_tRNS;
  163704. }
  163705. if (trans_values != NULL)
  163706. *trans_values = &(info_ptr->trans_values);
  163707. }
  163708. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163709. {
  163710. if (trans_values != NULL)
  163711. {
  163712. *trans_values = &(info_ptr->trans_values);
  163713. retval |= PNG_INFO_tRNS;
  163714. }
  163715. if(trans != NULL)
  163716. *trans = NULL;
  163717. }
  163718. if(num_trans != NULL)
  163719. {
  163720. *num_trans = info_ptr->num_trans;
  163721. retval |= PNG_INFO_tRNS;
  163722. }
  163723. }
  163724. return (retval);
  163725. }
  163726. #endif
  163727. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163728. png_uint_32 PNGAPI
  163729. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163730. png_unknown_chunkpp unknowns)
  163731. {
  163732. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163733. {
  163734. *unknowns = info_ptr->unknown_chunks;
  163735. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163736. }
  163737. return (0);
  163738. }
  163739. #endif
  163740. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163741. png_byte PNGAPI
  163742. png_get_rgb_to_gray_status (png_structp png_ptr)
  163743. {
  163744. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163745. }
  163746. #endif
  163747. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163748. png_voidp PNGAPI
  163749. png_get_user_chunk_ptr(png_structp png_ptr)
  163750. {
  163751. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163752. }
  163753. #endif
  163754. #ifdef PNG_WRITE_SUPPORTED
  163755. png_uint_32 PNGAPI
  163756. png_get_compression_buffer_size(png_structp png_ptr)
  163757. {
  163758. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163759. }
  163760. #endif
  163761. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163762. #ifndef PNG_1_0_X
  163763. png_uint_32 PNGAPI
  163764. png_get_asm_flags (png_structp png_ptr)
  163765. {
  163766. return (png_ptr? 0L: 0L);
  163767. }
  163768. png_uint_32 PNGAPI
  163769. png_get_asm_flagmask (int flag_select)
  163770. {
  163771. flag_select=flag_select;
  163772. return 0L;
  163773. }
  163774. png_uint_32 PNGAPI
  163775. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163776. {
  163777. flag_select=flag_select;
  163778. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163779. return 0L;
  163780. }
  163781. png_byte PNGAPI
  163782. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163783. {
  163784. return (png_ptr? 0: 0);
  163785. }
  163786. png_uint_32 PNGAPI
  163787. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163788. {
  163789. return (png_ptr? 0L: 0L);
  163790. }
  163791. #endif /* ?PNG_1_0_X */
  163792. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163793. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163794. png_uint_32 PNGAPI
  163795. png_get_user_width_max (png_structp png_ptr)
  163796. {
  163797. return (png_ptr? png_ptr->user_width_max : 0);
  163798. }
  163799. png_uint_32 PNGAPI
  163800. png_get_user_height_max (png_structp png_ptr)
  163801. {
  163802. return (png_ptr? png_ptr->user_height_max : 0);
  163803. }
  163804. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163805. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163806. /*** End of inlined file: pngget.c ***/
  163807. /*** Start of inlined file: pngmem.c ***/
  163808. #define PNG_INTERNAL
  163809. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163810. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163811. png_voidp /* PRIVATE */
  163812. png_create_struct(int type)
  163813. {
  163814. #ifdef PNG_USER_MEM_SUPPORTED
  163815. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163816. }
  163817. png_voidp /* PRIVATE */
  163818. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163819. {
  163820. #endif /* PNG_USER_MEM_SUPPORTED */
  163821. png_size_t size;
  163822. png_voidp struct_ptr;
  163823. if (type == PNG_STRUCT_INFO)
  163824. size = png_sizeof(png_info);
  163825. else if (type == PNG_STRUCT_PNG)
  163826. size = png_sizeof(png_struct);
  163827. else
  163828. return (png_get_copyright(NULL));
  163829. #ifdef PNG_USER_MEM_SUPPORTED
  163830. if(malloc_fn != NULL)
  163831. {
  163832. png_struct dummy_struct;
  163833. png_structp png_ptr = &dummy_struct;
  163834. png_ptr->mem_ptr=mem_ptr;
  163835. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163836. }
  163837. else
  163838. #endif /* PNG_USER_MEM_SUPPORTED */
  163839. struct_ptr = (png_voidp)farmalloc(size);
  163840. if (struct_ptr != NULL)
  163841. png_memset(struct_ptr, 0, size);
  163842. return (struct_ptr);
  163843. }
  163844. void /* PRIVATE */
  163845. png_destroy_struct(png_voidp struct_ptr)
  163846. {
  163847. #ifdef PNG_USER_MEM_SUPPORTED
  163848. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163849. }
  163850. void /* PRIVATE */
  163851. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163852. png_voidp mem_ptr)
  163853. {
  163854. #endif
  163855. if (struct_ptr != NULL)
  163856. {
  163857. #ifdef PNG_USER_MEM_SUPPORTED
  163858. if(free_fn != NULL)
  163859. {
  163860. png_struct dummy_struct;
  163861. png_structp png_ptr = &dummy_struct;
  163862. png_ptr->mem_ptr=mem_ptr;
  163863. (*(free_fn))(png_ptr, struct_ptr);
  163864. return;
  163865. }
  163866. #endif /* PNG_USER_MEM_SUPPORTED */
  163867. farfree (struct_ptr);
  163868. }
  163869. }
  163870. png_voidp PNGAPI
  163871. png_malloc(png_structp png_ptr, png_uint_32 size)
  163872. {
  163873. png_voidp ret;
  163874. if (png_ptr == NULL || size == 0)
  163875. return (NULL);
  163876. #ifdef PNG_USER_MEM_SUPPORTED
  163877. if(png_ptr->malloc_fn != NULL)
  163878. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163879. else
  163880. ret = (png_malloc_default(png_ptr, size));
  163881. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163882. png_error(png_ptr, "Out of memory!");
  163883. return (ret);
  163884. }
  163885. png_voidp PNGAPI
  163886. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163887. {
  163888. png_voidp ret;
  163889. #endif /* PNG_USER_MEM_SUPPORTED */
  163890. if (png_ptr == NULL || size == 0)
  163891. return (NULL);
  163892. #ifdef PNG_MAX_MALLOC_64K
  163893. if (size > (png_uint_32)65536L)
  163894. {
  163895. png_warning(png_ptr, "Cannot Allocate > 64K");
  163896. ret = NULL;
  163897. }
  163898. else
  163899. #endif
  163900. if (size != (size_t)size)
  163901. ret = NULL;
  163902. else if (size == (png_uint_32)65536L)
  163903. {
  163904. if (png_ptr->offset_table == NULL)
  163905. {
  163906. ret = farmalloc(size);
  163907. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163908. {
  163909. int num_blocks;
  163910. png_uint_32 total_size;
  163911. png_bytep table;
  163912. int i;
  163913. png_byte huge * hptr;
  163914. if (ret != NULL)
  163915. {
  163916. farfree(ret);
  163917. ret = NULL;
  163918. }
  163919. if(png_ptr->zlib_window_bits > 14)
  163920. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  163921. else
  163922. num_blocks = 1;
  163923. if (png_ptr->zlib_mem_level >= 7)
  163924. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  163925. else
  163926. num_blocks++;
  163927. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  163928. table = farmalloc(total_size);
  163929. if (table == NULL)
  163930. {
  163931. #ifndef PNG_USER_MEM_SUPPORTED
  163932. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163933. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  163934. else
  163935. png_warning(png_ptr, "Out Of Memory.");
  163936. #endif
  163937. return (NULL);
  163938. }
  163939. if ((png_size_t)table & 0xfff0)
  163940. {
  163941. #ifndef PNG_USER_MEM_SUPPORTED
  163942. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163943. png_error(png_ptr,
  163944. "Farmalloc didn't return normalized pointer");
  163945. else
  163946. png_warning(png_ptr,
  163947. "Farmalloc didn't return normalized pointer");
  163948. #endif
  163949. return (NULL);
  163950. }
  163951. png_ptr->offset_table = table;
  163952. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  163953. png_sizeof (png_bytep));
  163954. if (png_ptr->offset_table_ptr == NULL)
  163955. {
  163956. #ifndef PNG_USER_MEM_SUPPORTED
  163957. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163958. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  163959. else
  163960. png_warning(png_ptr, "Out Of memory.");
  163961. #endif
  163962. return (NULL);
  163963. }
  163964. hptr = (png_byte huge *)table;
  163965. if ((png_size_t)hptr & 0xf)
  163966. {
  163967. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  163968. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  163969. }
  163970. for (i = 0; i < num_blocks; i++)
  163971. {
  163972. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  163973. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  163974. }
  163975. png_ptr->offset_table_number = num_blocks;
  163976. png_ptr->offset_table_count = 0;
  163977. png_ptr->offset_table_count_free = 0;
  163978. }
  163979. }
  163980. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  163981. {
  163982. #ifndef PNG_USER_MEM_SUPPORTED
  163983. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163984. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  163985. else
  163986. png_warning(png_ptr, "Out of Memory.");
  163987. #endif
  163988. return (NULL);
  163989. }
  163990. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  163991. }
  163992. else
  163993. ret = farmalloc(size);
  163994. #ifndef PNG_USER_MEM_SUPPORTED
  163995. if (ret == NULL)
  163996. {
  163997. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163998. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163999. else
  164000. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164001. }
  164002. #endif
  164003. return (ret);
  164004. }
  164005. void PNGAPI
  164006. png_free(png_structp png_ptr, png_voidp ptr)
  164007. {
  164008. if (png_ptr == NULL || ptr == NULL)
  164009. return;
  164010. #ifdef PNG_USER_MEM_SUPPORTED
  164011. if (png_ptr->free_fn != NULL)
  164012. {
  164013. (*(png_ptr->free_fn))(png_ptr, ptr);
  164014. return;
  164015. }
  164016. else png_free_default(png_ptr, ptr);
  164017. }
  164018. void PNGAPI
  164019. png_free_default(png_structp png_ptr, png_voidp ptr)
  164020. {
  164021. #endif /* PNG_USER_MEM_SUPPORTED */
  164022. if(png_ptr == NULL) return;
  164023. if (png_ptr->offset_table != NULL)
  164024. {
  164025. int i;
  164026. for (i = 0; i < png_ptr->offset_table_count; i++)
  164027. {
  164028. if (ptr == png_ptr->offset_table_ptr[i])
  164029. {
  164030. ptr = NULL;
  164031. png_ptr->offset_table_count_free++;
  164032. break;
  164033. }
  164034. }
  164035. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164036. {
  164037. farfree(png_ptr->offset_table);
  164038. farfree(png_ptr->offset_table_ptr);
  164039. png_ptr->offset_table = NULL;
  164040. png_ptr->offset_table_ptr = NULL;
  164041. }
  164042. }
  164043. if (ptr != NULL)
  164044. {
  164045. farfree(ptr);
  164046. }
  164047. }
  164048. #else /* Not the Borland DOS special memory handler */
  164049. png_voidp /* PRIVATE */
  164050. png_create_struct(int type)
  164051. {
  164052. #ifdef PNG_USER_MEM_SUPPORTED
  164053. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164054. }
  164055. png_voidp /* PRIVATE */
  164056. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164057. {
  164058. #endif /* PNG_USER_MEM_SUPPORTED */
  164059. png_size_t size;
  164060. png_voidp struct_ptr;
  164061. if (type == PNG_STRUCT_INFO)
  164062. size = png_sizeof(png_info);
  164063. else if (type == PNG_STRUCT_PNG)
  164064. size = png_sizeof(png_struct);
  164065. else
  164066. return (NULL);
  164067. #ifdef PNG_USER_MEM_SUPPORTED
  164068. if(malloc_fn != NULL)
  164069. {
  164070. png_struct dummy_struct;
  164071. png_structp png_ptr = &dummy_struct;
  164072. png_ptr->mem_ptr=mem_ptr;
  164073. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164074. if (struct_ptr != NULL)
  164075. png_memset(struct_ptr, 0, size);
  164076. return (struct_ptr);
  164077. }
  164078. #endif /* PNG_USER_MEM_SUPPORTED */
  164079. #if defined(__TURBOC__) && !defined(__FLAT__)
  164080. struct_ptr = (png_voidp)farmalloc(size);
  164081. #else
  164082. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164083. struct_ptr = (png_voidp)halloc(size,1);
  164084. # else
  164085. struct_ptr = (png_voidp)malloc(size);
  164086. # endif
  164087. #endif
  164088. if (struct_ptr != NULL)
  164089. png_memset(struct_ptr, 0, size);
  164090. return (struct_ptr);
  164091. }
  164092. void /* PRIVATE */
  164093. png_destroy_struct(png_voidp struct_ptr)
  164094. {
  164095. #ifdef PNG_USER_MEM_SUPPORTED
  164096. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164097. }
  164098. void /* PRIVATE */
  164099. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164100. png_voidp mem_ptr)
  164101. {
  164102. #endif /* PNG_USER_MEM_SUPPORTED */
  164103. if (struct_ptr != NULL)
  164104. {
  164105. #ifdef PNG_USER_MEM_SUPPORTED
  164106. if(free_fn != NULL)
  164107. {
  164108. png_struct dummy_struct;
  164109. png_structp png_ptr = &dummy_struct;
  164110. png_ptr->mem_ptr=mem_ptr;
  164111. (*(free_fn))(png_ptr, struct_ptr);
  164112. return;
  164113. }
  164114. #endif /* PNG_USER_MEM_SUPPORTED */
  164115. #if defined(__TURBOC__) && !defined(__FLAT__)
  164116. farfree(struct_ptr);
  164117. #else
  164118. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164119. hfree(struct_ptr);
  164120. # else
  164121. free(struct_ptr);
  164122. # endif
  164123. #endif
  164124. }
  164125. }
  164126. png_voidp PNGAPI
  164127. png_malloc(png_structp png_ptr, png_uint_32 size)
  164128. {
  164129. png_voidp ret;
  164130. #ifdef PNG_USER_MEM_SUPPORTED
  164131. if (png_ptr == NULL || size == 0)
  164132. return (NULL);
  164133. if(png_ptr->malloc_fn != NULL)
  164134. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164135. else
  164136. ret = (png_malloc_default(png_ptr, size));
  164137. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164138. png_error(png_ptr, "Out of Memory!");
  164139. return (ret);
  164140. }
  164141. png_voidp PNGAPI
  164142. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164143. {
  164144. png_voidp ret;
  164145. #endif /* PNG_USER_MEM_SUPPORTED */
  164146. if (png_ptr == NULL || size == 0)
  164147. return (NULL);
  164148. #ifdef PNG_MAX_MALLOC_64K
  164149. if (size > (png_uint_32)65536L)
  164150. {
  164151. #ifndef PNG_USER_MEM_SUPPORTED
  164152. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164153. png_error(png_ptr, "Cannot Allocate > 64K");
  164154. else
  164155. #endif
  164156. return NULL;
  164157. }
  164158. #endif
  164159. #if defined(__TURBOC__) && !defined(__FLAT__)
  164160. if (size != (unsigned long)size)
  164161. ret = NULL;
  164162. else
  164163. ret = farmalloc(size);
  164164. #else
  164165. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164166. if (size != (unsigned long)size)
  164167. ret = NULL;
  164168. else
  164169. ret = halloc(size, 1);
  164170. # else
  164171. if (size != (size_t)size)
  164172. ret = NULL;
  164173. else
  164174. ret = malloc((size_t)size);
  164175. # endif
  164176. #endif
  164177. #ifndef PNG_USER_MEM_SUPPORTED
  164178. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164179. png_error(png_ptr, "Out of Memory");
  164180. #endif
  164181. return (ret);
  164182. }
  164183. void PNGAPI
  164184. png_free(png_structp png_ptr, png_voidp ptr)
  164185. {
  164186. if (png_ptr == NULL || ptr == NULL)
  164187. return;
  164188. #ifdef PNG_USER_MEM_SUPPORTED
  164189. if (png_ptr->free_fn != NULL)
  164190. {
  164191. (*(png_ptr->free_fn))(png_ptr, ptr);
  164192. return;
  164193. }
  164194. else png_free_default(png_ptr, ptr);
  164195. }
  164196. void PNGAPI
  164197. png_free_default(png_structp png_ptr, png_voidp ptr)
  164198. {
  164199. if (png_ptr == NULL || ptr == NULL)
  164200. return;
  164201. #endif /* PNG_USER_MEM_SUPPORTED */
  164202. #if defined(__TURBOC__) && !defined(__FLAT__)
  164203. farfree(ptr);
  164204. #else
  164205. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164206. hfree(ptr);
  164207. # else
  164208. free(ptr);
  164209. # endif
  164210. #endif
  164211. }
  164212. #endif /* Not Borland DOS special memory handler */
  164213. #if defined(PNG_1_0_X)
  164214. # define png_malloc_warn png_malloc
  164215. #else
  164216. png_voidp PNGAPI
  164217. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164218. {
  164219. png_voidp ptr;
  164220. png_uint_32 save_flags;
  164221. if(png_ptr == NULL) return (NULL);
  164222. save_flags=png_ptr->flags;
  164223. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164224. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164225. png_ptr->flags=save_flags;
  164226. return(ptr);
  164227. }
  164228. #endif
  164229. png_voidp PNGAPI
  164230. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164231. png_uint_32 length)
  164232. {
  164233. png_size_t size;
  164234. size = (png_size_t)length;
  164235. if ((png_uint_32)size != length)
  164236. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164237. return(png_memcpy (s1, s2, size));
  164238. }
  164239. png_voidp PNGAPI
  164240. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164241. png_uint_32 length)
  164242. {
  164243. png_size_t size;
  164244. size = (png_size_t)length;
  164245. if ((png_uint_32)size != length)
  164246. png_error(png_ptr,"Overflow in png_memset_check.");
  164247. return (png_memset (s1, value, size));
  164248. }
  164249. #ifdef PNG_USER_MEM_SUPPORTED
  164250. void PNGAPI
  164251. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164252. malloc_fn, png_free_ptr free_fn)
  164253. {
  164254. if(png_ptr != NULL) {
  164255. png_ptr->mem_ptr = mem_ptr;
  164256. png_ptr->malloc_fn = malloc_fn;
  164257. png_ptr->free_fn = free_fn;
  164258. }
  164259. }
  164260. png_voidp PNGAPI
  164261. png_get_mem_ptr(png_structp png_ptr)
  164262. {
  164263. if(png_ptr == NULL) return (NULL);
  164264. return ((png_voidp)png_ptr->mem_ptr);
  164265. }
  164266. #endif /* PNG_USER_MEM_SUPPORTED */
  164267. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164268. /*** End of inlined file: pngmem.c ***/
  164269. /*** Start of inlined file: pngread.c ***/
  164270. #define PNG_INTERNAL
  164271. #if defined(PNG_READ_SUPPORTED)
  164272. png_structp PNGAPI
  164273. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164274. png_error_ptr error_fn, png_error_ptr warn_fn)
  164275. {
  164276. #ifdef PNG_USER_MEM_SUPPORTED
  164277. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164278. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164279. }
  164280. png_structp PNGAPI
  164281. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164282. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164283. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164284. {
  164285. #endif /* PNG_USER_MEM_SUPPORTED */
  164286. png_structp png_ptr;
  164287. #ifdef PNG_SETJMP_SUPPORTED
  164288. #ifdef USE_FAR_KEYWORD
  164289. jmp_buf jmpbuf;
  164290. #endif
  164291. #endif
  164292. int i;
  164293. png_debug(1, "in png_create_read_struct\n");
  164294. #ifdef PNG_USER_MEM_SUPPORTED
  164295. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164296. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164297. #else
  164298. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164299. #endif
  164300. if (png_ptr == NULL)
  164301. return (NULL);
  164302. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164303. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164304. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164305. #endif
  164306. #ifdef PNG_SETJMP_SUPPORTED
  164307. #ifdef USE_FAR_KEYWORD
  164308. if (setjmp(jmpbuf))
  164309. #else
  164310. if (setjmp(png_ptr->jmpbuf))
  164311. #endif
  164312. {
  164313. png_free(png_ptr, png_ptr->zbuf);
  164314. png_ptr->zbuf=NULL;
  164315. #ifdef PNG_USER_MEM_SUPPORTED
  164316. png_destroy_struct_2((png_voidp)png_ptr,
  164317. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164318. #else
  164319. png_destroy_struct((png_voidp)png_ptr);
  164320. #endif
  164321. return (NULL);
  164322. }
  164323. #ifdef USE_FAR_KEYWORD
  164324. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164325. #endif
  164326. #endif
  164327. #ifdef PNG_USER_MEM_SUPPORTED
  164328. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164329. #endif
  164330. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164331. i=0;
  164332. do
  164333. {
  164334. if(user_png_ver[i] != png_libpng_ver[i])
  164335. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164336. } while (png_libpng_ver[i++]);
  164337. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164338. {
  164339. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164340. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164341. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164342. {
  164343. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164344. char msg[80];
  164345. if (user_png_ver)
  164346. {
  164347. png_snprintf(msg, 80,
  164348. "Application was compiled with png.h from libpng-%.20s",
  164349. user_png_ver);
  164350. png_warning(png_ptr, msg);
  164351. }
  164352. png_snprintf(msg, 80,
  164353. "Application is running with png.c from libpng-%.20s",
  164354. png_libpng_ver);
  164355. png_warning(png_ptr, msg);
  164356. #endif
  164357. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164358. png_ptr->flags=0;
  164359. #endif
  164360. png_error(png_ptr,
  164361. "Incompatible libpng version in application and library");
  164362. }
  164363. }
  164364. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164365. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164366. (png_uint_32)png_ptr->zbuf_size);
  164367. png_ptr->zstream.zalloc = png_zalloc;
  164368. png_ptr->zstream.zfree = png_zfree;
  164369. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164370. switch (inflateInit(&png_ptr->zstream))
  164371. {
  164372. case Z_OK: /* Do nothing */ break;
  164373. case Z_MEM_ERROR:
  164374. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164375. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164376. default: png_error(png_ptr, "Unknown zlib error");
  164377. }
  164378. png_ptr->zstream.next_out = png_ptr->zbuf;
  164379. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164380. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164381. #ifdef PNG_SETJMP_SUPPORTED
  164382. #ifdef USE_FAR_KEYWORD
  164383. if (setjmp(jmpbuf))
  164384. PNG_ABORT();
  164385. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164386. #else
  164387. if (setjmp(png_ptr->jmpbuf))
  164388. PNG_ABORT();
  164389. #endif
  164390. #endif
  164391. return (png_ptr);
  164392. }
  164393. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164394. #undef png_read_init
  164395. void PNGAPI
  164396. png_read_init(png_structp png_ptr)
  164397. {
  164398. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164399. }
  164400. void PNGAPI
  164401. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164402. png_size_t png_struct_size, png_size_t png_info_size)
  164403. {
  164404. if(png_ptr == NULL) return;
  164405. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164406. if(png_sizeof(png_struct) > png_struct_size ||
  164407. png_sizeof(png_info) > png_info_size)
  164408. {
  164409. char msg[80];
  164410. png_ptr->warning_fn=NULL;
  164411. if (user_png_ver)
  164412. {
  164413. png_snprintf(msg, 80,
  164414. "Application was compiled with png.h from libpng-%.20s",
  164415. user_png_ver);
  164416. png_warning(png_ptr, msg);
  164417. }
  164418. png_snprintf(msg, 80,
  164419. "Application is running with png.c from libpng-%.20s",
  164420. png_libpng_ver);
  164421. png_warning(png_ptr, msg);
  164422. }
  164423. #endif
  164424. if(png_sizeof(png_struct) > png_struct_size)
  164425. {
  164426. png_ptr->error_fn=NULL;
  164427. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164428. png_ptr->flags=0;
  164429. #endif
  164430. png_error(png_ptr,
  164431. "The png struct allocated by the application for reading is too small.");
  164432. }
  164433. if(png_sizeof(png_info) > png_info_size)
  164434. {
  164435. png_ptr->error_fn=NULL;
  164436. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164437. png_ptr->flags=0;
  164438. #endif
  164439. png_error(png_ptr,
  164440. "The info struct allocated by application for reading is too small.");
  164441. }
  164442. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164443. }
  164444. #endif /* PNG_1_0_X || PNG_1_2_X */
  164445. void PNGAPI
  164446. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164447. png_size_t png_struct_size)
  164448. {
  164449. #ifdef PNG_SETJMP_SUPPORTED
  164450. jmp_buf tmp_jmp; /* to save current jump buffer */
  164451. #endif
  164452. int i=0;
  164453. png_structp png_ptr=*ptr_ptr;
  164454. if(png_ptr == NULL) return;
  164455. do
  164456. {
  164457. if(user_png_ver[i] != png_libpng_ver[i])
  164458. {
  164459. #ifdef PNG_LEGACY_SUPPORTED
  164460. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164461. #else
  164462. png_ptr->warning_fn=NULL;
  164463. png_warning(png_ptr,
  164464. "Application uses deprecated png_read_init() and should be recompiled.");
  164465. break;
  164466. #endif
  164467. }
  164468. } while (png_libpng_ver[i++]);
  164469. png_debug(1, "in png_read_init_3\n");
  164470. #ifdef PNG_SETJMP_SUPPORTED
  164471. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164472. #endif
  164473. if(png_sizeof(png_struct) > png_struct_size)
  164474. {
  164475. png_destroy_struct(png_ptr);
  164476. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164477. png_ptr = *ptr_ptr;
  164478. }
  164479. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164480. #ifdef PNG_SETJMP_SUPPORTED
  164481. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164482. #endif
  164483. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164484. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164485. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164486. #endif
  164487. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164488. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164489. (png_uint_32)png_ptr->zbuf_size);
  164490. png_ptr->zstream.zalloc = png_zalloc;
  164491. png_ptr->zstream.zfree = png_zfree;
  164492. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164493. switch (inflateInit(&png_ptr->zstream))
  164494. {
  164495. case Z_OK: /* Do nothing */ break;
  164496. case Z_MEM_ERROR:
  164497. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164498. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164499. default: png_error(png_ptr, "Unknown zlib error");
  164500. }
  164501. png_ptr->zstream.next_out = png_ptr->zbuf;
  164502. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164503. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164504. }
  164505. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164506. void PNGAPI
  164507. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164508. {
  164509. if(png_ptr == NULL) return;
  164510. png_debug(1, "in png_read_info\n");
  164511. if (png_ptr->sig_bytes < 8)
  164512. {
  164513. png_size_t num_checked = png_ptr->sig_bytes,
  164514. num_to_check = 8 - num_checked;
  164515. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164516. png_ptr->sig_bytes = 8;
  164517. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164518. {
  164519. if (num_checked < 4 &&
  164520. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164521. png_error(png_ptr, "Not a PNG file");
  164522. else
  164523. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164524. }
  164525. if (num_checked < 3)
  164526. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164527. }
  164528. for(;;)
  164529. {
  164530. #ifdef PNG_USE_LOCAL_ARRAYS
  164531. PNG_CONST PNG_IHDR;
  164532. PNG_CONST PNG_IDAT;
  164533. PNG_CONST PNG_IEND;
  164534. PNG_CONST PNG_PLTE;
  164535. #if defined(PNG_READ_bKGD_SUPPORTED)
  164536. PNG_CONST PNG_bKGD;
  164537. #endif
  164538. #if defined(PNG_READ_cHRM_SUPPORTED)
  164539. PNG_CONST PNG_cHRM;
  164540. #endif
  164541. #if defined(PNG_READ_gAMA_SUPPORTED)
  164542. PNG_CONST PNG_gAMA;
  164543. #endif
  164544. #if defined(PNG_READ_hIST_SUPPORTED)
  164545. PNG_CONST PNG_hIST;
  164546. #endif
  164547. #if defined(PNG_READ_iCCP_SUPPORTED)
  164548. PNG_CONST PNG_iCCP;
  164549. #endif
  164550. #if defined(PNG_READ_iTXt_SUPPORTED)
  164551. PNG_CONST PNG_iTXt;
  164552. #endif
  164553. #if defined(PNG_READ_oFFs_SUPPORTED)
  164554. PNG_CONST PNG_oFFs;
  164555. #endif
  164556. #if defined(PNG_READ_pCAL_SUPPORTED)
  164557. PNG_CONST PNG_pCAL;
  164558. #endif
  164559. #if defined(PNG_READ_pHYs_SUPPORTED)
  164560. PNG_CONST PNG_pHYs;
  164561. #endif
  164562. #if defined(PNG_READ_sBIT_SUPPORTED)
  164563. PNG_CONST PNG_sBIT;
  164564. #endif
  164565. #if defined(PNG_READ_sCAL_SUPPORTED)
  164566. PNG_CONST PNG_sCAL;
  164567. #endif
  164568. #if defined(PNG_READ_sPLT_SUPPORTED)
  164569. PNG_CONST PNG_sPLT;
  164570. #endif
  164571. #if defined(PNG_READ_sRGB_SUPPORTED)
  164572. PNG_CONST PNG_sRGB;
  164573. #endif
  164574. #if defined(PNG_READ_tEXt_SUPPORTED)
  164575. PNG_CONST PNG_tEXt;
  164576. #endif
  164577. #if defined(PNG_READ_tIME_SUPPORTED)
  164578. PNG_CONST PNG_tIME;
  164579. #endif
  164580. #if defined(PNG_READ_tRNS_SUPPORTED)
  164581. PNG_CONST PNG_tRNS;
  164582. #endif
  164583. #if defined(PNG_READ_zTXt_SUPPORTED)
  164584. PNG_CONST PNG_zTXt;
  164585. #endif
  164586. #endif /* PNG_USE_LOCAL_ARRAYS */
  164587. png_byte chunk_length[4];
  164588. png_uint_32 length;
  164589. png_read_data(png_ptr, chunk_length, 4);
  164590. length = png_get_uint_31(png_ptr,chunk_length);
  164591. png_reset_crc(png_ptr);
  164592. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164593. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164594. length);
  164595. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164596. if(png_ptr->mode & PNG_AFTER_IDAT)
  164597. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164598. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164599. png_handle_IHDR(png_ptr, info_ptr, length);
  164600. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164601. png_handle_IEND(png_ptr, info_ptr, length);
  164602. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164603. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164604. {
  164605. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164606. png_ptr->mode |= PNG_HAVE_IDAT;
  164607. png_handle_unknown(png_ptr, info_ptr, length);
  164608. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164609. png_ptr->mode |= PNG_HAVE_PLTE;
  164610. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164611. {
  164612. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164613. png_error(png_ptr, "Missing IHDR before IDAT");
  164614. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164615. !(png_ptr->mode & PNG_HAVE_PLTE))
  164616. png_error(png_ptr, "Missing PLTE before IDAT");
  164617. break;
  164618. }
  164619. }
  164620. #endif
  164621. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164622. png_handle_PLTE(png_ptr, info_ptr, length);
  164623. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164624. {
  164625. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164626. png_error(png_ptr, "Missing IHDR before IDAT");
  164627. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164628. !(png_ptr->mode & PNG_HAVE_PLTE))
  164629. png_error(png_ptr, "Missing PLTE before IDAT");
  164630. png_ptr->idat_size = length;
  164631. png_ptr->mode |= PNG_HAVE_IDAT;
  164632. break;
  164633. }
  164634. #if defined(PNG_READ_bKGD_SUPPORTED)
  164635. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164636. png_handle_bKGD(png_ptr, info_ptr, length);
  164637. #endif
  164638. #if defined(PNG_READ_cHRM_SUPPORTED)
  164639. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164640. png_handle_cHRM(png_ptr, info_ptr, length);
  164641. #endif
  164642. #if defined(PNG_READ_gAMA_SUPPORTED)
  164643. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164644. png_handle_gAMA(png_ptr, info_ptr, length);
  164645. #endif
  164646. #if defined(PNG_READ_hIST_SUPPORTED)
  164647. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164648. png_handle_hIST(png_ptr, info_ptr, length);
  164649. #endif
  164650. #if defined(PNG_READ_oFFs_SUPPORTED)
  164651. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164652. png_handle_oFFs(png_ptr, info_ptr, length);
  164653. #endif
  164654. #if defined(PNG_READ_pCAL_SUPPORTED)
  164655. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164656. png_handle_pCAL(png_ptr, info_ptr, length);
  164657. #endif
  164658. #if defined(PNG_READ_sCAL_SUPPORTED)
  164659. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164660. png_handle_sCAL(png_ptr, info_ptr, length);
  164661. #endif
  164662. #if defined(PNG_READ_pHYs_SUPPORTED)
  164663. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164664. png_handle_pHYs(png_ptr, info_ptr, length);
  164665. #endif
  164666. #if defined(PNG_READ_sBIT_SUPPORTED)
  164667. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164668. png_handle_sBIT(png_ptr, info_ptr, length);
  164669. #endif
  164670. #if defined(PNG_READ_sRGB_SUPPORTED)
  164671. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164672. png_handle_sRGB(png_ptr, info_ptr, length);
  164673. #endif
  164674. #if defined(PNG_READ_iCCP_SUPPORTED)
  164675. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164676. png_handle_iCCP(png_ptr, info_ptr, length);
  164677. #endif
  164678. #if defined(PNG_READ_sPLT_SUPPORTED)
  164679. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164680. png_handle_sPLT(png_ptr, info_ptr, length);
  164681. #endif
  164682. #if defined(PNG_READ_tEXt_SUPPORTED)
  164683. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164684. png_handle_tEXt(png_ptr, info_ptr, length);
  164685. #endif
  164686. #if defined(PNG_READ_tIME_SUPPORTED)
  164687. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164688. png_handle_tIME(png_ptr, info_ptr, length);
  164689. #endif
  164690. #if defined(PNG_READ_tRNS_SUPPORTED)
  164691. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164692. png_handle_tRNS(png_ptr, info_ptr, length);
  164693. #endif
  164694. #if defined(PNG_READ_zTXt_SUPPORTED)
  164695. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164696. png_handle_zTXt(png_ptr, info_ptr, length);
  164697. #endif
  164698. #if defined(PNG_READ_iTXt_SUPPORTED)
  164699. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164700. png_handle_iTXt(png_ptr, info_ptr, length);
  164701. #endif
  164702. else
  164703. png_handle_unknown(png_ptr, info_ptr, length);
  164704. }
  164705. }
  164706. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164707. void PNGAPI
  164708. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164709. {
  164710. png_debug(1, "in png_read_update_info\n");
  164711. if(png_ptr == NULL) return;
  164712. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164713. png_read_start_row(png_ptr);
  164714. else
  164715. png_warning(png_ptr,
  164716. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164717. png_read_transform_info(png_ptr, info_ptr);
  164718. }
  164719. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164720. void PNGAPI
  164721. png_start_read_image(png_structp png_ptr)
  164722. {
  164723. png_debug(1, "in png_start_read_image\n");
  164724. if(png_ptr == NULL) return;
  164725. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164726. png_read_start_row(png_ptr);
  164727. }
  164728. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164729. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164730. void PNGAPI
  164731. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164732. {
  164733. #ifdef PNG_USE_LOCAL_ARRAYS
  164734. PNG_CONST PNG_IDAT;
  164735. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164736. 0xff};
  164737. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164738. #endif
  164739. int ret;
  164740. if(png_ptr == NULL) return;
  164741. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164742. png_ptr->row_number, png_ptr->pass);
  164743. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164744. png_read_start_row(png_ptr);
  164745. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164746. {
  164747. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164748. if (png_ptr->transformations & PNG_INVERT_MONO)
  164749. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164750. #endif
  164751. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164752. if (png_ptr->transformations & PNG_FILLER)
  164753. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164754. #endif
  164755. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164756. if (png_ptr->transformations & PNG_PACKSWAP)
  164757. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164758. #endif
  164759. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164760. if (png_ptr->transformations & PNG_PACK)
  164761. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164762. #endif
  164763. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164764. if (png_ptr->transformations & PNG_SHIFT)
  164765. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164766. #endif
  164767. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164768. if (png_ptr->transformations & PNG_BGR)
  164769. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164770. #endif
  164771. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164772. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164773. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164774. #endif
  164775. }
  164776. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164777. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164778. {
  164779. switch (png_ptr->pass)
  164780. {
  164781. case 0:
  164782. if (png_ptr->row_number & 0x07)
  164783. {
  164784. if (dsp_row != NULL)
  164785. png_combine_row(png_ptr, dsp_row,
  164786. png_pass_dsp_mask[png_ptr->pass]);
  164787. png_read_finish_row(png_ptr);
  164788. return;
  164789. }
  164790. break;
  164791. case 1:
  164792. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164793. {
  164794. if (dsp_row != NULL)
  164795. png_combine_row(png_ptr, dsp_row,
  164796. png_pass_dsp_mask[png_ptr->pass]);
  164797. png_read_finish_row(png_ptr);
  164798. return;
  164799. }
  164800. break;
  164801. case 2:
  164802. if ((png_ptr->row_number & 0x07) != 4)
  164803. {
  164804. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164805. png_combine_row(png_ptr, dsp_row,
  164806. png_pass_dsp_mask[png_ptr->pass]);
  164807. png_read_finish_row(png_ptr);
  164808. return;
  164809. }
  164810. break;
  164811. case 3:
  164812. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164813. {
  164814. if (dsp_row != NULL)
  164815. png_combine_row(png_ptr, dsp_row,
  164816. png_pass_dsp_mask[png_ptr->pass]);
  164817. png_read_finish_row(png_ptr);
  164818. return;
  164819. }
  164820. break;
  164821. case 4:
  164822. if ((png_ptr->row_number & 3) != 2)
  164823. {
  164824. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164825. png_combine_row(png_ptr, dsp_row,
  164826. png_pass_dsp_mask[png_ptr->pass]);
  164827. png_read_finish_row(png_ptr);
  164828. return;
  164829. }
  164830. break;
  164831. case 5:
  164832. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164833. {
  164834. if (dsp_row != NULL)
  164835. png_combine_row(png_ptr, dsp_row,
  164836. png_pass_dsp_mask[png_ptr->pass]);
  164837. png_read_finish_row(png_ptr);
  164838. return;
  164839. }
  164840. break;
  164841. case 6:
  164842. if (!(png_ptr->row_number & 1))
  164843. {
  164844. png_read_finish_row(png_ptr);
  164845. return;
  164846. }
  164847. break;
  164848. }
  164849. }
  164850. #endif
  164851. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164852. png_error(png_ptr, "Invalid attempt to read row data");
  164853. png_ptr->zstream.next_out = png_ptr->row_buf;
  164854. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164855. do
  164856. {
  164857. if (!(png_ptr->zstream.avail_in))
  164858. {
  164859. while (!png_ptr->idat_size)
  164860. {
  164861. png_byte chunk_length[4];
  164862. png_crc_finish(png_ptr, 0);
  164863. png_read_data(png_ptr, chunk_length, 4);
  164864. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164865. png_reset_crc(png_ptr);
  164866. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164867. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164868. png_error(png_ptr, "Not enough image data");
  164869. }
  164870. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164871. png_ptr->zstream.next_in = png_ptr->zbuf;
  164872. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164873. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164874. png_crc_read(png_ptr, png_ptr->zbuf,
  164875. (png_size_t)png_ptr->zstream.avail_in);
  164876. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164877. }
  164878. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164879. if (ret == Z_STREAM_END)
  164880. {
  164881. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164882. png_ptr->idat_size)
  164883. png_error(png_ptr, "Extra compressed data");
  164884. png_ptr->mode |= PNG_AFTER_IDAT;
  164885. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164886. break;
  164887. }
  164888. if (ret != Z_OK)
  164889. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164890. "Decompression error");
  164891. } while (png_ptr->zstream.avail_out);
  164892. png_ptr->row_info.color_type = png_ptr->color_type;
  164893. png_ptr->row_info.width = png_ptr->iwidth;
  164894. png_ptr->row_info.channels = png_ptr->channels;
  164895. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164896. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164897. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164898. png_ptr->row_info.width);
  164899. if(png_ptr->row_buf[0])
  164900. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164901. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164902. (int)(png_ptr->row_buf[0]));
  164903. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164904. png_ptr->rowbytes + 1);
  164905. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164906. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164907. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164908. {
  164909. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164910. }
  164911. #endif
  164912. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164913. png_do_read_transformations(png_ptr);
  164914. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164915. if (png_ptr->interlaced &&
  164916. (png_ptr->transformations & PNG_INTERLACE))
  164917. {
  164918. if (png_ptr->pass < 6)
  164919. png_do_read_interlace(png_ptr);
  164920. if (dsp_row != NULL)
  164921. png_combine_row(png_ptr, dsp_row,
  164922. png_pass_dsp_mask[png_ptr->pass]);
  164923. if (row != NULL)
  164924. png_combine_row(png_ptr, row,
  164925. png_pass_mask[png_ptr->pass]);
  164926. }
  164927. else
  164928. #endif
  164929. {
  164930. if (row != NULL)
  164931. png_combine_row(png_ptr, row, 0xff);
  164932. if (dsp_row != NULL)
  164933. png_combine_row(png_ptr, dsp_row, 0xff);
  164934. }
  164935. png_read_finish_row(png_ptr);
  164936. if (png_ptr->read_row_fn != NULL)
  164937. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  164938. }
  164939. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164940. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164941. void PNGAPI
  164942. png_read_rows(png_structp png_ptr, png_bytepp row,
  164943. png_bytepp display_row, png_uint_32 num_rows)
  164944. {
  164945. png_uint_32 i;
  164946. png_bytepp rp;
  164947. png_bytepp dp;
  164948. png_debug(1, "in png_read_rows\n");
  164949. if(png_ptr == NULL) return;
  164950. rp = row;
  164951. dp = display_row;
  164952. if (rp != NULL && dp != NULL)
  164953. for (i = 0; i < num_rows; i++)
  164954. {
  164955. png_bytep rptr = *rp++;
  164956. png_bytep dptr = *dp++;
  164957. png_read_row(png_ptr, rptr, dptr);
  164958. }
  164959. else if(rp != NULL)
  164960. for (i = 0; i < num_rows; i++)
  164961. {
  164962. png_bytep rptr = *rp;
  164963. png_read_row(png_ptr, rptr, png_bytep_NULL);
  164964. rp++;
  164965. }
  164966. else if(dp != NULL)
  164967. for (i = 0; i < num_rows; i++)
  164968. {
  164969. png_bytep dptr = *dp;
  164970. png_read_row(png_ptr, png_bytep_NULL, dptr);
  164971. dp++;
  164972. }
  164973. }
  164974. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164975. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164976. void PNGAPI
  164977. png_read_image(png_structp png_ptr, png_bytepp image)
  164978. {
  164979. png_uint_32 i,image_height;
  164980. int pass, j;
  164981. png_bytepp rp;
  164982. png_debug(1, "in png_read_image\n");
  164983. if(png_ptr == NULL) return;
  164984. #ifdef PNG_READ_INTERLACING_SUPPORTED
  164985. pass = png_set_interlace_handling(png_ptr);
  164986. #else
  164987. if (png_ptr->interlaced)
  164988. png_error(png_ptr,
  164989. "Cannot read interlaced image -- interlace handler disabled.");
  164990. pass = 1;
  164991. #endif
  164992. image_height=png_ptr->height;
  164993. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  164994. for (j = 0; j < pass; j++)
  164995. {
  164996. rp = image;
  164997. for (i = 0; i < image_height; i++)
  164998. {
  164999. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165000. rp++;
  165001. }
  165002. }
  165003. }
  165004. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165005. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165006. void PNGAPI
  165007. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165008. {
  165009. png_byte chunk_length[4];
  165010. png_uint_32 length;
  165011. png_debug(1, "in png_read_end\n");
  165012. if(png_ptr == NULL) return;
  165013. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165014. do
  165015. {
  165016. #ifdef PNG_USE_LOCAL_ARRAYS
  165017. PNG_CONST PNG_IHDR;
  165018. PNG_CONST PNG_IDAT;
  165019. PNG_CONST PNG_IEND;
  165020. PNG_CONST PNG_PLTE;
  165021. #if defined(PNG_READ_bKGD_SUPPORTED)
  165022. PNG_CONST PNG_bKGD;
  165023. #endif
  165024. #if defined(PNG_READ_cHRM_SUPPORTED)
  165025. PNG_CONST PNG_cHRM;
  165026. #endif
  165027. #if defined(PNG_READ_gAMA_SUPPORTED)
  165028. PNG_CONST PNG_gAMA;
  165029. #endif
  165030. #if defined(PNG_READ_hIST_SUPPORTED)
  165031. PNG_CONST PNG_hIST;
  165032. #endif
  165033. #if defined(PNG_READ_iCCP_SUPPORTED)
  165034. PNG_CONST PNG_iCCP;
  165035. #endif
  165036. #if defined(PNG_READ_iTXt_SUPPORTED)
  165037. PNG_CONST PNG_iTXt;
  165038. #endif
  165039. #if defined(PNG_READ_oFFs_SUPPORTED)
  165040. PNG_CONST PNG_oFFs;
  165041. #endif
  165042. #if defined(PNG_READ_pCAL_SUPPORTED)
  165043. PNG_CONST PNG_pCAL;
  165044. #endif
  165045. #if defined(PNG_READ_pHYs_SUPPORTED)
  165046. PNG_CONST PNG_pHYs;
  165047. #endif
  165048. #if defined(PNG_READ_sBIT_SUPPORTED)
  165049. PNG_CONST PNG_sBIT;
  165050. #endif
  165051. #if defined(PNG_READ_sCAL_SUPPORTED)
  165052. PNG_CONST PNG_sCAL;
  165053. #endif
  165054. #if defined(PNG_READ_sPLT_SUPPORTED)
  165055. PNG_CONST PNG_sPLT;
  165056. #endif
  165057. #if defined(PNG_READ_sRGB_SUPPORTED)
  165058. PNG_CONST PNG_sRGB;
  165059. #endif
  165060. #if defined(PNG_READ_tEXt_SUPPORTED)
  165061. PNG_CONST PNG_tEXt;
  165062. #endif
  165063. #if defined(PNG_READ_tIME_SUPPORTED)
  165064. PNG_CONST PNG_tIME;
  165065. #endif
  165066. #if defined(PNG_READ_tRNS_SUPPORTED)
  165067. PNG_CONST PNG_tRNS;
  165068. #endif
  165069. #if defined(PNG_READ_zTXt_SUPPORTED)
  165070. PNG_CONST PNG_zTXt;
  165071. #endif
  165072. #endif /* PNG_USE_LOCAL_ARRAYS */
  165073. png_read_data(png_ptr, chunk_length, 4);
  165074. length = png_get_uint_31(png_ptr,chunk_length);
  165075. png_reset_crc(png_ptr);
  165076. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165077. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165078. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165079. png_handle_IHDR(png_ptr, info_ptr, length);
  165080. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165081. png_handle_IEND(png_ptr, info_ptr, length);
  165082. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165083. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165084. {
  165085. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165086. {
  165087. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165088. png_error(png_ptr, "Too many IDAT's found");
  165089. }
  165090. png_handle_unknown(png_ptr, info_ptr, length);
  165091. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165092. png_ptr->mode |= PNG_HAVE_PLTE;
  165093. }
  165094. #endif
  165095. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165096. {
  165097. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165098. png_error(png_ptr, "Too many IDAT's found");
  165099. png_crc_finish(png_ptr, length);
  165100. }
  165101. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165102. png_handle_PLTE(png_ptr, info_ptr, length);
  165103. #if defined(PNG_READ_bKGD_SUPPORTED)
  165104. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165105. png_handle_bKGD(png_ptr, info_ptr, length);
  165106. #endif
  165107. #if defined(PNG_READ_cHRM_SUPPORTED)
  165108. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165109. png_handle_cHRM(png_ptr, info_ptr, length);
  165110. #endif
  165111. #if defined(PNG_READ_gAMA_SUPPORTED)
  165112. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165113. png_handle_gAMA(png_ptr, info_ptr, length);
  165114. #endif
  165115. #if defined(PNG_READ_hIST_SUPPORTED)
  165116. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165117. png_handle_hIST(png_ptr, info_ptr, length);
  165118. #endif
  165119. #if defined(PNG_READ_oFFs_SUPPORTED)
  165120. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165121. png_handle_oFFs(png_ptr, info_ptr, length);
  165122. #endif
  165123. #if defined(PNG_READ_pCAL_SUPPORTED)
  165124. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165125. png_handle_pCAL(png_ptr, info_ptr, length);
  165126. #endif
  165127. #if defined(PNG_READ_sCAL_SUPPORTED)
  165128. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165129. png_handle_sCAL(png_ptr, info_ptr, length);
  165130. #endif
  165131. #if defined(PNG_READ_pHYs_SUPPORTED)
  165132. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165133. png_handle_pHYs(png_ptr, info_ptr, length);
  165134. #endif
  165135. #if defined(PNG_READ_sBIT_SUPPORTED)
  165136. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165137. png_handle_sBIT(png_ptr, info_ptr, length);
  165138. #endif
  165139. #if defined(PNG_READ_sRGB_SUPPORTED)
  165140. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165141. png_handle_sRGB(png_ptr, info_ptr, length);
  165142. #endif
  165143. #if defined(PNG_READ_iCCP_SUPPORTED)
  165144. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165145. png_handle_iCCP(png_ptr, info_ptr, length);
  165146. #endif
  165147. #if defined(PNG_READ_sPLT_SUPPORTED)
  165148. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165149. png_handle_sPLT(png_ptr, info_ptr, length);
  165150. #endif
  165151. #if defined(PNG_READ_tEXt_SUPPORTED)
  165152. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165153. png_handle_tEXt(png_ptr, info_ptr, length);
  165154. #endif
  165155. #if defined(PNG_READ_tIME_SUPPORTED)
  165156. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165157. png_handle_tIME(png_ptr, info_ptr, length);
  165158. #endif
  165159. #if defined(PNG_READ_tRNS_SUPPORTED)
  165160. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165161. png_handle_tRNS(png_ptr, info_ptr, length);
  165162. #endif
  165163. #if defined(PNG_READ_zTXt_SUPPORTED)
  165164. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165165. png_handle_zTXt(png_ptr, info_ptr, length);
  165166. #endif
  165167. #if defined(PNG_READ_iTXt_SUPPORTED)
  165168. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165169. png_handle_iTXt(png_ptr, info_ptr, length);
  165170. #endif
  165171. else
  165172. png_handle_unknown(png_ptr, info_ptr, length);
  165173. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165174. }
  165175. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165176. void PNGAPI
  165177. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165178. png_infopp end_info_ptr_ptr)
  165179. {
  165180. png_structp png_ptr = NULL;
  165181. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165182. #ifdef PNG_USER_MEM_SUPPORTED
  165183. png_free_ptr free_fn;
  165184. png_voidp mem_ptr;
  165185. #endif
  165186. png_debug(1, "in png_destroy_read_struct\n");
  165187. if (png_ptr_ptr != NULL)
  165188. png_ptr = *png_ptr_ptr;
  165189. if (info_ptr_ptr != NULL)
  165190. info_ptr = *info_ptr_ptr;
  165191. if (end_info_ptr_ptr != NULL)
  165192. end_info_ptr = *end_info_ptr_ptr;
  165193. #ifdef PNG_USER_MEM_SUPPORTED
  165194. free_fn = png_ptr->free_fn;
  165195. mem_ptr = png_ptr->mem_ptr;
  165196. #endif
  165197. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165198. if (info_ptr != NULL)
  165199. {
  165200. #if defined(PNG_TEXT_SUPPORTED)
  165201. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165202. #endif
  165203. #ifdef PNG_USER_MEM_SUPPORTED
  165204. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165205. (png_voidp)mem_ptr);
  165206. #else
  165207. png_destroy_struct((png_voidp)info_ptr);
  165208. #endif
  165209. *info_ptr_ptr = NULL;
  165210. }
  165211. if (end_info_ptr != NULL)
  165212. {
  165213. #if defined(PNG_READ_TEXT_SUPPORTED)
  165214. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165215. #endif
  165216. #ifdef PNG_USER_MEM_SUPPORTED
  165217. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165218. (png_voidp)mem_ptr);
  165219. #else
  165220. png_destroy_struct((png_voidp)end_info_ptr);
  165221. #endif
  165222. *end_info_ptr_ptr = NULL;
  165223. }
  165224. if (png_ptr != NULL)
  165225. {
  165226. #ifdef PNG_USER_MEM_SUPPORTED
  165227. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165228. (png_voidp)mem_ptr);
  165229. #else
  165230. png_destroy_struct((png_voidp)png_ptr);
  165231. #endif
  165232. *png_ptr_ptr = NULL;
  165233. }
  165234. }
  165235. void /* PRIVATE */
  165236. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165237. {
  165238. #ifdef PNG_SETJMP_SUPPORTED
  165239. jmp_buf tmp_jmp;
  165240. #endif
  165241. png_error_ptr error_fn;
  165242. png_error_ptr warning_fn;
  165243. png_voidp error_ptr;
  165244. #ifdef PNG_USER_MEM_SUPPORTED
  165245. png_free_ptr free_fn;
  165246. #endif
  165247. png_debug(1, "in png_read_destroy\n");
  165248. if (info_ptr != NULL)
  165249. png_info_destroy(png_ptr, info_ptr);
  165250. if (end_info_ptr != NULL)
  165251. png_info_destroy(png_ptr, end_info_ptr);
  165252. png_free(png_ptr, png_ptr->zbuf);
  165253. png_free(png_ptr, png_ptr->big_row_buf);
  165254. png_free(png_ptr, png_ptr->prev_row);
  165255. #if defined(PNG_READ_DITHER_SUPPORTED)
  165256. png_free(png_ptr, png_ptr->palette_lookup);
  165257. png_free(png_ptr, png_ptr->dither_index);
  165258. #endif
  165259. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165260. png_free(png_ptr, png_ptr->gamma_table);
  165261. #endif
  165262. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165263. png_free(png_ptr, png_ptr->gamma_from_1);
  165264. png_free(png_ptr, png_ptr->gamma_to_1);
  165265. #endif
  165266. #ifdef PNG_FREE_ME_SUPPORTED
  165267. if (png_ptr->free_me & PNG_FREE_PLTE)
  165268. png_zfree(png_ptr, png_ptr->palette);
  165269. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165270. #else
  165271. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165272. png_zfree(png_ptr, png_ptr->palette);
  165273. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165274. #endif
  165275. #if defined(PNG_tRNS_SUPPORTED) || \
  165276. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165277. #ifdef PNG_FREE_ME_SUPPORTED
  165278. if (png_ptr->free_me & PNG_FREE_TRNS)
  165279. png_free(png_ptr, png_ptr->trans);
  165280. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165281. #else
  165282. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165283. png_free(png_ptr, png_ptr->trans);
  165284. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165285. #endif
  165286. #endif
  165287. #if defined(PNG_READ_hIST_SUPPORTED)
  165288. #ifdef PNG_FREE_ME_SUPPORTED
  165289. if (png_ptr->free_me & PNG_FREE_HIST)
  165290. png_free(png_ptr, png_ptr->hist);
  165291. png_ptr->free_me &= ~PNG_FREE_HIST;
  165292. #else
  165293. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165294. png_free(png_ptr, png_ptr->hist);
  165295. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165296. #endif
  165297. #endif
  165298. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165299. if (png_ptr->gamma_16_table != NULL)
  165300. {
  165301. int i;
  165302. int istop = (1 << (8 - png_ptr->gamma_shift));
  165303. for (i = 0; i < istop; i++)
  165304. {
  165305. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165306. }
  165307. png_free(png_ptr, png_ptr->gamma_16_table);
  165308. }
  165309. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165310. if (png_ptr->gamma_16_from_1 != NULL)
  165311. {
  165312. int i;
  165313. int istop = (1 << (8 - png_ptr->gamma_shift));
  165314. for (i = 0; i < istop; i++)
  165315. {
  165316. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165317. }
  165318. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165319. }
  165320. if (png_ptr->gamma_16_to_1 != NULL)
  165321. {
  165322. int i;
  165323. int istop = (1 << (8 - png_ptr->gamma_shift));
  165324. for (i = 0; i < istop; i++)
  165325. {
  165326. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165327. }
  165328. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165329. }
  165330. #endif
  165331. #endif
  165332. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165333. png_free(png_ptr, png_ptr->time_buffer);
  165334. #endif
  165335. inflateEnd(&png_ptr->zstream);
  165336. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165337. png_free(png_ptr, png_ptr->save_buffer);
  165338. #endif
  165339. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165340. #ifdef PNG_TEXT_SUPPORTED
  165341. png_free(png_ptr, png_ptr->current_text);
  165342. #endif /* PNG_TEXT_SUPPORTED */
  165343. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165344. #ifdef PNG_SETJMP_SUPPORTED
  165345. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165346. #endif
  165347. error_fn = png_ptr->error_fn;
  165348. warning_fn = png_ptr->warning_fn;
  165349. error_ptr = png_ptr->error_ptr;
  165350. #ifdef PNG_USER_MEM_SUPPORTED
  165351. free_fn = png_ptr->free_fn;
  165352. #endif
  165353. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165354. png_ptr->error_fn = error_fn;
  165355. png_ptr->warning_fn = warning_fn;
  165356. png_ptr->error_ptr = error_ptr;
  165357. #ifdef PNG_USER_MEM_SUPPORTED
  165358. png_ptr->free_fn = free_fn;
  165359. #endif
  165360. #ifdef PNG_SETJMP_SUPPORTED
  165361. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165362. #endif
  165363. }
  165364. void PNGAPI
  165365. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165366. {
  165367. if(png_ptr == NULL) return;
  165368. png_ptr->read_row_fn = read_row_fn;
  165369. }
  165370. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165371. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165372. void PNGAPI
  165373. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165374. int transforms,
  165375. voidp params)
  165376. {
  165377. int row;
  165378. if(png_ptr == NULL) return;
  165379. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165380. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165381. png_set_invert_alpha(png_ptr);
  165382. #endif
  165383. png_read_info(png_ptr, info_ptr);
  165384. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165385. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165386. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165387. if (transforms & PNG_TRANSFORM_STRIP_16)
  165388. png_set_strip_16(png_ptr);
  165389. #endif
  165390. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165391. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165392. png_set_strip_alpha(png_ptr);
  165393. #endif
  165394. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165395. if (transforms & PNG_TRANSFORM_PACKING)
  165396. png_set_packing(png_ptr);
  165397. #endif
  165398. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165399. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165400. png_set_packswap(png_ptr);
  165401. #endif
  165402. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165403. if (transforms & PNG_TRANSFORM_EXPAND)
  165404. if ((png_ptr->bit_depth < 8) ||
  165405. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165406. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165407. png_set_expand(png_ptr);
  165408. #endif
  165409. #if defined(PNG_READ_INVERT_SUPPORTED)
  165410. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165411. png_set_invert_mono(png_ptr);
  165412. #endif
  165413. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165414. if ((transforms & PNG_TRANSFORM_SHIFT)
  165415. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165416. {
  165417. png_color_8p sig_bit;
  165418. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165419. png_set_shift(png_ptr, sig_bit);
  165420. }
  165421. #endif
  165422. #if defined(PNG_READ_BGR_SUPPORTED)
  165423. if (transforms & PNG_TRANSFORM_BGR)
  165424. png_set_bgr(png_ptr);
  165425. #endif
  165426. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165427. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165428. png_set_swap_alpha(png_ptr);
  165429. #endif
  165430. #if defined(PNG_READ_SWAP_SUPPORTED)
  165431. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165432. png_set_swap(png_ptr);
  165433. #endif
  165434. png_read_update_info(png_ptr, info_ptr);
  165435. #ifdef PNG_FREE_ME_SUPPORTED
  165436. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165437. #endif
  165438. if(info_ptr->row_pointers == NULL)
  165439. {
  165440. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165441. info_ptr->height * png_sizeof(png_bytep));
  165442. #ifdef PNG_FREE_ME_SUPPORTED
  165443. info_ptr->free_me |= PNG_FREE_ROWS;
  165444. #endif
  165445. for (row = 0; row < (int)info_ptr->height; row++)
  165446. {
  165447. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165448. png_get_rowbytes(png_ptr, info_ptr));
  165449. }
  165450. }
  165451. png_read_image(png_ptr, info_ptr->row_pointers);
  165452. info_ptr->valid |= PNG_INFO_IDAT;
  165453. png_read_end(png_ptr, info_ptr);
  165454. transforms = transforms; /* quiet compiler warnings */
  165455. params = params;
  165456. }
  165457. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165458. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165459. #endif /* PNG_READ_SUPPORTED */
  165460. /*** End of inlined file: pngread.c ***/
  165461. /*** Start of inlined file: pngpread.c ***/
  165462. #define PNG_INTERNAL
  165463. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165464. #define PNG_READ_SIG_MODE 0
  165465. #define PNG_READ_CHUNK_MODE 1
  165466. #define PNG_READ_IDAT_MODE 2
  165467. #define PNG_SKIP_MODE 3
  165468. #define PNG_READ_tEXt_MODE 4
  165469. #define PNG_READ_zTXt_MODE 5
  165470. #define PNG_READ_DONE_MODE 6
  165471. #define PNG_READ_iTXt_MODE 7
  165472. #define PNG_ERROR_MODE 8
  165473. void PNGAPI
  165474. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165475. png_bytep buffer, png_size_t buffer_size)
  165476. {
  165477. if(png_ptr == NULL) return;
  165478. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165479. while (png_ptr->buffer_size)
  165480. {
  165481. png_process_some_data(png_ptr, info_ptr);
  165482. }
  165483. }
  165484. void /* PRIVATE */
  165485. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165486. {
  165487. if(png_ptr == NULL) return;
  165488. switch (png_ptr->process_mode)
  165489. {
  165490. case PNG_READ_SIG_MODE:
  165491. {
  165492. png_push_read_sig(png_ptr, info_ptr);
  165493. break;
  165494. }
  165495. case PNG_READ_CHUNK_MODE:
  165496. {
  165497. png_push_read_chunk(png_ptr, info_ptr);
  165498. break;
  165499. }
  165500. case PNG_READ_IDAT_MODE:
  165501. {
  165502. png_push_read_IDAT(png_ptr);
  165503. break;
  165504. }
  165505. #if defined(PNG_READ_tEXt_SUPPORTED)
  165506. case PNG_READ_tEXt_MODE:
  165507. {
  165508. png_push_read_tEXt(png_ptr, info_ptr);
  165509. break;
  165510. }
  165511. #endif
  165512. #if defined(PNG_READ_zTXt_SUPPORTED)
  165513. case PNG_READ_zTXt_MODE:
  165514. {
  165515. png_push_read_zTXt(png_ptr, info_ptr);
  165516. break;
  165517. }
  165518. #endif
  165519. #if defined(PNG_READ_iTXt_SUPPORTED)
  165520. case PNG_READ_iTXt_MODE:
  165521. {
  165522. png_push_read_iTXt(png_ptr, info_ptr);
  165523. break;
  165524. }
  165525. #endif
  165526. case PNG_SKIP_MODE:
  165527. {
  165528. png_push_crc_finish(png_ptr);
  165529. break;
  165530. }
  165531. default:
  165532. {
  165533. png_ptr->buffer_size = 0;
  165534. break;
  165535. }
  165536. }
  165537. }
  165538. void /* PRIVATE */
  165539. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165540. {
  165541. png_size_t num_checked = png_ptr->sig_bytes,
  165542. num_to_check = 8 - num_checked;
  165543. if (png_ptr->buffer_size < num_to_check)
  165544. {
  165545. num_to_check = png_ptr->buffer_size;
  165546. }
  165547. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165548. num_to_check);
  165549. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165550. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165551. {
  165552. if (num_checked < 4 &&
  165553. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165554. png_error(png_ptr, "Not a PNG file");
  165555. else
  165556. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165557. }
  165558. else
  165559. {
  165560. if (png_ptr->sig_bytes >= 8)
  165561. {
  165562. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165563. }
  165564. }
  165565. }
  165566. void /* PRIVATE */
  165567. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165568. {
  165569. #ifdef PNG_USE_LOCAL_ARRAYS
  165570. PNG_CONST PNG_IHDR;
  165571. PNG_CONST PNG_IDAT;
  165572. PNG_CONST PNG_IEND;
  165573. PNG_CONST PNG_PLTE;
  165574. #if defined(PNG_READ_bKGD_SUPPORTED)
  165575. PNG_CONST PNG_bKGD;
  165576. #endif
  165577. #if defined(PNG_READ_cHRM_SUPPORTED)
  165578. PNG_CONST PNG_cHRM;
  165579. #endif
  165580. #if defined(PNG_READ_gAMA_SUPPORTED)
  165581. PNG_CONST PNG_gAMA;
  165582. #endif
  165583. #if defined(PNG_READ_hIST_SUPPORTED)
  165584. PNG_CONST PNG_hIST;
  165585. #endif
  165586. #if defined(PNG_READ_iCCP_SUPPORTED)
  165587. PNG_CONST PNG_iCCP;
  165588. #endif
  165589. #if defined(PNG_READ_iTXt_SUPPORTED)
  165590. PNG_CONST PNG_iTXt;
  165591. #endif
  165592. #if defined(PNG_READ_oFFs_SUPPORTED)
  165593. PNG_CONST PNG_oFFs;
  165594. #endif
  165595. #if defined(PNG_READ_pCAL_SUPPORTED)
  165596. PNG_CONST PNG_pCAL;
  165597. #endif
  165598. #if defined(PNG_READ_pHYs_SUPPORTED)
  165599. PNG_CONST PNG_pHYs;
  165600. #endif
  165601. #if defined(PNG_READ_sBIT_SUPPORTED)
  165602. PNG_CONST PNG_sBIT;
  165603. #endif
  165604. #if defined(PNG_READ_sCAL_SUPPORTED)
  165605. PNG_CONST PNG_sCAL;
  165606. #endif
  165607. #if defined(PNG_READ_sRGB_SUPPORTED)
  165608. PNG_CONST PNG_sRGB;
  165609. #endif
  165610. #if defined(PNG_READ_sPLT_SUPPORTED)
  165611. PNG_CONST PNG_sPLT;
  165612. #endif
  165613. #if defined(PNG_READ_tEXt_SUPPORTED)
  165614. PNG_CONST PNG_tEXt;
  165615. #endif
  165616. #if defined(PNG_READ_tIME_SUPPORTED)
  165617. PNG_CONST PNG_tIME;
  165618. #endif
  165619. #if defined(PNG_READ_tRNS_SUPPORTED)
  165620. PNG_CONST PNG_tRNS;
  165621. #endif
  165622. #if defined(PNG_READ_zTXt_SUPPORTED)
  165623. PNG_CONST PNG_zTXt;
  165624. #endif
  165625. #endif /* PNG_USE_LOCAL_ARRAYS */
  165626. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165627. {
  165628. png_byte chunk_length[4];
  165629. if (png_ptr->buffer_size < 8)
  165630. {
  165631. png_push_save_buffer(png_ptr);
  165632. return;
  165633. }
  165634. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165635. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165636. png_reset_crc(png_ptr);
  165637. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165638. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165639. }
  165640. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165641. if(png_ptr->mode & PNG_AFTER_IDAT)
  165642. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165643. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165644. {
  165645. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165646. {
  165647. png_push_save_buffer(png_ptr);
  165648. return;
  165649. }
  165650. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165651. }
  165652. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165653. {
  165654. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165655. {
  165656. png_push_save_buffer(png_ptr);
  165657. return;
  165658. }
  165659. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165660. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165661. png_push_have_end(png_ptr, info_ptr);
  165662. }
  165663. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165664. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165665. {
  165666. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165667. {
  165668. png_push_save_buffer(png_ptr);
  165669. return;
  165670. }
  165671. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165672. png_ptr->mode |= PNG_HAVE_IDAT;
  165673. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165674. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165675. png_ptr->mode |= PNG_HAVE_PLTE;
  165676. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165677. {
  165678. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165679. png_error(png_ptr, "Missing IHDR before IDAT");
  165680. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165681. !(png_ptr->mode & PNG_HAVE_PLTE))
  165682. png_error(png_ptr, "Missing PLTE before IDAT");
  165683. }
  165684. }
  165685. #endif
  165686. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165687. {
  165688. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165689. {
  165690. png_push_save_buffer(png_ptr);
  165691. return;
  165692. }
  165693. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165694. }
  165695. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165696. {
  165697. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165698. png_error(png_ptr, "Missing IHDR before IDAT");
  165699. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165700. !(png_ptr->mode & PNG_HAVE_PLTE))
  165701. png_error(png_ptr, "Missing PLTE before IDAT");
  165702. if (png_ptr->mode & PNG_HAVE_IDAT)
  165703. {
  165704. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165705. if (png_ptr->push_length == 0)
  165706. return;
  165707. if (png_ptr->mode & PNG_AFTER_IDAT)
  165708. png_error(png_ptr, "Too many IDAT's found");
  165709. }
  165710. png_ptr->idat_size = png_ptr->push_length;
  165711. png_ptr->mode |= PNG_HAVE_IDAT;
  165712. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165713. png_push_have_info(png_ptr, info_ptr);
  165714. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165715. png_ptr->zstream.next_out = png_ptr->row_buf;
  165716. return;
  165717. }
  165718. #if defined(PNG_READ_gAMA_SUPPORTED)
  165719. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165720. {
  165721. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165722. {
  165723. png_push_save_buffer(png_ptr);
  165724. return;
  165725. }
  165726. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165727. }
  165728. #endif
  165729. #if defined(PNG_READ_sBIT_SUPPORTED)
  165730. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165731. {
  165732. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165733. {
  165734. png_push_save_buffer(png_ptr);
  165735. return;
  165736. }
  165737. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165738. }
  165739. #endif
  165740. #if defined(PNG_READ_cHRM_SUPPORTED)
  165741. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165742. {
  165743. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165744. {
  165745. png_push_save_buffer(png_ptr);
  165746. return;
  165747. }
  165748. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165749. }
  165750. #endif
  165751. #if defined(PNG_READ_sRGB_SUPPORTED)
  165752. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165753. {
  165754. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165755. {
  165756. png_push_save_buffer(png_ptr);
  165757. return;
  165758. }
  165759. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165760. }
  165761. #endif
  165762. #if defined(PNG_READ_iCCP_SUPPORTED)
  165763. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165764. {
  165765. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165766. {
  165767. png_push_save_buffer(png_ptr);
  165768. return;
  165769. }
  165770. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165771. }
  165772. #endif
  165773. #if defined(PNG_READ_sPLT_SUPPORTED)
  165774. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165775. {
  165776. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165777. {
  165778. png_push_save_buffer(png_ptr);
  165779. return;
  165780. }
  165781. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165782. }
  165783. #endif
  165784. #if defined(PNG_READ_tRNS_SUPPORTED)
  165785. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165786. {
  165787. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165788. {
  165789. png_push_save_buffer(png_ptr);
  165790. return;
  165791. }
  165792. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165793. }
  165794. #endif
  165795. #if defined(PNG_READ_bKGD_SUPPORTED)
  165796. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165797. {
  165798. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165799. {
  165800. png_push_save_buffer(png_ptr);
  165801. return;
  165802. }
  165803. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165804. }
  165805. #endif
  165806. #if defined(PNG_READ_hIST_SUPPORTED)
  165807. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165808. {
  165809. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165810. {
  165811. png_push_save_buffer(png_ptr);
  165812. return;
  165813. }
  165814. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165815. }
  165816. #endif
  165817. #if defined(PNG_READ_pHYs_SUPPORTED)
  165818. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165819. {
  165820. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165821. {
  165822. png_push_save_buffer(png_ptr);
  165823. return;
  165824. }
  165825. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165826. }
  165827. #endif
  165828. #if defined(PNG_READ_oFFs_SUPPORTED)
  165829. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165830. {
  165831. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165832. {
  165833. png_push_save_buffer(png_ptr);
  165834. return;
  165835. }
  165836. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165837. }
  165838. #endif
  165839. #if defined(PNG_READ_pCAL_SUPPORTED)
  165840. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165841. {
  165842. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165843. {
  165844. png_push_save_buffer(png_ptr);
  165845. return;
  165846. }
  165847. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165848. }
  165849. #endif
  165850. #if defined(PNG_READ_sCAL_SUPPORTED)
  165851. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165852. {
  165853. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165854. {
  165855. png_push_save_buffer(png_ptr);
  165856. return;
  165857. }
  165858. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165859. }
  165860. #endif
  165861. #if defined(PNG_READ_tIME_SUPPORTED)
  165862. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165863. {
  165864. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165865. {
  165866. png_push_save_buffer(png_ptr);
  165867. return;
  165868. }
  165869. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165870. }
  165871. #endif
  165872. #if defined(PNG_READ_tEXt_SUPPORTED)
  165873. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165874. {
  165875. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165876. {
  165877. png_push_save_buffer(png_ptr);
  165878. return;
  165879. }
  165880. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165881. }
  165882. #endif
  165883. #if defined(PNG_READ_zTXt_SUPPORTED)
  165884. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165885. {
  165886. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165887. {
  165888. png_push_save_buffer(png_ptr);
  165889. return;
  165890. }
  165891. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165892. }
  165893. #endif
  165894. #if defined(PNG_READ_iTXt_SUPPORTED)
  165895. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165896. {
  165897. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165898. {
  165899. png_push_save_buffer(png_ptr);
  165900. return;
  165901. }
  165902. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165903. }
  165904. #endif
  165905. else
  165906. {
  165907. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165908. {
  165909. png_push_save_buffer(png_ptr);
  165910. return;
  165911. }
  165912. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165913. }
  165914. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165915. }
  165916. void /* PRIVATE */
  165917. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165918. {
  165919. png_ptr->process_mode = PNG_SKIP_MODE;
  165920. png_ptr->skip_length = skip;
  165921. }
  165922. void /* PRIVATE */
  165923. png_push_crc_finish(png_structp png_ptr)
  165924. {
  165925. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  165926. {
  165927. png_size_t save_size;
  165928. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  165929. save_size = (png_size_t)png_ptr->skip_length;
  165930. else
  165931. save_size = png_ptr->save_buffer_size;
  165932. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165933. png_ptr->skip_length -= save_size;
  165934. png_ptr->buffer_size -= save_size;
  165935. png_ptr->save_buffer_size -= save_size;
  165936. png_ptr->save_buffer_ptr += save_size;
  165937. }
  165938. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  165939. {
  165940. png_size_t save_size;
  165941. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  165942. save_size = (png_size_t)png_ptr->skip_length;
  165943. else
  165944. save_size = png_ptr->current_buffer_size;
  165945. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165946. png_ptr->skip_length -= save_size;
  165947. png_ptr->buffer_size -= save_size;
  165948. png_ptr->current_buffer_size -= save_size;
  165949. png_ptr->current_buffer_ptr += save_size;
  165950. }
  165951. if (!png_ptr->skip_length)
  165952. {
  165953. if (png_ptr->buffer_size < 4)
  165954. {
  165955. png_push_save_buffer(png_ptr);
  165956. return;
  165957. }
  165958. png_crc_finish(png_ptr, 0);
  165959. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165960. }
  165961. }
  165962. void PNGAPI
  165963. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  165964. {
  165965. png_bytep ptr;
  165966. if(png_ptr == NULL) return;
  165967. ptr = buffer;
  165968. if (png_ptr->save_buffer_size)
  165969. {
  165970. png_size_t save_size;
  165971. if (length < png_ptr->save_buffer_size)
  165972. save_size = length;
  165973. else
  165974. save_size = png_ptr->save_buffer_size;
  165975. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  165976. length -= save_size;
  165977. ptr += save_size;
  165978. png_ptr->buffer_size -= save_size;
  165979. png_ptr->save_buffer_size -= save_size;
  165980. png_ptr->save_buffer_ptr += save_size;
  165981. }
  165982. if (length && png_ptr->current_buffer_size)
  165983. {
  165984. png_size_t save_size;
  165985. if (length < png_ptr->current_buffer_size)
  165986. save_size = length;
  165987. else
  165988. save_size = png_ptr->current_buffer_size;
  165989. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  165990. png_ptr->buffer_size -= save_size;
  165991. png_ptr->current_buffer_size -= save_size;
  165992. png_ptr->current_buffer_ptr += save_size;
  165993. }
  165994. }
  165995. void /* PRIVATE */
  165996. png_push_save_buffer(png_structp png_ptr)
  165997. {
  165998. if (png_ptr->save_buffer_size)
  165999. {
  166000. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166001. {
  166002. png_size_t i,istop;
  166003. png_bytep sp;
  166004. png_bytep dp;
  166005. istop = png_ptr->save_buffer_size;
  166006. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166007. i < istop; i++, sp++, dp++)
  166008. {
  166009. *dp = *sp;
  166010. }
  166011. }
  166012. }
  166013. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166014. png_ptr->save_buffer_max)
  166015. {
  166016. png_size_t new_max;
  166017. png_bytep old_buffer;
  166018. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166019. (png_ptr->current_buffer_size + 256))
  166020. {
  166021. png_error(png_ptr, "Potential overflow of save_buffer");
  166022. }
  166023. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166024. old_buffer = png_ptr->save_buffer;
  166025. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166026. (png_uint_32)new_max);
  166027. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166028. png_free(png_ptr, old_buffer);
  166029. png_ptr->save_buffer_max = new_max;
  166030. }
  166031. if (png_ptr->current_buffer_size)
  166032. {
  166033. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166034. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166035. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166036. png_ptr->current_buffer_size = 0;
  166037. }
  166038. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166039. png_ptr->buffer_size = 0;
  166040. }
  166041. void /* PRIVATE */
  166042. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166043. png_size_t buffer_length)
  166044. {
  166045. png_ptr->current_buffer = buffer;
  166046. png_ptr->current_buffer_size = buffer_length;
  166047. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166048. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166049. }
  166050. void /* PRIVATE */
  166051. png_push_read_IDAT(png_structp png_ptr)
  166052. {
  166053. #ifdef PNG_USE_LOCAL_ARRAYS
  166054. PNG_CONST PNG_IDAT;
  166055. #endif
  166056. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166057. {
  166058. png_byte chunk_length[4];
  166059. if (png_ptr->buffer_size < 8)
  166060. {
  166061. png_push_save_buffer(png_ptr);
  166062. return;
  166063. }
  166064. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166065. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166066. png_reset_crc(png_ptr);
  166067. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166068. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166069. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166070. {
  166071. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166072. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166073. png_error(png_ptr, "Not enough compressed data");
  166074. return;
  166075. }
  166076. png_ptr->idat_size = png_ptr->push_length;
  166077. }
  166078. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166079. {
  166080. png_size_t save_size;
  166081. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166082. {
  166083. save_size = (png_size_t)png_ptr->idat_size;
  166084. if((png_uint_32)save_size != png_ptr->idat_size)
  166085. png_error(png_ptr, "save_size overflowed in pngpread");
  166086. }
  166087. else
  166088. save_size = png_ptr->save_buffer_size;
  166089. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166090. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166091. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166092. png_ptr->idat_size -= save_size;
  166093. png_ptr->buffer_size -= save_size;
  166094. png_ptr->save_buffer_size -= save_size;
  166095. png_ptr->save_buffer_ptr += save_size;
  166096. }
  166097. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166098. {
  166099. png_size_t save_size;
  166100. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166101. {
  166102. save_size = (png_size_t)png_ptr->idat_size;
  166103. if((png_uint_32)save_size != png_ptr->idat_size)
  166104. png_error(png_ptr, "save_size overflowed in pngpread");
  166105. }
  166106. else
  166107. save_size = png_ptr->current_buffer_size;
  166108. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166109. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166110. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166111. png_ptr->idat_size -= save_size;
  166112. png_ptr->buffer_size -= save_size;
  166113. png_ptr->current_buffer_size -= save_size;
  166114. png_ptr->current_buffer_ptr += save_size;
  166115. }
  166116. if (!png_ptr->idat_size)
  166117. {
  166118. if (png_ptr->buffer_size < 4)
  166119. {
  166120. png_push_save_buffer(png_ptr);
  166121. return;
  166122. }
  166123. png_crc_finish(png_ptr, 0);
  166124. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166125. png_ptr->mode |= PNG_AFTER_IDAT;
  166126. }
  166127. }
  166128. void /* PRIVATE */
  166129. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166130. png_size_t buffer_length)
  166131. {
  166132. int ret;
  166133. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166134. png_error(png_ptr, "Extra compression data");
  166135. png_ptr->zstream.next_in = buffer;
  166136. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166137. for(;;)
  166138. {
  166139. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166140. if (ret != Z_OK)
  166141. {
  166142. if (ret == Z_STREAM_END)
  166143. {
  166144. if (png_ptr->zstream.avail_in)
  166145. png_error(png_ptr, "Extra compressed data");
  166146. if (!(png_ptr->zstream.avail_out))
  166147. {
  166148. png_push_process_row(png_ptr);
  166149. }
  166150. png_ptr->mode |= PNG_AFTER_IDAT;
  166151. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166152. break;
  166153. }
  166154. else if (ret == Z_BUF_ERROR)
  166155. break;
  166156. else
  166157. png_error(png_ptr, "Decompression Error");
  166158. }
  166159. if (!(png_ptr->zstream.avail_out))
  166160. {
  166161. if ((
  166162. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166163. png_ptr->interlaced && png_ptr->pass > 6) ||
  166164. (!png_ptr->interlaced &&
  166165. #endif
  166166. png_ptr->row_number == png_ptr->num_rows))
  166167. {
  166168. if (png_ptr->zstream.avail_in)
  166169. {
  166170. png_warning(png_ptr, "Too much data in IDAT chunks");
  166171. }
  166172. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166173. break;
  166174. }
  166175. png_push_process_row(png_ptr);
  166176. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166177. png_ptr->zstream.next_out = png_ptr->row_buf;
  166178. }
  166179. else
  166180. break;
  166181. }
  166182. }
  166183. void /* PRIVATE */
  166184. png_push_process_row(png_structp png_ptr)
  166185. {
  166186. png_ptr->row_info.color_type = png_ptr->color_type;
  166187. png_ptr->row_info.width = png_ptr->iwidth;
  166188. png_ptr->row_info.channels = png_ptr->channels;
  166189. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166190. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166191. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166192. png_ptr->row_info.width);
  166193. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166194. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166195. (int)(png_ptr->row_buf[0]));
  166196. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166197. png_ptr->rowbytes + 1);
  166198. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166199. png_do_read_transformations(png_ptr);
  166200. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166201. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166202. {
  166203. if (png_ptr->pass < 6)
  166204. png_do_read_interlace(png_ptr);
  166205. switch (png_ptr->pass)
  166206. {
  166207. case 0:
  166208. {
  166209. int i;
  166210. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166211. {
  166212. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166213. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166214. }
  166215. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166216. {
  166217. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166218. {
  166219. png_push_have_row(png_ptr, png_bytep_NULL);
  166220. png_read_push_finish_row(png_ptr);
  166221. }
  166222. }
  166223. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166224. {
  166225. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166226. {
  166227. png_push_have_row(png_ptr, png_bytep_NULL);
  166228. png_read_push_finish_row(png_ptr);
  166229. }
  166230. }
  166231. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166232. {
  166233. png_push_have_row(png_ptr, png_bytep_NULL);
  166234. png_read_push_finish_row(png_ptr);
  166235. }
  166236. break;
  166237. }
  166238. case 1:
  166239. {
  166240. int i;
  166241. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166242. {
  166243. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166244. png_read_push_finish_row(png_ptr);
  166245. }
  166246. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166247. {
  166248. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166249. {
  166250. png_push_have_row(png_ptr, png_bytep_NULL);
  166251. png_read_push_finish_row(png_ptr);
  166252. }
  166253. }
  166254. break;
  166255. }
  166256. case 2:
  166257. {
  166258. int i;
  166259. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166260. {
  166261. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166262. png_read_push_finish_row(png_ptr);
  166263. }
  166264. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166265. {
  166266. png_push_have_row(png_ptr, png_bytep_NULL);
  166267. png_read_push_finish_row(png_ptr);
  166268. }
  166269. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166270. {
  166271. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166272. {
  166273. png_push_have_row(png_ptr, png_bytep_NULL);
  166274. png_read_push_finish_row(png_ptr);
  166275. }
  166276. }
  166277. break;
  166278. }
  166279. case 3:
  166280. {
  166281. int i;
  166282. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166283. {
  166284. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166285. png_read_push_finish_row(png_ptr);
  166286. }
  166287. if (png_ptr->pass == 4) /* skip top two generated rows */
  166288. {
  166289. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166290. {
  166291. png_push_have_row(png_ptr, png_bytep_NULL);
  166292. png_read_push_finish_row(png_ptr);
  166293. }
  166294. }
  166295. break;
  166296. }
  166297. case 4:
  166298. {
  166299. int i;
  166300. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166301. {
  166302. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166303. png_read_push_finish_row(png_ptr);
  166304. }
  166305. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166306. {
  166307. png_push_have_row(png_ptr, png_bytep_NULL);
  166308. png_read_push_finish_row(png_ptr);
  166309. }
  166310. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166311. {
  166312. png_push_have_row(png_ptr, png_bytep_NULL);
  166313. png_read_push_finish_row(png_ptr);
  166314. }
  166315. break;
  166316. }
  166317. case 5:
  166318. {
  166319. int i;
  166320. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166321. {
  166322. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166323. png_read_push_finish_row(png_ptr);
  166324. }
  166325. if (png_ptr->pass == 6) /* skip top generated row */
  166326. {
  166327. png_push_have_row(png_ptr, png_bytep_NULL);
  166328. png_read_push_finish_row(png_ptr);
  166329. }
  166330. break;
  166331. }
  166332. case 6:
  166333. {
  166334. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166335. png_read_push_finish_row(png_ptr);
  166336. if (png_ptr->pass != 6)
  166337. break;
  166338. png_push_have_row(png_ptr, png_bytep_NULL);
  166339. png_read_push_finish_row(png_ptr);
  166340. }
  166341. }
  166342. }
  166343. else
  166344. #endif
  166345. {
  166346. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166347. png_read_push_finish_row(png_ptr);
  166348. }
  166349. }
  166350. void /* PRIVATE */
  166351. png_read_push_finish_row(png_structp png_ptr)
  166352. {
  166353. #ifdef PNG_USE_LOCAL_ARRAYS
  166354. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166355. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166356. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166357. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166358. #endif
  166359. png_ptr->row_number++;
  166360. if (png_ptr->row_number < png_ptr->num_rows)
  166361. return;
  166362. if (png_ptr->interlaced)
  166363. {
  166364. png_ptr->row_number = 0;
  166365. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166366. png_ptr->rowbytes + 1);
  166367. do
  166368. {
  166369. png_ptr->pass++;
  166370. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166371. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166372. (png_ptr->pass == 5 && png_ptr->width < 2))
  166373. png_ptr->pass++;
  166374. if (png_ptr->pass > 7)
  166375. png_ptr->pass--;
  166376. if (png_ptr->pass >= 7)
  166377. break;
  166378. png_ptr->iwidth = (png_ptr->width +
  166379. png_pass_inc[png_ptr->pass] - 1 -
  166380. png_pass_start[png_ptr->pass]) /
  166381. png_pass_inc[png_ptr->pass];
  166382. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166383. png_ptr->iwidth) + 1;
  166384. if (png_ptr->transformations & PNG_INTERLACE)
  166385. break;
  166386. png_ptr->num_rows = (png_ptr->height +
  166387. png_pass_yinc[png_ptr->pass] - 1 -
  166388. png_pass_ystart[png_ptr->pass]) /
  166389. png_pass_yinc[png_ptr->pass];
  166390. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166391. }
  166392. }
  166393. #if defined(PNG_READ_tEXt_SUPPORTED)
  166394. void /* PRIVATE */
  166395. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166396. length)
  166397. {
  166398. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166399. {
  166400. png_error(png_ptr, "Out of place tEXt");
  166401. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166402. }
  166403. #ifdef PNG_MAX_MALLOC_64K
  166404. png_ptr->skip_length = 0; /* This may not be necessary */
  166405. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166406. {
  166407. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166408. png_ptr->skip_length = length - (png_uint_32)65535L;
  166409. length = (png_uint_32)65535L;
  166410. }
  166411. #endif
  166412. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166413. (png_uint_32)(length+1));
  166414. png_ptr->current_text[length] = '\0';
  166415. png_ptr->current_text_ptr = png_ptr->current_text;
  166416. png_ptr->current_text_size = (png_size_t)length;
  166417. png_ptr->current_text_left = (png_size_t)length;
  166418. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166419. }
  166420. void /* PRIVATE */
  166421. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166422. {
  166423. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166424. {
  166425. png_size_t text_size;
  166426. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166427. text_size = png_ptr->buffer_size;
  166428. else
  166429. text_size = png_ptr->current_text_left;
  166430. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166431. png_ptr->current_text_left -= text_size;
  166432. png_ptr->current_text_ptr += text_size;
  166433. }
  166434. if (!(png_ptr->current_text_left))
  166435. {
  166436. png_textp text_ptr;
  166437. png_charp text;
  166438. png_charp key;
  166439. int ret;
  166440. if (png_ptr->buffer_size < 4)
  166441. {
  166442. png_push_save_buffer(png_ptr);
  166443. return;
  166444. }
  166445. png_push_crc_finish(png_ptr);
  166446. #if defined(PNG_MAX_MALLOC_64K)
  166447. if (png_ptr->skip_length)
  166448. return;
  166449. #endif
  166450. key = png_ptr->current_text;
  166451. for (text = key; *text; text++)
  166452. ;
  166453. if (text < key + png_ptr->current_text_size)
  166454. text++;
  166455. text_ptr = (png_textp)png_malloc(png_ptr,
  166456. (png_uint_32)png_sizeof(png_text));
  166457. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166458. text_ptr->key = key;
  166459. #ifdef PNG_iTXt_SUPPORTED
  166460. text_ptr->lang = NULL;
  166461. text_ptr->lang_key = NULL;
  166462. #endif
  166463. text_ptr->text = text;
  166464. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166465. png_free(png_ptr, key);
  166466. png_free(png_ptr, text_ptr);
  166467. png_ptr->current_text = NULL;
  166468. if (ret)
  166469. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166470. }
  166471. }
  166472. #endif
  166473. #if defined(PNG_READ_zTXt_SUPPORTED)
  166474. void /* PRIVATE */
  166475. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166476. length)
  166477. {
  166478. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166479. {
  166480. png_error(png_ptr, "Out of place zTXt");
  166481. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166482. }
  166483. #ifdef PNG_MAX_MALLOC_64K
  166484. if (length > (png_uint_32)65535L)
  166485. {
  166486. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166487. png_push_crc_skip(png_ptr, length);
  166488. return;
  166489. }
  166490. #endif
  166491. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166492. (png_uint_32)(length+1));
  166493. png_ptr->current_text[length] = '\0';
  166494. png_ptr->current_text_ptr = png_ptr->current_text;
  166495. png_ptr->current_text_size = (png_size_t)length;
  166496. png_ptr->current_text_left = (png_size_t)length;
  166497. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166498. }
  166499. void /* PRIVATE */
  166500. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166501. {
  166502. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166503. {
  166504. png_size_t text_size;
  166505. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166506. text_size = png_ptr->buffer_size;
  166507. else
  166508. text_size = png_ptr->current_text_left;
  166509. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166510. png_ptr->current_text_left -= text_size;
  166511. png_ptr->current_text_ptr += text_size;
  166512. }
  166513. if (!(png_ptr->current_text_left))
  166514. {
  166515. png_textp text_ptr;
  166516. png_charp text;
  166517. png_charp key;
  166518. int ret;
  166519. png_size_t text_size, key_size;
  166520. if (png_ptr->buffer_size < 4)
  166521. {
  166522. png_push_save_buffer(png_ptr);
  166523. return;
  166524. }
  166525. png_push_crc_finish(png_ptr);
  166526. key = png_ptr->current_text;
  166527. for (text = key; *text; text++)
  166528. ;
  166529. if (text >= key + png_ptr->current_text_size)
  166530. {
  166531. png_ptr->current_text = NULL;
  166532. png_free(png_ptr, key);
  166533. return;
  166534. }
  166535. text++;
  166536. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166537. {
  166538. png_ptr->current_text = NULL;
  166539. png_free(png_ptr, key);
  166540. return;
  166541. }
  166542. text++;
  166543. png_ptr->zstream.next_in = (png_bytep )text;
  166544. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166545. (text - key));
  166546. png_ptr->zstream.next_out = png_ptr->zbuf;
  166547. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166548. key_size = text - key;
  166549. text_size = 0;
  166550. text = NULL;
  166551. ret = Z_STREAM_END;
  166552. while (png_ptr->zstream.avail_in)
  166553. {
  166554. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166555. if (ret != Z_OK && ret != Z_STREAM_END)
  166556. {
  166557. inflateReset(&png_ptr->zstream);
  166558. png_ptr->zstream.avail_in = 0;
  166559. png_ptr->current_text = NULL;
  166560. png_free(png_ptr, key);
  166561. png_free(png_ptr, text);
  166562. return;
  166563. }
  166564. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166565. {
  166566. if (text == NULL)
  166567. {
  166568. text = (png_charp)png_malloc(png_ptr,
  166569. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166570. + key_size + 1));
  166571. png_memcpy(text + key_size, png_ptr->zbuf,
  166572. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166573. png_memcpy(text, key, key_size);
  166574. text_size = key_size + png_ptr->zbuf_size -
  166575. png_ptr->zstream.avail_out;
  166576. *(text + text_size) = '\0';
  166577. }
  166578. else
  166579. {
  166580. png_charp tmp;
  166581. tmp = text;
  166582. text = (png_charp)png_malloc(png_ptr, text_size +
  166583. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166584. + 1));
  166585. png_memcpy(text, tmp, text_size);
  166586. png_free(png_ptr, tmp);
  166587. png_memcpy(text + text_size, png_ptr->zbuf,
  166588. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166589. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166590. *(text + text_size) = '\0';
  166591. }
  166592. if (ret != Z_STREAM_END)
  166593. {
  166594. png_ptr->zstream.next_out = png_ptr->zbuf;
  166595. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166596. }
  166597. }
  166598. else
  166599. {
  166600. break;
  166601. }
  166602. if (ret == Z_STREAM_END)
  166603. break;
  166604. }
  166605. inflateReset(&png_ptr->zstream);
  166606. png_ptr->zstream.avail_in = 0;
  166607. if (ret != Z_STREAM_END)
  166608. {
  166609. png_ptr->current_text = NULL;
  166610. png_free(png_ptr, key);
  166611. png_free(png_ptr, text);
  166612. return;
  166613. }
  166614. png_ptr->current_text = NULL;
  166615. png_free(png_ptr, key);
  166616. key = text;
  166617. text += key_size;
  166618. text_ptr = (png_textp)png_malloc(png_ptr,
  166619. (png_uint_32)png_sizeof(png_text));
  166620. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166621. text_ptr->key = key;
  166622. #ifdef PNG_iTXt_SUPPORTED
  166623. text_ptr->lang = NULL;
  166624. text_ptr->lang_key = NULL;
  166625. #endif
  166626. text_ptr->text = text;
  166627. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166628. png_free(png_ptr, key);
  166629. png_free(png_ptr, text_ptr);
  166630. if (ret)
  166631. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166632. }
  166633. }
  166634. #endif
  166635. #if defined(PNG_READ_iTXt_SUPPORTED)
  166636. void /* PRIVATE */
  166637. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166638. length)
  166639. {
  166640. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166641. {
  166642. png_error(png_ptr, "Out of place iTXt");
  166643. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166644. }
  166645. #ifdef PNG_MAX_MALLOC_64K
  166646. png_ptr->skip_length = 0; /* This may not be necessary */
  166647. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166648. {
  166649. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166650. png_ptr->skip_length = length - (png_uint_32)65535L;
  166651. length = (png_uint_32)65535L;
  166652. }
  166653. #endif
  166654. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166655. (png_uint_32)(length+1));
  166656. png_ptr->current_text[length] = '\0';
  166657. png_ptr->current_text_ptr = png_ptr->current_text;
  166658. png_ptr->current_text_size = (png_size_t)length;
  166659. png_ptr->current_text_left = (png_size_t)length;
  166660. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166661. }
  166662. void /* PRIVATE */
  166663. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166664. {
  166665. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166666. {
  166667. png_size_t text_size;
  166668. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166669. text_size = png_ptr->buffer_size;
  166670. else
  166671. text_size = png_ptr->current_text_left;
  166672. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166673. png_ptr->current_text_left -= text_size;
  166674. png_ptr->current_text_ptr += text_size;
  166675. }
  166676. if (!(png_ptr->current_text_left))
  166677. {
  166678. png_textp text_ptr;
  166679. png_charp key;
  166680. int comp_flag;
  166681. png_charp lang;
  166682. png_charp lang_key;
  166683. png_charp text;
  166684. int ret;
  166685. if (png_ptr->buffer_size < 4)
  166686. {
  166687. png_push_save_buffer(png_ptr);
  166688. return;
  166689. }
  166690. png_push_crc_finish(png_ptr);
  166691. #if defined(PNG_MAX_MALLOC_64K)
  166692. if (png_ptr->skip_length)
  166693. return;
  166694. #endif
  166695. key = png_ptr->current_text;
  166696. for (lang = key; *lang; lang++)
  166697. ;
  166698. if (lang < key + png_ptr->current_text_size - 3)
  166699. lang++;
  166700. comp_flag = *lang++;
  166701. lang++; /* skip comp_type, always zero */
  166702. for (lang_key = lang; *lang_key; lang_key++)
  166703. ;
  166704. lang_key++; /* skip NUL separator */
  166705. text=lang_key;
  166706. if (lang_key < key + png_ptr->current_text_size - 1)
  166707. {
  166708. for (; *text; text++)
  166709. ;
  166710. }
  166711. if (text < key + png_ptr->current_text_size)
  166712. text++;
  166713. text_ptr = (png_textp)png_malloc(png_ptr,
  166714. (png_uint_32)png_sizeof(png_text));
  166715. text_ptr->compression = comp_flag + 2;
  166716. text_ptr->key = key;
  166717. text_ptr->lang = lang;
  166718. text_ptr->lang_key = lang_key;
  166719. text_ptr->text = text;
  166720. text_ptr->text_length = 0;
  166721. text_ptr->itxt_length = png_strlen(text);
  166722. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166723. png_ptr->current_text = NULL;
  166724. png_free(png_ptr, text_ptr);
  166725. if (ret)
  166726. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166727. }
  166728. }
  166729. #endif
  166730. void /* PRIVATE */
  166731. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166732. length)
  166733. {
  166734. png_uint_32 skip=0;
  166735. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166736. if (!(png_ptr->chunk_name[0] & 0x20))
  166737. {
  166738. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166739. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166740. PNG_HANDLE_CHUNK_ALWAYS
  166741. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166742. && png_ptr->read_user_chunk_fn == NULL
  166743. #endif
  166744. )
  166745. #endif
  166746. png_chunk_error(png_ptr, "unknown critical chunk");
  166747. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166748. }
  166749. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166750. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166751. {
  166752. #ifdef PNG_MAX_MALLOC_64K
  166753. if (length > (png_uint_32)65535L)
  166754. {
  166755. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166756. skip = length - (png_uint_32)65535L;
  166757. length = (png_uint_32)65535L;
  166758. }
  166759. #endif
  166760. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166761. (png_charp)png_ptr->chunk_name, 5);
  166762. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166763. png_ptr->unknown_chunk.size = (png_size_t)length;
  166764. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166765. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166766. if(png_ptr->read_user_chunk_fn != NULL)
  166767. {
  166768. int ret;
  166769. ret = (*(png_ptr->read_user_chunk_fn))
  166770. (png_ptr, &png_ptr->unknown_chunk);
  166771. if (ret < 0)
  166772. png_chunk_error(png_ptr, "error in user chunk");
  166773. if (ret == 0)
  166774. {
  166775. if (!(png_ptr->chunk_name[0] & 0x20))
  166776. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166777. PNG_HANDLE_CHUNK_ALWAYS)
  166778. png_chunk_error(png_ptr, "unknown critical chunk");
  166779. png_set_unknown_chunks(png_ptr, info_ptr,
  166780. &png_ptr->unknown_chunk, 1);
  166781. }
  166782. }
  166783. #else
  166784. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166785. #endif
  166786. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166787. png_ptr->unknown_chunk.data = NULL;
  166788. }
  166789. else
  166790. #endif
  166791. skip=length;
  166792. png_push_crc_skip(png_ptr, skip);
  166793. }
  166794. void /* PRIVATE */
  166795. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166796. {
  166797. if (png_ptr->info_fn != NULL)
  166798. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166799. }
  166800. void /* PRIVATE */
  166801. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166802. {
  166803. if (png_ptr->end_fn != NULL)
  166804. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166805. }
  166806. void /* PRIVATE */
  166807. png_push_have_row(png_structp png_ptr, png_bytep row)
  166808. {
  166809. if (png_ptr->row_fn != NULL)
  166810. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166811. (int)png_ptr->pass);
  166812. }
  166813. void PNGAPI
  166814. png_progressive_combine_row (png_structp png_ptr,
  166815. png_bytep old_row, png_bytep new_row)
  166816. {
  166817. #ifdef PNG_USE_LOCAL_ARRAYS
  166818. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166819. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166820. #endif
  166821. if(png_ptr == NULL) return;
  166822. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166823. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166824. }
  166825. void PNGAPI
  166826. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166827. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166828. png_progressive_end_ptr end_fn)
  166829. {
  166830. if(png_ptr == NULL) return;
  166831. png_ptr->info_fn = info_fn;
  166832. png_ptr->row_fn = row_fn;
  166833. png_ptr->end_fn = end_fn;
  166834. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166835. }
  166836. png_voidp PNGAPI
  166837. png_get_progressive_ptr(png_structp png_ptr)
  166838. {
  166839. if(png_ptr == NULL) return (NULL);
  166840. return png_ptr->io_ptr;
  166841. }
  166842. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166843. /*** End of inlined file: pngpread.c ***/
  166844. /*** Start of inlined file: pngrio.c ***/
  166845. #define PNG_INTERNAL
  166846. #if defined(PNG_READ_SUPPORTED)
  166847. void /* PRIVATE */
  166848. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166849. {
  166850. png_debug1(4,"reading %d bytes\n", (int)length);
  166851. if (png_ptr->read_data_fn != NULL)
  166852. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166853. else
  166854. png_error(png_ptr, "Call to NULL read function");
  166855. }
  166856. #if !defined(PNG_NO_STDIO)
  166857. #ifndef USE_FAR_KEYWORD
  166858. void PNGAPI
  166859. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166860. {
  166861. png_size_t check;
  166862. if(png_ptr == NULL) return;
  166863. #if defined(_WIN32_WCE)
  166864. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166865. check = 0;
  166866. #else
  166867. check = (png_size_t)fread(data, (png_size_t)1, length,
  166868. (png_FILE_p)png_ptr->io_ptr);
  166869. #endif
  166870. if (check != length)
  166871. png_error(png_ptr, "Read Error");
  166872. }
  166873. #else
  166874. #define NEAR_BUF_SIZE 1024
  166875. #define MIN(a,b) (a <= b ? a : b)
  166876. static void PNGAPI
  166877. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166878. {
  166879. int check;
  166880. png_byte *n_data;
  166881. png_FILE_p io_ptr;
  166882. if(png_ptr == NULL) return;
  166883. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166884. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166885. if ((png_bytep)n_data == data)
  166886. {
  166887. #if defined(_WIN32_WCE)
  166888. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166889. check = 0;
  166890. #else
  166891. check = fread(n_data, 1, length, io_ptr);
  166892. #endif
  166893. }
  166894. else
  166895. {
  166896. png_byte buf[NEAR_BUF_SIZE];
  166897. png_size_t read, remaining, err;
  166898. check = 0;
  166899. remaining = length;
  166900. do
  166901. {
  166902. read = MIN(NEAR_BUF_SIZE, remaining);
  166903. #if defined(_WIN32_WCE)
  166904. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166905. err = 0;
  166906. #else
  166907. err = fread(buf, (png_size_t)1, read, io_ptr);
  166908. #endif
  166909. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166910. if(err != read)
  166911. break;
  166912. else
  166913. check += err;
  166914. data += read;
  166915. remaining -= read;
  166916. }
  166917. while (remaining != 0);
  166918. }
  166919. if ((png_uint_32)check != (png_uint_32)length)
  166920. png_error(png_ptr, "read Error");
  166921. }
  166922. #endif
  166923. #endif
  166924. void PNGAPI
  166925. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  166926. png_rw_ptr read_data_fn)
  166927. {
  166928. if(png_ptr == NULL) return;
  166929. png_ptr->io_ptr = io_ptr;
  166930. #if !defined(PNG_NO_STDIO)
  166931. if (read_data_fn != NULL)
  166932. png_ptr->read_data_fn = read_data_fn;
  166933. else
  166934. png_ptr->read_data_fn = png_default_read_data;
  166935. #else
  166936. png_ptr->read_data_fn = read_data_fn;
  166937. #endif
  166938. if (png_ptr->write_data_fn != NULL)
  166939. {
  166940. png_ptr->write_data_fn = NULL;
  166941. png_warning(png_ptr,
  166942. "It's an error to set both read_data_fn and write_data_fn in the ");
  166943. png_warning(png_ptr,
  166944. "same structure. Resetting write_data_fn to NULL.");
  166945. }
  166946. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  166947. png_ptr->output_flush_fn = NULL;
  166948. #endif
  166949. }
  166950. #endif /* PNG_READ_SUPPORTED */
  166951. /*** End of inlined file: pngrio.c ***/
  166952. /*** Start of inlined file: pngrtran.c ***/
  166953. #define PNG_INTERNAL
  166954. #if defined(PNG_READ_SUPPORTED)
  166955. void PNGAPI
  166956. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  166957. {
  166958. png_debug(1, "in png_set_crc_action\n");
  166959. if(png_ptr == NULL) return;
  166960. switch (crit_action)
  166961. {
  166962. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166963. break;
  166964. case PNG_CRC_WARN_USE: /* warn/use data */
  166965. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166966. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  166967. break;
  166968. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166969. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166970. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  166971. PNG_FLAG_CRC_CRITICAL_IGNORE;
  166972. break;
  166973. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  166974. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  166975. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166976. case PNG_CRC_DEFAULT:
  166977. default:
  166978. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166979. break;
  166980. }
  166981. switch (ancil_action)
  166982. {
  166983. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166984. break;
  166985. case PNG_CRC_WARN_USE: /* warn/use data */
  166986. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166987. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  166988. break;
  166989. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166990. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166991. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  166992. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166993. break;
  166994. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166995. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166996. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166997. break;
  166998. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  166999. case PNG_CRC_DEFAULT:
  167000. default:
  167001. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167002. break;
  167003. }
  167004. }
  167005. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167006. defined(PNG_FLOATING_POINT_SUPPORTED)
  167007. void PNGAPI
  167008. png_set_background(png_structp png_ptr,
  167009. png_color_16p background_color, int background_gamma_code,
  167010. int need_expand, double background_gamma)
  167011. {
  167012. png_debug(1, "in png_set_background\n");
  167013. if(png_ptr == NULL) return;
  167014. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167015. {
  167016. png_warning(png_ptr, "Application must supply a known background gamma");
  167017. return;
  167018. }
  167019. png_ptr->transformations |= PNG_BACKGROUND;
  167020. png_memcpy(&(png_ptr->background), background_color,
  167021. png_sizeof(png_color_16));
  167022. png_ptr->background_gamma = (float)background_gamma;
  167023. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167024. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167025. }
  167026. #endif
  167027. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167028. void PNGAPI
  167029. png_set_strip_16(png_structp png_ptr)
  167030. {
  167031. png_debug(1, "in png_set_strip_16\n");
  167032. if(png_ptr == NULL) return;
  167033. png_ptr->transformations |= PNG_16_TO_8;
  167034. }
  167035. #endif
  167036. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167037. void PNGAPI
  167038. png_set_strip_alpha(png_structp png_ptr)
  167039. {
  167040. png_debug(1, "in png_set_strip_alpha\n");
  167041. if(png_ptr == NULL) return;
  167042. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167043. }
  167044. #endif
  167045. #if defined(PNG_READ_DITHER_SUPPORTED)
  167046. typedef struct png_dsort_struct
  167047. {
  167048. struct png_dsort_struct FAR * next;
  167049. png_byte left;
  167050. png_byte right;
  167051. } png_dsort;
  167052. typedef png_dsort FAR * png_dsortp;
  167053. typedef png_dsort FAR * FAR * png_dsortpp;
  167054. void PNGAPI
  167055. png_set_dither(png_structp png_ptr, png_colorp palette,
  167056. int num_palette, int maximum_colors, png_uint_16p histogram,
  167057. int full_dither)
  167058. {
  167059. png_debug(1, "in png_set_dither\n");
  167060. if(png_ptr == NULL) return;
  167061. png_ptr->transformations |= PNG_DITHER;
  167062. if (!full_dither)
  167063. {
  167064. int i;
  167065. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167066. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167067. for (i = 0; i < num_palette; i++)
  167068. png_ptr->dither_index[i] = (png_byte)i;
  167069. }
  167070. if (num_palette > maximum_colors)
  167071. {
  167072. if (histogram != NULL)
  167073. {
  167074. int i;
  167075. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167076. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167077. for (i = 0; i < num_palette; i++)
  167078. png_ptr->dither_sort[i] = (png_byte)i;
  167079. for (i = num_palette - 1; i >= maximum_colors; i--)
  167080. {
  167081. int done; /* to stop early if the list is pre-sorted */
  167082. int j;
  167083. done = 1;
  167084. for (j = 0; j < i; j++)
  167085. {
  167086. if (histogram[png_ptr->dither_sort[j]]
  167087. < histogram[png_ptr->dither_sort[j + 1]])
  167088. {
  167089. png_byte t;
  167090. t = png_ptr->dither_sort[j];
  167091. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167092. png_ptr->dither_sort[j + 1] = t;
  167093. done = 0;
  167094. }
  167095. }
  167096. if (done)
  167097. break;
  167098. }
  167099. if (full_dither)
  167100. {
  167101. int j = num_palette;
  167102. for (i = 0; i < maximum_colors; i++)
  167103. {
  167104. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167105. {
  167106. do
  167107. j--;
  167108. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167109. palette[i] = palette[j];
  167110. }
  167111. }
  167112. }
  167113. else
  167114. {
  167115. int j = num_palette;
  167116. for (i = 0; i < maximum_colors; i++)
  167117. {
  167118. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167119. {
  167120. png_color tmp_color;
  167121. do
  167122. j--;
  167123. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167124. tmp_color = palette[j];
  167125. palette[j] = palette[i];
  167126. palette[i] = tmp_color;
  167127. png_ptr->dither_index[j] = (png_byte)i;
  167128. png_ptr->dither_index[i] = (png_byte)j;
  167129. }
  167130. }
  167131. for (i = 0; i < num_palette; i++)
  167132. {
  167133. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167134. {
  167135. int min_d, k, min_k, d_index;
  167136. d_index = png_ptr->dither_index[i];
  167137. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167138. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167139. {
  167140. int d;
  167141. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167142. if (d < min_d)
  167143. {
  167144. min_d = d;
  167145. min_k = k;
  167146. }
  167147. }
  167148. png_ptr->dither_index[i] = (png_byte)min_k;
  167149. }
  167150. }
  167151. }
  167152. png_free(png_ptr, png_ptr->dither_sort);
  167153. png_ptr->dither_sort=NULL;
  167154. }
  167155. else
  167156. {
  167157. int i;
  167158. int max_d;
  167159. int num_new_palette;
  167160. png_dsortp t;
  167161. png_dsortpp hash;
  167162. t=NULL;
  167163. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167164. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167165. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167166. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167167. for (i = 0; i < num_palette; i++)
  167168. {
  167169. png_ptr->index_to_palette[i] = (png_byte)i;
  167170. png_ptr->palette_to_index[i] = (png_byte)i;
  167171. }
  167172. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167173. png_sizeof (png_dsortp)));
  167174. for (i = 0; i < 769; i++)
  167175. hash[i] = NULL;
  167176. num_new_palette = num_palette;
  167177. max_d = 96;
  167178. while (num_new_palette > maximum_colors)
  167179. {
  167180. for (i = 0; i < num_new_palette - 1; i++)
  167181. {
  167182. int j;
  167183. for (j = i + 1; j < num_new_palette; j++)
  167184. {
  167185. int d;
  167186. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167187. if (d <= max_d)
  167188. {
  167189. t = (png_dsortp)png_malloc_warn(png_ptr,
  167190. (png_uint_32)(png_sizeof(png_dsort)));
  167191. if (t == NULL)
  167192. break;
  167193. t->next = hash[d];
  167194. t->left = (png_byte)i;
  167195. t->right = (png_byte)j;
  167196. hash[d] = t;
  167197. }
  167198. }
  167199. if (t == NULL)
  167200. break;
  167201. }
  167202. if (t != NULL)
  167203. for (i = 0; i <= max_d; i++)
  167204. {
  167205. if (hash[i] != NULL)
  167206. {
  167207. png_dsortp p;
  167208. for (p = hash[i]; p; p = p->next)
  167209. {
  167210. if ((int)png_ptr->index_to_palette[p->left]
  167211. < num_new_palette &&
  167212. (int)png_ptr->index_to_palette[p->right]
  167213. < num_new_palette)
  167214. {
  167215. int j, next_j;
  167216. if (num_new_palette & 0x01)
  167217. {
  167218. j = p->left;
  167219. next_j = p->right;
  167220. }
  167221. else
  167222. {
  167223. j = p->right;
  167224. next_j = p->left;
  167225. }
  167226. num_new_palette--;
  167227. palette[png_ptr->index_to_palette[j]]
  167228. = palette[num_new_palette];
  167229. if (!full_dither)
  167230. {
  167231. int k;
  167232. for (k = 0; k < num_palette; k++)
  167233. {
  167234. if (png_ptr->dither_index[k] ==
  167235. png_ptr->index_to_palette[j])
  167236. png_ptr->dither_index[k] =
  167237. png_ptr->index_to_palette[next_j];
  167238. if ((int)png_ptr->dither_index[k] ==
  167239. num_new_palette)
  167240. png_ptr->dither_index[k] =
  167241. png_ptr->index_to_palette[j];
  167242. }
  167243. }
  167244. png_ptr->index_to_palette[png_ptr->palette_to_index
  167245. [num_new_palette]] = png_ptr->index_to_palette[j];
  167246. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167247. = png_ptr->palette_to_index[num_new_palette];
  167248. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167249. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167250. }
  167251. if (num_new_palette <= maximum_colors)
  167252. break;
  167253. }
  167254. if (num_new_palette <= maximum_colors)
  167255. break;
  167256. }
  167257. }
  167258. for (i = 0; i < 769; i++)
  167259. {
  167260. if (hash[i] != NULL)
  167261. {
  167262. png_dsortp p = hash[i];
  167263. while (p)
  167264. {
  167265. t = p->next;
  167266. png_free(png_ptr, p);
  167267. p = t;
  167268. }
  167269. }
  167270. hash[i] = 0;
  167271. }
  167272. max_d += 96;
  167273. }
  167274. png_free(png_ptr, hash);
  167275. png_free(png_ptr, png_ptr->palette_to_index);
  167276. png_free(png_ptr, png_ptr->index_to_palette);
  167277. png_ptr->palette_to_index=NULL;
  167278. png_ptr->index_to_palette=NULL;
  167279. }
  167280. num_palette = maximum_colors;
  167281. }
  167282. if (png_ptr->palette == NULL)
  167283. {
  167284. png_ptr->palette = palette;
  167285. }
  167286. png_ptr->num_palette = (png_uint_16)num_palette;
  167287. if (full_dither)
  167288. {
  167289. int i;
  167290. png_bytep distance;
  167291. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167292. PNG_DITHER_BLUE_BITS;
  167293. int num_red = (1 << PNG_DITHER_RED_BITS);
  167294. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167295. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167296. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167297. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167298. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167299. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167300. png_sizeof (png_byte));
  167301. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167302. png_sizeof(png_byte)));
  167303. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167304. for (i = 0; i < num_palette; i++)
  167305. {
  167306. int ir, ig, ib;
  167307. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167308. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167309. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167310. for (ir = 0; ir < num_red; ir++)
  167311. {
  167312. int dr = ((ir > r) ? ir - r : r - ir);
  167313. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167314. for (ig = 0; ig < num_green; ig++)
  167315. {
  167316. int dg = ((ig > g) ? ig - g : g - ig);
  167317. int dt = dr + dg;
  167318. int dm = ((dr > dg) ? dr : dg);
  167319. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167320. for (ib = 0; ib < num_blue; ib++)
  167321. {
  167322. int d_index = index_g | ib;
  167323. int db = ((ib > b) ? ib - b : b - ib);
  167324. int dmax = ((dm > db) ? dm : db);
  167325. int d = dmax + dt + db;
  167326. if (d < (int)distance[d_index])
  167327. {
  167328. distance[d_index] = (png_byte)d;
  167329. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167330. }
  167331. }
  167332. }
  167333. }
  167334. }
  167335. png_free(png_ptr, distance);
  167336. }
  167337. }
  167338. #endif
  167339. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167340. void PNGAPI
  167341. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167342. {
  167343. png_debug(1, "in png_set_gamma\n");
  167344. if(png_ptr == NULL) return;
  167345. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167346. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167347. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167348. png_ptr->transformations |= PNG_GAMMA;
  167349. png_ptr->gamma = (float)file_gamma;
  167350. png_ptr->screen_gamma = (float)scrn_gamma;
  167351. }
  167352. #endif
  167353. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167354. void PNGAPI
  167355. png_set_expand(png_structp png_ptr)
  167356. {
  167357. png_debug(1, "in png_set_expand\n");
  167358. if(png_ptr == NULL) return;
  167359. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167360. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167361. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167362. #endif
  167363. }
  167364. void PNGAPI
  167365. png_set_palette_to_rgb(png_structp png_ptr)
  167366. {
  167367. png_debug(1, "in png_set_palette_to_rgb\n");
  167368. if(png_ptr == NULL) return;
  167369. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167370. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167371. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167372. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167373. #endif
  167374. }
  167375. #if !defined(PNG_1_0_X)
  167376. void PNGAPI
  167377. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167378. {
  167379. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167380. if(png_ptr == NULL) return;
  167381. png_ptr->transformations |= PNG_EXPAND;
  167382. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167383. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167384. #endif
  167385. }
  167386. #endif
  167387. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167388. void PNGAPI
  167389. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167390. {
  167391. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167392. if(png_ptr == NULL) return;
  167393. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167394. }
  167395. #endif
  167396. void PNGAPI
  167397. png_set_tRNS_to_alpha(png_structp png_ptr)
  167398. {
  167399. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167400. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167401. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167402. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167403. #endif
  167404. }
  167405. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167406. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167407. void PNGAPI
  167408. png_set_gray_to_rgb(png_structp png_ptr)
  167409. {
  167410. png_debug(1, "in png_set_gray_to_rgb\n");
  167411. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167412. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167413. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167414. #endif
  167415. }
  167416. #endif
  167417. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167418. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167419. void PNGAPI
  167420. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167421. double green)
  167422. {
  167423. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167424. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167425. if(png_ptr == NULL) return;
  167426. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167427. }
  167428. #endif
  167429. void PNGAPI
  167430. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167431. png_fixed_point red, png_fixed_point green)
  167432. {
  167433. png_debug(1, "in png_set_rgb_to_gray\n");
  167434. if(png_ptr == NULL) return;
  167435. switch(error_action)
  167436. {
  167437. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167438. break;
  167439. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167440. break;
  167441. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167442. }
  167443. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167444. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167445. png_ptr->transformations |= PNG_EXPAND;
  167446. #else
  167447. {
  167448. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167449. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167450. }
  167451. #endif
  167452. {
  167453. png_uint_16 red_int, green_int;
  167454. if(red < 0 || green < 0)
  167455. {
  167456. red_int = 6968; /* .212671 * 32768 + .5 */
  167457. green_int = 23434; /* .715160 * 32768 + .5 */
  167458. }
  167459. else if(red + green < 100000L)
  167460. {
  167461. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167462. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167463. }
  167464. else
  167465. {
  167466. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167467. red_int = 6968;
  167468. green_int = 23434;
  167469. }
  167470. png_ptr->rgb_to_gray_red_coeff = red_int;
  167471. png_ptr->rgb_to_gray_green_coeff = green_int;
  167472. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167473. }
  167474. }
  167475. #endif
  167476. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167477. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167478. defined(PNG_LEGACY_SUPPORTED)
  167479. void PNGAPI
  167480. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167481. read_user_transform_fn)
  167482. {
  167483. png_debug(1, "in png_set_read_user_transform_fn\n");
  167484. if(png_ptr == NULL) return;
  167485. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167486. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167487. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167488. #endif
  167489. #ifdef PNG_LEGACY_SUPPORTED
  167490. if(read_user_transform_fn)
  167491. png_warning(png_ptr,
  167492. "This version of libpng does not support user transforms");
  167493. #endif
  167494. }
  167495. #endif
  167496. void /* PRIVATE */
  167497. png_init_read_transformations(png_structp png_ptr)
  167498. {
  167499. png_debug(1, "in png_init_read_transformations\n");
  167500. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167501. if(png_ptr != NULL)
  167502. #endif
  167503. {
  167504. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167505. || defined(PNG_READ_GAMMA_SUPPORTED)
  167506. int color_type = png_ptr->color_type;
  167507. #endif
  167508. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167509. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167510. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167511. !(color_type & PNG_COLOR_MASK_COLOR))
  167512. {
  167513. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167514. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167515. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167516. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167517. png_ptr->background.red == png_ptr->background.green &&
  167518. png_ptr->background.red == png_ptr->background.blue)
  167519. {
  167520. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167521. png_ptr->background.gray = png_ptr->background.red;
  167522. }
  167523. #endif
  167524. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167525. (png_ptr->transformations & PNG_EXPAND))
  167526. {
  167527. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167528. {
  167529. switch (png_ptr->bit_depth)
  167530. {
  167531. case 1:
  167532. png_ptr->background.gray *= (png_uint_16)0xff;
  167533. png_ptr->background.red = png_ptr->background.green
  167534. = png_ptr->background.blue = png_ptr->background.gray;
  167535. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167536. {
  167537. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167538. png_ptr->trans_values.red = png_ptr->trans_values.green
  167539. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167540. }
  167541. break;
  167542. case 2:
  167543. png_ptr->background.gray *= (png_uint_16)0x55;
  167544. png_ptr->background.red = png_ptr->background.green
  167545. = png_ptr->background.blue = png_ptr->background.gray;
  167546. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167547. {
  167548. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167549. png_ptr->trans_values.red = png_ptr->trans_values.green
  167550. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167551. }
  167552. break;
  167553. case 4:
  167554. png_ptr->background.gray *= (png_uint_16)0x11;
  167555. png_ptr->background.red = png_ptr->background.green
  167556. = png_ptr->background.blue = png_ptr->background.gray;
  167557. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167558. {
  167559. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167560. png_ptr->trans_values.red = png_ptr->trans_values.green
  167561. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167562. }
  167563. break;
  167564. case 8:
  167565. case 16:
  167566. png_ptr->background.red = png_ptr->background.green
  167567. = png_ptr->background.blue = png_ptr->background.gray;
  167568. break;
  167569. }
  167570. }
  167571. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167572. {
  167573. png_ptr->background.red =
  167574. png_ptr->palette[png_ptr->background.index].red;
  167575. png_ptr->background.green =
  167576. png_ptr->palette[png_ptr->background.index].green;
  167577. png_ptr->background.blue =
  167578. png_ptr->palette[png_ptr->background.index].blue;
  167579. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167580. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167581. {
  167582. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167583. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167584. #endif
  167585. {
  167586. int i,istop;
  167587. istop=(int)png_ptr->num_trans;
  167588. for (i=0; i<istop; i++)
  167589. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167590. }
  167591. }
  167592. #endif
  167593. }
  167594. }
  167595. #endif
  167596. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167597. png_ptr->background_1 = png_ptr->background;
  167598. #endif
  167599. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167600. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167601. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167602. < PNG_GAMMA_THRESHOLD))
  167603. {
  167604. int i,k;
  167605. k=0;
  167606. for (i=0; i<png_ptr->num_trans; i++)
  167607. {
  167608. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167609. k=1; /* partial transparency is present */
  167610. }
  167611. if (k == 0)
  167612. png_ptr->transformations &= (~PNG_GAMMA);
  167613. }
  167614. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167615. png_ptr->gamma != 0.0)
  167616. {
  167617. png_build_gamma_table(png_ptr);
  167618. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167619. if (png_ptr->transformations & PNG_BACKGROUND)
  167620. {
  167621. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167622. {
  167623. png_color back, back_1;
  167624. png_colorp palette = png_ptr->palette;
  167625. int num_palette = png_ptr->num_palette;
  167626. int i;
  167627. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167628. {
  167629. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167630. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167631. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167632. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167633. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167634. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167635. }
  167636. else
  167637. {
  167638. double g, gs;
  167639. switch (png_ptr->background_gamma_type)
  167640. {
  167641. case PNG_BACKGROUND_GAMMA_SCREEN:
  167642. g = (png_ptr->screen_gamma);
  167643. gs = 1.0;
  167644. break;
  167645. case PNG_BACKGROUND_GAMMA_FILE:
  167646. g = 1.0 / (png_ptr->gamma);
  167647. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167648. break;
  167649. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167650. g = 1.0 / (png_ptr->background_gamma);
  167651. gs = 1.0 / (png_ptr->background_gamma *
  167652. png_ptr->screen_gamma);
  167653. break;
  167654. default:
  167655. g = 1.0; /* back_1 */
  167656. gs = 1.0; /* back */
  167657. }
  167658. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167659. {
  167660. back.red = (png_byte)png_ptr->background.red;
  167661. back.green = (png_byte)png_ptr->background.green;
  167662. back.blue = (png_byte)png_ptr->background.blue;
  167663. }
  167664. else
  167665. {
  167666. back.red = (png_byte)(pow(
  167667. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167668. back.green = (png_byte)(pow(
  167669. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167670. back.blue = (png_byte)(pow(
  167671. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167672. }
  167673. back_1.red = (png_byte)(pow(
  167674. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167675. back_1.green = (png_byte)(pow(
  167676. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167677. back_1.blue = (png_byte)(pow(
  167678. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167679. }
  167680. for (i = 0; i < num_palette; i++)
  167681. {
  167682. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167683. {
  167684. if (png_ptr->trans[i] == 0)
  167685. {
  167686. palette[i] = back;
  167687. }
  167688. else /* if (png_ptr->trans[i] != 0xff) */
  167689. {
  167690. png_byte v, w;
  167691. v = png_ptr->gamma_to_1[palette[i].red];
  167692. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167693. palette[i].red = png_ptr->gamma_from_1[w];
  167694. v = png_ptr->gamma_to_1[palette[i].green];
  167695. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167696. palette[i].green = png_ptr->gamma_from_1[w];
  167697. v = png_ptr->gamma_to_1[palette[i].blue];
  167698. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167699. palette[i].blue = png_ptr->gamma_from_1[w];
  167700. }
  167701. }
  167702. else
  167703. {
  167704. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167705. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167706. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167707. }
  167708. }
  167709. }
  167710. else
  167711. {
  167712. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167713. double g = 1.0;
  167714. double gs = 1.0;
  167715. switch (png_ptr->background_gamma_type)
  167716. {
  167717. case PNG_BACKGROUND_GAMMA_SCREEN:
  167718. g = (png_ptr->screen_gamma);
  167719. gs = 1.0;
  167720. break;
  167721. case PNG_BACKGROUND_GAMMA_FILE:
  167722. g = 1.0 / (png_ptr->gamma);
  167723. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167724. break;
  167725. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167726. g = 1.0 / (png_ptr->background_gamma);
  167727. gs = 1.0 / (png_ptr->background_gamma *
  167728. png_ptr->screen_gamma);
  167729. break;
  167730. }
  167731. png_ptr->background_1.gray = (png_uint_16)(pow(
  167732. (double)png_ptr->background.gray / m, g) * m + .5);
  167733. png_ptr->background.gray = (png_uint_16)(pow(
  167734. (double)png_ptr->background.gray / m, gs) * m + .5);
  167735. if ((png_ptr->background.red != png_ptr->background.green) ||
  167736. (png_ptr->background.red != png_ptr->background.blue) ||
  167737. (png_ptr->background.red != png_ptr->background.gray))
  167738. {
  167739. png_ptr->background_1.red = (png_uint_16)(pow(
  167740. (double)png_ptr->background.red / m, g) * m + .5);
  167741. png_ptr->background_1.green = (png_uint_16)(pow(
  167742. (double)png_ptr->background.green / m, g) * m + .5);
  167743. png_ptr->background_1.blue = (png_uint_16)(pow(
  167744. (double)png_ptr->background.blue / m, g) * m + .5);
  167745. png_ptr->background.red = (png_uint_16)(pow(
  167746. (double)png_ptr->background.red / m, gs) * m + .5);
  167747. png_ptr->background.green = (png_uint_16)(pow(
  167748. (double)png_ptr->background.green / m, gs) * m + .5);
  167749. png_ptr->background.blue = (png_uint_16)(pow(
  167750. (double)png_ptr->background.blue / m, gs) * m + .5);
  167751. }
  167752. else
  167753. {
  167754. png_ptr->background_1.red = png_ptr->background_1.green
  167755. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167756. png_ptr->background.red = png_ptr->background.green
  167757. = png_ptr->background.blue = png_ptr->background.gray;
  167758. }
  167759. }
  167760. }
  167761. else
  167762. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167763. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167764. {
  167765. png_colorp palette = png_ptr->palette;
  167766. int num_palette = png_ptr->num_palette;
  167767. int i;
  167768. for (i = 0; i < num_palette; i++)
  167769. {
  167770. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167771. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167772. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167773. }
  167774. }
  167775. }
  167776. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167777. else
  167778. #endif
  167779. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167780. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167781. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167782. (color_type == PNG_COLOR_TYPE_PALETTE))
  167783. {
  167784. int i;
  167785. int istop = (int)png_ptr->num_trans;
  167786. png_color back;
  167787. png_colorp palette = png_ptr->palette;
  167788. back.red = (png_byte)png_ptr->background.red;
  167789. back.green = (png_byte)png_ptr->background.green;
  167790. back.blue = (png_byte)png_ptr->background.blue;
  167791. for (i = 0; i < istop; i++)
  167792. {
  167793. if (png_ptr->trans[i] == 0)
  167794. {
  167795. palette[i] = back;
  167796. }
  167797. else if (png_ptr->trans[i] != 0xff)
  167798. {
  167799. png_composite(palette[i].red, palette[i].red,
  167800. png_ptr->trans[i], back.red);
  167801. png_composite(palette[i].green, palette[i].green,
  167802. png_ptr->trans[i], back.green);
  167803. png_composite(palette[i].blue, palette[i].blue,
  167804. png_ptr->trans[i], back.blue);
  167805. }
  167806. }
  167807. }
  167808. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167809. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167810. if ((png_ptr->transformations & PNG_SHIFT) &&
  167811. (color_type == PNG_COLOR_TYPE_PALETTE))
  167812. {
  167813. png_uint_16 i;
  167814. png_uint_16 istop = png_ptr->num_palette;
  167815. int sr = 8 - png_ptr->sig_bit.red;
  167816. int sg = 8 - png_ptr->sig_bit.green;
  167817. int sb = 8 - png_ptr->sig_bit.blue;
  167818. if (sr < 0 || sr > 8)
  167819. sr = 0;
  167820. if (sg < 0 || sg > 8)
  167821. sg = 0;
  167822. if (sb < 0 || sb > 8)
  167823. sb = 0;
  167824. for (i = 0; i < istop; i++)
  167825. {
  167826. png_ptr->palette[i].red >>= sr;
  167827. png_ptr->palette[i].green >>= sg;
  167828. png_ptr->palette[i].blue >>= sb;
  167829. }
  167830. }
  167831. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167832. }
  167833. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167834. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167835. if(png_ptr)
  167836. return;
  167837. #endif
  167838. }
  167839. void /* PRIVATE */
  167840. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167841. {
  167842. png_debug(1, "in png_read_transform_info\n");
  167843. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167844. if (png_ptr->transformations & PNG_EXPAND)
  167845. {
  167846. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167847. {
  167848. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167849. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167850. else
  167851. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167852. info_ptr->bit_depth = 8;
  167853. info_ptr->num_trans = 0;
  167854. }
  167855. else
  167856. {
  167857. if (png_ptr->num_trans)
  167858. {
  167859. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167860. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167861. else
  167862. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167863. }
  167864. if (info_ptr->bit_depth < 8)
  167865. info_ptr->bit_depth = 8;
  167866. info_ptr->num_trans = 0;
  167867. }
  167868. }
  167869. #endif
  167870. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167871. if (png_ptr->transformations & PNG_BACKGROUND)
  167872. {
  167873. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167874. info_ptr->num_trans = 0;
  167875. info_ptr->background = png_ptr->background;
  167876. }
  167877. #endif
  167878. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167879. if (png_ptr->transformations & PNG_GAMMA)
  167880. {
  167881. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167882. info_ptr->gamma = png_ptr->gamma;
  167883. #endif
  167884. #ifdef PNG_FIXED_POINT_SUPPORTED
  167885. info_ptr->int_gamma = png_ptr->int_gamma;
  167886. #endif
  167887. }
  167888. #endif
  167889. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167890. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167891. info_ptr->bit_depth = 8;
  167892. #endif
  167893. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167894. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167895. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167896. #endif
  167897. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167898. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167899. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167900. #endif
  167901. #if defined(PNG_READ_DITHER_SUPPORTED)
  167902. if (png_ptr->transformations & PNG_DITHER)
  167903. {
  167904. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167905. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167906. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167907. {
  167908. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167909. }
  167910. }
  167911. #endif
  167912. #if defined(PNG_READ_PACK_SUPPORTED)
  167913. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167914. info_ptr->bit_depth = 8;
  167915. #endif
  167916. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167917. info_ptr->channels = 1;
  167918. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  167919. info_ptr->channels = 3;
  167920. else
  167921. info_ptr->channels = 1;
  167922. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167923. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167924. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167925. #endif
  167926. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  167927. info_ptr->channels++;
  167928. #if defined(PNG_READ_FILLER_SUPPORTED)
  167929. if ((png_ptr->transformations & PNG_FILLER) &&
  167930. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167931. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  167932. {
  167933. info_ptr->channels++;
  167934. #if !defined(PNG_1_0_X)
  167935. if (png_ptr->transformations & PNG_ADD_ALPHA)
  167936. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167937. #endif
  167938. }
  167939. #endif
  167940. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  167941. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167942. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  167943. {
  167944. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  167945. info_ptr->bit_depth = png_ptr->user_transform_depth;
  167946. if(info_ptr->channels < png_ptr->user_transform_channels)
  167947. info_ptr->channels = png_ptr->user_transform_channels;
  167948. }
  167949. #endif
  167950. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  167951. info_ptr->bit_depth);
  167952. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  167953. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  167954. if(png_ptr)
  167955. return;
  167956. #endif
  167957. }
  167958. void /* PRIVATE */
  167959. png_do_read_transformations(png_structp png_ptr)
  167960. {
  167961. png_debug(1, "in png_do_read_transformations\n");
  167962. if (png_ptr->row_buf == NULL)
  167963. {
  167964. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  167965. char msg[50];
  167966. png_snprintf2(msg, 50,
  167967. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  167968. png_ptr->pass);
  167969. png_error(png_ptr, msg);
  167970. #else
  167971. png_error(png_ptr, "NULL row buffer");
  167972. #endif
  167973. }
  167974. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167975. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  167976. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  167977. png_error(png_ptr, "Uninitialized row");
  167978. #else
  167979. png_warning(png_ptr, "Uninitialized row");
  167980. #endif
  167981. #endif
  167982. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167983. if (png_ptr->transformations & PNG_EXPAND)
  167984. {
  167985. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  167986. {
  167987. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167988. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  167989. }
  167990. else
  167991. {
  167992. if (png_ptr->num_trans &&
  167993. (png_ptr->transformations & PNG_EXPAND_tRNS))
  167994. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167995. &(png_ptr->trans_values));
  167996. else
  167997. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167998. NULL);
  167999. }
  168000. }
  168001. #endif
  168002. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168003. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168004. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168005. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168006. #endif
  168007. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168008. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168009. {
  168010. int rgb_error =
  168011. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168012. if(rgb_error)
  168013. {
  168014. png_ptr->rgb_to_gray_status=1;
  168015. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168016. PNG_RGB_TO_GRAY_WARN)
  168017. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168018. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168019. PNG_RGB_TO_GRAY_ERR)
  168020. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168021. }
  168022. }
  168023. #endif
  168024. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168025. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168026. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168027. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168028. #endif
  168029. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168030. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168031. ((png_ptr->num_trans != 0 ) ||
  168032. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168033. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168034. &(png_ptr->trans_values), &(png_ptr->background)
  168035. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168036. , &(png_ptr->background_1),
  168037. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168038. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168039. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168040. png_ptr->gamma_shift
  168041. #endif
  168042. );
  168043. #endif
  168044. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168045. if ((png_ptr->transformations & PNG_GAMMA) &&
  168046. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168047. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168048. ((png_ptr->num_trans != 0) ||
  168049. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168050. #endif
  168051. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168052. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168053. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168054. png_ptr->gamma_shift);
  168055. #endif
  168056. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168057. if (png_ptr->transformations & PNG_16_TO_8)
  168058. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168059. #endif
  168060. #if defined(PNG_READ_DITHER_SUPPORTED)
  168061. if (png_ptr->transformations & PNG_DITHER)
  168062. {
  168063. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168064. png_ptr->palette_lookup, png_ptr->dither_index);
  168065. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168066. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168067. }
  168068. #endif
  168069. #if defined(PNG_READ_INVERT_SUPPORTED)
  168070. if (png_ptr->transformations & PNG_INVERT_MONO)
  168071. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168072. #endif
  168073. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168074. if (png_ptr->transformations & PNG_SHIFT)
  168075. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168076. &(png_ptr->shift));
  168077. #endif
  168078. #if defined(PNG_READ_PACK_SUPPORTED)
  168079. if (png_ptr->transformations & PNG_PACK)
  168080. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168081. #endif
  168082. #if defined(PNG_READ_BGR_SUPPORTED)
  168083. if (png_ptr->transformations & PNG_BGR)
  168084. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168085. #endif
  168086. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168087. if (png_ptr->transformations & PNG_PACKSWAP)
  168088. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168089. #endif
  168090. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168091. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168092. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168093. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168094. #endif
  168095. #if defined(PNG_READ_FILLER_SUPPORTED)
  168096. if (png_ptr->transformations & PNG_FILLER)
  168097. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168098. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168099. #endif
  168100. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168101. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168102. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168103. #endif
  168104. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168105. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168106. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168107. #endif
  168108. #if defined(PNG_READ_SWAP_SUPPORTED)
  168109. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168110. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168111. #endif
  168112. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168113. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168114. {
  168115. if(png_ptr->read_user_transform_fn != NULL)
  168116. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168117. (png_ptr, /* png_ptr */
  168118. &(png_ptr->row_info), /* row_info: */
  168119. png_ptr->row_buf + 1); /* start of pixel data for row */
  168120. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168121. if(png_ptr->user_transform_depth)
  168122. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168123. if(png_ptr->user_transform_channels)
  168124. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168125. #endif
  168126. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168127. png_ptr->row_info.channels);
  168128. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168129. png_ptr->row_info.width);
  168130. }
  168131. #endif
  168132. }
  168133. #if defined(PNG_READ_PACK_SUPPORTED)
  168134. void /* PRIVATE */
  168135. png_do_unpack(png_row_infop row_info, png_bytep row)
  168136. {
  168137. png_debug(1, "in png_do_unpack\n");
  168138. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168139. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168140. #else
  168141. if (row_info->bit_depth < 8)
  168142. #endif
  168143. {
  168144. png_uint_32 i;
  168145. png_uint_32 row_width=row_info->width;
  168146. switch (row_info->bit_depth)
  168147. {
  168148. case 1:
  168149. {
  168150. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168151. png_bytep dp = row + (png_size_t)row_width - 1;
  168152. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168153. for (i = 0; i < row_width; i++)
  168154. {
  168155. *dp = (png_byte)((*sp >> shift) & 0x01);
  168156. if (shift == 7)
  168157. {
  168158. shift = 0;
  168159. sp--;
  168160. }
  168161. else
  168162. shift++;
  168163. dp--;
  168164. }
  168165. break;
  168166. }
  168167. case 2:
  168168. {
  168169. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168170. png_bytep dp = row + (png_size_t)row_width - 1;
  168171. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168172. for (i = 0; i < row_width; i++)
  168173. {
  168174. *dp = (png_byte)((*sp >> shift) & 0x03);
  168175. if (shift == 6)
  168176. {
  168177. shift = 0;
  168178. sp--;
  168179. }
  168180. else
  168181. shift += 2;
  168182. dp--;
  168183. }
  168184. break;
  168185. }
  168186. case 4:
  168187. {
  168188. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168189. png_bytep dp = row + (png_size_t)row_width - 1;
  168190. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168191. for (i = 0; i < row_width; i++)
  168192. {
  168193. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168194. if (shift == 4)
  168195. {
  168196. shift = 0;
  168197. sp--;
  168198. }
  168199. else
  168200. shift = 4;
  168201. dp--;
  168202. }
  168203. break;
  168204. }
  168205. }
  168206. row_info->bit_depth = 8;
  168207. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168208. row_info->rowbytes = row_width * row_info->channels;
  168209. }
  168210. }
  168211. #endif
  168212. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168213. void /* PRIVATE */
  168214. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168215. {
  168216. png_debug(1, "in png_do_unshift\n");
  168217. if (
  168218. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168219. row != NULL && row_info != NULL && sig_bits != NULL &&
  168220. #endif
  168221. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168222. {
  168223. int shift[4];
  168224. int channels = 0;
  168225. int c;
  168226. png_uint_16 value = 0;
  168227. png_uint_32 row_width = row_info->width;
  168228. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168229. {
  168230. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168231. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168232. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168233. }
  168234. else
  168235. {
  168236. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168237. }
  168238. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168239. {
  168240. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168241. }
  168242. for (c = 0; c < channels; c++)
  168243. {
  168244. if (shift[c] <= 0)
  168245. shift[c] = 0;
  168246. else
  168247. value = 1;
  168248. }
  168249. if (!value)
  168250. return;
  168251. switch (row_info->bit_depth)
  168252. {
  168253. case 2:
  168254. {
  168255. png_bytep bp;
  168256. png_uint_32 i;
  168257. png_uint_32 istop = row_info->rowbytes;
  168258. for (bp = row, i = 0; i < istop; i++)
  168259. {
  168260. *bp >>= 1;
  168261. *bp++ &= 0x55;
  168262. }
  168263. break;
  168264. }
  168265. case 4:
  168266. {
  168267. png_bytep bp = row;
  168268. png_uint_32 i;
  168269. png_uint_32 istop = row_info->rowbytes;
  168270. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168271. (png_byte)((int)0xf >> shift[0]));
  168272. for (i = 0; i < istop; i++)
  168273. {
  168274. *bp >>= shift[0];
  168275. *bp++ &= mask;
  168276. }
  168277. break;
  168278. }
  168279. case 8:
  168280. {
  168281. png_bytep bp = row;
  168282. png_uint_32 i;
  168283. png_uint_32 istop = row_width * channels;
  168284. for (i = 0; i < istop; i++)
  168285. {
  168286. *bp++ >>= shift[i%channels];
  168287. }
  168288. break;
  168289. }
  168290. case 16:
  168291. {
  168292. png_bytep bp = row;
  168293. png_uint_32 i;
  168294. png_uint_32 istop = channels * row_width;
  168295. for (i = 0; i < istop; i++)
  168296. {
  168297. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168298. value >>= shift[i%channels];
  168299. *bp++ = (png_byte)(value >> 8);
  168300. *bp++ = (png_byte)(value & 0xff);
  168301. }
  168302. break;
  168303. }
  168304. }
  168305. }
  168306. }
  168307. #endif
  168308. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168309. void /* PRIVATE */
  168310. png_do_chop(png_row_infop row_info, png_bytep row)
  168311. {
  168312. png_debug(1, "in png_do_chop\n");
  168313. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168314. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168315. #else
  168316. if (row_info->bit_depth == 16)
  168317. #endif
  168318. {
  168319. png_bytep sp = row;
  168320. png_bytep dp = row;
  168321. png_uint_32 i;
  168322. png_uint_32 istop = row_info->width * row_info->channels;
  168323. for (i = 0; i<istop; i++, sp += 2, dp++)
  168324. {
  168325. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168326. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168327. #else
  168328. *dp = *sp;
  168329. #endif
  168330. }
  168331. row_info->bit_depth = 8;
  168332. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168333. row_info->rowbytes = row_info->width * row_info->channels;
  168334. }
  168335. }
  168336. #endif
  168337. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168338. void /* PRIVATE */
  168339. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168340. {
  168341. png_debug(1, "in png_do_read_swap_alpha\n");
  168342. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168343. if (row != NULL && row_info != NULL)
  168344. #endif
  168345. {
  168346. png_uint_32 row_width = row_info->width;
  168347. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168348. {
  168349. if (row_info->bit_depth == 8)
  168350. {
  168351. png_bytep sp = row + row_info->rowbytes;
  168352. png_bytep dp = sp;
  168353. png_byte save;
  168354. png_uint_32 i;
  168355. for (i = 0; i < row_width; i++)
  168356. {
  168357. save = *(--sp);
  168358. *(--dp) = *(--sp);
  168359. *(--dp) = *(--sp);
  168360. *(--dp) = *(--sp);
  168361. *(--dp) = save;
  168362. }
  168363. }
  168364. else
  168365. {
  168366. png_bytep sp = row + row_info->rowbytes;
  168367. png_bytep dp = sp;
  168368. png_byte save[2];
  168369. png_uint_32 i;
  168370. for (i = 0; i < row_width; i++)
  168371. {
  168372. save[0] = *(--sp);
  168373. save[1] = *(--sp);
  168374. *(--dp) = *(--sp);
  168375. *(--dp) = *(--sp);
  168376. *(--dp) = *(--sp);
  168377. *(--dp) = *(--sp);
  168378. *(--dp) = *(--sp);
  168379. *(--dp) = *(--sp);
  168380. *(--dp) = save[0];
  168381. *(--dp) = save[1];
  168382. }
  168383. }
  168384. }
  168385. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168386. {
  168387. if (row_info->bit_depth == 8)
  168388. {
  168389. png_bytep sp = row + row_info->rowbytes;
  168390. png_bytep dp = sp;
  168391. png_byte save;
  168392. png_uint_32 i;
  168393. for (i = 0; i < row_width; i++)
  168394. {
  168395. save = *(--sp);
  168396. *(--dp) = *(--sp);
  168397. *(--dp) = save;
  168398. }
  168399. }
  168400. else
  168401. {
  168402. png_bytep sp = row + row_info->rowbytes;
  168403. png_bytep dp = sp;
  168404. png_byte save[2];
  168405. png_uint_32 i;
  168406. for (i = 0; i < row_width; i++)
  168407. {
  168408. save[0] = *(--sp);
  168409. save[1] = *(--sp);
  168410. *(--dp) = *(--sp);
  168411. *(--dp) = *(--sp);
  168412. *(--dp) = save[0];
  168413. *(--dp) = save[1];
  168414. }
  168415. }
  168416. }
  168417. }
  168418. }
  168419. #endif
  168420. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168421. void /* PRIVATE */
  168422. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168423. {
  168424. png_debug(1, "in png_do_read_invert_alpha\n");
  168425. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168426. if (row != NULL && row_info != NULL)
  168427. #endif
  168428. {
  168429. png_uint_32 row_width = row_info->width;
  168430. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168431. {
  168432. if (row_info->bit_depth == 8)
  168433. {
  168434. png_bytep sp = row + row_info->rowbytes;
  168435. png_bytep dp = sp;
  168436. png_uint_32 i;
  168437. for (i = 0; i < row_width; i++)
  168438. {
  168439. *(--dp) = (png_byte)(255 - *(--sp));
  168440. sp-=3;
  168441. dp=sp;
  168442. }
  168443. }
  168444. else
  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. *(--dp) = (png_byte)(255 - *(--sp));
  168453. sp-=6;
  168454. dp=sp;
  168455. }
  168456. }
  168457. }
  168458. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168459. {
  168460. if (row_info->bit_depth == 8)
  168461. {
  168462. png_bytep sp = row + row_info->rowbytes;
  168463. png_bytep dp = sp;
  168464. png_uint_32 i;
  168465. for (i = 0; i < row_width; i++)
  168466. {
  168467. *(--dp) = (png_byte)(255 - *(--sp));
  168468. *(--dp) = *(--sp);
  168469. }
  168470. }
  168471. else
  168472. {
  168473. png_bytep sp = row + row_info->rowbytes;
  168474. png_bytep dp = sp;
  168475. png_uint_32 i;
  168476. for (i = 0; i < row_width; i++)
  168477. {
  168478. *(--dp) = (png_byte)(255 - *(--sp));
  168479. *(--dp) = (png_byte)(255 - *(--sp));
  168480. sp-=2;
  168481. dp=sp;
  168482. }
  168483. }
  168484. }
  168485. }
  168486. }
  168487. #endif
  168488. #if defined(PNG_READ_FILLER_SUPPORTED)
  168489. void /* PRIVATE */
  168490. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168491. png_uint_32 filler, png_uint_32 flags)
  168492. {
  168493. png_uint_32 i;
  168494. png_uint_32 row_width = row_info->width;
  168495. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168496. png_byte lo_filler = (png_byte)(filler & 0xff);
  168497. png_debug(1, "in png_do_read_filler\n");
  168498. if (
  168499. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168500. row != NULL && row_info != NULL &&
  168501. #endif
  168502. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168503. {
  168504. if(row_info->bit_depth == 8)
  168505. {
  168506. if (flags & PNG_FLAG_FILLER_AFTER)
  168507. {
  168508. png_bytep sp = row + (png_size_t)row_width;
  168509. png_bytep dp = sp + (png_size_t)row_width;
  168510. for (i = 1; i < row_width; i++)
  168511. {
  168512. *(--dp) = lo_filler;
  168513. *(--dp) = *(--sp);
  168514. }
  168515. *(--dp) = lo_filler;
  168516. row_info->channels = 2;
  168517. row_info->pixel_depth = 16;
  168518. row_info->rowbytes = row_width * 2;
  168519. }
  168520. else
  168521. {
  168522. png_bytep sp = row + (png_size_t)row_width;
  168523. png_bytep dp = sp + (png_size_t)row_width;
  168524. for (i = 0; i < row_width; i++)
  168525. {
  168526. *(--dp) = *(--sp);
  168527. *(--dp) = lo_filler;
  168528. }
  168529. row_info->channels = 2;
  168530. row_info->pixel_depth = 16;
  168531. row_info->rowbytes = row_width * 2;
  168532. }
  168533. }
  168534. else if(row_info->bit_depth == 16)
  168535. {
  168536. if (flags & PNG_FLAG_FILLER_AFTER)
  168537. {
  168538. png_bytep sp = row + (png_size_t)row_width * 2;
  168539. png_bytep dp = sp + (png_size_t)row_width * 2;
  168540. for (i = 1; i < row_width; i++)
  168541. {
  168542. *(--dp) = hi_filler;
  168543. *(--dp) = lo_filler;
  168544. *(--dp) = *(--sp);
  168545. *(--dp) = *(--sp);
  168546. }
  168547. *(--dp) = hi_filler;
  168548. *(--dp) = lo_filler;
  168549. row_info->channels = 2;
  168550. row_info->pixel_depth = 32;
  168551. row_info->rowbytes = row_width * 4;
  168552. }
  168553. else
  168554. {
  168555. png_bytep sp = row + (png_size_t)row_width * 2;
  168556. png_bytep dp = sp + (png_size_t)row_width * 2;
  168557. for (i = 0; i < row_width; i++)
  168558. {
  168559. *(--dp) = *(--sp);
  168560. *(--dp) = *(--sp);
  168561. *(--dp) = hi_filler;
  168562. *(--dp) = lo_filler;
  168563. }
  168564. row_info->channels = 2;
  168565. row_info->pixel_depth = 32;
  168566. row_info->rowbytes = row_width * 4;
  168567. }
  168568. }
  168569. } /* COLOR_TYPE == GRAY */
  168570. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168571. {
  168572. if(row_info->bit_depth == 8)
  168573. {
  168574. if (flags & PNG_FLAG_FILLER_AFTER)
  168575. {
  168576. png_bytep sp = row + (png_size_t)row_width * 3;
  168577. png_bytep dp = sp + (png_size_t)row_width;
  168578. for (i = 1; i < row_width; i++)
  168579. {
  168580. *(--dp) = lo_filler;
  168581. *(--dp) = *(--sp);
  168582. *(--dp) = *(--sp);
  168583. *(--dp) = *(--sp);
  168584. }
  168585. *(--dp) = lo_filler;
  168586. row_info->channels = 4;
  168587. row_info->pixel_depth = 32;
  168588. row_info->rowbytes = row_width * 4;
  168589. }
  168590. else
  168591. {
  168592. png_bytep sp = row + (png_size_t)row_width * 3;
  168593. png_bytep dp = sp + (png_size_t)row_width;
  168594. for (i = 0; i < row_width; i++)
  168595. {
  168596. *(--dp) = *(--sp);
  168597. *(--dp) = *(--sp);
  168598. *(--dp) = *(--sp);
  168599. *(--dp) = lo_filler;
  168600. }
  168601. row_info->channels = 4;
  168602. row_info->pixel_depth = 32;
  168603. row_info->rowbytes = row_width * 4;
  168604. }
  168605. }
  168606. else if(row_info->bit_depth == 16)
  168607. {
  168608. if (flags & PNG_FLAG_FILLER_AFTER)
  168609. {
  168610. png_bytep sp = row + (png_size_t)row_width * 6;
  168611. png_bytep dp = sp + (png_size_t)row_width * 2;
  168612. for (i = 1; i < row_width; i++)
  168613. {
  168614. *(--dp) = hi_filler;
  168615. *(--dp) = lo_filler;
  168616. *(--dp) = *(--sp);
  168617. *(--dp) = *(--sp);
  168618. *(--dp) = *(--sp);
  168619. *(--dp) = *(--sp);
  168620. *(--dp) = *(--sp);
  168621. *(--dp) = *(--sp);
  168622. }
  168623. *(--dp) = hi_filler;
  168624. *(--dp) = lo_filler;
  168625. row_info->channels = 4;
  168626. row_info->pixel_depth = 64;
  168627. row_info->rowbytes = row_width * 8;
  168628. }
  168629. else
  168630. {
  168631. png_bytep sp = row + (png_size_t)row_width * 6;
  168632. png_bytep dp = sp + (png_size_t)row_width * 2;
  168633. for (i = 0; i < row_width; i++)
  168634. {
  168635. *(--dp) = *(--sp);
  168636. *(--dp) = *(--sp);
  168637. *(--dp) = *(--sp);
  168638. *(--dp) = *(--sp);
  168639. *(--dp) = *(--sp);
  168640. *(--dp) = *(--sp);
  168641. *(--dp) = hi_filler;
  168642. *(--dp) = lo_filler;
  168643. }
  168644. row_info->channels = 4;
  168645. row_info->pixel_depth = 64;
  168646. row_info->rowbytes = row_width * 8;
  168647. }
  168648. }
  168649. } /* COLOR_TYPE == RGB */
  168650. }
  168651. #endif
  168652. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168653. void /* PRIVATE */
  168654. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168655. {
  168656. png_uint_32 i;
  168657. png_uint_32 row_width = row_info->width;
  168658. png_debug(1, "in png_do_gray_to_rgb\n");
  168659. if (row_info->bit_depth >= 8 &&
  168660. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168661. row != NULL && row_info != NULL &&
  168662. #endif
  168663. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168664. {
  168665. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168666. {
  168667. if (row_info->bit_depth == 8)
  168668. {
  168669. png_bytep sp = row + (png_size_t)row_width - 1;
  168670. png_bytep dp = sp + (png_size_t)row_width * 2;
  168671. for (i = 0; i < row_width; i++)
  168672. {
  168673. *(dp--) = *sp;
  168674. *(dp--) = *sp;
  168675. *(dp--) = *(sp--);
  168676. }
  168677. }
  168678. else
  168679. {
  168680. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168681. png_bytep dp = sp + (png_size_t)row_width * 4;
  168682. for (i = 0; i < row_width; i++)
  168683. {
  168684. *(dp--) = *sp;
  168685. *(dp--) = *(sp - 1);
  168686. *(dp--) = *sp;
  168687. *(dp--) = *(sp - 1);
  168688. *(dp--) = *(sp--);
  168689. *(dp--) = *(sp--);
  168690. }
  168691. }
  168692. }
  168693. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168694. {
  168695. if (row_info->bit_depth == 8)
  168696. {
  168697. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168698. png_bytep dp = sp + (png_size_t)row_width * 2;
  168699. for (i = 0; i < row_width; i++)
  168700. {
  168701. *(dp--) = *(sp--);
  168702. *(dp--) = *sp;
  168703. *(dp--) = *sp;
  168704. *(dp--) = *(sp--);
  168705. }
  168706. }
  168707. else
  168708. {
  168709. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168710. png_bytep dp = sp + (png_size_t)row_width * 4;
  168711. for (i = 0; i < row_width; i++)
  168712. {
  168713. *(dp--) = *(sp--);
  168714. *(dp--) = *(sp--);
  168715. *(dp--) = *sp;
  168716. *(dp--) = *(sp - 1);
  168717. *(dp--) = *sp;
  168718. *(dp--) = *(sp - 1);
  168719. *(dp--) = *(sp--);
  168720. *(dp--) = *(sp--);
  168721. }
  168722. }
  168723. }
  168724. row_info->channels += (png_byte)2;
  168725. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168726. row_info->pixel_depth = (png_byte)(row_info->channels *
  168727. row_info->bit_depth);
  168728. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168729. }
  168730. }
  168731. #endif
  168732. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168733. int /* PRIVATE */
  168734. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168735. {
  168736. png_uint_32 i;
  168737. png_uint_32 row_width = row_info->width;
  168738. int rgb_error = 0;
  168739. png_debug(1, "in png_do_rgb_to_gray\n");
  168740. if (
  168741. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168742. row != NULL && row_info != NULL &&
  168743. #endif
  168744. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168745. {
  168746. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168747. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168748. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168749. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168750. {
  168751. if (row_info->bit_depth == 8)
  168752. {
  168753. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168754. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168755. {
  168756. png_bytep sp = row;
  168757. png_bytep dp = row;
  168758. for (i = 0; i < row_width; i++)
  168759. {
  168760. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168761. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168762. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168763. if(red != green || red != blue)
  168764. {
  168765. rgb_error |= 1;
  168766. *(dp++) = png_ptr->gamma_from_1[
  168767. (rc*red+gc*green+bc*blue)>>15];
  168768. }
  168769. else
  168770. *(dp++) = *(sp-1);
  168771. }
  168772. }
  168773. else
  168774. #endif
  168775. {
  168776. png_bytep sp = row;
  168777. png_bytep dp = row;
  168778. for (i = 0; i < row_width; i++)
  168779. {
  168780. png_byte red = *(sp++);
  168781. png_byte green = *(sp++);
  168782. png_byte blue = *(sp++);
  168783. if(red != green || red != blue)
  168784. {
  168785. rgb_error |= 1;
  168786. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168787. }
  168788. else
  168789. *(dp++) = *(sp-1);
  168790. }
  168791. }
  168792. }
  168793. else /* RGB bit_depth == 16 */
  168794. {
  168795. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168796. if (png_ptr->gamma_16_to_1 != NULL &&
  168797. png_ptr->gamma_16_from_1 != NULL)
  168798. {
  168799. png_bytep sp = row;
  168800. png_bytep dp = row;
  168801. for (i = 0; i < row_width; i++)
  168802. {
  168803. png_uint_16 red, green, blue, w;
  168804. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168805. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168806. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168807. if(red == green && red == blue)
  168808. w = red;
  168809. else
  168810. {
  168811. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168812. png_ptr->gamma_shift][red>>8];
  168813. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168814. png_ptr->gamma_shift][green>>8];
  168815. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168816. png_ptr->gamma_shift][blue>>8];
  168817. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168818. + bc*blue_1)>>15);
  168819. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168820. png_ptr->gamma_shift][gray16 >> 8];
  168821. rgb_error |= 1;
  168822. }
  168823. *(dp++) = (png_byte)((w>>8) & 0xff);
  168824. *(dp++) = (png_byte)(w & 0xff);
  168825. }
  168826. }
  168827. else
  168828. #endif
  168829. {
  168830. png_bytep sp = row;
  168831. png_bytep dp = row;
  168832. for (i = 0; i < row_width; i++)
  168833. {
  168834. png_uint_16 red, green, blue, gray16;
  168835. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168836. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168837. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168838. if(red != green || red != blue)
  168839. rgb_error |= 1;
  168840. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168841. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168842. *(dp++) = (png_byte)(gray16 & 0xff);
  168843. }
  168844. }
  168845. }
  168846. }
  168847. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168848. {
  168849. if (row_info->bit_depth == 8)
  168850. {
  168851. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168852. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168853. {
  168854. png_bytep sp = row;
  168855. png_bytep dp = row;
  168856. for (i = 0; i < row_width; i++)
  168857. {
  168858. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168859. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168860. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168861. if(red != green || red != blue)
  168862. rgb_error |= 1;
  168863. *(dp++) = png_ptr->gamma_from_1
  168864. [(rc*red + gc*green + bc*blue)>>15];
  168865. *(dp++) = *(sp++); /* alpha */
  168866. }
  168867. }
  168868. else
  168869. #endif
  168870. {
  168871. png_bytep sp = row;
  168872. png_bytep dp = row;
  168873. for (i = 0; i < row_width; i++)
  168874. {
  168875. png_byte red = *(sp++);
  168876. png_byte green = *(sp++);
  168877. png_byte blue = *(sp++);
  168878. if(red != green || red != blue)
  168879. rgb_error |= 1;
  168880. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168881. *(dp++) = *(sp++); /* alpha */
  168882. }
  168883. }
  168884. }
  168885. else /* RGBA bit_depth == 16 */
  168886. {
  168887. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168888. if (png_ptr->gamma_16_to_1 != NULL &&
  168889. png_ptr->gamma_16_from_1 != NULL)
  168890. {
  168891. png_bytep sp = row;
  168892. png_bytep dp = row;
  168893. for (i = 0; i < row_width; i++)
  168894. {
  168895. png_uint_16 red, green, blue, w;
  168896. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168897. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168898. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168899. if(red == green && red == blue)
  168900. w = red;
  168901. else
  168902. {
  168903. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168904. png_ptr->gamma_shift][red>>8];
  168905. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168906. png_ptr->gamma_shift][green>>8];
  168907. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168908. png_ptr->gamma_shift][blue>>8];
  168909. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168910. + gc * green_1 + bc * blue_1)>>15);
  168911. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168912. png_ptr->gamma_shift][gray16 >> 8];
  168913. rgb_error |= 1;
  168914. }
  168915. *(dp++) = (png_byte)((w>>8) & 0xff);
  168916. *(dp++) = (png_byte)(w & 0xff);
  168917. *(dp++) = *(sp++); /* alpha */
  168918. *(dp++) = *(sp++);
  168919. }
  168920. }
  168921. else
  168922. #endif
  168923. {
  168924. png_bytep sp = row;
  168925. png_bytep dp = row;
  168926. for (i = 0; i < row_width; i++)
  168927. {
  168928. png_uint_16 red, green, blue, gray16;
  168929. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168930. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168931. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168932. if(red != green || red != blue)
  168933. rgb_error |= 1;
  168934. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168935. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168936. *(dp++) = (png_byte)(gray16 & 0xff);
  168937. *(dp++) = *(sp++); /* alpha */
  168938. *(dp++) = *(sp++);
  168939. }
  168940. }
  168941. }
  168942. }
  168943. row_info->channels -= (png_byte)2;
  168944. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  168945. row_info->pixel_depth = (png_byte)(row_info->channels *
  168946. row_info->bit_depth);
  168947. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168948. }
  168949. return rgb_error;
  168950. }
  168951. #endif
  168952. void PNGAPI
  168953. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  168954. {
  168955. int num_palette;
  168956. int color_inc;
  168957. int i;
  168958. int v;
  168959. png_debug(1, "in png_do_build_grayscale_palette\n");
  168960. if (palette == NULL)
  168961. return;
  168962. switch (bit_depth)
  168963. {
  168964. case 1:
  168965. num_palette = 2;
  168966. color_inc = 0xff;
  168967. break;
  168968. case 2:
  168969. num_palette = 4;
  168970. color_inc = 0x55;
  168971. break;
  168972. case 4:
  168973. num_palette = 16;
  168974. color_inc = 0x11;
  168975. break;
  168976. case 8:
  168977. num_palette = 256;
  168978. color_inc = 1;
  168979. break;
  168980. default:
  168981. num_palette = 0;
  168982. color_inc = 0;
  168983. break;
  168984. }
  168985. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  168986. {
  168987. palette[i].red = (png_byte)v;
  168988. palette[i].green = (png_byte)v;
  168989. palette[i].blue = (png_byte)v;
  168990. }
  168991. }
  168992. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  168993. void /* PRIVATE */
  168994. png_correct_palette(png_structp png_ptr, png_colorp palette,
  168995. int num_palette)
  168996. {
  168997. png_debug(1, "in png_correct_palette\n");
  168998. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  168999. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169000. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169001. {
  169002. png_color back, back_1;
  169003. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169004. {
  169005. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169006. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169007. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169008. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169009. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169010. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169011. }
  169012. else
  169013. {
  169014. double g;
  169015. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169016. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169017. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169018. {
  169019. back.red = png_ptr->background.red;
  169020. back.green = png_ptr->background.green;
  169021. back.blue = png_ptr->background.blue;
  169022. }
  169023. else
  169024. {
  169025. back.red =
  169026. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169027. 255.0 + 0.5);
  169028. back.green =
  169029. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169030. 255.0 + 0.5);
  169031. back.blue =
  169032. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169033. 255.0 + 0.5);
  169034. }
  169035. g = 1.0 / png_ptr->background_gamma;
  169036. back_1.red =
  169037. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169038. 255.0 + 0.5);
  169039. back_1.green =
  169040. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169041. 255.0 + 0.5);
  169042. back_1.blue =
  169043. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169044. 255.0 + 0.5);
  169045. }
  169046. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169047. {
  169048. png_uint_32 i;
  169049. for (i = 0; i < (png_uint_32)num_palette; i++)
  169050. {
  169051. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169052. {
  169053. palette[i] = back;
  169054. }
  169055. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169056. {
  169057. png_byte v, w;
  169058. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169059. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169060. palette[i].red = png_ptr->gamma_from_1[w];
  169061. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169062. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169063. palette[i].green = png_ptr->gamma_from_1[w];
  169064. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169065. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169066. palette[i].blue = png_ptr->gamma_from_1[w];
  169067. }
  169068. else
  169069. {
  169070. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169071. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169072. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169073. }
  169074. }
  169075. }
  169076. else
  169077. {
  169078. int i;
  169079. for (i = 0; i < num_palette; i++)
  169080. {
  169081. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169082. {
  169083. palette[i] = back;
  169084. }
  169085. else
  169086. {
  169087. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169088. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169089. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169090. }
  169091. }
  169092. }
  169093. }
  169094. else
  169095. #endif
  169096. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169097. if (png_ptr->transformations & PNG_GAMMA)
  169098. {
  169099. int i;
  169100. for (i = 0; i < num_palette; i++)
  169101. {
  169102. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169103. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169104. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169105. }
  169106. }
  169107. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169108. else
  169109. #endif
  169110. #endif
  169111. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169112. if (png_ptr->transformations & PNG_BACKGROUND)
  169113. {
  169114. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169115. {
  169116. png_color back;
  169117. back.red = (png_byte)png_ptr->background.red;
  169118. back.green = (png_byte)png_ptr->background.green;
  169119. back.blue = (png_byte)png_ptr->background.blue;
  169120. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169121. {
  169122. if (png_ptr->trans[i] == 0)
  169123. {
  169124. palette[i].red = back.red;
  169125. palette[i].green = back.green;
  169126. palette[i].blue = back.blue;
  169127. }
  169128. else if (png_ptr->trans[i] != 0xff)
  169129. {
  169130. png_composite(palette[i].red, png_ptr->palette[i].red,
  169131. png_ptr->trans[i], back.red);
  169132. png_composite(palette[i].green, png_ptr->palette[i].green,
  169133. png_ptr->trans[i], back.green);
  169134. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169135. png_ptr->trans[i], back.blue);
  169136. }
  169137. }
  169138. }
  169139. else /* assume grayscale palette (what else could it be?) */
  169140. {
  169141. int i;
  169142. for (i = 0; i < num_palette; i++)
  169143. {
  169144. if (i == (png_byte)png_ptr->trans_values.gray)
  169145. {
  169146. palette[i].red = (png_byte)png_ptr->background.red;
  169147. palette[i].green = (png_byte)png_ptr->background.green;
  169148. palette[i].blue = (png_byte)png_ptr->background.blue;
  169149. }
  169150. }
  169151. }
  169152. }
  169153. #endif
  169154. }
  169155. #endif
  169156. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169157. void /* PRIVATE */
  169158. png_do_background(png_row_infop row_info, png_bytep row,
  169159. png_color_16p trans_values, png_color_16p background
  169160. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169161. , png_color_16p background_1,
  169162. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169163. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169164. png_uint_16pp gamma_16_to_1, int gamma_shift
  169165. #endif
  169166. )
  169167. {
  169168. png_bytep sp, dp;
  169169. png_uint_32 i;
  169170. png_uint_32 row_width=row_info->width;
  169171. int shift;
  169172. png_debug(1, "in png_do_background\n");
  169173. if (background != NULL &&
  169174. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169175. row != NULL && row_info != NULL &&
  169176. #endif
  169177. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169178. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169179. {
  169180. switch (row_info->color_type)
  169181. {
  169182. case PNG_COLOR_TYPE_GRAY:
  169183. {
  169184. switch (row_info->bit_depth)
  169185. {
  169186. case 1:
  169187. {
  169188. sp = row;
  169189. shift = 7;
  169190. for (i = 0; i < row_width; i++)
  169191. {
  169192. if ((png_uint_16)((*sp >> shift) & 0x01)
  169193. == trans_values->gray)
  169194. {
  169195. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169196. *sp |= (png_byte)(background->gray << shift);
  169197. }
  169198. if (!shift)
  169199. {
  169200. shift = 7;
  169201. sp++;
  169202. }
  169203. else
  169204. shift--;
  169205. }
  169206. break;
  169207. }
  169208. case 2:
  169209. {
  169210. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169211. if (gamma_table != NULL)
  169212. {
  169213. sp = row;
  169214. shift = 6;
  169215. for (i = 0; i < row_width; i++)
  169216. {
  169217. if ((png_uint_16)((*sp >> shift) & 0x03)
  169218. == trans_values->gray)
  169219. {
  169220. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169221. *sp |= (png_byte)(background->gray << shift);
  169222. }
  169223. else
  169224. {
  169225. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169226. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169227. (p << 4) | (p << 6)] >> 6) & 0x03);
  169228. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169229. *sp |= (png_byte)(g << shift);
  169230. }
  169231. if (!shift)
  169232. {
  169233. shift = 6;
  169234. sp++;
  169235. }
  169236. else
  169237. shift -= 2;
  169238. }
  169239. }
  169240. else
  169241. #endif
  169242. {
  169243. sp = row;
  169244. shift = 6;
  169245. for (i = 0; i < row_width; i++)
  169246. {
  169247. if ((png_uint_16)((*sp >> shift) & 0x03)
  169248. == trans_values->gray)
  169249. {
  169250. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169251. *sp |= (png_byte)(background->gray << shift);
  169252. }
  169253. if (!shift)
  169254. {
  169255. shift = 6;
  169256. sp++;
  169257. }
  169258. else
  169259. shift -= 2;
  169260. }
  169261. }
  169262. break;
  169263. }
  169264. case 4:
  169265. {
  169266. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169267. if (gamma_table != NULL)
  169268. {
  169269. sp = row;
  169270. shift = 4;
  169271. for (i = 0; i < row_width; i++)
  169272. {
  169273. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169274. == trans_values->gray)
  169275. {
  169276. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169277. *sp |= (png_byte)(background->gray << shift);
  169278. }
  169279. else
  169280. {
  169281. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169282. png_byte g = (png_byte)((gamma_table[p |
  169283. (p << 4)] >> 4) & 0x0f);
  169284. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169285. *sp |= (png_byte)(g << shift);
  169286. }
  169287. if (!shift)
  169288. {
  169289. shift = 4;
  169290. sp++;
  169291. }
  169292. else
  169293. shift -= 4;
  169294. }
  169295. }
  169296. else
  169297. #endif
  169298. {
  169299. sp = row;
  169300. shift = 4;
  169301. for (i = 0; i < row_width; i++)
  169302. {
  169303. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169304. == trans_values->gray)
  169305. {
  169306. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169307. *sp |= (png_byte)(background->gray << shift);
  169308. }
  169309. if (!shift)
  169310. {
  169311. shift = 4;
  169312. sp++;
  169313. }
  169314. else
  169315. shift -= 4;
  169316. }
  169317. }
  169318. break;
  169319. }
  169320. case 8:
  169321. {
  169322. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169323. if (gamma_table != NULL)
  169324. {
  169325. sp = row;
  169326. for (i = 0; i < row_width; i++, sp++)
  169327. {
  169328. if (*sp == trans_values->gray)
  169329. {
  169330. *sp = (png_byte)background->gray;
  169331. }
  169332. else
  169333. {
  169334. *sp = gamma_table[*sp];
  169335. }
  169336. }
  169337. }
  169338. else
  169339. #endif
  169340. {
  169341. sp = row;
  169342. for (i = 0; i < row_width; i++, sp++)
  169343. {
  169344. if (*sp == trans_values->gray)
  169345. {
  169346. *sp = (png_byte)background->gray;
  169347. }
  169348. }
  169349. }
  169350. break;
  169351. }
  169352. case 16:
  169353. {
  169354. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169355. if (gamma_16 != NULL)
  169356. {
  169357. sp = row;
  169358. for (i = 0; i < row_width; i++, sp += 2)
  169359. {
  169360. png_uint_16 v;
  169361. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169362. if (v == trans_values->gray)
  169363. {
  169364. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169365. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169366. }
  169367. else
  169368. {
  169369. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169370. *sp = (png_byte)((v >> 8) & 0xff);
  169371. *(sp + 1) = (png_byte)(v & 0xff);
  169372. }
  169373. }
  169374. }
  169375. else
  169376. #endif
  169377. {
  169378. sp = row;
  169379. for (i = 0; i < row_width; i++, sp += 2)
  169380. {
  169381. png_uint_16 v;
  169382. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169383. if (v == trans_values->gray)
  169384. {
  169385. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169386. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169387. }
  169388. }
  169389. }
  169390. break;
  169391. }
  169392. }
  169393. break;
  169394. }
  169395. case PNG_COLOR_TYPE_RGB:
  169396. {
  169397. if (row_info->bit_depth == 8)
  169398. {
  169399. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169400. if (gamma_table != NULL)
  169401. {
  169402. sp = row;
  169403. for (i = 0; i < row_width; i++, sp += 3)
  169404. {
  169405. if (*sp == trans_values->red &&
  169406. *(sp + 1) == trans_values->green &&
  169407. *(sp + 2) == trans_values->blue)
  169408. {
  169409. *sp = (png_byte)background->red;
  169410. *(sp + 1) = (png_byte)background->green;
  169411. *(sp + 2) = (png_byte)background->blue;
  169412. }
  169413. else
  169414. {
  169415. *sp = gamma_table[*sp];
  169416. *(sp + 1) = gamma_table[*(sp + 1)];
  169417. *(sp + 2) = gamma_table[*(sp + 2)];
  169418. }
  169419. }
  169420. }
  169421. else
  169422. #endif
  169423. {
  169424. sp = row;
  169425. for (i = 0; i < row_width; i++, sp += 3)
  169426. {
  169427. if (*sp == trans_values->red &&
  169428. *(sp + 1) == trans_values->green &&
  169429. *(sp + 2) == trans_values->blue)
  169430. {
  169431. *sp = (png_byte)background->red;
  169432. *(sp + 1) = (png_byte)background->green;
  169433. *(sp + 2) = (png_byte)background->blue;
  169434. }
  169435. }
  169436. }
  169437. }
  169438. else /* if (row_info->bit_depth == 16) */
  169439. {
  169440. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169441. if (gamma_16 != NULL)
  169442. {
  169443. sp = row;
  169444. for (i = 0; i < row_width; i++, sp += 6)
  169445. {
  169446. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169447. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169448. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169449. if (r == trans_values->red && g == trans_values->green &&
  169450. b == trans_values->blue)
  169451. {
  169452. *sp = (png_byte)((background->red >> 8) & 0xff);
  169453. *(sp + 1) = (png_byte)(background->red & 0xff);
  169454. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169455. *(sp + 3) = (png_byte)(background->green & 0xff);
  169456. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169457. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169458. }
  169459. else
  169460. {
  169461. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169462. *sp = (png_byte)((v >> 8) & 0xff);
  169463. *(sp + 1) = (png_byte)(v & 0xff);
  169464. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169465. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169466. *(sp + 3) = (png_byte)(v & 0xff);
  169467. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169468. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169469. *(sp + 5) = (png_byte)(v & 0xff);
  169470. }
  169471. }
  169472. }
  169473. else
  169474. #endif
  169475. {
  169476. sp = row;
  169477. for (i = 0; i < row_width; i++, sp += 6)
  169478. {
  169479. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169480. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169481. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169482. if (r == trans_values->red && g == trans_values->green &&
  169483. b == trans_values->blue)
  169484. {
  169485. *sp = (png_byte)((background->red >> 8) & 0xff);
  169486. *(sp + 1) = (png_byte)(background->red & 0xff);
  169487. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169488. *(sp + 3) = (png_byte)(background->green & 0xff);
  169489. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169490. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169491. }
  169492. }
  169493. }
  169494. }
  169495. break;
  169496. }
  169497. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169498. {
  169499. if (row_info->bit_depth == 8)
  169500. {
  169501. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169502. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169503. gamma_table != NULL)
  169504. {
  169505. sp = row;
  169506. dp = row;
  169507. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169508. {
  169509. png_uint_16 a = *(sp + 1);
  169510. if (a == 0xff)
  169511. {
  169512. *dp = gamma_table[*sp];
  169513. }
  169514. else if (a == 0)
  169515. {
  169516. *dp = (png_byte)background->gray;
  169517. }
  169518. else
  169519. {
  169520. png_byte v, w;
  169521. v = gamma_to_1[*sp];
  169522. png_composite(w, v, a, background_1->gray);
  169523. *dp = gamma_from_1[w];
  169524. }
  169525. }
  169526. }
  169527. else
  169528. #endif
  169529. {
  169530. sp = row;
  169531. dp = row;
  169532. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169533. {
  169534. png_byte a = *(sp + 1);
  169535. if (a == 0xff)
  169536. {
  169537. *dp = *sp;
  169538. }
  169539. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169540. else if (a == 0)
  169541. {
  169542. *dp = (png_byte)background->gray;
  169543. }
  169544. else
  169545. {
  169546. png_composite(*dp, *sp, a, background_1->gray);
  169547. }
  169548. #else
  169549. *dp = (png_byte)background->gray;
  169550. #endif
  169551. }
  169552. }
  169553. }
  169554. else /* if (png_ptr->bit_depth == 16) */
  169555. {
  169556. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169557. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169558. gamma_16_to_1 != NULL)
  169559. {
  169560. sp = row;
  169561. dp = row;
  169562. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169563. {
  169564. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169565. if (a == (png_uint_16)0xffff)
  169566. {
  169567. png_uint_16 v;
  169568. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169569. *dp = (png_byte)((v >> 8) & 0xff);
  169570. *(dp + 1) = (png_byte)(v & 0xff);
  169571. }
  169572. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169573. else if (a == 0)
  169574. #else
  169575. else
  169576. #endif
  169577. {
  169578. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169579. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169580. }
  169581. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169582. else
  169583. {
  169584. png_uint_16 g, v, w;
  169585. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169586. png_composite_16(v, g, a, background_1->gray);
  169587. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169588. *dp = (png_byte)((w >> 8) & 0xff);
  169589. *(dp + 1) = (png_byte)(w & 0xff);
  169590. }
  169591. #endif
  169592. }
  169593. }
  169594. else
  169595. #endif
  169596. {
  169597. sp = row;
  169598. dp = row;
  169599. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169600. {
  169601. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169602. if (a == (png_uint_16)0xffff)
  169603. {
  169604. png_memcpy(dp, sp, 2);
  169605. }
  169606. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169607. else if (a == 0)
  169608. #else
  169609. else
  169610. #endif
  169611. {
  169612. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169613. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169614. }
  169615. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169616. else
  169617. {
  169618. png_uint_16 g, v;
  169619. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169620. png_composite_16(v, g, a, background_1->gray);
  169621. *dp = (png_byte)((v >> 8) & 0xff);
  169622. *(dp + 1) = (png_byte)(v & 0xff);
  169623. }
  169624. #endif
  169625. }
  169626. }
  169627. }
  169628. break;
  169629. }
  169630. case PNG_COLOR_TYPE_RGB_ALPHA:
  169631. {
  169632. if (row_info->bit_depth == 8)
  169633. {
  169634. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169635. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169636. gamma_table != NULL)
  169637. {
  169638. sp = row;
  169639. dp = row;
  169640. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169641. {
  169642. png_byte a = *(sp + 3);
  169643. if (a == 0xff)
  169644. {
  169645. *dp = gamma_table[*sp];
  169646. *(dp + 1) = gamma_table[*(sp + 1)];
  169647. *(dp + 2) = gamma_table[*(sp + 2)];
  169648. }
  169649. else if (a == 0)
  169650. {
  169651. *dp = (png_byte)background->red;
  169652. *(dp + 1) = (png_byte)background->green;
  169653. *(dp + 2) = (png_byte)background->blue;
  169654. }
  169655. else
  169656. {
  169657. png_byte v, w;
  169658. v = gamma_to_1[*sp];
  169659. png_composite(w, v, a, background_1->red);
  169660. *dp = gamma_from_1[w];
  169661. v = gamma_to_1[*(sp + 1)];
  169662. png_composite(w, v, a, background_1->green);
  169663. *(dp + 1) = gamma_from_1[w];
  169664. v = gamma_to_1[*(sp + 2)];
  169665. png_composite(w, v, a, background_1->blue);
  169666. *(dp + 2) = gamma_from_1[w];
  169667. }
  169668. }
  169669. }
  169670. else
  169671. #endif
  169672. {
  169673. sp = row;
  169674. dp = row;
  169675. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169676. {
  169677. png_byte a = *(sp + 3);
  169678. if (a == 0xff)
  169679. {
  169680. *dp = *sp;
  169681. *(dp + 1) = *(sp + 1);
  169682. *(dp + 2) = *(sp + 2);
  169683. }
  169684. else if (a == 0)
  169685. {
  169686. *dp = (png_byte)background->red;
  169687. *(dp + 1) = (png_byte)background->green;
  169688. *(dp + 2) = (png_byte)background->blue;
  169689. }
  169690. else
  169691. {
  169692. png_composite(*dp, *sp, a, background->red);
  169693. png_composite(*(dp + 1), *(sp + 1), a,
  169694. background->green);
  169695. png_composite(*(dp + 2), *(sp + 2), a,
  169696. background->blue);
  169697. }
  169698. }
  169699. }
  169700. }
  169701. else /* if (row_info->bit_depth == 16) */
  169702. {
  169703. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169704. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169705. gamma_16_to_1 != NULL)
  169706. {
  169707. sp = row;
  169708. dp = row;
  169709. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169710. {
  169711. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169712. << 8) + (png_uint_16)(*(sp + 7)));
  169713. if (a == (png_uint_16)0xffff)
  169714. {
  169715. png_uint_16 v;
  169716. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169717. *dp = (png_byte)((v >> 8) & 0xff);
  169718. *(dp + 1) = (png_byte)(v & 0xff);
  169719. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169720. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169721. *(dp + 3) = (png_byte)(v & 0xff);
  169722. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169723. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169724. *(dp + 5) = (png_byte)(v & 0xff);
  169725. }
  169726. else if (a == 0)
  169727. {
  169728. *dp = (png_byte)((background->red >> 8) & 0xff);
  169729. *(dp + 1) = (png_byte)(background->red & 0xff);
  169730. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169731. *(dp + 3) = (png_byte)(background->green & 0xff);
  169732. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169733. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169734. }
  169735. else
  169736. {
  169737. png_uint_16 v, w, x;
  169738. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169739. png_composite_16(w, v, a, background_1->red);
  169740. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169741. *dp = (png_byte)((x >> 8) & 0xff);
  169742. *(dp + 1) = (png_byte)(x & 0xff);
  169743. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169744. png_composite_16(w, v, a, background_1->green);
  169745. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169746. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169747. *(dp + 3) = (png_byte)(x & 0xff);
  169748. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169749. png_composite_16(w, v, a, background_1->blue);
  169750. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169751. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169752. *(dp + 5) = (png_byte)(x & 0xff);
  169753. }
  169754. }
  169755. }
  169756. else
  169757. #endif
  169758. {
  169759. sp = row;
  169760. dp = row;
  169761. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169762. {
  169763. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169764. << 8) + (png_uint_16)(*(sp + 7)));
  169765. if (a == (png_uint_16)0xffff)
  169766. {
  169767. png_memcpy(dp, sp, 6);
  169768. }
  169769. else if (a == 0)
  169770. {
  169771. *dp = (png_byte)((background->red >> 8) & 0xff);
  169772. *(dp + 1) = (png_byte)(background->red & 0xff);
  169773. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169774. *(dp + 3) = (png_byte)(background->green & 0xff);
  169775. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169776. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169777. }
  169778. else
  169779. {
  169780. png_uint_16 v;
  169781. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169782. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169783. + *(sp + 3));
  169784. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169785. + *(sp + 5));
  169786. png_composite_16(v, r, a, background->red);
  169787. *dp = (png_byte)((v >> 8) & 0xff);
  169788. *(dp + 1) = (png_byte)(v & 0xff);
  169789. png_composite_16(v, g, a, background->green);
  169790. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169791. *(dp + 3) = (png_byte)(v & 0xff);
  169792. png_composite_16(v, b, a, background->blue);
  169793. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169794. *(dp + 5) = (png_byte)(v & 0xff);
  169795. }
  169796. }
  169797. }
  169798. }
  169799. break;
  169800. }
  169801. }
  169802. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169803. {
  169804. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169805. row_info->channels--;
  169806. row_info->pixel_depth = (png_byte)(row_info->channels *
  169807. row_info->bit_depth);
  169808. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169809. }
  169810. }
  169811. }
  169812. #endif
  169813. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169814. void /* PRIVATE */
  169815. png_do_gamma(png_row_infop row_info, png_bytep row,
  169816. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169817. int gamma_shift)
  169818. {
  169819. png_bytep sp;
  169820. png_uint_32 i;
  169821. png_uint_32 row_width=row_info->width;
  169822. png_debug(1, "in png_do_gamma\n");
  169823. if (
  169824. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169825. row != NULL && row_info != NULL &&
  169826. #endif
  169827. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169828. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169829. {
  169830. switch (row_info->color_type)
  169831. {
  169832. case PNG_COLOR_TYPE_RGB:
  169833. {
  169834. if (row_info->bit_depth == 8)
  169835. {
  169836. sp = row;
  169837. for (i = 0; i < row_width; i++)
  169838. {
  169839. *sp = gamma_table[*sp];
  169840. sp++;
  169841. *sp = gamma_table[*sp];
  169842. sp++;
  169843. *sp = gamma_table[*sp];
  169844. sp++;
  169845. }
  169846. }
  169847. else /* if (row_info->bit_depth == 16) */
  169848. {
  169849. sp = row;
  169850. for (i = 0; i < row_width; i++)
  169851. {
  169852. png_uint_16 v;
  169853. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169854. *sp = (png_byte)((v >> 8) & 0xff);
  169855. *(sp + 1) = (png_byte)(v & 0xff);
  169856. sp += 2;
  169857. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169858. *sp = (png_byte)((v >> 8) & 0xff);
  169859. *(sp + 1) = (png_byte)(v & 0xff);
  169860. sp += 2;
  169861. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169862. *sp = (png_byte)((v >> 8) & 0xff);
  169863. *(sp + 1) = (png_byte)(v & 0xff);
  169864. sp += 2;
  169865. }
  169866. }
  169867. break;
  169868. }
  169869. case PNG_COLOR_TYPE_RGB_ALPHA:
  169870. {
  169871. if (row_info->bit_depth == 8)
  169872. {
  169873. sp = row;
  169874. for (i = 0; i < row_width; i++)
  169875. {
  169876. *sp = gamma_table[*sp];
  169877. sp++;
  169878. *sp = gamma_table[*sp];
  169879. sp++;
  169880. *sp = gamma_table[*sp];
  169881. sp++;
  169882. sp++;
  169883. }
  169884. }
  169885. else /* if (row_info->bit_depth == 16) */
  169886. {
  169887. sp = row;
  169888. for (i = 0; i < row_width; i++)
  169889. {
  169890. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169891. *sp = (png_byte)((v >> 8) & 0xff);
  169892. *(sp + 1) = (png_byte)(v & 0xff);
  169893. sp += 2;
  169894. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169895. *sp = (png_byte)((v >> 8) & 0xff);
  169896. *(sp + 1) = (png_byte)(v & 0xff);
  169897. sp += 2;
  169898. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169899. *sp = (png_byte)((v >> 8) & 0xff);
  169900. *(sp + 1) = (png_byte)(v & 0xff);
  169901. sp += 4;
  169902. }
  169903. }
  169904. break;
  169905. }
  169906. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169907. {
  169908. if (row_info->bit_depth == 8)
  169909. {
  169910. sp = row;
  169911. for (i = 0; i < row_width; i++)
  169912. {
  169913. *sp = gamma_table[*sp];
  169914. sp += 2;
  169915. }
  169916. }
  169917. else /* if (row_info->bit_depth == 16) */
  169918. {
  169919. sp = row;
  169920. for (i = 0; i < row_width; i++)
  169921. {
  169922. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169923. *sp = (png_byte)((v >> 8) & 0xff);
  169924. *(sp + 1) = (png_byte)(v & 0xff);
  169925. sp += 4;
  169926. }
  169927. }
  169928. break;
  169929. }
  169930. case PNG_COLOR_TYPE_GRAY:
  169931. {
  169932. if (row_info->bit_depth == 2)
  169933. {
  169934. sp = row;
  169935. for (i = 0; i < row_width; i += 4)
  169936. {
  169937. int a = *sp & 0xc0;
  169938. int b = *sp & 0x30;
  169939. int c = *sp & 0x0c;
  169940. int d = *sp & 0x03;
  169941. *sp = (png_byte)(
  169942. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  169943. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  169944. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  169945. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  169946. sp++;
  169947. }
  169948. }
  169949. if (row_info->bit_depth == 4)
  169950. {
  169951. sp = row;
  169952. for (i = 0; i < row_width; i += 2)
  169953. {
  169954. int msb = *sp & 0xf0;
  169955. int lsb = *sp & 0x0f;
  169956. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  169957. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  169958. sp++;
  169959. }
  169960. }
  169961. else if (row_info->bit_depth == 8)
  169962. {
  169963. sp = row;
  169964. for (i = 0; i < row_width; i++)
  169965. {
  169966. *sp = gamma_table[*sp];
  169967. sp++;
  169968. }
  169969. }
  169970. else if (row_info->bit_depth == 16)
  169971. {
  169972. sp = row;
  169973. for (i = 0; i < row_width; i++)
  169974. {
  169975. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169976. *sp = (png_byte)((v >> 8) & 0xff);
  169977. *(sp + 1) = (png_byte)(v & 0xff);
  169978. sp += 2;
  169979. }
  169980. }
  169981. break;
  169982. }
  169983. }
  169984. }
  169985. }
  169986. #endif
  169987. #if defined(PNG_READ_EXPAND_SUPPORTED)
  169988. void /* PRIVATE */
  169989. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  169990. png_colorp palette, png_bytep trans, int num_trans)
  169991. {
  169992. int shift, value;
  169993. png_bytep sp, dp;
  169994. png_uint_32 i;
  169995. png_uint_32 row_width=row_info->width;
  169996. png_debug(1, "in png_do_expand_palette\n");
  169997. if (
  169998. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169999. row != NULL && row_info != NULL &&
  170000. #endif
  170001. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170002. {
  170003. if (row_info->bit_depth < 8)
  170004. {
  170005. switch (row_info->bit_depth)
  170006. {
  170007. case 1:
  170008. {
  170009. sp = row + (png_size_t)((row_width - 1) >> 3);
  170010. dp = row + (png_size_t)row_width - 1;
  170011. shift = 7 - (int)((row_width + 7) & 0x07);
  170012. for (i = 0; i < row_width; i++)
  170013. {
  170014. if ((*sp >> shift) & 0x01)
  170015. *dp = 1;
  170016. else
  170017. *dp = 0;
  170018. if (shift == 7)
  170019. {
  170020. shift = 0;
  170021. sp--;
  170022. }
  170023. else
  170024. shift++;
  170025. dp--;
  170026. }
  170027. break;
  170028. }
  170029. case 2:
  170030. {
  170031. sp = row + (png_size_t)((row_width - 1) >> 2);
  170032. dp = row + (png_size_t)row_width - 1;
  170033. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170034. for (i = 0; i < row_width; i++)
  170035. {
  170036. value = (*sp >> shift) & 0x03;
  170037. *dp = (png_byte)value;
  170038. if (shift == 6)
  170039. {
  170040. shift = 0;
  170041. sp--;
  170042. }
  170043. else
  170044. shift += 2;
  170045. dp--;
  170046. }
  170047. break;
  170048. }
  170049. case 4:
  170050. {
  170051. sp = row + (png_size_t)((row_width - 1) >> 1);
  170052. dp = row + (png_size_t)row_width - 1;
  170053. shift = (int)((row_width & 0x01) << 2);
  170054. for (i = 0; i < row_width; i++)
  170055. {
  170056. value = (*sp >> shift) & 0x0f;
  170057. *dp = (png_byte)value;
  170058. if (shift == 4)
  170059. {
  170060. shift = 0;
  170061. sp--;
  170062. }
  170063. else
  170064. shift += 4;
  170065. dp--;
  170066. }
  170067. break;
  170068. }
  170069. }
  170070. row_info->bit_depth = 8;
  170071. row_info->pixel_depth = 8;
  170072. row_info->rowbytes = row_width;
  170073. }
  170074. switch (row_info->bit_depth)
  170075. {
  170076. case 8:
  170077. {
  170078. if (trans != NULL)
  170079. {
  170080. sp = row + (png_size_t)row_width - 1;
  170081. dp = row + (png_size_t)(row_width << 2) - 1;
  170082. for (i = 0; i < row_width; i++)
  170083. {
  170084. if ((int)(*sp) >= num_trans)
  170085. *dp-- = 0xff;
  170086. else
  170087. *dp-- = trans[*sp];
  170088. *dp-- = palette[*sp].blue;
  170089. *dp-- = palette[*sp].green;
  170090. *dp-- = palette[*sp].red;
  170091. sp--;
  170092. }
  170093. row_info->bit_depth = 8;
  170094. row_info->pixel_depth = 32;
  170095. row_info->rowbytes = row_width * 4;
  170096. row_info->color_type = 6;
  170097. row_info->channels = 4;
  170098. }
  170099. else
  170100. {
  170101. sp = row + (png_size_t)row_width - 1;
  170102. dp = row + (png_size_t)(row_width * 3) - 1;
  170103. for (i = 0; i < row_width; i++)
  170104. {
  170105. *dp-- = palette[*sp].blue;
  170106. *dp-- = palette[*sp].green;
  170107. *dp-- = palette[*sp].red;
  170108. sp--;
  170109. }
  170110. row_info->bit_depth = 8;
  170111. row_info->pixel_depth = 24;
  170112. row_info->rowbytes = row_width * 3;
  170113. row_info->color_type = 2;
  170114. row_info->channels = 3;
  170115. }
  170116. break;
  170117. }
  170118. }
  170119. }
  170120. }
  170121. void /* PRIVATE */
  170122. png_do_expand(png_row_infop row_info, png_bytep row,
  170123. png_color_16p trans_value)
  170124. {
  170125. int shift, value;
  170126. png_bytep sp, dp;
  170127. png_uint_32 i;
  170128. png_uint_32 row_width=row_info->width;
  170129. png_debug(1, "in png_do_expand\n");
  170130. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170131. if (row != NULL && row_info != NULL)
  170132. #endif
  170133. {
  170134. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170135. {
  170136. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170137. if (row_info->bit_depth < 8)
  170138. {
  170139. switch (row_info->bit_depth)
  170140. {
  170141. case 1:
  170142. {
  170143. gray = (png_uint_16)((gray&0x01)*0xff);
  170144. sp = row + (png_size_t)((row_width - 1) >> 3);
  170145. dp = row + (png_size_t)row_width - 1;
  170146. shift = 7 - (int)((row_width + 7) & 0x07);
  170147. for (i = 0; i < row_width; i++)
  170148. {
  170149. if ((*sp >> shift) & 0x01)
  170150. *dp = 0xff;
  170151. else
  170152. *dp = 0;
  170153. if (shift == 7)
  170154. {
  170155. shift = 0;
  170156. sp--;
  170157. }
  170158. else
  170159. shift++;
  170160. dp--;
  170161. }
  170162. break;
  170163. }
  170164. case 2:
  170165. {
  170166. gray = (png_uint_16)((gray&0x03)*0x55);
  170167. sp = row + (png_size_t)((row_width - 1) >> 2);
  170168. dp = row + (png_size_t)row_width - 1;
  170169. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170170. for (i = 0; i < row_width; i++)
  170171. {
  170172. value = (*sp >> shift) & 0x03;
  170173. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170174. (value << 6));
  170175. if (shift == 6)
  170176. {
  170177. shift = 0;
  170178. sp--;
  170179. }
  170180. else
  170181. shift += 2;
  170182. dp--;
  170183. }
  170184. break;
  170185. }
  170186. case 4:
  170187. {
  170188. gray = (png_uint_16)((gray&0x0f)*0x11);
  170189. sp = row + (png_size_t)((row_width - 1) >> 1);
  170190. dp = row + (png_size_t)row_width - 1;
  170191. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170192. for (i = 0; i < row_width; i++)
  170193. {
  170194. value = (*sp >> shift) & 0x0f;
  170195. *dp = (png_byte)(value | (value << 4));
  170196. if (shift == 4)
  170197. {
  170198. shift = 0;
  170199. sp--;
  170200. }
  170201. else
  170202. shift = 4;
  170203. dp--;
  170204. }
  170205. break;
  170206. }
  170207. }
  170208. row_info->bit_depth = 8;
  170209. row_info->pixel_depth = 8;
  170210. row_info->rowbytes = row_width;
  170211. }
  170212. if (trans_value != NULL)
  170213. {
  170214. if (row_info->bit_depth == 8)
  170215. {
  170216. gray = gray & 0xff;
  170217. sp = row + (png_size_t)row_width - 1;
  170218. dp = row + (png_size_t)(row_width << 1) - 1;
  170219. for (i = 0; i < row_width; i++)
  170220. {
  170221. if (*sp == gray)
  170222. *dp-- = 0;
  170223. else
  170224. *dp-- = 0xff;
  170225. *dp-- = *sp--;
  170226. }
  170227. }
  170228. else if (row_info->bit_depth == 16)
  170229. {
  170230. png_byte gray_high = (gray >> 8) & 0xff;
  170231. png_byte gray_low = gray & 0xff;
  170232. sp = row + row_info->rowbytes - 1;
  170233. dp = row + (row_info->rowbytes << 1) - 1;
  170234. for (i = 0; i < row_width; i++)
  170235. {
  170236. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170237. {
  170238. *dp-- = 0;
  170239. *dp-- = 0;
  170240. }
  170241. else
  170242. {
  170243. *dp-- = 0xff;
  170244. *dp-- = 0xff;
  170245. }
  170246. *dp-- = *sp--;
  170247. *dp-- = *sp--;
  170248. }
  170249. }
  170250. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170251. row_info->channels = 2;
  170252. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170253. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170254. row_width);
  170255. }
  170256. }
  170257. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170258. {
  170259. if (row_info->bit_depth == 8)
  170260. {
  170261. png_byte red = trans_value->red & 0xff;
  170262. png_byte green = trans_value->green & 0xff;
  170263. png_byte blue = trans_value->blue & 0xff;
  170264. sp = row + (png_size_t)row_info->rowbytes - 1;
  170265. dp = row + (png_size_t)(row_width << 2) - 1;
  170266. for (i = 0; i < row_width; i++)
  170267. {
  170268. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170269. *dp-- = 0;
  170270. else
  170271. *dp-- = 0xff;
  170272. *dp-- = *sp--;
  170273. *dp-- = *sp--;
  170274. *dp-- = *sp--;
  170275. }
  170276. }
  170277. else if (row_info->bit_depth == 16)
  170278. {
  170279. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170280. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170281. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170282. png_byte red_low = trans_value->red & 0xff;
  170283. png_byte green_low = trans_value->green & 0xff;
  170284. png_byte blue_low = trans_value->blue & 0xff;
  170285. sp = row + row_info->rowbytes - 1;
  170286. dp = row + (png_size_t)(row_width << 3) - 1;
  170287. for (i = 0; i < row_width; i++)
  170288. {
  170289. if (*(sp - 5) == red_high &&
  170290. *(sp - 4) == red_low &&
  170291. *(sp - 3) == green_high &&
  170292. *(sp - 2) == green_low &&
  170293. *(sp - 1) == blue_high &&
  170294. *(sp ) == blue_low)
  170295. {
  170296. *dp-- = 0;
  170297. *dp-- = 0;
  170298. }
  170299. else
  170300. {
  170301. *dp-- = 0xff;
  170302. *dp-- = 0xff;
  170303. }
  170304. *dp-- = *sp--;
  170305. *dp-- = *sp--;
  170306. *dp-- = *sp--;
  170307. *dp-- = *sp--;
  170308. *dp-- = *sp--;
  170309. *dp-- = *sp--;
  170310. }
  170311. }
  170312. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170313. row_info->channels = 4;
  170314. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170315. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170316. }
  170317. }
  170318. }
  170319. #endif
  170320. #if defined(PNG_READ_DITHER_SUPPORTED)
  170321. void /* PRIVATE */
  170322. png_do_dither(png_row_infop row_info, png_bytep row,
  170323. png_bytep palette_lookup, png_bytep dither_lookup)
  170324. {
  170325. png_bytep sp, dp;
  170326. png_uint_32 i;
  170327. png_uint_32 row_width=row_info->width;
  170328. png_debug(1, "in png_do_dither\n");
  170329. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170330. if (row != NULL && row_info != NULL)
  170331. #endif
  170332. {
  170333. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170334. palette_lookup && row_info->bit_depth == 8)
  170335. {
  170336. int r, g, b, p;
  170337. sp = row;
  170338. dp = row;
  170339. for (i = 0; i < row_width; i++)
  170340. {
  170341. r = *sp++;
  170342. g = *sp++;
  170343. b = *sp++;
  170344. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170345. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170346. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170347. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170348. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170349. (PNG_DITHER_BLUE_BITS)) |
  170350. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170351. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170352. *dp++ = palette_lookup[p];
  170353. }
  170354. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170355. row_info->channels = 1;
  170356. row_info->pixel_depth = row_info->bit_depth;
  170357. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170358. }
  170359. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170360. palette_lookup != NULL && row_info->bit_depth == 8)
  170361. {
  170362. int r, g, b, p;
  170363. sp = row;
  170364. dp = row;
  170365. for (i = 0; i < row_width; i++)
  170366. {
  170367. r = *sp++;
  170368. g = *sp++;
  170369. b = *sp++;
  170370. sp++;
  170371. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170372. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170373. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170374. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170375. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170376. (PNG_DITHER_BLUE_BITS)) |
  170377. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170378. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170379. *dp++ = palette_lookup[p];
  170380. }
  170381. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170382. row_info->channels = 1;
  170383. row_info->pixel_depth = row_info->bit_depth;
  170384. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170385. }
  170386. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170387. dither_lookup && row_info->bit_depth == 8)
  170388. {
  170389. sp = row;
  170390. for (i = 0; i < row_width; i++, sp++)
  170391. {
  170392. *sp = dither_lookup[*sp];
  170393. }
  170394. }
  170395. }
  170396. }
  170397. #endif
  170398. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170399. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170400. static PNG_CONST int png_gamma_shift[] =
  170401. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170402. void /* PRIVATE */
  170403. png_build_gamma_table(png_structp png_ptr)
  170404. {
  170405. png_debug(1, "in png_build_gamma_table\n");
  170406. if (png_ptr->bit_depth <= 8)
  170407. {
  170408. int i;
  170409. double g;
  170410. if (png_ptr->screen_gamma > .000001)
  170411. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170412. else
  170413. g = 1.0;
  170414. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170415. (png_uint_32)256);
  170416. for (i = 0; i < 256; i++)
  170417. {
  170418. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170419. g) * 255.0 + .5);
  170420. }
  170421. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170422. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170423. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170424. {
  170425. g = 1.0 / (png_ptr->gamma);
  170426. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170427. (png_uint_32)256);
  170428. for (i = 0; i < 256; i++)
  170429. {
  170430. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170431. g) * 255.0 + .5);
  170432. }
  170433. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170434. (png_uint_32)256);
  170435. if(png_ptr->screen_gamma > 0.000001)
  170436. g = 1.0 / png_ptr->screen_gamma;
  170437. else
  170438. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170439. for (i = 0; i < 256; i++)
  170440. {
  170441. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170442. g) * 255.0 + .5);
  170443. }
  170444. }
  170445. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170446. }
  170447. else
  170448. {
  170449. double g;
  170450. int i, j, shift, num;
  170451. int sig_bit;
  170452. png_uint_32 ig;
  170453. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170454. {
  170455. sig_bit = (int)png_ptr->sig_bit.red;
  170456. if ((int)png_ptr->sig_bit.green > sig_bit)
  170457. sig_bit = png_ptr->sig_bit.green;
  170458. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170459. sig_bit = png_ptr->sig_bit.blue;
  170460. }
  170461. else
  170462. {
  170463. sig_bit = (int)png_ptr->sig_bit.gray;
  170464. }
  170465. if (sig_bit > 0)
  170466. shift = 16 - sig_bit;
  170467. else
  170468. shift = 0;
  170469. if (png_ptr->transformations & PNG_16_TO_8)
  170470. {
  170471. if (shift < (16 - PNG_MAX_GAMMA_8))
  170472. shift = (16 - PNG_MAX_GAMMA_8);
  170473. }
  170474. if (shift > 8)
  170475. shift = 8;
  170476. if (shift < 0)
  170477. shift = 0;
  170478. png_ptr->gamma_shift = (png_byte)shift;
  170479. num = (1 << (8 - shift));
  170480. if (png_ptr->screen_gamma > .000001)
  170481. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170482. else
  170483. g = 1.0;
  170484. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170485. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170486. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170487. {
  170488. double fin, fout;
  170489. png_uint_32 last, max;
  170490. for (i = 0; i < num; i++)
  170491. {
  170492. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170493. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170494. }
  170495. g = 1.0 / g;
  170496. last = 0;
  170497. for (i = 0; i < 256; i++)
  170498. {
  170499. fout = ((double)i + 0.5) / 256.0;
  170500. fin = pow(fout, g);
  170501. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170502. while (last <= max)
  170503. {
  170504. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170505. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170506. (png_uint_16)i | ((png_uint_16)i << 8));
  170507. last++;
  170508. }
  170509. }
  170510. while (last < ((png_uint_32)num << 8))
  170511. {
  170512. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170513. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170514. last++;
  170515. }
  170516. }
  170517. else
  170518. {
  170519. for (i = 0; i < num; i++)
  170520. {
  170521. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170522. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170523. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170524. for (j = 0; j < 256; j++)
  170525. {
  170526. png_ptr->gamma_16_table[i][j] =
  170527. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170528. 65535.0, g) * 65535.0 + .5);
  170529. }
  170530. }
  170531. }
  170532. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170533. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170534. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170535. {
  170536. g = 1.0 / (png_ptr->gamma);
  170537. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170538. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170539. for (i = 0; i < num; i++)
  170540. {
  170541. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170542. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170543. ig = (((png_uint_32)i *
  170544. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170545. for (j = 0; j < 256; j++)
  170546. {
  170547. png_ptr->gamma_16_to_1[i][j] =
  170548. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170549. 65535.0, g) * 65535.0 + .5);
  170550. }
  170551. }
  170552. if(png_ptr->screen_gamma > 0.000001)
  170553. g = 1.0 / png_ptr->screen_gamma;
  170554. else
  170555. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170556. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170557. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170558. for (i = 0; i < num; i++)
  170559. {
  170560. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170561. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170562. ig = (((png_uint_32)i *
  170563. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170564. for (j = 0; j < 256; j++)
  170565. {
  170566. png_ptr->gamma_16_from_1[i][j] =
  170567. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170568. 65535.0, g) * 65535.0 + .5);
  170569. }
  170570. }
  170571. }
  170572. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170573. }
  170574. }
  170575. #endif
  170576. #endif
  170577. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170578. void /* PRIVATE */
  170579. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170580. {
  170581. png_debug(1, "in png_do_read_intrapixel\n");
  170582. if (
  170583. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170584. row != NULL && row_info != NULL &&
  170585. #endif
  170586. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170587. {
  170588. int bytes_per_pixel;
  170589. png_uint_32 row_width = row_info->width;
  170590. if (row_info->bit_depth == 8)
  170591. {
  170592. png_bytep rp;
  170593. png_uint_32 i;
  170594. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170595. bytes_per_pixel = 3;
  170596. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170597. bytes_per_pixel = 4;
  170598. else
  170599. return;
  170600. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170601. {
  170602. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170603. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170604. }
  170605. }
  170606. else if (row_info->bit_depth == 16)
  170607. {
  170608. png_bytep rp;
  170609. png_uint_32 i;
  170610. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170611. bytes_per_pixel = 6;
  170612. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170613. bytes_per_pixel = 8;
  170614. else
  170615. return;
  170616. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170617. {
  170618. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170619. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170620. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170621. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170622. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170623. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170624. *(rp+1) = (png_byte)(red & 0xff);
  170625. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170626. *(rp+5) = (png_byte)(blue & 0xff);
  170627. }
  170628. }
  170629. }
  170630. }
  170631. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170632. #endif /* PNG_READ_SUPPORTED */
  170633. /*** End of inlined file: pngrtran.c ***/
  170634. /*** Start of inlined file: pngrutil.c ***/
  170635. #define PNG_INTERNAL
  170636. #if defined(PNG_READ_SUPPORTED)
  170637. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170638. # define WIN32_WCE_OLD
  170639. #endif
  170640. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170641. # if defined(WIN32_WCE_OLD)
  170642. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170643. {
  170644. double result = 0;
  170645. int len;
  170646. wchar_t *str, *end;
  170647. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170648. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170649. if ( NULL != str )
  170650. {
  170651. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170652. result = wcstod(str, &end);
  170653. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170654. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170655. png_free(png_ptr, str);
  170656. }
  170657. return result;
  170658. }
  170659. # else
  170660. # define png_strtod(p,a,b) strtod(a,b)
  170661. # endif
  170662. #endif
  170663. png_uint_32 PNGAPI
  170664. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170665. {
  170666. png_uint_32 i = png_get_uint_32(buf);
  170667. if (i > PNG_UINT_31_MAX)
  170668. png_error(png_ptr, "PNG unsigned integer out of range.");
  170669. return (i);
  170670. }
  170671. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170672. png_uint_32 PNGAPI
  170673. png_get_uint_32(png_bytep buf)
  170674. {
  170675. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170676. ((png_uint_32)(*(buf + 1)) << 16) +
  170677. ((png_uint_32)(*(buf + 2)) << 8) +
  170678. (png_uint_32)(*(buf + 3));
  170679. return (i);
  170680. }
  170681. png_int_32 PNGAPI
  170682. png_get_int_32(png_bytep buf)
  170683. {
  170684. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170685. ((png_int_32)(*(buf + 1)) << 16) +
  170686. ((png_int_32)(*(buf + 2)) << 8) +
  170687. (png_int_32)(*(buf + 3));
  170688. return (i);
  170689. }
  170690. png_uint_16 PNGAPI
  170691. png_get_uint_16(png_bytep buf)
  170692. {
  170693. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170694. (png_uint_16)(*(buf + 1)));
  170695. return (i);
  170696. }
  170697. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170698. void /* PRIVATE */
  170699. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170700. {
  170701. if(png_ptr == NULL) return;
  170702. png_read_data(png_ptr, buf, length);
  170703. png_calculate_crc(png_ptr, buf, length);
  170704. }
  170705. int /* PRIVATE */
  170706. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170707. {
  170708. png_size_t i;
  170709. png_size_t istop = png_ptr->zbuf_size;
  170710. for (i = (png_size_t)skip; i > istop; i -= istop)
  170711. {
  170712. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170713. }
  170714. if (i)
  170715. {
  170716. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170717. }
  170718. if (png_crc_error(png_ptr))
  170719. {
  170720. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170721. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170722. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170723. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170724. {
  170725. png_chunk_warning(png_ptr, "CRC error");
  170726. }
  170727. else
  170728. {
  170729. png_chunk_error(png_ptr, "CRC error");
  170730. }
  170731. return (1);
  170732. }
  170733. return (0);
  170734. }
  170735. int /* PRIVATE */
  170736. png_crc_error(png_structp png_ptr)
  170737. {
  170738. png_byte crc_bytes[4];
  170739. png_uint_32 crc;
  170740. int need_crc = 1;
  170741. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170742. {
  170743. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170744. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170745. need_crc = 0;
  170746. }
  170747. else /* critical */
  170748. {
  170749. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170750. need_crc = 0;
  170751. }
  170752. png_read_data(png_ptr, crc_bytes, 4);
  170753. if (need_crc)
  170754. {
  170755. crc = png_get_uint_32(crc_bytes);
  170756. return ((int)(crc != png_ptr->crc));
  170757. }
  170758. else
  170759. return (0);
  170760. }
  170761. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170762. defined(PNG_READ_iCCP_SUPPORTED)
  170763. png_charp /* PRIVATE */
  170764. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170765. png_charp chunkdata, png_size_t chunklength,
  170766. png_size_t prefix_size, png_size_t *newlength)
  170767. {
  170768. static PNG_CONST char msg[] = "Error decoding compressed text";
  170769. png_charp text;
  170770. png_size_t text_size;
  170771. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170772. {
  170773. int ret = Z_OK;
  170774. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170775. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170776. png_ptr->zstream.next_out = png_ptr->zbuf;
  170777. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170778. text_size = 0;
  170779. text = NULL;
  170780. while (png_ptr->zstream.avail_in)
  170781. {
  170782. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170783. if (ret != Z_OK && ret != Z_STREAM_END)
  170784. {
  170785. if (png_ptr->zstream.msg != NULL)
  170786. png_warning(png_ptr, png_ptr->zstream.msg);
  170787. else
  170788. png_warning(png_ptr, msg);
  170789. inflateReset(&png_ptr->zstream);
  170790. png_ptr->zstream.avail_in = 0;
  170791. if (text == NULL)
  170792. {
  170793. text_size = prefix_size + png_sizeof(msg) + 1;
  170794. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170795. if (text == NULL)
  170796. {
  170797. png_free(png_ptr,chunkdata);
  170798. png_error(png_ptr,"Not enough memory to decompress chunk");
  170799. }
  170800. png_memcpy(text, chunkdata, prefix_size);
  170801. }
  170802. text[text_size - 1] = 0x00;
  170803. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170804. text_size = png_sizeof(msg) > text_size ? text_size :
  170805. png_sizeof(msg);
  170806. png_memcpy(text + prefix_size, msg, text_size + 1);
  170807. break;
  170808. }
  170809. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170810. {
  170811. if (text == NULL)
  170812. {
  170813. text_size = prefix_size +
  170814. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170815. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170816. if (text == NULL)
  170817. {
  170818. png_free(png_ptr,chunkdata);
  170819. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170820. }
  170821. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170822. text_size - prefix_size);
  170823. png_memcpy(text, chunkdata, prefix_size);
  170824. *(text + text_size) = 0x00;
  170825. }
  170826. else
  170827. {
  170828. png_charp tmp;
  170829. tmp = text;
  170830. text = (png_charp)png_malloc_warn(png_ptr,
  170831. (png_uint_32)(text_size +
  170832. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170833. if (text == NULL)
  170834. {
  170835. png_free(png_ptr, tmp);
  170836. png_free(png_ptr, chunkdata);
  170837. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170838. }
  170839. png_memcpy(text, tmp, text_size);
  170840. png_free(png_ptr, tmp);
  170841. png_memcpy(text + text_size, png_ptr->zbuf,
  170842. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170843. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170844. *(text + text_size) = 0x00;
  170845. }
  170846. if (ret == Z_STREAM_END)
  170847. break;
  170848. else
  170849. {
  170850. png_ptr->zstream.next_out = png_ptr->zbuf;
  170851. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170852. }
  170853. }
  170854. }
  170855. if (ret != Z_STREAM_END)
  170856. {
  170857. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170858. char umsg[52];
  170859. if (ret == Z_BUF_ERROR)
  170860. png_snprintf(umsg, 52,
  170861. "Buffer error in compressed datastream in %s chunk",
  170862. png_ptr->chunk_name);
  170863. else if (ret == Z_DATA_ERROR)
  170864. png_snprintf(umsg, 52,
  170865. "Data error in compressed datastream in %s chunk",
  170866. png_ptr->chunk_name);
  170867. else
  170868. png_snprintf(umsg, 52,
  170869. "Incomplete compressed datastream in %s chunk",
  170870. png_ptr->chunk_name);
  170871. png_warning(png_ptr, umsg);
  170872. #else
  170873. png_warning(png_ptr,
  170874. "Incomplete compressed datastream in chunk other than IDAT");
  170875. #endif
  170876. text_size=prefix_size;
  170877. if (text == NULL)
  170878. {
  170879. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170880. if (text == NULL)
  170881. {
  170882. png_free(png_ptr, chunkdata);
  170883. png_error(png_ptr,"Not enough memory for text.");
  170884. }
  170885. png_memcpy(text, chunkdata, prefix_size);
  170886. }
  170887. *(text + text_size) = 0x00;
  170888. }
  170889. inflateReset(&png_ptr->zstream);
  170890. png_ptr->zstream.avail_in = 0;
  170891. png_free(png_ptr, chunkdata);
  170892. chunkdata = text;
  170893. *newlength=text_size;
  170894. }
  170895. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170896. {
  170897. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170898. char umsg[50];
  170899. png_snprintf(umsg, 50,
  170900. "Unknown zTXt compression type %d", comp_type);
  170901. png_warning(png_ptr, umsg);
  170902. #else
  170903. png_warning(png_ptr, "Unknown zTXt compression type");
  170904. #endif
  170905. *(chunkdata + prefix_size) = 0x00;
  170906. *newlength=prefix_size;
  170907. }
  170908. return chunkdata;
  170909. }
  170910. #endif
  170911. void /* PRIVATE */
  170912. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170913. {
  170914. png_byte buf[13];
  170915. png_uint_32 width, height;
  170916. int bit_depth, color_type, compression_type, filter_type;
  170917. int interlace_type;
  170918. png_debug(1, "in png_handle_IHDR\n");
  170919. if (png_ptr->mode & PNG_HAVE_IHDR)
  170920. png_error(png_ptr, "Out of place IHDR");
  170921. if (length != 13)
  170922. png_error(png_ptr, "Invalid IHDR chunk");
  170923. png_ptr->mode |= PNG_HAVE_IHDR;
  170924. png_crc_read(png_ptr, buf, 13);
  170925. png_crc_finish(png_ptr, 0);
  170926. width = png_get_uint_31(png_ptr, buf);
  170927. height = png_get_uint_31(png_ptr, buf + 4);
  170928. bit_depth = buf[8];
  170929. color_type = buf[9];
  170930. compression_type = buf[10];
  170931. filter_type = buf[11];
  170932. interlace_type = buf[12];
  170933. png_ptr->width = width;
  170934. png_ptr->height = height;
  170935. png_ptr->bit_depth = (png_byte)bit_depth;
  170936. png_ptr->interlaced = (png_byte)interlace_type;
  170937. png_ptr->color_type = (png_byte)color_type;
  170938. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170939. png_ptr->filter_type = (png_byte)filter_type;
  170940. #endif
  170941. png_ptr->compression_type = (png_byte)compression_type;
  170942. switch (png_ptr->color_type)
  170943. {
  170944. case PNG_COLOR_TYPE_GRAY:
  170945. case PNG_COLOR_TYPE_PALETTE:
  170946. png_ptr->channels = 1;
  170947. break;
  170948. case PNG_COLOR_TYPE_RGB:
  170949. png_ptr->channels = 3;
  170950. break;
  170951. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170952. png_ptr->channels = 2;
  170953. break;
  170954. case PNG_COLOR_TYPE_RGB_ALPHA:
  170955. png_ptr->channels = 4;
  170956. break;
  170957. }
  170958. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  170959. png_ptr->channels);
  170960. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  170961. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  170962. png_debug1(3,"channels = %d\n", png_ptr->channels);
  170963. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  170964. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  170965. color_type, interlace_type, compression_type, filter_type);
  170966. }
  170967. void /* PRIVATE */
  170968. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170969. {
  170970. png_color palette[PNG_MAX_PALETTE_LENGTH];
  170971. int num, i;
  170972. #ifndef PNG_NO_POINTER_INDEXING
  170973. png_colorp pal_ptr;
  170974. #endif
  170975. png_debug(1, "in png_handle_PLTE\n");
  170976. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170977. png_error(png_ptr, "Missing IHDR before PLTE");
  170978. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170979. {
  170980. png_warning(png_ptr, "Invalid PLTE after IDAT");
  170981. png_crc_finish(png_ptr, length);
  170982. return;
  170983. }
  170984. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170985. png_error(png_ptr, "Duplicate PLTE chunk");
  170986. png_ptr->mode |= PNG_HAVE_PLTE;
  170987. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  170988. {
  170989. png_warning(png_ptr,
  170990. "Ignoring PLTE chunk in grayscale PNG");
  170991. png_crc_finish(png_ptr, length);
  170992. return;
  170993. }
  170994. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170995. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170996. {
  170997. png_crc_finish(png_ptr, length);
  170998. return;
  170999. }
  171000. #endif
  171001. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171002. {
  171003. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171004. {
  171005. png_warning(png_ptr, "Invalid palette chunk");
  171006. png_crc_finish(png_ptr, length);
  171007. return;
  171008. }
  171009. else
  171010. {
  171011. png_error(png_ptr, "Invalid palette chunk");
  171012. }
  171013. }
  171014. num = (int)length / 3;
  171015. #ifndef PNG_NO_POINTER_INDEXING
  171016. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171017. {
  171018. png_byte buf[3];
  171019. png_crc_read(png_ptr, buf, 3);
  171020. pal_ptr->red = buf[0];
  171021. pal_ptr->green = buf[1];
  171022. pal_ptr->blue = buf[2];
  171023. }
  171024. #else
  171025. for (i = 0; i < num; i++)
  171026. {
  171027. png_byte buf[3];
  171028. png_crc_read(png_ptr, buf, 3);
  171029. palette[i].red = buf[0];
  171030. palette[i].green = buf[1];
  171031. palette[i].blue = buf[2];
  171032. }
  171033. #endif
  171034. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171035. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171036. #endif
  171037. {
  171038. png_crc_finish(png_ptr, 0);
  171039. }
  171040. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171041. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171042. {
  171043. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171044. {
  171045. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171046. {
  171047. png_chunk_error(png_ptr, "CRC error");
  171048. }
  171049. else
  171050. {
  171051. png_chunk_warning(png_ptr, "CRC error");
  171052. return;
  171053. }
  171054. }
  171055. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171056. {
  171057. png_chunk_warning(png_ptr, "CRC error");
  171058. }
  171059. }
  171060. #endif
  171061. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171062. #if defined(PNG_READ_tRNS_SUPPORTED)
  171063. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171064. {
  171065. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171066. {
  171067. if (png_ptr->num_trans > (png_uint_16)num)
  171068. {
  171069. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171070. png_ptr->num_trans = (png_uint_16)num;
  171071. }
  171072. if (info_ptr->num_trans > (png_uint_16)num)
  171073. {
  171074. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171075. info_ptr->num_trans = (png_uint_16)num;
  171076. }
  171077. }
  171078. }
  171079. #endif
  171080. }
  171081. void /* PRIVATE */
  171082. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171083. {
  171084. png_debug(1, "in png_handle_IEND\n");
  171085. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171086. {
  171087. png_error(png_ptr, "No image in file");
  171088. }
  171089. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171090. if (length != 0)
  171091. {
  171092. png_warning(png_ptr, "Incorrect IEND chunk length");
  171093. }
  171094. png_crc_finish(png_ptr, length);
  171095. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171096. }
  171097. #if defined(PNG_READ_gAMA_SUPPORTED)
  171098. void /* PRIVATE */
  171099. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171100. {
  171101. png_fixed_point igamma;
  171102. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171103. float file_gamma;
  171104. #endif
  171105. png_byte buf[4];
  171106. png_debug(1, "in png_handle_gAMA\n");
  171107. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171108. png_error(png_ptr, "Missing IHDR before gAMA");
  171109. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171110. {
  171111. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171112. png_crc_finish(png_ptr, length);
  171113. return;
  171114. }
  171115. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171116. png_warning(png_ptr, "Out of place gAMA chunk");
  171117. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171118. #if defined(PNG_READ_sRGB_SUPPORTED)
  171119. && !(info_ptr->valid & PNG_INFO_sRGB)
  171120. #endif
  171121. )
  171122. {
  171123. png_warning(png_ptr, "Duplicate gAMA chunk");
  171124. png_crc_finish(png_ptr, length);
  171125. return;
  171126. }
  171127. if (length != 4)
  171128. {
  171129. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171130. png_crc_finish(png_ptr, length);
  171131. return;
  171132. }
  171133. png_crc_read(png_ptr, buf, 4);
  171134. if (png_crc_finish(png_ptr, 0))
  171135. return;
  171136. igamma = (png_fixed_point)png_get_uint_32(buf);
  171137. if (igamma == 0)
  171138. {
  171139. png_warning(png_ptr,
  171140. "Ignoring gAMA chunk with gamma=0");
  171141. return;
  171142. }
  171143. #if defined(PNG_READ_sRGB_SUPPORTED)
  171144. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171145. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171146. {
  171147. png_warning(png_ptr,
  171148. "Ignoring incorrect gAMA value when sRGB is also present");
  171149. #ifndef PNG_NO_CONSOLE_IO
  171150. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171151. #endif
  171152. return;
  171153. }
  171154. #endif /* PNG_READ_sRGB_SUPPORTED */
  171155. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171156. file_gamma = (float)igamma / (float)100000.0;
  171157. # ifdef PNG_READ_GAMMA_SUPPORTED
  171158. png_ptr->gamma = file_gamma;
  171159. # endif
  171160. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171161. #endif
  171162. #ifdef PNG_FIXED_POINT_SUPPORTED
  171163. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171164. #endif
  171165. }
  171166. #endif
  171167. #if defined(PNG_READ_sBIT_SUPPORTED)
  171168. void /* PRIVATE */
  171169. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171170. {
  171171. png_size_t truelen;
  171172. png_byte buf[4];
  171173. png_debug(1, "in png_handle_sBIT\n");
  171174. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171175. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171176. png_error(png_ptr, "Missing IHDR before sBIT");
  171177. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171178. {
  171179. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171180. png_crc_finish(png_ptr, length);
  171181. return;
  171182. }
  171183. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171184. {
  171185. png_warning(png_ptr, "Out of place sBIT chunk");
  171186. }
  171187. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171188. {
  171189. png_warning(png_ptr, "Duplicate sBIT chunk");
  171190. png_crc_finish(png_ptr, length);
  171191. return;
  171192. }
  171193. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171194. truelen = 3;
  171195. else
  171196. truelen = (png_size_t)png_ptr->channels;
  171197. if (length != truelen || length > 4)
  171198. {
  171199. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171200. png_crc_finish(png_ptr, length);
  171201. return;
  171202. }
  171203. png_crc_read(png_ptr, buf, truelen);
  171204. if (png_crc_finish(png_ptr, 0))
  171205. return;
  171206. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171207. {
  171208. png_ptr->sig_bit.red = buf[0];
  171209. png_ptr->sig_bit.green = buf[1];
  171210. png_ptr->sig_bit.blue = buf[2];
  171211. png_ptr->sig_bit.alpha = buf[3];
  171212. }
  171213. else
  171214. {
  171215. png_ptr->sig_bit.gray = buf[0];
  171216. png_ptr->sig_bit.red = buf[0];
  171217. png_ptr->sig_bit.green = buf[0];
  171218. png_ptr->sig_bit.blue = buf[0];
  171219. png_ptr->sig_bit.alpha = buf[1];
  171220. }
  171221. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171222. }
  171223. #endif
  171224. #if defined(PNG_READ_cHRM_SUPPORTED)
  171225. void /* PRIVATE */
  171226. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171227. {
  171228. png_byte buf[4];
  171229. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171230. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171231. #endif
  171232. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171233. int_y_green, int_x_blue, int_y_blue;
  171234. png_uint_32 uint_x, uint_y;
  171235. png_debug(1, "in png_handle_cHRM\n");
  171236. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171237. png_error(png_ptr, "Missing IHDR before cHRM");
  171238. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171239. {
  171240. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171241. png_crc_finish(png_ptr, length);
  171242. return;
  171243. }
  171244. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171245. png_warning(png_ptr, "Missing PLTE before cHRM");
  171246. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171247. #if defined(PNG_READ_sRGB_SUPPORTED)
  171248. && !(info_ptr->valid & PNG_INFO_sRGB)
  171249. #endif
  171250. )
  171251. {
  171252. png_warning(png_ptr, "Duplicate cHRM chunk");
  171253. png_crc_finish(png_ptr, length);
  171254. return;
  171255. }
  171256. if (length != 32)
  171257. {
  171258. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171259. png_crc_finish(png_ptr, length);
  171260. return;
  171261. }
  171262. png_crc_read(png_ptr, buf, 4);
  171263. uint_x = png_get_uint_32(buf);
  171264. png_crc_read(png_ptr, buf, 4);
  171265. uint_y = png_get_uint_32(buf);
  171266. if (uint_x > 80000L || uint_y > 80000L ||
  171267. uint_x + uint_y > 100000L)
  171268. {
  171269. png_warning(png_ptr, "Invalid cHRM white point");
  171270. png_crc_finish(png_ptr, 24);
  171271. return;
  171272. }
  171273. int_x_white = (png_fixed_point)uint_x;
  171274. int_y_white = (png_fixed_point)uint_y;
  171275. png_crc_read(png_ptr, buf, 4);
  171276. uint_x = png_get_uint_32(buf);
  171277. png_crc_read(png_ptr, buf, 4);
  171278. uint_y = png_get_uint_32(buf);
  171279. if (uint_x + uint_y > 100000L)
  171280. {
  171281. png_warning(png_ptr, "Invalid cHRM red point");
  171282. png_crc_finish(png_ptr, 16);
  171283. return;
  171284. }
  171285. int_x_red = (png_fixed_point)uint_x;
  171286. int_y_red = (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 green point");
  171294. png_crc_finish(png_ptr, 8);
  171295. return;
  171296. }
  171297. int_x_green = (png_fixed_point)uint_x;
  171298. int_y_green = (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 blue point");
  171306. png_crc_finish(png_ptr, 0);
  171307. return;
  171308. }
  171309. int_x_blue = (png_fixed_point)uint_x;
  171310. int_y_blue = (png_fixed_point)uint_y;
  171311. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171312. white_x = (float)int_x_white / (float)100000.0;
  171313. white_y = (float)int_y_white / (float)100000.0;
  171314. red_x = (float)int_x_red / (float)100000.0;
  171315. red_y = (float)int_y_red / (float)100000.0;
  171316. green_x = (float)int_x_green / (float)100000.0;
  171317. green_y = (float)int_y_green / (float)100000.0;
  171318. blue_x = (float)int_x_blue / (float)100000.0;
  171319. blue_y = (float)int_y_blue / (float)100000.0;
  171320. #endif
  171321. #if defined(PNG_READ_sRGB_SUPPORTED)
  171322. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171323. {
  171324. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171325. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171326. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171327. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171328. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171329. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171330. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171331. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171332. {
  171333. png_warning(png_ptr,
  171334. "Ignoring incorrect cHRM value when sRGB is also present");
  171335. #ifndef PNG_NO_CONSOLE_IO
  171336. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171337. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171338. white_x, white_y, red_x, red_y);
  171339. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171340. green_x, green_y, blue_x, blue_y);
  171341. #else
  171342. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171343. int_x_white, int_y_white, int_x_red, int_y_red);
  171344. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171345. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171346. #endif
  171347. #endif /* PNG_NO_CONSOLE_IO */
  171348. }
  171349. png_crc_finish(png_ptr, 0);
  171350. return;
  171351. }
  171352. #endif /* PNG_READ_sRGB_SUPPORTED */
  171353. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171354. png_set_cHRM(png_ptr, info_ptr,
  171355. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171356. #endif
  171357. #ifdef PNG_FIXED_POINT_SUPPORTED
  171358. png_set_cHRM_fixed(png_ptr, info_ptr,
  171359. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171360. int_y_green, int_x_blue, int_y_blue);
  171361. #endif
  171362. if (png_crc_finish(png_ptr, 0))
  171363. return;
  171364. }
  171365. #endif
  171366. #if defined(PNG_READ_sRGB_SUPPORTED)
  171367. void /* PRIVATE */
  171368. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171369. {
  171370. int intent;
  171371. png_byte buf[1];
  171372. png_debug(1, "in png_handle_sRGB\n");
  171373. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171374. png_error(png_ptr, "Missing IHDR before sRGB");
  171375. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171376. {
  171377. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171378. png_crc_finish(png_ptr, length);
  171379. return;
  171380. }
  171381. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171382. png_warning(png_ptr, "Out of place sRGB chunk");
  171383. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171384. {
  171385. png_warning(png_ptr, "Duplicate sRGB chunk");
  171386. png_crc_finish(png_ptr, length);
  171387. return;
  171388. }
  171389. if (length != 1)
  171390. {
  171391. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171392. png_crc_finish(png_ptr, length);
  171393. return;
  171394. }
  171395. png_crc_read(png_ptr, buf, 1);
  171396. if (png_crc_finish(png_ptr, 0))
  171397. return;
  171398. intent = buf[0];
  171399. if (intent >= PNG_sRGB_INTENT_LAST)
  171400. {
  171401. png_warning(png_ptr, "Unknown sRGB intent");
  171402. return;
  171403. }
  171404. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171405. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171406. {
  171407. png_fixed_point igamma;
  171408. #ifdef PNG_FIXED_POINT_SUPPORTED
  171409. igamma=info_ptr->int_gamma;
  171410. #else
  171411. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171412. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171413. # endif
  171414. #endif
  171415. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171416. {
  171417. png_warning(png_ptr,
  171418. "Ignoring incorrect gAMA value when sRGB is also present");
  171419. #ifndef PNG_NO_CONSOLE_IO
  171420. # ifdef PNG_FIXED_POINT_SUPPORTED
  171421. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171422. # else
  171423. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171424. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171425. # endif
  171426. # endif
  171427. #endif
  171428. }
  171429. }
  171430. #endif /* PNG_READ_gAMA_SUPPORTED */
  171431. #ifdef PNG_READ_cHRM_SUPPORTED
  171432. #ifdef PNG_FIXED_POINT_SUPPORTED
  171433. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171434. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171435. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171436. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171437. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171438. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171439. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171440. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171441. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171442. {
  171443. png_warning(png_ptr,
  171444. "Ignoring incorrect cHRM value when sRGB is also present");
  171445. }
  171446. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171447. #endif /* PNG_READ_cHRM_SUPPORTED */
  171448. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171449. }
  171450. #endif /* PNG_READ_sRGB_SUPPORTED */
  171451. #if defined(PNG_READ_iCCP_SUPPORTED)
  171452. void /* PRIVATE */
  171453. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171454. {
  171455. png_charp chunkdata;
  171456. png_byte compression_type;
  171457. png_bytep pC;
  171458. png_charp profile;
  171459. png_uint_32 skip = 0;
  171460. png_uint_32 profile_size, profile_length;
  171461. png_size_t slength, prefix_length, data_length;
  171462. png_debug(1, "in png_handle_iCCP\n");
  171463. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171464. png_error(png_ptr, "Missing IHDR before iCCP");
  171465. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171466. {
  171467. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171468. png_crc_finish(png_ptr, length);
  171469. return;
  171470. }
  171471. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171472. png_warning(png_ptr, "Out of place iCCP chunk");
  171473. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171474. {
  171475. png_warning(png_ptr, "Duplicate iCCP chunk");
  171476. png_crc_finish(png_ptr, length);
  171477. return;
  171478. }
  171479. #ifdef PNG_MAX_MALLOC_64K
  171480. if (length > (png_uint_32)65535L)
  171481. {
  171482. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171483. skip = length - (png_uint_32)65535L;
  171484. length = (png_uint_32)65535L;
  171485. }
  171486. #endif
  171487. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171488. slength = (png_size_t)length;
  171489. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171490. if (png_crc_finish(png_ptr, skip))
  171491. {
  171492. png_free(png_ptr, chunkdata);
  171493. return;
  171494. }
  171495. chunkdata[slength] = 0x00;
  171496. for (profile = chunkdata; *profile; profile++)
  171497. ;
  171498. ++profile;
  171499. if ( profile >= chunkdata + slength - 1)
  171500. {
  171501. png_free(png_ptr, chunkdata);
  171502. png_warning(png_ptr, "Malformed iCCP chunk");
  171503. return;
  171504. }
  171505. compression_type = *profile++;
  171506. if (compression_type)
  171507. {
  171508. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171509. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171510. wrote nonzero) */
  171511. }
  171512. prefix_length = profile - chunkdata;
  171513. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171514. slength, prefix_length, &data_length);
  171515. profile_length = data_length - prefix_length;
  171516. if ( prefix_length > data_length || profile_length < 4)
  171517. {
  171518. png_free(png_ptr, chunkdata);
  171519. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171520. return;
  171521. }
  171522. pC = (png_bytep)(chunkdata+prefix_length);
  171523. profile_size = ((*(pC ))<<24) |
  171524. ((*(pC+1))<<16) |
  171525. ((*(pC+2))<< 8) |
  171526. ((*(pC+3)) );
  171527. if(profile_size < profile_length)
  171528. profile_length = profile_size;
  171529. if(profile_size > profile_length)
  171530. {
  171531. png_free(png_ptr, chunkdata);
  171532. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171533. return;
  171534. }
  171535. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171536. chunkdata + prefix_length, profile_length);
  171537. png_free(png_ptr, chunkdata);
  171538. }
  171539. #endif /* PNG_READ_iCCP_SUPPORTED */
  171540. #if defined(PNG_READ_sPLT_SUPPORTED)
  171541. void /* PRIVATE */
  171542. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171543. {
  171544. png_bytep chunkdata;
  171545. png_bytep entry_start;
  171546. png_sPLT_t new_palette;
  171547. #ifdef PNG_NO_POINTER_INDEXING
  171548. png_sPLT_entryp pp;
  171549. #endif
  171550. int data_length, entry_size, i;
  171551. png_uint_32 skip = 0;
  171552. png_size_t slength;
  171553. png_debug(1, "in png_handle_sPLT\n");
  171554. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171555. png_error(png_ptr, "Missing IHDR before sPLT");
  171556. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171557. {
  171558. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171559. png_crc_finish(png_ptr, length);
  171560. return;
  171561. }
  171562. #ifdef PNG_MAX_MALLOC_64K
  171563. if (length > (png_uint_32)65535L)
  171564. {
  171565. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171566. skip = length - (png_uint_32)65535L;
  171567. length = (png_uint_32)65535L;
  171568. }
  171569. #endif
  171570. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171571. slength = (png_size_t)length;
  171572. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171573. if (png_crc_finish(png_ptr, skip))
  171574. {
  171575. png_free(png_ptr, chunkdata);
  171576. return;
  171577. }
  171578. chunkdata[slength] = 0x00;
  171579. for (entry_start = chunkdata; *entry_start; entry_start++)
  171580. ;
  171581. ++entry_start;
  171582. if (entry_start > chunkdata + slength - 2)
  171583. {
  171584. png_free(png_ptr, chunkdata);
  171585. png_warning(png_ptr, "malformed sPLT chunk");
  171586. return;
  171587. }
  171588. new_palette.depth = *entry_start++;
  171589. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171590. data_length = (slength - (entry_start - chunkdata));
  171591. if (data_length % entry_size)
  171592. {
  171593. png_free(png_ptr, chunkdata);
  171594. png_warning(png_ptr, "sPLT chunk has bad length");
  171595. return;
  171596. }
  171597. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171598. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171599. png_sizeof(png_sPLT_entry)))
  171600. {
  171601. png_warning(png_ptr, "sPLT chunk too long");
  171602. return;
  171603. }
  171604. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171605. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171606. if (new_palette.entries == NULL)
  171607. {
  171608. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171609. return;
  171610. }
  171611. #ifndef PNG_NO_POINTER_INDEXING
  171612. for (i = 0; i < new_palette.nentries; i++)
  171613. {
  171614. png_sPLT_entryp pp = new_palette.entries + i;
  171615. if (new_palette.depth == 8)
  171616. {
  171617. pp->red = *entry_start++;
  171618. pp->green = *entry_start++;
  171619. pp->blue = *entry_start++;
  171620. pp->alpha = *entry_start++;
  171621. }
  171622. else
  171623. {
  171624. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171625. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171626. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171627. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171628. }
  171629. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171630. }
  171631. #else
  171632. pp = new_palette.entries;
  171633. for (i = 0; i < new_palette.nentries; i++)
  171634. {
  171635. if (new_palette.depth == 8)
  171636. {
  171637. pp[i].red = *entry_start++;
  171638. pp[i].green = *entry_start++;
  171639. pp[i].blue = *entry_start++;
  171640. pp[i].alpha = *entry_start++;
  171641. }
  171642. else
  171643. {
  171644. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171645. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171646. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171647. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171648. }
  171649. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171650. }
  171651. #endif
  171652. new_palette.name = (png_charp)chunkdata;
  171653. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171654. png_free(png_ptr, chunkdata);
  171655. png_free(png_ptr, new_palette.entries);
  171656. }
  171657. #endif /* PNG_READ_sPLT_SUPPORTED */
  171658. #if defined(PNG_READ_tRNS_SUPPORTED)
  171659. void /* PRIVATE */
  171660. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171661. {
  171662. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171663. int bit_mask;
  171664. png_debug(1, "in png_handle_tRNS\n");
  171665. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171666. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171667. png_error(png_ptr, "Missing IHDR before tRNS");
  171668. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171669. {
  171670. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171671. png_crc_finish(png_ptr, length);
  171672. return;
  171673. }
  171674. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171675. {
  171676. png_warning(png_ptr, "Duplicate tRNS chunk");
  171677. png_crc_finish(png_ptr, length);
  171678. return;
  171679. }
  171680. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171681. {
  171682. png_byte buf[2];
  171683. if (length != 2)
  171684. {
  171685. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171686. png_crc_finish(png_ptr, length);
  171687. return;
  171688. }
  171689. png_crc_read(png_ptr, buf, 2);
  171690. png_ptr->num_trans = 1;
  171691. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171692. }
  171693. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171694. {
  171695. png_byte buf[6];
  171696. if (length != 6)
  171697. {
  171698. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171699. png_crc_finish(png_ptr, length);
  171700. return;
  171701. }
  171702. png_crc_read(png_ptr, buf, (png_size_t)length);
  171703. png_ptr->num_trans = 1;
  171704. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171705. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171706. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171707. }
  171708. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171709. {
  171710. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171711. {
  171712. png_warning(png_ptr, "Missing PLTE before tRNS");
  171713. }
  171714. if (length > (png_uint_32)png_ptr->num_palette ||
  171715. length > PNG_MAX_PALETTE_LENGTH)
  171716. {
  171717. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171718. png_crc_finish(png_ptr, length);
  171719. return;
  171720. }
  171721. if (length == 0)
  171722. {
  171723. png_warning(png_ptr, "Zero length tRNS chunk");
  171724. png_crc_finish(png_ptr, length);
  171725. return;
  171726. }
  171727. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171728. png_ptr->num_trans = (png_uint_16)length;
  171729. }
  171730. else
  171731. {
  171732. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171733. png_crc_finish(png_ptr, length);
  171734. return;
  171735. }
  171736. if (png_crc_finish(png_ptr, 0))
  171737. {
  171738. png_ptr->num_trans = 0;
  171739. return;
  171740. }
  171741. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171742. &(png_ptr->trans_values));
  171743. }
  171744. #endif
  171745. #if defined(PNG_READ_bKGD_SUPPORTED)
  171746. void /* PRIVATE */
  171747. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171748. {
  171749. png_size_t truelen;
  171750. png_byte buf[6];
  171751. png_debug(1, "in png_handle_bKGD\n");
  171752. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171753. png_error(png_ptr, "Missing IHDR before bKGD");
  171754. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171755. {
  171756. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171757. png_crc_finish(png_ptr, length);
  171758. return;
  171759. }
  171760. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171761. !(png_ptr->mode & PNG_HAVE_PLTE))
  171762. {
  171763. png_warning(png_ptr, "Missing PLTE before bKGD");
  171764. png_crc_finish(png_ptr, length);
  171765. return;
  171766. }
  171767. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171768. {
  171769. png_warning(png_ptr, "Duplicate bKGD chunk");
  171770. png_crc_finish(png_ptr, length);
  171771. return;
  171772. }
  171773. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171774. truelen = 1;
  171775. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171776. truelen = 6;
  171777. else
  171778. truelen = 2;
  171779. if (length != truelen)
  171780. {
  171781. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171782. png_crc_finish(png_ptr, length);
  171783. return;
  171784. }
  171785. png_crc_read(png_ptr, buf, truelen);
  171786. if (png_crc_finish(png_ptr, 0))
  171787. return;
  171788. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171789. {
  171790. png_ptr->background.index = buf[0];
  171791. if(info_ptr->num_palette)
  171792. {
  171793. if(buf[0] > info_ptr->num_palette)
  171794. {
  171795. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171796. return;
  171797. }
  171798. png_ptr->background.red =
  171799. (png_uint_16)png_ptr->palette[buf[0]].red;
  171800. png_ptr->background.green =
  171801. (png_uint_16)png_ptr->palette[buf[0]].green;
  171802. png_ptr->background.blue =
  171803. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171804. }
  171805. }
  171806. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171807. {
  171808. png_ptr->background.red =
  171809. png_ptr->background.green =
  171810. png_ptr->background.blue =
  171811. png_ptr->background.gray = png_get_uint_16(buf);
  171812. }
  171813. else
  171814. {
  171815. png_ptr->background.red = png_get_uint_16(buf);
  171816. png_ptr->background.green = png_get_uint_16(buf + 2);
  171817. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171818. }
  171819. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171820. }
  171821. #endif
  171822. #if defined(PNG_READ_hIST_SUPPORTED)
  171823. void /* PRIVATE */
  171824. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171825. {
  171826. unsigned int num, i;
  171827. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171828. png_debug(1, "in png_handle_hIST\n");
  171829. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171830. png_error(png_ptr, "Missing IHDR before hIST");
  171831. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171832. {
  171833. png_warning(png_ptr, "Invalid hIST after IDAT");
  171834. png_crc_finish(png_ptr, length);
  171835. return;
  171836. }
  171837. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171838. {
  171839. png_warning(png_ptr, "Missing PLTE before hIST");
  171840. png_crc_finish(png_ptr, length);
  171841. return;
  171842. }
  171843. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171844. {
  171845. png_warning(png_ptr, "Duplicate hIST chunk");
  171846. png_crc_finish(png_ptr, length);
  171847. return;
  171848. }
  171849. num = length / 2 ;
  171850. if (num != (unsigned int) png_ptr->num_palette || num >
  171851. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171852. {
  171853. png_warning(png_ptr, "Incorrect hIST chunk length");
  171854. png_crc_finish(png_ptr, length);
  171855. return;
  171856. }
  171857. for (i = 0; i < num; i++)
  171858. {
  171859. png_byte buf[2];
  171860. png_crc_read(png_ptr, buf, 2);
  171861. readbuf[i] = png_get_uint_16(buf);
  171862. }
  171863. if (png_crc_finish(png_ptr, 0))
  171864. return;
  171865. png_set_hIST(png_ptr, info_ptr, readbuf);
  171866. }
  171867. #endif
  171868. #if defined(PNG_READ_pHYs_SUPPORTED)
  171869. void /* PRIVATE */
  171870. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171871. {
  171872. png_byte buf[9];
  171873. png_uint_32 res_x, res_y;
  171874. int unit_type;
  171875. png_debug(1, "in png_handle_pHYs\n");
  171876. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171877. png_error(png_ptr, "Missing IHDR before pHYs");
  171878. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171879. {
  171880. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171881. png_crc_finish(png_ptr, length);
  171882. return;
  171883. }
  171884. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171885. {
  171886. png_warning(png_ptr, "Duplicate pHYs chunk");
  171887. png_crc_finish(png_ptr, length);
  171888. return;
  171889. }
  171890. if (length != 9)
  171891. {
  171892. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171893. png_crc_finish(png_ptr, length);
  171894. return;
  171895. }
  171896. png_crc_read(png_ptr, buf, 9);
  171897. if (png_crc_finish(png_ptr, 0))
  171898. return;
  171899. res_x = png_get_uint_32(buf);
  171900. res_y = png_get_uint_32(buf + 4);
  171901. unit_type = buf[8];
  171902. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171903. }
  171904. #endif
  171905. #if defined(PNG_READ_oFFs_SUPPORTED)
  171906. void /* PRIVATE */
  171907. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171908. {
  171909. png_byte buf[9];
  171910. png_int_32 offset_x, offset_y;
  171911. int unit_type;
  171912. png_debug(1, "in png_handle_oFFs\n");
  171913. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171914. png_error(png_ptr, "Missing IHDR before oFFs");
  171915. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171916. {
  171917. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171918. png_crc_finish(png_ptr, length);
  171919. return;
  171920. }
  171921. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  171922. {
  171923. png_warning(png_ptr, "Duplicate oFFs chunk");
  171924. png_crc_finish(png_ptr, length);
  171925. return;
  171926. }
  171927. if (length != 9)
  171928. {
  171929. png_warning(png_ptr, "Incorrect oFFs chunk length");
  171930. png_crc_finish(png_ptr, length);
  171931. return;
  171932. }
  171933. png_crc_read(png_ptr, buf, 9);
  171934. if (png_crc_finish(png_ptr, 0))
  171935. return;
  171936. offset_x = png_get_int_32(buf);
  171937. offset_y = png_get_int_32(buf + 4);
  171938. unit_type = buf[8];
  171939. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  171940. }
  171941. #endif
  171942. #if defined(PNG_READ_pCAL_SUPPORTED)
  171943. void /* PRIVATE */
  171944. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171945. {
  171946. png_charp purpose;
  171947. png_int_32 X0, X1;
  171948. png_byte type, nparams;
  171949. png_charp buf, units, endptr;
  171950. png_charpp params;
  171951. png_size_t slength;
  171952. int i;
  171953. png_debug(1, "in png_handle_pCAL\n");
  171954. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171955. png_error(png_ptr, "Missing IHDR before pCAL");
  171956. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171957. {
  171958. png_warning(png_ptr, "Invalid pCAL after IDAT");
  171959. png_crc_finish(png_ptr, length);
  171960. return;
  171961. }
  171962. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  171963. {
  171964. png_warning(png_ptr, "Duplicate pCAL chunk");
  171965. png_crc_finish(png_ptr, length);
  171966. return;
  171967. }
  171968. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  171969. length + 1);
  171970. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171971. if (purpose == NULL)
  171972. {
  171973. png_warning(png_ptr, "No memory for pCAL purpose.");
  171974. return;
  171975. }
  171976. slength = (png_size_t)length;
  171977. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  171978. if (png_crc_finish(png_ptr, 0))
  171979. {
  171980. png_free(png_ptr, purpose);
  171981. return;
  171982. }
  171983. purpose[slength] = 0x00; /* null terminate the last string */
  171984. png_debug(3, "Finding end of pCAL purpose string\n");
  171985. for (buf = purpose; *buf; buf++)
  171986. ;
  171987. endptr = purpose + slength;
  171988. if (endptr <= buf + 12)
  171989. {
  171990. png_warning(png_ptr, "Invalid pCAL data");
  171991. png_free(png_ptr, purpose);
  171992. return;
  171993. }
  171994. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  171995. X0 = png_get_int_32((png_bytep)buf+1);
  171996. X1 = png_get_int_32((png_bytep)buf+5);
  171997. type = buf[9];
  171998. nparams = buf[10];
  171999. units = buf + 11;
  172000. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172001. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172002. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172003. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172004. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172005. {
  172006. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172007. png_free(png_ptr, purpose);
  172008. return;
  172009. }
  172010. else if (type >= PNG_EQUATION_LAST)
  172011. {
  172012. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172013. }
  172014. for (buf = units; *buf; buf++)
  172015. ;
  172016. png_debug(3, "Allocating pCAL parameters array\n");
  172017. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172018. *png_sizeof(png_charp))) ;
  172019. if (params == NULL)
  172020. {
  172021. png_free(png_ptr, purpose);
  172022. png_warning(png_ptr, "No memory for pCAL params.");
  172023. return;
  172024. }
  172025. for (i = 0; i < (int)nparams; i++)
  172026. {
  172027. buf++; /* Skip the null string terminator from previous parameter. */
  172028. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172029. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172030. ;
  172031. if (buf > endptr)
  172032. {
  172033. png_warning(png_ptr, "Invalid pCAL data");
  172034. png_free(png_ptr, purpose);
  172035. png_free(png_ptr, params);
  172036. return;
  172037. }
  172038. }
  172039. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172040. units, params);
  172041. png_free(png_ptr, purpose);
  172042. png_free(png_ptr, params);
  172043. }
  172044. #endif
  172045. #if defined(PNG_READ_sCAL_SUPPORTED)
  172046. void /* PRIVATE */
  172047. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172048. {
  172049. png_charp buffer, ep;
  172050. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172051. double width, height;
  172052. png_charp vp;
  172053. #else
  172054. #ifdef PNG_FIXED_POINT_SUPPORTED
  172055. png_charp swidth, sheight;
  172056. #endif
  172057. #endif
  172058. png_size_t slength;
  172059. png_debug(1, "in png_handle_sCAL\n");
  172060. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172061. png_error(png_ptr, "Missing IHDR before sCAL");
  172062. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172063. {
  172064. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172065. png_crc_finish(png_ptr, length);
  172066. return;
  172067. }
  172068. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172069. {
  172070. png_warning(png_ptr, "Duplicate sCAL chunk");
  172071. png_crc_finish(png_ptr, length);
  172072. return;
  172073. }
  172074. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172075. length + 1);
  172076. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172077. if (buffer == NULL)
  172078. {
  172079. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172080. return;
  172081. }
  172082. slength = (png_size_t)length;
  172083. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172084. if (png_crc_finish(png_ptr, 0))
  172085. {
  172086. png_free(png_ptr, buffer);
  172087. return;
  172088. }
  172089. buffer[slength] = 0x00; /* null terminate the last string */
  172090. ep = buffer + 1; /* skip unit byte */
  172091. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172092. width = png_strtod(png_ptr, ep, &vp);
  172093. if (*vp)
  172094. {
  172095. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172096. return;
  172097. }
  172098. #else
  172099. #ifdef PNG_FIXED_POINT_SUPPORTED
  172100. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172101. if (swidth == NULL)
  172102. {
  172103. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172104. return;
  172105. }
  172106. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172107. #endif
  172108. #endif
  172109. for (ep = buffer; *ep; ep++)
  172110. ;
  172111. ep++;
  172112. if (buffer + slength < ep)
  172113. {
  172114. png_warning(png_ptr, "Truncated sCAL chunk");
  172115. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172116. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172117. png_free(png_ptr, swidth);
  172118. #endif
  172119. png_free(png_ptr, buffer);
  172120. return;
  172121. }
  172122. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172123. height = png_strtod(png_ptr, ep, &vp);
  172124. if (*vp)
  172125. {
  172126. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172127. return;
  172128. }
  172129. #else
  172130. #ifdef PNG_FIXED_POINT_SUPPORTED
  172131. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172132. if (swidth == NULL)
  172133. {
  172134. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172135. return;
  172136. }
  172137. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172138. #endif
  172139. #endif
  172140. if (buffer + slength < ep
  172141. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172142. || width <= 0. || height <= 0.
  172143. #endif
  172144. )
  172145. {
  172146. png_warning(png_ptr, "Invalid sCAL data");
  172147. png_free(png_ptr, buffer);
  172148. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172149. png_free(png_ptr, swidth);
  172150. png_free(png_ptr, sheight);
  172151. #endif
  172152. return;
  172153. }
  172154. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172155. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172156. #else
  172157. #ifdef PNG_FIXED_POINT_SUPPORTED
  172158. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172159. #endif
  172160. #endif
  172161. png_free(png_ptr, buffer);
  172162. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172163. png_free(png_ptr, swidth);
  172164. png_free(png_ptr, sheight);
  172165. #endif
  172166. }
  172167. #endif
  172168. #if defined(PNG_READ_tIME_SUPPORTED)
  172169. void /* PRIVATE */
  172170. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172171. {
  172172. png_byte buf[7];
  172173. png_time mod_time;
  172174. png_debug(1, "in png_handle_tIME\n");
  172175. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172176. png_error(png_ptr, "Out of place tIME chunk");
  172177. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172178. {
  172179. png_warning(png_ptr, "Duplicate tIME chunk");
  172180. png_crc_finish(png_ptr, length);
  172181. return;
  172182. }
  172183. if (png_ptr->mode & PNG_HAVE_IDAT)
  172184. png_ptr->mode |= PNG_AFTER_IDAT;
  172185. if (length != 7)
  172186. {
  172187. png_warning(png_ptr, "Incorrect tIME chunk length");
  172188. png_crc_finish(png_ptr, length);
  172189. return;
  172190. }
  172191. png_crc_read(png_ptr, buf, 7);
  172192. if (png_crc_finish(png_ptr, 0))
  172193. return;
  172194. mod_time.second = buf[6];
  172195. mod_time.minute = buf[5];
  172196. mod_time.hour = buf[4];
  172197. mod_time.day = buf[3];
  172198. mod_time.month = buf[2];
  172199. mod_time.year = png_get_uint_16(buf);
  172200. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172201. }
  172202. #endif
  172203. #if defined(PNG_READ_tEXt_SUPPORTED)
  172204. void /* PRIVATE */
  172205. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172206. {
  172207. png_textp text_ptr;
  172208. png_charp key;
  172209. png_charp text;
  172210. png_uint_32 skip = 0;
  172211. png_size_t slength;
  172212. int ret;
  172213. png_debug(1, "in png_handle_tEXt\n");
  172214. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172215. png_error(png_ptr, "Missing IHDR before tEXt");
  172216. if (png_ptr->mode & PNG_HAVE_IDAT)
  172217. png_ptr->mode |= PNG_AFTER_IDAT;
  172218. #ifdef PNG_MAX_MALLOC_64K
  172219. if (length > (png_uint_32)65535L)
  172220. {
  172221. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172222. skip = length - (png_uint_32)65535L;
  172223. length = (png_uint_32)65535L;
  172224. }
  172225. #endif
  172226. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172227. if (key == NULL)
  172228. {
  172229. png_warning(png_ptr, "No memory to process text chunk.");
  172230. return;
  172231. }
  172232. slength = (png_size_t)length;
  172233. png_crc_read(png_ptr, (png_bytep)key, slength);
  172234. if (png_crc_finish(png_ptr, skip))
  172235. {
  172236. png_free(png_ptr, key);
  172237. return;
  172238. }
  172239. key[slength] = 0x00;
  172240. for (text = key; *text; text++)
  172241. ;
  172242. if (text != key + slength)
  172243. text++;
  172244. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172245. (png_uint_32)png_sizeof(png_text));
  172246. if (text_ptr == NULL)
  172247. {
  172248. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172249. png_free(png_ptr, key);
  172250. return;
  172251. }
  172252. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172253. text_ptr->key = key;
  172254. #ifdef PNG_iTXt_SUPPORTED
  172255. text_ptr->lang = NULL;
  172256. text_ptr->lang_key = NULL;
  172257. text_ptr->itxt_length = 0;
  172258. #endif
  172259. text_ptr->text = text;
  172260. text_ptr->text_length = png_strlen(text);
  172261. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172262. png_free(png_ptr, key);
  172263. png_free(png_ptr, text_ptr);
  172264. if (ret)
  172265. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172266. }
  172267. #endif
  172268. #if defined(PNG_READ_zTXt_SUPPORTED)
  172269. void /* PRIVATE */
  172270. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172271. {
  172272. png_textp text_ptr;
  172273. png_charp chunkdata;
  172274. png_charp text;
  172275. int comp_type;
  172276. int ret;
  172277. png_size_t slength, prefix_len, data_len;
  172278. png_debug(1, "in png_handle_zTXt\n");
  172279. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172280. png_error(png_ptr, "Missing IHDR before zTXt");
  172281. if (png_ptr->mode & PNG_HAVE_IDAT)
  172282. png_ptr->mode |= PNG_AFTER_IDAT;
  172283. #ifdef PNG_MAX_MALLOC_64K
  172284. if (length > (png_uint_32)65535L)
  172285. {
  172286. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172287. png_crc_finish(png_ptr, length);
  172288. return;
  172289. }
  172290. #endif
  172291. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172292. if (chunkdata == NULL)
  172293. {
  172294. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172295. return;
  172296. }
  172297. slength = (png_size_t)length;
  172298. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172299. if (png_crc_finish(png_ptr, 0))
  172300. {
  172301. png_free(png_ptr, chunkdata);
  172302. return;
  172303. }
  172304. chunkdata[slength] = 0x00;
  172305. for (text = chunkdata; *text; text++)
  172306. ;
  172307. if (text >= chunkdata + slength - 2)
  172308. {
  172309. png_warning(png_ptr, "Truncated zTXt chunk");
  172310. png_free(png_ptr, chunkdata);
  172311. return;
  172312. }
  172313. else
  172314. {
  172315. comp_type = *(++text);
  172316. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172317. {
  172318. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172319. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172320. }
  172321. text++; /* skip the compression_method byte */
  172322. }
  172323. prefix_len = text - chunkdata;
  172324. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172325. (png_size_t)length, prefix_len, &data_len);
  172326. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172327. (png_uint_32)png_sizeof(png_text));
  172328. if (text_ptr == NULL)
  172329. {
  172330. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172331. png_free(png_ptr, chunkdata);
  172332. return;
  172333. }
  172334. text_ptr->compression = comp_type;
  172335. text_ptr->key = chunkdata;
  172336. #ifdef PNG_iTXt_SUPPORTED
  172337. text_ptr->lang = NULL;
  172338. text_ptr->lang_key = NULL;
  172339. text_ptr->itxt_length = 0;
  172340. #endif
  172341. text_ptr->text = chunkdata + prefix_len;
  172342. text_ptr->text_length = data_len;
  172343. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172344. png_free(png_ptr, text_ptr);
  172345. png_free(png_ptr, chunkdata);
  172346. if (ret)
  172347. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172348. }
  172349. #endif
  172350. #if defined(PNG_READ_iTXt_SUPPORTED)
  172351. void /* PRIVATE */
  172352. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172353. {
  172354. png_textp text_ptr;
  172355. png_charp chunkdata;
  172356. png_charp key, lang, text, lang_key;
  172357. int comp_flag;
  172358. int comp_type = 0;
  172359. int ret;
  172360. png_size_t slength, prefix_len, data_len;
  172361. png_debug(1, "in png_handle_iTXt\n");
  172362. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172363. png_error(png_ptr, "Missing IHDR before iTXt");
  172364. if (png_ptr->mode & PNG_HAVE_IDAT)
  172365. png_ptr->mode |= PNG_AFTER_IDAT;
  172366. #ifdef PNG_MAX_MALLOC_64K
  172367. if (length > (png_uint_32)65535L)
  172368. {
  172369. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172370. png_crc_finish(png_ptr, length);
  172371. return;
  172372. }
  172373. #endif
  172374. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172375. if (chunkdata == NULL)
  172376. {
  172377. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172378. return;
  172379. }
  172380. slength = (png_size_t)length;
  172381. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172382. if (png_crc_finish(png_ptr, 0))
  172383. {
  172384. png_free(png_ptr, chunkdata);
  172385. return;
  172386. }
  172387. chunkdata[slength] = 0x00;
  172388. for (lang = chunkdata; *lang; lang++)
  172389. ;
  172390. lang++; /* skip NUL separator */
  172391. if (lang >= chunkdata + slength - 3)
  172392. {
  172393. png_warning(png_ptr, "Truncated iTXt chunk");
  172394. png_free(png_ptr, chunkdata);
  172395. return;
  172396. }
  172397. else
  172398. {
  172399. comp_flag = *lang++;
  172400. comp_type = *lang++;
  172401. }
  172402. for (lang_key = lang; *lang_key; lang_key++)
  172403. ;
  172404. lang_key++; /* skip NUL separator */
  172405. if (lang_key >= chunkdata + slength)
  172406. {
  172407. png_warning(png_ptr, "Truncated iTXt chunk");
  172408. png_free(png_ptr, chunkdata);
  172409. return;
  172410. }
  172411. for (text = lang_key; *text; text++)
  172412. ;
  172413. text++; /* skip NUL separator */
  172414. if (text >= chunkdata + slength)
  172415. {
  172416. png_warning(png_ptr, "Malformed iTXt chunk");
  172417. png_free(png_ptr, chunkdata);
  172418. return;
  172419. }
  172420. prefix_len = text - chunkdata;
  172421. key=chunkdata;
  172422. if (comp_flag)
  172423. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172424. (size_t)length, prefix_len, &data_len);
  172425. else
  172426. data_len=png_strlen(chunkdata + prefix_len);
  172427. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172428. (png_uint_32)png_sizeof(png_text));
  172429. if (text_ptr == NULL)
  172430. {
  172431. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172432. png_free(png_ptr, chunkdata);
  172433. return;
  172434. }
  172435. text_ptr->compression = (int)comp_flag + 1;
  172436. text_ptr->lang_key = chunkdata+(lang_key-key);
  172437. text_ptr->lang = chunkdata+(lang-key);
  172438. text_ptr->itxt_length = data_len;
  172439. text_ptr->text_length = 0;
  172440. text_ptr->key = chunkdata;
  172441. text_ptr->text = chunkdata + prefix_len;
  172442. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172443. png_free(png_ptr, text_ptr);
  172444. png_free(png_ptr, chunkdata);
  172445. if (ret)
  172446. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172447. }
  172448. #endif
  172449. void /* PRIVATE */
  172450. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172451. {
  172452. png_uint_32 skip = 0;
  172453. png_debug(1, "in png_handle_unknown\n");
  172454. if (png_ptr->mode & PNG_HAVE_IDAT)
  172455. {
  172456. #ifdef PNG_USE_LOCAL_ARRAYS
  172457. PNG_CONST PNG_IDAT;
  172458. #endif
  172459. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172460. png_ptr->mode |= PNG_AFTER_IDAT;
  172461. }
  172462. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172463. if (!(png_ptr->chunk_name[0] & 0x20))
  172464. {
  172465. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172466. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172467. PNG_HANDLE_CHUNK_ALWAYS
  172468. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172469. && png_ptr->read_user_chunk_fn == NULL
  172470. #endif
  172471. )
  172472. #endif
  172473. png_chunk_error(png_ptr, "unknown critical chunk");
  172474. }
  172475. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172476. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172477. (png_ptr->read_user_chunk_fn != NULL))
  172478. {
  172479. #ifdef PNG_MAX_MALLOC_64K
  172480. if (length > (png_uint_32)65535L)
  172481. {
  172482. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172483. skip = length - (png_uint_32)65535L;
  172484. length = (png_uint_32)65535L;
  172485. }
  172486. #endif
  172487. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172488. (png_charp)png_ptr->chunk_name, 5);
  172489. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172490. png_ptr->unknown_chunk.size = (png_size_t)length;
  172491. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172492. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172493. if(png_ptr->read_user_chunk_fn != NULL)
  172494. {
  172495. int ret;
  172496. ret = (*(png_ptr->read_user_chunk_fn))
  172497. (png_ptr, &png_ptr->unknown_chunk);
  172498. if (ret < 0)
  172499. png_chunk_error(png_ptr, "error in user chunk");
  172500. if (ret == 0)
  172501. {
  172502. if (!(png_ptr->chunk_name[0] & 0x20))
  172503. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172504. PNG_HANDLE_CHUNK_ALWAYS)
  172505. png_chunk_error(png_ptr, "unknown critical chunk");
  172506. png_set_unknown_chunks(png_ptr, info_ptr,
  172507. &png_ptr->unknown_chunk, 1);
  172508. }
  172509. }
  172510. #else
  172511. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172512. #endif
  172513. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172514. png_ptr->unknown_chunk.data = NULL;
  172515. }
  172516. else
  172517. #endif
  172518. skip = length;
  172519. png_crc_finish(png_ptr, skip);
  172520. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172521. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172522. #endif
  172523. }
  172524. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172525. void /* PRIVATE */
  172526. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172527. {
  172528. png_debug(1, "in png_check_chunk_name\n");
  172529. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172530. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172531. {
  172532. png_chunk_error(png_ptr, "invalid chunk type");
  172533. }
  172534. }
  172535. void /* PRIVATE */
  172536. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172537. {
  172538. png_debug(1,"in png_combine_row\n");
  172539. if (mask == 0xff)
  172540. {
  172541. png_memcpy(row, png_ptr->row_buf + 1,
  172542. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172543. }
  172544. else
  172545. {
  172546. switch (png_ptr->row_info.pixel_depth)
  172547. {
  172548. case 1:
  172549. {
  172550. png_bytep sp = png_ptr->row_buf + 1;
  172551. png_bytep dp = row;
  172552. int s_inc, s_start, s_end;
  172553. int m = 0x80;
  172554. int shift;
  172555. png_uint_32 i;
  172556. png_uint_32 row_width = png_ptr->width;
  172557. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172558. if (png_ptr->transformations & PNG_PACKSWAP)
  172559. {
  172560. s_start = 0;
  172561. s_end = 7;
  172562. s_inc = 1;
  172563. }
  172564. else
  172565. #endif
  172566. {
  172567. s_start = 7;
  172568. s_end = 0;
  172569. s_inc = -1;
  172570. }
  172571. shift = s_start;
  172572. for (i = 0; i < row_width; i++)
  172573. {
  172574. if (m & mask)
  172575. {
  172576. int value;
  172577. value = (*sp >> shift) & 0x01;
  172578. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172579. *dp |= (png_byte)(value << shift);
  172580. }
  172581. if (shift == s_end)
  172582. {
  172583. shift = s_start;
  172584. sp++;
  172585. dp++;
  172586. }
  172587. else
  172588. shift += s_inc;
  172589. if (m == 1)
  172590. m = 0x80;
  172591. else
  172592. m >>= 1;
  172593. }
  172594. break;
  172595. }
  172596. case 2:
  172597. {
  172598. png_bytep sp = png_ptr->row_buf + 1;
  172599. png_bytep dp = row;
  172600. int s_start, s_end, s_inc;
  172601. int m = 0x80;
  172602. int shift;
  172603. png_uint_32 i;
  172604. png_uint_32 row_width = png_ptr->width;
  172605. int value;
  172606. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172607. if (png_ptr->transformations & PNG_PACKSWAP)
  172608. {
  172609. s_start = 0;
  172610. s_end = 6;
  172611. s_inc = 2;
  172612. }
  172613. else
  172614. #endif
  172615. {
  172616. s_start = 6;
  172617. s_end = 0;
  172618. s_inc = -2;
  172619. }
  172620. shift = s_start;
  172621. for (i = 0; i < row_width; i++)
  172622. {
  172623. if (m & mask)
  172624. {
  172625. value = (*sp >> shift) & 0x03;
  172626. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172627. *dp |= (png_byte)(value << shift);
  172628. }
  172629. if (shift == s_end)
  172630. {
  172631. shift = s_start;
  172632. sp++;
  172633. dp++;
  172634. }
  172635. else
  172636. shift += s_inc;
  172637. if (m == 1)
  172638. m = 0x80;
  172639. else
  172640. m >>= 1;
  172641. }
  172642. break;
  172643. }
  172644. case 4:
  172645. {
  172646. png_bytep sp = png_ptr->row_buf + 1;
  172647. png_bytep dp = row;
  172648. int s_start, s_end, s_inc;
  172649. int m = 0x80;
  172650. int shift;
  172651. png_uint_32 i;
  172652. png_uint_32 row_width = png_ptr->width;
  172653. int value;
  172654. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172655. if (png_ptr->transformations & PNG_PACKSWAP)
  172656. {
  172657. s_start = 0;
  172658. s_end = 4;
  172659. s_inc = 4;
  172660. }
  172661. else
  172662. #endif
  172663. {
  172664. s_start = 4;
  172665. s_end = 0;
  172666. s_inc = -4;
  172667. }
  172668. shift = s_start;
  172669. for (i = 0; i < row_width; i++)
  172670. {
  172671. if (m & mask)
  172672. {
  172673. value = (*sp >> shift) & 0xf;
  172674. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172675. *dp |= (png_byte)(value << shift);
  172676. }
  172677. if (shift == s_end)
  172678. {
  172679. shift = s_start;
  172680. sp++;
  172681. dp++;
  172682. }
  172683. else
  172684. shift += s_inc;
  172685. if (m == 1)
  172686. m = 0x80;
  172687. else
  172688. m >>= 1;
  172689. }
  172690. break;
  172691. }
  172692. default:
  172693. {
  172694. png_bytep sp = png_ptr->row_buf + 1;
  172695. png_bytep dp = row;
  172696. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172697. png_uint_32 i;
  172698. png_uint_32 row_width = png_ptr->width;
  172699. png_byte m = 0x80;
  172700. for (i = 0; i < row_width; i++)
  172701. {
  172702. if (m & mask)
  172703. {
  172704. png_memcpy(dp, sp, pixel_bytes);
  172705. }
  172706. sp += pixel_bytes;
  172707. dp += pixel_bytes;
  172708. if (m == 1)
  172709. m = 0x80;
  172710. else
  172711. m >>= 1;
  172712. }
  172713. break;
  172714. }
  172715. }
  172716. }
  172717. }
  172718. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172719. void /* PRIVATE */
  172720. png_do_read_interlace(png_structp png_ptr)
  172721. {
  172722. png_row_infop row_info = &(png_ptr->row_info);
  172723. png_bytep row = png_ptr->row_buf + 1;
  172724. int pass = png_ptr->pass;
  172725. png_uint_32 transformations = png_ptr->transformations;
  172726. #ifdef PNG_USE_LOCAL_ARRAYS
  172727. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172728. #endif
  172729. png_debug(1,"in png_do_read_interlace\n");
  172730. if (row != NULL && row_info != NULL)
  172731. {
  172732. png_uint_32 final_width;
  172733. final_width = row_info->width * png_pass_inc[pass];
  172734. switch (row_info->pixel_depth)
  172735. {
  172736. case 1:
  172737. {
  172738. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172739. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172740. int sshift, dshift;
  172741. int s_start, s_end, s_inc;
  172742. int jstop = png_pass_inc[pass];
  172743. png_byte v;
  172744. png_uint_32 i;
  172745. int j;
  172746. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172747. if (transformations & PNG_PACKSWAP)
  172748. {
  172749. sshift = (int)((row_info->width + 7) & 0x07);
  172750. dshift = (int)((final_width + 7) & 0x07);
  172751. s_start = 7;
  172752. s_end = 0;
  172753. s_inc = -1;
  172754. }
  172755. else
  172756. #endif
  172757. {
  172758. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172759. dshift = 7 - (int)((final_width + 7) & 0x07);
  172760. s_start = 0;
  172761. s_end = 7;
  172762. s_inc = 1;
  172763. }
  172764. for (i = 0; i < row_info->width; i++)
  172765. {
  172766. v = (png_byte)((*sp >> sshift) & 0x01);
  172767. for (j = 0; j < jstop; j++)
  172768. {
  172769. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172770. *dp |= (png_byte)(v << dshift);
  172771. if (dshift == s_end)
  172772. {
  172773. dshift = s_start;
  172774. dp--;
  172775. }
  172776. else
  172777. dshift += s_inc;
  172778. }
  172779. if (sshift == s_end)
  172780. {
  172781. sshift = s_start;
  172782. sp--;
  172783. }
  172784. else
  172785. sshift += s_inc;
  172786. }
  172787. break;
  172788. }
  172789. case 2:
  172790. {
  172791. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172792. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172793. int sshift, dshift;
  172794. int s_start, s_end, s_inc;
  172795. int jstop = png_pass_inc[pass];
  172796. png_uint_32 i;
  172797. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172798. if (transformations & PNG_PACKSWAP)
  172799. {
  172800. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172801. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172802. s_start = 6;
  172803. s_end = 0;
  172804. s_inc = -2;
  172805. }
  172806. else
  172807. #endif
  172808. {
  172809. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172810. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172811. s_start = 0;
  172812. s_end = 6;
  172813. s_inc = 2;
  172814. }
  172815. for (i = 0; i < row_info->width; i++)
  172816. {
  172817. png_byte v;
  172818. int j;
  172819. v = (png_byte)((*sp >> sshift) & 0x03);
  172820. for (j = 0; j < jstop; j++)
  172821. {
  172822. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172823. *dp |= (png_byte)(v << dshift);
  172824. if (dshift == s_end)
  172825. {
  172826. dshift = s_start;
  172827. dp--;
  172828. }
  172829. else
  172830. dshift += s_inc;
  172831. }
  172832. if (sshift == s_end)
  172833. {
  172834. sshift = s_start;
  172835. sp--;
  172836. }
  172837. else
  172838. sshift += s_inc;
  172839. }
  172840. break;
  172841. }
  172842. case 4:
  172843. {
  172844. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172845. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172846. int sshift, dshift;
  172847. int s_start, s_end, s_inc;
  172848. png_uint_32 i;
  172849. int jstop = png_pass_inc[pass];
  172850. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172851. if (transformations & PNG_PACKSWAP)
  172852. {
  172853. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172854. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172855. s_start = 4;
  172856. s_end = 0;
  172857. s_inc = -4;
  172858. }
  172859. else
  172860. #endif
  172861. {
  172862. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172863. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172864. s_start = 0;
  172865. s_end = 4;
  172866. s_inc = 4;
  172867. }
  172868. for (i = 0; i < row_info->width; i++)
  172869. {
  172870. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172871. int j;
  172872. for (j = 0; j < jstop; j++)
  172873. {
  172874. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172875. *dp |= (png_byte)(v << dshift);
  172876. if (dshift == s_end)
  172877. {
  172878. dshift = s_start;
  172879. dp--;
  172880. }
  172881. else
  172882. dshift += s_inc;
  172883. }
  172884. if (sshift == s_end)
  172885. {
  172886. sshift = s_start;
  172887. sp--;
  172888. }
  172889. else
  172890. sshift += s_inc;
  172891. }
  172892. break;
  172893. }
  172894. default:
  172895. {
  172896. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172897. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172898. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172899. int jstop = png_pass_inc[pass];
  172900. png_uint_32 i;
  172901. for (i = 0; i < row_info->width; i++)
  172902. {
  172903. png_byte v[8];
  172904. int j;
  172905. png_memcpy(v, sp, pixel_bytes);
  172906. for (j = 0; j < jstop; j++)
  172907. {
  172908. png_memcpy(dp, v, pixel_bytes);
  172909. dp -= pixel_bytes;
  172910. }
  172911. sp -= pixel_bytes;
  172912. }
  172913. break;
  172914. }
  172915. }
  172916. row_info->width = final_width;
  172917. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172918. }
  172919. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  172920. transformations = transformations; /* silence compiler warning */
  172921. #endif
  172922. }
  172923. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  172924. void /* PRIVATE */
  172925. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  172926. png_bytep prev_row, int filter)
  172927. {
  172928. png_debug(1, "in png_read_filter_row\n");
  172929. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  172930. switch (filter)
  172931. {
  172932. case PNG_FILTER_VALUE_NONE:
  172933. break;
  172934. case PNG_FILTER_VALUE_SUB:
  172935. {
  172936. png_uint_32 i;
  172937. png_uint_32 istop = row_info->rowbytes;
  172938. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172939. png_bytep rp = row + bpp;
  172940. png_bytep lp = row;
  172941. for (i = bpp; i < istop; i++)
  172942. {
  172943. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  172944. rp++;
  172945. }
  172946. break;
  172947. }
  172948. case PNG_FILTER_VALUE_UP:
  172949. {
  172950. png_uint_32 i;
  172951. png_uint_32 istop = row_info->rowbytes;
  172952. png_bytep rp = row;
  172953. png_bytep pp = prev_row;
  172954. for (i = 0; i < istop; i++)
  172955. {
  172956. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172957. rp++;
  172958. }
  172959. break;
  172960. }
  172961. case PNG_FILTER_VALUE_AVG:
  172962. {
  172963. png_uint_32 i;
  172964. png_bytep rp = row;
  172965. png_bytep pp = prev_row;
  172966. png_bytep lp = row;
  172967. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172968. png_uint_32 istop = row_info->rowbytes - bpp;
  172969. for (i = 0; i < bpp; i++)
  172970. {
  172971. *rp = (png_byte)(((int)(*rp) +
  172972. ((int)(*pp++) / 2 )) & 0xff);
  172973. rp++;
  172974. }
  172975. for (i = 0; i < istop; i++)
  172976. {
  172977. *rp = (png_byte)(((int)(*rp) +
  172978. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  172979. rp++;
  172980. }
  172981. break;
  172982. }
  172983. case PNG_FILTER_VALUE_PAETH:
  172984. {
  172985. png_uint_32 i;
  172986. png_bytep rp = row;
  172987. png_bytep pp = prev_row;
  172988. png_bytep lp = row;
  172989. png_bytep cp = prev_row;
  172990. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172991. png_uint_32 istop=row_info->rowbytes - bpp;
  172992. for (i = 0; i < bpp; i++)
  172993. {
  172994. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172995. rp++;
  172996. }
  172997. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  172998. {
  172999. int a, b, c, pa, pb, pc, p;
  173000. a = *lp++;
  173001. b = *pp++;
  173002. c = *cp++;
  173003. p = b - c;
  173004. pc = a - c;
  173005. #ifdef PNG_USE_ABS
  173006. pa = abs(p);
  173007. pb = abs(pc);
  173008. pc = abs(p + pc);
  173009. #else
  173010. pa = p < 0 ? -p : p;
  173011. pb = pc < 0 ? -pc : pc;
  173012. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173013. #endif
  173014. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173015. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173016. rp++;
  173017. }
  173018. break;
  173019. }
  173020. default:
  173021. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173022. *row=0;
  173023. break;
  173024. }
  173025. }
  173026. void /* PRIVATE */
  173027. png_read_finish_row(png_structp png_ptr)
  173028. {
  173029. #ifdef PNG_USE_LOCAL_ARRAYS
  173030. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173031. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173032. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173033. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173034. #endif
  173035. png_debug(1, "in png_read_finish_row\n");
  173036. png_ptr->row_number++;
  173037. if (png_ptr->row_number < png_ptr->num_rows)
  173038. return;
  173039. if (png_ptr->interlaced)
  173040. {
  173041. png_ptr->row_number = 0;
  173042. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173043. png_ptr->rowbytes + 1);
  173044. do
  173045. {
  173046. png_ptr->pass++;
  173047. if (png_ptr->pass >= 7)
  173048. break;
  173049. png_ptr->iwidth = (png_ptr->width +
  173050. png_pass_inc[png_ptr->pass] - 1 -
  173051. png_pass_start[png_ptr->pass]) /
  173052. png_pass_inc[png_ptr->pass];
  173053. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173054. png_ptr->iwidth) + 1;
  173055. if (!(png_ptr->transformations & PNG_INTERLACE))
  173056. {
  173057. png_ptr->num_rows = (png_ptr->height +
  173058. png_pass_yinc[png_ptr->pass] - 1 -
  173059. png_pass_ystart[png_ptr->pass]) /
  173060. png_pass_yinc[png_ptr->pass];
  173061. if (!(png_ptr->num_rows))
  173062. continue;
  173063. }
  173064. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173065. break;
  173066. } while (png_ptr->iwidth == 0);
  173067. if (png_ptr->pass < 7)
  173068. return;
  173069. }
  173070. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173071. {
  173072. #ifdef PNG_USE_LOCAL_ARRAYS
  173073. PNG_CONST PNG_IDAT;
  173074. #endif
  173075. char extra;
  173076. int ret;
  173077. png_ptr->zstream.next_out = (Bytef *)&extra;
  173078. png_ptr->zstream.avail_out = (uInt)1;
  173079. for(;;)
  173080. {
  173081. if (!(png_ptr->zstream.avail_in))
  173082. {
  173083. while (!png_ptr->idat_size)
  173084. {
  173085. png_byte chunk_length[4];
  173086. png_crc_finish(png_ptr, 0);
  173087. png_read_data(png_ptr, chunk_length, 4);
  173088. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173089. png_reset_crc(png_ptr);
  173090. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173091. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173092. png_error(png_ptr, "Not enough image data");
  173093. }
  173094. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173095. png_ptr->zstream.next_in = png_ptr->zbuf;
  173096. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173097. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173098. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173099. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173100. }
  173101. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173102. if (ret == Z_STREAM_END)
  173103. {
  173104. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173105. png_ptr->idat_size)
  173106. png_warning(png_ptr, "Extra compressed data");
  173107. png_ptr->mode |= PNG_AFTER_IDAT;
  173108. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173109. break;
  173110. }
  173111. if (ret != Z_OK)
  173112. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173113. "Decompression Error");
  173114. if (!(png_ptr->zstream.avail_out))
  173115. {
  173116. png_warning(png_ptr, "Extra compressed data.");
  173117. png_ptr->mode |= PNG_AFTER_IDAT;
  173118. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173119. break;
  173120. }
  173121. }
  173122. png_ptr->zstream.avail_out = 0;
  173123. }
  173124. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173125. png_warning(png_ptr, "Extra compression data");
  173126. inflateReset(&png_ptr->zstream);
  173127. png_ptr->mode |= PNG_AFTER_IDAT;
  173128. }
  173129. void /* PRIVATE */
  173130. png_read_start_row(png_structp png_ptr)
  173131. {
  173132. #ifdef PNG_USE_LOCAL_ARRAYS
  173133. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173134. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173135. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173136. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173137. #endif
  173138. int max_pixel_depth;
  173139. png_uint_32 row_bytes;
  173140. png_debug(1, "in png_read_start_row\n");
  173141. png_ptr->zstream.avail_in = 0;
  173142. png_init_read_transformations(png_ptr);
  173143. if (png_ptr->interlaced)
  173144. {
  173145. if (!(png_ptr->transformations & PNG_INTERLACE))
  173146. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173147. png_pass_ystart[0]) / png_pass_yinc[0];
  173148. else
  173149. png_ptr->num_rows = png_ptr->height;
  173150. png_ptr->iwidth = (png_ptr->width +
  173151. png_pass_inc[png_ptr->pass] - 1 -
  173152. png_pass_start[png_ptr->pass]) /
  173153. png_pass_inc[png_ptr->pass];
  173154. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173155. png_ptr->irowbytes = (png_size_t)row_bytes;
  173156. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173157. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173158. }
  173159. else
  173160. {
  173161. png_ptr->num_rows = png_ptr->height;
  173162. png_ptr->iwidth = png_ptr->width;
  173163. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173164. }
  173165. max_pixel_depth = png_ptr->pixel_depth;
  173166. #if defined(PNG_READ_PACK_SUPPORTED)
  173167. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173168. max_pixel_depth = 8;
  173169. #endif
  173170. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173171. if (png_ptr->transformations & PNG_EXPAND)
  173172. {
  173173. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173174. {
  173175. if (png_ptr->num_trans)
  173176. max_pixel_depth = 32;
  173177. else
  173178. max_pixel_depth = 24;
  173179. }
  173180. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173181. {
  173182. if (max_pixel_depth < 8)
  173183. max_pixel_depth = 8;
  173184. if (png_ptr->num_trans)
  173185. max_pixel_depth *= 2;
  173186. }
  173187. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173188. {
  173189. if (png_ptr->num_trans)
  173190. {
  173191. max_pixel_depth *= 4;
  173192. max_pixel_depth /= 3;
  173193. }
  173194. }
  173195. }
  173196. #endif
  173197. #if defined(PNG_READ_FILLER_SUPPORTED)
  173198. if (png_ptr->transformations & (PNG_FILLER))
  173199. {
  173200. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173201. max_pixel_depth = 32;
  173202. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173203. {
  173204. if (max_pixel_depth <= 8)
  173205. max_pixel_depth = 16;
  173206. else
  173207. max_pixel_depth = 32;
  173208. }
  173209. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173210. {
  173211. if (max_pixel_depth <= 32)
  173212. max_pixel_depth = 32;
  173213. else
  173214. max_pixel_depth = 64;
  173215. }
  173216. }
  173217. #endif
  173218. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173219. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173220. {
  173221. if (
  173222. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173223. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173224. #endif
  173225. #if defined(PNG_READ_FILLER_SUPPORTED)
  173226. (png_ptr->transformations & (PNG_FILLER)) ||
  173227. #endif
  173228. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173229. {
  173230. if (max_pixel_depth <= 16)
  173231. max_pixel_depth = 32;
  173232. else
  173233. max_pixel_depth = 64;
  173234. }
  173235. else
  173236. {
  173237. if (max_pixel_depth <= 8)
  173238. {
  173239. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173240. max_pixel_depth = 32;
  173241. else
  173242. max_pixel_depth = 24;
  173243. }
  173244. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173245. max_pixel_depth = 64;
  173246. else
  173247. max_pixel_depth = 48;
  173248. }
  173249. }
  173250. #endif
  173251. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173252. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173253. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173254. {
  173255. int user_pixel_depth=png_ptr->user_transform_depth*
  173256. png_ptr->user_transform_channels;
  173257. if(user_pixel_depth > max_pixel_depth)
  173258. max_pixel_depth=user_pixel_depth;
  173259. }
  173260. #endif
  173261. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173262. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173263. 1 + ((max_pixel_depth + 7) >> 3);
  173264. #ifdef PNG_MAX_MALLOC_64K
  173265. if (row_bytes > (png_uint_32)65536L)
  173266. png_error(png_ptr, "This image requires a row greater than 64KB");
  173267. #endif
  173268. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173269. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173270. #ifdef PNG_MAX_MALLOC_64K
  173271. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173272. png_error(png_ptr, "This image requires a row greater than 64KB");
  173273. #endif
  173274. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173275. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173276. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173277. png_ptr->rowbytes + 1));
  173278. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173279. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173280. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173281. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173282. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173283. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173284. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173285. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173286. }
  173287. #endif /* PNG_READ_SUPPORTED */
  173288. /*** End of inlined file: pngrutil.c ***/
  173289. /*** Start of inlined file: pngset.c ***/
  173290. #define PNG_INTERNAL
  173291. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173292. #if defined(PNG_bKGD_SUPPORTED)
  173293. void PNGAPI
  173294. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173295. {
  173296. png_debug1(1, "in %s storage function\n", "bKGD");
  173297. if (png_ptr == NULL || info_ptr == NULL)
  173298. return;
  173299. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173300. info_ptr->valid |= PNG_INFO_bKGD;
  173301. }
  173302. #endif
  173303. #if defined(PNG_cHRM_SUPPORTED)
  173304. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173305. void PNGAPI
  173306. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173307. double white_x, double white_y, double red_x, double red_y,
  173308. double green_x, double green_y, double blue_x, double blue_y)
  173309. {
  173310. png_debug1(1, "in %s storage function\n", "cHRM");
  173311. if (png_ptr == NULL || info_ptr == NULL)
  173312. return;
  173313. if (white_x < 0.0 || white_y < 0.0 ||
  173314. red_x < 0.0 || red_y < 0.0 ||
  173315. green_x < 0.0 || green_y < 0.0 ||
  173316. blue_x < 0.0 || blue_y < 0.0)
  173317. {
  173318. png_warning(png_ptr,
  173319. "Ignoring attempt to set negative chromaticity value");
  173320. return;
  173321. }
  173322. if (white_x > 21474.83 || white_y > 21474.83 ||
  173323. red_x > 21474.83 || red_y > 21474.83 ||
  173324. green_x > 21474.83 || green_y > 21474.83 ||
  173325. blue_x > 21474.83 || blue_y > 21474.83)
  173326. {
  173327. png_warning(png_ptr,
  173328. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173329. return;
  173330. }
  173331. info_ptr->x_white = (float)white_x;
  173332. info_ptr->y_white = (float)white_y;
  173333. info_ptr->x_red = (float)red_x;
  173334. info_ptr->y_red = (float)red_y;
  173335. info_ptr->x_green = (float)green_x;
  173336. info_ptr->y_green = (float)green_y;
  173337. info_ptr->x_blue = (float)blue_x;
  173338. info_ptr->y_blue = (float)blue_y;
  173339. #ifdef PNG_FIXED_POINT_SUPPORTED
  173340. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173341. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173342. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173343. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173344. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173345. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173346. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173347. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173348. #endif
  173349. info_ptr->valid |= PNG_INFO_cHRM;
  173350. }
  173351. #endif
  173352. #ifdef PNG_FIXED_POINT_SUPPORTED
  173353. void PNGAPI
  173354. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173355. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173356. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173357. png_fixed_point blue_x, png_fixed_point blue_y)
  173358. {
  173359. png_debug1(1, "in %s storage function\n", "cHRM");
  173360. if (png_ptr == NULL || info_ptr == NULL)
  173361. return;
  173362. if (white_x < 0 || white_y < 0 ||
  173363. red_x < 0 || red_y < 0 ||
  173364. green_x < 0 || green_y < 0 ||
  173365. blue_x < 0 || blue_y < 0)
  173366. {
  173367. png_warning(png_ptr,
  173368. "Ignoring attempt to set negative chromaticity value");
  173369. return;
  173370. }
  173371. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173372. if (white_x > (double) PNG_UINT_31_MAX ||
  173373. white_y > (double) PNG_UINT_31_MAX ||
  173374. red_x > (double) PNG_UINT_31_MAX ||
  173375. red_y > (double) PNG_UINT_31_MAX ||
  173376. green_x > (double) PNG_UINT_31_MAX ||
  173377. green_y > (double) PNG_UINT_31_MAX ||
  173378. blue_x > (double) PNG_UINT_31_MAX ||
  173379. blue_y > (double) PNG_UINT_31_MAX)
  173380. #else
  173381. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173382. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173383. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173384. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173385. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173386. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173387. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173388. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173389. #endif
  173390. {
  173391. png_warning(png_ptr,
  173392. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173393. return;
  173394. }
  173395. info_ptr->int_x_white = white_x;
  173396. info_ptr->int_y_white = white_y;
  173397. info_ptr->int_x_red = red_x;
  173398. info_ptr->int_y_red = red_y;
  173399. info_ptr->int_x_green = green_x;
  173400. info_ptr->int_y_green = green_y;
  173401. info_ptr->int_x_blue = blue_x;
  173402. info_ptr->int_y_blue = blue_y;
  173403. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173404. info_ptr->x_white = (float)(white_x/100000.);
  173405. info_ptr->y_white = (float)(white_y/100000.);
  173406. info_ptr->x_red = (float)( red_x/100000.);
  173407. info_ptr->y_red = (float)( red_y/100000.);
  173408. info_ptr->x_green = (float)(green_x/100000.);
  173409. info_ptr->y_green = (float)(green_y/100000.);
  173410. info_ptr->x_blue = (float)( blue_x/100000.);
  173411. info_ptr->y_blue = (float)( blue_y/100000.);
  173412. #endif
  173413. info_ptr->valid |= PNG_INFO_cHRM;
  173414. }
  173415. #endif
  173416. #endif
  173417. #if defined(PNG_gAMA_SUPPORTED)
  173418. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173419. void PNGAPI
  173420. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173421. {
  173422. double gamma;
  173423. png_debug1(1, "in %s storage function\n", "gAMA");
  173424. if (png_ptr == NULL || info_ptr == NULL)
  173425. return;
  173426. if (file_gamma > 21474.83)
  173427. {
  173428. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173429. gamma=21474.83;
  173430. }
  173431. else
  173432. gamma=file_gamma;
  173433. info_ptr->gamma = (float)gamma;
  173434. #ifdef PNG_FIXED_POINT_SUPPORTED
  173435. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173436. #endif
  173437. info_ptr->valid |= PNG_INFO_gAMA;
  173438. if(gamma == 0.0)
  173439. png_warning(png_ptr, "Setting gamma=0");
  173440. }
  173441. #endif
  173442. void PNGAPI
  173443. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173444. int_gamma)
  173445. {
  173446. png_fixed_point gamma;
  173447. png_debug1(1, "in %s storage function\n", "gAMA");
  173448. if (png_ptr == NULL || info_ptr == NULL)
  173449. return;
  173450. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173451. {
  173452. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173453. gamma=PNG_UINT_31_MAX;
  173454. }
  173455. else
  173456. {
  173457. if (int_gamma < 0)
  173458. {
  173459. png_warning(png_ptr, "Setting negative gamma to zero");
  173460. gamma=0;
  173461. }
  173462. else
  173463. gamma=int_gamma;
  173464. }
  173465. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173466. info_ptr->gamma = (float)(gamma/100000.);
  173467. #endif
  173468. #ifdef PNG_FIXED_POINT_SUPPORTED
  173469. info_ptr->int_gamma = gamma;
  173470. #endif
  173471. info_ptr->valid |= PNG_INFO_gAMA;
  173472. if(gamma == 0)
  173473. png_warning(png_ptr, "Setting gamma=0");
  173474. }
  173475. #endif
  173476. #if defined(PNG_hIST_SUPPORTED)
  173477. void PNGAPI
  173478. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173479. {
  173480. int i;
  173481. png_debug1(1, "in %s storage function\n", "hIST");
  173482. if (png_ptr == NULL || info_ptr == NULL)
  173483. return;
  173484. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173485. > PNG_MAX_PALETTE_LENGTH)
  173486. {
  173487. png_warning(png_ptr,
  173488. "Invalid palette size, hIST allocation skipped.");
  173489. return;
  173490. }
  173491. #ifdef PNG_FREE_ME_SUPPORTED
  173492. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173493. #endif
  173494. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173495. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173496. if (png_ptr->hist == NULL)
  173497. {
  173498. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173499. return;
  173500. }
  173501. for (i = 0; i < info_ptr->num_palette; i++)
  173502. png_ptr->hist[i] = hist[i];
  173503. info_ptr->hist = png_ptr->hist;
  173504. info_ptr->valid |= PNG_INFO_hIST;
  173505. #ifdef PNG_FREE_ME_SUPPORTED
  173506. info_ptr->free_me |= PNG_FREE_HIST;
  173507. #else
  173508. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173509. #endif
  173510. }
  173511. #endif
  173512. void PNGAPI
  173513. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173514. png_uint_32 width, png_uint_32 height, int bit_depth,
  173515. int color_type, int interlace_type, int compression_type,
  173516. int filter_type)
  173517. {
  173518. png_debug1(1, "in %s storage function\n", "IHDR");
  173519. if (png_ptr == NULL || info_ptr == NULL)
  173520. return;
  173521. if (width == 0 || height == 0)
  173522. png_error(png_ptr, "Image width or height is zero in IHDR");
  173523. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173524. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173525. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173526. #else
  173527. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173528. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173529. #endif
  173530. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173531. png_error(png_ptr, "Invalid image size in IHDR");
  173532. if ( width > (PNG_UINT_32_MAX
  173533. >> 3) /* 8-byte RGBA pixels */
  173534. - 64 /* bigrowbuf hack */
  173535. - 1 /* filter byte */
  173536. - 7*8 /* rounding of width to multiple of 8 pixels */
  173537. - 8) /* extra max_pixel_depth pad */
  173538. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173539. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173540. bit_depth != 8 && bit_depth != 16)
  173541. png_error(png_ptr, "Invalid bit depth in IHDR");
  173542. if (color_type < 0 || color_type == 1 ||
  173543. color_type == 5 || color_type > 6)
  173544. png_error(png_ptr, "Invalid color type in IHDR");
  173545. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173546. ((color_type == PNG_COLOR_TYPE_RGB ||
  173547. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173548. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173549. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173550. if (interlace_type >= PNG_INTERLACE_LAST)
  173551. png_error(png_ptr, "Unknown interlace method in IHDR");
  173552. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173553. png_error(png_ptr, "Unknown compression method in IHDR");
  173554. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173555. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173556. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173557. if(filter_type != PNG_FILTER_TYPE_BASE)
  173558. {
  173559. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173560. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173561. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173562. (color_type == PNG_COLOR_TYPE_RGB ||
  173563. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173564. png_error(png_ptr, "Unknown filter method in IHDR");
  173565. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173566. png_warning(png_ptr, "Invalid filter method in IHDR");
  173567. }
  173568. #else
  173569. if(filter_type != PNG_FILTER_TYPE_BASE)
  173570. png_error(png_ptr, "Unknown filter method in IHDR");
  173571. #endif
  173572. info_ptr->width = width;
  173573. info_ptr->height = height;
  173574. info_ptr->bit_depth = (png_byte)bit_depth;
  173575. info_ptr->color_type =(png_byte) color_type;
  173576. info_ptr->compression_type = (png_byte)compression_type;
  173577. info_ptr->filter_type = (png_byte)filter_type;
  173578. info_ptr->interlace_type = (png_byte)interlace_type;
  173579. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173580. info_ptr->channels = 1;
  173581. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173582. info_ptr->channels = 3;
  173583. else
  173584. info_ptr->channels = 1;
  173585. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173586. info_ptr->channels++;
  173587. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173588. if (width > (PNG_UINT_32_MAX
  173589. >> 3) /* 8-byte RGBA pixels */
  173590. - 64 /* bigrowbuf hack */
  173591. - 1 /* filter byte */
  173592. - 7*8 /* rounding of width to multiple of 8 pixels */
  173593. - 8) /* extra max_pixel_depth pad */
  173594. info_ptr->rowbytes = (png_size_t)0;
  173595. else
  173596. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173597. }
  173598. #if defined(PNG_oFFs_SUPPORTED)
  173599. void PNGAPI
  173600. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173601. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173602. {
  173603. png_debug1(1, "in %s storage function\n", "oFFs");
  173604. if (png_ptr == NULL || info_ptr == NULL)
  173605. return;
  173606. info_ptr->x_offset = offset_x;
  173607. info_ptr->y_offset = offset_y;
  173608. info_ptr->offset_unit_type = (png_byte)unit_type;
  173609. info_ptr->valid |= PNG_INFO_oFFs;
  173610. }
  173611. #endif
  173612. #if defined(PNG_pCAL_SUPPORTED)
  173613. void PNGAPI
  173614. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173615. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173616. png_charp units, png_charpp params)
  173617. {
  173618. png_uint_32 length;
  173619. int i;
  173620. png_debug1(1, "in %s storage function\n", "pCAL");
  173621. if (png_ptr == NULL || info_ptr == NULL)
  173622. return;
  173623. length = png_strlen(purpose) + 1;
  173624. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173625. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173626. if (info_ptr->pcal_purpose == NULL)
  173627. {
  173628. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173629. return;
  173630. }
  173631. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173632. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173633. info_ptr->pcal_X0 = X0;
  173634. info_ptr->pcal_X1 = X1;
  173635. info_ptr->pcal_type = (png_byte)type;
  173636. info_ptr->pcal_nparams = (png_byte)nparams;
  173637. length = png_strlen(units) + 1;
  173638. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173639. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173640. if (info_ptr->pcal_units == NULL)
  173641. {
  173642. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173643. return;
  173644. }
  173645. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173646. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173647. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173648. if (info_ptr->pcal_params == NULL)
  173649. {
  173650. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173651. return;
  173652. }
  173653. info_ptr->pcal_params[nparams] = NULL;
  173654. for (i = 0; i < nparams; i++)
  173655. {
  173656. length = png_strlen(params[i]) + 1;
  173657. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173658. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173659. if (info_ptr->pcal_params[i] == NULL)
  173660. {
  173661. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173662. return;
  173663. }
  173664. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173665. }
  173666. info_ptr->valid |= PNG_INFO_pCAL;
  173667. #ifdef PNG_FREE_ME_SUPPORTED
  173668. info_ptr->free_me |= PNG_FREE_PCAL;
  173669. #endif
  173670. }
  173671. #endif
  173672. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173673. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173674. void PNGAPI
  173675. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173676. int unit, double width, double height)
  173677. {
  173678. png_debug1(1, "in %s storage function\n", "sCAL");
  173679. if (png_ptr == NULL || info_ptr == NULL)
  173680. return;
  173681. info_ptr->scal_unit = (png_byte)unit;
  173682. info_ptr->scal_pixel_width = width;
  173683. info_ptr->scal_pixel_height = height;
  173684. info_ptr->valid |= PNG_INFO_sCAL;
  173685. }
  173686. #else
  173687. #ifdef PNG_FIXED_POINT_SUPPORTED
  173688. void PNGAPI
  173689. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173690. int unit, png_charp swidth, png_charp sheight)
  173691. {
  173692. png_uint_32 length;
  173693. png_debug1(1, "in %s storage function\n", "sCAL");
  173694. if (png_ptr == NULL || info_ptr == NULL)
  173695. return;
  173696. info_ptr->scal_unit = (png_byte)unit;
  173697. length = png_strlen(swidth) + 1;
  173698. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173699. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173700. if (info_ptr->scal_s_width == NULL)
  173701. {
  173702. png_warning(png_ptr,
  173703. "Memory allocation failed while processing sCAL.");
  173704. }
  173705. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173706. length = png_strlen(sheight) + 1;
  173707. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173708. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173709. if (info_ptr->scal_s_height == NULL)
  173710. {
  173711. png_free (png_ptr, info_ptr->scal_s_width);
  173712. png_warning(png_ptr,
  173713. "Memory allocation failed while processing sCAL.");
  173714. }
  173715. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173716. info_ptr->valid |= PNG_INFO_sCAL;
  173717. #ifdef PNG_FREE_ME_SUPPORTED
  173718. info_ptr->free_me |= PNG_FREE_SCAL;
  173719. #endif
  173720. }
  173721. #endif
  173722. #endif
  173723. #endif
  173724. #if defined(PNG_pHYs_SUPPORTED)
  173725. void PNGAPI
  173726. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173727. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173728. {
  173729. png_debug1(1, "in %s storage function\n", "pHYs");
  173730. if (png_ptr == NULL || info_ptr == NULL)
  173731. return;
  173732. info_ptr->x_pixels_per_unit = res_x;
  173733. info_ptr->y_pixels_per_unit = res_y;
  173734. info_ptr->phys_unit_type = (png_byte)unit_type;
  173735. info_ptr->valid |= PNG_INFO_pHYs;
  173736. }
  173737. #endif
  173738. void PNGAPI
  173739. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173740. png_colorp palette, int num_palette)
  173741. {
  173742. png_debug1(1, "in %s storage function\n", "PLTE");
  173743. if (png_ptr == NULL || info_ptr == NULL)
  173744. return;
  173745. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173746. {
  173747. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173748. png_error(png_ptr, "Invalid palette length");
  173749. else
  173750. {
  173751. png_warning(png_ptr, "Invalid palette length");
  173752. return;
  173753. }
  173754. }
  173755. #ifdef PNG_FREE_ME_SUPPORTED
  173756. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173757. #endif
  173758. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173759. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173760. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173761. png_sizeof(png_color));
  173762. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173763. info_ptr->palette = png_ptr->palette;
  173764. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173765. #ifdef PNG_FREE_ME_SUPPORTED
  173766. info_ptr->free_me |= PNG_FREE_PLTE;
  173767. #else
  173768. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173769. #endif
  173770. info_ptr->valid |= PNG_INFO_PLTE;
  173771. }
  173772. #if defined(PNG_sBIT_SUPPORTED)
  173773. void PNGAPI
  173774. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173775. png_color_8p sig_bit)
  173776. {
  173777. png_debug1(1, "in %s storage function\n", "sBIT");
  173778. if (png_ptr == NULL || info_ptr == NULL)
  173779. return;
  173780. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173781. info_ptr->valid |= PNG_INFO_sBIT;
  173782. }
  173783. #endif
  173784. #if defined(PNG_sRGB_SUPPORTED)
  173785. void PNGAPI
  173786. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173787. {
  173788. png_debug1(1, "in %s storage function\n", "sRGB");
  173789. if (png_ptr == NULL || info_ptr == NULL)
  173790. return;
  173791. info_ptr->srgb_intent = (png_byte)intent;
  173792. info_ptr->valid |= PNG_INFO_sRGB;
  173793. }
  173794. void PNGAPI
  173795. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173796. int intent)
  173797. {
  173798. #if defined(PNG_gAMA_SUPPORTED)
  173799. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173800. float file_gamma;
  173801. #endif
  173802. #ifdef PNG_FIXED_POINT_SUPPORTED
  173803. png_fixed_point int_file_gamma;
  173804. #endif
  173805. #endif
  173806. #if defined(PNG_cHRM_SUPPORTED)
  173807. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173808. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173809. #endif
  173810. #ifdef PNG_FIXED_POINT_SUPPORTED
  173811. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173812. int_green_y, int_blue_x, int_blue_y;
  173813. #endif
  173814. #endif
  173815. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173816. if (png_ptr == NULL || info_ptr == NULL)
  173817. return;
  173818. png_set_sRGB(png_ptr, info_ptr, intent);
  173819. #if defined(PNG_gAMA_SUPPORTED)
  173820. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173821. file_gamma = (float).45455;
  173822. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173823. #endif
  173824. #ifdef PNG_FIXED_POINT_SUPPORTED
  173825. int_file_gamma = 45455L;
  173826. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173827. #endif
  173828. #endif
  173829. #if defined(PNG_cHRM_SUPPORTED)
  173830. #ifdef PNG_FIXED_POINT_SUPPORTED
  173831. int_white_x = 31270L;
  173832. int_white_y = 32900L;
  173833. int_red_x = 64000L;
  173834. int_red_y = 33000L;
  173835. int_green_x = 30000L;
  173836. int_green_y = 60000L;
  173837. int_blue_x = 15000L;
  173838. int_blue_y = 6000L;
  173839. png_set_cHRM_fixed(png_ptr, info_ptr,
  173840. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173841. int_blue_x, int_blue_y);
  173842. #endif
  173843. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173844. white_x = (float).3127;
  173845. white_y = (float).3290;
  173846. red_x = (float).64;
  173847. red_y = (float).33;
  173848. green_x = (float).30;
  173849. green_y = (float).60;
  173850. blue_x = (float).15;
  173851. blue_y = (float).06;
  173852. png_set_cHRM(png_ptr, info_ptr,
  173853. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173854. #endif
  173855. #endif
  173856. }
  173857. #endif
  173858. #if defined(PNG_iCCP_SUPPORTED)
  173859. void PNGAPI
  173860. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173861. png_charp name, int compression_type,
  173862. png_charp profile, png_uint_32 proflen)
  173863. {
  173864. png_charp new_iccp_name;
  173865. png_charp new_iccp_profile;
  173866. png_debug1(1, "in %s storage function\n", "iCCP");
  173867. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173868. return;
  173869. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173870. if (new_iccp_name == NULL)
  173871. {
  173872. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173873. return;
  173874. }
  173875. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173876. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173877. if (new_iccp_profile == NULL)
  173878. {
  173879. png_free (png_ptr, new_iccp_name);
  173880. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173881. return;
  173882. }
  173883. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173884. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173885. info_ptr->iccp_proflen = proflen;
  173886. info_ptr->iccp_name = new_iccp_name;
  173887. info_ptr->iccp_profile = new_iccp_profile;
  173888. info_ptr->iccp_compression = (png_byte)compression_type;
  173889. #ifdef PNG_FREE_ME_SUPPORTED
  173890. info_ptr->free_me |= PNG_FREE_ICCP;
  173891. #endif
  173892. info_ptr->valid |= PNG_INFO_iCCP;
  173893. }
  173894. #endif
  173895. #if defined(PNG_TEXT_SUPPORTED)
  173896. void PNGAPI
  173897. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173898. int num_text)
  173899. {
  173900. int ret;
  173901. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173902. if (ret)
  173903. png_error(png_ptr, "Insufficient memory to store text");
  173904. }
  173905. int /* PRIVATE */
  173906. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173907. int num_text)
  173908. {
  173909. int i;
  173910. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173911. "text" : (png_const_charp)png_ptr->chunk_name));
  173912. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173913. return(0);
  173914. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173915. {
  173916. if (info_ptr->text != NULL)
  173917. {
  173918. png_textp old_text;
  173919. int old_max;
  173920. old_max = info_ptr->max_text;
  173921. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  173922. old_text = info_ptr->text;
  173923. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173924. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173925. if (info_ptr->text == NULL)
  173926. {
  173927. png_free(png_ptr, old_text);
  173928. return(1);
  173929. }
  173930. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  173931. png_sizeof(png_text)));
  173932. png_free(png_ptr, old_text);
  173933. }
  173934. else
  173935. {
  173936. info_ptr->max_text = num_text + 8;
  173937. info_ptr->num_text = 0;
  173938. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173939. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173940. if (info_ptr->text == NULL)
  173941. return(1);
  173942. #ifdef PNG_FREE_ME_SUPPORTED
  173943. info_ptr->free_me |= PNG_FREE_TEXT;
  173944. #endif
  173945. }
  173946. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  173947. info_ptr->max_text);
  173948. }
  173949. for (i = 0; i < num_text; i++)
  173950. {
  173951. png_size_t text_length,key_len;
  173952. png_size_t lang_len,lang_key_len;
  173953. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  173954. if (text_ptr[i].key == NULL)
  173955. continue;
  173956. key_len = png_strlen(text_ptr[i].key);
  173957. if(text_ptr[i].compression <= 0)
  173958. {
  173959. lang_len = 0;
  173960. lang_key_len = 0;
  173961. }
  173962. else
  173963. #ifdef PNG_iTXt_SUPPORTED
  173964. {
  173965. if (text_ptr[i].lang != NULL)
  173966. lang_len = png_strlen(text_ptr[i].lang);
  173967. else
  173968. lang_len = 0;
  173969. if (text_ptr[i].lang_key != NULL)
  173970. lang_key_len = png_strlen(text_ptr[i].lang_key);
  173971. else
  173972. lang_key_len = 0;
  173973. }
  173974. #else
  173975. {
  173976. png_warning(png_ptr, "iTXt chunk not supported.");
  173977. continue;
  173978. }
  173979. #endif
  173980. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  173981. {
  173982. text_length = 0;
  173983. #ifdef PNG_iTXt_SUPPORTED
  173984. if(text_ptr[i].compression > 0)
  173985. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  173986. else
  173987. #endif
  173988. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  173989. }
  173990. else
  173991. {
  173992. text_length = png_strlen(text_ptr[i].text);
  173993. textp->compression = text_ptr[i].compression;
  173994. }
  173995. textp->key = (png_charp)png_malloc_warn(png_ptr,
  173996. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  173997. if (textp->key == NULL)
  173998. return(1);
  173999. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174000. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174001. (int)textp->key);
  174002. png_memcpy(textp->key, text_ptr[i].key,
  174003. (png_size_t)(key_len));
  174004. *(textp->key+key_len) = '\0';
  174005. #ifdef PNG_iTXt_SUPPORTED
  174006. if (text_ptr[i].compression > 0)
  174007. {
  174008. textp->lang=textp->key + key_len + 1;
  174009. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174010. *(textp->lang+lang_len) = '\0';
  174011. textp->lang_key=textp->lang + lang_len + 1;
  174012. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174013. *(textp->lang_key+lang_key_len) = '\0';
  174014. textp->text=textp->lang_key + lang_key_len + 1;
  174015. }
  174016. else
  174017. #endif
  174018. {
  174019. #ifdef PNG_iTXt_SUPPORTED
  174020. textp->lang=NULL;
  174021. textp->lang_key=NULL;
  174022. #endif
  174023. textp->text=textp->key + key_len + 1;
  174024. }
  174025. if(text_length)
  174026. png_memcpy(textp->text, text_ptr[i].text,
  174027. (png_size_t)(text_length));
  174028. *(textp->text+text_length) = '\0';
  174029. #ifdef PNG_iTXt_SUPPORTED
  174030. if(textp->compression > 0)
  174031. {
  174032. textp->text_length = 0;
  174033. textp->itxt_length = text_length;
  174034. }
  174035. else
  174036. #endif
  174037. {
  174038. textp->text_length = text_length;
  174039. #ifdef PNG_iTXt_SUPPORTED
  174040. textp->itxt_length = 0;
  174041. #endif
  174042. }
  174043. info_ptr->num_text++;
  174044. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174045. }
  174046. return(0);
  174047. }
  174048. #endif
  174049. #if defined(PNG_tIME_SUPPORTED)
  174050. void PNGAPI
  174051. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174052. {
  174053. png_debug1(1, "in %s storage function\n", "tIME");
  174054. if (png_ptr == NULL || info_ptr == NULL ||
  174055. (png_ptr->mode & PNG_WROTE_tIME))
  174056. return;
  174057. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174058. info_ptr->valid |= PNG_INFO_tIME;
  174059. }
  174060. #endif
  174061. #if defined(PNG_tRNS_SUPPORTED)
  174062. void PNGAPI
  174063. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174064. png_bytep trans, int num_trans, png_color_16p trans_values)
  174065. {
  174066. png_debug1(1, "in %s storage function\n", "tRNS");
  174067. if (png_ptr == NULL || info_ptr == NULL)
  174068. return;
  174069. if (trans != NULL)
  174070. {
  174071. #ifdef PNG_FREE_ME_SUPPORTED
  174072. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174073. #endif
  174074. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174075. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174076. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174077. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174078. #ifdef PNG_FREE_ME_SUPPORTED
  174079. info_ptr->free_me |= PNG_FREE_TRNS;
  174080. #else
  174081. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174082. #endif
  174083. }
  174084. if (trans_values != NULL)
  174085. {
  174086. png_memcpy(&(info_ptr->trans_values), trans_values,
  174087. png_sizeof(png_color_16));
  174088. if (num_trans == 0)
  174089. num_trans = 1;
  174090. }
  174091. info_ptr->num_trans = (png_uint_16)num_trans;
  174092. info_ptr->valid |= PNG_INFO_tRNS;
  174093. }
  174094. #endif
  174095. #if defined(PNG_sPLT_SUPPORTED)
  174096. void PNGAPI
  174097. png_set_sPLT(png_structp png_ptr,
  174098. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174099. {
  174100. png_sPLT_tp np;
  174101. int i;
  174102. if (png_ptr == NULL || info_ptr == NULL)
  174103. return;
  174104. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174105. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174106. if (np == NULL)
  174107. {
  174108. png_warning(png_ptr, "No memory for sPLT palettes.");
  174109. return;
  174110. }
  174111. png_memcpy(np, info_ptr->splt_palettes,
  174112. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174113. png_free(png_ptr, info_ptr->splt_palettes);
  174114. info_ptr->splt_palettes=NULL;
  174115. for (i = 0; i < nentries; i++)
  174116. {
  174117. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174118. png_sPLT_tp from = entries + i;
  174119. to->name = (png_charp)png_malloc_warn(png_ptr,
  174120. png_strlen(from->name) + 1);
  174121. if (to->name == NULL)
  174122. {
  174123. png_warning(png_ptr,
  174124. "Out of memory while processing sPLT chunk");
  174125. }
  174126. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174127. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174128. from->nentries * png_sizeof(png_sPLT_entry));
  174129. png_memcpy(to->entries, from->entries,
  174130. from->nentries * png_sizeof(png_sPLT_entry));
  174131. if (to->entries == NULL)
  174132. {
  174133. png_warning(png_ptr,
  174134. "Out of memory while processing sPLT chunk");
  174135. png_free(png_ptr,to->name);
  174136. to->name = NULL;
  174137. }
  174138. to->nentries = from->nentries;
  174139. to->depth = from->depth;
  174140. }
  174141. info_ptr->splt_palettes = np;
  174142. info_ptr->splt_palettes_num += nentries;
  174143. info_ptr->valid |= PNG_INFO_sPLT;
  174144. #ifdef PNG_FREE_ME_SUPPORTED
  174145. info_ptr->free_me |= PNG_FREE_SPLT;
  174146. #endif
  174147. }
  174148. #endif /* PNG_sPLT_SUPPORTED */
  174149. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174150. void PNGAPI
  174151. png_set_unknown_chunks(png_structp png_ptr,
  174152. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174153. {
  174154. png_unknown_chunkp np;
  174155. int i;
  174156. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174157. return;
  174158. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174159. (info_ptr->unknown_chunks_num + num_unknowns) *
  174160. png_sizeof(png_unknown_chunk));
  174161. if (np == NULL)
  174162. {
  174163. png_warning(png_ptr,
  174164. "Out of memory while processing unknown chunk.");
  174165. return;
  174166. }
  174167. png_memcpy(np, info_ptr->unknown_chunks,
  174168. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174169. png_free(png_ptr, info_ptr->unknown_chunks);
  174170. info_ptr->unknown_chunks=NULL;
  174171. for (i = 0; i < num_unknowns; i++)
  174172. {
  174173. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174174. png_unknown_chunkp from = unknowns + i;
  174175. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174176. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174177. if (to->data == NULL)
  174178. {
  174179. png_warning(png_ptr,
  174180. "Out of memory while processing unknown chunk.");
  174181. }
  174182. else
  174183. {
  174184. png_memcpy(to->data, from->data, from->size);
  174185. to->size = from->size;
  174186. to->location = (png_byte)(png_ptr->mode & 0xff);
  174187. }
  174188. }
  174189. info_ptr->unknown_chunks = np;
  174190. info_ptr->unknown_chunks_num += num_unknowns;
  174191. #ifdef PNG_FREE_ME_SUPPORTED
  174192. info_ptr->free_me |= PNG_FREE_UNKN;
  174193. #endif
  174194. }
  174195. void PNGAPI
  174196. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174197. int chunk, int location)
  174198. {
  174199. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174200. (int)info_ptr->unknown_chunks_num)
  174201. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174202. }
  174203. #endif
  174204. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174205. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174206. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174207. void PNGAPI
  174208. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174209. {
  174210. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174211. if (png_ptr == NULL)
  174212. return;
  174213. png_ptr->mng_features_permitted = (png_byte)
  174214. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174215. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174216. }
  174217. #endif
  174218. #endif
  174219. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174220. png_uint_32 PNGAPI
  174221. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174222. {
  174223. png_debug(1, "in png_permit_mng_features\n");
  174224. if (png_ptr == NULL)
  174225. return (png_uint_32)0;
  174226. png_ptr->mng_features_permitted =
  174227. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174228. return (png_uint_32)png_ptr->mng_features_permitted;
  174229. }
  174230. #endif
  174231. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174232. void PNGAPI
  174233. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174234. chunk_list, int num_chunks)
  174235. {
  174236. png_bytep new_list, p;
  174237. int i, old_num_chunks;
  174238. if (png_ptr == NULL)
  174239. return;
  174240. if (num_chunks == 0)
  174241. {
  174242. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174243. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174244. else
  174245. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174246. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174247. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174248. else
  174249. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174250. return;
  174251. }
  174252. if (chunk_list == NULL)
  174253. return;
  174254. old_num_chunks=png_ptr->num_chunk_list;
  174255. new_list=(png_bytep)png_malloc(png_ptr,
  174256. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174257. if(png_ptr->chunk_list != NULL)
  174258. {
  174259. png_memcpy(new_list, png_ptr->chunk_list,
  174260. (png_size_t)(5*old_num_chunks));
  174261. png_free(png_ptr, png_ptr->chunk_list);
  174262. png_ptr->chunk_list=NULL;
  174263. }
  174264. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174265. (png_size_t)(5*num_chunks));
  174266. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174267. *p=(png_byte)keep;
  174268. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174269. png_ptr->chunk_list=new_list;
  174270. #ifdef PNG_FREE_ME_SUPPORTED
  174271. png_ptr->free_me |= PNG_FREE_LIST;
  174272. #endif
  174273. }
  174274. #endif
  174275. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174276. void PNGAPI
  174277. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174278. png_user_chunk_ptr read_user_chunk_fn)
  174279. {
  174280. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174281. if (png_ptr == NULL)
  174282. return;
  174283. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174284. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174285. }
  174286. #endif
  174287. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174288. void PNGAPI
  174289. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174290. {
  174291. png_debug1(1, "in %s storage function\n", "rows");
  174292. if (png_ptr == NULL || info_ptr == NULL)
  174293. return;
  174294. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174295. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174296. info_ptr->row_pointers = row_pointers;
  174297. if(row_pointers)
  174298. info_ptr->valid |= PNG_INFO_IDAT;
  174299. }
  174300. #endif
  174301. #ifdef PNG_WRITE_SUPPORTED
  174302. void PNGAPI
  174303. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174304. {
  174305. if (png_ptr == NULL)
  174306. return;
  174307. if(png_ptr->zbuf)
  174308. png_free(png_ptr, png_ptr->zbuf);
  174309. png_ptr->zbuf_size = (png_size_t)size;
  174310. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174311. png_ptr->zstream.next_out = png_ptr->zbuf;
  174312. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174313. }
  174314. #endif
  174315. void PNGAPI
  174316. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174317. {
  174318. if (png_ptr && info_ptr)
  174319. info_ptr->valid &= ~(mask);
  174320. }
  174321. #ifndef PNG_1_0_X
  174322. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174323. void PNGAPI
  174324. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174325. {
  174326. if (png_ptr != NULL)
  174327. png_ptr->asm_flags = 0;
  174328. }
  174329. void PNGAPI
  174330. png_set_mmx_thresholds (png_structp png_ptr,
  174331. png_byte mmx_bitdepth_threshold,
  174332. png_uint_32 mmx_rowbytes_threshold)
  174333. {
  174334. if (png_ptr == NULL)
  174335. return;
  174336. }
  174337. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174338. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174339. void PNGAPI
  174340. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174341. png_uint_32 user_height_max)
  174342. {
  174343. if(png_ptr == NULL) return;
  174344. png_ptr->user_width_max = user_width_max;
  174345. png_ptr->user_height_max = user_height_max;
  174346. }
  174347. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174348. #endif /* ?PNG_1_0_X */
  174349. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174350. /*** End of inlined file: pngset.c ***/
  174351. /*** Start of inlined file: pngtrans.c ***/
  174352. #define PNG_INTERNAL
  174353. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174354. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174355. void PNGAPI
  174356. png_set_bgr(png_structp png_ptr)
  174357. {
  174358. png_debug(1, "in png_set_bgr\n");
  174359. if(png_ptr == NULL) return;
  174360. png_ptr->transformations |= PNG_BGR;
  174361. }
  174362. #endif
  174363. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174364. void PNGAPI
  174365. png_set_swap(png_structp png_ptr)
  174366. {
  174367. png_debug(1, "in png_set_swap\n");
  174368. if(png_ptr == NULL) return;
  174369. if (png_ptr->bit_depth == 16)
  174370. png_ptr->transformations |= PNG_SWAP_BYTES;
  174371. }
  174372. #endif
  174373. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174374. void PNGAPI
  174375. png_set_packing(png_structp png_ptr)
  174376. {
  174377. png_debug(1, "in png_set_packing\n");
  174378. if(png_ptr == NULL) return;
  174379. if (png_ptr->bit_depth < 8)
  174380. {
  174381. png_ptr->transformations |= PNG_PACK;
  174382. png_ptr->usr_bit_depth = 8;
  174383. }
  174384. }
  174385. #endif
  174386. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174387. void PNGAPI
  174388. png_set_packswap(png_structp png_ptr)
  174389. {
  174390. png_debug(1, "in png_set_packswap\n");
  174391. if(png_ptr == NULL) return;
  174392. if (png_ptr->bit_depth < 8)
  174393. png_ptr->transformations |= PNG_PACKSWAP;
  174394. }
  174395. #endif
  174396. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174397. void PNGAPI
  174398. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174399. {
  174400. png_debug(1, "in png_set_shift\n");
  174401. if(png_ptr == NULL) return;
  174402. png_ptr->transformations |= PNG_SHIFT;
  174403. png_ptr->shift = *true_bits;
  174404. }
  174405. #endif
  174406. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174407. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174408. int PNGAPI
  174409. png_set_interlace_handling(png_structp png_ptr)
  174410. {
  174411. png_debug(1, "in png_set_interlace handling\n");
  174412. if (png_ptr && png_ptr->interlaced)
  174413. {
  174414. png_ptr->transformations |= PNG_INTERLACE;
  174415. return (7);
  174416. }
  174417. return (1);
  174418. }
  174419. #endif
  174420. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174421. void PNGAPI
  174422. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174423. {
  174424. png_debug(1, "in png_set_filler\n");
  174425. if(png_ptr == NULL) return;
  174426. png_ptr->transformations |= PNG_FILLER;
  174427. png_ptr->filler = (png_byte)filler;
  174428. if (filler_loc == PNG_FILLER_AFTER)
  174429. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174430. else
  174431. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174432. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174433. {
  174434. png_ptr->usr_channels = 4;
  174435. }
  174436. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174437. {
  174438. png_ptr->usr_channels = 2;
  174439. }
  174440. }
  174441. #if !defined(PNG_1_0_X)
  174442. void PNGAPI
  174443. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174444. {
  174445. png_debug(1, "in png_set_add_alpha\n");
  174446. if(png_ptr == NULL) return;
  174447. png_set_filler(png_ptr, filler, filler_loc);
  174448. png_ptr->transformations |= PNG_ADD_ALPHA;
  174449. }
  174450. #endif
  174451. #endif
  174452. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174453. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174454. void PNGAPI
  174455. png_set_swap_alpha(png_structp png_ptr)
  174456. {
  174457. png_debug(1, "in png_set_swap_alpha\n");
  174458. if(png_ptr == NULL) return;
  174459. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174460. }
  174461. #endif
  174462. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174463. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174464. void PNGAPI
  174465. png_set_invert_alpha(png_structp png_ptr)
  174466. {
  174467. png_debug(1, "in png_set_invert_alpha\n");
  174468. if(png_ptr == NULL) return;
  174469. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174470. }
  174471. #endif
  174472. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174473. void PNGAPI
  174474. png_set_invert_mono(png_structp png_ptr)
  174475. {
  174476. png_debug(1, "in png_set_invert_mono\n");
  174477. if(png_ptr == NULL) return;
  174478. png_ptr->transformations |= PNG_INVERT_MONO;
  174479. }
  174480. void /* PRIVATE */
  174481. png_do_invert(png_row_infop row_info, png_bytep row)
  174482. {
  174483. png_debug(1, "in png_do_invert\n");
  174484. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174485. if (row == NULL || row_info == NULL)
  174486. return;
  174487. #endif
  174488. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174489. {
  174490. png_bytep rp = row;
  174491. png_uint_32 i;
  174492. png_uint_32 istop = row_info->rowbytes;
  174493. for (i = 0; i < istop; i++)
  174494. {
  174495. *rp = (png_byte)(~(*rp));
  174496. rp++;
  174497. }
  174498. }
  174499. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174500. row_info->bit_depth == 8)
  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+=2)
  174506. {
  174507. *rp = (png_byte)(~(*rp));
  174508. rp+=2;
  174509. }
  174510. }
  174511. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174512. row_info->bit_depth == 16)
  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+=4)
  174518. {
  174519. *rp = (png_byte)(~(*rp));
  174520. *(rp+1) = (png_byte)(~(*(rp+1)));
  174521. rp+=4;
  174522. }
  174523. }
  174524. }
  174525. #endif
  174526. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174527. void /* PRIVATE */
  174528. png_do_swap(png_row_infop row_info, png_bytep row)
  174529. {
  174530. png_debug(1, "in png_do_swap\n");
  174531. if (
  174532. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174533. row != NULL && row_info != NULL &&
  174534. #endif
  174535. row_info->bit_depth == 16)
  174536. {
  174537. png_bytep rp = row;
  174538. png_uint_32 i;
  174539. png_uint_32 istop= row_info->width * row_info->channels;
  174540. for (i = 0; i < istop; i++, rp += 2)
  174541. {
  174542. png_byte t = *rp;
  174543. *rp = *(rp + 1);
  174544. *(rp + 1) = t;
  174545. }
  174546. }
  174547. }
  174548. #endif
  174549. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174550. static PNG_CONST png_byte onebppswaptable[256] = {
  174551. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174552. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174553. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174554. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174555. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174556. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174557. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174558. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174559. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174560. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174561. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174562. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174563. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174564. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174565. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174566. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174567. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174568. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174569. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174570. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174571. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174572. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174573. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174574. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174575. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174576. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174577. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174578. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174579. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174580. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174581. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174582. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174583. };
  174584. static PNG_CONST png_byte twobppswaptable[256] = {
  174585. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174586. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174587. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174588. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174589. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174590. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174591. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174592. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174593. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174594. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174595. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174596. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174597. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174598. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174599. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174600. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174601. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174602. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174603. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174604. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174605. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174606. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174607. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174608. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174609. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174610. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174611. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174612. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174613. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174614. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174615. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174616. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174617. };
  174618. static PNG_CONST png_byte fourbppswaptable[256] = {
  174619. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174620. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174621. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174622. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174623. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174624. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174625. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174626. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174627. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174628. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174629. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174630. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174631. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174632. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174633. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174634. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174635. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174636. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174637. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174638. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174639. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174640. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174641. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174642. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174643. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174644. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174645. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174646. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174647. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174648. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174649. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174650. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174651. };
  174652. void /* PRIVATE */
  174653. png_do_packswap(png_row_infop row_info, png_bytep row)
  174654. {
  174655. png_debug(1, "in png_do_packswap\n");
  174656. if (
  174657. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174658. row != NULL && row_info != NULL &&
  174659. #endif
  174660. row_info->bit_depth < 8)
  174661. {
  174662. png_bytep rp, end, table;
  174663. end = row + row_info->rowbytes;
  174664. if (row_info->bit_depth == 1)
  174665. table = (png_bytep)onebppswaptable;
  174666. else if (row_info->bit_depth == 2)
  174667. table = (png_bytep)twobppswaptable;
  174668. else if (row_info->bit_depth == 4)
  174669. table = (png_bytep)fourbppswaptable;
  174670. else
  174671. return;
  174672. for (rp = row; rp < end; rp++)
  174673. *rp = table[*rp];
  174674. }
  174675. }
  174676. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174677. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174678. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174679. void /* PRIVATE */
  174680. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174681. {
  174682. png_debug(1, "in png_do_strip_filler\n");
  174683. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174684. if (row != NULL && row_info != NULL)
  174685. #endif
  174686. {
  174687. png_bytep sp=row;
  174688. png_bytep dp=row;
  174689. png_uint_32 row_width=row_info->width;
  174690. png_uint_32 i;
  174691. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174692. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174693. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174694. row_info->channels == 4)
  174695. {
  174696. if (row_info->bit_depth == 8)
  174697. {
  174698. if (flags & PNG_FLAG_FILLER_AFTER)
  174699. {
  174700. dp+=3; sp+=4;
  174701. for (i = 1; i < row_width; i++)
  174702. {
  174703. *dp++ = *sp++;
  174704. *dp++ = *sp++;
  174705. *dp++ = *sp++;
  174706. sp++;
  174707. }
  174708. }
  174709. else
  174710. {
  174711. for (i = 0; i < row_width; i++)
  174712. {
  174713. sp++;
  174714. *dp++ = *sp++;
  174715. *dp++ = *sp++;
  174716. *dp++ = *sp++;
  174717. }
  174718. }
  174719. row_info->pixel_depth = 24;
  174720. row_info->rowbytes = row_width * 3;
  174721. }
  174722. else /* if (row_info->bit_depth == 16) */
  174723. {
  174724. if (flags & PNG_FLAG_FILLER_AFTER)
  174725. {
  174726. sp += 8; dp += 6;
  174727. for (i = 1; i < row_width; i++)
  174728. {
  174729. *dp++ = *sp++;
  174730. *dp++ = *sp++;
  174731. *dp++ = *sp++;
  174732. *dp++ = *sp++;
  174733. *dp++ = *sp++;
  174734. *dp++ = *sp++;
  174735. sp += 2;
  174736. }
  174737. }
  174738. else
  174739. {
  174740. for (i = 0; i < row_width; i++)
  174741. {
  174742. sp+=2;
  174743. *dp++ = *sp++;
  174744. *dp++ = *sp++;
  174745. *dp++ = *sp++;
  174746. *dp++ = *sp++;
  174747. *dp++ = *sp++;
  174748. *dp++ = *sp++;
  174749. }
  174750. }
  174751. row_info->pixel_depth = 48;
  174752. row_info->rowbytes = row_width * 6;
  174753. }
  174754. row_info->channels = 3;
  174755. }
  174756. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174757. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174758. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174759. row_info->channels == 2)
  174760. {
  174761. if (row_info->bit_depth == 8)
  174762. {
  174763. if (flags & PNG_FLAG_FILLER_AFTER)
  174764. {
  174765. for (i = 0; i < row_width; i++)
  174766. {
  174767. *dp++ = *sp++;
  174768. sp++;
  174769. }
  174770. }
  174771. else
  174772. {
  174773. for (i = 0; i < row_width; i++)
  174774. {
  174775. sp++;
  174776. *dp++ = *sp++;
  174777. }
  174778. }
  174779. row_info->pixel_depth = 8;
  174780. row_info->rowbytes = row_width;
  174781. }
  174782. else /* if (row_info->bit_depth == 16) */
  174783. {
  174784. if (flags & PNG_FLAG_FILLER_AFTER)
  174785. {
  174786. sp += 4; dp += 2;
  174787. for (i = 1; i < row_width; i++)
  174788. {
  174789. *dp++ = *sp++;
  174790. *dp++ = *sp++;
  174791. sp += 2;
  174792. }
  174793. }
  174794. else
  174795. {
  174796. for (i = 0; i < row_width; i++)
  174797. {
  174798. sp += 2;
  174799. *dp++ = *sp++;
  174800. *dp++ = *sp++;
  174801. }
  174802. }
  174803. row_info->pixel_depth = 16;
  174804. row_info->rowbytes = row_width * 2;
  174805. }
  174806. row_info->channels = 1;
  174807. }
  174808. if (flags & PNG_FLAG_STRIP_ALPHA)
  174809. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174810. }
  174811. }
  174812. #endif
  174813. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174814. void /* PRIVATE */
  174815. png_do_bgr(png_row_infop row_info, png_bytep row)
  174816. {
  174817. png_debug(1, "in png_do_bgr\n");
  174818. if (
  174819. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174820. row != NULL && row_info != NULL &&
  174821. #endif
  174822. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174823. {
  174824. png_uint_32 row_width = row_info->width;
  174825. if (row_info->bit_depth == 8)
  174826. {
  174827. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174828. {
  174829. png_bytep rp;
  174830. png_uint_32 i;
  174831. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174832. {
  174833. png_byte save = *rp;
  174834. *rp = *(rp + 2);
  174835. *(rp + 2) = save;
  174836. }
  174837. }
  174838. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174839. {
  174840. png_bytep rp;
  174841. png_uint_32 i;
  174842. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174843. {
  174844. png_byte save = *rp;
  174845. *rp = *(rp + 2);
  174846. *(rp + 2) = save;
  174847. }
  174848. }
  174849. }
  174850. else if (row_info->bit_depth == 16)
  174851. {
  174852. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174853. {
  174854. png_bytep rp;
  174855. png_uint_32 i;
  174856. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174857. {
  174858. png_byte save = *rp;
  174859. *rp = *(rp + 4);
  174860. *(rp + 4) = save;
  174861. save = *(rp + 1);
  174862. *(rp + 1) = *(rp + 5);
  174863. *(rp + 5) = save;
  174864. }
  174865. }
  174866. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174867. {
  174868. png_bytep rp;
  174869. png_uint_32 i;
  174870. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174871. {
  174872. png_byte save = *rp;
  174873. *rp = *(rp + 4);
  174874. *(rp + 4) = save;
  174875. save = *(rp + 1);
  174876. *(rp + 1) = *(rp + 5);
  174877. *(rp + 5) = save;
  174878. }
  174879. }
  174880. }
  174881. }
  174882. }
  174883. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174884. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174885. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174886. defined(PNG_LEGACY_SUPPORTED)
  174887. void PNGAPI
  174888. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174889. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174890. {
  174891. png_debug(1, "in png_set_user_transform_info\n");
  174892. if(png_ptr == NULL) return;
  174893. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174894. png_ptr->user_transform_ptr = user_transform_ptr;
  174895. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174896. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174897. #else
  174898. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174899. png_warning(png_ptr,
  174900. "This version of libpng does not support user transform info");
  174901. #endif
  174902. }
  174903. #endif
  174904. png_voidp PNGAPI
  174905. png_get_user_transform_ptr(png_structp png_ptr)
  174906. {
  174907. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174908. if (png_ptr == NULL) return (NULL);
  174909. return ((png_voidp)png_ptr->user_transform_ptr);
  174910. #else
  174911. return (NULL);
  174912. #endif
  174913. }
  174914. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174915. /*** End of inlined file: pngtrans.c ***/
  174916. /*** Start of inlined file: pngwio.c ***/
  174917. #define PNG_INTERNAL
  174918. #ifdef PNG_WRITE_SUPPORTED
  174919. void /* PRIVATE */
  174920. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174921. {
  174922. if (png_ptr->write_data_fn != NULL )
  174923. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  174924. else
  174925. png_error(png_ptr, "Call to NULL write function");
  174926. }
  174927. #if !defined(PNG_NO_STDIO)
  174928. #ifndef USE_FAR_KEYWORD
  174929. void PNGAPI
  174930. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174931. {
  174932. png_uint_32 check;
  174933. if(png_ptr == NULL) return;
  174934. #if defined(_WIN32_WCE)
  174935. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  174936. check = 0;
  174937. #else
  174938. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  174939. #endif
  174940. if (check != length)
  174941. png_error(png_ptr, "Write Error");
  174942. }
  174943. #else
  174944. #define NEAR_BUF_SIZE 1024
  174945. #define MIN(a,b) (a <= b ? a : b)
  174946. void PNGAPI
  174947. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174948. {
  174949. png_uint_32 check;
  174950. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  174951. png_FILE_p io_ptr;
  174952. if(png_ptr == NULL) return;
  174953. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  174954. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  174955. if ((png_bytep)near_data == data)
  174956. {
  174957. #if defined(_WIN32_WCE)
  174958. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  174959. check = 0;
  174960. #else
  174961. check = fwrite(near_data, 1, length, io_ptr);
  174962. #endif
  174963. }
  174964. else
  174965. {
  174966. png_byte buf[NEAR_BUF_SIZE];
  174967. png_size_t written, remaining, err;
  174968. check = 0;
  174969. remaining = length;
  174970. do
  174971. {
  174972. written = MIN(NEAR_BUF_SIZE, remaining);
  174973. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  174974. #if defined(_WIN32_WCE)
  174975. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  174976. err = 0;
  174977. #else
  174978. err = fwrite(buf, 1, written, io_ptr);
  174979. #endif
  174980. if (err != written)
  174981. break;
  174982. else
  174983. check += err;
  174984. data += written;
  174985. remaining -= written;
  174986. }
  174987. while (remaining != 0);
  174988. }
  174989. if (check != length)
  174990. png_error(png_ptr, "Write Error");
  174991. }
  174992. #endif
  174993. #endif
  174994. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174995. void /* PRIVATE */
  174996. png_flush(png_structp png_ptr)
  174997. {
  174998. if (png_ptr->output_flush_fn != NULL)
  174999. (*(png_ptr->output_flush_fn))(png_ptr);
  175000. }
  175001. #if !defined(PNG_NO_STDIO)
  175002. void PNGAPI
  175003. png_default_flush(png_structp png_ptr)
  175004. {
  175005. #if !defined(_WIN32_WCE)
  175006. png_FILE_p io_ptr;
  175007. #endif
  175008. if(png_ptr == NULL) return;
  175009. #if !defined(_WIN32_WCE)
  175010. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175011. if (io_ptr != NULL)
  175012. fflush(io_ptr);
  175013. #endif
  175014. }
  175015. #endif
  175016. #endif
  175017. void PNGAPI
  175018. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175019. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175020. {
  175021. if(png_ptr == NULL) return;
  175022. png_ptr->io_ptr = io_ptr;
  175023. #if !defined(PNG_NO_STDIO)
  175024. if (write_data_fn != NULL)
  175025. png_ptr->write_data_fn = write_data_fn;
  175026. else
  175027. png_ptr->write_data_fn = png_default_write_data;
  175028. #else
  175029. png_ptr->write_data_fn = write_data_fn;
  175030. #endif
  175031. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175032. #if !defined(PNG_NO_STDIO)
  175033. if (output_flush_fn != NULL)
  175034. png_ptr->output_flush_fn = output_flush_fn;
  175035. else
  175036. png_ptr->output_flush_fn = png_default_flush;
  175037. #else
  175038. png_ptr->output_flush_fn = output_flush_fn;
  175039. #endif
  175040. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175041. if (png_ptr->read_data_fn != NULL)
  175042. {
  175043. png_ptr->read_data_fn = NULL;
  175044. png_warning(png_ptr,
  175045. "Attempted to set both read_data_fn and write_data_fn in");
  175046. png_warning(png_ptr,
  175047. "the same structure. Resetting read_data_fn to NULL.");
  175048. }
  175049. }
  175050. #if defined(USE_FAR_KEYWORD)
  175051. #if defined(_MSC_VER)
  175052. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175053. {
  175054. void *near_ptr;
  175055. void FAR *far_ptr;
  175056. FP_OFF(near_ptr) = FP_OFF(ptr);
  175057. far_ptr = (void FAR *)near_ptr;
  175058. if(check != 0)
  175059. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175060. png_error(png_ptr,"segment lost in conversion");
  175061. return(near_ptr);
  175062. }
  175063. # else
  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. near_ptr = (void FAR *)ptr;
  175069. far_ptr = (void FAR *)near_ptr;
  175070. if(check != 0)
  175071. if(far_ptr != ptr)
  175072. png_error(png_ptr,"segment lost in conversion");
  175073. return(near_ptr);
  175074. }
  175075. # endif
  175076. # endif
  175077. #endif /* PNG_WRITE_SUPPORTED */
  175078. /*** End of inlined file: pngwio.c ***/
  175079. /*** Start of inlined file: pngwrite.c ***/
  175080. #define PNG_INTERNAL
  175081. #ifdef PNG_WRITE_SUPPORTED
  175082. void PNGAPI
  175083. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175084. {
  175085. png_debug(1, "in png_write_info_before_PLTE\n");
  175086. if (png_ptr == NULL || info_ptr == NULL)
  175087. return;
  175088. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175089. {
  175090. png_write_sig(png_ptr); /* write PNG signature */
  175091. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175092. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175093. {
  175094. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175095. png_ptr->mng_features_permitted=0;
  175096. }
  175097. #endif
  175098. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175099. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175100. info_ptr->filter_type,
  175101. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175102. info_ptr->interlace_type);
  175103. #else
  175104. 0);
  175105. #endif
  175106. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175107. if (info_ptr->valid & PNG_INFO_gAMA)
  175108. {
  175109. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175110. png_write_gAMA(png_ptr, info_ptr->gamma);
  175111. #else
  175112. #ifdef PNG_FIXED_POINT_SUPPORTED
  175113. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175114. # endif
  175115. #endif
  175116. }
  175117. #endif
  175118. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175119. if (info_ptr->valid & PNG_INFO_sRGB)
  175120. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175121. #endif
  175122. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175123. if (info_ptr->valid & PNG_INFO_iCCP)
  175124. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175125. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175126. #endif
  175127. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175128. if (info_ptr->valid & PNG_INFO_sBIT)
  175129. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175130. #endif
  175131. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175132. if (info_ptr->valid & PNG_INFO_cHRM)
  175133. {
  175134. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175135. png_write_cHRM(png_ptr,
  175136. info_ptr->x_white, info_ptr->y_white,
  175137. info_ptr->x_red, info_ptr->y_red,
  175138. info_ptr->x_green, info_ptr->y_green,
  175139. info_ptr->x_blue, info_ptr->y_blue);
  175140. #else
  175141. # ifdef PNG_FIXED_POINT_SUPPORTED
  175142. png_write_cHRM_fixed(png_ptr,
  175143. info_ptr->int_x_white, info_ptr->int_y_white,
  175144. info_ptr->int_x_red, info_ptr->int_y_red,
  175145. info_ptr->int_x_green, info_ptr->int_y_green,
  175146. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175147. # endif
  175148. #endif
  175149. }
  175150. #endif
  175151. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175152. if (info_ptr->unknown_chunks_num)
  175153. {
  175154. png_unknown_chunk *up;
  175155. png_debug(5, "writing extra chunks\n");
  175156. for (up = info_ptr->unknown_chunks;
  175157. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175158. up++)
  175159. {
  175160. int keep=png_handle_as_unknown(png_ptr, up->name);
  175161. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175162. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175163. !(up->location & PNG_HAVE_IDAT) &&
  175164. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175165. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175166. {
  175167. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175168. }
  175169. }
  175170. }
  175171. #endif
  175172. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175173. }
  175174. }
  175175. void PNGAPI
  175176. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175177. {
  175178. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175179. int i;
  175180. #endif
  175181. png_debug(1, "in png_write_info\n");
  175182. if (png_ptr == NULL || info_ptr == NULL)
  175183. return;
  175184. png_write_info_before_PLTE(png_ptr, info_ptr);
  175185. if (info_ptr->valid & PNG_INFO_PLTE)
  175186. png_write_PLTE(png_ptr, info_ptr->palette,
  175187. (png_uint_32)info_ptr->num_palette);
  175188. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175189. png_error(png_ptr, "Valid palette required for paletted images");
  175190. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175191. if (info_ptr->valid & PNG_INFO_tRNS)
  175192. {
  175193. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175194. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175195. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175196. {
  175197. int j;
  175198. for (j=0; j<(int)info_ptr->num_trans; j++)
  175199. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175200. }
  175201. #endif
  175202. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175203. info_ptr->num_trans, info_ptr->color_type);
  175204. }
  175205. #endif
  175206. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175207. if (info_ptr->valid & PNG_INFO_bKGD)
  175208. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175209. #endif
  175210. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175211. if (info_ptr->valid & PNG_INFO_hIST)
  175212. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175213. #endif
  175214. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175215. if (info_ptr->valid & PNG_INFO_oFFs)
  175216. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175217. info_ptr->offset_unit_type);
  175218. #endif
  175219. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175220. if (info_ptr->valid & PNG_INFO_pCAL)
  175221. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175222. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175223. info_ptr->pcal_units, info_ptr->pcal_params);
  175224. #endif
  175225. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175226. if (info_ptr->valid & PNG_INFO_sCAL)
  175227. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175228. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175229. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175230. #else
  175231. #ifdef PNG_FIXED_POINT_SUPPORTED
  175232. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175233. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175234. #else
  175235. png_warning(png_ptr,
  175236. "png_write_sCAL not supported; sCAL chunk not written.");
  175237. #endif
  175238. #endif
  175239. #endif
  175240. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175241. if (info_ptr->valid & PNG_INFO_pHYs)
  175242. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175243. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175244. #endif
  175245. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175246. if (info_ptr->valid & PNG_INFO_tIME)
  175247. {
  175248. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175249. png_ptr->mode |= PNG_WROTE_tIME;
  175250. }
  175251. #endif
  175252. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175253. if (info_ptr->valid & PNG_INFO_sPLT)
  175254. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175255. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175256. #endif
  175257. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175258. for (i = 0; i < info_ptr->num_text; i++)
  175259. {
  175260. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175261. info_ptr->text[i].compression);
  175262. if (info_ptr->text[i].compression > 0)
  175263. {
  175264. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175265. png_write_iTXt(png_ptr,
  175266. info_ptr->text[i].compression,
  175267. info_ptr->text[i].key,
  175268. info_ptr->text[i].lang,
  175269. info_ptr->text[i].lang_key,
  175270. info_ptr->text[i].text);
  175271. #else
  175272. png_warning(png_ptr, "Unable to write international text");
  175273. #endif
  175274. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175275. }
  175276. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175277. {
  175278. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175279. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175280. info_ptr->text[i].text, 0,
  175281. info_ptr->text[i].compression);
  175282. #else
  175283. png_warning(png_ptr, "Unable to write compressed text");
  175284. #endif
  175285. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175286. }
  175287. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175288. {
  175289. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175290. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175291. info_ptr->text[i].text,
  175292. 0);
  175293. #else
  175294. png_warning(png_ptr, "Unable to write uncompressed text");
  175295. #endif
  175296. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175297. }
  175298. }
  175299. #endif
  175300. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175301. if (info_ptr->unknown_chunks_num)
  175302. {
  175303. png_unknown_chunk *up;
  175304. png_debug(5, "writing extra chunks\n");
  175305. for (up = info_ptr->unknown_chunks;
  175306. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175307. up++)
  175308. {
  175309. int keep=png_handle_as_unknown(png_ptr, up->name);
  175310. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175311. up->location && (up->location & PNG_HAVE_PLTE) &&
  175312. !(up->location & PNG_HAVE_IDAT) &&
  175313. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175314. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175315. {
  175316. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175317. }
  175318. }
  175319. }
  175320. #endif
  175321. }
  175322. void PNGAPI
  175323. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175324. {
  175325. png_debug(1, "in png_write_end\n");
  175326. if (png_ptr == NULL)
  175327. return;
  175328. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175329. png_error(png_ptr, "No IDATs written into file");
  175330. if (info_ptr != NULL)
  175331. {
  175332. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175333. int i; /* local index variable */
  175334. #endif
  175335. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175336. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175337. !(png_ptr->mode & PNG_WROTE_tIME))
  175338. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175339. #endif
  175340. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175341. for (i = 0; i < info_ptr->num_text; i++)
  175342. {
  175343. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175344. info_ptr->text[i].compression);
  175345. if (info_ptr->text[i].compression > 0)
  175346. {
  175347. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175348. png_write_iTXt(png_ptr,
  175349. info_ptr->text[i].compression,
  175350. info_ptr->text[i].key,
  175351. info_ptr->text[i].lang,
  175352. info_ptr->text[i].lang_key,
  175353. info_ptr->text[i].text);
  175354. #else
  175355. png_warning(png_ptr, "Unable to write international text");
  175356. #endif
  175357. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175358. }
  175359. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175360. {
  175361. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175362. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175363. info_ptr->text[i].text, 0,
  175364. info_ptr->text[i].compression);
  175365. #else
  175366. png_warning(png_ptr, "Unable to write compressed text");
  175367. #endif
  175368. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175369. }
  175370. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175371. {
  175372. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175373. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175374. info_ptr->text[i].text, 0);
  175375. #else
  175376. png_warning(png_ptr, "Unable to write uncompressed text");
  175377. #endif
  175378. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175379. }
  175380. }
  175381. #endif
  175382. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175383. if (info_ptr->unknown_chunks_num)
  175384. {
  175385. png_unknown_chunk *up;
  175386. png_debug(5, "writing extra chunks\n");
  175387. for (up = info_ptr->unknown_chunks;
  175388. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175389. up++)
  175390. {
  175391. int keep=png_handle_as_unknown(png_ptr, up->name);
  175392. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175393. up->location && (up->location & PNG_AFTER_IDAT) &&
  175394. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175395. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175396. {
  175397. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175398. }
  175399. }
  175400. }
  175401. #endif
  175402. }
  175403. png_ptr->mode |= PNG_AFTER_IDAT;
  175404. png_write_IEND(png_ptr);
  175405. }
  175406. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175407. #if !defined(_WIN32_WCE)
  175408. void PNGAPI
  175409. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175410. {
  175411. png_debug(1, "in png_convert_from_struct_tm\n");
  175412. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175413. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175414. ptime->day = (png_byte)ttime->tm_mday;
  175415. ptime->hour = (png_byte)ttime->tm_hour;
  175416. ptime->minute = (png_byte)ttime->tm_min;
  175417. ptime->second = (png_byte)ttime->tm_sec;
  175418. }
  175419. void PNGAPI
  175420. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175421. {
  175422. struct tm *tbuf;
  175423. png_debug(1, "in png_convert_from_time_t\n");
  175424. tbuf = gmtime(&ttime);
  175425. png_convert_from_struct_tm(ptime, tbuf);
  175426. }
  175427. #endif
  175428. #endif
  175429. png_structp PNGAPI
  175430. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175431. png_error_ptr error_fn, png_error_ptr warn_fn)
  175432. {
  175433. #ifdef PNG_USER_MEM_SUPPORTED
  175434. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175435. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175436. }
  175437. png_structp PNGAPI
  175438. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175439. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175440. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175441. {
  175442. #endif /* PNG_USER_MEM_SUPPORTED */
  175443. png_structp png_ptr;
  175444. #ifdef PNG_SETJMP_SUPPORTED
  175445. #ifdef USE_FAR_KEYWORD
  175446. jmp_buf jmpbuf;
  175447. #endif
  175448. #endif
  175449. int i;
  175450. png_debug(1, "in png_create_write_struct\n");
  175451. #ifdef PNG_USER_MEM_SUPPORTED
  175452. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175453. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175454. #else
  175455. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175456. #endif /* PNG_USER_MEM_SUPPORTED */
  175457. if (png_ptr == NULL)
  175458. return (NULL);
  175459. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175460. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175461. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175462. #endif
  175463. #ifdef PNG_SETJMP_SUPPORTED
  175464. #ifdef USE_FAR_KEYWORD
  175465. if (setjmp(jmpbuf))
  175466. #else
  175467. if (setjmp(png_ptr->jmpbuf))
  175468. #endif
  175469. {
  175470. png_free(png_ptr, png_ptr->zbuf);
  175471. png_ptr->zbuf=NULL;
  175472. png_destroy_struct(png_ptr);
  175473. return (NULL);
  175474. }
  175475. #ifdef USE_FAR_KEYWORD
  175476. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175477. #endif
  175478. #endif
  175479. #ifdef PNG_USER_MEM_SUPPORTED
  175480. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175481. #endif /* PNG_USER_MEM_SUPPORTED */
  175482. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175483. i=0;
  175484. do
  175485. {
  175486. if(user_png_ver[i] != png_libpng_ver[i])
  175487. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175488. } while (png_libpng_ver[i++]);
  175489. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175490. {
  175491. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175492. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175493. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175494. {
  175495. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175496. char msg[80];
  175497. if (user_png_ver)
  175498. {
  175499. png_snprintf(msg, 80,
  175500. "Application was compiled with png.h from libpng-%.20s",
  175501. user_png_ver);
  175502. png_warning(png_ptr, msg);
  175503. }
  175504. png_snprintf(msg, 80,
  175505. "Application is running with png.c from libpng-%.20s",
  175506. png_libpng_ver);
  175507. png_warning(png_ptr, msg);
  175508. #endif
  175509. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175510. png_ptr->flags=0;
  175511. #endif
  175512. png_error(png_ptr,
  175513. "Incompatible libpng version in application and library");
  175514. }
  175515. }
  175516. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175517. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175518. (png_uint_32)png_ptr->zbuf_size);
  175519. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175520. png_flush_ptr_NULL);
  175521. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175522. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175523. 1, png_doublep_NULL, png_doublep_NULL);
  175524. #endif
  175525. #ifdef PNG_SETJMP_SUPPORTED
  175526. #ifdef USE_FAR_KEYWORD
  175527. if (setjmp(jmpbuf))
  175528. PNG_ABORT();
  175529. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175530. #else
  175531. if (setjmp(png_ptr->jmpbuf))
  175532. PNG_ABORT();
  175533. #endif
  175534. #endif
  175535. return (png_ptr);
  175536. }
  175537. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175538. #undef png_write_init
  175539. void PNGAPI
  175540. png_write_init(png_structp png_ptr)
  175541. {
  175542. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175543. }
  175544. void PNGAPI
  175545. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175546. png_size_t png_struct_size, png_size_t png_info_size)
  175547. {
  175548. if(png_ptr == NULL) return;
  175549. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175550. if(png_sizeof(png_struct) > png_struct_size ||
  175551. png_sizeof(png_info) > png_info_size)
  175552. {
  175553. char msg[80];
  175554. png_ptr->warning_fn=NULL;
  175555. if (user_png_ver)
  175556. {
  175557. png_snprintf(msg, 80,
  175558. "Application was compiled with png.h from libpng-%.20s",
  175559. user_png_ver);
  175560. png_warning(png_ptr, msg);
  175561. }
  175562. png_snprintf(msg, 80,
  175563. "Application is running with png.c from libpng-%.20s",
  175564. png_libpng_ver);
  175565. png_warning(png_ptr, msg);
  175566. }
  175567. #endif
  175568. if(png_sizeof(png_struct) > png_struct_size)
  175569. {
  175570. png_ptr->error_fn=NULL;
  175571. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175572. png_ptr->flags=0;
  175573. #endif
  175574. png_error(png_ptr,
  175575. "The png struct allocated by the application for writing is too small.");
  175576. }
  175577. if(png_sizeof(png_info) > png_info_size)
  175578. {
  175579. png_ptr->error_fn=NULL;
  175580. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175581. png_ptr->flags=0;
  175582. #endif
  175583. png_error(png_ptr,
  175584. "The info struct allocated by the application for writing is too small.");
  175585. }
  175586. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175587. }
  175588. #endif /* PNG_1_0_X || PNG_1_2_X */
  175589. void PNGAPI
  175590. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175591. png_size_t png_struct_size)
  175592. {
  175593. png_structp png_ptr=*ptr_ptr;
  175594. #ifdef PNG_SETJMP_SUPPORTED
  175595. jmp_buf tmp_jmp; /* to save current jump buffer */
  175596. #endif
  175597. int i = 0;
  175598. if (png_ptr == NULL)
  175599. return;
  175600. do
  175601. {
  175602. if (user_png_ver[i] != png_libpng_ver[i])
  175603. {
  175604. #ifdef PNG_LEGACY_SUPPORTED
  175605. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175606. #else
  175607. png_ptr->warning_fn=NULL;
  175608. png_warning(png_ptr,
  175609. "Application uses deprecated png_write_init() and should be recompiled.");
  175610. break;
  175611. #endif
  175612. }
  175613. } while (png_libpng_ver[i++]);
  175614. png_debug(1, "in png_write_init_3\n");
  175615. #ifdef PNG_SETJMP_SUPPORTED
  175616. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175617. #endif
  175618. if (png_sizeof(png_struct) > png_struct_size)
  175619. {
  175620. png_destroy_struct(png_ptr);
  175621. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175622. *ptr_ptr = png_ptr;
  175623. }
  175624. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175625. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175626. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175627. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175628. #endif
  175629. #ifdef PNG_SETJMP_SUPPORTED
  175630. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175631. #endif
  175632. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175633. png_flush_ptr_NULL);
  175634. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175635. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175636. (png_uint_32)png_ptr->zbuf_size);
  175637. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175638. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175639. 1, png_doublep_NULL, png_doublep_NULL);
  175640. #endif
  175641. }
  175642. void PNGAPI
  175643. png_write_rows(png_structp png_ptr, png_bytepp row,
  175644. png_uint_32 num_rows)
  175645. {
  175646. png_uint_32 i; /* row counter */
  175647. png_bytepp rp; /* row pointer */
  175648. png_debug(1, "in png_write_rows\n");
  175649. if (png_ptr == NULL)
  175650. return;
  175651. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175652. {
  175653. png_write_row(png_ptr, *rp);
  175654. }
  175655. }
  175656. void PNGAPI
  175657. png_write_image(png_structp png_ptr, png_bytepp image)
  175658. {
  175659. png_uint_32 i; /* row index */
  175660. int pass, num_pass; /* pass variables */
  175661. png_bytepp rp; /* points to current row */
  175662. if (png_ptr == NULL)
  175663. return;
  175664. png_debug(1, "in png_write_image\n");
  175665. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175666. num_pass = png_set_interlace_handling(png_ptr);
  175667. #else
  175668. num_pass = 1;
  175669. #endif
  175670. for (pass = 0; pass < num_pass; pass++)
  175671. {
  175672. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175673. {
  175674. png_write_row(png_ptr, *rp);
  175675. }
  175676. }
  175677. }
  175678. void PNGAPI
  175679. png_write_row(png_structp png_ptr, png_bytep row)
  175680. {
  175681. if (png_ptr == NULL)
  175682. return;
  175683. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175684. png_ptr->row_number, png_ptr->pass);
  175685. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175686. {
  175687. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175688. png_error(png_ptr,
  175689. "png_write_info was never called before png_write_row.");
  175690. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175691. if (png_ptr->transformations & PNG_INVERT_MONO)
  175692. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175693. #endif
  175694. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175695. if (png_ptr->transformations & PNG_FILLER)
  175696. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175697. #endif
  175698. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175699. if (png_ptr->transformations & PNG_PACKSWAP)
  175700. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175701. #endif
  175702. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175703. if (png_ptr->transformations & PNG_PACK)
  175704. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175705. #endif
  175706. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175707. if (png_ptr->transformations & PNG_SHIFT)
  175708. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175709. #endif
  175710. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175711. if (png_ptr->transformations & PNG_BGR)
  175712. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175713. #endif
  175714. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175715. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175716. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175717. #endif
  175718. png_write_start_row(png_ptr);
  175719. }
  175720. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175721. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175722. {
  175723. switch (png_ptr->pass)
  175724. {
  175725. case 0:
  175726. if (png_ptr->row_number & 0x07)
  175727. {
  175728. png_write_finish_row(png_ptr);
  175729. return;
  175730. }
  175731. break;
  175732. case 1:
  175733. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175734. {
  175735. png_write_finish_row(png_ptr);
  175736. return;
  175737. }
  175738. break;
  175739. case 2:
  175740. if ((png_ptr->row_number & 0x07) != 4)
  175741. {
  175742. png_write_finish_row(png_ptr);
  175743. return;
  175744. }
  175745. break;
  175746. case 3:
  175747. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175748. {
  175749. png_write_finish_row(png_ptr);
  175750. return;
  175751. }
  175752. break;
  175753. case 4:
  175754. if ((png_ptr->row_number & 0x03) != 2)
  175755. {
  175756. png_write_finish_row(png_ptr);
  175757. return;
  175758. }
  175759. break;
  175760. case 5:
  175761. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175762. {
  175763. png_write_finish_row(png_ptr);
  175764. return;
  175765. }
  175766. break;
  175767. case 6:
  175768. if (!(png_ptr->row_number & 0x01))
  175769. {
  175770. png_write_finish_row(png_ptr);
  175771. return;
  175772. }
  175773. break;
  175774. }
  175775. }
  175776. #endif
  175777. png_ptr->row_info.color_type = png_ptr->color_type;
  175778. png_ptr->row_info.width = png_ptr->usr_width;
  175779. png_ptr->row_info.channels = png_ptr->usr_channels;
  175780. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175781. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175782. png_ptr->row_info.channels);
  175783. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175784. png_ptr->row_info.width);
  175785. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175786. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175787. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175788. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175789. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175790. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175791. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175792. png_ptr->row_info.rowbytes);
  175793. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175794. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175795. (png_ptr->transformations & PNG_INTERLACE))
  175796. {
  175797. png_do_write_interlace(&(png_ptr->row_info),
  175798. png_ptr->row_buf + 1, png_ptr->pass);
  175799. if (!(png_ptr->row_info.width))
  175800. {
  175801. png_write_finish_row(png_ptr);
  175802. return;
  175803. }
  175804. }
  175805. #endif
  175806. if (png_ptr->transformations)
  175807. png_do_write_transformations(png_ptr);
  175808. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175809. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175810. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175811. {
  175812. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175813. }
  175814. #endif
  175815. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175816. if (png_ptr->write_row_fn != NULL)
  175817. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175818. }
  175819. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175820. void PNGAPI
  175821. png_set_flush(png_structp png_ptr, int nrows)
  175822. {
  175823. png_debug(1, "in png_set_flush\n");
  175824. if (png_ptr == NULL)
  175825. return;
  175826. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175827. }
  175828. void PNGAPI
  175829. png_write_flush(png_structp png_ptr)
  175830. {
  175831. int wrote_IDAT;
  175832. png_debug(1, "in png_write_flush\n");
  175833. if (png_ptr == NULL)
  175834. return;
  175835. if (png_ptr->row_number >= png_ptr->num_rows)
  175836. return;
  175837. do
  175838. {
  175839. int ret;
  175840. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175841. wrote_IDAT = 0;
  175842. if (ret != Z_OK)
  175843. {
  175844. if (png_ptr->zstream.msg != NULL)
  175845. png_error(png_ptr, png_ptr->zstream.msg);
  175846. else
  175847. png_error(png_ptr, "zlib error");
  175848. }
  175849. if (!(png_ptr->zstream.avail_out))
  175850. {
  175851. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175852. png_ptr->zbuf_size);
  175853. png_ptr->zstream.next_out = png_ptr->zbuf;
  175854. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175855. wrote_IDAT = 1;
  175856. }
  175857. } while(wrote_IDAT == 1);
  175858. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175859. {
  175860. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175861. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175862. png_ptr->zstream.next_out = png_ptr->zbuf;
  175863. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175864. }
  175865. png_ptr->flush_rows = 0;
  175866. png_flush(png_ptr);
  175867. }
  175868. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175869. void PNGAPI
  175870. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175871. {
  175872. png_structp png_ptr = NULL;
  175873. png_infop info_ptr = NULL;
  175874. #ifdef PNG_USER_MEM_SUPPORTED
  175875. png_free_ptr free_fn = NULL;
  175876. png_voidp mem_ptr = NULL;
  175877. #endif
  175878. png_debug(1, "in png_destroy_write_struct\n");
  175879. if (png_ptr_ptr != NULL)
  175880. {
  175881. png_ptr = *png_ptr_ptr;
  175882. #ifdef PNG_USER_MEM_SUPPORTED
  175883. free_fn = png_ptr->free_fn;
  175884. mem_ptr = png_ptr->mem_ptr;
  175885. #endif
  175886. }
  175887. if (info_ptr_ptr != NULL)
  175888. info_ptr = *info_ptr_ptr;
  175889. if (info_ptr != NULL)
  175890. {
  175891. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175892. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175893. if (png_ptr->num_chunk_list)
  175894. {
  175895. png_free(png_ptr, png_ptr->chunk_list);
  175896. png_ptr->chunk_list=NULL;
  175897. png_ptr->num_chunk_list=0;
  175898. }
  175899. #endif
  175900. #ifdef PNG_USER_MEM_SUPPORTED
  175901. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175902. (png_voidp)mem_ptr);
  175903. #else
  175904. png_destroy_struct((png_voidp)info_ptr);
  175905. #endif
  175906. *info_ptr_ptr = NULL;
  175907. }
  175908. if (png_ptr != NULL)
  175909. {
  175910. png_write_destroy(png_ptr);
  175911. #ifdef PNG_USER_MEM_SUPPORTED
  175912. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175913. (png_voidp)mem_ptr);
  175914. #else
  175915. png_destroy_struct((png_voidp)png_ptr);
  175916. #endif
  175917. *png_ptr_ptr = NULL;
  175918. }
  175919. }
  175920. void /* PRIVATE */
  175921. png_write_destroy(png_structp png_ptr)
  175922. {
  175923. #ifdef PNG_SETJMP_SUPPORTED
  175924. jmp_buf tmp_jmp; /* save jump buffer */
  175925. #endif
  175926. png_error_ptr error_fn;
  175927. png_error_ptr warning_fn;
  175928. png_voidp error_ptr;
  175929. #ifdef PNG_USER_MEM_SUPPORTED
  175930. png_free_ptr free_fn;
  175931. #endif
  175932. png_debug(1, "in png_write_destroy\n");
  175933. deflateEnd(&png_ptr->zstream);
  175934. png_free(png_ptr, png_ptr->zbuf);
  175935. png_free(png_ptr, png_ptr->row_buf);
  175936. png_free(png_ptr, png_ptr->prev_row);
  175937. png_free(png_ptr, png_ptr->sub_row);
  175938. png_free(png_ptr, png_ptr->up_row);
  175939. png_free(png_ptr, png_ptr->avg_row);
  175940. png_free(png_ptr, png_ptr->paeth_row);
  175941. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  175942. png_free(png_ptr, png_ptr->time_buffer);
  175943. #endif
  175944. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175945. png_free(png_ptr, png_ptr->prev_filters);
  175946. png_free(png_ptr, png_ptr->filter_weights);
  175947. png_free(png_ptr, png_ptr->inv_filter_weights);
  175948. png_free(png_ptr, png_ptr->filter_costs);
  175949. png_free(png_ptr, png_ptr->inv_filter_costs);
  175950. #endif
  175951. #ifdef PNG_SETJMP_SUPPORTED
  175952. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175953. #endif
  175954. error_fn = png_ptr->error_fn;
  175955. warning_fn = png_ptr->warning_fn;
  175956. error_ptr = png_ptr->error_ptr;
  175957. #ifdef PNG_USER_MEM_SUPPORTED
  175958. free_fn = png_ptr->free_fn;
  175959. #endif
  175960. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175961. png_ptr->error_fn = error_fn;
  175962. png_ptr->warning_fn = warning_fn;
  175963. png_ptr->error_ptr = error_ptr;
  175964. #ifdef PNG_USER_MEM_SUPPORTED
  175965. png_ptr->free_fn = free_fn;
  175966. #endif
  175967. #ifdef PNG_SETJMP_SUPPORTED
  175968. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175969. #endif
  175970. }
  175971. void PNGAPI
  175972. png_set_filter(png_structp png_ptr, int method, int filters)
  175973. {
  175974. png_debug(1, "in png_set_filter\n");
  175975. if (png_ptr == NULL)
  175976. return;
  175977. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175978. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175979. (method == PNG_INTRAPIXEL_DIFFERENCING))
  175980. method = PNG_FILTER_TYPE_BASE;
  175981. #endif
  175982. if (method == PNG_FILTER_TYPE_BASE)
  175983. {
  175984. switch (filters & (PNG_ALL_FILTERS | 0x07))
  175985. {
  175986. #ifndef PNG_NO_WRITE_FILTER
  175987. case 5:
  175988. case 6:
  175989. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  175990. #endif /* PNG_NO_WRITE_FILTER */
  175991. case PNG_FILTER_VALUE_NONE:
  175992. png_ptr->do_filter=PNG_FILTER_NONE; break;
  175993. #ifndef PNG_NO_WRITE_FILTER
  175994. case PNG_FILTER_VALUE_SUB:
  175995. png_ptr->do_filter=PNG_FILTER_SUB; break;
  175996. case PNG_FILTER_VALUE_UP:
  175997. png_ptr->do_filter=PNG_FILTER_UP; break;
  175998. case PNG_FILTER_VALUE_AVG:
  175999. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176000. case PNG_FILTER_VALUE_PAETH:
  176001. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176002. default: png_ptr->do_filter = (png_byte)filters; break;
  176003. #else
  176004. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176005. #endif /* PNG_NO_WRITE_FILTER */
  176006. }
  176007. if (png_ptr->row_buf != NULL)
  176008. {
  176009. #ifndef PNG_NO_WRITE_FILTER
  176010. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176011. {
  176012. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176013. (png_ptr->rowbytes + 1));
  176014. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176015. }
  176016. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176017. {
  176018. if (png_ptr->prev_row == NULL)
  176019. {
  176020. png_warning(png_ptr, "Can't add Up filter after starting");
  176021. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176022. }
  176023. else
  176024. {
  176025. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176026. (png_ptr->rowbytes + 1));
  176027. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176028. }
  176029. }
  176030. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176031. {
  176032. if (png_ptr->prev_row == NULL)
  176033. {
  176034. png_warning(png_ptr, "Can't add Average filter after starting");
  176035. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176036. }
  176037. else
  176038. {
  176039. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176040. (png_ptr->rowbytes + 1));
  176041. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176042. }
  176043. }
  176044. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176045. png_ptr->paeth_row == NULL)
  176046. {
  176047. if (png_ptr->prev_row == NULL)
  176048. {
  176049. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176050. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176051. }
  176052. else
  176053. {
  176054. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176055. (png_ptr->rowbytes + 1));
  176056. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176057. }
  176058. }
  176059. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176060. #endif /* PNG_NO_WRITE_FILTER */
  176061. png_ptr->do_filter = PNG_FILTER_NONE;
  176062. }
  176063. }
  176064. else
  176065. png_error(png_ptr, "Unknown custom filter method");
  176066. }
  176067. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176068. void PNGAPI
  176069. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176070. int num_weights, png_doublep filter_weights,
  176071. png_doublep filter_costs)
  176072. {
  176073. int i;
  176074. png_debug(1, "in png_set_filter_heuristics\n");
  176075. if (png_ptr == NULL)
  176076. return;
  176077. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176078. {
  176079. png_warning(png_ptr, "Unknown filter heuristic method");
  176080. return;
  176081. }
  176082. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176083. {
  176084. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176085. }
  176086. if (num_weights < 0 || filter_weights == NULL ||
  176087. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176088. {
  176089. num_weights = 0;
  176090. }
  176091. png_ptr->num_prev_filters = (png_byte)num_weights;
  176092. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176093. if (num_weights > 0)
  176094. {
  176095. if (png_ptr->prev_filters == NULL)
  176096. {
  176097. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176098. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176099. for (i = 0; i < num_weights; i++)
  176100. {
  176101. png_ptr->prev_filters[i] = 255;
  176102. }
  176103. }
  176104. if (png_ptr->filter_weights == NULL)
  176105. {
  176106. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176107. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176108. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176109. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176110. for (i = 0; i < num_weights; i++)
  176111. {
  176112. png_ptr->inv_filter_weights[i] =
  176113. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176114. }
  176115. }
  176116. for (i = 0; i < num_weights; i++)
  176117. {
  176118. if (filter_weights[i] < 0.0)
  176119. {
  176120. png_ptr->inv_filter_weights[i] =
  176121. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176122. }
  176123. else
  176124. {
  176125. png_ptr->inv_filter_weights[i] =
  176126. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176127. png_ptr->filter_weights[i] =
  176128. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176129. }
  176130. }
  176131. }
  176132. if (png_ptr->filter_costs == NULL)
  176133. {
  176134. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176135. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176136. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176137. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176138. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176139. {
  176140. png_ptr->inv_filter_costs[i] =
  176141. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176142. }
  176143. }
  176144. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176145. {
  176146. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176147. {
  176148. png_ptr->inv_filter_costs[i] =
  176149. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176150. }
  176151. else if (filter_costs[i] >= 1.0)
  176152. {
  176153. png_ptr->inv_filter_costs[i] =
  176154. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176155. png_ptr->filter_costs[i] =
  176156. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176157. }
  176158. }
  176159. }
  176160. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176161. void PNGAPI
  176162. png_set_compression_level(png_structp png_ptr, int level)
  176163. {
  176164. png_debug(1, "in png_set_compression_level\n");
  176165. if (png_ptr == NULL)
  176166. return;
  176167. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176168. png_ptr->zlib_level = level;
  176169. }
  176170. void PNGAPI
  176171. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176172. {
  176173. png_debug(1, "in png_set_compression_mem_level\n");
  176174. if (png_ptr == NULL)
  176175. return;
  176176. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176177. png_ptr->zlib_mem_level = mem_level;
  176178. }
  176179. void PNGAPI
  176180. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176181. {
  176182. png_debug(1, "in png_set_compression_strategy\n");
  176183. if (png_ptr == NULL)
  176184. return;
  176185. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176186. png_ptr->zlib_strategy = strategy;
  176187. }
  176188. void PNGAPI
  176189. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176190. {
  176191. if (png_ptr == NULL)
  176192. return;
  176193. if (window_bits > 15)
  176194. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176195. else if (window_bits < 8)
  176196. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176197. #ifndef WBITS_8_OK
  176198. if (window_bits == 8)
  176199. {
  176200. png_warning(png_ptr, "Compression window is being reset to 512");
  176201. window_bits=9;
  176202. }
  176203. #endif
  176204. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176205. png_ptr->zlib_window_bits = window_bits;
  176206. }
  176207. void PNGAPI
  176208. png_set_compression_method(png_structp png_ptr, int method)
  176209. {
  176210. png_debug(1, "in png_set_compression_method\n");
  176211. if (png_ptr == NULL)
  176212. return;
  176213. if (method != 8)
  176214. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176215. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176216. png_ptr->zlib_method = method;
  176217. }
  176218. void PNGAPI
  176219. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176220. {
  176221. if (png_ptr == NULL)
  176222. return;
  176223. png_ptr->write_row_fn = write_row_fn;
  176224. }
  176225. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176226. void PNGAPI
  176227. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176228. write_user_transform_fn)
  176229. {
  176230. png_debug(1, "in png_set_write_user_transform_fn\n");
  176231. if (png_ptr == NULL)
  176232. return;
  176233. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176234. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176235. }
  176236. #endif
  176237. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176238. void PNGAPI
  176239. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176240. int transforms, voidp params)
  176241. {
  176242. if (png_ptr == NULL || info_ptr == NULL)
  176243. return;
  176244. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176245. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176246. png_set_invert_alpha(png_ptr);
  176247. #endif
  176248. png_write_info(png_ptr, info_ptr);
  176249. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176250. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176251. png_set_invert_mono(png_ptr);
  176252. #endif
  176253. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176254. if ((transforms & PNG_TRANSFORM_SHIFT)
  176255. && (info_ptr->valid & PNG_INFO_sBIT))
  176256. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176257. #endif
  176258. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176259. if (transforms & PNG_TRANSFORM_PACKING)
  176260. png_set_packing(png_ptr);
  176261. #endif
  176262. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176263. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176264. png_set_swap_alpha(png_ptr);
  176265. #endif
  176266. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176267. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176268. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176269. #endif
  176270. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176271. if (transforms & PNG_TRANSFORM_BGR)
  176272. png_set_bgr(png_ptr);
  176273. #endif
  176274. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176275. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176276. png_set_swap(png_ptr);
  176277. #endif
  176278. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176279. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176280. png_set_packswap(png_ptr);
  176281. #endif
  176282. if (info_ptr->valid & PNG_INFO_IDAT)
  176283. png_write_image(png_ptr, info_ptr->row_pointers);
  176284. png_write_end(png_ptr, info_ptr);
  176285. transforms = transforms; /* quiet compiler warnings */
  176286. params = params;
  176287. }
  176288. #endif
  176289. #endif /* PNG_WRITE_SUPPORTED */
  176290. /*** End of inlined file: pngwrite.c ***/
  176291. /*** Start of inlined file: pngwtran.c ***/
  176292. #define PNG_INTERNAL
  176293. #ifdef PNG_WRITE_SUPPORTED
  176294. void /* PRIVATE */
  176295. png_do_write_transformations(png_structp png_ptr)
  176296. {
  176297. png_debug(1, "in png_do_write_transformations\n");
  176298. if (png_ptr == NULL)
  176299. return;
  176300. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176301. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176302. if(png_ptr->write_user_transform_fn != NULL)
  176303. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176304. (png_ptr, /* png_ptr */
  176305. &(png_ptr->row_info), /* row_info: */
  176306. png_ptr->row_buf + 1); /* start of pixel data for row */
  176307. #endif
  176308. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176309. if (png_ptr->transformations & PNG_FILLER)
  176310. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176311. png_ptr->flags);
  176312. #endif
  176313. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176314. if (png_ptr->transformations & PNG_PACKSWAP)
  176315. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176316. #endif
  176317. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176318. if (png_ptr->transformations & PNG_PACK)
  176319. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176320. (png_uint_32)png_ptr->bit_depth);
  176321. #endif
  176322. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176323. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176324. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176325. #endif
  176326. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176327. if (png_ptr->transformations & PNG_SHIFT)
  176328. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176329. &(png_ptr->shift));
  176330. #endif
  176331. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176332. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176333. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176334. #endif
  176335. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176336. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176337. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176338. #endif
  176339. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176340. if (png_ptr->transformations & PNG_BGR)
  176341. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176342. #endif
  176343. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176344. if (png_ptr->transformations & PNG_INVERT_MONO)
  176345. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176346. #endif
  176347. }
  176348. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176349. void /* PRIVATE */
  176350. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176351. {
  176352. png_debug(1, "in png_do_pack\n");
  176353. if (row_info->bit_depth == 8 &&
  176354. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176355. row != NULL && row_info != NULL &&
  176356. #endif
  176357. row_info->channels == 1)
  176358. {
  176359. switch ((int)bit_depth)
  176360. {
  176361. case 1:
  176362. {
  176363. png_bytep sp, dp;
  176364. int mask, v;
  176365. png_uint_32 i;
  176366. png_uint_32 row_width = row_info->width;
  176367. sp = row;
  176368. dp = row;
  176369. mask = 0x80;
  176370. v = 0;
  176371. for (i = 0; i < row_width; i++)
  176372. {
  176373. if (*sp != 0)
  176374. v |= mask;
  176375. sp++;
  176376. if (mask > 1)
  176377. mask >>= 1;
  176378. else
  176379. {
  176380. mask = 0x80;
  176381. *dp = (png_byte)v;
  176382. dp++;
  176383. v = 0;
  176384. }
  176385. }
  176386. if (mask != 0x80)
  176387. *dp = (png_byte)v;
  176388. break;
  176389. }
  176390. case 2:
  176391. {
  176392. png_bytep sp, dp;
  176393. int shift, v;
  176394. png_uint_32 i;
  176395. png_uint_32 row_width = row_info->width;
  176396. sp = row;
  176397. dp = row;
  176398. shift = 6;
  176399. v = 0;
  176400. for (i = 0; i < row_width; i++)
  176401. {
  176402. png_byte value;
  176403. value = (png_byte)(*sp & 0x03);
  176404. v |= (value << shift);
  176405. if (shift == 0)
  176406. {
  176407. shift = 6;
  176408. *dp = (png_byte)v;
  176409. dp++;
  176410. v = 0;
  176411. }
  176412. else
  176413. shift -= 2;
  176414. sp++;
  176415. }
  176416. if (shift != 6)
  176417. *dp = (png_byte)v;
  176418. break;
  176419. }
  176420. case 4:
  176421. {
  176422. png_bytep sp, dp;
  176423. int shift, v;
  176424. png_uint_32 i;
  176425. png_uint_32 row_width = row_info->width;
  176426. sp = row;
  176427. dp = row;
  176428. shift = 4;
  176429. v = 0;
  176430. for (i = 0; i < row_width; i++)
  176431. {
  176432. png_byte value;
  176433. value = (png_byte)(*sp & 0x0f);
  176434. v |= (value << shift);
  176435. if (shift == 0)
  176436. {
  176437. shift = 4;
  176438. *dp = (png_byte)v;
  176439. dp++;
  176440. v = 0;
  176441. }
  176442. else
  176443. shift -= 4;
  176444. sp++;
  176445. }
  176446. if (shift != 4)
  176447. *dp = (png_byte)v;
  176448. break;
  176449. }
  176450. }
  176451. row_info->bit_depth = (png_byte)bit_depth;
  176452. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176453. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176454. row_info->width);
  176455. }
  176456. }
  176457. #endif
  176458. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176459. void /* PRIVATE */
  176460. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176461. {
  176462. png_debug(1, "in png_do_shift\n");
  176463. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176464. if (row != NULL && row_info != NULL &&
  176465. #else
  176466. if (
  176467. #endif
  176468. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176469. {
  176470. int shift_start[4], shift_dec[4];
  176471. int channels = 0;
  176472. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176473. {
  176474. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176475. shift_dec[channels] = bit_depth->red;
  176476. channels++;
  176477. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176478. shift_dec[channels] = bit_depth->green;
  176479. channels++;
  176480. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176481. shift_dec[channels] = bit_depth->blue;
  176482. channels++;
  176483. }
  176484. else
  176485. {
  176486. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176487. shift_dec[channels] = bit_depth->gray;
  176488. channels++;
  176489. }
  176490. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176491. {
  176492. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176493. shift_dec[channels] = bit_depth->alpha;
  176494. channels++;
  176495. }
  176496. if (row_info->bit_depth < 8)
  176497. {
  176498. png_bytep bp = row;
  176499. png_uint_32 i;
  176500. png_byte mask;
  176501. png_uint_32 row_bytes = row_info->rowbytes;
  176502. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176503. mask = 0x55;
  176504. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176505. mask = 0x11;
  176506. else
  176507. mask = 0xff;
  176508. for (i = 0; i < row_bytes; i++, bp++)
  176509. {
  176510. png_uint_16 v;
  176511. int j;
  176512. v = *bp;
  176513. *bp = 0;
  176514. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176515. {
  176516. if (j > 0)
  176517. *bp |= (png_byte)((v << j) & 0xff);
  176518. else
  176519. *bp |= (png_byte)((v >> (-j)) & mask);
  176520. }
  176521. }
  176522. }
  176523. else if (row_info->bit_depth == 8)
  176524. {
  176525. png_bytep bp = row;
  176526. png_uint_32 i;
  176527. png_uint_32 istop = channels * row_info->width;
  176528. for (i = 0; i < istop; i++, bp++)
  176529. {
  176530. png_uint_16 v;
  176531. int j;
  176532. int c = (int)(i%channels);
  176533. v = *bp;
  176534. *bp = 0;
  176535. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176536. {
  176537. if (j > 0)
  176538. *bp |= (png_byte)((v << j) & 0xff);
  176539. else
  176540. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176541. }
  176542. }
  176543. }
  176544. else
  176545. {
  176546. png_bytep bp;
  176547. png_uint_32 i;
  176548. png_uint_32 istop = channels * row_info->width;
  176549. for (bp = row, i = 0; i < istop; i++)
  176550. {
  176551. int c = (int)(i%channels);
  176552. png_uint_16 value, v;
  176553. int j;
  176554. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176555. value = 0;
  176556. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176557. {
  176558. if (j > 0)
  176559. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176560. else
  176561. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176562. }
  176563. *bp++ = (png_byte)(value >> 8);
  176564. *bp++ = (png_byte)(value & 0xff);
  176565. }
  176566. }
  176567. }
  176568. }
  176569. #endif
  176570. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176571. void /* PRIVATE */
  176572. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176573. {
  176574. png_debug(1, "in png_do_write_swap_alpha\n");
  176575. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176576. if (row != NULL && row_info != NULL)
  176577. #endif
  176578. {
  176579. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176580. {
  176581. if (row_info->bit_depth == 8)
  176582. {
  176583. png_bytep sp, dp;
  176584. png_uint_32 i;
  176585. png_uint_32 row_width = row_info->width;
  176586. for (i = 0, sp = dp = row; i < row_width; i++)
  176587. {
  176588. png_byte save = *(sp++);
  176589. *(dp++) = *(sp++);
  176590. *(dp++) = *(sp++);
  176591. *(dp++) = *(sp++);
  176592. *(dp++) = save;
  176593. }
  176594. }
  176595. else
  176596. {
  176597. png_bytep sp, dp;
  176598. png_uint_32 i;
  176599. png_uint_32 row_width = row_info->width;
  176600. for (i = 0, sp = dp = row; i < row_width; i++)
  176601. {
  176602. png_byte save[2];
  176603. save[0] = *(sp++);
  176604. save[1] = *(sp++);
  176605. *(dp++) = *(sp++);
  176606. *(dp++) = *(sp++);
  176607. *(dp++) = *(sp++);
  176608. *(dp++) = *(sp++);
  176609. *(dp++) = *(sp++);
  176610. *(dp++) = *(sp++);
  176611. *(dp++) = save[0];
  176612. *(dp++) = save[1];
  176613. }
  176614. }
  176615. }
  176616. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176617. {
  176618. if (row_info->bit_depth == 8)
  176619. {
  176620. png_bytep sp, dp;
  176621. png_uint_32 i;
  176622. png_uint_32 row_width = row_info->width;
  176623. for (i = 0, sp = dp = row; i < row_width; i++)
  176624. {
  176625. png_byte save = *(sp++);
  176626. *(dp++) = *(sp++);
  176627. *(dp++) = save;
  176628. }
  176629. }
  176630. else
  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[2];
  176638. save[0] = *(sp++);
  176639. save[1] = *(sp++);
  176640. *(dp++) = *(sp++);
  176641. *(dp++) = *(sp++);
  176642. *(dp++) = save[0];
  176643. *(dp++) = save[1];
  176644. }
  176645. }
  176646. }
  176647. }
  176648. }
  176649. #endif
  176650. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176651. void /* PRIVATE */
  176652. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176653. {
  176654. png_debug(1, "in png_do_write_invert_alpha\n");
  176655. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176656. if (row != NULL && row_info != NULL)
  176657. #endif
  176658. {
  176659. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176660. {
  176661. if (row_info->bit_depth == 8)
  176662. {
  176663. png_bytep sp, dp;
  176664. png_uint_32 i;
  176665. png_uint_32 row_width = row_info->width;
  176666. for (i = 0, sp = dp = row; i < row_width; i++)
  176667. {
  176668. sp+=3; dp = sp;
  176669. *(dp++) = (png_byte)(255 - *(sp++));
  176670. }
  176671. }
  176672. else
  176673. {
  176674. png_bytep sp, dp;
  176675. png_uint_32 i;
  176676. png_uint_32 row_width = row_info->width;
  176677. for (i = 0, sp = dp = row; i < row_width; i++)
  176678. {
  176679. sp+=6; dp = sp;
  176680. *(dp++) = (png_byte)(255 - *(sp++));
  176681. *(dp++) = (png_byte)(255 - *(sp++));
  176682. }
  176683. }
  176684. }
  176685. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176686. {
  176687. if (row_info->bit_depth == 8)
  176688. {
  176689. png_bytep sp, dp;
  176690. png_uint_32 i;
  176691. png_uint_32 row_width = row_info->width;
  176692. for (i = 0, sp = dp = row; i < row_width; i++)
  176693. {
  176694. *(dp++) = *(sp++);
  176695. *(dp++) = (png_byte)(255 - *(sp++));
  176696. }
  176697. }
  176698. else
  176699. {
  176700. png_bytep sp, dp;
  176701. png_uint_32 i;
  176702. png_uint_32 row_width = row_info->width;
  176703. for (i = 0, sp = dp = row; i < row_width; i++)
  176704. {
  176705. sp+=2; dp = sp;
  176706. *(dp++) = (png_byte)(255 - *(sp++));
  176707. *(dp++) = (png_byte)(255 - *(sp++));
  176708. }
  176709. }
  176710. }
  176711. }
  176712. }
  176713. #endif
  176714. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176715. void /* PRIVATE */
  176716. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176717. {
  176718. png_debug(1, "in png_do_write_intrapixel\n");
  176719. if (
  176720. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176721. row != NULL && row_info != NULL &&
  176722. #endif
  176723. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176724. {
  176725. int bytes_per_pixel;
  176726. png_uint_32 row_width = row_info->width;
  176727. if (row_info->bit_depth == 8)
  176728. {
  176729. png_bytep rp;
  176730. png_uint_32 i;
  176731. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176732. bytes_per_pixel = 3;
  176733. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176734. bytes_per_pixel = 4;
  176735. else
  176736. return;
  176737. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176738. {
  176739. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176740. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176741. }
  176742. }
  176743. else if (row_info->bit_depth == 16)
  176744. {
  176745. png_bytep rp;
  176746. png_uint_32 i;
  176747. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176748. bytes_per_pixel = 6;
  176749. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176750. bytes_per_pixel = 8;
  176751. else
  176752. return;
  176753. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176754. {
  176755. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176756. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176757. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176758. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176759. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176760. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176761. *(rp+1) = (png_byte)(red & 0xff);
  176762. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176763. *(rp+5) = (png_byte)(blue & 0xff);
  176764. }
  176765. }
  176766. }
  176767. }
  176768. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176769. #endif /* PNG_WRITE_SUPPORTED */
  176770. /*** End of inlined file: pngwtran.c ***/
  176771. /*** Start of inlined file: pngwutil.c ***/
  176772. #define PNG_INTERNAL
  176773. #ifdef PNG_WRITE_SUPPORTED
  176774. void PNGAPI
  176775. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176776. {
  176777. buf[0] = (png_byte)((i >> 24) & 0xff);
  176778. buf[1] = (png_byte)((i >> 16) & 0xff);
  176779. buf[2] = (png_byte)((i >> 8) & 0xff);
  176780. buf[3] = (png_byte)(i & 0xff);
  176781. }
  176782. void PNGAPI
  176783. png_save_int_32(png_bytep buf, png_int_32 i)
  176784. {
  176785. buf[0] = (png_byte)((i >> 24) & 0xff);
  176786. buf[1] = (png_byte)((i >> 16) & 0xff);
  176787. buf[2] = (png_byte)((i >> 8) & 0xff);
  176788. buf[3] = (png_byte)(i & 0xff);
  176789. }
  176790. void PNGAPI
  176791. png_save_uint_16(png_bytep buf, unsigned int i)
  176792. {
  176793. buf[0] = (png_byte)((i >> 8) & 0xff);
  176794. buf[1] = (png_byte)(i & 0xff);
  176795. }
  176796. void PNGAPI
  176797. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176798. png_bytep data, png_size_t length)
  176799. {
  176800. if(png_ptr == NULL) return;
  176801. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176802. png_write_chunk_data(png_ptr, data, length);
  176803. png_write_chunk_end(png_ptr);
  176804. }
  176805. void PNGAPI
  176806. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176807. png_uint_32 length)
  176808. {
  176809. png_byte buf[4];
  176810. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176811. if(png_ptr == NULL) return;
  176812. png_save_uint_32(buf, length);
  176813. png_write_data(png_ptr, buf, (png_size_t)4);
  176814. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176815. png_reset_crc(png_ptr);
  176816. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176817. }
  176818. void PNGAPI
  176819. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176820. {
  176821. if(png_ptr == NULL) return;
  176822. if (data != NULL && length > 0)
  176823. {
  176824. png_calculate_crc(png_ptr, data, length);
  176825. png_write_data(png_ptr, data, length);
  176826. }
  176827. }
  176828. void PNGAPI
  176829. png_write_chunk_end(png_structp png_ptr)
  176830. {
  176831. png_byte buf[4];
  176832. if(png_ptr == NULL) return;
  176833. png_save_uint_32(buf, png_ptr->crc);
  176834. png_write_data(png_ptr, buf, (png_size_t)4);
  176835. }
  176836. void /* PRIVATE */
  176837. png_write_sig(png_structp png_ptr)
  176838. {
  176839. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176840. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176841. (png_size_t)8 - png_ptr->sig_bytes);
  176842. if(png_ptr->sig_bytes < 3)
  176843. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176844. }
  176845. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176846. typedef struct
  176847. {
  176848. char *input; /* the uncompressed input data */
  176849. int input_len; /* its length */
  176850. int num_output_ptr; /* number of output pointers used */
  176851. int max_output_ptr; /* size of output_ptr */
  176852. png_charpp output_ptr; /* array of pointers to output */
  176853. } compression_state;
  176854. static int /* PRIVATE */
  176855. png_text_compress(png_structp png_ptr,
  176856. png_charp text, png_size_t text_len, int compression,
  176857. compression_state *comp)
  176858. {
  176859. int ret;
  176860. comp->num_output_ptr = 0;
  176861. comp->max_output_ptr = 0;
  176862. comp->output_ptr = NULL;
  176863. comp->input = NULL;
  176864. comp->input_len = 0;
  176865. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176866. {
  176867. comp->input = text;
  176868. comp->input_len = text_len;
  176869. return((int)text_len);
  176870. }
  176871. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176872. {
  176873. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176874. char msg[50];
  176875. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176876. png_warning(png_ptr, msg);
  176877. #else
  176878. png_warning(png_ptr, "Unknown compression type");
  176879. #endif
  176880. }
  176881. png_ptr->zstream.avail_in = (uInt)text_len;
  176882. png_ptr->zstream.next_in = (Bytef *)text;
  176883. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176884. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176885. do
  176886. {
  176887. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176888. if (ret != Z_OK)
  176889. {
  176890. if (png_ptr->zstream.msg != NULL)
  176891. png_error(png_ptr, png_ptr->zstream.msg);
  176892. else
  176893. png_error(png_ptr, "zlib error");
  176894. }
  176895. if (!(png_ptr->zstream.avail_out))
  176896. {
  176897. if (comp->num_output_ptr >= comp->max_output_ptr)
  176898. {
  176899. int old_max;
  176900. old_max = comp->max_output_ptr;
  176901. comp->max_output_ptr = comp->num_output_ptr + 4;
  176902. if (comp->output_ptr != NULL)
  176903. {
  176904. png_charpp old_ptr;
  176905. old_ptr = comp->output_ptr;
  176906. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176907. (png_uint_32)(comp->max_output_ptr *
  176908. png_sizeof (png_charpp)));
  176909. png_memcpy(comp->output_ptr, old_ptr, old_max
  176910. * png_sizeof (png_charp));
  176911. png_free(png_ptr, old_ptr);
  176912. }
  176913. else
  176914. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176915. (png_uint_32)(comp->max_output_ptr *
  176916. png_sizeof (png_charp)));
  176917. }
  176918. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  176919. (png_uint_32)png_ptr->zbuf_size);
  176920. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176921. png_ptr->zbuf_size);
  176922. comp->num_output_ptr++;
  176923. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176924. png_ptr->zstream.next_out = png_ptr->zbuf;
  176925. }
  176926. } while (png_ptr->zstream.avail_in);
  176927. do
  176928. {
  176929. ret = deflate(&png_ptr->zstream, Z_FINISH);
  176930. if (ret == Z_OK)
  176931. {
  176932. if (!(png_ptr->zstream.avail_out))
  176933. {
  176934. if (comp->num_output_ptr >= comp->max_output_ptr)
  176935. {
  176936. int old_max;
  176937. old_max = comp->max_output_ptr;
  176938. comp->max_output_ptr = comp->num_output_ptr + 4;
  176939. if (comp->output_ptr != NULL)
  176940. {
  176941. png_charpp old_ptr;
  176942. old_ptr = comp->output_ptr;
  176943. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176944. (png_uint_32)(comp->max_output_ptr *
  176945. png_sizeof (png_charpp)));
  176946. png_memcpy(comp->output_ptr, old_ptr,
  176947. old_max * png_sizeof (png_charp));
  176948. png_free(png_ptr, old_ptr);
  176949. }
  176950. else
  176951. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176952. (png_uint_32)(comp->max_output_ptr *
  176953. png_sizeof (png_charp)));
  176954. }
  176955. comp->output_ptr[comp->num_output_ptr] =
  176956. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  176957. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176958. png_ptr->zbuf_size);
  176959. comp->num_output_ptr++;
  176960. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176961. png_ptr->zstream.next_out = png_ptr->zbuf;
  176962. }
  176963. }
  176964. else if (ret != Z_STREAM_END)
  176965. {
  176966. if (png_ptr->zstream.msg != NULL)
  176967. png_error(png_ptr, png_ptr->zstream.msg);
  176968. else
  176969. png_error(png_ptr, "zlib error");
  176970. }
  176971. } while (ret != Z_STREAM_END);
  176972. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  176973. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  176974. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  176975. return((int)text_len);
  176976. }
  176977. static void /* PRIVATE */
  176978. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  176979. {
  176980. int i;
  176981. if (comp->input)
  176982. {
  176983. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  176984. (png_size_t)comp->input_len);
  176985. return;
  176986. }
  176987. for (i = 0; i < comp->num_output_ptr; i++)
  176988. {
  176989. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  176990. png_ptr->zbuf_size);
  176991. png_free(png_ptr, comp->output_ptr[i]);
  176992. comp->output_ptr[i]=NULL;
  176993. }
  176994. if (comp->max_output_ptr != 0)
  176995. png_free(png_ptr, comp->output_ptr);
  176996. comp->output_ptr=NULL;
  176997. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  176998. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  176999. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177000. deflateReset(&png_ptr->zstream);
  177001. png_ptr->zstream.data_type = Z_BINARY;
  177002. }
  177003. #endif
  177004. void /* PRIVATE */
  177005. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177006. int bit_depth, int color_type, int compression_type, int filter_type,
  177007. int interlace_type)
  177008. {
  177009. #ifdef PNG_USE_LOCAL_ARRAYS
  177010. PNG_IHDR;
  177011. #endif
  177012. png_byte buf[13]; /* buffer to store the IHDR info */
  177013. png_debug(1, "in png_write_IHDR\n");
  177014. switch (color_type)
  177015. {
  177016. case PNG_COLOR_TYPE_GRAY:
  177017. switch (bit_depth)
  177018. {
  177019. case 1:
  177020. case 2:
  177021. case 4:
  177022. case 8:
  177023. case 16: png_ptr->channels = 1; break;
  177024. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177025. }
  177026. break;
  177027. case PNG_COLOR_TYPE_RGB:
  177028. if (bit_depth != 8 && bit_depth != 16)
  177029. png_error(png_ptr, "Invalid bit depth for RGB image");
  177030. png_ptr->channels = 3;
  177031. break;
  177032. case PNG_COLOR_TYPE_PALETTE:
  177033. switch (bit_depth)
  177034. {
  177035. case 1:
  177036. case 2:
  177037. case 4:
  177038. case 8: png_ptr->channels = 1; break;
  177039. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177040. }
  177041. break;
  177042. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177043. if (bit_depth != 8 && bit_depth != 16)
  177044. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177045. png_ptr->channels = 2;
  177046. break;
  177047. case PNG_COLOR_TYPE_RGB_ALPHA:
  177048. if (bit_depth != 8 && bit_depth != 16)
  177049. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177050. png_ptr->channels = 4;
  177051. break;
  177052. default:
  177053. png_error(png_ptr, "Invalid image color type specified");
  177054. }
  177055. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177056. {
  177057. png_warning(png_ptr, "Invalid compression type specified");
  177058. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177059. }
  177060. if (
  177061. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177062. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177063. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177064. (color_type == PNG_COLOR_TYPE_RGB ||
  177065. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177066. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177067. #endif
  177068. filter_type != PNG_FILTER_TYPE_BASE)
  177069. {
  177070. png_warning(png_ptr, "Invalid filter type specified");
  177071. filter_type = PNG_FILTER_TYPE_BASE;
  177072. }
  177073. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177074. if (interlace_type != PNG_INTERLACE_NONE &&
  177075. interlace_type != PNG_INTERLACE_ADAM7)
  177076. {
  177077. png_warning(png_ptr, "Invalid interlace type specified");
  177078. interlace_type = PNG_INTERLACE_ADAM7;
  177079. }
  177080. #else
  177081. interlace_type=PNG_INTERLACE_NONE;
  177082. #endif
  177083. png_ptr->bit_depth = (png_byte)bit_depth;
  177084. png_ptr->color_type = (png_byte)color_type;
  177085. png_ptr->interlaced = (png_byte)interlace_type;
  177086. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177087. png_ptr->filter_type = (png_byte)filter_type;
  177088. #endif
  177089. png_ptr->compression_type = (png_byte)compression_type;
  177090. png_ptr->width = width;
  177091. png_ptr->height = height;
  177092. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177093. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177094. png_ptr->usr_width = png_ptr->width;
  177095. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177096. png_ptr->usr_channels = png_ptr->channels;
  177097. png_save_uint_32(buf, width);
  177098. png_save_uint_32(buf + 4, height);
  177099. buf[8] = (png_byte)bit_depth;
  177100. buf[9] = (png_byte)color_type;
  177101. buf[10] = (png_byte)compression_type;
  177102. buf[11] = (png_byte)filter_type;
  177103. buf[12] = (png_byte)interlace_type;
  177104. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177105. png_ptr->zstream.zalloc = png_zalloc;
  177106. png_ptr->zstream.zfree = png_zfree;
  177107. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177108. if (!(png_ptr->do_filter))
  177109. {
  177110. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177111. png_ptr->bit_depth < 8)
  177112. png_ptr->do_filter = PNG_FILTER_NONE;
  177113. else
  177114. png_ptr->do_filter = PNG_ALL_FILTERS;
  177115. }
  177116. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177117. {
  177118. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177119. png_ptr->zlib_strategy = Z_FILTERED;
  177120. else
  177121. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177122. }
  177123. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177124. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177125. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177126. png_ptr->zlib_mem_level = 8;
  177127. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177128. png_ptr->zlib_window_bits = 15;
  177129. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177130. png_ptr->zlib_method = 8;
  177131. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177132. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177133. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177134. png_error(png_ptr, "zlib failed to initialize compressor");
  177135. png_ptr->zstream.next_out = png_ptr->zbuf;
  177136. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177137. png_ptr->zstream.data_type = Z_BINARY;
  177138. png_ptr->mode = PNG_HAVE_IHDR;
  177139. }
  177140. void /* PRIVATE */
  177141. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177142. {
  177143. #ifdef PNG_USE_LOCAL_ARRAYS
  177144. PNG_PLTE;
  177145. #endif
  177146. png_uint_32 i;
  177147. png_colorp pal_ptr;
  177148. png_byte buf[3];
  177149. png_debug(1, "in png_write_PLTE\n");
  177150. if ((
  177151. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177152. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177153. #endif
  177154. num_pal == 0) || num_pal > 256)
  177155. {
  177156. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177157. {
  177158. png_error(png_ptr, "Invalid number of colors in palette");
  177159. }
  177160. else
  177161. {
  177162. png_warning(png_ptr, "Invalid number of colors in palette");
  177163. return;
  177164. }
  177165. }
  177166. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177167. {
  177168. png_warning(png_ptr,
  177169. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177170. return;
  177171. }
  177172. png_ptr->num_palette = (png_uint_16)num_pal;
  177173. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177174. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177175. #ifndef PNG_NO_POINTER_INDEXING
  177176. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177177. {
  177178. buf[0] = pal_ptr->red;
  177179. buf[1] = pal_ptr->green;
  177180. buf[2] = pal_ptr->blue;
  177181. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177182. }
  177183. #else
  177184. pal_ptr=palette;
  177185. for (i = 0; i < num_pal; i++)
  177186. {
  177187. buf[0] = pal_ptr[i].red;
  177188. buf[1] = pal_ptr[i].green;
  177189. buf[2] = pal_ptr[i].blue;
  177190. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177191. }
  177192. #endif
  177193. png_write_chunk_end(png_ptr);
  177194. png_ptr->mode |= PNG_HAVE_PLTE;
  177195. }
  177196. void /* PRIVATE */
  177197. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177198. {
  177199. #ifdef PNG_USE_LOCAL_ARRAYS
  177200. PNG_IDAT;
  177201. #endif
  177202. png_debug(1, "in png_write_IDAT\n");
  177203. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177204. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177205. {
  177206. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177207. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177208. {
  177209. if (length >= 2 &&
  177210. png_ptr->height < 16384 && png_ptr->width < 16384)
  177211. {
  177212. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177213. ((png_ptr->width *
  177214. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177215. unsigned int z_cinfo = z_cmf >> 4;
  177216. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177217. while (uncompressed_idat_size <= half_z_window_size &&
  177218. half_z_window_size >= 256)
  177219. {
  177220. z_cinfo--;
  177221. half_z_window_size >>= 1;
  177222. }
  177223. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177224. if (data[0] != (png_byte)z_cmf)
  177225. {
  177226. data[0] = (png_byte)z_cmf;
  177227. data[1] &= 0xe0;
  177228. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177229. }
  177230. }
  177231. }
  177232. else
  177233. png_error(png_ptr,
  177234. "Invalid zlib compression method or flags in IDAT");
  177235. }
  177236. png_write_chunk(png_ptr, png_IDAT, data, length);
  177237. png_ptr->mode |= PNG_HAVE_IDAT;
  177238. }
  177239. void /* PRIVATE */
  177240. png_write_IEND(png_structp png_ptr)
  177241. {
  177242. #ifdef PNG_USE_LOCAL_ARRAYS
  177243. PNG_IEND;
  177244. #endif
  177245. png_debug(1, "in png_write_IEND\n");
  177246. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177247. (png_size_t)0);
  177248. png_ptr->mode |= PNG_HAVE_IEND;
  177249. }
  177250. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177251. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177252. void /* PRIVATE */
  177253. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177254. {
  177255. #ifdef PNG_USE_LOCAL_ARRAYS
  177256. PNG_gAMA;
  177257. #endif
  177258. png_uint_32 igamma;
  177259. png_byte buf[4];
  177260. png_debug(1, "in png_write_gAMA\n");
  177261. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177262. png_save_uint_32(buf, igamma);
  177263. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177264. }
  177265. #endif
  177266. #ifdef PNG_FIXED_POINT_SUPPORTED
  177267. void /* PRIVATE */
  177268. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177269. {
  177270. #ifdef PNG_USE_LOCAL_ARRAYS
  177271. PNG_gAMA;
  177272. #endif
  177273. png_byte buf[4];
  177274. png_debug(1, "in png_write_gAMA\n");
  177275. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177276. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177277. }
  177278. #endif
  177279. #endif
  177280. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177281. void /* PRIVATE */
  177282. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177283. {
  177284. #ifdef PNG_USE_LOCAL_ARRAYS
  177285. PNG_sRGB;
  177286. #endif
  177287. png_byte buf[1];
  177288. png_debug(1, "in png_write_sRGB\n");
  177289. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177290. png_warning(png_ptr,
  177291. "Invalid sRGB rendering intent specified");
  177292. buf[0]=(png_byte)srgb_intent;
  177293. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177294. }
  177295. #endif
  177296. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177297. void /* PRIVATE */
  177298. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177299. png_charp profile, int profile_len)
  177300. {
  177301. #ifdef PNG_USE_LOCAL_ARRAYS
  177302. PNG_iCCP;
  177303. #endif
  177304. png_size_t name_len;
  177305. png_charp new_name;
  177306. compression_state comp;
  177307. int embedded_profile_len = 0;
  177308. png_debug(1, "in png_write_iCCP\n");
  177309. comp.num_output_ptr = 0;
  177310. comp.max_output_ptr = 0;
  177311. comp.output_ptr = NULL;
  177312. comp.input = NULL;
  177313. comp.input_len = 0;
  177314. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177315. &new_name)) == 0)
  177316. {
  177317. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177318. return;
  177319. }
  177320. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177321. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177322. if (profile == NULL)
  177323. profile_len = 0;
  177324. if (profile_len > 3)
  177325. embedded_profile_len =
  177326. ((*( (png_bytep)profile ))<<24) |
  177327. ((*( (png_bytep)profile+1))<<16) |
  177328. ((*( (png_bytep)profile+2))<< 8) |
  177329. ((*( (png_bytep)profile+3)) );
  177330. if (profile_len < embedded_profile_len)
  177331. {
  177332. png_warning(png_ptr,
  177333. "Embedded profile length too large in iCCP chunk");
  177334. return;
  177335. }
  177336. if (profile_len > embedded_profile_len)
  177337. {
  177338. png_warning(png_ptr,
  177339. "Truncating profile to actual length in iCCP chunk");
  177340. profile_len = embedded_profile_len;
  177341. }
  177342. if (profile_len)
  177343. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177344. PNG_COMPRESSION_TYPE_BASE, &comp);
  177345. png_write_chunk_start(png_ptr, png_iCCP,
  177346. (png_uint_32)name_len+profile_len+2);
  177347. new_name[name_len+1]=0x00;
  177348. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177349. if (profile_len)
  177350. png_write_compressed_data_out(png_ptr, &comp);
  177351. png_write_chunk_end(png_ptr);
  177352. png_free(png_ptr, new_name);
  177353. }
  177354. #endif
  177355. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177356. void /* PRIVATE */
  177357. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177358. {
  177359. #ifdef PNG_USE_LOCAL_ARRAYS
  177360. PNG_sPLT;
  177361. #endif
  177362. png_size_t name_len;
  177363. png_charp new_name;
  177364. png_byte entrybuf[10];
  177365. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177366. int palette_size = entry_size * spalette->nentries;
  177367. png_sPLT_entryp ep;
  177368. #ifdef PNG_NO_POINTER_INDEXING
  177369. int i;
  177370. #endif
  177371. png_debug(1, "in png_write_sPLT\n");
  177372. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177373. spalette->name, &new_name))==0)
  177374. {
  177375. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177376. return;
  177377. }
  177378. png_write_chunk_start(png_ptr, png_sPLT,
  177379. (png_uint_32)(name_len + 2 + palette_size));
  177380. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177381. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177382. #ifndef PNG_NO_POINTER_INDEXING
  177383. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177384. {
  177385. if (spalette->depth == 8)
  177386. {
  177387. entrybuf[0] = (png_byte)ep->red;
  177388. entrybuf[1] = (png_byte)ep->green;
  177389. entrybuf[2] = (png_byte)ep->blue;
  177390. entrybuf[3] = (png_byte)ep->alpha;
  177391. png_save_uint_16(entrybuf + 4, ep->frequency);
  177392. }
  177393. else
  177394. {
  177395. png_save_uint_16(entrybuf + 0, ep->red);
  177396. png_save_uint_16(entrybuf + 2, ep->green);
  177397. png_save_uint_16(entrybuf + 4, ep->blue);
  177398. png_save_uint_16(entrybuf + 6, ep->alpha);
  177399. png_save_uint_16(entrybuf + 8, ep->frequency);
  177400. }
  177401. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177402. }
  177403. #else
  177404. ep=spalette->entries;
  177405. for (i=0; i>spalette->nentries; i++)
  177406. {
  177407. if (spalette->depth == 8)
  177408. {
  177409. entrybuf[0] = (png_byte)ep[i].red;
  177410. entrybuf[1] = (png_byte)ep[i].green;
  177411. entrybuf[2] = (png_byte)ep[i].blue;
  177412. entrybuf[3] = (png_byte)ep[i].alpha;
  177413. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177414. }
  177415. else
  177416. {
  177417. png_save_uint_16(entrybuf + 0, ep[i].red);
  177418. png_save_uint_16(entrybuf + 2, ep[i].green);
  177419. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177420. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177421. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177422. }
  177423. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177424. }
  177425. #endif
  177426. png_write_chunk_end(png_ptr);
  177427. png_free(png_ptr, new_name);
  177428. }
  177429. #endif
  177430. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177431. void /* PRIVATE */
  177432. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177433. {
  177434. #ifdef PNG_USE_LOCAL_ARRAYS
  177435. PNG_sBIT;
  177436. #endif
  177437. png_byte buf[4];
  177438. png_size_t size;
  177439. png_debug(1, "in png_write_sBIT\n");
  177440. if (color_type & PNG_COLOR_MASK_COLOR)
  177441. {
  177442. png_byte maxbits;
  177443. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177444. png_ptr->usr_bit_depth);
  177445. if (sbit->red == 0 || sbit->red > maxbits ||
  177446. sbit->green == 0 || sbit->green > maxbits ||
  177447. sbit->blue == 0 || sbit->blue > maxbits)
  177448. {
  177449. png_warning(png_ptr, "Invalid sBIT depth specified");
  177450. return;
  177451. }
  177452. buf[0] = sbit->red;
  177453. buf[1] = sbit->green;
  177454. buf[2] = sbit->blue;
  177455. size = 3;
  177456. }
  177457. else
  177458. {
  177459. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177460. {
  177461. png_warning(png_ptr, "Invalid sBIT depth specified");
  177462. return;
  177463. }
  177464. buf[0] = sbit->gray;
  177465. size = 1;
  177466. }
  177467. if (color_type & PNG_COLOR_MASK_ALPHA)
  177468. {
  177469. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177470. {
  177471. png_warning(png_ptr, "Invalid sBIT depth specified");
  177472. return;
  177473. }
  177474. buf[size++] = sbit->alpha;
  177475. }
  177476. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177477. }
  177478. #endif
  177479. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177480. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177481. void /* PRIVATE */
  177482. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177483. double red_x, double red_y, double green_x, double green_y,
  177484. double blue_x, double blue_y)
  177485. {
  177486. #ifdef PNG_USE_LOCAL_ARRAYS
  177487. PNG_cHRM;
  177488. #endif
  177489. png_byte buf[32];
  177490. png_uint_32 itemp;
  177491. png_debug(1, "in png_write_cHRM\n");
  177492. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177493. white_x + white_y > 1.0)
  177494. {
  177495. png_warning(png_ptr, "Invalid cHRM white point specified");
  177496. #if !defined(PNG_NO_CONSOLE_IO)
  177497. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177498. #endif
  177499. return;
  177500. }
  177501. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177502. png_save_uint_32(buf, itemp);
  177503. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177504. png_save_uint_32(buf + 4, itemp);
  177505. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177506. {
  177507. png_warning(png_ptr, "Invalid cHRM red point specified");
  177508. return;
  177509. }
  177510. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177511. png_save_uint_32(buf + 8, itemp);
  177512. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177513. png_save_uint_32(buf + 12, itemp);
  177514. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177515. {
  177516. png_warning(png_ptr, "Invalid cHRM green point specified");
  177517. return;
  177518. }
  177519. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177520. png_save_uint_32(buf + 16, itemp);
  177521. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177522. png_save_uint_32(buf + 20, itemp);
  177523. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177524. {
  177525. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177526. return;
  177527. }
  177528. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177529. png_save_uint_32(buf + 24, itemp);
  177530. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177531. png_save_uint_32(buf + 28, itemp);
  177532. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177533. }
  177534. #endif
  177535. #ifdef PNG_FIXED_POINT_SUPPORTED
  177536. void /* PRIVATE */
  177537. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177538. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177539. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177540. png_fixed_point blue_y)
  177541. {
  177542. #ifdef PNG_USE_LOCAL_ARRAYS
  177543. PNG_cHRM;
  177544. #endif
  177545. png_byte buf[32];
  177546. png_debug(1, "in png_write_cHRM\n");
  177547. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177548. {
  177549. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177550. #if !defined(PNG_NO_CONSOLE_IO)
  177551. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177552. #endif
  177553. return;
  177554. }
  177555. png_save_uint_32(buf, (png_uint_32)white_x);
  177556. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177557. if (red_x + red_y > 100000L)
  177558. {
  177559. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177560. return;
  177561. }
  177562. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177563. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177564. if (green_x + green_y > 100000L)
  177565. {
  177566. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177567. return;
  177568. }
  177569. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177570. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177571. if (blue_x + blue_y > 100000L)
  177572. {
  177573. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177574. return;
  177575. }
  177576. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177577. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177578. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177579. }
  177580. #endif
  177581. #endif
  177582. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177583. void /* PRIVATE */
  177584. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177585. int num_trans, int color_type)
  177586. {
  177587. #ifdef PNG_USE_LOCAL_ARRAYS
  177588. PNG_tRNS;
  177589. #endif
  177590. png_byte buf[6];
  177591. png_debug(1, "in png_write_tRNS\n");
  177592. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177593. {
  177594. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177595. {
  177596. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177597. return;
  177598. }
  177599. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177600. }
  177601. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177602. {
  177603. if(tran->gray >= (1 << png_ptr->bit_depth))
  177604. {
  177605. png_warning(png_ptr,
  177606. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177607. return;
  177608. }
  177609. png_save_uint_16(buf, tran->gray);
  177610. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177611. }
  177612. else if (color_type == PNG_COLOR_TYPE_RGB)
  177613. {
  177614. png_save_uint_16(buf, tran->red);
  177615. png_save_uint_16(buf + 2, tran->green);
  177616. png_save_uint_16(buf + 4, tran->blue);
  177617. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177618. {
  177619. png_warning(png_ptr,
  177620. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177621. return;
  177622. }
  177623. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177624. }
  177625. else
  177626. {
  177627. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177628. }
  177629. }
  177630. #endif
  177631. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177632. void /* PRIVATE */
  177633. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177634. {
  177635. #ifdef PNG_USE_LOCAL_ARRAYS
  177636. PNG_bKGD;
  177637. #endif
  177638. png_byte buf[6];
  177639. png_debug(1, "in png_write_bKGD\n");
  177640. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177641. {
  177642. if (
  177643. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177644. (png_ptr->num_palette ||
  177645. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177646. #endif
  177647. back->index > png_ptr->num_palette)
  177648. {
  177649. png_warning(png_ptr, "Invalid background palette index");
  177650. return;
  177651. }
  177652. buf[0] = back->index;
  177653. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177654. }
  177655. else if (color_type & PNG_COLOR_MASK_COLOR)
  177656. {
  177657. png_save_uint_16(buf, back->red);
  177658. png_save_uint_16(buf + 2, back->green);
  177659. png_save_uint_16(buf + 4, back->blue);
  177660. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177661. {
  177662. png_warning(png_ptr,
  177663. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177664. return;
  177665. }
  177666. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177667. }
  177668. else
  177669. {
  177670. if(back->gray >= (1 << png_ptr->bit_depth))
  177671. {
  177672. png_warning(png_ptr,
  177673. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177674. return;
  177675. }
  177676. png_save_uint_16(buf, back->gray);
  177677. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177678. }
  177679. }
  177680. #endif
  177681. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177682. void /* PRIVATE */
  177683. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177684. {
  177685. #ifdef PNG_USE_LOCAL_ARRAYS
  177686. PNG_hIST;
  177687. #endif
  177688. int i;
  177689. png_byte buf[3];
  177690. png_debug(1, "in png_write_hIST\n");
  177691. if (num_hist > (int)png_ptr->num_palette)
  177692. {
  177693. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177694. png_ptr->num_palette);
  177695. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177696. return;
  177697. }
  177698. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177699. for (i = 0; i < num_hist; i++)
  177700. {
  177701. png_save_uint_16(buf, hist[i]);
  177702. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177703. }
  177704. png_write_chunk_end(png_ptr);
  177705. }
  177706. #endif
  177707. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177708. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177709. png_size_t /* PRIVATE */
  177710. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177711. {
  177712. png_size_t key_len;
  177713. png_charp kp, dp;
  177714. int kflag;
  177715. int kwarn=0;
  177716. png_debug(1, "in png_check_keyword\n");
  177717. *new_key = NULL;
  177718. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177719. {
  177720. png_warning(png_ptr, "zero length keyword");
  177721. return ((png_size_t)0);
  177722. }
  177723. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177724. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177725. if (*new_key == NULL)
  177726. {
  177727. png_warning(png_ptr, "Out of memory while procesing keyword");
  177728. return ((png_size_t)0);
  177729. }
  177730. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177731. {
  177732. if ((png_byte)*kp < 0x20 ||
  177733. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177734. {
  177735. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177736. char msg[40];
  177737. png_snprintf(msg, 40,
  177738. "invalid keyword character 0x%02X", (png_byte)*kp);
  177739. png_warning(png_ptr, msg);
  177740. #else
  177741. png_warning(png_ptr, "invalid character in keyword");
  177742. #endif
  177743. *dp = ' ';
  177744. }
  177745. else
  177746. {
  177747. *dp = *kp;
  177748. }
  177749. }
  177750. *dp = '\0';
  177751. kp = *new_key + key_len - 1;
  177752. if (*kp == ' ')
  177753. {
  177754. png_warning(png_ptr, "trailing spaces removed from keyword");
  177755. while (*kp == ' ')
  177756. {
  177757. *(kp--) = '\0';
  177758. key_len--;
  177759. }
  177760. }
  177761. kp = *new_key;
  177762. if (*kp == ' ')
  177763. {
  177764. png_warning(png_ptr, "leading spaces removed from keyword");
  177765. while (*kp == ' ')
  177766. {
  177767. kp++;
  177768. key_len--;
  177769. }
  177770. }
  177771. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177772. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177773. {
  177774. if (*kp == ' ' && kflag == 0)
  177775. {
  177776. *(dp++) = *kp;
  177777. kflag = 1;
  177778. }
  177779. else if (*kp == ' ')
  177780. {
  177781. key_len--;
  177782. kwarn=1;
  177783. }
  177784. else
  177785. {
  177786. *(dp++) = *kp;
  177787. kflag = 0;
  177788. }
  177789. }
  177790. *dp = '\0';
  177791. if(kwarn)
  177792. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177793. if (key_len == 0)
  177794. {
  177795. png_free(png_ptr, *new_key);
  177796. *new_key=NULL;
  177797. png_warning(png_ptr, "Zero length keyword");
  177798. }
  177799. if (key_len > 79)
  177800. {
  177801. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177802. new_key[79] = '\0';
  177803. key_len = 79;
  177804. }
  177805. return (key_len);
  177806. }
  177807. #endif
  177808. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177809. void /* PRIVATE */
  177810. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177811. png_size_t text_len)
  177812. {
  177813. #ifdef PNG_USE_LOCAL_ARRAYS
  177814. PNG_tEXt;
  177815. #endif
  177816. png_size_t key_len;
  177817. png_charp new_key;
  177818. png_debug(1, "in png_write_tEXt\n");
  177819. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177820. {
  177821. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177822. return;
  177823. }
  177824. if (text == NULL || *text == '\0')
  177825. text_len = 0;
  177826. else
  177827. text_len = png_strlen(text);
  177828. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177829. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177830. if (text_len)
  177831. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177832. png_write_chunk_end(png_ptr);
  177833. png_free(png_ptr, new_key);
  177834. }
  177835. #endif
  177836. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177837. void /* PRIVATE */
  177838. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177839. png_size_t text_len, int compression)
  177840. {
  177841. #ifdef PNG_USE_LOCAL_ARRAYS
  177842. PNG_zTXt;
  177843. #endif
  177844. png_size_t key_len;
  177845. char buf[1];
  177846. png_charp new_key;
  177847. compression_state comp;
  177848. png_debug(1, "in png_write_zTXt\n");
  177849. comp.num_output_ptr = 0;
  177850. comp.max_output_ptr = 0;
  177851. comp.output_ptr = NULL;
  177852. comp.input = NULL;
  177853. comp.input_len = 0;
  177854. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177855. {
  177856. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177857. return;
  177858. }
  177859. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177860. {
  177861. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177862. png_free(png_ptr, new_key);
  177863. return;
  177864. }
  177865. text_len = png_strlen(text);
  177866. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177867. &comp);
  177868. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177869. (key_len+text_len+2));
  177870. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177871. png_free(png_ptr, new_key);
  177872. buf[0] = (png_byte)compression;
  177873. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177874. png_write_compressed_data_out(png_ptr, &comp);
  177875. png_write_chunk_end(png_ptr);
  177876. }
  177877. #endif
  177878. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177879. void /* PRIVATE */
  177880. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177881. png_charp lang, png_charp lang_key, png_charp text)
  177882. {
  177883. #ifdef PNG_USE_LOCAL_ARRAYS
  177884. PNG_iTXt;
  177885. #endif
  177886. png_size_t lang_len, key_len, lang_key_len, text_len;
  177887. png_charp new_lang, new_key;
  177888. png_byte cbuf[2];
  177889. compression_state comp;
  177890. png_debug(1, "in png_write_iTXt\n");
  177891. comp.num_output_ptr = 0;
  177892. comp.max_output_ptr = 0;
  177893. comp.output_ptr = NULL;
  177894. comp.input = NULL;
  177895. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177896. {
  177897. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177898. return;
  177899. }
  177900. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177901. {
  177902. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177903. new_lang = NULL;
  177904. lang_len = 0;
  177905. }
  177906. if (lang_key == NULL)
  177907. lang_key_len = 0;
  177908. else
  177909. lang_key_len = png_strlen(lang_key);
  177910. if (text == NULL)
  177911. text_len = 0;
  177912. else
  177913. text_len = png_strlen(text);
  177914. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177915. &comp);
  177916. png_write_chunk_start(png_ptr, png_iTXt,
  177917. (png_uint_32)(
  177918. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  177919. + key_len
  177920. + lang_len
  177921. + lang_key_len
  177922. + text_len));
  177923. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177924. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  177925. compression == PNG_TEXT_COMPRESSION_NONE)
  177926. cbuf[0] = 0;
  177927. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  177928. cbuf[0] = 1;
  177929. cbuf[1] = 0;
  177930. png_write_chunk_data(png_ptr, cbuf, 2);
  177931. cbuf[0] = 0;
  177932. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  177933. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  177934. png_write_compressed_data_out(png_ptr, &comp);
  177935. png_write_chunk_end(png_ptr);
  177936. png_free(png_ptr, new_key);
  177937. if (new_lang)
  177938. png_free(png_ptr, new_lang);
  177939. }
  177940. #endif
  177941. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  177942. void /* PRIVATE */
  177943. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  177944. int unit_type)
  177945. {
  177946. #ifdef PNG_USE_LOCAL_ARRAYS
  177947. PNG_oFFs;
  177948. #endif
  177949. png_byte buf[9];
  177950. png_debug(1, "in png_write_oFFs\n");
  177951. if (unit_type >= PNG_OFFSET_LAST)
  177952. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  177953. png_save_int_32(buf, x_offset);
  177954. png_save_int_32(buf + 4, y_offset);
  177955. buf[8] = (png_byte)unit_type;
  177956. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  177957. }
  177958. #endif
  177959. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  177960. void /* PRIVATE */
  177961. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  177962. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  177963. {
  177964. #ifdef PNG_USE_LOCAL_ARRAYS
  177965. PNG_pCAL;
  177966. #endif
  177967. png_size_t purpose_len, units_len, total_len;
  177968. png_uint_32p params_len;
  177969. png_byte buf[10];
  177970. png_charp new_purpose;
  177971. int i;
  177972. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  177973. if (type >= PNG_EQUATION_LAST)
  177974. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  177975. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  177976. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  177977. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  177978. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  177979. total_len = purpose_len + units_len + 10;
  177980. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  177981. *png_sizeof(png_uint_32)));
  177982. for (i = 0; i < nparams; i++)
  177983. {
  177984. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  177985. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  177986. total_len += (png_size_t)params_len[i];
  177987. }
  177988. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  177989. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  177990. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  177991. png_save_int_32(buf, X0);
  177992. png_save_int_32(buf + 4, X1);
  177993. buf[8] = (png_byte)type;
  177994. buf[9] = (png_byte)nparams;
  177995. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  177996. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  177997. png_free(png_ptr, new_purpose);
  177998. for (i = 0; i < nparams; i++)
  177999. {
  178000. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178001. (png_size_t)params_len[i]);
  178002. }
  178003. png_free(png_ptr, params_len);
  178004. png_write_chunk_end(png_ptr);
  178005. }
  178006. #endif
  178007. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178008. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178009. void /* PRIVATE */
  178010. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178011. {
  178012. #ifdef PNG_USE_LOCAL_ARRAYS
  178013. PNG_sCAL;
  178014. #endif
  178015. char buf[64];
  178016. png_size_t total_len;
  178017. png_debug(1, "in png_write_sCAL\n");
  178018. buf[0] = (char)unit;
  178019. #if defined(_WIN32_WCE)
  178020. {
  178021. wchar_t wc_buf[32];
  178022. size_t wc_len;
  178023. swprintf(wc_buf, TEXT("%12.12e"), width);
  178024. wc_len = wcslen(wc_buf);
  178025. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178026. total_len = wc_len + 2;
  178027. swprintf(wc_buf, TEXT("%12.12e"), height);
  178028. wc_len = wcslen(wc_buf);
  178029. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178030. NULL, NULL);
  178031. total_len += wc_len;
  178032. }
  178033. #else
  178034. png_snprintf(buf + 1, 63, "%12.12e", width);
  178035. total_len = 1 + png_strlen(buf + 1) + 1;
  178036. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178037. total_len += png_strlen(buf + total_len);
  178038. #endif
  178039. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178040. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178041. }
  178042. #else
  178043. #ifdef PNG_FIXED_POINT_SUPPORTED
  178044. void /* PRIVATE */
  178045. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178046. png_charp height)
  178047. {
  178048. #ifdef PNG_USE_LOCAL_ARRAYS
  178049. PNG_sCAL;
  178050. #endif
  178051. png_byte buf[64];
  178052. png_size_t wlen, hlen, total_len;
  178053. png_debug(1, "in png_write_sCAL_s\n");
  178054. wlen = png_strlen(width);
  178055. hlen = png_strlen(height);
  178056. total_len = wlen + hlen + 2;
  178057. if (total_len > 64)
  178058. {
  178059. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178060. return;
  178061. }
  178062. buf[0] = (png_byte)unit;
  178063. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178064. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178065. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178066. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178067. }
  178068. #endif
  178069. #endif
  178070. #endif
  178071. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178072. void /* PRIVATE */
  178073. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178074. png_uint_32 y_pixels_per_unit,
  178075. int unit_type)
  178076. {
  178077. #ifdef PNG_USE_LOCAL_ARRAYS
  178078. PNG_pHYs;
  178079. #endif
  178080. png_byte buf[9];
  178081. png_debug(1, "in png_write_pHYs\n");
  178082. if (unit_type >= PNG_RESOLUTION_LAST)
  178083. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178084. png_save_uint_32(buf, x_pixels_per_unit);
  178085. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178086. buf[8] = (png_byte)unit_type;
  178087. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178088. }
  178089. #endif
  178090. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178091. void /* PRIVATE */
  178092. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178093. {
  178094. #ifdef PNG_USE_LOCAL_ARRAYS
  178095. PNG_tIME;
  178096. #endif
  178097. png_byte buf[7];
  178098. png_debug(1, "in png_write_tIME\n");
  178099. if (mod_time->month > 12 || mod_time->month < 1 ||
  178100. mod_time->day > 31 || mod_time->day < 1 ||
  178101. mod_time->hour > 23 || mod_time->second > 60)
  178102. {
  178103. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178104. return;
  178105. }
  178106. png_save_uint_16(buf, mod_time->year);
  178107. buf[2] = mod_time->month;
  178108. buf[3] = mod_time->day;
  178109. buf[4] = mod_time->hour;
  178110. buf[5] = mod_time->minute;
  178111. buf[6] = mod_time->second;
  178112. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178113. }
  178114. #endif
  178115. void /* PRIVATE */
  178116. png_write_start_row(png_structp png_ptr)
  178117. {
  178118. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178119. #ifdef PNG_USE_LOCAL_ARRAYS
  178120. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178121. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178122. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178123. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178124. #endif
  178125. #endif
  178126. png_size_t buf_size;
  178127. png_debug(1, "in png_write_start_row\n");
  178128. buf_size = (png_size_t)(PNG_ROWBYTES(
  178129. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178130. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178131. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178132. #ifndef PNG_NO_WRITE_FILTERING
  178133. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178134. {
  178135. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178136. (png_ptr->rowbytes + 1));
  178137. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178138. }
  178139. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178140. {
  178141. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178142. png_memset(png_ptr->prev_row, 0, buf_size);
  178143. if (png_ptr->do_filter & PNG_FILTER_UP)
  178144. {
  178145. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178146. (png_ptr->rowbytes + 1));
  178147. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178148. }
  178149. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178150. {
  178151. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178152. (png_ptr->rowbytes + 1));
  178153. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178154. }
  178155. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178156. {
  178157. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178158. (png_ptr->rowbytes + 1));
  178159. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178160. }
  178161. #endif /* PNG_NO_WRITE_FILTERING */
  178162. }
  178163. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178164. if (png_ptr->interlaced)
  178165. {
  178166. if (!(png_ptr->transformations & PNG_INTERLACE))
  178167. {
  178168. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178169. png_pass_ystart[0]) / png_pass_yinc[0];
  178170. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178171. png_pass_start[0]) / png_pass_inc[0];
  178172. }
  178173. else
  178174. {
  178175. png_ptr->num_rows = png_ptr->height;
  178176. png_ptr->usr_width = png_ptr->width;
  178177. }
  178178. }
  178179. else
  178180. #endif
  178181. {
  178182. png_ptr->num_rows = png_ptr->height;
  178183. png_ptr->usr_width = png_ptr->width;
  178184. }
  178185. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178186. png_ptr->zstream.next_out = png_ptr->zbuf;
  178187. }
  178188. void /* PRIVATE */
  178189. png_write_finish_row(png_structp png_ptr)
  178190. {
  178191. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178192. #ifdef PNG_USE_LOCAL_ARRAYS
  178193. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178194. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178195. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178196. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178197. #endif
  178198. #endif
  178199. int ret;
  178200. png_debug(1, "in png_write_finish_row\n");
  178201. png_ptr->row_number++;
  178202. if (png_ptr->row_number < png_ptr->num_rows)
  178203. return;
  178204. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178205. if (png_ptr->interlaced)
  178206. {
  178207. png_ptr->row_number = 0;
  178208. if (png_ptr->transformations & PNG_INTERLACE)
  178209. {
  178210. png_ptr->pass++;
  178211. }
  178212. else
  178213. {
  178214. do
  178215. {
  178216. png_ptr->pass++;
  178217. if (png_ptr->pass >= 7)
  178218. break;
  178219. png_ptr->usr_width = (png_ptr->width +
  178220. png_pass_inc[png_ptr->pass] - 1 -
  178221. png_pass_start[png_ptr->pass]) /
  178222. png_pass_inc[png_ptr->pass];
  178223. png_ptr->num_rows = (png_ptr->height +
  178224. png_pass_yinc[png_ptr->pass] - 1 -
  178225. png_pass_ystart[png_ptr->pass]) /
  178226. png_pass_yinc[png_ptr->pass];
  178227. if (png_ptr->transformations & PNG_INTERLACE)
  178228. break;
  178229. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178230. }
  178231. if (png_ptr->pass < 7)
  178232. {
  178233. if (png_ptr->prev_row != NULL)
  178234. png_memset(png_ptr->prev_row, 0,
  178235. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178236. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178237. return;
  178238. }
  178239. }
  178240. #endif
  178241. do
  178242. {
  178243. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178244. if (ret == Z_OK)
  178245. {
  178246. if (!(png_ptr->zstream.avail_out))
  178247. {
  178248. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178249. png_ptr->zstream.next_out = png_ptr->zbuf;
  178250. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178251. }
  178252. }
  178253. else if (ret != Z_STREAM_END)
  178254. {
  178255. if (png_ptr->zstream.msg != NULL)
  178256. png_error(png_ptr, png_ptr->zstream.msg);
  178257. else
  178258. png_error(png_ptr, "zlib error");
  178259. }
  178260. } while (ret != Z_STREAM_END);
  178261. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178262. {
  178263. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178264. png_ptr->zstream.avail_out);
  178265. }
  178266. deflateReset(&png_ptr->zstream);
  178267. png_ptr->zstream.data_type = Z_BINARY;
  178268. }
  178269. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178270. void /* PRIVATE */
  178271. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178272. {
  178273. #ifdef PNG_USE_LOCAL_ARRAYS
  178274. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178275. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178276. #endif
  178277. png_debug(1, "in png_do_write_interlace\n");
  178278. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178279. if (row != NULL && row_info != NULL && pass < 6)
  178280. #else
  178281. if (pass < 6)
  178282. #endif
  178283. {
  178284. switch (row_info->pixel_depth)
  178285. {
  178286. case 1:
  178287. {
  178288. png_bytep sp;
  178289. png_bytep dp;
  178290. int shift;
  178291. int d;
  178292. int value;
  178293. png_uint_32 i;
  178294. png_uint_32 row_width = row_info->width;
  178295. dp = row;
  178296. d = 0;
  178297. shift = 7;
  178298. for (i = png_pass_start[pass]; i < row_width;
  178299. i += png_pass_inc[pass])
  178300. {
  178301. sp = row + (png_size_t)(i >> 3);
  178302. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178303. d |= (value << shift);
  178304. if (shift == 0)
  178305. {
  178306. shift = 7;
  178307. *dp++ = (png_byte)d;
  178308. d = 0;
  178309. }
  178310. else
  178311. shift--;
  178312. }
  178313. if (shift != 7)
  178314. *dp = (png_byte)d;
  178315. break;
  178316. }
  178317. case 2:
  178318. {
  178319. png_bytep sp;
  178320. png_bytep dp;
  178321. int shift;
  178322. int d;
  178323. int value;
  178324. png_uint_32 i;
  178325. png_uint_32 row_width = row_info->width;
  178326. dp = row;
  178327. shift = 6;
  178328. d = 0;
  178329. for (i = png_pass_start[pass]; i < row_width;
  178330. i += png_pass_inc[pass])
  178331. {
  178332. sp = row + (png_size_t)(i >> 2);
  178333. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178334. d |= (value << shift);
  178335. if (shift == 0)
  178336. {
  178337. shift = 6;
  178338. *dp++ = (png_byte)d;
  178339. d = 0;
  178340. }
  178341. else
  178342. shift -= 2;
  178343. }
  178344. if (shift != 6)
  178345. *dp = (png_byte)d;
  178346. break;
  178347. }
  178348. case 4:
  178349. {
  178350. png_bytep sp;
  178351. png_bytep dp;
  178352. int shift;
  178353. int d;
  178354. int value;
  178355. png_uint_32 i;
  178356. png_uint_32 row_width = row_info->width;
  178357. dp = row;
  178358. shift = 4;
  178359. d = 0;
  178360. for (i = png_pass_start[pass]; i < row_width;
  178361. i += png_pass_inc[pass])
  178362. {
  178363. sp = row + (png_size_t)(i >> 1);
  178364. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178365. d |= (value << shift);
  178366. if (shift == 0)
  178367. {
  178368. shift = 4;
  178369. *dp++ = (png_byte)d;
  178370. d = 0;
  178371. }
  178372. else
  178373. shift -= 4;
  178374. }
  178375. if (shift != 4)
  178376. *dp = (png_byte)d;
  178377. break;
  178378. }
  178379. default:
  178380. {
  178381. png_bytep sp;
  178382. png_bytep dp;
  178383. png_uint_32 i;
  178384. png_uint_32 row_width = row_info->width;
  178385. png_size_t pixel_bytes;
  178386. dp = row;
  178387. pixel_bytes = (row_info->pixel_depth >> 3);
  178388. for (i = png_pass_start[pass]; i < row_width;
  178389. i += png_pass_inc[pass])
  178390. {
  178391. sp = row + (png_size_t)i * pixel_bytes;
  178392. if (dp != sp)
  178393. png_memcpy(dp, sp, pixel_bytes);
  178394. dp += pixel_bytes;
  178395. }
  178396. break;
  178397. }
  178398. }
  178399. row_info->width = (row_info->width +
  178400. png_pass_inc[pass] - 1 -
  178401. png_pass_start[pass]) /
  178402. png_pass_inc[pass];
  178403. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178404. row_info->width);
  178405. }
  178406. }
  178407. #endif
  178408. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178409. #define PNG_HISHIFT 10
  178410. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178411. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178412. void /* PRIVATE */
  178413. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178414. {
  178415. png_bytep best_row;
  178416. #ifndef PNG_NO_WRITE_FILTER
  178417. png_bytep prev_row, row_buf;
  178418. png_uint_32 mins, bpp;
  178419. png_byte filter_to_do = png_ptr->do_filter;
  178420. png_uint_32 row_bytes = row_info->rowbytes;
  178421. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178422. int num_p_filters = (int)png_ptr->num_prev_filters;
  178423. #endif
  178424. png_debug(1, "in png_write_find_filter\n");
  178425. bpp = (row_info->pixel_depth + 7) >> 3;
  178426. prev_row = png_ptr->prev_row;
  178427. #endif
  178428. best_row = png_ptr->row_buf;
  178429. #ifndef PNG_NO_WRITE_FILTER
  178430. row_buf = best_row;
  178431. mins = PNG_MAXSUM;
  178432. if ((filter_to_do & PNG_FILTER_NONE) &&
  178433. filter_to_do != PNG_FILTER_NONE)
  178434. {
  178435. png_bytep rp;
  178436. png_uint_32 sum = 0;
  178437. png_uint_32 i;
  178438. int v;
  178439. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178440. {
  178441. v = *rp;
  178442. sum += (v < 128) ? v : 256 - v;
  178443. }
  178444. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178445. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178446. {
  178447. png_uint_32 sumhi, sumlo;
  178448. int j;
  178449. sumlo = sum & PNG_LOMASK;
  178450. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178451. for (j = 0; j < num_p_filters; j++)
  178452. {
  178453. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178454. {
  178455. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178456. PNG_WEIGHT_SHIFT;
  178457. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178458. PNG_WEIGHT_SHIFT;
  178459. }
  178460. }
  178461. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178462. PNG_COST_SHIFT;
  178463. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178464. PNG_COST_SHIFT;
  178465. if (sumhi > PNG_HIMASK)
  178466. sum = PNG_MAXSUM;
  178467. else
  178468. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178469. }
  178470. #endif
  178471. mins = sum;
  178472. }
  178473. if (filter_to_do == PNG_FILTER_SUB)
  178474. {
  178475. png_bytep rp, lp, dp;
  178476. png_uint_32 i;
  178477. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178478. i++, rp++, dp++)
  178479. {
  178480. *dp = *rp;
  178481. }
  178482. for (lp = row_buf + 1; i < row_bytes;
  178483. i++, rp++, lp++, dp++)
  178484. {
  178485. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178486. }
  178487. best_row = png_ptr->sub_row;
  178488. }
  178489. else if (filter_to_do & PNG_FILTER_SUB)
  178490. {
  178491. png_bytep rp, dp, lp;
  178492. png_uint_32 sum = 0, lmins = mins;
  178493. png_uint_32 i;
  178494. int v;
  178495. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178496. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178497. {
  178498. int j;
  178499. png_uint_32 lmhi, lmlo;
  178500. lmlo = lmins & PNG_LOMASK;
  178501. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178502. for (j = 0; j < num_p_filters; j++)
  178503. {
  178504. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178505. {
  178506. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178507. PNG_WEIGHT_SHIFT;
  178508. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178509. PNG_WEIGHT_SHIFT;
  178510. }
  178511. }
  178512. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178513. PNG_COST_SHIFT;
  178514. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178515. PNG_COST_SHIFT;
  178516. if (lmhi > PNG_HIMASK)
  178517. lmins = PNG_MAXSUM;
  178518. else
  178519. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178520. }
  178521. #endif
  178522. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178523. i++, rp++, dp++)
  178524. {
  178525. v = *dp = *rp;
  178526. sum += (v < 128) ? v : 256 - v;
  178527. }
  178528. for (lp = row_buf + 1; i < row_bytes;
  178529. i++, rp++, lp++, dp++)
  178530. {
  178531. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178532. sum += (v < 128) ? v : 256 - v;
  178533. if (sum > lmins) /* We are already worse, don't continue. */
  178534. break;
  178535. }
  178536. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178537. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178538. {
  178539. int j;
  178540. png_uint_32 sumhi, sumlo;
  178541. sumlo = sum & PNG_LOMASK;
  178542. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178543. for (j = 0; j < num_p_filters; j++)
  178544. {
  178545. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178546. {
  178547. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178548. PNG_WEIGHT_SHIFT;
  178549. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178550. PNG_WEIGHT_SHIFT;
  178551. }
  178552. }
  178553. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178554. PNG_COST_SHIFT;
  178555. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178556. PNG_COST_SHIFT;
  178557. if (sumhi > PNG_HIMASK)
  178558. sum = PNG_MAXSUM;
  178559. else
  178560. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178561. }
  178562. #endif
  178563. if (sum < mins)
  178564. {
  178565. mins = sum;
  178566. best_row = png_ptr->sub_row;
  178567. }
  178568. }
  178569. if (filter_to_do == PNG_FILTER_UP)
  178570. {
  178571. png_bytep rp, dp, pp;
  178572. png_uint_32 i;
  178573. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178574. pp = prev_row + 1; i < row_bytes;
  178575. i++, rp++, pp++, dp++)
  178576. {
  178577. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178578. }
  178579. best_row = png_ptr->up_row;
  178580. }
  178581. else if (filter_to_do & PNG_FILTER_UP)
  178582. {
  178583. png_bytep rp, dp, pp;
  178584. png_uint_32 sum = 0, lmins = mins;
  178585. png_uint_32 i;
  178586. int v;
  178587. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178588. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178589. {
  178590. int j;
  178591. png_uint_32 lmhi, lmlo;
  178592. lmlo = lmins & PNG_LOMASK;
  178593. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178594. for (j = 0; j < num_p_filters; j++)
  178595. {
  178596. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178597. {
  178598. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178599. PNG_WEIGHT_SHIFT;
  178600. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178601. PNG_WEIGHT_SHIFT;
  178602. }
  178603. }
  178604. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178605. PNG_COST_SHIFT;
  178606. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178607. PNG_COST_SHIFT;
  178608. if (lmhi > PNG_HIMASK)
  178609. lmins = PNG_MAXSUM;
  178610. else
  178611. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178612. }
  178613. #endif
  178614. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178615. pp = prev_row + 1; i < row_bytes; i++)
  178616. {
  178617. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178618. sum += (v < 128) ? v : 256 - v;
  178619. if (sum > lmins) /* We are already worse, don't continue. */
  178620. break;
  178621. }
  178622. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178623. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178624. {
  178625. int j;
  178626. png_uint_32 sumhi, sumlo;
  178627. sumlo = sum & PNG_LOMASK;
  178628. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178629. for (j = 0; j < num_p_filters; j++)
  178630. {
  178631. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178632. {
  178633. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178634. PNG_WEIGHT_SHIFT;
  178635. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178636. PNG_WEIGHT_SHIFT;
  178637. }
  178638. }
  178639. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178640. PNG_COST_SHIFT;
  178641. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178642. PNG_COST_SHIFT;
  178643. if (sumhi > PNG_HIMASK)
  178644. sum = PNG_MAXSUM;
  178645. else
  178646. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178647. }
  178648. #endif
  178649. if (sum < mins)
  178650. {
  178651. mins = sum;
  178652. best_row = png_ptr->up_row;
  178653. }
  178654. }
  178655. if (filter_to_do == PNG_FILTER_AVG)
  178656. {
  178657. png_bytep rp, dp, pp, lp;
  178658. png_uint_32 i;
  178659. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178660. pp = prev_row + 1; i < bpp; i++)
  178661. {
  178662. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178663. }
  178664. for (lp = row_buf + 1; i < row_bytes; i++)
  178665. {
  178666. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178667. & 0xff);
  178668. }
  178669. best_row = png_ptr->avg_row;
  178670. }
  178671. else if (filter_to_do & PNG_FILTER_AVG)
  178672. {
  178673. png_bytep rp, dp, pp, lp;
  178674. png_uint_32 sum = 0, lmins = mins;
  178675. png_uint_32 i;
  178676. int v;
  178677. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178678. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178679. {
  178680. int j;
  178681. png_uint_32 lmhi, lmlo;
  178682. lmlo = lmins & PNG_LOMASK;
  178683. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178684. for (j = 0; j < num_p_filters; j++)
  178685. {
  178686. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178687. {
  178688. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178689. PNG_WEIGHT_SHIFT;
  178690. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178691. PNG_WEIGHT_SHIFT;
  178692. }
  178693. }
  178694. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178695. PNG_COST_SHIFT;
  178696. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178697. PNG_COST_SHIFT;
  178698. if (lmhi > PNG_HIMASK)
  178699. lmins = PNG_MAXSUM;
  178700. else
  178701. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178702. }
  178703. #endif
  178704. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178705. pp = prev_row + 1; i < bpp; i++)
  178706. {
  178707. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178708. sum += (v < 128) ? v : 256 - v;
  178709. }
  178710. for (lp = row_buf + 1; i < row_bytes; i++)
  178711. {
  178712. v = *dp++ =
  178713. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178714. sum += (v < 128) ? v : 256 - v;
  178715. if (sum > lmins) /* We are already worse, don't continue. */
  178716. break;
  178717. }
  178718. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178719. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178720. {
  178721. int j;
  178722. png_uint_32 sumhi, sumlo;
  178723. sumlo = sum & PNG_LOMASK;
  178724. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178725. for (j = 0; j < num_p_filters; j++)
  178726. {
  178727. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178728. {
  178729. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178730. PNG_WEIGHT_SHIFT;
  178731. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178732. PNG_WEIGHT_SHIFT;
  178733. }
  178734. }
  178735. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178736. PNG_COST_SHIFT;
  178737. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178738. PNG_COST_SHIFT;
  178739. if (sumhi > PNG_HIMASK)
  178740. sum = PNG_MAXSUM;
  178741. else
  178742. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178743. }
  178744. #endif
  178745. if (sum < mins)
  178746. {
  178747. mins = sum;
  178748. best_row = png_ptr->avg_row;
  178749. }
  178750. }
  178751. if (filter_to_do == PNG_FILTER_PAETH)
  178752. {
  178753. png_bytep rp, dp, pp, cp, lp;
  178754. png_uint_32 i;
  178755. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178756. pp = prev_row + 1; i < bpp; i++)
  178757. {
  178758. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178759. }
  178760. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178761. {
  178762. int a, b, c, pa, pb, pc, p;
  178763. b = *pp++;
  178764. c = *cp++;
  178765. a = *lp++;
  178766. p = b - c;
  178767. pc = a - c;
  178768. #ifdef PNG_USE_ABS
  178769. pa = abs(p);
  178770. pb = abs(pc);
  178771. pc = abs(p + pc);
  178772. #else
  178773. pa = p < 0 ? -p : p;
  178774. pb = pc < 0 ? -pc : pc;
  178775. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178776. #endif
  178777. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178778. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178779. }
  178780. best_row = png_ptr->paeth_row;
  178781. }
  178782. else if (filter_to_do & PNG_FILTER_PAETH)
  178783. {
  178784. png_bytep rp, dp, pp, cp, lp;
  178785. png_uint_32 sum = 0, lmins = mins;
  178786. png_uint_32 i;
  178787. int v;
  178788. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178789. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178790. {
  178791. int j;
  178792. png_uint_32 lmhi, lmlo;
  178793. lmlo = lmins & PNG_LOMASK;
  178794. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178795. for (j = 0; j < num_p_filters; j++)
  178796. {
  178797. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178798. {
  178799. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178800. PNG_WEIGHT_SHIFT;
  178801. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178802. PNG_WEIGHT_SHIFT;
  178803. }
  178804. }
  178805. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178806. PNG_COST_SHIFT;
  178807. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178808. PNG_COST_SHIFT;
  178809. if (lmhi > PNG_HIMASK)
  178810. lmins = PNG_MAXSUM;
  178811. else
  178812. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178813. }
  178814. #endif
  178815. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178816. pp = prev_row + 1; i < bpp; i++)
  178817. {
  178818. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178819. sum += (v < 128) ? v : 256 - v;
  178820. }
  178821. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178822. {
  178823. int a, b, c, pa, pb, pc, p;
  178824. b = *pp++;
  178825. c = *cp++;
  178826. a = *lp++;
  178827. #ifndef PNG_SLOW_PAETH
  178828. p = b - c;
  178829. pc = a - c;
  178830. #ifdef PNG_USE_ABS
  178831. pa = abs(p);
  178832. pb = abs(pc);
  178833. pc = abs(p + pc);
  178834. #else
  178835. pa = p < 0 ? -p : p;
  178836. pb = pc < 0 ? -pc : pc;
  178837. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178838. #endif
  178839. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178840. #else /* PNG_SLOW_PAETH */
  178841. p = a + b - c;
  178842. pa = abs(p - a);
  178843. pb = abs(p - b);
  178844. pc = abs(p - c);
  178845. if (pa <= pb && pa <= pc)
  178846. p = a;
  178847. else if (pb <= pc)
  178848. p = b;
  178849. else
  178850. p = c;
  178851. #endif /* PNG_SLOW_PAETH */
  178852. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178853. sum += (v < 128) ? v : 256 - v;
  178854. if (sum > lmins) /* We are already worse, don't continue. */
  178855. break;
  178856. }
  178857. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178858. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178859. {
  178860. int j;
  178861. png_uint_32 sumhi, sumlo;
  178862. sumlo = sum & PNG_LOMASK;
  178863. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178864. for (j = 0; j < num_p_filters; j++)
  178865. {
  178866. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178867. {
  178868. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178869. PNG_WEIGHT_SHIFT;
  178870. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178871. PNG_WEIGHT_SHIFT;
  178872. }
  178873. }
  178874. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178875. PNG_COST_SHIFT;
  178876. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178877. PNG_COST_SHIFT;
  178878. if (sumhi > PNG_HIMASK)
  178879. sum = PNG_MAXSUM;
  178880. else
  178881. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178882. }
  178883. #endif
  178884. if (sum < mins)
  178885. {
  178886. best_row = png_ptr->paeth_row;
  178887. }
  178888. }
  178889. #endif /* PNG_NO_WRITE_FILTER */
  178890. png_write_filtered_row(png_ptr, best_row);
  178891. #ifndef PNG_NO_WRITE_FILTER
  178892. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178893. if (png_ptr->num_prev_filters > 0)
  178894. {
  178895. int j;
  178896. for (j = 1; j < num_p_filters; j++)
  178897. {
  178898. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178899. }
  178900. png_ptr->prev_filters[j] = best_row[0];
  178901. }
  178902. #endif
  178903. #endif /* PNG_NO_WRITE_FILTER */
  178904. }
  178905. void /* PRIVATE */
  178906. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178907. {
  178908. png_debug(1, "in png_write_filtered_row\n");
  178909. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178910. png_ptr->zstream.next_in = filtered_row;
  178911. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178912. do
  178913. {
  178914. int ret; /* return of zlib */
  178915. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178916. if (ret != Z_OK)
  178917. {
  178918. if (png_ptr->zstream.msg != NULL)
  178919. png_error(png_ptr, png_ptr->zstream.msg);
  178920. else
  178921. png_error(png_ptr, "zlib error");
  178922. }
  178923. if (!(png_ptr->zstream.avail_out))
  178924. {
  178925. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178926. png_ptr->zstream.next_out = png_ptr->zbuf;
  178927. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178928. }
  178929. } while (png_ptr->zstream.avail_in);
  178930. if (png_ptr->prev_row != NULL)
  178931. {
  178932. png_bytep tptr;
  178933. tptr = png_ptr->prev_row;
  178934. png_ptr->prev_row = png_ptr->row_buf;
  178935. png_ptr->row_buf = tptr;
  178936. }
  178937. png_write_finish_row(png_ptr);
  178938. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  178939. png_ptr->flush_rows++;
  178940. if (png_ptr->flush_dist > 0 &&
  178941. png_ptr->flush_rows >= png_ptr->flush_dist)
  178942. {
  178943. png_write_flush(png_ptr);
  178944. }
  178945. #endif
  178946. }
  178947. #endif /* PNG_WRITE_SUPPORTED */
  178948. /*** End of inlined file: pngwutil.c ***/
  178949. }
  178950. #else
  178951. #define PNG_INTERNAL
  178952. #define PNG_SETJMP_NOT_SUPPORTED
  178953. #include <png.h>
  178954. #include <pngconf.h>
  178955. #endif
  178956. }
  178957. #undef max
  178958. #undef min
  178959. #ifdef _MSC_VER
  178960. #pragma warning (pop)
  178961. #endif
  178962. BEGIN_JUCE_NAMESPACE
  178963. using ::calloc;
  178964. using ::malloc;
  178965. using ::free;
  178966. namespace PNGHelpers
  178967. {
  178968. using namespace pnglibNamespace;
  178969. static void readCallback (png_structp png, png_bytep data, png_size_t length)
  178970. {
  178971. static_cast<InputStream*> (png->io_ptr)->read (data, (int) length);
  178972. }
  178973. static void writeDataCallback (png_structp png, png_bytep data, png_size_t length)
  178974. {
  178975. static_cast<OutputStream*> (png->io_ptr)->write (data, (int) length);
  178976. }
  178977. struct PNGErrorStruct {};
  178978. static void errorCallback (png_structp, png_const_charp)
  178979. {
  178980. throw PNGErrorStruct();
  178981. }
  178982. }
  178983. Image* juce_loadPNGImageFromStream (InputStream& in)
  178984. {
  178985. using namespace pnglibNamespace;
  178986. Image* image = 0;
  178987. png_structp pngReadStruct;
  178988. png_infop pngInfoStruct;
  178989. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178990. if (pngReadStruct != 0)
  178991. {
  178992. pngInfoStruct = png_create_info_struct (pngReadStruct);
  178993. if (pngInfoStruct == 0)
  178994. {
  178995. png_destroy_read_struct (&pngReadStruct, 0, 0);
  178996. return 0;
  178997. }
  178998. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  178999. // read the header..
  179000. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  179001. png_uint_32 width, height;
  179002. int bitDepth, colorType, interlaceType;
  179003. png_read_info (pngReadStruct, pngInfoStruct);
  179004. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179005. &width, &height,
  179006. &bitDepth, &colorType,
  179007. &interlaceType, 0, 0);
  179008. if (bitDepth == 16)
  179009. png_set_strip_16 (pngReadStruct);
  179010. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179011. png_set_expand (pngReadStruct);
  179012. if (bitDepth < 8)
  179013. png_set_expand (pngReadStruct);
  179014. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179015. png_set_expand (pngReadStruct);
  179016. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179017. png_set_gray_to_rgb (pngReadStruct);
  179018. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179019. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179020. || pngInfoStruct->num_trans > 0;
  179021. // Load the image into a temp buffer in the pnglib format..
  179022. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179023. {
  179024. HeapBlock <png_bytep> rows (height);
  179025. for (int y = (int) height; --y >= 0;)
  179026. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179027. png_read_image (pngReadStruct, rows);
  179028. png_read_end (pngReadStruct, pngInfoStruct);
  179029. }
  179030. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179031. // now convert the data to a juce image format..
  179032. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179033. (int) width, (int) height, hasAlphaChan);
  179034. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179035. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179036. uint8* srcRow = tempBuffer;
  179037. uint8* destRow = destData.data;
  179038. for (int y = 0; y < (int) height; ++y)
  179039. {
  179040. const uint8* src = srcRow;
  179041. srcRow += (width << 2);
  179042. uint8* dest = destRow;
  179043. destRow += destData.lineStride;
  179044. if (hasAlphaChan)
  179045. {
  179046. for (int i = (int) width; --i >= 0;)
  179047. {
  179048. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179049. ((PixelARGB*) dest)->premultiply();
  179050. dest += destData.pixelStride;
  179051. src += 4;
  179052. }
  179053. }
  179054. else
  179055. {
  179056. for (int i = (int) width; --i >= 0;)
  179057. {
  179058. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179059. dest += destData.pixelStride;
  179060. src += 4;
  179061. }
  179062. }
  179063. }
  179064. }
  179065. return image;
  179066. }
  179067. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179068. {
  179069. using namespace pnglibNamespace;
  179070. const int width = image.getWidth();
  179071. const int height = image.getHeight();
  179072. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179073. if (pngWriteStruct == 0)
  179074. return false;
  179075. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179076. if (pngInfoStruct == 0)
  179077. {
  179078. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179079. return false;
  179080. }
  179081. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  179082. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179083. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179084. : PNG_COLOR_TYPE_RGB,
  179085. PNG_INTERLACE_NONE,
  179086. PNG_COMPRESSION_TYPE_BASE,
  179087. PNG_FILTER_TYPE_BASE);
  179088. HeapBlock <png_byte> rowData (width * 4);
  179089. png_color_8 sig_bit;
  179090. sig_bit.red = 8;
  179091. sig_bit.green = 8;
  179092. sig_bit.blue = 8;
  179093. sig_bit.alpha = 8;
  179094. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179095. png_write_info (pngWriteStruct, pngInfoStruct);
  179096. png_set_shift (pngWriteStruct, &sig_bit);
  179097. png_set_packing (pngWriteStruct);
  179098. const Image::BitmapData srcData (image, 0, 0, width, height);
  179099. for (int y = 0; y < height; ++y)
  179100. {
  179101. uint8* dst = (uint8*) rowData;
  179102. const uint8* src = srcData.getLinePointer (y);
  179103. if (image.hasAlphaChannel())
  179104. {
  179105. for (int i = width; --i >= 0;)
  179106. {
  179107. PixelARGB p (*(const PixelARGB*) src);
  179108. p.unpremultiply();
  179109. *dst++ = p.getRed();
  179110. *dst++ = p.getGreen();
  179111. *dst++ = p.getBlue();
  179112. *dst++ = p.getAlpha();
  179113. src += srcData.pixelStride;
  179114. }
  179115. }
  179116. else
  179117. {
  179118. for (int i = width; --i >= 0;)
  179119. {
  179120. *dst++ = ((const PixelRGB*) src)->getRed();
  179121. *dst++ = ((const PixelRGB*) src)->getGreen();
  179122. *dst++ = ((const PixelRGB*) src)->getBlue();
  179123. src += srcData.pixelStride;
  179124. }
  179125. }
  179126. png_write_rows (pngWriteStruct, &rowData, 1);
  179127. }
  179128. png_write_end (pngWriteStruct, pngInfoStruct);
  179129. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179130. out.flush();
  179131. return true;
  179132. }
  179133. END_JUCE_NAMESPACE
  179134. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179135. #endif
  179136. //==============================================================================
  179137. #if JUCE_BUILD_NATIVE
  179138. #if JUCE_WINDOWS
  179139. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179140. #if JUCE_WINDOWS
  179141. BEGIN_JUCE_NAMESPACE
  179142. #define JUCE_INCLUDED_FILE 1
  179143. // Now include the actual code files..
  179144. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179145. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179146. // compiled on its own).
  179147. #if JUCE_INCLUDED_FILE
  179148. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179149. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179150. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179151. #ifndef DOXYGEN
  179152. // use with DynamicLibraryLoader to simplify importing functions
  179153. //
  179154. // functionName: function to import
  179155. // localFunctionName: name you want to use to actually call it (must be different)
  179156. // returnType: the return type
  179157. // object: the DynamicLibraryLoader to use
  179158. // params: list of params (bracketed)
  179159. //
  179160. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179161. typedef returnType (WINAPI *type##localFunctionName) params; \
  179162. type##localFunctionName localFunctionName \
  179163. = (type##localFunctionName)object.findProcAddress (#functionName);
  179164. // loads and unloads a DLL automatically
  179165. class JUCE_API DynamicLibraryLoader
  179166. {
  179167. public:
  179168. DynamicLibraryLoader (const String& name);
  179169. ~DynamicLibraryLoader();
  179170. void* findProcAddress (const String& functionName);
  179171. private:
  179172. void* libHandle;
  179173. };
  179174. #endif
  179175. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179176. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179177. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179178. {
  179179. libHandle = LoadLibrary (name);
  179180. }
  179181. DynamicLibraryLoader::~DynamicLibraryLoader()
  179182. {
  179183. FreeLibrary ((HMODULE) libHandle);
  179184. }
  179185. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179186. {
  179187. return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179188. }
  179189. #endif
  179190. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179191. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179192. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179193. // compiled on its own).
  179194. #if JUCE_INCLUDED_FILE
  179195. extern void juce_initialiseThreadEvents();
  179196. void Logger::outputDebugString (const String& text) throw()
  179197. {
  179198. OutputDebugString (text + "\n");
  179199. }
  179200. static int64 hiResTicksPerSecond;
  179201. static double hiResTicksScaleFactor;
  179202. #if JUCE_USE_INTRINSICS
  179203. // CPU info functions using intrinsics...
  179204. #pragma intrinsic (__cpuid)
  179205. #pragma intrinsic (__rdtsc)
  179206. const String SystemStats::getCpuVendor() throw()
  179207. {
  179208. int info [4];
  179209. __cpuid (info, 0);
  179210. char v [12];
  179211. memcpy (v, info + 1, 4);
  179212. memcpy (v + 4, info + 3, 4);
  179213. memcpy (v + 8, info + 2, 4);
  179214. return String (v, 12);
  179215. }
  179216. #else
  179217. // CPU info functions using old fashioned inline asm...
  179218. static void juce_getCpuVendor (char* const v)
  179219. {
  179220. int vendor[4];
  179221. zeromem (vendor, 16);
  179222. #ifdef JUCE_64BIT
  179223. #else
  179224. #ifndef __MINGW32__
  179225. __try
  179226. #endif
  179227. {
  179228. #if JUCE_GCC
  179229. unsigned int dummy = 0;
  179230. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179231. #else
  179232. __asm
  179233. {
  179234. mov eax, 0
  179235. cpuid
  179236. mov [vendor], ebx
  179237. mov [vendor + 4], edx
  179238. mov [vendor + 8], ecx
  179239. }
  179240. #endif
  179241. }
  179242. #ifndef __MINGW32__
  179243. __except (EXCEPTION_EXECUTE_HANDLER)
  179244. {
  179245. *v = 0;
  179246. }
  179247. #endif
  179248. #endif
  179249. memcpy (v, vendor, 16);
  179250. }
  179251. const String SystemStats::getCpuVendor() throw()
  179252. {
  179253. char v [16];
  179254. juce_getCpuVendor (v);
  179255. return String (v, 16);
  179256. }
  179257. #endif
  179258. struct CPUFlags
  179259. {
  179260. bool hasMMX : 1;
  179261. bool hasSSE : 1;
  179262. bool hasSSE2 : 1;
  179263. bool has3DNow : 1;
  179264. };
  179265. static CPUFlags cpuFlags;
  179266. bool SystemStats::hasMMX() throw()
  179267. {
  179268. return cpuFlags.hasMMX;
  179269. }
  179270. bool SystemStats::hasSSE() throw()
  179271. {
  179272. return cpuFlags.hasSSE;
  179273. }
  179274. bool SystemStats::hasSSE2() throw()
  179275. {
  179276. return cpuFlags.hasSSE2;
  179277. }
  179278. bool SystemStats::has3DNow() throw()
  179279. {
  179280. return cpuFlags.has3DNow;
  179281. }
  179282. void SystemStats::initialiseStats() throw()
  179283. {
  179284. juce_initialiseThreadEvents();
  179285. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179286. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179287. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179288. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179289. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179290. #else
  179291. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179292. #endif
  179293. LARGE_INTEGER f;
  179294. QueryPerformanceFrequency (&f);
  179295. hiResTicksPerSecond = f.QuadPart;
  179296. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179297. String s (SystemStats::getJUCEVersion());
  179298. #ifdef JUCE_DEBUG
  179299. const MMRESULT res = timeBeginPeriod (1);
  179300. jassert (res == TIMERR_NOERROR);
  179301. #else
  179302. timeBeginPeriod (1);
  179303. #endif
  179304. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179305. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179306. #endif
  179307. }
  179308. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179309. {
  179310. OSVERSIONINFO info;
  179311. info.dwOSVersionInfoSize = sizeof (info);
  179312. GetVersionEx (&info);
  179313. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179314. {
  179315. switch (info.dwMajorVersion)
  179316. {
  179317. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179318. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179319. default: jassertfalse; break; // !! not a supported OS!
  179320. }
  179321. }
  179322. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179323. {
  179324. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179325. return Win98;
  179326. }
  179327. return UnknownOS;
  179328. }
  179329. const String SystemStats::getOperatingSystemName() throw()
  179330. {
  179331. const char* name = "Unknown OS";
  179332. switch (getOperatingSystemType())
  179333. {
  179334. case Windows7: name = "Windows 7"; break;
  179335. case WinVista: name = "Windows Vista"; break;
  179336. case WinXP: name = "Windows XP"; break;
  179337. case Win2000: name = "Windows 2000"; break;
  179338. case Win98: name = "Windows 98"; break;
  179339. default: jassertfalse; break; // !! new type of OS?
  179340. }
  179341. return name;
  179342. }
  179343. bool SystemStats::isOperatingSystem64Bit() throw()
  179344. {
  179345. #ifdef _WIN64
  179346. return true;
  179347. #else
  179348. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179349. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179350. BOOL isWow64 = FALSE;
  179351. return (fnIsWow64Process != 0)
  179352. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179353. && (isWow64 != FALSE);
  179354. #endif
  179355. }
  179356. int SystemStats::getMemorySizeInMegabytes() throw()
  179357. {
  179358. MEMORYSTATUSEX mem;
  179359. mem.dwLength = sizeof (mem);
  179360. GlobalMemoryStatusEx (&mem);
  179361. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179362. }
  179363. int SystemStats::getNumCpus() throw()
  179364. {
  179365. SYSTEM_INFO systemInfo;
  179366. GetSystemInfo (&systemInfo);
  179367. return systemInfo.dwNumberOfProcessors;
  179368. }
  179369. uint32 juce_millisecondsSinceStartup() throw()
  179370. {
  179371. return (uint32) GetTickCount();
  179372. }
  179373. int64 Time::getHighResolutionTicks() throw()
  179374. {
  179375. LARGE_INTEGER ticks;
  179376. QueryPerformanceCounter (&ticks);
  179377. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179378. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179379. // fix for a very obscure PCI hardware bug that can make the counter
  179380. // sometimes jump forwards by a few seconds..
  179381. static int64 hiResTicksOffset = 0;
  179382. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179383. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179384. hiResTicksOffset = newOffset;
  179385. return ticks.QuadPart + hiResTicksOffset;
  179386. }
  179387. double Time::getMillisecondCounterHiRes() throw()
  179388. {
  179389. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179390. }
  179391. int64 Time::getHighResolutionTicksPerSecond() throw()
  179392. {
  179393. return hiResTicksPerSecond;
  179394. }
  179395. int64 SystemStats::getClockCycleCounter() throw()
  179396. {
  179397. #if JUCE_USE_INTRINSICS
  179398. // MS intrinsics version...
  179399. return __rdtsc();
  179400. #elif JUCE_GCC
  179401. // GNU inline asm version...
  179402. unsigned int hi = 0, lo = 0;
  179403. __asm__ __volatile__ (
  179404. "xor %%eax, %%eax \n\
  179405. xor %%edx, %%edx \n\
  179406. rdtsc \n\
  179407. movl %%eax, %[lo] \n\
  179408. movl %%edx, %[hi]"
  179409. :
  179410. : [hi] "m" (hi),
  179411. [lo] "m" (lo)
  179412. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179413. return (int64) ((((uint64) hi) << 32) | lo);
  179414. #else
  179415. // MSVC inline asm version...
  179416. unsigned int hi = 0, lo = 0;
  179417. __asm
  179418. {
  179419. xor eax, eax
  179420. xor edx, edx
  179421. rdtsc
  179422. mov lo, eax
  179423. mov hi, edx
  179424. }
  179425. return (int64) ((((uint64) hi) << 32) | lo);
  179426. #endif
  179427. }
  179428. int SystemStats::getCpuSpeedInMegaherz() throw()
  179429. {
  179430. const int64 cycles = SystemStats::getClockCycleCounter();
  179431. const uint32 millis = Time::getMillisecondCounter();
  179432. int lastResult = 0;
  179433. for (;;)
  179434. {
  179435. int n = 1000000;
  179436. while (--n > 0) {}
  179437. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179438. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179439. if (millisElapsed > 80)
  179440. {
  179441. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179442. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179443. return newResult;
  179444. lastResult = newResult;
  179445. }
  179446. }
  179447. }
  179448. bool Time::setSystemTimeToThisTime() const throw()
  179449. {
  179450. SYSTEMTIME st;
  179451. st.wDayOfWeek = 0;
  179452. st.wYear = (WORD) getYear();
  179453. st.wMonth = (WORD) (getMonth() + 1);
  179454. st.wDay = (WORD) getDayOfMonth();
  179455. st.wHour = (WORD) getHours();
  179456. st.wMinute = (WORD) getMinutes();
  179457. st.wSecond = (WORD) getSeconds();
  179458. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179459. // do this twice because of daylight saving conversion problems - the
  179460. // first one sets it up, the second one kicks it in.
  179461. return SetLocalTime (&st) != 0
  179462. && SetLocalTime (&st) != 0;
  179463. }
  179464. int SystemStats::getPageSize() throw()
  179465. {
  179466. SYSTEM_INFO systemInfo;
  179467. GetSystemInfo (&systemInfo);
  179468. return systemInfo.dwPageSize;
  179469. }
  179470. const String SystemStats::getLogonName()
  179471. {
  179472. TCHAR text [256];
  179473. DWORD len = numElementsInArray (text) - 2;
  179474. zerostruct (text);
  179475. GetUserName (text, &len);
  179476. return String (text, len);
  179477. }
  179478. const String SystemStats::getFullUserName()
  179479. {
  179480. return getLogonName();
  179481. }
  179482. #endif
  179483. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179484. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179485. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179486. // compiled on its own).
  179487. #if JUCE_INCLUDED_FILE
  179488. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179489. extern HWND juce_messageWindowHandle;
  179490. #endif
  179491. #if ! JUCE_USE_INTRINSICS
  179492. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179493. // older ones we have to actually call the ops as win32 functions..
  179494. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179495. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179496. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179497. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179498. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179499. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179500. #endif
  179501. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179502. CriticalSection::CriticalSection() throw()
  179503. {
  179504. // (just to check the MS haven't changed this structure and broken things...)
  179505. #if _MSC_VER >= 1400
  179506. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179507. #else
  179508. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179509. #endif
  179510. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179511. }
  179512. CriticalSection::~CriticalSection() throw()
  179513. {
  179514. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179515. }
  179516. void CriticalSection::enter() const throw()
  179517. {
  179518. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179519. }
  179520. bool CriticalSection::tryEnter() const throw()
  179521. {
  179522. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179523. }
  179524. void CriticalSection::exit() const throw()
  179525. {
  179526. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179527. }
  179528. WaitableEvent::WaitableEvent() throw()
  179529. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179530. {
  179531. }
  179532. WaitableEvent::~WaitableEvent() throw()
  179533. {
  179534. CloseHandle (internal);
  179535. }
  179536. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179537. {
  179538. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179539. }
  179540. void WaitableEvent::signal() const throw()
  179541. {
  179542. SetEvent (internal);
  179543. }
  179544. void WaitableEvent::reset() const throw()
  179545. {
  179546. ResetEvent (internal);
  179547. }
  179548. void JUCE_API juce_threadEntryPoint (void*);
  179549. static unsigned int __stdcall threadEntryProc (void* userData)
  179550. {
  179551. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179552. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179553. GetCurrentThreadId(), TRUE);
  179554. #endif
  179555. juce_threadEntryPoint (userData);
  179556. _endthreadex (0);
  179557. return 0;
  179558. }
  179559. void juce_CloseThreadHandle (void* handle)
  179560. {
  179561. CloseHandle ((HANDLE) handle);
  179562. }
  179563. void* juce_createThread (void* userData)
  179564. {
  179565. unsigned int threadId;
  179566. return (void*) _beginthreadex (0, 0,
  179567. &threadEntryProc,
  179568. userData,
  179569. 0, &threadId);
  179570. }
  179571. void juce_killThread (void* handle)
  179572. {
  179573. if (handle != 0)
  179574. {
  179575. #ifdef JUCE_DEBUG
  179576. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179577. #endif
  179578. TerminateThread (handle, 0);
  179579. }
  179580. }
  179581. void juce_setCurrentThreadName (const String& name)
  179582. {
  179583. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179584. struct
  179585. {
  179586. DWORD dwType;
  179587. LPCSTR szName;
  179588. DWORD dwThreadID;
  179589. DWORD dwFlags;
  179590. } info;
  179591. info.dwType = 0x1000;
  179592. info.szName = name.toCString();
  179593. info.dwThreadID = GetCurrentThreadId();
  179594. info.dwFlags = 0;
  179595. __try
  179596. {
  179597. RaiseException (0x406d1388 /*MS_VC_EXCEPTION*/, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179598. }
  179599. __except (EXCEPTION_CONTINUE_EXECUTION)
  179600. {}
  179601. #else
  179602. (void) name;
  179603. #endif
  179604. }
  179605. Thread::ThreadID Thread::getCurrentThreadId()
  179606. {
  179607. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179608. }
  179609. // priority 1 to 10 where 5=normal, 1=low
  179610. bool juce_setThreadPriority (void* threadHandle, int priority)
  179611. {
  179612. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179613. if (priority < 1)
  179614. pri = THREAD_PRIORITY_IDLE;
  179615. else if (priority < 2)
  179616. pri = THREAD_PRIORITY_LOWEST;
  179617. else if (priority < 5)
  179618. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179619. else if (priority < 7)
  179620. pri = THREAD_PRIORITY_NORMAL;
  179621. else if (priority < 9)
  179622. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179623. else if (priority < 10)
  179624. pri = THREAD_PRIORITY_HIGHEST;
  179625. if (threadHandle == 0)
  179626. threadHandle = GetCurrentThread();
  179627. return SetThreadPriority (threadHandle, pri) != FALSE;
  179628. }
  179629. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179630. {
  179631. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179632. }
  179633. static HANDLE sleepEvent = 0;
  179634. void juce_initialiseThreadEvents()
  179635. {
  179636. if (sleepEvent == 0)
  179637. #ifdef JUCE_DEBUG
  179638. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179639. #else
  179640. sleepEvent = CreateEvent (0, 0, 0, 0);
  179641. #endif
  179642. }
  179643. void Thread::yield()
  179644. {
  179645. Sleep (0);
  179646. }
  179647. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179648. {
  179649. if (millisecs >= 10)
  179650. {
  179651. Sleep (millisecs);
  179652. }
  179653. else
  179654. {
  179655. jassert (sleepEvent != 0);
  179656. // unlike Sleep() this is guaranteed to return to the current thread after
  179657. // the time expires, so we'll use this for short waits, which are more likely
  179658. // to need to be accurate
  179659. WaitForSingleObject (sleepEvent, millisecs);
  179660. }
  179661. }
  179662. static int lastProcessPriority = -1;
  179663. // called by WindowDriver because Windows does wierd things to process priority
  179664. // when you swap apps, and this forces an update when the app is brought to the front.
  179665. void juce_repeatLastProcessPriority()
  179666. {
  179667. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179668. {
  179669. DWORD p;
  179670. switch (lastProcessPriority)
  179671. {
  179672. case Process::LowPriority: p = IDLE_PRIORITY_CLASS; break;
  179673. case Process::NormalPriority: p = NORMAL_PRIORITY_CLASS; break;
  179674. case Process::HighPriority: p = HIGH_PRIORITY_CLASS; break;
  179675. case Process::RealtimePriority: p = REALTIME_PRIORITY_CLASS; break;
  179676. default: jassertfalse; return; // bad priority value
  179677. }
  179678. SetPriorityClass (GetCurrentProcess(), p);
  179679. }
  179680. }
  179681. void Process::setPriority (ProcessPriority prior)
  179682. {
  179683. if (lastProcessPriority != (int) prior)
  179684. {
  179685. lastProcessPriority = (int) prior;
  179686. juce_repeatLastProcessPriority();
  179687. }
  179688. }
  179689. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179690. {
  179691. return IsDebuggerPresent() != FALSE;
  179692. }
  179693. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179694. {
  179695. return juce_isRunningUnderDebugger();
  179696. }
  179697. void Process::raisePrivilege()
  179698. {
  179699. jassertfalse // xxx not implemented
  179700. }
  179701. void Process::lowerPrivilege()
  179702. {
  179703. jassertfalse // xxx not implemented
  179704. }
  179705. void Process::terminate()
  179706. {
  179707. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179708. _CrtDumpMemoryLeaks();
  179709. #endif
  179710. // bullet in the head in case there's a problem shutting down..
  179711. ExitProcess (0);
  179712. }
  179713. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179714. {
  179715. void* result = 0;
  179716. JUCE_TRY
  179717. {
  179718. result = (void*) LoadLibrary (name);
  179719. }
  179720. JUCE_CATCH_ALL
  179721. return result;
  179722. }
  179723. void PlatformUtilities::freeDynamicLibrary (void* h)
  179724. {
  179725. JUCE_TRY
  179726. {
  179727. if (h != 0)
  179728. FreeLibrary ((HMODULE) h);
  179729. }
  179730. JUCE_CATCH_ALL
  179731. }
  179732. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179733. {
  179734. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179735. }
  179736. InterProcessLock::InterProcessLock (const String& name_)
  179737. : internal (0),
  179738. name (name_),
  179739. reentrancyLevel (0)
  179740. {
  179741. }
  179742. InterProcessLock::~InterProcessLock()
  179743. {
  179744. exit();
  179745. }
  179746. bool InterProcessLock::enter (const int timeOutMillisecs)
  179747. {
  179748. if (reentrancyLevel++ == 0)
  179749. {
  179750. internal = CreateMutex (0, TRUE, "Global\\" + name);
  179751. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179752. {
  179753. if (timeOutMillisecs == 0
  179754. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  179755. == WAIT_TIMEOUT)
  179756. {
  179757. ReleaseMutex (internal);
  179758. CloseHandle (internal);
  179759. internal = 0;
  179760. }
  179761. }
  179762. }
  179763. return (internal != 0);
  179764. }
  179765. void InterProcessLock::exit()
  179766. {
  179767. if (--reentrancyLevel == 0 && internal != 0)
  179768. {
  179769. ReleaseMutex (internal);
  179770. CloseHandle (internal);
  179771. internal = 0;
  179772. }
  179773. }
  179774. #endif
  179775. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179776. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179777. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179778. // compiled on its own).
  179779. #if JUCE_INCLUDED_FILE
  179780. #ifndef CSIDL_MYMUSIC
  179781. #define CSIDL_MYMUSIC 0x000d
  179782. #endif
  179783. #ifndef CSIDL_MYVIDEO
  179784. #define CSIDL_MYVIDEO 0x000e
  179785. #endif
  179786. #ifndef INVALID_FILE_ATTRIBUTES
  179787. #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
  179788. #endif
  179789. const juce_wchar File::separator = '\\';
  179790. const juce_wchar* File::separatorString = T("\\");
  179791. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179792. {
  179793. if (fileName.isEmpty())
  179794. return false;
  179795. const DWORD attr = GetFileAttributes (fileName);
  179796. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179797. : (attr != INVALID_FILE_ATTRIBUTES);
  179798. }
  179799. bool juce_isDirectory (const String& fileName)
  179800. {
  179801. const DWORD attr = GetFileAttributes (fileName);
  179802. return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES);
  179803. }
  179804. bool juce_canWriteToFile (const String& fileName)
  179805. {
  179806. const DWORD attr = GetFileAttributes (fileName);
  179807. return (attr & FILE_ATTRIBUTE_READONLY) == 0;
  179808. }
  179809. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179810. {
  179811. DWORD attr = GetFileAttributes (fileName);
  179812. if (attr == INVALID_FILE_ATTRIBUTES)
  179813. return false;
  179814. if (isReadOnly != juce_canWriteToFile (fileName))
  179815. return true;
  179816. if (isReadOnly)
  179817. attr |= FILE_ATTRIBUTE_READONLY;
  179818. else
  179819. attr &= ~FILE_ATTRIBUTE_READONLY;
  179820. return SetFileAttributes (fileName, attr) != FALSE;
  179821. }
  179822. bool File::isHidden() const
  179823. {
  179824. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179825. }
  179826. bool juce_deleteFile (const String& fileName)
  179827. {
  179828. if (juce_isDirectory (fileName))
  179829. return RemoveDirectory (fileName) != 0;
  179830. return DeleteFile (fileName) != 0;
  179831. }
  179832. bool File::moveToTrash() const
  179833. {
  179834. if (! exists())
  179835. return true;
  179836. SHFILEOPSTRUCT fos;
  179837. zerostruct (fos);
  179838. // The string we pass in must be double null terminated..
  179839. String doubleNullTermPath (getFullPathName() + " ");
  179840. TCHAR* const p = const_cast <TCHAR*> (static_cast <const TCHAR*> (doubleNullTermPath));
  179841. p [getFullPathName().length()] = 0;
  179842. fos.wFunc = FO_DELETE;
  179843. fos.pFrom = p;
  179844. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179845. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179846. return SHFileOperation (&fos) == 0;
  179847. }
  179848. bool juce_moveFile (const String& source, const String& dest)
  179849. {
  179850. return MoveFile (source, dest) != 0;
  179851. }
  179852. bool juce_copyFile (const String& source, const String& dest)
  179853. {
  179854. return CopyFile (source, dest, false) != 0;
  179855. }
  179856. void juce_createDirectory (const String& fileName)
  179857. {
  179858. if (! juce_fileExists (fileName, true))
  179859. CreateDirectory (fileName, 0);
  179860. }
  179861. // return 0 if not possible
  179862. void* juce_fileOpen (const String& fileName, bool forWriting)
  179863. {
  179864. HANDLE h;
  179865. if (forWriting)
  179866. {
  179867. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179868. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179869. if (h != INVALID_HANDLE_VALUE)
  179870. SetFilePointer (h, 0, 0, FILE_END);
  179871. else
  179872. h = 0;
  179873. }
  179874. else
  179875. {
  179876. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179877. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179878. if (h == INVALID_HANDLE_VALUE)
  179879. h = 0;
  179880. }
  179881. return (void*) h;
  179882. }
  179883. void juce_fileClose (void* handle)
  179884. {
  179885. CloseHandle (handle);
  179886. }
  179887. int juce_fileRead (void* handle, void* buffer, int size)
  179888. {
  179889. DWORD num = 0;
  179890. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179891. return (int) num;
  179892. }
  179893. int juce_fileWrite (void* handle, const void* buffer, int size)
  179894. {
  179895. DWORD num;
  179896. WriteFile ((HANDLE) handle, buffer, size, &num, 0);
  179897. return (int) num;
  179898. }
  179899. int64 juce_fileSetPosition (void* handle, int64 pos)
  179900. {
  179901. LARGE_INTEGER li;
  179902. li.QuadPart = pos;
  179903. li.LowPart = SetFilePointer ((HANDLE) handle, li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails)
  179904. return li.QuadPart;
  179905. }
  179906. int64 juce_fileGetPosition (void* handle)
  179907. {
  179908. LARGE_INTEGER li;
  179909. li.QuadPart = 0;
  179910. li.LowPart = SetFilePointer ((HANDLE) handle, 0, &li.HighPart, FILE_CURRENT); // (returns -1 if it fails)
  179911. return jmax ((int64) 0, li.QuadPart);
  179912. }
  179913. void juce_fileFlush (void* handle)
  179914. {
  179915. FlushFileBuffers ((HANDLE) handle);
  179916. }
  179917. int64 juce_getFileSize (const String& fileName)
  179918. {
  179919. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179920. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179921. return (((int64) attributes.nFileSizeHigh) << 32) | attributes.nFileSizeLow;
  179922. return 0;
  179923. }
  179924. static int64 fileTimeToTime (const FILETIME* const ft)
  179925. {
  179926. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME)); // tell me if this fails!
  179927. return (reinterpret_cast<const ULARGE_INTEGER*> (ft)->QuadPart - literal64bit (116444736000000000)) / 10000;
  179928. }
  179929. static void timeToFileTime (const int64 time, FILETIME* const ft)
  179930. {
  179931. reinterpret_cast<ULARGE_INTEGER*> (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000);
  179932. }
  179933. void juce_getFileTimes (const String& fileName,
  179934. int64& modificationTime,
  179935. int64& accessTime,
  179936. int64& creationTime)
  179937. {
  179938. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179939. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179940. {
  179941. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  179942. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  179943. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  179944. }
  179945. else
  179946. {
  179947. creationTime = accessTime = modificationTime = 0;
  179948. }
  179949. }
  179950. bool juce_setFileTimes (const String& fileName,
  179951. int64 modificationTime,
  179952. int64 accessTime,
  179953. int64 creationTime)
  179954. {
  179955. void* const h = juce_fileOpen (fileName, true);
  179956. bool ok = false;
  179957. if (h != 0)
  179958. {
  179959. FILETIME m, a, c;
  179960. timeToFileTime (modificationTime, &m);
  179961. timeToFileTime (accessTime, &a);
  179962. timeToFileTime (creationTime, &c);
  179963. ok = SetFileTime ((HANDLE) h,
  179964. creationTime > 0 ? &c : 0,
  179965. accessTime > 0 ? &a : 0,
  179966. modificationTime > 0 ? &m : 0) != 0;
  179967. juce_fileClose (h);
  179968. }
  179969. return ok;
  179970. }
  179971. // return '\0' separated list of strings
  179972. const StringArray juce_getFileSystemRoots()
  179973. {
  179974. TCHAR buffer [2048];
  179975. buffer[0] = 0;
  179976. buffer[1] = 0;
  179977. GetLogicalDriveStrings (2048, buffer);
  179978. const TCHAR* n = buffer;
  179979. StringArray roots;
  179980. while (*n != 0)
  179981. {
  179982. roots.add (String (n));
  179983. while (*n++ != 0)
  179984. {}
  179985. }
  179986. roots.sort (true);
  179987. return roots;
  179988. }
  179989. static const String getDriveFromPath (const String& path)
  179990. {
  179991. if (path.isNotEmpty() && path[1] == ':')
  179992. return path.substring (0, 2) + '\\';
  179993. return path;
  179994. }
  179995. const String juce_getVolumeLabel (const String& filenameOnVolume,
  179996. int& volumeSerialNumber)
  179997. {
  179998. TCHAR dest[64];
  179999. DWORD serialNum;
  180000. if (! GetVolumeInformation (getDriveFromPath (filenameOnVolume), dest,
  180001. numElementsInArray (dest), &serialNum, 0, 0, 0, 0))
  180002. {
  180003. dest[0] = 0;
  180004. serialNum = 0;
  180005. }
  180006. volumeSerialNumber = serialNum;
  180007. return dest;
  180008. }
  180009. static int64 getDiskSpaceInfo (const String& path, const bool total)
  180010. {
  180011. ULARGE_INTEGER spc, tot, totFree;
  180012. if (GetDiskFreeSpaceEx (getDriveFromPath (path), &spc, &tot, &totFree))
  180013. return total ? (int64) tot.QuadPart
  180014. : (int64) spc.QuadPart;
  180015. return 0;
  180016. }
  180017. int64 File::getBytesFreeOnVolume() const
  180018. {
  180019. return getDiskSpaceInfo (getFullPathName(), false);
  180020. }
  180021. int64 File::getVolumeTotalSize() const
  180022. {
  180023. return getDiskSpaceInfo (getFullPathName(), true);
  180024. }
  180025. static unsigned int getWindowsDriveType (const String& path)
  180026. {
  180027. return GetDriveType (getDriveFromPath (path));
  180028. }
  180029. bool File::isOnCDRomDrive() const
  180030. {
  180031. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180032. }
  180033. bool File::isOnHardDisk() const
  180034. {
  180035. if (fullPath.isEmpty())
  180036. return false;
  180037. const unsigned int n = getWindowsDriveType (getFullPathName());
  180038. if (fullPath.toLowerCase()[0] <= 'b' && fullPath[1] == ':')
  180039. return n != DRIVE_REMOVABLE;
  180040. else
  180041. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180042. }
  180043. bool File::isOnRemovableDrive() const
  180044. {
  180045. if (fullPath.isEmpty())
  180046. return false;
  180047. const unsigned int n = getWindowsDriveType (getFullPathName());
  180048. return n == DRIVE_CDROM
  180049. || n == DRIVE_REMOTE
  180050. || n == DRIVE_REMOVABLE
  180051. || n == DRIVE_RAMDISK;
  180052. }
  180053. static const File juce_getSpecialFolderPath (int type)
  180054. {
  180055. WCHAR path [MAX_PATH + 256];
  180056. if (SHGetSpecialFolderPath (0, path, type, FALSE))
  180057. return File (String (path));
  180058. return File::nonexistent;
  180059. }
  180060. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180061. {
  180062. int csidlType = 0;
  180063. switch (type)
  180064. {
  180065. case userHomeDirectory: csidlType = CSIDL_PROFILE; break;
  180066. case userDocumentsDirectory: csidlType = CSIDL_PERSONAL; break;
  180067. case userDesktopDirectory: csidlType = CSIDL_DESKTOP; break;
  180068. case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break;
  180069. case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break;
  180070. case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break;
  180071. case userMusicDirectory: csidlType = CSIDL_MYMUSIC; break;
  180072. case userMoviesDirectory: csidlType = CSIDL_MYVIDEO; break;
  180073. case tempDirectory:
  180074. {
  180075. WCHAR dest [2048];
  180076. dest[0] = 0;
  180077. GetTempPath (numElementsInArray (dest), dest);
  180078. return File (String (dest));
  180079. }
  180080. case invokedExecutableFile:
  180081. case currentExecutableFile:
  180082. case currentApplicationFile:
  180083. {
  180084. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180085. WCHAR dest [MAX_PATH + 256];
  180086. dest[0] = 0;
  180087. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  180088. return File (String (dest));
  180089. }
  180090. break;
  180091. default:
  180092. jassertfalse // unknown type?
  180093. return File::nonexistent;
  180094. }
  180095. return juce_getSpecialFolderPath (csidlType);
  180096. }
  180097. const File File::getCurrentWorkingDirectory()
  180098. {
  180099. WCHAR dest [MAX_PATH + 256];
  180100. dest[0] = 0;
  180101. GetCurrentDirectory (numElementsInArray (dest), dest);
  180102. return File (String (dest));
  180103. }
  180104. bool File::setAsCurrentWorkingDirectory() const
  180105. {
  180106. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180107. }
  180108. const String File::getVersion() const
  180109. {
  180110. String result;
  180111. DWORD handle = 0;
  180112. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180113. HeapBlock<char> buffer;
  180114. buffer.calloc (bufferSize);
  180115. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180116. {
  180117. VS_FIXEDFILEINFO* vffi;
  180118. UINT len = 0;
  180119. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180120. {
  180121. result << (int) HIWORD (vffi->dwFileVersionMS) << '.'
  180122. << (int) LOWORD (vffi->dwFileVersionMS) << '.'
  180123. << (int) HIWORD (vffi->dwFileVersionLS) << '.'
  180124. << (int) LOWORD (vffi->dwFileVersionLS);
  180125. }
  180126. }
  180127. return result;
  180128. }
  180129. const File File::getLinkedTarget() const
  180130. {
  180131. File result (*this);
  180132. String p (getFullPathName());
  180133. if (! exists())
  180134. p += ".lnk";
  180135. else if (getFileExtension() != ".lnk")
  180136. return result;
  180137. ComSmartPtr <IShellLink> shellLink;
  180138. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180139. {
  180140. ComSmartPtr <IPersistFile> persistFile;
  180141. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180142. {
  180143. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180144. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180145. {
  180146. WIN32_FIND_DATA winFindData;
  180147. WCHAR resolvedPath [MAX_PATH];
  180148. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180149. result = File (resolvedPath);
  180150. }
  180151. }
  180152. }
  180153. return result;
  180154. }
  180155. template <class FindDataType>
  180156. static void getFindFileInfo (FindDataType& findData,
  180157. String& filename, bool* const isDir, bool* const isHidden,
  180158. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180159. bool* const isReadOnly)
  180160. {
  180161. filename = findData.cFileName;
  180162. if (isDir != 0)
  180163. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180164. if (isHidden != 0)
  180165. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180166. if (fileSize != 0)
  180167. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180168. if (modTime != 0)
  180169. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180170. if (creationTime != 0)
  180171. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180172. if (isReadOnly != 0)
  180173. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180174. }
  180175. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180176. bool* isDir, bool* isHidden, int64* fileSize,
  180177. Time* modTime, Time* creationTime, bool* isReadOnly)
  180178. {
  180179. String wc (directory);
  180180. if (! wc.endsWithChar (File::separator))
  180181. wc += File::separator;
  180182. wc += wildCard;
  180183. WIN32_FIND_DATA findData;
  180184. HANDLE h = FindFirstFile (wc, &findData);
  180185. if (h != INVALID_HANDLE_VALUE)
  180186. {
  180187. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180188. modTime, creationTime, isReadOnly);
  180189. return h;
  180190. }
  180191. firstResult = String::empty;
  180192. return 0;
  180193. }
  180194. bool juce_findFileNext (void* handle, String& resultFile,
  180195. bool* isDir, bool* isHidden, int64* fileSize,
  180196. Time* modTime, Time* creationTime, bool* isReadOnly)
  180197. {
  180198. WIN32_FIND_DATA findData;
  180199. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180200. {
  180201. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180202. modTime, creationTime, isReadOnly);
  180203. return true;
  180204. }
  180205. resultFile = String::empty;
  180206. return false;
  180207. }
  180208. void juce_findFileClose (void* handle)
  180209. {
  180210. FindClose (handle);
  180211. }
  180212. bool juce_launchFile (const String& fileName, const String& parameters)
  180213. {
  180214. HINSTANCE hInstance = 0;
  180215. JUCE_TRY
  180216. {
  180217. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180218. }
  180219. JUCE_CATCH_ALL
  180220. return hInstance > (HINSTANCE) 32;
  180221. }
  180222. void File::revealToUser() const
  180223. {
  180224. if (isDirectory())
  180225. startAsProcess();
  180226. else if (getParentDirectory().exists())
  180227. getParentDirectory().startAsProcess();
  180228. }
  180229. class NamedPipeInternal
  180230. {
  180231. public:
  180232. NamedPipeInternal (const String& file, const bool isPipe_)
  180233. : pipeH (0),
  180234. cancelEvent (0),
  180235. connected (false),
  180236. isPipe (isPipe_)
  180237. {
  180238. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180239. pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180240. PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
  180241. : CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
  180242. OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
  180243. }
  180244. ~NamedPipeInternal()
  180245. {
  180246. disconnectPipe();
  180247. if (pipeH != 0)
  180248. CloseHandle (pipeH);
  180249. CloseHandle (cancelEvent);
  180250. }
  180251. bool connect (const int timeOutMs)
  180252. {
  180253. if (! isPipe)
  180254. return true;
  180255. if (! connected)
  180256. {
  180257. OVERLAPPED over;
  180258. zerostruct (over);
  180259. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180260. if (ConnectNamedPipe (pipeH, &over))
  180261. {
  180262. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180263. }
  180264. else
  180265. {
  180266. const int err = GetLastError();
  180267. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180268. {
  180269. HANDLE handles[] = { over.hEvent, cancelEvent };
  180270. if (WaitForMultipleObjects (2, handles, FALSE,
  180271. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180272. connected = true;
  180273. }
  180274. else if (err == ERROR_PIPE_CONNECTED)
  180275. {
  180276. connected = true;
  180277. }
  180278. }
  180279. CloseHandle (over.hEvent);
  180280. }
  180281. return connected;
  180282. }
  180283. void disconnectPipe()
  180284. {
  180285. if (connected)
  180286. {
  180287. DisconnectNamedPipe (pipeH);
  180288. connected = false;
  180289. }
  180290. }
  180291. HANDLE pipeH;
  180292. HANDLE cancelEvent;
  180293. bool connected, isPipe;
  180294. };
  180295. void NamedPipe::close()
  180296. {
  180297. cancelPendingReads();
  180298. const ScopedLock sl (lock);
  180299. delete static_cast<NamedPipeInternal*> (internal);
  180300. internal = 0;
  180301. }
  180302. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180303. {
  180304. close();
  180305. ScopedPointer<NamedPipeInternal> intern (new NamedPipeInternal ("\\\\.\\pipe\\" + pipeName, createPipe));
  180306. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180307. {
  180308. internal = intern.release();
  180309. return true;
  180310. }
  180311. return false;
  180312. }
  180313. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180314. {
  180315. const ScopedLock sl (lock);
  180316. int bytesRead = -1;
  180317. bool waitAgain = true;
  180318. while (waitAgain && internal != 0)
  180319. {
  180320. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180321. waitAgain = false;
  180322. if (! intern->connect (timeOutMilliseconds))
  180323. break;
  180324. if (maxBytesToRead <= 0)
  180325. return 0;
  180326. OVERLAPPED over;
  180327. zerostruct (over);
  180328. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180329. unsigned long numRead;
  180330. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180331. {
  180332. bytesRead = (int) numRead;
  180333. }
  180334. else if (GetLastError() == ERROR_IO_PENDING)
  180335. {
  180336. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180337. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180338. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180339. : INFINITE);
  180340. if (waitResult != WAIT_OBJECT_0)
  180341. {
  180342. // if the operation timed out, let's cancel it...
  180343. CancelIo (intern->pipeH);
  180344. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180345. }
  180346. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180347. {
  180348. bytesRead = (int) numRead;
  180349. }
  180350. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180351. {
  180352. intern->disconnectPipe();
  180353. waitAgain = true;
  180354. }
  180355. }
  180356. else
  180357. {
  180358. waitAgain = internal != 0;
  180359. Sleep (5);
  180360. }
  180361. CloseHandle (over.hEvent);
  180362. }
  180363. return bytesRead;
  180364. }
  180365. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180366. {
  180367. int bytesWritten = -1;
  180368. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180369. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180370. {
  180371. if (numBytesToWrite <= 0)
  180372. return 0;
  180373. OVERLAPPED over;
  180374. zerostruct (over);
  180375. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180376. unsigned long numWritten;
  180377. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180378. {
  180379. bytesWritten = (int) numWritten;
  180380. }
  180381. else if (GetLastError() == ERROR_IO_PENDING)
  180382. {
  180383. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180384. DWORD waitResult;
  180385. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180386. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180387. : INFINITE);
  180388. if (waitResult != WAIT_OBJECT_0)
  180389. {
  180390. CancelIo (intern->pipeH);
  180391. WaitForSingleObject (over.hEvent, INFINITE);
  180392. }
  180393. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180394. {
  180395. bytesWritten = (int) numWritten;
  180396. }
  180397. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180398. {
  180399. intern->disconnectPipe();
  180400. }
  180401. }
  180402. CloseHandle (over.hEvent);
  180403. }
  180404. return bytesWritten;
  180405. }
  180406. void NamedPipe::cancelPendingReads()
  180407. {
  180408. if (internal != 0)
  180409. SetEvent (static_cast<NamedPipeInternal*> (internal)->cancelEvent);
  180410. }
  180411. #endif
  180412. /*** End of inlined file: juce_win32_Files.cpp ***/
  180413. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180414. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180415. // compiled on its own).
  180416. #if JUCE_INCLUDED_FILE
  180417. #ifndef INTERNET_FLAG_NEED_FILE
  180418. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180419. #endif
  180420. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180421. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180422. #endif
  180423. bool juce_isOnLine()
  180424. {
  180425. DWORD connectionType;
  180426. return InternetGetConnectedState (&connectionType, 0) != 0
  180427. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180428. }
  180429. struct ConnectionAndRequestStruct
  180430. {
  180431. HINTERNET connection, request;
  180432. };
  180433. static HINTERNET sessionHandle = 0;
  180434. #ifndef WORKAROUND_TIMEOUT_BUG
  180435. //#define WORKAROUND_TIMEOUT_BUG 1
  180436. #endif
  180437. #if WORKAROUND_TIMEOUT_BUG
  180438. // Required because of a Microsoft bug in setting a timeout
  180439. class InternetConnectThread : public Thread
  180440. {
  180441. public:
  180442. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180443. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180444. {
  180445. startThread();
  180446. }
  180447. ~InternetConnectThread()
  180448. {
  180449. stopThread (60000);
  180450. }
  180451. void run()
  180452. {
  180453. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180454. uc.nPort, _T(""), _T(""),
  180455. isFtp ? INTERNET_SERVICE_FTP
  180456. : INTERNET_SERVICE_HTTP,
  180457. 0, 0);
  180458. notify();
  180459. }
  180460. juce_UseDebuggingNewOperator
  180461. private:
  180462. URL_COMPONENTS& uc;
  180463. HINTERNET& connection;
  180464. const bool isFtp;
  180465. InternetConnectThread (const InternetConnectThread&);
  180466. InternetConnectThread& operator= (const InternetConnectThread&);
  180467. };
  180468. #endif
  180469. void* juce_openInternetFile (const String& url,
  180470. const String& headers,
  180471. const MemoryBlock& postData,
  180472. const bool isPost,
  180473. URL::OpenStreamProgressCallback* callback,
  180474. void* callbackContext,
  180475. int timeOutMs)
  180476. {
  180477. if (sessionHandle == 0)
  180478. sessionHandle = InternetOpen (_T("juce"),
  180479. INTERNET_OPEN_TYPE_PRECONFIG,
  180480. 0, 0, 0);
  180481. if (sessionHandle != 0)
  180482. {
  180483. // break up the url..
  180484. TCHAR file[1024], server[1024];
  180485. URL_COMPONENTS uc;
  180486. zerostruct (uc);
  180487. uc.dwStructSize = sizeof (uc);
  180488. uc.dwUrlPathLength = sizeof (file);
  180489. uc.dwHostNameLength = sizeof (server);
  180490. uc.lpszUrlPath = file;
  180491. uc.lpszHostName = server;
  180492. if (InternetCrackUrl (url, 0, 0, &uc))
  180493. {
  180494. int disable = 1;
  180495. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180496. if (timeOutMs == 0)
  180497. timeOutMs = 30000;
  180498. else if (timeOutMs < 0)
  180499. timeOutMs = -1;
  180500. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180501. const bool isFtp = url.startsWithIgnoreCase ("ftp:");
  180502. #if WORKAROUND_TIMEOUT_BUG
  180503. HINTERNET connection = 0;
  180504. {
  180505. InternetConnectThread connectThread (uc, connection, isFtp);
  180506. connectThread.wait (timeOutMs);
  180507. if (connection == 0)
  180508. {
  180509. InternetCloseHandle (sessionHandle);
  180510. sessionHandle = 0;
  180511. }
  180512. }
  180513. #else
  180514. HINTERNET connection = InternetConnect (sessionHandle,
  180515. uc.lpszHostName,
  180516. uc.nPort,
  180517. _T(""), _T(""),
  180518. isFtp ? INTERNET_SERVICE_FTP
  180519. : INTERNET_SERVICE_HTTP,
  180520. 0, 0);
  180521. #endif
  180522. if (connection != 0)
  180523. {
  180524. if (isFtp)
  180525. {
  180526. HINTERNET request = FtpOpenFile (connection,
  180527. uc.lpszUrlPath,
  180528. GENERIC_READ,
  180529. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180530. 0);
  180531. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180532. result->connection = connection;
  180533. result->request = request;
  180534. return result;
  180535. }
  180536. else
  180537. {
  180538. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180539. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180540. if (url.startsWithIgnoreCase ("https:"))
  180541. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180542. // IE7 seems to automatically work out when it's https)
  180543. HINTERNET request = HttpOpenRequest (connection,
  180544. isPost ? _T("POST")
  180545. : _T("GET"),
  180546. uc.lpszUrlPath,
  180547. 0, 0, mimeTypes, flags, 0);
  180548. if (request != 0)
  180549. {
  180550. INTERNET_BUFFERS buffers;
  180551. zerostruct (buffers);
  180552. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180553. buffers.lpcszHeader = (LPCTSTR) headers;
  180554. buffers.dwHeadersLength = headers.length();
  180555. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180556. ConnectionAndRequestStruct* result = 0;
  180557. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180558. {
  180559. int bytesSent = 0;
  180560. for (;;)
  180561. {
  180562. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180563. DWORD bytesDone = 0;
  180564. if (bytesToDo > 0
  180565. && ! InternetWriteFile (request,
  180566. ((const char*) postData.getData()) + bytesSent,
  180567. bytesToDo, &bytesDone))
  180568. {
  180569. break;
  180570. }
  180571. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180572. {
  180573. result = new ConnectionAndRequestStruct();
  180574. result->connection = connection;
  180575. result->request = request;
  180576. HttpEndRequest (request, 0, 0, 0);
  180577. return result;
  180578. }
  180579. bytesSent += bytesDone;
  180580. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180581. break;
  180582. }
  180583. }
  180584. InternetCloseHandle (request);
  180585. }
  180586. InternetCloseHandle (connection);
  180587. }
  180588. }
  180589. }
  180590. }
  180591. return 0;
  180592. }
  180593. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180594. {
  180595. DWORD bytesRead = 0;
  180596. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180597. if (crs != 0)
  180598. InternetReadFile (crs->request,
  180599. buffer, bytesToRead,
  180600. &bytesRead);
  180601. return bytesRead;
  180602. }
  180603. int juce_seekInInternetFile (void* handle, int newPosition)
  180604. {
  180605. if (handle != 0)
  180606. {
  180607. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180608. return InternetSetFilePointer (crs->request,
  180609. newPosition, 0,
  180610. FILE_BEGIN, 0);
  180611. }
  180612. else
  180613. {
  180614. return -1;
  180615. }
  180616. }
  180617. int64 juce_getInternetFileContentLength (void* handle)
  180618. {
  180619. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180620. if (crs != 0)
  180621. {
  180622. DWORD index = 0;
  180623. DWORD result = 0;
  180624. DWORD size = sizeof (result);
  180625. if (HttpQueryInfo (crs->request,
  180626. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180627. &result,
  180628. &size,
  180629. &index))
  180630. {
  180631. return (int64) result;
  180632. }
  180633. }
  180634. return -1;
  180635. }
  180636. void juce_closeInternetFile (void* handle)
  180637. {
  180638. if (handle != 0)
  180639. {
  180640. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  180641. InternetCloseHandle (crs->request);
  180642. InternetCloseHandle (crs->connection);
  180643. delete crs;
  180644. }
  180645. }
  180646. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180647. {
  180648. int numFound = 0;
  180649. DynamicLibraryLoader dll ("iphlpapi.dll");
  180650. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180651. if (getAdaptersInfo != 0)
  180652. {
  180653. ULONG len = sizeof (IP_ADAPTER_INFO);
  180654. MemoryBlock mb;
  180655. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180656. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180657. {
  180658. mb.setSize (len);
  180659. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180660. }
  180661. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180662. {
  180663. PIP_ADAPTER_INFO adapter = adapterInfo;
  180664. while (adapter != 0)
  180665. {
  180666. int64 mac = 0;
  180667. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180668. mac = (mac << 8) | adapter->Address[i];
  180669. if (littleEndian)
  180670. mac = (int64) ByteOrder::swap ((uint64) mac);
  180671. if (numFound < maxNum && mac != 0)
  180672. addresses [numFound++] = mac;
  180673. adapter = adapter->Next;
  180674. }
  180675. }
  180676. }
  180677. return numFound;
  180678. }
  180679. struct ASTAT
  180680. {
  180681. ADAPTER_STATUS adapt;
  180682. NAME_BUFFER NameBuff [30];
  180683. };
  180684. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180685. {
  180686. int numFound = 0;
  180687. DynamicLibraryLoader dll ("netapi32.dll");
  180688. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180689. if (NetbiosCall != 0)
  180690. {
  180691. NCB ncb;
  180692. zerostruct (ncb);
  180693. ASTAT astat;
  180694. zerostruct (astat);
  180695. LANA_ENUM enums;
  180696. zerostruct (enums);
  180697. ncb.ncb_command = NCBENUM;
  180698. ncb.ncb_buffer = (unsigned char*) &enums;
  180699. ncb.ncb_length = sizeof (LANA_ENUM);
  180700. NetbiosCall (&ncb);
  180701. for (int i = 0; i < enums.length; ++i)
  180702. {
  180703. zerostruct (ncb);
  180704. ncb.ncb_command = NCBRESET;
  180705. ncb.ncb_lana_num = enums.lana[i];
  180706. if (NetbiosCall (&ncb) == 0)
  180707. {
  180708. zerostruct (ncb);
  180709. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180710. ncb.ncb_command = NCBASTAT;
  180711. ncb.ncb_lana_num = enums.lana[i];
  180712. ncb.ncb_buffer = (unsigned char*) &astat;
  180713. ncb.ncb_length = sizeof (ASTAT);
  180714. if (NetbiosCall (&ncb) == 0)
  180715. {
  180716. if (astat.adapt.adapter_type == 0xfe)
  180717. {
  180718. uint64 mac = 0;
  180719. for (int i = 6; --i >= 0;)
  180720. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180721. if (numFound < maxNum && mac != 0)
  180722. addresses [numFound++] = mac;
  180723. }
  180724. }
  180725. }
  180726. }
  180727. }
  180728. return numFound;
  180729. }
  180730. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180731. {
  180732. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180733. if (numFound == 0)
  180734. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180735. return numFound;
  180736. }
  180737. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180738. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180739. const String& emailSubject,
  180740. const String& bodyText,
  180741. const StringArray& filesToAttach)
  180742. {
  180743. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180744. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180745. bool ok = false;
  180746. if (mapiSendMail != 0)
  180747. {
  180748. MapiMessage message;
  180749. zerostruct (message);
  180750. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180751. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180752. MapiRecipDesc recip;
  180753. zerostruct (recip);
  180754. recip.ulRecipClass = MAPI_TO;
  180755. String targetEmailAddress_ (targetEmailAddress);
  180756. if (targetEmailAddress_.isEmpty())
  180757. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180758. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180759. message.nRecipCount = 1;
  180760. message.lpRecips = &recip;
  180761. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  180762. mb.fillWith (0);
  180763. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  180764. message.nFileCount = filesToAttach.size();
  180765. message.lpFiles = files;
  180766. for (int i = 0; i < filesToAttach.size(); ++i)
  180767. {
  180768. files[i].nPosition = (ULONG) -1;
  180769. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180770. }
  180771. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180772. }
  180773. FreeLibrary (h);
  180774. return ok;
  180775. }
  180776. #endif
  180777. /*** End of inlined file: juce_win32_Network.cpp ***/
  180778. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180779. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180780. // compiled on its own).
  180781. #if JUCE_INCLUDED_FILE
  180782. static HKEY findKeyForPath (String name,
  180783. const bool createForWriting,
  180784. String& valueName)
  180785. {
  180786. HKEY rootKey = 0;
  180787. if (name.startsWithIgnoreCase ("HKEY_CURRENT_USER\\"))
  180788. rootKey = HKEY_CURRENT_USER;
  180789. else if (name.startsWithIgnoreCase ("HKEY_LOCAL_MACHINE\\"))
  180790. rootKey = HKEY_LOCAL_MACHINE;
  180791. else if (name.startsWithIgnoreCase ("HKEY_CLASSES_ROOT\\"))
  180792. rootKey = HKEY_CLASSES_ROOT;
  180793. if (rootKey != 0)
  180794. {
  180795. name = name.substring (name.indexOfChar ('\\') + 1);
  180796. const int lastSlash = name.lastIndexOfChar ('\\');
  180797. valueName = name.substring (lastSlash + 1);
  180798. name = name.substring (0, lastSlash);
  180799. HKEY key;
  180800. DWORD result;
  180801. if (createForWriting)
  180802. {
  180803. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180804. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180805. return key;
  180806. }
  180807. else
  180808. {
  180809. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180810. return key;
  180811. }
  180812. }
  180813. return 0;
  180814. }
  180815. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180816. const String& defaultValue)
  180817. {
  180818. String valueName, result (defaultValue);
  180819. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180820. if (k != 0)
  180821. {
  180822. WCHAR buffer [2048];
  180823. unsigned long bufferSize = sizeof (buffer);
  180824. DWORD type = REG_SZ;
  180825. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180826. {
  180827. if (type == REG_SZ)
  180828. result = buffer;
  180829. else if (type == REG_DWORD)
  180830. result = String ((int) *(DWORD*) buffer);
  180831. }
  180832. RegCloseKey (k);
  180833. }
  180834. return result;
  180835. }
  180836. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180837. const String& value)
  180838. {
  180839. String valueName;
  180840. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180841. if (k != 0)
  180842. {
  180843. RegSetValueEx (k, valueName, 0, REG_SZ,
  180844. (const BYTE*) (const WCHAR*) value,
  180845. sizeof (WCHAR) * (value.length() + 1));
  180846. RegCloseKey (k);
  180847. }
  180848. }
  180849. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  180850. {
  180851. bool exists = false;
  180852. String valueName;
  180853. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180854. if (k != 0)
  180855. {
  180856. unsigned char buffer [2048];
  180857. unsigned long bufferSize = sizeof (buffer);
  180858. DWORD type = 0;
  180859. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  180860. exists = true;
  180861. RegCloseKey (k);
  180862. }
  180863. return exists;
  180864. }
  180865. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  180866. {
  180867. String valueName;
  180868. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180869. if (k != 0)
  180870. {
  180871. RegDeleteValue (k, valueName);
  180872. RegCloseKey (k);
  180873. }
  180874. }
  180875. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  180876. {
  180877. String valueName;
  180878. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  180879. if (k != 0)
  180880. {
  180881. RegDeleteKey (k, valueName);
  180882. RegCloseKey (k);
  180883. }
  180884. }
  180885. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  180886. const String& symbolicDescription,
  180887. const String& fullDescription,
  180888. const File& targetExecutable,
  180889. int iconResourceNumber)
  180890. {
  180891. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  180892. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  180893. if (iconResourceNumber != 0)
  180894. setRegistryValue (key + "\\DefaultIcon\\",
  180895. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  180896. setRegistryValue (key + "\\", fullDescription);
  180897. setRegistryValue (key + "\\shell\\open\\command\\",
  180898. targetExecutable.getFullPathName() + " %1");
  180899. }
  180900. bool juce_IsRunningInWine()
  180901. {
  180902. HKEY key;
  180903. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  180904. {
  180905. RegCloseKey (key);
  180906. return true;
  180907. }
  180908. return false;
  180909. }
  180910. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  180911. {
  180912. String s (::GetCommandLineW());
  180913. StringArray tokens;
  180914. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  180915. return tokens.joinIntoString (" ", 1);
  180916. }
  180917. static void* currentModuleHandle = 0;
  180918. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  180919. {
  180920. if (currentModuleHandle == 0)
  180921. currentModuleHandle = GetModuleHandle (0);
  180922. return currentModuleHandle;
  180923. }
  180924. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  180925. {
  180926. currentModuleHandle = newHandle;
  180927. }
  180928. void PlatformUtilities::fpuReset()
  180929. {
  180930. #if JUCE_MSVC
  180931. _clearfp();
  180932. #endif
  180933. }
  180934. void PlatformUtilities::beep()
  180935. {
  180936. MessageBeep (MB_OK);
  180937. }
  180938. #endif
  180939. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  180940. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180941. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  180942. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180943. // compiled on its own).
  180944. #if JUCE_INCLUDED_FILE
  180945. static const unsigned int specialId = WM_APP + 0x4400;
  180946. static const unsigned int broadcastId = WM_APP + 0x4403;
  180947. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  180948. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  180949. HWND juce_messageWindowHandle = 0;
  180950. extern long improbableWindowNumber; // defined in windowing.cpp
  180951. #ifndef WM_APPCOMMAND
  180952. #define WM_APPCOMMAND 0x0319
  180953. #endif
  180954. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  180955. const UINT message,
  180956. const WPARAM wParam,
  180957. const LPARAM lParam) throw()
  180958. {
  180959. JUCE_TRY
  180960. {
  180961. if (h == juce_messageWindowHandle)
  180962. {
  180963. if (message == specialCallbackId)
  180964. {
  180965. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  180966. return (LRESULT) (*func) ((void*) lParam);
  180967. }
  180968. else if (message == specialId)
  180969. {
  180970. // these are trapped early in the dispatch call, but must also be checked
  180971. // here in case there are windows modal dialog boxes doing their own
  180972. // dispatch loop and not calling our version
  180973. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  180974. return 0;
  180975. }
  180976. else if (message == broadcastId)
  180977. {
  180978. const ScopedPointer <String> messageString ((String*) lParam);
  180979. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  180980. return 0;
  180981. }
  180982. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  180983. {
  180984. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  180985. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  180986. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  180987. return 0;
  180988. }
  180989. }
  180990. }
  180991. JUCE_CATCH_EXCEPTION
  180992. return DefWindowProc (h, message, wParam, lParam);
  180993. }
  180994. static bool isEventBlockedByModalComps (MSG& m)
  180995. {
  180996. if (Component::getNumCurrentlyModalComponents() == 0
  180997. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  180998. return false;
  180999. switch (m.message)
  181000. {
  181001. case WM_MOUSEMOVE:
  181002. case WM_NCMOUSEMOVE:
  181003. case 0x020A: /* WM_MOUSEWHEEL */
  181004. case 0x020E: /* WM_MOUSEHWHEEL */
  181005. case WM_KEYUP:
  181006. case WM_SYSKEYUP:
  181007. case WM_CHAR:
  181008. case WM_APPCOMMAND:
  181009. case WM_LBUTTONUP:
  181010. case WM_MBUTTONUP:
  181011. case WM_RBUTTONUP:
  181012. case WM_MOUSEACTIVATE:
  181013. case WM_NCMOUSEHOVER:
  181014. case WM_MOUSEHOVER:
  181015. return true;
  181016. case WM_NCLBUTTONDOWN:
  181017. case WM_NCLBUTTONDBLCLK:
  181018. case WM_NCRBUTTONDOWN:
  181019. case WM_NCRBUTTONDBLCLK:
  181020. case WM_NCMBUTTONDOWN:
  181021. case WM_NCMBUTTONDBLCLK:
  181022. case WM_LBUTTONDOWN:
  181023. case WM_LBUTTONDBLCLK:
  181024. case WM_MBUTTONDOWN:
  181025. case WM_MBUTTONDBLCLK:
  181026. case WM_RBUTTONDOWN:
  181027. case WM_RBUTTONDBLCLK:
  181028. case WM_KEYDOWN:
  181029. case WM_SYSKEYDOWN:
  181030. {
  181031. Component* const modal = Component::getCurrentlyModalComponent (0);
  181032. if (modal != 0)
  181033. modal->inputAttemptWhenModal();
  181034. return true;
  181035. }
  181036. default:
  181037. break;
  181038. }
  181039. return false;
  181040. }
  181041. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181042. {
  181043. MSG m;
  181044. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181045. return false;
  181046. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181047. {
  181048. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181049. {
  181050. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181051. }
  181052. else if (m.message == WM_QUIT)
  181053. {
  181054. if (JUCEApplication::getInstance())
  181055. JUCEApplication::getInstance()->systemRequestedQuit();
  181056. }
  181057. else if (! isEventBlockedByModalComps (m))
  181058. {
  181059. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181060. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181061. {
  181062. // if it's someone else's window being clicked on, and the focus is
  181063. // currently on a juce window, pass the kb focus over..
  181064. HWND currentFocus = GetFocus();
  181065. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181066. SetFocus (m.hwnd);
  181067. }
  181068. TranslateMessage (&m);
  181069. DispatchMessage (&m);
  181070. }
  181071. }
  181072. return true;
  181073. }
  181074. bool juce_postMessageToSystemQueue (void* message)
  181075. {
  181076. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181077. }
  181078. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181079. void* userData)
  181080. {
  181081. if (MessageManager::getInstance()->isThisTheMessageThread())
  181082. {
  181083. return (*callback) (userData);
  181084. }
  181085. else
  181086. {
  181087. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181088. // deadlock because the message manager is blocked from running, and can't
  181089. // call your function..
  181090. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181091. return (void*) SendMessage (juce_messageWindowHandle,
  181092. specialCallbackId,
  181093. (WPARAM) callback,
  181094. (LPARAM) userData);
  181095. }
  181096. }
  181097. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181098. {
  181099. if (hwnd != juce_messageWindowHandle)
  181100. reinterpret_cast <VoidArray*> (lParam)->add ((void*) hwnd);
  181101. return TRUE;
  181102. }
  181103. void MessageManager::broadcastMessage (const String& value) throw()
  181104. {
  181105. VoidArray windows;
  181106. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181107. const String localCopy (value);
  181108. COPYDATASTRUCT data;
  181109. data.dwData = broadcastId;
  181110. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181111. data.lpData = (void*) (const juce_wchar*) localCopy;
  181112. for (int i = windows.size(); --i >= 0;)
  181113. {
  181114. HWND hwnd = (HWND) windows.getUnchecked(i);
  181115. TCHAR windowName [64]; // no need to read longer strings than this
  181116. GetWindowText (hwnd, windowName, 64);
  181117. windowName [63] = 0;
  181118. if (String (windowName) == String (messageWindowName))
  181119. {
  181120. DWORD_PTR result;
  181121. SendMessageTimeout (hwnd, WM_COPYDATA,
  181122. (WPARAM) juce_messageWindowHandle,
  181123. (LPARAM) &data,
  181124. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181125. 8000,
  181126. &result);
  181127. }
  181128. }
  181129. }
  181130. static const String getMessageWindowClassName()
  181131. {
  181132. // this name has to be different for each app/dll instance because otherwise
  181133. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181134. // window class).
  181135. static int number = 0;
  181136. if (number == 0)
  181137. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181138. return "JUCEcs_" + String (number);
  181139. }
  181140. void MessageManager::doPlatformSpecificInitialisation()
  181141. {
  181142. OleInitialize (0);
  181143. const String className (getMessageWindowClassName());
  181144. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181145. WNDCLASSEX wc;
  181146. zerostruct (wc);
  181147. wc.cbSize = sizeof (wc);
  181148. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181149. wc.cbWndExtra = 4;
  181150. wc.hInstance = hmod;
  181151. wc.lpszClassName = className;
  181152. RegisterClassEx (&wc);
  181153. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181154. messageWindowName,
  181155. 0, 0, 0, 0, 0, 0, 0,
  181156. hmod, 0);
  181157. }
  181158. void MessageManager::doPlatformSpecificShutdown()
  181159. {
  181160. DestroyWindow (juce_messageWindowHandle);
  181161. UnregisterClass (getMessageWindowClassName(), 0);
  181162. OleUninitialize();
  181163. }
  181164. #endif
  181165. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181166. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181167. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181168. // compiled on its own).
  181169. #if JUCE_INCLUDED_FILE
  181170. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181171. // these are in the windows SDK, but need to be repeated here for GCC..
  181172. #ifndef GET_APPCOMMAND_LPARAM
  181173. #define FAPPCOMMAND_MASK 0xF000
  181174. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181175. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181176. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181177. #define APPCOMMAND_MEDIA_STOP 13
  181178. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181179. #define WM_APPCOMMAND 0x0319
  181180. #endif
  181181. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181182. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181183. extern bool juce_IsRunningInWine();
  181184. #ifndef ULW_ALPHA
  181185. #define ULW_ALPHA 0x00000002
  181186. #endif
  181187. #ifndef AC_SRC_ALPHA
  181188. #define AC_SRC_ALPHA 0x01
  181189. #endif
  181190. static HPALETTE palette = 0;
  181191. static bool createPaletteIfNeeded = true;
  181192. static bool shouldDeactivateTitleBar = true;
  181193. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181194. #define WM_TRAYNOTIFY WM_USER + 100
  181195. using ::abs;
  181196. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181197. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181198. bool Desktop::canUseSemiTransparentWindows() throw()
  181199. {
  181200. if (updateLayeredWindow == 0)
  181201. {
  181202. if (! juce_IsRunningInWine())
  181203. {
  181204. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181205. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181206. }
  181207. }
  181208. return updateLayeredWindow != 0;
  181209. }
  181210. const int extendedKeyModifier = 0x10000;
  181211. const int KeyPress::spaceKey = VK_SPACE;
  181212. const int KeyPress::returnKey = VK_RETURN;
  181213. const int KeyPress::escapeKey = VK_ESCAPE;
  181214. const int KeyPress::backspaceKey = VK_BACK;
  181215. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181216. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181217. const int KeyPress::tabKey = VK_TAB;
  181218. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181219. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181220. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181221. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181222. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181223. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181224. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181225. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181226. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181227. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181228. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181229. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181230. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181231. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181232. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181233. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181234. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181235. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181236. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181237. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181238. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181239. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181240. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181241. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181242. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181243. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181244. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181245. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181246. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181247. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181248. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181249. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181250. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181251. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181252. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181253. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181254. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181255. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181256. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181257. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181258. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181259. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181260. const int KeyPress::playKey = 0x30000;
  181261. const int KeyPress::stopKey = 0x30001;
  181262. const int KeyPress::fastForwardKey = 0x30002;
  181263. const int KeyPress::rewindKey = 0x30003;
  181264. class WindowsBitmapImage : public Image
  181265. {
  181266. public:
  181267. HBITMAP hBitmap;
  181268. BITMAPV4HEADER bitmapInfo;
  181269. HDC hdc;
  181270. unsigned char* bitmapData;
  181271. WindowsBitmapImage (const PixelFormat format_,
  181272. const int w, const int h, const bool clearImage)
  181273. : Image (format_, w, h)
  181274. {
  181275. jassert (format_ == RGB || format_ == ARGB);
  181276. pixelStride = (format_ == RGB) ? 3 : 4;
  181277. zerostruct (bitmapInfo);
  181278. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181279. bitmapInfo.bV4Width = w;
  181280. bitmapInfo.bV4Height = h;
  181281. bitmapInfo.bV4Planes = 1;
  181282. bitmapInfo.bV4CSType = 1;
  181283. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181284. if (format_ == ARGB)
  181285. {
  181286. bitmapInfo.bV4AlphaMask = 0xff000000;
  181287. bitmapInfo.bV4RedMask = 0xff0000;
  181288. bitmapInfo.bV4GreenMask = 0xff00;
  181289. bitmapInfo.bV4BlueMask = 0xff;
  181290. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181291. }
  181292. else
  181293. {
  181294. bitmapInfo.bV4V4Compression = BI_RGB;
  181295. }
  181296. lineStride = -((w * pixelStride + 3) & ~3);
  181297. HDC dc = GetDC (0);
  181298. hdc = CreateCompatibleDC (dc);
  181299. ReleaseDC (0, dc);
  181300. SetMapMode (hdc, MM_TEXT);
  181301. hBitmap = CreateDIBSection (hdc,
  181302. (BITMAPINFO*) &(bitmapInfo),
  181303. DIB_RGB_COLORS,
  181304. (void**) &bitmapData,
  181305. 0, 0);
  181306. SelectObject (hdc, hBitmap);
  181307. if (format_ == ARGB && clearImage)
  181308. zeromem (bitmapData, abs (h * lineStride));
  181309. imageData = bitmapData - (lineStride * (h - 1));
  181310. }
  181311. ~WindowsBitmapImage()
  181312. {
  181313. DeleteDC (hdc);
  181314. DeleteObject (hBitmap);
  181315. }
  181316. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181317. const int x, const int y,
  181318. const RectangleList& maskedRegion) throw()
  181319. {
  181320. static HDRAWDIB hdd = 0;
  181321. static bool needToCreateDrawDib = true;
  181322. if (needToCreateDrawDib)
  181323. {
  181324. needToCreateDrawDib = false;
  181325. HDC dc = GetDC (0);
  181326. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181327. ReleaseDC (0, dc);
  181328. // only open if we're not palettised
  181329. if (n > 8)
  181330. hdd = DrawDibOpen();
  181331. }
  181332. if (createPaletteIfNeeded)
  181333. {
  181334. HDC dc = GetDC (0);
  181335. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181336. ReleaseDC (0, dc);
  181337. if (n <= 8)
  181338. palette = CreateHalftonePalette (dc);
  181339. createPaletteIfNeeded = false;
  181340. }
  181341. if (palette != 0)
  181342. {
  181343. SelectPalette (dc, palette, FALSE);
  181344. RealizePalette (dc);
  181345. SetStretchBltMode (dc, HALFTONE);
  181346. }
  181347. SetMapMode (dc, MM_TEXT);
  181348. if (transparent)
  181349. {
  181350. POINT p, pos;
  181351. SIZE size;
  181352. RECT windowBounds;
  181353. GetWindowRect (hwnd, &windowBounds);
  181354. p.x = -x;
  181355. p.y = -y;
  181356. pos.x = windowBounds.left;
  181357. pos.y = windowBounds.top;
  181358. size.cx = windowBounds.right - windowBounds.left;
  181359. size.cy = windowBounds.bottom - windowBounds.top;
  181360. BLENDFUNCTION bf;
  181361. bf.AlphaFormat = AC_SRC_ALPHA;
  181362. bf.BlendFlags = 0;
  181363. bf.BlendOp = AC_SRC_OVER;
  181364. bf.SourceConstantAlpha = 0xff;
  181365. if (! maskedRegion.isEmpty())
  181366. {
  181367. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181368. {
  181369. const Rectangle<int>& r = *i.getRectangle();
  181370. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181371. }
  181372. }
  181373. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181374. }
  181375. else
  181376. {
  181377. int savedDC = 0;
  181378. if (! maskedRegion.isEmpty())
  181379. {
  181380. savedDC = SaveDC (dc);
  181381. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181382. {
  181383. const Rectangle<int>& r = *i.getRectangle();
  181384. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181385. }
  181386. }
  181387. const int w = getWidth();
  181388. const int h = getHeight();
  181389. if (hdd == 0)
  181390. {
  181391. StretchDIBits (dc,
  181392. x, y, w, h,
  181393. 0, 0, w, h,
  181394. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181395. DIB_RGB_COLORS, SRCCOPY);
  181396. }
  181397. else
  181398. {
  181399. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181400. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181401. 0, 0, w, h, 0);
  181402. }
  181403. if (! maskedRegion.isEmpty())
  181404. RestoreDC (dc, savedDC);
  181405. }
  181406. }
  181407. juce_UseDebuggingNewOperator
  181408. private:
  181409. WindowsBitmapImage (const WindowsBitmapImage&);
  181410. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181411. };
  181412. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181413. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181414. {
  181415. SHORT k = (SHORT) keyCode;
  181416. if ((keyCode & extendedKeyModifier) == 0
  181417. && (k >= (SHORT) 'a' && k <= (SHORT) 'z'))
  181418. k += (SHORT) 'A' - (SHORT) 'a';
  181419. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181420. (SHORT) '+', VK_OEM_PLUS,
  181421. (SHORT) '-', VK_OEM_MINUS,
  181422. (SHORT) '.', VK_OEM_PERIOD,
  181423. (SHORT) ';', VK_OEM_1,
  181424. (SHORT) ':', VK_OEM_1,
  181425. (SHORT) '/', VK_OEM_2,
  181426. (SHORT) '?', VK_OEM_2,
  181427. (SHORT) '[', VK_OEM_4,
  181428. (SHORT) ']', VK_OEM_6 };
  181429. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181430. if (k == translatedValues [i])
  181431. k = translatedValues [i + 1];
  181432. return (GetKeyState (k) & 0x8000) != 0;
  181433. }
  181434. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181435. {
  181436. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181437. return callback (userData);
  181438. else
  181439. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181440. }
  181441. class Win32ComponentPeer : public ComponentPeer
  181442. {
  181443. public:
  181444. Win32ComponentPeer (Component* const component,
  181445. const int windowStyleFlags)
  181446. : ComponentPeer (component, windowStyleFlags),
  181447. dontRepaint (false),
  181448. fullScreen (false),
  181449. isDragging (false),
  181450. isMouseOver (false),
  181451. hasCreatedCaret (false),
  181452. currentWindowIcon (0),
  181453. taskBarIcon (0),
  181454. dropTarget (0)
  181455. {
  181456. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181457. setTitle (component->getName());
  181458. if ((windowStyleFlags & windowHasDropShadow) != 0
  181459. && Desktop::canUseSemiTransparentWindows())
  181460. {
  181461. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181462. if (shadower != 0)
  181463. shadower->setOwner (component);
  181464. }
  181465. else
  181466. {
  181467. shadower = 0;
  181468. }
  181469. }
  181470. ~Win32ComponentPeer()
  181471. {
  181472. setTaskBarIcon (0);
  181473. deleteAndZero (shadower);
  181474. // do this before the next bit to avoid messages arriving for this window
  181475. // before it's destroyed
  181476. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181477. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181478. if (currentWindowIcon != 0)
  181479. DestroyIcon (currentWindowIcon);
  181480. if (dropTarget != 0)
  181481. {
  181482. dropTarget->Release();
  181483. dropTarget = 0;
  181484. }
  181485. }
  181486. void* getNativeHandle() const
  181487. {
  181488. return (void*) hwnd;
  181489. }
  181490. void setVisible (bool shouldBeVisible)
  181491. {
  181492. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181493. if (shouldBeVisible)
  181494. InvalidateRect (hwnd, 0, 0);
  181495. else
  181496. lastPaintTime = 0;
  181497. }
  181498. void setTitle (const String& title)
  181499. {
  181500. SetWindowText (hwnd, title);
  181501. }
  181502. void setPosition (int x, int y)
  181503. {
  181504. offsetWithinParent (x, y);
  181505. SetWindowPos (hwnd, 0,
  181506. x - windowBorder.getLeft(),
  181507. y - windowBorder.getTop(),
  181508. 0, 0,
  181509. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181510. }
  181511. void repaintNowIfTransparent()
  181512. {
  181513. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181514. handlePaintMessage();
  181515. }
  181516. void updateBorderSize()
  181517. {
  181518. WINDOWINFO info;
  181519. info.cbSize = sizeof (info);
  181520. if (GetWindowInfo (hwnd, &info))
  181521. {
  181522. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181523. info.rcClient.left - info.rcWindow.left,
  181524. info.rcWindow.bottom - info.rcClient.bottom,
  181525. info.rcWindow.right - info.rcClient.right);
  181526. }
  181527. }
  181528. void setSize (int w, int h)
  181529. {
  181530. SetWindowPos (hwnd, 0, 0, 0,
  181531. w + windowBorder.getLeftAndRight(),
  181532. h + windowBorder.getTopAndBottom(),
  181533. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181534. updateBorderSize();
  181535. repaintNowIfTransparent();
  181536. }
  181537. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  181538. {
  181539. fullScreen = isNowFullScreen;
  181540. offsetWithinParent (x, y);
  181541. SetWindowPos (hwnd, 0,
  181542. x - windowBorder.getLeft(),
  181543. y - windowBorder.getTop(),
  181544. w + windowBorder.getLeftAndRight(),
  181545. h + windowBorder.getTopAndBottom(),
  181546. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181547. updateBorderSize();
  181548. repaintNowIfTransparent();
  181549. }
  181550. const Rectangle<int> getBounds() const
  181551. {
  181552. RECT r;
  181553. GetWindowRect (hwnd, &r);
  181554. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181555. HWND parentH = GetParent (hwnd);
  181556. if (parentH != 0)
  181557. {
  181558. GetWindowRect (parentH, &r);
  181559. bounds.translate (-r.left, -r.top);
  181560. }
  181561. return windowBorder.subtractedFrom (bounds);
  181562. }
  181563. const Point<int> getScreenPosition() const
  181564. {
  181565. RECT r;
  181566. GetWindowRect (hwnd, &r);
  181567. return Point<int> (r.left + windowBorder.getLeft(),
  181568. r.top + windowBorder.getTop());
  181569. }
  181570. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181571. {
  181572. return relativePosition + getScreenPosition();
  181573. }
  181574. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181575. {
  181576. return screenPosition - getScreenPosition();
  181577. }
  181578. void setMinimised (bool shouldBeMinimised)
  181579. {
  181580. if (shouldBeMinimised != isMinimised())
  181581. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181582. }
  181583. bool isMinimised() const
  181584. {
  181585. WINDOWPLACEMENT wp;
  181586. wp.length = sizeof (WINDOWPLACEMENT);
  181587. GetWindowPlacement (hwnd, &wp);
  181588. return wp.showCmd == SW_SHOWMINIMIZED;
  181589. }
  181590. void setFullScreen (bool shouldBeFullScreen)
  181591. {
  181592. setMinimised (false);
  181593. if (fullScreen != shouldBeFullScreen)
  181594. {
  181595. fullScreen = shouldBeFullScreen;
  181596. const Component::SafePointer<Component> deletionChecker (component);
  181597. if (! fullScreen)
  181598. {
  181599. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181600. if (hasTitleBar())
  181601. ShowWindow (hwnd, SW_SHOWNORMAL);
  181602. if (! boundsCopy.isEmpty())
  181603. {
  181604. setBounds (boundsCopy.getX(),
  181605. boundsCopy.getY(),
  181606. boundsCopy.getWidth(),
  181607. boundsCopy.getHeight(),
  181608. false);
  181609. }
  181610. }
  181611. else
  181612. {
  181613. if (hasTitleBar())
  181614. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181615. else
  181616. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181617. }
  181618. if (deletionChecker != 0)
  181619. handleMovedOrResized();
  181620. }
  181621. }
  181622. bool isFullScreen() const
  181623. {
  181624. if (! hasTitleBar())
  181625. return fullScreen;
  181626. WINDOWPLACEMENT wp;
  181627. wp.length = sizeof (wp);
  181628. GetWindowPlacement (hwnd, &wp);
  181629. return wp.showCmd == SW_SHOWMAXIMIZED;
  181630. }
  181631. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181632. {
  181633. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181634. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181635. return false;
  181636. RECT r;
  181637. GetWindowRect (hwnd, &r);
  181638. POINT p;
  181639. p.x = position.getX() + r.left + windowBorder.getLeft();
  181640. p.y = position.getY() + r.top + windowBorder.getTop();
  181641. HWND w = WindowFromPoint (p);
  181642. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181643. }
  181644. const BorderSize getFrameSize() const
  181645. {
  181646. return windowBorder;
  181647. }
  181648. bool setAlwaysOnTop (bool alwaysOnTop)
  181649. {
  181650. const bool oldDeactivate = shouldDeactivateTitleBar;
  181651. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181652. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181653. 0, 0, 0, 0,
  181654. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181655. shouldDeactivateTitleBar = oldDeactivate;
  181656. if (shadower != 0)
  181657. shadower->componentBroughtToFront (*component);
  181658. return true;
  181659. }
  181660. void toFront (bool makeActive)
  181661. {
  181662. setMinimised (false);
  181663. const bool oldDeactivate = shouldDeactivateTitleBar;
  181664. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181665. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  181666. : &toFrontCallback2,
  181667. (void*) hwnd);
  181668. shouldDeactivateTitleBar = oldDeactivate;
  181669. if (! makeActive)
  181670. {
  181671. // in this case a broughttofront call won't have occured, so do it now..
  181672. handleBroughtToFront();
  181673. }
  181674. }
  181675. void toBehind (ComponentPeer* other)
  181676. {
  181677. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181678. jassert (otherPeer != 0); // wrong type of window?
  181679. if (otherPeer != 0)
  181680. {
  181681. setMinimised (false);
  181682. // must be careful not to try to put a topmost window behind a normal one, or win32
  181683. // promotes the normal one to be topmost!
  181684. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181685. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181686. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181687. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181688. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181689. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181690. }
  181691. }
  181692. bool isFocused() const
  181693. {
  181694. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181695. }
  181696. void grabFocus()
  181697. {
  181698. const bool oldDeactivate = shouldDeactivateTitleBar;
  181699. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181700. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  181701. shouldDeactivateTitleBar = oldDeactivate;
  181702. }
  181703. void textInputRequired (const Point<int>&)
  181704. {
  181705. if (! hasCreatedCaret)
  181706. {
  181707. hasCreatedCaret = true;
  181708. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181709. }
  181710. ShowCaret (hwnd);
  181711. SetCaretPos (0, 0);
  181712. }
  181713. void repaint (int x, int y, int w, int h)
  181714. {
  181715. const RECT r = { x, y, x + w, y + h };
  181716. InvalidateRect (hwnd, &r, FALSE);
  181717. }
  181718. void performAnyPendingRepaintsNow()
  181719. {
  181720. MSG m;
  181721. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181722. DispatchMessage (&m);
  181723. }
  181724. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181725. {
  181726. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181727. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181728. return 0;
  181729. }
  181730. void setTaskBarIcon (const Image* const image)
  181731. {
  181732. if (image != 0)
  181733. {
  181734. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181735. if (taskBarIcon == 0)
  181736. {
  181737. taskBarIcon = new NOTIFYICONDATA();
  181738. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181739. taskBarIcon->hWnd = (HWND) hwnd;
  181740. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181741. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181742. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181743. taskBarIcon->hIcon = hicon;
  181744. taskBarIcon->szTip[0] = 0;
  181745. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181746. }
  181747. else
  181748. {
  181749. HICON oldIcon = taskBarIcon->hIcon;
  181750. taskBarIcon->hIcon = hicon;
  181751. taskBarIcon->uFlags = NIF_ICON;
  181752. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181753. DestroyIcon (oldIcon);
  181754. }
  181755. DestroyIcon (hicon);
  181756. }
  181757. else if (taskBarIcon != 0)
  181758. {
  181759. taskBarIcon->uFlags = 0;
  181760. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181761. DestroyIcon (taskBarIcon->hIcon);
  181762. deleteAndZero (taskBarIcon);
  181763. }
  181764. }
  181765. void setTaskBarIconToolTip (const String& toolTip) const
  181766. {
  181767. if (taskBarIcon != 0)
  181768. {
  181769. taskBarIcon->uFlags = NIF_TIP;
  181770. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181771. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181772. }
  181773. }
  181774. bool isInside (HWND h) const
  181775. {
  181776. return GetAncestor (hwnd, GA_ROOT) == h;
  181777. }
  181778. static void updateKeyModifiers() throw()
  181779. {
  181780. int keyMods = 0;
  181781. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181782. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181783. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181784. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181785. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181786. }
  181787. static void updateModifiersFromWParam (const WPARAM wParam)
  181788. {
  181789. int mouseMods = 0;
  181790. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181791. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181792. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181793. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181794. updateKeyModifiers();
  181795. }
  181796. static int64 getMouseEventTime()
  181797. {
  181798. static int64 eventTimeOffset = 0;
  181799. static DWORD lastMessageTime = 0;
  181800. const DWORD thisMessageTime = GetMessageTime();
  181801. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181802. {
  181803. lastMessageTime = thisMessageTime;
  181804. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181805. }
  181806. return eventTimeOffset + thisMessageTime;
  181807. }
  181808. juce_UseDebuggingNewOperator
  181809. bool dontRepaint;
  181810. static ModifierKeys currentModifiers;
  181811. static ModifierKeys modifiersAtLastCallback;
  181812. private:
  181813. HWND hwnd;
  181814. DropShadower* shadower;
  181815. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181816. BorderSize windowBorder;
  181817. HICON currentWindowIcon;
  181818. NOTIFYICONDATA* taskBarIcon;
  181819. IDropTarget* dropTarget;
  181820. class TemporaryImage : public Timer
  181821. {
  181822. public:
  181823. TemporaryImage()
  181824. : image (0)
  181825. {
  181826. }
  181827. ~TemporaryImage()
  181828. {
  181829. delete image;
  181830. }
  181831. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181832. {
  181833. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181834. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181835. {
  181836. delete image;
  181837. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181838. }
  181839. startTimer (3000);
  181840. return image;
  181841. }
  181842. void timerCallback()
  181843. {
  181844. stopTimer();
  181845. deleteAndZero (image);
  181846. }
  181847. private:
  181848. WindowsBitmapImage* image;
  181849. TemporaryImage (const TemporaryImage&);
  181850. TemporaryImage& operator= (const TemporaryImage&);
  181851. };
  181852. TemporaryImage offscreenImageGenerator;
  181853. class WindowClassHolder : public DeletedAtShutdown
  181854. {
  181855. public:
  181856. WindowClassHolder()
  181857. : windowClassName ("JUCE_")
  181858. {
  181859. // this name has to be different for each app/dll instance because otherwise
  181860. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181861. // window class).
  181862. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  181863. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181864. TCHAR moduleFile [1024];
  181865. moduleFile[0] = 0;
  181866. GetModuleFileName (moduleHandle, moduleFile, 1024);
  181867. WORD iconNum = 0;
  181868. WNDCLASSEX wcex;
  181869. wcex.cbSize = sizeof (wcex);
  181870. wcex.style = CS_OWNDC;
  181871. wcex.lpfnWndProc = (WNDPROC) windowProc;
  181872. wcex.lpszClassName = windowClassName;
  181873. wcex.cbClsExtra = 0;
  181874. wcex.cbWndExtra = 32;
  181875. wcex.hInstance = moduleHandle;
  181876. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181877. iconNum = 1;
  181878. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181879. wcex.hCursor = 0;
  181880. wcex.hbrBackground = 0;
  181881. wcex.lpszMenuName = 0;
  181882. RegisterClassEx (&wcex);
  181883. }
  181884. ~WindowClassHolder()
  181885. {
  181886. if (ComponentPeer::getNumPeers() == 0)
  181887. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  181888. clearSingletonInstance();
  181889. }
  181890. String windowClassName;
  181891. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  181892. };
  181893. static void* createWindowCallback (void* userData)
  181894. {
  181895. ((Win32ComponentPeer*) userData)->createWindow();
  181896. return 0;
  181897. }
  181898. void createWindow()
  181899. {
  181900. DWORD exstyle = WS_EX_ACCEPTFILES;
  181901. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  181902. if (hasTitleBar())
  181903. {
  181904. type |= WS_OVERLAPPED;
  181905. exstyle |= WS_EX_APPWINDOW;
  181906. if ((styleFlags & windowHasCloseButton) != 0)
  181907. {
  181908. type |= WS_SYSMENU;
  181909. }
  181910. else
  181911. {
  181912. // annoyingly, windows won't let you have a min/max button without a close button
  181913. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  181914. }
  181915. if ((styleFlags & windowIsResizable) != 0)
  181916. type |= WS_THICKFRAME;
  181917. }
  181918. else
  181919. {
  181920. type |= WS_POPUP | WS_SYSMENU;
  181921. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  181922. exstyle |= WS_EX_TOOLWINDOW;
  181923. else
  181924. exstyle |= WS_EX_APPWINDOW;
  181925. }
  181926. if ((styleFlags & windowHasMinimiseButton) != 0)
  181927. type |= WS_MINIMIZEBOX;
  181928. if ((styleFlags & windowHasMaximiseButton) != 0)
  181929. type |= WS_MAXIMIZEBOX;
  181930. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  181931. exstyle |= WS_EX_TRANSPARENT;
  181932. if ((styleFlags & windowIsSemiTransparent) != 0
  181933. && Desktop::canUseSemiTransparentWindows())
  181934. exstyle |= WS_EX_LAYERED;
  181935. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  181936. if (hwnd != 0)
  181937. {
  181938. SetWindowLongPtr (hwnd, 0, 0);
  181939. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  181940. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  181941. if (dropTarget == 0)
  181942. dropTarget = new JuceDropTarget (this);
  181943. RegisterDragDrop (hwnd, dropTarget);
  181944. updateBorderSize();
  181945. // Calling this function here is (for some reason) necessary to make Windows
  181946. // correctly enable the menu items that we specify in the wm_initmenu message.
  181947. GetSystemMenu (hwnd, false);
  181948. }
  181949. else
  181950. {
  181951. jassertfalse
  181952. }
  181953. }
  181954. static void* destroyWindowCallback (void* handle)
  181955. {
  181956. RevokeDragDrop ((HWND) handle);
  181957. DestroyWindow ((HWND) handle);
  181958. return 0;
  181959. }
  181960. static void* toFrontCallback1 (void* h)
  181961. {
  181962. SetForegroundWindow ((HWND) h);
  181963. return 0;
  181964. }
  181965. static void* toFrontCallback2 (void* h)
  181966. {
  181967. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181968. return 0;
  181969. }
  181970. static void* setFocusCallback (void* h)
  181971. {
  181972. SetFocus ((HWND) h);
  181973. return 0;
  181974. }
  181975. static void* getFocusCallback (void*)
  181976. {
  181977. return (void*) GetFocus();
  181978. }
  181979. void offsetWithinParent (int& x, int& y) const
  181980. {
  181981. if (isTransparent())
  181982. {
  181983. HWND parentHwnd = GetParent (hwnd);
  181984. if (parentHwnd != 0)
  181985. {
  181986. RECT parentRect;
  181987. GetWindowRect (parentHwnd, &parentRect);
  181988. x += parentRect.left;
  181989. y += parentRect.top;
  181990. }
  181991. }
  181992. }
  181993. bool isTransparent() const
  181994. {
  181995. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  181996. }
  181997. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  181998. void setIcon (const Image& newIcon)
  181999. {
  182000. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182001. if (hicon != 0)
  182002. {
  182003. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182004. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182005. if (currentWindowIcon != 0)
  182006. DestroyIcon (currentWindowIcon);
  182007. currentWindowIcon = hicon;
  182008. }
  182009. }
  182010. void handlePaintMessage()
  182011. {
  182012. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182013. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182014. PAINTSTRUCT paintStruct;
  182015. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182016. // message and become re-entrant, but that's OK
  182017. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182018. // corrupt the image it's using to paint into, so do a check here.
  182019. static bool reentrant = false;
  182020. if (reentrant)
  182021. {
  182022. DeleteObject (rgn);
  182023. EndPaint (hwnd, &paintStruct);
  182024. return;
  182025. }
  182026. reentrant = true;
  182027. // this is the rectangle to update..
  182028. int x = paintStruct.rcPaint.left;
  182029. int y = paintStruct.rcPaint.top;
  182030. int w = paintStruct.rcPaint.right - x;
  182031. int h = paintStruct.rcPaint.bottom - y;
  182032. const bool transparent = isTransparent();
  182033. if (transparent)
  182034. {
  182035. // it's not possible to have a transparent window with a title bar at the moment!
  182036. jassert (! hasTitleBar());
  182037. RECT r;
  182038. GetWindowRect (hwnd, &r);
  182039. x = y = 0;
  182040. w = r.right - r.left;
  182041. h = r.bottom - r.top;
  182042. }
  182043. if (w > 0 && h > 0)
  182044. {
  182045. clearMaskedRegion();
  182046. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182047. RectangleList contextClip;
  182048. bool needToPaintAll = true;
  182049. if (regionType == COMPLEXREGION && ! transparent)
  182050. {
  182051. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182052. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182053. DeleteObject (clipRgn);
  182054. char rgnData [8192];
  182055. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182056. if (res > 0 && res <= sizeof (rgnData))
  182057. {
  182058. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182059. if (hdr->iType == RDH_RECTANGLES
  182060. && hdr->rcBound.right - hdr->rcBound.left >= w
  182061. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182062. {
  182063. needToPaintAll = false;
  182064. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182065. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182066. while (--num >= 0)
  182067. {
  182068. // (need to move this one pixel to the left because of a win32 bug)
  182069. const int cx = jmax (x, (int) rects->left - 1);
  182070. const int cy = rects->top;
  182071. const int cw = rects->right - cx;
  182072. const int ch = rects->bottom - rects->top;
  182073. if (cx + cw - x <= w && cy + ch - y <= h)
  182074. {
  182075. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182076. }
  182077. else
  182078. {
  182079. needToPaintAll = true;
  182080. break;
  182081. }
  182082. ++rects;
  182083. }
  182084. }
  182085. }
  182086. }
  182087. if (needToPaintAll)
  182088. {
  182089. contextClip.clear();
  182090. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182091. }
  182092. if (transparent)
  182093. {
  182094. RectangleList::Iterator i (contextClip);
  182095. while (i.next())
  182096. {
  182097. const Rectangle<int>& r = *i.getRectangle();
  182098. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182099. }
  182100. }
  182101. // if the component's not opaque, this won't draw properly unless the platform can support this
  182102. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182103. updateCurrentModifiers();
  182104. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182105. context.clipToRectangleList (contextClip);
  182106. context.setOrigin (-x, -y);
  182107. handlePaint (context);
  182108. if (! dontRepaint)
  182109. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182110. }
  182111. DeleteObject (rgn);
  182112. EndPaint (hwnd, &paintStruct);
  182113. reentrant = false;
  182114. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182115. _fpreset(); // because some graphics cards can unmask FP exceptions
  182116. #endif
  182117. lastPaintTime = Time::getMillisecondCounter();
  182118. }
  182119. void doMouseEvent (const Point<int>& position)
  182120. {
  182121. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182122. }
  182123. void doMouseMove (const Point<int>& position)
  182124. {
  182125. if (! isMouseOver)
  182126. {
  182127. isMouseOver = true;
  182128. updateKeyModifiers();
  182129. TRACKMOUSEEVENT tme;
  182130. tme.cbSize = sizeof (tme);
  182131. tme.dwFlags = TME_LEAVE;
  182132. tme.hwndTrack = hwnd;
  182133. tme.dwHoverTime = 0;
  182134. if (! TrackMouseEvent (&tme))
  182135. jassertfalse;
  182136. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182137. }
  182138. else if (! isDragging)
  182139. {
  182140. if (! contains (position, false))
  182141. return;
  182142. }
  182143. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182144. static uint32 lastMouseTime = 0;
  182145. const uint32 now = Time::getMillisecondCounter();
  182146. const int maxMouseMovesPerSecond = 60;
  182147. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182148. {
  182149. lastMouseTime = now;
  182150. doMouseEvent (position);
  182151. }
  182152. }
  182153. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182154. {
  182155. if (GetCapture() != hwnd)
  182156. SetCapture (hwnd);
  182157. doMouseMove (position);
  182158. updateModifiersFromWParam (wParam);
  182159. isDragging = true;
  182160. doMouseEvent (position);
  182161. }
  182162. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182163. {
  182164. updateModifiersFromWParam (wParam);
  182165. isDragging = false;
  182166. // release the mouse capture if the user has released all buttons
  182167. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182168. ReleaseCapture();
  182169. doMouseEvent (position);
  182170. }
  182171. void doCaptureChanged()
  182172. {
  182173. if (isDragging)
  182174. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182175. }
  182176. void doMouseExit()
  182177. {
  182178. isMouseOver = false;
  182179. doMouseEvent (getCurrentMousePos());
  182180. }
  182181. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182182. {
  182183. updateKeyModifiers();
  182184. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182185. handleMouseWheel (0, position, getMouseEventTime(),
  182186. isVertical ? 0.0f : amount,
  182187. isVertical ? amount : 0.0f);
  182188. }
  182189. void sendModifierKeyChangeIfNeeded()
  182190. {
  182191. if (modifiersAtLastCallback != currentModifiers)
  182192. {
  182193. modifiersAtLastCallback = currentModifiers;
  182194. handleModifierKeysChange();
  182195. }
  182196. }
  182197. bool doKeyUp (const WPARAM key)
  182198. {
  182199. updateKeyModifiers();
  182200. switch (key)
  182201. {
  182202. case VK_SHIFT:
  182203. case VK_CONTROL:
  182204. case VK_MENU:
  182205. case VK_CAPITAL:
  182206. case VK_LWIN:
  182207. case VK_RWIN:
  182208. case VK_APPS:
  182209. case VK_NUMLOCK:
  182210. case VK_SCROLL:
  182211. case VK_LSHIFT:
  182212. case VK_RSHIFT:
  182213. case VK_LCONTROL:
  182214. case VK_LMENU:
  182215. case VK_RCONTROL:
  182216. case VK_RMENU:
  182217. sendModifierKeyChangeIfNeeded();
  182218. }
  182219. return handleKeyUpOrDown (false)
  182220. || Component::getCurrentlyModalComponent() != 0;
  182221. }
  182222. bool doKeyDown (const WPARAM key)
  182223. {
  182224. updateKeyModifiers();
  182225. bool used = false;
  182226. switch (key)
  182227. {
  182228. case VK_SHIFT:
  182229. case VK_LSHIFT:
  182230. case VK_RSHIFT:
  182231. case VK_CONTROL:
  182232. case VK_LCONTROL:
  182233. case VK_RCONTROL:
  182234. case VK_MENU:
  182235. case VK_LMENU:
  182236. case VK_RMENU:
  182237. case VK_LWIN:
  182238. case VK_RWIN:
  182239. case VK_CAPITAL:
  182240. case VK_NUMLOCK:
  182241. case VK_SCROLL:
  182242. case VK_APPS:
  182243. sendModifierKeyChangeIfNeeded();
  182244. break;
  182245. case VK_LEFT:
  182246. case VK_RIGHT:
  182247. case VK_UP:
  182248. case VK_DOWN:
  182249. case VK_PRIOR:
  182250. case VK_NEXT:
  182251. case VK_HOME:
  182252. case VK_END:
  182253. case VK_DELETE:
  182254. case VK_INSERT:
  182255. case VK_F1:
  182256. case VK_F2:
  182257. case VK_F3:
  182258. case VK_F4:
  182259. case VK_F5:
  182260. case VK_F6:
  182261. case VK_F7:
  182262. case VK_F8:
  182263. case VK_F9:
  182264. case VK_F10:
  182265. case VK_F11:
  182266. case VK_F12:
  182267. case VK_F13:
  182268. case VK_F14:
  182269. case VK_F15:
  182270. case VK_F16:
  182271. used = handleKeyUpOrDown (true);
  182272. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182273. break;
  182274. case VK_ADD:
  182275. case VK_SUBTRACT:
  182276. case VK_MULTIPLY:
  182277. case VK_DIVIDE:
  182278. case VK_SEPARATOR:
  182279. case VK_DECIMAL:
  182280. used = handleKeyUpOrDown (true);
  182281. break;
  182282. default:
  182283. used = handleKeyUpOrDown (true);
  182284. {
  182285. MSG msg;
  182286. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182287. {
  182288. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182289. // manually generate the key-press event that matches this key-down.
  182290. const UINT keyChar = MapVirtualKey (key, 2);
  182291. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182292. }
  182293. }
  182294. break;
  182295. }
  182296. if (Component::getCurrentlyModalComponent() != 0)
  182297. used = true;
  182298. return used;
  182299. }
  182300. bool doKeyChar (int key, const LPARAM flags)
  182301. {
  182302. updateKeyModifiers();
  182303. juce_wchar textChar = (juce_wchar) key;
  182304. const int virtualScanCode = (flags >> 16) & 0xff;
  182305. if (key >= '0' && key <= '9')
  182306. {
  182307. switch (virtualScanCode) // check for a numeric keypad scan-code
  182308. {
  182309. case 0x52:
  182310. case 0x4f:
  182311. case 0x50:
  182312. case 0x51:
  182313. case 0x4b:
  182314. case 0x4c:
  182315. case 0x4d:
  182316. case 0x47:
  182317. case 0x48:
  182318. case 0x49:
  182319. key = (key - '0') + KeyPress::numberPad0;
  182320. break;
  182321. default:
  182322. break;
  182323. }
  182324. }
  182325. else
  182326. {
  182327. // convert the scan code to an unmodified character code..
  182328. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182329. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182330. keyChar = LOWORD (keyChar);
  182331. if (keyChar != 0)
  182332. key = (int) keyChar;
  182333. // avoid sending junk text characters for some control-key combinations
  182334. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182335. textChar = 0;
  182336. }
  182337. return handleKeyPress (key, textChar);
  182338. }
  182339. bool doAppCommand (const LPARAM lParam)
  182340. {
  182341. int key = 0;
  182342. switch (GET_APPCOMMAND_LPARAM (lParam))
  182343. {
  182344. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182345. key = KeyPress::playKey;
  182346. break;
  182347. case APPCOMMAND_MEDIA_STOP:
  182348. key = KeyPress::stopKey;
  182349. break;
  182350. case APPCOMMAND_MEDIA_NEXTTRACK:
  182351. key = KeyPress::fastForwardKey;
  182352. break;
  182353. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182354. key = KeyPress::rewindKey;
  182355. break;
  182356. }
  182357. if (key != 0)
  182358. {
  182359. updateKeyModifiers();
  182360. if (hwnd == GetActiveWindow())
  182361. {
  182362. handleKeyPress (key, 0);
  182363. return true;
  182364. }
  182365. }
  182366. return false;
  182367. }
  182368. class JuceDropTarget : public IDropTarget
  182369. {
  182370. public:
  182371. JuceDropTarget (Win32ComponentPeer* const owner_)
  182372. : owner (owner_),
  182373. refCount (1)
  182374. {
  182375. }
  182376. virtual ~JuceDropTarget()
  182377. {
  182378. jassert (refCount == 0);
  182379. }
  182380. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182381. {
  182382. if (id == IID_IUnknown || id == IID_IDropTarget)
  182383. {
  182384. AddRef();
  182385. *result = this;
  182386. return S_OK;
  182387. }
  182388. *result = 0;
  182389. return E_NOINTERFACE;
  182390. }
  182391. ULONG __stdcall AddRef() { return ++refCount; }
  182392. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182393. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182394. {
  182395. updateFileList (pDataObject);
  182396. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182397. *pdwEffect = DROPEFFECT_COPY;
  182398. return S_OK;
  182399. }
  182400. HRESULT __stdcall DragLeave()
  182401. {
  182402. owner->handleFileDragExit (files);
  182403. return S_OK;
  182404. }
  182405. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182406. {
  182407. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182408. *pdwEffect = DROPEFFECT_COPY;
  182409. return S_OK;
  182410. }
  182411. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182412. {
  182413. updateFileList (pDataObject);
  182414. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182415. *pdwEffect = DROPEFFECT_COPY;
  182416. return S_OK;
  182417. }
  182418. private:
  182419. Win32ComponentPeer* const owner;
  182420. int refCount;
  182421. StringArray files;
  182422. void updateFileList (IDataObject* const pDataObject)
  182423. {
  182424. files.clear();
  182425. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182426. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182427. if (pDataObject->GetData (&format, &medium) == S_OK)
  182428. {
  182429. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182430. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182431. unsigned int i = 0;
  182432. if (pDropFiles->fWide)
  182433. {
  182434. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182435. for (;;)
  182436. {
  182437. unsigned int len = 0;
  182438. while (i + len < totalLen && fname [i + len] != 0)
  182439. ++len;
  182440. if (len == 0)
  182441. break;
  182442. files.add (String (fname + i, len));
  182443. i += len + 1;
  182444. }
  182445. }
  182446. else
  182447. {
  182448. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182449. for (;;)
  182450. {
  182451. unsigned int len = 0;
  182452. while (i + len < totalLen && fname [i + len] != 0)
  182453. ++len;
  182454. if (len == 0)
  182455. break;
  182456. files.add (String (fname + i, len));
  182457. i += len + 1;
  182458. }
  182459. }
  182460. GlobalUnlock (medium.hGlobal);
  182461. }
  182462. }
  182463. JuceDropTarget (const JuceDropTarget&);
  182464. JuceDropTarget& operator= (const JuceDropTarget&);
  182465. };
  182466. void doSettingChange()
  182467. {
  182468. Desktop::getInstance().refreshMonitorSizes();
  182469. if (fullScreen && ! isMinimised())
  182470. {
  182471. const Rectangle<int> r (component->getParentMonitorArea());
  182472. SetWindowPos (hwnd, 0,
  182473. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182474. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182475. }
  182476. }
  182477. public:
  182478. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182479. {
  182480. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182481. if (peer != 0)
  182482. return peer->peerWindowProc (h, message, wParam, lParam);
  182483. return DefWindowProcW (h, message, wParam, lParam);
  182484. }
  182485. private:
  182486. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182487. {
  182488. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182489. }
  182490. const Point<int> getCurrentMousePos() throw()
  182491. {
  182492. RECT wr;
  182493. GetWindowRect (hwnd, &wr);
  182494. const DWORD mp = GetMessagePos();
  182495. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182496. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182497. }
  182498. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182499. {
  182500. if (isValidPeer (this))
  182501. {
  182502. switch (message)
  182503. {
  182504. case WM_NCHITTEST:
  182505. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182506. return HTTRANSPARENT;
  182507. if (hasTitleBar())
  182508. break;
  182509. return HTCLIENT;
  182510. case WM_PAINT:
  182511. handlePaintMessage();
  182512. return 0;
  182513. case WM_NCPAINT:
  182514. if (wParam != 1)
  182515. handlePaintMessage();
  182516. if (hasTitleBar())
  182517. break;
  182518. return 0;
  182519. case WM_ERASEBKGND:
  182520. case WM_NCCALCSIZE:
  182521. if (hasTitleBar())
  182522. break;
  182523. return 1;
  182524. case WM_MOUSEMOVE:
  182525. doMouseMove (getPointFromLParam (lParam));
  182526. return 0;
  182527. case WM_MOUSELEAVE:
  182528. doMouseExit();
  182529. return 0;
  182530. case WM_LBUTTONDOWN:
  182531. case WM_MBUTTONDOWN:
  182532. case WM_RBUTTONDOWN:
  182533. doMouseDown (getPointFromLParam (lParam), wParam);
  182534. return 0;
  182535. case WM_LBUTTONUP:
  182536. case WM_MBUTTONUP:
  182537. case WM_RBUTTONUP:
  182538. doMouseUp (getPointFromLParam (lParam), wParam);
  182539. return 0;
  182540. case WM_CAPTURECHANGED:
  182541. doCaptureChanged();
  182542. return 0;
  182543. case WM_NCMOUSEMOVE:
  182544. if (hasTitleBar())
  182545. break;
  182546. return 0;
  182547. case 0x020A: /* WM_MOUSEWHEEL */
  182548. doMouseWheel (getCurrentMousePos(), wParam, true);
  182549. return 0;
  182550. case 0x020E: /* WM_MOUSEHWHEEL */
  182551. doMouseWheel (getCurrentMousePos(), wParam, false);
  182552. return 0;
  182553. case WM_WINDOWPOSCHANGING:
  182554. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182555. {
  182556. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182557. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182558. {
  182559. if (constrainer != 0)
  182560. {
  182561. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182562. component->getY() - windowBorder.getTop(),
  182563. component->getWidth() + windowBorder.getLeftAndRight(),
  182564. component->getHeight() + windowBorder.getTopAndBottom());
  182565. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182566. constrainer->checkBounds (pos, current,
  182567. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182568. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182569. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182570. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182571. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182572. wp->x = pos.getX();
  182573. wp->y = pos.getY();
  182574. wp->cx = pos.getWidth();
  182575. wp->cy = pos.getHeight();
  182576. }
  182577. }
  182578. }
  182579. return 0;
  182580. case WM_WINDOWPOSCHANGED:
  182581. handleMovedOrResized();
  182582. if (dontRepaint)
  182583. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182584. return 0;
  182585. case WM_KEYDOWN:
  182586. case WM_SYSKEYDOWN:
  182587. if (doKeyDown (wParam))
  182588. return 0;
  182589. break;
  182590. case WM_KEYUP:
  182591. case WM_SYSKEYUP:
  182592. if (doKeyUp (wParam))
  182593. return 0;
  182594. break;
  182595. case WM_CHAR:
  182596. if (doKeyChar ((int) wParam, lParam))
  182597. return 0;
  182598. break;
  182599. case WM_APPCOMMAND:
  182600. if (doAppCommand (lParam))
  182601. return TRUE;
  182602. break;
  182603. case WM_SETFOCUS:
  182604. updateKeyModifiers();
  182605. handleFocusGain();
  182606. break;
  182607. case WM_KILLFOCUS:
  182608. if (hasCreatedCaret)
  182609. {
  182610. hasCreatedCaret = false;
  182611. DestroyCaret();
  182612. }
  182613. handleFocusLoss();
  182614. break;
  182615. case WM_ACTIVATEAPP:
  182616. // Windows does weird things to process priority when you swap apps,
  182617. // so this forces an update when the app is brought to the front
  182618. if (wParam != FALSE)
  182619. juce_repeatLastProcessPriority();
  182620. else
  182621. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182622. juce_CheckCurrentlyFocusedTopLevelWindow();
  182623. modifiersAtLastCallback = -1;
  182624. return 0;
  182625. case WM_ACTIVATE:
  182626. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182627. {
  182628. modifiersAtLastCallback = -1;
  182629. updateKeyModifiers();
  182630. if (isMinimised())
  182631. {
  182632. component->repaint();
  182633. handleMovedOrResized();
  182634. if (! ComponentPeer::isValidPeer (this))
  182635. return 0;
  182636. }
  182637. if (LOWORD (wParam) == WA_CLICKACTIVE
  182638. && component->isCurrentlyBlockedByAnotherModalComponent())
  182639. {
  182640. const Point<int> mousePos (component->getMouseXYRelative());
  182641. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182642. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182643. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182644. return 0;
  182645. }
  182646. handleBroughtToFront();
  182647. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182648. Component::getCurrentlyModalComponent()->toFront (true);
  182649. return 0;
  182650. }
  182651. break;
  182652. case WM_NCACTIVATE:
  182653. // while a temporary window is being shown, prevent Windows from deactivating the
  182654. // title bars of our main windows.
  182655. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182656. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182657. break;
  182658. case WM_MOUSEACTIVATE:
  182659. if (! component->getMouseClickGrabsKeyboardFocus())
  182660. return MA_NOACTIVATE;
  182661. break;
  182662. case WM_SHOWWINDOW:
  182663. if (wParam != 0)
  182664. handleBroughtToFront();
  182665. break;
  182666. case WM_CLOSE:
  182667. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182668. handleUserClosingWindow();
  182669. return 0;
  182670. case WM_QUERYENDSESSION:
  182671. if (JUCEApplication::getInstance() != 0)
  182672. {
  182673. JUCEApplication::getInstance()->systemRequestedQuit();
  182674. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182675. }
  182676. return TRUE;
  182677. case WM_TRAYNOTIFY:
  182678. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182679. {
  182680. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182681. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182682. {
  182683. Component* const current = Component::getCurrentlyModalComponent();
  182684. if (current != 0)
  182685. current->inputAttemptWhenModal();
  182686. }
  182687. }
  182688. else
  182689. {
  182690. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182691. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182692. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182693. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182694. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182695. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182696. eventMods = eventMods.withoutMouseButtons();
  182697. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182698. Point<int>(), eventMods, component, getMouseEventTime(),
  182699. Point<int>(), getMouseEventTime(), 1, false);
  182700. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182701. {
  182702. SetFocus (hwnd);
  182703. SetForegroundWindow (hwnd);
  182704. component->mouseDown (e);
  182705. }
  182706. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182707. {
  182708. component->mouseUp (e);
  182709. }
  182710. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182711. {
  182712. component->mouseDoubleClick (e);
  182713. }
  182714. else if (lParam == WM_MOUSEMOVE)
  182715. {
  182716. component->mouseMove (e);
  182717. }
  182718. }
  182719. break;
  182720. case WM_SYNCPAINT:
  182721. return 0;
  182722. case WM_PALETTECHANGED:
  182723. InvalidateRect (h, 0, 0);
  182724. break;
  182725. case WM_DISPLAYCHANGE:
  182726. InvalidateRect (h, 0, 0);
  182727. createPaletteIfNeeded = true;
  182728. // intentional fall-through...
  182729. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182730. doSettingChange();
  182731. break;
  182732. case WM_INITMENU:
  182733. if (! hasTitleBar())
  182734. {
  182735. if (isFullScreen())
  182736. {
  182737. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182738. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182739. }
  182740. else if (! isMinimised())
  182741. {
  182742. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182743. }
  182744. }
  182745. break;
  182746. case WM_SYSCOMMAND:
  182747. switch (wParam & 0xfff0)
  182748. {
  182749. case SC_CLOSE:
  182750. if (sendInputAttemptWhenModalMessage())
  182751. return 0;
  182752. if (hasTitleBar())
  182753. {
  182754. PostMessage (h, WM_CLOSE, 0, 0);
  182755. return 0;
  182756. }
  182757. break;
  182758. case SC_KEYMENU:
  182759. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182760. // obscure situations that can arise if a modal loop is started from an alt-key
  182761. // keypress).
  182762. if (hasTitleBar() && h == GetCapture())
  182763. ReleaseCapture();
  182764. break;
  182765. case SC_MAXIMIZE:
  182766. if (sendInputAttemptWhenModalMessage())
  182767. return 0;
  182768. setFullScreen (true);
  182769. return 0;
  182770. case SC_MINIMIZE:
  182771. if (sendInputAttemptWhenModalMessage())
  182772. return 0;
  182773. if (! hasTitleBar())
  182774. {
  182775. setMinimised (true);
  182776. return 0;
  182777. }
  182778. break;
  182779. case SC_RESTORE:
  182780. if (sendInputAttemptWhenModalMessage())
  182781. return 0;
  182782. if (hasTitleBar())
  182783. {
  182784. if (isFullScreen())
  182785. {
  182786. setFullScreen (false);
  182787. return 0;
  182788. }
  182789. }
  182790. else
  182791. {
  182792. if (isMinimised())
  182793. setMinimised (false);
  182794. else if (isFullScreen())
  182795. setFullScreen (false);
  182796. return 0;
  182797. }
  182798. break;
  182799. }
  182800. break;
  182801. case WM_NCLBUTTONDOWN:
  182802. case WM_NCRBUTTONDOWN:
  182803. case WM_NCMBUTTONDOWN:
  182804. sendInputAttemptWhenModalMessage();
  182805. break;
  182806. //case WM_IME_STARTCOMPOSITION;
  182807. // return 0;
  182808. case WM_GETDLGCODE:
  182809. return DLGC_WANTALLKEYS;
  182810. default:
  182811. break;
  182812. }
  182813. }
  182814. return DefWindowProcW (h, message, wParam, lParam);
  182815. }
  182816. bool sendInputAttemptWhenModalMessage()
  182817. {
  182818. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182819. {
  182820. Component* const current = Component::getCurrentlyModalComponent();
  182821. if (current != 0)
  182822. current->inputAttemptWhenModal();
  182823. return true;
  182824. }
  182825. return false;
  182826. }
  182827. Win32ComponentPeer (const Win32ComponentPeer&);
  182828. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182829. };
  182830. ModifierKeys Win32ComponentPeer::currentModifiers;
  182831. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182832. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182833. {
  182834. return new Win32ComponentPeer (this, styleFlags);
  182835. }
  182836. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182837. void ModifierKeys::updateCurrentModifiers() throw()
  182838. {
  182839. currentModifiers = Win32ComponentPeer::currentModifiers;
  182840. }
  182841. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182842. {
  182843. Win32ComponentPeer::updateKeyModifiers();
  182844. int keyMods = 0;
  182845. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182846. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182847. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182848. Win32ComponentPeer::currentModifiers
  182849. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182850. return Win32ComponentPeer::currentModifiers;
  182851. }
  182852. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  182853. {
  182854. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182855. if (wp != 0)
  182856. wp->setTaskBarIcon (&newImage);
  182857. }
  182858. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  182859. {
  182860. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182861. if (wp != 0)
  182862. wp->setTaskBarIconToolTip (tooltip);
  182863. }
  182864. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  182865. {
  182866. DWORD val = GetWindowLong (h, styleType);
  182867. if (bitIsSet)
  182868. val |= feature;
  182869. else
  182870. val &= ~feature;
  182871. SetWindowLongPtr (h, styleType, val);
  182872. SetWindowPos (h, 0, 0, 0, 0, 0,
  182873. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  182874. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  182875. }
  182876. bool Process::isForegroundProcess()
  182877. {
  182878. HWND fg = GetForegroundWindow();
  182879. if (fg == 0)
  182880. return true;
  182881. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  182882. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  182883. // have to see if any of our windows are children of the foreground window
  182884. fg = GetAncestor (fg, GA_ROOT);
  182885. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  182886. {
  182887. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  182888. if (wp != 0 && wp->isInside (fg))
  182889. return true;
  182890. }
  182891. return false;
  182892. }
  182893. bool AlertWindow::showNativeDialogBox (const String& title,
  182894. const String& bodyText,
  182895. bool isOkCancel)
  182896. {
  182897. return MessageBox (0, bodyText, title,
  182898. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  182899. : MB_OK)) == IDOK;
  182900. }
  182901. void Desktop::createMouseInputSources()
  182902. {
  182903. mouseSources.add (new MouseInputSource (0, true));
  182904. }
  182905. const Point<int> Desktop::getMousePosition()
  182906. {
  182907. POINT mousePos;
  182908. GetCursorPos (&mousePos);
  182909. return Point<int> (mousePos.x, mousePos.y);
  182910. }
  182911. void Desktop::setMousePosition (const Point<int>& newPosition)
  182912. {
  182913. SetCursorPos (newPosition.getX(), newPosition.getY());
  182914. }
  182915. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  182916. {
  182917. return new Image (format, imageWidth, imageHeight, clearImage);
  182918. }
  182919. class ScreenSaverDefeater : public Timer,
  182920. public DeletedAtShutdown
  182921. {
  182922. public:
  182923. ScreenSaverDefeater() throw()
  182924. {
  182925. startTimer (10000);
  182926. timerCallback();
  182927. }
  182928. ~ScreenSaverDefeater() {}
  182929. void timerCallback()
  182930. {
  182931. if (Process::isForegroundProcess())
  182932. {
  182933. // simulate a shift key getting pressed..
  182934. INPUT input[2];
  182935. input[0].type = INPUT_KEYBOARD;
  182936. input[0].ki.wVk = VK_SHIFT;
  182937. input[0].ki.dwFlags = 0;
  182938. input[0].ki.dwExtraInfo = 0;
  182939. input[1].type = INPUT_KEYBOARD;
  182940. input[1].ki.wVk = VK_SHIFT;
  182941. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  182942. input[1].ki.dwExtraInfo = 0;
  182943. SendInput (2, input, sizeof (INPUT));
  182944. }
  182945. }
  182946. };
  182947. static ScreenSaverDefeater* screenSaverDefeater = 0;
  182948. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  182949. {
  182950. if (isEnabled)
  182951. {
  182952. deleteAndZero (screenSaverDefeater);
  182953. }
  182954. else if (screenSaverDefeater == 0)
  182955. {
  182956. screenSaverDefeater = new ScreenSaverDefeater();
  182957. }
  182958. }
  182959. bool Desktop::isScreenSaverEnabled() throw()
  182960. {
  182961. return screenSaverDefeater == 0;
  182962. }
  182963. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  182964. {
  182965. if (enableOrDisable)
  182966. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  182967. }
  182968. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  182969. {
  182970. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  182971. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  182972. return TRUE;
  182973. }
  182974. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  182975. {
  182976. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  182977. // make sure the first in the list is the main monitor
  182978. for (int i = 1; i < monitorCoords.size(); ++i)
  182979. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  182980. monitorCoords.swap (i, 0);
  182981. if (monitorCoords.size() == 0)
  182982. {
  182983. RECT r;
  182984. GetWindowRect (GetDesktopWindow(), &r);
  182985. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  182986. }
  182987. if (clipToWorkArea)
  182988. {
  182989. // clip the main monitor to the active non-taskbar area
  182990. RECT r;
  182991. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  182992. Rectangle<int>& screen = monitorCoords.getReference (0);
  182993. screen.setPosition (jmax (screen.getX(), (int) r.left),
  182994. jmax (screen.getY(), (int) r.top));
  182995. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  182996. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  182997. }
  182998. }
  182999. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183000. {
  183001. Image* im = 0;
  183002. if (bitmap != 0)
  183003. {
  183004. BITMAP bm;
  183005. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183006. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183007. {
  183008. HDC tempDC = GetDC (0);
  183009. HDC dc = CreateCompatibleDC (tempDC);
  183010. ReleaseDC (0, tempDC);
  183011. SelectObject (dc, bitmap);
  183012. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183013. for (int y = bm.bmHeight; --y >= 0;)
  183014. {
  183015. for (int x = bm.bmWidth; --x >= 0;)
  183016. {
  183017. COLORREF col = GetPixel (dc, x, y);
  183018. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183019. (uint8) GetGValue (col),
  183020. (uint8) GetBValue (col)));
  183021. }
  183022. }
  183023. DeleteDC (dc);
  183024. }
  183025. }
  183026. return im;
  183027. }
  183028. static Image* createImageFromHICON (HICON icon) throw()
  183029. {
  183030. ICONINFO info;
  183031. if (GetIconInfo (icon, &info))
  183032. {
  183033. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183034. if (mask == 0)
  183035. return 0;
  183036. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183037. if (image == 0)
  183038. return mask;
  183039. for (int y = image->getHeight(); --y >= 0;)
  183040. {
  183041. for (int x = image->getWidth(); --x >= 0;)
  183042. {
  183043. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183044. if (brightness > 0.0f)
  183045. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183046. }
  183047. }
  183048. delete mask;
  183049. return image;
  183050. }
  183051. return 0;
  183052. }
  183053. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183054. {
  183055. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183056. ICONINFO info;
  183057. info.fIcon = isIcon;
  183058. info.xHotspot = hotspotX;
  183059. info.yHotspot = hotspotY;
  183060. info.hbmMask = mask;
  183061. HICON hi = 0;
  183062. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183063. {
  183064. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183065. Graphics g (bitmap);
  183066. g.drawImageAt (&image, 0, 0);
  183067. info.hbmColor = bitmap.hBitmap;
  183068. hi = CreateIconIndirect (&info);
  183069. }
  183070. else
  183071. {
  183072. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183073. HDC colDC = CreateCompatibleDC (GetDC (0));
  183074. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183075. SelectObject (colDC, colour);
  183076. SelectObject (alphaDC, mask);
  183077. for (int y = image.getHeight(); --y >= 0;)
  183078. {
  183079. for (int x = image.getWidth(); --x >= 0;)
  183080. {
  183081. const Colour c (image.getPixelAt (x, y));
  183082. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183083. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183084. }
  183085. }
  183086. DeleteDC (colDC);
  183087. DeleteDC (alphaDC);
  183088. info.hbmColor = colour;
  183089. hi = CreateIconIndirect (&info);
  183090. DeleteObject (colour);
  183091. }
  183092. DeleteObject (mask);
  183093. return hi;
  183094. }
  183095. Image* juce_createIconForFile (const File& file)
  183096. {
  183097. Image* image = 0;
  183098. WCHAR filename [1024];
  183099. file.getFullPathName().copyToUnicode (filename, 1023);
  183100. WORD iconNum = 0;
  183101. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183102. filename, &iconNum);
  183103. if (icon != 0)
  183104. {
  183105. image = createImageFromHICON (icon);
  183106. DestroyIcon (icon);
  183107. }
  183108. return image;
  183109. }
  183110. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183111. {
  183112. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183113. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183114. const Image* im = &image;
  183115. Image* newIm = 0;
  183116. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183117. {
  183118. im = newIm = image.createCopy (maxW, maxH);
  183119. hotspotX = (hotspotX * maxW) / image.getWidth();
  183120. hotspotY = (hotspotY * maxH) / image.getHeight();
  183121. }
  183122. void* cursorH = 0;
  183123. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183124. if (os == SystemStats::WinXP)
  183125. {
  183126. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183127. }
  183128. else
  183129. {
  183130. const int stride = (maxW + 7) >> 3;
  183131. HeapBlock <uint8> andPlane, xorPlane;
  183132. andPlane.calloc (stride * maxH);
  183133. xorPlane.calloc (stride * maxH);
  183134. int index = 0;
  183135. for (int y = 0; y < maxH; ++y)
  183136. {
  183137. for (int x = 0; x < maxW; ++x)
  183138. {
  183139. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183140. const Colour pixelColour (im->getPixelAt (x, y));
  183141. if (pixelColour.getAlpha() < 127)
  183142. andPlane [index + (x >> 3)] |= bit;
  183143. else if (pixelColour.getBrightness() >= 0.5f)
  183144. xorPlane [index + (x >> 3)] |= bit;
  183145. }
  183146. index += stride;
  183147. }
  183148. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183149. }
  183150. delete newIm;
  183151. return cursorH;
  183152. }
  183153. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183154. {
  183155. if (cursorHandle != 0 && ! isStandard)
  183156. DestroyCursor ((HCURSOR) cursorHandle);
  183157. }
  183158. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183159. {
  183160. LPCTSTR cursorName = IDC_ARROW;
  183161. switch (type)
  183162. {
  183163. case MouseCursor::NormalCursor:
  183164. cursorName = IDC_ARROW;
  183165. break;
  183166. case MouseCursor::NoCursor:
  183167. return 0;
  183168. case MouseCursor::DraggingHandCursor:
  183169. {
  183170. static void* dragHandCursor = 0;
  183171. if (dragHandCursor == 0)
  183172. {
  183173. static const unsigned char dragHandData[] =
  183174. { 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,
  183175. 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,
  183176. 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 };
  183177. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183178. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183179. }
  183180. return dragHandCursor;
  183181. }
  183182. case MouseCursor::WaitCursor:
  183183. cursorName = IDC_WAIT;
  183184. break;
  183185. case MouseCursor::IBeamCursor:
  183186. cursorName = IDC_IBEAM;
  183187. break;
  183188. case MouseCursor::PointingHandCursor:
  183189. cursorName = MAKEINTRESOURCE(32649);
  183190. break;
  183191. case MouseCursor::LeftRightResizeCursor:
  183192. case MouseCursor::LeftEdgeResizeCursor:
  183193. case MouseCursor::RightEdgeResizeCursor:
  183194. cursorName = IDC_SIZEWE;
  183195. break;
  183196. case MouseCursor::UpDownResizeCursor:
  183197. case MouseCursor::TopEdgeResizeCursor:
  183198. case MouseCursor::BottomEdgeResizeCursor:
  183199. cursorName = IDC_SIZENS;
  183200. break;
  183201. case MouseCursor::TopLeftCornerResizeCursor:
  183202. case MouseCursor::BottomRightCornerResizeCursor:
  183203. cursorName = IDC_SIZENWSE;
  183204. break;
  183205. case MouseCursor::TopRightCornerResizeCursor:
  183206. case MouseCursor::BottomLeftCornerResizeCursor:
  183207. cursorName = IDC_SIZENESW;
  183208. break;
  183209. case MouseCursor::UpDownLeftRightResizeCursor:
  183210. cursorName = IDC_SIZEALL;
  183211. break;
  183212. case MouseCursor::CrosshairCursor:
  183213. cursorName = IDC_CROSS;
  183214. break;
  183215. case MouseCursor::CopyingCursor:
  183216. // can't seem to find one of these in the win32 list..
  183217. break;
  183218. }
  183219. HCURSOR cursorH = LoadCursor (0, cursorName);
  183220. if (cursorH == 0)
  183221. cursorH = LoadCursor (0, IDC_ARROW);
  183222. return (void*) cursorH;
  183223. }
  183224. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183225. {
  183226. SetCursor ((HCURSOR) getHandle());
  183227. }
  183228. void MouseCursor::showInAllWindows() const throw()
  183229. {
  183230. showInWindow (0);
  183231. }
  183232. class JuceDropSource : public IDropSource
  183233. {
  183234. int refCount;
  183235. public:
  183236. JuceDropSource()
  183237. : refCount (1)
  183238. {
  183239. }
  183240. virtual ~JuceDropSource()
  183241. {
  183242. jassert (refCount == 0);
  183243. }
  183244. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183245. {
  183246. if (id == IID_IUnknown || id == IID_IDropSource)
  183247. {
  183248. AddRef();
  183249. *result = this;
  183250. return S_OK;
  183251. }
  183252. *result = 0;
  183253. return E_NOINTERFACE;
  183254. }
  183255. ULONG __stdcall AddRef() { return ++refCount; }
  183256. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183257. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183258. {
  183259. if (escapePressed)
  183260. return DRAGDROP_S_CANCEL;
  183261. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183262. return DRAGDROP_S_DROP;
  183263. return S_OK;
  183264. }
  183265. HRESULT __stdcall GiveFeedback (DWORD)
  183266. {
  183267. return DRAGDROP_S_USEDEFAULTCURSORS;
  183268. }
  183269. };
  183270. class JuceEnumFormatEtc : public IEnumFORMATETC
  183271. {
  183272. public:
  183273. JuceEnumFormatEtc (const FORMATETC* const format_)
  183274. : refCount (1),
  183275. format (format_),
  183276. index (0)
  183277. {
  183278. }
  183279. virtual ~JuceEnumFormatEtc()
  183280. {
  183281. jassert (refCount == 0);
  183282. }
  183283. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183284. {
  183285. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183286. {
  183287. AddRef();
  183288. *result = this;
  183289. return S_OK;
  183290. }
  183291. *result = 0;
  183292. return E_NOINTERFACE;
  183293. }
  183294. ULONG __stdcall AddRef() { return ++refCount; }
  183295. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183296. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183297. {
  183298. if (result == 0)
  183299. return E_POINTER;
  183300. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183301. newOne->index = index;
  183302. *result = newOne;
  183303. return S_OK;
  183304. }
  183305. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183306. {
  183307. if (pceltFetched != 0)
  183308. *pceltFetched = 0;
  183309. else if (celt != 1)
  183310. return S_FALSE;
  183311. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183312. {
  183313. copyFormatEtc (lpFormatEtc [0], *format);
  183314. ++index;
  183315. if (pceltFetched != 0)
  183316. *pceltFetched = 1;
  183317. return S_OK;
  183318. }
  183319. return S_FALSE;
  183320. }
  183321. HRESULT __stdcall Skip (ULONG celt)
  183322. {
  183323. if (index + (int) celt >= 1)
  183324. return S_FALSE;
  183325. index += celt;
  183326. return S_OK;
  183327. }
  183328. HRESULT __stdcall Reset()
  183329. {
  183330. index = 0;
  183331. return S_OK;
  183332. }
  183333. private:
  183334. int refCount;
  183335. const FORMATETC* const format;
  183336. int index;
  183337. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183338. {
  183339. dest = source;
  183340. if (source.ptd != 0)
  183341. {
  183342. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183343. *(dest.ptd) = *(source.ptd);
  183344. }
  183345. }
  183346. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183347. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183348. };
  183349. class JuceDataObject : public IDataObject
  183350. {
  183351. JuceDropSource* const dropSource;
  183352. const FORMATETC* const format;
  183353. const STGMEDIUM* const medium;
  183354. int refCount;
  183355. JuceDataObject (const JuceDataObject&);
  183356. JuceDataObject& operator= (const JuceDataObject&);
  183357. public:
  183358. JuceDataObject (JuceDropSource* const dropSource_,
  183359. const FORMATETC* const format_,
  183360. const STGMEDIUM* const medium_)
  183361. : dropSource (dropSource_),
  183362. format (format_),
  183363. medium (medium_),
  183364. refCount (1)
  183365. {
  183366. }
  183367. virtual ~JuceDataObject()
  183368. {
  183369. jassert (refCount == 0);
  183370. }
  183371. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183372. {
  183373. if (id == IID_IUnknown || id == IID_IDataObject)
  183374. {
  183375. AddRef();
  183376. *result = this;
  183377. return S_OK;
  183378. }
  183379. *result = 0;
  183380. return E_NOINTERFACE;
  183381. }
  183382. ULONG __stdcall AddRef() { return ++refCount; }
  183383. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183384. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183385. {
  183386. if ((pFormatEtc->tymed & format->tymed) != 0
  183387. && pFormatEtc->cfFormat == format->cfFormat
  183388. && pFormatEtc->dwAspect == format->dwAspect)
  183389. {
  183390. pMedium->tymed = format->tymed;
  183391. pMedium->pUnkForRelease = 0;
  183392. if (format->tymed == TYMED_HGLOBAL)
  183393. {
  183394. const SIZE_T len = GlobalSize (medium->hGlobal);
  183395. void* const src = GlobalLock (medium->hGlobal);
  183396. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183397. memcpy (dst, src, len);
  183398. GlobalUnlock (medium->hGlobal);
  183399. pMedium->hGlobal = dst;
  183400. return S_OK;
  183401. }
  183402. }
  183403. return DV_E_FORMATETC;
  183404. }
  183405. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183406. {
  183407. if (f == 0)
  183408. return E_INVALIDARG;
  183409. if (f->tymed == format->tymed
  183410. && f->cfFormat == format->cfFormat
  183411. && f->dwAspect == format->dwAspect)
  183412. return S_OK;
  183413. return DV_E_FORMATETC;
  183414. }
  183415. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183416. {
  183417. pFormatEtcOut->ptd = 0;
  183418. return E_NOTIMPL;
  183419. }
  183420. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183421. {
  183422. if (result == 0)
  183423. return E_POINTER;
  183424. if (direction == DATADIR_GET)
  183425. {
  183426. *result = new JuceEnumFormatEtc (format);
  183427. return S_OK;
  183428. }
  183429. *result = 0;
  183430. return E_NOTIMPL;
  183431. }
  183432. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183433. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183434. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183435. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183436. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183437. };
  183438. static HDROP createHDrop (const StringArray& fileNames) throw()
  183439. {
  183440. int totalChars = 0;
  183441. for (int i = fileNames.size(); --i >= 0;)
  183442. totalChars += fileNames[i].length() + 1;
  183443. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183444. sizeof (DROPFILES)
  183445. + sizeof (WCHAR) * (totalChars + 2));
  183446. if (hDrop != 0)
  183447. {
  183448. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183449. pDropFiles->pFiles = sizeof (DROPFILES);
  183450. pDropFiles->fWide = true;
  183451. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183452. for (int i = 0; i < fileNames.size(); ++i)
  183453. {
  183454. fileNames[i].copyToUnicode (fname, 2048);
  183455. fname += fileNames[i].length() + 1;
  183456. }
  183457. *fname = 0;
  183458. GlobalUnlock (hDrop);
  183459. }
  183460. return hDrop;
  183461. }
  183462. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183463. {
  183464. JuceDropSource* const source = new JuceDropSource();
  183465. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183466. DWORD effect;
  183467. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183468. data->Release();
  183469. source->Release();
  183470. return res == DRAGDROP_S_DROP;
  183471. }
  183472. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183473. {
  183474. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183475. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183476. medium.hGlobal = createHDrop (files);
  183477. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183478. : DROPEFFECT_COPY);
  183479. }
  183480. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183481. {
  183482. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183483. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183484. const int numChars = text.length();
  183485. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183486. char* d = (char*) GlobalLock (medium.hGlobal);
  183487. text.copyToUnicode ((WCHAR*) d, numChars + 1);
  183488. format.cfFormat = CF_UNICODETEXT;
  183489. GlobalUnlock (medium.hGlobal);
  183490. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183491. }
  183492. #endif
  183493. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183494. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183495. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183496. // compiled on its own).
  183497. #if JUCE_INCLUDED_FILE
  183498. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183499. NEWTEXTMETRICEXW*,
  183500. int type,
  183501. LPARAM lParam)
  183502. {
  183503. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183504. {
  183505. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183506. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters ("@"));
  183507. }
  183508. return 1;
  183509. }
  183510. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183511. NEWTEXTMETRICEXW*,
  183512. int type,
  183513. LPARAM lParam)
  183514. {
  183515. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183516. {
  183517. LOGFONTW lf;
  183518. zerostruct (lf);
  183519. lf.lfWeight = FW_DONTCARE;
  183520. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183521. lf.lfQuality = DEFAULT_QUALITY;
  183522. lf.lfCharSet = DEFAULT_CHARSET;
  183523. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183524. lf.lfPitchAndFamily = FF_DONTCARE;
  183525. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183526. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183527. HDC dc = CreateCompatibleDC (0);
  183528. EnumFontFamiliesEx (dc, &lf,
  183529. (FONTENUMPROCW) &wfontEnum2,
  183530. lParam, 0);
  183531. DeleteDC (dc);
  183532. }
  183533. return 1;
  183534. }
  183535. const StringArray Font::findAllTypefaceNames()
  183536. {
  183537. StringArray results;
  183538. HDC dc = CreateCompatibleDC (0);
  183539. {
  183540. LOGFONTW lf;
  183541. zerostruct (lf);
  183542. lf.lfWeight = FW_DONTCARE;
  183543. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183544. lf.lfQuality = DEFAULT_QUALITY;
  183545. lf.lfCharSet = DEFAULT_CHARSET;
  183546. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183547. lf.lfPitchAndFamily = FF_DONTCARE;
  183548. lf.lfFaceName[0] = 0;
  183549. EnumFontFamiliesEx (dc, &lf,
  183550. (FONTENUMPROCW) &wfontEnum1,
  183551. (LPARAM) &results, 0);
  183552. }
  183553. DeleteDC (dc);
  183554. results.sort (true);
  183555. return results;
  183556. }
  183557. extern bool juce_IsRunningInWine();
  183558. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  183559. {
  183560. if (juce_IsRunningInWine())
  183561. {
  183562. // If we're running in Wine, then use fonts that might be available on Linux..
  183563. defaultSans = "Bitstream Vera Sans";
  183564. defaultSerif = "Bitstream Vera Serif";
  183565. defaultFixed = "Bitstream Vera Sans Mono";
  183566. }
  183567. else
  183568. {
  183569. defaultSans = "Verdana";
  183570. defaultSerif = "Times";
  183571. defaultFixed = "Lucida Console";
  183572. }
  183573. }
  183574. class FontDCHolder : private DeletedAtShutdown
  183575. {
  183576. public:
  183577. FontDCHolder() throw()
  183578. : dc (0), numKPs (0), size (0),
  183579. bold (false), italic (false)
  183580. {
  183581. }
  183582. ~FontDCHolder() throw()
  183583. {
  183584. if (dc != 0)
  183585. {
  183586. DeleteDC (dc);
  183587. DeleteObject (fontH);
  183588. }
  183589. clearSingletonInstance();
  183590. }
  183591. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183592. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183593. {
  183594. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183595. {
  183596. fontName = fontName_;
  183597. bold = bold_;
  183598. italic = italic_;
  183599. size = size_;
  183600. if (dc != 0)
  183601. {
  183602. DeleteDC (dc);
  183603. DeleteObject (fontH);
  183604. kps.free();
  183605. }
  183606. fontH = 0;
  183607. dc = CreateCompatibleDC (0);
  183608. SetMapperFlags (dc, 0);
  183609. SetMapMode (dc, MM_TEXT);
  183610. LOGFONTW lfw;
  183611. zerostruct (lfw);
  183612. lfw.lfCharSet = DEFAULT_CHARSET;
  183613. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183614. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183615. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183616. lfw.lfQuality = PROOF_QUALITY;
  183617. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183618. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183619. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183620. lfw.lfHeight = size > 0 ? size : -256;
  183621. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183622. if (standardSizedFont != 0)
  183623. {
  183624. if (SelectObject (dc, standardSizedFont) != 0)
  183625. {
  183626. fontH = standardSizedFont;
  183627. if (size == 0)
  183628. {
  183629. OUTLINETEXTMETRIC otm;
  183630. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183631. {
  183632. lfw.lfHeight = -(int) otm.otmEMSquare;
  183633. fontH = CreateFontIndirect (&lfw);
  183634. SelectObject (dc, fontH);
  183635. DeleteObject (standardSizedFont);
  183636. }
  183637. }
  183638. }
  183639. else
  183640. {
  183641. jassertfalse
  183642. }
  183643. }
  183644. else
  183645. {
  183646. jassertfalse
  183647. }
  183648. }
  183649. return dc;
  183650. }
  183651. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183652. {
  183653. if (kps == 0)
  183654. {
  183655. numKPs = GetKerningPairs (dc, 0, 0);
  183656. kps.calloc (numKPs);
  183657. GetKerningPairs (dc, numKPs, kps);
  183658. }
  183659. numKPs_ = numKPs;
  183660. return kps;
  183661. }
  183662. private:
  183663. HFONT fontH;
  183664. HDC dc;
  183665. String fontName;
  183666. HeapBlock <KERNINGPAIR> kps;
  183667. int numKPs, size;
  183668. bool bold, italic;
  183669. FontDCHolder (const FontDCHolder&);
  183670. FontDCHolder& operator= (const FontDCHolder&);
  183671. };
  183672. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183673. class WindowsTypeface : public CustomTypeface
  183674. {
  183675. public:
  183676. WindowsTypeface (const Font& font)
  183677. {
  183678. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183679. font.isBold(), font.isItalic(), 0);
  183680. TEXTMETRIC tm;
  183681. tm.tmAscent = tm.tmHeight = 1;
  183682. tm.tmDefaultChar = 0;
  183683. GetTextMetrics (dc, &tm);
  183684. setCharacteristics (font.getTypefaceName(),
  183685. tm.tmAscent / (float) tm.tmHeight,
  183686. font.isBold(), font.isItalic(),
  183687. tm.tmDefaultChar);
  183688. }
  183689. bool loadGlyphIfPossible (juce_wchar character)
  183690. {
  183691. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183692. GLYPHMETRICS gm;
  183693. {
  183694. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183695. WORD index = 0;
  183696. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183697. && index == 0xffff)
  183698. {
  183699. return false;
  183700. }
  183701. }
  183702. Path glyphPath;
  183703. TEXTMETRIC tm;
  183704. if (! GetTextMetrics (dc, &tm))
  183705. {
  183706. addGlyph (character, glyphPath, 0);
  183707. return true;
  183708. }
  183709. const float height = (float) tm.tmHeight;
  183710. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183711. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183712. &gm, 0, 0, &identityMatrix);
  183713. if (bufSize > 0)
  183714. {
  183715. HeapBlock<char> data (bufSize);
  183716. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183717. bufSize, data, &identityMatrix);
  183718. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183719. const float scaleX = 1.0f / height;
  183720. const float scaleY = -1.0f / height;
  183721. while ((char*) pheader < data + bufSize)
  183722. {
  183723. float x = scaleX * pheader->pfxStart.x.value;
  183724. float y = scaleY * pheader->pfxStart.y.value;
  183725. glyphPath.startNewSubPath (x, y);
  183726. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183727. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183728. while ((const char*) curve < curveEnd)
  183729. {
  183730. if (curve->wType == TT_PRIM_LINE)
  183731. {
  183732. for (int i = 0; i < curve->cpfx; ++i)
  183733. {
  183734. x = scaleX * curve->apfx[i].x.value;
  183735. y = scaleY * curve->apfx[i].y.value;
  183736. glyphPath.lineTo (x, y);
  183737. }
  183738. }
  183739. else if (curve->wType == TT_PRIM_QSPLINE)
  183740. {
  183741. for (int i = 0; i < curve->cpfx - 1; ++i)
  183742. {
  183743. const float x2 = scaleX * curve->apfx[i].x.value;
  183744. const float y2 = scaleY * curve->apfx[i].y.value;
  183745. float x3, y3;
  183746. if (i < curve->cpfx - 2)
  183747. {
  183748. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183749. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183750. }
  183751. else
  183752. {
  183753. x3 = scaleX * curve->apfx[i + 1].x.value;
  183754. y3 = scaleY * curve->apfx[i + 1].y.value;
  183755. }
  183756. glyphPath.quadraticTo (x2, y2, x3, y3);
  183757. x = x3;
  183758. y = y3;
  183759. }
  183760. }
  183761. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183762. }
  183763. pheader = (const TTPOLYGONHEADER*) curve;
  183764. glyphPath.closeSubPath();
  183765. }
  183766. }
  183767. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183768. int numKPs;
  183769. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183770. for (int i = 0; i < numKPs; ++i)
  183771. {
  183772. if (kps[i].wFirst == character)
  183773. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183774. kps[i].iKernAmount / height);
  183775. }
  183776. return true;
  183777. }
  183778. };
  183779. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183780. {
  183781. return new WindowsTypeface (font);
  183782. }
  183783. #endif
  183784. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183785. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183786. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183787. // compiled on its own).
  183788. #if JUCE_INCLUDED_FILE
  183789. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183790. namespace FileChooserHelpers
  183791. {
  183792. static const void* defaultDirPath = 0;
  183793. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183794. static Component* currentExtraFileWin = 0;
  183795. static bool areThereAnyAlwaysOnTopWindows()
  183796. {
  183797. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183798. {
  183799. Component* c = Desktop::getInstance().getComponent (i);
  183800. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183801. return true;
  183802. }
  183803. return false;
  183804. }
  183805. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183806. {
  183807. if (msg == BFFM_INITIALIZED)
  183808. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183809. else if (msg == BFFM_VALIDATEFAILEDW)
  183810. returnedString = (LPCWSTR) lParam;
  183811. else if (msg == BFFM_VALIDATEFAILEDA)
  183812. returnedString = (const char*) lParam;
  183813. return 0;
  183814. }
  183815. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183816. {
  183817. if (currentExtraFileWin != 0)
  183818. {
  183819. if (uiMsg == WM_INITDIALOG)
  183820. {
  183821. HWND dialogH = GetParent (hdlg);
  183822. jassert (dialogH != 0);
  183823. if (dialogH == 0)
  183824. dialogH = hdlg;
  183825. RECT r, cr;
  183826. GetWindowRect (dialogH, &r);
  183827. GetClientRect (dialogH, &cr);
  183828. SetWindowPos (dialogH, 0,
  183829. r.left, r.top,
  183830. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183831. jmax (150, (int) (r.bottom - r.top)),
  183832. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183833. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183834. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183835. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183836. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183837. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183838. }
  183839. else if (uiMsg == WM_NOTIFY)
  183840. {
  183841. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183842. if (ofn->hdr.code == CDN_SELCHANGE)
  183843. {
  183844. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183845. if (comp != 0)
  183846. {
  183847. TCHAR path [MAX_PATH * 2];
  183848. path[0] = 0;
  183849. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  183850. const String fn ((const WCHAR*) path);
  183851. comp->selectedFileChanged (File (fn));
  183852. }
  183853. }
  183854. }
  183855. }
  183856. return 0;
  183857. }
  183858. class FPComponentHolder : public Component
  183859. {
  183860. public:
  183861. FPComponentHolder()
  183862. {
  183863. setVisible (true);
  183864. setOpaque (true);
  183865. }
  183866. ~FPComponentHolder()
  183867. {
  183868. }
  183869. void paint (Graphics& g)
  183870. {
  183871. g.fillAll (Colours::lightgrey);
  183872. }
  183873. private:
  183874. FPComponentHolder (const FPComponentHolder&);
  183875. FPComponentHolder& operator= (const FPComponentHolder&);
  183876. };
  183877. }
  183878. void FileChooser::showPlatformDialog (Array<File>& results,
  183879. const String& title,
  183880. const File& currentFileOrDirectory,
  183881. const String& filter,
  183882. bool selectsDirectory,
  183883. bool /*selectsFiles*/,
  183884. bool isSaveDialogue,
  183885. bool warnAboutOverwritingExistingFiles,
  183886. bool selectMultipleFiles,
  183887. FilePreviewComponent* extraInfoComponent)
  183888. {
  183889. using namespace FileChooserHelpers;
  183890. const int numCharsAvailable = 32768;
  183891. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  183892. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  183893. int fnameIdx = 0;
  183894. JUCE_TRY
  183895. {
  183896. // use a modal window as the parent for this dialog box
  183897. // to block input from other app windows
  183898. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  183899. Component w (String::empty);
  183900. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  183901. mainMon.getY() + mainMon.getHeight() / 4,
  183902. 0, 0);
  183903. w.setOpaque (true);
  183904. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  183905. w.addToDesktop (0);
  183906. if (extraInfoComponent == 0)
  183907. w.enterModalState();
  183908. String initialDir;
  183909. if (currentFileOrDirectory.isDirectory())
  183910. {
  183911. initialDir = currentFileOrDirectory.getFullPathName();
  183912. }
  183913. else
  183914. {
  183915. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  183916. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  183917. }
  183918. if (currentExtraFileWin->isValidComponent())
  183919. {
  183920. jassertfalse
  183921. return;
  183922. }
  183923. if (selectsDirectory)
  183924. {
  183925. LPITEMIDLIST list = 0;
  183926. filenameSpace.fillWith (0);
  183927. {
  183928. BROWSEINFO bi;
  183929. zerostruct (bi);
  183930. bi.hwndOwner = (HWND) w.getWindowHandle();
  183931. bi.pszDisplayName = fname;
  183932. bi.lpszTitle = title;
  183933. bi.lpfn = browseCallbackProc;
  183934. #ifdef BIF_USENEWUI
  183935. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  183936. #else
  183937. bi.ulFlags = 0x50;
  183938. #endif
  183939. defaultDirPath = (const WCHAR*) initialDir;
  183940. list = SHBrowseForFolder (&bi);
  183941. if (! SHGetPathFromIDListW (list, fname))
  183942. {
  183943. fname[0] = 0;
  183944. returnedString = String::empty;
  183945. }
  183946. }
  183947. LPMALLOC al;
  183948. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  183949. al->Free (list);
  183950. defaultDirPath = 0;
  183951. if (returnedString.isNotEmpty())
  183952. {
  183953. const String stringFName (fname);
  183954. results.add (File (stringFName).getSiblingFile (returnedString));
  183955. returnedString = String::empty;
  183956. return;
  183957. }
  183958. }
  183959. else
  183960. {
  183961. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  183962. if (warnAboutOverwritingExistingFiles)
  183963. flags |= OFN_OVERWRITEPROMPT;
  183964. if (selectMultipleFiles)
  183965. flags |= OFN_ALLOWMULTISELECT;
  183966. if (extraInfoComponent != 0)
  183967. {
  183968. flags |= OFN_ENABLEHOOK;
  183969. currentExtraFileWin = new FPComponentHolder();
  183970. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  183971. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  183972. extraInfoComponent->getHeight());
  183973. currentExtraFileWin->addToDesktop (0);
  183974. currentExtraFileWin->enterModalState();
  183975. }
  183976. {
  183977. WCHAR filters [1024];
  183978. zeromem (filters, sizeof (filters));
  183979. filter.copyToUnicode (filters, 1024);
  183980. filter.copyToUnicode (filters + filter.length() + 1,
  183981. 1022 - filter.length());
  183982. OPENFILENAMEW of;
  183983. zerostruct (of);
  183984. #ifdef OPENFILENAME_SIZE_VERSION_400W
  183985. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  183986. #else
  183987. of.lStructSize = sizeof (of);
  183988. #endif
  183989. of.hwndOwner = (HWND) w.getWindowHandle();
  183990. of.lpstrFilter = filters;
  183991. of.nFilterIndex = 1;
  183992. of.lpstrFile = fname;
  183993. of.nMaxFile = numCharsAvailable;
  183994. of.lpstrInitialDir = initialDir;
  183995. of.lpstrTitle = title;
  183996. of.Flags = flags;
  183997. if (extraInfoComponent != 0)
  183998. of.lpfnHook = &openCallback;
  183999. if (isSaveDialogue)
  184000. {
  184001. if (! GetSaveFileName (&of))
  184002. fname[0] = 0;
  184003. else
  184004. fnameIdx = of.nFileOffset;
  184005. }
  184006. else
  184007. {
  184008. if (! GetOpenFileName (&of))
  184009. fname[0] = 0;
  184010. else
  184011. fnameIdx = of.nFileOffset;
  184012. }
  184013. }
  184014. }
  184015. }
  184016. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184017. catch (...)
  184018. {
  184019. fname[0] = 0;
  184020. }
  184021. #endif
  184022. deleteAndZero (currentExtraFileWin);
  184023. const WCHAR* const files = fname;
  184024. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184025. {
  184026. const WCHAR* filename = files + fnameIdx;
  184027. while (*filename != 0)
  184028. {
  184029. const String filepath (String (files) + "\\" + String (filename));
  184030. results.add (File (filepath));
  184031. filename += CharacterFunctions::length (filename) + 1;
  184032. }
  184033. }
  184034. else if (files[0] != 0)
  184035. {
  184036. results.add (File (files));
  184037. }
  184038. }
  184039. #endif
  184040. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184041. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184042. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184043. // compiled on its own).
  184044. #if JUCE_INCLUDED_FILE
  184045. void SystemClipboard::copyTextToClipboard (const String& text)
  184046. {
  184047. if (OpenClipboard (0) != 0)
  184048. {
  184049. if (EmptyClipboard() != 0)
  184050. {
  184051. const int len = text.length();
  184052. if (len > 0)
  184053. {
  184054. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184055. (len + 1) * sizeof (wchar_t));
  184056. if (bufH != 0)
  184057. {
  184058. WCHAR* const data = (WCHAR*) GlobalLock (bufH);
  184059. text.copyToUnicode (data, len);
  184060. GlobalUnlock (bufH);
  184061. SetClipboardData (CF_UNICODETEXT, bufH);
  184062. }
  184063. }
  184064. }
  184065. CloseClipboard();
  184066. }
  184067. }
  184068. const String SystemClipboard::getTextFromClipboard()
  184069. {
  184070. String result;
  184071. if (OpenClipboard (0) != 0)
  184072. {
  184073. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184074. if (bufH != 0)
  184075. {
  184076. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184077. if (data != 0)
  184078. {
  184079. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184080. GlobalUnlock (bufH);
  184081. }
  184082. }
  184083. CloseClipboard();
  184084. }
  184085. return result;
  184086. }
  184087. #endif
  184088. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184089. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184090. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184091. // compiled on its own).
  184092. #if JUCE_INCLUDED_FILE
  184093. namespace ActiveXHelpers
  184094. {
  184095. class JuceIStorage : public IStorage
  184096. {
  184097. int refCount;
  184098. public:
  184099. JuceIStorage() : refCount (1) {}
  184100. virtual ~JuceIStorage()
  184101. {
  184102. jassert (refCount == 0);
  184103. }
  184104. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184105. {
  184106. if (id == IID_IUnknown || id == IID_IStorage)
  184107. {
  184108. AddRef();
  184109. *result = this;
  184110. return S_OK;
  184111. }
  184112. *result = 0;
  184113. return E_NOINTERFACE;
  184114. }
  184115. ULONG __stdcall AddRef() { return ++refCount; }
  184116. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184117. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184118. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184119. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184120. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184121. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184122. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184123. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184124. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184125. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184126. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184127. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184128. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184129. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184130. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184131. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184132. juce_UseDebuggingNewOperator
  184133. };
  184134. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184135. {
  184136. int refCount;
  184137. HWND window;
  184138. public:
  184139. JuceOleInPlaceFrame (HWND window_)
  184140. : refCount (1),
  184141. window (window_)
  184142. {
  184143. }
  184144. virtual ~JuceOleInPlaceFrame()
  184145. {
  184146. jassert (refCount == 0);
  184147. }
  184148. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184149. {
  184150. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184151. {
  184152. AddRef();
  184153. *result = this;
  184154. return S_OK;
  184155. }
  184156. *result = 0;
  184157. return E_NOINTERFACE;
  184158. }
  184159. ULONG __stdcall AddRef() { return ++refCount; }
  184160. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184161. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184162. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184163. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184164. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184165. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184166. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184167. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184168. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184169. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184170. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184171. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184172. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184173. juce_UseDebuggingNewOperator
  184174. };
  184175. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184176. {
  184177. int refCount;
  184178. HWND window;
  184179. JuceOleInPlaceFrame* frame;
  184180. public:
  184181. JuceIOleInPlaceSite (HWND window_)
  184182. : refCount (1),
  184183. window (window_)
  184184. {
  184185. frame = new JuceOleInPlaceFrame (window);
  184186. }
  184187. virtual ~JuceIOleInPlaceSite()
  184188. {
  184189. jassert (refCount == 0);
  184190. frame->Release();
  184191. }
  184192. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184193. {
  184194. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184195. {
  184196. AddRef();
  184197. *result = this;
  184198. return S_OK;
  184199. }
  184200. *result = 0;
  184201. return E_NOINTERFACE;
  184202. }
  184203. ULONG __stdcall AddRef() { return ++refCount; }
  184204. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184205. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184206. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184207. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184208. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184209. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184210. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184211. {
  184212. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184213. *lplpFrame = frame;
  184214. *lplpDoc = 0;
  184215. lpFrameInfo->fMDIApp = FALSE;
  184216. lpFrameInfo->hwndFrame = window;
  184217. lpFrameInfo->haccel = 0;
  184218. lpFrameInfo->cAccelEntries = 0;
  184219. return S_OK;
  184220. }
  184221. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184222. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184223. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184224. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184225. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184226. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184227. juce_UseDebuggingNewOperator
  184228. };
  184229. class JuceIOleClientSite : public IOleClientSite
  184230. {
  184231. int refCount;
  184232. JuceIOleInPlaceSite* inplaceSite;
  184233. public:
  184234. JuceIOleClientSite (HWND window)
  184235. : refCount (1)
  184236. {
  184237. inplaceSite = new JuceIOleInPlaceSite (window);
  184238. }
  184239. virtual ~JuceIOleClientSite()
  184240. {
  184241. jassert (refCount == 0);
  184242. inplaceSite->Release();
  184243. }
  184244. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184245. {
  184246. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184247. {
  184248. AddRef();
  184249. *result = this;
  184250. return S_OK;
  184251. }
  184252. else if (id == IID_IOleInPlaceSite)
  184253. {
  184254. inplaceSite->AddRef();
  184255. *result = inplaceSite;
  184256. return S_OK;
  184257. }
  184258. *result = 0;
  184259. return E_NOINTERFACE;
  184260. }
  184261. ULONG __stdcall AddRef() { return ++refCount; }
  184262. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184263. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184264. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184265. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184266. HRESULT __stdcall ShowObject() { return S_OK; }
  184267. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184268. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184269. juce_UseDebuggingNewOperator
  184270. };
  184271. static VoidArray activeXComps;
  184272. static HWND getHWND (const ActiveXControlComponent* const component)
  184273. {
  184274. HWND hwnd = 0;
  184275. const IID iid = IID_IOleWindow;
  184276. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184277. if (window != 0)
  184278. {
  184279. window->GetWindow (&hwnd);
  184280. window->Release();
  184281. }
  184282. return hwnd;
  184283. }
  184284. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184285. {
  184286. RECT activeXRect, peerRect;
  184287. GetWindowRect (hwnd, &activeXRect);
  184288. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184289. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184290. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184291. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184292. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184293. switch (message)
  184294. {
  184295. case WM_MOUSEMOVE:
  184296. case WM_LBUTTONDOWN:
  184297. case WM_MBUTTONDOWN:
  184298. case WM_RBUTTONDOWN:
  184299. case WM_LBUTTONUP:
  184300. case WM_MBUTTONUP:
  184301. case WM_RBUTTONUP:
  184302. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184303. break;
  184304. default:
  184305. break;
  184306. }
  184307. }
  184308. }
  184309. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184310. {
  184311. ActiveXControlComponent* const owner;
  184312. bool wasShowing;
  184313. public:
  184314. HWND controlHWND;
  184315. IStorage* storage;
  184316. IOleClientSite* clientSite;
  184317. IOleObject* control;
  184318. ActiveXControlData (HWND hwnd,
  184319. ActiveXControlComponent* const owner_)
  184320. : ComponentMovementWatcher (owner_),
  184321. owner (owner_),
  184322. wasShowing (owner_ != 0 && owner_->isShowing()),
  184323. controlHWND (0),
  184324. storage (new ActiveXHelpers::JuceIStorage()),
  184325. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184326. control (0)
  184327. {
  184328. }
  184329. ~ActiveXControlData()
  184330. {
  184331. if (control != 0)
  184332. {
  184333. control->Close (OLECLOSE_NOSAVE);
  184334. control->Release();
  184335. }
  184336. clientSite->Release();
  184337. storage->Release();
  184338. }
  184339. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184340. {
  184341. Component* const topComp = owner->getTopLevelComponent();
  184342. if (topComp->getPeer() != 0)
  184343. {
  184344. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184345. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184346. }
  184347. }
  184348. void componentPeerChanged()
  184349. {
  184350. const bool isShowingNow = owner->isShowing();
  184351. if (wasShowing != isShowingNow)
  184352. {
  184353. wasShowing = isShowingNow;
  184354. owner->setControlVisible (isShowingNow);
  184355. }
  184356. componentMovedOrResized (true, true);
  184357. }
  184358. void componentVisibilityChanged (Component&)
  184359. {
  184360. componentPeerChanged();
  184361. }
  184362. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184363. {
  184364. return ((ActiveXControlData*) ax->control) != 0
  184365. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184366. }
  184367. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184368. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184369. {
  184370. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184371. {
  184372. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184373. if (doesWindowMatch (ax, hwnd))
  184374. {
  184375. switch (message)
  184376. {
  184377. case WM_MOUSEMOVE:
  184378. case WM_LBUTTONDOWN:
  184379. case WM_MBUTTONDOWN:
  184380. case WM_RBUTTONDOWN:
  184381. case WM_LBUTTONUP:
  184382. case WM_MBUTTONUP:
  184383. case WM_RBUTTONUP:
  184384. case WM_LBUTTONDBLCLK:
  184385. case WM_MBUTTONDBLCLK:
  184386. case WM_RBUTTONDBLCLK:
  184387. if (ax->isShowing())
  184388. {
  184389. ComponentPeer* const peer = ax->getPeer();
  184390. if (peer != 0)
  184391. {
  184392. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184393. if (! ax->areMouseEventsAllowed())
  184394. return 0;
  184395. }
  184396. }
  184397. break;
  184398. default:
  184399. break;
  184400. }
  184401. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184402. }
  184403. }
  184404. return DefWindowProc (hwnd, message, wParam, lParam);
  184405. }
  184406. };
  184407. ActiveXControlComponent::ActiveXControlComponent()
  184408. : originalWndProc (0),
  184409. control (0),
  184410. mouseEventsAllowed (true)
  184411. {
  184412. ActiveXHelpers::activeXComps.add (this);
  184413. }
  184414. ActiveXControlComponent::~ActiveXControlComponent()
  184415. {
  184416. deleteControl();
  184417. ActiveXHelpers::activeXComps.removeValue (this);
  184418. }
  184419. void ActiveXControlComponent::paint (Graphics& g)
  184420. {
  184421. if (control == 0)
  184422. g.fillAll (Colours::lightgrey);
  184423. }
  184424. bool ActiveXControlComponent::createControl (const void* controlIID)
  184425. {
  184426. deleteControl();
  184427. ComponentPeer* const peer = getPeer();
  184428. // the component must have already been added to a real window when you call this!
  184429. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184430. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184431. {
  184432. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184433. HWND hwnd = (HWND) peer->getNativeHandle();
  184434. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184435. HRESULT hr;
  184436. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184437. info->clientSite, info->storage,
  184438. (void**) &(info->control))) == S_OK)
  184439. {
  184440. info->control->SetHostNames (L"Juce", 0);
  184441. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184442. {
  184443. RECT rect;
  184444. rect.left = pos.getX();
  184445. rect.top = pos.getY();
  184446. rect.right = pos.getX() + getWidth();
  184447. rect.bottom = pos.getY() + getHeight();
  184448. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184449. {
  184450. control = info.release();
  184451. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184452. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184453. if (((ActiveXControlData*) control)->controlHWND != 0)
  184454. {
  184455. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184456. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184457. }
  184458. return true;
  184459. }
  184460. }
  184461. }
  184462. }
  184463. return false;
  184464. }
  184465. void ActiveXControlComponent::deleteControl()
  184466. {
  184467. ActiveXControlData* const info = (ActiveXControlData*) control;
  184468. if (info != 0)
  184469. {
  184470. delete info;
  184471. control = 0;
  184472. originalWndProc = 0;
  184473. }
  184474. }
  184475. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184476. {
  184477. ActiveXControlData* const info = (ActiveXControlData*) control;
  184478. void* result = 0;
  184479. if (info != 0 && info->control != 0
  184480. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184481. return result;
  184482. return 0;
  184483. }
  184484. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184485. {
  184486. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184487. if (hwnd != 0)
  184488. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184489. }
  184490. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184491. {
  184492. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184493. if (hwnd != 0)
  184494. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184495. }
  184496. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184497. {
  184498. mouseEventsAllowed = eventsCanReachControl;
  184499. }
  184500. #endif
  184501. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184502. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184503. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184504. // compiled on its own).
  184505. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184506. using namespace QTOLibrary;
  184507. using namespace QTOControlLib;
  184508. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184509. static bool isQTAvailable = false;
  184510. class QuickTimeMovieComponent::Pimpl
  184511. {
  184512. public:
  184513. Pimpl() : dataHandle (0)
  184514. {
  184515. }
  184516. ~Pimpl()
  184517. {
  184518. clearHandle();
  184519. }
  184520. void clearHandle()
  184521. {
  184522. if (dataHandle != 0)
  184523. {
  184524. DisposeHandle (dataHandle);
  184525. dataHandle = 0;
  184526. }
  184527. }
  184528. IQTControlPtr qtControl;
  184529. IQTMoviePtr qtMovie;
  184530. Handle dataHandle;
  184531. };
  184532. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184533. : movieLoaded (false),
  184534. controllerVisible (true)
  184535. {
  184536. pimpl = new Pimpl();
  184537. setMouseEventsAllowed (false);
  184538. }
  184539. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184540. {
  184541. closeMovie();
  184542. pimpl->qtControl = 0;
  184543. deleteControl();
  184544. pimpl = 0;
  184545. }
  184546. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184547. {
  184548. if (! isQTAvailable)
  184549. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184550. return isQTAvailable;
  184551. }
  184552. void QuickTimeMovieComponent::createControlIfNeeded()
  184553. {
  184554. if (isShowing() && ! isControlCreated())
  184555. {
  184556. const IID qtIID = __uuidof (QTControl);
  184557. if (createControl (&qtIID))
  184558. {
  184559. const IID qtInterfaceIID = __uuidof (IQTControl);
  184560. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184561. if (pimpl->qtControl != 0)
  184562. {
  184563. pimpl->qtControl->Release(); // it has one ref too many at this point
  184564. pimpl->qtControl->QuickTimeInitialize();
  184565. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184566. if (movieFile != File::nonexistent)
  184567. loadMovie (movieFile, controllerVisible);
  184568. }
  184569. }
  184570. }
  184571. }
  184572. bool QuickTimeMovieComponent::isControlCreated() const
  184573. {
  184574. return isControlOpen();
  184575. }
  184576. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184577. const bool isControllerVisible)
  184578. {
  184579. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184580. movieFile = File::nonexistent;
  184581. movieLoaded = false;
  184582. pimpl->qtMovie = 0;
  184583. controllerVisible = isControllerVisible;
  184584. createControlIfNeeded();
  184585. if (isControlCreated())
  184586. {
  184587. if (pimpl->qtControl != 0)
  184588. {
  184589. pimpl->qtControl->Put_MovieHandle (0);
  184590. pimpl->clearHandle();
  184591. Movie movie;
  184592. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184593. {
  184594. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184595. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184596. if (pimpl->qtMovie != 0)
  184597. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184598. : qtMovieControllerTypeNone);
  184599. }
  184600. if (movie == 0)
  184601. pimpl->clearHandle();
  184602. }
  184603. movieLoaded = (pimpl->qtMovie != 0);
  184604. }
  184605. else
  184606. {
  184607. // You're trying to open a movie when the control hasn't yet been created, probably because
  184608. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184609. jassertfalse
  184610. }
  184611. return movieLoaded;
  184612. }
  184613. void QuickTimeMovieComponent::closeMovie()
  184614. {
  184615. stop();
  184616. movieFile = File::nonexistent;
  184617. movieLoaded = false;
  184618. pimpl->qtMovie = 0;
  184619. if (pimpl->qtControl != 0)
  184620. pimpl->qtControl->Put_MovieHandle (0);
  184621. pimpl->clearHandle();
  184622. }
  184623. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184624. {
  184625. return movieFile;
  184626. }
  184627. bool QuickTimeMovieComponent::isMovieOpen() const
  184628. {
  184629. return movieLoaded;
  184630. }
  184631. double QuickTimeMovieComponent::getMovieDuration() const
  184632. {
  184633. if (pimpl->qtMovie != 0)
  184634. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184635. return 0.0;
  184636. }
  184637. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184638. {
  184639. if (pimpl->qtMovie != 0)
  184640. {
  184641. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184642. width = r.right - r.left;
  184643. height = r.bottom - r.top;
  184644. }
  184645. else
  184646. {
  184647. width = height = 0;
  184648. }
  184649. }
  184650. void QuickTimeMovieComponent::play()
  184651. {
  184652. if (pimpl->qtMovie != 0)
  184653. pimpl->qtMovie->Play();
  184654. }
  184655. void QuickTimeMovieComponent::stop()
  184656. {
  184657. if (pimpl->qtMovie != 0)
  184658. pimpl->qtMovie->Stop();
  184659. }
  184660. bool QuickTimeMovieComponent::isPlaying() const
  184661. {
  184662. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184663. }
  184664. void QuickTimeMovieComponent::setPosition (const double seconds)
  184665. {
  184666. if (pimpl->qtMovie != 0)
  184667. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184668. }
  184669. double QuickTimeMovieComponent::getPosition() const
  184670. {
  184671. if (pimpl->qtMovie != 0)
  184672. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184673. return 0.0;
  184674. }
  184675. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184676. {
  184677. if (pimpl->qtMovie != 0)
  184678. pimpl->qtMovie->PutRate (newSpeed);
  184679. }
  184680. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184681. {
  184682. if (pimpl->qtMovie != 0)
  184683. {
  184684. pimpl->qtMovie->PutAudioVolume (newVolume);
  184685. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184686. }
  184687. }
  184688. float QuickTimeMovieComponent::getMovieVolume() const
  184689. {
  184690. if (pimpl->qtMovie != 0)
  184691. return pimpl->qtMovie->GetAudioVolume();
  184692. return 0.0f;
  184693. }
  184694. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184695. {
  184696. if (pimpl->qtMovie != 0)
  184697. pimpl->qtMovie->PutLoop (shouldLoop);
  184698. }
  184699. bool QuickTimeMovieComponent::isLooping() const
  184700. {
  184701. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184702. }
  184703. bool QuickTimeMovieComponent::isControllerVisible() const
  184704. {
  184705. return controllerVisible;
  184706. }
  184707. void QuickTimeMovieComponent::parentHierarchyChanged()
  184708. {
  184709. createControlIfNeeded();
  184710. QTCompBaseClass::parentHierarchyChanged();
  184711. }
  184712. void QuickTimeMovieComponent::visibilityChanged()
  184713. {
  184714. createControlIfNeeded();
  184715. QTCompBaseClass::visibilityChanged();
  184716. }
  184717. void QuickTimeMovieComponent::paint (Graphics& g)
  184718. {
  184719. if (! isControlCreated())
  184720. g.fillAll (Colours::black);
  184721. }
  184722. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184723. {
  184724. Handle dataRef = 0;
  184725. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184726. if (err == noErr)
  184727. {
  184728. Str255 suffix;
  184729. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184730. StringPtr name = suffix;
  184731. err = PtrAndHand (name, dataRef, name[0] + 1);
  184732. if (err == noErr)
  184733. {
  184734. long atoms[3];
  184735. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184736. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184737. atoms[2] = EndianU32_NtoB (MovieFileType);
  184738. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184739. if (err == noErr)
  184740. return dataRef;
  184741. }
  184742. DisposeHandle (dataRef);
  184743. }
  184744. return 0;
  184745. }
  184746. static CFStringRef juceStringToCFString (const String& s)
  184747. {
  184748. const int len = s.length();
  184749. const juce_wchar* const t = (const juce_wchar*) s;
  184750. HeapBlock <UniChar> temp (len + 2);
  184751. for (int i = 0; i <= len; ++i)
  184752. temp[i] = t[i];
  184753. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184754. }
  184755. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184756. {
  184757. Boolean trueBool = true;
  184758. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184759. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184760. props[prop].propValueSize = sizeof (trueBool);
  184761. props[prop].propValueAddress = &trueBool;
  184762. ++prop;
  184763. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184764. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184765. props[prop].propValueSize = sizeof (trueBool);
  184766. props[prop].propValueAddress = &trueBool;
  184767. ++prop;
  184768. Boolean isActive = true;
  184769. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184770. props[prop].propID = kQTNewMoviePropertyID_Active;
  184771. props[prop].propValueSize = sizeof (isActive);
  184772. props[prop].propValueAddress = &isActive;
  184773. ++prop;
  184774. MacSetPort (0);
  184775. jassert (prop <= 5);
  184776. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184777. return err == noErr;
  184778. }
  184779. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184780. {
  184781. if (input == 0)
  184782. return false;
  184783. dataHandle = 0;
  184784. bool ok = false;
  184785. QTNewMoviePropertyElement props[5];
  184786. zeromem (props, sizeof (props));
  184787. int prop = 0;
  184788. DataReferenceRecord dr;
  184789. props[prop].propClass = kQTPropertyClass_DataLocation;
  184790. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184791. props[prop].propValueSize = sizeof (dr);
  184792. props[prop].propValueAddress = (void*) &dr;
  184793. ++prop;
  184794. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184795. if (fin != 0)
  184796. {
  184797. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184798. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184799. &dr.dataRef, &dr.dataRefType);
  184800. ok = openMovie (props, prop, movie);
  184801. DisposeHandle (dr.dataRef);
  184802. CFRelease (filePath);
  184803. }
  184804. else
  184805. {
  184806. // sanity-check because this currently needs to load the whole stream into memory..
  184807. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184808. dataHandle = NewHandle ((Size) input->getTotalLength());
  184809. HLock (dataHandle);
  184810. // read the entire stream into memory - this is a pain, but can't get it to work
  184811. // properly using a custom callback to supply the data.
  184812. input->read (*dataHandle, (int) input->getTotalLength());
  184813. HUnlock (dataHandle);
  184814. // different types to get QT to try. (We should really be a bit smarter here by
  184815. // working out in advance which one the stream contains, rather than just trying
  184816. // each one)
  184817. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184818. "\04.avi", "\04.m4a" };
  184819. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184820. {
  184821. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184822. dr.dataRefType = HandleDataHandlerSubType;
  184823. ok = openMovie (props, prop, movie);
  184824. DisposeHandle (dr.dataRef);
  184825. }
  184826. }
  184827. return ok;
  184828. }
  184829. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184830. const bool isControllerVisible)
  184831. {
  184832. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184833. movieFile = movieFile_;
  184834. return ok;
  184835. }
  184836. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184837. const bool isControllerVisible)
  184838. {
  184839. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184840. }
  184841. void QuickTimeMovieComponent::goToStart()
  184842. {
  184843. setPosition (0.0);
  184844. }
  184845. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184846. const RectanglePlacement& placement)
  184847. {
  184848. int normalWidth, normalHeight;
  184849. getMovieNormalSize (normalWidth, normalHeight);
  184850. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  184851. {
  184852. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  184853. placement.applyTo (x, y, w, h,
  184854. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  184855. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  184856. if (w > 0 && h > 0)
  184857. {
  184858. setBounds (roundToInt (x), roundToInt (y),
  184859. roundToInt (w), roundToInt (h));
  184860. }
  184861. }
  184862. else
  184863. {
  184864. setBounds (spaceToFitWithin);
  184865. }
  184866. }
  184867. #endif
  184868. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184869. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184870. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184871. // compiled on its own).
  184872. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  184873. class WebBrowserComponentInternal : public ActiveXControlComponent
  184874. {
  184875. public:
  184876. WebBrowserComponentInternal()
  184877. : browser (0),
  184878. connectionPoint (0),
  184879. adviseCookie (0)
  184880. {
  184881. }
  184882. ~WebBrowserComponentInternal()
  184883. {
  184884. if (connectionPoint != 0)
  184885. connectionPoint->Unadvise (adviseCookie);
  184886. if (browser != 0)
  184887. browser->Release();
  184888. }
  184889. void createBrowser()
  184890. {
  184891. createControl (&CLSID_WebBrowser);
  184892. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  184893. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  184894. if (connectionPointContainer != 0)
  184895. {
  184896. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  184897. &connectionPoint);
  184898. if (connectionPoint != 0)
  184899. {
  184900. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  184901. jassert (owner != 0);
  184902. EventHandler* handler = new EventHandler (owner);
  184903. connectionPoint->Advise (handler, &adviseCookie);
  184904. }
  184905. }
  184906. }
  184907. void goToURL (const String& url,
  184908. const StringArray* headers,
  184909. const MemoryBlock* postData)
  184910. {
  184911. if (browser != 0)
  184912. {
  184913. LPSAFEARRAY sa = 0;
  184914. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  184915. VariantInit (&flags);
  184916. VariantInit (&frame);
  184917. VariantInit (&postDataVar);
  184918. VariantInit (&headersVar);
  184919. if (headers != 0)
  184920. {
  184921. V_VT (&headersVar) = VT_BSTR;
  184922. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  184923. }
  184924. if (postData != 0 && postData->getSize() > 0)
  184925. {
  184926. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  184927. if (sa != 0)
  184928. {
  184929. void* data = 0;
  184930. SafeArrayAccessData (sa, &data);
  184931. jassert (data != 0);
  184932. if (data != 0)
  184933. {
  184934. postData->copyTo (data, 0, postData->getSize());
  184935. SafeArrayUnaccessData (sa);
  184936. VARIANT postDataVar2;
  184937. VariantInit (&postDataVar2);
  184938. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  184939. V_ARRAY (&postDataVar2) = sa;
  184940. postDataVar = postDataVar2;
  184941. }
  184942. }
  184943. }
  184944. browser->Navigate ((BSTR) (const OLECHAR*) url,
  184945. &flags, &frame,
  184946. &postDataVar, &headersVar);
  184947. if (sa != 0)
  184948. SafeArrayDestroy (sa);
  184949. VariantClear (&flags);
  184950. VariantClear (&frame);
  184951. VariantClear (&postDataVar);
  184952. VariantClear (&headersVar);
  184953. }
  184954. }
  184955. IWebBrowser2* browser;
  184956. juce_UseDebuggingNewOperator
  184957. private:
  184958. IConnectionPoint* connectionPoint;
  184959. DWORD adviseCookie;
  184960. class EventHandler : public IDispatch,
  184961. public ComponentMovementWatcher
  184962. {
  184963. public:
  184964. EventHandler (WebBrowserComponent* owner_)
  184965. : ComponentMovementWatcher (owner_),
  184966. owner (owner_),
  184967. refCount (0)
  184968. {
  184969. }
  184970. ~EventHandler()
  184971. {
  184972. }
  184973. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184974. {
  184975. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  184976. {
  184977. AddRef();
  184978. *result = this;
  184979. return S_OK;
  184980. }
  184981. *result = 0;
  184982. return E_NOINTERFACE;
  184983. }
  184984. ULONG __stdcall AddRef() { return ++refCount; }
  184985. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184986. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  184987. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  184988. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  184989. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  184990. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  184991. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  184992. UINT __RPC_FAR* /*puArgErr*/)
  184993. {
  184994. switch (dispIdMember)
  184995. {
  184996. case DISPID_BEFORENAVIGATE2:
  184997. {
  184998. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  184999. String url;
  185000. if ((vurl->vt & VT_BYREF) != 0)
  185001. url = *vurl->pbstrVal;
  185002. else
  185003. url = vurl->bstrVal;
  185004. *pDispParams->rgvarg->pboolVal
  185005. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185006. : VARIANT_TRUE;
  185007. return S_OK;
  185008. }
  185009. default:
  185010. break;
  185011. }
  185012. return E_NOTIMPL;
  185013. }
  185014. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185015. void componentPeerChanged() {}
  185016. void componentVisibilityChanged (Component&)
  185017. {
  185018. owner->visibilityChanged();
  185019. }
  185020. juce_UseDebuggingNewOperator
  185021. private:
  185022. WebBrowserComponent* const owner;
  185023. int refCount;
  185024. EventHandler (const EventHandler&);
  185025. EventHandler& operator= (const EventHandler&);
  185026. };
  185027. };
  185028. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185029. : browser (0),
  185030. blankPageShown (false),
  185031. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185032. {
  185033. setOpaque (true);
  185034. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185035. }
  185036. WebBrowserComponent::~WebBrowserComponent()
  185037. {
  185038. delete browser;
  185039. }
  185040. void WebBrowserComponent::goToURL (const String& url,
  185041. const StringArray* headers,
  185042. const MemoryBlock* postData)
  185043. {
  185044. lastURL = url;
  185045. lastHeaders.clear();
  185046. if (headers != 0)
  185047. lastHeaders = *headers;
  185048. lastPostData.setSize (0);
  185049. if (postData != 0)
  185050. lastPostData = *postData;
  185051. blankPageShown = false;
  185052. browser->goToURL (url, headers, postData);
  185053. }
  185054. void WebBrowserComponent::stop()
  185055. {
  185056. if (browser->browser != 0)
  185057. browser->browser->Stop();
  185058. }
  185059. void WebBrowserComponent::goBack()
  185060. {
  185061. lastURL = String::empty;
  185062. blankPageShown = false;
  185063. if (browser->browser != 0)
  185064. browser->browser->GoBack();
  185065. }
  185066. void WebBrowserComponent::goForward()
  185067. {
  185068. lastURL = String::empty;
  185069. if (browser->browser != 0)
  185070. browser->browser->GoForward();
  185071. }
  185072. void WebBrowserComponent::refresh()
  185073. {
  185074. if (browser->browser != 0)
  185075. browser->browser->Refresh();
  185076. }
  185077. void WebBrowserComponent::paint (Graphics& g)
  185078. {
  185079. if (browser->browser == 0)
  185080. g.fillAll (Colours::white);
  185081. }
  185082. void WebBrowserComponent::checkWindowAssociation()
  185083. {
  185084. if (isShowing())
  185085. {
  185086. if (browser->browser == 0 && getPeer() != 0)
  185087. {
  185088. browser->createBrowser();
  185089. reloadLastURL();
  185090. }
  185091. else
  185092. {
  185093. if (blankPageShown)
  185094. goBack();
  185095. }
  185096. }
  185097. else
  185098. {
  185099. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185100. {
  185101. // when the component becomes invisible, some stuff like flash
  185102. // carries on playing audio, so we need to force it onto a blank
  185103. // page to avoid this..
  185104. blankPageShown = true;
  185105. browser->goToURL ("about:blank", 0, 0);
  185106. }
  185107. }
  185108. }
  185109. void WebBrowserComponent::reloadLastURL()
  185110. {
  185111. if (lastURL.isNotEmpty())
  185112. {
  185113. goToURL (lastURL, &lastHeaders, &lastPostData);
  185114. lastURL = String::empty;
  185115. }
  185116. }
  185117. void WebBrowserComponent::parentHierarchyChanged()
  185118. {
  185119. checkWindowAssociation();
  185120. }
  185121. void WebBrowserComponent::resized()
  185122. {
  185123. browser->setSize (getWidth(), getHeight());
  185124. }
  185125. void WebBrowserComponent::visibilityChanged()
  185126. {
  185127. checkWindowAssociation();
  185128. }
  185129. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185130. {
  185131. return true;
  185132. }
  185133. #endif
  185134. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185135. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185136. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185137. // compiled on its own).
  185138. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185139. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185140. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185141. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185142. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185143. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185144. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185145. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185146. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185147. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185148. #define WGL_ACCELERATION_ARB 0x2003
  185149. #define WGL_SWAP_METHOD_ARB 0x2007
  185150. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185151. #define WGL_PIXEL_TYPE_ARB 0x2013
  185152. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185153. #define WGL_COLOR_BITS_ARB 0x2014
  185154. #define WGL_RED_BITS_ARB 0x2015
  185155. #define WGL_GREEN_BITS_ARB 0x2017
  185156. #define WGL_BLUE_BITS_ARB 0x2019
  185157. #define WGL_ALPHA_BITS_ARB 0x201B
  185158. #define WGL_DEPTH_BITS_ARB 0x2022
  185159. #define WGL_STENCIL_BITS_ARB 0x2023
  185160. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185161. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185162. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185163. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185164. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185165. #define WGL_STEREO_ARB 0x2012
  185166. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185167. #define WGL_SAMPLES_ARB 0x2042
  185168. #define WGL_TYPE_RGBA_ARB 0x202B
  185169. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185170. {
  185171. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185172. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185173. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185174. else
  185175. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185176. }
  185177. class WindowedGLContext : public OpenGLContext
  185178. {
  185179. public:
  185180. WindowedGLContext (Component* const component_,
  185181. HGLRC contextToShareWith,
  185182. const OpenGLPixelFormat& pixelFormat)
  185183. : renderContext (0),
  185184. nativeWindow (0),
  185185. dc (0),
  185186. component (component_)
  185187. {
  185188. jassert (component != 0);
  185189. createNativeWindow();
  185190. // Use a default pixel format that should be supported everywhere
  185191. PIXELFORMATDESCRIPTOR pfd;
  185192. zerostruct (pfd);
  185193. pfd.nSize = sizeof (pfd);
  185194. pfd.nVersion = 1;
  185195. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185196. pfd.iPixelType = PFD_TYPE_RGBA;
  185197. pfd.cColorBits = 24;
  185198. pfd.cDepthBits = 16;
  185199. const int format = ChoosePixelFormat (dc, &pfd);
  185200. if (format != 0)
  185201. SetPixelFormat (dc, format, &pfd);
  185202. renderContext = wglCreateContext (dc);
  185203. makeActive();
  185204. setPixelFormat (pixelFormat);
  185205. if (contextToShareWith != 0 && renderContext != 0)
  185206. wglShareLists (contextToShareWith, renderContext);
  185207. }
  185208. ~WindowedGLContext()
  185209. {
  185210. makeInactive();
  185211. wglDeleteContext (renderContext);
  185212. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185213. delete nativeWindow;
  185214. }
  185215. bool makeActive() const throw()
  185216. {
  185217. jassert (renderContext != 0);
  185218. return wglMakeCurrent (dc, renderContext) != 0;
  185219. }
  185220. bool makeInactive() const throw()
  185221. {
  185222. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185223. }
  185224. bool isActive() const throw()
  185225. {
  185226. return wglGetCurrentContext() == renderContext;
  185227. }
  185228. const OpenGLPixelFormat getPixelFormat() const
  185229. {
  185230. OpenGLPixelFormat pf;
  185231. makeActive();
  185232. StringArray availableExtensions;
  185233. getWglExtensions (dc, availableExtensions);
  185234. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185235. return pf;
  185236. }
  185237. void* getRawContext() const throw()
  185238. {
  185239. return renderContext;
  185240. }
  185241. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185242. {
  185243. makeActive();
  185244. PIXELFORMATDESCRIPTOR pfd;
  185245. zerostruct (pfd);
  185246. pfd.nSize = sizeof (pfd);
  185247. pfd.nVersion = 1;
  185248. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185249. pfd.iPixelType = PFD_TYPE_RGBA;
  185250. pfd.iLayerType = PFD_MAIN_PLANE;
  185251. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185252. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185253. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185254. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185255. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185256. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185257. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185258. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185259. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185260. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185261. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185262. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185263. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185264. int format = 0;
  185265. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185266. StringArray availableExtensions;
  185267. getWglExtensions (dc, availableExtensions);
  185268. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185269. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185270. {
  185271. int attributes[64];
  185272. int n = 0;
  185273. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185274. attributes[n++] = GL_TRUE;
  185275. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185276. attributes[n++] = GL_TRUE;
  185277. attributes[n++] = WGL_ACCELERATION_ARB;
  185278. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185279. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185280. attributes[n++] = GL_TRUE;
  185281. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185282. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185283. attributes[n++] = WGL_COLOR_BITS_ARB;
  185284. attributes[n++] = pfd.cColorBits;
  185285. attributes[n++] = WGL_RED_BITS_ARB;
  185286. attributes[n++] = pixelFormat.redBits;
  185287. attributes[n++] = WGL_GREEN_BITS_ARB;
  185288. attributes[n++] = pixelFormat.greenBits;
  185289. attributes[n++] = WGL_BLUE_BITS_ARB;
  185290. attributes[n++] = pixelFormat.blueBits;
  185291. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185292. attributes[n++] = pixelFormat.alphaBits;
  185293. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185294. attributes[n++] = pixelFormat.depthBufferBits;
  185295. if (pixelFormat.stencilBufferBits > 0)
  185296. {
  185297. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185298. attributes[n++] = pixelFormat.stencilBufferBits;
  185299. }
  185300. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185301. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185302. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185303. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185304. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185305. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185306. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185307. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185308. if (availableExtensions.contains ("WGL_ARB_multisample")
  185309. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185310. {
  185311. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185312. attributes[n++] = 1;
  185313. attributes[n++] = WGL_SAMPLES_ARB;
  185314. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185315. }
  185316. attributes[n++] = 0;
  185317. UINT formatsCount;
  185318. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185319. (void) ok;
  185320. jassert (ok);
  185321. }
  185322. else
  185323. {
  185324. format = ChoosePixelFormat (dc, &pfd);
  185325. }
  185326. if (format != 0)
  185327. {
  185328. makeInactive();
  185329. // win32 can't change the pixel format of a window, so need to delete the
  185330. // old one and create a new one..
  185331. jassert (nativeWindow != 0);
  185332. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185333. delete nativeWindow;
  185334. createNativeWindow();
  185335. if (SetPixelFormat (dc, format, &pfd))
  185336. {
  185337. wglDeleteContext (renderContext);
  185338. renderContext = wglCreateContext (dc);
  185339. jassert (renderContext != 0);
  185340. return renderContext != 0;
  185341. }
  185342. }
  185343. return false;
  185344. }
  185345. void updateWindowPosition (int x, int y, int w, int h, int)
  185346. {
  185347. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185348. x, y, w, h,
  185349. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185350. }
  185351. void repaint()
  185352. {
  185353. const Rectangle<int> bounds (nativeWindow->getBounds());
  185354. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185355. }
  185356. void swapBuffers()
  185357. {
  185358. SwapBuffers (dc);
  185359. }
  185360. bool setSwapInterval (const int numFramesPerSwap)
  185361. {
  185362. makeActive();
  185363. StringArray availableExtensions;
  185364. getWglExtensions (dc, availableExtensions);
  185365. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185366. return availableExtensions.contains ("WGL_EXT_swap_control")
  185367. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185368. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185369. }
  185370. int getSwapInterval() const
  185371. {
  185372. makeActive();
  185373. StringArray availableExtensions;
  185374. getWglExtensions (dc, availableExtensions);
  185375. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185376. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185377. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185378. return wglGetSwapIntervalEXT();
  185379. return 0;
  185380. }
  185381. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185382. {
  185383. jassert (isActive());
  185384. StringArray availableExtensions;
  185385. getWglExtensions (dc, availableExtensions);
  185386. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185387. int numTypes = 0;
  185388. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185389. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185390. {
  185391. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185392. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185393. jassertfalse
  185394. }
  185395. else
  185396. {
  185397. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185398. }
  185399. OpenGLPixelFormat pf;
  185400. for (int i = 0; i < numTypes; ++i)
  185401. {
  185402. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185403. {
  185404. bool alreadyListed = false;
  185405. for (int j = results.size(); --j >= 0;)
  185406. if (pf == *results.getUnchecked(j))
  185407. alreadyListed = true;
  185408. if (! alreadyListed)
  185409. results.add (new OpenGLPixelFormat (pf));
  185410. }
  185411. }
  185412. }
  185413. void* getNativeWindowHandle() const
  185414. {
  185415. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185416. }
  185417. juce_UseDebuggingNewOperator
  185418. HGLRC renderContext;
  185419. private:
  185420. Win32ComponentPeer* nativeWindow;
  185421. Component* const component;
  185422. HDC dc;
  185423. void createNativeWindow()
  185424. {
  185425. nativeWindow = new Win32ComponentPeer (component, 0);
  185426. nativeWindow->dontRepaint = true;
  185427. nativeWindow->setVisible (true);
  185428. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185429. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185430. if (peer != 0)
  185431. {
  185432. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185433. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185434. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185435. }
  185436. dc = GetDC (hwnd);
  185437. }
  185438. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185439. OpenGLPixelFormat& result,
  185440. const StringArray& availableExtensions) const throw()
  185441. {
  185442. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185443. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185444. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185445. {
  185446. int attributes[32];
  185447. int numAttributes = 0;
  185448. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185449. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185450. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185451. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185452. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185453. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185454. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185455. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185456. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185457. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185458. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185459. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185460. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185461. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185462. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185463. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185464. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185465. int values[32];
  185466. zeromem (values, sizeof (values));
  185467. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185468. {
  185469. int n = 0;
  185470. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185471. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185472. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185473. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185474. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185475. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185476. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185477. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185478. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185479. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185480. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185481. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185482. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185483. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185484. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185485. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185486. return isValidFormat;
  185487. }
  185488. else
  185489. {
  185490. jassertfalse
  185491. }
  185492. }
  185493. else
  185494. {
  185495. PIXELFORMATDESCRIPTOR pfd;
  185496. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185497. {
  185498. result.redBits = pfd.cRedBits;
  185499. result.greenBits = pfd.cGreenBits;
  185500. result.blueBits = pfd.cBlueBits;
  185501. result.alphaBits = pfd.cAlphaBits;
  185502. result.depthBufferBits = pfd.cDepthBits;
  185503. result.stencilBufferBits = pfd.cStencilBits;
  185504. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185505. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185506. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185507. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185508. result.fullSceneAntiAliasingNumSamples = 0;
  185509. return true;
  185510. }
  185511. else
  185512. {
  185513. jassertfalse
  185514. }
  185515. }
  185516. return false;
  185517. }
  185518. WindowedGLContext (const WindowedGLContext&);
  185519. WindowedGLContext& operator= (const WindowedGLContext&);
  185520. };
  185521. OpenGLContext* OpenGLComponent::createContext()
  185522. {
  185523. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this,
  185524. contextToShareListsWith != 0 ? (HGLRC) contextToShareListsWith->getRawContext() : 0,
  185525. preferredPixelFormat));
  185526. return (c->renderContext != 0) ? c.release() : 0;
  185527. }
  185528. void* OpenGLComponent::getNativeWindowHandle() const
  185529. {
  185530. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle() : 0;
  185531. }
  185532. void juce_glViewport (const int w, const int h)
  185533. {
  185534. glViewport (0, 0, w, h);
  185535. }
  185536. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185537. OwnedArray <OpenGLPixelFormat>& results)
  185538. {
  185539. Component tempComp;
  185540. {
  185541. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185542. wc.makeActive();
  185543. wc.findAlternativeOpenGLPixelFormats (results);
  185544. }
  185545. }
  185546. #endif
  185547. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185548. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185549. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185550. // compiled on its own).
  185551. #if JUCE_INCLUDED_FILE
  185552. #if JUCE_USE_CDREADER
  185553. namespace CDReaderHelpers
  185554. {
  185555. //***************************************************************************
  185556. // %%% TARGET STATUS VALUES %%%
  185557. //***************************************************************************
  185558. #define STATUS_GOOD 0x00 // Status Good
  185559. #define STATUS_CHKCOND 0x02 // Check Condition
  185560. #define STATUS_CONDMET 0x04 // Condition Met
  185561. #define STATUS_BUSY 0x08 // Busy
  185562. #define STATUS_INTERM 0x10 // Intermediate
  185563. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185564. #define STATUS_RESCONF 0x18 // Reservation conflict
  185565. #define STATUS_COMTERM 0x22 // Command Terminated
  185566. #define STATUS_QFULL 0x28 // Queue full
  185567. //***************************************************************************
  185568. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185569. //***************************************************************************
  185570. #define MAXLUN 7 // Maximum Logical Unit Id
  185571. #define MAXTARG 7 // Maximum Target Id
  185572. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185573. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185574. //***************************************************************************
  185575. // %%% Commands for all Device Types %%%
  185576. //***************************************************************************
  185577. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185578. #define SCSI_COMPARE 0x39 // Compare (O)
  185579. #define SCSI_COPY 0x18 // Copy (O)
  185580. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185581. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185582. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185583. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185584. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185585. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185586. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185587. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185588. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185589. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185590. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185591. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185592. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185593. //***************************************************************************
  185594. // %%% Commands Unique to Direct Access Devices %%%
  185595. //***************************************************************************
  185596. #define SCSI_COMPARE 0x39 // Compare (O)
  185597. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185598. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185599. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185600. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185601. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185602. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185603. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185604. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185605. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185606. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185607. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185608. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185609. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185610. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185611. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185612. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185613. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185614. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185615. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185616. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185617. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185618. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185619. #define SCSI_VERIFY 0x2F // Verify (O)
  185620. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185621. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185622. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185623. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185624. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185625. //***************************************************************************
  185626. // %%% Commands Unique to Sequential Access Devices %%%
  185627. //***************************************************************************
  185628. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185629. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185630. #define SCSI_LOCATE 0x2B // Locate (O)
  185631. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185632. #define SCSI_READ_POS 0x34 // Read Position (O)
  185633. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185634. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185635. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185636. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185637. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185638. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185639. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185640. //***************************************************************************
  185641. // %%% Commands Unique to Printer Devices %%%
  185642. //***************************************************************************
  185643. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185644. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185645. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185646. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185647. //***************************************************************************
  185648. // %%% Commands Unique to Processor Devices %%%
  185649. //***************************************************************************
  185650. #define SCSI_RECEIVE 0x08 // Receive (O)
  185651. #define SCSI_SEND 0x0A // Send (O)
  185652. //***************************************************************************
  185653. // %%% Commands Unique to Write-Once Devices %%%
  185654. //***************************************************************************
  185655. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185656. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185657. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185658. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185659. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185660. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185661. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185662. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185663. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185664. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185665. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185666. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185667. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185668. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185669. //***************************************************************************
  185670. // %%% Commands Unique to CD-ROM Devices %%%
  185671. //***************************************************************************
  185672. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185673. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185674. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185675. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185676. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185677. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185678. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185679. #define SCSI_READHEADER 0x44 // Read Header (O)
  185680. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185681. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185682. //***************************************************************************
  185683. // %%% Commands Unique to Scanner Devices %%%
  185684. //***************************************************************************
  185685. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185686. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185687. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185688. #define SCSI_SCAN 0x1B // Scan (O)
  185689. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185690. //***************************************************************************
  185691. // %%% Commands Unique to Optical Memory Devices %%%
  185692. //***************************************************************************
  185693. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185694. //***************************************************************************
  185695. // %%% Commands Unique to Medium Changer Devices %%%
  185696. //***************************************************************************
  185697. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185698. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185699. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185700. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185701. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185702. //***************************************************************************
  185703. // %%% Commands Unique to Communication Devices %%%
  185704. //***************************************************************************
  185705. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185706. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185707. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185708. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185709. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185710. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185711. //***************************************************************************
  185712. // %%% Request Sense Data Format %%%
  185713. //***************************************************************************
  185714. typedef struct {
  185715. BYTE ErrorCode; // Error Code (70H or 71H)
  185716. BYTE SegmentNum; // Number of current segment descriptor
  185717. BYTE SenseKey; // Sense Key(See bit definitions too)
  185718. BYTE InfoByte0; // Information MSB
  185719. BYTE InfoByte1; // Information MID
  185720. BYTE InfoByte2; // Information MID
  185721. BYTE InfoByte3; // Information LSB
  185722. BYTE AddSenLen; // Additional Sense Length
  185723. BYTE ComSpecInf0; // Command Specific Information MSB
  185724. BYTE ComSpecInf1; // Command Specific Information MID
  185725. BYTE ComSpecInf2; // Command Specific Information MID
  185726. BYTE ComSpecInf3; // Command Specific Information LSB
  185727. BYTE AddSenseCode; // Additional Sense Code
  185728. BYTE AddSenQual; // Additional Sense Code Qualifier
  185729. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185730. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185731. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185732. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185733. BYTE AddSenseBytes; // Additional Sense Bytes
  185734. } SENSE_DATA_FMT;
  185735. //***************************************************************************
  185736. // %%% REQUEST SENSE ERROR CODE %%%
  185737. //***************************************************************************
  185738. #define SERROR_CURRENT 0x70 // Current Errors
  185739. #define SERROR_DEFERED 0x71 // Deferred Errors
  185740. //***************************************************************************
  185741. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185742. //***************************************************************************
  185743. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185744. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185745. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185746. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185747. //***************************************************************************
  185748. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185749. //***************************************************************************
  185750. #define KEY_NOSENSE 0x00 // No Sense
  185751. #define KEY_RECERROR 0x01 // Recovered Error
  185752. #define KEY_NOTREADY 0x02 // Not Ready
  185753. #define KEY_MEDIUMERR 0x03 // Medium Error
  185754. #define KEY_HARDERROR 0x04 // Hardware Error
  185755. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185756. #define KEY_UNITATT 0x06 // Unit Attention
  185757. #define KEY_DATAPROT 0x07 // Data Protect
  185758. #define KEY_BLANKCHK 0x08 // Blank Check
  185759. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185760. #define KEY_COPYABORT 0x0A // Copy Abort
  185761. #define KEY_EQUAL 0x0C // Equal (Search)
  185762. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185763. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185764. #define KEY_RESERVED 0x0F // Reserved
  185765. //***************************************************************************
  185766. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185767. //***************************************************************************
  185768. #define DTYPE_DASD 0x00 // Disk Device
  185769. #define DTYPE_SEQD 0x01 // Tape Device
  185770. #define DTYPE_PRNT 0x02 // Printer
  185771. #define DTYPE_PROC 0x03 // Processor
  185772. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185773. #define DTYPE_CROM 0x05 // CD-ROM device
  185774. #define DTYPE_SCAN 0x06 // Scanner device
  185775. #define DTYPE_OPTI 0x07 // Optical memory device
  185776. #define DTYPE_JUKE 0x08 // Medium Changer device
  185777. #define DTYPE_COMM 0x09 // Communications device
  185778. #define DTYPE_RESL 0x0A // Reserved (low)
  185779. #define DTYPE_RESH 0x1E // Reserved (high)
  185780. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185781. //***************************************************************************
  185782. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185783. //***************************************************************************
  185784. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185785. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185786. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185787. #define ANSI_RESLO 0x3 // Reserved (low)
  185788. #define ANSI_RESHI 0x7 // Reserved (high)
  185789. typedef struct
  185790. {
  185791. USHORT Length;
  185792. UCHAR ScsiStatus;
  185793. UCHAR PathId;
  185794. UCHAR TargetId;
  185795. UCHAR Lun;
  185796. UCHAR CdbLength;
  185797. UCHAR SenseInfoLength;
  185798. UCHAR DataIn;
  185799. ULONG DataTransferLength;
  185800. ULONG TimeOutValue;
  185801. ULONG DataBufferOffset;
  185802. ULONG SenseInfoOffset;
  185803. UCHAR Cdb[16];
  185804. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185805. typedef struct
  185806. {
  185807. USHORT Length;
  185808. UCHAR ScsiStatus;
  185809. UCHAR PathId;
  185810. UCHAR TargetId;
  185811. UCHAR Lun;
  185812. UCHAR CdbLength;
  185813. UCHAR SenseInfoLength;
  185814. UCHAR DataIn;
  185815. ULONG DataTransferLength;
  185816. ULONG TimeOutValue;
  185817. PVOID DataBuffer;
  185818. ULONG SenseInfoOffset;
  185819. UCHAR Cdb[16];
  185820. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185821. typedef struct
  185822. {
  185823. SCSI_PASS_THROUGH_DIRECT spt;
  185824. ULONG Filler;
  185825. UCHAR ucSenseBuf[32];
  185826. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185827. typedef struct
  185828. {
  185829. ULONG Length;
  185830. UCHAR PortNumber;
  185831. UCHAR PathId;
  185832. UCHAR TargetId;
  185833. UCHAR Lun;
  185834. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185835. #define METHOD_BUFFERED 0
  185836. #define METHOD_IN_DIRECT 1
  185837. #define METHOD_OUT_DIRECT 2
  185838. #define METHOD_NEITHER 3
  185839. #define FILE_ANY_ACCESS 0
  185840. #ifndef FILE_READ_ACCESS
  185841. #define FILE_READ_ACCESS (0x0001)
  185842. #endif
  185843. #ifndef FILE_WRITE_ACCESS
  185844. #define FILE_WRITE_ACCESS (0x0002)
  185845. #endif
  185846. #define IOCTL_SCSI_BASE 0x00000004
  185847. #define SCSI_IOCTL_DATA_OUT 0
  185848. #define SCSI_IOCTL_DATA_IN 1
  185849. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  185850. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  185851. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  185852. )
  185853. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185854. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  185855. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185856. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  185857. #define SENSE_LEN 14
  185858. #define SRB_DIR_SCSI 0x00
  185859. #define SRB_POSTING 0x01
  185860. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  185861. #define SRB_DIR_IN 0x08
  185862. #define SRB_DIR_OUT 0x10
  185863. #define SRB_EVENT_NOTIFY 0x40
  185864. #define RESIDUAL_COUNT_SUPPORTED 0x02
  185865. #define MAX_SRB_TIMEOUT 1080001u
  185866. #define DEFAULT_SRB_TIMEOUT 1080001u
  185867. #define SC_HA_INQUIRY 0x00
  185868. #define SC_GET_DEV_TYPE 0x01
  185869. #define SC_EXEC_SCSI_CMD 0x02
  185870. #define SC_ABORT_SRB 0x03
  185871. #define SC_RESET_DEV 0x04
  185872. #define SC_SET_HA_PARMS 0x05
  185873. #define SC_GET_DISK_INFO 0x06
  185874. #define SC_RESCAN_SCSI_BUS 0x07
  185875. #define SC_GETSET_TIMEOUTS 0x08
  185876. #define SS_PENDING 0x00
  185877. #define SS_COMP 0x01
  185878. #define SS_ABORTED 0x02
  185879. #define SS_ABORT_FAIL 0x03
  185880. #define SS_ERR 0x04
  185881. #define SS_INVALID_CMD 0x80
  185882. #define SS_INVALID_HA 0x81
  185883. #define SS_NO_DEVICE 0x82
  185884. #define SS_INVALID_SRB 0xE0
  185885. #define SS_OLD_MANAGER 0xE1
  185886. #define SS_BUFFER_ALIGN 0xE1
  185887. #define SS_ILLEGAL_MODE 0xE2
  185888. #define SS_NO_ASPI 0xE3
  185889. #define SS_FAILED_INIT 0xE4
  185890. #define SS_ASPI_IS_BUSY 0xE5
  185891. #define SS_BUFFER_TO_BIG 0xE6
  185892. #define SS_BUFFER_TOO_BIG 0xE6
  185893. #define SS_MISMATCHED_COMPONENTS 0xE7
  185894. #define SS_NO_ADAPTERS 0xE8
  185895. #define SS_INSUFFICIENT_RESOURCES 0xE9
  185896. #define SS_ASPI_IS_SHUTDOWN 0xEA
  185897. #define SS_BAD_INSTALL 0xEB
  185898. #define HASTAT_OK 0x00
  185899. #define HASTAT_SEL_TO 0x11
  185900. #define HASTAT_DO_DU 0x12
  185901. #define HASTAT_BUS_FREE 0x13
  185902. #define HASTAT_PHASE_ERR 0x14
  185903. #define HASTAT_TIMEOUT 0x09
  185904. #define HASTAT_COMMAND_TIMEOUT 0x0B
  185905. #define HASTAT_MESSAGE_REJECT 0x0D
  185906. #define HASTAT_BUS_RESET 0x0E
  185907. #define HASTAT_PARITY_ERROR 0x0F
  185908. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  185909. #define PACKED
  185910. #pragma pack(1)
  185911. typedef struct
  185912. {
  185913. BYTE SRB_Cmd;
  185914. BYTE SRB_Status;
  185915. BYTE SRB_HaID;
  185916. BYTE SRB_Flags;
  185917. DWORD SRB_Hdr_Rsvd;
  185918. BYTE HA_Count;
  185919. BYTE HA_SCSI_ID;
  185920. BYTE HA_ManagerId[16];
  185921. BYTE HA_Identifier[16];
  185922. BYTE HA_Unique[16];
  185923. WORD HA_Rsvd1;
  185924. BYTE pad[20];
  185925. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  185926. typedef struct
  185927. {
  185928. BYTE SRB_Cmd;
  185929. BYTE SRB_Status;
  185930. BYTE SRB_HaID;
  185931. BYTE SRB_Flags;
  185932. DWORD SRB_Hdr_Rsvd;
  185933. BYTE SRB_Target;
  185934. BYTE SRB_Lun;
  185935. BYTE SRB_DeviceType;
  185936. BYTE SRB_Rsvd1;
  185937. BYTE pad[68];
  185938. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  185939. typedef struct
  185940. {
  185941. BYTE SRB_Cmd;
  185942. BYTE SRB_Status;
  185943. BYTE SRB_HaID;
  185944. BYTE SRB_Flags;
  185945. DWORD SRB_Hdr_Rsvd;
  185946. BYTE SRB_Target;
  185947. BYTE SRB_Lun;
  185948. WORD SRB_Rsvd1;
  185949. DWORD SRB_BufLen;
  185950. BYTE FAR *SRB_BufPointer;
  185951. BYTE SRB_SenseLen;
  185952. BYTE SRB_CDBLen;
  185953. BYTE SRB_HaStat;
  185954. BYTE SRB_TargStat;
  185955. VOID FAR *SRB_PostProc;
  185956. BYTE SRB_Rsvd2[20];
  185957. BYTE CDBByte[16];
  185958. BYTE SenseArea[SENSE_LEN+2];
  185959. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  185960. typedef struct
  185961. {
  185962. BYTE SRB_Cmd;
  185963. BYTE SRB_Status;
  185964. BYTE SRB_HaId;
  185965. BYTE SRB_Flags;
  185966. DWORD SRB_Hdr_Rsvd;
  185967. } PACKED SRB, *PSRB, FAR *LPSRB;
  185968. #pragma pack()
  185969. struct CDDeviceInfo
  185970. {
  185971. char vendor[9];
  185972. char productId[17];
  185973. char rev[5];
  185974. char vendorSpec[21];
  185975. BYTE ha;
  185976. BYTE tgt;
  185977. BYTE lun;
  185978. char scsiDriveLetter; // will be 0 if not using scsi
  185979. };
  185980. class CDReadBuffer
  185981. {
  185982. public:
  185983. int startFrame;
  185984. int numFrames;
  185985. int dataStartOffset;
  185986. int dataLength;
  185987. BYTE* buffer;
  185988. int bufferSize;
  185989. int index;
  185990. bool wantsIndex;
  185991. CDReadBuffer (const int numberOfFrames)
  185992. : startFrame (0),
  185993. numFrames (0),
  185994. dataStartOffset (0),
  185995. dataLength (0),
  185996. index (0),
  185997. wantsIndex (false)
  185998. {
  185999. bufferSize = 2352 * numberOfFrames;
  186000. buffer = (BYTE*) juce_malloc (bufferSize);
  186001. }
  186002. ~CDReadBuffer()
  186003. {
  186004. juce_free (buffer);
  186005. }
  186006. bool isZero() const
  186007. {
  186008. BYTE* p = buffer + dataStartOffset;
  186009. for (int i = dataLength; --i >= 0;)
  186010. if (*p++ != 0)
  186011. return false;
  186012. return true;
  186013. }
  186014. };
  186015. class CDDeviceHandle;
  186016. class CDController
  186017. {
  186018. public:
  186019. CDController();
  186020. virtual ~CDController();
  186021. virtual bool read (CDReadBuffer* t) = 0;
  186022. virtual void shutDown();
  186023. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186024. int getLastIndex();
  186025. public:
  186026. bool initialised;
  186027. CDDeviceHandle* deviceInfo;
  186028. int framesToCheck, framesOverlap;
  186029. void prepare (SRB_ExecSCSICmd& s);
  186030. void perform (SRB_ExecSCSICmd& s);
  186031. void setPaused (bool paused);
  186032. };
  186033. #pragma pack(1)
  186034. struct TOCTRACK
  186035. {
  186036. BYTE rsvd;
  186037. BYTE ADR;
  186038. BYTE trackNumber;
  186039. BYTE rsvd2;
  186040. BYTE addr[4];
  186041. };
  186042. struct TOC
  186043. {
  186044. WORD tocLen;
  186045. BYTE firstTrack;
  186046. BYTE lastTrack;
  186047. TOCTRACK tracks[100];
  186048. };
  186049. #pragma pack()
  186050. enum
  186051. {
  186052. READTYPE_ANY = 0,
  186053. READTYPE_ATAPI1 = 1,
  186054. READTYPE_ATAPI2 = 2,
  186055. READTYPE_READ6 = 3,
  186056. READTYPE_READ10 = 4,
  186057. READTYPE_READ_D8 = 5,
  186058. READTYPE_READ_D4 = 6,
  186059. READTYPE_READ_D4_1 = 7,
  186060. READTYPE_READ10_2 = 8
  186061. };
  186062. class CDDeviceHandle
  186063. {
  186064. public:
  186065. CDDeviceHandle (const CDDeviceInfo* const device)
  186066. : scsiHandle (0),
  186067. readType (READTYPE_ANY),
  186068. controller (0)
  186069. {
  186070. memcpy (&info, device, sizeof (info));
  186071. }
  186072. ~CDDeviceHandle()
  186073. {
  186074. if (controller != 0)
  186075. {
  186076. controller->shutDown();
  186077. controller = 0;
  186078. }
  186079. if (scsiHandle != 0)
  186080. CloseHandle (scsiHandle);
  186081. }
  186082. bool readTOC (TOC* lpToc, bool useMSF);
  186083. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186084. void openDrawer (bool shouldBeOpen);
  186085. CDDeviceInfo info;
  186086. HANDLE scsiHandle;
  186087. BYTE readType;
  186088. private:
  186089. ScopedPointer<CDController> controller;
  186090. bool testController (const int readType,
  186091. CDController* const newController,
  186092. CDReadBuffer* const bufferToUse);
  186093. };
  186094. DWORD (*fGetASPI32SupportInfo)(void);
  186095. DWORD (*fSendASPI32Command)(LPSRB);
  186096. static HINSTANCE winAspiLib = 0;
  186097. static bool usingScsi = false;
  186098. static bool initialised = false;
  186099. static bool InitialiseCDRipper()
  186100. {
  186101. if (! initialised)
  186102. {
  186103. initialised = true;
  186104. OSVERSIONINFO info;
  186105. info.dwOSVersionInfoSize = sizeof (info);
  186106. GetVersionEx (&info);
  186107. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186108. if (! usingScsi)
  186109. {
  186110. fGetASPI32SupportInfo = 0;
  186111. fSendASPI32Command = 0;
  186112. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186113. if (winAspiLib != 0)
  186114. {
  186115. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186116. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186117. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186118. return false;
  186119. }
  186120. else
  186121. {
  186122. usingScsi = true;
  186123. }
  186124. }
  186125. }
  186126. return true;
  186127. }
  186128. static void DeinitialiseCDRipper()
  186129. {
  186130. if (winAspiLib != 0)
  186131. {
  186132. fGetASPI32SupportInfo = 0;
  186133. fSendASPI32Command = 0;
  186134. FreeLibrary (winAspiLib);
  186135. winAspiLib = 0;
  186136. }
  186137. initialised = false;
  186138. }
  186139. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186140. {
  186141. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186142. OSVERSIONINFO info;
  186143. info.dwOSVersionInfoSize = sizeof (info);
  186144. GetVersionEx (&info);
  186145. DWORD flags = GENERIC_READ;
  186146. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186147. flags = GENERIC_READ | GENERIC_WRITE;
  186148. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186149. if (h == INVALID_HANDLE_VALUE)
  186150. {
  186151. flags ^= GENERIC_WRITE;
  186152. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186153. }
  186154. return h;
  186155. }
  186156. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186157. const char driveLetter,
  186158. HANDLE& deviceHandle,
  186159. const bool retryOnFailure = true)
  186160. {
  186161. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186162. zerostruct (s);
  186163. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186164. s.spt.CdbLength = srb->SRB_CDBLen;
  186165. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186166. ? SCSI_IOCTL_DATA_IN
  186167. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186168. ? SCSI_IOCTL_DATA_OUT
  186169. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186170. s.spt.DataTransferLength = srb->SRB_BufLen;
  186171. s.spt.TimeOutValue = 5;
  186172. s.spt.DataBuffer = srb->SRB_BufPointer;
  186173. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186174. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186175. srb->SRB_Status = SS_ERR;
  186176. srb->SRB_TargStat = 0x0004;
  186177. DWORD bytesReturned = 0;
  186178. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186179. &s, sizeof (s),
  186180. &s, sizeof (s),
  186181. &bytesReturned, 0) != 0)
  186182. {
  186183. srb->SRB_Status = SS_COMP;
  186184. }
  186185. else if (retryOnFailure)
  186186. {
  186187. const DWORD error = GetLastError();
  186188. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186189. {
  186190. if (error != ERROR_INVALID_HANDLE)
  186191. CloseHandle (deviceHandle);
  186192. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186193. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186194. }
  186195. }
  186196. return srb->SRB_Status;
  186197. }
  186198. // Controller types..
  186199. class ControllerType1 : public CDController
  186200. {
  186201. public:
  186202. ControllerType1() {}
  186203. ~ControllerType1() {}
  186204. bool read (CDReadBuffer* rb)
  186205. {
  186206. if (rb->numFrames * 2352 > rb->bufferSize)
  186207. return false;
  186208. SRB_ExecSCSICmd s;
  186209. prepare (s);
  186210. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186211. s.SRB_BufLen = rb->bufferSize;
  186212. s.SRB_BufPointer = rb->buffer;
  186213. s.SRB_CDBLen = 12;
  186214. s.CDBByte[0] = 0xBE;
  186215. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186216. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186217. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186218. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186219. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186220. perform (s);
  186221. if (s.SRB_Status != SS_COMP)
  186222. return false;
  186223. rb->dataLength = rb->numFrames * 2352;
  186224. rb->dataStartOffset = 0;
  186225. return true;
  186226. }
  186227. };
  186228. class ControllerType2 : public CDController
  186229. {
  186230. public:
  186231. ControllerType2() {}
  186232. ~ControllerType2() {}
  186233. void shutDown()
  186234. {
  186235. if (initialised)
  186236. {
  186237. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186238. SRB_ExecSCSICmd s;
  186239. prepare (s);
  186240. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186241. s.SRB_BufLen = 0x0C;
  186242. s.SRB_BufPointer = bufPointer;
  186243. s.SRB_CDBLen = 6;
  186244. s.CDBByte[0] = 0x15;
  186245. s.CDBByte[4] = 0x0C;
  186246. perform (s);
  186247. }
  186248. }
  186249. bool init()
  186250. {
  186251. SRB_ExecSCSICmd s;
  186252. s.SRB_Status = SS_ERR;
  186253. if (deviceInfo->readType == READTYPE_READ10_2)
  186254. {
  186255. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186256. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186257. for (int i = 0; i < 2; ++i)
  186258. {
  186259. prepare (s);
  186260. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186261. s.SRB_BufLen = 0x14;
  186262. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186263. s.SRB_CDBLen = 6;
  186264. s.CDBByte[0] = 0x15;
  186265. s.CDBByte[1] = 0x10;
  186266. s.CDBByte[4] = 0x14;
  186267. perform (s);
  186268. if (s.SRB_Status != SS_COMP)
  186269. return false;
  186270. }
  186271. }
  186272. else
  186273. {
  186274. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186275. prepare (s);
  186276. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186277. s.SRB_BufLen = 0x0C;
  186278. s.SRB_BufPointer = bufPointer;
  186279. s.SRB_CDBLen = 6;
  186280. s.CDBByte[0] = 0x15;
  186281. s.CDBByte[4] = 0x0C;
  186282. perform (s);
  186283. }
  186284. return s.SRB_Status == SS_COMP;
  186285. }
  186286. bool read (CDReadBuffer* rb)
  186287. {
  186288. if (rb->numFrames * 2352 > rb->bufferSize)
  186289. return false;
  186290. if (!initialised)
  186291. {
  186292. initialised = init();
  186293. if (!initialised)
  186294. return false;
  186295. }
  186296. SRB_ExecSCSICmd s;
  186297. prepare (s);
  186298. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186299. s.SRB_BufLen = rb->bufferSize;
  186300. s.SRB_BufPointer = rb->buffer;
  186301. s.SRB_CDBLen = 10;
  186302. s.CDBByte[0] = 0x28;
  186303. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186304. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186305. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186306. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186307. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186308. perform (s);
  186309. if (s.SRB_Status != SS_COMP)
  186310. return false;
  186311. rb->dataLength = rb->numFrames * 2352;
  186312. rb->dataStartOffset = 0;
  186313. return true;
  186314. }
  186315. };
  186316. class ControllerType3 : public CDController
  186317. {
  186318. public:
  186319. ControllerType3() {}
  186320. ~ControllerType3() {}
  186321. bool read (CDReadBuffer* rb)
  186322. {
  186323. if (rb->numFrames * 2352 > rb->bufferSize)
  186324. return false;
  186325. if (!initialised)
  186326. {
  186327. setPaused (false);
  186328. initialised = true;
  186329. }
  186330. SRB_ExecSCSICmd s;
  186331. prepare (s);
  186332. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186333. s.SRB_BufLen = rb->numFrames * 2352;
  186334. s.SRB_BufPointer = rb->buffer;
  186335. s.SRB_CDBLen = 12;
  186336. s.CDBByte[0] = 0xD8;
  186337. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186338. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186339. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186340. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186341. perform (s);
  186342. if (s.SRB_Status != SS_COMP)
  186343. return false;
  186344. rb->dataLength = rb->numFrames * 2352;
  186345. rb->dataStartOffset = 0;
  186346. return true;
  186347. }
  186348. };
  186349. class ControllerType4 : public CDController
  186350. {
  186351. public:
  186352. ControllerType4() {}
  186353. ~ControllerType4() {}
  186354. bool selectD4Mode()
  186355. {
  186356. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186357. SRB_ExecSCSICmd s;
  186358. prepare (s);
  186359. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186360. s.SRB_CDBLen = 6;
  186361. s.SRB_BufLen = 12;
  186362. s.SRB_BufPointer = bufPointer;
  186363. s.CDBByte[0] = 0x15;
  186364. s.CDBByte[1] = 0x10;
  186365. s.CDBByte[4] = 0x08;
  186366. perform (s);
  186367. return s.SRB_Status == SS_COMP;
  186368. }
  186369. bool read (CDReadBuffer* rb)
  186370. {
  186371. if (rb->numFrames * 2352 > rb->bufferSize)
  186372. return false;
  186373. if (!initialised)
  186374. {
  186375. setPaused (true);
  186376. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186377. selectD4Mode();
  186378. initialised = true;
  186379. }
  186380. SRB_ExecSCSICmd s;
  186381. prepare (s);
  186382. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186383. s.SRB_BufLen = rb->bufferSize;
  186384. s.SRB_BufPointer = rb->buffer;
  186385. s.SRB_CDBLen = 10;
  186386. s.CDBByte[0] = 0xD4;
  186387. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186388. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186389. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186390. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186391. perform (s);
  186392. if (s.SRB_Status != SS_COMP)
  186393. return false;
  186394. rb->dataLength = rb->numFrames * 2352;
  186395. rb->dataStartOffset = 0;
  186396. return true;
  186397. }
  186398. };
  186399. CDController::CDController() : initialised (false)
  186400. {
  186401. }
  186402. CDController::~CDController()
  186403. {
  186404. }
  186405. void CDController::prepare (SRB_ExecSCSICmd& s)
  186406. {
  186407. zerostruct (s);
  186408. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186409. s.SRB_HaID = deviceInfo->info.ha;
  186410. s.SRB_Target = deviceInfo->info.tgt;
  186411. s.SRB_Lun = deviceInfo->info.lun;
  186412. s.SRB_SenseLen = SENSE_LEN;
  186413. }
  186414. void CDController::perform (SRB_ExecSCSICmd& s)
  186415. {
  186416. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186417. s.SRB_PostProc = (void*)event;
  186418. ResetEvent (event);
  186419. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186420. deviceInfo->info.scsiDriveLetter,
  186421. deviceInfo->scsiHandle)
  186422. : fSendASPI32Command ((LPSRB)&s);
  186423. if (status == SS_PENDING)
  186424. WaitForSingleObject (event, 4000);
  186425. CloseHandle (event);
  186426. }
  186427. void CDController::setPaused (bool paused)
  186428. {
  186429. SRB_ExecSCSICmd s;
  186430. prepare (s);
  186431. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186432. s.SRB_CDBLen = 10;
  186433. s.CDBByte[0] = 0x4B;
  186434. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186435. perform (s);
  186436. }
  186437. void CDController::shutDown()
  186438. {
  186439. }
  186440. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186441. {
  186442. if (overlapBuffer != 0)
  186443. {
  186444. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186445. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186446. if (doJitter
  186447. && overlapBuffer->startFrame > 0
  186448. && overlapBuffer->numFrames > 0
  186449. && overlapBuffer->dataLength > 0)
  186450. {
  186451. const int numFrames = rb->numFrames;
  186452. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186453. {
  186454. rb->startFrame -= framesOverlap;
  186455. if (framesToCheck < framesOverlap
  186456. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186457. rb->numFrames += framesOverlap;
  186458. }
  186459. else
  186460. {
  186461. overlapBuffer->dataLength = 0;
  186462. overlapBuffer->startFrame = 0;
  186463. overlapBuffer->numFrames = 0;
  186464. }
  186465. }
  186466. if (! read (rb))
  186467. return false;
  186468. if (doJitter)
  186469. {
  186470. const int checkLen = framesToCheck * 2352;
  186471. const int maxToCheck = rb->dataLength - checkLen;
  186472. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186473. return true;
  186474. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186475. bool found = false;
  186476. for (int i = 0; i < maxToCheck; ++i)
  186477. {
  186478. if (memcmp (p, rb->buffer + i, checkLen) == 0)
  186479. {
  186480. i += checkLen;
  186481. rb->dataStartOffset = i;
  186482. rb->dataLength -= i;
  186483. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186484. found = true;
  186485. break;
  186486. }
  186487. }
  186488. rb->numFrames = rb->dataLength / 2352;
  186489. rb->dataLength = 2352 * rb->numFrames;
  186490. if (!found)
  186491. return false;
  186492. }
  186493. if (canDoJitter)
  186494. {
  186495. memcpy (overlapBuffer->buffer,
  186496. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186497. 2352 * framesToCheck);
  186498. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186499. overlapBuffer->numFrames = framesToCheck;
  186500. overlapBuffer->dataLength = 2352 * framesToCheck;
  186501. overlapBuffer->dataStartOffset = 0;
  186502. }
  186503. else
  186504. {
  186505. overlapBuffer->startFrame = 0;
  186506. overlapBuffer->numFrames = 0;
  186507. overlapBuffer->dataLength = 0;
  186508. }
  186509. return true;
  186510. }
  186511. else
  186512. {
  186513. return read (rb);
  186514. }
  186515. }
  186516. int CDController::getLastIndex()
  186517. {
  186518. char qdata[100];
  186519. SRB_ExecSCSICmd s;
  186520. prepare (s);
  186521. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186522. s.SRB_BufLen = sizeof (qdata);
  186523. s.SRB_BufPointer = (BYTE*)qdata;
  186524. s.SRB_CDBLen = 12;
  186525. s.CDBByte[0] = 0x42;
  186526. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186527. s.CDBByte[2] = 64;
  186528. s.CDBByte[3] = 1; // get current position
  186529. s.CDBByte[7] = 0;
  186530. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186531. perform (s);
  186532. if (s.SRB_Status == SS_COMP)
  186533. return qdata[7];
  186534. return 0;
  186535. }
  186536. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186537. {
  186538. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186539. SRB_ExecSCSICmd s;
  186540. zerostruct (s);
  186541. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186542. s.SRB_HaID = info.ha;
  186543. s.SRB_Target = info.tgt;
  186544. s.SRB_Lun = info.lun;
  186545. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186546. s.SRB_BufLen = 0x324;
  186547. s.SRB_BufPointer = (BYTE*)lpToc;
  186548. s.SRB_SenseLen = 0x0E;
  186549. s.SRB_CDBLen = 0x0A;
  186550. s.SRB_PostProc = (void*)event;
  186551. s.CDBByte[0] = 0x43;
  186552. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186553. s.CDBByte[7] = 0x03;
  186554. s.CDBByte[8] = 0x24;
  186555. ResetEvent (event);
  186556. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186557. : fSendASPI32Command ((LPSRB)&s);
  186558. if (status == SS_PENDING)
  186559. WaitForSingleObject (event, 4000);
  186560. CloseHandle (event);
  186561. return (s.SRB_Status == SS_COMP);
  186562. }
  186563. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186564. CDReadBuffer* const overlapBuffer)
  186565. {
  186566. if (controller == 0)
  186567. {
  186568. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186569. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186570. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186571. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186572. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186573. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186574. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186575. }
  186576. buffer->index = 0;
  186577. if ((controller != 0)
  186578. && controller->readAudio (buffer, overlapBuffer))
  186579. {
  186580. if (buffer->wantsIndex)
  186581. buffer->index = controller->getLastIndex();
  186582. return true;
  186583. }
  186584. return false;
  186585. }
  186586. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186587. {
  186588. if (shouldBeOpen)
  186589. {
  186590. if (controller != 0)
  186591. {
  186592. controller->shutDown();
  186593. controller = 0;
  186594. }
  186595. if (scsiHandle != 0)
  186596. {
  186597. CloseHandle (scsiHandle);
  186598. scsiHandle = 0;
  186599. }
  186600. }
  186601. SRB_ExecSCSICmd s;
  186602. zerostruct (s);
  186603. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186604. s.SRB_HaID = info.ha;
  186605. s.SRB_Target = info.tgt;
  186606. s.SRB_Lun = info.lun;
  186607. s.SRB_SenseLen = SENSE_LEN;
  186608. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186609. s.SRB_BufLen = 0;
  186610. s.SRB_BufPointer = 0;
  186611. s.SRB_CDBLen = 12;
  186612. s.CDBByte[0] = 0x1b;
  186613. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186614. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186615. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186616. s.SRB_PostProc = (void*)event;
  186617. ResetEvent (event);
  186618. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186619. : fSendASPI32Command ((LPSRB)&s);
  186620. if (status == SS_PENDING)
  186621. WaitForSingleObject (event, 4000);
  186622. CloseHandle (event);
  186623. }
  186624. bool CDDeviceHandle::testController (const int type,
  186625. CDController* const newController,
  186626. CDReadBuffer* const rb)
  186627. {
  186628. controller = newController;
  186629. readType = (BYTE)type;
  186630. controller->deviceInfo = this;
  186631. controller->framesToCheck = 1;
  186632. controller->framesOverlap = 3;
  186633. bool passed = false;
  186634. memset (rb->buffer, 0xcd, rb->bufferSize);
  186635. if (controller->read (rb))
  186636. {
  186637. passed = true;
  186638. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186639. int wrong = 0;
  186640. for (int i = rb->dataLength / 4; --i >= 0;)
  186641. {
  186642. if (*p++ == (int) 0xcdcdcdcd)
  186643. {
  186644. if (++wrong == 4)
  186645. {
  186646. passed = false;
  186647. break;
  186648. }
  186649. }
  186650. else
  186651. {
  186652. wrong = 0;
  186653. }
  186654. }
  186655. }
  186656. if (! passed)
  186657. {
  186658. controller->shutDown();
  186659. controller = 0;
  186660. }
  186661. return passed;
  186662. }
  186663. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186664. {
  186665. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186666. const int bufSize = 128;
  186667. BYTE buffer[bufSize];
  186668. zeromem (buffer, bufSize);
  186669. SRB_ExecSCSICmd s;
  186670. zerostruct (s);
  186671. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186672. s.SRB_HaID = ha;
  186673. s.SRB_Target = tgt;
  186674. s.SRB_Lun = lun;
  186675. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186676. s.SRB_BufLen = bufSize;
  186677. s.SRB_BufPointer = buffer;
  186678. s.SRB_SenseLen = SENSE_LEN;
  186679. s.SRB_CDBLen = 6;
  186680. s.SRB_PostProc = (void*)event;
  186681. s.CDBByte[0] = SCSI_INQUIRY;
  186682. s.CDBByte[4] = 100;
  186683. ResetEvent (event);
  186684. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186685. WaitForSingleObject (event, 4000);
  186686. CloseHandle (event);
  186687. if (s.SRB_Status == SS_COMP)
  186688. {
  186689. memcpy (dev->vendor, &buffer[8], 8);
  186690. memcpy (dev->productId, &buffer[16], 16);
  186691. memcpy (dev->rev, &buffer[32], 4);
  186692. memcpy (dev->vendorSpec, &buffer[36], 20);
  186693. }
  186694. }
  186695. static int FindCDDevices (CDDeviceInfo* const list,
  186696. int maxItems)
  186697. {
  186698. int count = 0;
  186699. if (usingScsi)
  186700. {
  186701. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186702. {
  186703. TCHAR drivePath[8];
  186704. drivePath[0] = driveLetter;
  186705. drivePath[1] = ':';
  186706. drivePath[2] = '\\';
  186707. drivePath[3] = 0;
  186708. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186709. {
  186710. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186711. if (h != INVALID_HANDLE_VALUE)
  186712. {
  186713. BYTE buffer[100], passThroughStruct[1024];
  186714. zeromem (buffer, sizeof (buffer));
  186715. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186716. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186717. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186718. p->spt.CdbLength = 6;
  186719. p->spt.SenseInfoLength = 24;
  186720. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186721. p->spt.DataTransferLength = 100;
  186722. p->spt.TimeOutValue = 2;
  186723. p->spt.DataBuffer = buffer;
  186724. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186725. p->spt.Cdb[0] = 0x12;
  186726. p->spt.Cdb[4] = 100;
  186727. DWORD bytesReturned = 0;
  186728. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186729. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186730. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186731. &bytesReturned, 0) != 0)
  186732. {
  186733. zeromem (&list[count], sizeof (CDDeviceInfo));
  186734. list[count].scsiDriveLetter = driveLetter;
  186735. memcpy (list[count].vendor, &buffer[8], 8);
  186736. memcpy (list[count].productId, &buffer[16], 16);
  186737. memcpy (list[count].rev, &buffer[32], 4);
  186738. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186739. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186740. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186741. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186742. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186743. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186744. &bytesReturned, 0) != 0)
  186745. {
  186746. list[count].ha = scsiAddr->PortNumber;
  186747. list[count].tgt = scsiAddr->TargetId;
  186748. list[count].lun = scsiAddr->Lun;
  186749. ++count;
  186750. }
  186751. }
  186752. CloseHandle (h);
  186753. }
  186754. }
  186755. }
  186756. }
  186757. else
  186758. {
  186759. const DWORD d = fGetASPI32SupportInfo();
  186760. BYTE status = HIBYTE (LOWORD (d));
  186761. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186762. return 0;
  186763. const int numAdapters = LOBYTE (LOWORD (d));
  186764. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186765. {
  186766. SRB_HAInquiry s;
  186767. zerostruct (s);
  186768. s.SRB_Cmd = SC_HA_INQUIRY;
  186769. s.SRB_HaID = ha;
  186770. fSendASPI32Command ((LPSRB)&s);
  186771. if (s.SRB_Status == SS_COMP)
  186772. {
  186773. maxItems = (int)s.HA_Unique[3];
  186774. if (maxItems == 0)
  186775. maxItems = 8;
  186776. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186777. {
  186778. for (BYTE lun = 0; lun < 8; ++lun)
  186779. {
  186780. SRB_GDEVBlock sb;
  186781. zerostruct (sb);
  186782. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186783. sb.SRB_HaID = ha;
  186784. sb.SRB_Target = tgt;
  186785. sb.SRB_Lun = lun;
  186786. fSendASPI32Command ((LPSRB) &sb);
  186787. if (sb.SRB_Status == SS_COMP
  186788. && sb.SRB_DeviceType == DTYPE_CROM)
  186789. {
  186790. zeromem (&list[count], sizeof (CDDeviceInfo));
  186791. list[count].ha = ha;
  186792. list[count].tgt = tgt;
  186793. list[count].lun = lun;
  186794. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186795. ++count;
  186796. }
  186797. }
  186798. }
  186799. }
  186800. }
  186801. }
  186802. return count;
  186803. }
  186804. static int ripperUsers = 0;
  186805. static bool initialisedOk = false;
  186806. class DeinitialiseTimer : private Timer,
  186807. private DeletedAtShutdown
  186808. {
  186809. DeinitialiseTimer (const DeinitialiseTimer&);
  186810. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186811. public:
  186812. DeinitialiseTimer()
  186813. {
  186814. startTimer (4000);
  186815. }
  186816. ~DeinitialiseTimer()
  186817. {
  186818. if (--ripperUsers == 0)
  186819. DeinitialiseCDRipper();
  186820. }
  186821. void timerCallback()
  186822. {
  186823. delete this;
  186824. }
  186825. juce_UseDebuggingNewOperator
  186826. };
  186827. static void incUserCount()
  186828. {
  186829. if (ripperUsers++ == 0)
  186830. initialisedOk = InitialiseCDRipper();
  186831. }
  186832. static void decUserCount()
  186833. {
  186834. new DeinitialiseTimer();
  186835. }
  186836. struct CDDeviceWrapper
  186837. {
  186838. ScopedPointer<CDDeviceHandle> cdH;
  186839. ScopedPointer<CDReadBuffer> overlapBuffer;
  186840. bool jitter;
  186841. };
  186842. static int getAddressOf (const TOCTRACK* const t)
  186843. {
  186844. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  186845. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  186846. }
  186847. static int getMSFAddressOf (const TOCTRACK* const t)
  186848. {
  186849. return 60 * t->addr[1] + t->addr[2];
  186850. }
  186851. static const int samplesPerFrame = 44100 / 75;
  186852. static const int bytesPerFrame = samplesPerFrame * 4;
  186853. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  186854. {
  186855. SRB_GDEVBlock s;
  186856. zerostruct (s);
  186857. s.SRB_Cmd = SC_GET_DEV_TYPE;
  186858. s.SRB_HaID = device->ha;
  186859. s.SRB_Target = device->tgt;
  186860. s.SRB_Lun = device->lun;
  186861. if (usingScsi)
  186862. {
  186863. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  186864. if (h != INVALID_HANDLE_VALUE)
  186865. {
  186866. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  186867. cdh->scsiHandle = h;
  186868. return cdh;
  186869. }
  186870. }
  186871. else
  186872. {
  186873. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  186874. && s.SRB_DeviceType == DTYPE_CROM)
  186875. {
  186876. return new CDDeviceHandle (device);
  186877. }
  186878. }
  186879. return 0;
  186880. }
  186881. }
  186882. const StringArray AudioCDReader::getAvailableCDNames()
  186883. {
  186884. using namespace CDReaderHelpers;
  186885. StringArray results;
  186886. incUserCount();
  186887. if (initialisedOk)
  186888. {
  186889. CDDeviceInfo list[8];
  186890. const int num = FindCDDevices (list, 8);
  186891. decUserCount();
  186892. for (int i = 0; i < num; ++i)
  186893. {
  186894. String s;
  186895. if (list[i].scsiDriveLetter > 0)
  186896. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << ": ";
  186897. s << String (list[i].vendor).trim()
  186898. << ' ' << String (list[i].productId).trim()
  186899. << ' ' << String (list[i].rev).trim();
  186900. results.add (s);
  186901. }
  186902. }
  186903. return results;
  186904. }
  186905. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  186906. {
  186907. using namespace CDReaderHelpers;
  186908. incUserCount();
  186909. if (initialisedOk)
  186910. {
  186911. CDDeviceInfo list[8];
  186912. const int num = FindCDDevices (list, 8);
  186913. if (((unsigned int) deviceIndex) < (unsigned int) num)
  186914. {
  186915. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  186916. if (handle != 0)
  186917. {
  186918. CDDeviceWrapper* const d = new CDDeviceWrapper();
  186919. d->cdH = handle;
  186920. d->overlapBuffer = new CDReadBuffer(3);
  186921. return new AudioCDReader (d);
  186922. }
  186923. }
  186924. }
  186925. decUserCount();
  186926. return 0;
  186927. }
  186928. AudioCDReader::AudioCDReader (void* handle_)
  186929. : AudioFormatReader (0, "CD Audio"),
  186930. handle (handle_),
  186931. indexingEnabled (false),
  186932. lastIndex (0),
  186933. firstFrameInBuffer (0),
  186934. samplesInBuffer (0)
  186935. {
  186936. using namespace CDReaderHelpers;
  186937. jassert (handle_ != 0);
  186938. refreshTrackLengths();
  186939. sampleRate = 44100.0;
  186940. bitsPerSample = 16;
  186941. lengthInSamples = getPositionOfTrackStart (numTracks);
  186942. numChannels = 2;
  186943. usesFloatingPointData = false;
  186944. buffer.setSize (4 * bytesPerFrame, true);
  186945. }
  186946. AudioCDReader::~AudioCDReader()
  186947. {
  186948. using namespace CDReaderHelpers;
  186949. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186950. delete device;
  186951. decUserCount();
  186952. }
  186953. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  186954. int64 startSampleInFile, int numSamples)
  186955. {
  186956. using namespace CDReaderHelpers;
  186957. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186958. bool ok = true;
  186959. while (numSamples > 0)
  186960. {
  186961. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  186962. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  186963. if (startSampleInFile >= bufferStartSample
  186964. && startSampleInFile < bufferEndSample)
  186965. {
  186966. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  186967. int* const l = destSamples[0] + startOffsetInDestBuffer;
  186968. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186969. const short* src = (const short*) buffer.getData();
  186970. src += 2 * (startSampleInFile - bufferStartSample);
  186971. for (int i = 0; i < toDo; ++i)
  186972. {
  186973. l[i] = src [i << 1] << 16;
  186974. if (r != 0)
  186975. r[i] = src [(i << 1) + 1] << 16;
  186976. }
  186977. startOffsetInDestBuffer += toDo;
  186978. startSampleInFile += toDo;
  186979. numSamples -= toDo;
  186980. }
  186981. else
  186982. {
  186983. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  186984. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  186985. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  186986. {
  186987. device->overlapBuffer->dataLength = 0;
  186988. device->overlapBuffer->startFrame = 0;
  186989. device->overlapBuffer->numFrames = 0;
  186990. device->jitter = false;
  186991. }
  186992. firstFrameInBuffer = frameNeeded;
  186993. lastIndex = 0;
  186994. CDReadBuffer readBuffer (framesInBuffer + 4);
  186995. readBuffer.wantsIndex = indexingEnabled;
  186996. int i;
  186997. for (i = 5; --i >= 0;)
  186998. {
  186999. readBuffer.startFrame = frameNeeded;
  187000. readBuffer.numFrames = framesInBuffer;
  187001. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187002. break;
  187003. else
  187004. device->overlapBuffer->dataLength = 0;
  187005. }
  187006. if (i >= 0)
  187007. {
  187008. memcpy ((char*) buffer.getData(),
  187009. readBuffer.buffer + readBuffer.dataStartOffset,
  187010. readBuffer.dataLength);
  187011. samplesInBuffer = readBuffer.dataLength >> 2;
  187012. lastIndex = readBuffer.index;
  187013. }
  187014. else
  187015. {
  187016. int* l = destSamples[0] + startOffsetInDestBuffer;
  187017. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187018. while (--numSamples >= 0)
  187019. {
  187020. *l++ = 0;
  187021. if (r != 0)
  187022. *r++ = 0;
  187023. }
  187024. // sometimes the read fails for just the very last couple of blocks, so
  187025. // we'll ignore and errors in the last half-second of the disk..
  187026. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187027. break;
  187028. }
  187029. }
  187030. }
  187031. return ok;
  187032. }
  187033. bool AudioCDReader::isCDStillPresent() const
  187034. {
  187035. using namespace CDReaderHelpers;
  187036. TOC toc;
  187037. zerostruct (toc);
  187038. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  187039. }
  187040. int AudioCDReader::getNumTracks() const
  187041. {
  187042. return numTracks;
  187043. }
  187044. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187045. {
  187046. using namespace CDReaderHelpers;
  187047. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187048. : 0;
  187049. }
  187050. void AudioCDReader::refreshTrackLengths()
  187051. {
  187052. using namespace CDReaderHelpers;
  187053. zeromem (trackStarts, sizeof (trackStarts));
  187054. zeromem (audioTracks, sizeof (audioTracks));
  187055. TOC toc;
  187056. zerostruct (toc);
  187057. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187058. {
  187059. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187060. for (int i = 0; i <= numTracks; ++i)
  187061. {
  187062. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187063. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187064. }
  187065. }
  187066. else
  187067. {
  187068. numTracks = 0;
  187069. }
  187070. }
  187071. bool AudioCDReader::isTrackAudio (int trackNum) const
  187072. {
  187073. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187074. : false;
  187075. }
  187076. void AudioCDReader::enableIndexScanning (bool b)
  187077. {
  187078. indexingEnabled = b;
  187079. }
  187080. int AudioCDReader::getLastIndex() const
  187081. {
  187082. return lastIndex;
  187083. }
  187084. const int framesPerIndexRead = 4;
  187085. int AudioCDReader::getIndexAt (int samplePos)
  187086. {
  187087. using namespace CDReaderHelpers;
  187088. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187089. const int frameNeeded = samplePos / samplesPerFrame;
  187090. device->overlapBuffer->dataLength = 0;
  187091. device->overlapBuffer->startFrame = 0;
  187092. device->overlapBuffer->numFrames = 0;
  187093. device->jitter = false;
  187094. firstFrameInBuffer = 0;
  187095. lastIndex = 0;
  187096. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187097. readBuffer.wantsIndex = true;
  187098. int i;
  187099. for (i = 5; --i >= 0;)
  187100. {
  187101. readBuffer.startFrame = frameNeeded;
  187102. readBuffer.numFrames = framesPerIndexRead;
  187103. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187104. break;
  187105. }
  187106. if (i >= 0)
  187107. return readBuffer.index;
  187108. return -1;
  187109. }
  187110. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187111. {
  187112. using namespace CDReaderHelpers;
  187113. Array <int> indexes;
  187114. const int trackStart = getPositionOfTrackStart (trackNumber);
  187115. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187116. bool needToScan = true;
  187117. if (trackEnd - trackStart > 20 * 44100)
  187118. {
  187119. // check the end of the track for indexes before scanning the whole thing
  187120. needToScan = false;
  187121. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187122. bool seenAnIndex = false;
  187123. while (pos <= trackEnd - samplesPerFrame)
  187124. {
  187125. const int index = getIndexAt (pos);
  187126. if (index == 0)
  187127. {
  187128. // lead-out, so skip back a bit if we've not found any indexes yet..
  187129. if (seenAnIndex)
  187130. break;
  187131. pos -= 44100 * 5;
  187132. if (pos < trackStart)
  187133. break;
  187134. }
  187135. else
  187136. {
  187137. if (index > 0)
  187138. seenAnIndex = true;
  187139. if (index > 1)
  187140. {
  187141. needToScan = true;
  187142. break;
  187143. }
  187144. pos += samplesPerFrame * framesPerIndexRead;
  187145. }
  187146. }
  187147. }
  187148. if (needToScan)
  187149. {
  187150. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187151. int pos = trackStart;
  187152. int last = -1;
  187153. while (pos < trackEnd - samplesPerFrame * 10)
  187154. {
  187155. const int frameNeeded = pos / samplesPerFrame;
  187156. device->overlapBuffer->dataLength = 0;
  187157. device->overlapBuffer->startFrame = 0;
  187158. device->overlapBuffer->numFrames = 0;
  187159. device->jitter = false;
  187160. firstFrameInBuffer = 0;
  187161. CDReadBuffer readBuffer (4);
  187162. readBuffer.wantsIndex = true;
  187163. int i;
  187164. for (i = 5; --i >= 0;)
  187165. {
  187166. readBuffer.startFrame = frameNeeded;
  187167. readBuffer.numFrames = framesPerIndexRead;
  187168. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187169. break;
  187170. }
  187171. if (i < 0)
  187172. break;
  187173. if (readBuffer.index > last && readBuffer.index > 1)
  187174. {
  187175. last = readBuffer.index;
  187176. indexes.add (pos);
  187177. }
  187178. pos += samplesPerFrame * framesPerIndexRead;
  187179. }
  187180. indexes.removeValue (trackStart);
  187181. }
  187182. return indexes;
  187183. }
  187184. int AudioCDReader::getCDDBId()
  187185. {
  187186. using namespace CDReaderHelpers;
  187187. refreshTrackLengths();
  187188. if (numTracks > 0)
  187189. {
  187190. TOC toc;
  187191. zerostruct (toc);
  187192. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187193. {
  187194. int n = 0;
  187195. for (int i = numTracks; --i >= 0;)
  187196. {
  187197. int j = getMSFAddressOf (&toc.tracks[i]);
  187198. while (j > 0)
  187199. {
  187200. n += (j % 10);
  187201. j /= 10;
  187202. }
  187203. }
  187204. if (n != 0)
  187205. {
  187206. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187207. - getMSFAddressOf (&toc.tracks[0]);
  187208. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187209. }
  187210. }
  187211. }
  187212. return 0;
  187213. }
  187214. void AudioCDReader::ejectDisk()
  187215. {
  187216. using namespace CDReaderHelpers;
  187217. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187218. }
  187219. #endif
  187220. #if JUCE_USE_CDBURNER
  187221. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187222. {
  187223. CoInitialize (0);
  187224. IDiscMaster* dm;
  187225. IDiscRecorder* result = 0;
  187226. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187227. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187228. IID_IDiscMaster,
  187229. (void**) &dm)))
  187230. {
  187231. if (SUCCEEDED (dm->Open()))
  187232. {
  187233. IEnumDiscRecorders* drEnum = 0;
  187234. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187235. {
  187236. IDiscRecorder* dr = 0;
  187237. DWORD dummy;
  187238. int index = 0;
  187239. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187240. {
  187241. if (indexToOpen == index)
  187242. {
  187243. result = dr;
  187244. break;
  187245. }
  187246. else if (list != 0)
  187247. {
  187248. BSTR path;
  187249. if (SUCCEEDED (dr->GetPath (&path)))
  187250. list->add ((const WCHAR*) path);
  187251. }
  187252. ++index;
  187253. dr->Release();
  187254. }
  187255. drEnum->Release();
  187256. }
  187257. if (master == 0)
  187258. dm->Close();
  187259. }
  187260. if (master != 0)
  187261. *master = dm;
  187262. else
  187263. dm->Release();
  187264. }
  187265. return result;
  187266. }
  187267. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187268. public Timer
  187269. {
  187270. public:
  187271. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187272. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187273. listener (0), progress (0), shouldCancel (false), refCount (1)
  187274. {
  187275. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187276. jassert (SUCCEEDED (hr));
  187277. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187278. //jassert (SUCCEEDED (hr));
  187279. lastState = getDiskState();
  187280. startTimer (2000);
  187281. }
  187282. ~Pimpl() {}
  187283. void releaseObjects()
  187284. {
  187285. discRecorder->Close();
  187286. if (redbook != 0)
  187287. redbook->Release();
  187288. discRecorder->Release();
  187289. discMaster->Release();
  187290. Release();
  187291. }
  187292. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187293. {
  187294. if (result == 0)
  187295. return E_POINTER;
  187296. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187297. {
  187298. AddRef();
  187299. *result = this;
  187300. return S_OK;
  187301. }
  187302. *result = 0;
  187303. return E_NOINTERFACE;
  187304. }
  187305. ULONG __stdcall AddRef() { return ++refCount; }
  187306. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187307. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187308. {
  187309. if (listener != 0 && ! shouldCancel)
  187310. shouldCancel = listener->audioCDBurnProgress (progress);
  187311. *pbCancel = shouldCancel;
  187312. return S_OK;
  187313. }
  187314. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187315. {
  187316. progress = nCompleted / (float) nTotal;
  187317. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187318. return E_NOTIMPL;
  187319. }
  187320. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187321. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187322. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187323. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187324. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187325. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187326. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187327. class ScopedDiscOpener
  187328. {
  187329. public:
  187330. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187331. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187332. private:
  187333. Pimpl& pimpl;
  187334. ScopedDiscOpener (const ScopedDiscOpener&);
  187335. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187336. };
  187337. DiskState getDiskState()
  187338. {
  187339. const ScopedDiscOpener opener (*this);
  187340. long type, flags;
  187341. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187342. if (FAILED (hr))
  187343. return unknown;
  187344. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187345. return writableDiskPresent;
  187346. if (type == 0)
  187347. return noDisc;
  187348. else
  187349. return readOnlyDiskPresent;
  187350. }
  187351. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187352. {
  187353. ComSmartPtr<IPropertyStorage> prop;
  187354. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187355. return defaultReturn;
  187356. PROPSPEC iPropSpec;
  187357. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187358. iPropSpec.lpwstr = name;
  187359. PROPVARIANT iPropVariant;
  187360. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187361. ? defaultReturn : (int) iPropVariant.lVal;
  187362. }
  187363. bool setIntProperty (const LPOLESTR name, const int value) const
  187364. {
  187365. ComSmartPtr<IPropertyStorage> prop;
  187366. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187367. return false;
  187368. PROPSPEC iPropSpec;
  187369. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187370. iPropSpec.lpwstr = name;
  187371. PROPVARIANT iPropVariant;
  187372. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187373. return false;
  187374. iPropVariant.lVal = (long) value;
  187375. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187376. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187377. }
  187378. void timerCallback()
  187379. {
  187380. const DiskState state = getDiskState();
  187381. if (state != lastState)
  187382. {
  187383. lastState = state;
  187384. owner.sendChangeMessage (&owner);
  187385. }
  187386. }
  187387. AudioCDBurner& owner;
  187388. DiskState lastState;
  187389. IDiscMaster* discMaster;
  187390. IDiscRecorder* discRecorder;
  187391. IRedbookDiscMaster* redbook;
  187392. AudioCDBurner::BurnProgressListener* listener;
  187393. float progress;
  187394. bool shouldCancel;
  187395. private:
  187396. int refCount;
  187397. };
  187398. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187399. {
  187400. IDiscMaster* discMaster = 0;
  187401. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187402. if (discRecorder != 0)
  187403. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187404. }
  187405. AudioCDBurner::~AudioCDBurner()
  187406. {
  187407. if (pimpl != 0)
  187408. pimpl.release()->releaseObjects();
  187409. }
  187410. const StringArray AudioCDBurner::findAvailableDevices()
  187411. {
  187412. StringArray devs;
  187413. enumCDBurners (&devs, -1, 0);
  187414. return devs;
  187415. }
  187416. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187417. {
  187418. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187419. if (b->pimpl == 0)
  187420. b = 0;
  187421. return b.release();
  187422. }
  187423. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187424. {
  187425. return pimpl->getDiskState();
  187426. }
  187427. bool AudioCDBurner::isDiskPresent() const
  187428. {
  187429. return getDiskState() == writableDiskPresent;
  187430. }
  187431. bool AudioCDBurner::openTray()
  187432. {
  187433. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187434. return SUCCEEDED (pimpl->discRecorder->Eject());
  187435. }
  187436. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187437. {
  187438. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187439. DiskState oldState = getDiskState();
  187440. DiskState newState = oldState;
  187441. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187442. {
  187443. newState = getDiskState();
  187444. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187445. }
  187446. return newState;
  187447. }
  187448. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187449. {
  187450. Array<int> results;
  187451. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187452. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187453. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187454. if (speeds[i] <= maxSpeed)
  187455. results.add (speeds[i]);
  187456. results.addIfNotAlreadyThere (maxSpeed);
  187457. return results;
  187458. }
  187459. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187460. {
  187461. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187462. return false;
  187463. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187464. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187465. }
  187466. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187467. {
  187468. long blocksFree = 0;
  187469. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187470. return blocksFree;
  187471. }
  187472. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187473. bool performFakeBurnForTesting, int writeSpeed)
  187474. {
  187475. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187476. pimpl->listener = listener;
  187477. pimpl->progress = 0;
  187478. pimpl->shouldCancel = false;
  187479. UINT_PTR cookie;
  187480. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187481. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187482. ejectDiscAfterwards);
  187483. String error;
  187484. if (hr != S_OK)
  187485. {
  187486. const char* e = "Couldn't open or write to the CD device";
  187487. if (hr == IMAPI_E_USERABORT)
  187488. e = "User cancelled the write operation";
  187489. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187490. e = "No Disk present";
  187491. error = e;
  187492. }
  187493. pimpl->discMaster->ProgressUnadvise (cookie);
  187494. pimpl->listener = 0;
  187495. return error;
  187496. }
  187497. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187498. {
  187499. if (audioSource == 0)
  187500. return false;
  187501. ScopedPointer<AudioSource> source (audioSource);
  187502. long bytesPerBlock;
  187503. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187504. const int samplesPerBlock = bytesPerBlock / 4;
  187505. bool ok = true;
  187506. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187507. HeapBlock <byte> buffer (bytesPerBlock);
  187508. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187509. int samplesDone = 0;
  187510. source->prepareToPlay (samplesPerBlock, 44100.0);
  187511. while (ok)
  187512. {
  187513. {
  187514. AudioSourceChannelInfo info;
  187515. info.buffer = &sourceBuffer;
  187516. info.numSamples = samplesPerBlock;
  187517. info.startSample = 0;
  187518. sourceBuffer.clear();
  187519. source->getNextAudioBlock (info);
  187520. }
  187521. zeromem (buffer, bytesPerBlock);
  187522. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187523. buffer, samplesPerBlock, 4);
  187524. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187525. buffer + 2, samplesPerBlock, 4);
  187526. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187527. if (FAILED (hr))
  187528. ok = false;
  187529. samplesDone += samplesPerBlock;
  187530. if (samplesDone >= numSamples)
  187531. break;
  187532. }
  187533. hr = pimpl->redbook->CloseAudioTrack();
  187534. return ok && hr == S_OK;
  187535. }
  187536. #endif
  187537. #endif
  187538. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187539. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187540. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187541. // compiled on its own).
  187542. #if JUCE_INCLUDED_FILE
  187543. using ::free;
  187544. namespace MidiConstants
  187545. {
  187546. static const int midiBufferSize = 1024 * 10;
  187547. static const int numInHeaders = 32;
  187548. static const int inBufferSize = 256;
  187549. }
  187550. class MidiInThread : public Thread
  187551. {
  187552. public:
  187553. MidiInThread (MidiInput* const input_,
  187554. MidiInputCallback* const callback_)
  187555. : Thread ("Juce Midi"),
  187556. hIn (0),
  187557. input (input_),
  187558. callback (callback_),
  187559. isStarted (false),
  187560. startTime (0),
  187561. pendingLength(0)
  187562. {
  187563. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187564. {
  187565. zeromem (&hdr[i], sizeof (MIDIHDR));
  187566. hdr[i].lpData = inData[i];
  187567. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187568. }
  187569. };
  187570. ~MidiInThread()
  187571. {
  187572. stop();
  187573. if (hIn != 0)
  187574. {
  187575. int count = 5;
  187576. while (--count >= 0)
  187577. {
  187578. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187579. break;
  187580. Sleep (20);
  187581. }
  187582. }
  187583. }
  187584. void handle (const uint32 message, const uint32 timeStamp) throw()
  187585. {
  187586. const int byte = message & 0xff;
  187587. if (byte < 0x80)
  187588. return;
  187589. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187590. const double time = timeStampToTime (timeStamp);
  187591. {
  187592. const ScopedLock sl (lock);
  187593. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187594. {
  187595. char* const p = pending + pendingLength;
  187596. *(double*) p = time;
  187597. *(uint32*) (p + 8) = numBytes;
  187598. *(uint32*) (p + 12) = message;
  187599. pendingLength += 12 + numBytes;
  187600. }
  187601. else
  187602. {
  187603. jassertfalse // midi buffer overflow! You might need to increase the size..
  187604. }
  187605. }
  187606. notify();
  187607. }
  187608. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187609. {
  187610. const int num = hdr->dwBytesRecorded;
  187611. if (num > 0)
  187612. {
  187613. const double time = timeStampToTime (timeStamp);
  187614. {
  187615. const ScopedLock sl (lock);
  187616. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187617. {
  187618. char* const p = pending + pendingLength;
  187619. *(double*) p = time;
  187620. *(uint32*) (p + 8) = num;
  187621. memcpy (p + 12, hdr->lpData, num);
  187622. pendingLength += 12 + num;
  187623. }
  187624. else
  187625. {
  187626. jassertfalse // midi buffer overflow! You might need to increase the size..
  187627. }
  187628. }
  187629. notify();
  187630. }
  187631. }
  187632. void writeBlock (const int i) throw()
  187633. {
  187634. hdr[i].dwBytesRecorded = 0;
  187635. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187636. jassert (res == MMSYSERR_NOERROR);
  187637. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187638. jassert (res == MMSYSERR_NOERROR);
  187639. }
  187640. void run()
  187641. {
  187642. MemoryBlock pendingCopy (64);
  187643. while (! threadShouldExit())
  187644. {
  187645. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187646. {
  187647. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187648. {
  187649. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187650. (void) res;
  187651. jassert (res == MMSYSERR_NOERROR);
  187652. writeBlock (i);
  187653. }
  187654. }
  187655. int len;
  187656. {
  187657. const ScopedLock sl (lock);
  187658. len = pendingLength;
  187659. if (len > 0)
  187660. {
  187661. pendingCopy.ensureSize (len);
  187662. pendingCopy.copyFrom (pending, 0, len);
  187663. pendingLength = 0;
  187664. }
  187665. }
  187666. //xxx needs to figure out if blocks are broken up or not
  187667. if (len == 0)
  187668. {
  187669. wait (500);
  187670. }
  187671. else
  187672. {
  187673. const char* p = (const char*) pendingCopy.getData();
  187674. while (len > 0)
  187675. {
  187676. const double time = *(const double*) p;
  187677. const int messageLen = *(const int*) (p + 8);
  187678. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187679. callback->handleIncomingMidiMessage (input, message);
  187680. p += 12 + messageLen;
  187681. len -= 12 + messageLen;
  187682. }
  187683. }
  187684. }
  187685. }
  187686. void start() throw()
  187687. {
  187688. jassert (hIn != 0);
  187689. if (hIn != 0 && ! isStarted)
  187690. {
  187691. stop();
  187692. activeMidiThreads.addIfNotAlreadyThere (this);
  187693. int i;
  187694. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187695. writeBlock (i);
  187696. startTime = Time::getMillisecondCounter();
  187697. MMRESULT res = midiInStart (hIn);
  187698. jassert (res == MMSYSERR_NOERROR);
  187699. if (res == MMSYSERR_NOERROR)
  187700. {
  187701. isStarted = true;
  187702. pendingLength = 0;
  187703. startThread (6);
  187704. }
  187705. }
  187706. }
  187707. void stop() throw()
  187708. {
  187709. if (isStarted)
  187710. {
  187711. stopThread (5000);
  187712. midiInReset (hIn);
  187713. midiInStop (hIn);
  187714. activeMidiThreads.removeValue (this);
  187715. { const ScopedLock sl (lock); }
  187716. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187717. {
  187718. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187719. {
  187720. int c = 10;
  187721. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187722. Sleep (20);
  187723. jassert (c >= 0);
  187724. }
  187725. }
  187726. isStarted = false;
  187727. pendingLength = 0;
  187728. }
  187729. }
  187730. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187731. {
  187732. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187733. if (thread != 0 && activeMidiThreads.contains (thread))
  187734. {
  187735. if (uMsg == MIM_DATA)
  187736. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187737. else if (uMsg == MIM_LONGDATA)
  187738. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187739. }
  187740. }
  187741. juce_UseDebuggingNewOperator
  187742. HMIDIIN hIn;
  187743. private:
  187744. static Array <void*, CriticalSection> activeMidiThreads;
  187745. MidiInput* input;
  187746. MidiInputCallback* callback;
  187747. bool isStarted;
  187748. uint32 startTime;
  187749. CriticalSection lock;
  187750. MIDIHDR hdr [MidiConstants::numInHeaders];
  187751. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187752. int pendingLength;
  187753. char pending [MidiConstants::midiBufferSize];
  187754. double timeStampToTime (uint32 timeStamp) throw()
  187755. {
  187756. timeStamp += startTime;
  187757. const uint32 now = Time::getMillisecondCounter();
  187758. if (timeStamp > now)
  187759. {
  187760. if (timeStamp > now + 2)
  187761. --startTime;
  187762. timeStamp = now;
  187763. }
  187764. return 0.001 * timeStamp;
  187765. }
  187766. MidiInThread (const MidiInThread&);
  187767. MidiInThread& operator= (const MidiInThread&);
  187768. };
  187769. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187770. const StringArray MidiInput::getDevices()
  187771. {
  187772. StringArray s;
  187773. const int num = midiInGetNumDevs();
  187774. for (int i = 0; i < num; ++i)
  187775. {
  187776. MIDIINCAPS mc;
  187777. zerostruct (mc);
  187778. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187779. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187780. }
  187781. return s;
  187782. }
  187783. int MidiInput::getDefaultDeviceIndex()
  187784. {
  187785. return 0;
  187786. }
  187787. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187788. {
  187789. if (callback == 0)
  187790. return 0;
  187791. UINT deviceId = MIDI_MAPPER;
  187792. int n = 0;
  187793. String name;
  187794. const int num = midiInGetNumDevs();
  187795. for (int i = 0; i < num; ++i)
  187796. {
  187797. MIDIINCAPS mc;
  187798. zerostruct (mc);
  187799. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187800. {
  187801. if (index == n)
  187802. {
  187803. deviceId = i;
  187804. name = String (mc.szPname, sizeof (mc.szPname));
  187805. break;
  187806. }
  187807. ++n;
  187808. }
  187809. }
  187810. ScopedPointer <MidiInput> in (new MidiInput (name));
  187811. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187812. HMIDIIN h;
  187813. HRESULT err = midiInOpen (&h, deviceId,
  187814. (DWORD_PTR) &MidiInThread::midiInCallback,
  187815. (DWORD_PTR) (MidiInThread*) thread,
  187816. CALLBACK_FUNCTION);
  187817. if (err == MMSYSERR_NOERROR)
  187818. {
  187819. thread->hIn = h;
  187820. in->internal = (void*) thread.release();
  187821. return in.release();
  187822. }
  187823. return 0;
  187824. }
  187825. MidiInput::MidiInput (const String& name_)
  187826. : name (name_),
  187827. internal (0)
  187828. {
  187829. }
  187830. MidiInput::~MidiInput()
  187831. {
  187832. delete static_cast <MidiInThread*> (internal);
  187833. }
  187834. void MidiInput::start()
  187835. {
  187836. static_cast <MidiInThread*> (internal)->start();
  187837. }
  187838. void MidiInput::stop()
  187839. {
  187840. static_cast <MidiInThread*> (internal)->stop();
  187841. }
  187842. struct MidiOutHandle
  187843. {
  187844. int refCount;
  187845. UINT deviceId;
  187846. HMIDIOUT handle;
  187847. static Array<MidiOutHandle*> activeHandles;
  187848. juce_UseDebuggingNewOperator
  187849. };
  187850. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  187851. const StringArray MidiOutput::getDevices()
  187852. {
  187853. StringArray s;
  187854. const int num = midiOutGetNumDevs();
  187855. for (int i = 0; i < num; ++i)
  187856. {
  187857. MIDIOUTCAPS mc;
  187858. zerostruct (mc);
  187859. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187860. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187861. }
  187862. return s;
  187863. }
  187864. int MidiOutput::getDefaultDeviceIndex()
  187865. {
  187866. const int num = midiOutGetNumDevs();
  187867. int n = 0;
  187868. for (int i = 0; i < num; ++i)
  187869. {
  187870. MIDIOUTCAPS mc;
  187871. zerostruct (mc);
  187872. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187873. {
  187874. if ((mc.wTechnology & MOD_MAPPER) != 0)
  187875. return n;
  187876. ++n;
  187877. }
  187878. }
  187879. return 0;
  187880. }
  187881. MidiOutput* MidiOutput::openDevice (int index)
  187882. {
  187883. UINT deviceId = MIDI_MAPPER;
  187884. const int num = midiOutGetNumDevs();
  187885. int i, n = 0;
  187886. for (i = 0; i < num; ++i)
  187887. {
  187888. MIDIOUTCAPS mc;
  187889. zerostruct (mc);
  187890. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187891. {
  187892. // use the microsoft sw synth as a default - best not to allow deviceId
  187893. // to be MIDI_MAPPER, or else device sharing breaks
  187894. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase ("microsoft"))
  187895. deviceId = i;
  187896. if (index == n)
  187897. {
  187898. deviceId = i;
  187899. break;
  187900. }
  187901. ++n;
  187902. }
  187903. }
  187904. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  187905. {
  187906. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  187907. if (han != 0 && han->deviceId == deviceId)
  187908. {
  187909. han->refCount++;
  187910. MidiOutput* const out = new MidiOutput();
  187911. out->internal = (void*) han;
  187912. return out;
  187913. }
  187914. }
  187915. for (i = 4; --i >= 0;)
  187916. {
  187917. HMIDIOUT h = 0;
  187918. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  187919. if (res == MMSYSERR_NOERROR)
  187920. {
  187921. MidiOutHandle* const han = new MidiOutHandle();
  187922. han->deviceId = deviceId;
  187923. han->refCount = 1;
  187924. han->handle = h;
  187925. MidiOutHandle::activeHandles.add (han);
  187926. MidiOutput* const out = new MidiOutput();
  187927. out->internal = (void*) han;
  187928. return out;
  187929. }
  187930. else if (res == MMSYSERR_ALLOCATED)
  187931. {
  187932. Sleep (100);
  187933. }
  187934. else
  187935. {
  187936. break;
  187937. }
  187938. }
  187939. return 0;
  187940. }
  187941. MidiOutput::~MidiOutput()
  187942. {
  187943. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  187944. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  187945. {
  187946. midiOutClose (h->handle);
  187947. MidiOutHandle::activeHandles.removeValue (h);
  187948. delete h;
  187949. }
  187950. }
  187951. void MidiOutput::reset()
  187952. {
  187953. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  187954. midiOutReset (h->handle);
  187955. }
  187956. bool MidiOutput::getVolume (float& leftVol,
  187957. float& rightVol)
  187958. {
  187959. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187960. DWORD n;
  187961. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  187962. {
  187963. const unsigned short* const nn = (const unsigned short*) &n;
  187964. rightVol = nn[0] / (float) 0xffff;
  187965. leftVol = nn[1] / (float) 0xffff;
  187966. return true;
  187967. }
  187968. else
  187969. {
  187970. rightVol = leftVol = 1.0f;
  187971. return false;
  187972. }
  187973. }
  187974. void MidiOutput::setVolume (float leftVol,
  187975. float rightVol)
  187976. {
  187977. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  187978. DWORD n;
  187979. unsigned short* const nn = (unsigned short*) &n;
  187980. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  187981. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  187982. midiOutSetVolume (handle->handle, n);
  187983. }
  187984. void MidiOutput::sendMessageNow (const MidiMessage& message)
  187985. {
  187986. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187987. if (message.getRawDataSize() > 3
  187988. || message.isSysEx())
  187989. {
  187990. MIDIHDR h;
  187991. zerostruct (h);
  187992. h.lpData = (char*) message.getRawData();
  187993. h.dwBufferLength = message.getRawDataSize();
  187994. h.dwBytesRecorded = message.getRawDataSize();
  187995. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  187996. {
  187997. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  187998. if (res == MMSYSERR_NOERROR)
  187999. {
  188000. while ((h.dwFlags & MHDR_DONE) == 0)
  188001. Sleep (1);
  188002. int count = 500; // 1 sec timeout
  188003. while (--count >= 0)
  188004. {
  188005. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188006. if (res == MIDIERR_STILLPLAYING)
  188007. Sleep (2);
  188008. else
  188009. break;
  188010. }
  188011. }
  188012. }
  188013. }
  188014. else
  188015. {
  188016. midiOutShortMsg (handle->handle,
  188017. *(unsigned int*) message.getRawData());
  188018. }
  188019. }
  188020. #endif
  188021. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188022. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188023. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188024. // compiled on its own).
  188025. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188026. #undef WINDOWS
  188027. // #define ASIO_DEBUGGING
  188028. #ifdef ASIO_DEBUGGING
  188029. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188030. #else
  188031. #define log(a) {}
  188032. #endif
  188033. #ifdef ASIO_DEBUGGING
  188034. static void logError (const String& context, long error)
  188035. {
  188036. String err ("unknown error");
  188037. if (error == ASE_NotPresent)
  188038. err = "Not Present";
  188039. else if (error == ASE_HWMalfunction)
  188040. err = "Hardware Malfunction";
  188041. else if (error == ASE_InvalidParameter)
  188042. err = "Invalid Parameter";
  188043. else if (error == ASE_InvalidMode)
  188044. err = "Invalid Mode";
  188045. else if (error == ASE_SPNotAdvancing)
  188046. err = "Sample position not advancing";
  188047. else if (error == ASE_NoClock)
  188048. err = "No Clock";
  188049. else if (error == ASE_NoMemory)
  188050. err = "Out of memory";
  188051. log ("!!error: " + context + " - " + err);
  188052. }
  188053. #else
  188054. #define logError(a, b) {}
  188055. #endif
  188056. class ASIOAudioIODevice;
  188057. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188058. static const int maxASIOChannels = 160;
  188059. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188060. private Timer
  188061. {
  188062. public:
  188063. Component ourWindow;
  188064. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188065. const String& optionalDllForDirectLoading_)
  188066. : AudioIODevice (name_, "ASIO"),
  188067. asioObject (0),
  188068. classId (classId_),
  188069. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188070. currentBitDepth (16),
  188071. currentSampleRate (0),
  188072. isOpen_ (false),
  188073. isStarted (false),
  188074. postOutput (true),
  188075. insideControlPanelModalLoop (false),
  188076. shouldUsePreferredSize (false)
  188077. {
  188078. name = name_;
  188079. ourWindow.addToDesktop (0);
  188080. windowHandle = ourWindow.getWindowHandle();
  188081. jassert (currentASIODev [slotNumber] == 0);
  188082. currentASIODev [slotNumber] = this;
  188083. openDevice();
  188084. }
  188085. ~ASIOAudioIODevice()
  188086. {
  188087. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188088. if (currentASIODev[i] == this)
  188089. currentASIODev[i] = 0;
  188090. close();
  188091. log ("ASIO - exiting");
  188092. removeCurrentDriver();
  188093. }
  188094. void updateSampleRates()
  188095. {
  188096. // find a list of sample rates..
  188097. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188098. sampleRates.clear();
  188099. if (asioObject != 0)
  188100. {
  188101. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188102. {
  188103. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188104. if (err == 0)
  188105. {
  188106. sampleRates.add ((int) possibleSampleRates[index]);
  188107. log ("rate: " + String ((int) possibleSampleRates[index]));
  188108. }
  188109. else if (err != ASE_NoClock)
  188110. {
  188111. logError ("CanSampleRate", err);
  188112. }
  188113. }
  188114. if (sampleRates.size() == 0)
  188115. {
  188116. double cr = 0;
  188117. const long err = asioObject->getSampleRate (&cr);
  188118. log ("No sample rates supported - current rate: " + String ((int) cr));
  188119. if (err == 0)
  188120. sampleRates.add ((int) cr);
  188121. }
  188122. }
  188123. }
  188124. const StringArray getOutputChannelNames()
  188125. {
  188126. return outputChannelNames;
  188127. }
  188128. const StringArray getInputChannelNames()
  188129. {
  188130. return inputChannelNames;
  188131. }
  188132. int getNumSampleRates()
  188133. {
  188134. return sampleRates.size();
  188135. }
  188136. double getSampleRate (int index)
  188137. {
  188138. return sampleRates [index];
  188139. }
  188140. int getNumBufferSizesAvailable()
  188141. {
  188142. return bufferSizes.size();
  188143. }
  188144. int getBufferSizeSamples (int index)
  188145. {
  188146. return bufferSizes [index];
  188147. }
  188148. int getDefaultBufferSize()
  188149. {
  188150. return preferredSize;
  188151. }
  188152. const String open (const BigInteger& inputChannels,
  188153. const BigInteger& outputChannels,
  188154. double sr,
  188155. int bufferSizeSamples)
  188156. {
  188157. close();
  188158. currentCallback = 0;
  188159. if (bufferSizeSamples <= 0)
  188160. shouldUsePreferredSize = true;
  188161. if (asioObject == 0 || ! isASIOOpen)
  188162. {
  188163. log ("Warning: device not open");
  188164. const String err (openDevice());
  188165. if (asioObject == 0 || ! isASIOOpen)
  188166. return err;
  188167. }
  188168. isStarted = false;
  188169. bufferIndex = -1;
  188170. long err = 0;
  188171. long newPreferredSize = 0;
  188172. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188173. minSize = 0;
  188174. maxSize = 0;
  188175. newPreferredSize = 0;
  188176. granularity = 0;
  188177. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188178. {
  188179. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188180. shouldUsePreferredSize = true;
  188181. preferredSize = newPreferredSize;
  188182. }
  188183. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188184. // dynamic changes to the buffer size...
  188185. shouldUsePreferredSize = shouldUsePreferredSize
  188186. || getName().containsIgnoreCase ("Digidesign");
  188187. if (shouldUsePreferredSize)
  188188. {
  188189. log ("Using preferred size for buffer..");
  188190. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188191. {
  188192. bufferSizeSamples = preferredSize;
  188193. }
  188194. else
  188195. {
  188196. bufferSizeSamples = 1024;
  188197. logError ("GetBufferSize1", err);
  188198. }
  188199. shouldUsePreferredSize = false;
  188200. }
  188201. int sampleRate = roundDoubleToInt (sr);
  188202. currentSampleRate = sampleRate;
  188203. currentBlockSizeSamples = bufferSizeSamples;
  188204. currentChansOut.clear();
  188205. currentChansIn.clear();
  188206. zeromem (inBuffers, sizeof (inBuffers));
  188207. zeromem (outBuffers, sizeof (outBuffers));
  188208. updateSampleRates();
  188209. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188210. sampleRate = sampleRates[0];
  188211. jassert (sampleRate != 0);
  188212. if (sampleRate == 0)
  188213. sampleRate = 44100;
  188214. long numSources = 32;
  188215. ASIOClockSource clocks[32];
  188216. zeromem (clocks, sizeof (clocks));
  188217. asioObject->getClockSources (clocks, &numSources);
  188218. bool isSourceSet = false;
  188219. // careful not to remove this loop because it does more than just logging!
  188220. int i;
  188221. for (i = 0; i < numSources; ++i)
  188222. {
  188223. String s ("clock: ");
  188224. s += clocks[i].name;
  188225. if (clocks[i].isCurrentSource)
  188226. {
  188227. isSourceSet = true;
  188228. s << " (cur)";
  188229. }
  188230. log (s);
  188231. }
  188232. if (numSources > 1 && ! isSourceSet)
  188233. {
  188234. log ("setting clock source");
  188235. asioObject->setClockSource (clocks[0].index);
  188236. Thread::sleep (20);
  188237. }
  188238. else
  188239. {
  188240. if (numSources == 0)
  188241. {
  188242. log ("ASIO - no clock sources!");
  188243. }
  188244. }
  188245. double cr = 0;
  188246. err = asioObject->getSampleRate (&cr);
  188247. if (err == 0)
  188248. {
  188249. currentSampleRate = cr;
  188250. }
  188251. else
  188252. {
  188253. logError ("GetSampleRate", err);
  188254. currentSampleRate = 0;
  188255. }
  188256. error = String::empty;
  188257. needToReset = false;
  188258. isReSync = false;
  188259. err = 0;
  188260. bool buffersCreated = false;
  188261. if (currentSampleRate != sampleRate)
  188262. {
  188263. log ("ASIO samplerate: " + String (currentSampleRate) + " to " + String (sampleRate));
  188264. err = asioObject->setSampleRate (sampleRate);
  188265. if (err == ASE_NoClock && numSources > 0)
  188266. {
  188267. log ("trying to set a clock source..");
  188268. Thread::sleep (10);
  188269. err = asioObject->setClockSource (clocks[0].index);
  188270. if (err != 0)
  188271. {
  188272. logError ("SetClock", err);
  188273. }
  188274. Thread::sleep (10);
  188275. err = asioObject->setSampleRate (sampleRate);
  188276. }
  188277. }
  188278. if (err == 0)
  188279. {
  188280. currentSampleRate = sampleRate;
  188281. if (needToReset)
  188282. {
  188283. if (isReSync)
  188284. {
  188285. log ("Resync request");
  188286. }
  188287. log ("! Resetting ASIO after sample rate change");
  188288. removeCurrentDriver();
  188289. loadDriver();
  188290. const String error (initDriver());
  188291. if (error.isNotEmpty())
  188292. {
  188293. log ("ASIOInit: " + error);
  188294. }
  188295. needToReset = false;
  188296. isReSync = false;
  188297. }
  188298. numActiveInputChans = 0;
  188299. numActiveOutputChans = 0;
  188300. ASIOBufferInfo* info = bufferInfos;
  188301. int i;
  188302. for (i = 0; i < totalNumInputChans; ++i)
  188303. {
  188304. if (inputChannels[i])
  188305. {
  188306. currentChansIn.setBit (i);
  188307. info->isInput = 1;
  188308. info->channelNum = i;
  188309. info->buffers[0] = info->buffers[1] = 0;
  188310. ++info;
  188311. ++numActiveInputChans;
  188312. }
  188313. }
  188314. for (i = 0; i < totalNumOutputChans; ++i)
  188315. {
  188316. if (outputChannels[i])
  188317. {
  188318. currentChansOut.setBit (i);
  188319. info->isInput = 0;
  188320. info->channelNum = i;
  188321. info->buffers[0] = info->buffers[1] = 0;
  188322. ++info;
  188323. ++numActiveOutputChans;
  188324. }
  188325. }
  188326. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188327. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188328. if (currentASIODev[0] == this)
  188329. {
  188330. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188331. callbacks.asioMessage = &asioMessagesCallback0;
  188332. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188333. }
  188334. else if (currentASIODev[1] == this)
  188335. {
  188336. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188337. callbacks.asioMessage = &asioMessagesCallback1;
  188338. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188339. }
  188340. else if (currentASIODev[2] == this)
  188341. {
  188342. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188343. callbacks.asioMessage = &asioMessagesCallback2;
  188344. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188345. }
  188346. else
  188347. {
  188348. jassertfalse
  188349. }
  188350. log ("disposing buffers");
  188351. err = asioObject->disposeBuffers();
  188352. log ("creating buffers: " + String (totalBuffers) + ", " + String (currentBlockSizeSamples));
  188353. err = asioObject->createBuffers (bufferInfos,
  188354. totalBuffers,
  188355. currentBlockSizeSamples,
  188356. &callbacks);
  188357. if (err != 0)
  188358. {
  188359. currentBlockSizeSamples = preferredSize;
  188360. logError ("create buffers 2", err);
  188361. asioObject->disposeBuffers();
  188362. err = asioObject->createBuffers (bufferInfos,
  188363. totalBuffers,
  188364. currentBlockSizeSamples,
  188365. &callbacks);
  188366. }
  188367. if (err == 0)
  188368. {
  188369. buffersCreated = true;
  188370. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188371. int n = 0;
  188372. Array <int> types;
  188373. currentBitDepth = 16;
  188374. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188375. {
  188376. if (inputChannels[i])
  188377. {
  188378. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188379. ASIOChannelInfo channelInfo;
  188380. zerostruct (channelInfo);
  188381. channelInfo.channel = i;
  188382. channelInfo.isInput = 1;
  188383. asioObject->getChannelInfo (&channelInfo);
  188384. types.addIfNotAlreadyThere (channelInfo.type);
  188385. typeToFormatParameters (channelInfo.type,
  188386. inputChannelBitDepths[n],
  188387. inputChannelBytesPerSample[n],
  188388. inputChannelIsFloat[n],
  188389. inputChannelLittleEndian[n]);
  188390. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188391. ++n;
  188392. }
  188393. }
  188394. jassert (numActiveInputChans == n);
  188395. n = 0;
  188396. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188397. {
  188398. if (outputChannels[i])
  188399. {
  188400. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188401. ASIOChannelInfo channelInfo;
  188402. zerostruct (channelInfo);
  188403. channelInfo.channel = i;
  188404. channelInfo.isInput = 0;
  188405. asioObject->getChannelInfo (&channelInfo);
  188406. types.addIfNotAlreadyThere (channelInfo.type);
  188407. typeToFormatParameters (channelInfo.type,
  188408. outputChannelBitDepths[n],
  188409. outputChannelBytesPerSample[n],
  188410. outputChannelIsFloat[n],
  188411. outputChannelLittleEndian[n]);
  188412. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188413. ++n;
  188414. }
  188415. }
  188416. jassert (numActiveOutputChans == n);
  188417. for (i = types.size(); --i >= 0;)
  188418. {
  188419. log ("channel format: " + String (types[i]));
  188420. }
  188421. jassert (n <= totalBuffers);
  188422. for (i = 0; i < numActiveOutputChans; ++i)
  188423. {
  188424. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188425. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188426. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188427. {
  188428. log ("!! Null buffers");
  188429. }
  188430. else
  188431. {
  188432. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188433. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188434. }
  188435. }
  188436. inputLatency = outputLatency = 0;
  188437. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188438. {
  188439. log ("ASIO - no latencies");
  188440. }
  188441. else
  188442. {
  188443. log ("ASIO latencies: " + String ((int) outputLatency) + ", " + String ((int) inputLatency));
  188444. }
  188445. isOpen_ = true;
  188446. log ("starting ASIO");
  188447. calledback = false;
  188448. err = asioObject->start();
  188449. if (err != 0)
  188450. {
  188451. isOpen_ = false;
  188452. log ("ASIO - stop on failure");
  188453. Thread::sleep (10);
  188454. asioObject->stop();
  188455. error = "Can't start device";
  188456. Thread::sleep (10);
  188457. }
  188458. else
  188459. {
  188460. int count = 300;
  188461. while (--count > 0 && ! calledback)
  188462. Thread::sleep (10);
  188463. isStarted = true;
  188464. if (! calledback)
  188465. {
  188466. error = "Device didn't start correctly";
  188467. log ("ASIO didn't callback - stopping..");
  188468. asioObject->stop();
  188469. }
  188470. }
  188471. }
  188472. else
  188473. {
  188474. error = "Can't create i/o buffers";
  188475. }
  188476. }
  188477. else
  188478. {
  188479. error = "Can't set sample rate: ";
  188480. error << sampleRate;
  188481. }
  188482. if (error.isNotEmpty())
  188483. {
  188484. logError (error, err);
  188485. if (asioObject != 0 && buffersCreated)
  188486. asioObject->disposeBuffers();
  188487. Thread::sleep (20);
  188488. isStarted = false;
  188489. isOpen_ = false;
  188490. close();
  188491. }
  188492. needToReset = false;
  188493. isReSync = false;
  188494. return error;
  188495. }
  188496. void close()
  188497. {
  188498. error = String::empty;
  188499. stopTimer();
  188500. stop();
  188501. if (isASIOOpen && isOpen_)
  188502. {
  188503. const ScopedLock sl (callbackLock);
  188504. isOpen_ = false;
  188505. isStarted = false;
  188506. needToReset = false;
  188507. isReSync = false;
  188508. log ("ASIO - stopping");
  188509. if (asioObject != 0)
  188510. {
  188511. Thread::sleep (20);
  188512. asioObject->stop();
  188513. Thread::sleep (10);
  188514. asioObject->disposeBuffers();
  188515. }
  188516. Thread::sleep (10);
  188517. }
  188518. }
  188519. bool isOpen()
  188520. {
  188521. return isOpen_ || insideControlPanelModalLoop;
  188522. }
  188523. int getCurrentBufferSizeSamples()
  188524. {
  188525. return currentBlockSizeSamples;
  188526. }
  188527. double getCurrentSampleRate()
  188528. {
  188529. return currentSampleRate;
  188530. }
  188531. const BigInteger getActiveOutputChannels() const
  188532. {
  188533. return currentChansOut;
  188534. }
  188535. const BigInteger getActiveInputChannels() const
  188536. {
  188537. return currentChansIn;
  188538. }
  188539. int getCurrentBitDepth()
  188540. {
  188541. return currentBitDepth;
  188542. }
  188543. int getOutputLatencyInSamples()
  188544. {
  188545. return outputLatency + currentBlockSizeSamples / 4;
  188546. }
  188547. int getInputLatencyInSamples()
  188548. {
  188549. return inputLatency + currentBlockSizeSamples / 4;
  188550. }
  188551. void start (AudioIODeviceCallback* callback)
  188552. {
  188553. if (callback != 0)
  188554. {
  188555. callback->audioDeviceAboutToStart (this);
  188556. const ScopedLock sl (callbackLock);
  188557. currentCallback = callback;
  188558. }
  188559. }
  188560. void stop()
  188561. {
  188562. AudioIODeviceCallback* const lastCallback = currentCallback;
  188563. {
  188564. const ScopedLock sl (callbackLock);
  188565. currentCallback = 0;
  188566. }
  188567. if (lastCallback != 0)
  188568. lastCallback->audioDeviceStopped();
  188569. }
  188570. bool isPlaying()
  188571. {
  188572. return isASIOOpen && (currentCallback != 0);
  188573. }
  188574. const String getLastError()
  188575. {
  188576. return error;
  188577. }
  188578. bool hasControlPanel() const
  188579. {
  188580. return true;
  188581. }
  188582. bool showControlPanel()
  188583. {
  188584. log ("ASIO - showing control panel");
  188585. Component modalWindow (String::empty);
  188586. modalWindow.setOpaque (true);
  188587. modalWindow.addToDesktop (0);
  188588. modalWindow.enterModalState();
  188589. bool done = false;
  188590. JUCE_TRY
  188591. {
  188592. // are there are devices that need to be closed before showing their control panel?
  188593. // close();
  188594. insideControlPanelModalLoop = true;
  188595. const uint32 started = Time::getMillisecondCounter();
  188596. if (asioObject != 0)
  188597. {
  188598. asioObject->controlPanel();
  188599. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188600. log ("spent: " + String (spent));
  188601. if (spent > 300)
  188602. {
  188603. shouldUsePreferredSize = true;
  188604. done = true;
  188605. }
  188606. }
  188607. }
  188608. JUCE_CATCH_ALL
  188609. insideControlPanelModalLoop = false;
  188610. return done;
  188611. }
  188612. void resetRequest() throw()
  188613. {
  188614. needToReset = true;
  188615. }
  188616. void resyncRequest() throw()
  188617. {
  188618. needToReset = true;
  188619. isReSync = true;
  188620. }
  188621. void timerCallback()
  188622. {
  188623. if (! insideControlPanelModalLoop)
  188624. {
  188625. stopTimer();
  188626. // used to cause a reset
  188627. log ("! ASIO restart request!");
  188628. if (isOpen_)
  188629. {
  188630. AudioIODeviceCallback* const oldCallback = currentCallback;
  188631. close();
  188632. open (BigInteger (currentChansIn), BigInteger (currentChansOut),
  188633. currentSampleRate, currentBlockSizeSamples);
  188634. if (oldCallback != 0)
  188635. start (oldCallback);
  188636. }
  188637. }
  188638. else
  188639. {
  188640. startTimer (100);
  188641. }
  188642. }
  188643. juce_UseDebuggingNewOperator
  188644. private:
  188645. IASIO* volatile asioObject;
  188646. ASIOCallbacks callbacks;
  188647. void* windowHandle;
  188648. CLSID classId;
  188649. const String optionalDllForDirectLoading;
  188650. String error;
  188651. long totalNumInputChans, totalNumOutputChans;
  188652. StringArray inputChannelNames, outputChannelNames;
  188653. Array<int> sampleRates, bufferSizes;
  188654. long inputLatency, outputLatency;
  188655. long minSize, maxSize, preferredSize, granularity;
  188656. int volatile currentBlockSizeSamples;
  188657. int volatile currentBitDepth;
  188658. double volatile currentSampleRate;
  188659. BigInteger currentChansOut, currentChansIn;
  188660. AudioIODeviceCallback* volatile currentCallback;
  188661. CriticalSection callbackLock;
  188662. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188663. float* inBuffers [maxASIOChannels];
  188664. float* outBuffers [maxASIOChannels];
  188665. int inputChannelBitDepths [maxASIOChannels];
  188666. int outputChannelBitDepths [maxASIOChannels];
  188667. int inputChannelBytesPerSample [maxASIOChannels];
  188668. int outputChannelBytesPerSample [maxASIOChannels];
  188669. bool inputChannelIsFloat [maxASIOChannels];
  188670. bool outputChannelIsFloat [maxASIOChannels];
  188671. bool inputChannelLittleEndian [maxASIOChannels];
  188672. bool outputChannelLittleEndian [maxASIOChannels];
  188673. WaitableEvent event1;
  188674. HeapBlock <float> tempBuffer;
  188675. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188676. bool isOpen_, isStarted;
  188677. bool volatile isASIOOpen;
  188678. bool volatile calledback;
  188679. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188680. bool volatile insideControlPanelModalLoop;
  188681. bool volatile shouldUsePreferredSize;
  188682. void removeCurrentDriver()
  188683. {
  188684. if (asioObject != 0)
  188685. {
  188686. asioObject->Release();
  188687. asioObject = 0;
  188688. }
  188689. }
  188690. bool loadDriver()
  188691. {
  188692. removeCurrentDriver();
  188693. JUCE_TRY
  188694. {
  188695. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188696. classId, (void**) &asioObject) == S_OK)
  188697. {
  188698. return true;
  188699. }
  188700. // If a class isn't registered but we have a path for it, we can fallback to
  188701. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188702. if (optionalDllForDirectLoading.isNotEmpty())
  188703. {
  188704. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188705. if (h != 0)
  188706. {
  188707. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188708. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188709. if (dllGetClassObject != 0)
  188710. {
  188711. IClassFactory* classFactory = 0;
  188712. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188713. if (classFactory != 0)
  188714. {
  188715. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188716. classFactory->Release();
  188717. }
  188718. return asioObject != 0;
  188719. }
  188720. }
  188721. }
  188722. }
  188723. JUCE_CATCH_ALL
  188724. asioObject = 0;
  188725. return false;
  188726. }
  188727. const String initDriver()
  188728. {
  188729. if (asioObject != 0)
  188730. {
  188731. char buffer [256];
  188732. zeromem (buffer, sizeof (buffer));
  188733. if (! asioObject->init (windowHandle))
  188734. {
  188735. asioObject->getErrorMessage (buffer);
  188736. return String (buffer, sizeof (buffer) - 1);
  188737. }
  188738. // just in case any daft drivers expect this to be called..
  188739. asioObject->getDriverName (buffer);
  188740. return String::empty;
  188741. }
  188742. return "No Driver";
  188743. }
  188744. const String openDevice()
  188745. {
  188746. // use this in case the driver starts opening dialog boxes..
  188747. Component modalWindow (String::empty);
  188748. modalWindow.setOpaque (true);
  188749. modalWindow.addToDesktop (0);
  188750. modalWindow.enterModalState();
  188751. // open the device and get its info..
  188752. log ("opening ASIO device: " + getName());
  188753. needToReset = false;
  188754. isReSync = false;
  188755. outputChannelNames.clear();
  188756. inputChannelNames.clear();
  188757. bufferSizes.clear();
  188758. sampleRates.clear();
  188759. isASIOOpen = false;
  188760. isOpen_ = false;
  188761. totalNumInputChans = 0;
  188762. totalNumOutputChans = 0;
  188763. numActiveInputChans = 0;
  188764. numActiveOutputChans = 0;
  188765. currentCallback = 0;
  188766. error = String::empty;
  188767. if (getName().isEmpty())
  188768. return error;
  188769. long err = 0;
  188770. if (loadDriver())
  188771. {
  188772. if ((error = initDriver()).isEmpty())
  188773. {
  188774. numActiveInputChans = 0;
  188775. numActiveOutputChans = 0;
  188776. totalNumInputChans = 0;
  188777. totalNumOutputChans = 0;
  188778. if (asioObject != 0
  188779. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188780. {
  188781. log (String ((int) totalNumInputChans) + " in, " + String ((int) totalNumOutputChans) + " out");
  188782. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188783. {
  188784. // find a list of buffer sizes..
  188785. log (String ((int) minSize) + " " + String ((int) maxSize) + " " + String ((int) preferredSize) + " " + String ((int) granularity));
  188786. if (granularity >= 0)
  188787. {
  188788. granularity = jmax (1, (int) granularity);
  188789. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188790. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188791. }
  188792. else if (granularity < 0)
  188793. {
  188794. for (int i = 0; i < 18; ++i)
  188795. {
  188796. const int s = (1 << i);
  188797. if (s >= minSize && s <= maxSize)
  188798. bufferSizes.add (s);
  188799. }
  188800. }
  188801. if (! bufferSizes.contains (preferredSize))
  188802. bufferSizes.insert (0, preferredSize);
  188803. double currentRate = 0;
  188804. asioObject->getSampleRate (&currentRate);
  188805. if (currentRate <= 0.0 || currentRate > 192001.0)
  188806. {
  188807. log ("setting sample rate");
  188808. err = asioObject->setSampleRate (44100.0);
  188809. if (err != 0)
  188810. {
  188811. logError ("setting sample rate", err);
  188812. }
  188813. asioObject->getSampleRate (&currentRate);
  188814. }
  188815. currentSampleRate = currentRate;
  188816. postOutput = (asioObject->outputReady() == 0);
  188817. if (postOutput)
  188818. {
  188819. log ("ASIO outputReady = ok");
  188820. }
  188821. updateSampleRates();
  188822. // ..because cubase does it at this point
  188823. inputLatency = outputLatency = 0;
  188824. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188825. {
  188826. log ("ASIO - no latencies");
  188827. }
  188828. log ("latencies: " + String ((int) inputLatency) + ", " + String ((int) outputLatency));
  188829. // create some dummy buffers now.. because cubase does..
  188830. numActiveInputChans = 0;
  188831. numActiveOutputChans = 0;
  188832. ASIOBufferInfo* info = bufferInfos;
  188833. int i, numChans = 0;
  188834. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188835. {
  188836. info->isInput = 1;
  188837. info->channelNum = i;
  188838. info->buffers[0] = info->buffers[1] = 0;
  188839. ++info;
  188840. ++numChans;
  188841. }
  188842. const int outputBufferIndex = numChans;
  188843. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  188844. {
  188845. info->isInput = 0;
  188846. info->channelNum = i;
  188847. info->buffers[0] = info->buffers[1] = 0;
  188848. ++info;
  188849. ++numChans;
  188850. }
  188851. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188852. if (currentASIODev[0] == this)
  188853. {
  188854. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188855. callbacks.asioMessage = &asioMessagesCallback0;
  188856. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188857. }
  188858. else if (currentASIODev[1] == this)
  188859. {
  188860. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188861. callbacks.asioMessage = &asioMessagesCallback1;
  188862. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188863. }
  188864. else if (currentASIODev[2] == this)
  188865. {
  188866. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188867. callbacks.asioMessage = &asioMessagesCallback2;
  188868. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188869. }
  188870. else
  188871. {
  188872. jassertfalse
  188873. }
  188874. log ("creating buffers (dummy): " + String (numChans) + ", " + String ((int) preferredSize));
  188875. if (preferredSize > 0)
  188876. {
  188877. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  188878. if (err != 0)
  188879. {
  188880. logError ("dummy buffers", err);
  188881. }
  188882. }
  188883. long newInps = 0, newOuts = 0;
  188884. asioObject->getChannels (&newInps, &newOuts);
  188885. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  188886. {
  188887. totalNumInputChans = newInps;
  188888. totalNumOutputChans = newOuts;
  188889. log (String ((int) totalNumInputChans) + " in; " + String ((int) totalNumOutputChans) + " out");
  188890. }
  188891. updateSampleRates();
  188892. ASIOChannelInfo channelInfo;
  188893. channelInfo.type = 0;
  188894. for (i = 0; i < totalNumInputChans; ++i)
  188895. {
  188896. zerostruct (channelInfo);
  188897. channelInfo.channel = i;
  188898. channelInfo.isInput = 1;
  188899. asioObject->getChannelInfo (&channelInfo);
  188900. inputChannelNames.add (String (channelInfo.name));
  188901. }
  188902. for (i = 0; i < totalNumOutputChans; ++i)
  188903. {
  188904. zerostruct (channelInfo);
  188905. channelInfo.channel = i;
  188906. channelInfo.isInput = 0;
  188907. asioObject->getChannelInfo (&channelInfo);
  188908. outputChannelNames.add (String (channelInfo.name));
  188909. typeToFormatParameters (channelInfo.type,
  188910. outputChannelBitDepths[i],
  188911. outputChannelBytesPerSample[i],
  188912. outputChannelIsFloat[i],
  188913. outputChannelLittleEndian[i]);
  188914. if (i < 2)
  188915. {
  188916. // clear the channels that are used with the dummy stuff
  188917. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  188918. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  188919. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  188920. }
  188921. }
  188922. outputChannelNames.trim();
  188923. inputChannelNames.trim();
  188924. outputChannelNames.appendNumbersToDuplicates (false, true);
  188925. inputChannelNames.appendNumbersToDuplicates (false, true);
  188926. // start and stop because cubase does it..
  188927. asioObject->getLatencies (&inputLatency, &outputLatency);
  188928. if ((err = asioObject->start()) != 0)
  188929. {
  188930. // ignore an error here, as it might start later after setting other stuff up
  188931. logError ("ASIO start", err);
  188932. }
  188933. Thread::sleep (100);
  188934. asioObject->stop();
  188935. }
  188936. else
  188937. {
  188938. error = "Can't detect buffer sizes";
  188939. }
  188940. }
  188941. else
  188942. {
  188943. error = "Can't detect asio channels";
  188944. }
  188945. }
  188946. }
  188947. else
  188948. {
  188949. error = "No such device";
  188950. }
  188951. if (error.isNotEmpty())
  188952. {
  188953. logError (error, err);
  188954. if (asioObject != 0)
  188955. asioObject->disposeBuffers();
  188956. removeCurrentDriver();
  188957. isASIOOpen = false;
  188958. }
  188959. else
  188960. {
  188961. isASIOOpen = true;
  188962. log ("ASIO device open");
  188963. }
  188964. isOpen_ = false;
  188965. needToReset = false;
  188966. isReSync = false;
  188967. return error;
  188968. }
  188969. void callback (const long index) throw()
  188970. {
  188971. if (isStarted)
  188972. {
  188973. bufferIndex = index;
  188974. processBuffer();
  188975. }
  188976. else
  188977. {
  188978. if (postOutput && (asioObject != 0))
  188979. asioObject->outputReady();
  188980. }
  188981. calledback = true;
  188982. }
  188983. void processBuffer() throw()
  188984. {
  188985. const ASIOBufferInfo* const infos = bufferInfos;
  188986. const int bi = bufferIndex;
  188987. const ScopedLock sl (callbackLock);
  188988. if (needToReset)
  188989. {
  188990. needToReset = false;
  188991. if (isReSync)
  188992. {
  188993. log ("! ASIO resync");
  188994. isReSync = false;
  188995. }
  188996. else
  188997. {
  188998. startTimer (20);
  188999. }
  189000. }
  189001. if (bi >= 0)
  189002. {
  189003. const int samps = currentBlockSizeSamples;
  189004. if (currentCallback != 0)
  189005. {
  189006. int i;
  189007. for (i = 0; i < numActiveInputChans; ++i)
  189008. {
  189009. float* const dst = inBuffers[i];
  189010. jassert (dst != 0);
  189011. const char* const src = (const char*) (infos[i].buffers[bi]);
  189012. if (inputChannelIsFloat[i])
  189013. {
  189014. memcpy (dst, src, samps * sizeof (float));
  189015. }
  189016. else
  189017. {
  189018. jassert (dst == tempBuffer + (samps * i));
  189019. switch (inputChannelBitDepths[i])
  189020. {
  189021. case 16:
  189022. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189023. samps, inputChannelLittleEndian[i]);
  189024. break;
  189025. case 24:
  189026. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189027. samps, inputChannelLittleEndian[i]);
  189028. break;
  189029. case 32:
  189030. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189031. samps, inputChannelLittleEndian[i]);
  189032. break;
  189033. case 64:
  189034. jassertfalse
  189035. break;
  189036. }
  189037. }
  189038. }
  189039. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189040. numActiveInputChans,
  189041. outBuffers,
  189042. numActiveOutputChans,
  189043. samps);
  189044. for (i = 0; i < numActiveOutputChans; ++i)
  189045. {
  189046. float* const src = outBuffers[i];
  189047. jassert (src != 0);
  189048. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189049. if (outputChannelIsFloat[i])
  189050. {
  189051. memcpy (dst, src, samps * sizeof (float));
  189052. }
  189053. else
  189054. {
  189055. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189056. switch (outputChannelBitDepths[i])
  189057. {
  189058. case 16:
  189059. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189060. samps, outputChannelLittleEndian[i]);
  189061. break;
  189062. case 24:
  189063. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189064. samps, outputChannelLittleEndian[i]);
  189065. break;
  189066. case 32:
  189067. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189068. samps, outputChannelLittleEndian[i]);
  189069. break;
  189070. case 64:
  189071. jassertfalse
  189072. break;
  189073. }
  189074. }
  189075. }
  189076. }
  189077. else
  189078. {
  189079. for (int i = 0; i < numActiveOutputChans; ++i)
  189080. {
  189081. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189082. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189083. }
  189084. }
  189085. }
  189086. if (postOutput)
  189087. asioObject->outputReady();
  189088. }
  189089. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189090. {
  189091. if (currentASIODev[0] != 0)
  189092. currentASIODev[0]->callback (index);
  189093. return 0;
  189094. }
  189095. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189096. {
  189097. if (currentASIODev[1] != 0)
  189098. currentASIODev[1]->callback (index);
  189099. return 0;
  189100. }
  189101. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189102. {
  189103. if (currentASIODev[2] != 0)
  189104. currentASIODev[2]->callback (index);
  189105. return 0;
  189106. }
  189107. static void bufferSwitchCallback0 (long index, long) throw()
  189108. {
  189109. if (currentASIODev[0] != 0)
  189110. currentASIODev[0]->callback (index);
  189111. }
  189112. static void bufferSwitchCallback1 (long index, long) throw()
  189113. {
  189114. if (currentASIODev[1] != 0)
  189115. currentASIODev[1]->callback (index);
  189116. }
  189117. static void bufferSwitchCallback2 (long index, long) throw()
  189118. {
  189119. if (currentASIODev[2] != 0)
  189120. currentASIODev[2]->callback (index);
  189121. }
  189122. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189123. {
  189124. return asioMessagesCallback (selector, value, 0);
  189125. }
  189126. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189127. {
  189128. return asioMessagesCallback (selector, value, 1);
  189129. }
  189130. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189131. {
  189132. return asioMessagesCallback (selector, value, 2);
  189133. }
  189134. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189135. {
  189136. switch (selector)
  189137. {
  189138. case kAsioSelectorSupported:
  189139. if (value == kAsioResetRequest
  189140. || value == kAsioEngineVersion
  189141. || value == kAsioResyncRequest
  189142. || value == kAsioLatenciesChanged
  189143. || value == kAsioSupportsInputMonitor)
  189144. return 1;
  189145. break;
  189146. case kAsioBufferSizeChange:
  189147. break;
  189148. case kAsioResetRequest:
  189149. if (currentASIODev[deviceIndex] != 0)
  189150. currentASIODev[deviceIndex]->resetRequest();
  189151. return 1;
  189152. case kAsioResyncRequest:
  189153. if (currentASIODev[deviceIndex] != 0)
  189154. currentASIODev[deviceIndex]->resyncRequest();
  189155. return 1;
  189156. case kAsioLatenciesChanged:
  189157. return 1;
  189158. case kAsioEngineVersion:
  189159. return 2;
  189160. case kAsioSupportsTimeInfo:
  189161. case kAsioSupportsTimeCode:
  189162. return 0;
  189163. }
  189164. return 0;
  189165. }
  189166. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189167. {
  189168. }
  189169. static void convertInt16ToFloat (const char* src,
  189170. float* dest,
  189171. const int srcStrideBytes,
  189172. int numSamples,
  189173. const bool littleEndian) throw()
  189174. {
  189175. const double g = 1.0 / 32768.0;
  189176. if (littleEndian)
  189177. {
  189178. while (--numSamples >= 0)
  189179. {
  189180. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189181. src += srcStrideBytes;
  189182. }
  189183. }
  189184. else
  189185. {
  189186. while (--numSamples >= 0)
  189187. {
  189188. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189189. src += srcStrideBytes;
  189190. }
  189191. }
  189192. }
  189193. static void convertFloatToInt16 (const float* src,
  189194. char* dest,
  189195. const int dstStrideBytes,
  189196. int numSamples,
  189197. const bool littleEndian) throw()
  189198. {
  189199. const double maxVal = (double) 0x7fff;
  189200. if (littleEndian)
  189201. {
  189202. while (--numSamples >= 0)
  189203. {
  189204. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189205. dest += dstStrideBytes;
  189206. }
  189207. }
  189208. else
  189209. {
  189210. while (--numSamples >= 0)
  189211. {
  189212. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189213. dest += dstStrideBytes;
  189214. }
  189215. }
  189216. }
  189217. static void convertInt24ToFloat (const char* src,
  189218. float* dest,
  189219. const int srcStrideBytes,
  189220. int numSamples,
  189221. const bool littleEndian) throw()
  189222. {
  189223. const double g = 1.0 / 0x7fffff;
  189224. if (littleEndian)
  189225. {
  189226. while (--numSamples >= 0)
  189227. {
  189228. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189229. src += srcStrideBytes;
  189230. }
  189231. }
  189232. else
  189233. {
  189234. while (--numSamples >= 0)
  189235. {
  189236. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189237. src += srcStrideBytes;
  189238. }
  189239. }
  189240. }
  189241. static void convertFloatToInt24 (const float* src,
  189242. char* dest,
  189243. const int dstStrideBytes,
  189244. int numSamples,
  189245. const bool littleEndian) throw()
  189246. {
  189247. const double maxVal = (double) 0x7fffff;
  189248. if (littleEndian)
  189249. {
  189250. while (--numSamples >= 0)
  189251. {
  189252. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189253. dest += dstStrideBytes;
  189254. }
  189255. }
  189256. else
  189257. {
  189258. while (--numSamples >= 0)
  189259. {
  189260. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189261. dest += dstStrideBytes;
  189262. }
  189263. }
  189264. }
  189265. static void convertInt32ToFloat (const char* src,
  189266. float* dest,
  189267. const int srcStrideBytes,
  189268. int numSamples,
  189269. const bool littleEndian) throw()
  189270. {
  189271. const double g = 1.0 / 0x7fffffff;
  189272. if (littleEndian)
  189273. {
  189274. while (--numSamples >= 0)
  189275. {
  189276. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189277. src += srcStrideBytes;
  189278. }
  189279. }
  189280. else
  189281. {
  189282. while (--numSamples >= 0)
  189283. {
  189284. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189285. src += srcStrideBytes;
  189286. }
  189287. }
  189288. }
  189289. static void convertFloatToInt32 (const float* src,
  189290. char* dest,
  189291. const int dstStrideBytes,
  189292. int numSamples,
  189293. const bool littleEndian) throw()
  189294. {
  189295. const double maxVal = (double) 0x7fffffff;
  189296. if (littleEndian)
  189297. {
  189298. while (--numSamples >= 0)
  189299. {
  189300. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189301. dest += dstStrideBytes;
  189302. }
  189303. }
  189304. else
  189305. {
  189306. while (--numSamples >= 0)
  189307. {
  189308. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189309. dest += dstStrideBytes;
  189310. }
  189311. }
  189312. }
  189313. static void typeToFormatParameters (const long type,
  189314. int& bitDepth,
  189315. int& byteStride,
  189316. bool& formatIsFloat,
  189317. bool& littleEndian) throw()
  189318. {
  189319. bitDepth = 0;
  189320. littleEndian = false;
  189321. formatIsFloat = false;
  189322. switch (type)
  189323. {
  189324. case ASIOSTInt16MSB:
  189325. case ASIOSTInt16LSB:
  189326. case ASIOSTInt32MSB16:
  189327. case ASIOSTInt32LSB16:
  189328. bitDepth = 16; break;
  189329. case ASIOSTFloat32MSB:
  189330. case ASIOSTFloat32LSB:
  189331. formatIsFloat = true;
  189332. bitDepth = 32; break;
  189333. case ASIOSTInt32MSB:
  189334. case ASIOSTInt32LSB:
  189335. bitDepth = 32; break;
  189336. case ASIOSTInt24MSB:
  189337. case ASIOSTInt24LSB:
  189338. case ASIOSTInt32MSB24:
  189339. case ASIOSTInt32LSB24:
  189340. case ASIOSTInt32MSB18:
  189341. case ASIOSTInt32MSB20:
  189342. case ASIOSTInt32LSB18:
  189343. case ASIOSTInt32LSB20:
  189344. bitDepth = 24; break;
  189345. case ASIOSTFloat64MSB:
  189346. case ASIOSTFloat64LSB:
  189347. default:
  189348. bitDepth = 64;
  189349. break;
  189350. }
  189351. switch (type)
  189352. {
  189353. case ASIOSTInt16MSB:
  189354. case ASIOSTInt32MSB16:
  189355. case ASIOSTFloat32MSB:
  189356. case ASIOSTFloat64MSB:
  189357. case ASIOSTInt32MSB:
  189358. case ASIOSTInt32MSB18:
  189359. case ASIOSTInt32MSB20:
  189360. case ASIOSTInt32MSB24:
  189361. case ASIOSTInt24MSB:
  189362. littleEndian = false; break;
  189363. case ASIOSTInt16LSB:
  189364. case ASIOSTInt32LSB16:
  189365. case ASIOSTFloat32LSB:
  189366. case ASIOSTFloat64LSB:
  189367. case ASIOSTInt32LSB:
  189368. case ASIOSTInt32LSB18:
  189369. case ASIOSTInt32LSB20:
  189370. case ASIOSTInt32LSB24:
  189371. case ASIOSTInt24LSB:
  189372. littleEndian = true; break;
  189373. default:
  189374. break;
  189375. }
  189376. switch (type)
  189377. {
  189378. case ASIOSTInt16LSB:
  189379. case ASIOSTInt16MSB:
  189380. byteStride = 2; break;
  189381. case ASIOSTInt24LSB:
  189382. case ASIOSTInt24MSB:
  189383. byteStride = 3; break;
  189384. case ASIOSTInt32MSB16:
  189385. case ASIOSTInt32LSB16:
  189386. case ASIOSTInt32MSB:
  189387. case ASIOSTInt32MSB18:
  189388. case ASIOSTInt32MSB20:
  189389. case ASIOSTInt32MSB24:
  189390. case ASIOSTInt32LSB:
  189391. case ASIOSTInt32LSB18:
  189392. case ASIOSTInt32LSB20:
  189393. case ASIOSTInt32LSB24:
  189394. case ASIOSTFloat32LSB:
  189395. case ASIOSTFloat32MSB:
  189396. byteStride = 4; break;
  189397. case ASIOSTFloat64MSB:
  189398. case ASIOSTFloat64LSB:
  189399. byteStride = 8; break;
  189400. default:
  189401. break;
  189402. }
  189403. }
  189404. };
  189405. class ASIOAudioIODeviceType : public AudioIODeviceType
  189406. {
  189407. public:
  189408. ASIOAudioIODeviceType()
  189409. : AudioIODeviceType ("ASIO"),
  189410. hasScanned (false)
  189411. {
  189412. CoInitialize (0);
  189413. }
  189414. ~ASIOAudioIODeviceType()
  189415. {
  189416. }
  189417. void scanForDevices()
  189418. {
  189419. hasScanned = true;
  189420. deviceNames.clear();
  189421. classIds.clear();
  189422. HKEY hk = 0;
  189423. int index = 0;
  189424. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189425. {
  189426. for (;;)
  189427. {
  189428. char name [256];
  189429. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189430. {
  189431. addDriverInfo (name, hk);
  189432. }
  189433. else
  189434. {
  189435. break;
  189436. }
  189437. }
  189438. RegCloseKey (hk);
  189439. }
  189440. }
  189441. const StringArray getDeviceNames (bool /*wantInputNames*/) const
  189442. {
  189443. jassert (hasScanned); // need to call scanForDevices() before doing this
  189444. return deviceNames;
  189445. }
  189446. int getDefaultDeviceIndex (bool) const
  189447. {
  189448. jassert (hasScanned); // need to call scanForDevices() before doing this
  189449. for (int i = deviceNames.size(); --i >= 0;)
  189450. if (deviceNames[i].containsIgnoreCase ("asio4all"))
  189451. return i; // asio4all is a safe choice for a default..
  189452. #if JUCE_DEBUG
  189453. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase ("digidesign"))
  189454. return 1; // (the digi m-box driver crashes the app when you run
  189455. // it in the debugger, which can be a bit annoying)
  189456. #endif
  189457. return 0;
  189458. }
  189459. static int findFreeSlot()
  189460. {
  189461. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189462. if (currentASIODev[i] == 0)
  189463. return i;
  189464. jassertfalse; // unfortunately you can only have a finite number
  189465. // of ASIO devices open at the same time..
  189466. return -1;
  189467. }
  189468. int getIndexOfDevice (AudioIODevice* d, bool /*asInput*/) const
  189469. {
  189470. jassert (hasScanned); // need to call scanForDevices() before doing this
  189471. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189472. }
  189473. bool hasSeparateInputsAndOutputs() const { return false; }
  189474. AudioIODevice* createDevice (const String& outputDeviceName,
  189475. const String& inputDeviceName)
  189476. {
  189477. // ASIO can't open two different devices for input and output - they must be the same one.
  189478. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189479. jassert (hasScanned); // need to call scanForDevices() before doing this
  189480. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189481. : inputDeviceName);
  189482. if (index >= 0)
  189483. {
  189484. const int freeSlot = findFreeSlot();
  189485. if (freeSlot >= 0)
  189486. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189487. }
  189488. return 0;
  189489. }
  189490. juce_UseDebuggingNewOperator
  189491. private:
  189492. StringArray deviceNames;
  189493. OwnedArray <CLSID> classIds;
  189494. bool hasScanned;
  189495. static bool checkClassIsOk (const String& classId)
  189496. {
  189497. HKEY hk = 0;
  189498. bool ok = false;
  189499. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189500. {
  189501. int index = 0;
  189502. for (;;)
  189503. {
  189504. WCHAR buf [512];
  189505. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189506. {
  189507. if (classId.equalsIgnoreCase (buf))
  189508. {
  189509. HKEY subKey, pathKey;
  189510. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189511. {
  189512. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189513. {
  189514. WCHAR pathName [1024];
  189515. DWORD dtype = REG_SZ;
  189516. DWORD dsize = sizeof (pathName);
  189517. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189518. ok = File (pathName).exists();
  189519. RegCloseKey (pathKey);
  189520. }
  189521. RegCloseKey (subKey);
  189522. }
  189523. break;
  189524. }
  189525. }
  189526. else
  189527. {
  189528. break;
  189529. }
  189530. }
  189531. RegCloseKey (hk);
  189532. }
  189533. return ok;
  189534. }
  189535. void addDriverInfo (const String& keyName, HKEY hk)
  189536. {
  189537. HKEY subKey;
  189538. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189539. {
  189540. WCHAR buf [256];
  189541. zerostruct (buf);
  189542. DWORD dtype = REG_SZ;
  189543. DWORD dsize = sizeof (buf);
  189544. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189545. {
  189546. if (dsize > 0 && checkClassIsOk (buf))
  189547. {
  189548. CLSID classId;
  189549. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189550. {
  189551. dtype = REG_SZ;
  189552. dsize = sizeof (buf);
  189553. String deviceName;
  189554. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189555. deviceName = buf;
  189556. else
  189557. deviceName = keyName;
  189558. log ("found " + deviceName);
  189559. deviceNames.add (deviceName);
  189560. classIds.add (new CLSID (classId));
  189561. }
  189562. }
  189563. RegCloseKey (subKey);
  189564. }
  189565. }
  189566. }
  189567. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189568. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189569. };
  189570. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189571. {
  189572. return new ASIOAudioIODeviceType();
  189573. }
  189574. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189575. void* guid,
  189576. const String& optionalDllForDirectLoading)
  189577. {
  189578. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189579. if (freeSlot < 0)
  189580. return 0;
  189581. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189582. }
  189583. #undef log
  189584. #endif
  189585. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189586. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189587. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189588. // compiled on its own).
  189589. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189590. END_JUCE_NAMESPACE
  189591. extern "C"
  189592. {
  189593. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189594. typedef struct typeDSBUFFERDESC
  189595. {
  189596. DWORD dwSize;
  189597. DWORD dwFlags;
  189598. DWORD dwBufferBytes;
  189599. DWORD dwReserved;
  189600. LPWAVEFORMATEX lpwfxFormat;
  189601. GUID guid3DAlgorithm;
  189602. } DSBUFFERDESC;
  189603. struct IDirectSoundBuffer;
  189604. #undef INTERFACE
  189605. #define INTERFACE IDirectSound
  189606. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189607. {
  189608. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189609. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189610. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189611. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189612. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189613. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189614. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189615. STDMETHOD(Compact) (THIS) PURE;
  189616. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189617. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189618. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189619. };
  189620. #undef INTERFACE
  189621. #define INTERFACE IDirectSoundBuffer
  189622. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189623. {
  189624. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189625. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189626. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189627. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189628. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189629. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189630. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189631. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189632. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189633. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189634. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189635. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189636. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189637. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189638. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189639. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189640. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189641. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189642. STDMETHOD(Stop) (THIS) PURE;
  189643. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189644. STDMETHOD(Restore) (THIS) PURE;
  189645. };
  189646. typedef struct typeDSCBUFFERDESC
  189647. {
  189648. DWORD dwSize;
  189649. DWORD dwFlags;
  189650. DWORD dwBufferBytes;
  189651. DWORD dwReserved;
  189652. LPWAVEFORMATEX lpwfxFormat;
  189653. } DSCBUFFERDESC;
  189654. struct IDirectSoundCaptureBuffer;
  189655. #undef INTERFACE
  189656. #define INTERFACE IDirectSoundCapture
  189657. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189658. {
  189659. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189660. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189661. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189662. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189663. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189664. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189665. };
  189666. #undef INTERFACE
  189667. #define INTERFACE IDirectSoundCaptureBuffer
  189668. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189669. {
  189670. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189671. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189672. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189673. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189674. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189675. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189676. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189677. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189678. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189679. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189680. STDMETHOD(Stop) (THIS) PURE;
  189681. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189682. };
  189683. };
  189684. BEGIN_JUCE_NAMESPACE
  189685. static const String getDSErrorMessage (HRESULT hr)
  189686. {
  189687. const char* result = 0;
  189688. switch (hr)
  189689. {
  189690. case MAKE_HRESULT(1, 0x878, 10):
  189691. result = "Device already allocated";
  189692. break;
  189693. case MAKE_HRESULT(1, 0x878, 30):
  189694. result = "Control unavailable";
  189695. break;
  189696. case E_INVALIDARG:
  189697. result = "Invalid parameter";
  189698. break;
  189699. case MAKE_HRESULT(1, 0x878, 50):
  189700. result = "Invalid call";
  189701. break;
  189702. case E_FAIL:
  189703. result = "Generic error";
  189704. break;
  189705. case MAKE_HRESULT(1, 0x878, 70):
  189706. result = "Priority level error";
  189707. break;
  189708. case E_OUTOFMEMORY:
  189709. result = "Out of memory";
  189710. break;
  189711. case MAKE_HRESULT(1, 0x878, 100):
  189712. result = "Bad format";
  189713. break;
  189714. case E_NOTIMPL:
  189715. result = "Unsupported function";
  189716. break;
  189717. case MAKE_HRESULT(1, 0x878, 120):
  189718. result = "No driver";
  189719. break;
  189720. case MAKE_HRESULT(1, 0x878, 130):
  189721. result = "Already initialised";
  189722. break;
  189723. case CLASS_E_NOAGGREGATION:
  189724. result = "No aggregation";
  189725. break;
  189726. case MAKE_HRESULT(1, 0x878, 150):
  189727. result = "Buffer lost";
  189728. break;
  189729. case MAKE_HRESULT(1, 0x878, 160):
  189730. result = "Another app has priority";
  189731. break;
  189732. case MAKE_HRESULT(1, 0x878, 170):
  189733. result = "Uninitialised";
  189734. break;
  189735. case E_NOINTERFACE:
  189736. result = "No interface";
  189737. break;
  189738. case S_OK:
  189739. result = "No error";
  189740. break;
  189741. default:
  189742. return "Unknown error: " + String ((int) hr);
  189743. }
  189744. return result;
  189745. }
  189746. #define DS_DEBUGGING 1
  189747. #ifdef DS_DEBUGGING
  189748. #define CATCH JUCE_CATCH_EXCEPTION
  189749. #undef log
  189750. #define log(a) Logger::writeToLog(a);
  189751. #undef logError
  189752. #define logError(a) logDSError(a, __LINE__);
  189753. static void logDSError (HRESULT hr, int lineNum)
  189754. {
  189755. if (hr != S_OK)
  189756. {
  189757. String error ("DS error at line ");
  189758. error << lineNum << " - " << getDSErrorMessage (hr);
  189759. log (error);
  189760. }
  189761. }
  189762. #else
  189763. #define CATCH JUCE_CATCH_ALL
  189764. #define log(a)
  189765. #define logError(a)
  189766. #endif
  189767. #define DSOUND_FUNCTION(functionName, params) \
  189768. typedef HRESULT (WINAPI *type##functionName) params; \
  189769. static type##functionName ds##functionName = 0;
  189770. #define DSOUND_FUNCTION_LOAD(functionName) \
  189771. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189772. jassert (ds##functionName != 0);
  189773. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189774. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189775. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189776. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189777. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189778. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189779. static void initialiseDSoundFunctions()
  189780. {
  189781. if (dsDirectSoundCreate == 0)
  189782. {
  189783. HMODULE h = LoadLibraryA ("dsound.dll");
  189784. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189785. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189786. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189787. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189788. }
  189789. }
  189790. class DSoundInternalOutChannel
  189791. {
  189792. String name;
  189793. LPGUID guid;
  189794. int sampleRate, bufferSizeSamples;
  189795. float* leftBuffer;
  189796. float* rightBuffer;
  189797. IDirectSound* pDirectSound;
  189798. IDirectSoundBuffer* pOutputBuffer;
  189799. DWORD writeOffset;
  189800. int totalBytesPerBuffer;
  189801. int bytesPerBuffer;
  189802. unsigned int lastPlayCursor;
  189803. public:
  189804. int bitDepth;
  189805. bool doneFlag;
  189806. DSoundInternalOutChannel (const String& name_,
  189807. LPGUID guid_,
  189808. int rate,
  189809. int bufferSize,
  189810. float* left,
  189811. float* right)
  189812. : name (name_),
  189813. guid (guid_),
  189814. sampleRate (rate),
  189815. bufferSizeSamples (bufferSize),
  189816. leftBuffer (left),
  189817. rightBuffer (right),
  189818. pDirectSound (0),
  189819. pOutputBuffer (0),
  189820. bitDepth (16)
  189821. {
  189822. }
  189823. ~DSoundInternalOutChannel()
  189824. {
  189825. close();
  189826. }
  189827. void close()
  189828. {
  189829. HRESULT hr;
  189830. if (pOutputBuffer != 0)
  189831. {
  189832. JUCE_TRY
  189833. {
  189834. log ("closing dsound out: " + name);
  189835. hr = pOutputBuffer->Stop();
  189836. logError (hr);
  189837. }
  189838. CATCH
  189839. JUCE_TRY
  189840. {
  189841. hr = pOutputBuffer->Release();
  189842. logError (hr);
  189843. }
  189844. CATCH
  189845. pOutputBuffer = 0;
  189846. }
  189847. if (pDirectSound != 0)
  189848. {
  189849. JUCE_TRY
  189850. {
  189851. hr = pDirectSound->Release();
  189852. logError (hr);
  189853. }
  189854. CATCH
  189855. pDirectSound = 0;
  189856. }
  189857. }
  189858. const String open()
  189859. {
  189860. log ("opening dsound out device: " + name + " rate=" + String (sampleRate)
  189861. + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  189862. pDirectSound = 0;
  189863. pOutputBuffer = 0;
  189864. writeOffset = 0;
  189865. String error;
  189866. HRESULT hr = E_NOINTERFACE;
  189867. if (dsDirectSoundCreate != 0)
  189868. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  189869. if (hr == S_OK)
  189870. {
  189871. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  189872. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  189873. const int numChannels = 2;
  189874. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  189875. logError (hr);
  189876. if (hr == S_OK)
  189877. {
  189878. IDirectSoundBuffer* pPrimaryBuffer;
  189879. DSBUFFERDESC primaryDesc;
  189880. zerostruct (primaryDesc);
  189881. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189882. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  189883. primaryDesc.dwBufferBytes = 0;
  189884. primaryDesc.lpwfxFormat = 0;
  189885. log ("opening dsound out step 2");
  189886. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  189887. logError (hr);
  189888. if (hr == S_OK)
  189889. {
  189890. WAVEFORMATEX wfFormat;
  189891. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  189892. wfFormat.nChannels = (unsigned short) numChannels;
  189893. wfFormat.nSamplesPerSec = sampleRate;
  189894. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  189895. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  189896. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  189897. wfFormat.cbSize = 0;
  189898. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  189899. logError (hr);
  189900. if (hr == S_OK)
  189901. {
  189902. DSBUFFERDESC secondaryDesc;
  189903. zerostruct (secondaryDesc);
  189904. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189905. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  189906. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  189907. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  189908. secondaryDesc.lpwfxFormat = &wfFormat;
  189909. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  189910. logError (hr);
  189911. if (hr == S_OK)
  189912. {
  189913. log ("opening dsound out step 3");
  189914. DWORD dwDataLen;
  189915. unsigned char* pDSBuffData;
  189916. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  189917. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  189918. logError (hr);
  189919. if (hr == S_OK)
  189920. {
  189921. zeromem (pDSBuffData, dwDataLen);
  189922. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  189923. if (hr == S_OK)
  189924. {
  189925. hr = pOutputBuffer->SetCurrentPosition (0);
  189926. if (hr == S_OK)
  189927. {
  189928. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  189929. if (hr == S_OK)
  189930. return String::empty;
  189931. }
  189932. }
  189933. }
  189934. }
  189935. }
  189936. }
  189937. }
  189938. }
  189939. error = getDSErrorMessage (hr);
  189940. close();
  189941. return error;
  189942. }
  189943. void synchronisePosition()
  189944. {
  189945. if (pOutputBuffer != 0)
  189946. {
  189947. DWORD playCursor;
  189948. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  189949. }
  189950. }
  189951. bool service()
  189952. {
  189953. if (pOutputBuffer == 0)
  189954. return true;
  189955. DWORD playCursor, writeCursor;
  189956. for (;;)
  189957. {
  189958. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  189959. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189960. {
  189961. pOutputBuffer->Restore();
  189962. continue;
  189963. }
  189964. if (hr == S_OK)
  189965. break;
  189966. logError (hr);
  189967. jassertfalse
  189968. return true;
  189969. }
  189970. int playWriteGap = writeCursor - playCursor;
  189971. if (playWriteGap < 0)
  189972. playWriteGap += totalBytesPerBuffer;
  189973. int bytesEmpty = playCursor - writeOffset;
  189974. if (bytesEmpty < 0)
  189975. bytesEmpty += totalBytesPerBuffer;
  189976. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  189977. {
  189978. writeOffset = writeCursor;
  189979. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  189980. }
  189981. if (bytesEmpty >= bytesPerBuffer)
  189982. {
  189983. LPBYTE lpbuf1 = 0;
  189984. LPBYTE lpbuf2 = 0;
  189985. DWORD dwSize1 = 0;
  189986. DWORD dwSize2 = 0;
  189987. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  189988. bytesPerBuffer,
  189989. (void**) &lpbuf1, &dwSize1,
  189990. (void**) &lpbuf2, &dwSize2, 0);
  189991. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189992. {
  189993. pOutputBuffer->Restore();
  189994. hr = pOutputBuffer->Lock (writeOffset,
  189995. bytesPerBuffer,
  189996. (void**) &lpbuf1, &dwSize1,
  189997. (void**) &lpbuf2, &dwSize2, 0);
  189998. }
  189999. if (hr == S_OK)
  190000. {
  190001. if (bitDepth == 16)
  190002. {
  190003. const float gainL = 32767.0f;
  190004. const float gainR = 32767.0f;
  190005. int* dest = (int*)lpbuf1;
  190006. const float* left = leftBuffer;
  190007. const float* right = rightBuffer;
  190008. int samples1 = dwSize1 >> 2;
  190009. int samples2 = dwSize2 >> 2;
  190010. if (left == 0)
  190011. {
  190012. while (--samples1 >= 0)
  190013. {
  190014. int r = roundToInt (gainR * *right++);
  190015. if (r < -32768)
  190016. r = -32768;
  190017. else if (r > 32767)
  190018. r = 32767;
  190019. *dest++ = (r << 16);
  190020. }
  190021. dest = (int*)lpbuf2;
  190022. while (--samples2 >= 0)
  190023. {
  190024. int r = roundToInt (gainR * *right++);
  190025. if (r < -32768)
  190026. r = -32768;
  190027. else if (r > 32767)
  190028. r = 32767;
  190029. *dest++ = (r << 16);
  190030. }
  190031. }
  190032. else if (right == 0)
  190033. {
  190034. while (--samples1 >= 0)
  190035. {
  190036. int l = roundToInt (gainL * *left++);
  190037. if (l < -32768)
  190038. l = -32768;
  190039. else if (l > 32767)
  190040. l = 32767;
  190041. l &= 0xffff;
  190042. *dest++ = l;
  190043. }
  190044. dest = (int*)lpbuf2;
  190045. while (--samples2 >= 0)
  190046. {
  190047. int l = roundToInt (gainL * *left++);
  190048. if (l < -32768)
  190049. l = -32768;
  190050. else if (l > 32767)
  190051. l = 32767;
  190052. l &= 0xffff;
  190053. *dest++ = l;
  190054. }
  190055. }
  190056. else
  190057. {
  190058. while (--samples1 >= 0)
  190059. {
  190060. int l = roundToInt (gainL * *left++);
  190061. if (l < -32768)
  190062. l = -32768;
  190063. else if (l > 32767)
  190064. l = 32767;
  190065. l &= 0xffff;
  190066. int r = roundToInt (gainR * *right++);
  190067. if (r < -32768)
  190068. r = -32768;
  190069. else if (r > 32767)
  190070. r = 32767;
  190071. *dest++ = (r << 16) | l;
  190072. }
  190073. dest = (int*)lpbuf2;
  190074. while (--samples2 >= 0)
  190075. {
  190076. int l = roundToInt (gainL * *left++);
  190077. if (l < -32768)
  190078. l = -32768;
  190079. else if (l > 32767)
  190080. l = 32767;
  190081. l &= 0xffff;
  190082. int r = roundToInt (gainR * *right++);
  190083. if (r < -32768)
  190084. r = -32768;
  190085. else if (r > 32767)
  190086. r = 32767;
  190087. *dest++ = (r << 16) | l;
  190088. }
  190089. }
  190090. }
  190091. else
  190092. {
  190093. jassertfalse
  190094. }
  190095. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190096. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190097. }
  190098. else
  190099. {
  190100. jassertfalse
  190101. logError (hr);
  190102. }
  190103. bytesEmpty -= bytesPerBuffer;
  190104. return true;
  190105. }
  190106. else
  190107. {
  190108. return false;
  190109. }
  190110. }
  190111. };
  190112. struct DSoundInternalInChannel
  190113. {
  190114. String name;
  190115. LPGUID guid;
  190116. int sampleRate, bufferSizeSamples;
  190117. float* leftBuffer;
  190118. float* rightBuffer;
  190119. IDirectSound* pDirectSound;
  190120. IDirectSoundCapture* pDirectSoundCapture;
  190121. IDirectSoundCaptureBuffer* pInputBuffer;
  190122. public:
  190123. unsigned int readOffset;
  190124. int bytesPerBuffer, totalBytesPerBuffer;
  190125. int bitDepth;
  190126. bool doneFlag;
  190127. DSoundInternalInChannel (const String& name_,
  190128. LPGUID guid_,
  190129. int rate,
  190130. int bufferSize,
  190131. float* left,
  190132. float* right)
  190133. : name (name_),
  190134. guid (guid_),
  190135. sampleRate (rate),
  190136. bufferSizeSamples (bufferSize),
  190137. leftBuffer (left),
  190138. rightBuffer (right),
  190139. pDirectSound (0),
  190140. pDirectSoundCapture (0),
  190141. pInputBuffer (0),
  190142. bitDepth (16)
  190143. {
  190144. }
  190145. ~DSoundInternalInChannel()
  190146. {
  190147. close();
  190148. }
  190149. void close()
  190150. {
  190151. HRESULT hr;
  190152. if (pInputBuffer != 0)
  190153. {
  190154. JUCE_TRY
  190155. {
  190156. log ("closing dsound in: " + name);
  190157. hr = pInputBuffer->Stop();
  190158. logError (hr);
  190159. }
  190160. CATCH
  190161. JUCE_TRY
  190162. {
  190163. hr = pInputBuffer->Release();
  190164. logError (hr);
  190165. }
  190166. CATCH
  190167. pInputBuffer = 0;
  190168. }
  190169. if (pDirectSoundCapture != 0)
  190170. {
  190171. JUCE_TRY
  190172. {
  190173. hr = pDirectSoundCapture->Release();
  190174. logError (hr);
  190175. }
  190176. CATCH
  190177. pDirectSoundCapture = 0;
  190178. }
  190179. if (pDirectSound != 0)
  190180. {
  190181. JUCE_TRY
  190182. {
  190183. hr = pDirectSound->Release();
  190184. logError (hr);
  190185. }
  190186. CATCH
  190187. pDirectSound = 0;
  190188. }
  190189. }
  190190. const String open()
  190191. {
  190192. log ("opening dsound in device: " + name
  190193. + " rate=" + String (sampleRate) + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  190194. pDirectSound = 0;
  190195. pDirectSoundCapture = 0;
  190196. pInputBuffer = 0;
  190197. readOffset = 0;
  190198. totalBytesPerBuffer = 0;
  190199. String error;
  190200. HRESULT hr = E_NOINTERFACE;
  190201. if (dsDirectSoundCaptureCreate != 0)
  190202. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190203. logError (hr);
  190204. if (hr == S_OK)
  190205. {
  190206. const int numChannels = 2;
  190207. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190208. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190209. WAVEFORMATEX wfFormat;
  190210. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190211. wfFormat.nChannels = (unsigned short)numChannels;
  190212. wfFormat.nSamplesPerSec = sampleRate;
  190213. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190214. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190215. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190216. wfFormat.cbSize = 0;
  190217. DSCBUFFERDESC captureDesc;
  190218. zerostruct (captureDesc);
  190219. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190220. captureDesc.dwFlags = 0;
  190221. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190222. captureDesc.lpwfxFormat = &wfFormat;
  190223. log ("opening dsound in step 2");
  190224. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190225. logError (hr);
  190226. if (hr == S_OK)
  190227. {
  190228. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190229. logError (hr);
  190230. if (hr == S_OK)
  190231. return String::empty;
  190232. }
  190233. }
  190234. error = getDSErrorMessage (hr);
  190235. close();
  190236. return error;
  190237. }
  190238. void synchronisePosition()
  190239. {
  190240. if (pInputBuffer != 0)
  190241. {
  190242. DWORD capturePos;
  190243. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190244. }
  190245. }
  190246. bool service()
  190247. {
  190248. if (pInputBuffer == 0)
  190249. return true;
  190250. DWORD capturePos, readPos;
  190251. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190252. logError (hr);
  190253. if (hr != S_OK)
  190254. return true;
  190255. int bytesFilled = readPos - readOffset;
  190256. if (bytesFilled < 0)
  190257. bytesFilled += totalBytesPerBuffer;
  190258. if (bytesFilled >= bytesPerBuffer)
  190259. {
  190260. LPBYTE lpbuf1 = 0;
  190261. LPBYTE lpbuf2 = 0;
  190262. DWORD dwsize1 = 0;
  190263. DWORD dwsize2 = 0;
  190264. HRESULT hr = pInputBuffer->Lock (readOffset,
  190265. bytesPerBuffer,
  190266. (void**) &lpbuf1, &dwsize1,
  190267. (void**) &lpbuf2, &dwsize2, 0);
  190268. if (hr == S_OK)
  190269. {
  190270. if (bitDepth == 16)
  190271. {
  190272. const float g = 1.0f / 32768.0f;
  190273. float* destL = leftBuffer;
  190274. float* destR = rightBuffer;
  190275. int samples1 = dwsize1 >> 2;
  190276. int samples2 = dwsize2 >> 2;
  190277. const short* src = (const short*)lpbuf1;
  190278. if (destL == 0)
  190279. {
  190280. while (--samples1 >= 0)
  190281. {
  190282. ++src;
  190283. *destR++ = *src++ * g;
  190284. }
  190285. src = (const short*)lpbuf2;
  190286. while (--samples2 >= 0)
  190287. {
  190288. ++src;
  190289. *destR++ = *src++ * g;
  190290. }
  190291. }
  190292. else if (destR == 0)
  190293. {
  190294. while (--samples1 >= 0)
  190295. {
  190296. *destL++ = *src++ * g;
  190297. ++src;
  190298. }
  190299. src = (const short*)lpbuf2;
  190300. while (--samples2 >= 0)
  190301. {
  190302. *destL++ = *src++ * g;
  190303. ++src;
  190304. }
  190305. }
  190306. else
  190307. {
  190308. while (--samples1 >= 0)
  190309. {
  190310. *destL++ = *src++ * g;
  190311. *destR++ = *src++ * g;
  190312. }
  190313. src = (const short*)lpbuf2;
  190314. while (--samples2 >= 0)
  190315. {
  190316. *destL++ = *src++ * g;
  190317. *destR++ = *src++ * g;
  190318. }
  190319. }
  190320. }
  190321. else
  190322. {
  190323. jassertfalse
  190324. }
  190325. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190326. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190327. }
  190328. else
  190329. {
  190330. logError (hr);
  190331. jassertfalse
  190332. }
  190333. bytesFilled -= bytesPerBuffer;
  190334. return true;
  190335. }
  190336. else
  190337. {
  190338. return false;
  190339. }
  190340. }
  190341. };
  190342. class DSoundAudioIODevice : public AudioIODevice,
  190343. public Thread
  190344. {
  190345. public:
  190346. DSoundAudioIODevice (const String& deviceName,
  190347. const int outputDeviceIndex_,
  190348. const int inputDeviceIndex_)
  190349. : AudioIODevice (deviceName, "DirectSound"),
  190350. Thread ("Juce DSound"),
  190351. isOpen_ (false),
  190352. isStarted (false),
  190353. outputDeviceIndex (outputDeviceIndex_),
  190354. inputDeviceIndex (inputDeviceIndex_),
  190355. numInputBuffers (0),
  190356. numOutputBuffers (0),
  190357. totalSamplesOut (0),
  190358. sampleRate (0.0),
  190359. inputBuffers (0),
  190360. outputBuffers (0),
  190361. callback (0),
  190362. bufferSizeSamples (0)
  190363. {
  190364. if (outputDeviceIndex_ >= 0)
  190365. {
  190366. outChannels.add (TRANS("Left"));
  190367. outChannels.add (TRANS("Right"));
  190368. }
  190369. if (inputDeviceIndex_ >= 0)
  190370. {
  190371. inChannels.add (TRANS("Left"));
  190372. inChannels.add (TRANS("Right"));
  190373. }
  190374. }
  190375. ~DSoundAudioIODevice()
  190376. {
  190377. close();
  190378. }
  190379. const StringArray getOutputChannelNames()
  190380. {
  190381. return outChannels;
  190382. }
  190383. const StringArray getInputChannelNames()
  190384. {
  190385. return inChannels;
  190386. }
  190387. int getNumSampleRates()
  190388. {
  190389. return 4;
  190390. }
  190391. double getSampleRate (int index)
  190392. {
  190393. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190394. return samps [jlimit (0, 3, index)];
  190395. }
  190396. int getNumBufferSizesAvailable()
  190397. {
  190398. return 50;
  190399. }
  190400. int getBufferSizeSamples (int index)
  190401. {
  190402. int n = 64;
  190403. for (int i = 0; i < index; ++i)
  190404. n += (n < 512) ? 32
  190405. : ((n < 1024) ? 64
  190406. : ((n < 2048) ? 128 : 256));
  190407. return n;
  190408. }
  190409. int getDefaultBufferSize()
  190410. {
  190411. return 2560;
  190412. }
  190413. const String open (const BigInteger& inputChannels,
  190414. const BigInteger& outputChannels,
  190415. double sampleRate,
  190416. int bufferSizeSamples)
  190417. {
  190418. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190419. isOpen_ = lastError.isEmpty();
  190420. return lastError;
  190421. }
  190422. void close()
  190423. {
  190424. stop();
  190425. if (isOpen_)
  190426. {
  190427. closeDevice();
  190428. isOpen_ = false;
  190429. }
  190430. }
  190431. bool isOpen()
  190432. {
  190433. return isOpen_ && isThreadRunning();
  190434. }
  190435. int getCurrentBufferSizeSamples()
  190436. {
  190437. return bufferSizeSamples;
  190438. }
  190439. double getCurrentSampleRate()
  190440. {
  190441. return sampleRate;
  190442. }
  190443. int getCurrentBitDepth()
  190444. {
  190445. int i, bits = 256;
  190446. for (i = inChans.size(); --i >= 0;)
  190447. bits = jmin (bits, inChans[i]->bitDepth);
  190448. for (i = outChans.size(); --i >= 0;)
  190449. bits = jmin (bits, outChans[i]->bitDepth);
  190450. if (bits > 32)
  190451. bits = 16;
  190452. return bits;
  190453. }
  190454. const BigInteger getActiveOutputChannels() const
  190455. {
  190456. return enabledOutputs;
  190457. }
  190458. const BigInteger getActiveInputChannels() const
  190459. {
  190460. return enabledInputs;
  190461. }
  190462. int getOutputLatencyInSamples()
  190463. {
  190464. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190465. }
  190466. int getInputLatencyInSamples()
  190467. {
  190468. return getOutputLatencyInSamples();
  190469. }
  190470. void start (AudioIODeviceCallback* call)
  190471. {
  190472. if (isOpen_ && call != 0 && ! isStarted)
  190473. {
  190474. if (! isThreadRunning())
  190475. {
  190476. // something gone wrong and the thread's stopped..
  190477. isOpen_ = false;
  190478. return;
  190479. }
  190480. call->audioDeviceAboutToStart (this);
  190481. const ScopedLock sl (startStopLock);
  190482. callback = call;
  190483. isStarted = true;
  190484. }
  190485. }
  190486. void stop()
  190487. {
  190488. if (isStarted)
  190489. {
  190490. AudioIODeviceCallback* const callbackLocal = callback;
  190491. {
  190492. const ScopedLock sl (startStopLock);
  190493. isStarted = false;
  190494. }
  190495. if (callbackLocal != 0)
  190496. callbackLocal->audioDeviceStopped();
  190497. }
  190498. }
  190499. bool isPlaying()
  190500. {
  190501. return isStarted && isOpen_ && isThreadRunning();
  190502. }
  190503. const String getLastError()
  190504. {
  190505. return lastError;
  190506. }
  190507. juce_UseDebuggingNewOperator
  190508. StringArray inChannels, outChannels;
  190509. int outputDeviceIndex, inputDeviceIndex;
  190510. private:
  190511. bool isOpen_;
  190512. bool isStarted;
  190513. String lastError;
  190514. OwnedArray <DSoundInternalInChannel> inChans;
  190515. OwnedArray <DSoundInternalOutChannel> outChans;
  190516. WaitableEvent startEvent;
  190517. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190518. int volatile totalSamplesOut;
  190519. int64 volatile lastBlockTime;
  190520. double sampleRate;
  190521. BigInteger enabledInputs, enabledOutputs;
  190522. HeapBlock <float*> inputBuffers, outputBuffers;
  190523. AudioIODeviceCallback* callback;
  190524. CriticalSection startStopLock;
  190525. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190526. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190527. const String openDevice (const BigInteger& inputChannels,
  190528. const BigInteger& outputChannels,
  190529. double sampleRate_,
  190530. int bufferSizeSamples_);
  190531. void closeDevice()
  190532. {
  190533. isStarted = false;
  190534. stopThread (5000);
  190535. inChans.clear();
  190536. outChans.clear();
  190537. int i;
  190538. for (i = 0; i < numInputBuffers; ++i)
  190539. juce_free (inputBuffers[i]);
  190540. inputBuffers.free();
  190541. numInputBuffers = 0;
  190542. for (i = 0; i < numOutputBuffers; ++i)
  190543. juce_free (outputBuffers[i]);
  190544. outputBuffers.free();
  190545. numOutputBuffers = 0;
  190546. }
  190547. void resync()
  190548. {
  190549. if (! threadShouldExit())
  190550. {
  190551. sleep (5);
  190552. int i;
  190553. for (i = 0; i < outChans.size(); ++i)
  190554. outChans.getUnchecked(i)->synchronisePosition();
  190555. for (i = 0; i < inChans.size(); ++i)
  190556. inChans.getUnchecked(i)->synchronisePosition();
  190557. }
  190558. }
  190559. public:
  190560. void run()
  190561. {
  190562. while (! threadShouldExit())
  190563. {
  190564. if (wait (100))
  190565. break;
  190566. }
  190567. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190568. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190569. while (! threadShouldExit())
  190570. {
  190571. int numToDo = 0;
  190572. uint32 startTime = Time::getMillisecondCounter();
  190573. int i;
  190574. for (i = inChans.size(); --i >= 0;)
  190575. {
  190576. inChans.getUnchecked(i)->doneFlag = false;
  190577. ++numToDo;
  190578. }
  190579. for (i = outChans.size(); --i >= 0;)
  190580. {
  190581. outChans.getUnchecked(i)->doneFlag = false;
  190582. ++numToDo;
  190583. }
  190584. if (numToDo > 0)
  190585. {
  190586. const int maxCount = 3;
  190587. int count = maxCount;
  190588. for (;;)
  190589. {
  190590. for (i = inChans.size(); --i >= 0;)
  190591. {
  190592. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190593. if ((! in->doneFlag) && in->service())
  190594. {
  190595. in->doneFlag = true;
  190596. --numToDo;
  190597. }
  190598. }
  190599. for (i = outChans.size(); --i >= 0;)
  190600. {
  190601. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190602. if ((! out->doneFlag) && out->service())
  190603. {
  190604. out->doneFlag = true;
  190605. --numToDo;
  190606. }
  190607. }
  190608. if (numToDo <= 0)
  190609. break;
  190610. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190611. {
  190612. resync();
  190613. break;
  190614. }
  190615. if (--count <= 0)
  190616. {
  190617. Sleep (1);
  190618. count = maxCount;
  190619. }
  190620. if (threadShouldExit())
  190621. return;
  190622. }
  190623. }
  190624. else
  190625. {
  190626. sleep (1);
  190627. }
  190628. const ScopedLock sl (startStopLock);
  190629. if (isStarted)
  190630. {
  190631. JUCE_TRY
  190632. {
  190633. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190634. numInputBuffers,
  190635. outputBuffers,
  190636. numOutputBuffers,
  190637. bufferSizeSamples);
  190638. }
  190639. JUCE_CATCH_EXCEPTION
  190640. totalSamplesOut += bufferSizeSamples;
  190641. }
  190642. else
  190643. {
  190644. for (i = 0; i < numOutputBuffers; ++i)
  190645. if (outputBuffers[i] != 0)
  190646. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190647. totalSamplesOut = 0;
  190648. sleep (1);
  190649. }
  190650. }
  190651. }
  190652. };
  190653. class DSoundAudioIODeviceType : public AudioIODeviceType
  190654. {
  190655. public:
  190656. DSoundAudioIODeviceType()
  190657. : AudioIODeviceType ("DirectSound"),
  190658. hasScanned (false)
  190659. {
  190660. initialiseDSoundFunctions();
  190661. }
  190662. ~DSoundAudioIODeviceType()
  190663. {
  190664. }
  190665. void scanForDevices()
  190666. {
  190667. hasScanned = true;
  190668. outputDeviceNames.clear();
  190669. outputGuids.clear();
  190670. inputDeviceNames.clear();
  190671. inputGuids.clear();
  190672. if (dsDirectSoundEnumerateW != 0)
  190673. {
  190674. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190675. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190676. }
  190677. }
  190678. const StringArray getDeviceNames (bool wantInputNames) const
  190679. {
  190680. jassert (hasScanned); // need to call scanForDevices() before doing this
  190681. return wantInputNames ? inputDeviceNames
  190682. : outputDeviceNames;
  190683. }
  190684. int getDefaultDeviceIndex (bool /*forInput*/) const
  190685. {
  190686. jassert (hasScanned); // need to call scanForDevices() before doing this
  190687. return 0;
  190688. }
  190689. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  190690. {
  190691. jassert (hasScanned); // need to call scanForDevices() before doing this
  190692. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190693. if (d == 0)
  190694. return -1;
  190695. return asInput ? d->inputDeviceIndex
  190696. : d->outputDeviceIndex;
  190697. }
  190698. bool hasSeparateInputsAndOutputs() const { return true; }
  190699. AudioIODevice* createDevice (const String& outputDeviceName,
  190700. const String& inputDeviceName)
  190701. {
  190702. jassert (hasScanned); // need to call scanForDevices() before doing this
  190703. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190704. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190705. if (outputIndex >= 0 || inputIndex >= 0)
  190706. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190707. : inputDeviceName,
  190708. outputIndex, inputIndex);
  190709. return 0;
  190710. }
  190711. juce_UseDebuggingNewOperator
  190712. StringArray outputDeviceNames;
  190713. OwnedArray <GUID> outputGuids;
  190714. StringArray inputDeviceNames;
  190715. OwnedArray <GUID> inputGuids;
  190716. private:
  190717. bool hasScanned;
  190718. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190719. {
  190720. desc = desc.trim();
  190721. if (desc.isNotEmpty())
  190722. {
  190723. const String origDesc (desc);
  190724. int n = 2;
  190725. while (outputDeviceNames.contains (desc))
  190726. desc = origDesc + " (" + String (n++) + ")";
  190727. outputDeviceNames.add (desc);
  190728. if (lpGUID != 0)
  190729. outputGuids.add (new GUID (*lpGUID));
  190730. else
  190731. outputGuids.add (0);
  190732. }
  190733. return TRUE;
  190734. }
  190735. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190736. {
  190737. return ((DSoundAudioIODeviceType*) object)
  190738. ->outputEnumProc (lpGUID, String (description));
  190739. }
  190740. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190741. {
  190742. return ((DSoundAudioIODeviceType*) object)
  190743. ->outputEnumProc (lpGUID, String (description));
  190744. }
  190745. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190746. {
  190747. desc = desc.trim();
  190748. if (desc.isNotEmpty())
  190749. {
  190750. const String origDesc (desc);
  190751. int n = 2;
  190752. while (inputDeviceNames.contains (desc))
  190753. desc = origDesc + " (" + String (n++) + ")";
  190754. inputDeviceNames.add (desc);
  190755. if (lpGUID != 0)
  190756. inputGuids.add (new GUID (*lpGUID));
  190757. else
  190758. inputGuids.add (0);
  190759. }
  190760. return TRUE;
  190761. }
  190762. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190763. {
  190764. return ((DSoundAudioIODeviceType*) object)
  190765. ->inputEnumProc (lpGUID, String (description));
  190766. }
  190767. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190768. {
  190769. return ((DSoundAudioIODeviceType*) object)
  190770. ->inputEnumProc (lpGUID, String (description));
  190771. }
  190772. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190773. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190774. };
  190775. const String DSoundAudioIODevice::openDevice (const BigInteger& inputChannels,
  190776. const BigInteger& outputChannels,
  190777. double sampleRate_,
  190778. int bufferSizeSamples_)
  190779. {
  190780. closeDevice();
  190781. totalSamplesOut = 0;
  190782. sampleRate = sampleRate_;
  190783. if (bufferSizeSamples_ <= 0)
  190784. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190785. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190786. DSoundAudioIODeviceType dlh;
  190787. dlh.scanForDevices();
  190788. enabledInputs = inputChannels;
  190789. enabledInputs.setRange (inChannels.size(),
  190790. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190791. false);
  190792. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190793. inputBuffers.calloc (numInputBuffers + 2);
  190794. int i, numIns = 0;
  190795. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190796. {
  190797. float* left = 0;
  190798. float* right = 0;
  190799. if (enabledInputs[i])
  190800. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190801. if (enabledInputs[i + 1])
  190802. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190803. if (left != 0 || right != 0)
  190804. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190805. dlh.inputGuids [inputDeviceIndex],
  190806. (int) sampleRate, bufferSizeSamples,
  190807. left, right));
  190808. }
  190809. enabledOutputs = outputChannels;
  190810. enabledOutputs.setRange (outChannels.size(),
  190811. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190812. false);
  190813. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190814. outputBuffers.calloc (numOutputBuffers + 2);
  190815. int numOuts = 0;
  190816. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190817. {
  190818. float* left = 0;
  190819. float* right = 0;
  190820. if (enabledOutputs[i])
  190821. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190822. if (enabledOutputs[i + 1])
  190823. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190824. if (left != 0 || right != 0)
  190825. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190826. dlh.outputGuids [outputDeviceIndex],
  190827. (int) sampleRate, bufferSizeSamples,
  190828. left, right));
  190829. }
  190830. String error;
  190831. // boost our priority while opening the devices to try to get better sync between them
  190832. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190833. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190834. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  190835. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  190836. for (i = 0; i < outChans.size(); ++i)
  190837. {
  190838. error = outChans[i]->open();
  190839. if (error.isNotEmpty())
  190840. {
  190841. error = "Error opening " + dlh.outputDeviceNames[i] + ": \"" + error + "\"";
  190842. break;
  190843. }
  190844. }
  190845. if (error.isEmpty())
  190846. {
  190847. for (i = 0; i < inChans.size(); ++i)
  190848. {
  190849. error = inChans[i]->open();
  190850. if (error.isNotEmpty())
  190851. {
  190852. error = "Error opening " + dlh.inputDeviceNames[i] + ": \"" + error + "\"";
  190853. break;
  190854. }
  190855. }
  190856. }
  190857. if (error.isEmpty())
  190858. {
  190859. totalSamplesOut = 0;
  190860. for (i = 0; i < outChans.size(); ++i)
  190861. outChans.getUnchecked(i)->synchronisePosition();
  190862. for (i = 0; i < inChans.size(); ++i)
  190863. inChans.getUnchecked(i)->synchronisePosition();
  190864. startThread (9);
  190865. sleep (10);
  190866. notify();
  190867. }
  190868. else
  190869. {
  190870. log (error);
  190871. }
  190872. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  190873. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  190874. return error;
  190875. }
  190876. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  190877. {
  190878. return new DSoundAudioIODeviceType();
  190879. }
  190880. #undef log
  190881. #endif
  190882. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  190883. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  190884. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190885. // compiled on its own).
  190886. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  190887. #if 1
  190888. const String getAudioErrorDesc (HRESULT hr)
  190889. {
  190890. const char* e = 0;
  190891. switch (hr)
  190892. {
  190893. case E_POINTER: e = "E_POINTER"; break;
  190894. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  190895. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  190896. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  190897. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  190898. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  190899. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  190900. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  190901. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  190902. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  190903. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  190904. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  190905. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  190906. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  190907. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  190908. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  190909. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  190910. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  190911. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  190912. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  190913. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  190914. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  190915. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  190916. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  190917. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  190918. default: return String::toHexString ((int) hr);
  190919. }
  190920. return e;
  190921. }
  190922. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  190923. #define OK(a) wasapi_checkResult(a)
  190924. static bool wasapi_checkResult (HRESULT hr)
  190925. {
  190926. logFailure (hr);
  190927. return SUCCEEDED (hr);
  190928. }
  190929. #else
  190930. #define logFailure(hr) {}
  190931. #define OK(a) SUCCEEDED(a)
  190932. #endif
  190933. static const String wasapi_getDeviceID (IMMDevice* const device)
  190934. {
  190935. String s;
  190936. WCHAR* deviceId = 0;
  190937. if (OK (device->GetId (&deviceId)))
  190938. {
  190939. s = String (deviceId);
  190940. CoTaskMemFree (deviceId);
  190941. }
  190942. return s;
  190943. }
  190944. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  190945. {
  190946. EDataFlow flow = eRender;
  190947. ComSmartPtr <IMMEndpoint> endPoint;
  190948. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  190949. (void) OK (endPoint->GetDataFlow (&flow));
  190950. return flow;
  190951. }
  190952. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  190953. {
  190954. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  190955. }
  190956. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  190957. {
  190958. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  190959. : sizeof (WAVEFORMATEX));
  190960. }
  190961. class WASAPIDeviceBase
  190962. {
  190963. public:
  190964. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  190965. : device (device_),
  190966. sampleRate (0),
  190967. numChannels (0),
  190968. actualNumChannels (0),
  190969. defaultSampleRate (0),
  190970. minBufferSize (0),
  190971. defaultBufferSize (0),
  190972. latencySamples (0),
  190973. useExclusiveMode (useExclusiveMode_)
  190974. {
  190975. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  190976. ComSmartPtr <IAudioClient> tempClient (createClient());
  190977. if (tempClient == 0)
  190978. return;
  190979. REFERENCE_TIME defaultPeriod, minPeriod;
  190980. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  190981. return;
  190982. WAVEFORMATEX* mixFormat = 0;
  190983. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  190984. return;
  190985. WAVEFORMATEXTENSIBLE format;
  190986. wasapi_copyWavFormat (format, mixFormat);
  190987. CoTaskMemFree (mixFormat);
  190988. actualNumChannels = numChannels = format.Format.nChannels;
  190989. defaultSampleRate = format.Format.nSamplesPerSec;
  190990. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  190991. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  190992. FloatElementComparator<double> comparator;
  190993. rates.addSorted (comparator, defaultSampleRate);
  190994. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190995. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  190996. {
  190997. if (ratesToTest[i] == defaultSampleRate)
  190998. continue;
  190999. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191000. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191001. (WAVEFORMATEX*) &format, 0)))
  191002. if (! rates.contains (ratesToTest[i]))
  191003. rates.addSorted (comparator, ratesToTest[i]);
  191004. }
  191005. }
  191006. ~WASAPIDeviceBase()
  191007. {
  191008. device = 0;
  191009. CloseHandle (clientEvent);
  191010. }
  191011. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191012. bool openClient (const double newSampleRate, const BigInteger& newChannels)
  191013. {
  191014. sampleRate = newSampleRate;
  191015. channels = newChannels;
  191016. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191017. numChannels = channels.getHighestBit() + 1;
  191018. if (numChannels == 0)
  191019. return true;
  191020. client = createClient();
  191021. if (client != 0
  191022. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191023. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191024. {
  191025. channelMaps.clear();
  191026. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191027. if (channels[i])
  191028. channelMaps.add (i);
  191029. REFERENCE_TIME latency;
  191030. if (OK (client->GetStreamLatency (&latency)))
  191031. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191032. (void) OK (client->GetBufferSize (&actualBufferSize));
  191033. return OK (client->SetEventHandle (clientEvent));
  191034. }
  191035. return false;
  191036. }
  191037. void closeClient()
  191038. {
  191039. if (client != 0)
  191040. client->Stop();
  191041. client = 0;
  191042. ResetEvent (clientEvent);
  191043. }
  191044. ComSmartPtr <IMMDevice> device;
  191045. ComSmartPtr <IAudioClient> client;
  191046. double sampleRate, defaultSampleRate;
  191047. int numChannels, actualNumChannels;
  191048. int minBufferSize, defaultBufferSize, latencySamples;
  191049. const bool useExclusiveMode;
  191050. Array <double> rates;
  191051. HANDLE clientEvent;
  191052. BigInteger channels;
  191053. AudioDataConverters::DataFormat dataFormat;
  191054. Array <int> channelMaps;
  191055. UINT32 actualBufferSize;
  191056. int bytesPerSample;
  191057. private:
  191058. const ComSmartPtr <IAudioClient> createClient()
  191059. {
  191060. ComSmartPtr <IAudioClient> client;
  191061. if (device != 0)
  191062. {
  191063. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191064. logFailure (hr);
  191065. }
  191066. return client;
  191067. }
  191068. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191069. {
  191070. WAVEFORMATEXTENSIBLE format;
  191071. zerostruct (format);
  191072. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191073. {
  191074. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191075. }
  191076. else
  191077. {
  191078. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191079. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191080. }
  191081. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191082. format.Format.nChannels = (WORD) numChannels;
  191083. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191084. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191085. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191086. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191087. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191088. switch (numChannels)
  191089. {
  191090. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191091. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191092. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191093. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191094. 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;
  191095. default: break;
  191096. }
  191097. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191098. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191099. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191100. logFailure (hr);
  191101. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191102. {
  191103. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191104. hr = S_OK;
  191105. }
  191106. CoTaskMemFree (nearestFormat);
  191107. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191108. if (useExclusiveMode)
  191109. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191110. GUID session;
  191111. if (hr == S_OK
  191112. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191113. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191114. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191115. {
  191116. actualNumChannels = format.Format.nChannels;
  191117. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191118. bytesPerSample = format.Format.wBitsPerSample / 8;
  191119. dataFormat = isFloat ? AudioDataConverters::float32LE
  191120. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191121. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191122. : AudioDataConverters::int16LE)));
  191123. return true;
  191124. }
  191125. return false;
  191126. }
  191127. };
  191128. class WASAPIInputDevice : public WASAPIDeviceBase
  191129. {
  191130. public:
  191131. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191132. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191133. reservoir (1, 1)
  191134. {
  191135. }
  191136. ~WASAPIInputDevice()
  191137. {
  191138. close();
  191139. }
  191140. bool open (const double newSampleRate, const BigInteger& newChannels)
  191141. {
  191142. reservoirSize = 0;
  191143. reservoirCapacity = 16384;
  191144. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191145. return openClient (newSampleRate, newChannels)
  191146. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191147. }
  191148. void close()
  191149. {
  191150. closeClient();
  191151. captureClient = 0;
  191152. reservoir.setSize (0);
  191153. }
  191154. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191155. {
  191156. if (numChannels <= 0)
  191157. return;
  191158. int offset = 0;
  191159. while (bufferSize > 0)
  191160. {
  191161. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191162. {
  191163. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191164. for (int i = 0; i < numDestBuffers; ++i)
  191165. {
  191166. float* const dest = destBuffers[i] + offset;
  191167. const int srcChan = channelMaps.getUnchecked(i);
  191168. switch (dataFormat)
  191169. {
  191170. case AudioDataConverters::float32LE:
  191171. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191172. break;
  191173. case AudioDataConverters::int32LE:
  191174. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191175. break;
  191176. case AudioDataConverters::int24LE:
  191177. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191178. break;
  191179. case AudioDataConverters::int16LE:
  191180. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191181. break;
  191182. default: jassertfalse; break;
  191183. }
  191184. }
  191185. bufferSize -= samplesToDo;
  191186. offset += samplesToDo;
  191187. reservoirSize -= samplesToDo;
  191188. }
  191189. else
  191190. {
  191191. UINT32 packetLength = 0;
  191192. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191193. break;
  191194. if (packetLength == 0)
  191195. {
  191196. if (thread.threadShouldExit())
  191197. break;
  191198. Thread::sleep (1);
  191199. continue;
  191200. }
  191201. uint8* inputData = 0;
  191202. UINT32 numSamplesAvailable;
  191203. DWORD flags;
  191204. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191205. {
  191206. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191207. for (int i = 0; i < numDestBuffers; ++i)
  191208. {
  191209. float* const dest = destBuffers[i] + offset;
  191210. const int srcChan = channelMaps.getUnchecked(i);
  191211. switch (dataFormat)
  191212. {
  191213. case AudioDataConverters::float32LE:
  191214. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191215. break;
  191216. case AudioDataConverters::int32LE:
  191217. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191218. break;
  191219. case AudioDataConverters::int24LE:
  191220. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191221. break;
  191222. case AudioDataConverters::int16LE:
  191223. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191224. break;
  191225. default: jassertfalse; break;
  191226. }
  191227. }
  191228. bufferSize -= samplesToDo;
  191229. offset += samplesToDo;
  191230. if (samplesToDo < (int) numSamplesAvailable)
  191231. {
  191232. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191233. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191234. bytesPerSample * actualNumChannels * reservoirSize);
  191235. }
  191236. captureClient->ReleaseBuffer (numSamplesAvailable);
  191237. }
  191238. }
  191239. }
  191240. }
  191241. ComSmartPtr <IAudioCaptureClient> captureClient;
  191242. MemoryBlock reservoir;
  191243. int reservoirSize, reservoirCapacity;
  191244. };
  191245. class WASAPIOutputDevice : public WASAPIDeviceBase
  191246. {
  191247. public:
  191248. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191249. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191250. {
  191251. }
  191252. ~WASAPIOutputDevice()
  191253. {
  191254. close();
  191255. }
  191256. bool open (const double newSampleRate, const BigInteger& newChannels)
  191257. {
  191258. return openClient (newSampleRate, newChannels)
  191259. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191260. }
  191261. void close()
  191262. {
  191263. closeClient();
  191264. renderClient = 0;
  191265. }
  191266. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191267. {
  191268. if (numChannels <= 0)
  191269. return;
  191270. int offset = 0;
  191271. while (bufferSize > 0)
  191272. {
  191273. UINT32 padding = 0;
  191274. if (! OK (client->GetCurrentPadding (&padding)))
  191275. return;
  191276. int samplesToDo = useExclusiveMode ? bufferSize
  191277. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191278. if (samplesToDo <= 0)
  191279. {
  191280. if (thread.threadShouldExit())
  191281. break;
  191282. Thread::sleep (0);
  191283. continue;
  191284. }
  191285. uint8* outputData = 0;
  191286. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191287. {
  191288. for (int i = 0; i < numSrcBuffers; ++i)
  191289. {
  191290. const float* const source = srcBuffers[i] + offset;
  191291. const int destChan = channelMaps.getUnchecked(i);
  191292. switch (dataFormat)
  191293. {
  191294. case AudioDataConverters::float32LE:
  191295. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191296. break;
  191297. case AudioDataConverters::int32LE:
  191298. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191299. break;
  191300. case AudioDataConverters::int24LE:
  191301. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191302. break;
  191303. case AudioDataConverters::int16LE:
  191304. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191305. break;
  191306. default: jassertfalse; break;
  191307. }
  191308. }
  191309. renderClient->ReleaseBuffer (samplesToDo, 0);
  191310. offset += samplesToDo;
  191311. bufferSize -= samplesToDo;
  191312. }
  191313. }
  191314. }
  191315. ComSmartPtr <IAudioRenderClient> renderClient;
  191316. };
  191317. class WASAPIAudioIODevice : public AudioIODevice,
  191318. public Thread
  191319. {
  191320. public:
  191321. WASAPIAudioIODevice (const String& deviceName,
  191322. const String& outputDeviceId_,
  191323. const String& inputDeviceId_,
  191324. const bool useExclusiveMode_)
  191325. : AudioIODevice (deviceName, "Windows Audio"),
  191326. Thread ("Juce WASAPI"),
  191327. isOpen_ (false),
  191328. isStarted (false),
  191329. outputDevice (0),
  191330. outputDeviceId (outputDeviceId_),
  191331. inputDevice (0),
  191332. inputDeviceId (inputDeviceId_),
  191333. useExclusiveMode (useExclusiveMode_),
  191334. currentBufferSizeSamples (0),
  191335. currentSampleRate (0),
  191336. callback (0)
  191337. {
  191338. }
  191339. ~WASAPIAudioIODevice()
  191340. {
  191341. close();
  191342. deleteAndZero (inputDevice);
  191343. deleteAndZero (outputDevice);
  191344. }
  191345. bool initialise()
  191346. {
  191347. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191348. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191349. latencyIn = latencyOut = 0;
  191350. Array <double> ratesIn, ratesOut;
  191351. if (createDevices())
  191352. {
  191353. jassert (inputDevice != 0 || outputDevice != 0);
  191354. if (inputDevice != 0 && outputDevice != 0)
  191355. {
  191356. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191357. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191358. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191359. sampleRates = inputDevice->rates;
  191360. sampleRates.removeValuesNotIn (outputDevice->rates);
  191361. }
  191362. else
  191363. {
  191364. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191365. defaultSampleRate = d->defaultSampleRate;
  191366. minBufferSize = d->minBufferSize;
  191367. defaultBufferSize = d->defaultBufferSize;
  191368. sampleRates = d->rates;
  191369. }
  191370. IntegerElementComparator<int> comparator;
  191371. bufferSizes.addSorted (comparator, defaultBufferSize);
  191372. if (minBufferSize != defaultBufferSize)
  191373. bufferSizes.addSorted (comparator, minBufferSize);
  191374. int n = 64;
  191375. for (int i = 0; i < 40; ++i)
  191376. {
  191377. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191378. bufferSizes.addSorted (comparator, n);
  191379. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191380. }
  191381. return true;
  191382. }
  191383. return false;
  191384. }
  191385. const StringArray getOutputChannelNames()
  191386. {
  191387. StringArray outChannels;
  191388. if (outputDevice != 0)
  191389. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191390. outChannels.add ("Output channel " + String (i));
  191391. return outChannels;
  191392. }
  191393. const StringArray getInputChannelNames()
  191394. {
  191395. StringArray inChannels;
  191396. if (inputDevice != 0)
  191397. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191398. inChannels.add ("Input channel " + String (i));
  191399. return inChannels;
  191400. }
  191401. int getNumSampleRates() { return sampleRates.size(); }
  191402. double getSampleRate (int index) { return sampleRates [index]; }
  191403. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191404. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191405. int getDefaultBufferSize() { return defaultBufferSize; }
  191406. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191407. double getCurrentSampleRate() { return currentSampleRate; }
  191408. int getCurrentBitDepth() { return 32; }
  191409. int getOutputLatencyInSamples() { return latencyOut; }
  191410. int getInputLatencyInSamples() { return latencyIn; }
  191411. const BigInteger getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BigInteger(); }
  191412. const BigInteger getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BigInteger(); }
  191413. const String getLastError() { return lastError; }
  191414. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  191415. double sampleRate, int bufferSizeSamples)
  191416. {
  191417. close();
  191418. lastError = String::empty;
  191419. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191420. {
  191421. lastError = "The input and output devices don't share a common sample rate!";
  191422. return lastError;
  191423. }
  191424. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191425. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191426. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191427. {
  191428. lastError = "Couldn't open the input device!";
  191429. return lastError;
  191430. }
  191431. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191432. {
  191433. close();
  191434. lastError = "Couldn't open the output device!";
  191435. return lastError;
  191436. }
  191437. if (inputDevice != 0)
  191438. ResetEvent (inputDevice->clientEvent);
  191439. if (outputDevice != 0)
  191440. ResetEvent (outputDevice->clientEvent);
  191441. startThread (8);
  191442. Thread::sleep (5);
  191443. if (inputDevice != 0 && inputDevice->client != 0)
  191444. {
  191445. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191446. HRESULT hr = inputDevice->client->Start();
  191447. logFailure (hr); //xxx handle this
  191448. }
  191449. if (outputDevice != 0 && outputDevice->client != 0)
  191450. {
  191451. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191452. HRESULT hr = outputDevice->client->Start();
  191453. logFailure (hr); //xxx handle this
  191454. }
  191455. isOpen_ = true;
  191456. return lastError;
  191457. }
  191458. void close()
  191459. {
  191460. stop();
  191461. if (inputDevice != 0)
  191462. SetEvent (inputDevice->clientEvent);
  191463. if (outputDevice != 0)
  191464. SetEvent (outputDevice->clientEvent);
  191465. stopThread (5000);
  191466. if (inputDevice != 0)
  191467. inputDevice->close();
  191468. if (outputDevice != 0)
  191469. outputDevice->close();
  191470. isOpen_ = false;
  191471. }
  191472. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191473. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191474. void start (AudioIODeviceCallback* call)
  191475. {
  191476. if (isOpen_ && call != 0 && ! isStarted)
  191477. {
  191478. if (! isThreadRunning())
  191479. {
  191480. // something's gone wrong and the thread's stopped..
  191481. isOpen_ = false;
  191482. return;
  191483. }
  191484. call->audioDeviceAboutToStart (this);
  191485. const ScopedLock sl (startStopLock);
  191486. callback = call;
  191487. isStarted = true;
  191488. }
  191489. }
  191490. void stop()
  191491. {
  191492. if (isStarted)
  191493. {
  191494. AudioIODeviceCallback* const callbackLocal = callback;
  191495. {
  191496. const ScopedLock sl (startStopLock);
  191497. isStarted = false;
  191498. }
  191499. if (callbackLocal != 0)
  191500. callbackLocal->audioDeviceStopped();
  191501. }
  191502. }
  191503. void setMMThreadPriority()
  191504. {
  191505. DynamicLibraryLoader dll ("avrt.dll");
  191506. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191507. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191508. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191509. {
  191510. DWORD dummy = 0;
  191511. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191512. if (h != 0)
  191513. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191514. }
  191515. }
  191516. void run()
  191517. {
  191518. setMMThreadPriority();
  191519. const int bufferSize = currentBufferSizeSamples;
  191520. HANDLE events[2];
  191521. int numEvents = 0;
  191522. if (inputDevice != 0)
  191523. events [numEvents++] = inputDevice->clientEvent;
  191524. if (outputDevice != 0)
  191525. events [numEvents++] = outputDevice->clientEvent;
  191526. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191527. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191528. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191529. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191530. float** const inputBuffers = ins.getArrayOfChannels();
  191531. float** const outputBuffers = outs.getArrayOfChannels();
  191532. ins.clear();
  191533. while (! threadShouldExit())
  191534. {
  191535. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191536. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191537. if (result == WAIT_TIMEOUT)
  191538. continue;
  191539. if (threadShouldExit())
  191540. break;
  191541. if (inputDevice != 0)
  191542. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191543. // Make the callback..
  191544. {
  191545. const ScopedLock sl (startStopLock);
  191546. if (isStarted)
  191547. {
  191548. JUCE_TRY
  191549. {
  191550. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191551. numInputBuffers,
  191552. outputBuffers,
  191553. numOutputBuffers,
  191554. bufferSize);
  191555. }
  191556. JUCE_CATCH_EXCEPTION
  191557. }
  191558. else
  191559. {
  191560. outs.clear();
  191561. }
  191562. }
  191563. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191564. continue;
  191565. if (outputDevice != 0)
  191566. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191567. }
  191568. }
  191569. juce_UseDebuggingNewOperator
  191570. String outputDeviceId, inputDeviceId;
  191571. String lastError;
  191572. private:
  191573. // Device stats...
  191574. WASAPIInputDevice* inputDevice;
  191575. WASAPIOutputDevice* outputDevice;
  191576. const bool useExclusiveMode;
  191577. double defaultSampleRate;
  191578. int minBufferSize, defaultBufferSize;
  191579. int latencyIn, latencyOut;
  191580. Array <double> sampleRates;
  191581. Array <int> bufferSizes;
  191582. // Active state...
  191583. bool isOpen_, isStarted;
  191584. int currentBufferSizeSamples;
  191585. double currentSampleRate;
  191586. AudioIODeviceCallback* callback;
  191587. CriticalSection startStopLock;
  191588. bool createDevices()
  191589. {
  191590. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191591. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191592. return false;
  191593. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191594. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191595. return false;
  191596. UINT32 numDevices = 0;
  191597. if (! OK (deviceCollection->GetCount (&numDevices)))
  191598. return false;
  191599. for (UINT32 i = 0; i < numDevices; ++i)
  191600. {
  191601. ComSmartPtr <IMMDevice> device;
  191602. if (! OK (deviceCollection->Item (i, &device)))
  191603. continue;
  191604. const String deviceId (wasapi_getDeviceID (device));
  191605. if (deviceId.isEmpty())
  191606. continue;
  191607. const EDataFlow flow = wasapi_getDataFlow (device);
  191608. if (deviceId == inputDeviceId && flow == eCapture)
  191609. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191610. else if (deviceId == outputDeviceId && flow == eRender)
  191611. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191612. }
  191613. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191614. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191615. }
  191616. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191617. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191618. };
  191619. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191620. {
  191621. public:
  191622. WASAPIAudioIODeviceType()
  191623. : AudioIODeviceType ("Windows Audio"),
  191624. hasScanned (false)
  191625. {
  191626. }
  191627. ~WASAPIAudioIODeviceType()
  191628. {
  191629. }
  191630. void scanForDevices()
  191631. {
  191632. hasScanned = true;
  191633. outputDeviceNames.clear();
  191634. inputDeviceNames.clear();
  191635. outputDeviceIds.clear();
  191636. inputDeviceIds.clear();
  191637. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191638. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191639. return;
  191640. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191641. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191642. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191643. UINT32 numDevices = 0;
  191644. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191645. && OK (deviceCollection->GetCount (&numDevices))))
  191646. return;
  191647. for (UINT32 i = 0; i < numDevices; ++i)
  191648. {
  191649. ComSmartPtr <IMMDevice> device;
  191650. if (! OK (deviceCollection->Item (i, &device)))
  191651. continue;
  191652. const String deviceId (wasapi_getDeviceID (device));
  191653. DWORD state = 0;
  191654. if (! OK (device->GetState (&state)))
  191655. continue;
  191656. if (state != DEVICE_STATE_ACTIVE)
  191657. continue;
  191658. String name;
  191659. {
  191660. ComSmartPtr <IPropertyStore> properties;
  191661. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191662. continue;
  191663. PROPVARIANT value;
  191664. PropVariantInit (&value);
  191665. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191666. name = value.pwszVal;
  191667. PropVariantClear (&value);
  191668. }
  191669. const EDataFlow flow = wasapi_getDataFlow (device);
  191670. if (flow == eRender)
  191671. {
  191672. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191673. outputDeviceIds.insert (index, deviceId);
  191674. outputDeviceNames.insert (index, name);
  191675. }
  191676. else if (flow == eCapture)
  191677. {
  191678. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191679. inputDeviceIds.insert (index, deviceId);
  191680. inputDeviceNames.insert (index, name);
  191681. }
  191682. }
  191683. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191684. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191685. }
  191686. const StringArray getDeviceNames (bool wantInputNames) const
  191687. {
  191688. jassert (hasScanned); // need to call scanForDevices() before doing this
  191689. return wantInputNames ? inputDeviceNames
  191690. : outputDeviceNames;
  191691. }
  191692. int getDefaultDeviceIndex (bool /*forInput*/) const
  191693. {
  191694. jassert (hasScanned); // need to call scanForDevices() before doing this
  191695. return 0;
  191696. }
  191697. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  191698. {
  191699. jassert (hasScanned); // need to call scanForDevices() before doing this
  191700. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191701. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191702. : outputDeviceIds.indexOf (d->outputDeviceId));
  191703. }
  191704. bool hasSeparateInputsAndOutputs() const { return true; }
  191705. AudioIODevice* createDevice (const String& outputDeviceName,
  191706. const String& inputDeviceName)
  191707. {
  191708. jassert (hasScanned); // need to call scanForDevices() before doing this
  191709. const bool useExclusiveMode = false;
  191710. ScopedPointer<WASAPIAudioIODevice> device;
  191711. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191712. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191713. if (outputIndex >= 0 || inputIndex >= 0)
  191714. {
  191715. device = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191716. : inputDeviceName,
  191717. outputDeviceIds [outputIndex],
  191718. inputDeviceIds [inputIndex],
  191719. useExclusiveMode);
  191720. if (! device->initialise())
  191721. device = 0;
  191722. }
  191723. return device.release();
  191724. }
  191725. juce_UseDebuggingNewOperator
  191726. StringArray outputDeviceNames, outputDeviceIds;
  191727. StringArray inputDeviceNames, inputDeviceIds;
  191728. private:
  191729. bool hasScanned;
  191730. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191731. {
  191732. String s;
  191733. IMMDevice* dev = 0;
  191734. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191735. eMultimedia, &dev)))
  191736. {
  191737. WCHAR* deviceId = 0;
  191738. if (OK (dev->GetId (&deviceId)))
  191739. {
  191740. s = String (deviceId);
  191741. CoTaskMemFree (deviceId);
  191742. }
  191743. dev->Release();
  191744. }
  191745. return s;
  191746. }
  191747. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191748. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191749. };
  191750. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191751. {
  191752. return new WASAPIAudioIODeviceType();
  191753. }
  191754. #undef logFailure
  191755. #undef OK
  191756. #endif
  191757. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191758. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191759. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191760. // compiled on its own).
  191761. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191762. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191763. {
  191764. public:
  191765. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191766. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191767. const ComSmartPtr <IBaseFilter>& filter_,
  191768. int minWidth, int minHeight,
  191769. int maxWidth, int maxHeight)
  191770. : owner (owner_),
  191771. captureGraphBuilder (captureGraphBuilder_),
  191772. filter (filter_),
  191773. ok (false),
  191774. imageNeedsFlipping (false),
  191775. width (0),
  191776. height (0),
  191777. activeUsers (0),
  191778. recordNextFrameTime (false),
  191779. activeImage (0),
  191780. loadingImage (0)
  191781. {
  191782. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191783. if (FAILED (hr))
  191784. return;
  191785. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191786. if (FAILED (hr))
  191787. return;
  191788. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191789. if (FAILED (hr))
  191790. return;
  191791. {
  191792. ComSmartPtr <IAMStreamConfig> streamConfig;
  191793. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191794. IID_IAMStreamConfig, (void**) &streamConfig);
  191795. if (streamConfig != 0)
  191796. {
  191797. getVideoSizes (streamConfig);
  191798. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191799. return;
  191800. }
  191801. }
  191802. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191803. if (FAILED (hr))
  191804. return;
  191805. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  191806. if (FAILED (hr))
  191807. return;
  191808. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191809. if (FAILED (hr))
  191810. return;
  191811. if (! connectFilters (filter, smartTee))
  191812. return;
  191813. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191814. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  191815. if (FAILED (hr))
  191816. return;
  191817. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191818. if (FAILED (hr))
  191819. return;
  191820. AM_MEDIA_TYPE mt;
  191821. zerostruct (mt);
  191822. mt.majortype = MEDIATYPE_Video;
  191823. mt.subtype = MEDIASUBTYPE_RGB24;
  191824. mt.formattype = FORMAT_VideoInfo;
  191825. sampleGrabber->SetMediaType (&mt);
  191826. callback = new GrabberCallback (*this);
  191827. sampleGrabber->SetCallback (callback, 1);
  191828. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191829. if (FAILED (hr))
  191830. return;
  191831. ComSmartPtr <IPin> grabberInputPin;
  191832. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  191833. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  191834. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  191835. return;
  191836. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  191837. if (FAILED (hr))
  191838. return;
  191839. zerostruct (mt);
  191840. hr = sampleGrabber->GetConnectedMediaType (&mt);
  191841. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  191842. width = pVih->bmiHeader.biWidth;
  191843. height = pVih->bmiHeader.biHeight;
  191844. ComSmartPtr <IBaseFilter> nullFilter;
  191845. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  191846. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  191847. if (connectFilters (sampleGrabberBase, nullFilter)
  191848. && addGraphToRot())
  191849. {
  191850. activeImage = new Image (Image::RGB, width, height, true);
  191851. loadingImage = new Image (Image::RGB, width, height, true);
  191852. ok = true;
  191853. }
  191854. }
  191855. ~DShowCameraDeviceInteral()
  191856. {
  191857. if (mediaControl != 0)
  191858. mediaControl->Stop();
  191859. removeGraphFromRot();
  191860. for (int i = viewerComps.size(); --i >= 0;)
  191861. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  191862. callback = 0;
  191863. graphBuilder = 0;
  191864. sampleGrabber = 0;
  191865. mediaControl = 0;
  191866. filter = 0;
  191867. captureGraphBuilder = 0;
  191868. smartTee = 0;
  191869. smartTeePreviewOutputPin = 0;
  191870. smartTeeCaptureOutputPin = 0;
  191871. asfWriter = 0;
  191872. delete activeImage;
  191873. delete loadingImage;
  191874. }
  191875. void addUser()
  191876. {
  191877. if (ok && activeUsers++ == 0)
  191878. mediaControl->Run();
  191879. }
  191880. void removeUser()
  191881. {
  191882. if (ok && --activeUsers == 0)
  191883. mediaControl->Stop();
  191884. }
  191885. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  191886. {
  191887. if (recordNextFrameTime)
  191888. {
  191889. const double defaultCameraLatency = 0.1;
  191890. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  191891. recordNextFrameTime = false;
  191892. ComSmartPtr <IPin> pin;
  191893. if (getPin (filter, PINDIR_OUTPUT, &pin))
  191894. {
  191895. ComSmartPtr <IAMPushSource> pushSource;
  191896. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  191897. if (pushSource != 0)
  191898. {
  191899. REFERENCE_TIME latency = 0;
  191900. hr = pushSource->GetLatency (&latency);
  191901. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  191902. }
  191903. }
  191904. }
  191905. {
  191906. const int lineStride = width * 3;
  191907. const ScopedLock sl (imageSwapLock);
  191908. {
  191909. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  191910. for (int i = 0; i < height; ++i)
  191911. memcpy (destData.getLinePointer ((height - 1) - i),
  191912. buffer + lineStride * i,
  191913. lineStride);
  191914. }
  191915. imageNeedsFlipping = true;
  191916. }
  191917. if (listeners.size() > 0)
  191918. callListeners (*loadingImage);
  191919. sendChangeMessage (this);
  191920. }
  191921. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  191922. {
  191923. if (imageNeedsFlipping)
  191924. {
  191925. const ScopedLock sl (imageSwapLock);
  191926. swapVariables (loadingImage, activeImage);
  191927. imageNeedsFlipping = false;
  191928. }
  191929. RectanglePlacement rp (RectanglePlacement::centred);
  191930. double dx = 0, dy = 0, dw = width, dh = height;
  191931. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  191932. const int rx = roundToInt (dx), ry = roundToInt (dy);
  191933. const int rw = roundToInt (dw), rh = roundToInt (dh);
  191934. g.saveState();
  191935. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  191936. g.fillAll (Colours::black);
  191937. g.restoreState();
  191938. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  191939. }
  191940. bool createFileCaptureFilter (const File& file)
  191941. {
  191942. removeFileCaptureFilter();
  191943. file.deleteFile();
  191944. mediaControl->Stop();
  191945. firstRecordedTime = Time();
  191946. recordNextFrameTime = true;
  191947. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  191948. if (SUCCEEDED (hr))
  191949. {
  191950. ComSmartPtr <IFileSinkFilter> fileSink;
  191951. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  191952. if (SUCCEEDED (hr))
  191953. {
  191954. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  191955. if (SUCCEEDED (hr))
  191956. {
  191957. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  191958. if (SUCCEEDED (hr))
  191959. {
  191960. ComSmartPtr <IConfigAsfWriter> asfConfig;
  191961. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  191962. asfConfig->SetIndexMode (true);
  191963. ComSmartPtr <IWMProfileManager> profileManager;
  191964. hr = WMCreateProfileManager (&profileManager);
  191965. // This gibberish is the DirectShow profile for a video-only wmv file.
  191966. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  191967. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  191968. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  191969. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  191970. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  191971. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  191972. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  191973. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  191974. prof = prof.replace ("$WIDTH", String (width))
  191975. .replace ("$HEIGHT", String (height));
  191976. ComSmartPtr <IWMProfile> currentProfile;
  191977. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  191978. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  191979. if (SUCCEEDED (hr))
  191980. {
  191981. ComSmartPtr <IPin> asfWriterInputPin;
  191982. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  191983. {
  191984. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  191985. if (SUCCEEDED (hr)
  191986. && ok && activeUsers > 0
  191987. && SUCCEEDED (mediaControl->Run()))
  191988. {
  191989. return true;
  191990. }
  191991. }
  191992. }
  191993. }
  191994. }
  191995. }
  191996. }
  191997. removeFileCaptureFilter();
  191998. if (ok && activeUsers > 0)
  191999. mediaControl->Run();
  192000. return false;
  192001. }
  192002. void removeFileCaptureFilter()
  192003. {
  192004. mediaControl->Stop();
  192005. if (asfWriter != 0)
  192006. {
  192007. graphBuilder->RemoveFilter (asfWriter);
  192008. asfWriter = 0;
  192009. }
  192010. if (ok && activeUsers > 0)
  192011. mediaControl->Run();
  192012. }
  192013. void addListener (CameraImageListener* listenerToAdd)
  192014. {
  192015. const ScopedLock sl (listenerLock);
  192016. if (listeners.size() == 0)
  192017. addUser();
  192018. listeners.addIfNotAlreadyThere (listenerToAdd);
  192019. }
  192020. void removeListener (CameraImageListener* listenerToRemove)
  192021. {
  192022. const ScopedLock sl (listenerLock);
  192023. listeners.removeValue (listenerToRemove);
  192024. if (listeners.size() == 0)
  192025. removeUser();
  192026. }
  192027. void callListeners (Image& image)
  192028. {
  192029. const ScopedLock sl (listenerLock);
  192030. for (int i = listeners.size(); --i >= 0;)
  192031. {
  192032. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192033. if (l != 0)
  192034. l->imageReceived (image);
  192035. }
  192036. }
  192037. class DShowCaptureViewerComp : public Component,
  192038. public ChangeListener
  192039. {
  192040. public:
  192041. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192042. : owner (owner_)
  192043. {
  192044. setOpaque (true);
  192045. owner->addChangeListener (this);
  192046. owner->addUser();
  192047. owner->viewerComps.add (this);
  192048. setSize (owner_->width, owner_->height);
  192049. }
  192050. ~DShowCaptureViewerComp()
  192051. {
  192052. if (owner != 0)
  192053. {
  192054. owner->viewerComps.removeValue (this);
  192055. owner->removeUser();
  192056. owner->removeChangeListener (this);
  192057. }
  192058. }
  192059. void ownerDeleted()
  192060. {
  192061. owner = 0;
  192062. }
  192063. void paint (Graphics& g)
  192064. {
  192065. g.setColour (Colours::black);
  192066. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192067. if (owner != 0)
  192068. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192069. else
  192070. g.fillAll (Colours::black);
  192071. }
  192072. void changeListenerCallback (void*)
  192073. {
  192074. repaint();
  192075. }
  192076. private:
  192077. DShowCameraDeviceInteral* owner;
  192078. };
  192079. bool ok;
  192080. int width, height;
  192081. Time firstRecordedTime;
  192082. VoidArray viewerComps;
  192083. private:
  192084. CameraDevice* const owner;
  192085. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192086. ComSmartPtr <IBaseFilter> filter;
  192087. ComSmartPtr <IBaseFilter> smartTee;
  192088. ComSmartPtr <IGraphBuilder> graphBuilder;
  192089. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192090. ComSmartPtr <IMediaControl> mediaControl;
  192091. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192092. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192093. ComSmartPtr <IBaseFilter> asfWriter;
  192094. int activeUsers;
  192095. Array <int> widths, heights;
  192096. DWORD graphRegistrationID;
  192097. CriticalSection imageSwapLock;
  192098. bool imageNeedsFlipping;
  192099. Image* loadingImage;
  192100. Image* activeImage;
  192101. bool recordNextFrameTime;
  192102. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192103. {
  192104. widths.clear();
  192105. heights.clear();
  192106. int count = 0, size = 0;
  192107. streamConfig->GetNumberOfCapabilities (&count, &size);
  192108. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192109. {
  192110. for (int i = 0; i < count; ++i)
  192111. {
  192112. VIDEO_STREAM_CONFIG_CAPS scc;
  192113. AM_MEDIA_TYPE* config;
  192114. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192115. if (SUCCEEDED (hr))
  192116. {
  192117. const int w = scc.InputSize.cx;
  192118. const int h = scc.InputSize.cy;
  192119. bool duplicate = false;
  192120. for (int j = widths.size(); --j >= 0;)
  192121. {
  192122. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192123. {
  192124. duplicate = true;
  192125. break;
  192126. }
  192127. }
  192128. if (! duplicate)
  192129. {
  192130. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192131. widths.add (w);
  192132. heights.add (h);
  192133. }
  192134. deleteMediaType (config);
  192135. }
  192136. }
  192137. }
  192138. }
  192139. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192140. const int minWidth, const int minHeight,
  192141. const int maxWidth, const int maxHeight)
  192142. {
  192143. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192144. streamConfig->GetNumberOfCapabilities (&count, &size);
  192145. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192146. {
  192147. AM_MEDIA_TYPE* config;
  192148. VIDEO_STREAM_CONFIG_CAPS scc;
  192149. for (int i = 0; i < count; ++i)
  192150. {
  192151. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192152. if (SUCCEEDED (hr))
  192153. {
  192154. if (scc.InputSize.cx >= minWidth
  192155. && scc.InputSize.cy >= minHeight
  192156. && scc.InputSize.cx <= maxWidth
  192157. && scc.InputSize.cy <= maxHeight)
  192158. {
  192159. int area = scc.InputSize.cx * scc.InputSize.cy;
  192160. if (area > bestArea)
  192161. {
  192162. bestIndex = i;
  192163. bestArea = area;
  192164. }
  192165. }
  192166. deleteMediaType (config);
  192167. }
  192168. }
  192169. if (bestIndex >= 0)
  192170. {
  192171. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192172. hr = streamConfig->SetFormat (config);
  192173. deleteMediaType (config);
  192174. return SUCCEEDED (hr);
  192175. }
  192176. }
  192177. return false;
  192178. }
  192179. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192180. {
  192181. ComSmartPtr <IEnumPins> enumerator;
  192182. ComSmartPtr <IPin> pin;
  192183. filter->EnumPins (&enumerator);
  192184. while (enumerator->Next (1, &pin, 0) == S_OK)
  192185. {
  192186. PIN_DIRECTION dir;
  192187. pin->QueryDirection (&dir);
  192188. if (wantedDirection == dir)
  192189. {
  192190. PIN_INFO info;
  192191. zerostruct (info);
  192192. pin->QueryPinInfo (&info);
  192193. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192194. {
  192195. pin.p->AddRef();
  192196. *result = pin;
  192197. return true;
  192198. }
  192199. }
  192200. }
  192201. return false;
  192202. }
  192203. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192204. {
  192205. ComSmartPtr <IPin> in, out;
  192206. return getPin (first, PINDIR_OUTPUT, &out)
  192207. && getPin (second, PINDIR_INPUT, &in)
  192208. && SUCCEEDED (graphBuilder->Connect (out, in));
  192209. }
  192210. bool addGraphToRot()
  192211. {
  192212. ComSmartPtr <IRunningObjectTable> rot;
  192213. if (FAILED (GetRunningObjectTable (0, &rot)))
  192214. return false;
  192215. ComSmartPtr <IMoniker> moniker;
  192216. WCHAR buffer[128];
  192217. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192218. if (FAILED (hr))
  192219. return false;
  192220. graphRegistrationID = 0;
  192221. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192222. }
  192223. void removeGraphFromRot()
  192224. {
  192225. ComSmartPtr <IRunningObjectTable> rot;
  192226. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192227. rot->Revoke (graphRegistrationID);
  192228. }
  192229. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192230. {
  192231. if (pmt->cbFormat != 0)
  192232. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192233. if (pmt->pUnk != 0)
  192234. pmt->pUnk->Release();
  192235. CoTaskMemFree (pmt);
  192236. }
  192237. class GrabberCallback : public ISampleGrabberCB
  192238. {
  192239. public:
  192240. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192241. : owner (owner_)
  192242. {
  192243. }
  192244. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192245. {
  192246. if (id == IID_IUnknown)
  192247. *result = dynamic_cast <IUnknown*> (this);
  192248. else if (id == IID_ISampleGrabberCB)
  192249. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192250. else
  192251. {
  192252. *result = 0;
  192253. return E_NOINTERFACE;
  192254. }
  192255. AddRef();
  192256. return S_OK;
  192257. }
  192258. ULONG __stdcall AddRef() { return ++refCount; }
  192259. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192260. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192261. {
  192262. return E_FAIL;
  192263. }
  192264. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192265. {
  192266. owner.handleFrame (time, buffer, bufferSize);
  192267. return S_OK;
  192268. }
  192269. private:
  192270. int refCount;
  192271. DShowCameraDeviceInteral& owner;
  192272. GrabberCallback (const GrabberCallback&);
  192273. GrabberCallback& operator= (const GrabberCallback&);
  192274. };
  192275. ComSmartPtr <GrabberCallback> callback;
  192276. VoidArray listeners;
  192277. CriticalSection listenerLock;
  192278. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192279. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192280. };
  192281. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192282. : name (name_)
  192283. {
  192284. isRecording = false;
  192285. }
  192286. CameraDevice::~CameraDevice()
  192287. {
  192288. stopRecording();
  192289. delete (DShowCameraDeviceInteral*) internal;
  192290. internal = 0;
  192291. }
  192292. Component* CameraDevice::createViewerComponent()
  192293. {
  192294. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192295. }
  192296. const String CameraDevice::getFileExtension()
  192297. {
  192298. return ".wmv";
  192299. }
  192300. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192301. {
  192302. stopRecording();
  192303. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192304. d->addUser();
  192305. isRecording = d->createFileCaptureFilter (file);
  192306. }
  192307. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192308. {
  192309. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192310. return d->firstRecordedTime;
  192311. }
  192312. void CameraDevice::stopRecording()
  192313. {
  192314. if (isRecording)
  192315. {
  192316. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192317. d->removeFileCaptureFilter();
  192318. d->removeUser();
  192319. isRecording = false;
  192320. }
  192321. }
  192322. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192323. {
  192324. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192325. if (listenerToAdd != 0)
  192326. d->addListener (listenerToAdd);
  192327. }
  192328. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192329. {
  192330. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192331. if (listenerToRemove != 0)
  192332. d->removeListener (listenerToRemove);
  192333. }
  192334. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192335. const int deviceIndexToOpen,
  192336. String& name)
  192337. {
  192338. int index = 0;
  192339. ComSmartPtr <IBaseFilter> result;
  192340. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192341. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192342. if (SUCCEEDED (hr))
  192343. {
  192344. ComSmartPtr <IEnumMoniker> enumerator;
  192345. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192346. if (SUCCEEDED (hr) && enumerator != 0)
  192347. {
  192348. ComSmartPtr <IBaseFilter> captureFilter;
  192349. ComSmartPtr <IMoniker> moniker;
  192350. ULONG fetched;
  192351. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192352. {
  192353. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192354. if (SUCCEEDED (hr))
  192355. {
  192356. ComSmartPtr <IPropertyBag> propertyBag;
  192357. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192358. if (SUCCEEDED (hr))
  192359. {
  192360. VARIANT var;
  192361. var.vt = VT_BSTR;
  192362. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192363. propertyBag = 0;
  192364. if (SUCCEEDED (hr))
  192365. {
  192366. if (names != 0)
  192367. names->add (var.bstrVal);
  192368. if (index == deviceIndexToOpen)
  192369. {
  192370. name = var.bstrVal;
  192371. result = captureFilter;
  192372. captureFilter = 0;
  192373. break;
  192374. }
  192375. ++index;
  192376. }
  192377. moniker = 0;
  192378. }
  192379. captureFilter = 0;
  192380. }
  192381. }
  192382. }
  192383. }
  192384. return result;
  192385. }
  192386. const StringArray CameraDevice::getAvailableDevices()
  192387. {
  192388. StringArray devs;
  192389. String dummy;
  192390. enumerateCameras (&devs, -1, dummy);
  192391. return devs;
  192392. }
  192393. CameraDevice* CameraDevice::openDevice (int index,
  192394. int minWidth, int minHeight,
  192395. int maxWidth, int maxHeight)
  192396. {
  192397. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192398. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192399. if (SUCCEEDED (hr))
  192400. {
  192401. String name;
  192402. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192403. if (filter != 0)
  192404. {
  192405. CameraDevice* const cam = new CameraDevice (name, index);
  192406. DShowCameraDeviceInteral* const intern
  192407. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192408. minWidth, minHeight, maxWidth, maxHeight);
  192409. cam->internal = intern;
  192410. if (intern->ok)
  192411. return cam;
  192412. else
  192413. delete cam;
  192414. }
  192415. }
  192416. return 0;
  192417. }
  192418. #endif
  192419. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192420. #endif
  192421. // Auto-link the other win32 libs that are needed by library calls..
  192422. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192423. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192424. // Auto-links to various win32 libs that are needed by library calls..
  192425. #pragma comment(lib, "kernel32.lib")
  192426. #pragma comment(lib, "user32.lib")
  192427. #pragma comment(lib, "shell32.lib")
  192428. #pragma comment(lib, "gdi32.lib")
  192429. #pragma comment(lib, "vfw32.lib")
  192430. #pragma comment(lib, "comdlg32.lib")
  192431. #pragma comment(lib, "winmm.lib")
  192432. #pragma comment(lib, "wininet.lib")
  192433. #pragma comment(lib, "ole32.lib")
  192434. #pragma comment(lib, "oleaut32.lib")
  192435. #pragma comment(lib, "advapi32.lib")
  192436. #pragma comment(lib, "ws2_32.lib")
  192437. #pragma comment(lib, "comsupp.lib")
  192438. #pragma comment(lib, "version.lib")
  192439. #if JUCE_OPENGL
  192440. #pragma comment(lib, "OpenGL32.Lib")
  192441. #pragma comment(lib, "GlU32.Lib")
  192442. #endif
  192443. #if JUCE_QUICKTIME
  192444. #pragma comment (lib, "QTMLClient.lib")
  192445. #endif
  192446. #if JUCE_USE_CAMERA
  192447. #pragma comment (lib, "Strmiids.lib")
  192448. #pragma comment (lib, "wmvcore.lib")
  192449. #endif
  192450. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192451. #endif
  192452. END_JUCE_NAMESPACE
  192453. #endif
  192454. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192455. #endif
  192456. #if JUCE_LINUX
  192457. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192458. #if JUCE_LINUX
  192459. BEGIN_JUCE_NAMESPACE
  192460. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192461. #define SUPPORT_AFFINITIES 1
  192462. #endif
  192463. #define JUCE_INCLUDED_FILE 1
  192464. // Now include the actual code files..
  192465. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192466. CriticalSection::CriticalSection() throw()
  192467. {
  192468. pthread_mutexattr_t atts;
  192469. pthread_mutexattr_init (&atts);
  192470. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192471. pthread_mutex_init (&internal, &atts);
  192472. }
  192473. CriticalSection::~CriticalSection() throw()
  192474. {
  192475. pthread_mutex_destroy (&internal);
  192476. }
  192477. void CriticalSection::enter() const throw()
  192478. {
  192479. pthread_mutex_lock (&internal);
  192480. }
  192481. bool CriticalSection::tryEnter() const throw()
  192482. {
  192483. return pthread_mutex_trylock (&internal) == 0;
  192484. }
  192485. void CriticalSection::exit() const throw()
  192486. {
  192487. pthread_mutex_unlock (&internal);
  192488. }
  192489. class WaitableEventImpl
  192490. {
  192491. public:
  192492. WaitableEventImpl()
  192493. : triggered (false)
  192494. {
  192495. pthread_cond_init (&condition, 0);
  192496. pthread_mutex_init (&mutex, 0);
  192497. }
  192498. ~WaitableEventImpl()
  192499. {
  192500. pthread_cond_destroy (&condition);
  192501. pthread_mutex_destroy (&mutex);
  192502. }
  192503. bool wait (const int timeOutMillisecs) throw()
  192504. {
  192505. pthread_mutex_lock (&mutex);
  192506. if (! triggered)
  192507. {
  192508. if (timeOutMillisecs < 0)
  192509. {
  192510. do
  192511. {
  192512. pthread_cond_wait (&condition, &mutex);
  192513. }
  192514. while (! triggered);
  192515. }
  192516. else
  192517. {
  192518. struct timeval now;
  192519. gettimeofday (&now, 0);
  192520. struct timespec time;
  192521. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  192522. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192523. if (time.tv_nsec >= 1000000000)
  192524. {
  192525. time.tv_nsec -= 1000000000;
  192526. time.tv_sec++;
  192527. }
  192528. do
  192529. {
  192530. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  192531. {
  192532. pthread_mutex_unlock (&mutex);
  192533. return false;
  192534. }
  192535. }
  192536. while (! triggered);
  192537. }
  192538. }
  192539. triggered = false;
  192540. pthread_mutex_unlock (&mutex);
  192541. return true;
  192542. }
  192543. void signal() throw()
  192544. {
  192545. pthread_mutex_lock (&mutex);
  192546. triggered = true;
  192547. pthread_cond_broadcast (&condition);
  192548. pthread_mutex_unlock (&mutex);
  192549. }
  192550. void reset() throw()
  192551. {
  192552. pthread_mutex_lock (&mutex);
  192553. triggered = false;
  192554. pthread_mutex_unlock (&mutex);
  192555. }
  192556. private:
  192557. pthread_cond_t condition;
  192558. pthread_mutex_t mutex;
  192559. bool triggered;
  192560. WaitableEventImpl (const WaitableEventImpl&);
  192561. WaitableEventImpl& operator= (const WaitableEventImpl&);
  192562. };
  192563. WaitableEvent::WaitableEvent() throw()
  192564. : internal (new WaitableEventImpl())
  192565. {
  192566. }
  192567. WaitableEvent::~WaitableEvent() throw()
  192568. {
  192569. delete static_cast <WaitableEventImpl*> (internal);
  192570. }
  192571. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192572. {
  192573. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  192574. }
  192575. void WaitableEvent::signal() const throw()
  192576. {
  192577. static_cast <WaitableEventImpl*> (internal)->signal();
  192578. }
  192579. void WaitableEvent::reset() const throw()
  192580. {
  192581. static_cast <WaitableEventImpl*> (internal)->reset();
  192582. }
  192583. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192584. {
  192585. struct timespec time;
  192586. time.tv_sec = millisecs / 1000;
  192587. time.tv_nsec = (millisecs % 1000) * 1000000;
  192588. nanosleep (&time, 0);
  192589. }
  192590. const juce_wchar File::separator = '/';
  192591. const juce_wchar* File::separatorString = L"/";
  192592. const File File::getCurrentWorkingDirectory()
  192593. {
  192594. HeapBlock<char> heapBuffer;
  192595. char localBuffer [1024];
  192596. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192597. int bufferSize = 4096;
  192598. while (cwd == 0 && errno == ERANGE)
  192599. {
  192600. heapBuffer.malloc (bufferSize);
  192601. cwd = getcwd (heapBuffer, bufferSize - 1);
  192602. bufferSize += 1024;
  192603. }
  192604. return File (String::fromUTF8 (cwd));
  192605. }
  192606. bool File::setAsCurrentWorkingDirectory() const
  192607. {
  192608. return chdir (getFullPathName().toUTF8()) == 0;
  192609. }
  192610. bool juce_copyFile (const String& s, const String& d);
  192611. static bool juce_stat (const String& fileName, struct stat& info)
  192612. {
  192613. return fileName.isNotEmpty()
  192614. && (stat (fileName.toUTF8(), &info) == 0);
  192615. }
  192616. bool juce_isDirectory (const String& fileName)
  192617. {
  192618. struct stat info;
  192619. return fileName.isEmpty()
  192620. || (juce_stat (fileName, info)
  192621. && ((info.st_mode & S_IFDIR) != 0));
  192622. }
  192623. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192624. {
  192625. if (fileName.isEmpty())
  192626. return false;
  192627. const char* const fileNameUTF8 = fileName.toUTF8();
  192628. bool exists = access (fileNameUTF8, F_OK) == 0;
  192629. if (exists && dontCountDirectories)
  192630. {
  192631. struct stat info;
  192632. const int res = stat (fileNameUTF8, &info);
  192633. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192634. exists = false;
  192635. }
  192636. return exists;
  192637. }
  192638. int64 juce_getFileSize (const String& fileName)
  192639. {
  192640. struct stat info;
  192641. return juce_stat (fileName, info) ? info.st_size : 0;
  192642. }
  192643. bool juce_canWriteToFile (const String& fileName)
  192644. {
  192645. return access (fileName.toUTF8(), W_OK) == 0;
  192646. }
  192647. bool juce_deleteFile (const String& fileName)
  192648. {
  192649. if (juce_isDirectory (fileName))
  192650. return rmdir (fileName.toUTF8()) == 0;
  192651. else
  192652. return remove (fileName.toUTF8()) == 0;
  192653. }
  192654. bool juce_moveFile (const String& source, const String& dest)
  192655. {
  192656. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192657. return true;
  192658. if (juce_canWriteToFile (source)
  192659. && juce_copyFile (source, dest))
  192660. {
  192661. if (juce_deleteFile (source))
  192662. return true;
  192663. juce_deleteFile (dest);
  192664. }
  192665. return false;
  192666. }
  192667. void juce_createDirectory (const String& fileName)
  192668. {
  192669. mkdir (fileName.toUTF8(), 0777);
  192670. }
  192671. void* juce_fileOpen (const String& fileName, bool forWriting)
  192672. {
  192673. int flags = O_RDONLY;
  192674. if (forWriting)
  192675. {
  192676. if (juce_fileExists (fileName, false))
  192677. {
  192678. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  192679. if (f != -1)
  192680. lseek (f, 0, SEEK_END);
  192681. return (void*) f;
  192682. }
  192683. else
  192684. {
  192685. flags = O_RDWR + O_CREAT;
  192686. }
  192687. }
  192688. return (void*) open (fileName.toUTF8(), flags, 00644);
  192689. }
  192690. void juce_fileClose (void* handle)
  192691. {
  192692. if (handle != 0)
  192693. close ((int) (pointer_sized_int) handle);
  192694. }
  192695. int juce_fileRead (void* handle, void* buffer, int size)
  192696. {
  192697. if (handle != 0)
  192698. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  192699. return 0;
  192700. }
  192701. int juce_fileWrite (void* handle, const void* buffer, int size)
  192702. {
  192703. if (handle != 0)
  192704. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192705. return 0;
  192706. }
  192707. int64 juce_fileSetPosition (void* handle, int64 pos)
  192708. {
  192709. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192710. return pos;
  192711. return -1;
  192712. }
  192713. int64 juce_fileGetPosition (void* handle)
  192714. {
  192715. if (handle != 0)
  192716. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192717. return -1;
  192718. }
  192719. void juce_fileFlush (void* handle)
  192720. {
  192721. if (handle != 0)
  192722. fsync ((int) (pointer_sized_int) handle);
  192723. }
  192724. const File juce_getExecutableFile()
  192725. {
  192726. Dl_info exeInfo;
  192727. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192728. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  192729. }
  192730. // if this file doesn't exist, find a parent of it that does..
  192731. static bool doStatFS (const File* file, struct statfs& result)
  192732. {
  192733. File f (*file);
  192734. for (int i = 5; --i >= 0;)
  192735. {
  192736. if (f.exists())
  192737. break;
  192738. f = f.getParentDirectory();
  192739. }
  192740. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192741. }
  192742. int64 File::getBytesFreeOnVolume() const
  192743. {
  192744. struct statfs buf;
  192745. if (doStatFS (this, buf))
  192746. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192747. return 0;
  192748. }
  192749. int64 File::getVolumeTotalSize() const
  192750. {
  192751. struct statfs buf;
  192752. if (doStatFS (this, buf))
  192753. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192754. return 0;
  192755. }
  192756. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192757. int& volumeSerialNumber)
  192758. {
  192759. volumeSerialNumber = 0;
  192760. #if JUCE_MAC
  192761. struct VolAttrBuf
  192762. {
  192763. u_int32_t length;
  192764. attrreference_t mountPointRef;
  192765. char mountPointSpace [MAXPATHLEN];
  192766. } attrBuf;
  192767. struct attrlist attrList;
  192768. zerostruct (attrList);
  192769. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192770. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192771. File f (filenameOnVolume);
  192772. for (;;)
  192773. {
  192774. if (getattrlist (f.getFullPathName().toUTF8(),
  192775. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192776. {
  192777. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192778. (int) attrBuf.mountPointRef.attr_length);
  192779. }
  192780. const File parent (f.getParentDirectory());
  192781. if (f == parent)
  192782. break;
  192783. f = parent;
  192784. }
  192785. #endif
  192786. return String::empty;
  192787. }
  192788. void juce_runSystemCommand (const String& command)
  192789. {
  192790. int result = system (command.toUTF8());
  192791. (void) result;
  192792. }
  192793. const String juce_getOutputFromCommand (const String& command)
  192794. {
  192795. // slight bodge here, as we just pipe the output into a temp file and read it...
  192796. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192797. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192798. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192799. String result (tempFile.loadFileAsString());
  192800. tempFile.deleteFile();
  192801. return result;
  192802. }
  192803. InterProcessLock::InterProcessLock (const String& name_)
  192804. : internal (0),
  192805. name (name_),
  192806. reentrancyLevel (0)
  192807. {
  192808. #if JUCE_MAC
  192809. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192810. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  192811. #else
  192812. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192813. #endif
  192814. temp.create();
  192815. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192816. }
  192817. InterProcessLock::~InterProcessLock()
  192818. {
  192819. while (reentrancyLevel > 0)
  192820. this->exit();
  192821. close (internal);
  192822. }
  192823. bool InterProcessLock::enter (const int timeOutMillisecs)
  192824. {
  192825. if (internal == 0)
  192826. return false;
  192827. if (reentrancyLevel != 0)
  192828. return true;
  192829. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192830. struct flock fl;
  192831. zerostruct (fl);
  192832. fl.l_whence = SEEK_SET;
  192833. fl.l_type = F_WRLCK;
  192834. for (;;)
  192835. {
  192836. const int result = fcntl (internal, F_SETLK, &fl);
  192837. if (result >= 0)
  192838. {
  192839. ++reentrancyLevel;
  192840. return true;
  192841. }
  192842. if (errno != EINTR)
  192843. {
  192844. if (timeOutMillisecs == 0
  192845. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192846. break;
  192847. Thread::sleep (10);
  192848. }
  192849. }
  192850. return false;
  192851. }
  192852. void InterProcessLock::exit()
  192853. {
  192854. if (reentrancyLevel > 0 && internal != 0)
  192855. {
  192856. --reentrancyLevel;
  192857. struct flock fl;
  192858. zerostruct (fl);
  192859. fl.l_whence = SEEK_SET;
  192860. fl.l_type = F_UNLCK;
  192861. for (;;)
  192862. {
  192863. const int result = fcntl (internal, F_SETLKW, &fl);
  192864. if (result >= 0 || errno != EINTR)
  192865. break;
  192866. }
  192867. }
  192868. }
  192869. /*** End of inlined file: juce_posix_SharedCode.h ***/
  192870. /*** Start of inlined file: juce_linux_Files.cpp ***/
  192871. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  192872. // compiled on its own).
  192873. #if JUCE_INCLUDED_FILE
  192874. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  192875. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  192876. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  192877. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  192878. void juce_getFileTimes (const String& fileName,
  192879. int64& modificationTime,
  192880. int64& accessTime,
  192881. int64& creationTime)
  192882. {
  192883. modificationTime = 0;
  192884. accessTime = 0;
  192885. creationTime = 0;
  192886. struct stat info;
  192887. const int res = stat (fileName.toUTF8(), &info);
  192888. if (res == 0)
  192889. {
  192890. modificationTime = (int64) info.st_mtime * 1000;
  192891. accessTime = (int64) info.st_atime * 1000;
  192892. creationTime = (int64) info.st_ctime * 1000;
  192893. }
  192894. }
  192895. bool juce_setFileTimes (const String& fileName,
  192896. int64 modificationTime,
  192897. int64 accessTime,
  192898. int64 creationTime)
  192899. {
  192900. struct utimbuf times;
  192901. times.actime = (time_t) (accessTime / 1000);
  192902. times.modtime = (time_t) (modificationTime / 1000);
  192903. return utime (fileName.toUTF8(), &times) == 0;
  192904. }
  192905. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  192906. {
  192907. struct stat info;
  192908. const int res = stat (fileName.toUTF8(), &info);
  192909. if (res != 0)
  192910. return false;
  192911. info.st_mode &= 0777; // Just permissions
  192912. if( isReadOnly )
  192913. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  192914. else
  192915. // Give everybody write permission?
  192916. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  192917. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  192918. }
  192919. bool juce_copyFile (const String& s, const String& d)
  192920. {
  192921. const File source (s), dest (d);
  192922. FileInputStream* in = source.createInputStream();
  192923. bool ok = false;
  192924. if (in != 0)
  192925. {
  192926. if (dest.deleteFile())
  192927. {
  192928. FileOutputStream* const out = dest.createOutputStream();
  192929. if (out != 0)
  192930. {
  192931. const int bytesCopied = out->writeFromInputStream (*in, -1);
  192932. delete out;
  192933. ok = (bytesCopied == source.getSize());
  192934. if (! ok)
  192935. dest.deleteFile();
  192936. }
  192937. }
  192938. delete in;
  192939. }
  192940. return ok;
  192941. }
  192942. const StringArray juce_getFileSystemRoots()
  192943. {
  192944. StringArray s;
  192945. s.add ("/");
  192946. return s;
  192947. }
  192948. bool File::isOnCDRomDrive() const
  192949. {
  192950. struct statfs buf;
  192951. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192952. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  192953. // Assume not if this fails for some reason
  192954. return false;
  192955. }
  192956. bool File::isOnHardDisk() const
  192957. {
  192958. struct statfs buf;
  192959. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192960. {
  192961. switch (buf.f_type)
  192962. {
  192963. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  192964. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  192965. case U_NFS_SUPER_MAGIC: // Network NFS
  192966. case U_SMB_SUPER_MAGIC: // Network Samba
  192967. return false;
  192968. default:
  192969. // Assume anything else is a hard-disk (but note it could
  192970. // be a RAM disk. There isn't a good way of determining
  192971. // this for sure)
  192972. return true;
  192973. }
  192974. }
  192975. // Assume so if this fails for some reason
  192976. return true;
  192977. }
  192978. bool File::isOnRemovableDrive() const
  192979. {
  192980. jassertfalse // xxx not implemented for linux!
  192981. return false;
  192982. }
  192983. bool File::isHidden() const
  192984. {
  192985. return getFileName().startsWithChar ('.');
  192986. }
  192987. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  192988. const File File::getSpecialLocation (const SpecialLocationType type)
  192989. {
  192990. switch (type)
  192991. {
  192992. case userHomeDirectory:
  192993. {
  192994. const char* homeDir = getenv ("HOME");
  192995. if (homeDir == 0)
  192996. {
  192997. struct passwd* const pw = getpwuid (getuid());
  192998. if (pw != 0)
  192999. homeDir = pw->pw_dir;
  193000. }
  193001. return File (String::fromUTF8 (homeDir));
  193002. }
  193003. case userDocumentsDirectory:
  193004. case userMusicDirectory:
  193005. case userMoviesDirectory:
  193006. case userApplicationDataDirectory:
  193007. return File ("~");
  193008. case userDesktopDirectory:
  193009. return File ("~/Desktop");
  193010. case commonApplicationDataDirectory:
  193011. return File ("/var");
  193012. case globalApplicationsDirectory:
  193013. return File ("/usr");
  193014. case tempDirectory:
  193015. {
  193016. File tmp ("/var/tmp");
  193017. if (! tmp.isDirectory())
  193018. {
  193019. tmp = "/tmp";
  193020. if (! tmp.isDirectory())
  193021. tmp = File::getCurrentWorkingDirectory();
  193022. }
  193023. return tmp;
  193024. }
  193025. case invokedExecutableFile:
  193026. if (juce_Argv0 != 0)
  193027. return File (String::fromUTF8 (juce_Argv0));
  193028. // deliberate fall-through...
  193029. case currentExecutableFile:
  193030. case currentApplicationFile:
  193031. return juce_getExecutableFile();
  193032. default:
  193033. jassertfalse // unknown type?
  193034. break;
  193035. }
  193036. return File::nonexistent;
  193037. }
  193038. const String File::getVersion() const
  193039. {
  193040. return String::empty; // xxx not yet implemented
  193041. }
  193042. const File File::getLinkedTarget() const
  193043. {
  193044. char buffer [4096];
  193045. size_t numChars = readlink (getFullPathName().toUTF8(),
  193046. buffer, sizeof (buffer));
  193047. if (numChars > 0 && numChars <= sizeof (buffer))
  193048. return File (String::fromUTF8 (buffer, (int) numChars));
  193049. return *this;
  193050. }
  193051. bool File::moveToTrash() const
  193052. {
  193053. if (! exists())
  193054. return true;
  193055. File trashCan ("~/.Trash");
  193056. if (! trashCan.isDirectory())
  193057. trashCan = "~/.local/share/Trash/files";
  193058. if (! trashCan.isDirectory())
  193059. return false;
  193060. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193061. getFileExtension()));
  193062. }
  193063. struct FindFileStruct
  193064. {
  193065. String parentDir, wildCard;
  193066. DIR* dir;
  193067. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193068. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193069. {
  193070. const char* const wildcardUTF8 = wildCard.toUTF8();
  193071. for (;;)
  193072. {
  193073. struct dirent* const de = readdir (dir);
  193074. if (de == 0)
  193075. break;
  193076. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193077. {
  193078. result = String::fromUTF8 (de->d_name);
  193079. const String path (parentDir + result);
  193080. if (isDir != 0 || fileSize != 0)
  193081. {
  193082. struct stat info;
  193083. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193084. if (isDir != 0)
  193085. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193086. if (isHidden != 0)
  193087. *isHidden = (de->d_name[0] == '.');
  193088. if (fileSize != 0)
  193089. *fileSize = statOk ? info.st_size : 0;
  193090. }
  193091. if (modTime != 0 || creationTime != 0)
  193092. {
  193093. int64 m, a, c;
  193094. juce_getFileTimes (path, m, a, c);
  193095. if (modTime != 0)
  193096. *modTime = m;
  193097. if (creationTime != 0)
  193098. *creationTime = c;
  193099. }
  193100. if (isReadOnly != 0)
  193101. *isReadOnly = ! juce_canWriteToFile (path);
  193102. return true;
  193103. }
  193104. }
  193105. return false;
  193106. }
  193107. };
  193108. // returns 0 on failure
  193109. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193110. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193111. Time* creationTime, bool* isReadOnly)
  193112. {
  193113. DIR* d = opendir (directory.toUTF8());
  193114. if (d != 0)
  193115. {
  193116. FindFileStruct* ff = new FindFileStruct();
  193117. ff->parentDir = directory;
  193118. if (!ff->parentDir.endsWithChar (File::separator))
  193119. ff->parentDir += File::separator;
  193120. ff->wildCard = wildCard;
  193121. if (wildCard == "*.*")
  193122. ff->wildCard = "*";
  193123. ff->dir = d;
  193124. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193125. {
  193126. return ff;
  193127. }
  193128. else
  193129. {
  193130. firstResultFile = String::empty;
  193131. isDir = false;
  193132. isHidden = false;
  193133. closedir (d);
  193134. delete ff;
  193135. }
  193136. }
  193137. return 0;
  193138. }
  193139. bool juce_findFileNext (void* handle, String& resultFile,
  193140. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193141. {
  193142. FindFileStruct* const ff = (FindFileStruct*) handle;
  193143. if (ff != 0)
  193144. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193145. return false;
  193146. }
  193147. void juce_findFileClose (void* handle)
  193148. {
  193149. FindFileStruct* const ff = (FindFileStruct*) handle;
  193150. if (ff != 0)
  193151. {
  193152. closedir (ff->dir);
  193153. delete ff;
  193154. }
  193155. }
  193156. bool juce_launchFile (const String& fileName,
  193157. const String& parameters)
  193158. {
  193159. String cmdString (fileName.replace (" ", "\\ ",false));
  193160. cmdString << " " << parameters;
  193161. if (URL::isProbablyAWebsiteURL (fileName)
  193162. || cmdString.startsWithIgnoreCase ("file:")
  193163. || URL::isProbablyAnEmailAddress (fileName))
  193164. {
  193165. // create a command that tries to launch a bunch of likely browsers
  193166. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193167. StringArray cmdLines;
  193168. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193169. cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());
  193170. cmdString = cmdLines.joinIntoString (" || ");
  193171. }
  193172. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
  193173. const int cpid = fork();
  193174. if (cpid == 0)
  193175. {
  193176. setsid();
  193177. // Child process
  193178. execve (argv[0], (char**) argv, environ);
  193179. exit (0);
  193180. }
  193181. return cpid >= 0;
  193182. }
  193183. void File::revealToUser() const
  193184. {
  193185. if (isDirectory())
  193186. startAsProcess();
  193187. else if (getParentDirectory().exists())
  193188. getParentDirectory().startAsProcess();
  193189. }
  193190. #endif
  193191. /*** End of inlined file: juce_linux_Files.cpp ***/
  193192. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193193. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193194. // compiled on its own).
  193195. #if JUCE_INCLUDED_FILE
  193196. struct NamedPipeInternal
  193197. {
  193198. String pipeInName, pipeOutName;
  193199. int pipeIn, pipeOut;
  193200. bool volatile createdPipe, blocked, stopReadOperation;
  193201. static void signalHandler (int) {}
  193202. };
  193203. void NamedPipe::cancelPendingReads()
  193204. {
  193205. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193206. {
  193207. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193208. intern->stopReadOperation = true;
  193209. char buffer [1] = { 0 };
  193210. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193211. (void) bytesWritten;
  193212. int timeout = 2000;
  193213. while (intern->blocked && --timeout >= 0)
  193214. Thread::sleep (2);
  193215. intern->stopReadOperation = false;
  193216. }
  193217. }
  193218. void NamedPipe::close()
  193219. {
  193220. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193221. if (intern != 0)
  193222. {
  193223. internal = 0;
  193224. if (intern->pipeIn != -1)
  193225. ::close (intern->pipeIn);
  193226. if (intern->pipeOut != -1)
  193227. ::close (intern->pipeOut);
  193228. if (intern->createdPipe)
  193229. {
  193230. unlink (intern->pipeInName.toUTF8());
  193231. unlink (intern->pipeOutName.toUTF8());
  193232. }
  193233. delete intern;
  193234. }
  193235. }
  193236. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193237. {
  193238. close();
  193239. NamedPipeInternal* const intern = new NamedPipeInternal();
  193240. internal = intern;
  193241. intern->createdPipe = createPipe;
  193242. intern->blocked = false;
  193243. intern->stopReadOperation = false;
  193244. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193245. siginterrupt (SIGPIPE, 1);
  193246. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  193247. intern->pipeInName = pipePath + "_in";
  193248. intern->pipeOutName = pipePath + "_out";
  193249. intern->pipeIn = -1;
  193250. intern->pipeOut = -1;
  193251. if (createPipe)
  193252. {
  193253. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193254. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193255. {
  193256. delete intern;
  193257. internal = 0;
  193258. return false;
  193259. }
  193260. }
  193261. return true;
  193262. }
  193263. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193264. {
  193265. int bytesRead = -1;
  193266. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193267. if (intern != 0)
  193268. {
  193269. intern->blocked = true;
  193270. if (intern->pipeIn == -1)
  193271. {
  193272. if (intern->createdPipe)
  193273. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193274. else
  193275. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193276. if (intern->pipeIn == -1)
  193277. {
  193278. intern->blocked = false;
  193279. return -1;
  193280. }
  193281. }
  193282. bytesRead = 0;
  193283. char* p = (char*) destBuffer;
  193284. while (bytesRead < maxBytesToRead)
  193285. {
  193286. const int bytesThisTime = maxBytesToRead - bytesRead;
  193287. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193288. if (numRead <= 0 || intern->stopReadOperation)
  193289. {
  193290. bytesRead = -1;
  193291. break;
  193292. }
  193293. bytesRead += numRead;
  193294. p += bytesRead;
  193295. }
  193296. intern->blocked = false;
  193297. }
  193298. return bytesRead;
  193299. }
  193300. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193301. {
  193302. int bytesWritten = -1;
  193303. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193304. if (intern != 0)
  193305. {
  193306. if (intern->pipeOut == -1)
  193307. {
  193308. if (intern->createdPipe)
  193309. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193310. else
  193311. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193312. if (intern->pipeOut == -1)
  193313. {
  193314. return -1;
  193315. }
  193316. }
  193317. const char* p = (const char*) sourceBuffer;
  193318. bytesWritten = 0;
  193319. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193320. while (bytesWritten < numBytesToWrite
  193321. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193322. {
  193323. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193324. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193325. if (numWritten <= 0)
  193326. {
  193327. bytesWritten = -1;
  193328. break;
  193329. }
  193330. bytesWritten += numWritten;
  193331. p += bytesWritten;
  193332. }
  193333. }
  193334. return bytesWritten;
  193335. }
  193336. #endif
  193337. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193338. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193339. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193340. // compiled on its own).
  193341. #if JUCE_INCLUDED_FILE
  193342. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193343. {
  193344. int numResults = 0;
  193345. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193346. if (s != -1)
  193347. {
  193348. char buf [1024];
  193349. struct ifconf ifc;
  193350. ifc.ifc_len = sizeof (buf);
  193351. ifc.ifc_buf = buf;
  193352. ioctl (s, SIOCGIFCONF, &ifc);
  193353. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193354. {
  193355. struct ifreq ifr;
  193356. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193357. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193358. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193359. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193360. && numResults < maxNum)
  193361. {
  193362. int64 a = 0;
  193363. for (int j = 6; --j >= 0;)
  193364. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193365. *addresses++ = a;
  193366. ++numResults;
  193367. }
  193368. }
  193369. close (s);
  193370. }
  193371. return numResults;
  193372. }
  193373. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193374. const String& emailSubject,
  193375. const String& bodyText,
  193376. const StringArray& filesToAttach)
  193377. {
  193378. jassertfalse // xxx todo
  193379. return false;
  193380. }
  193381. class JUCE_HTTPSocketStream
  193382. {
  193383. public:
  193384. JUCE_HTTPSocketStream()
  193385. : readPosition (0),
  193386. socketHandle (-1),
  193387. levelsOfRedirection (0),
  193388. timeoutSeconds (15)
  193389. {
  193390. }
  193391. ~JUCE_HTTPSocketStream()
  193392. {
  193393. closeSocket();
  193394. }
  193395. bool open (const String& url,
  193396. const String& headers,
  193397. const MemoryBlock& postData,
  193398. const bool isPost,
  193399. URL::OpenStreamProgressCallback* callback,
  193400. void* callbackContext,
  193401. int timeOutMs)
  193402. {
  193403. closeSocket();
  193404. uint32 timeOutTime = Time::getMillisecondCounter();
  193405. if (timeOutMs == 0)
  193406. timeOutTime += 60000;
  193407. else if (timeOutMs < 0)
  193408. timeOutTime = 0xffffffff;
  193409. else
  193410. timeOutTime += timeOutMs;
  193411. String hostName, hostPath;
  193412. int hostPort;
  193413. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193414. return false;
  193415. const struct hostent* host = 0;
  193416. int port = 0;
  193417. String proxyName, proxyPath;
  193418. int proxyPort = 0;
  193419. String proxyURL (getenv ("http_proxy"));
  193420. if (proxyURL.startsWithIgnoreCase ("http://"))
  193421. {
  193422. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193423. return false;
  193424. host = gethostbyname (proxyName.toUTF8());
  193425. port = proxyPort;
  193426. }
  193427. else
  193428. {
  193429. host = gethostbyname (hostName.toUTF8());
  193430. port = hostPort;
  193431. }
  193432. if (host == 0)
  193433. return false;
  193434. struct sockaddr_in address;
  193435. zerostruct (address);
  193436. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193437. address.sin_family = host->h_addrtype;
  193438. address.sin_port = htons (port);
  193439. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193440. if (socketHandle == -1)
  193441. return false;
  193442. int receiveBufferSize = 16384;
  193443. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193444. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193445. #if JUCE_MAC
  193446. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193447. #endif
  193448. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193449. {
  193450. closeSocket();
  193451. return false;
  193452. }
  193453. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193454. proxyName, proxyPort,
  193455. hostPath, url,
  193456. headers, postData,
  193457. isPost));
  193458. size_t totalHeaderSent = 0;
  193459. while (totalHeaderSent < requestHeader.getSize())
  193460. {
  193461. if (Time::getMillisecondCounter() > timeOutTime)
  193462. {
  193463. closeSocket();
  193464. return false;
  193465. }
  193466. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193467. if (send (socketHandle,
  193468. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193469. numToSend, 0)
  193470. != numToSend)
  193471. {
  193472. closeSocket();
  193473. return false;
  193474. }
  193475. totalHeaderSent += numToSend;
  193476. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193477. {
  193478. closeSocket();
  193479. return false;
  193480. }
  193481. }
  193482. const String responseHeader (readResponse (timeOutTime));
  193483. if (responseHeader.isNotEmpty())
  193484. {
  193485. //DBG (responseHeader);
  193486. StringArray lines;
  193487. lines.addLines (responseHeader);
  193488. const int statusCode = responseHeader.fromFirstOccurrenceOf (" ", false, false)
  193489. .substring (0, 3).getIntValue();
  193490. //int contentLength = findHeaderItem (lines, "Content-Length:").getIntValue();
  193491. //bool isChunked = findHeaderItem (lines, "Transfer-Encoding:").equalsIgnoreCase ("chunked");
  193492. String location (findHeaderItem (lines, "Location:"));
  193493. if (statusCode >= 300 && statusCode < 400
  193494. && location.isNotEmpty())
  193495. {
  193496. if (! location.startsWithIgnoreCase ("http://"))
  193497. location = "http://" + location;
  193498. if (levelsOfRedirection++ < 3)
  193499. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193500. }
  193501. else
  193502. {
  193503. levelsOfRedirection = 0;
  193504. return true;
  193505. }
  193506. }
  193507. closeSocket();
  193508. return false;
  193509. }
  193510. int read (void* buffer, int bytesToRead)
  193511. {
  193512. fd_set readbits;
  193513. FD_ZERO (&readbits);
  193514. FD_SET (socketHandle, &readbits);
  193515. struct timeval tv;
  193516. tv.tv_sec = timeoutSeconds;
  193517. tv.tv_usec = 0;
  193518. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193519. return 0; // (timeout)
  193520. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193521. readPosition += bytesRead;
  193522. return bytesRead;
  193523. }
  193524. int readPosition;
  193525. juce_UseDebuggingNewOperator
  193526. private:
  193527. int socketHandle, levelsOfRedirection;
  193528. const int timeoutSeconds;
  193529. void closeSocket()
  193530. {
  193531. if (socketHandle >= 0)
  193532. close (socketHandle);
  193533. socketHandle = -1;
  193534. }
  193535. const MemoryBlock createRequestHeader (const String& hostName,
  193536. const int hostPort,
  193537. const String& proxyName,
  193538. const int proxyPort,
  193539. const String& hostPath,
  193540. const String& originalURL,
  193541. const String& headers,
  193542. const MemoryBlock& postData,
  193543. const bool isPost)
  193544. {
  193545. String header (isPost ? "POST " : "GET ");
  193546. if (proxyName.isEmpty())
  193547. {
  193548. header << hostPath << " HTTP/1.0\r\nHost: "
  193549. << hostName << ':' << hostPort;
  193550. }
  193551. else
  193552. {
  193553. header << originalURL << " HTTP/1.0\r\nHost: "
  193554. << proxyName << ':' << proxyPort;
  193555. }
  193556. header << "\r\nUser-Agent: JUCE/"
  193557. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193558. << "\r\nConnection: Close\r\nContent-Length: "
  193559. << postData.getSize() << "\r\n"
  193560. << headers << "\r\n";
  193561. MemoryBlock mb;
  193562. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193563. mb.append (postData.getData(), postData.getSize());
  193564. return mb;
  193565. }
  193566. const String readResponse (const uint32 timeOutTime)
  193567. {
  193568. int bytesRead = 0, numConsecutiveLFs = 0;
  193569. MemoryBlock buffer (1024, true);
  193570. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193571. && Time::getMillisecondCounter() <= timeOutTime)
  193572. {
  193573. fd_set readbits;
  193574. FD_ZERO (&readbits);
  193575. FD_SET (socketHandle, &readbits);
  193576. struct timeval tv;
  193577. tv.tv_sec = timeoutSeconds;
  193578. tv.tv_usec = 0;
  193579. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193580. return String::empty; // (timeout)
  193581. buffer.ensureSize (bytesRead + 8, true);
  193582. char* const dest = (char*) buffer.getData() + bytesRead;
  193583. if (recv (socketHandle, dest, 1, 0) == -1)
  193584. return String::empty;
  193585. const char lastByte = *dest;
  193586. ++bytesRead;
  193587. if (lastByte == '\n')
  193588. ++numConsecutiveLFs;
  193589. else if (lastByte != '\r')
  193590. numConsecutiveLFs = 0;
  193591. }
  193592. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193593. if (header.startsWithIgnoreCase ("HTTP/"))
  193594. return header.trimEnd();
  193595. return String::empty;
  193596. }
  193597. static bool decomposeURL (const String& url,
  193598. String& host, String& path, int& port)
  193599. {
  193600. if (! url.startsWithIgnoreCase ("http://"))
  193601. return false;
  193602. const int nextSlash = url.indexOfChar (7, '/');
  193603. int nextColon = url.indexOfChar (7, ':');
  193604. if (nextColon > nextSlash && nextSlash > 0)
  193605. nextColon = -1;
  193606. if (nextColon >= 0)
  193607. {
  193608. host = url.substring (7, nextColon);
  193609. if (nextSlash >= 0)
  193610. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193611. else
  193612. port = url.substring (nextColon + 1).getIntValue();
  193613. }
  193614. else
  193615. {
  193616. port = 80;
  193617. if (nextSlash >= 0)
  193618. host = url.substring (7, nextSlash);
  193619. else
  193620. host = url.substring (7);
  193621. }
  193622. if (nextSlash >= 0)
  193623. path = url.substring (nextSlash);
  193624. else
  193625. path = "/";
  193626. return true;
  193627. }
  193628. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193629. {
  193630. for (int i = 0; i < lines.size(); ++i)
  193631. if (lines[i].startsWithIgnoreCase (itemName))
  193632. return lines[i].substring (itemName.length()).trim();
  193633. return String::empty;
  193634. }
  193635. };
  193636. bool juce_isOnLine()
  193637. {
  193638. return true;
  193639. }
  193640. void* juce_openInternetFile (const String& url,
  193641. const String& headers,
  193642. const MemoryBlock& postData,
  193643. const bool isPost,
  193644. URL::OpenStreamProgressCallback* callback,
  193645. void* callbackContext,
  193646. int timeOutMs)
  193647. {
  193648. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193649. if (s->open (url, headers, postData, isPost,
  193650. callback, callbackContext, timeOutMs))
  193651. return s;
  193652. delete s;
  193653. return 0;
  193654. }
  193655. void juce_closeInternetFile (void* handle)
  193656. {
  193657. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193658. if (s != 0)
  193659. delete s;
  193660. }
  193661. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193662. {
  193663. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193664. if (s != 0)
  193665. return s->read (buffer, bytesToRead);
  193666. return 0;
  193667. }
  193668. int64 juce_getInternetFileContentLength (void* handle)
  193669. {
  193670. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193671. if (s != 0)
  193672. {
  193673. //xxx todo
  193674. jassertfalse
  193675. }
  193676. return -1;
  193677. }
  193678. int juce_seekInInternetFile (void* handle, int newPosition)
  193679. {
  193680. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193681. if (s != 0)
  193682. return s->readPosition;
  193683. return 0;
  193684. }
  193685. #endif
  193686. /*** End of inlined file: juce_linux_Network.cpp ***/
  193687. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193688. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193689. // compiled on its own).
  193690. #if JUCE_INCLUDED_FILE
  193691. void Logger::outputDebugString (const String& text) throw()
  193692. {
  193693. std::cerr << text << std::endl;
  193694. }
  193695. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193696. {
  193697. return Linux;
  193698. }
  193699. const String SystemStats::getOperatingSystemName() throw()
  193700. {
  193701. return "Linux";
  193702. }
  193703. bool SystemStats::isOperatingSystem64Bit() throw()
  193704. {
  193705. #if JUCE_64BIT
  193706. return true;
  193707. #else
  193708. //xxx not sure how to find this out?..
  193709. return false;
  193710. #endif
  193711. }
  193712. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193713. {
  193714. String info;
  193715. char buf [256];
  193716. FILE* f = fopen ("/proc/cpuinfo", "r");
  193717. while (f != 0 && fgets (buf, sizeof(buf), f))
  193718. {
  193719. if (strncmp (buf, key, strlen (key)) == 0)
  193720. {
  193721. char* p = buf;
  193722. while (*p && *p != '\n')
  193723. ++p;
  193724. if (*p != 0)
  193725. *p = 0;
  193726. p = buf;
  193727. while (*p != 0 && *p != ':')
  193728. ++p;
  193729. if (*p != 0 && *(p + 1) != 0)
  193730. info = p + 2;
  193731. if (! lastOne)
  193732. break;
  193733. }
  193734. }
  193735. fclose (f);
  193736. return info;
  193737. }
  193738. bool SystemStats::hasMMX() throw()
  193739. {
  193740. return getCpuInfo ("flags").contains ("mmx");
  193741. }
  193742. bool SystemStats::hasSSE() throw()
  193743. {
  193744. return getCpuInfo ("flags").contains ("sse");
  193745. }
  193746. bool SystemStats::hasSSE2() throw()
  193747. {
  193748. return getCpuInfo ("flags").contains ("sse2");
  193749. }
  193750. bool SystemStats::has3DNow() throw()
  193751. {
  193752. return getCpuInfo ("flags").contains ("3dnow");
  193753. }
  193754. const String SystemStats::getCpuVendor() throw()
  193755. {
  193756. return getCpuInfo ("vendor_id");
  193757. }
  193758. int SystemStats::getCpuSpeedInMegaherz() throw()
  193759. {
  193760. const String speed (getCpuInfo ("cpu MHz"));
  193761. return (int) (speed.getFloatValue() + 0.5f);
  193762. }
  193763. int SystemStats::getMemorySizeInMegabytes() throw()
  193764. {
  193765. struct sysinfo sysi;
  193766. if (sysinfo (&sysi) == 0)
  193767. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193768. return 0;
  193769. }
  193770. uint32 juce_millisecondsSinceStartup() throw()
  193771. {
  193772. static unsigned int calibrate = 0;
  193773. static bool calibrated = false;
  193774. timeval t;
  193775. unsigned int ret = 0;
  193776. if (! gettimeofday (&t, 0))
  193777. {
  193778. if (! calibrated)
  193779. {
  193780. struct sysinfo sysi;
  193781. if (sysinfo (&sysi) == 0)
  193782. // Safe to assume system was not brought up earlier than 1970!
  193783. calibrate = t.tv_sec - sysi.uptime;
  193784. calibrated = true;
  193785. }
  193786. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193787. }
  193788. return ret;
  193789. }
  193790. double Time::getMillisecondCounterHiRes() throw()
  193791. {
  193792. return getHighResolutionTicks() * 0.001;
  193793. }
  193794. int64 Time::getHighResolutionTicks() throw()
  193795. {
  193796. timeval t;
  193797. if (gettimeofday (&t, 0))
  193798. return 0;
  193799. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193800. }
  193801. int64 Time::getHighResolutionTicksPerSecond() throw()
  193802. {
  193803. // Microseconds
  193804. return 1000000;
  193805. }
  193806. bool Time::setSystemTimeToThisTime() const throw()
  193807. {
  193808. timeval t;
  193809. t.tv_sec = millisSinceEpoch % 1000000;
  193810. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193811. return settimeofday (&t, NULL) ? false : true;
  193812. }
  193813. int SystemStats::getPageSize() throw()
  193814. {
  193815. static int systemPageSize = 0;
  193816. if (systemPageSize == 0)
  193817. systemPageSize = sysconf (_SC_PAGESIZE);
  193818. return systemPageSize;
  193819. }
  193820. int SystemStats::getNumCpus() throw()
  193821. {
  193822. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193823. return lastCpu + 1;
  193824. }
  193825. const String SystemStats::getLogonName()
  193826. {
  193827. const char* user = getenv ("USER");
  193828. if (user == 0)
  193829. {
  193830. struct passwd* const pw = getpwuid (getuid());
  193831. if (pw != 0)
  193832. user = pw->pw_name;
  193833. }
  193834. return String::fromUTF8 (user);
  193835. }
  193836. const String SystemStats::getFullUserName()
  193837. {
  193838. return getLogonName();
  193839. }
  193840. void SystemStats::initialiseStats() throw()
  193841. {
  193842. // Process starts off as root when running suid
  193843. Process::lowerPrivilege();
  193844. String s (SystemStats::getJUCEVersion());
  193845. }
  193846. void PlatformUtilities::fpuReset()
  193847. {
  193848. }
  193849. #endif
  193850. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193851. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193852. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193853. // compiled on its own).
  193854. #if JUCE_INCLUDED_FILE
  193855. void JUCE_API juce_threadEntryPoint (void*);
  193856. void* threadEntryProc (void* value)
  193857. {
  193858. // New threads start off as root when running suid
  193859. Process::lowerPrivilege();
  193860. juce_threadEntryPoint (value);
  193861. return 0;
  193862. }
  193863. void* juce_createThread (void* userData)
  193864. {
  193865. pthread_t handle = 0;
  193866. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  193867. {
  193868. pthread_detach (handle);
  193869. return (void*)handle;
  193870. }
  193871. return 0;
  193872. }
  193873. void juce_killThread (void* handle)
  193874. {
  193875. if (handle != 0)
  193876. pthread_cancel ((pthread_t)handle);
  193877. }
  193878. void juce_setCurrentThreadName (const String& /*name*/)
  193879. {
  193880. }
  193881. Thread::ThreadID Thread::getCurrentThreadId()
  193882. {
  193883. return (ThreadID) pthread_self();
  193884. }
  193885. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  193886. // priority of the current thread
  193887. bool juce_setThreadPriority (void* handle, int priority)
  193888. {
  193889. struct sched_param param;
  193890. int policy, maxp, minp, pri;
  193891. if (handle == 0)
  193892. handle = (void*) pthread_self();
  193893. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  193894. && policy != SCHED_OTHER)
  193895. {
  193896. minp = sched_get_priority_min(policy);
  193897. maxp = sched_get_priority_max(policy);
  193898. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  193899. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  193900. // Realtime process priority
  193901. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  193902. else
  193903. // High process priority
  193904. param.__sched_priority = minp + pri;
  193905. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  193906. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  193907. }
  193908. return false;
  193909. }
  193910. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  193911. {
  193912. #if SUPPORT_AFFINITIES
  193913. cpu_set_t affinity;
  193914. CPU_ZERO (&affinity);
  193915. for (int i = 0; i < 32; ++i)
  193916. if ((affinityMask & (1 << i)) != 0)
  193917. CPU_SET (i, &affinity);
  193918. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  193919. sched_yield();
  193920. #else
  193921. /* affinities aren't supported because either the appropriate header files weren't found,
  193922. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  193923. */
  193924. jassertfalse
  193925. #endif
  193926. }
  193927. void Thread::yield()
  193928. {
  193929. sched_yield();
  193930. }
  193931. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  193932. void Process::setPriority (ProcessPriority prior)
  193933. {
  193934. struct sched_param param;
  193935. int policy, maxp, minp;
  193936. const int p = (int) prior;
  193937. if (p <= 1)
  193938. policy = SCHED_OTHER;
  193939. else
  193940. policy = SCHED_RR;
  193941. minp = sched_get_priority_min (policy);
  193942. maxp = sched_get_priority_max (policy);
  193943. if (p < 2)
  193944. param.__sched_priority = 0;
  193945. else if (p == 2 )
  193946. // Set to middle of lower realtime priority range
  193947. param.__sched_priority = minp + (maxp - minp) / 4;
  193948. else
  193949. // Set to middle of higher realtime priority range
  193950. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  193951. pthread_setschedparam (pthread_self(), policy, &param);
  193952. }
  193953. void Process::terminate()
  193954. {
  193955. exit (0);
  193956. }
  193957. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  193958. {
  193959. static char testResult = 0;
  193960. if (testResult == 0)
  193961. {
  193962. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  193963. if (testResult >= 0)
  193964. {
  193965. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  193966. testResult = 1;
  193967. }
  193968. }
  193969. return testResult < 0;
  193970. }
  193971. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  193972. {
  193973. return juce_isRunningUnderDebugger();
  193974. }
  193975. void Process::raisePrivilege()
  193976. {
  193977. // If running suid root, change effective user
  193978. // to root
  193979. if (geteuid() != 0 && getuid() == 0)
  193980. {
  193981. setreuid (geteuid(), getuid());
  193982. setregid (getegid(), getgid());
  193983. }
  193984. }
  193985. void Process::lowerPrivilege()
  193986. {
  193987. // If runing suid root, change effective user
  193988. // back to real user
  193989. if (geteuid() == 0 && getuid() != 0)
  193990. {
  193991. setreuid (geteuid(), getuid());
  193992. setregid (getegid(), getgid());
  193993. }
  193994. }
  193995. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  193996. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  193997. {
  193998. return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  193999. }
  194000. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194001. {
  194002. dlclose(handle);
  194003. }
  194004. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194005. {
  194006. return dlsym (libraryHandle, procedureName.toCString());
  194007. }
  194008. #endif
  194009. #endif
  194010. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194011. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194012. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194013. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194014. // compiled on its own).
  194015. #if JUCE_INCLUDED_FILE
  194016. #ifdef JUCE_DEBUG
  194017. #define JUCE_DEBUG_XERRORS 1
  194018. #endif
  194019. extern Display* display;
  194020. extern Window juce_messageWindowHandle;
  194021. static String localClipboardContent;
  194022. static Atom atom_UTF8_STRING;
  194023. static Atom atom_CLIPBOARD;
  194024. static Atom atom_TARGETS;
  194025. static void initSelectionAtoms()
  194026. {
  194027. static bool isInitialised = false;
  194028. if (! isInitialised)
  194029. {
  194030. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194031. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194032. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194033. }
  194034. }
  194035. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194036. // works only for strings shorter than 1000000 bytes
  194037. static String juce_readWindowProperty (Window window, Atom prop,
  194038. Atom fmt, // XA_STRING or UTF8_STRING
  194039. bool deleteAfterReading)
  194040. {
  194041. String returnData;
  194042. char* clipData;
  194043. Atom actualType;
  194044. int actualFormat;
  194045. unsigned long numItems, bytesLeft;
  194046. if (XGetWindowProperty (display, window, prop,
  194047. 0L /* offset */, 1000000 /* length (max) */, False,
  194048. AnyPropertyType /* format */,
  194049. &actualType, &actualFormat, &numItems, &bytesLeft,
  194050. (unsigned char**) &clipData) == Success)
  194051. {
  194052. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194053. {
  194054. returnData = String::fromUTF8 (clipData, numItems);
  194055. }
  194056. else if (actualType == XA_STRING && actualFormat == 8)
  194057. {
  194058. returnData = String (clipData, numItems);
  194059. }
  194060. if (clipData != 0)
  194061. XFree (clipData);
  194062. jassert (bytesLeft == 0 || numItems == 1000000);
  194063. }
  194064. if (deleteAfterReading)
  194065. XDeleteProperty (display, window, prop);
  194066. return returnData;
  194067. }
  194068. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194069. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194070. {
  194071. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194072. // The selection owner will be asked to set the JUCE_SEL property on the
  194073. // juce_messageWindowHandle with the selection content
  194074. XConvertSelection (display, selection, requested_format, property_name,
  194075. juce_messageWindowHandle, CurrentTime);
  194076. int timeoutMs = 200; // will wait at most for 200 ms
  194077. do
  194078. {
  194079. XEvent event;
  194080. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194081. {
  194082. if (event.xselection.property == property_name)
  194083. {
  194084. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194085. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194086. event.xselection.property,
  194087. requested_format, true);
  194088. return true;
  194089. }
  194090. else
  194091. {
  194092. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194093. }
  194094. }
  194095. // not very elegant.. we could do a select() or something like that...
  194096. // however clipboard content requesting is inherently slow on x11, it
  194097. // often takes 50ms or more so...
  194098. Thread::sleep (4);
  194099. timeoutMs -= 4;
  194100. }
  194101. while (timeoutMs > 0);
  194102. DBG("timeout for juce_requestSelectionContent");
  194103. return false;
  194104. }
  194105. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194106. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194107. {
  194108. initSelectionAtoms();
  194109. // the selection content is sent to the target window as a window property
  194110. XSelectionEvent reply;
  194111. reply.type = SelectionNotify;
  194112. reply.display = evt.display;
  194113. reply.requestor = evt.requestor;
  194114. reply.selection = evt.selection;
  194115. reply.target = evt.target;
  194116. reply.property = None; // == "fail"
  194117. reply.time = evt.time;
  194118. HeapBlock <char> data;
  194119. int propertyFormat = 0, numDataItems = 0;
  194120. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194121. {
  194122. if (evt.target == XA_STRING)
  194123. {
  194124. // format data according to system locale
  194125. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194126. data.calloc (numDataItems + 1);
  194127. localClipboardContent.copyToCString (data, numDataItems);
  194128. propertyFormat = 8; // bits/item
  194129. }
  194130. else if (evt.target == atom_UTF8_STRING)
  194131. {
  194132. // translate to utf8
  194133. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194134. data.calloc (numDataItems + 1);
  194135. localClipboardContent.copyToUTF8 (data, numDataItems);
  194136. propertyFormat = 8; // bits/item
  194137. }
  194138. else if (evt.target == atom_TARGETS)
  194139. {
  194140. // another application wants to know what we are able to send
  194141. numDataItems = 2;
  194142. propertyFormat = 32; // atoms are 32-bit
  194143. data.calloc (numDataItems * 4);
  194144. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194145. atoms[0] = atom_UTF8_STRING;
  194146. atoms[1] = XA_STRING;
  194147. }
  194148. }
  194149. else
  194150. {
  194151. DBG ("requested unsupported clipboard");
  194152. }
  194153. if (data != 0)
  194154. {
  194155. const int maxReasonableSelectionSize = 1000000;
  194156. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194157. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194158. {
  194159. XChangeProperty (evt.display, evt.requestor,
  194160. evt.property, evt.target,
  194161. propertyFormat /* 8 or 32 */, PropModeReplace,
  194162. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194163. reply.property = evt.property; // " == success"
  194164. }
  194165. }
  194166. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194167. }
  194168. void SystemClipboard::copyTextToClipboard (const String& clipText)
  194169. {
  194170. initSelectionAtoms();
  194171. localClipboardContent = clipText;
  194172. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194173. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194174. }
  194175. const String SystemClipboard::getTextFromClipboard()
  194176. {
  194177. initSelectionAtoms();
  194178. String content;
  194179. Atom selection = XA_PRIMARY;
  194180. Window selectionOwner = None;
  194181. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194182. {
  194183. selection = atom_CLIPBOARD;
  194184. selectionOwner = XGetSelectionOwner (display, selection);
  194185. }
  194186. if (selectionOwner != None)
  194187. {
  194188. if (selectionOwner == juce_messageWindowHandle)
  194189. {
  194190. content = localClipboardContent;
  194191. }
  194192. else
  194193. {
  194194. // first try: we want an utf8 string
  194195. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194196. if (! ok)
  194197. {
  194198. // second chance, ask for a good old locale-dependent string ..
  194199. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194200. }
  194201. }
  194202. }
  194203. return content;
  194204. }
  194205. #endif
  194206. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194207. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194208. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194209. // compiled on its own).
  194210. #if JUCE_INCLUDED_FILE
  194211. #ifdef JUCE_DEBUG
  194212. #define JUCE_DEBUG_XERRORS 1
  194213. #endif
  194214. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194215. Window juce_messageWindowHandle = None;
  194216. XContext improbableNumber; // This is referenced from Windowing.cpp
  194217. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194218. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194219. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194220. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194221. class InternalMessageQueue
  194222. {
  194223. public:
  194224. InternalMessageQueue()
  194225. : bytesInSocket (0)
  194226. {
  194227. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194228. (void) ret; jassert (ret == 0);
  194229. //setNonBlocking (fd[0]);
  194230. //setNonBlocking (fd[1]);
  194231. }
  194232. ~InternalMessageQueue()
  194233. {
  194234. close (fd[0]);
  194235. close (fd[1]);
  194236. }
  194237. void postMessage (Message* msg)
  194238. {
  194239. const int maxBytesInSocketQueue = 128;
  194240. ScopedLock sl (lock);
  194241. queue.add (msg);
  194242. if (bytesInSocket < maxBytesInSocketQueue)
  194243. {
  194244. ++bytesInSocket;
  194245. ScopedUnlock ul (lock);
  194246. const unsigned char x = 0xff;
  194247. size_t bytesWritten = write (fd[0], &x, 1);
  194248. (void) bytesWritten;
  194249. }
  194250. }
  194251. bool isEmpty() const
  194252. {
  194253. ScopedLock sl (lock);
  194254. return queue.size() == 0;
  194255. }
  194256. Message* popNextMessage()
  194257. {
  194258. ScopedLock sl (lock);
  194259. if (bytesInSocket > 0)
  194260. {
  194261. --bytesInSocket;
  194262. ScopedUnlock ul (lock);
  194263. unsigned char x;
  194264. size_t numBytes = read (fd[1], &x, 1);
  194265. (void) numBytes;
  194266. }
  194267. Message* m = queue[0];
  194268. queue.remove (0, false /* deleteObject */);
  194269. return m;
  194270. }
  194271. int getWaitHandle() const { return fd[1]; }
  194272. private:
  194273. CriticalSection lock;
  194274. OwnedArray <Message> queue;
  194275. int fd[2];
  194276. int bytesInSocket;
  194277. static bool setNonBlocking (int handle)
  194278. {
  194279. int socketFlags = fcntl (handle, F_GETFL, 0);
  194280. if (socketFlags == -1)
  194281. return false;
  194282. socketFlags |= O_NONBLOCK;
  194283. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194284. }
  194285. };
  194286. struct MessageThreadFuncCall
  194287. {
  194288. enum { uniqueID = 0x73774623 };
  194289. MessageCallbackFunction* func;
  194290. void* parameter;
  194291. void* result;
  194292. CriticalSection lock;
  194293. WaitableEvent event;
  194294. };
  194295. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194296. // error handling in X11
  194297. static bool errorOccurred = false;
  194298. static bool keyboardBreakOccurred = false;
  194299. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194300. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194301. // Usually happens when client-server connection is broken
  194302. static int ioErrorHandler (Display* display)
  194303. {
  194304. DBG ("ERROR: connection to X server broken.. terminating.");
  194305. errorOccurred = true;
  194306. if (JUCEApplication::getInstance() != 0)
  194307. Process::terminate();
  194308. return 0;
  194309. }
  194310. // A protocol error has occurred
  194311. static int errorHandler (Display* display, XErrorEvent* event)
  194312. {
  194313. #ifdef JUCE_DEBUG_XERRORS
  194314. char errorStr[64] = { 0 };
  194315. char requestStr[64] = { 0 };
  194316. XGetErrorText (display, event->error_code, errorStr, 64);
  194317. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194318. "Unknown", requestStr, 64);
  194319. DBG ("ERROR: X returned " + String (errorStr) + " for operation " + String (requestStr));
  194320. #endif
  194321. return 0;
  194322. }
  194323. // Breakin from keyboard
  194324. static void signalHandler (int sig)
  194325. {
  194326. if (sig == SIGINT)
  194327. {
  194328. keyboardBreakOccurred = true;
  194329. return;
  194330. }
  194331. static bool reentrant = false;
  194332. if (! reentrant)
  194333. {
  194334. reentrant = true;
  194335. // Illegal instruction
  194336. fflush (stdout);
  194337. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194338. errorOccurred = true;
  194339. if (JUCEApplication::getInstance() != 0)
  194340. Process::terminate();
  194341. }
  194342. else
  194343. {
  194344. if (JUCEApplication::getInstance() != 0)
  194345. exit(0);
  194346. }
  194347. }
  194348. void MessageManager::doPlatformSpecificInitialisation()
  194349. {
  194350. // Initialise xlib for multiple thread support
  194351. static bool initThreadCalled = false;
  194352. if (! initThreadCalled)
  194353. {
  194354. if (! XInitThreads())
  194355. {
  194356. // This is fatal! Print error and closedown
  194357. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194358. if (JUCEApplication::getInstance() != 0)
  194359. Process::terminate();
  194360. return;
  194361. }
  194362. initThreadCalled = true;
  194363. }
  194364. // This is called if the client/server connection is broken
  194365. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194366. // This is called if a protocol error occurs
  194367. oldErrorHandler = XSetErrorHandler (errorHandler);
  194368. // Install signal handler for break-in
  194369. struct sigaction saction;
  194370. sigset_t maskSet;
  194371. sigemptyset (&maskSet);
  194372. saction.sa_handler = signalHandler;
  194373. saction.sa_mask = maskSet;
  194374. saction.sa_flags = 0;
  194375. sigaction (SIGINT, &saction, NULL);
  194376. #ifndef _DEBUG
  194377. // Setup signal handlers for various fatal errors
  194378. sigaction (SIGILL, &saction, NULL);
  194379. sigaction (SIGBUS, &saction, NULL);
  194380. sigaction (SIGFPE, &saction, NULL);
  194381. sigaction (SIGSEGV, &saction, NULL);
  194382. sigaction (SIGSYS, &saction, NULL);
  194383. #endif
  194384. // Create the internal message queue
  194385. juce_internalMessageQueue = new InternalMessageQueue();
  194386. // Try to connect to a display
  194387. String displayName (getenv ("DISPLAY"));
  194388. if (displayName.isEmpty())
  194389. displayName = ":0.0";
  194390. display = XOpenDisplay (displayName.toCString());
  194391. if (display == 0)
  194392. {
  194393. // This is not fatal! we can run headless.
  194394. return;
  194395. }
  194396. // Get defaults for various properties
  194397. int screen = DefaultScreen (display);
  194398. Window root = RootWindow (display, screen);
  194399. Visual* visual = DefaultVisual (display, screen);
  194400. // Create a context to store user data associated with Windows we
  194401. // create in WindowDriver
  194402. improbableNumber = XUniqueContext();
  194403. // We're only interested in client messages for this window
  194404. // which are always sent
  194405. XSetWindowAttributes swa;
  194406. swa.event_mask = NoEventMask;
  194407. // Create our message window (this will never be mapped)
  194408. juce_messageWindowHandle = XCreateWindow (display, root,
  194409. 0, 0, 1, 1, 0, 0, InputOnly,
  194410. visual, CWEventMask, &swa);
  194411. }
  194412. void MessageManager::doPlatformSpecificShutdown()
  194413. {
  194414. deleteAndZero (juce_internalMessageQueue);
  194415. if (display != 0 && ! errorOccurred)
  194416. {
  194417. XDestroyWindow (display, juce_messageWindowHandle);
  194418. XCloseDisplay (display);
  194419. // reset pointers
  194420. juce_messageWindowHandle = 0;
  194421. display = 0;
  194422. // Restore original error handlers
  194423. XSetIOErrorHandler (oldIOErrorHandler);
  194424. oldIOErrorHandler = 0;
  194425. XSetErrorHandler (oldErrorHandler);
  194426. oldErrorHandler = 0;
  194427. }
  194428. }
  194429. bool juce_postMessageToSystemQueue (void* message)
  194430. {
  194431. if (errorOccurred)
  194432. return false;
  194433. juce_internalMessageQueue->postMessage ((Message*) message);
  194434. return true;
  194435. }
  194436. void MessageManager::broadcastMessage (const String& value) throw()
  194437. {
  194438. }
  194439. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194440. void* parameter)
  194441. {
  194442. if (errorOccurred)
  194443. return 0;
  194444. if (! isThisTheMessageThread())
  194445. {
  194446. MessageThreadFuncCall messageCallContext;
  194447. messageCallContext.func = func;
  194448. messageCallContext.parameter = parameter;
  194449. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194450. 0, 0, &messageCallContext));
  194451. // Wait for it to complete before continuing
  194452. messageCallContext.event.wait();
  194453. return messageCallContext.result;
  194454. }
  194455. else
  194456. {
  194457. // Just call the function directly
  194458. return func (parameter);
  194459. }
  194460. }
  194461. // Wait for an event (either XEvent, or an internal Message)
  194462. static bool juce_sleepUntilEvent (const int timeoutMs)
  194463. {
  194464. if (! juce_internalMessageQueue->isEmpty())
  194465. return true;
  194466. if (display != 0)
  194467. {
  194468. ScopedXLock xlock;
  194469. if (XPending (display))
  194470. return true;
  194471. }
  194472. struct timeval tv;
  194473. tv.tv_sec = 0;
  194474. tv.tv_usec = timeoutMs * 1000;
  194475. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194476. int fdmax = fd0;
  194477. fd_set readset;
  194478. FD_ZERO (&readset);
  194479. FD_SET (fd0, &readset);
  194480. if (display != 0)
  194481. {
  194482. ScopedXLock xlock;
  194483. int fd1 = XConnectionNumber (display);
  194484. FD_SET (fd1, &readset);
  194485. fdmax = jmax (fd0, fd1);
  194486. }
  194487. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194488. return (ret > 0); // ret <= 0 if error or timeout
  194489. }
  194490. // Handle next XEvent (if any)
  194491. static bool juce_dispatchNextXEvent()
  194492. {
  194493. if (display == 0)
  194494. return false;
  194495. XEvent evt;
  194496. {
  194497. ScopedXLock xlock;
  194498. if (! XPending (display))
  194499. return false;
  194500. XNextEvent (display, &evt);
  194501. }
  194502. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194503. {
  194504. juce_handleSelectionRequest (evt.xselectionrequest);
  194505. }
  194506. else if (evt.xany.window != juce_messageWindowHandle)
  194507. {
  194508. juce_windowMessageReceive (&evt);
  194509. }
  194510. return true;
  194511. }
  194512. // Handle next internal Message (if any)
  194513. static bool juce_dispatchNextInternalMessage()
  194514. {
  194515. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194516. if (msg == 0)
  194517. return false;
  194518. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194519. {
  194520. // Handle callback message
  194521. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194522. call->result = (*(call->func)) (call->parameter);
  194523. call->event.signal();
  194524. }
  194525. else
  194526. {
  194527. // Handle "normal" messages
  194528. MessageManager::getInstance()->deliverMessage (msg.release());
  194529. }
  194530. return true;
  194531. }
  194532. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194533. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194534. {
  194535. for (;;)
  194536. {
  194537. if (errorOccurred)
  194538. break;
  194539. if (keyboardBreakOccurred)
  194540. {
  194541. errorOccurred = true;
  194542. if (JUCEApplication::getInstance() != 0)
  194543. Process::terminate();
  194544. break;
  194545. }
  194546. static int totalEventCount = 0;
  194547. ++totalEventCount;
  194548. // The purpose here is to give either priority to XEvents or
  194549. // to internal messages This is necessary to keep a "good"
  194550. // behaviour when the cpu is overloaded
  194551. if (totalEventCount & 1)
  194552. {
  194553. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194554. return true;
  194555. }
  194556. else
  194557. {
  194558. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194559. return true;
  194560. }
  194561. if (returnIfNoPendingMessages) // early exit
  194562. break;
  194563. // the timeout is to be on the safe side, but it does not seem to be useful
  194564. juce_sleepUntilEvent (2000);
  194565. }
  194566. return false;
  194567. }
  194568. #endif
  194569. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194570. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194571. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194572. // compiled on its own).
  194573. #if JUCE_INCLUDED_FILE
  194574. class FreeTypeFontFace
  194575. {
  194576. public:
  194577. enum FontStyle
  194578. {
  194579. Plain = 0,
  194580. Bold = 1,
  194581. Italic = 2
  194582. };
  194583. struct FontNameIndex
  194584. {
  194585. String fileName;
  194586. int faceIndex;
  194587. };
  194588. FreeTypeFontFace (const String& familyName)
  194589. : hasSerif (false),
  194590. monospaced (false)
  194591. {
  194592. family = familyName;
  194593. }
  194594. void setFileName (const String& name, const int faceIndex, FontStyle style)
  194595. {
  194596. if (names [(int) style].fileName.isEmpty())
  194597. {
  194598. names [(int) style].fileName = name;
  194599. names [(int) style].faceIndex = faceIndex;
  194600. }
  194601. }
  194602. const String& getFamilyName() const throw() { return family; }
  194603. const String& getFileName (const int style, int& faceIndex) const throw()
  194604. {
  194605. faceIndex = names[style].faceIndex;
  194606. return names[style].fileName;
  194607. }
  194608. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194609. bool getMonospaced() const throw() { return monospaced; }
  194610. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194611. bool getSerif() const throw() { return hasSerif; }
  194612. private:
  194613. String family;
  194614. FontNameIndex names[4];
  194615. bool hasSerif, monospaced;
  194616. };
  194617. class FreeTypeInterface : public DeletedAtShutdown
  194618. {
  194619. public:
  194620. FreeTypeInterface()
  194621. : lastFace (0),
  194622. lastBold (false),
  194623. lastItalic (false)
  194624. {
  194625. if (FT_Init_FreeType (&ftLib) != 0)
  194626. {
  194627. ftLib = 0;
  194628. DBG ("Failed to initialize FreeType");
  194629. }
  194630. StringArray fontDirs;
  194631. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194632. fontDirs.removeEmptyStrings (true);
  194633. if (fontDirs.size() == 0)
  194634. {
  194635. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194636. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194637. if (fontsInfo != 0)
  194638. {
  194639. forEachXmlChildElementWithTagName (*fontsInfo, e, "dir")
  194640. {
  194641. fontDirs.add (e->getAllSubText().trim());
  194642. }
  194643. delete fontsInfo;
  194644. }
  194645. }
  194646. if (fontDirs.size() == 0)
  194647. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194648. for (int i = 0; i < fontDirs.size(); ++i)
  194649. enumerateFaces (fontDirs[i]);
  194650. }
  194651. ~FreeTypeInterface()
  194652. {
  194653. if (lastFace != 0)
  194654. FT_Done_Face (lastFace);
  194655. if (ftLib != 0)
  194656. FT_Done_FreeType (ftLib);
  194657. clearSingletonInstance();
  194658. }
  194659. FreeTypeFontFace* findOrCreate (const String& familyName, const bool create = false)
  194660. {
  194661. for (int i = 0; i < faces.size(); i++)
  194662. if (faces[i]->getFamilyName() == familyName)
  194663. return faces[i];
  194664. if (! create)
  194665. return NULL;
  194666. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194667. faces.add (newFace);
  194668. return newFace;
  194669. }
  194670. // Enumerate all font faces available in a given directory
  194671. void enumerateFaces (const String& path)
  194672. {
  194673. File dirPath (path);
  194674. if (path.isEmpty() || ! dirPath.isDirectory())
  194675. return;
  194676. DirectoryIterator di (dirPath, true);
  194677. while (di.next())
  194678. {
  194679. File possible (di.getFile());
  194680. if (possible.hasFileExtension ("ttf")
  194681. || possible.hasFileExtension ("pfb")
  194682. || possible.hasFileExtension ("pcf"))
  194683. {
  194684. FT_Face face;
  194685. int faceIndex = 0;
  194686. int numFaces = 0;
  194687. do
  194688. {
  194689. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194690. faceIndex, &face) == 0)
  194691. {
  194692. if (faceIndex == 0)
  194693. numFaces = face->num_faces;
  194694. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194695. {
  194696. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194697. int style = (int) FreeTypeFontFace::Plain;
  194698. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194699. style |= (int) FreeTypeFontFace::Bold;
  194700. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194701. style |= (int) FreeTypeFontFace::Italic;
  194702. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194703. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194704. // Surely there must be a better way to do this?
  194705. const String name (face->family_name);
  194706. newFace->setSerif (! (name.containsIgnoreCase ("Sans")
  194707. || name.containsIgnoreCase ("Verdana")
  194708. || name.containsIgnoreCase ("Arial")));
  194709. }
  194710. FT_Done_Face (face);
  194711. }
  194712. ++faceIndex;
  194713. }
  194714. while (faceIndex < numFaces);
  194715. }
  194716. }
  194717. }
  194718. // Create a FreeType face object for a given font
  194719. FT_Face createFT_Face (const String& fontName, const bool bold, const bool italic)
  194720. {
  194721. FT_Face face = 0;
  194722. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194723. {
  194724. face = lastFace;
  194725. }
  194726. else
  194727. {
  194728. if (lastFace != 0)
  194729. {
  194730. FT_Done_Face (lastFace);
  194731. lastFace = 0;
  194732. }
  194733. lastFontName = fontName;
  194734. lastBold = bold;
  194735. lastItalic = italic;
  194736. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194737. if (ftFace != 0)
  194738. {
  194739. int style = (int) FreeTypeFontFace::Plain;
  194740. if (bold)
  194741. style |= (int) FreeTypeFontFace::Bold;
  194742. if (italic)
  194743. style |= (int) FreeTypeFontFace::Italic;
  194744. int faceIndex;
  194745. String fileName (ftFace->getFileName (style, faceIndex));
  194746. if (fileName.isEmpty())
  194747. {
  194748. style ^= (int) FreeTypeFontFace::Bold;
  194749. fileName = ftFace->getFileName (style, faceIndex);
  194750. if (fileName.isEmpty())
  194751. {
  194752. style ^= (int) FreeTypeFontFace::Bold;
  194753. style ^= (int) FreeTypeFontFace::Italic;
  194754. fileName = ftFace->getFileName (style, faceIndex);
  194755. if (! fileName.length())
  194756. {
  194757. style ^= (int) FreeTypeFontFace::Bold;
  194758. fileName = ftFace->getFileName (style, faceIndex);
  194759. }
  194760. }
  194761. }
  194762. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194763. {
  194764. face = lastFace;
  194765. // If there isn't a unicode charmap then select the first one.
  194766. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194767. FT_Set_Charmap (face, face->charmaps[0]);
  194768. }
  194769. }
  194770. }
  194771. return face;
  194772. }
  194773. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character)
  194774. {
  194775. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194776. const float height = (float) (face->ascender - face->descender);
  194777. const float scaleX = 1.0f / height;
  194778. const float scaleY = -1.0f / height;
  194779. Path destShape;
  194780. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194781. || face->glyph->format != ft_glyph_format_outline)
  194782. {
  194783. return false;
  194784. }
  194785. const FT_Outline* const outline = &face->glyph->outline;
  194786. const short* const contours = outline->contours;
  194787. const char* const tags = outline->tags;
  194788. FT_Vector* const points = outline->points;
  194789. for (int c = 0; c < outline->n_contours; c++)
  194790. {
  194791. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194792. const int endPoint = contours[c];
  194793. for (int p = startPoint; p <= endPoint; p++)
  194794. {
  194795. const float x = scaleX * points[p].x;
  194796. const float y = scaleY * points[p].y;
  194797. if (p == startPoint)
  194798. {
  194799. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194800. {
  194801. float x2 = scaleX * points [endPoint].x;
  194802. float y2 = scaleY * points [endPoint].y;
  194803. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194804. {
  194805. x2 = (x + x2) * 0.5f;
  194806. y2 = (y + y2) * 0.5f;
  194807. }
  194808. destShape.startNewSubPath (x2, y2);
  194809. }
  194810. else
  194811. {
  194812. destShape.startNewSubPath (x, y);
  194813. }
  194814. }
  194815. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194816. {
  194817. if (p != startPoint)
  194818. destShape.lineTo (x, y);
  194819. }
  194820. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194821. {
  194822. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194823. float x2 = scaleX * points [nextIndex].x;
  194824. float y2 = scaleY * points [nextIndex].y;
  194825. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194826. {
  194827. x2 = (x + x2) * 0.5f;
  194828. y2 = (y + y2) * 0.5f;
  194829. }
  194830. else
  194831. {
  194832. ++p;
  194833. }
  194834. destShape.quadraticTo (x, y, x2, y2);
  194835. }
  194836. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194837. {
  194838. if (p >= endPoint)
  194839. return false;
  194840. const int next1 = p + 1;
  194841. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194842. const float x2 = scaleX * points [next1].x;
  194843. const float y2 = scaleY * points [next1].y;
  194844. const float x3 = scaleX * points [next2].x;
  194845. const float y3 = scaleY * points [next2].y;
  194846. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194847. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194848. return false;
  194849. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194850. p += 2;
  194851. }
  194852. }
  194853. destShape.closeSubPath();
  194854. }
  194855. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  194856. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  194857. addKerning (face, dest, character, glyphIndex);
  194858. return true;
  194859. }
  194860. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex)
  194861. {
  194862. const float height = (float) (face->ascender - face->descender);
  194863. uint32 rightGlyphIndex;
  194864. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  194865. while (rightGlyphIndex != 0)
  194866. {
  194867. FT_Vector kerning;
  194868. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  194869. {
  194870. if (kerning.x != 0)
  194871. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  194872. }
  194873. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  194874. }
  194875. }
  194876. // Add a glyph to a font
  194877. bool addGlyphToFont (const uint32 character,
  194878. const tchar* fontName, bool bold, bool italic,
  194879. CustomTypeface& dest)
  194880. {
  194881. FT_Face face = createFT_Face (fontName, bold, italic);
  194882. if (face != 0)
  194883. return addGlyph (face, dest, character);
  194884. return false;
  194885. }
  194886. void getFamilyNames (StringArray& familyNames) const
  194887. {
  194888. for (int i = 0; i < faces.size(); i++)
  194889. familyNames.add (faces[i]->getFamilyName());
  194890. }
  194891. void getMonospacedNames (StringArray& monoSpaced) const
  194892. {
  194893. for (int i = 0; i < faces.size(); i++)
  194894. if (faces[i]->getMonospaced())
  194895. monoSpaced.add (faces[i]->getFamilyName());
  194896. }
  194897. void getSerifNames (StringArray& serif) const
  194898. {
  194899. for (int i = 0; i < faces.size(); i++)
  194900. if (faces[i]->getSerif())
  194901. serif.add (faces[i]->getFamilyName());
  194902. }
  194903. void getSansSerifNames (StringArray& sansSerif) const
  194904. {
  194905. for (int i = 0; i < faces.size(); i++)
  194906. if (! faces[i]->getSerif())
  194907. sansSerif.add (faces[i]->getFamilyName());
  194908. }
  194909. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  194910. private:
  194911. FT_Library ftLib;
  194912. FT_Face lastFace;
  194913. String lastFontName;
  194914. bool lastBold, lastItalic;
  194915. OwnedArray<FreeTypeFontFace> faces;
  194916. };
  194917. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  194918. class FreetypeTypeface : public CustomTypeface
  194919. {
  194920. public:
  194921. FreetypeTypeface (const Font& font)
  194922. {
  194923. FT_Face face = FreeTypeInterface::getInstance()
  194924. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  194925. if (face == 0)
  194926. {
  194927. #ifdef JUCE_DEBUG
  194928. String msg ("Failed to create typeface: ");
  194929. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  194930. DBG (msg);
  194931. #endif
  194932. }
  194933. else
  194934. {
  194935. setCharacteristics (font.getTypefaceName(),
  194936. face->ascender / (float) (face->ascender - face->descender),
  194937. font.isBold(), font.isItalic(),
  194938. L' ');
  194939. }
  194940. }
  194941. bool loadGlyphIfPossible (juce_wchar character)
  194942. {
  194943. return FreeTypeInterface::getInstance()
  194944. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  194945. }
  194946. };
  194947. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  194948. {
  194949. return new FreetypeTypeface (font);
  194950. }
  194951. const StringArray Font::findAllTypefaceNames()
  194952. {
  194953. StringArray s;
  194954. FreeTypeInterface::getInstance()->getFamilyNames (s);
  194955. s.sort (true);
  194956. return s;
  194957. }
  194958. static const String pickBestFont (const StringArray& names,
  194959. const char* const choicesString)
  194960. {
  194961. StringArray choices;
  194962. choices.addTokens (String (choicesString), ",", String::empty);
  194963. choices.trim();
  194964. choices.removeEmptyStrings();
  194965. int i, j;
  194966. for (j = 0; j < choices.size(); ++j)
  194967. if (names.contains (choices[j], true))
  194968. return choices[j];
  194969. for (j = 0; j < choices.size(); ++j)
  194970. for (i = 0; i < names.size(); i++)
  194971. if (names[i].startsWithIgnoreCase (choices[j]))
  194972. return names[i];
  194973. for (j = 0; j < choices.size(); ++j)
  194974. for (i = 0; i < names.size(); i++)
  194975. if (names[i].containsIgnoreCase (choices[j]))
  194976. return names[i];
  194977. return names[0];
  194978. }
  194979. static const String linux_getDefaultSansSerifFontName()
  194980. {
  194981. StringArray allFonts;
  194982. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  194983. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  194984. }
  194985. static const String linux_getDefaultSerifFontName()
  194986. {
  194987. StringArray allFonts;
  194988. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  194989. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  194990. }
  194991. static const String linux_getDefaultMonospacedFontName()
  194992. {
  194993. StringArray allFonts;
  194994. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  194995. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  194996. }
  194997. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  194998. {
  194999. defaultSans = linux_getDefaultSansSerifFontName();
  195000. defaultSerif = linux_getDefaultSerifFontName();
  195001. defaultFixed = linux_getDefaultMonospacedFontName();
  195002. }
  195003. #endif
  195004. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195005. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195006. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195007. // compiled on its own).
  195008. #if JUCE_INCLUDED_FILE
  195009. // These are defined in juce_linux_Messaging.cpp
  195010. extern Display* display;
  195011. extern XContext improbableNumber;
  195012. namespace Atoms
  195013. {
  195014. enum ProtocolItems
  195015. {
  195016. TAKE_FOCUS = 0,
  195017. DELETE_WINDOW = 1
  195018. };
  195019. static Atom Protocols, ProtocolList[2], ChangeState, State,
  195020. ActiveWin, Pid, WindowType, WindowState,
  195021. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  195022. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  195023. XdndActionDescription, XdndActionCopy,
  195024. allowedActions[5],
  195025. allowedMimeTypes[2];
  195026. const unsigned long DndVersion = 3;
  195027. static void initialiseAtoms()
  195028. {
  195029. static bool atomsInitialised = false;
  195030. if (! atomsInitialised)
  195031. {
  195032. atomsInitialised = true;
  195033. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  195034. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  195035. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  195036. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  195037. State = XInternAtom (display, "WM_STATE", True);
  195038. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  195039. Pid = XInternAtom (display, "_NET_WM_PID", False);
  195040. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  195041. WindowState = XInternAtom (display, "_NET_WM_WINDOW_STATE", True);
  195042. XdndAware = XInternAtom (display, "XdndAware", False);
  195043. XdndEnter = XInternAtom (display, "XdndEnter", False);
  195044. XdndLeave = XInternAtom (display, "XdndLeave", False);
  195045. XdndPosition = XInternAtom (display, "XdndPosition", False);
  195046. XdndStatus = XInternAtom (display, "XdndStatus", False);
  195047. XdndDrop = XInternAtom (display, "XdndDrop", False);
  195048. XdndFinished = XInternAtom (display, "XdndFinished", False);
  195049. XdndSelection = XInternAtom (display, "XdndSelection", False);
  195050. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  195051. XdndActionList = XInternAtom (display, "XdndActionList", False);
  195052. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  195053. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  195054. allowedMimeTypes[0] = XInternAtom (display, "text/plain", False);
  195055. allowedMimeTypes[1] = XInternAtom (display, "text/uri-list", False);
  195056. allowedActions[0] = XInternAtom (display, "XdndActionMove", False);
  195057. allowedActions[1] = XdndActionCopy;
  195058. allowedActions[2] = XInternAtom (display, "XdndActionLink", False);
  195059. allowedActions[3] = XInternAtom (display, "XdndActionAsk", False);
  195060. allowedActions[4] = XInternAtom (display, "XdndActionPrivate", False);
  195061. }
  195062. }
  195063. }
  195064. namespace Keys
  195065. {
  195066. enum MouseButtons
  195067. {
  195068. NoButton = 0,
  195069. LeftButton = 1,
  195070. MiddleButton = 2,
  195071. RightButton = 3,
  195072. WheelUp = 4,
  195073. WheelDown = 5
  195074. };
  195075. static int AltMask = 0;
  195076. static int NumLockMask = 0;
  195077. static bool numLock = false;
  195078. static bool capsLock = false;
  195079. static char keyStates [32];
  195080. static const int extendedKeyModifier = 0x10000000;
  195081. }
  195082. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195083. {
  195084. int keysym;
  195085. if (keyCode & Keys::extendedKeyModifier)
  195086. {
  195087. keysym = 0xff00 | (keyCode & 0xff);
  195088. }
  195089. else
  195090. {
  195091. keysym = keyCode;
  195092. if (keysym == (XK_Tab & 0xff)
  195093. || keysym == (XK_Return & 0xff)
  195094. || keysym == (XK_Escape & 0xff)
  195095. || keysym == (XK_BackSpace & 0xff))
  195096. {
  195097. keysym |= 0xff00;
  195098. }
  195099. }
  195100. ScopedXLock xlock;
  195101. const int keycode = XKeysymToKeycode (display, keysym);
  195102. const int keybyte = keycode >> 3;
  195103. const int keybit = (1 << (keycode & 7));
  195104. return (Keys::keyStates [keybyte] & keybit) != 0;
  195105. }
  195106. #if JUCE_USE_XSHM
  195107. namespace XSHMHelpers
  195108. {
  195109. static int trappedErrorCode = 0;
  195110. extern "C" int errorTrapHandler (Display*, XErrorEvent* err)
  195111. {
  195112. trappedErrorCode = err->error_code;
  195113. return 0;
  195114. }
  195115. static bool isShmAvailable() throw()
  195116. {
  195117. static bool isChecked = false;
  195118. static bool isAvailable = false;
  195119. if (! isChecked)
  195120. {
  195121. isChecked = true;
  195122. int major, minor;
  195123. Bool pixmaps;
  195124. ScopedXLock xlock;
  195125. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195126. {
  195127. trappedErrorCode = 0;
  195128. XErrorHandler oldHandler = XSetErrorHandler (errorTrapHandler);
  195129. XShmSegmentInfo segmentInfo;
  195130. zerostruct (segmentInfo);
  195131. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195132. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195133. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195134. xImage->bytes_per_line * xImage->height,
  195135. IPC_CREAT | 0777)) >= 0)
  195136. {
  195137. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195138. if (segmentInfo.shmaddr != (void*) -1)
  195139. {
  195140. segmentInfo.readOnly = False;
  195141. xImage->data = segmentInfo.shmaddr;
  195142. XSync (display, False);
  195143. if (XShmAttach (display, &segmentInfo) != 0)
  195144. {
  195145. XSync (display, False);
  195146. XShmDetach (display, &segmentInfo);
  195147. isAvailable = true;
  195148. }
  195149. }
  195150. XFlush (display);
  195151. XDestroyImage (xImage);
  195152. shmdt (segmentInfo.shmaddr);
  195153. }
  195154. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195155. XSetErrorHandler (oldHandler);
  195156. if (trappedErrorCode != 0)
  195157. isAvailable = false;
  195158. }
  195159. }
  195160. return isAvailable;
  195161. }
  195162. }
  195163. #endif
  195164. #if JUCE_USE_XRENDER
  195165. namespace XRender
  195166. {
  195167. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195168. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195169. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195170. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195171. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195172. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195173. static tXRenderFindFormat xRenderFindFormat = 0;
  195174. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195175. static bool isAvailable()
  195176. {
  195177. static bool hasLoaded = false;
  195178. if (! hasLoaded)
  195179. {
  195180. ScopedXLock xlock;
  195181. hasLoaded = true;
  195182. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195183. if (h != 0)
  195184. {
  195185. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195186. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195187. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195188. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195189. }
  195190. if (xRenderQueryVersion != 0
  195191. && xRenderFindStandardFormat != 0
  195192. && xRenderFindFormat != 0
  195193. && xRenderFindVisualFormat != 0)
  195194. {
  195195. int major, minor;
  195196. if (xRenderQueryVersion (display, &major, &minor))
  195197. return true;
  195198. }
  195199. xRenderQueryVersion = 0;
  195200. }
  195201. return xRenderQueryVersion != 0;
  195202. }
  195203. static XRenderPictFormat* findPictureFormat()
  195204. {
  195205. ScopedXLock xlock;
  195206. XRenderPictFormat* pictFormat = 0;
  195207. if (isAvailable())
  195208. {
  195209. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195210. if (pictFormat == 0)
  195211. {
  195212. XRenderPictFormat desiredFormat;
  195213. desiredFormat.type = PictTypeDirect;
  195214. desiredFormat.depth = 32;
  195215. desiredFormat.direct.alphaMask = 0xff;
  195216. desiredFormat.direct.redMask = 0xff;
  195217. desiredFormat.direct.greenMask = 0xff;
  195218. desiredFormat.direct.blueMask = 0xff;
  195219. desiredFormat.direct.alpha = 24;
  195220. desiredFormat.direct.red = 16;
  195221. desiredFormat.direct.green = 8;
  195222. desiredFormat.direct.blue = 0;
  195223. pictFormat = xRenderFindFormat (display,
  195224. PictFormatType | PictFormatDepth
  195225. | PictFormatRedMask | PictFormatRed
  195226. | PictFormatGreenMask | PictFormatGreen
  195227. | PictFormatBlueMask | PictFormatBlue
  195228. | PictFormatAlphaMask | PictFormatAlpha,
  195229. &desiredFormat,
  195230. 0);
  195231. }
  195232. }
  195233. return pictFormat;
  195234. }
  195235. }
  195236. #endif
  195237. namespace Visuals
  195238. {
  195239. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195240. {
  195241. ScopedXLock xlock;
  195242. Visual* visual = 0;
  195243. int numVisuals = 0;
  195244. long desiredMask = VisualNoMask;
  195245. XVisualInfo desiredVisual;
  195246. desiredVisual.screen = DefaultScreen (display);
  195247. desiredVisual.depth = desiredDepth;
  195248. desiredMask = VisualScreenMask | VisualDepthMask;
  195249. if (desiredDepth == 32)
  195250. {
  195251. desiredVisual.c_class = TrueColor;
  195252. desiredVisual.red_mask = 0x00FF0000;
  195253. desiredVisual.green_mask = 0x0000FF00;
  195254. desiredVisual.blue_mask = 0x000000FF;
  195255. desiredVisual.bits_per_rgb = 8;
  195256. desiredMask |= VisualClassMask;
  195257. desiredMask |= VisualRedMaskMask;
  195258. desiredMask |= VisualGreenMaskMask;
  195259. desiredMask |= VisualBlueMaskMask;
  195260. desiredMask |= VisualBitsPerRGBMask;
  195261. }
  195262. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195263. desiredMask,
  195264. &desiredVisual,
  195265. &numVisuals);
  195266. if (xvinfos != 0)
  195267. {
  195268. for (int i = 0; i < numVisuals; i++)
  195269. {
  195270. if (xvinfos[i].depth == desiredDepth)
  195271. {
  195272. visual = xvinfos[i].visual;
  195273. break;
  195274. }
  195275. }
  195276. XFree (xvinfos);
  195277. }
  195278. return visual;
  195279. }
  195280. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195281. {
  195282. Visual* visual = 0;
  195283. if (desiredDepth == 32)
  195284. {
  195285. #if JUCE_USE_XSHM
  195286. if (XSHMHelpers::isShmAvailable())
  195287. {
  195288. #if JUCE_USE_XRENDER
  195289. if (XRender::isAvailable())
  195290. {
  195291. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195292. if (pictFormat != 0)
  195293. {
  195294. int numVisuals = 0;
  195295. XVisualInfo desiredVisual;
  195296. desiredVisual.screen = DefaultScreen (display);
  195297. desiredVisual.depth = 32;
  195298. desiredVisual.bits_per_rgb = 8;
  195299. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195300. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195301. &desiredVisual, &numVisuals);
  195302. if (xvinfos != 0)
  195303. {
  195304. for (int i = 0; i < numVisuals; ++i)
  195305. {
  195306. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195307. if (pictVisualFormat != 0
  195308. && pictVisualFormat->type == PictTypeDirect
  195309. && pictVisualFormat->direct.alphaMask)
  195310. {
  195311. visual = xvinfos[i].visual;
  195312. matchedDepth = 32;
  195313. break;
  195314. }
  195315. }
  195316. XFree (xvinfos);
  195317. }
  195318. }
  195319. }
  195320. #endif
  195321. if (visual == 0)
  195322. {
  195323. visual = findVisualWithDepth (32);
  195324. if (visual != 0)
  195325. matchedDepth = 32;
  195326. }
  195327. }
  195328. #endif
  195329. }
  195330. if (visual == 0 && desiredDepth >= 24)
  195331. {
  195332. visual = findVisualWithDepth (24);
  195333. if (visual != 0)
  195334. matchedDepth = 24;
  195335. }
  195336. if (visual == 0 && desiredDepth >= 16)
  195337. {
  195338. visual = findVisualWithDepth (16);
  195339. if (visual != 0)
  195340. matchedDepth = 16;
  195341. }
  195342. return visual;
  195343. }
  195344. }
  195345. class XBitmapImage : public Image
  195346. {
  195347. public:
  195348. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195349. const bool clearImage, const int imageDepth_, Visual* visual)
  195350. : Image (format_, w, h),
  195351. imageDepth (imageDepth_),
  195352. gc (None)
  195353. {
  195354. jassert (format_ == RGB || format_ == ARGB);
  195355. pixelStride = (format_ == RGB) ? 3 : 4;
  195356. lineStride = ((w * pixelStride + 3) & ~3);
  195357. ScopedXLock xlock;
  195358. #if JUCE_USE_XSHM
  195359. usingXShm = false;
  195360. if ((imageDepth > 16) && XSHMHelpers::isShmAvailable())
  195361. {
  195362. zerostruct (segmentInfo);
  195363. segmentInfo.shmid = -1;
  195364. segmentInfo.shmaddr = (char *) -1;
  195365. segmentInfo.readOnly = False;
  195366. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195367. if (xImage != 0)
  195368. {
  195369. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195370. xImage->bytes_per_line * xImage->height,
  195371. IPC_CREAT | 0777)) >= 0)
  195372. {
  195373. if (segmentInfo.shmid != -1)
  195374. {
  195375. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195376. if (segmentInfo.shmaddr != (void*) -1)
  195377. {
  195378. segmentInfo.readOnly = False;
  195379. xImage->data = segmentInfo.shmaddr;
  195380. imageData = (uint8*) segmentInfo.shmaddr;
  195381. if (XShmAttach (display, &segmentInfo) != 0)
  195382. {
  195383. usingXShm = true;
  195384. }
  195385. else
  195386. {
  195387. jassertfalse
  195388. }
  195389. }
  195390. else
  195391. {
  195392. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195393. }
  195394. }
  195395. }
  195396. }
  195397. }
  195398. if (! usingXShm)
  195399. #endif
  195400. {
  195401. imageDataAllocated.malloc (lineStride * h);
  195402. imageData = imageDataAllocated;
  195403. if (format_ == ARGB && clearImage)
  195404. zeromem (imageData, h * lineStride);
  195405. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195406. xImage->width = w;
  195407. xImage->height = h;
  195408. xImage->xoffset = 0;
  195409. xImage->format = ZPixmap;
  195410. xImage->data = (char*) imageData;
  195411. xImage->byte_order = ImageByteOrder (display);
  195412. xImage->bitmap_unit = BitmapUnit (display);
  195413. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195414. xImage->bitmap_pad = 32;
  195415. xImage->depth = pixelStride * 8;
  195416. xImage->bytes_per_line = lineStride;
  195417. xImage->bits_per_pixel = pixelStride * 8;
  195418. xImage->red_mask = 0x00FF0000;
  195419. xImage->green_mask = 0x0000FF00;
  195420. xImage->blue_mask = 0x000000FF;
  195421. if (imageDepth == 16)
  195422. {
  195423. const int pixelStride = 2;
  195424. const int lineStride = ((w * pixelStride + 3) & ~3);
  195425. imageData16Bit.malloc (lineStride * h);
  195426. xImage->data = imageData16Bit;
  195427. xImage->bitmap_pad = 16;
  195428. xImage->depth = pixelStride * 8;
  195429. xImage->bytes_per_line = lineStride;
  195430. xImage->bits_per_pixel = pixelStride * 8;
  195431. xImage->red_mask = visual->red_mask;
  195432. xImage->green_mask = visual->green_mask;
  195433. xImage->blue_mask = visual->blue_mask;
  195434. }
  195435. if (! XInitImage (xImage))
  195436. {
  195437. jassertfalse
  195438. }
  195439. }
  195440. }
  195441. ~XBitmapImage()
  195442. {
  195443. ScopedXLock xlock;
  195444. #if JUCE_USE_XSHM
  195445. if (usingXShm)
  195446. {
  195447. XShmDetach (display, &segmentInfo);
  195448. XFlush (display);
  195449. XDestroyImage (xImage);
  195450. shmdt (segmentInfo.shmaddr);
  195451. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195452. }
  195453. else
  195454. #endif
  195455. {
  195456. xImage->data = 0;
  195457. XDestroyImage (xImage);
  195458. }
  195459. }
  195460. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195461. {
  195462. ScopedXLock xlock;
  195463. if (gc == 0)
  195464. {
  195465. XGCValues gcvalues;
  195466. gcvalues.foreground = None;
  195467. gcvalues.background = None;
  195468. gcvalues.function = GXcopy;
  195469. gcvalues.plane_mask = AllPlanes;
  195470. gcvalues.clip_mask = None;
  195471. gcvalues.graphics_exposures = False;
  195472. gc = XCreateGC (display, window,
  195473. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195474. &gcvalues);
  195475. }
  195476. if (imageDepth == 16)
  195477. {
  195478. const uint32 rMask = xImage->red_mask;
  195479. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195480. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195481. const uint32 gMask = xImage->green_mask;
  195482. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195483. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195484. const uint32 bMask = xImage->blue_mask;
  195485. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195486. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195487. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195488. for (int y = sy; y < sy + dh; ++y)
  195489. {
  195490. const uint8* p = srcData.getPixelPointer (sx, y);
  195491. for (int x = sx; x < sx + dw; ++x)
  195492. {
  195493. const PixelRGB* const pixel = (const PixelRGB*) p;
  195494. p += srcData.pixelStride;
  195495. XPutPixel (xImage, x, y,
  195496. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195497. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195498. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195499. }
  195500. }
  195501. }
  195502. // blit results to screen.
  195503. #if JUCE_USE_XSHM
  195504. if (usingXShm)
  195505. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195506. else
  195507. #endif
  195508. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195509. }
  195510. juce_UseDebuggingNewOperator
  195511. private:
  195512. XImage* xImage;
  195513. const int imageDepth;
  195514. HeapBlock <char> imageData16Bit;
  195515. GC gc;
  195516. #if JUCE_USE_XSHM
  195517. XShmSegmentInfo segmentInfo;
  195518. bool usingXShm;
  195519. #endif
  195520. static int getShiftNeeded (const uint32 mask) throw()
  195521. {
  195522. for (int i = 32; --i >= 0;)
  195523. if (((mask >> i) & 1) != 0)
  195524. return i - 7;
  195525. jassertfalse
  195526. return 0;
  195527. }
  195528. };
  195529. class LinuxComponentPeer : public ComponentPeer
  195530. {
  195531. public:
  195532. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195533. : ComponentPeer (component, windowStyleFlags),
  195534. windowH (0),
  195535. parentWindow (0),
  195536. wx (0),
  195537. wy (0),
  195538. ww (0),
  195539. wh (0),
  195540. fullScreen (false),
  195541. mapped (false),
  195542. visual (0),
  195543. depth (0)
  195544. {
  195545. // it's dangerous to create a window on a thread other than the message thread..
  195546. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195547. repainter = new LinuxRepaintManager (this);
  195548. createWindow();
  195549. setTitle (component->getName());
  195550. }
  195551. ~LinuxComponentPeer()
  195552. {
  195553. // it's dangerous to delete a window on a thread other than the message thread..
  195554. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195555. deleteIconPixmaps();
  195556. destroyWindow();
  195557. windowH = 0;
  195558. }
  195559. void* getNativeHandle() const
  195560. {
  195561. return (void*) windowH;
  195562. }
  195563. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195564. {
  195565. XPointer peer = 0;
  195566. ScopedXLock xlock;
  195567. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195568. {
  195569. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195570. peer = 0;
  195571. }
  195572. return (LinuxComponentPeer*) peer;
  195573. }
  195574. void setVisible (bool shouldBeVisible)
  195575. {
  195576. ScopedXLock xlock;
  195577. if (shouldBeVisible)
  195578. XMapWindow (display, windowH);
  195579. else
  195580. XUnmapWindow (display, windowH);
  195581. }
  195582. void setTitle (const String& title)
  195583. {
  195584. setWindowTitle (windowH, title);
  195585. }
  195586. void setPosition (int x, int y)
  195587. {
  195588. setBounds (x, y, ww, wh, false);
  195589. }
  195590. void setSize (int w, int h)
  195591. {
  195592. setBounds (wx, wy, w, h, false);
  195593. }
  195594. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  195595. {
  195596. fullScreen = isNowFullScreen;
  195597. if (windowH != 0)
  195598. {
  195599. Component::SafePointer<Component> deletionChecker (component);
  195600. wx = x;
  195601. wy = y;
  195602. ww = jmax (1, w);
  195603. wh = jmax (1, h);
  195604. ScopedXLock xlock;
  195605. // Make sure the Window manager does what we want
  195606. XSizeHints* hints = XAllocSizeHints();
  195607. hints->flags = USSize | USPosition;
  195608. hints->width = ww;
  195609. hints->height = wh;
  195610. hints->x = wx;
  195611. hints->y = wy;
  195612. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195613. {
  195614. hints->min_width = hints->max_width = hints->width;
  195615. hints->min_height = hints->max_height = hints->height;
  195616. hints->flags |= PMinSize | PMaxSize;
  195617. }
  195618. XSetWMNormalHints (display, windowH, hints);
  195619. XFree (hints);
  195620. XMoveResizeWindow (display, windowH,
  195621. wx - windowBorder.getLeft(),
  195622. wy - windowBorder.getTop(), ww, wh);
  195623. if (deletionChecker != 0)
  195624. {
  195625. updateBorderSize();
  195626. handleMovedOrResized();
  195627. }
  195628. }
  195629. }
  195630. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195631. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195632. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195633. {
  195634. return relativePosition + getScreenPosition();
  195635. }
  195636. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195637. {
  195638. return screenPosition - getScreenPosition();
  195639. }
  195640. void setMinimised (bool shouldBeMinimised)
  195641. {
  195642. if (shouldBeMinimised)
  195643. {
  195644. Window root = RootWindow (display, DefaultScreen (display));
  195645. XClientMessageEvent clientMsg;
  195646. clientMsg.display = display;
  195647. clientMsg.window = windowH;
  195648. clientMsg.type = ClientMessage;
  195649. clientMsg.format = 32;
  195650. clientMsg.message_type = Atoms::ChangeState;
  195651. clientMsg.data.l[0] = IconicState;
  195652. ScopedXLock xlock;
  195653. XSendEvent (display, root, false,
  195654. SubstructureRedirectMask | SubstructureNotifyMask,
  195655. (XEvent*) &clientMsg);
  195656. }
  195657. else
  195658. {
  195659. setVisible (true);
  195660. }
  195661. }
  195662. bool isMinimised() const
  195663. {
  195664. bool minimised = false;
  195665. unsigned char* stateProp;
  195666. unsigned long nitems, bytesLeft;
  195667. Atom actualType;
  195668. int actualFormat;
  195669. ScopedXLock xlock;
  195670. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195671. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195672. &stateProp) == Success
  195673. && actualType == Atoms::State
  195674. && actualFormat == 32
  195675. && nitems > 0)
  195676. {
  195677. if (((unsigned long*) stateProp)[0] == IconicState)
  195678. minimised = true;
  195679. XFree (stateProp);
  195680. }
  195681. return minimised;
  195682. }
  195683. void setFullScreen (const bool shouldBeFullScreen)
  195684. {
  195685. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195686. setMinimised (false);
  195687. if (fullScreen != shouldBeFullScreen)
  195688. {
  195689. if (shouldBeFullScreen)
  195690. r = Desktop::getInstance().getMainMonitorArea();
  195691. if (! r.isEmpty())
  195692. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195693. getComponent()->repaint();
  195694. }
  195695. }
  195696. bool isFullScreen() const
  195697. {
  195698. return fullScreen;
  195699. }
  195700. bool isChildWindowOf (Window possibleParent) const
  195701. {
  195702. Window* windowList = 0;
  195703. uint32 windowListSize = 0;
  195704. Window parent, root;
  195705. ScopedXLock xlock;
  195706. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195707. {
  195708. if (windowList != 0)
  195709. XFree (windowList);
  195710. return parent == possibleParent;
  195711. }
  195712. return false;
  195713. }
  195714. bool isFrontWindow() const
  195715. {
  195716. Window* windowList = 0;
  195717. uint32 windowListSize = 0;
  195718. bool result = false;
  195719. ScopedXLock xlock;
  195720. Window parent, root = RootWindow (display, DefaultScreen (display));
  195721. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195722. {
  195723. for (int i = windowListSize; --i >= 0;)
  195724. {
  195725. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195726. if (peer != 0)
  195727. {
  195728. result = (peer == this);
  195729. break;
  195730. }
  195731. }
  195732. }
  195733. if (windowList != 0)
  195734. XFree (windowList);
  195735. return result;
  195736. }
  195737. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195738. {
  195739. int x = position.getX();
  195740. int y = position.getY();
  195741. if (((unsigned int) x) >= (unsigned int) ww
  195742. || ((unsigned int) y) >= (unsigned int) wh)
  195743. return false;
  195744. bool inFront = false;
  195745. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195746. {
  195747. Component* const c = Desktop::getInstance().getComponent (i);
  195748. if (inFront)
  195749. {
  195750. if (c->contains (x + wx - c->getScreenX(),
  195751. y + wy - c->getScreenY()))
  195752. {
  195753. return false;
  195754. }
  195755. }
  195756. else if (c == getComponent())
  195757. {
  195758. inFront = true;
  195759. }
  195760. }
  195761. if (trueIfInAChildWindow)
  195762. return true;
  195763. ::Window root, child;
  195764. unsigned int bw, depth;
  195765. int wx, wy, w, h;
  195766. ScopedXLock xlock;
  195767. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195768. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195769. &bw, &depth))
  195770. {
  195771. return false;
  195772. }
  195773. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195774. return false;
  195775. return child == None;
  195776. }
  195777. const BorderSize getFrameSize() const
  195778. {
  195779. return BorderSize();
  195780. }
  195781. bool setAlwaysOnTop (bool alwaysOnTop)
  195782. {
  195783. if (windowH != 0)
  195784. {
  195785. const bool wasVisible = component->isVisible();
  195786. if (wasVisible)
  195787. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195788. {
  195789. ScopedXLock xlock;
  195790. XSetWindowAttributes swa;
  195791. swa.override_redirect = alwaysOnTop ? True : False;
  195792. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195793. }
  195794. if (wasVisible)
  195795. setVisible (true);
  195796. }
  195797. return true;
  195798. }
  195799. void toFront (bool makeActive)
  195800. {
  195801. if (makeActive)
  195802. {
  195803. setVisible (true);
  195804. grabFocus();
  195805. }
  195806. XEvent ev;
  195807. ev.xclient.type = ClientMessage;
  195808. ev.xclient.serial = 0;
  195809. ev.xclient.send_event = True;
  195810. ev.xclient.message_type = Atoms::ActiveWin;
  195811. ev.xclient.window = windowH;
  195812. ev.xclient.format = 32;
  195813. ev.xclient.data.l[0] = 2;
  195814. ev.xclient.data.l[1] = CurrentTime;
  195815. ev.xclient.data.l[2] = 0;
  195816. ev.xclient.data.l[3] = 0;
  195817. ev.xclient.data.l[4] = 0;
  195818. {
  195819. ScopedXLock xlock;
  195820. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195821. False,
  195822. SubstructureRedirectMask | SubstructureNotifyMask,
  195823. &ev);
  195824. XWindowAttributes attr;
  195825. XGetWindowAttributes (display, windowH, &attr);
  195826. if (attr.override_redirect)
  195827. XRaiseWindow (display, windowH);
  195828. XSync (display, False);
  195829. }
  195830. handleBroughtToFront();
  195831. }
  195832. void toBehind (ComponentPeer* other)
  195833. {
  195834. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  195835. jassert (otherPeer != 0); // wrong type of window?
  195836. if (otherPeer != 0)
  195837. {
  195838. setMinimised (false);
  195839. Window newStack[] = { otherPeer->windowH, windowH };
  195840. ScopedXLock xlock;
  195841. XRestackWindows (display, newStack, 2);
  195842. }
  195843. }
  195844. bool isFocused() const
  195845. {
  195846. int revert;
  195847. Window focusedWindow = 0;
  195848. ScopedXLock xlock;
  195849. XGetInputFocus (display, &focusedWindow, &revert);
  195850. return focusedWindow == windowH;
  195851. }
  195852. void grabFocus()
  195853. {
  195854. XWindowAttributes atts;
  195855. ScopedXLock xlock;
  195856. if (windowH != 0
  195857. && XGetWindowAttributes (display, windowH, &atts)
  195858. && atts.map_state == IsViewable
  195859. && ! isFocused())
  195860. {
  195861. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  195862. isActiveApplication = true;
  195863. }
  195864. }
  195865. void textInputRequired (const Point<int>&)
  195866. {
  195867. }
  195868. void repaint (int x, int y, int w, int h)
  195869. {
  195870. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  195871. 0, 0,
  195872. getComponent()->getWidth(),
  195873. getComponent()->getHeight()))
  195874. {
  195875. repainter->repaint (x, y, w, h);
  195876. }
  195877. }
  195878. void performAnyPendingRepaintsNow()
  195879. {
  195880. repainter->performAnyPendingRepaintsNow();
  195881. }
  195882. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195883. {
  195884. ScopedXLock xlock;
  195885. const int width = image.getWidth();
  195886. const int height = image.getHeight();
  195887. HeapBlock <char> colour (width * height);
  195888. int index = 0;
  195889. for (int y = 0; y < height; ++y)
  195890. for (int x = 0; x < width; ++x)
  195891. colour[index++] = static_cast<char> (image.getPixelAt (x, y).getARGB());
  195892. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195893. 0, colour.getData(),
  195894. width, height, 32, 0);
  195895. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195896. width, height, 24);
  195897. GC gc = XCreateGC (display, pixmap, 0, 0);
  195898. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195899. XFreeGC (display, gc);
  195900. return pixmap;
  195901. }
  195902. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195903. {
  195904. ScopedXLock xlock;
  195905. const int width = image.getWidth();
  195906. const int height = image.getHeight();
  195907. const int stride = (width + 7) >> 3;
  195908. HeapBlock <char> mask;
  195909. mask.calloc (stride * height);
  195910. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195911. for (int y = 0; y < height; ++y)
  195912. {
  195913. for (int x = 0; x < width; ++x)
  195914. {
  195915. const char bit = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195916. const int offset = y * stride + (x >> 3);
  195917. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195918. mask[offset] |= bit;
  195919. }
  195920. }
  195921. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195922. mask.getData(), width, height, 1, 0, 1);
  195923. }
  195924. void setIcon (const Image& newIcon)
  195925. {
  195926. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  195927. HeapBlock <unsigned long> data (dataSize);
  195928. int index = 0;
  195929. data[index++] = newIcon.getWidth();
  195930. data[index++] = newIcon.getHeight();
  195931. for (int y = 0; y < newIcon.getHeight(); ++y)
  195932. for (int x = 0; x < newIcon.getWidth(); ++x)
  195933. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  195934. ScopedXLock xlock;
  195935. XChangeProperty (display, windowH,
  195936. XInternAtom (display, "_NET_WM_ICON", False),
  195937. XA_CARDINAL, 32, PropModeReplace,
  195938. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  195939. deleteIconPixmaps();
  195940. XWMHints* wmHints = XGetWMHints (display, windowH);
  195941. if (wmHints == 0)
  195942. wmHints = XAllocWMHints();
  195943. wmHints->flags |= IconPixmapHint | IconMaskHint;
  195944. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  195945. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  195946. XSetWMHints (display, windowH, wmHints);
  195947. XFree (wmHints);
  195948. XSync (display, False);
  195949. }
  195950. void deleteIconPixmaps()
  195951. {
  195952. ScopedXLock xlock;
  195953. XWMHints* wmHints = XGetWMHints (display, windowH);
  195954. if (wmHints != 0)
  195955. {
  195956. if ((wmHints->flags & IconPixmapHint) != 0)
  195957. {
  195958. wmHints->flags &= ~IconPixmapHint;
  195959. XFreePixmap (display, wmHints->icon_pixmap);
  195960. }
  195961. if ((wmHints->flags & IconMaskHint) != 0)
  195962. {
  195963. wmHints->flags &= ~IconMaskHint;
  195964. XFreePixmap (display, wmHints->icon_mask);
  195965. }
  195966. XSetWMHints (display, windowH, wmHints);
  195967. XFree (wmHints);
  195968. }
  195969. }
  195970. void handleWindowMessage (XEvent* event)
  195971. {
  195972. switch (event->xany.type)
  195973. {
  195974. case 2: // 'KeyPress'
  195975. {
  195976. ScopedXLock xlock;
  195977. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  195978. updateKeyStates (keyEvent->keycode, true);
  195979. char utf8 [64];
  195980. zeromem (utf8, sizeof (utf8));
  195981. KeySym sym;
  195982. {
  195983. const char* oldLocale = ::setlocale (LC_ALL, 0);
  195984. ::setlocale (LC_ALL, "");
  195985. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  195986. ::setlocale (LC_ALL, oldLocale);
  195987. }
  195988. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1);
  195989. int keyCode = (int) unicodeChar;
  195990. if (keyCode < 0x20)
  195991. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  195992. const ModifierKeys oldMods (currentModifiers);
  195993. bool keyPressed = false;
  195994. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  195995. if ((sym & 0xff00) == 0xff00)
  195996. {
  195997. // Translate keypad
  195998. if (sym == XK_KP_Divide)
  195999. keyCode = XK_slash;
  196000. else if (sym == XK_KP_Multiply)
  196001. keyCode = XK_asterisk;
  196002. else if (sym == XK_KP_Subtract)
  196003. keyCode = XK_hyphen;
  196004. else if (sym == XK_KP_Add)
  196005. keyCode = XK_plus;
  196006. else if (sym == XK_KP_Enter)
  196007. keyCode = XK_Return;
  196008. else if (sym == XK_KP_Decimal)
  196009. keyCode = Keys::numLock ? XK_period : XK_Delete;
  196010. else if (sym == XK_KP_0)
  196011. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  196012. else if (sym == XK_KP_1)
  196013. keyCode = Keys::numLock ? XK_1 : XK_End;
  196014. else if (sym == XK_KP_2)
  196015. keyCode = Keys::numLock ? XK_2 : XK_Down;
  196016. else if (sym == XK_KP_3)
  196017. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  196018. else if (sym == XK_KP_4)
  196019. keyCode = Keys::numLock ? XK_4 : XK_Left;
  196020. else if (sym == XK_KP_5)
  196021. keyCode = XK_5;
  196022. else if (sym == XK_KP_6)
  196023. keyCode = Keys::numLock ? XK_6 : XK_Right;
  196024. else if (sym == XK_KP_7)
  196025. keyCode = Keys::numLock ? XK_7 : XK_Home;
  196026. else if (sym == XK_KP_8)
  196027. keyCode = Keys::numLock ? XK_8 : XK_Up;
  196028. else if (sym == XK_KP_9)
  196029. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  196030. switch (sym)
  196031. {
  196032. case XK_Left:
  196033. case XK_Right:
  196034. case XK_Up:
  196035. case XK_Down:
  196036. case XK_Page_Up:
  196037. case XK_Page_Down:
  196038. case XK_End:
  196039. case XK_Home:
  196040. case XK_Delete:
  196041. case XK_Insert:
  196042. keyPressed = true;
  196043. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196044. break;
  196045. case XK_Tab:
  196046. case XK_Return:
  196047. case XK_Escape:
  196048. case XK_BackSpace:
  196049. keyPressed = true;
  196050. keyCode &= 0xff;
  196051. break;
  196052. default:
  196053. {
  196054. if (sym >= XK_F1 && sym <= XK_F16)
  196055. {
  196056. keyPressed = true;
  196057. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196058. }
  196059. break;
  196060. }
  196061. }
  196062. }
  196063. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196064. keyPressed = true;
  196065. if (oldMods != currentModifiers)
  196066. handleModifierKeysChange();
  196067. if (keyDownChange)
  196068. handleKeyUpOrDown (true);
  196069. if (keyPressed)
  196070. handleKeyPress (keyCode, unicodeChar);
  196071. break;
  196072. }
  196073. case KeyRelease:
  196074. {
  196075. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196076. updateKeyStates (keyEvent->keycode, false);
  196077. ScopedXLock xlock;
  196078. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196079. const ModifierKeys oldMods (currentModifiers);
  196080. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196081. if (oldMods != currentModifiers)
  196082. handleModifierKeysChange();
  196083. if (keyDownChange)
  196084. handleKeyUpOrDown (false);
  196085. break;
  196086. }
  196087. case ButtonPress:
  196088. {
  196089. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196090. updateKeyModifiers (buttonPressEvent->state);
  196091. bool buttonMsg = false;
  196092. const int map = pointerMap [buttonPressEvent->button - Button1];
  196093. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196094. {
  196095. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196096. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196097. }
  196098. if (map == Keys::LeftButton)
  196099. {
  196100. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196101. buttonMsg = true;
  196102. }
  196103. else if (map == Keys::RightButton)
  196104. {
  196105. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196106. buttonMsg = true;
  196107. }
  196108. else if (map == Keys::MiddleButton)
  196109. {
  196110. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196111. buttonMsg = true;
  196112. }
  196113. if (buttonMsg)
  196114. {
  196115. toFront (true);
  196116. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196117. getEventTime (buttonPressEvent->time));
  196118. }
  196119. clearLastMousePos();
  196120. break;
  196121. }
  196122. case ButtonRelease:
  196123. {
  196124. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196125. updateKeyModifiers (buttonRelEvent->state);
  196126. const int map = pointerMap [buttonRelEvent->button - Button1];
  196127. if (map == Keys::LeftButton)
  196128. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196129. else if (map == Keys::RightButton)
  196130. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196131. else if (map == Keys::MiddleButton)
  196132. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196133. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196134. getEventTime (buttonRelEvent->time));
  196135. clearLastMousePos();
  196136. break;
  196137. }
  196138. case MotionNotify:
  196139. {
  196140. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196141. updateKeyModifiers (movedEvent->state);
  196142. const Point<int> mousePos (Desktop::getMousePosition());
  196143. if (lastMousePos != mousePos)
  196144. {
  196145. lastMousePos = mousePos;
  196146. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196147. {
  196148. Window wRoot = 0, wParent = 0;
  196149. {
  196150. ScopedXLock xlock;
  196151. unsigned int numChildren;
  196152. Window* wChild = 0;
  196153. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196154. }
  196155. if (wParent != 0
  196156. && wParent != windowH
  196157. && wParent != wRoot)
  196158. {
  196159. parentWindow = wParent;
  196160. updateBounds();
  196161. }
  196162. else
  196163. {
  196164. parentWindow = 0;
  196165. }
  196166. }
  196167. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196168. }
  196169. break;
  196170. }
  196171. case EnterNotify:
  196172. {
  196173. clearLastMousePos();
  196174. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196175. if (! currentModifiers.isAnyMouseButtonDown())
  196176. {
  196177. updateKeyModifiers (enterEvent->state);
  196178. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196179. }
  196180. break;
  196181. }
  196182. case LeaveNotify:
  196183. {
  196184. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196185. // Suppress the normal leave if we've got a pointer grab, or if
  196186. // it's a bogus one caused by clicking a mouse button when running
  196187. // in a Window manager
  196188. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196189. || leaveEvent->mode == NotifyUngrab)
  196190. {
  196191. updateKeyModifiers (leaveEvent->state);
  196192. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196193. }
  196194. break;
  196195. }
  196196. case FocusIn:
  196197. {
  196198. isActiveApplication = true;
  196199. if (isFocused())
  196200. handleFocusGain();
  196201. break;
  196202. }
  196203. case FocusOut:
  196204. {
  196205. isActiveApplication = false;
  196206. if (! isFocused())
  196207. handleFocusLoss();
  196208. break;
  196209. }
  196210. case Expose:
  196211. {
  196212. // Batch together all pending expose events
  196213. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196214. XEvent nextEvent;
  196215. ScopedXLock xlock;
  196216. if (exposeEvent->window != windowH)
  196217. {
  196218. Window child;
  196219. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196220. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196221. &child);
  196222. }
  196223. repaint (exposeEvent->x, exposeEvent->y,
  196224. exposeEvent->width, exposeEvent->height);
  196225. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196226. {
  196227. XPeekEvent (display, (XEvent*) &nextEvent);
  196228. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196229. break;
  196230. XNextEvent (display, (XEvent*) &nextEvent);
  196231. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196232. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196233. nextExposeEvent->width, nextExposeEvent->height);
  196234. }
  196235. break;
  196236. }
  196237. case CirculateNotify:
  196238. case CreateNotify:
  196239. case DestroyNotify:
  196240. // Think we can ignore these
  196241. break;
  196242. case ConfigureNotify:
  196243. {
  196244. updateBounds();
  196245. updateBorderSize();
  196246. handleMovedOrResized();
  196247. // if the native title bar is dragged, need to tell any active menus, etc.
  196248. if ((styleFlags & windowHasTitleBar) != 0
  196249. && component->isCurrentlyBlockedByAnotherModalComponent())
  196250. {
  196251. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196252. if (currentModalComp != 0)
  196253. currentModalComp->inputAttemptWhenModal();
  196254. }
  196255. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196256. if (confEvent->window == windowH
  196257. && confEvent->above != 0
  196258. && isFrontWindow())
  196259. {
  196260. handleBroughtToFront();
  196261. }
  196262. break;
  196263. }
  196264. case ReparentNotify:
  196265. case GravityNotify:
  196266. {
  196267. parentWindow = 0;
  196268. Window wRoot = 0;
  196269. Window* wChild = 0;
  196270. unsigned int numChildren;
  196271. {
  196272. ScopedXLock xlock;
  196273. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196274. }
  196275. if (parentWindow == windowH || parentWindow == wRoot)
  196276. parentWindow = 0;
  196277. updateBounds();
  196278. updateBorderSize();
  196279. handleMovedOrResized();
  196280. break;
  196281. }
  196282. case MapNotify:
  196283. mapped = true;
  196284. handleBroughtToFront();
  196285. break;
  196286. case UnmapNotify:
  196287. mapped = false;
  196288. break;
  196289. case MappingNotify:
  196290. {
  196291. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196292. if (mappingEvent->request != MappingPointer)
  196293. {
  196294. // Deal with modifier/keyboard mapping
  196295. ScopedXLock xlock;
  196296. XRefreshKeyboardMapping (mappingEvent);
  196297. updateModifierMappings();
  196298. }
  196299. break;
  196300. }
  196301. case ClientMessage:
  196302. {
  196303. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196304. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196305. {
  196306. const Atom atom = (Atom) clientMsg->data.l[0];
  196307. if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196308. {
  196309. XWindowAttributes atts;
  196310. ScopedXLock xlock;
  196311. if (clientMsg->window != 0
  196312. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196313. {
  196314. if (atts.map_state == IsViewable)
  196315. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196316. }
  196317. }
  196318. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196319. {
  196320. handleUserClosingWindow();
  196321. }
  196322. }
  196323. else if (clientMsg->message_type == Atoms::XdndEnter)
  196324. {
  196325. handleDragAndDropEnter (clientMsg);
  196326. }
  196327. else if (clientMsg->message_type == Atoms::XdndLeave)
  196328. {
  196329. resetDragAndDrop();
  196330. }
  196331. else if (clientMsg->message_type == Atoms::XdndPosition)
  196332. {
  196333. handleDragAndDropPosition (clientMsg);
  196334. }
  196335. else if (clientMsg->message_type == Atoms::XdndDrop)
  196336. {
  196337. handleDragAndDropDrop (clientMsg);
  196338. }
  196339. else if (clientMsg->message_type == Atoms::XdndStatus)
  196340. {
  196341. handleDragAndDropStatus (clientMsg);
  196342. }
  196343. else if (clientMsg->message_type == Atoms::XdndFinished)
  196344. {
  196345. resetDragAndDrop();
  196346. }
  196347. break;
  196348. }
  196349. case SelectionNotify:
  196350. handleDragAndDropSelection (event);
  196351. break;
  196352. case SelectionClear:
  196353. case SelectionRequest:
  196354. break;
  196355. default:
  196356. #if JUCE_USE_XSHM
  196357. {
  196358. ScopedXLock xlock;
  196359. if (event->xany.type == XShmGetEventBase (display))
  196360. repainter->notifyPaintCompleted();
  196361. }
  196362. #endif
  196363. break;
  196364. }
  196365. }
  196366. void showMouseCursor (Cursor cursor) throw()
  196367. {
  196368. ScopedXLock xlock;
  196369. XDefineCursor (display, windowH, cursor);
  196370. }
  196371. void setTaskBarIcon (const Image& image)
  196372. {
  196373. ScopedXLock xlock;
  196374. taskbarImage = image.createCopy();
  196375. Screen* const screen = XDefaultScreenOfDisplay (display);
  196376. const int screenNumber = XScreenNumberOfScreen (screen);
  196377. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196378. screenAtom << screenNumber;
  196379. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196380. XGrabServer (display);
  196381. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196382. if (managerWin != None)
  196383. XSelectInput (display, managerWin, StructureNotifyMask);
  196384. XUngrabServer (display);
  196385. XFlush (display);
  196386. if (managerWin != None)
  196387. {
  196388. XEvent ev;
  196389. zerostruct (ev);
  196390. ev.xclient.type = ClientMessage;
  196391. ev.xclient.window = managerWin;
  196392. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196393. ev.xclient.format = 32;
  196394. ev.xclient.data.l[0] = CurrentTime;
  196395. ev.xclient.data.l[1] = 0 /*SYSTEM_TRAY_REQUEST_DOCK*/;
  196396. ev.xclient.data.l[2] = windowH;
  196397. ev.xclient.data.l[3] = 0;
  196398. ev.xclient.data.l[4] = 0;
  196399. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196400. XSync (display, False);
  196401. }
  196402. // For older KDE's ...
  196403. long atomData = 1;
  196404. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196405. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196406. // For more recent KDE's...
  196407. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196408. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196409. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196410. XSizeHints* hints = XAllocSizeHints();
  196411. hints->flags = PMinSize;
  196412. hints->min_width = 22;
  196413. hints->min_height = 22;
  196414. XSetWMNormalHints (display, windowH, hints);
  196415. XFree (hints);
  196416. }
  196417. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196418. juce_UseDebuggingNewOperator
  196419. bool dontRepaint;
  196420. static ModifierKeys currentModifiers;
  196421. static bool isActiveApplication;
  196422. private:
  196423. class LinuxRepaintManager : public Timer
  196424. {
  196425. public:
  196426. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196427. : peer (peer_),
  196428. lastTimeImageUsed (0)
  196429. {
  196430. #if JUCE_USE_XSHM
  196431. shmCompletedDrawing = true;
  196432. useARGBImagesForRendering = XSHMHelpers::isShmAvailable();
  196433. if (useARGBImagesForRendering)
  196434. {
  196435. ScopedXLock xlock;
  196436. XShmSegmentInfo segmentinfo;
  196437. XImage* const testImage
  196438. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196439. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196440. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196441. XDestroyImage (testImage);
  196442. }
  196443. #endif
  196444. }
  196445. ~LinuxRepaintManager()
  196446. {
  196447. }
  196448. void timerCallback()
  196449. {
  196450. #if JUCE_USE_XSHM
  196451. if (! shmCompletedDrawing)
  196452. return;
  196453. #endif
  196454. if (! regionsNeedingRepaint.isEmpty())
  196455. {
  196456. stopTimer();
  196457. performAnyPendingRepaintsNow();
  196458. }
  196459. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196460. {
  196461. stopTimer();
  196462. image = 0;
  196463. }
  196464. }
  196465. void repaint (int x, int y, int w, int h)
  196466. {
  196467. if (! isTimerRunning())
  196468. startTimer (repaintTimerPeriod);
  196469. regionsNeedingRepaint.add (x, y, w, h);
  196470. }
  196471. void performAnyPendingRepaintsNow()
  196472. {
  196473. #if JUCE_USE_XSHM
  196474. if (! shmCompletedDrawing)
  196475. {
  196476. startTimer (repaintTimerPeriod);
  196477. return;
  196478. }
  196479. #endif
  196480. peer->clearMaskedRegion();
  196481. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196482. regionsNeedingRepaint.clear();
  196483. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196484. if (! totalArea.isEmpty())
  196485. {
  196486. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196487. || image->getHeight() < totalArea.getHeight())
  196488. {
  196489. #if JUCE_USE_XSHM
  196490. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196491. : Image::RGB,
  196492. #else
  196493. image = new XBitmapImage (Image::RGB,
  196494. #endif
  196495. (totalArea.getWidth() + 31) & ~31,
  196496. (totalArea.getHeight() + 31) & ~31,
  196497. false,
  196498. peer->depth,
  196499. peer->visual);
  196500. }
  196501. startTimer (repaintTimerPeriod);
  196502. LowLevelGraphicsSoftwareRenderer context (*image);
  196503. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196504. if (context.clipToRectangleList (originalRepaintRegion))
  196505. {
  196506. if (peer->depth == 32)
  196507. {
  196508. RectangleList::Iterator i (originalRepaintRegion);
  196509. while (i.next())
  196510. {
  196511. const Rectangle<int>& r = *i.getRectangle();
  196512. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196513. }
  196514. }
  196515. peer->handlePaint (context);
  196516. }
  196517. if (! peer->maskedRegion.isEmpty())
  196518. originalRepaintRegion.subtract (peer->maskedRegion);
  196519. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196520. {
  196521. #if JUCE_USE_XSHM
  196522. shmCompletedDrawing = false;
  196523. #endif
  196524. const Rectangle<int>& r = *i.getRectangle();
  196525. image->blitToWindow (peer->windowH,
  196526. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196527. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196528. }
  196529. }
  196530. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196531. startTimer (repaintTimerPeriod);
  196532. }
  196533. #if JUCE_USE_XSHM
  196534. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196535. #endif
  196536. private:
  196537. enum { repaintTimerPeriod = 1000 / 100 };
  196538. LinuxComponentPeer* const peer;
  196539. ScopedPointer <XBitmapImage> image;
  196540. uint32 lastTimeImageUsed;
  196541. RectangleList regionsNeedingRepaint;
  196542. #if JUCE_USE_XSHM
  196543. bool useARGBImagesForRendering, shmCompletedDrawing;
  196544. #endif
  196545. LinuxRepaintManager (const LinuxRepaintManager&);
  196546. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196547. };
  196548. ScopedPointer <LinuxRepaintManager> repainter;
  196549. friend class LinuxRepaintManager;
  196550. Window windowH, parentWindow;
  196551. int wx, wy, ww, wh;
  196552. ScopedPointer<Image> taskbarImage;
  196553. bool fullScreen, mapped;
  196554. Visual* visual;
  196555. int depth;
  196556. BorderSize windowBorder;
  196557. struct MotifWmHints
  196558. {
  196559. unsigned long flags;
  196560. unsigned long functions;
  196561. unsigned long decorations;
  196562. long input_mode;
  196563. unsigned long status;
  196564. };
  196565. static void updateKeyStates (const int keycode, const bool press) throw()
  196566. {
  196567. const int keybyte = keycode >> 3;
  196568. const int keybit = (1 << (keycode & 7));
  196569. if (press)
  196570. Keys::keyStates [keybyte] |= keybit;
  196571. else
  196572. Keys::keyStates [keybyte] &= ~keybit;
  196573. }
  196574. static void updateKeyModifiers (const int status) throw()
  196575. {
  196576. int keyMods = 0;
  196577. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196578. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196579. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196580. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196581. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196582. Keys::capsLock = ((status & LockMask) != 0);
  196583. }
  196584. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196585. {
  196586. int modifier = 0;
  196587. bool isModifier = true;
  196588. switch (sym)
  196589. {
  196590. case XK_Shift_L:
  196591. case XK_Shift_R:
  196592. modifier = ModifierKeys::shiftModifier;
  196593. break;
  196594. case XK_Control_L:
  196595. case XK_Control_R:
  196596. modifier = ModifierKeys::ctrlModifier;
  196597. break;
  196598. case XK_Alt_L:
  196599. case XK_Alt_R:
  196600. modifier = ModifierKeys::altModifier;
  196601. break;
  196602. case XK_Num_Lock:
  196603. if (press)
  196604. Keys::numLock = ! Keys::numLock;
  196605. break;
  196606. case XK_Caps_Lock:
  196607. if (press)
  196608. Keys::capsLock = ! Keys::capsLock;
  196609. break;
  196610. case XK_Scroll_Lock:
  196611. break;
  196612. default:
  196613. isModifier = false;
  196614. break;
  196615. }
  196616. if (modifier != 0)
  196617. {
  196618. if (press)
  196619. currentModifiers = currentModifiers.withFlags (modifier);
  196620. else
  196621. currentModifiers = currentModifiers.withoutFlags (modifier);
  196622. }
  196623. return isModifier;
  196624. }
  196625. // Alt and Num lock are not defined by standard X
  196626. // modifier constants: check what they're mapped to
  196627. static void updateModifierMappings() throw()
  196628. {
  196629. ScopedXLock xlock;
  196630. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196631. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196632. Keys::AltMask = 0;
  196633. Keys::NumLockMask = 0;
  196634. XModifierKeymap* mapping = XGetModifierMapping (display);
  196635. if (mapping)
  196636. {
  196637. for (int i = 0; i < 8; i++)
  196638. {
  196639. if (mapping->modifiermap [i << 1] == altLeftCode)
  196640. Keys::AltMask = 1 << i;
  196641. else if (mapping->modifiermap [i << 1] == numLockCode)
  196642. Keys::NumLockMask = 1 << i;
  196643. }
  196644. XFreeModifiermap (mapping);
  196645. }
  196646. }
  196647. void removeWindowDecorations (Window wndH)
  196648. {
  196649. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196650. if (hints != None)
  196651. {
  196652. MotifWmHints motifHints;
  196653. zerostruct (motifHints);
  196654. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196655. motifHints.decorations = 0;
  196656. ScopedXLock xlock;
  196657. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196658. (unsigned char*) &motifHints, 4);
  196659. }
  196660. hints = XInternAtom (display, "_WIN_HINTS", True);
  196661. if (hints != None)
  196662. {
  196663. long gnomeHints = 0;
  196664. ScopedXLock xlock;
  196665. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196666. (unsigned char*) &gnomeHints, 1);
  196667. }
  196668. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196669. if (hints != None)
  196670. {
  196671. long kwmHints = 2; /*KDE_tinyDecoration*/
  196672. ScopedXLock xlock;
  196673. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196674. (unsigned char*) &kwmHints, 1);
  196675. }
  196676. }
  196677. void addWindowButtons (Window wndH)
  196678. {
  196679. ScopedXLock xlock;
  196680. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196681. if (hints != None)
  196682. {
  196683. MotifWmHints motifHints;
  196684. zerostruct (motifHints);
  196685. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196686. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196687. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196688. if ((styleFlags & windowHasCloseButton) != 0)
  196689. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196690. if ((styleFlags & windowHasMinimiseButton) != 0)
  196691. {
  196692. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196693. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196694. }
  196695. if ((styleFlags & windowHasMaximiseButton) != 0)
  196696. {
  196697. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196698. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196699. }
  196700. if ((styleFlags & windowIsResizable) != 0)
  196701. {
  196702. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196703. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196704. }
  196705. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196706. }
  196707. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196708. if (hints != None)
  196709. {
  196710. int netHints [6];
  196711. int num = 0;
  196712. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196713. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196714. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196715. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196716. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196717. (unsigned char*) &netHints, num);
  196718. }
  196719. }
  196720. void setWindowType (Window wndH)
  196721. {
  196722. int netHints [2];
  196723. int numHints = 0;
  196724. if ((styleFlags & windowIsTemporary) != 0
  196725. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196726. {
  196727. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196728. }
  196729. else
  196730. {
  196731. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196732. }
  196733. if (netHints [numHints] != 0)
  196734. ++numHints;
  196735. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196736. if (netHints [numHints] != 0)
  196737. ++numHints;
  196738. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196739. (unsigned char*) &netHints, numHints);
  196740. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196741. {
  196742. }
  196743. }
  196744. void createWindow()
  196745. {
  196746. ScopedXLock xlock;
  196747. Atoms::initialiseAtoms();
  196748. resetDragAndDrop();
  196749. // Get defaults for various properties
  196750. const int screen = DefaultScreen (display);
  196751. Window root = RootWindow (display, screen);
  196752. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196753. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196754. if (visual == 0)
  196755. {
  196756. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196757. Process::terminate();
  196758. }
  196759. // Create and install a colormap suitable fr our visual
  196760. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196761. XInstallColormap (display, colormap);
  196762. // Set up the window attributes
  196763. XSetWindowAttributes swa;
  196764. swa.border_pixel = 0;
  196765. swa.background_pixmap = None;
  196766. swa.colormap = colormap;
  196767. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196768. swa.event_mask = getAllEventsMask();
  196769. Window wndH = XCreateWindow (display, root,
  196770. 0, 0, 1, 1,
  196771. 0, depth, InputOutput, visual,
  196772. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196773. &swa);
  196774. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196775. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196776. GrabModeAsync, GrabModeAsync, None, None);
  196777. // Set the window context to identify the window handle object
  196778. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196779. {
  196780. // Failed
  196781. jassertfalse
  196782. Logger::outputDebugString ("Failed to create context information for window.\n");
  196783. XDestroyWindow (display, wndH);
  196784. wndH = 0;
  196785. }
  196786. // Set window manager hints
  196787. XWMHints* wmHints = XAllocWMHints();
  196788. wmHints->flags = InputHint | StateHint;
  196789. wmHints->input = True; // Locally active input model
  196790. wmHints->initial_state = NormalState;
  196791. XSetWMHints (display, wndH, wmHints);
  196792. XFree (wmHints);
  196793. // Set the window type
  196794. setWindowType (wndH);
  196795. // Define decoration
  196796. if ((styleFlags & windowHasTitleBar) == 0)
  196797. removeWindowDecorations (wndH);
  196798. else
  196799. addWindowButtons (wndH);
  196800. // Set window name
  196801. setWindowTitle (wndH, getComponent()->getName());
  196802. // Associate the PID, allowing to be shut down when something goes wrong
  196803. unsigned long pid = getpid();
  196804. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196805. (unsigned char*) &pid, 1);
  196806. // Set window manager protocols
  196807. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196808. (unsigned char*) Atoms::ProtocolList, 2);
  196809. // Set drag and drop flags
  196810. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196811. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196812. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196813. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196814. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196815. (const unsigned char*) "", 0);
  196816. unsigned long dndVersion = Atoms::DndVersion;
  196817. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196818. (const unsigned char*) &dndVersion, 1);
  196819. // Initialise the pointer and keyboard mapping
  196820. // This is not the same as the logical pointer mapping the X server uses:
  196821. // we don't mess with this.
  196822. static bool mappingInitialised = false;
  196823. if (! mappingInitialised)
  196824. {
  196825. mappingInitialised = true;
  196826. const int numButtons = XGetPointerMapping (display, 0, 0);
  196827. if (numButtons == 2)
  196828. {
  196829. pointerMap[0] = Keys::LeftButton;
  196830. pointerMap[1] = Keys::RightButton;
  196831. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  196832. }
  196833. else if (numButtons >= 3)
  196834. {
  196835. pointerMap[0] = Keys::LeftButton;
  196836. pointerMap[1] = Keys::MiddleButton;
  196837. pointerMap[2] = Keys::RightButton;
  196838. if (numButtons >= 5)
  196839. {
  196840. pointerMap[3] = Keys::WheelUp;
  196841. pointerMap[4] = Keys::WheelDown;
  196842. }
  196843. }
  196844. updateModifierMappings();
  196845. }
  196846. windowH = wndH;
  196847. }
  196848. void destroyWindow()
  196849. {
  196850. ScopedXLock xlock;
  196851. XPointer handlePointer;
  196852. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  196853. XDeleteContext (display, (XID) windowH, improbableNumber);
  196854. XDestroyWindow (display, windowH);
  196855. // Wait for it to complete and then remove any events for this
  196856. // window from the event queue.
  196857. XSync (display, false);
  196858. XEvent event;
  196859. while (XCheckWindowEvent (display, windowH, getAllEventsMask(), &event) == True)
  196860. {}
  196861. }
  196862. static int getAllEventsMask() throw()
  196863. {
  196864. return NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  196865. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  196866. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  196867. }
  196868. static int64 getEventTime (::Time t)
  196869. {
  196870. static int64 eventTimeOffset = 0x12345678;
  196871. const int64 thisMessageTime = t;
  196872. if (eventTimeOffset == 0x12345678)
  196873. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  196874. return eventTimeOffset + thisMessageTime;
  196875. }
  196876. static void setWindowTitle (Window xwin, const String& title)
  196877. {
  196878. XTextProperty nameProperty;
  196879. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  196880. ScopedXLock xlock;
  196881. if (XStringListToTextProperty (strings, 1, &nameProperty))
  196882. {
  196883. XSetWMName (display, xwin, &nameProperty);
  196884. XSetWMIconName (display, xwin, &nameProperty);
  196885. XFree (nameProperty.value);
  196886. }
  196887. }
  196888. void updateBorderSize()
  196889. {
  196890. if ((styleFlags & windowHasTitleBar) == 0)
  196891. {
  196892. windowBorder = BorderSize (0);
  196893. }
  196894. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  196895. {
  196896. ScopedXLock xlock;
  196897. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  196898. if (hints != None)
  196899. {
  196900. unsigned char* data = 0;
  196901. unsigned long nitems, bytesLeft;
  196902. Atom actualType;
  196903. int actualFormat;
  196904. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  196905. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  196906. &data) == Success)
  196907. {
  196908. const unsigned long* const sizes = (const unsigned long*) data;
  196909. if (actualFormat == 32)
  196910. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  196911. (int) sizes[3], (int) sizes[1]);
  196912. XFree (data);
  196913. }
  196914. }
  196915. }
  196916. }
  196917. void updateBounds()
  196918. {
  196919. jassert (windowH != 0);
  196920. if (windowH != 0)
  196921. {
  196922. Window root, child;
  196923. unsigned int bw, depth;
  196924. ScopedXLock xlock;
  196925. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196926. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  196927. &bw, &depth))
  196928. {
  196929. wx = wy = ww = wh = 0;
  196930. }
  196931. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  196932. {
  196933. wx = wy = 0;
  196934. }
  196935. }
  196936. }
  196937. void resetDragAndDrop()
  196938. {
  196939. dragAndDropFiles.clear();
  196940. lastDropPos = Point<int> (-1, -1);
  196941. dragAndDropCurrentMimeType = 0;
  196942. dragAndDropSourceWindow = 0;
  196943. srcMimeTypeAtomList.clear();
  196944. }
  196945. void sendDragAndDropMessage (XClientMessageEvent& msg)
  196946. {
  196947. msg.type = ClientMessage;
  196948. msg.display = display;
  196949. msg.window = dragAndDropSourceWindow;
  196950. msg.format = 32;
  196951. msg.data.l[0] = windowH;
  196952. ScopedXLock xlock;
  196953. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  196954. }
  196955. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  196956. {
  196957. XClientMessageEvent msg;
  196958. zerostruct (msg);
  196959. msg.message_type = Atoms::XdndStatus;
  196960. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  196961. msg.data.l[4] = dropAction;
  196962. sendDragAndDropMessage (msg);
  196963. }
  196964. void sendDragAndDropLeave()
  196965. {
  196966. XClientMessageEvent msg;
  196967. zerostruct (msg);
  196968. msg.message_type = Atoms::XdndLeave;
  196969. sendDragAndDropMessage (msg);
  196970. }
  196971. void sendDragAndDropFinish()
  196972. {
  196973. XClientMessageEvent msg;
  196974. zerostruct (msg);
  196975. msg.message_type = Atoms::XdndFinished;
  196976. sendDragAndDropMessage (msg);
  196977. }
  196978. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  196979. {
  196980. if ((clientMsg->data.l[1] & 1) == 0)
  196981. {
  196982. sendDragAndDropLeave();
  196983. if (dragAndDropFiles.size() > 0)
  196984. handleFileDragExit (dragAndDropFiles);
  196985. dragAndDropFiles.clear();
  196986. }
  196987. }
  196988. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  196989. {
  196990. if (dragAndDropSourceWindow == 0)
  196991. return;
  196992. dragAndDropSourceWindow = clientMsg->data.l[0];
  196993. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  196994. (int) clientMsg->data.l[2] & 0xffff);
  196995. dropPos -= getScreenPosition();
  196996. if (lastDropPos != dropPos)
  196997. {
  196998. lastDropPos = dropPos;
  196999. dragAndDropTimestamp = clientMsg->data.l[3];
  197000. Atom targetAction = Atoms::XdndActionCopy;
  197001. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  197002. {
  197003. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  197004. {
  197005. targetAction = Atoms::allowedActions[i];
  197006. break;
  197007. }
  197008. }
  197009. sendDragAndDropStatus (true, targetAction);
  197010. if (dragAndDropFiles.size() == 0)
  197011. updateDraggedFileList (clientMsg);
  197012. if (dragAndDropFiles.size() > 0)
  197013. handleFileDragMove (dragAndDropFiles, dropPos);
  197014. }
  197015. }
  197016. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197017. {
  197018. if (dragAndDropFiles.size() == 0)
  197019. updateDraggedFileList (clientMsg);
  197020. const StringArray files (dragAndDropFiles);
  197021. const Point<int> lastPos (lastDropPos);
  197022. sendDragAndDropFinish();
  197023. resetDragAndDrop();
  197024. if (files.size() > 0)
  197025. handleFileDragDrop (files, lastPos);
  197026. }
  197027. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197028. {
  197029. dragAndDropFiles.clear();
  197030. srcMimeTypeAtomList.clear();
  197031. dragAndDropCurrentMimeType = 0;
  197032. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  197033. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  197034. {
  197035. dragAndDropSourceWindow = 0;
  197036. return;
  197037. }
  197038. dragAndDropSourceWindow = clientMsg->data.l[0];
  197039. if ((clientMsg->data.l[1] & 1) != 0)
  197040. {
  197041. Atom actual;
  197042. int format;
  197043. unsigned long count = 0, remaining = 0;
  197044. unsigned char* data = 0;
  197045. ScopedXLock xlock;
  197046. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  197047. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197048. &count, &remaining, &data);
  197049. if (data != 0)
  197050. {
  197051. if (actual == XA_ATOM && format == 32 && count != 0)
  197052. {
  197053. const unsigned long* const types = (const unsigned long*) data;
  197054. for (unsigned int i = 0; i < count; ++i)
  197055. if (types[i] != None)
  197056. srcMimeTypeAtomList.add (types[i]);
  197057. }
  197058. XFree (data);
  197059. }
  197060. }
  197061. if (srcMimeTypeAtomList.size() == 0)
  197062. {
  197063. for (int i = 2; i < 5; ++i)
  197064. if (clientMsg->data.l[i] != None)
  197065. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197066. if (srcMimeTypeAtomList.size() == 0)
  197067. {
  197068. dragAndDropSourceWindow = 0;
  197069. return;
  197070. }
  197071. }
  197072. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197073. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197074. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197075. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197076. handleDragAndDropPosition (clientMsg);
  197077. }
  197078. void handleDragAndDropSelection (const XEvent* const evt)
  197079. {
  197080. dragAndDropFiles.clear();
  197081. if (evt->xselection.property != 0)
  197082. {
  197083. StringArray lines;
  197084. {
  197085. MemoryBlock dropData;
  197086. for (;;)
  197087. {
  197088. Atom actual;
  197089. uint8* data = 0;
  197090. unsigned long count = 0, remaining = 0;
  197091. int format = 0;
  197092. ScopedXLock xlock;
  197093. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197094. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197095. &format, &count, &remaining, &data) == Success)
  197096. {
  197097. dropData.append (data, count * format / 8);
  197098. XFree (data);
  197099. if (remaining == 0)
  197100. break;
  197101. }
  197102. else
  197103. {
  197104. XFree (data);
  197105. break;
  197106. }
  197107. }
  197108. lines.addLines (dropData.toString());
  197109. }
  197110. for (int i = 0; i < lines.size(); ++i)
  197111. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf ("file://", false, true)));
  197112. dragAndDropFiles.trim();
  197113. dragAndDropFiles.removeEmptyStrings();
  197114. }
  197115. }
  197116. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197117. {
  197118. dragAndDropFiles.clear();
  197119. if (dragAndDropSourceWindow != None
  197120. && dragAndDropCurrentMimeType != 0)
  197121. {
  197122. dragAndDropTimestamp = clientMsg->data.l[2];
  197123. ScopedXLock xlock;
  197124. XConvertSelection (display,
  197125. Atoms::XdndSelection,
  197126. dragAndDropCurrentMimeType,
  197127. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197128. windowH,
  197129. dragAndDropTimestamp);
  197130. }
  197131. }
  197132. StringArray dragAndDropFiles;
  197133. int dragAndDropTimestamp;
  197134. Point<int> lastDropPos;
  197135. Atom dragAndDropCurrentMimeType;
  197136. Window dragAndDropSourceWindow;
  197137. Array <Atom> srcMimeTypeAtomList;
  197138. static int pointerMap[5];
  197139. static Point<int> lastMousePos;
  197140. static void clearLastMousePos() throw()
  197141. {
  197142. lastMousePos = Point<int> (0x100000, 0x100000);
  197143. }
  197144. };
  197145. ModifierKeys LinuxComponentPeer::currentModifiers;
  197146. bool LinuxComponentPeer::isActiveApplication = false;
  197147. int LinuxComponentPeer::pointerMap[5];
  197148. Point<int> LinuxComponentPeer::lastMousePos;
  197149. bool Process::isForegroundProcess()
  197150. {
  197151. return LinuxComponentPeer::isActiveApplication;
  197152. }
  197153. void ModifierKeys::updateCurrentModifiers() throw()
  197154. {
  197155. currentModifiers = LinuxComponentPeer::currentModifiers;
  197156. }
  197157. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197158. {
  197159. Window root, child;
  197160. int x, y, winx, winy;
  197161. unsigned int mask;
  197162. int mouseMods = 0;
  197163. ScopedXLock xlock;
  197164. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197165. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197166. {
  197167. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197168. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197169. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197170. }
  197171. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197172. return LinuxComponentPeer::currentModifiers;
  197173. }
  197174. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197175. {
  197176. if (enableOrDisable)
  197177. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197178. }
  197179. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197180. {
  197181. return new LinuxComponentPeer (this, styleFlags);
  197182. }
  197183. // (this callback is hooked up in the messaging code)
  197184. void juce_windowMessageReceive (XEvent* event)
  197185. {
  197186. if (event->xany.window != None)
  197187. {
  197188. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197189. if (ComponentPeer::isValidPeer (peer))
  197190. peer->handleWindowMessage (event);
  197191. }
  197192. else
  197193. {
  197194. switch (event->xany.type)
  197195. {
  197196. case KeymapNotify:
  197197. {
  197198. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197199. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197200. break;
  197201. }
  197202. default:
  197203. break;
  197204. }
  197205. }
  197206. }
  197207. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197208. {
  197209. if (display == 0)
  197210. return;
  197211. #if JUCE_USE_XINERAMA
  197212. int major_opcode, first_event, first_error;
  197213. ScopedXLock xlock;
  197214. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197215. {
  197216. typedef Bool (*tXineramaIsActive) (Display*);
  197217. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197218. static tXineramaIsActive xXineramaIsActive = 0;
  197219. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197220. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197221. {
  197222. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197223. if (h != 0)
  197224. {
  197225. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197226. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197227. }
  197228. }
  197229. if (xXineramaIsActive != 0
  197230. && xXineramaQueryScreens != 0
  197231. && xXineramaIsActive (display))
  197232. {
  197233. int numMonitors = 0;
  197234. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197235. if (screens != 0)
  197236. {
  197237. for (int i = numMonitors; --i >= 0;)
  197238. {
  197239. int index = screens[i].screen_number;
  197240. if (index >= 0)
  197241. {
  197242. while (monitorCoords.size() < index)
  197243. monitorCoords.add (Rectangle<int>());
  197244. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197245. screens[i].y_org,
  197246. screens[i].width,
  197247. screens[i].height));
  197248. }
  197249. }
  197250. XFree (screens);
  197251. }
  197252. }
  197253. }
  197254. if (monitorCoords.size() == 0)
  197255. #endif
  197256. {
  197257. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197258. if (hints != None)
  197259. {
  197260. const int numMonitors = ScreenCount (display);
  197261. for (int i = 0; i < numMonitors; ++i)
  197262. {
  197263. Window root = RootWindow (display, i);
  197264. unsigned long nitems, bytesLeft;
  197265. Atom actualType;
  197266. int actualFormat;
  197267. unsigned char* data = 0;
  197268. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197269. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197270. &data) == Success)
  197271. {
  197272. const long* const position = (const long*) data;
  197273. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197274. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197275. position[2], position[3]));
  197276. XFree (data);
  197277. }
  197278. }
  197279. }
  197280. if (monitorCoords.size() == 0)
  197281. {
  197282. monitorCoords.add (Rectangle<int> (0, 0,
  197283. DisplayWidth (display, DefaultScreen (display)),
  197284. DisplayHeight (display, DefaultScreen (display))));
  197285. }
  197286. }
  197287. }
  197288. void Desktop::createMouseInputSources()
  197289. {
  197290. mouseSources.add (new MouseInputSource (0, true));
  197291. }
  197292. bool Desktop::canUseSemiTransparentWindows() throw()
  197293. {
  197294. int matchedDepth = 0;
  197295. const int desiredDepth = 32;
  197296. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197297. && (matchedDepth == desiredDepth);
  197298. }
  197299. const Point<int> Desktop::getMousePosition()
  197300. {
  197301. Window root, child;
  197302. int x, y, winx, winy;
  197303. unsigned int mask;
  197304. ScopedXLock xlock;
  197305. if (XQueryPointer (display,
  197306. RootWindow (display, DefaultScreen (display)),
  197307. &root, &child,
  197308. &x, &y, &winx, &winy, &mask) == False)
  197309. {
  197310. // Pointer not on the default screen
  197311. x = y = -1;
  197312. }
  197313. return Point<int> (x, y);
  197314. }
  197315. void Desktop::setMousePosition (const Point<int>& newPosition)
  197316. {
  197317. ScopedXLock xlock;
  197318. Window root = RootWindow (display, DefaultScreen (display));
  197319. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197320. }
  197321. static bool screenSaverAllowed = true;
  197322. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197323. {
  197324. if (screenSaverAllowed != isEnabled)
  197325. {
  197326. screenSaverAllowed = isEnabled;
  197327. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197328. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197329. if (xScreenSaverSuspend == 0)
  197330. {
  197331. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197332. if (h != 0)
  197333. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197334. }
  197335. ScopedXLock xlock;
  197336. if (xScreenSaverSuspend != 0)
  197337. xScreenSaverSuspend (display, ! isEnabled);
  197338. }
  197339. }
  197340. bool Desktop::isScreenSaverEnabled() throw()
  197341. {
  197342. return screenSaverAllowed;
  197343. }
  197344. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197345. {
  197346. ScopedXLock xlock;
  197347. const unsigned int imageW = image.getWidth();
  197348. const unsigned int imageH = image.getHeight();
  197349. #if JUCE_USE_XCURSOR
  197350. {
  197351. typedef XcursorBool (*tXcursorSupportsARGB) (Display*);
  197352. typedef XcursorImage* (*tXcursorImageCreate) (int, int);
  197353. typedef void (*tXcursorImageDestroy) (XcursorImage*);
  197354. typedef Cursor (*tXcursorImageLoadCursor) (Display*, const XcursorImage*);
  197355. static tXcursorSupportsARGB xXcursorSupportsARGB = 0;
  197356. static tXcursorImageCreate xXcursorImageCreate = 0;
  197357. static tXcursorImageDestroy xXcursorImageDestroy = 0;
  197358. static tXcursorImageLoadCursor xXcursorImageLoadCursor = 0;
  197359. static bool hasBeenLoaded = false;
  197360. if (! hasBeenLoaded)
  197361. {
  197362. hasBeenLoaded = true;
  197363. void* h = dlopen ("libXcursor.so", RTLD_GLOBAL | RTLD_NOW);
  197364. if (h != 0)
  197365. {
  197366. xXcursorSupportsARGB = (tXcursorSupportsARGB) dlsym (h, "XcursorSupportsARGB");
  197367. xXcursorImageCreate = (tXcursorImageCreate) dlsym (h, "XcursorImageCreate");
  197368. xXcursorImageLoadCursor = (tXcursorImageLoadCursor) dlsym (h, "XcursorImageLoadCursor");
  197369. xXcursorImageDestroy = (tXcursorImageDestroy) dlsym (h, "XcursorImageDestroy");
  197370. if (xXcursorSupportsARGB == 0 || xXcursorImageCreate == 0
  197371. || xXcursorImageLoadCursor == 0 || xXcursorImageDestroy == 0
  197372. || ! xXcursorSupportsARGB (display))
  197373. xXcursorSupportsARGB = 0;
  197374. }
  197375. }
  197376. if (xXcursorSupportsARGB != 0)
  197377. {
  197378. XcursorImage* xcImage = xXcursorImageCreate (imageW, imageH);
  197379. if (xcImage != 0)
  197380. {
  197381. xcImage->xhot = hotspotX;
  197382. xcImage->yhot = hotspotY;
  197383. XcursorPixel* dest = xcImage->pixels;
  197384. for (int y = 0; y < (int) imageH; ++y)
  197385. for (int x = 0; x < (int) imageW; ++x)
  197386. *dest++ = image.getPixelAt (x, y).getARGB();
  197387. void* result = (void*) xXcursorImageLoadCursor (display, xcImage);
  197388. xXcursorImageDestroy (xcImage);
  197389. if (result != 0)
  197390. return result;
  197391. }
  197392. }
  197393. }
  197394. #endif
  197395. Window root = RootWindow (display, DefaultScreen (display));
  197396. unsigned int cursorW, cursorH;
  197397. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197398. return 0;
  197399. Image im (Image::ARGB, cursorW, cursorH, true);
  197400. {
  197401. Graphics g (im);
  197402. if (imageW > cursorW || imageH > cursorH)
  197403. {
  197404. hotspotX = (hotspotX * cursorW) / imageW;
  197405. hotspotY = (hotspotY * cursorH) / imageH;
  197406. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197407. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197408. false);
  197409. }
  197410. else
  197411. {
  197412. g.drawImageAt (&image, 0, 0);
  197413. }
  197414. }
  197415. const int stride = (cursorW + 7) >> 3;
  197416. HeapBlock <char> maskPlane, sourcePlane;
  197417. maskPlane.calloc (stride * cursorH);
  197418. sourcePlane.calloc (stride * cursorH);
  197419. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197420. for (int y = cursorH; --y >= 0;)
  197421. {
  197422. for (int x = cursorW; --x >= 0;)
  197423. {
  197424. const char mask = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197425. const int offset = y * stride + (x >> 3);
  197426. const Colour c (im.getPixelAt (x, y));
  197427. if (c.getAlpha() >= 128)
  197428. maskPlane[offset] |= mask;
  197429. if (c.getBrightness() >= 0.5f)
  197430. sourcePlane[offset] |= mask;
  197431. }
  197432. }
  197433. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, sourcePlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197434. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, maskPlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197435. XColor white, black;
  197436. black.red = black.green = black.blue = 0;
  197437. white.red = white.green = white.blue = 0xffff;
  197438. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197439. XFreePixmap (display, sourcePixmap);
  197440. XFreePixmap (display, maskPixmap);
  197441. return result;
  197442. }
  197443. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197444. {
  197445. ScopedXLock xlock;
  197446. if (cursorHandle != None)
  197447. XFreeCursor (display, (Cursor) cursorHandle);
  197448. }
  197449. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197450. {
  197451. unsigned int shape;
  197452. switch (type)
  197453. {
  197454. case MouseCursor::NoCursor:
  197455. {
  197456. const Image im (Image::ARGB, 16, 16, true);
  197457. return juce_createMouseCursorFromImage (im, 0, 0);
  197458. }
  197459. case MouseCursor::NormalCursor:
  197460. return (void*) None; // Use parent cursor
  197461. case MouseCursor::DraggingHandCursor:
  197462. {
  197463. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197464. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197465. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197466. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197467. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197468. const int dragHandDataSize = 99;
  197469. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (dragHandData, dragHandDataSize));
  197470. return juce_createMouseCursorFromImage (*im, 8, 7);
  197471. }
  197472. case MouseCursor::CopyingCursor:
  197473. {
  197474. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197475. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197476. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197477. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197478. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197479. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197480. const int copyCursorSize = 119;
  197481. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (copyCursorData, copyCursorSize));
  197482. return juce_createMouseCursorFromImage (*im, 1, 3);
  197483. }
  197484. case MouseCursor::WaitCursor:
  197485. shape = XC_watch;
  197486. break;
  197487. case MouseCursor::IBeamCursor:
  197488. shape = XC_xterm;
  197489. break;
  197490. case MouseCursor::PointingHandCursor:
  197491. shape = XC_hand2;
  197492. break;
  197493. case MouseCursor::LeftRightResizeCursor:
  197494. shape = XC_sb_h_double_arrow;
  197495. break;
  197496. case MouseCursor::UpDownResizeCursor:
  197497. shape = XC_sb_v_double_arrow;
  197498. break;
  197499. case MouseCursor::UpDownLeftRightResizeCursor:
  197500. shape = XC_fleur;
  197501. break;
  197502. case MouseCursor::TopEdgeResizeCursor:
  197503. shape = XC_top_side;
  197504. break;
  197505. case MouseCursor::BottomEdgeResizeCursor:
  197506. shape = XC_bottom_side;
  197507. break;
  197508. case MouseCursor::LeftEdgeResizeCursor:
  197509. shape = XC_left_side;
  197510. break;
  197511. case MouseCursor::RightEdgeResizeCursor:
  197512. shape = XC_right_side;
  197513. break;
  197514. case MouseCursor::TopLeftCornerResizeCursor:
  197515. shape = XC_top_left_corner;
  197516. break;
  197517. case MouseCursor::TopRightCornerResizeCursor:
  197518. shape = XC_top_right_corner;
  197519. break;
  197520. case MouseCursor::BottomLeftCornerResizeCursor:
  197521. shape = XC_bottom_left_corner;
  197522. break;
  197523. case MouseCursor::BottomRightCornerResizeCursor:
  197524. shape = XC_bottom_right_corner;
  197525. break;
  197526. case MouseCursor::CrosshairCursor:
  197527. shape = XC_crosshair;
  197528. break;
  197529. default:
  197530. return (void*) None; // Use parent cursor
  197531. }
  197532. ScopedXLock xlock;
  197533. return (void*) XCreateFontCursor (display, shape);
  197534. }
  197535. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197536. {
  197537. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197538. if (lp != 0)
  197539. lp->showMouseCursor ((Cursor) getHandle());
  197540. }
  197541. void MouseCursor::showInAllWindows() const throw()
  197542. {
  197543. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197544. showInWindow (ComponentPeer::getPeer (i));
  197545. }
  197546. Image* juce_createIconForFile (const File& file)
  197547. {
  197548. return 0;
  197549. }
  197550. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197551. {
  197552. return new Image (format, imageWidth, imageHeight, clearImage);
  197553. }
  197554. #if JUCE_OPENGL
  197555. class WindowedGLContext : public OpenGLContext
  197556. {
  197557. public:
  197558. WindowedGLContext (Component* const component,
  197559. const OpenGLPixelFormat& pixelFormat_,
  197560. GLXContext sharedContext)
  197561. : renderContext (0),
  197562. embeddedWindow (0),
  197563. pixelFormat (pixelFormat_)
  197564. {
  197565. jassert (component != 0);
  197566. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197567. if (peer == 0)
  197568. return;
  197569. ScopedXLock xlock;
  197570. XSync (display, False);
  197571. GLint attribs [64];
  197572. int n = 0;
  197573. attribs[n++] = GLX_RGBA;
  197574. attribs[n++] = GLX_DOUBLEBUFFER;
  197575. attribs[n++] = GLX_RED_SIZE;
  197576. attribs[n++] = pixelFormat.redBits;
  197577. attribs[n++] = GLX_GREEN_SIZE;
  197578. attribs[n++] = pixelFormat.greenBits;
  197579. attribs[n++] = GLX_BLUE_SIZE;
  197580. attribs[n++] = pixelFormat.blueBits;
  197581. attribs[n++] = GLX_ALPHA_SIZE;
  197582. attribs[n++] = pixelFormat.alphaBits;
  197583. attribs[n++] = GLX_DEPTH_SIZE;
  197584. attribs[n++] = pixelFormat.depthBufferBits;
  197585. attribs[n++] = GLX_STENCIL_SIZE;
  197586. attribs[n++] = pixelFormat.stencilBufferBits;
  197587. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197588. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197589. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197590. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197591. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197592. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197593. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197594. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197595. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197596. attribs[n++] = None;
  197597. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197598. if (bestVisual == 0)
  197599. return;
  197600. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197601. Window windowH = (Window) peer->getNativeHandle();
  197602. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197603. XSetWindowAttributes swa;
  197604. swa.colormap = colourMap;
  197605. swa.border_pixel = 0;
  197606. swa.event_mask = ExposureMask | StructureNotifyMask;
  197607. embeddedWindow = XCreateWindow (display, windowH,
  197608. 0, 0, 1, 1, 0,
  197609. bestVisual->depth,
  197610. InputOutput,
  197611. bestVisual->visual,
  197612. CWBorderPixel | CWColormap | CWEventMask,
  197613. &swa);
  197614. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197615. XMapWindow (display, embeddedWindow);
  197616. XFreeColormap (display, colourMap);
  197617. XFree (bestVisual);
  197618. XSync (display, False);
  197619. }
  197620. ~WindowedGLContext()
  197621. {
  197622. makeInactive();
  197623. ScopedXLock xlock;
  197624. glXDestroyContext (display, renderContext);
  197625. XUnmapWindow (display, embeddedWindow);
  197626. XDestroyWindow (display, embeddedWindow);
  197627. }
  197628. bool makeActive() const throw()
  197629. {
  197630. jassert (renderContext != 0);
  197631. ScopedXLock xlock;
  197632. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197633. && XSync (display, False);
  197634. }
  197635. bool makeInactive() const throw()
  197636. {
  197637. ScopedXLock xlock;
  197638. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197639. }
  197640. bool isActive() const throw()
  197641. {
  197642. ScopedXLock xlock;
  197643. return glXGetCurrentContext() == renderContext;
  197644. }
  197645. const OpenGLPixelFormat getPixelFormat() const
  197646. {
  197647. return pixelFormat;
  197648. }
  197649. void* getRawContext() const throw()
  197650. {
  197651. return renderContext;
  197652. }
  197653. void updateWindowPosition (int x, int y, int w, int h, int)
  197654. {
  197655. ScopedXLock xlock;
  197656. XMoveResizeWindow (display, embeddedWindow,
  197657. x, y, jmax (1, w), jmax (1, h));
  197658. }
  197659. void swapBuffers()
  197660. {
  197661. ScopedXLock xlock;
  197662. glXSwapBuffers (display, embeddedWindow);
  197663. }
  197664. bool setSwapInterval (const int numFramesPerSwap)
  197665. {
  197666. // xxx needs doing..
  197667. return false;
  197668. }
  197669. int getSwapInterval() const
  197670. {
  197671. // xxx needs doing..
  197672. return 0;
  197673. }
  197674. void repaint()
  197675. {
  197676. }
  197677. juce_UseDebuggingNewOperator
  197678. GLXContext renderContext;
  197679. private:
  197680. Window embeddedWindow;
  197681. OpenGLPixelFormat pixelFormat;
  197682. WindowedGLContext (const WindowedGLContext&);
  197683. WindowedGLContext& operator= (const WindowedGLContext&);
  197684. };
  197685. OpenGLContext* OpenGLComponent::createContext()
  197686. {
  197687. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  197688. contextToShareListsWith != 0 ? (GLXContext) contextToShareListsWith->getRawContext() : 0));
  197689. return (c->renderContext != 0) ? c.release() : 0;
  197690. }
  197691. void juce_glViewport (const int w, const int h)
  197692. {
  197693. glViewport (0, 0, w, h);
  197694. }
  197695. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197696. OwnedArray <OpenGLPixelFormat>& results)
  197697. {
  197698. results.add (new OpenGLPixelFormat()); // xxx
  197699. }
  197700. #endif
  197701. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197702. {
  197703. jassertfalse // not implemented!
  197704. return false;
  197705. }
  197706. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197707. {
  197708. jassertfalse // not implemented!
  197709. return false;
  197710. }
  197711. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197712. {
  197713. if (! isOnDesktop ())
  197714. addToDesktop (0);
  197715. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197716. if (wp != 0)
  197717. {
  197718. wp->setTaskBarIcon (newImage);
  197719. setVisible (true);
  197720. toFront (false);
  197721. repaint();
  197722. }
  197723. }
  197724. void SystemTrayIconComponent::paint (Graphics& g)
  197725. {
  197726. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197727. if (wp != 0)
  197728. {
  197729. const Image* const image = wp->getTaskbarIcon();
  197730. if (image != 0)
  197731. {
  197732. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197733. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197734. false);
  197735. }
  197736. }
  197737. }
  197738. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197739. {
  197740. // xxx not yet implemented!
  197741. }
  197742. void PlatformUtilities::beep()
  197743. {
  197744. std::cout << "\a" << std::flush;
  197745. }
  197746. bool AlertWindow::showNativeDialogBox (const String& title,
  197747. const String& bodyText,
  197748. bool isOkCancel)
  197749. {
  197750. // use a non-native one for the time being..
  197751. if (isOkCancel)
  197752. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197753. else
  197754. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197755. return true;
  197756. }
  197757. const int KeyPress::spaceKey = XK_space & 0xff;
  197758. const int KeyPress::returnKey = XK_Return & 0xff;
  197759. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197760. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197761. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197762. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197763. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197764. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197765. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197766. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197767. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197768. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197769. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197770. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197771. const int KeyPress::tabKey = XK_Tab & 0xff;
  197772. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197773. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197774. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197775. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197776. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197777. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197778. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197779. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197780. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197781. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197782. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197783. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197784. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197785. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197786. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197787. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197788. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197789. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197790. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197791. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197792. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197793. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197794. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197795. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197796. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197797. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197798. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197799. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197800. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197801. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197802. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197803. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197804. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197805. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197806. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197807. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197808. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197809. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197810. #endif
  197811. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197812. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197813. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197814. // compiled on its own).
  197815. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197816. static const int maxNumChans = 64;
  197817. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197818. {
  197819. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197820. snd_pcm_hw_params_t* hwParams;
  197821. snd_pcm_hw_params_alloca (&hwParams);
  197822. for (int i = 0; ratesToTry[i] != 0; ++i)
  197823. {
  197824. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197825. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197826. {
  197827. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197828. }
  197829. }
  197830. }
  197831. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197832. {
  197833. snd_pcm_hw_params_t *params;
  197834. snd_pcm_hw_params_alloca (&params);
  197835. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197836. {
  197837. snd_pcm_hw_params_get_channels_min (params, minChans);
  197838. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197839. }
  197840. }
  197841. static void getDeviceProperties (const String& deviceID,
  197842. unsigned int& minChansOut,
  197843. unsigned int& maxChansOut,
  197844. unsigned int& minChansIn,
  197845. unsigned int& maxChansIn,
  197846. Array <int>& rates)
  197847. {
  197848. if (deviceID.isEmpty())
  197849. return;
  197850. snd_ctl_t* handle;
  197851. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (",", false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197852. {
  197853. snd_pcm_info_t* info;
  197854. snd_pcm_info_alloca (&info);
  197855. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197856. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (",", false, false).getIntValue());
  197857. snd_pcm_info_set_subdevice (info, 0);
  197858. if (snd_ctl_pcm_info (handle, info) >= 0)
  197859. {
  197860. snd_pcm_t* pcmHandle;
  197861. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197862. {
  197863. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197864. getDeviceSampleRates (pcmHandle, rates);
  197865. snd_pcm_close (pcmHandle);
  197866. }
  197867. }
  197868. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197869. if (snd_ctl_pcm_info (handle, info) >= 0)
  197870. {
  197871. snd_pcm_t* pcmHandle;
  197872. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197873. {
  197874. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197875. if (rates.size() == 0)
  197876. getDeviceSampleRates (pcmHandle, rates);
  197877. snd_pcm_close (pcmHandle);
  197878. }
  197879. }
  197880. snd_ctl_close (handle);
  197881. }
  197882. }
  197883. class ALSADevice
  197884. {
  197885. public:
  197886. ALSADevice (const String& deviceID,
  197887. const bool forInput)
  197888. : handle (0),
  197889. bitDepth (16),
  197890. numChannelsRunning (0),
  197891. isInput (forInput),
  197892. sampleFormat (AudioDataConverters::int16LE)
  197893. {
  197894. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  197895. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  197896. SND_PCM_ASYNC));
  197897. }
  197898. ~ALSADevice()
  197899. {
  197900. if (handle != 0)
  197901. snd_pcm_close (handle);
  197902. }
  197903. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  197904. {
  197905. if (handle == 0)
  197906. return false;
  197907. snd_pcm_hw_params_t* hwParams;
  197908. snd_pcm_hw_params_alloca (&hwParams);
  197909. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  197910. return false;
  197911. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  197912. isInterleaved = false;
  197913. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  197914. isInterleaved = true;
  197915. else
  197916. {
  197917. jassertfalse
  197918. return false;
  197919. }
  197920. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  197921. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  197922. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  197923. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  197924. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  197925. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  197926. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  197927. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  197928. bitDepth = 0;
  197929. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  197930. {
  197931. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  197932. {
  197933. bitDepth = formatsToTry [i + 1];
  197934. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  197935. break;
  197936. }
  197937. }
  197938. if (bitDepth == 0)
  197939. {
  197940. error = "device doesn't support a compatible PCM format";
  197941. DBG ("ALSA error: " + error + "\n");
  197942. return false;
  197943. }
  197944. int dir = 0;
  197945. unsigned int periods = 4;
  197946. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  197947. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  197948. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  197949. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  197950. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  197951. || failed (snd_pcm_hw_params (handle, hwParams)))
  197952. {
  197953. return false;
  197954. }
  197955. snd_pcm_sw_params_t* swParams;
  197956. snd_pcm_sw_params_alloca (&swParams);
  197957. snd_pcm_uframes_t boundary;
  197958. if (failed (snd_pcm_sw_params_current (handle, swParams))
  197959. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  197960. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  197961. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  197962. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  197963. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  197964. || failed (snd_pcm_sw_params (handle, swParams)))
  197965. {
  197966. return false;
  197967. }
  197968. numChannelsRunning = numChannels;
  197969. return true;
  197970. }
  197971. bool write (float** const data, const int numSamples)
  197972. {
  197973. if (isInterleaved)
  197974. {
  197975. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197976. float* interleaved = static_cast <float*> (scratch.getData());
  197977. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  197978. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  197979. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  197980. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  197981. return false;
  197982. }
  197983. else
  197984. {
  197985. for (int i = 0; i < numChannelsRunning; ++i)
  197986. if (data[i] != 0)
  197987. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  197988. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  197989. if (failed (num))
  197990. {
  197991. if (num == -EPIPE)
  197992. {
  197993. if (failed (snd_pcm_prepare (handle)))
  197994. return false;
  197995. }
  197996. else if (num != -ESTRPIPE)
  197997. return false;
  197998. }
  197999. }
  198000. return true;
  198001. }
  198002. bool read (float** const data, const int numSamples)
  198003. {
  198004. if (isInterleaved)
  198005. {
  198006. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198007. float* interleaved = static_cast <float*> (scratch.getData());
  198008. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198009. if (failed (num))
  198010. {
  198011. if (num == -EPIPE)
  198012. {
  198013. if (failed (snd_pcm_prepare (handle)))
  198014. return false;
  198015. }
  198016. else if (num != -ESTRPIPE)
  198017. return false;
  198018. }
  198019. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198020. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198021. }
  198022. else
  198023. {
  198024. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198025. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198026. return false;
  198027. for (int i = 0; i < numChannelsRunning; ++i)
  198028. if (data[i] != 0)
  198029. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198030. }
  198031. return true;
  198032. }
  198033. juce_UseDebuggingNewOperator
  198034. snd_pcm_t* handle;
  198035. String error;
  198036. int bitDepth, numChannelsRunning;
  198037. private:
  198038. const bool isInput;
  198039. bool isInterleaved;
  198040. MemoryBlock scratch;
  198041. AudioDataConverters::DataFormat sampleFormat;
  198042. bool failed (const int errorNum)
  198043. {
  198044. if (errorNum >= 0)
  198045. return false;
  198046. error = snd_strerror (errorNum);
  198047. DBG ("ALSA error: " + error + "\n");
  198048. return true;
  198049. }
  198050. };
  198051. class ALSAThread : public Thread
  198052. {
  198053. public:
  198054. ALSAThread (const String& inputId_,
  198055. const String& outputId_)
  198056. : Thread ("Juce ALSA"),
  198057. sampleRate (0),
  198058. bufferSize (0),
  198059. callback (0),
  198060. inputId (inputId_),
  198061. outputId (outputId_),
  198062. outputDevice (0),
  198063. inputDevice (0),
  198064. numCallbacks (0),
  198065. totalNumInputChannels (0),
  198066. totalNumOutputChannels (0)
  198067. {
  198068. zeromem (outputChannelData, sizeof (outputChannelData));
  198069. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198070. zeromem (inputChannelData, sizeof (inputChannelData));
  198071. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198072. initialiseRatesAndChannels();
  198073. }
  198074. ~ALSAThread()
  198075. {
  198076. close();
  198077. }
  198078. void open (BigInteger inputChannels,
  198079. BigInteger outputChannels,
  198080. const double sampleRate_,
  198081. const int bufferSize_)
  198082. {
  198083. close();
  198084. error = String::empty;
  198085. sampleRate = sampleRate_;
  198086. bufferSize = bufferSize_;
  198087. currentInputChans.clear();
  198088. currentOutputChans.clear();
  198089. if (inputChannels.getHighestBit() >= 0)
  198090. {
  198091. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198092. {
  198093. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198094. if (inputChannels[i])
  198095. {
  198096. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198097. currentInputChans.setBit (i);
  198098. }
  198099. }
  198100. }
  198101. if (outputChannels.getHighestBit() >= 0)
  198102. {
  198103. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198104. {
  198105. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198106. if (outputChannels[i])
  198107. {
  198108. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198109. currentOutputChans.setBit (i);
  198110. }
  198111. }
  198112. }
  198113. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198114. {
  198115. outputDevice = new ALSADevice (outputId, false);
  198116. if (outputDevice->error.isNotEmpty())
  198117. {
  198118. error = outputDevice->error;
  198119. deleteAndZero (outputDevice);
  198120. return;
  198121. }
  198122. currentOutputChans.setRange (0, minChansOut, true);
  198123. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198124. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198125. bufferSize))
  198126. {
  198127. error = outputDevice->error;
  198128. deleteAndZero (outputDevice);
  198129. return;
  198130. }
  198131. }
  198132. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198133. {
  198134. inputDevice = new ALSADevice (inputId, true);
  198135. if (inputDevice->error.isNotEmpty())
  198136. {
  198137. error = inputDevice->error;
  198138. deleteAndZero (inputDevice);
  198139. return;
  198140. }
  198141. currentInputChans.setRange (0, minChansIn, true);
  198142. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198143. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198144. bufferSize))
  198145. {
  198146. error = inputDevice->error;
  198147. deleteAndZero (inputDevice);
  198148. return;
  198149. }
  198150. }
  198151. if (outputDevice == 0 && inputDevice == 0)
  198152. {
  198153. error = "no channels";
  198154. return;
  198155. }
  198156. if (outputDevice != 0 && inputDevice != 0)
  198157. {
  198158. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198159. }
  198160. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198161. return;
  198162. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198163. return;
  198164. startThread (9);
  198165. int count = 1000;
  198166. while (numCallbacks == 0)
  198167. {
  198168. sleep (5);
  198169. if (--count < 0 || ! isThreadRunning())
  198170. {
  198171. error = "device didn't start";
  198172. break;
  198173. }
  198174. }
  198175. }
  198176. void close()
  198177. {
  198178. stopThread (6000);
  198179. deleteAndZero (inputDevice);
  198180. deleteAndZero (outputDevice);
  198181. for (int i = 0; i < maxNumChans; ++i)
  198182. {
  198183. juce_free (inputChannelData [i]);
  198184. juce_free (outputChannelData [i]);
  198185. }
  198186. zeromem (outputChannelData, sizeof (outputChannelData));
  198187. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198188. zeromem (inputChannelData, sizeof (inputChannelData));
  198189. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198190. totalNumOutputChannels = 0;
  198191. totalNumInputChannels = 0;
  198192. numCallbacks = 0;
  198193. }
  198194. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198195. {
  198196. const ScopedLock sl (callbackLock);
  198197. callback = newCallback;
  198198. }
  198199. void run()
  198200. {
  198201. while (! threadShouldExit())
  198202. {
  198203. if (inputDevice != 0)
  198204. {
  198205. if (! inputDevice->read (inputChannelData, bufferSize))
  198206. {
  198207. DBG ("ALSA: read failure");
  198208. break;
  198209. }
  198210. }
  198211. if (threadShouldExit())
  198212. break;
  198213. {
  198214. const ScopedLock sl (callbackLock);
  198215. ++numCallbacks;
  198216. if (callback != 0)
  198217. {
  198218. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198219. totalNumInputChannels,
  198220. outputChannelDataForCallback,
  198221. totalNumOutputChannels,
  198222. bufferSize);
  198223. }
  198224. else
  198225. {
  198226. for (int i = 0; i < totalNumOutputChannels; ++i)
  198227. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198228. }
  198229. }
  198230. if (outputDevice != 0)
  198231. {
  198232. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198233. if (threadShouldExit())
  198234. break;
  198235. failed (snd_pcm_avail_update (outputDevice->handle));
  198236. if (! outputDevice->write (outputChannelData, bufferSize))
  198237. {
  198238. DBG ("ALSA: write failure");
  198239. break;
  198240. }
  198241. }
  198242. }
  198243. }
  198244. int getBitDepth() const throw()
  198245. {
  198246. if (outputDevice != 0)
  198247. return outputDevice->bitDepth;
  198248. if (inputDevice != 0)
  198249. return inputDevice->bitDepth;
  198250. return 16;
  198251. }
  198252. juce_UseDebuggingNewOperator
  198253. String error;
  198254. double sampleRate;
  198255. int bufferSize;
  198256. BigInteger currentInputChans, currentOutputChans;
  198257. Array <int> sampleRates;
  198258. StringArray channelNamesOut, channelNamesIn;
  198259. AudioIODeviceCallback* callback;
  198260. private:
  198261. const String inputId, outputId;
  198262. ALSADevice* outputDevice;
  198263. ALSADevice* inputDevice;
  198264. int numCallbacks;
  198265. CriticalSection callbackLock;
  198266. float* outputChannelData [maxNumChans];
  198267. float* outputChannelDataForCallback [maxNumChans];
  198268. int totalNumInputChannels;
  198269. float* inputChannelData [maxNumChans];
  198270. float* inputChannelDataForCallback [maxNumChans];
  198271. int totalNumOutputChannels;
  198272. unsigned int minChansOut, maxChansOut;
  198273. unsigned int minChansIn, maxChansIn;
  198274. bool failed (const int errorNum) throw()
  198275. {
  198276. if (errorNum >= 0)
  198277. return false;
  198278. error = snd_strerror (errorNum);
  198279. DBG ("ALSA error: " + error + "\n");
  198280. return true;
  198281. }
  198282. void initialiseRatesAndChannels() throw()
  198283. {
  198284. sampleRates.clear();
  198285. channelNamesOut.clear();
  198286. channelNamesIn.clear();
  198287. minChansOut = 0;
  198288. maxChansOut = 0;
  198289. minChansIn = 0;
  198290. maxChansIn = 0;
  198291. unsigned int dummy = 0;
  198292. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198293. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198294. unsigned int i;
  198295. for (i = 0; i < maxChansOut; ++i)
  198296. channelNamesOut.add ("channel " + String ((int) i + 1));
  198297. for (i = 0; i < maxChansIn; ++i)
  198298. channelNamesIn.add ("channel " + String ((int) i + 1));
  198299. }
  198300. };
  198301. class ALSAAudioIODevice : public AudioIODevice
  198302. {
  198303. public:
  198304. ALSAAudioIODevice (const String& deviceName,
  198305. const String& inputId_,
  198306. const String& outputId_)
  198307. : AudioIODevice (deviceName, "ALSA"),
  198308. inputId (inputId_),
  198309. outputId (outputId_),
  198310. isOpen_ (false),
  198311. isStarted (false),
  198312. internal (0)
  198313. {
  198314. internal = new ALSAThread (inputId, outputId);
  198315. }
  198316. ~ALSAAudioIODevice()
  198317. {
  198318. delete internal;
  198319. }
  198320. const StringArray getOutputChannelNames()
  198321. {
  198322. return internal->channelNamesOut;
  198323. }
  198324. const StringArray getInputChannelNames()
  198325. {
  198326. return internal->channelNamesIn;
  198327. }
  198328. int getNumSampleRates()
  198329. {
  198330. return internal->sampleRates.size();
  198331. }
  198332. double getSampleRate (int index)
  198333. {
  198334. return internal->sampleRates [index];
  198335. }
  198336. int getNumBufferSizesAvailable()
  198337. {
  198338. return 50;
  198339. }
  198340. int getBufferSizeSamples (int index)
  198341. {
  198342. int n = 16;
  198343. for (int i = 0; i < index; ++i)
  198344. n += n < 64 ? 16
  198345. : (n < 512 ? 32
  198346. : (n < 1024 ? 64
  198347. : (n < 2048 ? 128 : 256)));
  198348. return n;
  198349. }
  198350. int getDefaultBufferSize()
  198351. {
  198352. return 512;
  198353. }
  198354. const String open (const BigInteger& inputChannels,
  198355. const BigInteger& outputChannels,
  198356. double sampleRate,
  198357. int bufferSizeSamples)
  198358. {
  198359. close();
  198360. if (bufferSizeSamples <= 0)
  198361. bufferSizeSamples = getDefaultBufferSize();
  198362. if (sampleRate <= 0)
  198363. {
  198364. for (int i = 0; i < getNumSampleRates(); ++i)
  198365. {
  198366. if (getSampleRate (i) >= 44100)
  198367. {
  198368. sampleRate = getSampleRate (i);
  198369. break;
  198370. }
  198371. }
  198372. }
  198373. internal->open (inputChannels, outputChannels,
  198374. sampleRate, bufferSizeSamples);
  198375. isOpen_ = internal->error.isEmpty();
  198376. return internal->error;
  198377. }
  198378. void close()
  198379. {
  198380. stop();
  198381. internal->close();
  198382. isOpen_ = false;
  198383. }
  198384. bool isOpen()
  198385. {
  198386. return isOpen_;
  198387. }
  198388. int getCurrentBufferSizeSamples()
  198389. {
  198390. return internal->bufferSize;
  198391. }
  198392. double getCurrentSampleRate()
  198393. {
  198394. return internal->sampleRate;
  198395. }
  198396. int getCurrentBitDepth()
  198397. {
  198398. return internal->getBitDepth();
  198399. }
  198400. const BigInteger getActiveOutputChannels() const
  198401. {
  198402. return internal->currentOutputChans;
  198403. }
  198404. const BigInteger getActiveInputChannels() const
  198405. {
  198406. return internal->currentInputChans;
  198407. }
  198408. int getOutputLatencyInSamples()
  198409. {
  198410. return 0;
  198411. }
  198412. int getInputLatencyInSamples()
  198413. {
  198414. return 0;
  198415. }
  198416. void start (AudioIODeviceCallback* callback)
  198417. {
  198418. if (! isOpen_)
  198419. callback = 0;
  198420. internal->setCallback (callback);
  198421. if (callback != 0)
  198422. callback->audioDeviceAboutToStart (this);
  198423. isStarted = (callback != 0);
  198424. }
  198425. void stop()
  198426. {
  198427. AudioIODeviceCallback* const oldCallback = internal->callback;
  198428. start (0);
  198429. if (oldCallback != 0)
  198430. oldCallback->audioDeviceStopped();
  198431. }
  198432. bool isPlaying()
  198433. {
  198434. return isStarted && internal->error.isEmpty();
  198435. }
  198436. const String getLastError()
  198437. {
  198438. return internal->error;
  198439. }
  198440. String inputId, outputId;
  198441. private:
  198442. bool isOpen_, isStarted;
  198443. ALSAThread* internal;
  198444. };
  198445. class ALSAAudioIODeviceType : public AudioIODeviceType
  198446. {
  198447. public:
  198448. ALSAAudioIODeviceType()
  198449. : AudioIODeviceType ("ALSA"),
  198450. hasScanned (false)
  198451. {
  198452. }
  198453. ~ALSAAudioIODeviceType()
  198454. {
  198455. }
  198456. void scanForDevices()
  198457. {
  198458. if (hasScanned)
  198459. return;
  198460. hasScanned = true;
  198461. inputNames.clear();
  198462. inputIds.clear();
  198463. outputNames.clear();
  198464. outputIds.clear();
  198465. snd_ctl_t* handle;
  198466. snd_ctl_card_info_t* info;
  198467. snd_ctl_card_info_alloca (&info);
  198468. int cardNum = -1;
  198469. while (outputIds.size() + inputIds.size() <= 32)
  198470. {
  198471. snd_card_next (&cardNum);
  198472. if (cardNum < 0)
  198473. break;
  198474. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198475. {
  198476. if (snd_ctl_card_info (handle, info) >= 0)
  198477. {
  198478. String cardId (snd_ctl_card_info_get_id (info));
  198479. if (cardId.removeCharacters ("0123456789").isEmpty())
  198480. cardId = String (cardNum);
  198481. int device = -1;
  198482. for (;;)
  198483. {
  198484. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198485. break;
  198486. String id, name;
  198487. id << "hw:" << cardId << ',' << device;
  198488. bool isInput, isOutput;
  198489. if (testDevice (id, isInput, isOutput))
  198490. {
  198491. name << snd_ctl_card_info_get_name (info);
  198492. if (name.isEmpty())
  198493. name = id;
  198494. if (isInput)
  198495. {
  198496. inputNames.add (name);
  198497. inputIds.add (id);
  198498. }
  198499. if (isOutput)
  198500. {
  198501. outputNames.add (name);
  198502. outputIds.add (id);
  198503. }
  198504. }
  198505. }
  198506. }
  198507. snd_ctl_close (handle);
  198508. }
  198509. }
  198510. inputNames.appendNumbersToDuplicates (false, true);
  198511. outputNames.appendNumbersToDuplicates (false, true);
  198512. }
  198513. const StringArray getDeviceNames (bool wantInputNames) const
  198514. {
  198515. jassert (hasScanned); // need to call scanForDevices() before doing this
  198516. return wantInputNames ? inputNames : outputNames;
  198517. }
  198518. int getDefaultDeviceIndex (bool forInput) const
  198519. {
  198520. jassert (hasScanned); // need to call scanForDevices() before doing this
  198521. return 0;
  198522. }
  198523. bool hasSeparateInputsAndOutputs() const { return true; }
  198524. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198525. {
  198526. jassert (hasScanned); // need to call scanForDevices() before doing this
  198527. ALSAAudioIODevice* d = dynamic_cast <ALSAAudioIODevice*> (device);
  198528. if (d == 0)
  198529. return -1;
  198530. return asInput ? inputIds.indexOf (d->inputId)
  198531. : outputIds.indexOf (d->outputId);
  198532. }
  198533. AudioIODevice* createDevice (const String& outputDeviceName,
  198534. const String& inputDeviceName)
  198535. {
  198536. jassert (hasScanned); // need to call scanForDevices() before doing this
  198537. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198538. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198539. String deviceName (outputIndex >= 0 ? outputDeviceName
  198540. : inputDeviceName);
  198541. if (inputIndex >= 0 || outputIndex >= 0)
  198542. return new ALSAAudioIODevice (deviceName,
  198543. inputIds [inputIndex],
  198544. outputIds [outputIndex]);
  198545. return 0;
  198546. }
  198547. juce_UseDebuggingNewOperator
  198548. private:
  198549. StringArray inputNames, outputNames, inputIds, outputIds;
  198550. bool hasScanned;
  198551. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198552. {
  198553. unsigned int minChansOut = 0, maxChansOut = 0;
  198554. unsigned int minChansIn = 0, maxChansIn = 0;
  198555. Array <int> rates;
  198556. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198557. DBG ("ALSA device: " + id
  198558. + " outs=" + String ((int) minChansOut) + "-" + String ((int) maxChansOut)
  198559. + " ins=" + String ((int) minChansIn) + "-" + String ((int) maxChansIn)
  198560. + " rates=" + String (rates.size()));
  198561. isInput = maxChansIn > 0;
  198562. isOutput = maxChansOut > 0;
  198563. return (isInput || isOutput) && rates.size() > 0;
  198564. }
  198565. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198566. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198567. };
  198568. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198569. {
  198570. return new ALSAAudioIODeviceType();
  198571. }
  198572. #endif
  198573. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198574. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198575. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198576. // compiled on its own).
  198577. #ifdef JUCE_INCLUDED_FILE
  198578. #if JUCE_JACK
  198579. static void* juce_libjack_handle = 0;
  198580. void* juce_load_jack_function (const char* const name)
  198581. {
  198582. if (juce_libjack_handle == 0)
  198583. return 0;
  198584. return dlsym (juce_libjack_handle, name);
  198585. }
  198586. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198587. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198588. return_type fn_name argument_types { \
  198589. static fn_name##_ptr_t fn = 0; \
  198590. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198591. if (fn) return (*fn)arguments; \
  198592. else return 0; \
  198593. }
  198594. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198595. typedef void (*fn_name##_ptr_t)argument_types; \
  198596. void fn_name argument_types { \
  198597. static fn_name##_ptr_t fn = 0; \
  198598. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198599. if (fn) (*fn)arguments; \
  198600. }
  198601. 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));
  198602. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198603. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198604. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198605. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198606. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198607. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198608. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198609. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198610. 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));
  198611. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198612. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198613. 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));
  198614. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198615. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198616. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198617. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198618. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198619. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198620. #if JUCE_DEBUG
  198621. #define JACK_LOGGING_ENABLED 1
  198622. #endif
  198623. #if JACK_LOGGING_ENABLED
  198624. static void jack_Log (const String& s)
  198625. {
  198626. std::cerr << s << std::endl;
  198627. }
  198628. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198629. {
  198630. if (status & JackServerFailed || status & JackServerError)
  198631. jack_Log ("Unable to connect to JACK server");
  198632. if (status & JackVersionError)
  198633. jack_Log ("Client's protocol version does not match");
  198634. if (status & JackInvalidOption)
  198635. jack_Log ("The operation contained an invalid or unsupported option");
  198636. if (status & JackNameNotUnique)
  198637. jack_Log ("The desired client name was not unique");
  198638. if (status & JackNoSuchClient)
  198639. jack_Log ("Requested client does not exist");
  198640. if (status & JackInitFailure)
  198641. jack_Log ("Unable to initialize client");
  198642. }
  198643. #else
  198644. #define dumpJackErrorMessage(a) {}
  198645. #define jack_Log(...) {}
  198646. #endif
  198647. #ifndef JUCE_JACK_CLIENT_NAME
  198648. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198649. #endif
  198650. class JackAudioIODevice : public AudioIODevice
  198651. {
  198652. public:
  198653. JackAudioIODevice (const String& deviceName,
  198654. const String& inputId_,
  198655. const String& outputId_)
  198656. : AudioIODevice (deviceName, "JACK"),
  198657. inputId (inputId_),
  198658. outputId (outputId_),
  198659. isOpen_ (false),
  198660. callback (0),
  198661. totalNumberOfInputChannels (0),
  198662. totalNumberOfOutputChannels (0)
  198663. {
  198664. jassert (deviceName.isNotEmpty());
  198665. jack_status_t status;
  198666. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198667. if (client == 0)
  198668. {
  198669. dumpJackErrorMessage (status);
  198670. }
  198671. else
  198672. {
  198673. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198674. // open input ports
  198675. const StringArray inputChannels (getInputChannelNames());
  198676. for (int i = 0; i < inputChannels.size(); i++)
  198677. {
  198678. String inputName;
  198679. inputName << "in_" << ++totalNumberOfInputChannels;
  198680. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198681. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198682. }
  198683. // open output ports
  198684. const StringArray outputChannels (getOutputChannelNames());
  198685. for (int i = 0; i < outputChannels.size (); i++)
  198686. {
  198687. String outputName;
  198688. outputName << "out_" << ++totalNumberOfOutputChannels;
  198689. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198690. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198691. }
  198692. inChans.calloc (totalNumberOfInputChannels + 2);
  198693. outChans.calloc (totalNumberOfOutputChannels + 2);
  198694. }
  198695. }
  198696. ~JackAudioIODevice()
  198697. {
  198698. close();
  198699. if (client != 0)
  198700. {
  198701. JUCE_NAMESPACE::jack_client_close (client);
  198702. client = 0;
  198703. }
  198704. }
  198705. const StringArray getChannelNames (bool forInput) const
  198706. {
  198707. StringArray names;
  198708. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198709. forInput ? JackPortIsInput : JackPortIsOutput);
  198710. if (ports != 0)
  198711. {
  198712. int j = 0;
  198713. while (ports[j] != 0)
  198714. {
  198715. const String portName (ports [j++]);
  198716. if (portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198717. names.add (portName.fromFirstOccurrenceOf (":", false, false));
  198718. }
  198719. free (ports);
  198720. }
  198721. return names;
  198722. }
  198723. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198724. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198725. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198726. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198727. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198728. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198729. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198730. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  198731. double sampleRate, int bufferSizeSamples)
  198732. {
  198733. if (client == 0)
  198734. {
  198735. lastError = "No JACK client running";
  198736. return lastError;
  198737. }
  198738. lastError = String::empty;
  198739. close();
  198740. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198741. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198742. JUCE_NAMESPACE::jack_activate (client);
  198743. isOpen_ = true;
  198744. if (! inputChannels.isZero())
  198745. {
  198746. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198747. if (ports != 0)
  198748. {
  198749. const int numInputChannels = inputChannels.getHighestBit() + 1;
  198750. for (int i = 0; i < numInputChannels; ++i)
  198751. {
  198752. const String portName (ports[i]);
  198753. if (inputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198754. {
  198755. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198756. if (error != 0)
  198757. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198758. }
  198759. }
  198760. free (ports);
  198761. }
  198762. }
  198763. if (! outputChannels.isZero())
  198764. {
  198765. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198766. if (ports != 0)
  198767. {
  198768. const int numOutputChannels = outputChannels.getHighestBit() + 1;
  198769. for (int i = 0; i < numOutputChannels; ++i)
  198770. {
  198771. const String portName (ports[i]);
  198772. if (outputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198773. {
  198774. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198775. if (error != 0)
  198776. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198777. }
  198778. }
  198779. free (ports);
  198780. }
  198781. }
  198782. return lastError;
  198783. }
  198784. void close()
  198785. {
  198786. stop();
  198787. if (client != 0)
  198788. {
  198789. JUCE_NAMESPACE::jack_deactivate (client);
  198790. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198791. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198792. }
  198793. isOpen_ = false;
  198794. }
  198795. void start (AudioIODeviceCallback* newCallback)
  198796. {
  198797. if (isOpen_ && newCallback != callback)
  198798. {
  198799. if (newCallback != 0)
  198800. newCallback->audioDeviceAboutToStart (this);
  198801. AudioIODeviceCallback* const oldCallback = callback;
  198802. {
  198803. const ScopedLock sl (callbackLock);
  198804. callback = newCallback;
  198805. }
  198806. if (oldCallback != 0)
  198807. oldCallback->audioDeviceStopped();
  198808. }
  198809. }
  198810. void stop()
  198811. {
  198812. start (0);
  198813. }
  198814. bool isOpen() { return isOpen_; }
  198815. bool isPlaying() { return callback != 0; }
  198816. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198817. double getCurrentSampleRate() { return getSampleRate (0); }
  198818. int getCurrentBitDepth() { return 32; }
  198819. const String getLastError() { return lastError; }
  198820. const BigInteger getActiveOutputChannels() const
  198821. {
  198822. BigInteger outputBits;
  198823. for (int i = 0; i < outputPorts.size(); i++)
  198824. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198825. outputBits.setBit (i);
  198826. return outputBits;
  198827. }
  198828. const BigInteger getActiveInputChannels() const
  198829. {
  198830. BigInteger inputBits;
  198831. for (int i = 0; i < inputPorts.size(); i++)
  198832. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198833. inputBits.setBit (i);
  198834. return inputBits;
  198835. }
  198836. int getOutputLatencyInSamples()
  198837. {
  198838. int latency = 0;
  198839. for (int i = 0; i < outputPorts.size(); i++)
  198840. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198841. return latency;
  198842. }
  198843. int getInputLatencyInSamples()
  198844. {
  198845. int latency = 0;
  198846. for (int i = 0; i < inputPorts.size(); i++)
  198847. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198848. return latency;
  198849. }
  198850. String inputId, outputId;
  198851. private:
  198852. void process (const int numSamples)
  198853. {
  198854. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198855. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198856. {
  198857. jack_default_audio_sample_t* in
  198858. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198859. if (in != 0)
  198860. inChans [numActiveInChans++] = (float*) in;
  198861. }
  198862. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198863. {
  198864. jack_default_audio_sample_t* out
  198865. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198866. if (out != 0)
  198867. outChans [numActiveOutChans++] = (float*) out;
  198868. }
  198869. const ScopedLock sl (callbackLock);
  198870. if (callback != 0)
  198871. {
  198872. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198873. outChans, numActiveOutChans, numSamples);
  198874. }
  198875. else
  198876. {
  198877. for (i = 0; i < numActiveOutChans; ++i)
  198878. zeromem (outChans[i], sizeof (float) * numSamples);
  198879. }
  198880. }
  198881. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  198882. {
  198883. if (callbackArgument != 0)
  198884. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  198885. return 0;
  198886. }
  198887. static void threadInitCallback (void* callbackArgument)
  198888. {
  198889. jack_Log ("JackAudioIODevice::initialise");
  198890. }
  198891. static void shutdownCallback (void* callbackArgument)
  198892. {
  198893. jack_Log ("JackAudioIODevice::shutdown");
  198894. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  198895. if (device != 0)
  198896. {
  198897. device->client = 0;
  198898. device->close();
  198899. }
  198900. }
  198901. static void errorCallback (const char* msg)
  198902. {
  198903. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  198904. }
  198905. bool isOpen_;
  198906. jack_client_t* client;
  198907. String lastError;
  198908. AudioIODeviceCallback* callback;
  198909. CriticalSection callbackLock;
  198910. HeapBlock <float*> inChans, outChans;
  198911. int totalNumberOfInputChannels;
  198912. int totalNumberOfOutputChannels;
  198913. VoidArray inputPorts, outputPorts;
  198914. };
  198915. class JackAudioIODeviceType : public AudioIODeviceType
  198916. {
  198917. public:
  198918. JackAudioIODeviceType()
  198919. : AudioIODeviceType ("JACK"),
  198920. hasScanned (false)
  198921. {
  198922. }
  198923. ~JackAudioIODeviceType()
  198924. {
  198925. }
  198926. void scanForDevices()
  198927. {
  198928. hasScanned = true;
  198929. inputNames.clear();
  198930. inputIds.clear();
  198931. outputNames.clear();
  198932. outputIds.clear();
  198933. if (juce_libjack_handle == 0)
  198934. {
  198935. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  198936. if (juce_libjack_handle == 0)
  198937. return;
  198938. }
  198939. // open a dummy client
  198940. jack_status_t status;
  198941. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  198942. if (client == 0)
  198943. {
  198944. dumpJackErrorMessage (status);
  198945. }
  198946. else
  198947. {
  198948. // scan for output devices
  198949. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198950. if (ports != 0)
  198951. {
  198952. int j = 0;
  198953. while (ports[j] != 0)
  198954. {
  198955. String clientName (ports[j]);
  198956. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198957. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198958. && ! inputNames.contains (clientName))
  198959. {
  198960. inputNames.add (clientName);
  198961. inputIds.add (ports [j]);
  198962. }
  198963. ++j;
  198964. }
  198965. free (ports);
  198966. }
  198967. // scan for input devices
  198968. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198969. if (ports != 0)
  198970. {
  198971. int j = 0;
  198972. while (ports[j] != 0)
  198973. {
  198974. String clientName (ports[j]);
  198975. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198976. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198977. && ! outputNames.contains (clientName))
  198978. {
  198979. outputNames.add (clientName);
  198980. outputIds.add (ports [j]);
  198981. }
  198982. ++j;
  198983. }
  198984. free (ports);
  198985. }
  198986. JUCE_NAMESPACE::jack_client_close (client);
  198987. }
  198988. }
  198989. const StringArray getDeviceNames (bool wantInputNames) const
  198990. {
  198991. jassert (hasScanned); // need to call scanForDevices() before doing this
  198992. return wantInputNames ? inputNames : outputNames;
  198993. }
  198994. int getDefaultDeviceIndex (bool forInput) const
  198995. {
  198996. jassert (hasScanned); // need to call scanForDevices() before doing this
  198997. return 0;
  198998. }
  198999. bool hasSeparateInputsAndOutputs() const { return true; }
  199000. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  199001. {
  199002. jassert (hasScanned); // need to call scanForDevices() before doing this
  199003. JackAudioIODevice* d = dynamic_cast <JackAudioIODevice*> (device);
  199004. if (d == 0)
  199005. return -1;
  199006. return asInput ? inputIds.indexOf (d->inputId)
  199007. : outputIds.indexOf (d->outputId);
  199008. }
  199009. AudioIODevice* createDevice (const String& outputDeviceName,
  199010. const String& inputDeviceName)
  199011. {
  199012. jassert (hasScanned); // need to call scanForDevices() before doing this
  199013. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199014. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199015. if (inputIndex >= 0 || outputIndex >= 0)
  199016. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199017. : inputDeviceName,
  199018. inputIds [inputIndex],
  199019. outputIds [outputIndex]);
  199020. return 0;
  199021. }
  199022. juce_UseDebuggingNewOperator
  199023. private:
  199024. StringArray inputNames, outputNames, inputIds, outputIds;
  199025. bool hasScanned;
  199026. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199027. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199028. };
  199029. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199030. {
  199031. return new JackAudioIODeviceType();
  199032. }
  199033. #else // if JACK is turned off..
  199034. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199035. #endif
  199036. #endif
  199037. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199038. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199039. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199040. // compiled on its own).
  199041. #if JUCE_INCLUDED_FILE
  199042. #if JUCE_ALSA
  199043. static snd_seq_t* iterateDevices (const bool forInput,
  199044. StringArray& deviceNamesFound,
  199045. const int deviceIndexToOpen)
  199046. {
  199047. snd_seq_t* returnedHandle = 0;
  199048. snd_seq_t* seqHandle;
  199049. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199050. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199051. {
  199052. snd_seq_system_info_t* systemInfo;
  199053. snd_seq_client_info_t* clientInfo;
  199054. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199055. {
  199056. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199057. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199058. {
  199059. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199060. while (--numClients >= 0 && returnedHandle == 0)
  199061. {
  199062. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199063. {
  199064. snd_seq_port_info_t* portInfo;
  199065. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199066. {
  199067. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199068. const int client = snd_seq_client_info_get_client (clientInfo);
  199069. snd_seq_port_info_set_client (portInfo, client);
  199070. snd_seq_port_info_set_port (portInfo, -1);
  199071. while (--numPorts >= 0)
  199072. {
  199073. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199074. && (snd_seq_port_info_get_capability (portInfo)
  199075. & (forInput ? SND_SEQ_PORT_CAP_READ
  199076. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199077. {
  199078. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199079. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199080. {
  199081. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199082. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199083. if (sourcePort != -1)
  199084. {
  199085. snd_seq_set_client_name (seqHandle,
  199086. forInput ? "Juce Midi Input"
  199087. : "Juce Midi Output");
  199088. const int portId
  199089. = snd_seq_create_simple_port (seqHandle,
  199090. forInput ? "Juce Midi In Port"
  199091. : "Juce Midi Out Port",
  199092. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199093. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199094. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199095. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199096. returnedHandle = seqHandle;
  199097. }
  199098. }
  199099. }
  199100. }
  199101. snd_seq_port_info_free (portInfo);
  199102. }
  199103. }
  199104. }
  199105. snd_seq_client_info_free (clientInfo);
  199106. }
  199107. snd_seq_system_info_free (systemInfo);
  199108. }
  199109. if (returnedHandle == 0)
  199110. snd_seq_close (seqHandle);
  199111. }
  199112. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199113. return returnedHandle;
  199114. }
  199115. static snd_seq_t* createDevice (const bool forInput,
  199116. const String& deviceNameToOpen)
  199117. {
  199118. snd_seq_t* seqHandle = 0;
  199119. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199120. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199121. {
  199122. snd_seq_set_client_name (seqHandle,
  199123. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199124. const int portId
  199125. = snd_seq_create_simple_port (seqHandle,
  199126. forInput ? "in"
  199127. : "out",
  199128. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199129. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199130. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199131. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199132. if (portId < 0)
  199133. {
  199134. snd_seq_close (seqHandle);
  199135. seqHandle = 0;
  199136. }
  199137. }
  199138. return seqHandle;
  199139. }
  199140. class MidiOutputDevice
  199141. {
  199142. public:
  199143. MidiOutputDevice (MidiOutput* const midiOutput_,
  199144. snd_seq_t* const seqHandle_)
  199145. :
  199146. midiOutput (midiOutput_),
  199147. seqHandle (seqHandle_),
  199148. maxEventSize (16 * 1024)
  199149. {
  199150. jassert (seqHandle != 0 && midiOutput != 0);
  199151. snd_midi_event_new (maxEventSize, &midiParser);
  199152. }
  199153. ~MidiOutputDevice()
  199154. {
  199155. snd_midi_event_free (midiParser);
  199156. snd_seq_close (seqHandle);
  199157. }
  199158. void sendMessageNow (const MidiMessage& message)
  199159. {
  199160. if (message.getRawDataSize() > maxEventSize)
  199161. {
  199162. maxEventSize = message.getRawDataSize();
  199163. snd_midi_event_free (midiParser);
  199164. snd_midi_event_new (maxEventSize, &midiParser);
  199165. }
  199166. snd_seq_event_t event;
  199167. snd_seq_ev_clear (&event);
  199168. snd_midi_event_encode (midiParser,
  199169. message.getRawData(),
  199170. message.getRawDataSize(),
  199171. &event);
  199172. snd_midi_event_reset_encode (midiParser);
  199173. snd_seq_ev_set_source (&event, 0);
  199174. snd_seq_ev_set_subs (&event);
  199175. snd_seq_ev_set_direct (&event);
  199176. snd_seq_event_output (seqHandle, &event);
  199177. snd_seq_drain_output (seqHandle);
  199178. }
  199179. juce_UseDebuggingNewOperator
  199180. private:
  199181. MidiOutput* const midiOutput;
  199182. snd_seq_t* const seqHandle;
  199183. snd_midi_event_t* midiParser;
  199184. int maxEventSize;
  199185. };
  199186. const StringArray MidiOutput::getDevices()
  199187. {
  199188. StringArray devices;
  199189. iterateDevices (false, devices, -1);
  199190. return devices;
  199191. }
  199192. int MidiOutput::getDefaultDeviceIndex()
  199193. {
  199194. return 0;
  199195. }
  199196. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199197. {
  199198. MidiOutput* newDevice = 0;
  199199. StringArray devices;
  199200. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199201. if (handle != 0)
  199202. {
  199203. newDevice = new MidiOutput();
  199204. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199205. }
  199206. return newDevice;
  199207. }
  199208. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199209. {
  199210. MidiOutput* newDevice = 0;
  199211. snd_seq_t* const handle = createDevice (false, deviceName);
  199212. if (handle != 0)
  199213. {
  199214. newDevice = new MidiOutput();
  199215. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199216. }
  199217. return newDevice;
  199218. }
  199219. MidiOutput::~MidiOutput()
  199220. {
  199221. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199222. delete device;
  199223. }
  199224. void MidiOutput::reset()
  199225. {
  199226. }
  199227. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199228. {
  199229. return false;
  199230. }
  199231. void MidiOutput::setVolume (float leftVol, float rightVol)
  199232. {
  199233. }
  199234. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199235. {
  199236. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199237. }
  199238. class MidiInputThread : public Thread
  199239. {
  199240. public:
  199241. MidiInputThread (MidiInput* const midiInput_,
  199242. snd_seq_t* const seqHandle_,
  199243. MidiInputCallback* const callback_)
  199244. : Thread ("Juce MIDI Input"),
  199245. midiInput (midiInput_),
  199246. seqHandle (seqHandle_),
  199247. callback (callback_)
  199248. {
  199249. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199250. }
  199251. ~MidiInputThread()
  199252. {
  199253. snd_seq_close (seqHandle);
  199254. }
  199255. void run()
  199256. {
  199257. const int maxEventSize = 16 * 1024;
  199258. snd_midi_event_t* midiParser;
  199259. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199260. {
  199261. HeapBlock <uint8> buffer (maxEventSize);
  199262. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199263. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199264. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199265. while (! threadShouldExit())
  199266. {
  199267. if (poll (pfd, numPfds, 500) > 0)
  199268. {
  199269. snd_seq_event_t* inputEvent = 0;
  199270. snd_seq_nonblock (seqHandle, 1);
  199271. do
  199272. {
  199273. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199274. {
  199275. // xxx what about SYSEXes that are too big for the buffer?
  199276. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199277. snd_midi_event_reset_decode (midiParser);
  199278. if (numBytes > 0)
  199279. {
  199280. const MidiMessage message ((const uint8*) buffer,
  199281. numBytes,
  199282. Time::getMillisecondCounter() * 0.001);
  199283. callback->handleIncomingMidiMessage (midiInput, message);
  199284. }
  199285. snd_seq_free_event (inputEvent);
  199286. }
  199287. }
  199288. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199289. snd_seq_free_event (inputEvent);
  199290. }
  199291. }
  199292. snd_midi_event_free (midiParser);
  199293. }
  199294. };
  199295. juce_UseDebuggingNewOperator
  199296. private:
  199297. MidiInput* const midiInput;
  199298. snd_seq_t* const seqHandle;
  199299. MidiInputCallback* const callback;
  199300. };
  199301. MidiInput::MidiInput (const String& name_)
  199302. : name (name_),
  199303. internal (0)
  199304. {
  199305. }
  199306. MidiInput::~MidiInput()
  199307. {
  199308. stop();
  199309. MidiInputThread* const thread = (MidiInputThread*) internal;
  199310. delete thread;
  199311. }
  199312. void MidiInput::start()
  199313. {
  199314. ((MidiInputThread*) internal)->startThread();
  199315. }
  199316. void MidiInput::stop()
  199317. {
  199318. ((MidiInputThread*) internal)->stopThread (3000);
  199319. }
  199320. int MidiInput::getDefaultDeviceIndex()
  199321. {
  199322. return 0;
  199323. }
  199324. const StringArray MidiInput::getDevices()
  199325. {
  199326. StringArray devices;
  199327. iterateDevices (true, devices, -1);
  199328. return devices;
  199329. }
  199330. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199331. {
  199332. MidiInput* newDevice = 0;
  199333. StringArray devices;
  199334. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199335. if (handle != 0)
  199336. {
  199337. newDevice = new MidiInput (devices [deviceIndex]);
  199338. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199339. }
  199340. return newDevice;
  199341. }
  199342. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199343. {
  199344. MidiInput* newDevice = 0;
  199345. snd_seq_t* const handle = createDevice (true, deviceName);
  199346. if (handle != 0)
  199347. {
  199348. newDevice = new MidiInput (deviceName);
  199349. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199350. }
  199351. return newDevice;
  199352. }
  199353. #else
  199354. // (These are just stub functions if ALSA is unavailable...)
  199355. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199356. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199357. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199358. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199359. MidiOutput::~MidiOutput() {}
  199360. void MidiOutput::reset() {}
  199361. bool MidiOutput::getVolume (float&, float&) { return false; }
  199362. void MidiOutput::setVolume (float, float) {}
  199363. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199364. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199365. MidiInput::~MidiInput() {}
  199366. void MidiInput::start() {}
  199367. void MidiInput::stop() {}
  199368. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199369. const StringArray MidiInput::getDevices() { return StringArray(); }
  199370. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199371. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199372. #endif
  199373. #endif
  199374. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199375. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199376. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199377. // compiled on its own).
  199378. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199379. AudioCDReader::AudioCDReader()
  199380. : AudioFormatReader (0, "CD Audio")
  199381. {
  199382. }
  199383. const StringArray AudioCDReader::getAvailableCDNames()
  199384. {
  199385. StringArray names;
  199386. return names;
  199387. }
  199388. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199389. {
  199390. return 0;
  199391. }
  199392. AudioCDReader::~AudioCDReader()
  199393. {
  199394. }
  199395. void AudioCDReader::refreshTrackLengths()
  199396. {
  199397. }
  199398. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199399. int64 startSampleInFile, int numSamples)
  199400. {
  199401. return false;
  199402. }
  199403. bool AudioCDReader::isCDStillPresent() const
  199404. {
  199405. return false;
  199406. }
  199407. int AudioCDReader::getNumTracks() const
  199408. {
  199409. return 0;
  199410. }
  199411. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199412. {
  199413. return 0;
  199414. }
  199415. bool AudioCDReader::isTrackAudio (int trackNum) const
  199416. {
  199417. return false;
  199418. }
  199419. void AudioCDReader::enableIndexScanning (bool b)
  199420. {
  199421. }
  199422. int AudioCDReader::getLastIndex() const
  199423. {
  199424. return 0;
  199425. }
  199426. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199427. {
  199428. return Array<int>();
  199429. }
  199430. int AudioCDReader::getCDDBId()
  199431. {
  199432. return 0;
  199433. }
  199434. #endif
  199435. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199436. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199437. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199438. // compiled on its own).
  199439. #if JUCE_INCLUDED_FILE
  199440. void FileChooser::showPlatformDialog (Array<File>& results,
  199441. const String& title,
  199442. const File& file,
  199443. const String& filters,
  199444. bool isDirectory,
  199445. bool selectsFiles,
  199446. bool isSave,
  199447. bool warnAboutOverwritingExistingFiles,
  199448. bool selectMultipleFiles,
  199449. FilePreviewComponent* previewComponent)
  199450. {
  199451. const String separator (":");
  199452. String command ("zenity --file-selection");
  199453. if (title.isNotEmpty())
  199454. command << " --title=\"" << title << "\"";
  199455. if (file != File::nonexistent)
  199456. command << " --filename=\"" << file.getFullPathName () << "\"";
  199457. if (isDirectory)
  199458. command << " --directory";
  199459. if (isSave)
  199460. command << " --save";
  199461. if (selectMultipleFiles)
  199462. command << " --multiple --separator=\"" << separator << "\"";
  199463. command << " 2>&1";
  199464. MemoryOutputStream result;
  199465. int status = -1;
  199466. FILE* stream = popen (command.toUTF8(), "r");
  199467. if (stream != 0)
  199468. {
  199469. for (;;)
  199470. {
  199471. char buffer [1024];
  199472. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199473. if (bytesRead <= 0)
  199474. break;
  199475. result.write (buffer, bytesRead);
  199476. }
  199477. status = pclose (stream);
  199478. }
  199479. if (status == 0)
  199480. {
  199481. StringArray tokens;
  199482. if (selectMultipleFiles)
  199483. tokens.addTokens (result.toUTF8(), separator, String::empty);
  199484. else
  199485. tokens.add (result.toUTF8());
  199486. for (int i = 0; i < tokens.size(); i++)
  199487. results.add (File (tokens[i]));
  199488. return;
  199489. }
  199490. //xxx ain't got one!
  199491. jassertfalse
  199492. }
  199493. #endif
  199494. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199495. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199496. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199497. // compiled on its own).
  199498. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199499. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199500. : browser (0),
  199501. blankPageShown (false),
  199502. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199503. {
  199504. setOpaque (true);
  199505. }
  199506. WebBrowserComponent::~WebBrowserComponent()
  199507. {
  199508. }
  199509. void WebBrowserComponent::goToURL (const String& url,
  199510. const StringArray* headers,
  199511. const MemoryBlock* postData)
  199512. {
  199513. lastURL = url;
  199514. lastHeaders.clear();
  199515. if (headers != 0)
  199516. lastHeaders = *headers;
  199517. lastPostData.setSize (0);
  199518. if (postData != 0)
  199519. lastPostData = *postData;
  199520. blankPageShown = false;
  199521. }
  199522. void WebBrowserComponent::stop()
  199523. {
  199524. }
  199525. void WebBrowserComponent::goBack()
  199526. {
  199527. lastURL = String::empty;
  199528. blankPageShown = false;
  199529. }
  199530. void WebBrowserComponent::goForward()
  199531. {
  199532. lastURL = String::empty;
  199533. }
  199534. void WebBrowserComponent::refresh()
  199535. {
  199536. }
  199537. void WebBrowserComponent::paint (Graphics& g)
  199538. {
  199539. g.fillAll (Colours::white);
  199540. }
  199541. void WebBrowserComponent::checkWindowAssociation()
  199542. {
  199543. }
  199544. void WebBrowserComponent::reloadLastURL()
  199545. {
  199546. if (lastURL.isNotEmpty())
  199547. {
  199548. goToURL (lastURL, &lastHeaders, &lastPostData);
  199549. lastURL = String::empty;
  199550. }
  199551. }
  199552. void WebBrowserComponent::parentHierarchyChanged()
  199553. {
  199554. checkWindowAssociation();
  199555. }
  199556. void WebBrowserComponent::resized()
  199557. {
  199558. }
  199559. void WebBrowserComponent::visibilityChanged()
  199560. {
  199561. checkWindowAssociation();
  199562. }
  199563. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199564. {
  199565. return true;
  199566. }
  199567. #endif
  199568. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199569. #endif
  199570. END_JUCE_NAMESPACE
  199571. #endif
  199572. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199573. #endif
  199574. #if JUCE_MAC || JUCE_IPHONE
  199575. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199576. #if JUCE_MAC || JUCE_IPHONE
  199577. BEGIN_JUCE_NAMESPACE
  199578. #undef Point
  199579. #define JUCE_INCLUDED_FILE 1
  199580. // Now include the actual code files..
  199581. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199582. #ifndef JUCE_ObjCExtraSuffix
  199583. #define JUCE_ObjCExtraSuffix 3
  199584. #endif
  199585. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199586. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199587. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199588. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199589. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199590. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199591. // compiled on its own).
  199592. #if JUCE_INCLUDED_FILE
  199593. static const String nsStringToJuce (NSString* s)
  199594. {
  199595. return String::fromUTF8 ([s UTF8String]);
  199596. }
  199597. static NSString* juceStringToNS (const String& s)
  199598. {
  199599. return [NSString stringWithUTF8String: s.toUTF8()];
  199600. }
  199601. static const String convertUTF16ToString (const UniChar* utf16)
  199602. {
  199603. String s;
  199604. while (*utf16 != 0)
  199605. s += (juce_wchar) *utf16++;
  199606. return s;
  199607. }
  199608. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199609. {
  199610. String result;
  199611. if (cfString != 0)
  199612. {
  199613. CFRange range = { 0, CFStringGetLength (cfString) };
  199614. HeapBlock <UniChar> u (range.length + 1);
  199615. CFStringGetCharacters (cfString, range, u);
  199616. u[range.length] = 0;
  199617. result = convertUTF16ToString (u);
  199618. }
  199619. return result;
  199620. }
  199621. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199622. {
  199623. const int len = s.length();
  199624. const juce_wchar* t = (const juce_wchar*) s;
  199625. HeapBlock <UniChar> temp (len + 2);
  199626. for (int i = 0; i <= len; ++i)
  199627. temp[i] = t[i];
  199628. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199629. }
  199630. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199631. {
  199632. #if JUCE_IPHONE
  199633. const ScopedAutoReleasePool pool;
  199634. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199635. #else
  199636. UnicodeMapping map;
  199637. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199638. kUnicodeNoSubset,
  199639. kTextEncodingDefaultFormat);
  199640. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199641. kUnicodeCanonicalCompVariant,
  199642. kTextEncodingDefaultFormat);
  199643. map.mappingVersion = kUnicodeUseLatestMapping;
  199644. UnicodeToTextInfo conversionInfo = 0;
  199645. String result;
  199646. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199647. {
  199648. const int len = s.length();
  199649. HeapBlock <UniChar> tempIn, tempOut;
  199650. tempIn.calloc (len + 2);
  199651. tempOut.calloc (len + 2);
  199652. for (int i = 0; i <= len; ++i)
  199653. tempIn[i] = s[i];
  199654. ByteCount bytesRead = 0;
  199655. ByteCount outputBufferSize = 0;
  199656. if (ConvertFromUnicodeToText (conversionInfo,
  199657. len * sizeof (UniChar), tempIn,
  199658. kUnicodeDefaultDirectionMask,
  199659. 0, 0, 0, 0,
  199660. len * sizeof (UniChar), &bytesRead,
  199661. &outputBufferSize, tempOut) == noErr)
  199662. {
  199663. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199664. tchar* t = const_cast <tchar*> ((const tchar*) result);
  199665. unsigned int i;
  199666. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199667. t[i] = (tchar) tempOut[i];
  199668. t[i] = 0;
  199669. }
  199670. DisposeUnicodeToTextInfo (&conversionInfo);
  199671. }
  199672. return result;
  199673. #endif
  199674. }
  199675. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199676. void SystemClipboard::copyTextToClipboard (const String& text)
  199677. {
  199678. #if JUCE_IPHONE
  199679. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199680. forPasteboardType: @"public.text"];
  199681. #else
  199682. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199683. owner: nil];
  199684. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199685. forType: NSStringPboardType];
  199686. #endif
  199687. }
  199688. const String SystemClipboard::getTextFromClipboard()
  199689. {
  199690. #if JUCE_IPHONE
  199691. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199692. #else
  199693. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199694. #endif
  199695. return text == 0 ? String::empty
  199696. : nsStringToJuce (text);
  199697. }
  199698. #endif
  199699. #endif
  199700. /*** End of inlined file: juce_mac_Strings.mm ***/
  199701. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199702. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199703. // compiled on its own).
  199704. #if JUCE_INCLUDED_FILE
  199705. namespace SystemStatsHelpers
  199706. {
  199707. static int64 highResTimerFrequency = 0;
  199708. static double highResTimerToMillisecRatio = 0;
  199709. #if JUCE_INTEL
  199710. static void juce_getCpuVendor (char* const v) throw()
  199711. {
  199712. int vendor[4];
  199713. zerostruct (vendor);
  199714. int dummy = 0;
  199715. asm ("mov %%ebx, %%esi \n\t"
  199716. "cpuid \n\t"
  199717. "xchg %%esi, %%ebx"
  199718. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199719. memcpy (v, vendor, 16);
  199720. }
  199721. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199722. {
  199723. unsigned int cpu = 0;
  199724. unsigned int ext = 0;
  199725. unsigned int family = 0;
  199726. unsigned int dummy = 0;
  199727. asm ("mov %%ebx, %%esi \n\t"
  199728. "cpuid \n\t"
  199729. "xchg %%esi, %%ebx"
  199730. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199731. familyModel = family;
  199732. extFeatures = ext;
  199733. return cpu;
  199734. }
  199735. struct CPUFlags
  199736. {
  199737. bool hasMMX : 1;
  199738. bool hasSSE : 1;
  199739. bool hasSSE2 : 1;
  199740. bool has3DNow : 1;
  199741. };
  199742. static CPUFlags cpuFlags;
  199743. #endif
  199744. }
  199745. void SystemStats::initialiseStats() throw()
  199746. {
  199747. using namespace SystemStatsHelpers;
  199748. static bool initialised = false;
  199749. if (! initialised)
  199750. {
  199751. initialised = true;
  199752. #if JUCE_MAC
  199753. // extremely annoying: adding this line stops the apple menu items from working. Of
  199754. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199755. // any events.
  199756. //NSApplicationLoad();
  199757. [NSApplication sharedApplication];
  199758. #endif
  199759. #if JUCE_INTEL
  199760. {
  199761. unsigned int familyModel, extFeatures;
  199762. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199763. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199764. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199765. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199766. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199767. }
  199768. #endif
  199769. mach_timebase_info_data_t timebase;
  199770. (void) mach_timebase_info (&timebase);
  199771. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199772. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199773. String s (SystemStats::getJUCEVersion());
  199774. rlimit lim;
  199775. getrlimit (RLIMIT_NOFILE, &lim);
  199776. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199777. setrlimit (RLIMIT_NOFILE, &lim);
  199778. }
  199779. }
  199780. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199781. {
  199782. return MacOSX;
  199783. }
  199784. const String SystemStats::getOperatingSystemName() throw()
  199785. {
  199786. return "Mac OS X";
  199787. }
  199788. bool SystemStats::isOperatingSystem64Bit() throw()
  199789. {
  199790. #if JUCE_64BIT
  199791. return true;
  199792. #else
  199793. //xxx not sure how to find this out?..
  199794. return false;
  199795. #endif
  199796. }
  199797. int SystemStats::getMemorySizeInMegabytes() throw()
  199798. {
  199799. uint64 mem = 0;
  199800. size_t memSize = sizeof (mem);
  199801. int mib[] = { CTL_HW, HW_MEMSIZE };
  199802. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199803. return (int) (mem / (1024 * 1024));
  199804. }
  199805. bool SystemStats::hasMMX() throw()
  199806. {
  199807. #if JUCE_INTEL
  199808. return SystemStatsHelpers::cpuFlags.hasMMX;
  199809. #else
  199810. return false;
  199811. #endif
  199812. }
  199813. bool SystemStats::hasSSE() throw()
  199814. {
  199815. #if JUCE_INTEL
  199816. return SystemStatsHelpers::cpuFlags.hasSSE;
  199817. #else
  199818. return false;
  199819. #endif
  199820. }
  199821. bool SystemStats::hasSSE2() throw()
  199822. {
  199823. #if JUCE_INTEL
  199824. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199825. #else
  199826. return false;
  199827. #endif
  199828. }
  199829. bool SystemStats::has3DNow() throw()
  199830. {
  199831. #if JUCE_INTEL
  199832. return SystemStatsHelpers::cpuFlags.has3DNow;
  199833. #else
  199834. return false;
  199835. #endif
  199836. }
  199837. const String SystemStats::getCpuVendor() throw()
  199838. {
  199839. #if JUCE_INTEL
  199840. char v [16];
  199841. SystemStatsHelpers::juce_getCpuVendor (v);
  199842. return String (v, 16);
  199843. #else
  199844. return String::empty;
  199845. #endif
  199846. }
  199847. int SystemStats::getCpuSpeedInMegaherz() throw()
  199848. {
  199849. uint64 speedHz = 0;
  199850. size_t speedSize = sizeof (speedHz);
  199851. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199852. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199853. #if JUCE_BIG_ENDIAN
  199854. if (speedSize == 4)
  199855. speedHz >>= 32;
  199856. #endif
  199857. return (int) (speedHz / 1000000);
  199858. }
  199859. int SystemStats::getNumCpus() throw()
  199860. {
  199861. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199862. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199863. #else
  199864. return MPProcessors();
  199865. #endif
  199866. }
  199867. const String SystemStats::getLogonName()
  199868. {
  199869. return nsStringToJuce (NSUserName());
  199870. }
  199871. const String SystemStats::getFullUserName()
  199872. {
  199873. return nsStringToJuce (NSFullUserName());
  199874. }
  199875. uint32 juce_millisecondsSinceStartup() throw()
  199876. {
  199877. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  199878. }
  199879. double Time::getMillisecondCounterHiRes() throw()
  199880. {
  199881. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  199882. }
  199883. int64 Time::getHighResolutionTicks() throw()
  199884. {
  199885. return (int64) mach_absolute_time();
  199886. }
  199887. int64 Time::getHighResolutionTicksPerSecond() throw()
  199888. {
  199889. return SystemStatsHelpers::highResTimerFrequency;
  199890. }
  199891. int64 SystemStats::getClockCycleCounter() throw()
  199892. {
  199893. return (int64) mach_absolute_time();
  199894. }
  199895. bool Time::setSystemTimeToThisTime() const throw()
  199896. {
  199897. jassertfalse
  199898. return false;
  199899. }
  199900. int SystemStats::getPageSize() throw()
  199901. {
  199902. return (int) NSPageSize();
  199903. }
  199904. void PlatformUtilities::fpuReset()
  199905. {
  199906. }
  199907. #endif
  199908. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  199909. /*** Start of inlined file: juce_mac_Network.mm ***/
  199910. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199911. // compiled on its own).
  199912. #if JUCE_INCLUDED_FILE
  199913. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  199914. {
  199915. #ifndef IFT_ETHER
  199916. #define IFT_ETHER 6
  199917. #endif
  199918. ifaddrs* addrs = 0;
  199919. int numResults = 0;
  199920. if (getifaddrs (&addrs) == 0)
  199921. {
  199922. const ifaddrs* cursor = addrs;
  199923. while (cursor != 0 && numResults < maxNum)
  199924. {
  199925. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  199926. if (sto->ss_family == AF_LINK)
  199927. {
  199928. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  199929. if (sadd->sdl_type == IFT_ETHER)
  199930. {
  199931. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  199932. uint64 a = 0;
  199933. for (int i = 6; --i >= 0;)
  199934. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  199935. *addresses++ = (int64) a;
  199936. ++numResults;
  199937. }
  199938. }
  199939. cursor = cursor->ifa_next;
  199940. }
  199941. freeifaddrs (addrs);
  199942. }
  199943. return numResults;
  199944. }
  199945. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  199946. const String& emailSubject,
  199947. const String& bodyText,
  199948. const StringArray& filesToAttach)
  199949. {
  199950. #if JUCE_IPHONE
  199951. //xxx probably need to use MFMailComposeViewController
  199952. jassertfalse
  199953. return false;
  199954. #else
  199955. const ScopedAutoReleasePool pool;
  199956. String script;
  199957. script << "tell application \"Mail\"\r\n"
  199958. "set newMessage to make new outgoing message with properties {subject:\""
  199959. << emailSubject.replace ("\"", "\\\"")
  199960. << "\", content:\""
  199961. << bodyText.replace ("\"", "\\\"")
  199962. << "\" & return & return}\r\n"
  199963. "tell newMessage\r\n"
  199964. "set visible to true\r\n"
  199965. "set sender to \"sdfsdfsdfewf\"\r\n"
  199966. "make new to recipient at end of to recipients with properties {address:\""
  199967. << targetEmailAddress
  199968. << "\"}\r\n";
  199969. for (int i = 0; i < filesToAttach.size(); ++i)
  199970. {
  199971. script << "tell content\r\n"
  199972. "make new attachment with properties {file name:\""
  199973. << filesToAttach[i].replace ("\"", "\\\"")
  199974. << "\"} at after the last paragraph\r\n"
  199975. "end tell\r\n";
  199976. }
  199977. script << "end tell\r\n"
  199978. "end tell\r\n";
  199979. NSAppleScript* s = [[NSAppleScript alloc]
  199980. initWithSource: juceStringToNS (script)];
  199981. NSDictionary* error = 0;
  199982. const bool ok = [s executeAndReturnError: &error] != nil;
  199983. [s release];
  199984. return ok;
  199985. #endif
  199986. }
  199987. END_JUCE_NAMESPACE
  199988. using namespace JUCE_NAMESPACE;
  199989. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  199990. @interface JuceURLConnection : NSObject
  199991. {
  199992. @public
  199993. NSURLRequest* request;
  199994. NSURLConnection* connection;
  199995. NSMutableData* data;
  199996. Thread* runLoopThread;
  199997. bool initialised, hasFailed, hasFinished;
  199998. int position;
  199999. int64 contentLength;
  200000. NSLock* dataLock;
  200001. }
  200002. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200003. - (void) dealloc;
  200004. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200005. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200006. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200007. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200008. - (BOOL) isOpen;
  200009. - (int) read: (char*) dest numBytes: (int) num;
  200010. - (int) readPosition;
  200011. - (void) stop;
  200012. - (void) createConnection;
  200013. @end
  200014. class JuceURLConnectionMessageThread : public Thread
  200015. {
  200016. JuceURLConnection* owner;
  200017. public:
  200018. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200019. : Thread ("http connection"),
  200020. owner (owner_)
  200021. {
  200022. }
  200023. ~JuceURLConnectionMessageThread()
  200024. {
  200025. stopThread (10000);
  200026. }
  200027. void run()
  200028. {
  200029. [owner createConnection];
  200030. while (! threadShouldExit())
  200031. {
  200032. const ScopedAutoReleasePool pool;
  200033. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200034. }
  200035. }
  200036. };
  200037. @implementation JuceURLConnection
  200038. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200039. withCallback: (URL::OpenStreamProgressCallback*) callback
  200040. withContext: (void*) context;
  200041. {
  200042. [super init];
  200043. request = req;
  200044. [request retain];
  200045. data = [[NSMutableData data] retain];
  200046. dataLock = [[NSLock alloc] init];
  200047. connection = 0;
  200048. initialised = false;
  200049. hasFailed = false;
  200050. hasFinished = false;
  200051. contentLength = -1;
  200052. runLoopThread = new JuceURLConnectionMessageThread (self);
  200053. runLoopThread->startThread();
  200054. while (runLoopThread->isThreadRunning() && ! initialised)
  200055. {
  200056. if (callback != 0)
  200057. callback (context, -1, (int) [[request HTTPBody] length]);
  200058. Thread::sleep (1);
  200059. }
  200060. return self;
  200061. }
  200062. - (void) dealloc
  200063. {
  200064. [self stop];
  200065. delete runLoopThread;
  200066. [connection release];
  200067. [data release];
  200068. [dataLock release];
  200069. [request release];
  200070. [super dealloc];
  200071. }
  200072. - (void) createConnection
  200073. {
  200074. connection = [[NSURLConnection alloc] initWithRequest: request
  200075. delegate: [self retain]];
  200076. if (connection == nil)
  200077. runLoopThread->signalThreadShouldExit();
  200078. }
  200079. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200080. {
  200081. [dataLock lock];
  200082. [data setLength: 0];
  200083. [dataLock unlock];
  200084. initialised = true;
  200085. contentLength = [response expectedContentLength];
  200086. }
  200087. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200088. {
  200089. DBG (nsStringToJuce ([error description]));
  200090. hasFailed = true;
  200091. initialised = true;
  200092. runLoopThread->signalThreadShouldExit();
  200093. }
  200094. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200095. {
  200096. [dataLock lock];
  200097. [data appendData: newData];
  200098. [dataLock unlock];
  200099. initialised = true;
  200100. }
  200101. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200102. {
  200103. hasFinished = true;
  200104. initialised = true;
  200105. runLoopThread->signalThreadShouldExit();
  200106. }
  200107. - (BOOL) isOpen
  200108. {
  200109. return connection != 0 && ! hasFailed;
  200110. }
  200111. - (int) readPosition
  200112. {
  200113. return position;
  200114. }
  200115. - (int) read: (char*) dest numBytes: (int) numNeeded
  200116. {
  200117. int numDone = 0;
  200118. while (numNeeded > 0)
  200119. {
  200120. int available = jmin (numNeeded, (int) [data length]);
  200121. if (available > 0)
  200122. {
  200123. [dataLock lock];
  200124. [data getBytes: dest length: available];
  200125. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200126. [dataLock unlock];
  200127. numDone += available;
  200128. numNeeded -= available;
  200129. dest += available;
  200130. }
  200131. else
  200132. {
  200133. if (hasFailed || hasFinished)
  200134. break;
  200135. Thread::sleep (1);
  200136. }
  200137. }
  200138. position += numDone;
  200139. return numDone;
  200140. }
  200141. - (void) stop
  200142. {
  200143. [connection cancel];
  200144. runLoopThread->stopThread (10000);
  200145. }
  200146. @end
  200147. BEGIN_JUCE_NAMESPACE
  200148. bool juce_isOnLine()
  200149. {
  200150. return true;
  200151. }
  200152. void* juce_openInternetFile (const String& url,
  200153. const String& headers,
  200154. const MemoryBlock& postData,
  200155. const bool isPost,
  200156. URL::OpenStreamProgressCallback* callback,
  200157. void* callbackContext,
  200158. int timeOutMs)
  200159. {
  200160. const ScopedAutoReleasePool pool;
  200161. NSMutableURLRequest* req = [NSMutableURLRequest
  200162. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200163. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200164. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200165. if (req == nil)
  200166. return 0;
  200167. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200168. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200169. StringArray headerLines;
  200170. headerLines.addLines (headers);
  200171. headerLines.removeEmptyStrings (true);
  200172. for (int i = 0; i < headerLines.size(); ++i)
  200173. {
  200174. const String key (headerLines[i].upToFirstOccurrenceOf (":", false, false).trim());
  200175. const String value (headerLines[i].fromFirstOccurrenceOf (":", false, false).trim());
  200176. if (key.isNotEmpty() && value.isNotEmpty())
  200177. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200178. }
  200179. if (isPost && postData.getSize() > 0)
  200180. {
  200181. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200182. length: postData.getSize()]];
  200183. }
  200184. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200185. withCallback: callback
  200186. withContext: callbackContext];
  200187. if ([s isOpen])
  200188. return s;
  200189. [s release];
  200190. return 0;
  200191. }
  200192. void juce_closeInternetFile (void* handle)
  200193. {
  200194. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200195. if (s != 0)
  200196. {
  200197. const ScopedAutoReleasePool pool;
  200198. [s stop];
  200199. [s release];
  200200. }
  200201. }
  200202. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200203. {
  200204. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200205. if (s != 0)
  200206. {
  200207. const ScopedAutoReleasePool pool;
  200208. return [s read: (char*) buffer numBytes: bytesToRead];
  200209. }
  200210. return 0;
  200211. }
  200212. int64 juce_getInternetFileContentLength (void* handle)
  200213. {
  200214. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200215. if (s != 0)
  200216. return s->contentLength;
  200217. return -1;
  200218. }
  200219. int juce_seekInInternetFile (void* handle, int newPosition)
  200220. {
  200221. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200222. if (s != 0)
  200223. return [s readPosition];
  200224. return 0;
  200225. }
  200226. #endif
  200227. /*** End of inlined file: juce_mac_Network.mm ***/
  200228. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200229. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200230. // compiled on its own).
  200231. #if JUCE_INCLUDED_FILE
  200232. struct NamedPipeInternal
  200233. {
  200234. String pipeInName, pipeOutName;
  200235. int pipeIn, pipeOut;
  200236. bool volatile createdPipe, blocked, stopReadOperation;
  200237. static void signalHandler (int) {}
  200238. };
  200239. void NamedPipe::cancelPendingReads()
  200240. {
  200241. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200242. {
  200243. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200244. intern->stopReadOperation = true;
  200245. char buffer [1] = { 0 };
  200246. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200247. (void) bytesWritten;
  200248. int timeout = 2000;
  200249. while (intern->blocked && --timeout >= 0)
  200250. Thread::sleep (2);
  200251. intern->stopReadOperation = false;
  200252. }
  200253. }
  200254. void NamedPipe::close()
  200255. {
  200256. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200257. if (intern != 0)
  200258. {
  200259. internal = 0;
  200260. if (intern->pipeIn != -1)
  200261. ::close (intern->pipeIn);
  200262. if (intern->pipeOut != -1)
  200263. ::close (intern->pipeOut);
  200264. if (intern->createdPipe)
  200265. {
  200266. unlink (intern->pipeInName.toUTF8());
  200267. unlink (intern->pipeOutName.toUTF8());
  200268. }
  200269. delete intern;
  200270. }
  200271. }
  200272. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200273. {
  200274. close();
  200275. NamedPipeInternal* const intern = new NamedPipeInternal();
  200276. internal = intern;
  200277. intern->createdPipe = createPipe;
  200278. intern->blocked = false;
  200279. intern->stopReadOperation = false;
  200280. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200281. siginterrupt (SIGPIPE, 1);
  200282. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  200283. intern->pipeInName = pipePath + "_in";
  200284. intern->pipeOutName = pipePath + "_out";
  200285. intern->pipeIn = -1;
  200286. intern->pipeOut = -1;
  200287. if (createPipe)
  200288. {
  200289. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200290. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200291. {
  200292. delete intern;
  200293. internal = 0;
  200294. return false;
  200295. }
  200296. }
  200297. return true;
  200298. }
  200299. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200300. {
  200301. int bytesRead = -1;
  200302. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200303. if (intern != 0)
  200304. {
  200305. intern->blocked = true;
  200306. if (intern->pipeIn == -1)
  200307. {
  200308. if (intern->createdPipe)
  200309. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200310. else
  200311. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200312. if (intern->pipeIn == -1)
  200313. {
  200314. intern->blocked = false;
  200315. return -1;
  200316. }
  200317. }
  200318. bytesRead = 0;
  200319. char* p = (char*) destBuffer;
  200320. while (bytesRead < maxBytesToRead)
  200321. {
  200322. const int bytesThisTime = maxBytesToRead - bytesRead;
  200323. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200324. if (numRead <= 0 || intern->stopReadOperation)
  200325. {
  200326. bytesRead = -1;
  200327. break;
  200328. }
  200329. bytesRead += numRead;
  200330. p += bytesRead;
  200331. }
  200332. intern->blocked = false;
  200333. }
  200334. return bytesRead;
  200335. }
  200336. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200337. {
  200338. int bytesWritten = -1;
  200339. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200340. if (intern != 0)
  200341. {
  200342. if (intern->pipeOut == -1)
  200343. {
  200344. if (intern->createdPipe)
  200345. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200346. else
  200347. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200348. if (intern->pipeOut == -1)
  200349. {
  200350. return -1;
  200351. }
  200352. }
  200353. const char* p = (const char*) sourceBuffer;
  200354. bytesWritten = 0;
  200355. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200356. while (bytesWritten < numBytesToWrite
  200357. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200358. {
  200359. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200360. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200361. if (numWritten <= 0)
  200362. {
  200363. bytesWritten = -1;
  200364. break;
  200365. }
  200366. bytesWritten += numWritten;
  200367. p += bytesWritten;
  200368. }
  200369. }
  200370. return bytesWritten;
  200371. }
  200372. #endif
  200373. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200374. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200375. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200376. // compiled on its own).
  200377. #if JUCE_INCLUDED_FILE
  200378. void JUCE_API juce_threadEntryPoint (void*);
  200379. void* threadEntryProc (void* userData)
  200380. {
  200381. const ScopedAutoReleasePool pool;
  200382. juce_threadEntryPoint (userData);
  200383. return 0;
  200384. }
  200385. void* juce_createThread (void* userData)
  200386. {
  200387. pthread_t handle = 0;
  200388. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200389. {
  200390. pthread_detach (handle);
  200391. return (void*) handle;
  200392. }
  200393. return 0;
  200394. }
  200395. void juce_killThread (void* handle)
  200396. {
  200397. if (handle != 0)
  200398. pthread_cancel ((pthread_t) handle);
  200399. }
  200400. void juce_setCurrentThreadName (const String& /*name*/)
  200401. {
  200402. }
  200403. bool juce_setThreadPriority (void* handle, int priority)
  200404. {
  200405. if (handle == 0)
  200406. handle = (void*) pthread_self();
  200407. struct sched_param param;
  200408. int policy;
  200409. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200410. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200411. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200412. }
  200413. Thread::ThreadID Thread::getCurrentThreadId()
  200414. {
  200415. return static_cast <ThreadID> (pthread_self());
  200416. }
  200417. void Thread::yield()
  200418. {
  200419. sched_yield();
  200420. }
  200421. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200422. {
  200423. // xxx
  200424. jassertfalse
  200425. }
  200426. bool Process::isForegroundProcess()
  200427. {
  200428. #if JUCE_MAC
  200429. return [NSApp isActive];
  200430. #else
  200431. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200432. #endif
  200433. }
  200434. void Process::raisePrivilege()
  200435. {
  200436. jassertfalse
  200437. }
  200438. void Process::lowerPrivilege()
  200439. {
  200440. jassertfalse
  200441. }
  200442. void Process::terminate()
  200443. {
  200444. exit (0);
  200445. }
  200446. void Process::setPriority (ProcessPriority p)
  200447. {
  200448. // xxx
  200449. }
  200450. #endif
  200451. /*** End of inlined file: juce_mac_Threads.mm ***/
  200452. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200453. CriticalSection::CriticalSection() throw()
  200454. {
  200455. pthread_mutexattr_t atts;
  200456. pthread_mutexattr_init (&atts);
  200457. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200458. pthread_mutex_init (&internal, &atts);
  200459. }
  200460. CriticalSection::~CriticalSection() throw()
  200461. {
  200462. pthread_mutex_destroy (&internal);
  200463. }
  200464. void CriticalSection::enter() const throw()
  200465. {
  200466. pthread_mutex_lock (&internal);
  200467. }
  200468. bool CriticalSection::tryEnter() const throw()
  200469. {
  200470. return pthread_mutex_trylock (&internal) == 0;
  200471. }
  200472. void CriticalSection::exit() const throw()
  200473. {
  200474. pthread_mutex_unlock (&internal);
  200475. }
  200476. class WaitableEventImpl
  200477. {
  200478. public:
  200479. WaitableEventImpl()
  200480. : triggered (false)
  200481. {
  200482. pthread_cond_init (&condition, 0);
  200483. pthread_mutex_init (&mutex, 0);
  200484. }
  200485. ~WaitableEventImpl()
  200486. {
  200487. pthread_cond_destroy (&condition);
  200488. pthread_mutex_destroy (&mutex);
  200489. }
  200490. bool wait (const int timeOutMillisecs) throw()
  200491. {
  200492. pthread_mutex_lock (&mutex);
  200493. if (! triggered)
  200494. {
  200495. if (timeOutMillisecs < 0)
  200496. {
  200497. do
  200498. {
  200499. pthread_cond_wait (&condition, &mutex);
  200500. }
  200501. while (! triggered);
  200502. }
  200503. else
  200504. {
  200505. struct timeval now;
  200506. gettimeofday (&now, 0);
  200507. struct timespec time;
  200508. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  200509. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200510. if (time.tv_nsec >= 1000000000)
  200511. {
  200512. time.tv_nsec -= 1000000000;
  200513. time.tv_sec++;
  200514. }
  200515. do
  200516. {
  200517. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  200518. {
  200519. pthread_mutex_unlock (&mutex);
  200520. return false;
  200521. }
  200522. }
  200523. while (! triggered);
  200524. }
  200525. }
  200526. triggered = false;
  200527. pthread_mutex_unlock (&mutex);
  200528. return true;
  200529. }
  200530. void signal() throw()
  200531. {
  200532. pthread_mutex_lock (&mutex);
  200533. triggered = true;
  200534. pthread_cond_broadcast (&condition);
  200535. pthread_mutex_unlock (&mutex);
  200536. }
  200537. void reset() throw()
  200538. {
  200539. pthread_mutex_lock (&mutex);
  200540. triggered = false;
  200541. pthread_mutex_unlock (&mutex);
  200542. }
  200543. private:
  200544. pthread_cond_t condition;
  200545. pthread_mutex_t mutex;
  200546. bool triggered;
  200547. WaitableEventImpl (const WaitableEventImpl&);
  200548. WaitableEventImpl& operator= (const WaitableEventImpl&);
  200549. };
  200550. WaitableEvent::WaitableEvent() throw()
  200551. : internal (new WaitableEventImpl())
  200552. {
  200553. }
  200554. WaitableEvent::~WaitableEvent() throw()
  200555. {
  200556. delete static_cast <WaitableEventImpl*> (internal);
  200557. }
  200558. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200559. {
  200560. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  200561. }
  200562. void WaitableEvent::signal() const throw()
  200563. {
  200564. static_cast <WaitableEventImpl*> (internal)->signal();
  200565. }
  200566. void WaitableEvent::reset() const throw()
  200567. {
  200568. static_cast <WaitableEventImpl*> (internal)->reset();
  200569. }
  200570. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200571. {
  200572. struct timespec time;
  200573. time.tv_sec = millisecs / 1000;
  200574. time.tv_nsec = (millisecs % 1000) * 1000000;
  200575. nanosleep (&time, 0);
  200576. }
  200577. const juce_wchar File::separator = '/';
  200578. const juce_wchar* File::separatorString = L"/";
  200579. const File File::getCurrentWorkingDirectory()
  200580. {
  200581. HeapBlock<char> heapBuffer;
  200582. char localBuffer [1024];
  200583. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200584. int bufferSize = 4096;
  200585. while (cwd == 0 && errno == ERANGE)
  200586. {
  200587. heapBuffer.malloc (bufferSize);
  200588. cwd = getcwd (heapBuffer, bufferSize - 1);
  200589. bufferSize += 1024;
  200590. }
  200591. return File (String::fromUTF8 (cwd));
  200592. }
  200593. bool File::setAsCurrentWorkingDirectory() const
  200594. {
  200595. return chdir (getFullPathName().toUTF8()) == 0;
  200596. }
  200597. bool juce_copyFile (const String& s, const String& d);
  200598. static bool juce_stat (const String& fileName, struct stat& info)
  200599. {
  200600. return fileName.isNotEmpty()
  200601. && (stat (fileName.toUTF8(), &info) == 0);
  200602. }
  200603. bool juce_isDirectory (const String& fileName)
  200604. {
  200605. struct stat info;
  200606. return fileName.isEmpty()
  200607. || (juce_stat (fileName, info)
  200608. && ((info.st_mode & S_IFDIR) != 0));
  200609. }
  200610. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200611. {
  200612. if (fileName.isEmpty())
  200613. return false;
  200614. const char* const fileNameUTF8 = fileName.toUTF8();
  200615. bool exists = access (fileNameUTF8, F_OK) == 0;
  200616. if (exists && dontCountDirectories)
  200617. {
  200618. struct stat info;
  200619. const int res = stat (fileNameUTF8, &info);
  200620. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200621. exists = false;
  200622. }
  200623. return exists;
  200624. }
  200625. int64 juce_getFileSize (const String& fileName)
  200626. {
  200627. struct stat info;
  200628. return juce_stat (fileName, info) ? info.st_size : 0;
  200629. }
  200630. bool juce_canWriteToFile (const String& fileName)
  200631. {
  200632. return access (fileName.toUTF8(), W_OK) == 0;
  200633. }
  200634. bool juce_deleteFile (const String& fileName)
  200635. {
  200636. if (juce_isDirectory (fileName))
  200637. return rmdir (fileName.toUTF8()) == 0;
  200638. else
  200639. return remove (fileName.toUTF8()) == 0;
  200640. }
  200641. bool juce_moveFile (const String& source, const String& dest)
  200642. {
  200643. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200644. return true;
  200645. if (juce_canWriteToFile (source)
  200646. && juce_copyFile (source, dest))
  200647. {
  200648. if (juce_deleteFile (source))
  200649. return true;
  200650. juce_deleteFile (dest);
  200651. }
  200652. return false;
  200653. }
  200654. void juce_createDirectory (const String& fileName)
  200655. {
  200656. mkdir (fileName.toUTF8(), 0777);
  200657. }
  200658. void* juce_fileOpen (const String& fileName, bool forWriting)
  200659. {
  200660. int flags = O_RDONLY;
  200661. if (forWriting)
  200662. {
  200663. if (juce_fileExists (fileName, false))
  200664. {
  200665. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  200666. if (f != -1)
  200667. lseek (f, 0, SEEK_END);
  200668. return (void*) f;
  200669. }
  200670. else
  200671. {
  200672. flags = O_RDWR + O_CREAT;
  200673. }
  200674. }
  200675. return (void*) open (fileName.toUTF8(), flags, 00644);
  200676. }
  200677. void juce_fileClose (void* handle)
  200678. {
  200679. if (handle != 0)
  200680. close ((int) (pointer_sized_int) handle);
  200681. }
  200682. int juce_fileRead (void* handle, void* buffer, int size)
  200683. {
  200684. if (handle != 0)
  200685. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  200686. return 0;
  200687. }
  200688. int juce_fileWrite (void* handle, const void* buffer, int size)
  200689. {
  200690. if (handle != 0)
  200691. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200692. return 0;
  200693. }
  200694. int64 juce_fileSetPosition (void* handle, int64 pos)
  200695. {
  200696. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200697. return pos;
  200698. return -1;
  200699. }
  200700. int64 juce_fileGetPosition (void* handle)
  200701. {
  200702. if (handle != 0)
  200703. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200704. return -1;
  200705. }
  200706. void juce_fileFlush (void* handle)
  200707. {
  200708. if (handle != 0)
  200709. fsync ((int) (pointer_sized_int) handle);
  200710. }
  200711. const File juce_getExecutableFile()
  200712. {
  200713. Dl_info exeInfo;
  200714. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200715. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  200716. }
  200717. // if this file doesn't exist, find a parent of it that does..
  200718. static bool doStatFS (const File* file, struct statfs& result)
  200719. {
  200720. File f (*file);
  200721. for (int i = 5; --i >= 0;)
  200722. {
  200723. if (f.exists())
  200724. break;
  200725. f = f.getParentDirectory();
  200726. }
  200727. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200728. }
  200729. int64 File::getBytesFreeOnVolume() const
  200730. {
  200731. struct statfs buf;
  200732. if (doStatFS (this, buf))
  200733. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200734. return 0;
  200735. }
  200736. int64 File::getVolumeTotalSize() const
  200737. {
  200738. struct statfs buf;
  200739. if (doStatFS (this, buf))
  200740. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200741. return 0;
  200742. }
  200743. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200744. int& volumeSerialNumber)
  200745. {
  200746. volumeSerialNumber = 0;
  200747. #if JUCE_MAC
  200748. struct VolAttrBuf
  200749. {
  200750. u_int32_t length;
  200751. attrreference_t mountPointRef;
  200752. char mountPointSpace [MAXPATHLEN];
  200753. } attrBuf;
  200754. struct attrlist attrList;
  200755. zerostruct (attrList);
  200756. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200757. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200758. File f (filenameOnVolume);
  200759. for (;;)
  200760. {
  200761. if (getattrlist (f.getFullPathName().toUTF8(),
  200762. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200763. {
  200764. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200765. (int) attrBuf.mountPointRef.attr_length);
  200766. }
  200767. const File parent (f.getParentDirectory());
  200768. if (f == parent)
  200769. break;
  200770. f = parent;
  200771. }
  200772. #endif
  200773. return String::empty;
  200774. }
  200775. void juce_runSystemCommand (const String& command)
  200776. {
  200777. int result = system (command.toUTF8());
  200778. (void) result;
  200779. }
  200780. const String juce_getOutputFromCommand (const String& command)
  200781. {
  200782. // slight bodge here, as we just pipe the output into a temp file and read it...
  200783. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200784. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200785. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200786. String result (tempFile.loadFileAsString());
  200787. tempFile.deleteFile();
  200788. return result;
  200789. }
  200790. InterProcessLock::InterProcessLock (const String& name_)
  200791. : internal (0),
  200792. name (name_),
  200793. reentrancyLevel (0)
  200794. {
  200795. #if JUCE_MAC
  200796. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200797. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  200798. #else
  200799. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200800. #endif
  200801. temp.create();
  200802. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200803. }
  200804. InterProcessLock::~InterProcessLock()
  200805. {
  200806. while (reentrancyLevel > 0)
  200807. this->exit();
  200808. close (internal);
  200809. }
  200810. bool InterProcessLock::enter (const int timeOutMillisecs)
  200811. {
  200812. if (internal == 0)
  200813. return false;
  200814. if (reentrancyLevel != 0)
  200815. return true;
  200816. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200817. struct flock fl;
  200818. zerostruct (fl);
  200819. fl.l_whence = SEEK_SET;
  200820. fl.l_type = F_WRLCK;
  200821. for (;;)
  200822. {
  200823. const int result = fcntl (internal, F_SETLK, &fl);
  200824. if (result >= 0)
  200825. {
  200826. ++reentrancyLevel;
  200827. return true;
  200828. }
  200829. if (errno != EINTR)
  200830. {
  200831. if (timeOutMillisecs == 0
  200832. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200833. break;
  200834. Thread::sleep (10);
  200835. }
  200836. }
  200837. return false;
  200838. }
  200839. void InterProcessLock::exit()
  200840. {
  200841. if (reentrancyLevel > 0 && internal != 0)
  200842. {
  200843. --reentrancyLevel;
  200844. struct flock fl;
  200845. zerostruct (fl);
  200846. fl.l_whence = SEEK_SET;
  200847. fl.l_type = F_UNLCK;
  200848. for (;;)
  200849. {
  200850. const int result = fcntl (internal, F_SETLKW, &fl);
  200851. if (result >= 0 || errno != EINTR)
  200852. break;
  200853. }
  200854. }
  200855. }
  200856. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200857. /*** Start of inlined file: juce_mac_Files.mm ***/
  200858. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200859. // compiled on its own).
  200860. #if JUCE_INCLUDED_FILE
  200861. void juce_getFileTimes (const String& fileName,
  200862. int64& modificationTime,
  200863. int64& accessTime,
  200864. int64& creationTime)
  200865. {
  200866. modificationTime = 0;
  200867. accessTime = 0;
  200868. creationTime = 0;
  200869. struct stat info;
  200870. const int res = stat (fileName.toUTF8(), &info);
  200871. if (res == 0)
  200872. {
  200873. modificationTime = (int64) info.st_mtime * 1000;
  200874. accessTime = (int64) info.st_atime * 1000;
  200875. creationTime = (int64) info.st_ctime * 1000;
  200876. }
  200877. }
  200878. bool juce_setFileTimes (const String& fileName,
  200879. int64 modificationTime,
  200880. int64 accessTime,
  200881. int64 creationTime)
  200882. {
  200883. struct utimbuf times;
  200884. times.actime = (time_t) (accessTime / 1000);
  200885. times.modtime = (time_t) (modificationTime / 1000);
  200886. return utime (fileName.toUTF8(), &times) == 0;
  200887. }
  200888. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  200889. {
  200890. struct stat info;
  200891. const int res = stat (fileName.toUTF8(), &info);
  200892. if (res != 0)
  200893. return false;
  200894. info.st_mode &= 0777; // Just permissions
  200895. if (isReadOnly)
  200896. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  200897. else
  200898. // Give everybody write permission?
  200899. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  200900. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  200901. }
  200902. bool juce_copyFile (const String& src, const String& dst)
  200903. {
  200904. const ScopedAutoReleasePool pool;
  200905. NSFileManager* fm = [NSFileManager defaultManager];
  200906. return [fm fileExistsAtPath: juceStringToNS (src)]
  200907. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  200908. && [fm copyItemAtPath: juceStringToNS (src)
  200909. toPath: juceStringToNS (dst)
  200910. error: nil];
  200911. #else
  200912. && [fm copyPath: juceStringToNS (src)
  200913. toPath: juceStringToNS (dst)
  200914. handler: nil];
  200915. #endif
  200916. }
  200917. const StringArray juce_getFileSystemRoots()
  200918. {
  200919. StringArray s;
  200920. s.add ("/");
  200921. return s;
  200922. }
  200923. static bool isFileOnDriveType (const File* const f, const char** types)
  200924. {
  200925. struct statfs buf;
  200926. if (doStatFS (f, buf))
  200927. {
  200928. const String type (buf.f_fstypename);
  200929. while (*types != 0)
  200930. if (type.equalsIgnoreCase (*types++))
  200931. return true;
  200932. }
  200933. return false;
  200934. }
  200935. bool File::isOnCDRomDrive() const
  200936. {
  200937. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  200938. return isFileOnDriveType (this, (const char**) cdTypes);
  200939. }
  200940. bool File::isOnHardDisk() const
  200941. {
  200942. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  200943. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  200944. }
  200945. bool File::isOnRemovableDrive() const
  200946. {
  200947. #if JUCE_IPHONE
  200948. return false; // xxx is this possible?
  200949. #else
  200950. const ScopedAutoReleasePool pool;
  200951. BOOL removable = false;
  200952. [[NSWorkspace sharedWorkspace]
  200953. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  200954. isRemovable: &removable
  200955. isWritable: nil
  200956. isUnmountable: nil
  200957. description: nil
  200958. type: nil];
  200959. return removable;
  200960. #endif
  200961. }
  200962. static bool juce_isHiddenFile (const String& path)
  200963. {
  200964. #if JUCE_IPHONE
  200965. return File (path).getFileName().startsWithChar ('.');
  200966. #else
  200967. FSRef ref;
  200968. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  200969. return false;
  200970. FSCatalogInfo info;
  200971. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  200972. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  200973. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200974. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200975. #endif
  200976. }
  200977. bool File::isHidden() const
  200978. {
  200979. return juce_isHiddenFile (getFullPathName());
  200980. }
  200981. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  200982. const File File::getSpecialLocation (const SpecialLocationType type)
  200983. {
  200984. const ScopedAutoReleasePool pool;
  200985. String resultPath;
  200986. switch (type)
  200987. {
  200988. case userHomeDirectory:
  200989. resultPath = nsStringToJuce (NSHomeDirectory());
  200990. break;
  200991. case userDocumentsDirectory:
  200992. resultPath = "~/Documents";
  200993. break;
  200994. case userDesktopDirectory:
  200995. resultPath = "~/Desktop";
  200996. break;
  200997. case userApplicationDataDirectory:
  200998. resultPath = "~/Library";
  200999. break;
  201000. case commonApplicationDataDirectory:
  201001. resultPath = "/Library";
  201002. break;
  201003. case globalApplicationsDirectory:
  201004. resultPath = "/Applications";
  201005. break;
  201006. case userMusicDirectory:
  201007. resultPath = "~/Music";
  201008. break;
  201009. case userMoviesDirectory:
  201010. resultPath = "~/Movies";
  201011. break;
  201012. case tempDirectory:
  201013. {
  201014. File tmp ("~/Library/Caches/" + juce_getExecutableFile().getFileNameWithoutExtension());
  201015. tmp.createDirectory();
  201016. return tmp.getFullPathName();
  201017. }
  201018. case invokedExecutableFile:
  201019. if (juce_Argv0 != 0)
  201020. return File (String::fromUTF8 (juce_Argv0));
  201021. // deliberate fall-through...
  201022. case currentExecutableFile:
  201023. return juce_getExecutableFile();
  201024. case currentApplicationFile:
  201025. {
  201026. const File exe (juce_getExecutableFile());
  201027. const File parent (exe.getParentDirectory());
  201028. return parent.getFullPathName().endsWithIgnoreCase ("Contents/MacOS")
  201029. ? parent.getParentDirectory().getParentDirectory()
  201030. : exe;
  201031. }
  201032. default:
  201033. jassertfalse // unknown type?
  201034. break;
  201035. }
  201036. if (resultPath.isNotEmpty())
  201037. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201038. return File::nonexistent;
  201039. }
  201040. const String File::getVersion() const
  201041. {
  201042. const ScopedAutoReleasePool pool;
  201043. String result;
  201044. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201045. if (bundle != 0)
  201046. {
  201047. NSDictionary* info = [bundle infoDictionary];
  201048. if (info != 0)
  201049. {
  201050. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201051. if (name != nil)
  201052. result = nsStringToJuce (name);
  201053. }
  201054. }
  201055. return result;
  201056. }
  201057. const File File::getLinkedTarget() const
  201058. {
  201059. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201060. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201061. #else
  201062. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201063. #endif
  201064. if (dest != nil)
  201065. return File (nsStringToJuce (dest));
  201066. return *this;
  201067. }
  201068. bool File::moveToTrash() const
  201069. {
  201070. if (! exists())
  201071. return true;
  201072. #if JUCE_IPHONE
  201073. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201074. #else
  201075. const ScopedAutoReleasePool pool;
  201076. NSString* p = juceStringToNS (getFullPathName());
  201077. return [[NSWorkspace sharedWorkspace]
  201078. performFileOperation: NSWorkspaceRecycleOperation
  201079. source: [p stringByDeletingLastPathComponent]
  201080. destination: @""
  201081. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201082. tag: nil ];
  201083. #endif
  201084. }
  201085. struct FindFileStruct
  201086. {
  201087. NSDirectoryEnumerator* enumerator;
  201088. String parentDir, wildCard;
  201089. };
  201090. bool juce_findFileNext (void* handle, String& resultFile,
  201091. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201092. {
  201093. ScopedAutoReleasePool pool;
  201094. FindFileStruct* ff = (FindFileStruct*) handle;
  201095. NSString* file;
  201096. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201097. for (;;)
  201098. {
  201099. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201100. return false;
  201101. [ff->enumerator skipDescendents];
  201102. resultFile = nsStringToJuce (file);
  201103. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201104. continue;
  201105. const String path (ff->parentDir + resultFile);
  201106. if (isDir != 0 || fileSize != 0)
  201107. {
  201108. struct stat info;
  201109. const bool statOk = juce_stat (path, info);
  201110. if (isDir != 0)
  201111. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201112. if (isHidden != 0)
  201113. *isHidden = juce_isHiddenFile (path);
  201114. if (fileSize != 0)
  201115. *fileSize = statOk ? info.st_size : 0;
  201116. }
  201117. if (modTime != 0 || creationTime != 0)
  201118. {
  201119. int64 m, a, c;
  201120. juce_getFileTimes (path, m, a, c);
  201121. if (modTime != 0)
  201122. *modTime = m;
  201123. if (creationTime != 0)
  201124. *creationTime = c;
  201125. }
  201126. if (isReadOnly != 0)
  201127. *isReadOnly = ! juce_canWriteToFile (path);
  201128. return true;
  201129. }
  201130. }
  201131. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201132. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201133. Time* creationTime, bool* isReadOnly)
  201134. {
  201135. ScopedAutoReleasePool pool;
  201136. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201137. if (e != 0)
  201138. {
  201139. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201140. ff->enumerator = [e retain];
  201141. ff->parentDir = directory;
  201142. ff->wildCard = wildCard;
  201143. if (! ff->parentDir.endsWithChar (File::separator))
  201144. ff->parentDir += File::separator;
  201145. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201146. return ff.release();
  201147. [e release];
  201148. }
  201149. return 0;
  201150. }
  201151. void juce_findFileClose (void* handle)
  201152. {
  201153. ScopedAutoReleasePool pool;
  201154. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201155. [ff->enumerator release];
  201156. }
  201157. bool juce_launchExecutable (const String& pathAndArguments)
  201158. {
  201159. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201160. const int cpid = fork();
  201161. if (cpid == 0)
  201162. {
  201163. // Child process
  201164. if (execve (argv[0], (char**) argv, 0) < 0)
  201165. exit (0);
  201166. }
  201167. else
  201168. {
  201169. if (cpid < 0)
  201170. return false;
  201171. }
  201172. return true;
  201173. }
  201174. bool juce_launchFile (const String& fileName, const String& parameters)
  201175. {
  201176. #if JUCE_IPHONE
  201177. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201178. #else
  201179. const ScopedAutoReleasePool pool;
  201180. if (parameters.isEmpty())
  201181. {
  201182. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201183. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201184. }
  201185. bool ok = false;
  201186. FSRef ref;
  201187. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201188. {
  201189. if (PlatformUtilities::isBundle (fileName))
  201190. {
  201191. NSMutableArray* urls = [NSMutableArray array];
  201192. StringArray docs;
  201193. docs.addTokens (parameters, true);
  201194. for (int i = 0; i < docs.size(); ++i)
  201195. [urls addObject: juceStringToNS (docs[i])];
  201196. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201197. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201198. options: 0
  201199. additionalEventParamDescriptor: nil
  201200. launchIdentifiers: nil];
  201201. }
  201202. else
  201203. {
  201204. ok = juce_launchExecutable ("\"" + fileName + "\" " + parameters);
  201205. }
  201206. }
  201207. return ok;
  201208. #endif
  201209. }
  201210. void File::revealToUser() const
  201211. {
  201212. #if ! JUCE_IPHONE
  201213. if (exists())
  201214. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201215. else if (getParentDirectory().exists())
  201216. getParentDirectory().revealToUser();
  201217. #endif
  201218. }
  201219. #if ! JUCE_IPHONE
  201220. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201221. {
  201222. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201223. }
  201224. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201225. {
  201226. char path [2048];
  201227. zerostruct (path);
  201228. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201229. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201230. return String::empty;
  201231. }
  201232. #endif
  201233. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201234. {
  201235. const ScopedAutoReleasePool pool;
  201236. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201237. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201238. #else
  201239. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201240. #endif
  201241. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201242. return [fileDict fileHFSTypeCode];
  201243. }
  201244. bool PlatformUtilities::isBundle (const String& filename)
  201245. {
  201246. #if JUCE_IPHONE
  201247. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201248. #else
  201249. const ScopedAutoReleasePool pool;
  201250. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201251. #endif
  201252. }
  201253. #endif
  201254. /*** End of inlined file: juce_mac_Files.mm ***/
  201255. #if JUCE_IPHONE
  201256. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201257. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201258. // compiled on its own).
  201259. #if JUCE_INCLUDED_FILE
  201260. static JUCEApplication* juce_intialisingApp;
  201261. END_JUCE_NAMESPACE
  201262. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201263. {
  201264. }
  201265. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201266. - (void) applicationWillResignActive: (UIApplication*) application;
  201267. @end
  201268. @implementation JuceAppStartupDelegate
  201269. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201270. {
  201271. String dummy;
  201272. if (! juce_intialisingApp->initialiseApp (dummy))
  201273. exit (0);
  201274. }
  201275. - (void) applicationWillResignActive: (UIApplication*) application
  201276. {
  201277. JUCEApplication::shutdownAppAndClearUp();
  201278. }
  201279. @end
  201280. BEGIN_JUCE_NAMESPACE
  201281. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201282. {
  201283. juce_intialisingApp = app;
  201284. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201285. }
  201286. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201287. {
  201288. pool = [[NSAutoreleasePool alloc] init];
  201289. }
  201290. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201291. {
  201292. [((NSAutoreleasePool*) pool) release];
  201293. }
  201294. void PlatformUtilities::beep()
  201295. {
  201296. //xxx
  201297. //AudioServicesPlaySystemSound ();
  201298. }
  201299. void PlatformUtilities::addItemToDock (const File& file)
  201300. {
  201301. }
  201302. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201303. END_JUCE_NAMESPACE
  201304. @interface JuceAlertBoxDelegate : NSObject
  201305. {
  201306. @public
  201307. bool clickedOk;
  201308. }
  201309. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201310. @end
  201311. @implementation JuceAlertBoxDelegate
  201312. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201313. {
  201314. clickedOk = (buttonIndex == 0);
  201315. alertView.hidden = true;
  201316. }
  201317. @end
  201318. BEGIN_JUCE_NAMESPACE
  201319. // (This function is used directly by other bits of code)
  201320. bool juce_iPhoneShowModalAlert (const String& title,
  201321. const String& bodyText,
  201322. NSString* okButtonText,
  201323. NSString* cancelButtonText)
  201324. {
  201325. const ScopedAutoReleasePool pool;
  201326. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201327. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201328. message: juceStringToNS (bodyText)
  201329. delegate: callback
  201330. cancelButtonTitle: okButtonText
  201331. otherButtonTitles: cancelButtonText, nil];
  201332. [alert retain];
  201333. [alert show];
  201334. while (! alert.hidden && alert.superview != nil)
  201335. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201336. const bool result = callback->clickedOk;
  201337. [alert release];
  201338. [callback release];
  201339. return result;
  201340. }
  201341. bool AlertWindow::showNativeDialogBox (const String& title,
  201342. const String& bodyText,
  201343. bool isOkCancel)
  201344. {
  201345. return juce_iPhoneShowModalAlert (title, bodyText,
  201346. @"OK",
  201347. isOkCancel ? @"Cancel" : nil);
  201348. }
  201349. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201350. {
  201351. jassertfalse // no such thing on the iphone!
  201352. return false;
  201353. }
  201354. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201355. {
  201356. jassertfalse // no such thing on the iphone!
  201357. return false;
  201358. }
  201359. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201360. {
  201361. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201362. }
  201363. bool Desktop::isScreenSaverEnabled() throw()
  201364. {
  201365. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201366. }
  201367. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201368. {
  201369. const ScopedAutoReleasePool pool;
  201370. monitorCoords.clear();
  201371. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201372. : [[UIScreen mainScreen] bounds];
  201373. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201374. (int) r.origin.y,
  201375. (int) r.size.width,
  201376. (int) r.size.height));
  201377. }
  201378. #endif
  201379. #endif
  201380. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201381. #else
  201382. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201383. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201384. // compiled on its own).
  201385. #if JUCE_INCLUDED_FILE
  201386. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201387. {
  201388. pool = [[NSAutoreleasePool alloc] init];
  201389. }
  201390. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201391. {
  201392. [((NSAutoreleasePool*) pool) release];
  201393. }
  201394. void PlatformUtilities::beep()
  201395. {
  201396. NSBeep();
  201397. }
  201398. void PlatformUtilities::addItemToDock (const File& file)
  201399. {
  201400. // check that it's not already there...
  201401. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201402. .containsIgnoreCase (file.getFullPathName()))
  201403. {
  201404. 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>"
  201405. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201406. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201407. }
  201408. }
  201409. int PlatformUtilities::getOSXMinorVersionNumber()
  201410. {
  201411. SInt32 versionMinor = 0;
  201412. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201413. (void) err;
  201414. jassert (err == noErr);
  201415. return (int) versionMinor;
  201416. }
  201417. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201418. bool AlertWindow::showNativeDialogBox (const String& title,
  201419. const String& bodyText,
  201420. bool isOkCancel)
  201421. {
  201422. const ScopedAutoReleasePool pool;
  201423. return NSRunAlertPanel (juceStringToNS (title),
  201424. juceStringToNS (bodyText),
  201425. @"Ok",
  201426. isOkCancel ? @"Cancel" : nil,
  201427. nil) == NSAlertDefaultReturn;
  201428. }
  201429. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201430. {
  201431. if (files.size() == 0)
  201432. return false;
  201433. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201434. if (draggingSource == 0)
  201435. {
  201436. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201437. return false;
  201438. }
  201439. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201440. if (sourceComp == 0)
  201441. {
  201442. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201443. return false;
  201444. }
  201445. const ScopedAutoReleasePool pool;
  201446. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201447. if (view == 0)
  201448. return false;
  201449. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201450. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201451. owner: nil];
  201452. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201453. for (int i = 0; i < files.size(); ++i)
  201454. [filesArray addObject: juceStringToNS (files[i])];
  201455. [pboard setPropertyList: filesArray
  201456. forType: NSFilenamesPboardType];
  201457. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201458. fromView: nil];
  201459. dragPosition.x -= 16;
  201460. dragPosition.y -= 16;
  201461. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201462. at: dragPosition
  201463. offset: NSMakeSize (0, 0)
  201464. event: [[view window] currentEvent]
  201465. pasteboard: pboard
  201466. source: view
  201467. slideBack: YES];
  201468. return true;
  201469. }
  201470. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201471. {
  201472. jassertfalse // not implemented!
  201473. return false;
  201474. }
  201475. bool Desktop::canUseSemiTransparentWindows() throw()
  201476. {
  201477. return true;
  201478. }
  201479. const Point<int> Desktop::getMousePosition()
  201480. {
  201481. const ScopedAutoReleasePool pool;
  201482. const NSPoint p ([NSEvent mouseLocation]);
  201483. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201484. }
  201485. void Desktop::setMousePosition (const Point<int>& newPosition)
  201486. {
  201487. // this rubbish needs to be done around the warp call, to avoid causing a
  201488. // bizarre glitch..
  201489. CGAssociateMouseAndMouseCursorPosition (false);
  201490. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201491. CGAssociateMouseAndMouseCursorPosition (true);
  201492. }
  201493. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201494. class ScreenSaverDefeater : public Timer,
  201495. public DeletedAtShutdown
  201496. {
  201497. public:
  201498. ScreenSaverDefeater() throw()
  201499. {
  201500. startTimer (10000);
  201501. timerCallback();
  201502. }
  201503. ~ScreenSaverDefeater() {}
  201504. void timerCallback()
  201505. {
  201506. if (Process::isForegroundProcess())
  201507. UpdateSystemActivity (UsrActivity);
  201508. }
  201509. };
  201510. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201511. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201512. {
  201513. if (isEnabled)
  201514. {
  201515. deleteAndZero (screenSaverDefeater);
  201516. }
  201517. else if (screenSaverDefeater == 0)
  201518. {
  201519. screenSaverDefeater = new ScreenSaverDefeater();
  201520. }
  201521. }
  201522. bool Desktop::isScreenSaverEnabled() throw()
  201523. {
  201524. return screenSaverDefeater == 0;
  201525. }
  201526. #else
  201527. static IOPMAssertionID screenSaverDisablerID = 0;
  201528. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201529. {
  201530. if (isEnabled)
  201531. {
  201532. if (screenSaverDisablerID != 0)
  201533. {
  201534. IOPMAssertionRelease (screenSaverDisablerID);
  201535. screenSaverDisablerID = 0;
  201536. }
  201537. }
  201538. else
  201539. {
  201540. if (screenSaverDisablerID == 0)
  201541. {
  201542. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201543. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201544. CFSTR ("Juce"), &screenSaverDisablerID);
  201545. #else
  201546. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201547. &screenSaverDisablerID);
  201548. #endif
  201549. }
  201550. }
  201551. }
  201552. bool Desktop::isScreenSaverEnabled() throw()
  201553. {
  201554. return screenSaverDisablerID == 0;
  201555. }
  201556. #endif
  201557. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201558. {
  201559. const ScopedAutoReleasePool pool;
  201560. monitorCoords.clear();
  201561. NSArray* screens = [NSScreen screens];
  201562. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201563. for (unsigned int i = 0; i < [screens count]; ++i)
  201564. {
  201565. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201566. NSRect r = clipToWorkArea ? [s visibleFrame]
  201567. : [s frame];
  201568. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201569. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201570. (int) r.size.width,
  201571. (int) r.size.height));
  201572. }
  201573. jassert (monitorCoords.size() > 0);
  201574. }
  201575. #endif
  201576. #endif
  201577. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201578. #endif
  201579. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201580. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201581. // compiled on its own).
  201582. #if JUCE_INCLUDED_FILE
  201583. void Logger::outputDebugString (const String& text) throw()
  201584. {
  201585. std::cerr << text << std::endl;
  201586. }
  201587. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201588. {
  201589. static char testResult = 0;
  201590. if (testResult == 0)
  201591. {
  201592. struct kinfo_proc info;
  201593. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201594. size_t sz = sizeof (info);
  201595. sysctl (m, 4, &info, &sz, 0, 0);
  201596. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201597. }
  201598. return testResult > 0;
  201599. }
  201600. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201601. {
  201602. return juce_isRunningUnderDebugger();
  201603. }
  201604. #endif
  201605. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201606. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201607. #if JUCE_IPHONE
  201608. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201609. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201610. // compiled on its own).
  201611. #if JUCE_INCLUDED_FILE
  201612. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201613. #define SUPPORT_10_4_FONTS 1
  201614. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201615. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201616. #define SUPPORT_ONLY_10_4_FONTS 1
  201617. #endif
  201618. END_JUCE_NAMESPACE
  201619. @interface NSFont (PrivateHack)
  201620. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201621. @end
  201622. BEGIN_JUCE_NAMESPACE
  201623. #endif
  201624. class MacTypeface : public Typeface
  201625. {
  201626. public:
  201627. MacTypeface (const Font& font)
  201628. : Typeface (font.getTypefaceName())
  201629. {
  201630. const ScopedAutoReleasePool pool;
  201631. renderingTransform = CGAffineTransformIdentity;
  201632. bool needsItalicTransform = false;
  201633. #if JUCE_IPHONE
  201634. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201635. if (font.isItalic() || font.isBold())
  201636. {
  201637. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201638. for (NSString* i in familyFonts)
  201639. {
  201640. const String fn (nsStringToJuce (i));
  201641. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  201642. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  201643. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  201644. || afterDash.containsIgnoreCase ("italic")
  201645. || fn.endsWithIgnoreCase ("oblique")
  201646. || fn.endsWithIgnoreCase ("italic");
  201647. if (probablyBold == font.isBold()
  201648. && probablyItalic == font.isItalic())
  201649. {
  201650. fontName = i;
  201651. needsItalicTransform = false;
  201652. break;
  201653. }
  201654. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201655. {
  201656. fontName = i;
  201657. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201658. }
  201659. }
  201660. if (needsItalicTransform)
  201661. renderingTransform.c = 0.15f;
  201662. }
  201663. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201664. const int ascender = abs (CGFontGetAscent (fontRef));
  201665. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201666. ascent = ascender / totalHeight;
  201667. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201668. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201669. #else
  201670. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201671. if (font.isItalic())
  201672. {
  201673. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201674. toHaveTrait: NSItalicFontMask];
  201675. if (newFont == nsFont)
  201676. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201677. nsFont = newFont;
  201678. }
  201679. if (font.isBold())
  201680. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201681. [nsFont retain];
  201682. ascent = fabsf ((float) [nsFont ascender]);
  201683. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201684. ascent /= totalSize;
  201685. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201686. if (needsItalicTransform)
  201687. {
  201688. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201689. renderingTransform.c = 0.15f;
  201690. }
  201691. #if SUPPORT_ONLY_10_4_FONTS
  201692. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201693. if (atsFont == 0)
  201694. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201695. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201696. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201697. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201698. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201699. #else
  201700. #if SUPPORT_10_4_FONTS
  201701. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201702. {
  201703. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201704. if (atsFont == 0)
  201705. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201706. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201707. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201708. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201709. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201710. }
  201711. else
  201712. #endif
  201713. {
  201714. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201715. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201716. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201717. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201718. }
  201719. #endif
  201720. #endif
  201721. }
  201722. ~MacTypeface()
  201723. {
  201724. #if ! JUCE_IPHONE
  201725. [nsFont release];
  201726. #endif
  201727. if (fontRef != 0)
  201728. CGFontRelease (fontRef);
  201729. }
  201730. float getAscent() const
  201731. {
  201732. return ascent;
  201733. }
  201734. float getDescent() const
  201735. {
  201736. return 1.0f - ascent;
  201737. }
  201738. float getStringWidth (const String& text)
  201739. {
  201740. if (fontRef == 0 || text.isEmpty())
  201741. return 0;
  201742. const int length = text.length();
  201743. HeapBlock <CGGlyph> glyphs;
  201744. createGlyphsForString (text, length, glyphs);
  201745. float x = 0;
  201746. #if SUPPORT_ONLY_10_4_FONTS
  201747. HeapBlock <NSSize> advances (length);
  201748. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201749. for (int i = 0; i < length; ++i)
  201750. x += advances[i].width;
  201751. #else
  201752. #if SUPPORT_10_4_FONTS
  201753. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201754. {
  201755. HeapBlock <NSSize> advances (length);
  201756. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201757. for (int i = 0; i < length; ++i)
  201758. x += advances[i].width;
  201759. }
  201760. else
  201761. #endif
  201762. {
  201763. HeapBlock <int> advances (length);
  201764. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201765. for (int i = 0; i < length; ++i)
  201766. x += advances[i];
  201767. }
  201768. #endif
  201769. return x * unitsToHeightScaleFactor;
  201770. }
  201771. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201772. {
  201773. xOffsets.add (0);
  201774. if (fontRef == 0 || text.isEmpty())
  201775. return;
  201776. const int length = text.length();
  201777. HeapBlock <CGGlyph> glyphs;
  201778. createGlyphsForString (text, length, glyphs);
  201779. #if SUPPORT_ONLY_10_4_FONTS
  201780. HeapBlock <NSSize> advances (length);
  201781. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201782. int x = 0;
  201783. for (int i = 0; i < length; ++i)
  201784. {
  201785. x += advances[i].width;
  201786. xOffsets.add (x * unitsToHeightScaleFactor);
  201787. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201788. }
  201789. #else
  201790. #if SUPPORT_10_4_FONTS
  201791. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201792. {
  201793. HeapBlock <NSSize> advances (length);
  201794. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201795. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201796. float x = 0;
  201797. for (int i = 0; i < length; ++i)
  201798. {
  201799. x += advances[i].width;
  201800. xOffsets.add (x * unitsToHeightScaleFactor);
  201801. resultGlyphs.add (nsGlyphs[i]);
  201802. }
  201803. }
  201804. else
  201805. #endif
  201806. {
  201807. HeapBlock <int> advances (length);
  201808. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201809. {
  201810. int x = 0;
  201811. for (int i = 0; i < length; ++i)
  201812. {
  201813. x += advances [i];
  201814. xOffsets.add (x * unitsToHeightScaleFactor);
  201815. resultGlyphs.add (glyphs[i]);
  201816. }
  201817. }
  201818. }
  201819. #endif
  201820. }
  201821. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201822. {
  201823. #if JUCE_IPHONE
  201824. return false;
  201825. #else
  201826. if (nsFont == 0)
  201827. return false;
  201828. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201829. jassert (path.isEmpty());
  201830. const ScopedAutoReleasePool pool;
  201831. NSBezierPath* bez = [NSBezierPath bezierPath];
  201832. [bez moveToPoint: NSMakePoint (0, 0)];
  201833. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201834. inFont: nsFont];
  201835. for (int i = 0; i < [bez elementCount]; ++i)
  201836. {
  201837. NSPoint p[3];
  201838. switch ([bez elementAtIndex: i associatedPoints: p])
  201839. {
  201840. case NSMoveToBezierPathElement:
  201841. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201842. break;
  201843. case NSLineToBezierPathElement:
  201844. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201845. break;
  201846. case NSCurveToBezierPathElement:
  201847. 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);
  201848. break;
  201849. case NSClosePathBezierPathElement:
  201850. path.closeSubPath();
  201851. break;
  201852. default:
  201853. jassertfalse
  201854. break;
  201855. }
  201856. }
  201857. path.applyTransform (pathTransform);
  201858. return true;
  201859. #endif
  201860. }
  201861. juce_UseDebuggingNewOperator
  201862. CGFontRef fontRef;
  201863. float fontHeightToCGSizeFactor;
  201864. CGAffineTransform renderingTransform;
  201865. private:
  201866. float ascent, unitsToHeightScaleFactor;
  201867. #if JUCE_IPHONE
  201868. #else
  201869. NSFont* nsFont;
  201870. AffineTransform pathTransform;
  201871. #endif
  201872. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201873. {
  201874. #if SUPPORT_10_4_FONTS
  201875. #if ! SUPPORT_ONLY_10_4_FONTS
  201876. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201877. #endif
  201878. {
  201879. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201880. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201881. for (int i = 0; i < length; ++i)
  201882. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201883. return;
  201884. }
  201885. #endif
  201886. #if ! SUPPORT_ONLY_10_4_FONTS
  201887. if (charToGlyphMapper == 0)
  201888. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201889. glyphs.malloc (length);
  201890. for (int i = 0; i < length; ++i)
  201891. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  201892. #endif
  201893. }
  201894. #if ! SUPPORT_ONLY_10_4_FONTS
  201895. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  201896. class CharToGlyphMapper
  201897. {
  201898. public:
  201899. CharToGlyphMapper (CGFontRef fontRef)
  201900. : segCount (0), endCode (0), startCode (0), idDelta (0),
  201901. idRangeOffset (0), glyphIndexes (0)
  201902. {
  201903. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  201904. if (cmapTable != 0)
  201905. {
  201906. const int numSubtables = getValue16 (cmapTable, 2);
  201907. for (int i = 0; i < numSubtables; ++i)
  201908. {
  201909. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  201910. {
  201911. const int offset = getValue32 (cmapTable, i * 8 + 8);
  201912. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  201913. {
  201914. const int length = getValue16 (cmapTable, offset + 2);
  201915. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  201916. segCount = segCountX2 / 2;
  201917. const int endCodeOffset = offset + 14;
  201918. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  201919. const int idDeltaOffset = startCodeOffset + segCountX2;
  201920. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  201921. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  201922. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  201923. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  201924. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  201925. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  201926. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  201927. }
  201928. break;
  201929. }
  201930. }
  201931. CFRelease (cmapTable);
  201932. }
  201933. }
  201934. ~CharToGlyphMapper()
  201935. {
  201936. if (endCode != 0)
  201937. {
  201938. CFRelease (endCode);
  201939. CFRelease (startCode);
  201940. CFRelease (idDelta);
  201941. CFRelease (idRangeOffset);
  201942. CFRelease (glyphIndexes);
  201943. }
  201944. }
  201945. int getGlyphForCharacter (const juce_wchar c) const
  201946. {
  201947. for (int i = 0; i < segCount; ++i)
  201948. {
  201949. if (getValue16 (endCode, i * 2) >= c)
  201950. {
  201951. const int start = getValue16 (startCode, i * 2);
  201952. if (start > c)
  201953. break;
  201954. const int delta = getValue16 (idDelta, i * 2);
  201955. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  201956. if (rangeOffset == 0)
  201957. return delta + c;
  201958. else
  201959. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  201960. }
  201961. }
  201962. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  201963. return jmax (-1, c - 29);
  201964. }
  201965. private:
  201966. int segCount;
  201967. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  201968. static uint16 getValue16 (CFDataRef data, const int index)
  201969. {
  201970. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  201971. }
  201972. static uint32 getValue32 (CFDataRef data, const int index)
  201973. {
  201974. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  201975. }
  201976. };
  201977. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  201978. #endif
  201979. MacTypeface (const MacTypeface&);
  201980. MacTypeface& operator= (const MacTypeface&);
  201981. };
  201982. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  201983. {
  201984. return new MacTypeface (font);
  201985. }
  201986. const StringArray Font::findAllTypefaceNames()
  201987. {
  201988. StringArray names;
  201989. const ScopedAutoReleasePool pool;
  201990. #if JUCE_IPHONE
  201991. NSArray* fonts = [UIFont familyNames];
  201992. #else
  201993. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  201994. #endif
  201995. for (unsigned int i = 0; i < [fonts count]; ++i)
  201996. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  201997. names.sort (true);
  201998. return names;
  201999. }
  202000. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  202001. {
  202002. #if JUCE_IPHONE
  202003. defaultSans = "Helvetica";
  202004. defaultSerif = "Times New Roman";
  202005. defaultFixed = "Courier New";
  202006. #else
  202007. defaultSans = "Lucida Grande";
  202008. defaultSerif = "Times New Roman";
  202009. defaultFixed = "Monaco";
  202010. #endif
  202011. }
  202012. #endif
  202013. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202014. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202015. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202016. // compiled on its own).
  202017. #if JUCE_INCLUDED_FILE
  202018. class CoreGraphicsImage : public Image
  202019. {
  202020. public:
  202021. CoreGraphicsImage (const PixelFormat format_,
  202022. const int imageWidth_,
  202023. const int imageHeight_,
  202024. const bool clearImage)
  202025. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202026. {
  202027. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  202028. : CGColorSpaceCreateDeviceRGB();
  202029. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202030. colourSpace, getCGImageFlags (*this));
  202031. CGColorSpaceRelease (colourSpace);
  202032. }
  202033. ~CoreGraphicsImage()
  202034. {
  202035. CGContextRelease (context);
  202036. }
  202037. LowLevelGraphicsContext* createLowLevelContext();
  202038. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202039. {
  202040. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202041. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202042. {
  202043. return CGBitmapContextCreateImage (nativeImage->context);
  202044. }
  202045. else
  202046. {
  202047. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202048. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202049. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202050. 8, srcData.pixelStride * 8, srcData.lineStride,
  202051. colourSpace, getCGImageFlags (juceImage), provider,
  202052. 0, true, kCGRenderingIntentDefault);
  202053. CGDataProviderRelease (provider);
  202054. return imageRef;
  202055. }
  202056. }
  202057. #if JUCE_MAC
  202058. static NSImage* createNSImage (const Image& image)
  202059. {
  202060. const ScopedAutoReleasePool pool;
  202061. NSImage* im = [[NSImage alloc] init];
  202062. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202063. [im lockFocus];
  202064. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202065. CGImageRef imageRef = createImage (image, false, colourSpace);
  202066. CGColorSpaceRelease (colourSpace);
  202067. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202068. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202069. CGImageRelease (imageRef);
  202070. [im unlockFocus];
  202071. return im;
  202072. }
  202073. #endif
  202074. CGContextRef context;
  202075. private:
  202076. static CGBitmapInfo getCGImageFlags (const Image& image)
  202077. {
  202078. #if JUCE_BIG_ENDIAN
  202079. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202080. #else
  202081. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202082. #endif
  202083. }
  202084. };
  202085. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202086. {
  202087. #if USE_COREGRAPHICS_RENDERING
  202088. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202089. #else
  202090. return new Image (format, imageWidth, imageHeight, clearImage);
  202091. #endif
  202092. }
  202093. class CoreGraphicsContext : public LowLevelGraphicsContext
  202094. {
  202095. public:
  202096. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202097. : context (context_),
  202098. flipHeight (flipHeight_),
  202099. state (new SavedState()),
  202100. numGradientLookupEntries (0)
  202101. {
  202102. CGContextRetain (context);
  202103. CGContextSaveGState(context);
  202104. CGContextSetShouldSmoothFonts (context, true);
  202105. CGContextSetShouldAntialias (context, true);
  202106. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202107. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202108. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202109. gradientCallbacks.version = 0;
  202110. gradientCallbacks.evaluate = gradientCallback;
  202111. gradientCallbacks.releaseInfo = 0;
  202112. setFont (Font());
  202113. }
  202114. ~CoreGraphicsContext()
  202115. {
  202116. CGContextRestoreGState (context);
  202117. CGContextRelease (context);
  202118. CGColorSpaceRelease (rgbColourSpace);
  202119. CGColorSpaceRelease (greyColourSpace);
  202120. }
  202121. bool isVectorDevice() const { return false; }
  202122. void setOrigin (int x, int y)
  202123. {
  202124. CGContextTranslateCTM (context, x, -y);
  202125. }
  202126. bool clipToRectangle (const Rectangle<int>& r)
  202127. {
  202128. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202129. return ! isClipEmpty();
  202130. }
  202131. bool clipToRectangleList (const RectangleList& clipRegion)
  202132. {
  202133. if (clipRegion.isEmpty())
  202134. {
  202135. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202136. return false;
  202137. }
  202138. else
  202139. {
  202140. const int numRects = clipRegion.getNumRectangles();
  202141. HeapBlock <CGRect> rects (numRects);
  202142. for (int i = 0; i < numRects; ++i)
  202143. {
  202144. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202145. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202146. }
  202147. CGContextClipToRects (context, rects, numRects);
  202148. return ! isClipEmpty();
  202149. }
  202150. }
  202151. void excludeClipRectangle (const Rectangle<int>& r)
  202152. {
  202153. RectangleList remaining (getClipBounds());
  202154. remaining.subtract (r);
  202155. clipToRectangleList (remaining);
  202156. }
  202157. void clipToPath (const Path& path, const AffineTransform& transform)
  202158. {
  202159. createPath (path, transform);
  202160. CGContextClip (context);
  202161. }
  202162. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202163. {
  202164. if (! transform.isSingularity())
  202165. {
  202166. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202167. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202168. flip();
  202169. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202170. applyTransform (t);
  202171. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202172. CGContextClipToMask (context, r, image);
  202173. applyTransform (t.inverted());
  202174. flip();
  202175. CGImageRelease (image);
  202176. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202177. }
  202178. }
  202179. bool clipRegionIntersects (const Rectangle<int>& r)
  202180. {
  202181. return getClipBounds().intersects (r);
  202182. }
  202183. const Rectangle<int> getClipBounds() const
  202184. {
  202185. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202186. return Rectangle<int> (roundToInt (bounds.origin.x),
  202187. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202188. roundToInt (bounds.size.width),
  202189. roundToInt (bounds.size.height));
  202190. }
  202191. bool isClipEmpty() const
  202192. {
  202193. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202194. }
  202195. void saveState()
  202196. {
  202197. CGContextSaveGState (context);
  202198. stateStack.add (new SavedState (*state));
  202199. }
  202200. void restoreState()
  202201. {
  202202. CGContextRestoreGState (context);
  202203. SavedState* const top = stateStack.getLast();
  202204. if (top != 0)
  202205. {
  202206. state = top;
  202207. stateStack.removeLast (1, false);
  202208. }
  202209. else
  202210. {
  202211. jassertfalse // trying to pop with an empty stack!
  202212. }
  202213. }
  202214. void setFill (const FillType& fillType)
  202215. {
  202216. state->fillType = fillType;
  202217. if (fillType.isColour())
  202218. {
  202219. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202220. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202221. CGContextSetAlpha (context, 1.0f);
  202222. }
  202223. }
  202224. void setOpacity (float newOpacity)
  202225. {
  202226. state->fillType.setOpacity (newOpacity);
  202227. setFill (state->fillType);
  202228. }
  202229. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202230. {
  202231. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202232. ? kCGInterpolationLow
  202233. : kCGInterpolationHigh);
  202234. }
  202235. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202236. {
  202237. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202238. if (replaceExistingContents)
  202239. {
  202240. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202241. CGContextClearRect (context, cgRect);
  202242. #else
  202243. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202244. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202245. CGContextClearRect (context, cgRect);
  202246. else
  202247. #endif
  202248. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202249. #endif
  202250. fillRect (r, false);
  202251. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202252. }
  202253. else
  202254. {
  202255. if (state->fillType.isColour())
  202256. {
  202257. CGContextFillRect (context, cgRect);
  202258. }
  202259. else if (state->fillType.isGradient())
  202260. {
  202261. CGContextSaveGState (context);
  202262. CGContextClipToRect (context, cgRect);
  202263. drawGradient();
  202264. CGContextRestoreGState (context);
  202265. }
  202266. else
  202267. {
  202268. CGContextSaveGState (context);
  202269. CGContextClipToRect (context, cgRect);
  202270. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202271. CGContextRestoreGState (context);
  202272. }
  202273. }
  202274. }
  202275. void fillPath (const Path& path, const AffineTransform& transform)
  202276. {
  202277. CGContextSaveGState (context);
  202278. if (state->fillType.isColour())
  202279. {
  202280. flip();
  202281. applyTransform (transform);
  202282. createPath (path);
  202283. if (path.isUsingNonZeroWinding())
  202284. CGContextFillPath (context);
  202285. else
  202286. CGContextEOFillPath (context);
  202287. }
  202288. else
  202289. {
  202290. createPath (path, transform);
  202291. if (path.isUsingNonZeroWinding())
  202292. CGContextClip (context);
  202293. else
  202294. CGContextEOClip (context);
  202295. if (state->fillType.isGradient())
  202296. drawGradient();
  202297. else
  202298. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202299. }
  202300. CGContextRestoreGState (context);
  202301. }
  202302. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202303. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202304. {
  202305. jassert (sourceImage.getBounds().contains (srcClip));
  202306. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202307. CGImageRef image = fullImage;
  202308. if (srcClip != sourceImage.getBounds())
  202309. {
  202310. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202311. srcClip.getWidth(), srcClip.getHeight()));
  202312. CGImageRelease (fullImage);
  202313. }
  202314. CGContextSaveGState (context);
  202315. CGContextSetAlpha (context, state->fillType.getOpacity());
  202316. flip();
  202317. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202318. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202319. if (fillEntireClipAsTiles)
  202320. {
  202321. #if JUCE_IPHONE
  202322. CGContextDrawTiledImage (context, imageRect, image);
  202323. #else
  202324. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202325. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202326. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202327. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202328. CGContextDrawTiledImage (context, imageRect, image);
  202329. else
  202330. #endif
  202331. {
  202332. // Fallback to manually doing a tiled fill on 10.4
  202333. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202334. const int iw = srcClip.getWidth();
  202335. const int ih = srcClip.getHeight();
  202336. int x = 0, y = 0;
  202337. while (x > clip.origin.x) x -= iw;
  202338. while (y > clip.origin.y) y -= ih;
  202339. const int right = (int) (clip.origin.x + clip.size.width);
  202340. const int bottom = (int) (clip.origin.y + clip.size.height);
  202341. while (y < bottom)
  202342. {
  202343. for (int x2 = x; x2 < right; x2 += iw)
  202344. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202345. y += ih;
  202346. }
  202347. }
  202348. #endif
  202349. }
  202350. else
  202351. {
  202352. CGContextDrawImage (context, imageRect, image);
  202353. }
  202354. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202355. CGContextRestoreGState (context);
  202356. }
  202357. void drawLine (double x1, double y1, double x2, double y2)
  202358. {
  202359. CGContextSetLineCap (context, kCGLineCapSquare);
  202360. CGContextSetLineWidth (context, 1.0f);
  202361. CGContextSetRGBStrokeColor (context,
  202362. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202363. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202364. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  202365. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  202366. CGContextStrokeLineSegments (context, line, 1);
  202367. }
  202368. void drawVerticalLine (const int x, double top, double bottom)
  202369. {
  202370. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202371. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202372. #else
  202373. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202374. // the x co-ord slightly to trick it..
  202375. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202376. #endif
  202377. }
  202378. void drawHorizontalLine (const int y, double left, double right)
  202379. {
  202380. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202381. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202382. #else
  202383. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202384. // the x co-ord slightly to trick it..
  202385. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202386. #endif
  202387. }
  202388. void setFont (const Font& newFont)
  202389. {
  202390. if (state->font != newFont)
  202391. {
  202392. state->fontRef = 0;
  202393. state->font = newFont;
  202394. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202395. if (mf != 0)
  202396. {
  202397. state->fontRef = mf->fontRef;
  202398. CGContextSetFont (context, state->fontRef);
  202399. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202400. state->fontTransform = mf->renderingTransform;
  202401. state->fontTransform.a *= state->font.getHorizontalScale();
  202402. CGContextSetTextMatrix (context, state->fontTransform);
  202403. }
  202404. }
  202405. }
  202406. const Font getFont()
  202407. {
  202408. return state->font;
  202409. }
  202410. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202411. {
  202412. if (state->fontRef != 0 && state->fillType.isColour())
  202413. {
  202414. if (transform.isOnlyTranslation())
  202415. {
  202416. CGGlyph g = glyphNumber;
  202417. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202418. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202419. }
  202420. else
  202421. {
  202422. CGContextSaveGState (context);
  202423. flip();
  202424. applyTransform (transform);
  202425. CGAffineTransform t = state->fontTransform;
  202426. t.d = -t.d;
  202427. CGContextSetTextMatrix (context, t);
  202428. CGGlyph g = glyphNumber;
  202429. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202430. CGContextSetTextMatrix (context, state->fontTransform);
  202431. CGContextRestoreGState (context);
  202432. }
  202433. }
  202434. else
  202435. {
  202436. Path p;
  202437. Font& f = state->font;
  202438. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202439. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202440. .followedBy (transform));
  202441. }
  202442. }
  202443. private:
  202444. CGContextRef context;
  202445. const CGFloat flipHeight;
  202446. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202447. CGFunctionCallbacks gradientCallbacks;
  202448. struct SavedState
  202449. {
  202450. SavedState()
  202451. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202452. {
  202453. }
  202454. SavedState (const SavedState& other)
  202455. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202456. fontTransform (other.fontTransform)
  202457. {
  202458. }
  202459. ~SavedState()
  202460. {
  202461. }
  202462. FillType fillType;
  202463. Font font;
  202464. CGFontRef fontRef;
  202465. CGAffineTransform fontTransform;
  202466. };
  202467. ScopedPointer <SavedState> state;
  202468. OwnedArray <SavedState> stateStack;
  202469. HeapBlock <PixelARGB> gradientLookupTable;
  202470. int numGradientLookupEntries;
  202471. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202472. {
  202473. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202474. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202475. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202476. colour.unpremultiply();
  202477. outData[0] = colour.getRed() / 255.0f;
  202478. outData[1] = colour.getGreen() / 255.0f;
  202479. outData[2] = colour.getBlue() / 255.0f;
  202480. outData[3] = colour.getAlpha() / 255.0f;
  202481. }
  202482. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202483. {
  202484. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202485. --numGradientLookupEntries;
  202486. CGShadingRef result = 0;
  202487. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202488. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202489. if (gradient.isRadial)
  202490. {
  202491. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202492. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202493. function, true, true);
  202494. }
  202495. else
  202496. {
  202497. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202498. CGPointMake (gradient.x2, gradient.y2),
  202499. function, true, true);
  202500. }
  202501. CGFunctionRelease (function);
  202502. return result;
  202503. }
  202504. void drawGradient()
  202505. {
  202506. flip();
  202507. applyTransform (state->fillType.transform);
  202508. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202509. // you draw a gradient with high quality interp enabled).
  202510. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202511. CGContextSetAlpha (context, state->fillType.getOpacity());
  202512. CGContextDrawShading (context, shading);
  202513. CGShadingRelease (shading);
  202514. }
  202515. void createPath (const Path& path) const
  202516. {
  202517. CGContextBeginPath (context);
  202518. Path::Iterator i (path);
  202519. while (i.next())
  202520. {
  202521. switch (i.elementType)
  202522. {
  202523. case Path::Iterator::startNewSubPath:
  202524. CGContextMoveToPoint (context, i.x1, i.y1);
  202525. break;
  202526. case Path::Iterator::lineTo:
  202527. CGContextAddLineToPoint (context, i.x1, i.y1);
  202528. break;
  202529. case Path::Iterator::quadraticTo:
  202530. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202531. break;
  202532. case Path::Iterator::cubicTo:
  202533. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202534. break;
  202535. case Path::Iterator::closePath:
  202536. CGContextClosePath (context); break;
  202537. default:
  202538. jassertfalse
  202539. break;
  202540. }
  202541. }
  202542. }
  202543. void createPath (const Path& path, const AffineTransform& transform) const
  202544. {
  202545. CGContextBeginPath (context);
  202546. Path::Iterator i (path);
  202547. while (i.next())
  202548. {
  202549. switch (i.elementType)
  202550. {
  202551. case Path::Iterator::startNewSubPath:
  202552. transform.transformPoint (i.x1, i.y1);
  202553. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202554. break;
  202555. case Path::Iterator::lineTo:
  202556. transform.transformPoint (i.x1, i.y1);
  202557. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202558. break;
  202559. case Path::Iterator::quadraticTo:
  202560. transform.transformPoint (i.x1, i.y1);
  202561. transform.transformPoint (i.x2, i.y2);
  202562. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202563. break;
  202564. case Path::Iterator::cubicTo:
  202565. transform.transformPoint (i.x1, i.y1);
  202566. transform.transformPoint (i.x2, i.y2);
  202567. transform.transformPoint (i.x3, i.y3);
  202568. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202569. break;
  202570. case Path::Iterator::closePath:
  202571. CGContextClosePath (context); break;
  202572. default:
  202573. jassertfalse
  202574. break;
  202575. }
  202576. }
  202577. }
  202578. static Image* createAlphaChannelImage (const Image& im)
  202579. {
  202580. if (im.getFormat() == Image::SingleChannel)
  202581. return const_cast <Image*> (&im);
  202582. return im.createCopyOfAlphaChannel();
  202583. }
  202584. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202585. {
  202586. if (im.getFormat() != Image::SingleChannel)
  202587. delete alphaIm;
  202588. }
  202589. void flip() const
  202590. {
  202591. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202592. }
  202593. void applyTransform (const AffineTransform& transform) const
  202594. {
  202595. CGAffineTransform t;
  202596. t.a = transform.mat00;
  202597. t.b = transform.mat10;
  202598. t.c = transform.mat01;
  202599. t.d = transform.mat11;
  202600. t.tx = transform.mat02;
  202601. t.ty = transform.mat12;
  202602. CGContextConcatCTM (context, t);
  202603. }
  202604. CoreGraphicsContext (const CoreGraphicsContext&);
  202605. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202606. };
  202607. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202608. {
  202609. return new CoreGraphicsContext (context, imageHeight);
  202610. }
  202611. #endif
  202612. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202613. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202614. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202615. // compiled on its own).
  202616. #if JUCE_INCLUDED_FILE
  202617. class UIViewComponentPeer;
  202618. END_JUCE_NAMESPACE
  202619. #define JuceUIView MakeObjCClassName(JuceUIView)
  202620. @interface JuceUIView : UIView <UITextFieldDelegate>
  202621. {
  202622. @public
  202623. UIViewComponentPeer* owner;
  202624. UITextField *hiddenTextField;
  202625. }
  202626. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202627. - (void) dealloc;
  202628. - (void) drawRect: (CGRect) r;
  202629. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202630. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202631. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202632. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202633. - (BOOL) becomeFirstResponder;
  202634. - (BOOL) resignFirstResponder;
  202635. - (BOOL) canBecomeFirstResponder;
  202636. - (void) asyncRepaint: (id) rect;
  202637. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string;
  202638. - (BOOL) textFieldShouldClear: (UITextField*) textField;
  202639. - (BOOL) textFieldShouldReturn: (UITextField*) textField;
  202640. @end
  202641. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202642. @interface JuceUIWindow : UIWindow
  202643. {
  202644. @private
  202645. UIViewComponentPeer* owner;
  202646. bool isZooming;
  202647. }
  202648. - (void) setOwner: (UIViewComponentPeer*) owner;
  202649. - (void) becomeKeyWindow;
  202650. @end
  202651. BEGIN_JUCE_NAMESPACE
  202652. class UIViewComponentPeer : public ComponentPeer,
  202653. public FocusChangeListener
  202654. {
  202655. public:
  202656. UIViewComponentPeer (Component* const component,
  202657. const int windowStyleFlags,
  202658. UIView* viewToAttachTo);
  202659. ~UIViewComponentPeer();
  202660. void* getNativeHandle() const;
  202661. void setVisible (bool shouldBeVisible);
  202662. void setTitle (const String& title);
  202663. void setPosition (int x, int y);
  202664. void setSize (int w, int h);
  202665. void setBounds (int x, int y, int w, int h, bool isNowFullScreen);
  202666. const Rectangle<int> getBounds() const;
  202667. const Rectangle<int> getBounds (const bool global) const;
  202668. const Point<int> getScreenPosition() const;
  202669. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202670. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202671. void setMinimised (bool shouldBeMinimised);
  202672. bool isMinimised() const;
  202673. void setFullScreen (bool shouldBeFullScreen);
  202674. bool isFullScreen() const;
  202675. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202676. const BorderSize getFrameSize() const;
  202677. bool setAlwaysOnTop (bool alwaysOnTop);
  202678. void toFront (bool makeActiveWindow);
  202679. void toBehind (ComponentPeer* other);
  202680. void setIcon (const Image& newIcon);
  202681. virtual void drawRect (CGRect r);
  202682. virtual bool canBecomeKeyWindow();
  202683. virtual bool windowShouldClose();
  202684. virtual void redirectMovedOrResized();
  202685. virtual CGRect constrainRect (CGRect r);
  202686. virtual void viewFocusGain();
  202687. virtual void viewFocusLoss();
  202688. bool isFocused() const;
  202689. void grabFocus();
  202690. void textInputRequired (const Point<int>& position);
  202691. virtual BOOL textFieldReplaceCharacters (const Range<int>& range, const String& text);
  202692. virtual BOOL textFieldShouldClear();
  202693. virtual BOOL textFieldShouldReturn();
  202694. void updateHiddenTextContent (TextInputTarget* target);
  202695. void globalFocusChanged (Component*);
  202696. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202697. void repaint (int x, int y, int w, int h);
  202698. void performAnyPendingRepaintsNow();
  202699. juce_UseDebuggingNewOperator
  202700. UIWindow* window;
  202701. JuceUIView* view;
  202702. bool isSharedWindow, fullScreen, insideDrawRect;
  202703. static ModifierKeys currentModifiers;
  202704. static int64 getMouseTime (UIEvent* e)
  202705. {
  202706. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202707. + (int64) ([e timestamp] * 1000.0);
  202708. }
  202709. Array <UITouch*> currentTouches;
  202710. };
  202711. END_JUCE_NAMESPACE
  202712. @implementation JuceUIView
  202713. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202714. withFrame: (CGRect) frame
  202715. {
  202716. [super initWithFrame: frame];
  202717. owner = owner_;
  202718. hiddenTextField = [[UITextField alloc] initWithFrame: CGRectMake (0, 0, 0, 0)];
  202719. [self addSubview: hiddenTextField];
  202720. hiddenTextField.delegate = self;
  202721. return self;
  202722. }
  202723. - (void) dealloc
  202724. {
  202725. [hiddenTextField removeFromSuperview];
  202726. [hiddenTextField release];
  202727. [super dealloc];
  202728. }
  202729. - (void) drawRect: (CGRect) r
  202730. {
  202731. if (owner != 0)
  202732. owner->drawRect (r);
  202733. }
  202734. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  202735. {
  202736. return false;
  202737. }
  202738. ModifierKeys UIViewComponentPeer::currentModifiers;
  202739. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202740. {
  202741. return UIViewComponentPeer::currentModifiers;
  202742. }
  202743. void ModifierKeys::updateCurrentModifiers() throw()
  202744. {
  202745. currentModifiers = UIViewComponentPeer::currentModifiers;
  202746. }
  202747. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202748. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202749. {
  202750. if (owner != 0)
  202751. owner->handleTouches (event, true, false, false);
  202752. }
  202753. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202754. {
  202755. if (owner != 0)
  202756. owner->handleTouches (event, false, false, false);
  202757. }
  202758. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202759. {
  202760. if (owner != 0)
  202761. owner->handleTouches (event, false, true, false);
  202762. }
  202763. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202764. {
  202765. if (owner != 0)
  202766. owner->handleTouches (event, false, true, true);
  202767. [self touchesEnded: touches withEvent: event];
  202768. }
  202769. - (BOOL) becomeFirstResponder
  202770. {
  202771. if (owner != 0)
  202772. owner->viewFocusGain();
  202773. return true;
  202774. }
  202775. - (BOOL) resignFirstResponder
  202776. {
  202777. if (owner != 0)
  202778. owner->viewFocusLoss();
  202779. return true;
  202780. }
  202781. - (BOOL) canBecomeFirstResponder
  202782. {
  202783. return owner != 0 && owner->canBecomeKeyWindow();
  202784. }
  202785. - (void) asyncRepaint: (id) rect
  202786. {
  202787. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202788. [self setNeedsDisplayInRect: *r];
  202789. }
  202790. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) text
  202791. {
  202792. return owner->textFieldReplaceCharacters (Range<int> (range.location, range.location + range.length),
  202793. nsStringToJuce (text));
  202794. }
  202795. - (BOOL) textFieldShouldClear: (UITextField*) textField
  202796. {
  202797. return owner->textFieldShouldClear();
  202798. }
  202799. - (BOOL) textFieldShouldReturn: (UITextField*) textField
  202800. {
  202801. return owner->textFieldShouldReturn();
  202802. }
  202803. @end
  202804. @implementation JuceUIWindow
  202805. - (void) setOwner: (UIViewComponentPeer*) owner_
  202806. {
  202807. owner = owner_;
  202808. isZooming = false;
  202809. }
  202810. - (void) becomeKeyWindow
  202811. {
  202812. [super becomeKeyWindow];
  202813. if (owner != 0)
  202814. owner->grabFocus();
  202815. }
  202816. @end
  202817. BEGIN_JUCE_NAMESPACE
  202818. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202819. const int windowStyleFlags,
  202820. UIView* viewToAttachTo)
  202821. : ComponentPeer (component, windowStyleFlags),
  202822. window (0),
  202823. view (0),
  202824. isSharedWindow (viewToAttachTo != 0),
  202825. fullScreen (false),
  202826. insideDrawRect (false)
  202827. {
  202828. CGRect r = CGRectMake (0, 0, (float) component->getWidth(), (float) component->getHeight());
  202829. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202830. if (isSharedWindow)
  202831. {
  202832. window = [viewToAttachTo window];
  202833. [viewToAttachTo addSubview: view];
  202834. setVisible (component->isVisible());
  202835. }
  202836. else
  202837. {
  202838. r.origin.x = (float) component->getX();
  202839. r.origin.y = (float) component->getY();
  202840. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202841. window = [[JuceUIWindow alloc] init];
  202842. window.frame = r;
  202843. window.opaque = component->isOpaque();
  202844. view.opaque = component->isOpaque();
  202845. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202846. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202847. [((JuceUIWindow*) window) setOwner: this];
  202848. if (component->isAlwaysOnTop())
  202849. window.windowLevel = UIWindowLevelAlert;
  202850. [window addSubview: view];
  202851. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202852. view.hidden = ! component->isVisible();
  202853. window.hidden = ! component->isVisible();
  202854. view.multipleTouchEnabled = YES;
  202855. }
  202856. setTitle (component->getName());
  202857. Desktop::getInstance().addFocusChangeListener (this);
  202858. }
  202859. UIViewComponentPeer::~UIViewComponentPeer()
  202860. {
  202861. Desktop::getInstance().removeFocusChangeListener (this);
  202862. view->owner = 0;
  202863. [view removeFromSuperview];
  202864. [view release];
  202865. if (! isSharedWindow)
  202866. {
  202867. [((JuceUIWindow*) window) setOwner: 0];
  202868. [window release];
  202869. }
  202870. }
  202871. void* UIViewComponentPeer::getNativeHandle() const
  202872. {
  202873. return view;
  202874. }
  202875. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202876. {
  202877. view.hidden = ! shouldBeVisible;
  202878. if (! isSharedWindow)
  202879. window.hidden = ! shouldBeVisible;
  202880. }
  202881. void UIViewComponentPeer::setTitle (const String& title)
  202882. {
  202883. // xxx is this possible?
  202884. }
  202885. void UIViewComponentPeer::setPosition (int x, int y)
  202886. {
  202887. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202888. }
  202889. void UIViewComponentPeer::setSize (int w, int h)
  202890. {
  202891. setBounds (component->getX(), component->getY(), w, h, false);
  202892. }
  202893. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202894. {
  202895. fullScreen = isNowFullScreen;
  202896. w = jmax (0, w);
  202897. h = jmax (0, h);
  202898. CGRect r;
  202899. r.origin.x = (float) x;
  202900. r.origin.y = (float) y;
  202901. r.size.width = (float) w;
  202902. r.size.height = (float) h;
  202903. if (isSharedWindow)
  202904. {
  202905. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202906. if ([view frame].size.width != r.size.width
  202907. || [view frame].size.height != r.size.height)
  202908. [view setNeedsDisplay];
  202909. view.frame = r;
  202910. }
  202911. else
  202912. {
  202913. window.frame = r;
  202914. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202915. }
  202916. }
  202917. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202918. {
  202919. CGRect r = [view frame];
  202920. if (global && [view window] != 0)
  202921. {
  202922. r = [view convertRect: r toView: nil];
  202923. CGRect wr = [[view window] frame];
  202924. r.origin.x += wr.origin.x;
  202925. r.origin.y += wr.origin.y;
  202926. }
  202927. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  202928. (int) r.size.width, (int) r.size.height);
  202929. }
  202930. const Rectangle<int> UIViewComponentPeer::getBounds() const
  202931. {
  202932. return getBounds (! isSharedWindow);
  202933. }
  202934. const Point<int> UIViewComponentPeer::getScreenPosition() const
  202935. {
  202936. return getBounds (true).getPosition();
  202937. }
  202938. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  202939. {
  202940. return relativePosition + getScreenPosition();
  202941. }
  202942. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  202943. {
  202944. return screenPosition - getScreenPosition();
  202945. }
  202946. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  202947. {
  202948. if (constrainer != 0)
  202949. {
  202950. CGRect current = [window frame];
  202951. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  202952. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  202953. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  202954. (int) r.size.width, (int) r.size.height);
  202955. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  202956. (int) current.size.width, (int) current.size.height);
  202957. constrainer->checkBounds (pos, original,
  202958. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  202959. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  202960. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  202961. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  202962. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  202963. r.origin.x = pos.getX();
  202964. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  202965. r.size.width = pos.getWidth();
  202966. r.size.height = pos.getHeight();
  202967. }
  202968. return r;
  202969. }
  202970. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  202971. {
  202972. // xxx
  202973. }
  202974. bool UIViewComponentPeer::isMinimised() const
  202975. {
  202976. return false;
  202977. }
  202978. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  202979. {
  202980. if (! isSharedWindow)
  202981. {
  202982. Rectangle<int> r (lastNonFullscreenBounds);
  202983. setMinimised (false);
  202984. if (fullScreen != shouldBeFullScreen)
  202985. {
  202986. if (shouldBeFullScreen)
  202987. r = Desktop::getInstance().getMainMonitorArea();
  202988. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  202989. if (r != getComponent()->getBounds() && ! r.isEmpty())
  202990. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  202991. }
  202992. }
  202993. }
  202994. bool UIViewComponentPeer::isFullScreen() const
  202995. {
  202996. return fullScreen;
  202997. }
  202998. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  202999. {
  203000. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  203001. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  203002. return false;
  203003. CGPoint p;
  203004. p.x = (float) position.getX();
  203005. p.y = (float) position.getY();
  203006. UIView* v = [view hitTest: p withEvent: nil];
  203007. if (trueIfInAChildWindow)
  203008. return v != nil;
  203009. return v == view;
  203010. }
  203011. const BorderSize UIViewComponentPeer::getFrameSize() const
  203012. {
  203013. BorderSize b;
  203014. if (! isSharedWindow)
  203015. {
  203016. CGRect v = [view convertRect: [view frame] toView: nil];
  203017. CGRect w = [window frame];
  203018. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203019. b.setBottom ((int) v.origin.y);
  203020. b.setLeft ((int) v.origin.x);
  203021. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203022. }
  203023. return b;
  203024. }
  203025. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203026. {
  203027. if (! isSharedWindow)
  203028. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203029. return true;
  203030. }
  203031. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203032. {
  203033. if (isSharedWindow)
  203034. [[view superview] bringSubviewToFront: view];
  203035. if (window != 0 && component->isVisible())
  203036. [window makeKeyAndVisible];
  203037. }
  203038. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203039. {
  203040. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203041. if (isSharedWindow)
  203042. {
  203043. [[view superview] insertSubview: view belowSubview: o->view];
  203044. }
  203045. else
  203046. {
  203047. jassertfalse // don't know how to do this
  203048. }
  203049. }
  203050. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203051. {
  203052. // to do..
  203053. }
  203054. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203055. {
  203056. NSArray* touches = [[event touchesForView: view] allObjects];
  203057. for (unsigned int i = 0; i < [touches count]; ++i)
  203058. {
  203059. UITouch* touch = [touches objectAtIndex: i];
  203060. CGPoint p = [touch locationInView: view];
  203061. const Point<int> pos ((int) p.x, (int) p.y);
  203062. juce_lastMousePos = pos + getScreenPosition();
  203063. const int64 time = getMouseTime (event);
  203064. int touchIndex = currentTouches.indexOf (touch);
  203065. if (touchIndex < 0)
  203066. {
  203067. touchIndex = currentTouches.size();
  203068. currentTouches.add (touch);
  203069. }
  203070. if (isDown)
  203071. {
  203072. currentModifiers = currentModifiers.withoutMouseButtons();
  203073. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203074. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203075. }
  203076. else if (isUp)
  203077. {
  203078. currentModifiers = currentModifiers.withoutMouseButtons();
  203079. currentTouches.remove (touchIndex);
  203080. }
  203081. if (isCancel)
  203082. currentTouches.clear();
  203083. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203084. }
  203085. }
  203086. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203087. void UIViewComponentPeer::viewFocusGain()
  203088. {
  203089. if (currentlyFocusedPeer != this)
  203090. {
  203091. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203092. currentlyFocusedPeer->handleFocusLoss();
  203093. currentlyFocusedPeer = this;
  203094. handleFocusGain();
  203095. }
  203096. }
  203097. void UIViewComponentPeer::viewFocusLoss()
  203098. {
  203099. if (currentlyFocusedPeer == this)
  203100. {
  203101. currentlyFocusedPeer = 0;
  203102. handleFocusLoss();
  203103. }
  203104. }
  203105. void juce_HandleProcessFocusChange()
  203106. {
  203107. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203108. {
  203109. if (Process::isForegroundProcess())
  203110. {
  203111. currentlyFocusedPeer->handleFocusGain();
  203112. ComponentPeer::bringModalComponentToFront();
  203113. }
  203114. else
  203115. {
  203116. currentlyFocusedPeer->handleFocusLoss();
  203117. // turn kiosk mode off if we lose focus..
  203118. Desktop::getInstance().setKioskModeComponent (0);
  203119. }
  203120. }
  203121. }
  203122. bool UIViewComponentPeer::isFocused() const
  203123. {
  203124. return isSharedWindow ? this == currentlyFocusedPeer
  203125. : (window != 0 && [window isKeyWindow]);
  203126. }
  203127. void UIViewComponentPeer::grabFocus()
  203128. {
  203129. if (window != 0)
  203130. {
  203131. [window makeKeyWindow];
  203132. viewFocusGain();
  203133. }
  203134. }
  203135. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203136. {
  203137. }
  203138. void UIViewComponentPeer::updateHiddenTextContent (TextInputTarget* target)
  203139. {
  203140. view->hiddenTextField.text = juceStringToNS (target->getTextInRange (Range<int> (0, target->getHighlightedRegion().getStart())));
  203141. }
  203142. BOOL UIViewComponentPeer::textFieldReplaceCharacters (const Range<int>& range, const String& text)
  203143. {
  203144. TextInputTarget* const target = findCurrentTextInputTarget();
  203145. if (target != 0)
  203146. {
  203147. const Range<int> currentSelection (target->getHighlightedRegion());
  203148. if (range.getLength() == 1 && text.isEmpty()) // (detect backspace)
  203149. if (currentSelection.isEmpty())
  203150. target->setHighlightedRegion (currentSelection.withStart (currentSelection.getStart() - 1));
  203151. target->insertTextAtCaret (text);
  203152. updateHiddenTextContent (target);
  203153. }
  203154. return NO;
  203155. }
  203156. BOOL UIViewComponentPeer::textFieldShouldClear()
  203157. {
  203158. TextInputTarget* const target = findCurrentTextInputTarget();
  203159. if (target != 0)
  203160. {
  203161. target->setHighlightedRegion (Range<int> (0, std::numeric_limits<int>::max()));
  203162. target->insertTextAtCaret (String::empty);
  203163. updateHiddenTextContent (target);
  203164. }
  203165. return YES;
  203166. }
  203167. BOOL UIViewComponentPeer::textFieldShouldReturn()
  203168. {
  203169. TextInputTarget* const target = findCurrentTextInputTarget();
  203170. if (target != 0)
  203171. {
  203172. target->insertTextAtCaret ("\n");
  203173. updateHiddenTextContent (target);
  203174. }
  203175. return YES;
  203176. }
  203177. void UIViewComponentPeer::globalFocusChanged (Component*)
  203178. {
  203179. TextInputTarget* const target = findCurrentTextInputTarget();
  203180. if (target != 0)
  203181. {
  203182. Component* comp = dynamic_cast<Component*> (target);
  203183. Point<int> pos (comp->relativePositionToOtherComponent (component, Point<int>()));
  203184. view->hiddenTextField.frame = CGRectMake (pos.getX(), pos.getY(), 0, 0);
  203185. updateHiddenTextContent (target);
  203186. [view->hiddenTextField becomeFirstResponder];
  203187. }
  203188. else
  203189. {
  203190. [view->hiddenTextField resignFirstResponder];
  203191. }
  203192. }
  203193. void UIViewComponentPeer::drawRect (CGRect r)
  203194. {
  203195. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203196. return;
  203197. CGContextRef cg = UIGraphicsGetCurrentContext();
  203198. if (! component->isOpaque())
  203199. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203200. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203201. CoreGraphicsContext g (cg, view.bounds.size.height);
  203202. insideDrawRect = true;
  203203. handlePaint (g);
  203204. insideDrawRect = false;
  203205. }
  203206. bool UIViewComponentPeer::canBecomeKeyWindow()
  203207. {
  203208. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203209. }
  203210. bool UIViewComponentPeer::windowShouldClose()
  203211. {
  203212. if (! isValidPeer (this))
  203213. return YES;
  203214. handleUserClosingWindow();
  203215. return NO;
  203216. }
  203217. void UIViewComponentPeer::redirectMovedOrResized()
  203218. {
  203219. handleMovedOrResized();
  203220. }
  203221. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203222. {
  203223. }
  203224. class AsyncRepaintMessage : public CallbackMessage
  203225. {
  203226. public:
  203227. UIViewComponentPeer* const peer;
  203228. const Rectangle<int> rect;
  203229. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203230. : peer (peer_), rect (rect_)
  203231. {
  203232. }
  203233. void messageCallback()
  203234. {
  203235. if (ComponentPeer::isValidPeer (peer))
  203236. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203237. }
  203238. };
  203239. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203240. {
  203241. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203242. {
  203243. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203244. }
  203245. else
  203246. {
  203247. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203248. }
  203249. }
  203250. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203251. {
  203252. }
  203253. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203254. {
  203255. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203256. }
  203257. Image* juce_createIconForFile (const File& file)
  203258. {
  203259. return 0;
  203260. }
  203261. void Desktop::createMouseInputSources()
  203262. {
  203263. for (int i = 0; i < 10; ++i)
  203264. mouseSources.add (new MouseInputSource (i, false));
  203265. }
  203266. bool Desktop::canUseSemiTransparentWindows() throw()
  203267. {
  203268. return true;
  203269. }
  203270. const Point<int> Desktop::getMousePosition()
  203271. {
  203272. return juce_lastMousePos;
  203273. }
  203274. void Desktop::setMousePosition (const Point<int>&)
  203275. {
  203276. }
  203277. const int KeyPress::spaceKey = ' ';
  203278. const int KeyPress::returnKey = 0x0d;
  203279. const int KeyPress::escapeKey = 0x1b;
  203280. const int KeyPress::backspaceKey = 0x7f;
  203281. const int KeyPress::leftKey = 0x1000;
  203282. const int KeyPress::rightKey = 0x1001;
  203283. const int KeyPress::upKey = 0x1002;
  203284. const int KeyPress::downKey = 0x1003;
  203285. const int KeyPress::pageUpKey = 0x1004;
  203286. const int KeyPress::pageDownKey = 0x1005;
  203287. const int KeyPress::endKey = 0x1006;
  203288. const int KeyPress::homeKey = 0x1007;
  203289. const int KeyPress::deleteKey = 0x1008;
  203290. const int KeyPress::insertKey = -1;
  203291. const int KeyPress::tabKey = 9;
  203292. const int KeyPress::F1Key = 0x2001;
  203293. const int KeyPress::F2Key = 0x2002;
  203294. const int KeyPress::F3Key = 0x2003;
  203295. const int KeyPress::F4Key = 0x2004;
  203296. const int KeyPress::F5Key = 0x2005;
  203297. const int KeyPress::F6Key = 0x2006;
  203298. const int KeyPress::F7Key = 0x2007;
  203299. const int KeyPress::F8Key = 0x2008;
  203300. const int KeyPress::F9Key = 0x2009;
  203301. const int KeyPress::F10Key = 0x200a;
  203302. const int KeyPress::F11Key = 0x200b;
  203303. const int KeyPress::F12Key = 0x200c;
  203304. const int KeyPress::F13Key = 0x200d;
  203305. const int KeyPress::F14Key = 0x200e;
  203306. const int KeyPress::F15Key = 0x200f;
  203307. const int KeyPress::F16Key = 0x2010;
  203308. const int KeyPress::numberPad0 = 0x30020;
  203309. const int KeyPress::numberPad1 = 0x30021;
  203310. const int KeyPress::numberPad2 = 0x30022;
  203311. const int KeyPress::numberPad3 = 0x30023;
  203312. const int KeyPress::numberPad4 = 0x30024;
  203313. const int KeyPress::numberPad5 = 0x30025;
  203314. const int KeyPress::numberPad6 = 0x30026;
  203315. const int KeyPress::numberPad7 = 0x30027;
  203316. const int KeyPress::numberPad8 = 0x30028;
  203317. const int KeyPress::numberPad9 = 0x30029;
  203318. const int KeyPress::numberPadAdd = 0x3002a;
  203319. const int KeyPress::numberPadSubtract = 0x3002b;
  203320. const int KeyPress::numberPadMultiply = 0x3002c;
  203321. const int KeyPress::numberPadDivide = 0x3002d;
  203322. const int KeyPress::numberPadSeparator = 0x3002e;
  203323. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203324. const int KeyPress::numberPadEquals = 0x30030;
  203325. const int KeyPress::numberPadDelete = 0x30031;
  203326. const int KeyPress::playKey = 0x30000;
  203327. const int KeyPress::stopKey = 0x30001;
  203328. const int KeyPress::fastForwardKey = 0x30002;
  203329. const int KeyPress::rewindKey = 0x30003;
  203330. #endif
  203331. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203332. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203333. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203334. // compiled on its own).
  203335. #if JUCE_INCLUDED_FILE
  203336. struct CallbackMessagePayload
  203337. {
  203338. MessageCallbackFunction* function;
  203339. void* parameter;
  203340. void* volatile result;
  203341. bool volatile hasBeenExecuted;
  203342. };
  203343. END_JUCE_NAMESPACE
  203344. using namespace JUCE_NAMESPACE;
  203345. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203346. {
  203347. }
  203348. - (JuceAppDelegate*) init;
  203349. - (void) dealloc;
  203350. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203351. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203352. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203353. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203354. - (void) customEvent: (id) data;
  203355. - (void) performCallback: (id) info;
  203356. @end
  203357. @implementation JuceAppDelegate
  203358. - (JuceAppDelegate*) init
  203359. {
  203360. [super init];
  203361. [[UIApplication sharedApplication] setDelegate: self];
  203362. return self;
  203363. }
  203364. - (void) dealloc
  203365. {
  203366. [[UIApplication sharedApplication] setDelegate: nil];
  203367. [super dealloc];
  203368. }
  203369. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203370. {
  203371. if (JUCEApplication::getInstance() != 0)
  203372. {
  203373. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203374. return YES;
  203375. }
  203376. return NO;
  203377. }
  203378. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203379. {
  203380. juce_HandleProcessFocusChange();
  203381. }
  203382. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203383. {
  203384. juce_HandleProcessFocusChange();
  203385. }
  203386. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203387. {
  203388. juce_HandleProcessFocusChange();
  203389. }
  203390. - (void) customEvent: (id) n
  203391. {
  203392. NSData* data = (NSData*) n;
  203393. void* message = 0;
  203394. [data getBytes: &message length: sizeof (message)];
  203395. [data release];
  203396. if (message != 0)
  203397. MessageManager::getInstance()->deliverMessage (message);
  203398. }
  203399. - (void) performCallback: (id) info
  203400. {
  203401. if ([info isKindOfClass: [NSData class]])
  203402. {
  203403. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203404. if (pl != 0)
  203405. {
  203406. pl->result = (*pl->function) (pl->parameter);
  203407. pl->hasBeenExecuted = true;
  203408. }
  203409. }
  203410. else
  203411. {
  203412. jassertfalse // should never get here!
  203413. }
  203414. }
  203415. @end
  203416. BEGIN_JUCE_NAMESPACE
  203417. static JuceAppDelegate* juceAppDelegate = 0;
  203418. void MessageManager::runDispatchLoop()
  203419. {
  203420. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203421. runDispatchLoopUntil (-1);
  203422. }
  203423. void MessageManager::stopDispatchLoop()
  203424. {
  203425. exit (0); // iPhone apps get no mercy..
  203426. }
  203427. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203428. {
  203429. const ScopedAutoReleasePool pool;
  203430. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203431. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203432. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203433. while (! quitMessagePosted)
  203434. {
  203435. const ScopedAutoReleasePool pool;
  203436. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203437. beforeDate: endDate];
  203438. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203439. break;
  203440. }
  203441. return ! quitMessagePosted;
  203442. }
  203443. static CFRunLoopRef runLoop = 0;
  203444. static CFRunLoopSourceRef runLoopSource = 0;
  203445. static Array <void*, CriticalSection>* pendingMessages = 0;
  203446. static void runLoopSourceCallback (void*)
  203447. {
  203448. if (pendingMessages != 0)
  203449. {
  203450. int numDispatched = 0;
  203451. do
  203452. {
  203453. void* const nextMessage = pendingMessages->remove (0);
  203454. if (nextMessage == 0)
  203455. return;
  203456. const ScopedAutoReleasePool pool;
  203457. MessageManager::getInstance()->deliverMessage (nextMessage);
  203458. } while (++numDispatched <= 4);
  203459. CFRunLoopSourceSignal (runLoopSource);
  203460. CFRunLoopWakeUp (runLoop);
  203461. }
  203462. }
  203463. void MessageManager::doPlatformSpecificInitialisation()
  203464. {
  203465. pendingMessages = new Array <void*, CriticalSection>();
  203466. runLoop = CFRunLoopGetCurrent();
  203467. CFRunLoopSourceContext sourceContext;
  203468. zerostruct (sourceContext);
  203469. sourceContext.perform = runLoopSourceCallback;
  203470. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203471. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203472. if (juceAppDelegate == 0)
  203473. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203474. }
  203475. void MessageManager::doPlatformSpecificShutdown()
  203476. {
  203477. CFRunLoopSourceInvalidate (runLoopSource);
  203478. CFRelease (runLoopSource);
  203479. runLoopSource = 0;
  203480. if (pendingMessages != 0)
  203481. {
  203482. while (pendingMessages->size() > 0)
  203483. delete ((Message*) pendingMessages->remove(0));
  203484. deleteAndZero (pendingMessages);
  203485. }
  203486. if (juceAppDelegate != 0)
  203487. {
  203488. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203489. [juceAppDelegate release];
  203490. juceAppDelegate = 0;
  203491. }
  203492. }
  203493. bool juce_postMessageToSystemQueue (void* message)
  203494. {
  203495. if (pendingMessages != 0)
  203496. {
  203497. pendingMessages->add (message);
  203498. CFRunLoopSourceSignal (runLoopSource);
  203499. CFRunLoopWakeUp (runLoop);
  203500. }
  203501. return true;
  203502. }
  203503. void MessageManager::broadcastMessage (const String& value) throw()
  203504. {
  203505. }
  203506. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203507. void* data)
  203508. {
  203509. if (isThisTheMessageThread())
  203510. {
  203511. return (*callback) (data);
  203512. }
  203513. else
  203514. {
  203515. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203516. // deadlock because the message manager is blocked from running, so can never
  203517. // call your function..
  203518. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203519. const ScopedAutoReleasePool pool;
  203520. CallbackMessagePayload cmp;
  203521. cmp.function = callback;
  203522. cmp.parameter = data;
  203523. cmp.result = 0;
  203524. cmp.hasBeenExecuted = false;
  203525. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203526. withObject: [NSData dataWithBytesNoCopy: &cmp
  203527. length: sizeof (cmp)
  203528. freeWhenDone: NO]
  203529. waitUntilDone: YES];
  203530. return cmp.result;
  203531. }
  203532. }
  203533. #endif
  203534. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203535. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203536. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203537. // compiled on its own).
  203538. #if JUCE_INCLUDED_FILE
  203539. #if JUCE_MAC
  203540. END_JUCE_NAMESPACE
  203541. using namespace JUCE_NAMESPACE;
  203542. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203543. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203544. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203545. #else
  203546. @interface JuceFileChooserDelegate : NSObject
  203547. #endif
  203548. {
  203549. StringArray* filters;
  203550. }
  203551. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203552. - (void) dealloc;
  203553. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203554. @end
  203555. @implementation JuceFileChooserDelegate
  203556. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203557. {
  203558. [super init];
  203559. filters = filters_;
  203560. return self;
  203561. }
  203562. - (void) dealloc
  203563. {
  203564. delete filters;
  203565. [super dealloc];
  203566. }
  203567. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203568. {
  203569. const File f (nsStringToJuce (filename));
  203570. for (int i = filters->size(); --i >= 0;)
  203571. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203572. return true;
  203573. return f.isDirectory();
  203574. }
  203575. @end
  203576. BEGIN_JUCE_NAMESPACE
  203577. void FileChooser::showPlatformDialog (Array<File>& results,
  203578. const String& title,
  203579. const File& currentFileOrDirectory,
  203580. const String& filter,
  203581. bool selectsDirectory,
  203582. bool selectsFiles,
  203583. bool isSaveDialogue,
  203584. bool warnAboutOverwritingExistingFiles,
  203585. bool selectMultipleFiles,
  203586. FilePreviewComponent* extraInfoComponent)
  203587. {
  203588. const ScopedAutoReleasePool pool;
  203589. StringArray* filters = new StringArray();
  203590. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  203591. filters->trim();
  203592. filters->removeEmptyStrings();
  203593. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203594. [delegate autorelease];
  203595. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203596. : [NSOpenPanel openPanel];
  203597. [panel setTitle: juceStringToNS (title)];
  203598. if (! isSaveDialogue)
  203599. {
  203600. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203601. [openPanel setCanChooseDirectories: selectsDirectory];
  203602. [openPanel setCanChooseFiles: selectsFiles];
  203603. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203604. }
  203605. [panel setDelegate: delegate];
  203606. if (isSaveDialogue || selectsDirectory)
  203607. [panel setCanCreateDirectories: YES];
  203608. String directory, filename;
  203609. if (currentFileOrDirectory.isDirectory())
  203610. {
  203611. directory = currentFileOrDirectory.getFullPathName();
  203612. }
  203613. else
  203614. {
  203615. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203616. filename = currentFileOrDirectory.getFileName();
  203617. }
  203618. if ([panel runModalForDirectory: juceStringToNS (directory)
  203619. file: juceStringToNS (filename)]
  203620. == NSOKButton)
  203621. {
  203622. if (isSaveDialogue)
  203623. {
  203624. results.add (File (nsStringToJuce ([panel filename])));
  203625. }
  203626. else
  203627. {
  203628. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203629. NSArray* urls = [openPanel filenames];
  203630. for (unsigned int i = 0; i < [urls count]; ++i)
  203631. {
  203632. NSString* f = [urls objectAtIndex: i];
  203633. results.add (File (nsStringToJuce (f)));
  203634. }
  203635. }
  203636. }
  203637. [panel setDelegate: nil];
  203638. }
  203639. #else
  203640. void FileChooser::showPlatformDialog (Array<File>& results,
  203641. const String& title,
  203642. const File& currentFileOrDirectory,
  203643. const String& filter,
  203644. bool selectsDirectory,
  203645. bool selectsFiles,
  203646. bool isSaveDialogue,
  203647. bool warnAboutOverwritingExistingFiles,
  203648. bool selectMultipleFiles,
  203649. FilePreviewComponent* extraInfoComponent)
  203650. {
  203651. const ScopedAutoReleasePool pool;
  203652. jassertfalse //xxx to do
  203653. }
  203654. #endif
  203655. #endif
  203656. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203657. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203658. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203659. // compiled on its own).
  203660. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203661. #if JUCE_MAC
  203662. END_JUCE_NAMESPACE
  203663. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203664. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203665. {
  203666. CriticalSection* contextLock;
  203667. bool needsUpdate;
  203668. }
  203669. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203670. - (bool) makeActive;
  203671. - (void) makeInactive;
  203672. - (void) reshape;
  203673. @end
  203674. @implementation ThreadSafeNSOpenGLView
  203675. - (id) initWithFrame: (NSRect) frameRect
  203676. pixelFormat: (NSOpenGLPixelFormat*) format
  203677. {
  203678. contextLock = new CriticalSection();
  203679. self = [super initWithFrame: frameRect pixelFormat: format];
  203680. if (self != nil)
  203681. [[NSNotificationCenter defaultCenter] addObserver: self
  203682. selector: @selector (_surfaceNeedsUpdate:)
  203683. name: NSViewGlobalFrameDidChangeNotification
  203684. object: self];
  203685. return self;
  203686. }
  203687. - (void) dealloc
  203688. {
  203689. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203690. delete contextLock;
  203691. [super dealloc];
  203692. }
  203693. - (bool) makeActive
  203694. {
  203695. const ScopedLock sl (*contextLock);
  203696. if ([self openGLContext] == 0)
  203697. return false;
  203698. [[self openGLContext] makeCurrentContext];
  203699. if (needsUpdate)
  203700. {
  203701. [super update];
  203702. needsUpdate = false;
  203703. }
  203704. return true;
  203705. }
  203706. - (void) makeInactive
  203707. {
  203708. const ScopedLock sl (*contextLock);
  203709. [NSOpenGLContext clearCurrentContext];
  203710. }
  203711. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203712. {
  203713. const ScopedLock sl (*contextLock);
  203714. needsUpdate = true;
  203715. }
  203716. - (void) update
  203717. {
  203718. const ScopedLock sl (*contextLock);
  203719. needsUpdate = true;
  203720. }
  203721. - (void) reshape
  203722. {
  203723. const ScopedLock sl (*contextLock);
  203724. needsUpdate = true;
  203725. }
  203726. @end
  203727. BEGIN_JUCE_NAMESPACE
  203728. class WindowedGLContext : public OpenGLContext
  203729. {
  203730. public:
  203731. WindowedGLContext (Component* const component,
  203732. const OpenGLPixelFormat& pixelFormat_,
  203733. NSOpenGLContext* sharedContext)
  203734. : renderContext (0),
  203735. pixelFormat (pixelFormat_)
  203736. {
  203737. jassert (component != 0);
  203738. NSOpenGLPixelFormatAttribute attribs [64];
  203739. int n = 0;
  203740. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203741. attribs[n++] = NSOpenGLPFAAccelerated;
  203742. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203743. attribs[n++] = NSOpenGLPFAColorSize;
  203744. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203745. pixelFormat.greenBits,
  203746. pixelFormat.blueBits);
  203747. attribs[n++] = NSOpenGLPFAAlphaSize;
  203748. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203749. attribs[n++] = NSOpenGLPFADepthSize;
  203750. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203751. attribs[n++] = NSOpenGLPFAStencilSize;
  203752. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203753. attribs[n++] = NSOpenGLPFAAccumSize;
  203754. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203755. pixelFormat.accumulationBufferGreenBits,
  203756. pixelFormat.accumulationBufferBlueBits,
  203757. pixelFormat.accumulationBufferAlphaBits);
  203758. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203759. attribs[n++] = NSOpenGLPFASampleBuffers;
  203760. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203761. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203762. attribs[n++] = NSOpenGLPFANoRecovery;
  203763. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203764. NSOpenGLPixelFormat* format
  203765. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203766. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203767. pixelFormat: format];
  203768. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203769. shareContext: sharedContext] autorelease];
  203770. const GLint swapInterval = 1;
  203771. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203772. [view setOpenGLContext: renderContext];
  203773. [renderContext setView: view];
  203774. [format release];
  203775. viewHolder = new NSViewComponentInternal (view, component);
  203776. }
  203777. ~WindowedGLContext()
  203778. {
  203779. makeInactive();
  203780. [renderContext clearDrawable];
  203781. viewHolder = 0;
  203782. }
  203783. bool makeActive() const throw()
  203784. {
  203785. jassert (renderContext != 0);
  203786. [view makeActive];
  203787. return isActive();
  203788. }
  203789. bool makeInactive() const throw()
  203790. {
  203791. [view makeInactive];
  203792. return true;
  203793. }
  203794. bool isActive() const throw()
  203795. {
  203796. return [NSOpenGLContext currentContext] == renderContext;
  203797. }
  203798. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203799. void* getRawContext() const throw() { return renderContext; }
  203800. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203801. {
  203802. }
  203803. void swapBuffers()
  203804. {
  203805. [renderContext flushBuffer];
  203806. }
  203807. bool setSwapInterval (const int numFramesPerSwap)
  203808. {
  203809. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203810. forParameter: NSOpenGLCPSwapInterval];
  203811. return true;
  203812. }
  203813. int getSwapInterval() const
  203814. {
  203815. GLint numFrames = 0;
  203816. [renderContext getValues: &numFrames
  203817. forParameter: NSOpenGLCPSwapInterval];
  203818. return numFrames;
  203819. }
  203820. void repaint()
  203821. {
  203822. // we need to invalidate the juce view that holds this gl view, to make it
  203823. // cause a repaint callback
  203824. NSView* v = (NSView*) viewHolder->view;
  203825. NSRect r = [v frame];
  203826. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203827. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203828. // repaint message, thus never causing our paint() callback, and never repainting
  203829. // the comp. So invalidating just a little bit around the edge helps..
  203830. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203831. }
  203832. void* getNativeWindowHandle() const { return viewHolder->view; }
  203833. juce_UseDebuggingNewOperator
  203834. NSOpenGLContext* renderContext;
  203835. ThreadSafeNSOpenGLView* view;
  203836. private:
  203837. OpenGLPixelFormat pixelFormat;
  203838. ScopedPointer <NSViewComponentInternal> viewHolder;
  203839. WindowedGLContext (const WindowedGLContext&);
  203840. WindowedGLContext& operator= (const WindowedGLContext&);
  203841. };
  203842. OpenGLContext* OpenGLComponent::createContext()
  203843. {
  203844. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  203845. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  203846. return (c->renderContext != 0) ? c.release() : 0;
  203847. }
  203848. void* OpenGLComponent::getNativeWindowHandle() const
  203849. {
  203850. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  203851. : 0;
  203852. }
  203853. void juce_glViewport (const int w, const int h)
  203854. {
  203855. glViewport (0, 0, w, h);
  203856. }
  203857. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203858. OwnedArray <OpenGLPixelFormat>& results)
  203859. {
  203860. /* GLint attribs [64];
  203861. int n = 0;
  203862. attribs[n++] = AGL_RGBA;
  203863. attribs[n++] = AGL_DOUBLEBUFFER;
  203864. attribs[n++] = AGL_ACCELERATED;
  203865. attribs[n++] = AGL_NO_RECOVERY;
  203866. attribs[n++] = AGL_NONE;
  203867. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203868. while (p != 0)
  203869. {
  203870. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203871. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203872. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203873. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203874. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203875. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203876. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203877. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203878. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203879. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203880. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203881. results.add (pf);
  203882. p = aglNextPixelFormat (p);
  203883. }*/
  203884. //jassertfalse //xxx can't see how you do this in cocoa!
  203885. }
  203886. #else
  203887. END_JUCE_NAMESPACE
  203888. @interface JuceGLView : UIView
  203889. {
  203890. }
  203891. + (Class) layerClass;
  203892. @end
  203893. @implementation JuceGLView
  203894. + (Class) layerClass
  203895. {
  203896. return [CAEAGLLayer class];
  203897. }
  203898. @end
  203899. BEGIN_JUCE_NAMESPACE
  203900. class GLESContext : public OpenGLContext
  203901. {
  203902. public:
  203903. GLESContext (UIViewComponentPeer* peer,
  203904. Component* const component_,
  203905. const OpenGLPixelFormat& pixelFormat_,
  203906. const GLESContext* const sharedContext,
  203907. NSUInteger apiType)
  203908. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  203909. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  203910. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  203911. {
  203912. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  203913. view.opaque = YES;
  203914. view.hidden = NO;
  203915. view.backgroundColor = [UIColor blackColor];
  203916. view.userInteractionEnabled = NO;
  203917. glLayer = (CAEAGLLayer*) [view layer];
  203918. [peer->view addSubview: view];
  203919. if (sharedContext != 0)
  203920. context = [[EAGLContext alloc] initWithAPI: apiType
  203921. sharegroup: [sharedContext->context sharegroup]];
  203922. else
  203923. context = [[EAGLContext alloc] initWithAPI: apiType];
  203924. createGLBuffers();
  203925. }
  203926. ~GLESContext()
  203927. {
  203928. makeInactive();
  203929. [context release];
  203930. [view removeFromSuperview];
  203931. [view release];
  203932. freeGLBuffers();
  203933. }
  203934. bool makeActive() const throw()
  203935. {
  203936. jassert (context != 0);
  203937. [EAGLContext setCurrentContext: context];
  203938. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203939. return true;
  203940. }
  203941. void swapBuffers()
  203942. {
  203943. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203944. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  203945. }
  203946. bool makeInactive() const throw()
  203947. {
  203948. return [EAGLContext setCurrentContext: nil];
  203949. }
  203950. bool isActive() const throw()
  203951. {
  203952. return [EAGLContext currentContext] == context;
  203953. }
  203954. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203955. void* getRawContext() const throw() { return (void*) glLayer; }
  203956. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203957. {
  203958. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  203959. if (lastWidth != w || lastHeight != h)
  203960. {
  203961. lastWidth = w;
  203962. lastHeight = h;
  203963. freeGLBuffers();
  203964. createGLBuffers();
  203965. }
  203966. }
  203967. bool setSwapInterval (const int numFramesPerSwap)
  203968. {
  203969. numFrames = numFramesPerSwap;
  203970. return true;
  203971. }
  203972. int getSwapInterval() const
  203973. {
  203974. return numFrames;
  203975. }
  203976. void repaint()
  203977. {
  203978. }
  203979. void createGLBuffers()
  203980. {
  203981. makeActive();
  203982. glGenFramebuffersOES (1, &frameBufferHandle);
  203983. glGenRenderbuffersOES (1, &colorBufferHandle);
  203984. glGenRenderbuffersOES (1, &depthBufferHandle);
  203985. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203986. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  203987. GLint width, height;
  203988. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  203989. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  203990. if (useDepthBuffer)
  203991. {
  203992. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  203993. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  203994. }
  203995. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203996. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203997. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  203998. if (useDepthBuffer)
  203999. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  204000. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  204001. }
  204002. void freeGLBuffers()
  204003. {
  204004. if (frameBufferHandle != 0)
  204005. {
  204006. glDeleteFramebuffersOES (1, &frameBufferHandle);
  204007. frameBufferHandle = 0;
  204008. }
  204009. if (colorBufferHandle != 0)
  204010. {
  204011. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  204012. colorBufferHandle = 0;
  204013. }
  204014. if (depthBufferHandle != 0)
  204015. {
  204016. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  204017. depthBufferHandle = 0;
  204018. }
  204019. }
  204020. juce_UseDebuggingNewOperator
  204021. private:
  204022. Component::SafePointer<Component> component;
  204023. OpenGLPixelFormat pixelFormat;
  204024. JuceGLView* view;
  204025. CAEAGLLayer* glLayer;
  204026. EAGLContext* context;
  204027. bool useDepthBuffer;
  204028. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  204029. int numFrames;
  204030. int lastWidth, lastHeight;
  204031. GLESContext (const GLESContext&);
  204032. GLESContext& operator= (const GLESContext&);
  204033. };
  204034. OpenGLContext* OpenGLComponent::createContext()
  204035. {
  204036. ScopedAutoReleasePool pool;
  204037. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  204038. if (peer != 0)
  204039. return new GLESContext (peer, this, preferredPixelFormat,
  204040. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  204041. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  204042. return 0;
  204043. }
  204044. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204045. OwnedArray <OpenGLPixelFormat>& /*results*/)
  204046. {
  204047. }
  204048. void juce_glViewport (const int w, const int h)
  204049. {
  204050. glViewport (0, 0, w, h);
  204051. }
  204052. #endif
  204053. #endif
  204054. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204055. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204056. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204057. // compiled on its own).
  204058. #if JUCE_INCLUDED_FILE
  204059. #if JUCE_MAC
  204060. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  204061. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204062. {
  204063. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204064. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204065. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204066. [im release];
  204067. return (void*) c;
  204068. }
  204069. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204070. {
  204071. MemoryInputStream stream (data, size, false);
  204072. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  204073. jassert (im != 0);
  204074. if (im == 0)
  204075. return 0;
  204076. return juce_createMouseCursorFromImage (*im,
  204077. (int) (hx * im->getWidth()),
  204078. (int) (hy * im->getHeight()));
  204079. }
  204080. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204081. {
  204082. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204083. MemoryBlock mb;
  204084. if (f.getChildFile (filename).loadFileAsData (mb))
  204085. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204086. return 0;
  204087. }
  204088. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204089. {
  204090. const ScopedAutoReleasePool pool;
  204091. NSCursor* c = 0;
  204092. switch (type)
  204093. {
  204094. case MouseCursor::NormalCursor:
  204095. c = [NSCursor arrowCursor];
  204096. break;
  204097. case MouseCursor::NoCursor:
  204098. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  204099. case MouseCursor::DraggingHandCursor:
  204100. c = [NSCursor openHandCursor];
  204101. break;
  204102. case MouseCursor::CopyingCursor:
  204103. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204104. case MouseCursor::WaitCursor:
  204105. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204106. break;
  204107. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204108. case MouseCursor::IBeamCursor:
  204109. c = [NSCursor IBeamCursor];
  204110. break;
  204111. case MouseCursor::PointingHandCursor:
  204112. c = [NSCursor pointingHandCursor];
  204113. break;
  204114. case MouseCursor::LeftRightResizeCursor:
  204115. c = [NSCursor resizeLeftRightCursor];
  204116. break;
  204117. case MouseCursor::LeftEdgeResizeCursor:
  204118. c = [NSCursor resizeLeftCursor];
  204119. break;
  204120. case MouseCursor::RightEdgeResizeCursor:
  204121. c = [NSCursor resizeRightCursor];
  204122. break;
  204123. case MouseCursor::UpDownResizeCursor:
  204124. case MouseCursor::TopEdgeResizeCursor:
  204125. case MouseCursor::BottomEdgeResizeCursor:
  204126. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204127. case MouseCursor::TopLeftCornerResizeCursor:
  204128. case MouseCursor::BottomRightCornerResizeCursor:
  204129. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204130. case MouseCursor::TopRightCornerResizeCursor:
  204131. case MouseCursor::BottomLeftCornerResizeCursor:
  204132. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204133. case MouseCursor::UpDownLeftRightResizeCursor:
  204134. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204135. case MouseCursor::CrosshairCursor:
  204136. c = [NSCursor crosshairCursor];
  204137. break;
  204138. }
  204139. [c retain];
  204140. return (void*) c;
  204141. }
  204142. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204143. {
  204144. NSCursor* c = (NSCursor*) cursorHandle;
  204145. [c release];
  204146. }
  204147. void MouseCursor::showInAllWindows() const throw()
  204148. {
  204149. showInWindow (0);
  204150. }
  204151. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204152. {
  204153. NSCursor* const c = (NSCursor*) getHandle();
  204154. [c set];
  204155. }
  204156. #else
  204157. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204158. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204159. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204160. void MouseCursor::showInAllWindows() const throw() {}
  204161. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204162. #endif
  204163. #endif
  204164. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204165. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204166. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204167. // compiled on its own).
  204168. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204169. #if JUCE_MAC
  204170. END_JUCE_NAMESPACE
  204171. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204172. @interface DownloadClickDetector : NSObject
  204173. {
  204174. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204175. }
  204176. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204177. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204178. request: (NSURLRequest*) request
  204179. frame: (WebFrame*) frame
  204180. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204181. @end
  204182. @implementation DownloadClickDetector
  204183. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204184. {
  204185. [super init];
  204186. ownerComponent = ownerComponent_;
  204187. return self;
  204188. }
  204189. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204190. request: (NSURLRequest*) request
  204191. frame: (WebFrame*) frame
  204192. decisionListener: (id <WebPolicyDecisionListener>) listener
  204193. {
  204194. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204195. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204196. [listener use];
  204197. else
  204198. [listener ignore];
  204199. }
  204200. @end
  204201. BEGIN_JUCE_NAMESPACE
  204202. class WebBrowserComponentInternal : public NSViewComponent
  204203. {
  204204. public:
  204205. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204206. {
  204207. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204208. frameName: @""
  204209. groupName: @""];
  204210. setView (webView);
  204211. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204212. [webView setPolicyDelegate: clickListener];
  204213. }
  204214. ~WebBrowserComponentInternal()
  204215. {
  204216. [webView setPolicyDelegate: nil];
  204217. [clickListener release];
  204218. setView (0);
  204219. }
  204220. void goToURL (const String& url,
  204221. const StringArray* headers,
  204222. const MemoryBlock* postData)
  204223. {
  204224. NSMutableURLRequest* r
  204225. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204226. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204227. timeoutInterval: 30.0];
  204228. if (postData != 0 && postData->getSize() > 0)
  204229. {
  204230. [r setHTTPMethod: @"POST"];
  204231. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204232. length: postData->getSize()]];
  204233. }
  204234. if (headers != 0)
  204235. {
  204236. for (int i = 0; i < headers->size(); ++i)
  204237. {
  204238. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  204239. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  204240. [r setValue: juceStringToNS (headerValue)
  204241. forHTTPHeaderField: juceStringToNS (headerName)];
  204242. }
  204243. }
  204244. stop();
  204245. [[webView mainFrame] loadRequest: r];
  204246. }
  204247. void goBack()
  204248. {
  204249. [webView goBack];
  204250. }
  204251. void goForward()
  204252. {
  204253. [webView goForward];
  204254. }
  204255. void stop()
  204256. {
  204257. [webView stopLoading: nil];
  204258. }
  204259. void refresh()
  204260. {
  204261. [webView reload: nil];
  204262. }
  204263. private:
  204264. WebView* webView;
  204265. DownloadClickDetector* clickListener;
  204266. };
  204267. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204268. : browser (0),
  204269. blankPageShown (false),
  204270. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204271. {
  204272. setOpaque (true);
  204273. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204274. }
  204275. WebBrowserComponent::~WebBrowserComponent()
  204276. {
  204277. deleteAndZero (browser);
  204278. }
  204279. void WebBrowserComponent::goToURL (const String& url,
  204280. const StringArray* headers,
  204281. const MemoryBlock* postData)
  204282. {
  204283. lastURL = url;
  204284. lastHeaders.clear();
  204285. if (headers != 0)
  204286. lastHeaders = *headers;
  204287. lastPostData.setSize (0);
  204288. if (postData != 0)
  204289. lastPostData = *postData;
  204290. blankPageShown = false;
  204291. browser->goToURL (url, headers, postData);
  204292. }
  204293. void WebBrowserComponent::stop()
  204294. {
  204295. browser->stop();
  204296. }
  204297. void WebBrowserComponent::goBack()
  204298. {
  204299. lastURL = String::empty;
  204300. blankPageShown = false;
  204301. browser->goBack();
  204302. }
  204303. void WebBrowserComponent::goForward()
  204304. {
  204305. lastURL = String::empty;
  204306. browser->goForward();
  204307. }
  204308. void WebBrowserComponent::refresh()
  204309. {
  204310. browser->refresh();
  204311. }
  204312. void WebBrowserComponent::paint (Graphics& g)
  204313. {
  204314. }
  204315. void WebBrowserComponent::checkWindowAssociation()
  204316. {
  204317. if (isShowing())
  204318. {
  204319. if (blankPageShown)
  204320. goBack();
  204321. }
  204322. else
  204323. {
  204324. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204325. {
  204326. // when the component becomes invisible, some stuff like flash
  204327. // carries on playing audio, so we need to force it onto a blank
  204328. // page to avoid this, (and send it back when it's made visible again).
  204329. blankPageShown = true;
  204330. browser->goToURL ("about:blank", 0, 0);
  204331. }
  204332. }
  204333. }
  204334. void WebBrowserComponent::reloadLastURL()
  204335. {
  204336. if (lastURL.isNotEmpty())
  204337. {
  204338. goToURL (lastURL, &lastHeaders, &lastPostData);
  204339. lastURL = String::empty;
  204340. }
  204341. }
  204342. void WebBrowserComponent::parentHierarchyChanged()
  204343. {
  204344. checkWindowAssociation();
  204345. }
  204346. void WebBrowserComponent::resized()
  204347. {
  204348. browser->setSize (getWidth(), getHeight());
  204349. }
  204350. void WebBrowserComponent::visibilityChanged()
  204351. {
  204352. checkWindowAssociation();
  204353. }
  204354. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204355. {
  204356. return true;
  204357. }
  204358. #else
  204359. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204360. {
  204361. }
  204362. WebBrowserComponent::~WebBrowserComponent()
  204363. {
  204364. }
  204365. void WebBrowserComponent::goToURL (const String& url,
  204366. const StringArray* headers,
  204367. const MemoryBlock* postData)
  204368. {
  204369. }
  204370. void WebBrowserComponent::stop()
  204371. {
  204372. }
  204373. void WebBrowserComponent::goBack()
  204374. {
  204375. }
  204376. void WebBrowserComponent::goForward()
  204377. {
  204378. }
  204379. void WebBrowserComponent::refresh()
  204380. {
  204381. }
  204382. void WebBrowserComponent::paint (Graphics& g)
  204383. {
  204384. }
  204385. void WebBrowserComponent::checkWindowAssociation()
  204386. {
  204387. }
  204388. void WebBrowserComponent::reloadLastURL()
  204389. {
  204390. }
  204391. void WebBrowserComponent::parentHierarchyChanged()
  204392. {
  204393. }
  204394. void WebBrowserComponent::resized()
  204395. {
  204396. }
  204397. void WebBrowserComponent::visibilityChanged()
  204398. {
  204399. }
  204400. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204401. {
  204402. return true;
  204403. }
  204404. #endif
  204405. #endif
  204406. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204407. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204408. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204409. // compiled on its own).
  204410. #if JUCE_INCLUDED_FILE
  204411. class IPhoneAudioIODevice : public AudioIODevice
  204412. {
  204413. public:
  204414. IPhoneAudioIODevice (const String& deviceName)
  204415. : AudioIODevice (deviceName, "Audio"),
  204416. audioUnit (0),
  204417. isRunning (false),
  204418. callback (0),
  204419. actualBufferSize (0),
  204420. floatData (1, 2)
  204421. {
  204422. numInputChannels = 2;
  204423. numOutputChannels = 2;
  204424. preferredBufferSize = 0;
  204425. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204426. updateDeviceInfo();
  204427. }
  204428. ~IPhoneAudioIODevice()
  204429. {
  204430. close();
  204431. }
  204432. const StringArray getOutputChannelNames()
  204433. {
  204434. StringArray s;
  204435. s.add ("Left");
  204436. s.add ("Right");
  204437. return s;
  204438. }
  204439. const StringArray getInputChannelNames()
  204440. {
  204441. StringArray s;
  204442. if (audioInputIsAvailable)
  204443. {
  204444. s.add ("Left");
  204445. s.add ("Right");
  204446. }
  204447. return s;
  204448. }
  204449. int getNumSampleRates()
  204450. {
  204451. return 1;
  204452. }
  204453. double getSampleRate (int index)
  204454. {
  204455. return sampleRate;
  204456. }
  204457. int getNumBufferSizesAvailable()
  204458. {
  204459. return 1;
  204460. }
  204461. int getBufferSizeSamples (int index)
  204462. {
  204463. return getDefaultBufferSize();
  204464. }
  204465. int getDefaultBufferSize()
  204466. {
  204467. return 1024;
  204468. }
  204469. const String open (const BigInteger& inputChannels,
  204470. const BigInteger& outputChannels,
  204471. double sampleRate,
  204472. int bufferSize)
  204473. {
  204474. close();
  204475. lastError = String::empty;
  204476. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204477. // xxx set up channel mapping
  204478. activeOutputChans = outputChannels;
  204479. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204480. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204481. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204482. activeInputChans = inputChannels;
  204483. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204484. numInputChannels = activeInputChans.countNumberOfSetBits();
  204485. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204486. AudioSessionSetActive (true);
  204487. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204488. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204489. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204490. fixAudioRouteIfSetToReceiver();
  204491. updateDeviceInfo();
  204492. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204493. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204494. actualBufferSize = preferredBufferSize;
  204495. prepareFloatBuffers();
  204496. isRunning = true;
  204497. propertyChanged (0, 0, 0); // creates and starts the AU
  204498. lastError = audioUnit != 0 ? "" : "Couldn't open the device";
  204499. return lastError;
  204500. }
  204501. void close()
  204502. {
  204503. if (isRunning)
  204504. {
  204505. isRunning = false;
  204506. AudioSessionSetActive (false);
  204507. if (audioUnit != 0)
  204508. {
  204509. AudioComponentInstanceDispose (audioUnit);
  204510. audioUnit = 0;
  204511. }
  204512. }
  204513. }
  204514. bool isOpen()
  204515. {
  204516. return isRunning;
  204517. }
  204518. int getCurrentBufferSizeSamples()
  204519. {
  204520. return actualBufferSize;
  204521. }
  204522. double getCurrentSampleRate()
  204523. {
  204524. return sampleRate;
  204525. }
  204526. int getCurrentBitDepth()
  204527. {
  204528. return 16;
  204529. }
  204530. const BigInteger getActiveOutputChannels() const
  204531. {
  204532. return activeOutputChans;
  204533. }
  204534. const BigInteger getActiveInputChannels() const
  204535. {
  204536. return activeInputChans;
  204537. }
  204538. int getOutputLatencyInSamples()
  204539. {
  204540. return 0; //xxx
  204541. }
  204542. int getInputLatencyInSamples()
  204543. {
  204544. return 0; //xxx
  204545. }
  204546. void start (AudioIODeviceCallback* callback_)
  204547. {
  204548. if (isRunning && callback != callback_)
  204549. {
  204550. if (callback_ != 0)
  204551. callback_->audioDeviceAboutToStart (this);
  204552. const ScopedLock sl (callbackLock);
  204553. callback = callback_;
  204554. }
  204555. }
  204556. void stop()
  204557. {
  204558. if (isRunning)
  204559. {
  204560. AudioIODeviceCallback* lastCallback;
  204561. {
  204562. const ScopedLock sl (callbackLock);
  204563. lastCallback = callback;
  204564. callback = 0;
  204565. }
  204566. if (lastCallback != 0)
  204567. lastCallback->audioDeviceStopped();
  204568. }
  204569. }
  204570. bool isPlaying()
  204571. {
  204572. return isRunning && callback != 0;
  204573. }
  204574. const String getLastError()
  204575. {
  204576. return lastError;
  204577. }
  204578. private:
  204579. CriticalSection callbackLock;
  204580. Float64 sampleRate;
  204581. int numInputChannels, numOutputChannels;
  204582. int preferredBufferSize;
  204583. int actualBufferSize;
  204584. bool isRunning;
  204585. String lastError;
  204586. AudioStreamBasicDescription format;
  204587. AudioUnit audioUnit;
  204588. UInt32 audioInputIsAvailable;
  204589. AudioIODeviceCallback* callback;
  204590. BigInteger activeOutputChans, activeInputChans;
  204591. AudioSampleBuffer floatData;
  204592. float* inputChannels[3];
  204593. float* outputChannels[3];
  204594. bool monoInputChannelNumber, monoOutputChannelNumber;
  204595. void prepareFloatBuffers()
  204596. {
  204597. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204598. zerostruct (inputChannels);
  204599. zerostruct (outputChannels);
  204600. for (int i = 0; i < numInputChannels; ++i)
  204601. inputChannels[i] = floatData.getSampleData (i);
  204602. for (int i = 0; i < numOutputChannels; ++i)
  204603. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204604. }
  204605. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204606. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204607. {
  204608. OSStatus err = noErr;
  204609. if (audioInputIsAvailable)
  204610. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204611. const ScopedLock sl (callbackLock);
  204612. if (callback != 0)
  204613. {
  204614. if (audioInputIsAvailable && numInputChannels > 0)
  204615. {
  204616. short* shortData = (short*) ioData->mBuffers[0].mData;
  204617. if (numInputChannels >= 2)
  204618. {
  204619. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204620. {
  204621. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204622. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204623. }
  204624. }
  204625. else
  204626. {
  204627. if (monoInputChannelNumber > 0)
  204628. ++shortData;
  204629. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204630. {
  204631. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204632. ++shortData;
  204633. }
  204634. }
  204635. }
  204636. else
  204637. {
  204638. for (int i = numInputChannels; --i >= 0;)
  204639. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204640. }
  204641. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204642. outputChannels, numOutputChannels,
  204643. (int) inNumberFrames);
  204644. short* shortData = (short*) ioData->mBuffers[0].mData;
  204645. int n = 0;
  204646. if (numOutputChannels >= 2)
  204647. {
  204648. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204649. {
  204650. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204651. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204652. }
  204653. }
  204654. else if (numOutputChannels == 1)
  204655. {
  204656. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204657. {
  204658. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204659. shortData [n++] = s;
  204660. shortData [n++] = s;
  204661. }
  204662. }
  204663. else
  204664. {
  204665. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204666. }
  204667. }
  204668. else
  204669. {
  204670. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204671. }
  204672. return err;
  204673. }
  204674. void updateDeviceInfo()
  204675. {
  204676. UInt32 size = sizeof (sampleRate);
  204677. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204678. size = sizeof (audioInputIsAvailable);
  204679. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204680. }
  204681. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204682. {
  204683. if (! isRunning)
  204684. return;
  204685. if (inPropertyValue != 0)
  204686. {
  204687. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204688. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204689. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204690. SInt32 routeChangeReason;
  204691. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204692. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204693. fixAudioRouteIfSetToReceiver();
  204694. }
  204695. updateDeviceInfo();
  204696. createAudioUnit();
  204697. AudioSessionSetActive (true);
  204698. if (audioUnit != 0)
  204699. {
  204700. UInt32 formatSize = sizeof (format);
  204701. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204702. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204703. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204704. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204705. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204706. AudioOutputUnitStart (audioUnit);
  204707. }
  204708. }
  204709. void interruptionListener (UInt32 inInterruption)
  204710. {
  204711. if (inInterruption == kAudioSessionEndInterruption)
  204712. {
  204713. isRunning = true;
  204714. AudioSessionSetActive (true);
  204715. AudioOutputUnitStart (audioUnit);
  204716. }
  204717. }
  204718. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204719. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204720. {
  204721. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204722. }
  204723. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204724. {
  204725. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204726. }
  204727. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204728. {
  204729. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204730. }
  204731. void resetFormat (const int numChannels)
  204732. {
  204733. memset (&format, 0, sizeof (format));
  204734. format.mFormatID = kAudioFormatLinearPCM;
  204735. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204736. format.mBitsPerChannel = 8 * sizeof (short);
  204737. format.mChannelsPerFrame = 2;
  204738. format.mFramesPerPacket = 1;
  204739. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204740. }
  204741. bool createAudioUnit()
  204742. {
  204743. if (audioUnit != 0)
  204744. {
  204745. AudioComponentInstanceDispose (audioUnit);
  204746. audioUnit = 0;
  204747. }
  204748. resetFormat (2);
  204749. AudioComponentDescription desc;
  204750. desc.componentType = kAudioUnitType_Output;
  204751. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204752. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204753. desc.componentFlags = 0;
  204754. desc.componentFlagsMask = 0;
  204755. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204756. AudioComponentInstanceNew (comp, &audioUnit);
  204757. if (audioUnit == 0)
  204758. return false;
  204759. const UInt32 one = 1;
  204760. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204761. AudioChannelLayout layout;
  204762. layout.mChannelBitmap = 0;
  204763. layout.mNumberChannelDescriptions = 0;
  204764. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204765. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204766. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204767. AURenderCallbackStruct inputProc;
  204768. inputProc.inputProc = processStatic;
  204769. inputProc.inputProcRefCon = this;
  204770. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204771. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204772. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204773. AudioUnitInitialize (audioUnit);
  204774. return true;
  204775. }
  204776. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204777. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204778. static void fixAudioRouteIfSetToReceiver()
  204779. {
  204780. CFStringRef audioRoute = 0;
  204781. UInt32 propertySize = sizeof (audioRoute);
  204782. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204783. {
  204784. NSString* route = (NSString*) audioRoute;
  204785. //DBG ("audio route: " + nsStringToJuce (route));
  204786. if ([route hasPrefix: @"Receiver"])
  204787. {
  204788. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204789. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204790. }
  204791. CFRelease (audioRoute);
  204792. }
  204793. }
  204794. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204795. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204796. };
  204797. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204798. {
  204799. public:
  204800. IPhoneAudioIODeviceType()
  204801. : AudioIODeviceType ("iPhone Audio")
  204802. {
  204803. }
  204804. ~IPhoneAudioIODeviceType()
  204805. {
  204806. }
  204807. void scanForDevices()
  204808. {
  204809. }
  204810. const StringArray getDeviceNames (bool wantInputNames) const
  204811. {
  204812. StringArray s;
  204813. s.add ("iPhone Audio");
  204814. return s;
  204815. }
  204816. int getDefaultDeviceIndex (bool forInput) const
  204817. {
  204818. return 0;
  204819. }
  204820. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  204821. {
  204822. return device != 0 ? 0 : -1;
  204823. }
  204824. bool hasSeparateInputsAndOutputs() const { return false; }
  204825. AudioIODevice* createDevice (const String& outputDeviceName,
  204826. const String& inputDeviceName)
  204827. {
  204828. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204829. {
  204830. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204831. : inputDeviceName);
  204832. }
  204833. return 0;
  204834. }
  204835. juce_UseDebuggingNewOperator
  204836. private:
  204837. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204838. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204839. };
  204840. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204841. {
  204842. return new IPhoneAudioIODeviceType();
  204843. }
  204844. #endif
  204845. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204846. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204847. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204848. // compiled on its own).
  204849. #if JUCE_INCLUDED_FILE
  204850. #if JUCE_MAC
  204851. #undef log
  204852. #define log(a) Logger::writeToLog(a)
  204853. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204854. {
  204855. if (err == noErr)
  204856. return true;
  204857. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  204858. jassertfalse
  204859. return false;
  204860. }
  204861. #undef OK
  204862. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204863. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204864. {
  204865. String result;
  204866. CFStringRef str = 0;
  204867. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204868. if (str != 0)
  204869. {
  204870. result = PlatformUtilities::cfStringToJuceString (str);
  204871. CFRelease (str);
  204872. str = 0;
  204873. }
  204874. MIDIEntityRef entity = 0;
  204875. MIDIEndpointGetEntity (endpoint, &entity);
  204876. if (entity == 0)
  204877. return result; // probably virtual
  204878. if (result.isEmpty())
  204879. {
  204880. // endpoint name has zero length - try the entity
  204881. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204882. if (str != 0)
  204883. {
  204884. result += PlatformUtilities::cfStringToJuceString (str);
  204885. CFRelease (str);
  204886. str = 0;
  204887. }
  204888. }
  204889. // now consider the device's name
  204890. MIDIDeviceRef device = 0;
  204891. MIDIEntityGetDevice (entity, &device);
  204892. if (device == 0)
  204893. return result;
  204894. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204895. if (str != 0)
  204896. {
  204897. const String s (PlatformUtilities::cfStringToJuceString (str));
  204898. CFRelease (str);
  204899. // if an external device has only one entity, throw away
  204900. // the endpoint name and just use the device name
  204901. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204902. {
  204903. result = s;
  204904. }
  204905. else if (! result.startsWithIgnoreCase (s))
  204906. {
  204907. // prepend the device name to the entity name
  204908. result = (s + " " + result).trimEnd();
  204909. }
  204910. }
  204911. return result;
  204912. }
  204913. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204914. {
  204915. String result;
  204916. // Does the endpoint have connections?
  204917. CFDataRef connections = 0;
  204918. int numConnections = 0;
  204919. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204920. if (connections != 0)
  204921. {
  204922. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204923. if (numConnections > 0)
  204924. {
  204925. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204926. for (int i = 0; i < numConnections; ++i, ++pid)
  204927. {
  204928. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204929. MIDIObjectRef connObject;
  204930. MIDIObjectType connObjectType;
  204931. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204932. if (err == noErr)
  204933. {
  204934. String s;
  204935. if (connObjectType == kMIDIObjectType_ExternalSource
  204936. || connObjectType == kMIDIObjectType_ExternalDestination)
  204937. {
  204938. // Connected to an external device's endpoint (10.3 and later).
  204939. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204940. }
  204941. else
  204942. {
  204943. // Connected to an external device (10.2) (or something else, catch-all)
  204944. CFStringRef str = 0;
  204945. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204946. if (str != 0)
  204947. {
  204948. s = PlatformUtilities::cfStringToJuceString (str);
  204949. CFRelease (str);
  204950. }
  204951. }
  204952. if (s.isNotEmpty())
  204953. {
  204954. if (result.isNotEmpty())
  204955. result += ", ";
  204956. result += s;
  204957. }
  204958. }
  204959. }
  204960. }
  204961. CFRelease (connections);
  204962. }
  204963. if (result.isNotEmpty())
  204964. return result;
  204965. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204966. return getEndpointName (endpoint, false);
  204967. }
  204968. const StringArray MidiOutput::getDevices()
  204969. {
  204970. StringArray s;
  204971. const ItemCount num = MIDIGetNumberOfDestinations();
  204972. for (ItemCount i = 0; i < num; ++i)
  204973. {
  204974. MIDIEndpointRef dest = MIDIGetDestination (i);
  204975. if (dest != 0)
  204976. {
  204977. String name (getConnectedEndpointName (dest));
  204978. if (name.isEmpty())
  204979. name = "<error>";
  204980. s.add (name);
  204981. }
  204982. else
  204983. {
  204984. s.add ("<error>");
  204985. }
  204986. }
  204987. return s;
  204988. }
  204989. int MidiOutput::getDefaultDeviceIndex()
  204990. {
  204991. return 0;
  204992. }
  204993. static MIDIClientRef globalMidiClient;
  204994. static bool hasGlobalClientBeenCreated = false;
  204995. static bool makeSureClientExists()
  204996. {
  204997. if (! hasGlobalClientBeenCreated)
  204998. {
  204999. String name ("JUCE");
  205000. if (JUCEApplication::getInstance() != 0)
  205001. name = JUCEApplication::getInstance()->getApplicationName();
  205002. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205003. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205004. CFRelease (appName);
  205005. }
  205006. return hasGlobalClientBeenCreated;
  205007. }
  205008. class MidiPortAndEndpoint
  205009. {
  205010. public:
  205011. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205012. : port (port_), endPoint (endPoint_)
  205013. {
  205014. }
  205015. ~MidiPortAndEndpoint()
  205016. {
  205017. if (port != 0)
  205018. MIDIPortDispose (port);
  205019. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205020. MIDIEndpointDispose (endPoint);
  205021. }
  205022. MIDIPortRef port;
  205023. MIDIEndpointRef endPoint;
  205024. };
  205025. MidiOutput* MidiOutput::openDevice (int index)
  205026. {
  205027. MidiOutput* mo = 0;
  205028. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205029. {
  205030. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205031. CFStringRef pname;
  205032. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205033. {
  205034. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  205035. if (makeSureClientExists())
  205036. {
  205037. MIDIPortRef port;
  205038. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205039. {
  205040. mo = new MidiOutput();
  205041. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205042. }
  205043. }
  205044. CFRelease (pname);
  205045. }
  205046. }
  205047. return mo;
  205048. }
  205049. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205050. {
  205051. MidiOutput* mo = 0;
  205052. if (makeSureClientExists())
  205053. {
  205054. MIDIEndpointRef endPoint;
  205055. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205056. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205057. {
  205058. mo = new MidiOutput();
  205059. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205060. }
  205061. CFRelease (name);
  205062. }
  205063. return mo;
  205064. }
  205065. MidiOutput::~MidiOutput()
  205066. {
  205067. delete (MidiPortAndEndpoint*) internal;
  205068. }
  205069. void MidiOutput::reset()
  205070. {
  205071. }
  205072. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205073. {
  205074. return false;
  205075. }
  205076. void MidiOutput::setVolume (float leftVol, float rightVol)
  205077. {
  205078. }
  205079. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205080. {
  205081. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205082. if (message.isSysEx())
  205083. {
  205084. const int maxPacketSize = 256;
  205085. int pos = 0, bytesLeft = message.getRawDataSize();
  205086. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205087. HeapBlock <MIDIPacketList> packets;
  205088. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205089. packets->numPackets = numPackets;
  205090. MIDIPacket* p = packets->packet;
  205091. for (int i = 0; i < numPackets; ++i)
  205092. {
  205093. p->timeStamp = 0;
  205094. p->length = jmin (maxPacketSize, bytesLeft);
  205095. memcpy (p->data, message.getRawData() + pos, p->length);
  205096. pos += p->length;
  205097. bytesLeft -= p->length;
  205098. p = MIDIPacketNext (p);
  205099. }
  205100. if (mpe->port != 0)
  205101. MIDISend (mpe->port, mpe->endPoint, packets);
  205102. else
  205103. MIDIReceived (mpe->endPoint, packets);
  205104. }
  205105. else
  205106. {
  205107. MIDIPacketList packets;
  205108. packets.numPackets = 1;
  205109. packets.packet[0].timeStamp = 0;
  205110. packets.packet[0].length = message.getRawDataSize();
  205111. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205112. if (mpe->port != 0)
  205113. MIDISend (mpe->port, mpe->endPoint, &packets);
  205114. else
  205115. MIDIReceived (mpe->endPoint, &packets);
  205116. }
  205117. }
  205118. const StringArray MidiInput::getDevices()
  205119. {
  205120. StringArray s;
  205121. const ItemCount num = MIDIGetNumberOfSources();
  205122. for (ItemCount i = 0; i < num; ++i)
  205123. {
  205124. MIDIEndpointRef source = MIDIGetSource (i);
  205125. if (source != 0)
  205126. {
  205127. String name (getConnectedEndpointName (source));
  205128. if (name.isEmpty())
  205129. name = "<error>";
  205130. s.add (name);
  205131. }
  205132. else
  205133. {
  205134. s.add ("<error>");
  205135. }
  205136. }
  205137. return s;
  205138. }
  205139. int MidiInput::getDefaultDeviceIndex()
  205140. {
  205141. return 0;
  205142. }
  205143. struct MidiPortAndCallback
  205144. {
  205145. MidiInput* input;
  205146. MidiPortAndEndpoint* portAndEndpoint;
  205147. MidiInputCallback* callback;
  205148. MemoryBlock pendingData;
  205149. int pendingBytes;
  205150. double pendingDataTime;
  205151. bool active;
  205152. void processSysex (const uint8*& d, int& size, const double time)
  205153. {
  205154. if (*d == 0xf0)
  205155. {
  205156. pendingBytes = 0;
  205157. pendingDataTime = time;
  205158. }
  205159. pendingData.ensureSize (pendingBytes + size, false);
  205160. uint8* totalMessage = (uint8*) pendingData.getData();
  205161. uint8* dest = totalMessage + pendingBytes;
  205162. while (size > 0)
  205163. {
  205164. if (pendingBytes > 0 && *d >= 0x80)
  205165. {
  205166. if (*d >= 0xfa || *d == 0xf8)
  205167. {
  205168. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205169. ++d;
  205170. --size;
  205171. }
  205172. else
  205173. {
  205174. if (*d == 0xf7)
  205175. {
  205176. *dest++ = *d++;
  205177. pendingBytes++;
  205178. --size;
  205179. }
  205180. break;
  205181. }
  205182. }
  205183. else
  205184. {
  205185. *dest++ = *d++;
  205186. pendingBytes++;
  205187. --size;
  205188. }
  205189. }
  205190. if (totalMessage [pendingBytes - 1] == 0xf7)
  205191. {
  205192. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205193. pendingBytes = 0;
  205194. }
  205195. else
  205196. {
  205197. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205198. }
  205199. }
  205200. };
  205201. namespace CoreMidiCallbacks
  205202. {
  205203. static CriticalSection callbackLock;
  205204. static VoidArray activeCallbacks;
  205205. }
  205206. static void midiInputProc (const MIDIPacketList* pktlist,
  205207. void* readProcRefCon,
  205208. void* srcConnRefCon)
  205209. {
  205210. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205211. const double originalTime = time;
  205212. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205213. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205214. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205215. {
  205216. const MIDIPacket* packet = &pktlist->packet[0];
  205217. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205218. {
  205219. const uint8* d = (const uint8*) (packet->data);
  205220. int size = packet->length;
  205221. while (size > 0)
  205222. {
  205223. time = originalTime;
  205224. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205225. {
  205226. mpc->processSysex (d, size, time);
  205227. }
  205228. else
  205229. {
  205230. int used = 0;
  205231. const MidiMessage m (d, size, used, 0, time);
  205232. if (used <= 0)
  205233. {
  205234. jassertfalse // malformed midi message
  205235. break;
  205236. }
  205237. else
  205238. {
  205239. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205240. }
  205241. size -= used;
  205242. d += used;
  205243. }
  205244. }
  205245. packet = MIDIPacketNext (packet);
  205246. }
  205247. }
  205248. }
  205249. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205250. {
  205251. MidiInput* mi = 0;
  205252. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205253. {
  205254. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205255. if (endPoint != 0)
  205256. {
  205257. CFStringRef pname;
  205258. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205259. {
  205260. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  205261. if (makeSureClientExists())
  205262. {
  205263. MIDIPortRef port;
  205264. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205265. mpc->active = false;
  205266. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205267. {
  205268. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205269. {
  205270. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205271. mpc->callback = callback;
  205272. mpc->pendingBytes = 0;
  205273. mpc->pendingData.ensureSize (128);
  205274. mi = new MidiInput (getDevices() [index]);
  205275. mpc->input = mi;
  205276. mi->internal = (void*) mpc;
  205277. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205278. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205279. }
  205280. else
  205281. {
  205282. OK (MIDIPortDispose (port));
  205283. }
  205284. }
  205285. }
  205286. }
  205287. CFRelease (pname);
  205288. }
  205289. }
  205290. return mi;
  205291. }
  205292. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205293. {
  205294. MidiInput* mi = 0;
  205295. if (makeSureClientExists())
  205296. {
  205297. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205298. mpc->active = false;
  205299. MIDIEndpointRef endPoint;
  205300. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205301. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205302. {
  205303. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205304. mpc->callback = callback;
  205305. mpc->pendingBytes = 0;
  205306. mpc->pendingData.ensureSize (128);
  205307. mi = new MidiInput (deviceName);
  205308. mpc->input = mi;
  205309. mi->internal = (void*) mpc;
  205310. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205311. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205312. }
  205313. CFRelease (name);
  205314. }
  205315. return mi;
  205316. }
  205317. MidiInput::MidiInput (const String& name_)
  205318. : name (name_)
  205319. {
  205320. }
  205321. MidiInput::~MidiInput()
  205322. {
  205323. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205324. mpc->active = false;
  205325. {
  205326. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205327. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205328. }
  205329. if (mpc->portAndEndpoint->port != 0)
  205330. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205331. delete mpc->portAndEndpoint;
  205332. delete mpc;
  205333. }
  205334. void MidiInput::start()
  205335. {
  205336. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205337. ((MidiPortAndCallback*) internal)->active = true;
  205338. }
  205339. void MidiInput::stop()
  205340. {
  205341. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205342. ((MidiPortAndCallback*) internal)->active = false;
  205343. }
  205344. #undef log
  205345. #else
  205346. MidiOutput::~MidiOutput()
  205347. {
  205348. }
  205349. void MidiOutput::reset()
  205350. {
  205351. }
  205352. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205353. {
  205354. return false;
  205355. }
  205356. void MidiOutput::setVolume (float leftVol, float rightVol)
  205357. {
  205358. }
  205359. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205360. {
  205361. }
  205362. const StringArray MidiOutput::getDevices()
  205363. {
  205364. return StringArray();
  205365. }
  205366. MidiOutput* MidiOutput::openDevice (int index)
  205367. {
  205368. return 0;
  205369. }
  205370. const StringArray MidiInput::getDevices()
  205371. {
  205372. return StringArray();
  205373. }
  205374. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205375. {
  205376. return 0;
  205377. }
  205378. #endif
  205379. #endif
  205380. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205381. #else
  205382. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205383. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205384. // compiled on its own).
  205385. #if JUCE_INCLUDED_FILE
  205386. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205387. #define SUPPORT_10_4_FONTS 1
  205388. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205389. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205390. #define SUPPORT_ONLY_10_4_FONTS 1
  205391. #endif
  205392. END_JUCE_NAMESPACE
  205393. @interface NSFont (PrivateHack)
  205394. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205395. @end
  205396. BEGIN_JUCE_NAMESPACE
  205397. #endif
  205398. class MacTypeface : public Typeface
  205399. {
  205400. public:
  205401. MacTypeface (const Font& font)
  205402. : Typeface (font.getTypefaceName())
  205403. {
  205404. const ScopedAutoReleasePool pool;
  205405. renderingTransform = CGAffineTransformIdentity;
  205406. bool needsItalicTransform = false;
  205407. #if JUCE_IPHONE
  205408. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205409. if (font.isItalic() || font.isBold())
  205410. {
  205411. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205412. for (NSString* i in familyFonts)
  205413. {
  205414. const String fn (nsStringToJuce (i));
  205415. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  205416. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  205417. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  205418. || afterDash.containsIgnoreCase ("italic")
  205419. || fn.endsWithIgnoreCase ("oblique")
  205420. || fn.endsWithIgnoreCase ("italic");
  205421. if (probablyBold == font.isBold()
  205422. && probablyItalic == font.isItalic())
  205423. {
  205424. fontName = i;
  205425. needsItalicTransform = false;
  205426. break;
  205427. }
  205428. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205429. {
  205430. fontName = i;
  205431. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205432. }
  205433. }
  205434. if (needsItalicTransform)
  205435. renderingTransform.c = 0.15f;
  205436. }
  205437. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205438. const int ascender = abs (CGFontGetAscent (fontRef));
  205439. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205440. ascent = ascender / totalHeight;
  205441. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205442. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205443. #else
  205444. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205445. if (font.isItalic())
  205446. {
  205447. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205448. toHaveTrait: NSItalicFontMask];
  205449. if (newFont == nsFont)
  205450. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205451. nsFont = newFont;
  205452. }
  205453. if (font.isBold())
  205454. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205455. [nsFont retain];
  205456. ascent = fabsf ((float) [nsFont ascender]);
  205457. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205458. ascent /= totalSize;
  205459. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205460. if (needsItalicTransform)
  205461. {
  205462. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205463. renderingTransform.c = 0.15f;
  205464. }
  205465. #if SUPPORT_ONLY_10_4_FONTS
  205466. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205467. if (atsFont == 0)
  205468. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205469. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205470. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205471. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205472. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205473. #else
  205474. #if SUPPORT_10_4_FONTS
  205475. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205476. {
  205477. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205478. if (atsFont == 0)
  205479. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205480. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205481. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205482. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205483. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205484. }
  205485. else
  205486. #endif
  205487. {
  205488. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205489. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205490. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205491. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205492. }
  205493. #endif
  205494. #endif
  205495. }
  205496. ~MacTypeface()
  205497. {
  205498. #if ! JUCE_IPHONE
  205499. [nsFont release];
  205500. #endif
  205501. if (fontRef != 0)
  205502. CGFontRelease (fontRef);
  205503. }
  205504. float getAscent() const
  205505. {
  205506. return ascent;
  205507. }
  205508. float getDescent() const
  205509. {
  205510. return 1.0f - ascent;
  205511. }
  205512. float getStringWidth (const String& text)
  205513. {
  205514. if (fontRef == 0 || text.isEmpty())
  205515. return 0;
  205516. const int length = text.length();
  205517. HeapBlock <CGGlyph> glyphs;
  205518. createGlyphsForString (text, length, glyphs);
  205519. float x = 0;
  205520. #if SUPPORT_ONLY_10_4_FONTS
  205521. HeapBlock <NSSize> advances (length);
  205522. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205523. for (int i = 0; i < length; ++i)
  205524. x += advances[i].width;
  205525. #else
  205526. #if SUPPORT_10_4_FONTS
  205527. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205528. {
  205529. HeapBlock <NSSize> advances (length);
  205530. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205531. for (int i = 0; i < length; ++i)
  205532. x += advances[i].width;
  205533. }
  205534. else
  205535. #endif
  205536. {
  205537. HeapBlock <int> advances (length);
  205538. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205539. for (int i = 0; i < length; ++i)
  205540. x += advances[i];
  205541. }
  205542. #endif
  205543. return x * unitsToHeightScaleFactor;
  205544. }
  205545. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205546. {
  205547. xOffsets.add (0);
  205548. if (fontRef == 0 || text.isEmpty())
  205549. return;
  205550. const int length = text.length();
  205551. HeapBlock <CGGlyph> glyphs;
  205552. createGlyphsForString (text, length, glyphs);
  205553. #if SUPPORT_ONLY_10_4_FONTS
  205554. HeapBlock <NSSize> advances (length);
  205555. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205556. int x = 0;
  205557. for (int i = 0; i < length; ++i)
  205558. {
  205559. x += advances[i].width;
  205560. xOffsets.add (x * unitsToHeightScaleFactor);
  205561. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205562. }
  205563. #else
  205564. #if SUPPORT_10_4_FONTS
  205565. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205566. {
  205567. HeapBlock <NSSize> advances (length);
  205568. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205569. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205570. float x = 0;
  205571. for (int i = 0; i < length; ++i)
  205572. {
  205573. x += advances[i].width;
  205574. xOffsets.add (x * unitsToHeightScaleFactor);
  205575. resultGlyphs.add (nsGlyphs[i]);
  205576. }
  205577. }
  205578. else
  205579. #endif
  205580. {
  205581. HeapBlock <int> advances (length);
  205582. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205583. {
  205584. int x = 0;
  205585. for (int i = 0; i < length; ++i)
  205586. {
  205587. x += advances [i];
  205588. xOffsets.add (x * unitsToHeightScaleFactor);
  205589. resultGlyphs.add (glyphs[i]);
  205590. }
  205591. }
  205592. }
  205593. #endif
  205594. }
  205595. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205596. {
  205597. #if JUCE_IPHONE
  205598. return false;
  205599. #else
  205600. if (nsFont == 0)
  205601. return false;
  205602. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205603. jassert (path.isEmpty());
  205604. const ScopedAutoReleasePool pool;
  205605. NSBezierPath* bez = [NSBezierPath bezierPath];
  205606. [bez moveToPoint: NSMakePoint (0, 0)];
  205607. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205608. inFont: nsFont];
  205609. for (int i = 0; i < [bez elementCount]; ++i)
  205610. {
  205611. NSPoint p[3];
  205612. switch ([bez elementAtIndex: i associatedPoints: p])
  205613. {
  205614. case NSMoveToBezierPathElement:
  205615. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205616. break;
  205617. case NSLineToBezierPathElement:
  205618. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205619. break;
  205620. case NSCurveToBezierPathElement:
  205621. 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);
  205622. break;
  205623. case NSClosePathBezierPathElement:
  205624. path.closeSubPath();
  205625. break;
  205626. default:
  205627. jassertfalse
  205628. break;
  205629. }
  205630. }
  205631. path.applyTransform (pathTransform);
  205632. return true;
  205633. #endif
  205634. }
  205635. juce_UseDebuggingNewOperator
  205636. CGFontRef fontRef;
  205637. float fontHeightToCGSizeFactor;
  205638. CGAffineTransform renderingTransform;
  205639. private:
  205640. float ascent, unitsToHeightScaleFactor;
  205641. #if JUCE_IPHONE
  205642. #else
  205643. NSFont* nsFont;
  205644. AffineTransform pathTransform;
  205645. #endif
  205646. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205647. {
  205648. #if SUPPORT_10_4_FONTS
  205649. #if ! SUPPORT_ONLY_10_4_FONTS
  205650. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205651. #endif
  205652. {
  205653. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205654. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205655. for (int i = 0; i < length; ++i)
  205656. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205657. return;
  205658. }
  205659. #endif
  205660. #if ! SUPPORT_ONLY_10_4_FONTS
  205661. if (charToGlyphMapper == 0)
  205662. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205663. glyphs.malloc (length);
  205664. for (int i = 0; i < length; ++i)
  205665. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205666. #endif
  205667. }
  205668. #if ! SUPPORT_ONLY_10_4_FONTS
  205669. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205670. class CharToGlyphMapper
  205671. {
  205672. public:
  205673. CharToGlyphMapper (CGFontRef fontRef)
  205674. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205675. idRangeOffset (0), glyphIndexes (0)
  205676. {
  205677. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205678. if (cmapTable != 0)
  205679. {
  205680. const int numSubtables = getValue16 (cmapTable, 2);
  205681. for (int i = 0; i < numSubtables; ++i)
  205682. {
  205683. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205684. {
  205685. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205686. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205687. {
  205688. const int length = getValue16 (cmapTable, offset + 2);
  205689. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205690. segCount = segCountX2 / 2;
  205691. const int endCodeOffset = offset + 14;
  205692. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205693. const int idDeltaOffset = startCodeOffset + segCountX2;
  205694. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205695. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205696. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205697. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205698. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205699. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205700. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205701. }
  205702. break;
  205703. }
  205704. }
  205705. CFRelease (cmapTable);
  205706. }
  205707. }
  205708. ~CharToGlyphMapper()
  205709. {
  205710. if (endCode != 0)
  205711. {
  205712. CFRelease (endCode);
  205713. CFRelease (startCode);
  205714. CFRelease (idDelta);
  205715. CFRelease (idRangeOffset);
  205716. CFRelease (glyphIndexes);
  205717. }
  205718. }
  205719. int getGlyphForCharacter (const juce_wchar c) const
  205720. {
  205721. for (int i = 0; i < segCount; ++i)
  205722. {
  205723. if (getValue16 (endCode, i * 2) >= c)
  205724. {
  205725. const int start = getValue16 (startCode, i * 2);
  205726. if (start > c)
  205727. break;
  205728. const int delta = getValue16 (idDelta, i * 2);
  205729. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205730. if (rangeOffset == 0)
  205731. return delta + c;
  205732. else
  205733. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205734. }
  205735. }
  205736. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205737. return jmax (-1, c - 29);
  205738. }
  205739. private:
  205740. int segCount;
  205741. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205742. static uint16 getValue16 (CFDataRef data, const int index)
  205743. {
  205744. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205745. }
  205746. static uint32 getValue32 (CFDataRef data, const int index)
  205747. {
  205748. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205749. }
  205750. };
  205751. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205752. #endif
  205753. MacTypeface (const MacTypeface&);
  205754. MacTypeface& operator= (const MacTypeface&);
  205755. };
  205756. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205757. {
  205758. return new MacTypeface (font);
  205759. }
  205760. const StringArray Font::findAllTypefaceNames()
  205761. {
  205762. StringArray names;
  205763. const ScopedAutoReleasePool pool;
  205764. #if JUCE_IPHONE
  205765. NSArray* fonts = [UIFont familyNames];
  205766. #else
  205767. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205768. #endif
  205769. for (unsigned int i = 0; i < [fonts count]; ++i)
  205770. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205771. names.sort (true);
  205772. return names;
  205773. }
  205774. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  205775. {
  205776. #if JUCE_IPHONE
  205777. defaultSans = "Helvetica";
  205778. defaultSerif = "Times New Roman";
  205779. defaultFixed = "Courier New";
  205780. #else
  205781. defaultSans = "Lucida Grande";
  205782. defaultSerif = "Times New Roman";
  205783. defaultFixed = "Monaco";
  205784. #endif
  205785. }
  205786. #endif
  205787. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205788. // (must go before juce_mac_CoreGraphicsContext.mm)
  205789. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205790. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205791. // compiled on its own).
  205792. #if JUCE_INCLUDED_FILE
  205793. class CoreGraphicsImage : public Image
  205794. {
  205795. public:
  205796. CoreGraphicsImage (const PixelFormat format_,
  205797. const int imageWidth_,
  205798. const int imageHeight_,
  205799. const bool clearImage)
  205800. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205801. {
  205802. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205803. : CGColorSpaceCreateDeviceRGB();
  205804. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205805. colourSpace, getCGImageFlags (*this));
  205806. CGColorSpaceRelease (colourSpace);
  205807. }
  205808. ~CoreGraphicsImage()
  205809. {
  205810. CGContextRelease (context);
  205811. }
  205812. LowLevelGraphicsContext* createLowLevelContext();
  205813. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205814. {
  205815. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205816. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205817. {
  205818. return CGBitmapContextCreateImage (nativeImage->context);
  205819. }
  205820. else
  205821. {
  205822. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205823. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205824. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205825. 8, srcData.pixelStride * 8, srcData.lineStride,
  205826. colourSpace, getCGImageFlags (juceImage), provider,
  205827. 0, true, kCGRenderingIntentDefault);
  205828. CGDataProviderRelease (provider);
  205829. return imageRef;
  205830. }
  205831. }
  205832. #if JUCE_MAC
  205833. static NSImage* createNSImage (const Image& image)
  205834. {
  205835. const ScopedAutoReleasePool pool;
  205836. NSImage* im = [[NSImage alloc] init];
  205837. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205838. [im lockFocus];
  205839. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205840. CGImageRef imageRef = createImage (image, false, colourSpace);
  205841. CGColorSpaceRelease (colourSpace);
  205842. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205843. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205844. CGImageRelease (imageRef);
  205845. [im unlockFocus];
  205846. return im;
  205847. }
  205848. #endif
  205849. CGContextRef context;
  205850. private:
  205851. static CGBitmapInfo getCGImageFlags (const Image& image)
  205852. {
  205853. #if JUCE_BIG_ENDIAN
  205854. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205855. #else
  205856. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205857. #endif
  205858. }
  205859. };
  205860. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205861. {
  205862. #if USE_COREGRAPHICS_RENDERING
  205863. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205864. #else
  205865. return new Image (format, imageWidth, imageHeight, clearImage);
  205866. #endif
  205867. }
  205868. class CoreGraphicsContext : public LowLevelGraphicsContext
  205869. {
  205870. public:
  205871. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205872. : context (context_),
  205873. flipHeight (flipHeight_),
  205874. state (new SavedState()),
  205875. numGradientLookupEntries (0)
  205876. {
  205877. CGContextRetain (context);
  205878. CGContextSaveGState(context);
  205879. CGContextSetShouldSmoothFonts (context, true);
  205880. CGContextSetShouldAntialias (context, true);
  205881. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205882. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205883. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205884. gradientCallbacks.version = 0;
  205885. gradientCallbacks.evaluate = gradientCallback;
  205886. gradientCallbacks.releaseInfo = 0;
  205887. setFont (Font());
  205888. }
  205889. ~CoreGraphicsContext()
  205890. {
  205891. CGContextRestoreGState (context);
  205892. CGContextRelease (context);
  205893. CGColorSpaceRelease (rgbColourSpace);
  205894. CGColorSpaceRelease (greyColourSpace);
  205895. }
  205896. bool isVectorDevice() const { return false; }
  205897. void setOrigin (int x, int y)
  205898. {
  205899. CGContextTranslateCTM (context, x, -y);
  205900. }
  205901. bool clipToRectangle (const Rectangle<int>& r)
  205902. {
  205903. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205904. return ! isClipEmpty();
  205905. }
  205906. bool clipToRectangleList (const RectangleList& clipRegion)
  205907. {
  205908. if (clipRegion.isEmpty())
  205909. {
  205910. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205911. return false;
  205912. }
  205913. else
  205914. {
  205915. const int numRects = clipRegion.getNumRectangles();
  205916. HeapBlock <CGRect> rects (numRects);
  205917. for (int i = 0; i < numRects; ++i)
  205918. {
  205919. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205920. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205921. }
  205922. CGContextClipToRects (context, rects, numRects);
  205923. return ! isClipEmpty();
  205924. }
  205925. }
  205926. void excludeClipRectangle (const Rectangle<int>& r)
  205927. {
  205928. RectangleList remaining (getClipBounds());
  205929. remaining.subtract (r);
  205930. clipToRectangleList (remaining);
  205931. }
  205932. void clipToPath (const Path& path, const AffineTransform& transform)
  205933. {
  205934. createPath (path, transform);
  205935. CGContextClip (context);
  205936. }
  205937. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205938. {
  205939. if (! transform.isSingularity())
  205940. {
  205941. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205942. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205943. flip();
  205944. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205945. applyTransform (t);
  205946. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205947. CGContextClipToMask (context, r, image);
  205948. applyTransform (t.inverted());
  205949. flip();
  205950. CGImageRelease (image);
  205951. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205952. }
  205953. }
  205954. bool clipRegionIntersects (const Rectangle<int>& r)
  205955. {
  205956. return getClipBounds().intersects (r);
  205957. }
  205958. const Rectangle<int> getClipBounds() const
  205959. {
  205960. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205961. return Rectangle<int> (roundToInt (bounds.origin.x),
  205962. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205963. roundToInt (bounds.size.width),
  205964. roundToInt (bounds.size.height));
  205965. }
  205966. bool isClipEmpty() const
  205967. {
  205968. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205969. }
  205970. void saveState()
  205971. {
  205972. CGContextSaveGState (context);
  205973. stateStack.add (new SavedState (*state));
  205974. }
  205975. void restoreState()
  205976. {
  205977. CGContextRestoreGState (context);
  205978. SavedState* const top = stateStack.getLast();
  205979. if (top != 0)
  205980. {
  205981. state = top;
  205982. stateStack.removeLast (1, false);
  205983. }
  205984. else
  205985. {
  205986. jassertfalse // trying to pop with an empty stack!
  205987. }
  205988. }
  205989. void setFill (const FillType& fillType)
  205990. {
  205991. state->fillType = fillType;
  205992. if (fillType.isColour())
  205993. {
  205994. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  205995. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  205996. CGContextSetAlpha (context, 1.0f);
  205997. }
  205998. }
  205999. void setOpacity (float newOpacity)
  206000. {
  206001. state->fillType.setOpacity (newOpacity);
  206002. setFill (state->fillType);
  206003. }
  206004. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206005. {
  206006. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206007. ? kCGInterpolationLow
  206008. : kCGInterpolationHigh);
  206009. }
  206010. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206011. {
  206012. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206013. if (replaceExistingContents)
  206014. {
  206015. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206016. CGContextClearRect (context, cgRect);
  206017. #else
  206018. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206019. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206020. CGContextClearRect (context, cgRect);
  206021. else
  206022. #endif
  206023. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206024. #endif
  206025. fillRect (r, false);
  206026. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206027. }
  206028. else
  206029. {
  206030. if (state->fillType.isColour())
  206031. {
  206032. CGContextFillRect (context, cgRect);
  206033. }
  206034. else if (state->fillType.isGradient())
  206035. {
  206036. CGContextSaveGState (context);
  206037. CGContextClipToRect (context, cgRect);
  206038. drawGradient();
  206039. CGContextRestoreGState (context);
  206040. }
  206041. else
  206042. {
  206043. CGContextSaveGState (context);
  206044. CGContextClipToRect (context, cgRect);
  206045. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206046. CGContextRestoreGState (context);
  206047. }
  206048. }
  206049. }
  206050. void fillPath (const Path& path, const AffineTransform& transform)
  206051. {
  206052. CGContextSaveGState (context);
  206053. if (state->fillType.isColour())
  206054. {
  206055. flip();
  206056. applyTransform (transform);
  206057. createPath (path);
  206058. if (path.isUsingNonZeroWinding())
  206059. CGContextFillPath (context);
  206060. else
  206061. CGContextEOFillPath (context);
  206062. }
  206063. else
  206064. {
  206065. createPath (path, transform);
  206066. if (path.isUsingNonZeroWinding())
  206067. CGContextClip (context);
  206068. else
  206069. CGContextEOClip (context);
  206070. if (state->fillType.isGradient())
  206071. drawGradient();
  206072. else
  206073. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206074. }
  206075. CGContextRestoreGState (context);
  206076. }
  206077. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206078. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206079. {
  206080. jassert (sourceImage.getBounds().contains (srcClip));
  206081. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206082. CGImageRef image = fullImage;
  206083. if (srcClip != sourceImage.getBounds())
  206084. {
  206085. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206086. srcClip.getWidth(), srcClip.getHeight()));
  206087. CGImageRelease (fullImage);
  206088. }
  206089. CGContextSaveGState (context);
  206090. CGContextSetAlpha (context, state->fillType.getOpacity());
  206091. flip();
  206092. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206093. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206094. if (fillEntireClipAsTiles)
  206095. {
  206096. #if JUCE_IPHONE
  206097. CGContextDrawTiledImage (context, imageRect, image);
  206098. #else
  206099. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206100. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206101. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206102. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206103. CGContextDrawTiledImage (context, imageRect, image);
  206104. else
  206105. #endif
  206106. {
  206107. // Fallback to manually doing a tiled fill on 10.4
  206108. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206109. const int iw = srcClip.getWidth();
  206110. const int ih = srcClip.getHeight();
  206111. int x = 0, y = 0;
  206112. while (x > clip.origin.x) x -= iw;
  206113. while (y > clip.origin.y) y -= ih;
  206114. const int right = (int) (clip.origin.x + clip.size.width);
  206115. const int bottom = (int) (clip.origin.y + clip.size.height);
  206116. while (y < bottom)
  206117. {
  206118. for (int x2 = x; x2 < right; x2 += iw)
  206119. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206120. y += ih;
  206121. }
  206122. }
  206123. #endif
  206124. }
  206125. else
  206126. {
  206127. CGContextDrawImage (context, imageRect, image);
  206128. }
  206129. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206130. CGContextRestoreGState (context);
  206131. }
  206132. void drawLine (double x1, double y1, double x2, double y2)
  206133. {
  206134. CGContextSetLineCap (context, kCGLineCapSquare);
  206135. CGContextSetLineWidth (context, 1.0f);
  206136. CGContextSetRGBStrokeColor (context,
  206137. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206138. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206139. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  206140. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  206141. CGContextStrokeLineSegments (context, line, 1);
  206142. }
  206143. void drawVerticalLine (const int x, double top, double bottom)
  206144. {
  206145. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206146. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206147. #else
  206148. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206149. // the x co-ord slightly to trick it..
  206150. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206151. #endif
  206152. }
  206153. void drawHorizontalLine (const int y, double left, double right)
  206154. {
  206155. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206156. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206157. #else
  206158. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206159. // the x co-ord slightly to trick it..
  206160. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206161. #endif
  206162. }
  206163. void setFont (const Font& newFont)
  206164. {
  206165. if (state->font != newFont)
  206166. {
  206167. state->fontRef = 0;
  206168. state->font = newFont;
  206169. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206170. if (mf != 0)
  206171. {
  206172. state->fontRef = mf->fontRef;
  206173. CGContextSetFont (context, state->fontRef);
  206174. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206175. state->fontTransform = mf->renderingTransform;
  206176. state->fontTransform.a *= state->font.getHorizontalScale();
  206177. CGContextSetTextMatrix (context, state->fontTransform);
  206178. }
  206179. }
  206180. }
  206181. const Font getFont()
  206182. {
  206183. return state->font;
  206184. }
  206185. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206186. {
  206187. if (state->fontRef != 0 && state->fillType.isColour())
  206188. {
  206189. if (transform.isOnlyTranslation())
  206190. {
  206191. CGGlyph g = glyphNumber;
  206192. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206193. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206194. }
  206195. else
  206196. {
  206197. CGContextSaveGState (context);
  206198. flip();
  206199. applyTransform (transform);
  206200. CGAffineTransform t = state->fontTransform;
  206201. t.d = -t.d;
  206202. CGContextSetTextMatrix (context, t);
  206203. CGGlyph g = glyphNumber;
  206204. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206205. CGContextSetTextMatrix (context, state->fontTransform);
  206206. CGContextRestoreGState (context);
  206207. }
  206208. }
  206209. else
  206210. {
  206211. Path p;
  206212. Font& f = state->font;
  206213. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206214. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206215. .followedBy (transform));
  206216. }
  206217. }
  206218. private:
  206219. CGContextRef context;
  206220. const CGFloat flipHeight;
  206221. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206222. CGFunctionCallbacks gradientCallbacks;
  206223. struct SavedState
  206224. {
  206225. SavedState()
  206226. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206227. {
  206228. }
  206229. SavedState (const SavedState& other)
  206230. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206231. fontTransform (other.fontTransform)
  206232. {
  206233. }
  206234. ~SavedState()
  206235. {
  206236. }
  206237. FillType fillType;
  206238. Font font;
  206239. CGFontRef fontRef;
  206240. CGAffineTransform fontTransform;
  206241. };
  206242. ScopedPointer <SavedState> state;
  206243. OwnedArray <SavedState> stateStack;
  206244. HeapBlock <PixelARGB> gradientLookupTable;
  206245. int numGradientLookupEntries;
  206246. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206247. {
  206248. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206249. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206250. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206251. colour.unpremultiply();
  206252. outData[0] = colour.getRed() / 255.0f;
  206253. outData[1] = colour.getGreen() / 255.0f;
  206254. outData[2] = colour.getBlue() / 255.0f;
  206255. outData[3] = colour.getAlpha() / 255.0f;
  206256. }
  206257. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206258. {
  206259. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206260. --numGradientLookupEntries;
  206261. CGShadingRef result = 0;
  206262. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206263. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206264. if (gradient.isRadial)
  206265. {
  206266. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206267. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206268. function, true, true);
  206269. }
  206270. else
  206271. {
  206272. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206273. CGPointMake (gradient.x2, gradient.y2),
  206274. function, true, true);
  206275. }
  206276. CGFunctionRelease (function);
  206277. return result;
  206278. }
  206279. void drawGradient()
  206280. {
  206281. flip();
  206282. applyTransform (state->fillType.transform);
  206283. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206284. // you draw a gradient with high quality interp enabled).
  206285. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206286. CGContextSetAlpha (context, state->fillType.getOpacity());
  206287. CGContextDrawShading (context, shading);
  206288. CGShadingRelease (shading);
  206289. }
  206290. void createPath (const Path& path) const
  206291. {
  206292. CGContextBeginPath (context);
  206293. Path::Iterator i (path);
  206294. while (i.next())
  206295. {
  206296. switch (i.elementType)
  206297. {
  206298. case Path::Iterator::startNewSubPath:
  206299. CGContextMoveToPoint (context, i.x1, i.y1);
  206300. break;
  206301. case Path::Iterator::lineTo:
  206302. CGContextAddLineToPoint (context, i.x1, i.y1);
  206303. break;
  206304. case Path::Iterator::quadraticTo:
  206305. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206306. break;
  206307. case Path::Iterator::cubicTo:
  206308. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206309. break;
  206310. case Path::Iterator::closePath:
  206311. CGContextClosePath (context); break;
  206312. default:
  206313. jassertfalse
  206314. break;
  206315. }
  206316. }
  206317. }
  206318. void createPath (const Path& path, const AffineTransform& transform) const
  206319. {
  206320. CGContextBeginPath (context);
  206321. Path::Iterator i (path);
  206322. while (i.next())
  206323. {
  206324. switch (i.elementType)
  206325. {
  206326. case Path::Iterator::startNewSubPath:
  206327. transform.transformPoint (i.x1, i.y1);
  206328. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206329. break;
  206330. case Path::Iterator::lineTo:
  206331. transform.transformPoint (i.x1, i.y1);
  206332. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206333. break;
  206334. case Path::Iterator::quadraticTo:
  206335. transform.transformPoint (i.x1, i.y1);
  206336. transform.transformPoint (i.x2, i.y2);
  206337. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206338. break;
  206339. case Path::Iterator::cubicTo:
  206340. transform.transformPoint (i.x1, i.y1);
  206341. transform.transformPoint (i.x2, i.y2);
  206342. transform.transformPoint (i.x3, i.y3);
  206343. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206344. break;
  206345. case Path::Iterator::closePath:
  206346. CGContextClosePath (context); break;
  206347. default:
  206348. jassertfalse
  206349. break;
  206350. }
  206351. }
  206352. }
  206353. static Image* createAlphaChannelImage (const Image& im)
  206354. {
  206355. if (im.getFormat() == Image::SingleChannel)
  206356. return const_cast <Image*> (&im);
  206357. return im.createCopyOfAlphaChannel();
  206358. }
  206359. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206360. {
  206361. if (im.getFormat() != Image::SingleChannel)
  206362. delete alphaIm;
  206363. }
  206364. void flip() const
  206365. {
  206366. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206367. }
  206368. void applyTransform (const AffineTransform& transform) const
  206369. {
  206370. CGAffineTransform t;
  206371. t.a = transform.mat00;
  206372. t.b = transform.mat10;
  206373. t.c = transform.mat01;
  206374. t.d = transform.mat11;
  206375. t.tx = transform.mat02;
  206376. t.ty = transform.mat12;
  206377. CGContextConcatCTM (context, t);
  206378. }
  206379. CoreGraphicsContext (const CoreGraphicsContext&);
  206380. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  206381. };
  206382. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206383. {
  206384. return new CoreGraphicsContext (context, imageHeight);
  206385. }
  206386. #endif
  206387. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206388. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206389. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206390. // compiled on its own).
  206391. #if JUCE_INCLUDED_FILE
  206392. class NSViewComponentPeer;
  206393. END_JUCE_NAMESPACE
  206394. #define JuceNSView MakeObjCClassName(JuceNSView)
  206395. @interface JuceNSView : NSView<NSTextInput>
  206396. {
  206397. @public
  206398. NSViewComponentPeer* owner;
  206399. NSNotificationCenter* notificationCenter;
  206400. String* stringBeingComposed;
  206401. bool textWasInserted;
  206402. }
  206403. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206404. - (void) dealloc;
  206405. - (BOOL) isOpaque;
  206406. - (void) drawRect: (NSRect) r;
  206407. - (void) mouseDown: (NSEvent*) ev;
  206408. - (void) asyncMouseDown: (NSEvent*) ev;
  206409. - (void) mouseUp: (NSEvent*) ev;
  206410. - (void) asyncMouseUp: (NSEvent*) ev;
  206411. - (void) mouseDragged: (NSEvent*) ev;
  206412. - (void) mouseMoved: (NSEvent*) ev;
  206413. - (void) mouseEntered: (NSEvent*) ev;
  206414. - (void) mouseExited: (NSEvent*) ev;
  206415. - (void) rightMouseDown: (NSEvent*) ev;
  206416. - (void) rightMouseDragged: (NSEvent*) ev;
  206417. - (void) rightMouseUp: (NSEvent*) ev;
  206418. - (void) otherMouseDown: (NSEvent*) ev;
  206419. - (void) otherMouseDragged: (NSEvent*) ev;
  206420. - (void) otherMouseUp: (NSEvent*) ev;
  206421. - (void) scrollWheel: (NSEvent*) ev;
  206422. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206423. - (void) frameChanged: (NSNotification*) n;
  206424. - (void) viewDidMoveToWindow;
  206425. - (void) keyDown: (NSEvent*) ev;
  206426. - (void) keyUp: (NSEvent*) ev;
  206427. // NSTextInput Methods
  206428. - (void) insertText: (id) aString;
  206429. - (void) doCommandBySelector: (SEL) aSelector;
  206430. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206431. - (void) unmarkText;
  206432. - (BOOL) hasMarkedText;
  206433. - (long) conversationIdentifier;
  206434. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206435. - (NSRange) markedRange;
  206436. - (NSRange) selectedRange;
  206437. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206438. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206439. - (NSArray*) validAttributesForMarkedText;
  206440. - (void) flagsChanged: (NSEvent*) ev;
  206441. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206442. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206443. #endif
  206444. - (BOOL) becomeFirstResponder;
  206445. - (BOOL) resignFirstResponder;
  206446. - (BOOL) acceptsFirstResponder;
  206447. - (void) asyncRepaint: (id) rect;
  206448. - (NSArray*) getSupportedDragTypes;
  206449. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206450. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206451. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206452. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206453. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206454. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206455. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206456. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206457. @end
  206458. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206459. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206460. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206461. #else
  206462. @interface JuceNSWindow : NSWindow
  206463. #endif
  206464. {
  206465. @private
  206466. NSViewComponentPeer* owner;
  206467. bool isZooming;
  206468. }
  206469. - (void) setOwner: (NSViewComponentPeer*) owner;
  206470. - (BOOL) canBecomeKeyWindow;
  206471. - (void) becomeKeyWindow;
  206472. - (BOOL) windowShouldClose: (id) window;
  206473. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206474. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206475. - (void) zoom: (id) sender;
  206476. @end
  206477. BEGIN_JUCE_NAMESPACE
  206478. class NSViewComponentPeer : public ComponentPeer
  206479. {
  206480. public:
  206481. NSViewComponentPeer (Component* const component,
  206482. const int windowStyleFlags,
  206483. NSView* viewToAttachTo);
  206484. ~NSViewComponentPeer();
  206485. void* getNativeHandle() const;
  206486. void setVisible (bool shouldBeVisible);
  206487. void setTitle (const String& title);
  206488. void setPosition (int x, int y);
  206489. void setSize (int w, int h);
  206490. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206491. const Rectangle<int> getBounds (const bool global) const;
  206492. const Rectangle<int> getBounds() const;
  206493. const Point<int> getScreenPosition() const;
  206494. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206495. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206496. void setMinimised (bool shouldBeMinimised);
  206497. bool isMinimised() const;
  206498. void setFullScreen (bool shouldBeFullScreen);
  206499. bool isFullScreen() const;
  206500. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206501. const BorderSize getFrameSize() const;
  206502. bool setAlwaysOnTop (bool alwaysOnTop);
  206503. void toFront (bool makeActiveWindow);
  206504. void toBehind (ComponentPeer* other);
  206505. void setIcon (const Image& newIcon);
  206506. const StringArray getAvailableRenderingEngines() throw();
  206507. int getCurrentRenderingEngine() throw();
  206508. void setCurrentRenderingEngine (int index) throw();
  206509. virtual void redirectMouseDown (NSEvent* ev);
  206510. virtual void redirectMouseUp (NSEvent* ev);
  206511. virtual void redirectMouseDrag (NSEvent* ev);
  206512. virtual void redirectMouseMove (NSEvent* ev);
  206513. virtual void redirectMouseEnter (NSEvent* ev);
  206514. virtual void redirectMouseExit (NSEvent* ev);
  206515. virtual void redirectMouseWheel (NSEvent* ev);
  206516. void sendMouseEvent (NSEvent* ev);
  206517. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206518. virtual bool redirectKeyDown (NSEvent* ev);
  206519. virtual bool redirectKeyUp (NSEvent* ev);
  206520. virtual void redirectModKeyChange (NSEvent* ev);
  206521. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206522. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206523. #endif
  206524. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206525. virtual bool isOpaque();
  206526. virtual void drawRect (NSRect r);
  206527. virtual bool canBecomeKeyWindow();
  206528. virtual bool windowShouldClose();
  206529. virtual void redirectMovedOrResized();
  206530. virtual void viewMovedToWindow();
  206531. virtual NSRect constrainRect (NSRect r);
  206532. static void showArrowCursorIfNeeded();
  206533. static void updateModifiers (NSEvent* e);
  206534. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206535. static int getKeyCodeFromEvent (NSEvent* ev)
  206536. {
  206537. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206538. int keyCode = unmodified[0];
  206539. if (keyCode == 0x19) // (backwards-tab)
  206540. keyCode = '\t';
  206541. else if (keyCode == 0x03) // (enter)
  206542. keyCode = '\r';
  206543. return keyCode;
  206544. }
  206545. static int64 getMouseTime (NSEvent* e)
  206546. {
  206547. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206548. + (int64) ([e timestamp] * 1000.0);
  206549. }
  206550. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206551. {
  206552. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206553. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206554. }
  206555. static int getModifierForButtonNumber (const NSInteger num)
  206556. {
  206557. return num == 0 ? ModifierKeys::leftButtonModifier
  206558. : (num == 1 ? ModifierKeys::rightButtonModifier
  206559. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206560. }
  206561. virtual void viewFocusGain();
  206562. virtual void viewFocusLoss();
  206563. bool isFocused() const;
  206564. void grabFocus();
  206565. void textInputRequired (const Point<int>& position);
  206566. void repaint (int x, int y, int w, int h);
  206567. void performAnyPendingRepaintsNow();
  206568. juce_UseDebuggingNewOperator
  206569. NSWindow* window;
  206570. JuceNSView* view;
  206571. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206572. static ModifierKeys currentModifiers;
  206573. static ComponentPeer* currentlyFocusedPeer;
  206574. static VoidArray keysCurrentlyDown;
  206575. };
  206576. END_JUCE_NAMESPACE
  206577. @implementation JuceNSView
  206578. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206579. withFrame: (NSRect) frame
  206580. {
  206581. [super initWithFrame: frame];
  206582. owner = owner_;
  206583. stringBeingComposed = 0;
  206584. textWasInserted = false;
  206585. notificationCenter = [NSNotificationCenter defaultCenter];
  206586. [notificationCenter addObserver: self
  206587. selector: @selector (frameChanged:)
  206588. name: NSViewFrameDidChangeNotification
  206589. object: self];
  206590. if (! owner_->isSharedWindow)
  206591. {
  206592. [notificationCenter addObserver: self
  206593. selector: @selector (frameChanged:)
  206594. name: NSWindowDidMoveNotification
  206595. object: owner_->window];
  206596. }
  206597. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206598. return self;
  206599. }
  206600. - (void) dealloc
  206601. {
  206602. [notificationCenter removeObserver: self];
  206603. delete stringBeingComposed;
  206604. [super dealloc];
  206605. }
  206606. - (void) drawRect: (NSRect) r
  206607. {
  206608. if (owner != 0)
  206609. owner->drawRect (r);
  206610. }
  206611. - (BOOL) isOpaque
  206612. {
  206613. return owner == 0 || owner->isOpaque();
  206614. }
  206615. - (void) mouseDown: (NSEvent*) ev
  206616. {
  206617. // In some host situations, the host will stop modal loops from working
  206618. // correctly if they're called from a mouse event, so we'll trigger
  206619. // the event asynchronously..
  206620. if (JUCEApplication::getInstance() == 0)
  206621. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206622. withObject: ev
  206623. waitUntilDone: NO];
  206624. else
  206625. [self asyncMouseDown: ev];
  206626. }
  206627. - (void) asyncMouseDown: (NSEvent*) ev
  206628. {
  206629. if (owner != 0)
  206630. owner->redirectMouseDown (ev);
  206631. }
  206632. - (void) mouseUp: (NSEvent*) ev
  206633. {
  206634. // In some host situations, the host will stop modal loops from working
  206635. // correctly if they're called from a mouse event, so we'll trigger
  206636. // the event asynchronously..
  206637. if (JUCEApplication::getInstance() == 0)
  206638. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206639. withObject: ev
  206640. waitUntilDone: NO];
  206641. else
  206642. [self asyncMouseUp: ev];
  206643. }
  206644. - (void) asyncMouseUp: (NSEvent*) ev
  206645. {
  206646. if (owner != 0)
  206647. owner->redirectMouseUp (ev);
  206648. }
  206649. - (void) mouseDragged: (NSEvent*) ev
  206650. {
  206651. if (owner != 0)
  206652. owner->redirectMouseDrag (ev);
  206653. }
  206654. - (void) mouseMoved: (NSEvent*) ev
  206655. {
  206656. if (owner != 0)
  206657. owner->redirectMouseMove (ev);
  206658. }
  206659. - (void) mouseEntered: (NSEvent*) ev
  206660. {
  206661. if (owner != 0)
  206662. owner->redirectMouseEnter (ev);
  206663. }
  206664. - (void) mouseExited: (NSEvent*) ev
  206665. {
  206666. if (owner != 0)
  206667. owner->redirectMouseExit (ev);
  206668. }
  206669. - (void) rightMouseDown: (NSEvent*) ev
  206670. {
  206671. [self mouseDown: ev];
  206672. }
  206673. - (void) rightMouseDragged: (NSEvent*) ev
  206674. {
  206675. [self mouseDragged: ev];
  206676. }
  206677. - (void) rightMouseUp: (NSEvent*) ev
  206678. {
  206679. [self mouseUp: ev];
  206680. }
  206681. - (void) otherMouseDown: (NSEvent*) ev
  206682. {
  206683. [self mouseDown: ev];
  206684. }
  206685. - (void) otherMouseDragged: (NSEvent*) ev
  206686. {
  206687. [self mouseDragged: ev];
  206688. }
  206689. - (void) otherMouseUp: (NSEvent*) ev
  206690. {
  206691. [self mouseUp: ev];
  206692. }
  206693. - (void) scrollWheel: (NSEvent*) ev
  206694. {
  206695. if (owner != 0)
  206696. owner->redirectMouseWheel (ev);
  206697. }
  206698. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206699. {
  206700. return YES;
  206701. }
  206702. - (void) frameChanged: (NSNotification*) n
  206703. {
  206704. if (owner != 0)
  206705. owner->redirectMovedOrResized();
  206706. }
  206707. - (void) viewDidMoveToWindow
  206708. {
  206709. if (owner != 0)
  206710. owner->viewMovedToWindow();
  206711. }
  206712. - (void) asyncRepaint: (id) rect
  206713. {
  206714. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206715. [self setNeedsDisplayInRect: *r];
  206716. }
  206717. - (void) keyDown: (NSEvent*) ev
  206718. {
  206719. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206720. textWasInserted = false;
  206721. if (target != 0)
  206722. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206723. else
  206724. deleteAndZero (stringBeingComposed);
  206725. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206726. [super keyDown: ev];
  206727. }
  206728. - (void) keyUp: (NSEvent*) ev
  206729. {
  206730. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206731. [super keyUp: ev];
  206732. }
  206733. - (void) insertText: (id) aString
  206734. {
  206735. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206736. if ([aString length] > 0)
  206737. {
  206738. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206739. if (target != 0)
  206740. {
  206741. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206742. textWasInserted = true;
  206743. }
  206744. }
  206745. deleteAndZero (stringBeingComposed);
  206746. }
  206747. - (void) doCommandBySelector: (SEL) aSelector
  206748. {
  206749. }
  206750. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206751. {
  206752. if (stringBeingComposed == 0)
  206753. stringBeingComposed = new String();
  206754. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206755. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206756. if (target != 0)
  206757. {
  206758. const Range<int> currentHighlight (target->getHighlightedRegion());
  206759. target->insertTextAtCaret (*stringBeingComposed);
  206760. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206761. textWasInserted = true;
  206762. }
  206763. }
  206764. - (void) unmarkText
  206765. {
  206766. if (stringBeingComposed != 0)
  206767. {
  206768. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206769. if (target != 0)
  206770. {
  206771. target->insertTextAtCaret (*stringBeingComposed);
  206772. textWasInserted = true;
  206773. }
  206774. }
  206775. deleteAndZero (stringBeingComposed);
  206776. }
  206777. - (BOOL) hasMarkedText
  206778. {
  206779. return stringBeingComposed != 0;
  206780. }
  206781. - (long) conversationIdentifier
  206782. {
  206783. return (long) (pointer_sized_int) self;
  206784. }
  206785. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206786. {
  206787. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206788. if (target != 0)
  206789. {
  206790. const Range<int> r ((int) theRange.location,
  206791. (int) (theRange.location + theRange.length));
  206792. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206793. }
  206794. return nil;
  206795. }
  206796. - (NSRange) markedRange
  206797. {
  206798. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206799. : NSMakeRange (NSNotFound, 0);
  206800. }
  206801. - (NSRange) selectedRange
  206802. {
  206803. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206804. if (target != 0)
  206805. {
  206806. const Range<int> highlight (target->getHighlightedRegion());
  206807. if (! highlight.isEmpty())
  206808. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206809. }
  206810. return NSMakeRange (NSNotFound, 0);
  206811. }
  206812. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206813. {
  206814. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206815. if (comp == 0)
  206816. return NSMakeRect (0, 0, 0, 0);
  206817. const Rectangle<int> bounds (comp->getScreenBounds());
  206818. return NSMakeRect (bounds.getX(),
  206819. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206820. bounds.getWidth(),
  206821. bounds.getHeight());
  206822. }
  206823. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206824. {
  206825. return NSNotFound;
  206826. }
  206827. - (NSArray*) validAttributesForMarkedText
  206828. {
  206829. return [NSArray array];
  206830. }
  206831. - (void) flagsChanged: (NSEvent*) ev
  206832. {
  206833. if (owner != 0)
  206834. owner->redirectModKeyChange (ev);
  206835. }
  206836. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206837. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206838. {
  206839. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206840. return true;
  206841. return [super performKeyEquivalent: ev];
  206842. }
  206843. #endif
  206844. - (BOOL) becomeFirstResponder
  206845. {
  206846. if (owner != 0)
  206847. owner->viewFocusGain();
  206848. return true;
  206849. }
  206850. - (BOOL) resignFirstResponder
  206851. {
  206852. if (owner != 0)
  206853. owner->viewFocusLoss();
  206854. return true;
  206855. }
  206856. - (BOOL) acceptsFirstResponder
  206857. {
  206858. return owner != 0 && owner->canBecomeKeyWindow();
  206859. }
  206860. - (NSArray*) getSupportedDragTypes
  206861. {
  206862. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206863. }
  206864. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206865. {
  206866. return owner != 0 && owner->sendDragCallback (type, sender);
  206867. }
  206868. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206869. {
  206870. if ([self sendDragCallback: 0 sender: sender])
  206871. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206872. else
  206873. return NSDragOperationNone;
  206874. }
  206875. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206876. {
  206877. if ([self sendDragCallback: 0 sender: sender])
  206878. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206879. else
  206880. return NSDragOperationNone;
  206881. }
  206882. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206883. {
  206884. [self sendDragCallback: 1 sender: sender];
  206885. }
  206886. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206887. {
  206888. [self sendDragCallback: 1 sender: sender];
  206889. }
  206890. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206891. {
  206892. return YES;
  206893. }
  206894. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206895. {
  206896. return [self sendDragCallback: 2 sender: sender];
  206897. }
  206898. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206899. {
  206900. }
  206901. @end
  206902. @implementation JuceNSWindow
  206903. - (void) setOwner: (NSViewComponentPeer*) owner_
  206904. {
  206905. owner = owner_;
  206906. isZooming = false;
  206907. }
  206908. - (BOOL) canBecomeKeyWindow
  206909. {
  206910. return owner != 0 && owner->canBecomeKeyWindow();
  206911. }
  206912. - (void) becomeKeyWindow
  206913. {
  206914. [super becomeKeyWindow];
  206915. if (owner != 0)
  206916. owner->grabFocus();
  206917. }
  206918. - (BOOL) windowShouldClose: (id) window
  206919. {
  206920. return owner == 0 || owner->windowShouldClose();
  206921. }
  206922. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206923. {
  206924. if (owner != 0)
  206925. frameRect = owner->constrainRect (frameRect);
  206926. return frameRect;
  206927. }
  206928. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206929. {
  206930. if (isZooming)
  206931. return proposedFrameSize;
  206932. NSRect frameRect = [self frame];
  206933. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206934. frameRect.size = proposedFrameSize;
  206935. if (owner != 0)
  206936. frameRect = owner->constrainRect (frameRect);
  206937. return frameRect.size;
  206938. }
  206939. - (void) zoom: (id) sender
  206940. {
  206941. isZooming = true;
  206942. [super zoom: sender];
  206943. isZooming = false;
  206944. }
  206945. - (void) windowWillMove: (NSNotification*) notification
  206946. {
  206947. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206948. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206949. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206950. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206951. }
  206952. @end
  206953. BEGIN_JUCE_NAMESPACE
  206954. ModifierKeys NSViewComponentPeer::currentModifiers;
  206955. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206956. VoidArray NSViewComponentPeer::keysCurrentlyDown;
  206957. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206958. {
  206959. if (NSViewComponentPeer::keysCurrentlyDown.contains ((void*) keyCode))
  206960. return true;
  206961. if (keyCode >= 'A' && keyCode <= 'Z'
  206962. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206963. return true;
  206964. if (keyCode >= 'a' && keyCode <= 'z'
  206965. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206966. return true;
  206967. return false;
  206968. }
  206969. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206970. {
  206971. int m = 0;
  206972. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206973. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206974. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  206975. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  206976. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  206977. }
  206978. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  206979. {
  206980. updateModifiers (ev);
  206981. int keyCode = getKeyCodeFromEvent (ev);
  206982. if (keyCode != 0)
  206983. {
  206984. if (isKeyDown)
  206985. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  206986. else
  206987. keysCurrentlyDown.removeValue ((void*) keyCode);
  206988. }
  206989. }
  206990. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  206991. {
  206992. return NSViewComponentPeer::currentModifiers;
  206993. }
  206994. void ModifierKeys::updateCurrentModifiers() throw()
  206995. {
  206996. currentModifiers = NSViewComponentPeer::currentModifiers;
  206997. }
  206998. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  206999. const int windowStyleFlags,
  207000. NSView* viewToAttachTo)
  207001. : ComponentPeer (component_, windowStyleFlags),
  207002. window (0),
  207003. view (0),
  207004. isSharedWindow (viewToAttachTo != 0),
  207005. fullScreen (false),
  207006. insideDrawRect (false),
  207007. #if USE_COREGRAPHICS_RENDERING
  207008. usingCoreGraphics (true),
  207009. #else
  207010. usingCoreGraphics (false),
  207011. #endif
  207012. recursiveToFrontCall (false)
  207013. {
  207014. NSRect r;
  207015. r.origin.x = 0;
  207016. r.origin.y = 0;
  207017. r.size.width = (float) component->getWidth();
  207018. r.size.height = (float) component->getHeight();
  207019. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207020. [view setPostsFrameChangedNotifications: YES];
  207021. if (isSharedWindow)
  207022. {
  207023. window = [viewToAttachTo window];
  207024. [viewToAttachTo addSubview: view];
  207025. setVisible (component->isVisible());
  207026. }
  207027. else
  207028. {
  207029. r.origin.x = (float) component->getX();
  207030. r.origin.y = (float) component->getY();
  207031. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207032. unsigned int style = 0;
  207033. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207034. style = NSBorderlessWindowMask;
  207035. else
  207036. style = NSTitledWindowMask;
  207037. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207038. style |= NSMiniaturizableWindowMask;
  207039. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207040. style |= NSClosableWindowMask;
  207041. if ((windowStyleFlags & windowIsResizable) != 0)
  207042. style |= NSResizableWindowMask;
  207043. window = [[JuceNSWindow alloc] initWithContentRect: r
  207044. styleMask: style
  207045. backing: NSBackingStoreBuffered
  207046. defer: YES];
  207047. [((JuceNSWindow*) window) setOwner: this];
  207048. [window orderOut: nil];
  207049. [window setDelegate: (JuceNSWindow*) window];
  207050. [window setOpaque: component->isOpaque()];
  207051. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207052. if (component->isAlwaysOnTop())
  207053. [window setLevel: NSFloatingWindowLevel];
  207054. [window setContentView: view];
  207055. [window setAutodisplay: YES];
  207056. [window setAcceptsMouseMovedEvents: YES];
  207057. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207058. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207059. [window setReleasedWhenClosed: YES];
  207060. [window retain];
  207061. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207062. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207063. }
  207064. setTitle (component->getName());
  207065. }
  207066. NSViewComponentPeer::~NSViewComponentPeer()
  207067. {
  207068. view->owner = 0;
  207069. [view removeFromSuperview];
  207070. [view release];
  207071. if (! isSharedWindow)
  207072. {
  207073. [((JuceNSWindow*) window) setOwner: 0];
  207074. [window close];
  207075. [window release];
  207076. }
  207077. }
  207078. void* NSViewComponentPeer::getNativeHandle() const
  207079. {
  207080. return view;
  207081. }
  207082. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207083. {
  207084. if (isSharedWindow)
  207085. {
  207086. [view setHidden: ! shouldBeVisible];
  207087. }
  207088. else
  207089. {
  207090. if (shouldBeVisible)
  207091. {
  207092. [window orderFront: nil];
  207093. handleBroughtToFront();
  207094. }
  207095. else
  207096. {
  207097. [window orderOut: nil];
  207098. }
  207099. }
  207100. }
  207101. void NSViewComponentPeer::setTitle (const String& title)
  207102. {
  207103. const ScopedAutoReleasePool pool;
  207104. if (! isSharedWindow)
  207105. [window setTitle: juceStringToNS (title)];
  207106. }
  207107. void NSViewComponentPeer::setPosition (int x, int y)
  207108. {
  207109. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207110. }
  207111. void NSViewComponentPeer::setSize (int w, int h)
  207112. {
  207113. setBounds (component->getX(), component->getY(), w, h, false);
  207114. }
  207115. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  207116. {
  207117. fullScreen = isNowFullScreen;
  207118. w = jmax (0, w);
  207119. h = jmax (0, h);
  207120. NSRect r;
  207121. r.origin.x = (float) x;
  207122. r.origin.y = (float) y;
  207123. r.size.width = (float) w;
  207124. r.size.height = (float) h;
  207125. if (isSharedWindow)
  207126. {
  207127. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207128. if ([view frame].size.width != r.size.width
  207129. || [view frame].size.height != r.size.height)
  207130. [view setNeedsDisplay: true];
  207131. [view setFrame: r];
  207132. }
  207133. else
  207134. {
  207135. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207136. [window setFrame: [window frameRectForContentRect: r]
  207137. display: true];
  207138. }
  207139. }
  207140. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207141. {
  207142. NSRect r = [view frame];
  207143. if (global && [view window] != 0)
  207144. {
  207145. r = [view convertRect: r toView: nil];
  207146. NSRect wr = [[view window] frame];
  207147. r.origin.x += wr.origin.x;
  207148. r.origin.y += wr.origin.y;
  207149. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207150. }
  207151. else
  207152. {
  207153. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207154. }
  207155. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207156. }
  207157. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207158. {
  207159. return getBounds (! isSharedWindow);
  207160. }
  207161. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207162. {
  207163. return getBounds (true).getPosition();
  207164. }
  207165. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207166. {
  207167. return relativePosition + getScreenPosition();
  207168. }
  207169. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207170. {
  207171. return screenPosition - getScreenPosition();
  207172. }
  207173. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207174. {
  207175. if (constrainer != 0)
  207176. {
  207177. NSRect current = [window frame];
  207178. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207179. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207180. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207181. (int) r.size.width, (int) r.size.height);
  207182. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207183. (int) current.size.width, (int) current.size.height);
  207184. constrainer->checkBounds (pos, original,
  207185. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207186. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207187. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207188. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207189. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207190. r.origin.x = pos.getX();
  207191. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207192. r.size.width = pos.getWidth();
  207193. r.size.height = pos.getHeight();
  207194. }
  207195. return r;
  207196. }
  207197. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207198. {
  207199. if (! isSharedWindow)
  207200. {
  207201. if (shouldBeMinimised)
  207202. [window miniaturize: nil];
  207203. else
  207204. [window deminiaturize: nil];
  207205. }
  207206. }
  207207. bool NSViewComponentPeer::isMinimised() const
  207208. {
  207209. return window != 0 && [window isMiniaturized];
  207210. }
  207211. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207212. {
  207213. if (! isSharedWindow)
  207214. {
  207215. Rectangle<int> r (lastNonFullscreenBounds);
  207216. setMinimised (false);
  207217. if (fullScreen != shouldBeFullScreen)
  207218. {
  207219. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207220. {
  207221. fullScreen = true;
  207222. [window performZoom: nil];
  207223. }
  207224. else
  207225. {
  207226. if (shouldBeFullScreen)
  207227. r = Desktop::getInstance().getMainMonitorArea();
  207228. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207229. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207230. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207231. }
  207232. }
  207233. }
  207234. }
  207235. bool NSViewComponentPeer::isFullScreen() const
  207236. {
  207237. return fullScreen;
  207238. }
  207239. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207240. {
  207241. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207242. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207243. return false;
  207244. NSPoint p;
  207245. p.x = (float) position.getX();
  207246. p.y = (float) position.getY();
  207247. NSView* v = [view hitTest: p];
  207248. if (trueIfInAChildWindow)
  207249. return v != nil;
  207250. return v == view;
  207251. }
  207252. const BorderSize NSViewComponentPeer::getFrameSize() const
  207253. {
  207254. BorderSize b;
  207255. if (! isSharedWindow)
  207256. {
  207257. NSRect v = [view convertRect: [view frame] toView: nil];
  207258. NSRect w = [window frame];
  207259. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207260. b.setBottom ((int) v.origin.y);
  207261. b.setLeft ((int) v.origin.x);
  207262. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207263. }
  207264. return b;
  207265. }
  207266. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207267. {
  207268. if (! isSharedWindow)
  207269. {
  207270. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207271. : NSNormalWindowLevel];
  207272. }
  207273. return true;
  207274. }
  207275. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207276. {
  207277. if (isSharedWindow)
  207278. {
  207279. [[view superview] addSubview: view
  207280. positioned: NSWindowAbove
  207281. relativeTo: nil];
  207282. }
  207283. if (window != 0 && component->isVisible())
  207284. {
  207285. if (makeActiveWindow)
  207286. [window makeKeyAndOrderFront: nil];
  207287. else
  207288. [window orderFront: nil];
  207289. if (! recursiveToFrontCall)
  207290. {
  207291. recursiveToFrontCall = true;
  207292. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207293. handleBroughtToFront();
  207294. recursiveToFrontCall = false;
  207295. }
  207296. }
  207297. }
  207298. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207299. {
  207300. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207301. if (isSharedWindow)
  207302. {
  207303. [[view superview] addSubview: view
  207304. positioned: NSWindowBelow
  207305. relativeTo: o->view];
  207306. }
  207307. else
  207308. {
  207309. [window orderWindow: NSWindowBelow
  207310. relativeTo: o->window != 0 ? [o->window windowNumber]
  207311. : nil ];
  207312. }
  207313. }
  207314. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207315. {
  207316. // to do..
  207317. }
  207318. void NSViewComponentPeer::viewFocusGain()
  207319. {
  207320. if (currentlyFocusedPeer != this)
  207321. {
  207322. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207323. currentlyFocusedPeer->handleFocusLoss();
  207324. currentlyFocusedPeer = this;
  207325. handleFocusGain();
  207326. }
  207327. }
  207328. void NSViewComponentPeer::viewFocusLoss()
  207329. {
  207330. if (currentlyFocusedPeer == this)
  207331. {
  207332. currentlyFocusedPeer = 0;
  207333. handleFocusLoss();
  207334. }
  207335. }
  207336. void juce_HandleProcessFocusChange()
  207337. {
  207338. NSViewComponentPeer::keysCurrentlyDown.clear();
  207339. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207340. {
  207341. if (Process::isForegroundProcess())
  207342. {
  207343. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207344. ComponentPeer::bringModalComponentToFront();
  207345. }
  207346. else
  207347. {
  207348. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207349. // turn kiosk mode off if we lose focus..
  207350. Desktop::getInstance().setKioskModeComponent (0);
  207351. }
  207352. }
  207353. }
  207354. bool NSViewComponentPeer::isFocused() const
  207355. {
  207356. return isSharedWindow ? this == currentlyFocusedPeer
  207357. : (window != 0 && [window isKeyWindow]);
  207358. }
  207359. void NSViewComponentPeer::grabFocus()
  207360. {
  207361. if (window != 0)
  207362. {
  207363. [window makeKeyWindow];
  207364. [window makeFirstResponder: view];
  207365. viewFocusGain();
  207366. }
  207367. }
  207368. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207369. {
  207370. }
  207371. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207372. {
  207373. String unicode (nsStringToJuce ([ev characters]));
  207374. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207375. int keyCode = getKeyCodeFromEvent (ev);
  207376. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207377. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207378. if (unicode.isNotEmpty() || keyCode != 0)
  207379. {
  207380. if (isKeyDown)
  207381. {
  207382. bool used = false;
  207383. while (unicode.length() > 0)
  207384. {
  207385. juce_wchar textCharacter = unicode[0];
  207386. unicode = unicode.substring (1);
  207387. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207388. textCharacter = 0;
  207389. used = handleKeyUpOrDown (true) || used;
  207390. used = handleKeyPress (keyCode, textCharacter) || used;
  207391. }
  207392. return used;
  207393. }
  207394. else
  207395. {
  207396. if (handleKeyUpOrDown (false))
  207397. return true;
  207398. }
  207399. }
  207400. return false;
  207401. }
  207402. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207403. {
  207404. updateKeysDown (ev, true);
  207405. bool used = handleKeyEvent (ev, true);
  207406. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207407. {
  207408. // for command keys, the key-up event is thrown away, so simulate one..
  207409. updateKeysDown (ev, false);
  207410. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207411. }
  207412. // (If we're running modally, don't allow unused keystrokes to be passed
  207413. // along to other blocked views..)
  207414. if (Component::getCurrentlyModalComponent() != 0)
  207415. used = true;
  207416. return used;
  207417. }
  207418. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207419. {
  207420. updateKeysDown (ev, false);
  207421. return handleKeyEvent (ev, false)
  207422. || Component::getCurrentlyModalComponent() != 0;
  207423. }
  207424. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207425. {
  207426. keysCurrentlyDown.clear();
  207427. handleKeyUpOrDown (true);
  207428. updateModifiers (ev);
  207429. handleModifierKeysChange();
  207430. }
  207431. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207432. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207433. {
  207434. if ([ev type] == NSKeyDown)
  207435. return redirectKeyDown (ev);
  207436. else if ([ev type] == NSKeyUp)
  207437. return redirectKeyUp (ev);
  207438. return false;
  207439. }
  207440. #endif
  207441. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207442. {
  207443. updateModifiers (ev);
  207444. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207445. }
  207446. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207447. {
  207448. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207449. sendMouseEvent (ev);
  207450. }
  207451. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207452. {
  207453. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207454. sendMouseEvent (ev);
  207455. showArrowCursorIfNeeded();
  207456. }
  207457. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207458. {
  207459. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207460. sendMouseEvent (ev);
  207461. }
  207462. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207463. {
  207464. currentModifiers = currentModifiers.withoutMouseButtons();
  207465. sendMouseEvent (ev);
  207466. showArrowCursorIfNeeded();
  207467. }
  207468. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207469. {
  207470. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207471. currentModifiers = currentModifiers.withoutMouseButtons();
  207472. sendMouseEvent (ev);
  207473. }
  207474. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207475. {
  207476. currentModifiers = currentModifiers.withoutMouseButtons();
  207477. sendMouseEvent (ev);
  207478. }
  207479. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207480. {
  207481. updateModifiers (ev);
  207482. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207483. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207484. }
  207485. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207486. {
  207487. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207488. if (mouse.getComponentUnderMouse() == 0
  207489. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207490. {
  207491. [[NSCursor arrowCursor] set];
  207492. }
  207493. }
  207494. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207495. {
  207496. NSString* bestType
  207497. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207498. if (bestType == nil)
  207499. return false;
  207500. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207501. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207502. StringArray files;
  207503. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207504. if (list == nil)
  207505. return false;
  207506. if ([list isKindOfClass: [NSArray class]])
  207507. {
  207508. NSArray* items = (NSArray*) list;
  207509. for (unsigned int i = 0; i < [items count]; ++i)
  207510. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207511. }
  207512. if (files.size() == 0)
  207513. return false;
  207514. if (type == 0)
  207515. handleFileDragMove (files, pos);
  207516. else if (type == 1)
  207517. handleFileDragExit (files);
  207518. else if (type == 2)
  207519. handleFileDragDrop (files, pos);
  207520. return true;
  207521. }
  207522. bool NSViewComponentPeer::isOpaque()
  207523. {
  207524. return component == 0 || component->isOpaque();
  207525. }
  207526. void NSViewComponentPeer::drawRect (NSRect r)
  207527. {
  207528. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207529. return;
  207530. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207531. if (! component->isOpaque())
  207532. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207533. #if USE_COREGRAPHICS_RENDERING
  207534. if (usingCoreGraphics)
  207535. {
  207536. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207537. insideDrawRect = true;
  207538. handlePaint (context);
  207539. insideDrawRect = false;
  207540. }
  207541. else
  207542. #endif
  207543. {
  207544. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207545. (int) (r.size.width + 0.5f),
  207546. (int) (r.size.height + 0.5f),
  207547. ! getComponent()->isOpaque());
  207548. LowLevelGraphicsSoftwareRenderer context (temp);
  207549. context.setOrigin (-roundToInt (r.origin.x),
  207550. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207551. const NSRect* rects = 0;
  207552. NSInteger numRects = 0;
  207553. [view getRectsBeingDrawn: &rects count: &numRects];
  207554. RectangleList clip;
  207555. for (int i = 0; i < numRects; ++i)
  207556. {
  207557. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207558. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207559. roundToInt (rects[i].size.width),
  207560. roundToInt (rects[i].size.height)));
  207561. }
  207562. if (context.clipToRectangleList (clip))
  207563. {
  207564. insideDrawRect = true;
  207565. handlePaint (context);
  207566. insideDrawRect = false;
  207567. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207568. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207569. CGColorSpaceRelease (colourSpace);
  207570. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207571. CGImageRelease (image);
  207572. }
  207573. }
  207574. }
  207575. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207576. {
  207577. StringArray s;
  207578. s.add ("Software Renderer");
  207579. #if USE_COREGRAPHICS_RENDERING
  207580. s.add ("CoreGraphics Renderer");
  207581. #endif
  207582. return s;
  207583. }
  207584. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207585. {
  207586. return usingCoreGraphics ? 1 : 0;
  207587. }
  207588. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207589. {
  207590. #if USE_COREGRAPHICS_RENDERING
  207591. if (usingCoreGraphics != (index > 0))
  207592. {
  207593. usingCoreGraphics = index > 0;
  207594. [view setNeedsDisplay: true];
  207595. }
  207596. #endif
  207597. }
  207598. bool NSViewComponentPeer::canBecomeKeyWindow()
  207599. {
  207600. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207601. }
  207602. bool NSViewComponentPeer::windowShouldClose()
  207603. {
  207604. if (! isValidPeer (this))
  207605. return YES;
  207606. handleUserClosingWindow();
  207607. return NO;
  207608. }
  207609. void NSViewComponentPeer::redirectMovedOrResized()
  207610. {
  207611. handleMovedOrResized();
  207612. }
  207613. void NSViewComponentPeer::viewMovedToWindow()
  207614. {
  207615. if (isSharedWindow)
  207616. window = [view window];
  207617. }
  207618. void Desktop::createMouseInputSources()
  207619. {
  207620. mouseSources.add (new MouseInputSource (0, true));
  207621. }
  207622. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207623. {
  207624. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207625. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207626. // is apparently still available in 64-bit apps..
  207627. if (enableOrDisable)
  207628. {
  207629. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207630. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207631. }
  207632. else
  207633. {
  207634. SetSystemUIMode (kUIModeNormal, 0);
  207635. }
  207636. }
  207637. class AsyncRepaintMessage : public CallbackMessage
  207638. {
  207639. public:
  207640. NSViewComponentPeer* const peer;
  207641. const Rectangle<int> rect;
  207642. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207643. : peer (peer_), rect (rect_)
  207644. {
  207645. }
  207646. void messageCallback()
  207647. {
  207648. if (ComponentPeer::isValidPeer (peer))
  207649. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207650. }
  207651. };
  207652. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207653. {
  207654. if (insideDrawRect)
  207655. {
  207656. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207657. }
  207658. else
  207659. {
  207660. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207661. (float) w, (float) h)];
  207662. }
  207663. }
  207664. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207665. {
  207666. [view displayIfNeeded];
  207667. }
  207668. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207669. {
  207670. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207671. }
  207672. Image* juce_createIconForFile (const File& file)
  207673. {
  207674. const ScopedAutoReleasePool pool;
  207675. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207676. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207677. [NSGraphicsContext saveGraphicsState];
  207678. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207679. [image drawAtPoint: NSMakePoint (0, 0)
  207680. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207681. operation: NSCompositeSourceOver fraction: 1.0f];
  207682. [[NSGraphicsContext currentContext] flushGraphics];
  207683. [NSGraphicsContext restoreGraphicsState];
  207684. return result;
  207685. }
  207686. const int KeyPress::spaceKey = ' ';
  207687. const int KeyPress::returnKey = 0x0d;
  207688. const int KeyPress::escapeKey = 0x1b;
  207689. const int KeyPress::backspaceKey = 0x7f;
  207690. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207691. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207692. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207693. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207694. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207695. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207696. const int KeyPress::endKey = NSEndFunctionKey;
  207697. const int KeyPress::homeKey = NSHomeFunctionKey;
  207698. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207699. const int KeyPress::insertKey = -1;
  207700. const int KeyPress::tabKey = 9;
  207701. const int KeyPress::F1Key = NSF1FunctionKey;
  207702. const int KeyPress::F2Key = NSF2FunctionKey;
  207703. const int KeyPress::F3Key = NSF3FunctionKey;
  207704. const int KeyPress::F4Key = NSF4FunctionKey;
  207705. const int KeyPress::F5Key = NSF5FunctionKey;
  207706. const int KeyPress::F6Key = NSF6FunctionKey;
  207707. const int KeyPress::F7Key = NSF7FunctionKey;
  207708. const int KeyPress::F8Key = NSF8FunctionKey;
  207709. const int KeyPress::F9Key = NSF9FunctionKey;
  207710. const int KeyPress::F10Key = NSF10FunctionKey;
  207711. const int KeyPress::F11Key = NSF1FunctionKey;
  207712. const int KeyPress::F12Key = NSF12FunctionKey;
  207713. const int KeyPress::F13Key = NSF13FunctionKey;
  207714. const int KeyPress::F14Key = NSF14FunctionKey;
  207715. const int KeyPress::F15Key = NSF15FunctionKey;
  207716. const int KeyPress::F16Key = NSF16FunctionKey;
  207717. const int KeyPress::numberPad0 = 0x30020;
  207718. const int KeyPress::numberPad1 = 0x30021;
  207719. const int KeyPress::numberPad2 = 0x30022;
  207720. const int KeyPress::numberPad3 = 0x30023;
  207721. const int KeyPress::numberPad4 = 0x30024;
  207722. const int KeyPress::numberPad5 = 0x30025;
  207723. const int KeyPress::numberPad6 = 0x30026;
  207724. const int KeyPress::numberPad7 = 0x30027;
  207725. const int KeyPress::numberPad8 = 0x30028;
  207726. const int KeyPress::numberPad9 = 0x30029;
  207727. const int KeyPress::numberPadAdd = 0x3002a;
  207728. const int KeyPress::numberPadSubtract = 0x3002b;
  207729. const int KeyPress::numberPadMultiply = 0x3002c;
  207730. const int KeyPress::numberPadDivide = 0x3002d;
  207731. const int KeyPress::numberPadSeparator = 0x3002e;
  207732. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207733. const int KeyPress::numberPadEquals = 0x30030;
  207734. const int KeyPress::numberPadDelete = 0x30031;
  207735. const int KeyPress::playKey = 0x30000;
  207736. const int KeyPress::stopKey = 0x30001;
  207737. const int KeyPress::fastForwardKey = 0x30002;
  207738. const int KeyPress::rewindKey = 0x30003;
  207739. #endif
  207740. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207741. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207742. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207743. // compiled on its own).
  207744. #if JUCE_INCLUDED_FILE
  207745. #if JUCE_MAC
  207746. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207747. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207748. {
  207749. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207750. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207751. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207752. [im release];
  207753. return (void*) c;
  207754. }
  207755. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207756. {
  207757. MemoryInputStream stream (data, size, false);
  207758. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207759. jassert (im != 0);
  207760. if (im == 0)
  207761. return 0;
  207762. return juce_createMouseCursorFromImage (*im,
  207763. (int) (hx * im->getWidth()),
  207764. (int) (hy * im->getHeight()));
  207765. }
  207766. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207767. {
  207768. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207769. MemoryBlock mb;
  207770. if (f.getChildFile (filename).loadFileAsData (mb))
  207771. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207772. return 0;
  207773. }
  207774. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207775. {
  207776. const ScopedAutoReleasePool pool;
  207777. NSCursor* c = 0;
  207778. switch (type)
  207779. {
  207780. case MouseCursor::NormalCursor:
  207781. c = [NSCursor arrowCursor];
  207782. break;
  207783. case MouseCursor::NoCursor:
  207784. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207785. case MouseCursor::DraggingHandCursor:
  207786. c = [NSCursor openHandCursor];
  207787. break;
  207788. case MouseCursor::CopyingCursor:
  207789. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207790. case MouseCursor::WaitCursor:
  207791. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207792. break;
  207793. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207794. case MouseCursor::IBeamCursor:
  207795. c = [NSCursor IBeamCursor];
  207796. break;
  207797. case MouseCursor::PointingHandCursor:
  207798. c = [NSCursor pointingHandCursor];
  207799. break;
  207800. case MouseCursor::LeftRightResizeCursor:
  207801. c = [NSCursor resizeLeftRightCursor];
  207802. break;
  207803. case MouseCursor::LeftEdgeResizeCursor:
  207804. c = [NSCursor resizeLeftCursor];
  207805. break;
  207806. case MouseCursor::RightEdgeResizeCursor:
  207807. c = [NSCursor resizeRightCursor];
  207808. break;
  207809. case MouseCursor::UpDownResizeCursor:
  207810. case MouseCursor::TopEdgeResizeCursor:
  207811. case MouseCursor::BottomEdgeResizeCursor:
  207812. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207813. case MouseCursor::TopLeftCornerResizeCursor:
  207814. case MouseCursor::BottomRightCornerResizeCursor:
  207815. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207816. case MouseCursor::TopRightCornerResizeCursor:
  207817. case MouseCursor::BottomLeftCornerResizeCursor:
  207818. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207819. case MouseCursor::UpDownLeftRightResizeCursor:
  207820. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207821. case MouseCursor::CrosshairCursor:
  207822. c = [NSCursor crosshairCursor];
  207823. break;
  207824. }
  207825. [c retain];
  207826. return (void*) c;
  207827. }
  207828. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207829. {
  207830. NSCursor* c = (NSCursor*) cursorHandle;
  207831. [c release];
  207832. }
  207833. void MouseCursor::showInAllWindows() const throw()
  207834. {
  207835. showInWindow (0);
  207836. }
  207837. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207838. {
  207839. NSCursor* const c = (NSCursor*) getHandle();
  207840. [c set];
  207841. }
  207842. #else
  207843. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207844. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207845. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207846. void MouseCursor::showInAllWindows() const throw() {}
  207847. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207848. #endif
  207849. #endif
  207850. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207851. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207852. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207853. // compiled on its own).
  207854. #if JUCE_INCLUDED_FILE
  207855. class NSViewComponentInternal : public ComponentMovementWatcher
  207856. {
  207857. Component* const owner;
  207858. NSViewComponentPeer* currentPeer;
  207859. bool wasShowing;
  207860. public:
  207861. NSView* const view;
  207862. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207863. : ComponentMovementWatcher (owner_),
  207864. owner (owner_),
  207865. currentPeer (0),
  207866. wasShowing (false),
  207867. view (view_)
  207868. {
  207869. [view_ retain];
  207870. if (owner_->isShowing())
  207871. componentPeerChanged();
  207872. }
  207873. ~NSViewComponentInternal()
  207874. {
  207875. [view removeFromSuperview];
  207876. [view release];
  207877. }
  207878. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207879. {
  207880. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207881. // The ComponentMovementWatcher version of this method avoids calling
  207882. // us when the top-level comp is resized, but for an NSView we need to know this
  207883. // because with inverted co-ords, we need to update the position even if the
  207884. // top-left pos hasn't changed
  207885. if (comp.isOnDesktop() && wasResized)
  207886. componentMovedOrResized (wasMoved, wasResized);
  207887. }
  207888. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207889. {
  207890. Component* const topComp = owner->getTopLevelComponent();
  207891. if (topComp->getPeer() != 0)
  207892. {
  207893. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207894. NSRect r;
  207895. r.origin.x = (float) pos.getX();
  207896. r.origin.y = (float) pos.getY();
  207897. r.size.width = (float) owner->getWidth();
  207898. r.size.height = (float) owner->getHeight();
  207899. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207900. [view setFrame: r];
  207901. }
  207902. }
  207903. void componentPeerChanged()
  207904. {
  207905. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207906. if (currentPeer != peer)
  207907. {
  207908. [view removeFromSuperview];
  207909. currentPeer = peer;
  207910. if (peer != 0)
  207911. {
  207912. [peer->view addSubview: view];
  207913. componentMovedOrResized (false, false);
  207914. }
  207915. }
  207916. [view setHidden: ! owner->isShowing()];
  207917. }
  207918. void componentVisibilityChanged (Component&)
  207919. {
  207920. componentPeerChanged();
  207921. }
  207922. juce_UseDebuggingNewOperator
  207923. private:
  207924. NSViewComponentInternal (const NSViewComponentInternal&);
  207925. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207926. };
  207927. NSViewComponent::NSViewComponent()
  207928. {
  207929. }
  207930. NSViewComponent::~NSViewComponent()
  207931. {
  207932. }
  207933. void NSViewComponent::setView (void* view)
  207934. {
  207935. if (view != getView())
  207936. {
  207937. if (view != 0)
  207938. info = new NSViewComponentInternal ((NSView*) view, this);
  207939. else
  207940. info = 0;
  207941. }
  207942. }
  207943. void* NSViewComponent::getView() const
  207944. {
  207945. return info == 0 ? 0 : info->view;
  207946. }
  207947. void NSViewComponent::paint (Graphics& g)
  207948. {
  207949. }
  207950. #endif
  207951. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207952. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207953. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207954. // compiled on its own).
  207955. #if JUCE_INCLUDED_FILE
  207956. AppleRemoteDevice::AppleRemoteDevice()
  207957. : device (0),
  207958. queue (0),
  207959. remoteId (0)
  207960. {
  207961. }
  207962. AppleRemoteDevice::~AppleRemoteDevice()
  207963. {
  207964. stop();
  207965. }
  207966. static io_object_t getAppleRemoteDevice()
  207967. {
  207968. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207969. io_iterator_t iter = 0;
  207970. io_object_t iod = 0;
  207971. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207972. && iter != 0)
  207973. {
  207974. iod = IOIteratorNext (iter);
  207975. }
  207976. IOObjectRelease (iter);
  207977. return iod;
  207978. }
  207979. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207980. {
  207981. jassert (*device == 0);
  207982. io_name_t classname;
  207983. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207984. {
  207985. IOCFPlugInInterface** cfPlugInInterface = 0;
  207986. SInt32 score = 0;
  207987. if (IOCreatePlugInInterfaceForService (iod,
  207988. kIOHIDDeviceUserClientTypeID,
  207989. kIOCFPlugInInterfaceID,
  207990. &cfPlugInInterface,
  207991. &score) == kIOReturnSuccess)
  207992. {
  207993. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  207994. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  207995. device);
  207996. (void) hr;
  207997. (*cfPlugInInterface)->Release (cfPlugInInterface);
  207998. }
  207999. }
  208000. return *device != 0;
  208001. }
  208002. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208003. {
  208004. if (queue != 0)
  208005. return true;
  208006. stop();
  208007. bool result = false;
  208008. io_object_t iod = getAppleRemoteDevice();
  208009. if (iod != 0)
  208010. {
  208011. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208012. result = true;
  208013. else
  208014. stop();
  208015. IOObjectRelease (iod);
  208016. }
  208017. return result;
  208018. }
  208019. void AppleRemoteDevice::stop()
  208020. {
  208021. if (queue != 0)
  208022. {
  208023. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208024. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208025. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208026. queue = 0;
  208027. }
  208028. if (device != 0)
  208029. {
  208030. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208031. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208032. device = 0;
  208033. }
  208034. }
  208035. bool AppleRemoteDevice::isActive() const
  208036. {
  208037. return queue != 0;
  208038. }
  208039. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208040. {
  208041. if (result == kIOReturnSuccess)
  208042. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208043. }
  208044. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208045. {
  208046. Array <int> cookies;
  208047. CFArrayRef elements;
  208048. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208049. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208050. return false;
  208051. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208052. {
  208053. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208054. // get the cookie
  208055. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208056. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208057. continue;
  208058. long number;
  208059. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208060. continue;
  208061. cookies.add ((int) number);
  208062. }
  208063. CFRelease (elements);
  208064. if ((*(IOHIDDeviceInterface**) device)
  208065. ->open ((IOHIDDeviceInterface**) device,
  208066. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208067. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208068. {
  208069. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208070. if (queue != 0)
  208071. {
  208072. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208073. for (int i = 0; i < cookies.size(); ++i)
  208074. {
  208075. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208076. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208077. }
  208078. CFRunLoopSourceRef eventSource;
  208079. if ((*(IOHIDQueueInterface**) queue)
  208080. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208081. {
  208082. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208083. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208084. {
  208085. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208086. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208087. return true;
  208088. }
  208089. }
  208090. }
  208091. }
  208092. return false;
  208093. }
  208094. void AppleRemoteDevice::handleCallbackInternal()
  208095. {
  208096. int totalValues = 0;
  208097. AbsoluteTime nullTime = { 0, 0 };
  208098. char cookies [12];
  208099. int numCookies = 0;
  208100. while (numCookies < numElementsInArray (cookies))
  208101. {
  208102. IOHIDEventStruct e;
  208103. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208104. break;
  208105. if ((int) e.elementCookie == 19)
  208106. {
  208107. remoteId = e.value;
  208108. buttonPressed (switched, false);
  208109. }
  208110. else
  208111. {
  208112. totalValues += e.value;
  208113. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208114. }
  208115. }
  208116. cookies [numCookies++] = 0;
  208117. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208118. static const char buttonPatterns[] =
  208119. {
  208120. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208121. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208122. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208123. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208124. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208125. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208126. 0x1f, 0x12, 0x04, 0x02, 0,
  208127. 0x1f, 0x12, 0x03, 0x02, 0,
  208128. 0x1f, 0x12, 0x1f, 0x12, 0,
  208129. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208130. 19, 0
  208131. };
  208132. int buttonNum = (int) menuButton;
  208133. int i = 0;
  208134. while (i < numElementsInArray (buttonPatterns))
  208135. {
  208136. if (strcmp (cookies, buttonPatterns + i) == 0)
  208137. {
  208138. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208139. break;
  208140. }
  208141. i += (int) strlen (buttonPatterns + i) + 1;
  208142. ++buttonNum;
  208143. }
  208144. }
  208145. #endif
  208146. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208147. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208148. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208149. // compiled on its own).
  208150. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208151. #if JUCE_MAC
  208152. END_JUCE_NAMESPACE
  208153. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208154. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208155. {
  208156. CriticalSection* contextLock;
  208157. bool needsUpdate;
  208158. }
  208159. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208160. - (bool) makeActive;
  208161. - (void) makeInactive;
  208162. - (void) reshape;
  208163. @end
  208164. @implementation ThreadSafeNSOpenGLView
  208165. - (id) initWithFrame: (NSRect) frameRect
  208166. pixelFormat: (NSOpenGLPixelFormat*) format
  208167. {
  208168. contextLock = new CriticalSection();
  208169. self = [super initWithFrame: frameRect pixelFormat: format];
  208170. if (self != nil)
  208171. [[NSNotificationCenter defaultCenter] addObserver: self
  208172. selector: @selector (_surfaceNeedsUpdate:)
  208173. name: NSViewGlobalFrameDidChangeNotification
  208174. object: self];
  208175. return self;
  208176. }
  208177. - (void) dealloc
  208178. {
  208179. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208180. delete contextLock;
  208181. [super dealloc];
  208182. }
  208183. - (bool) makeActive
  208184. {
  208185. const ScopedLock sl (*contextLock);
  208186. if ([self openGLContext] == 0)
  208187. return false;
  208188. [[self openGLContext] makeCurrentContext];
  208189. if (needsUpdate)
  208190. {
  208191. [super update];
  208192. needsUpdate = false;
  208193. }
  208194. return true;
  208195. }
  208196. - (void) makeInactive
  208197. {
  208198. const ScopedLock sl (*contextLock);
  208199. [NSOpenGLContext clearCurrentContext];
  208200. }
  208201. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208202. {
  208203. const ScopedLock sl (*contextLock);
  208204. needsUpdate = true;
  208205. }
  208206. - (void) update
  208207. {
  208208. const ScopedLock sl (*contextLock);
  208209. needsUpdate = true;
  208210. }
  208211. - (void) reshape
  208212. {
  208213. const ScopedLock sl (*contextLock);
  208214. needsUpdate = true;
  208215. }
  208216. @end
  208217. BEGIN_JUCE_NAMESPACE
  208218. class WindowedGLContext : public OpenGLContext
  208219. {
  208220. public:
  208221. WindowedGLContext (Component* const component,
  208222. const OpenGLPixelFormat& pixelFormat_,
  208223. NSOpenGLContext* sharedContext)
  208224. : renderContext (0),
  208225. pixelFormat (pixelFormat_)
  208226. {
  208227. jassert (component != 0);
  208228. NSOpenGLPixelFormatAttribute attribs [64];
  208229. int n = 0;
  208230. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208231. attribs[n++] = NSOpenGLPFAAccelerated;
  208232. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208233. attribs[n++] = NSOpenGLPFAColorSize;
  208234. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208235. pixelFormat.greenBits,
  208236. pixelFormat.blueBits);
  208237. attribs[n++] = NSOpenGLPFAAlphaSize;
  208238. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208239. attribs[n++] = NSOpenGLPFADepthSize;
  208240. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208241. attribs[n++] = NSOpenGLPFAStencilSize;
  208242. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208243. attribs[n++] = NSOpenGLPFAAccumSize;
  208244. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208245. pixelFormat.accumulationBufferGreenBits,
  208246. pixelFormat.accumulationBufferBlueBits,
  208247. pixelFormat.accumulationBufferAlphaBits);
  208248. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208249. attribs[n++] = NSOpenGLPFASampleBuffers;
  208250. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208251. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208252. attribs[n++] = NSOpenGLPFANoRecovery;
  208253. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208254. NSOpenGLPixelFormat* format
  208255. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208256. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208257. pixelFormat: format];
  208258. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208259. shareContext: sharedContext] autorelease];
  208260. const GLint swapInterval = 1;
  208261. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208262. [view setOpenGLContext: renderContext];
  208263. [renderContext setView: view];
  208264. [format release];
  208265. viewHolder = new NSViewComponentInternal (view, component);
  208266. }
  208267. ~WindowedGLContext()
  208268. {
  208269. makeInactive();
  208270. [renderContext clearDrawable];
  208271. viewHolder = 0;
  208272. }
  208273. bool makeActive() const throw()
  208274. {
  208275. jassert (renderContext != 0);
  208276. [view makeActive];
  208277. return isActive();
  208278. }
  208279. bool makeInactive() const throw()
  208280. {
  208281. [view makeInactive];
  208282. return true;
  208283. }
  208284. bool isActive() const throw()
  208285. {
  208286. return [NSOpenGLContext currentContext] == renderContext;
  208287. }
  208288. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208289. void* getRawContext() const throw() { return renderContext; }
  208290. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208291. {
  208292. }
  208293. void swapBuffers()
  208294. {
  208295. [renderContext flushBuffer];
  208296. }
  208297. bool setSwapInterval (const int numFramesPerSwap)
  208298. {
  208299. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208300. forParameter: NSOpenGLCPSwapInterval];
  208301. return true;
  208302. }
  208303. int getSwapInterval() const
  208304. {
  208305. GLint numFrames = 0;
  208306. [renderContext getValues: &numFrames
  208307. forParameter: NSOpenGLCPSwapInterval];
  208308. return numFrames;
  208309. }
  208310. void repaint()
  208311. {
  208312. // we need to invalidate the juce view that holds this gl view, to make it
  208313. // cause a repaint callback
  208314. NSView* v = (NSView*) viewHolder->view;
  208315. NSRect r = [v frame];
  208316. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208317. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208318. // repaint message, thus never causing our paint() callback, and never repainting
  208319. // the comp. So invalidating just a little bit around the edge helps..
  208320. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208321. }
  208322. void* getNativeWindowHandle() const { return viewHolder->view; }
  208323. juce_UseDebuggingNewOperator
  208324. NSOpenGLContext* renderContext;
  208325. ThreadSafeNSOpenGLView* view;
  208326. private:
  208327. OpenGLPixelFormat pixelFormat;
  208328. ScopedPointer <NSViewComponentInternal> viewHolder;
  208329. WindowedGLContext (const WindowedGLContext&);
  208330. WindowedGLContext& operator= (const WindowedGLContext&);
  208331. };
  208332. OpenGLContext* OpenGLComponent::createContext()
  208333. {
  208334. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  208335. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  208336. return (c->renderContext != 0) ? c.release() : 0;
  208337. }
  208338. void* OpenGLComponent::getNativeWindowHandle() const
  208339. {
  208340. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  208341. : 0;
  208342. }
  208343. void juce_glViewport (const int w, const int h)
  208344. {
  208345. glViewport (0, 0, w, h);
  208346. }
  208347. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208348. OwnedArray <OpenGLPixelFormat>& results)
  208349. {
  208350. /* GLint attribs [64];
  208351. int n = 0;
  208352. attribs[n++] = AGL_RGBA;
  208353. attribs[n++] = AGL_DOUBLEBUFFER;
  208354. attribs[n++] = AGL_ACCELERATED;
  208355. attribs[n++] = AGL_NO_RECOVERY;
  208356. attribs[n++] = AGL_NONE;
  208357. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208358. while (p != 0)
  208359. {
  208360. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208361. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208362. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208363. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208364. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208365. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208366. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208367. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208368. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208369. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208370. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208371. results.add (pf);
  208372. p = aglNextPixelFormat (p);
  208373. }*/
  208374. //jassertfalse //xxx can't see how you do this in cocoa!
  208375. }
  208376. #else
  208377. END_JUCE_NAMESPACE
  208378. @interface JuceGLView : UIView
  208379. {
  208380. }
  208381. + (Class) layerClass;
  208382. @end
  208383. @implementation JuceGLView
  208384. + (Class) layerClass
  208385. {
  208386. return [CAEAGLLayer class];
  208387. }
  208388. @end
  208389. BEGIN_JUCE_NAMESPACE
  208390. class GLESContext : public OpenGLContext
  208391. {
  208392. public:
  208393. GLESContext (UIViewComponentPeer* peer,
  208394. Component* const component_,
  208395. const OpenGLPixelFormat& pixelFormat_,
  208396. const GLESContext* const sharedContext,
  208397. NSUInteger apiType)
  208398. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  208399. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  208400. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  208401. {
  208402. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  208403. view.opaque = YES;
  208404. view.hidden = NO;
  208405. view.backgroundColor = [UIColor blackColor];
  208406. view.userInteractionEnabled = NO;
  208407. glLayer = (CAEAGLLayer*) [view layer];
  208408. [peer->view addSubview: view];
  208409. if (sharedContext != 0)
  208410. context = [[EAGLContext alloc] initWithAPI: apiType
  208411. sharegroup: [sharedContext->context sharegroup]];
  208412. else
  208413. context = [[EAGLContext alloc] initWithAPI: apiType];
  208414. createGLBuffers();
  208415. }
  208416. ~GLESContext()
  208417. {
  208418. makeInactive();
  208419. [context release];
  208420. [view removeFromSuperview];
  208421. [view release];
  208422. freeGLBuffers();
  208423. }
  208424. bool makeActive() const throw()
  208425. {
  208426. jassert (context != 0);
  208427. [EAGLContext setCurrentContext: context];
  208428. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208429. return true;
  208430. }
  208431. void swapBuffers()
  208432. {
  208433. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208434. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  208435. }
  208436. bool makeInactive() const throw()
  208437. {
  208438. return [EAGLContext setCurrentContext: nil];
  208439. }
  208440. bool isActive() const throw()
  208441. {
  208442. return [EAGLContext currentContext] == context;
  208443. }
  208444. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208445. void* getRawContext() const throw() { return (void*) glLayer; }
  208446. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208447. {
  208448. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  208449. if (lastWidth != w || lastHeight != h)
  208450. {
  208451. lastWidth = w;
  208452. lastHeight = h;
  208453. freeGLBuffers();
  208454. createGLBuffers();
  208455. }
  208456. }
  208457. bool setSwapInterval (const int numFramesPerSwap)
  208458. {
  208459. numFrames = numFramesPerSwap;
  208460. return true;
  208461. }
  208462. int getSwapInterval() const
  208463. {
  208464. return numFrames;
  208465. }
  208466. void repaint()
  208467. {
  208468. }
  208469. void createGLBuffers()
  208470. {
  208471. makeActive();
  208472. glGenFramebuffersOES (1, &frameBufferHandle);
  208473. glGenRenderbuffersOES (1, &colorBufferHandle);
  208474. glGenRenderbuffersOES (1, &depthBufferHandle);
  208475. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208476. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  208477. GLint width, height;
  208478. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  208479. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  208480. if (useDepthBuffer)
  208481. {
  208482. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  208483. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  208484. }
  208485. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208486. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208487. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  208488. if (useDepthBuffer)
  208489. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  208490. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  208491. }
  208492. void freeGLBuffers()
  208493. {
  208494. if (frameBufferHandle != 0)
  208495. {
  208496. glDeleteFramebuffersOES (1, &frameBufferHandle);
  208497. frameBufferHandle = 0;
  208498. }
  208499. if (colorBufferHandle != 0)
  208500. {
  208501. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  208502. colorBufferHandle = 0;
  208503. }
  208504. if (depthBufferHandle != 0)
  208505. {
  208506. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  208507. depthBufferHandle = 0;
  208508. }
  208509. }
  208510. juce_UseDebuggingNewOperator
  208511. private:
  208512. Component::SafePointer<Component> component;
  208513. OpenGLPixelFormat pixelFormat;
  208514. JuceGLView* view;
  208515. CAEAGLLayer* glLayer;
  208516. EAGLContext* context;
  208517. bool useDepthBuffer;
  208518. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  208519. int numFrames;
  208520. int lastWidth, lastHeight;
  208521. GLESContext (const GLESContext&);
  208522. GLESContext& operator= (const GLESContext&);
  208523. };
  208524. OpenGLContext* OpenGLComponent::createContext()
  208525. {
  208526. ScopedAutoReleasePool pool;
  208527. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  208528. if (peer != 0)
  208529. return new GLESContext (peer, this, preferredPixelFormat,
  208530. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  208531. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  208532. return 0;
  208533. }
  208534. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208535. OwnedArray <OpenGLPixelFormat>& /*results*/)
  208536. {
  208537. }
  208538. void juce_glViewport (const int w, const int h)
  208539. {
  208540. glViewport (0, 0, w, h);
  208541. }
  208542. #endif
  208543. #endif
  208544. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208545. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208546. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208547. // compiled on its own).
  208548. #if JUCE_INCLUDED_FILE
  208549. class JuceMainMenuHandler;
  208550. END_JUCE_NAMESPACE
  208551. using namespace JUCE_NAMESPACE;
  208552. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208553. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208554. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208555. #else
  208556. @interface JuceMenuCallback : NSObject
  208557. #endif
  208558. {
  208559. JuceMainMenuHandler* owner;
  208560. }
  208561. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208562. - (void) dealloc;
  208563. - (void) menuItemInvoked: (id) menu;
  208564. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208565. @end
  208566. BEGIN_JUCE_NAMESPACE
  208567. class JuceMainMenuHandler : private MenuBarModelListener,
  208568. private DeletedAtShutdown
  208569. {
  208570. public:
  208571. static JuceMainMenuHandler* instance;
  208572. JuceMainMenuHandler()
  208573. : currentModel (0),
  208574. lastUpdateTime (0)
  208575. {
  208576. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208577. }
  208578. ~JuceMainMenuHandler()
  208579. {
  208580. setMenu (0);
  208581. jassert (instance == this);
  208582. instance = 0;
  208583. [callback release];
  208584. }
  208585. void setMenu (MenuBarModel* const newMenuBarModel)
  208586. {
  208587. if (currentModel != newMenuBarModel)
  208588. {
  208589. if (currentModel != 0)
  208590. currentModel->removeListener (this);
  208591. currentModel = newMenuBarModel;
  208592. if (currentModel != 0)
  208593. currentModel->addListener (this);
  208594. menuBarItemsChanged (0);
  208595. }
  208596. }
  208597. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208598. const String& name, const int menuId, const int tag)
  208599. {
  208600. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208601. action: nil
  208602. keyEquivalent: @""];
  208603. [item setTag: tag];
  208604. NSMenu* sub = createMenu (child, name, menuId, tag);
  208605. [parent setSubmenu: sub forItem: item];
  208606. [sub setAutoenablesItems: false];
  208607. [sub release];
  208608. }
  208609. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208610. const String& name, const int menuId, const int tag)
  208611. {
  208612. [parentItem setTag: tag];
  208613. NSMenu* menu = [parentItem submenu];
  208614. [menu setTitle: juceStringToNS (name)];
  208615. while ([menu numberOfItems] > 0)
  208616. [menu removeItemAtIndex: 0];
  208617. PopupMenu::MenuItemIterator iter (menuToCopy);
  208618. while (iter.next())
  208619. addMenuItem (iter, menu, menuId, tag);
  208620. [menu setAutoenablesItems: false];
  208621. [menu update];
  208622. }
  208623. void menuBarItemsChanged (MenuBarModel*)
  208624. {
  208625. lastUpdateTime = Time::getMillisecondCounter();
  208626. StringArray menuNames;
  208627. if (currentModel != 0)
  208628. menuNames = currentModel->getMenuBarNames();
  208629. NSMenu* menuBar = [NSApp mainMenu];
  208630. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208631. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208632. int menuId = 1;
  208633. for (int i = 0; i < menuNames.size(); ++i)
  208634. {
  208635. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208636. if (i >= [menuBar numberOfItems] - 1)
  208637. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208638. else
  208639. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208640. }
  208641. }
  208642. static void flashMenuBar (NSMenu* menu)
  208643. {
  208644. if ([[menu title] isEqualToString: @"Apple"])
  208645. return;
  208646. [menu retain];
  208647. const unichar f35Key = NSF35FunctionKey;
  208648. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208649. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208650. action: nil
  208651. keyEquivalent: f35String];
  208652. [item setTarget: nil];
  208653. [menu insertItem: item atIndex: [menu numberOfItems]];
  208654. [item release];
  208655. if ([menu indexOfItem: item] >= 0)
  208656. {
  208657. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208658. location: NSZeroPoint
  208659. modifierFlags: NSCommandKeyMask
  208660. timestamp: 0
  208661. windowNumber: 0
  208662. context: [NSGraphicsContext currentContext]
  208663. characters: f35String
  208664. charactersIgnoringModifiers: f35String
  208665. isARepeat: NO
  208666. keyCode: 0];
  208667. [menu performKeyEquivalent: f35Event];
  208668. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208669. }
  208670. [menu release];
  208671. }
  208672. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208673. {
  208674. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208675. {
  208676. NSMenuItem* m = [menu itemAtIndex: i];
  208677. if ([m tag] == info.commandID)
  208678. return m;
  208679. if ([m submenu] != 0)
  208680. {
  208681. NSMenuItem* found = findMenuItem ([m submenu], info);
  208682. if (found != 0)
  208683. return found;
  208684. }
  208685. }
  208686. return 0;
  208687. }
  208688. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208689. {
  208690. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208691. if (item != 0)
  208692. flashMenuBar ([item menu]);
  208693. }
  208694. void updateMenus()
  208695. {
  208696. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208697. menuBarItemsChanged (0);
  208698. }
  208699. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208700. {
  208701. if (currentModel != 0)
  208702. {
  208703. if (commandManager != 0)
  208704. {
  208705. ApplicationCommandTarget::InvocationInfo info (commandId);
  208706. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208707. commandManager->invoke (info, true);
  208708. }
  208709. currentModel->menuItemSelected (commandId, topLevelIndex);
  208710. }
  208711. }
  208712. MenuBarModel* currentModel;
  208713. uint32 lastUpdateTime;
  208714. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208715. const int topLevelMenuId, const int topLevelIndex)
  208716. {
  208717. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf ("<end>", false, true));
  208718. if (text == 0)
  208719. text = @"";
  208720. if (iter.isSeparator)
  208721. {
  208722. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208723. }
  208724. else if (iter.isSectionHeader)
  208725. {
  208726. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208727. action: nil
  208728. keyEquivalent: @""];
  208729. [item setEnabled: false];
  208730. }
  208731. else if (iter.subMenu != 0)
  208732. {
  208733. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208734. action: nil
  208735. keyEquivalent: @""];
  208736. [item setTag: iter.itemId];
  208737. [item setEnabled: iter.isEnabled];
  208738. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208739. [sub setDelegate: nil];
  208740. [menuToAddTo setSubmenu: sub forItem: item];
  208741. [sub release];
  208742. }
  208743. else
  208744. {
  208745. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208746. action: @selector (menuItemInvoked:)
  208747. keyEquivalent: @""];
  208748. [item setTag: iter.itemId];
  208749. [item setEnabled: iter.isEnabled];
  208750. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208751. [item setTarget: (id) callback];
  208752. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208753. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208754. [item setRepresentedObject: info];
  208755. if (iter.commandManager != 0)
  208756. {
  208757. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208758. ->getKeyPressesAssignedToCommand (iter.itemId));
  208759. if (keyPresses.size() > 0)
  208760. {
  208761. const KeyPress& kp = keyPresses.getReference(0);
  208762. juce_wchar key = kp.getTextCharacter();
  208763. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208764. key = NSBackspaceCharacter;
  208765. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208766. key = NSDeleteCharacter;
  208767. else if (key == 0)
  208768. key = (juce_wchar) kp.getKeyCode();
  208769. unsigned int mods = 0;
  208770. if (kp.getModifiers().isShiftDown())
  208771. mods |= NSShiftKeyMask;
  208772. if (kp.getModifiers().isCtrlDown())
  208773. mods |= NSControlKeyMask;
  208774. if (kp.getModifiers().isAltDown())
  208775. mods |= NSAlternateKeyMask;
  208776. if (kp.getModifiers().isCommandDown())
  208777. mods |= NSCommandKeyMask;
  208778. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208779. [item setKeyEquivalentModifierMask: mods];
  208780. }
  208781. }
  208782. }
  208783. }
  208784. JuceMenuCallback* callback;
  208785. private:
  208786. NSMenu* createMenu (const PopupMenu menu,
  208787. const String& menuName,
  208788. const int topLevelMenuId,
  208789. const int topLevelIndex)
  208790. {
  208791. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208792. [m setAutoenablesItems: false];
  208793. [m setDelegate: callback];
  208794. PopupMenu::MenuItemIterator iter (menu);
  208795. while (iter.next())
  208796. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208797. [m update];
  208798. return m;
  208799. }
  208800. };
  208801. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208802. END_JUCE_NAMESPACE
  208803. @implementation JuceMenuCallback
  208804. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208805. {
  208806. [super init];
  208807. owner = owner_;
  208808. return self;
  208809. }
  208810. - (void) dealloc
  208811. {
  208812. [super dealloc];
  208813. }
  208814. - (void) menuItemInvoked: (id) menu
  208815. {
  208816. NSMenuItem* item = (NSMenuItem*) menu;
  208817. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208818. {
  208819. // 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
  208820. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208821. // into the focused component and let it trigger the menu item indirectly.
  208822. NSEvent* e = [NSApp currentEvent];
  208823. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208824. {
  208825. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208826. {
  208827. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208828. if (peer != 0)
  208829. {
  208830. if ([e type] == NSKeyDown)
  208831. peer->redirectKeyDown (e);
  208832. else
  208833. peer->redirectKeyUp (e);
  208834. return;
  208835. }
  208836. }
  208837. }
  208838. NSArray* info = (NSArray*) [item representedObject];
  208839. owner->invoke ((int) [item tag],
  208840. (ApplicationCommandManager*) (pointer_sized_int)
  208841. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208842. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208843. }
  208844. }
  208845. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208846. {
  208847. if (JuceMainMenuHandler::instance != 0)
  208848. JuceMainMenuHandler::instance->updateMenus();
  208849. }
  208850. @end
  208851. BEGIN_JUCE_NAMESPACE
  208852. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208853. const PopupMenu* extraItems)
  208854. {
  208855. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208856. {
  208857. PopupMenu::MenuItemIterator iter (*extraItems);
  208858. while (iter.next())
  208859. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208860. [menu addItem: [NSMenuItem separatorItem]];
  208861. }
  208862. NSMenuItem* item;
  208863. // Services...
  208864. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208865. action: nil keyEquivalent: @""];
  208866. [menu addItem: item];
  208867. [item release];
  208868. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208869. [menu setSubmenu: servicesMenu forItem: item];
  208870. [NSApp setServicesMenu: servicesMenu];
  208871. [servicesMenu release];
  208872. [menu addItem: [NSMenuItem separatorItem]];
  208873. // Hide + Show stuff...
  208874. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208875. action: @selector (hide:) keyEquivalent: @"h"];
  208876. [item setTarget: NSApp];
  208877. [menu addItem: item];
  208878. [item release];
  208879. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208880. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208881. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208882. [item setTarget: NSApp];
  208883. [menu addItem: item];
  208884. [item release];
  208885. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208886. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208887. [item setTarget: NSApp];
  208888. [menu addItem: item];
  208889. [item release];
  208890. [menu addItem: [NSMenuItem separatorItem]];
  208891. // Quit item....
  208892. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208893. action: @selector (terminate:) keyEquivalent: @"q"];
  208894. [item setTarget: NSApp];
  208895. [menu addItem: item];
  208896. [item release];
  208897. return menu;
  208898. }
  208899. // Since our app has no NIB, this initialises a standard app menu...
  208900. static void rebuildMainMenu (const PopupMenu* extraItems)
  208901. {
  208902. // this can't be used in a plugin!
  208903. jassert (JUCEApplication::getInstance() != 0);
  208904. if (JUCEApplication::getInstance() != 0)
  208905. {
  208906. const ScopedAutoReleasePool pool;
  208907. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208908. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208909. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208910. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208911. [mainMenu setSubmenu: appMenu forItem: item];
  208912. [NSApp setMainMenu: mainMenu];
  208913. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208914. [appMenu release];
  208915. [mainMenu release];
  208916. }
  208917. }
  208918. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208919. const PopupMenu* extraAppleMenuItems)
  208920. {
  208921. if (getMacMainMenu() != newMenuBarModel)
  208922. {
  208923. const ScopedAutoReleasePool pool;
  208924. if (newMenuBarModel == 0)
  208925. {
  208926. delete JuceMainMenuHandler::instance;
  208927. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208928. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208929. extraAppleMenuItems = 0;
  208930. }
  208931. else
  208932. {
  208933. if (JuceMainMenuHandler::instance == 0)
  208934. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208935. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208936. }
  208937. }
  208938. rebuildMainMenu (extraAppleMenuItems);
  208939. if (newMenuBarModel != 0)
  208940. newMenuBarModel->menuItemsChanged();
  208941. }
  208942. MenuBarModel* MenuBarModel::getMacMainMenu()
  208943. {
  208944. return JuceMainMenuHandler::instance != 0
  208945. ? JuceMainMenuHandler::instance->currentModel : 0;
  208946. }
  208947. void initialiseMainMenu()
  208948. {
  208949. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208950. rebuildMainMenu (0);
  208951. }
  208952. #endif
  208953. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208954. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208955. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208956. // compiled on its own).
  208957. #if JUCE_INCLUDED_FILE
  208958. #if JUCE_MAC
  208959. END_JUCE_NAMESPACE
  208960. using namespace JUCE_NAMESPACE;
  208961. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208962. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208963. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208964. #else
  208965. @interface JuceFileChooserDelegate : NSObject
  208966. #endif
  208967. {
  208968. StringArray* filters;
  208969. }
  208970. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208971. - (void) dealloc;
  208972. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208973. @end
  208974. @implementation JuceFileChooserDelegate
  208975. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208976. {
  208977. [super init];
  208978. filters = filters_;
  208979. return self;
  208980. }
  208981. - (void) dealloc
  208982. {
  208983. delete filters;
  208984. [super dealloc];
  208985. }
  208986. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208987. {
  208988. const File f (nsStringToJuce (filename));
  208989. for (int i = filters->size(); --i >= 0;)
  208990. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208991. return true;
  208992. return f.isDirectory();
  208993. }
  208994. @end
  208995. BEGIN_JUCE_NAMESPACE
  208996. void FileChooser::showPlatformDialog (Array<File>& results,
  208997. const String& title,
  208998. const File& currentFileOrDirectory,
  208999. const String& filter,
  209000. bool selectsDirectory,
  209001. bool selectsFiles,
  209002. bool isSaveDialogue,
  209003. bool warnAboutOverwritingExistingFiles,
  209004. bool selectMultipleFiles,
  209005. FilePreviewComponent* extraInfoComponent)
  209006. {
  209007. const ScopedAutoReleasePool pool;
  209008. StringArray* filters = new StringArray();
  209009. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  209010. filters->trim();
  209011. filters->removeEmptyStrings();
  209012. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  209013. [delegate autorelease];
  209014. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  209015. : [NSOpenPanel openPanel];
  209016. [panel setTitle: juceStringToNS (title)];
  209017. if (! isSaveDialogue)
  209018. {
  209019. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209020. [openPanel setCanChooseDirectories: selectsDirectory];
  209021. [openPanel setCanChooseFiles: selectsFiles];
  209022. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  209023. }
  209024. [panel setDelegate: delegate];
  209025. if (isSaveDialogue || selectsDirectory)
  209026. [panel setCanCreateDirectories: YES];
  209027. String directory, filename;
  209028. if (currentFileOrDirectory.isDirectory())
  209029. {
  209030. directory = currentFileOrDirectory.getFullPathName();
  209031. }
  209032. else
  209033. {
  209034. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  209035. filename = currentFileOrDirectory.getFileName();
  209036. }
  209037. if ([panel runModalForDirectory: juceStringToNS (directory)
  209038. file: juceStringToNS (filename)]
  209039. == NSOKButton)
  209040. {
  209041. if (isSaveDialogue)
  209042. {
  209043. results.add (File (nsStringToJuce ([panel filename])));
  209044. }
  209045. else
  209046. {
  209047. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209048. NSArray* urls = [openPanel filenames];
  209049. for (unsigned int i = 0; i < [urls count]; ++i)
  209050. {
  209051. NSString* f = [urls objectAtIndex: i];
  209052. results.add (File (nsStringToJuce (f)));
  209053. }
  209054. }
  209055. }
  209056. [panel setDelegate: nil];
  209057. }
  209058. #else
  209059. void FileChooser::showPlatformDialog (Array<File>& results,
  209060. const String& title,
  209061. const File& currentFileOrDirectory,
  209062. const String& filter,
  209063. bool selectsDirectory,
  209064. bool selectsFiles,
  209065. bool isSaveDialogue,
  209066. bool warnAboutOverwritingExistingFiles,
  209067. bool selectMultipleFiles,
  209068. FilePreviewComponent* extraInfoComponent)
  209069. {
  209070. const ScopedAutoReleasePool pool;
  209071. jassertfalse //xxx to do
  209072. }
  209073. #endif
  209074. #endif
  209075. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209076. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209077. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209078. // compiled on its own).
  209079. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209080. END_JUCE_NAMESPACE
  209081. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  209082. @interface NonInterceptingQTMovieView : QTMovieView
  209083. {
  209084. }
  209085. - (id) initWithFrame: (NSRect) frame;
  209086. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  209087. - (NSView*) hitTest: (NSPoint) p;
  209088. @end
  209089. @implementation NonInterceptingQTMovieView
  209090. - (id) initWithFrame: (NSRect) frame
  209091. {
  209092. self = [super initWithFrame: frame];
  209093. [self setNextResponder: [self superview]];
  209094. return self;
  209095. }
  209096. - (void) dealloc
  209097. {
  209098. [super dealloc];
  209099. }
  209100. - (NSView*) hitTest: (NSPoint) point
  209101. {
  209102. return [self isControllerVisible] ? [super hitTest: point] : nil;
  209103. }
  209104. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  209105. {
  209106. return YES;
  209107. }
  209108. @end
  209109. BEGIN_JUCE_NAMESPACE
  209110. #define theMovie (static_cast <QTMovie*> (movie))
  209111. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209112. : movie (0)
  209113. {
  209114. setOpaque (true);
  209115. setVisible (true);
  209116. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209117. setView (view);
  209118. [view release];
  209119. }
  209120. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209121. {
  209122. closeMovie();
  209123. setView (0);
  209124. }
  209125. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209126. {
  209127. return true;
  209128. }
  209129. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209130. {
  209131. // unfortunately, QTMovie objects can only be created on the main thread..
  209132. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209133. QTMovie* movie = 0;
  209134. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209135. if (fin != 0)
  209136. {
  209137. movieFile = fin->getFile();
  209138. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209139. error: nil];
  209140. }
  209141. else
  209142. {
  209143. MemoryBlock temp;
  209144. movieStream->readIntoMemoryBlock (temp);
  209145. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209146. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209147. {
  209148. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209149. length: temp.getSize()]
  209150. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209151. MIMEType: @""]
  209152. error: nil];
  209153. if (movie != 0)
  209154. break;
  209155. }
  209156. }
  209157. return movie;
  209158. }
  209159. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209160. const bool isControllerVisible_)
  209161. {
  209162. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209163. }
  209164. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209165. const bool controllerVisible_)
  209166. {
  209167. closeMovie();
  209168. if (getPeer() == 0)
  209169. {
  209170. // To open a movie, this component must be visible inside a functioning window, so that
  209171. // the QT control can be assigned to the window.
  209172. jassertfalse
  209173. return false;
  209174. }
  209175. movie = openMovieFromStream (movieStream, movieFile);
  209176. [theMovie retain];
  209177. QTMovieView* view = (QTMovieView*) getView();
  209178. [view setMovie: theMovie];
  209179. [view setControllerVisible: controllerVisible_];
  209180. setLooping (looping);
  209181. return movie != nil;
  209182. }
  209183. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209184. const bool isControllerVisible_)
  209185. {
  209186. // unfortunately, QTMovie objects can only be created on the main thread..
  209187. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209188. closeMovie();
  209189. if (getPeer() == 0)
  209190. {
  209191. // To open a movie, this component must be visible inside a functioning window, so that
  209192. // the QT control can be assigned to the window.
  209193. jassertfalse
  209194. return false;
  209195. }
  209196. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209197. NSError* err;
  209198. if ([QTMovie canInitWithURL: url])
  209199. movie = [QTMovie movieWithURL: url error: &err];
  209200. [theMovie retain];
  209201. QTMovieView* view = (QTMovieView*) getView();
  209202. [view setMovie: theMovie];
  209203. [view setControllerVisible: controllerVisible];
  209204. setLooping (looping);
  209205. return movie != nil;
  209206. }
  209207. void QuickTimeMovieComponent::closeMovie()
  209208. {
  209209. stop();
  209210. QTMovieView* view = (QTMovieView*) getView();
  209211. [view setMovie: nil];
  209212. [theMovie release];
  209213. movie = 0;
  209214. movieFile = File::nonexistent;
  209215. }
  209216. bool QuickTimeMovieComponent::isMovieOpen() const
  209217. {
  209218. return movie != nil;
  209219. }
  209220. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209221. {
  209222. return movieFile;
  209223. }
  209224. void QuickTimeMovieComponent::play()
  209225. {
  209226. [theMovie play];
  209227. }
  209228. void QuickTimeMovieComponent::stop()
  209229. {
  209230. [theMovie stop];
  209231. }
  209232. bool QuickTimeMovieComponent::isPlaying() const
  209233. {
  209234. return movie != 0 && [theMovie rate] != 0;
  209235. }
  209236. void QuickTimeMovieComponent::setPosition (const double seconds)
  209237. {
  209238. if (movie != 0)
  209239. {
  209240. QTTime t;
  209241. t.timeValue = (uint64) (100000.0 * seconds);
  209242. t.timeScale = 100000;
  209243. t.flags = 0;
  209244. [theMovie setCurrentTime: t];
  209245. }
  209246. }
  209247. double QuickTimeMovieComponent::getPosition() const
  209248. {
  209249. if (movie == 0)
  209250. return 0.0;
  209251. QTTime t = [theMovie currentTime];
  209252. return t.timeValue / (double) t.timeScale;
  209253. }
  209254. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209255. {
  209256. [theMovie setRate: newSpeed];
  209257. }
  209258. double QuickTimeMovieComponent::getMovieDuration() const
  209259. {
  209260. if (movie == 0)
  209261. return 0.0;
  209262. QTTime t = [theMovie duration];
  209263. return t.timeValue / (double) t.timeScale;
  209264. }
  209265. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209266. {
  209267. looping = shouldLoop;
  209268. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209269. forKey: QTMovieLoopsAttribute];
  209270. }
  209271. bool QuickTimeMovieComponent::isLooping() const
  209272. {
  209273. return looping;
  209274. }
  209275. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209276. {
  209277. [theMovie setVolume: newVolume];
  209278. }
  209279. float QuickTimeMovieComponent::getMovieVolume() const
  209280. {
  209281. return movie != 0 ? [theMovie volume] : 0.0f;
  209282. }
  209283. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209284. {
  209285. width = 0;
  209286. height = 0;
  209287. if (movie != 0)
  209288. {
  209289. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209290. width = (int) s.width;
  209291. height = (int) s.height;
  209292. }
  209293. }
  209294. void QuickTimeMovieComponent::paint (Graphics& g)
  209295. {
  209296. if (movie == 0)
  209297. g.fillAll (Colours::black);
  209298. }
  209299. bool QuickTimeMovieComponent::isControllerVisible() const
  209300. {
  209301. return controllerVisible;
  209302. }
  209303. void QuickTimeMovieComponent::goToStart()
  209304. {
  209305. setPosition (0.0);
  209306. }
  209307. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209308. const RectanglePlacement& placement)
  209309. {
  209310. int normalWidth, normalHeight;
  209311. getMovieNormalSize (normalWidth, normalHeight);
  209312. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209313. {
  209314. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209315. placement.applyTo (x, y, w, h,
  209316. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209317. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209318. if (w > 0 && h > 0)
  209319. {
  209320. setBounds (roundToInt (x), roundToInt (y),
  209321. roundToInt (w), roundToInt (h));
  209322. }
  209323. }
  209324. else
  209325. {
  209326. setBounds (spaceToFitWithin);
  209327. }
  209328. }
  209329. #if ! (JUCE_MAC && JUCE_64BIT)
  209330. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209331. {
  209332. if (movieStream == 0)
  209333. return false;
  209334. File file;
  209335. QTMovie* movie = openMovieFromStream (movieStream, file);
  209336. if (movie != nil)
  209337. result = [movie quickTimeMovie];
  209338. return movie != nil;
  209339. }
  209340. #endif
  209341. #endif
  209342. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209343. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209344. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209345. // compiled on its own).
  209346. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209347. const int kilobytesPerSecond1x = 176;
  209348. END_JUCE_NAMESPACE
  209349. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209350. @interface OpenDiskDevice : NSObject
  209351. {
  209352. @public
  209353. DRDevice* device;
  209354. NSMutableArray* tracks;
  209355. bool underrunProtection;
  209356. }
  209357. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209358. - (void) dealloc;
  209359. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209360. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209361. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209362. @end
  209363. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209364. @interface AudioTrackProducer : NSObject
  209365. {
  209366. JUCE_NAMESPACE::AudioSource* source;
  209367. int readPosition, lengthInFrames;
  209368. }
  209369. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209370. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209371. - (void) dealloc;
  209372. - (void) setupTrackProperties: (DRTrack*) track;
  209373. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209374. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209375. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209376. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209377. toMedia:(NSDictionary*)mediaInfo;
  209378. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209379. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209380. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209381. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209382. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209383. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209384. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209385. ioFlags:(uint32_t*)flags;
  209386. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209387. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209388. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209389. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209390. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209391. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209392. ioFlags:(uint32_t*)flags;
  209393. @end
  209394. @implementation OpenDiskDevice
  209395. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209396. {
  209397. [super init];
  209398. device = device_;
  209399. tracks = [[NSMutableArray alloc] init];
  209400. underrunProtection = true;
  209401. return self;
  209402. }
  209403. - (void) dealloc
  209404. {
  209405. [tracks release];
  209406. [super dealloc];
  209407. }
  209408. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209409. {
  209410. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209411. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209412. [p setupTrackProperties: t];
  209413. [tracks addObject: t];
  209414. [t release];
  209415. [p release];
  209416. }
  209417. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209418. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209419. {
  209420. DRBurn* burn = [DRBurn burnForDevice: device];
  209421. if (! [device acquireExclusiveAccess])
  209422. {
  209423. *error = "Couldn't open or write to the CD device";
  209424. return;
  209425. }
  209426. [device acquireMediaReservation];
  209427. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209428. [d autorelease];
  209429. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209430. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209431. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209432. if (burnSpeed > 0)
  209433. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209434. if (! underrunProtection)
  209435. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209436. [burn setProperties: d];
  209437. [burn writeLayout: tracks];
  209438. for (;;)
  209439. {
  209440. JUCE_NAMESPACE::Thread::sleep (300);
  209441. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209442. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209443. {
  209444. [burn abort];
  209445. *error = "User cancelled the write operation";
  209446. break;
  209447. }
  209448. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209449. {
  209450. *error = "Write operation failed";
  209451. break;
  209452. }
  209453. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209454. {
  209455. break;
  209456. }
  209457. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209458. objectForKey: DRErrorStatusErrorStringKey];
  209459. if ([err length] > 0)
  209460. {
  209461. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209462. break;
  209463. }
  209464. }
  209465. [device releaseMediaReservation];
  209466. [device releaseExclusiveAccess];
  209467. }
  209468. @end
  209469. @implementation AudioTrackProducer
  209470. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209471. {
  209472. lengthInFrames = lengthInFrames_;
  209473. readPosition = 0;
  209474. return self;
  209475. }
  209476. - (void) setupTrackProperties: (DRTrack*) track
  209477. {
  209478. NSMutableDictionary* p = [[track properties] mutableCopy];
  209479. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209480. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209481. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209482. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209483. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209484. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209485. [track setProperties: p];
  209486. [p release];
  209487. }
  209488. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209489. {
  209490. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209491. if (s != nil)
  209492. s->source = source_;
  209493. return s;
  209494. }
  209495. - (void) dealloc
  209496. {
  209497. if (source != 0)
  209498. {
  209499. source->releaseResources();
  209500. delete source;
  209501. }
  209502. [super dealloc];
  209503. }
  209504. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209505. {
  209506. }
  209507. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209508. {
  209509. return true;
  209510. }
  209511. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209512. {
  209513. return lengthInFrames;
  209514. }
  209515. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209516. toMedia: (NSDictionary*) mediaInfo
  209517. {
  209518. if (source != 0)
  209519. source->prepareToPlay (44100 / 75, 44100);
  209520. readPosition = 0;
  209521. return true;
  209522. }
  209523. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209524. {
  209525. if (source != 0)
  209526. source->prepareToPlay (44100 / 75, 44100);
  209527. return true;
  209528. }
  209529. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209530. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209531. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209532. {
  209533. if (source != 0)
  209534. {
  209535. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209536. if (numSamples > 0)
  209537. {
  209538. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209539. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209540. info.buffer = &tempBuffer;
  209541. info.startSample = 0;
  209542. info.numSamples = numSamples;
  209543. source->getNextAudioBlock (info);
  209544. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209545. buffer, numSamples, 4);
  209546. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209547. buffer + 2, numSamples, 4);
  209548. readPosition += numSamples;
  209549. }
  209550. return numSamples * 4;
  209551. }
  209552. return 0;
  209553. }
  209554. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209555. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209556. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209557. ioFlags: (uint32_t*) flags
  209558. {
  209559. zeromem (buffer, bufferLength);
  209560. return bufferLength;
  209561. }
  209562. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209563. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209564. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209565. {
  209566. return true;
  209567. }
  209568. @end
  209569. BEGIN_JUCE_NAMESPACE
  209570. class AudioCDBurner::Pimpl : public Timer
  209571. {
  209572. public:
  209573. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209574. : device (0), owner (owner_)
  209575. {
  209576. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209577. if (dev != 0)
  209578. {
  209579. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209580. lastState = getDiskState();
  209581. startTimer (1000);
  209582. }
  209583. }
  209584. ~Pimpl()
  209585. {
  209586. stopTimer();
  209587. [device release];
  209588. }
  209589. void timerCallback()
  209590. {
  209591. const DiskState state = getDiskState();
  209592. if (state != lastState)
  209593. {
  209594. lastState = state;
  209595. owner.sendChangeMessage (&owner);
  209596. }
  209597. }
  209598. DiskState getDiskState() const
  209599. {
  209600. if ([device->device isValid])
  209601. {
  209602. NSDictionary* status = [device->device status];
  209603. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209604. if ([state isEqualTo: DRDeviceMediaStateNone])
  209605. {
  209606. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209607. return trayOpen;
  209608. return noDisc;
  209609. }
  209610. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209611. {
  209612. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209613. return writableDiskPresent;
  209614. else
  209615. return readOnlyDiskPresent;
  209616. }
  209617. }
  209618. return unknown;
  209619. }
  209620. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209621. const Array<int> getAvailableWriteSpeeds() const
  209622. {
  209623. Array<int> results;
  209624. if ([device->device isValid])
  209625. {
  209626. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209627. for (unsigned int i = 0; i < [speeds count]; ++i)
  209628. {
  209629. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209630. results.add (kbPerSec / kilobytesPerSecond1x);
  209631. }
  209632. }
  209633. return results;
  209634. }
  209635. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209636. {
  209637. if ([device->device isValid])
  209638. {
  209639. device->underrunProtection = shouldBeEnabled;
  209640. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209641. }
  209642. return false;
  209643. }
  209644. int getNumAvailableAudioBlocks() const
  209645. {
  209646. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209647. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209648. }
  209649. OpenDiskDevice* device;
  209650. private:
  209651. DiskState lastState;
  209652. AudioCDBurner& owner;
  209653. };
  209654. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209655. {
  209656. pimpl = new Pimpl (*this, deviceIndex);
  209657. }
  209658. AudioCDBurner::~AudioCDBurner()
  209659. {
  209660. }
  209661. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209662. {
  209663. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209664. if (b->pimpl->device == 0)
  209665. b = 0;
  209666. return b.release();
  209667. }
  209668. static NSArray* findDiskBurnerDevices()
  209669. {
  209670. NSMutableArray* results = [NSMutableArray array];
  209671. NSArray* devs = [DRDevice devices];
  209672. if (devs != 0)
  209673. {
  209674. int num = [devs count];
  209675. int i;
  209676. for (i = 0; i < num; ++i)
  209677. {
  209678. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209679. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209680. if (name != nil)
  209681. [results addObject: name];
  209682. }
  209683. }
  209684. return results;
  209685. }
  209686. const StringArray AudioCDBurner::findAvailableDevices()
  209687. {
  209688. NSArray* names = findDiskBurnerDevices();
  209689. StringArray s;
  209690. for (unsigned int i = 0; i < [names count]; ++i)
  209691. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209692. return s;
  209693. }
  209694. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209695. {
  209696. return pimpl->getDiskState();
  209697. }
  209698. bool AudioCDBurner::isDiskPresent() const
  209699. {
  209700. return getDiskState() == writableDiskPresent;
  209701. }
  209702. bool AudioCDBurner::openTray()
  209703. {
  209704. return pimpl->openTray();
  209705. }
  209706. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209707. {
  209708. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209709. DiskState oldState = getDiskState();
  209710. DiskState newState = oldState;
  209711. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209712. {
  209713. newState = getDiskState();
  209714. Thread::sleep (100);
  209715. }
  209716. return newState;
  209717. }
  209718. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209719. {
  209720. return pimpl->getAvailableWriteSpeeds();
  209721. }
  209722. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209723. {
  209724. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209725. }
  209726. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209727. {
  209728. return pimpl->getNumAvailableAudioBlocks();
  209729. }
  209730. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209731. {
  209732. if ([pimpl->device->device isValid])
  209733. {
  209734. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209735. return true;
  209736. }
  209737. return false;
  209738. }
  209739. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209740. bool ejectDiscAfterwards,
  209741. bool performFakeBurnForTesting,
  209742. int writeSpeed)
  209743. {
  209744. String error ("Couldn't open or write to the CD device");
  209745. if ([pimpl->device->device isValid])
  209746. {
  209747. error = String::empty;
  209748. [pimpl->device burn: listener
  209749. errorString: &error
  209750. ejectAfterwards: ejectDiscAfterwards
  209751. isFake: performFakeBurnForTesting
  209752. speed: writeSpeed];
  209753. }
  209754. return error;
  209755. }
  209756. #endif
  209757. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209758. void AudioCDReader::ejectDisk()
  209759. {
  209760. const ScopedAutoReleasePool p;
  209761. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209762. }
  209763. #endif
  209764. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209765. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209766. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209767. // compiled on its own).
  209768. #if JUCE_INCLUDED_FILE
  209769. class AppDelegateRedirector
  209770. {
  209771. public:
  209772. AppDelegateRedirector()
  209773. {
  209774. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209775. runLoop = CFRunLoopGetMain();
  209776. #else
  209777. runLoop = CFRunLoopGetCurrent();
  209778. #endif
  209779. CFRunLoopSourceContext sourceContext;
  209780. zerostruct (sourceContext);
  209781. sourceContext.info = this;
  209782. sourceContext.perform = runLoopSourceCallback;
  209783. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209784. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209785. }
  209786. virtual ~AppDelegateRedirector()
  209787. {
  209788. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209789. CFRunLoopSourceInvalidate (runLoopSource);
  209790. CFRelease (runLoopSource);
  209791. while (messages.size() > 0)
  209792. delete ((Message*) messages.remove(0));
  209793. }
  209794. virtual NSApplicationTerminateReply shouldTerminate()
  209795. {
  209796. if (JUCEApplication::getInstance() != 0)
  209797. {
  209798. JUCEApplication::getInstance()->systemRequestedQuit();
  209799. return NSTerminateCancel;
  209800. }
  209801. return NSTerminateNow;
  209802. }
  209803. virtual BOOL openFile (const NSString* filename)
  209804. {
  209805. if (JUCEApplication::getInstance() != 0)
  209806. {
  209807. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209808. return YES;
  209809. }
  209810. return NO;
  209811. }
  209812. virtual void openFiles (NSArray* filenames)
  209813. {
  209814. StringArray files;
  209815. for (unsigned int i = 0; i < [filenames count]; ++i)
  209816. {
  209817. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209818. if (filename.containsChar (' '))
  209819. filename = filename.quoted('"');
  209820. files.add (filename);
  209821. }
  209822. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209823. {
  209824. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (" "));
  209825. }
  209826. }
  209827. virtual void focusChanged()
  209828. {
  209829. juce_HandleProcessFocusChange();
  209830. }
  209831. struct CallbackMessagePayload
  209832. {
  209833. MessageCallbackFunction* function;
  209834. void* parameter;
  209835. void* volatile result;
  209836. bool volatile hasBeenExecuted;
  209837. };
  209838. virtual void performCallback (CallbackMessagePayload* pl)
  209839. {
  209840. pl->result = (*pl->function) (pl->parameter);
  209841. pl->hasBeenExecuted = true;
  209842. }
  209843. virtual void deleteSelf()
  209844. {
  209845. delete this;
  209846. }
  209847. void postMessage (void* m)
  209848. {
  209849. messages.add (m);
  209850. CFRunLoopSourceSignal (runLoopSource);
  209851. CFRunLoopWakeUp (runLoop);
  209852. }
  209853. private:
  209854. CFRunLoopRef runLoop;
  209855. CFRunLoopSourceRef runLoopSource;
  209856. Array <void*, CriticalSection> messages;
  209857. void runLoopCallback()
  209858. {
  209859. int numDispatched = 0;
  209860. do
  209861. {
  209862. void* const nextMessage = messages.remove (0);
  209863. if (nextMessage == 0)
  209864. return;
  209865. const ScopedAutoReleasePool pool;
  209866. MessageManager::getInstance()->deliverMessage (nextMessage);
  209867. } while (++numDispatched <= 4);
  209868. CFRunLoopSourceSignal (runLoopSource);
  209869. CFRunLoopWakeUp (runLoop);
  209870. }
  209871. static void runLoopSourceCallback (void* info)
  209872. {
  209873. ((AppDelegateRedirector*) info)->runLoopCallback();
  209874. }
  209875. };
  209876. END_JUCE_NAMESPACE
  209877. using namespace JUCE_NAMESPACE;
  209878. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209879. @interface JuceAppDelegate : NSObject
  209880. {
  209881. @private
  209882. id oldDelegate;
  209883. @public
  209884. AppDelegateRedirector* redirector;
  209885. }
  209886. - (JuceAppDelegate*) init;
  209887. - (void) dealloc;
  209888. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209889. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209890. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209891. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209892. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209893. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209894. - (void) performCallback: (id) info;
  209895. - (void) dummyMethod;
  209896. @end
  209897. @implementation JuceAppDelegate
  209898. - (JuceAppDelegate*) init
  209899. {
  209900. [super init];
  209901. redirector = new AppDelegateRedirector();
  209902. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209903. if (JUCEApplication::getInstance() != 0)
  209904. {
  209905. oldDelegate = [NSApp delegate];
  209906. [NSApp setDelegate: self];
  209907. }
  209908. else
  209909. {
  209910. oldDelegate = 0;
  209911. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209912. name: NSApplicationDidResignActiveNotification object: NSApp];
  209913. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209914. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209915. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209916. name: NSApplicationWillUnhideNotification object: NSApp];
  209917. }
  209918. return self;
  209919. }
  209920. - (void) dealloc
  209921. {
  209922. if (oldDelegate != 0)
  209923. [NSApp setDelegate: oldDelegate];
  209924. redirector->deleteSelf();
  209925. [super dealloc];
  209926. }
  209927. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209928. {
  209929. return redirector->shouldTerminate();
  209930. }
  209931. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209932. {
  209933. return redirector->openFile (filename);
  209934. }
  209935. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209936. {
  209937. return redirector->openFiles (filenames);
  209938. }
  209939. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209940. {
  209941. redirector->focusChanged();
  209942. }
  209943. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209944. {
  209945. redirector->focusChanged();
  209946. }
  209947. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209948. {
  209949. redirector->focusChanged();
  209950. }
  209951. - (void) performCallback: (id) info
  209952. {
  209953. if ([info isKindOfClass: [NSData class]])
  209954. {
  209955. AppDelegateRedirector::CallbackMessagePayload* pl
  209956. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  209957. if (pl != 0)
  209958. redirector->performCallback (pl);
  209959. }
  209960. else
  209961. {
  209962. jassertfalse // should never get here!
  209963. }
  209964. }
  209965. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209966. @end
  209967. BEGIN_JUCE_NAMESPACE
  209968. static JuceAppDelegate* juceAppDelegate = 0;
  209969. void MessageManager::runDispatchLoop()
  209970. {
  209971. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209972. {
  209973. const ScopedAutoReleasePool pool;
  209974. // must only be called by the message thread!
  209975. jassert (isThisTheMessageThread());
  209976. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209977. @try
  209978. {
  209979. [NSApp run];
  209980. }
  209981. @catch (NSException* e)
  209982. {
  209983. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209984. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209985. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209986. }
  209987. @finally
  209988. {
  209989. }
  209990. #else
  209991. [NSApp run];
  209992. #endif
  209993. }
  209994. }
  209995. void MessageManager::stopDispatchLoop()
  209996. {
  209997. quitMessagePosted = true;
  209998. [NSApp stop: nil];
  209999. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  210000. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  210001. }
  210002. static bool isEventBlockedByModalComps (NSEvent* e)
  210003. {
  210004. if (Component::getNumCurrentlyModalComponents() == 0)
  210005. return false;
  210006. NSWindow* const w = [e window];
  210007. if (w == 0 || [w worksWhenModal])
  210008. return false;
  210009. bool isKey = false, isInputAttempt = false;
  210010. switch ([e type])
  210011. {
  210012. case NSKeyDown:
  210013. case NSKeyUp:
  210014. isKey = isInputAttempt = true;
  210015. break;
  210016. case NSLeftMouseDown:
  210017. case NSRightMouseDown:
  210018. case NSOtherMouseDown:
  210019. isInputAttempt = true;
  210020. break;
  210021. case NSLeftMouseDragged:
  210022. case NSRightMouseDragged:
  210023. case NSLeftMouseUp:
  210024. case NSRightMouseUp:
  210025. case NSOtherMouseUp:
  210026. case NSOtherMouseDragged:
  210027. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  210028. return false;
  210029. break;
  210030. case NSMouseMoved:
  210031. case NSMouseEntered:
  210032. case NSMouseExited:
  210033. case NSCursorUpdate:
  210034. case NSScrollWheel:
  210035. case NSTabletPoint:
  210036. case NSTabletProximity:
  210037. break;
  210038. default:
  210039. return false;
  210040. }
  210041. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  210042. {
  210043. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  210044. NSView* const compView = (NSView*) peer->getNativeHandle();
  210045. if ([compView window] == w)
  210046. {
  210047. if (isKey)
  210048. {
  210049. if (compView == [w firstResponder])
  210050. return false;
  210051. }
  210052. else
  210053. {
  210054. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  210055. [compView bounds]))
  210056. return false;
  210057. }
  210058. }
  210059. }
  210060. if (isInputAttempt)
  210061. {
  210062. if (! [NSApp isActive])
  210063. [NSApp activateIgnoringOtherApps: YES];
  210064. Component* const modal = Component::getCurrentlyModalComponent (0);
  210065. if (modal != 0)
  210066. modal->inputAttemptWhenModal();
  210067. }
  210068. return true;
  210069. }
  210070. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210071. {
  210072. const ScopedAutoReleasePool pool;
  210073. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210074. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210075. while (! quitMessagePosted)
  210076. {
  210077. const ScopedAutoReleasePool pool2;
  210078. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210079. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210080. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210081. inMode: NSDefaultRunLoopMode
  210082. dequeue: YES];
  210083. if (e != 0 && ! isEventBlockedByModalComps (e))
  210084. [NSApp sendEvent: e];
  210085. if (Time::getMillisecondCounter() >= endTime)
  210086. break;
  210087. }
  210088. return ! quitMessagePosted;
  210089. }
  210090. void MessageManager::doPlatformSpecificInitialisation()
  210091. {
  210092. if (juceAppDelegate == 0)
  210093. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210094. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210095. // correctly (needed prior to 10.5)
  210096. if (! [NSThread isMultiThreaded])
  210097. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210098. toTarget: juceAppDelegate
  210099. withObject: nil];
  210100. initialiseMainMenu();
  210101. }
  210102. void MessageManager::doPlatformSpecificShutdown()
  210103. {
  210104. if (juceAppDelegate != 0)
  210105. {
  210106. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210107. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210108. [juceAppDelegate release];
  210109. juceAppDelegate = 0;
  210110. }
  210111. }
  210112. bool juce_postMessageToSystemQueue (void* message)
  210113. {
  210114. juceAppDelegate->redirector->postMessage (message);
  210115. return true;
  210116. }
  210117. void MessageManager::broadcastMessage (const String& value) throw()
  210118. {
  210119. }
  210120. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210121. void* data)
  210122. {
  210123. if (isThisTheMessageThread())
  210124. {
  210125. return (*callback) (data);
  210126. }
  210127. else
  210128. {
  210129. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210130. // deadlock because the message manager is blocked from running, so can never
  210131. // call your function..
  210132. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210133. const ScopedAutoReleasePool pool;
  210134. AppDelegateRedirector::CallbackMessagePayload cmp;
  210135. cmp.function = callback;
  210136. cmp.parameter = data;
  210137. cmp.result = 0;
  210138. cmp.hasBeenExecuted = false;
  210139. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210140. withObject: [NSData dataWithBytesNoCopy: &cmp
  210141. length: sizeof (cmp)
  210142. freeWhenDone: NO]
  210143. waitUntilDone: YES];
  210144. return cmp.result;
  210145. }
  210146. }
  210147. #endif
  210148. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210149. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210150. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210151. // compiled on its own).
  210152. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210153. #if JUCE_MAC
  210154. END_JUCE_NAMESPACE
  210155. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210156. @interface DownloadClickDetector : NSObject
  210157. {
  210158. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210159. }
  210160. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210161. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210162. request: (NSURLRequest*) request
  210163. frame: (WebFrame*) frame
  210164. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210165. @end
  210166. @implementation DownloadClickDetector
  210167. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210168. {
  210169. [super init];
  210170. ownerComponent = ownerComponent_;
  210171. return self;
  210172. }
  210173. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210174. request: (NSURLRequest*) request
  210175. frame: (WebFrame*) frame
  210176. decisionListener: (id <WebPolicyDecisionListener>) listener
  210177. {
  210178. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210179. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210180. [listener use];
  210181. else
  210182. [listener ignore];
  210183. }
  210184. @end
  210185. BEGIN_JUCE_NAMESPACE
  210186. class WebBrowserComponentInternal : public NSViewComponent
  210187. {
  210188. public:
  210189. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210190. {
  210191. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210192. frameName: @""
  210193. groupName: @""];
  210194. setView (webView);
  210195. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210196. [webView setPolicyDelegate: clickListener];
  210197. }
  210198. ~WebBrowserComponentInternal()
  210199. {
  210200. [webView setPolicyDelegate: nil];
  210201. [clickListener release];
  210202. setView (0);
  210203. }
  210204. void goToURL (const String& url,
  210205. const StringArray* headers,
  210206. const MemoryBlock* postData)
  210207. {
  210208. NSMutableURLRequest* r
  210209. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210210. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210211. timeoutInterval: 30.0];
  210212. if (postData != 0 && postData->getSize() > 0)
  210213. {
  210214. [r setHTTPMethod: @"POST"];
  210215. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210216. length: postData->getSize()]];
  210217. }
  210218. if (headers != 0)
  210219. {
  210220. for (int i = 0; i < headers->size(); ++i)
  210221. {
  210222. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  210223. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  210224. [r setValue: juceStringToNS (headerValue)
  210225. forHTTPHeaderField: juceStringToNS (headerName)];
  210226. }
  210227. }
  210228. stop();
  210229. [[webView mainFrame] loadRequest: r];
  210230. }
  210231. void goBack()
  210232. {
  210233. [webView goBack];
  210234. }
  210235. void goForward()
  210236. {
  210237. [webView goForward];
  210238. }
  210239. void stop()
  210240. {
  210241. [webView stopLoading: nil];
  210242. }
  210243. void refresh()
  210244. {
  210245. [webView reload: nil];
  210246. }
  210247. private:
  210248. WebView* webView;
  210249. DownloadClickDetector* clickListener;
  210250. };
  210251. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210252. : browser (0),
  210253. blankPageShown (false),
  210254. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210255. {
  210256. setOpaque (true);
  210257. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210258. }
  210259. WebBrowserComponent::~WebBrowserComponent()
  210260. {
  210261. deleteAndZero (browser);
  210262. }
  210263. void WebBrowserComponent::goToURL (const String& url,
  210264. const StringArray* headers,
  210265. const MemoryBlock* postData)
  210266. {
  210267. lastURL = url;
  210268. lastHeaders.clear();
  210269. if (headers != 0)
  210270. lastHeaders = *headers;
  210271. lastPostData.setSize (0);
  210272. if (postData != 0)
  210273. lastPostData = *postData;
  210274. blankPageShown = false;
  210275. browser->goToURL (url, headers, postData);
  210276. }
  210277. void WebBrowserComponent::stop()
  210278. {
  210279. browser->stop();
  210280. }
  210281. void WebBrowserComponent::goBack()
  210282. {
  210283. lastURL = String::empty;
  210284. blankPageShown = false;
  210285. browser->goBack();
  210286. }
  210287. void WebBrowserComponent::goForward()
  210288. {
  210289. lastURL = String::empty;
  210290. browser->goForward();
  210291. }
  210292. void WebBrowserComponent::refresh()
  210293. {
  210294. browser->refresh();
  210295. }
  210296. void WebBrowserComponent::paint (Graphics& g)
  210297. {
  210298. }
  210299. void WebBrowserComponent::checkWindowAssociation()
  210300. {
  210301. if (isShowing())
  210302. {
  210303. if (blankPageShown)
  210304. goBack();
  210305. }
  210306. else
  210307. {
  210308. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210309. {
  210310. // when the component becomes invisible, some stuff like flash
  210311. // carries on playing audio, so we need to force it onto a blank
  210312. // page to avoid this, (and send it back when it's made visible again).
  210313. blankPageShown = true;
  210314. browser->goToURL ("about:blank", 0, 0);
  210315. }
  210316. }
  210317. }
  210318. void WebBrowserComponent::reloadLastURL()
  210319. {
  210320. if (lastURL.isNotEmpty())
  210321. {
  210322. goToURL (lastURL, &lastHeaders, &lastPostData);
  210323. lastURL = String::empty;
  210324. }
  210325. }
  210326. void WebBrowserComponent::parentHierarchyChanged()
  210327. {
  210328. checkWindowAssociation();
  210329. }
  210330. void WebBrowserComponent::resized()
  210331. {
  210332. browser->setSize (getWidth(), getHeight());
  210333. }
  210334. void WebBrowserComponent::visibilityChanged()
  210335. {
  210336. checkWindowAssociation();
  210337. }
  210338. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210339. {
  210340. return true;
  210341. }
  210342. #else
  210343. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210344. {
  210345. }
  210346. WebBrowserComponent::~WebBrowserComponent()
  210347. {
  210348. }
  210349. void WebBrowserComponent::goToURL (const String& url,
  210350. const StringArray* headers,
  210351. const MemoryBlock* postData)
  210352. {
  210353. }
  210354. void WebBrowserComponent::stop()
  210355. {
  210356. }
  210357. void WebBrowserComponent::goBack()
  210358. {
  210359. }
  210360. void WebBrowserComponent::goForward()
  210361. {
  210362. }
  210363. void WebBrowserComponent::refresh()
  210364. {
  210365. }
  210366. void WebBrowserComponent::paint (Graphics& g)
  210367. {
  210368. }
  210369. void WebBrowserComponent::checkWindowAssociation()
  210370. {
  210371. }
  210372. void WebBrowserComponent::reloadLastURL()
  210373. {
  210374. }
  210375. void WebBrowserComponent::parentHierarchyChanged()
  210376. {
  210377. }
  210378. void WebBrowserComponent::resized()
  210379. {
  210380. }
  210381. void WebBrowserComponent::visibilityChanged()
  210382. {
  210383. }
  210384. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210385. {
  210386. return true;
  210387. }
  210388. #endif
  210389. #endif
  210390. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210391. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210392. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210393. // compiled on its own).
  210394. #if JUCE_INCLUDED_FILE
  210395. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210396. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210397. #endif
  210398. #undef log
  210399. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210400. #define log(a) Logger::writeToLog (a)
  210401. #else
  210402. #define log(a)
  210403. #endif
  210404. #undef OK
  210405. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210406. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210407. {
  210408. if (err == noErr)
  210409. return true;
  210410. Logger::writeToLog ("CoreAudio error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  210411. jassertfalse
  210412. return false;
  210413. }
  210414. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210415. #else
  210416. #define OK(a) (a == noErr)
  210417. #endif
  210418. class CoreAudioInternal : public Timer
  210419. {
  210420. public:
  210421. CoreAudioInternal (AudioDeviceID id)
  210422. : inputLatency (0),
  210423. outputLatency (0),
  210424. callback (0),
  210425. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210426. audioProcID (0),
  210427. #endif
  210428. inputDevice (0),
  210429. isSlaveDevice (false),
  210430. deviceID (id),
  210431. started (false),
  210432. sampleRate (0),
  210433. bufferSize (512),
  210434. numInputChans (0),
  210435. numOutputChans (0),
  210436. callbacksAllowed (true),
  210437. numInputChannelInfos (0),
  210438. numOutputChannelInfos (0)
  210439. {
  210440. jassert (deviceID != 0);
  210441. updateDetailsFromDevice();
  210442. AudioObjectPropertyAddress pa;
  210443. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210444. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210445. pa.mElement = kAudioObjectPropertyElementWildcard;
  210446. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210447. }
  210448. ~CoreAudioInternal()
  210449. {
  210450. AudioObjectPropertyAddress pa;
  210451. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210452. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210453. pa.mElement = kAudioObjectPropertyElementWildcard;
  210454. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210455. stop (false);
  210456. delete inputDevice;
  210457. }
  210458. void allocateTempBuffers()
  210459. {
  210460. const int tempBufSize = bufferSize + 4;
  210461. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210462. tempInputBuffers.calloc (numInputChans + 2);
  210463. tempOutputBuffers.calloc (numOutputChans + 2);
  210464. int i, count = 0;
  210465. for (i = 0; i < numInputChans; ++i)
  210466. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210467. for (i = 0; i < numOutputChans; ++i)
  210468. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210469. }
  210470. // returns the number of actual available channels
  210471. void fillInChannelInfo (const bool input)
  210472. {
  210473. int chanNum = 0;
  210474. UInt32 size;
  210475. AudioObjectPropertyAddress pa;
  210476. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210477. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210478. pa.mElement = kAudioObjectPropertyElementMaster;
  210479. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210480. {
  210481. HeapBlock <AudioBufferList> bufList;
  210482. bufList.calloc (size, 1);
  210483. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210484. {
  210485. const int numStreams = bufList->mNumberBuffers;
  210486. for (int i = 0; i < numStreams; ++i)
  210487. {
  210488. const AudioBuffer& b = bufList->mBuffers[i];
  210489. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210490. {
  210491. String name;
  210492. {
  210493. char channelName [256];
  210494. zerostruct (channelName);
  210495. UInt32 nameSize = sizeof (channelName);
  210496. UInt32 channelNum = chanNum + 1;
  210497. pa.mSelector = kAudioDevicePropertyChannelName;
  210498. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210499. name = String::fromUTF8 (channelName, nameSize);
  210500. }
  210501. if (input)
  210502. {
  210503. if (activeInputChans[chanNum])
  210504. {
  210505. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210506. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210507. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210508. ++numInputChannelInfos;
  210509. }
  210510. if (name.isEmpty())
  210511. name << "Input " << (chanNum + 1);
  210512. inChanNames.add (name);
  210513. }
  210514. else
  210515. {
  210516. if (activeOutputChans[chanNum])
  210517. {
  210518. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210519. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210520. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210521. ++numOutputChannelInfos;
  210522. }
  210523. if (name.isEmpty())
  210524. name << "Output " << (chanNum + 1);
  210525. outChanNames.add (name);
  210526. }
  210527. ++chanNum;
  210528. }
  210529. }
  210530. }
  210531. }
  210532. }
  210533. void updateDetailsFromDevice()
  210534. {
  210535. stopTimer();
  210536. if (deviceID == 0)
  210537. return;
  210538. const ScopedLock sl (callbackLock);
  210539. Float64 sr;
  210540. UInt32 size = sizeof (Float64);
  210541. AudioObjectPropertyAddress pa;
  210542. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210543. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210544. pa.mElement = kAudioObjectPropertyElementMaster;
  210545. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210546. sampleRate = sr;
  210547. UInt32 framesPerBuf;
  210548. size = sizeof (framesPerBuf);
  210549. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210550. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210551. {
  210552. bufferSize = framesPerBuf;
  210553. allocateTempBuffers();
  210554. }
  210555. bufferSizes.clear();
  210556. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210557. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210558. {
  210559. HeapBlock <AudioValueRange> ranges;
  210560. ranges.calloc (size, 1);
  210561. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210562. {
  210563. bufferSizes.add ((int) ranges[0].mMinimum);
  210564. for (int i = 32; i < 2048; i += 32)
  210565. {
  210566. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210567. {
  210568. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210569. {
  210570. bufferSizes.addIfNotAlreadyThere (i);
  210571. break;
  210572. }
  210573. }
  210574. }
  210575. if (bufferSize > 0)
  210576. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210577. }
  210578. }
  210579. if (bufferSizes.size() == 0 && bufferSize > 0)
  210580. bufferSizes.add (bufferSize);
  210581. sampleRates.clear();
  210582. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210583. String rates;
  210584. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210585. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210586. {
  210587. HeapBlock <AudioValueRange> ranges;
  210588. ranges.calloc (size, 1);
  210589. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210590. {
  210591. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210592. {
  210593. bool ok = false;
  210594. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210595. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210596. ok = true;
  210597. if (ok)
  210598. {
  210599. sampleRates.add (possibleRates[i]);
  210600. rates << possibleRates[i] << ' ';
  210601. }
  210602. }
  210603. }
  210604. }
  210605. if (sampleRates.size() == 0 && sampleRate > 0)
  210606. {
  210607. sampleRates.add (sampleRate);
  210608. rates << sampleRate;
  210609. }
  210610. log ("sr: " + rates);
  210611. inputLatency = 0;
  210612. outputLatency = 0;
  210613. UInt32 lat;
  210614. size = sizeof (lat);
  210615. pa.mSelector = kAudioDevicePropertyLatency;
  210616. pa.mScope = kAudioDevicePropertyScopeInput;
  210617. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210618. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210619. inputLatency = (int) lat;
  210620. pa.mScope = kAudioDevicePropertyScopeOutput;
  210621. size = sizeof (lat);
  210622. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210623. outputLatency = (int) lat;
  210624. log ("lat: " + String (inputLatency) + " " + String (outputLatency));
  210625. inChanNames.clear();
  210626. outChanNames.clear();
  210627. inputChannelInfo.calloc (numInputChans + 2);
  210628. numInputChannelInfos = 0;
  210629. outputChannelInfo.calloc (numOutputChans + 2);
  210630. numOutputChannelInfos = 0;
  210631. fillInChannelInfo (true);
  210632. fillInChannelInfo (false);
  210633. }
  210634. const StringArray getSources (bool input)
  210635. {
  210636. StringArray s;
  210637. HeapBlock <OSType> types;
  210638. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210639. for (int i = 0; i < num; ++i)
  210640. {
  210641. AudioValueTranslation avt;
  210642. char buffer[256];
  210643. avt.mInputData = (void*) &(types[i]);
  210644. avt.mInputDataSize = sizeof (UInt32);
  210645. avt.mOutputData = buffer;
  210646. avt.mOutputDataSize = 256;
  210647. UInt32 transSize = sizeof (avt);
  210648. AudioObjectPropertyAddress pa;
  210649. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210650. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210651. pa.mElement = kAudioObjectPropertyElementMaster;
  210652. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210653. {
  210654. DBG (buffer);
  210655. s.add (buffer);
  210656. }
  210657. }
  210658. return s;
  210659. }
  210660. int getCurrentSourceIndex (bool input) const
  210661. {
  210662. OSType currentSourceID = 0;
  210663. UInt32 size = sizeof (currentSourceID);
  210664. int result = -1;
  210665. AudioObjectPropertyAddress pa;
  210666. pa.mSelector = kAudioDevicePropertyDataSource;
  210667. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210668. pa.mElement = kAudioObjectPropertyElementMaster;
  210669. if (deviceID != 0)
  210670. {
  210671. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210672. {
  210673. HeapBlock <OSType> types;
  210674. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210675. for (int i = 0; i < num; ++i)
  210676. {
  210677. if (types[num] == currentSourceID)
  210678. {
  210679. result = i;
  210680. break;
  210681. }
  210682. }
  210683. }
  210684. }
  210685. return result;
  210686. }
  210687. void setCurrentSourceIndex (int index, bool input)
  210688. {
  210689. if (deviceID != 0)
  210690. {
  210691. HeapBlock <OSType> types;
  210692. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210693. if (((unsigned int) index) < (unsigned int) num)
  210694. {
  210695. AudioObjectPropertyAddress pa;
  210696. pa.mSelector = kAudioDevicePropertyDataSource;
  210697. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210698. pa.mElement = kAudioObjectPropertyElementMaster;
  210699. OSType typeId = types[index];
  210700. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210701. }
  210702. }
  210703. }
  210704. const String reopen (const BigInteger& inputChannels,
  210705. const BigInteger& outputChannels,
  210706. double newSampleRate,
  210707. int bufferSizeSamples)
  210708. {
  210709. String error;
  210710. log ("CoreAudio reopen");
  210711. callbacksAllowed = false;
  210712. stopTimer();
  210713. stop (false);
  210714. activeInputChans = inputChannels;
  210715. activeInputChans.setRange (inChanNames.size(),
  210716. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210717. false);
  210718. activeOutputChans = outputChannels;
  210719. activeOutputChans.setRange (outChanNames.size(),
  210720. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210721. false);
  210722. numInputChans = activeInputChans.countNumberOfSetBits();
  210723. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210724. // set sample rate
  210725. AudioObjectPropertyAddress pa;
  210726. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210727. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210728. pa.mElement = kAudioObjectPropertyElementMaster;
  210729. Float64 sr = newSampleRate;
  210730. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210731. {
  210732. error = "Couldn't change sample rate";
  210733. }
  210734. else
  210735. {
  210736. // change buffer size
  210737. UInt32 framesPerBuf = bufferSizeSamples;
  210738. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210739. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210740. {
  210741. error = "Couldn't change buffer size";
  210742. }
  210743. else
  210744. {
  210745. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210746. // correctly report their new settings until some random time in the future, so
  210747. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210748. // to make sure we're using the correct numbers..
  210749. updateDetailsFromDevice();
  210750. sampleRate = newSampleRate;
  210751. bufferSize = bufferSizeSamples;
  210752. if (sampleRates.size() == 0)
  210753. error = "Device has no available sample-rates";
  210754. else if (bufferSizes.size() == 0)
  210755. error = "Device has no available buffer-sizes";
  210756. else if (inputDevice != 0)
  210757. error = inputDevice->reopen (inputChannels,
  210758. outputChannels,
  210759. newSampleRate,
  210760. bufferSizeSamples);
  210761. }
  210762. }
  210763. callbacksAllowed = true;
  210764. return error;
  210765. }
  210766. bool start (AudioIODeviceCallback* cb)
  210767. {
  210768. if (! started)
  210769. {
  210770. callback = 0;
  210771. if (deviceID != 0)
  210772. {
  210773. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210774. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210775. #else
  210776. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210777. #endif
  210778. {
  210779. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210780. {
  210781. started = true;
  210782. }
  210783. else
  210784. {
  210785. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210786. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210787. #else
  210788. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210789. audioProcID = 0;
  210790. #endif
  210791. }
  210792. }
  210793. }
  210794. }
  210795. if (started)
  210796. {
  210797. const ScopedLock sl (callbackLock);
  210798. callback = cb;
  210799. }
  210800. if (inputDevice != 0)
  210801. return started && inputDevice->start (cb);
  210802. else
  210803. return started;
  210804. }
  210805. void stop (bool leaveInterruptRunning)
  210806. {
  210807. {
  210808. const ScopedLock sl (callbackLock);
  210809. callback = 0;
  210810. }
  210811. if (started
  210812. && (deviceID != 0)
  210813. && ! leaveInterruptRunning)
  210814. {
  210815. OK (AudioDeviceStop (deviceID, audioIOProc));
  210816. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210817. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210818. #else
  210819. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210820. audioProcID = 0;
  210821. #endif
  210822. started = false;
  210823. { const ScopedLock sl (callbackLock); }
  210824. // wait until it's definately stopped calling back..
  210825. for (int i = 40; --i >= 0;)
  210826. {
  210827. Thread::sleep (50);
  210828. UInt32 running = 0;
  210829. UInt32 size = sizeof (running);
  210830. AudioObjectPropertyAddress pa;
  210831. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210832. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210833. pa.mElement = kAudioObjectPropertyElementMaster;
  210834. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210835. if (running == 0)
  210836. break;
  210837. }
  210838. const ScopedLock sl (callbackLock);
  210839. }
  210840. if (inputDevice != 0)
  210841. inputDevice->stop (leaveInterruptRunning);
  210842. }
  210843. double getSampleRate() const
  210844. {
  210845. return sampleRate;
  210846. }
  210847. int getBufferSize() const
  210848. {
  210849. return bufferSize;
  210850. }
  210851. void audioCallback (const AudioBufferList* inInputData,
  210852. AudioBufferList* outOutputData)
  210853. {
  210854. int i;
  210855. const ScopedLock sl (callbackLock);
  210856. if (callback != 0)
  210857. {
  210858. if (inputDevice == 0)
  210859. {
  210860. for (i = numInputChans; --i >= 0;)
  210861. {
  210862. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210863. float* dest = tempInputBuffers [i];
  210864. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210865. + info.dataOffsetSamples;
  210866. const int stride = info.dataStrideSamples;
  210867. if (stride != 0) // if this is zero, info is invalid
  210868. {
  210869. for (int j = bufferSize; --j >= 0;)
  210870. {
  210871. *dest++ = *src;
  210872. src += stride;
  210873. }
  210874. }
  210875. }
  210876. }
  210877. if (! isSlaveDevice)
  210878. {
  210879. if (inputDevice == 0)
  210880. {
  210881. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210882. numInputChans,
  210883. tempOutputBuffers,
  210884. numOutputChans,
  210885. bufferSize);
  210886. }
  210887. else
  210888. {
  210889. jassert (inputDevice->bufferSize == bufferSize);
  210890. // Sometimes the two linked devices seem to get their callbacks in
  210891. // parallel, so we need to lock both devices to stop the input data being
  210892. // changed while inside our callback..
  210893. const ScopedLock sl2 (inputDevice->callbackLock);
  210894. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210895. inputDevice->numInputChans,
  210896. tempOutputBuffers,
  210897. numOutputChans,
  210898. bufferSize);
  210899. }
  210900. for (i = numOutputChans; --i >= 0;)
  210901. {
  210902. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210903. const float* src = tempOutputBuffers [i];
  210904. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210905. + info.dataOffsetSamples;
  210906. const int stride = info.dataStrideSamples;
  210907. if (stride != 0) // if this is zero, info is invalid
  210908. {
  210909. for (int j = bufferSize; --j >= 0;)
  210910. {
  210911. *dest = *src++;
  210912. dest += stride;
  210913. }
  210914. }
  210915. }
  210916. }
  210917. }
  210918. else
  210919. {
  210920. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210921. {
  210922. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210923. float* dest = ((float*) outOutputData->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 = 0.0f;
  210931. dest += stride;
  210932. }
  210933. }
  210934. }
  210935. }
  210936. }
  210937. // called by callbacks
  210938. void deviceDetailsChanged()
  210939. {
  210940. if (callbacksAllowed)
  210941. startTimer (100);
  210942. }
  210943. void timerCallback()
  210944. {
  210945. stopTimer();
  210946. log ("CoreAudio device changed callback");
  210947. const double oldSampleRate = sampleRate;
  210948. const int oldBufferSize = bufferSize;
  210949. updateDetailsFromDevice();
  210950. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210951. {
  210952. callbacksAllowed = false;
  210953. stop (false);
  210954. updateDetailsFromDevice();
  210955. callbacksAllowed = true;
  210956. }
  210957. }
  210958. CoreAudioInternal* getRelatedDevice() const
  210959. {
  210960. UInt32 size = 0;
  210961. ScopedPointer <CoreAudioInternal> result;
  210962. AudioObjectPropertyAddress pa;
  210963. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210964. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210965. pa.mElement = kAudioObjectPropertyElementMaster;
  210966. if (deviceID != 0
  210967. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210968. && size > 0)
  210969. {
  210970. HeapBlock <AudioDeviceID> devs;
  210971. devs.calloc (size, 1);
  210972. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210973. {
  210974. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210975. {
  210976. if (devs[i] != deviceID && devs[i] != 0)
  210977. {
  210978. result = new CoreAudioInternal (devs[i]);
  210979. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210980. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210981. if (thisIsInput != otherIsInput
  210982. || (inChanNames.size() + outChanNames.size() == 0)
  210983. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210984. break;
  210985. result = 0;
  210986. }
  210987. }
  210988. }
  210989. }
  210990. return result.release();
  210991. }
  210992. juce_UseDebuggingNewOperator
  210993. int inputLatency, outputLatency;
  210994. BigInteger activeInputChans, activeOutputChans;
  210995. StringArray inChanNames, outChanNames;
  210996. Array <double> sampleRates;
  210997. Array <int> bufferSizes;
  210998. AudioIODeviceCallback* callback;
  210999. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  211000. AudioDeviceIOProcID audioProcID;
  211001. #endif
  211002. CoreAudioInternal* inputDevice;
  211003. bool isSlaveDevice;
  211004. private:
  211005. CriticalSection callbackLock;
  211006. AudioDeviceID deviceID;
  211007. bool started;
  211008. double sampleRate;
  211009. int bufferSize;
  211010. HeapBlock <float> audioBuffer;
  211011. int numInputChans, numOutputChans;
  211012. bool callbacksAllowed;
  211013. struct CallbackDetailsForChannel
  211014. {
  211015. int streamNum;
  211016. int dataOffsetSamples;
  211017. int dataStrideSamples;
  211018. };
  211019. int numInputChannelInfos, numOutputChannelInfos;
  211020. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  211021. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  211022. CoreAudioInternal (const CoreAudioInternal&);
  211023. CoreAudioInternal& operator= (const CoreAudioInternal&);
  211024. static OSStatus audioIOProc (AudioDeviceID inDevice,
  211025. const AudioTimeStamp* inNow,
  211026. const AudioBufferList* inInputData,
  211027. const AudioTimeStamp* inInputTime,
  211028. AudioBufferList* outOutputData,
  211029. const AudioTimeStamp* inOutputTime,
  211030. void* device)
  211031. {
  211032. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  211033. return noErr;
  211034. }
  211035. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211036. {
  211037. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211038. switch (pa->mSelector)
  211039. {
  211040. case kAudioDevicePropertyBufferSize:
  211041. case kAudioDevicePropertyBufferFrameSize:
  211042. case kAudioDevicePropertyNominalSampleRate:
  211043. case kAudioDevicePropertyStreamFormat:
  211044. case kAudioDevicePropertyDeviceIsAlive:
  211045. intern->deviceDetailsChanged();
  211046. break;
  211047. case kAudioDevicePropertyBufferSizeRange:
  211048. case kAudioDevicePropertyVolumeScalar:
  211049. case kAudioDevicePropertyMute:
  211050. case kAudioDevicePropertyPlayThru:
  211051. case kAudioDevicePropertyDataSource:
  211052. case kAudioDevicePropertyDeviceIsRunning:
  211053. break;
  211054. }
  211055. return noErr;
  211056. }
  211057. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  211058. {
  211059. AudioObjectPropertyAddress pa;
  211060. pa.mSelector = kAudioDevicePropertyDataSources;
  211061. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211062. pa.mElement = kAudioObjectPropertyElementMaster;
  211063. UInt32 size = 0;
  211064. if (deviceID != 0
  211065. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211066. {
  211067. types.calloc (size, 1);
  211068. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211069. return size / (int) sizeof (OSType);
  211070. }
  211071. return 0;
  211072. }
  211073. };
  211074. class CoreAudioIODevice : public AudioIODevice
  211075. {
  211076. public:
  211077. CoreAudioIODevice (const String& deviceName,
  211078. AudioDeviceID inputDeviceId,
  211079. const int inputIndex_,
  211080. AudioDeviceID outputDeviceId,
  211081. const int outputIndex_)
  211082. : AudioIODevice (deviceName, "CoreAudio"),
  211083. inputIndex (inputIndex_),
  211084. outputIndex (outputIndex_),
  211085. isOpen_ (false),
  211086. isStarted (false)
  211087. {
  211088. internal = 0;
  211089. CoreAudioInternal* device = 0;
  211090. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211091. {
  211092. jassert (inputDeviceId != 0);
  211093. device = new CoreAudioInternal (inputDeviceId);
  211094. }
  211095. else
  211096. {
  211097. device = new CoreAudioInternal (outputDeviceId);
  211098. if (inputDeviceId != 0)
  211099. {
  211100. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211101. device->inputDevice = secondDevice;
  211102. secondDevice->isSlaveDevice = true;
  211103. }
  211104. }
  211105. internal = device;
  211106. AudioObjectPropertyAddress pa;
  211107. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211108. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211109. pa.mElement = kAudioObjectPropertyElementWildcard;
  211110. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211111. }
  211112. ~CoreAudioIODevice()
  211113. {
  211114. AudioObjectPropertyAddress pa;
  211115. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211116. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211117. pa.mElement = kAudioObjectPropertyElementWildcard;
  211118. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211119. delete internal;
  211120. }
  211121. const StringArray getOutputChannelNames()
  211122. {
  211123. return internal->outChanNames;
  211124. }
  211125. const StringArray getInputChannelNames()
  211126. {
  211127. if (internal->inputDevice != 0)
  211128. return internal->inputDevice->inChanNames;
  211129. else
  211130. return internal->inChanNames;
  211131. }
  211132. int getNumSampleRates()
  211133. {
  211134. return internal->sampleRates.size();
  211135. }
  211136. double getSampleRate (int index)
  211137. {
  211138. return internal->sampleRates [index];
  211139. }
  211140. int getNumBufferSizesAvailable()
  211141. {
  211142. return internal->bufferSizes.size();
  211143. }
  211144. int getBufferSizeSamples (int index)
  211145. {
  211146. return internal->bufferSizes [index];
  211147. }
  211148. int getDefaultBufferSize()
  211149. {
  211150. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211151. if (getBufferSizeSamples(i) >= 512)
  211152. return getBufferSizeSamples(i);
  211153. return 512;
  211154. }
  211155. const String open (const BigInteger& inputChannels,
  211156. const BigInteger& outputChannels,
  211157. double sampleRate,
  211158. int bufferSizeSamples)
  211159. {
  211160. isOpen_ = true;
  211161. if (bufferSizeSamples <= 0)
  211162. bufferSizeSamples = getDefaultBufferSize();
  211163. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211164. isOpen_ = lastError.isEmpty();
  211165. return lastError;
  211166. }
  211167. void close()
  211168. {
  211169. isOpen_ = false;
  211170. internal->stop (false);
  211171. }
  211172. bool isOpen()
  211173. {
  211174. return isOpen_;
  211175. }
  211176. int getCurrentBufferSizeSamples()
  211177. {
  211178. return internal != 0 ? internal->getBufferSize() : 512;
  211179. }
  211180. double getCurrentSampleRate()
  211181. {
  211182. return internal != 0 ? internal->getSampleRate() : 0;
  211183. }
  211184. int getCurrentBitDepth()
  211185. {
  211186. return 32; // no way to find out, so just assume it's high..
  211187. }
  211188. const BigInteger getActiveOutputChannels() const
  211189. {
  211190. return internal != 0 ? internal->activeOutputChans : BigInteger();
  211191. }
  211192. const BigInteger getActiveInputChannels() const
  211193. {
  211194. BigInteger chans;
  211195. if (internal != 0)
  211196. {
  211197. chans = internal->activeInputChans;
  211198. if (internal->inputDevice != 0)
  211199. chans |= internal->inputDevice->activeInputChans;
  211200. }
  211201. return chans;
  211202. }
  211203. int getOutputLatencyInSamples()
  211204. {
  211205. if (internal == 0)
  211206. return 0;
  211207. // this seems like a good guess at getting the latency right - comparing
  211208. // this with a round-trip measurement, it gets it to within a few millisecs
  211209. // for the built-in mac soundcard
  211210. return internal->outputLatency + internal->getBufferSize() * 2;
  211211. }
  211212. int getInputLatencyInSamples()
  211213. {
  211214. if (internal == 0)
  211215. return 0;
  211216. return internal->inputLatency + internal->getBufferSize() * 2;
  211217. }
  211218. void start (AudioIODeviceCallback* callback)
  211219. {
  211220. if (internal != 0 && ! isStarted)
  211221. {
  211222. if (callback != 0)
  211223. callback->audioDeviceAboutToStart (this);
  211224. isStarted = true;
  211225. internal->start (callback);
  211226. }
  211227. }
  211228. void stop()
  211229. {
  211230. if (isStarted && internal != 0)
  211231. {
  211232. AudioIODeviceCallback* const lastCallback = internal->callback;
  211233. isStarted = false;
  211234. internal->stop (true);
  211235. if (lastCallback != 0)
  211236. lastCallback->audioDeviceStopped();
  211237. }
  211238. }
  211239. bool isPlaying()
  211240. {
  211241. if (internal->callback == 0)
  211242. isStarted = false;
  211243. return isStarted;
  211244. }
  211245. const String getLastError()
  211246. {
  211247. return lastError;
  211248. }
  211249. int inputIndex, outputIndex;
  211250. juce_UseDebuggingNewOperator
  211251. private:
  211252. CoreAudioInternal* internal;
  211253. bool isOpen_, isStarted;
  211254. String lastError;
  211255. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211256. {
  211257. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211258. switch (pa->mSelector)
  211259. {
  211260. case kAudioHardwarePropertyDevices:
  211261. intern->deviceDetailsChanged();
  211262. break;
  211263. case kAudioHardwarePropertyDefaultOutputDevice:
  211264. case kAudioHardwarePropertyDefaultInputDevice:
  211265. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211266. break;
  211267. }
  211268. return noErr;
  211269. }
  211270. CoreAudioIODevice (const CoreAudioIODevice&);
  211271. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211272. };
  211273. class CoreAudioIODeviceType : public AudioIODeviceType
  211274. {
  211275. public:
  211276. CoreAudioIODeviceType()
  211277. : AudioIODeviceType ("CoreAudio"),
  211278. hasScanned (false)
  211279. {
  211280. }
  211281. ~CoreAudioIODeviceType()
  211282. {
  211283. }
  211284. void scanForDevices()
  211285. {
  211286. hasScanned = true;
  211287. inputDeviceNames.clear();
  211288. outputDeviceNames.clear();
  211289. inputIds.clear();
  211290. outputIds.clear();
  211291. UInt32 size;
  211292. AudioObjectPropertyAddress pa;
  211293. pa.mSelector = kAudioHardwarePropertyDevices;
  211294. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211295. pa.mElement = kAudioObjectPropertyElementMaster;
  211296. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211297. {
  211298. HeapBlock <AudioDeviceID> devs;
  211299. devs.calloc (size, 1);
  211300. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211301. {
  211302. static bool alreadyLogged = false;
  211303. const int num = size / (int) sizeof (AudioDeviceID);
  211304. for (int i = 0; i < num; ++i)
  211305. {
  211306. char name [1024];
  211307. size = sizeof (name);
  211308. pa.mSelector = kAudioDevicePropertyDeviceName;
  211309. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211310. {
  211311. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211312. if (! alreadyLogged)
  211313. log ("CoreAudio device: " + nameString);
  211314. const int numIns = getNumChannels (devs[i], true);
  211315. const int numOuts = getNumChannels (devs[i], false);
  211316. if (numIns > 0)
  211317. {
  211318. inputDeviceNames.add (nameString);
  211319. inputIds.add (devs[i]);
  211320. }
  211321. if (numOuts > 0)
  211322. {
  211323. outputDeviceNames.add (nameString);
  211324. outputIds.add (devs[i]);
  211325. }
  211326. }
  211327. }
  211328. alreadyLogged = true;
  211329. }
  211330. }
  211331. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211332. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211333. }
  211334. const StringArray getDeviceNames (bool wantInputNames) const
  211335. {
  211336. jassert (hasScanned); // need to call scanForDevices() before doing this
  211337. if (wantInputNames)
  211338. return inputDeviceNames;
  211339. else
  211340. return outputDeviceNames;
  211341. }
  211342. int getDefaultDeviceIndex (bool forInput) const
  211343. {
  211344. jassert (hasScanned); // need to call scanForDevices() before doing this
  211345. AudioDeviceID deviceID;
  211346. UInt32 size = sizeof (deviceID);
  211347. // if they're asking for any input channels at all, use the default input, so we
  211348. // get the built-in mic rather than the built-in output with no inputs..
  211349. AudioObjectPropertyAddress pa;
  211350. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211351. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211352. pa.mElement = kAudioObjectPropertyElementMaster;
  211353. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211354. {
  211355. if (forInput)
  211356. {
  211357. for (int i = inputIds.size(); --i >= 0;)
  211358. if (inputIds[i] == deviceID)
  211359. return i;
  211360. }
  211361. else
  211362. {
  211363. for (int i = outputIds.size(); --i >= 0;)
  211364. if (outputIds[i] == deviceID)
  211365. return i;
  211366. }
  211367. }
  211368. return 0;
  211369. }
  211370. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  211371. {
  211372. jassert (hasScanned); // need to call scanForDevices() before doing this
  211373. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211374. if (d == 0)
  211375. return -1;
  211376. return asInput ? d->inputIndex
  211377. : d->outputIndex;
  211378. }
  211379. bool hasSeparateInputsAndOutputs() const { return true; }
  211380. AudioIODevice* createDevice (const String& outputDeviceName,
  211381. const String& inputDeviceName)
  211382. {
  211383. jassert (hasScanned); // need to call scanForDevices() before doing this
  211384. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211385. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211386. String deviceName (outputDeviceName);
  211387. if (deviceName.isEmpty())
  211388. deviceName = inputDeviceName;
  211389. if (index >= 0)
  211390. return new CoreAudioIODevice (deviceName,
  211391. inputIds [inputIndex],
  211392. inputIndex,
  211393. outputIds [outputIndex],
  211394. outputIndex);
  211395. return 0;
  211396. }
  211397. juce_UseDebuggingNewOperator
  211398. private:
  211399. StringArray inputDeviceNames, outputDeviceNames;
  211400. Array <AudioDeviceID> inputIds, outputIds;
  211401. bool hasScanned;
  211402. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211403. {
  211404. int total = 0;
  211405. UInt32 size;
  211406. AudioObjectPropertyAddress pa;
  211407. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211408. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211409. pa.mElement = kAudioObjectPropertyElementMaster;
  211410. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211411. {
  211412. HeapBlock <AudioBufferList> bufList;
  211413. bufList.calloc (size, 1);
  211414. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211415. {
  211416. const int numStreams = bufList->mNumberBuffers;
  211417. for (int i = 0; i < numStreams; ++i)
  211418. {
  211419. const AudioBuffer& b = bufList->mBuffers[i];
  211420. total += b.mNumberChannels;
  211421. }
  211422. }
  211423. }
  211424. return total;
  211425. }
  211426. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211427. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211428. };
  211429. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211430. {
  211431. return new CoreAudioIODeviceType();
  211432. }
  211433. #undef log
  211434. #endif
  211435. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211436. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211437. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211438. // compiled on its own).
  211439. #if JUCE_INCLUDED_FILE
  211440. #if JUCE_MAC
  211441. #undef log
  211442. #define log(a) Logger::writeToLog(a)
  211443. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211444. {
  211445. if (err == noErr)
  211446. return true;
  211447. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  211448. jassertfalse
  211449. return false;
  211450. }
  211451. #undef OK
  211452. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211453. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211454. {
  211455. String result;
  211456. CFStringRef str = 0;
  211457. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211458. if (str != 0)
  211459. {
  211460. result = PlatformUtilities::cfStringToJuceString (str);
  211461. CFRelease (str);
  211462. str = 0;
  211463. }
  211464. MIDIEntityRef entity = 0;
  211465. MIDIEndpointGetEntity (endpoint, &entity);
  211466. if (entity == 0)
  211467. return result; // probably virtual
  211468. if (result.isEmpty())
  211469. {
  211470. // endpoint name has zero length - try the entity
  211471. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211472. if (str != 0)
  211473. {
  211474. result += PlatformUtilities::cfStringToJuceString (str);
  211475. CFRelease (str);
  211476. str = 0;
  211477. }
  211478. }
  211479. // now consider the device's name
  211480. MIDIDeviceRef device = 0;
  211481. MIDIEntityGetDevice (entity, &device);
  211482. if (device == 0)
  211483. return result;
  211484. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211485. if (str != 0)
  211486. {
  211487. const String s (PlatformUtilities::cfStringToJuceString (str));
  211488. CFRelease (str);
  211489. // if an external device has only one entity, throw away
  211490. // the endpoint name and just use the device name
  211491. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211492. {
  211493. result = s;
  211494. }
  211495. else if (! result.startsWithIgnoreCase (s))
  211496. {
  211497. // prepend the device name to the entity name
  211498. result = (s + " " + result).trimEnd();
  211499. }
  211500. }
  211501. return result;
  211502. }
  211503. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211504. {
  211505. String result;
  211506. // Does the endpoint have connections?
  211507. CFDataRef connections = 0;
  211508. int numConnections = 0;
  211509. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211510. if (connections != 0)
  211511. {
  211512. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211513. if (numConnections > 0)
  211514. {
  211515. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211516. for (int i = 0; i < numConnections; ++i, ++pid)
  211517. {
  211518. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211519. MIDIObjectRef connObject;
  211520. MIDIObjectType connObjectType;
  211521. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211522. if (err == noErr)
  211523. {
  211524. String s;
  211525. if (connObjectType == kMIDIObjectType_ExternalSource
  211526. || connObjectType == kMIDIObjectType_ExternalDestination)
  211527. {
  211528. // Connected to an external device's endpoint (10.3 and later).
  211529. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211530. }
  211531. else
  211532. {
  211533. // Connected to an external device (10.2) (or something else, catch-all)
  211534. CFStringRef str = 0;
  211535. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211536. if (str != 0)
  211537. {
  211538. s = PlatformUtilities::cfStringToJuceString (str);
  211539. CFRelease (str);
  211540. }
  211541. }
  211542. if (s.isNotEmpty())
  211543. {
  211544. if (result.isNotEmpty())
  211545. result += ", ";
  211546. result += s;
  211547. }
  211548. }
  211549. }
  211550. }
  211551. CFRelease (connections);
  211552. }
  211553. if (result.isNotEmpty())
  211554. return result;
  211555. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211556. return getEndpointName (endpoint, false);
  211557. }
  211558. const StringArray MidiOutput::getDevices()
  211559. {
  211560. StringArray s;
  211561. const ItemCount num = MIDIGetNumberOfDestinations();
  211562. for (ItemCount i = 0; i < num; ++i)
  211563. {
  211564. MIDIEndpointRef dest = MIDIGetDestination (i);
  211565. if (dest != 0)
  211566. {
  211567. String name (getConnectedEndpointName (dest));
  211568. if (name.isEmpty())
  211569. name = "<error>";
  211570. s.add (name);
  211571. }
  211572. else
  211573. {
  211574. s.add ("<error>");
  211575. }
  211576. }
  211577. return s;
  211578. }
  211579. int MidiOutput::getDefaultDeviceIndex()
  211580. {
  211581. return 0;
  211582. }
  211583. static MIDIClientRef globalMidiClient;
  211584. static bool hasGlobalClientBeenCreated = false;
  211585. static bool makeSureClientExists()
  211586. {
  211587. if (! hasGlobalClientBeenCreated)
  211588. {
  211589. String name ("JUCE");
  211590. if (JUCEApplication::getInstance() != 0)
  211591. name = JUCEApplication::getInstance()->getApplicationName();
  211592. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211593. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211594. CFRelease (appName);
  211595. }
  211596. return hasGlobalClientBeenCreated;
  211597. }
  211598. class MidiPortAndEndpoint
  211599. {
  211600. public:
  211601. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211602. : port (port_), endPoint (endPoint_)
  211603. {
  211604. }
  211605. ~MidiPortAndEndpoint()
  211606. {
  211607. if (port != 0)
  211608. MIDIPortDispose (port);
  211609. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211610. MIDIEndpointDispose (endPoint);
  211611. }
  211612. MIDIPortRef port;
  211613. MIDIEndpointRef endPoint;
  211614. };
  211615. MidiOutput* MidiOutput::openDevice (int index)
  211616. {
  211617. MidiOutput* mo = 0;
  211618. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211619. {
  211620. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211621. CFStringRef pname;
  211622. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211623. {
  211624. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  211625. if (makeSureClientExists())
  211626. {
  211627. MIDIPortRef port;
  211628. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211629. {
  211630. mo = new MidiOutput();
  211631. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211632. }
  211633. }
  211634. CFRelease (pname);
  211635. }
  211636. }
  211637. return mo;
  211638. }
  211639. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211640. {
  211641. MidiOutput* mo = 0;
  211642. if (makeSureClientExists())
  211643. {
  211644. MIDIEndpointRef endPoint;
  211645. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211646. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211647. {
  211648. mo = new MidiOutput();
  211649. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211650. }
  211651. CFRelease (name);
  211652. }
  211653. return mo;
  211654. }
  211655. MidiOutput::~MidiOutput()
  211656. {
  211657. delete (MidiPortAndEndpoint*) internal;
  211658. }
  211659. void MidiOutput::reset()
  211660. {
  211661. }
  211662. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211663. {
  211664. return false;
  211665. }
  211666. void MidiOutput::setVolume (float leftVol, float rightVol)
  211667. {
  211668. }
  211669. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211670. {
  211671. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211672. if (message.isSysEx())
  211673. {
  211674. const int maxPacketSize = 256;
  211675. int pos = 0, bytesLeft = message.getRawDataSize();
  211676. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211677. HeapBlock <MIDIPacketList> packets;
  211678. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211679. packets->numPackets = numPackets;
  211680. MIDIPacket* p = packets->packet;
  211681. for (int i = 0; i < numPackets; ++i)
  211682. {
  211683. p->timeStamp = 0;
  211684. p->length = jmin (maxPacketSize, bytesLeft);
  211685. memcpy (p->data, message.getRawData() + pos, p->length);
  211686. pos += p->length;
  211687. bytesLeft -= p->length;
  211688. p = MIDIPacketNext (p);
  211689. }
  211690. if (mpe->port != 0)
  211691. MIDISend (mpe->port, mpe->endPoint, packets);
  211692. else
  211693. MIDIReceived (mpe->endPoint, packets);
  211694. }
  211695. else
  211696. {
  211697. MIDIPacketList packets;
  211698. packets.numPackets = 1;
  211699. packets.packet[0].timeStamp = 0;
  211700. packets.packet[0].length = message.getRawDataSize();
  211701. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211702. if (mpe->port != 0)
  211703. MIDISend (mpe->port, mpe->endPoint, &packets);
  211704. else
  211705. MIDIReceived (mpe->endPoint, &packets);
  211706. }
  211707. }
  211708. const StringArray MidiInput::getDevices()
  211709. {
  211710. StringArray s;
  211711. const ItemCount num = MIDIGetNumberOfSources();
  211712. for (ItemCount i = 0; i < num; ++i)
  211713. {
  211714. MIDIEndpointRef source = MIDIGetSource (i);
  211715. if (source != 0)
  211716. {
  211717. String name (getConnectedEndpointName (source));
  211718. if (name.isEmpty())
  211719. name = "<error>";
  211720. s.add (name);
  211721. }
  211722. else
  211723. {
  211724. s.add ("<error>");
  211725. }
  211726. }
  211727. return s;
  211728. }
  211729. int MidiInput::getDefaultDeviceIndex()
  211730. {
  211731. return 0;
  211732. }
  211733. struct MidiPortAndCallback
  211734. {
  211735. MidiInput* input;
  211736. MidiPortAndEndpoint* portAndEndpoint;
  211737. MidiInputCallback* callback;
  211738. MemoryBlock pendingData;
  211739. int pendingBytes;
  211740. double pendingDataTime;
  211741. bool active;
  211742. void processSysex (const uint8*& d, int& size, const double time)
  211743. {
  211744. if (*d == 0xf0)
  211745. {
  211746. pendingBytes = 0;
  211747. pendingDataTime = time;
  211748. }
  211749. pendingData.ensureSize (pendingBytes + size, false);
  211750. uint8* totalMessage = (uint8*) pendingData.getData();
  211751. uint8* dest = totalMessage + pendingBytes;
  211752. while (size > 0)
  211753. {
  211754. if (pendingBytes > 0 && *d >= 0x80)
  211755. {
  211756. if (*d >= 0xfa || *d == 0xf8)
  211757. {
  211758. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211759. ++d;
  211760. --size;
  211761. }
  211762. else
  211763. {
  211764. if (*d == 0xf7)
  211765. {
  211766. *dest++ = *d++;
  211767. pendingBytes++;
  211768. --size;
  211769. }
  211770. break;
  211771. }
  211772. }
  211773. else
  211774. {
  211775. *dest++ = *d++;
  211776. pendingBytes++;
  211777. --size;
  211778. }
  211779. }
  211780. if (totalMessage [pendingBytes - 1] == 0xf7)
  211781. {
  211782. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211783. pendingBytes = 0;
  211784. }
  211785. else
  211786. {
  211787. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211788. }
  211789. }
  211790. };
  211791. namespace CoreMidiCallbacks
  211792. {
  211793. static CriticalSection callbackLock;
  211794. static VoidArray activeCallbacks;
  211795. }
  211796. static void midiInputProc (const MIDIPacketList* pktlist,
  211797. void* readProcRefCon,
  211798. void* srcConnRefCon)
  211799. {
  211800. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211801. const double originalTime = time;
  211802. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211803. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211804. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211805. {
  211806. const MIDIPacket* packet = &pktlist->packet[0];
  211807. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211808. {
  211809. const uint8* d = (const uint8*) (packet->data);
  211810. int size = packet->length;
  211811. while (size > 0)
  211812. {
  211813. time = originalTime;
  211814. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211815. {
  211816. mpc->processSysex (d, size, time);
  211817. }
  211818. else
  211819. {
  211820. int used = 0;
  211821. const MidiMessage m (d, size, used, 0, time);
  211822. if (used <= 0)
  211823. {
  211824. jassertfalse // malformed midi message
  211825. break;
  211826. }
  211827. else
  211828. {
  211829. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211830. }
  211831. size -= used;
  211832. d += used;
  211833. }
  211834. }
  211835. packet = MIDIPacketNext (packet);
  211836. }
  211837. }
  211838. }
  211839. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211840. {
  211841. MidiInput* mi = 0;
  211842. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211843. {
  211844. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211845. if (endPoint != 0)
  211846. {
  211847. CFStringRef pname;
  211848. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211849. {
  211850. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  211851. if (makeSureClientExists())
  211852. {
  211853. MIDIPortRef port;
  211854. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211855. mpc->active = false;
  211856. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211857. {
  211858. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211859. {
  211860. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211861. mpc->callback = callback;
  211862. mpc->pendingBytes = 0;
  211863. mpc->pendingData.ensureSize (128);
  211864. mi = new MidiInput (getDevices() [index]);
  211865. mpc->input = mi;
  211866. mi->internal = (void*) mpc;
  211867. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211868. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211869. }
  211870. else
  211871. {
  211872. OK (MIDIPortDispose (port));
  211873. }
  211874. }
  211875. }
  211876. }
  211877. CFRelease (pname);
  211878. }
  211879. }
  211880. return mi;
  211881. }
  211882. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211883. {
  211884. MidiInput* mi = 0;
  211885. if (makeSureClientExists())
  211886. {
  211887. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211888. mpc->active = false;
  211889. MIDIEndpointRef endPoint;
  211890. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211891. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211892. {
  211893. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211894. mpc->callback = callback;
  211895. mpc->pendingBytes = 0;
  211896. mpc->pendingData.ensureSize (128);
  211897. mi = new MidiInput (deviceName);
  211898. mpc->input = mi;
  211899. mi->internal = (void*) mpc;
  211900. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211901. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211902. }
  211903. CFRelease (name);
  211904. }
  211905. return mi;
  211906. }
  211907. MidiInput::MidiInput (const String& name_)
  211908. : name (name_)
  211909. {
  211910. }
  211911. MidiInput::~MidiInput()
  211912. {
  211913. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211914. mpc->active = false;
  211915. {
  211916. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211917. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211918. }
  211919. if (mpc->portAndEndpoint->port != 0)
  211920. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211921. delete mpc->portAndEndpoint;
  211922. delete mpc;
  211923. }
  211924. void MidiInput::start()
  211925. {
  211926. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211927. ((MidiPortAndCallback*) internal)->active = true;
  211928. }
  211929. void MidiInput::stop()
  211930. {
  211931. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211932. ((MidiPortAndCallback*) internal)->active = false;
  211933. }
  211934. #undef log
  211935. #else
  211936. MidiOutput::~MidiOutput()
  211937. {
  211938. }
  211939. void MidiOutput::reset()
  211940. {
  211941. }
  211942. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211943. {
  211944. return false;
  211945. }
  211946. void MidiOutput::setVolume (float leftVol, float rightVol)
  211947. {
  211948. }
  211949. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211950. {
  211951. }
  211952. const StringArray MidiOutput::getDevices()
  211953. {
  211954. return StringArray();
  211955. }
  211956. MidiOutput* MidiOutput::openDevice (int index)
  211957. {
  211958. return 0;
  211959. }
  211960. const StringArray MidiInput::getDevices()
  211961. {
  211962. return StringArray();
  211963. }
  211964. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211965. {
  211966. return 0;
  211967. }
  211968. #endif
  211969. #endif
  211970. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211971. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211972. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211973. // compiled on its own).
  211974. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  211975. #if ! JUCE_QUICKTIME
  211976. #error "On the Mac, cameras use Quicktime, so if you turn on JUCE_USE_CAMERA, you also need to enable JUCE_QUICKTIME"
  211977. #endif
  211978. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211979. class QTCameraDeviceInteral;
  211980. END_JUCE_NAMESPACE
  211981. @interface QTCaptureCallbackDelegate : NSObject
  211982. {
  211983. @public
  211984. CameraDevice* owner;
  211985. QTCameraDeviceInteral* internal;
  211986. int64 firstPresentationTime;
  211987. int64 averageTimeOffset;
  211988. }
  211989. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211990. - (void) dealloc;
  211991. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211992. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211993. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211994. fromConnection: (QTCaptureConnection*) connection;
  211995. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211996. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211997. fromConnection: (QTCaptureConnection*) connection;
  211998. @end
  211999. BEGIN_JUCE_NAMESPACE
  212000. class QTCameraDeviceInteral
  212001. {
  212002. public:
  212003. QTCameraDeviceInteral (CameraDevice* owner, int index)
  212004. {
  212005. const ScopedAutoReleasePool pool;
  212006. session = [[QTCaptureSession alloc] init];
  212007. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212008. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  212009. input = 0;
  212010. audioInput = 0;
  212011. audioDevice = 0;
  212012. fileOutput = 0;
  212013. imageOutput = 0;
  212014. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  212015. internalDev: this];
  212016. NSError* err = 0;
  212017. [device retain];
  212018. [device open: &err];
  212019. if (err == 0)
  212020. {
  212021. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212022. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212023. [session addInput: input error: &err];
  212024. if (err == 0)
  212025. {
  212026. resetFile();
  212027. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  212028. [imageOutput setDelegate: callbackDelegate];
  212029. if (err == 0)
  212030. {
  212031. [session startRunning];
  212032. return;
  212033. }
  212034. }
  212035. }
  212036. openingError = nsStringToJuce ([err description]);
  212037. DBG (openingError);
  212038. }
  212039. ~QTCameraDeviceInteral()
  212040. {
  212041. [session stopRunning];
  212042. [session removeOutput: imageOutput];
  212043. [session release];
  212044. [input release];
  212045. [device release];
  212046. [audioDevice release];
  212047. [audioInput release];
  212048. [fileOutput release];
  212049. [imageOutput release];
  212050. [callbackDelegate release];
  212051. }
  212052. void resetFile()
  212053. {
  212054. [fileOutput recordToOutputFileURL: nil];
  212055. [session removeOutput: fileOutput];
  212056. [fileOutput release];
  212057. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  212058. [session removeInput: audioInput];
  212059. [audioInput release];
  212060. audioInput = 0;
  212061. [audioDevice release];
  212062. audioDevice = 0;
  212063. [fileOutput setDelegate: callbackDelegate];
  212064. }
  212065. void addDefaultAudioInput()
  212066. {
  212067. NSError* err = nil;
  212068. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212069. if ([audioDevice open: &err])
  212070. [audioDevice retain];
  212071. else
  212072. audioDevice = nil;
  212073. if (audioDevice != 0)
  212074. {
  212075. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212076. [session addInput: audioInput error: &err];
  212077. }
  212078. }
  212079. void addListener (CameraImageListener* listenerToAdd)
  212080. {
  212081. const ScopedLock sl (listenerLock);
  212082. if (listeners.size() == 0)
  212083. [session addOutput: imageOutput error: nil];
  212084. listeners.addIfNotAlreadyThere (listenerToAdd);
  212085. }
  212086. void removeListener (CameraImageListener* listenerToRemove)
  212087. {
  212088. const ScopedLock sl (listenerLock);
  212089. listeners.removeValue (listenerToRemove);
  212090. if (listeners.size() == 0)
  212091. [session removeOutput: imageOutput];
  212092. }
  212093. void callListeners (CIImage* frame, int w, int h)
  212094. {
  212095. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212096. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212097. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212098. CGContextFlush (image.context);
  212099. const ScopedLock sl (listenerLock);
  212100. for (int i = listeners.size(); --i >= 0;)
  212101. {
  212102. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212103. if (l != 0)
  212104. l->imageReceived (image);
  212105. }
  212106. }
  212107. QTCaptureDevice* device;
  212108. QTCaptureDeviceInput* input;
  212109. QTCaptureDevice* audioDevice;
  212110. QTCaptureDeviceInput* audioInput;
  212111. QTCaptureSession* session;
  212112. QTCaptureMovieFileOutput* fileOutput;
  212113. QTCaptureDecompressedVideoOutput* imageOutput;
  212114. QTCaptureCallbackDelegate* callbackDelegate;
  212115. String openingError;
  212116. VoidArray listeners;
  212117. CriticalSection listenerLock;
  212118. };
  212119. END_JUCE_NAMESPACE
  212120. @implementation QTCaptureCallbackDelegate
  212121. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212122. internalDev: (QTCameraDeviceInteral*) d
  212123. {
  212124. [super init];
  212125. owner = owner_;
  212126. internal = d;
  212127. firstPresentationTime = 0;
  212128. averageTimeOffset = 0;
  212129. return self;
  212130. }
  212131. - (void) dealloc
  212132. {
  212133. [super dealloc];
  212134. }
  212135. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212136. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212137. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212138. fromConnection: (QTCaptureConnection*) connection
  212139. {
  212140. if (internal->listeners.size() > 0)
  212141. {
  212142. const ScopedAutoReleasePool pool;
  212143. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212144. CVPixelBufferGetWidth (videoFrame),
  212145. CVPixelBufferGetHeight (videoFrame));
  212146. }
  212147. }
  212148. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212149. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212150. fromConnection: (QTCaptureConnection*) connection
  212151. {
  212152. const Time now (Time::getCurrentTime());
  212153. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212154. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212155. #else
  212156. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212157. #endif
  212158. int64 presentationTime = (hosttime != nil)
  212159. ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
  212160. : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50);
  212161. const int64 timeDiff = now.toMilliseconds() - presentationTime;
  212162. if (firstPresentationTime == 0)
  212163. {
  212164. firstPresentationTime = presentationTime;
  212165. averageTimeOffset = timeDiff;
  212166. }
  212167. else
  212168. {
  212169. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212170. }
  212171. }
  212172. @end
  212173. BEGIN_JUCE_NAMESPACE
  212174. class QTCaptureViewerComp : public NSViewComponent
  212175. {
  212176. public:
  212177. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212178. {
  212179. const ScopedAutoReleasePool pool;
  212180. captureView = [[QTCaptureView alloc] init];
  212181. [captureView setCaptureSession: internal->session];
  212182. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212183. setView (captureView);
  212184. }
  212185. ~QTCaptureViewerComp()
  212186. {
  212187. setView (0);
  212188. [captureView setCaptureSession: nil];
  212189. [captureView release];
  212190. }
  212191. QTCaptureView* captureView;
  212192. };
  212193. CameraDevice::CameraDevice (const String& name_, int index)
  212194. : name (name_)
  212195. {
  212196. isRecording = false;
  212197. internal = new QTCameraDeviceInteral (this, index);
  212198. }
  212199. CameraDevice::~CameraDevice()
  212200. {
  212201. stopRecording();
  212202. delete static_cast <QTCameraDeviceInteral*> (internal);
  212203. internal = 0;
  212204. }
  212205. Component* CameraDevice::createViewerComponent()
  212206. {
  212207. return new QTCaptureViewerComp (this, static_cast <QTCameraDeviceInteral*> (internal));
  212208. }
  212209. const String CameraDevice::getFileExtension()
  212210. {
  212211. return ".mov";
  212212. }
  212213. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212214. {
  212215. stopRecording();
  212216. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212217. d->callbackDelegate->firstPresentationTime = 0;
  212218. file.deleteFile();
  212219. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212220. // out wrong, so we'll put some audio in there too..,
  212221. d->addDefaultAudioInput();
  212222. [d->session addOutput: d->fileOutput error: nil];
  212223. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212224. for (;;)
  212225. {
  212226. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212227. if (connection == 0)
  212228. break;
  212229. QTCompressionOptions* options = 0;
  212230. NSString* mediaType = [connection mediaType];
  212231. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212232. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212233. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212234. : @"QTCompressionOptions240SizeH264Video"];
  212235. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212236. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212237. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212238. }
  212239. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212240. isRecording = true;
  212241. }
  212242. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212243. {
  212244. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212245. if (d->callbackDelegate->firstPresentationTime != 0)
  212246. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212247. return Time();
  212248. }
  212249. void CameraDevice::stopRecording()
  212250. {
  212251. if (isRecording)
  212252. {
  212253. static_cast <QTCameraDeviceInteral*> (internal)->resetFile();
  212254. isRecording = false;
  212255. }
  212256. }
  212257. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212258. {
  212259. if (listenerToAdd != 0)
  212260. static_cast <QTCameraDeviceInteral*> (internal)->addListener (listenerToAdd);
  212261. }
  212262. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212263. {
  212264. if (listenerToRemove != 0)
  212265. static_cast <QTCameraDeviceInteral*> (internal)->removeListener (listenerToRemove);
  212266. }
  212267. const StringArray CameraDevice::getAvailableDevices()
  212268. {
  212269. const ScopedAutoReleasePool pool;
  212270. StringArray results;
  212271. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212272. for (int i = 0; i < (int) [devs count]; ++i)
  212273. {
  212274. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212275. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212276. }
  212277. return results;
  212278. }
  212279. CameraDevice* CameraDevice::openDevice (int index,
  212280. int minWidth, int minHeight,
  212281. int maxWidth, int maxHeight)
  212282. {
  212283. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212284. if (static_cast <QTCameraDeviceInteral*> (d->internal)->openingError.isEmpty())
  212285. return d.release();
  212286. return 0;
  212287. }
  212288. #endif
  212289. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212290. #endif
  212291. #endif
  212292. END_JUCE_NAMESPACE
  212293. #endif
  212294. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212295. #endif
  212296. #endif